Exemplo n.º 1
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++;
    }
}
Exemplo n.º 2
0
void init_menusystem(const char *title)
{
  int i;
    
  ms = NULL;
  ms = (pt_menusystem) malloc(sizeof(t_menusystem));
  if (ms == NULL) return;
  ms->nummenus = 0;
  // Initialise all menu pointers
  for (i=0; i < MAXMENUS; i++) ms->menus[i] = NULL; 
    
  if (title == NULL)
    ms->title = TITLESTR; // Copy pointers
  else ms->title = title;

  // Timeout settings
  ms->tm_stepsize = TIMEOUTSTEPSIZE;
  ms->tm_numsteps = TIMEOUTNUMSTEPS;

  ms->normalattr[NOHLITE] = NORMALATTR; 
  ms->normalattr[HLITE] = NORMALHLITE;

  ms->reverseattr[NOHLITE] = REVERSEATTR;
  ms->reverseattr[HLITE] = REVERSEHLITE;

  ms->inactattr[NOHLITE] = INACTATTR;
  ms->inactattr[HLITE] = INACTHLITE;

  ms->revinactattr[NOHLITE] = REVINACTATTR;
  ms->revinactattr[HLITE] = REVINACTHLITE;

  ms->statusattr[NOHLITE] = STATUSATTR;
  ms->statusattr[HLITE] = STATUSHLITE;

  ms->statline = STATLINE;
  ms->tfillchar= TFILLCHAR;
  ms->titleattr= TITLEATTR;
    
  ms->fillchar = FILLCHAR;
  ms->fillattr = FILLATTR;
  ms->spacechar= SPACECHAR;
  ms->shadowattr = SHADOWATTR;

  ms->menupage = MENUPAGE; // Usually no need to change this at all
  ms->handler = NULL; // No handler function
  ms->ontimeout=NULL; // No timeout handler

  // Figure out the size of the screen we are in now.
  // By default we use the whole screen for our menu
  ms->minrow = ms->mincol = 0;
  ms->numcols = getnumcols();
  ms->numrows = getnumrows();
  ms->maxcol = ms->numcols - 1;
  ms->maxrow = ms->numrows - 1;
}
Exemplo n.º 3
0
void set_window_size(char top, char left, char bot, char right) // Set the window which menusystem should use
{
    
  char nr,nc;
  if ((top > bot) || (left > right)) return; // Sorry no change will happen here
  nr = getnumrows();
  nc = getnumcols();
  if (bot >= nr) bot = nr-1;
  if (right >= nc) right = nc-1;
  ms->minrow = top;
  ms->mincol = left;
  ms->maxrow = bot;
  ms->maxcol = right;
  ms->numcols = right - left + 1;
  ms->numrows = bot - top + 1;
  if (ms->statline >= ms->numrows) ms->statline = ms->numrows - 1; // Clip statline if need be
}
Exemplo n.º 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++;
    }
}
Exemplo n.º 5
0
// Print numlines of text starting from buf
void printtext(char*buf, int from)
{
  char *p,*f;
  char right,bot,nlines;

  // clear window to print
  right = getnumcols() - HELP_RIGHT_MARGIN;
  bot = getnumrows() - HELP_BOTTOM_MARGIN;
  nlines = bot-HELP_BODY_ROW+1;
  scrollupwindow(HELP_BODY_ROW,HELP_LEFT_MARGIN,bot,right,0x07,nlines);

  f  = findline(buf,from);
  if (!f) return; // nothing to print
  if (*f=='\n') f++; // start of from+1st line
  p = findline(f,nlines);
  if (p && (*p=='\n')) *p = '\0'; // change to NUL
  gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
  cswprint(f,0x07,HELP_LEFT_MARGIN);
  if (p) *p = '\n'; // set it back
}
Exemplo n.º 6
0
void showhelp(const char *filename)
{
   char nc,nr,ph;
   char *title,*text;
   union { char *buffer; void *vbuf; } buf; // This is to avoild type-punning issues

   char line[512];
   size_t size;
   char scan;
   int rv,numlines,curr_line;

   nc = getnumcols();
   nr = getnumrows();
   ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1;
   cls();
   drawbox(0,0,nr,nc-1,HELPPAGE,0x07,HELPBOX);

   drawhorizline(2,0,nc-1,HELPPAGE,0x07,HELPBOX,0); // dumb==0
   if (filename == NULL) { // print file contents
     gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
     cswprint("Filename not given",0x07,HELP_LEFT_MARGIN);
     while (1) {
       inputc(&scan);
       if (scan == ESCAPE) break;
     }
     cls();
     return;
   }

   rv = loadfile(filename,(void **)&buf.vbuf, &size); // load entire file into memory
   if (rv < 0) { // Error reading file or no such file
      sprintf(line, "Error reading file or file not found\n file=%s",filename);
      gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
      cswprint(line,0x07,HELP_LEFT_MARGIN);
      while (1) {
        inputc(&scan);
        if (scan == ESCAPE) break;
      }
      cls();
      return;
   }

   title = buf.buffer;
   text = findline(title,1); // end of first line
   *text++='\0'; // end the title string and increment text

   // Now we have a file just print it.
   gotoxy(1,(nc-strlen(title))/2,HELPPAGE);
   csprint(title,0x07);
   numlines = countlines(text);
   curr_line = 0;
   scan = ESCAPE+1; // anything except ESCAPE

   while(scan != ESCAPE) {
       printtext(text,curr_line);
       gotoxy(HELP_BODY_ROW-1,nc-HELP_RIGHT_MARGIN,HELPPAGE);
       if (curr_line > 0)
          putch(HELP_MORE_ABOVE,0x07,HELPPAGE);
       else putch(' ',0x07,HELPPAGE);
       gotoxy(nr-HELP_BOTTOM_MARGIN+1,nc-HELP_RIGHT_MARGIN,HELPPAGE);
       if (curr_line < numlines - ph)
          putch(HELP_MORE_BELOW,0x07,HELPPAGE);
       else putch(' ',0x07,HELPPAGE);

       inputc(&scan); // wait for user keypress

       switch(scan) {
         case HOMEKEY:
             curr_line = 0;
             break;
         case ENDKEY:
             curr_line = numlines;
             break;
         case UPARROW:
             curr_line--;
             break;
         case DNARROW:
             curr_line++;
             break;
         case PAGEUP:
             curr_line -= ph;
             break;
         case PAGEDN:
             curr_line += ph;
             break;
         default:
           break;
       }
       if (curr_line > numlines - ph) curr_line = numlines-ph;
       if (curr_line < 0) curr_line = 0;
   }
   cls();
   return;
}
Exemplo n.º 7
0
void cls(void)
{
    unsigned char dp = getdisppage();
    gotoxy(0, 0, dp);
    cprint(' ', GETSTRATTR, (1 + getnumrows()) * getnumcols(), dp);
}