Example #1
0
pt_menuitem showmenus(char startmenu)
{
  pt_menuitem rv;
  char oldpage,tpos;

  // Setup screen for menusystem
  oldpage = getdisppage();
  setdisppage(ms->menupage);
  cls();
  clearwindow(ms->minrow, ms->mincol, ms->maxrow, ms->maxcol, 
	      ms->menupage, ms->fillchar, ms->fillattr);
  tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line    
  gotoxy(ms->minrow,ms->mincol,ms->menupage);
  cprint(ms->tfillchar,ms->titleattr,ms->numcols,ms->menupage);
  gotoxy(ms->minrow,ms->mincol+tpos,ms->menupage);
  csprint(ms->title,ms->titleattr);

  cursoroff(); // Doesn't seem to work?

  // Go, main menu cannot be a radio menu 
  rv = runmenusystem(ms->minrow+MENUROW, ms->mincol+MENUCOL, 
		     ms->menus[(unsigned int)startmenu], 0, NORMALMENU);

  // Hide the garbage we left on the screen
  cursoron();
  if (oldpage == ms->menupage) cls(); else setdisppage(oldpage);

  // Return user choice
  return rv;
}
Example #2
0
/* Print a C string (NUL-terminated) */
void cswprint(const char *str, char attr, char left)
{
    char page = getdisppage();
    char newattr = 0, cha, chb;
    char row, col;
    char nr, nc;

    nr = getnumrows();
    nc = getnumcols();
    getpos(&row, &col, page);
    while (*str) {
	switch (*str) {
	case '\b':
	    --col;
	    break;
	case '\n':
	    ++row;
	    col = left;
	    break;
	case '\r':
	    //col=left;
	    break;
	case BELL:		// Bell Char
	    beep();
	    break;
	case CHRELATTR:	// change attribute (relatively)
	case CHABSATTR:	// change attribute (absolute)
	    cha = *(str + 1);
	    chb = *(str + 2);
	    if ((((cha >= '0') && (cha <= '9')) || ((cha >= 'A') && (cha <= 'F'))) && (((chb >= '0') && (chb <= '9')) || ((chb >= 'A') && (chb <= 'F'))))	// Next two chars are legal
	    {
		if ((cha >= 'A') && (cha <= 'F'))
		    cha = cha - 'A' + 10;
		else
		    cha = cha - '0';
		if ((chb >= 'A') && (chb <= 'F'))
		    chb = chb - 'A' + 10;
		else
		    chb = chb - '0';
		newattr = (cha << 4) + chb;
		attr = (*str == CHABSATTR ? newattr : attr ^ newattr);
		str += 2;	// Will be incremented again later
	    }
	    break;
	default:
	    putch(*str, attr, page);
	    ++col;
	}
	if (col >= nc) {
	    ++row;
	    col = left;
	}
	if (row > nr) {
	    scrollup();
	    row = nr;
	}
	gotoxy(row, col, page);
	str++;
    }
}
Example #3
0
void runhelp(const char *filename)
{
   char dp;
   char fullname[HELPDIRLEN+16];

   dp = getdisppage();
   if (dp != HELPPAGE) setdisppage(HELPPAGE);
   cursoroff();
   if (helpbasedir[0] != 0) {
      strcpy(fullname,helpbasedir);
      strcat(fullname,"/");
      strcat(fullname,filename);
      showhelp(fullname);
   }
   else showhelp (filename); // Assume filename is absolute
   if (dp != HELPPAGE) setdisppage(dp);
}
Example #4
0
/* attr[0] is non-hilite attr, attr[1] is highlight attr */
void printmenuitem(const char *str,char* attr)
{
    char page = getdisppage();
    char row,col;
    int hlite=NOHLITE; // Initially no highlighting

    getpos(&row,&col,page);
    while ( *str ) {
      switch (*str) 
	{
	case '\b':
	  --col;
	  break;
	case '\n':
	  ++row;
	  break;
	case '\r':
	  col=0;
	  break;
	case BELL: // No Bell Char
	  break;
	case ENABLEHLITE: // Switch on highlighting
	  hlite = HLITE;
	  break;
	case DISABLEHLITE: // Turn off highlighting
	  hlite = NOHLITE;
	  break;
	default:
	  putch(*str, attr[hlite], page);
	  ++col;
	}
      if (col > getnumcols())
	{
	  ++row;
	  col=0;
	}
      if (row > getnumrows())
	{
	  scrollup();
	  row= getnumrows();
	}
      gotoxy(row,col,page);
      str++;
    }
}
Example #5
0
void cls(void)
{
    unsigned char dp = getdisppage();
    gotoxy(0, 0, dp);
    cprint(' ', GETSTRATTR, (1 + getnumrows()) * getnumcols(), dp);
}
Example #6
0
// Reads a line of input from stdin. Replace CR with NUL byte
// password <> 0 implies not echoed on screen
// showoldvalue <> 0 implies currentvalue displayed first
// If showoldvalue <> 0 then caller responsibility to ensure that
// str is NULL terminated.
void getuserinput(char *stra, unsigned int size, unsigned int password,
		  unsigned int showoldvalue)
{
    unsigned char c, scan;
    char *p, *q;		// p = current char of string, q = tmp
    char *last;			// The current last char of string
    char *str;			// pointer to string which is going to be allocated
    char page;
    char row, col;
    char start, end;		// Cursor shape
    char fudge;			// How many chars should be removed from output
    char insmode;		// Are we in insert or overwrite

    page = getdisppage();
    getpos(&row, &col, page);	// Get current position
    getcursorshape(&start, &end);
    insmode = 1;

    str = (char *)malloc(size + 1);	// Allocate memory to store user input
    memset(str, 0, size + 1);	// Zero it out
    if (password != 0)
	showoldvalue = 0;	// Password's never displayed

    if (showoldvalue != 0)
	strcpy(str, stra);	// If show old value copy current value

    last = str;
    while (*last) {
	last++;
    }				// Find the terminating null byte
    p = str + strlen(str);

    if (insmode == 0)
	setcursorshape(1, 7);	// Block cursor
    else
	setcursorshape(6, 7);	// Normal cursor

    // Invariants: p is the current char
    // col is the corresponding column on the screen
    if (password == 0)		// Not a password, print initial value
    {
	gotoxy(row, col, page);
	csprint(str, GETSTRATTR);
    }
    while (1) {			// Do forever
	c = inputc(&scan);
	if (c == '\r')
	    break;		// User hit Enter getout of loop
	if (scan == ESCAPE)	// User hit escape getout and nullify string
	{
	    *str = 0;
	    break;
	}
	fudge = 0;
	// if scan code is regognized do something
	// else if char code is recognized do something
	// else ignore
	switch (scan) {
	case HOMEKEY:
	    p = str;
	    break;
	case ENDKEY:
	    p = last;
	    break;
	case LTARROW:
	    if (p > str)
		p--;
	    break;
	case CTRLLT:
	    if (p == str)
		break;
	    if (*p == ' ')
		while ((p > str) && (*p == ' '))
		    p--;
	    else {
		if (*(p - 1) == ' ') {
		    p--;
		    while ((p > str) && (*p == ' '))
			p--;
		}
	    }
	    while ((p > str) && ((*p == ' ') || (*(p - 1) != ' ')))
		p--;
	    break;
	case RTARROW:
	    if (p < last)
		p++;
	    break;
	case CTRLRT:
	    if (*p == 0)
		break;		// At end of string
	    if (*p != ' ')
		while ((*p != 0) && (*p != ' '))
		    p++;
	    while ((*p != 0) && ((*p == ' ') && (*(p + 1) != ' ')))
		p++;
	    if (*p == ' ')
		p++;
	    break;
	case DELETE:
	    q = p;
	    while (*(q + 1)) {
		*q = *(q + 1);
		q++;
	    }
	    if (last > str)
		last--;
	    fudge = 1;
	    break;
	case INSERT:
	    insmode = 1 - insmode;	// Switch mode
	    if (insmode == 0)
		setcursorshape(1, 7);	// Block cursor
	    else
		setcursorshape(6, 7);	// Normal cursor
	    break;

	default:		// Unrecognized scan code, look at the ascii value
	    switch (c) {
	    case '\b':		// Move over by one
		q = p;
		while (q <= last) {
		    *(q - 1) = *q;
		    q++;
		}
		if (last > str)
		    last--;
		if (p > str)
		    p--;
		fudge = 1;
		break;
	    case '\x15':	/* Ctrl-U: kill input */
		fudge = last - str;
		while (p > str)
		    *p-- = 0;
		p = str;
		*p = 0;
		last = str;
		break;
	    default:		// Handle insert and overwrite mode
		if ((c >= ' ') && (c < 128) &&
		    ((unsigned int)(p - str) < size - 1)) {
		    if (insmode == 0) {	// Overwrite mode
			if (p == last)
			    last++;
			*last = 0;
			*p++ = c;
		    } else {	// Insert mode
			if (p == last) {	// last char
			    last++;
			    *last = 0;
			    *p++ = c;
			} else {	// Non-last char
			    q = last++;
			    while (q >= p) {
				*q = *(q - 1);
				q--;
			    }
			    *p++ = c;
			}
		    }
		} else
		    beep();
	    }
	    break;
	}
	// Now the string has been modified, print it
	if (password == 0) {
	    gotoxy(row, col, page);
	    csprint(str, GETSTRATTR);
	    if (fudge > 0)
		cprint(' ', GETSTRATTR, fudge, page);
	    gotoxy(row, col + (p - str), page);
	}
    }
    *p = '\0';
    if (password == 0)
	csprint("\r\n", GETSTRATTR);
    setcursorshape(start, end);	// Block cursor
    // If user hit ESCAPE so return without any changes
    if (scan != ESCAPE)
	strcpy(stra, str);
    free(str);
}