home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / crssrc12 / widgetli.c < prev    next >
C/C++ Source or Header  |  1993-07-29  |  36KB  |  1,447 lines

  1. /*****************************************************************************
  2. /*  FILE:        widgetlib.c
  3. /*  DATE:        August 1988.
  4. /*  AUTHOR:        Richard A. Culshaw.
  5. /*  DESCRIPTION:    Contains the code to manipulate the widget structures
  6. /*            and the i/o. It forms a single library that should
  7. /*            be linked in with all code using these widgets.
  8. /* DISCLAIMER:        This file is deemed to be public-domain, on the simple
  9. /*            provisos that this section remains in this file and
  10. /*            that code using it do not do so for monetary gain.
  11. /*            Neither the author, nor the authors employees at the
  12. /*            time of developing this code, accept any liability or
  13. /*            responsibility for the use, abuse or misuse of this
  14. /*            code.
  15. /*****************************************************************************/
  16.  
  17. #include <widget.h>
  18. #ifdef __STDC__
  19. #include <stddef.h>
  20. #include <stdlib.h>
  21. #else
  22. typedef unsigned long size_t;
  23. #endif
  24. #include <string.h>
  25. #include <signal.h>
  26.  
  27.  
  28. __EXTERN void *malloc __PROTO((size_t));
  29.  
  30. int        textwindowdefined = FALSE;
  31. int            widx, widy;    
  32. int        maxwidy;
  33. int            scry;
  34. int            curid;
  35. int        sizescreg;
  36. int        screenborder = 0;
  37.  
  38. WINDOW    *screen;
  39. WINDOW    *screenbox;
  40. WINDOW    *edge1;
  41. WINDOW      *edge2;
  42.  
  43.  
  44. void initialisewidgets ()
  45. /* sets up screen and initialises global variables */
  46. {
  47.     int i;
  48.     __EXTERN void endwidgets __PROTO((void));
  49.  
  50.     widx = widy = scry = 0;
  51.     curid = 1;
  52.     maxwidy = LINES - 3;
  53.     initscr ();
  54.     crmode ();
  55.     noecho ();
  56.     cmdlist = NULLCMD;
  57.     lbllist = NULLLBL;
  58.     tgllist = NULLTGL;
  59.     inplist = NULLINP;
  60.     actlist = NULLCH;
  61.     for (i=0; i<NSIG; i++)
  62.     signal (i, endwidgets);
  63. }
  64.  
  65. void drawtextwindow (y)
  66. /* draws the text window and draws a box around it */
  67. int y;
  68. {
  69.     int i;
  70.  
  71.     if ((screenborder & VERTICAL) && (screenborder & HORIZONTAL)) {
  72.         box (screenbox, '|', '-');
  73.         mvwaddch (screenbox, 0, 0, '.');
  74.         mvwaddch (screenbox, 0, COLS-2, '.');
  75.         mvwaddch (screenbox, LINES-y-1, 0, '`');
  76.         mvwaddch (screenbox, LINES-y-1, COLS-2, '\'');
  77.         touchwin (screenbox);
  78.         wrefresh (screenbox);
  79.     }
  80.     else if (screenborder & HORIZONTAL) {
  81.     waddstr (edge1, "-------------------------------------------------------------------------------");
  82.         waddstr (edge2, "-------------------------------------------------------------------------------");
  83.     wrefresh (edge1);
  84.     wrefresh (edge2);
  85.     }
  86.     else if (screenborder & VERTICAL) {
  87.     for (i=0; i<=sizescreg; i++) {
  88.         mvwaddch (edge1, i, 0, '|');
  89.         mvwaddch (edge2, i, 0, '|');
  90.        }
  91.     wrefresh (edge1);
  92.     wrefresh (edge2);
  93.     }
  94.     touchwin (screen);
  95.     wrefresh (screen);
  96. }
  97.  
  98. int opentextwindow (position, border)
  99. /* define the text window from current position down + position * widget depth*/
  100. int    position;
  101. int    border;
  102. {
  103.     if ((position >= 0) && (!textwindowdefined) && (widy + 3*position < 21)) {
  104.         maxwidy = widy + position * 3 + 3;
  105.     if ((border & VERTICAL) && (border & HORIZONTAL)) {
  106.             screenbox = newwin (LINES-maxwidy, COLS-1, maxwidy, 0);
  107.         screen = newwin (LINES-2-maxwidy, COLS-3, maxwidy+1, 1);
  108.         sizescreg = LINES-2-maxwidy;
  109.         }
  110.     else if (border & HORIZONTAL) {
  111.         screen = newwin (LINES-2-maxwidy, COLS-1, maxwidy+1, 0);
  112.             edge1 = newwin (1, COLS-1, maxwidy, 0);
  113.             edge2 = newwin (1, COLS-1, LINES-1, 0);
  114.         sizescreg = LINES-2-maxwidy;
  115.         }
  116.     else if (border & VERTICAL) {
  117.         screen = newwin (LINES-maxwidy, COLS-3, maxwidy, 1);
  118.         edge1 = newwin (LINES-maxwidy, 1, maxwidy, 0);
  119.         edge2 = newwin (LINES-maxwidy, 1, maxwidy, COLS-2);
  120.         sizescreg = LINES-maxwidy;
  121.         }
  122.     else {
  123.         screen = newwin (LINES-maxwidy, COLS-1, maxwidy, 0);
  124.         sizescreg = LINES-maxwidy;
  125.         }
  126.         screenborder = border;
  127.         scrollok (screen, TRUE);
  128.     drawtextwindow (maxwidy);
  129.         wmove (screen, scry, 0);
  130.     wrefresh (screen);
  131.     textwindowdefined = 1;
  132.     return sizescreg;
  133.     }
  134. }
  135.  
  136. #ifdef __STDC__
  137. int addtochlist (int ch, int id, WIDGETTYPE type)
  138. #else
  139. int addtochlist (ch, id, type)
  140. /* add a new character to array of activation chars.
  141.  * returns TRUE if successful (char not already in list) else FALSE
  142.  */
  143. char           ch;
  144. int            id;
  145. WIDGETTYPE  type;    
  146. #endif
  147. {
  148.     struct chentry  *chlist;
  149.     struct chentry  *newentry;
  150.     /* search list to see char already entered in the list */    
  151.     chlist = actlist;
  152.     if (chlist != NULLCH) {
  153.     while (chlist -> next != NULLCH) 
  154.        if (chlist -> ch == ch)
  155.         return FALSE;           /* char exists => error */
  156.         else
  157.         chlist = chlist -> next;
  158.         newentry = (struct chentry*)malloc((size_t)sizeof(struct chentry));
  159.     chlist -> next = newentry;
  160.     }
  161.     else {
  162.         newentry = (struct chentry*)malloc((size_t)sizeof(struct chentry));
  163.     actlist = newentry;
  164.     }
  165.     /* char not there so add to list */
  166.     newentry -> ch = ch;
  167.     newentry -> id = id;
  168.     newentry -> type = type;
  169.     newentry -> next = NULLCH;
  170.     return TRUE;
  171. }
  172.  
  173.  
  174. #ifdef __STDC__
  175. WIDGETTYPE widgettype (WIDGET ptr)
  176. #else
  177. WIDGETTYPE widgettype (ptr)
  178. /* given a widget pointer returns the type of widget.
  179.  */
  180. WIDGET    ptr;
  181. #endif
  182. {
  183.     struct cmdwid    *clist;
  184.     struct tglwid    *tlist;
  185.     struct lblwid    *llist;
  186.     struct inpwid    *ilist;
  187.  
  188.     /* is it a command widget ? */
  189.     for (clist = cmdlist; clist != NULLCMD; clist = clist -> next)       
  190.         if ((clist != NULLCMD) && (clist -> id == ptr))
  191.             return CMD;
  192.  
  193.     /* is it a toggle widget ? */
  194.     for (tlist = tgllist; tlist != NULLTGL; tlist = tlist -> next)       
  195.         if ((tlist != NULLTGL) && (tlist -> id == ptr))
  196.             return TGL;
  197.  
  198.     /* is it a label widget ? */
  199.     for (llist = lbllist; llist != NULLLBL; llist = llist -> next)       
  200.         if ((llist != NULLLBL) && (llist -> id == ptr))
  201.             return LBL;
  202.  
  203.     /* is in an input widget ? */
  204.     for (ilist = inplist; ilist != NULLINP; ilist = ilist -> next)       
  205.         if ((ilist != NULLINP) && (ilist -> id == ptr))
  206.             return INP;
  207.  
  208.     /* doesn't exist, return error */
  209.     return FALSE;             
  210. }
  211.  
  212. void boxwidget (widget, length)
  213. WINDOW    *widget;
  214. int    length;
  215. {
  216.     int i;
  217.  
  218.     wmove (widget, 0, 1);
  219.     for (i=1; i < length; i++)
  220.            waddch (widget, '-');
  221.     wmove (widget, 2, 1);
  222.     for (i=1; i < length; i++)
  223.            waddch (widget, '-');
  224.     mvwaddch (widget, 1, 0, '|');
  225.     mvwaddch (widget, 1, length, '|');
  226.     mvwaddch (widget, 0, 0, '.');
  227.     mvwaddch (widget, 0, length, '.');
  228.     mvwaddch (widget, 2, 0, '`');
  229.     mvwaddch (widget, 2, length, '\'');
  230. }
  231.  
  232. void drawcmdwidget (widget, info, ch, length, boolean)
  233. WINDOW    *widget;
  234. char    info[];
  235. int    ch;
  236. int    length;
  237. int    boolean;
  238. {
  239.     boxwidget (widget, length-1);
  240.     wmove (widget, 1, 1);
  241.     wstandout (widget);
  242.     waddch (widget, ch);
  243.     if (!boolean)
  244.         wstandend (widget);
  245.     wprintw (widget, ":%s", info);
  246.     if (boolean)
  247.         wstandend (widget);
  248.     wrefresh (widget);
  249. }
  250.  
  251. void drawlblwidget (widget, info, pos, difference, space, boolean)
  252. WINDOW    *widget;
  253. char    info[];
  254. int    pos;
  255. int    difference;
  256. int    space;
  257. int    boolean;
  258. {
  259.     boxwidget (widget, space+1);
  260.  
  261.     /* work out justification */
  262.     if ((pos & LEFTJUST) || (difference == 0))
  263.     wmove (widget, 1, 1);
  264.     else if (pos & RIGHTJUST)
  265.     wmove (widget, 1, 1+difference);
  266.     else if (pos & CENTRE)
  267.     wmove (widget, 1, difference / 2 + 1);
  268.     if (boolean)
  269.         wstandout (widget);
  270.     wprintw (widget, "%s", info);
  271.     if (boolean)
  272.         wstandend (widget);
  273.     wrefresh (widget);
  274. }
  275.   
  276.  
  277. void drawtglwidget (widget, info, tgl, toggle, length, boolean)
  278. WINDOW    *widget;
  279. char    info[];
  280. char    tgl[];
  281. int    toggle;
  282. int    length;
  283. int    boolean;
  284. {
  285.     boxwidget (widget, length-1);
  286.     wmove (widget, 1, 1);
  287.     wstandout (widget);
  288.     wprintw (widget, "%c", toggle);
  289.     if (!boolean)
  290.         wstandend (widget);
  291.     wprintw (widget, ":%s:", info);
  292.     if (!boolean)
  293.         wstandout (widget);
  294.     wprintw (widget, "%s", tgl);
  295.     wstandend (widget);
  296.     wrefresh (widget);
  297. }
  298.  
  299. void drawinpwidget (widget, info, ch, length, boolean, exec)
  300. WINDOW    *widget;
  301. char    info[];
  302. int    ch;
  303. int    length;
  304. int    boolean;
  305. {
  306.     boxwidget (widget, length-1);
  307.     wmove (widget, 1, 1);
  308.     if (boolean)
  309.         wstandout (widget);
  310.     if (exec)
  311.      wprintw (widget, "%s", info);
  312.     else
  313.         wprintw (widget, "%c:%s", ch, info);
  314.     if (boolean)
  315.         wstandend (widget);
  316.     waddch (widget, '>');
  317.     wrefresh (widget);
  318. }
  319.  
  320. void screenrefresh ()
  321. /* clear the screen and redraw all the widgets and the text screen if present */
  322. {
  323.     struct cmdwid *clist;
  324.     struct lblwid *llist;
  325.     struct tglwid *tlist;
  326.     struct inpwid *ilist;
  327.  
  328.     /* clear the entire screen */
  329.     clear();
  330.     refresh();
  331.  
  332.     /* redraw all the command widgets */
  333.     clist = cmdlist;
  334.     while (clist != NULLCMD) {
  335.     touchwin (clist -> widget);
  336.     wrefresh (clist -> widget);
  337.     clist = clist -> next;
  338.     }
  339.  
  340.     /* redraw all the label widgets */
  341.     llist = lbllist;
  342.     while (llist != NULLLBL) {
  343.     touchwin (llist -> widget);
  344.     wrefresh (llist -> widget);
  345.     llist = llist -> next;
  346.     }
  347.  
  348.     /* redraw all the toggle widgets */
  349.     tlist = tgllist;
  350.     while (tlist != NULLTGL) {
  351.     touchwin (tlist -> widget);
  352.     wrefresh (tlist -> widget);
  353.     tlist = tlist -> next;
  354.     }
  355.  
  356.     /* redraw all the input widgets */
  357.     ilist = inplist;
  358.     while (ilist != NULLINP) {
  359.     touchwin (ilist -> widget);
  360.     wrefresh (ilist -> widget);
  361.     ilist = ilist -> next;
  362.     }
  363.  
  364.     /* redraw text window if present */
  365.     if (textwindowdefined) {
  366.     touchwin (screen);
  367.     touchwin (screenbox);
  368.         wrefresh (screenbox);
  369.         wrefresh (screen);
  370.     }
  371. }
  372.  
  373. WIDGET widgetinput ()
  374. /* scan standard input for chars and act on them */
  375. {
  376.     struct cmdwid *list;    
  377.     struct chentry *chlist;
  378.     char      ch;
  379.     int          i;
  380.     int          j;
  381.  
  382.     for (;;)
  383.     {
  384.         ch = getchar ();
  385.  
  386.     if (ch == '\014') {
  387.         screenrefresh ();
  388.         continue;
  389.     }
  390.     
  391.     chlist = actlist;
  392.     while ((chlist != NULLCH) && (chlist -> ch != ch))
  393.         chlist = chlist -> next; 
  394.     
  395.     if (chlist == NULLCH)
  396.         continue;
  397.  
  398.         if (chlist -> type == 1) {  /* does char activate a command widget ? */
  399.             for (list = cmdlist; list != NULLCMD; list = list->next)
  400.             if (list -> id == chlist -> id)
  401.             if (list -> active)
  402.                       return (*(list -> func))();
  403.         }
  404.         else if (chlist -> type == 2) /* does char activate a toggle widget ?*/
  405.             togglewidget (chlist -> id);
  406.         else 
  407.             return (getinput (chlist -> id)); /* must activate input widget */    
  408.     }
  409. }
  410.  
  411.     
  412. #ifdef __STDC__
  413. void togglewidget (WIDGET id)
  414. #else
  415. void togglewidget (id)
  416. /* toggle widget given its id */
  417. WIDGET id;
  418. #endif
  419. {
  420.     struct tglwid *list;
  421.     int       i=0;
  422.     int       x,y;
  423.     int       pos;
  424.  
  425.  
  426.     list = tgllist;    
  427.     /* find toggle widget with given id */
  428.     while (list -> id != id)
  429.         list = list -> next;
  430.  
  431.     if (!list -> active)
  432.     return;
  433.  
  434.     /* increase its toggle value */
  435.     pos = ++(list -> cur);
  436.     if (pos == list -> total)   /* do we need to wrap round values */
  437.     {    pos = 0;
  438.         list -> cur = 0;
  439.     }
  440.  
  441.     /* output new toggle value */
  442.     wstandout (list -> widget);
  443.     mvwaddstr (list -> widget, 1, list -> xtgl, list -> tgl[pos]);
  444.     wstandend (list -> widget);
  445.     getyx (list -> widget, y, x);
  446.     for (; x < list -> length-1; x++)
  447.         waddch (list -> widget, ' ');
  448.     wrefresh (list -> widget);
  449.     if (textwindowdefined)
  450.         wrefresh (screen);
  451. }
  452.  
  453.  
  454. #ifdef __STDC__
  455. int getinput (WIDGET id)
  456. #else
  457. int getinput (id)
  458. /* get input from an input widget and put value into given place */
  459. WIDGET id;
  460. #endif
  461. {
  462.     struct inpwid *list;    
  463.     int       i = 0;
  464.     int         j;
  465.     int         cursor = 0;
  466.     int         index = 0;
  467.     WINDOW      *widgy;
  468.     int      max;
  469.     char     ch = '\0';
  470.     int         flag = 0;
  471.     int         sofi;
  472.  
  473.     highlight (id);
  474.     list = inplist;
  475.     /* find the input widget with the given id */
  476.     while (list -> id != id)
  477.         list = list -> next;
  478.  
  479.     if (!list -> active)
  480.     /* return; */
  481.     return (int)NULLWIDGET;        /* is this correct? ++jrb */
  482.  
  483.     widgy = list -> widget;
  484.     sofi = list -> sofi;
  485.     max = list -> length - sofi - 1;
  486.     wmove (widgy, 1, sofi);
  487.     wrefresh (widgy);
  488.  
  489.     /* repeatidly get chars from stdin until carriage return is pressed */
  490.     while ((ch = getchar()) != '\n') {
  491.         if ((ch > 31) || (ch == '\025') || (ch == '\014'))
  492.         {
  493.         switch (ch) {
  494.     
  495.     /* delete ? */
  496.         case '\177' : if ((!flag) && (cursor > 0)){ /* chars don't spill over */
  497.                    cursor -= 1;
  498.                    mvwaddch (widgy, 1, cursor + sofi, ' ');
  499.                    wmove (widgy, 1, cursor + sofi);
  500.                    index -= 1;
  501.                    wrefresh (widgy);
  502.                    break;
  503.                   }
  504.                   else if (cursor > 0){  /* chars spill over */
  505.                       index -= 1;
  506.                   if (index == max-1) {
  507.                       flag = 0;
  508.                       mvwaddch (widgy, 1, sofi-1, '>');
  509.                   }
  510.                   for (j=0; j < max-1; j++)
  511.                       mvwaddch (widgy, 1, j+sofi, list -> input [index-max+j+1]);
  512.                       wmove (widgy, 1, cursor + sofi);
  513.                       wrefresh (widgy);
  514.                       break;
  515.                   }
  516.  
  517.                   else        /* nothing to delete ! */    
  518.                   break;
  519.  
  520.     /* ^U pressed (delete all) */
  521.         case '\025' : index = cursor = 0;
  522.                   wmove (widgy, 1, sofi);
  523.                   for (j=0; j < max; j++)
  524.                   waddch (widgy, ' ');
  525.                   mvwaddch (widgy, 1, sofi-1, '>');
  526.                   wrefresh (widgy);
  527.                   break;
  528.  
  529.     /* ^L pressed (screen refresh) */
  530.     case '\014' : screenrefresh ();
  531.                   wmove (widgy,1,cursor+sofi);
  532.               wrefresh (widgy);
  533.               break;
  534.  
  535.     /* default = all other chars except remaining control chars */
  536.         default :    if (index < list -> lofs) {  /* space still remaining ? */
  537.                  list -> input [index++] = ch;
  538.                        if (cursor == (max-1)) { /* about to spill over ? */
  539.                     mvwaddch (widgy, 1, sofi-1, '<');
  540.                     for (j=0; j < max-2; j++)
  541.                     mvwaddch (widgy, 1, j+sofi, list ->input [index-max+j+1]);
  542.                     mvwaddch (widgy, 1, cursor+sofi-1, ch);
  543.                     flag = 1;
  544.                     }            
  545.                     else    /* not spilt over */
  546.                       mvwaddch (widgy, 1, (cursor++) +sofi, ch);
  547.                     wrefresh (widgy);
  548.                     break;
  549.                       }
  550.                  else         /* no room left ! */
  551.                  break;
  552.                  }
  553.         }
  554.         }        
  555.     /* terminate input */
  556.     list -> input [index] = '\0';
  557.  
  558.     /* clean up input line */
  559.     wmove (widgy, 1, sofi);
  560.     for (j=0; j < max; j++)
  561.         waddch (widgy, ' ');
  562.     mvwaddch (widgy, 1, sofi-1, '>');
  563.     wrefresh (widgy);
  564.     if (textwindowdefined)
  565.         wrefresh (screen);
  566.     dehighlight (id);
  567.     return id;
  568. }
  569.  
  570. WIDGET mkcmdwidget (info, acpt, func, line)
  571. /* make a new command widget */
  572. char   info[];
  573. int    acpt;
  574. int    (*func)();
  575. int    line;
  576. {
  577.     struct cmdwid     *list;
  578.     struct cmdwid     *temp;
  579.     int         length = 0;
  580.  
  581.     while (info [length++] != '\0')   /* work out length of command */
  582.         ;    
  583.     length += 3;
  584.     if ((line == 1) || ((length + widx) > COLS-1) || widx == COLS-1)
  585.         if (widy + 3 == maxwidy) /* go onto next line */
  586.             return NULLWIDGET;
  587.     else {
  588.             widy += 3;
  589.             widx = 0;          
  590.     }
  591.     if (!addtochlist (acpt, curid, 1))  /* activation char in use ? */
  592.         return NULLWIDGET;
  593.     
  594.     /* find end of list and allocate memory for new entry */
  595.     temp = cmdlist; 
  596.     if (temp != NULLCMD) {
  597.         while (temp -> next != NULLCMD)
  598.             temp = temp -> next;
  599.         list = (struct cmdwid *)malloc((size_t)sizeof(struct cmdwid));
  600.         temp -> next = list;
  601.     }
  602.     else {
  603.         list = (struct cmdwid *)malloc((size_t)sizeof(struct cmdwid));
  604.         cmdlist = list;
  605.     }
  606.  
  607.     /* create and display new widget */
  608.     list -> widget = newwin (3, length, widy, widx);
  609.  
  610.     drawcmdwidget (list -> widget, info, acpt, length, FALSE);
  611.  
  612.     /* assign information to be withheld */
  613.     list -> x = widx;
  614.     list -> y = widy;
  615.     list -> id = curid;
  616.     strcpy (list -> msg ,info);
  617.     list -> func = func;
  618.     list -> acpt = acpt;
  619.     list -> length = length;
  620.     list -> next = NULLCMD;
  621.     list -> active = TRUE;
  622.     curid += 1;
  623.     widx += length;
  624.     if (textwindowdefined)
  625.         wrefresh (screen);
  626.     return (curid-1);
  627. }
  628.  
  629. WIDGET mklblwidget (info, pos, space, line)
  630. /* make a new label widget */
  631. char    info[];
  632. int     pos;
  633. int     space;
  634. int     line;
  635. {
  636.     struct lblwid    *list;
  637.     struct lblwid    *temp;
  638.     int         length = 0;
  639.     int         difference;
  640.  
  641.     if (!((pos & CENTRE) || (pos & LEFTJUST) || (pos & RIGHTJUST)))
  642.     pos = pos|LEFTJUST;
  643.  
  644.     /* calculate length of label widget */
  645.     while (info [length++] != '\0')    
  646.         ;    
  647.     length -= 1;
  648.     if ((space < length) && (space > 0))    /* not given enough room so error */
  649.         return NULLWIDGET; 
  650.     
  651.     if (space <= 0)
  652.         if ((line == 1) || (widx == COLS-1))
  653.         space += COLS - 3;
  654.     else
  655.         space += COLS - 3 - widx;
  656.  
  657.     difference = space - length;
  658.  
  659.     if ((line == 1) || ((space + 2 + widx) > COLS-1) || (widx == COLS-1))
  660.     /* not enough room on existing line so go onto next */
  661.         if (widy + 3 == maxwidy)
  662.             return NULLWIDGET;
  663.     else {
  664.         widx = 0;
  665.         widy += 3;
  666.      }
  667.  
  668.     /* find end of list and alllocate memory for new entry */
  669.     temp = lbllist;
  670.     if (temp != NULLLBL) {
  671.         while (temp -> next != NULLLBL)
  672.             temp = temp -> next;
  673.         list = (struct lblwid *)malloc((size_t)sizeof(struct lblwid));
  674.         temp -> next = list;
  675.     }
  676.     else {
  677.         list = (struct lblwid *)malloc((size_t)sizeof(struct lblwid));
  678.         lbllist = list;
  679.     }
  680.  
  681.     /* create new and display new widget */
  682.     list -> widget = newwin (3, space+2, widy, widx);
  683.  
  684.     drawlblwidget (list -> widget, info, pos, difference, space, !(pos & NOHIGH));
  685.  
  686.     /* assign information to be withheld */
  687.     list -> x = widx;
  688.     list -> y = widy;
  689.     list -> id = curid;
  690.     strcpy (list -> msg ,info);
  691.     list -> pos = pos;
  692.     list -> length = space+2;
  693.     list -> difference = difference;
  694.     list -> next = NULLLBL;
  695.     curid += 1;
  696.     widx += space+2;
  697.     if (textwindowdefined)
  698.         wrefresh (screen);
  699.     return (curid - 1);
  700. }
  701.  
  702. WIDGET mktglwidget (info, num, tgl, toggle, line)
  703. /* make a new toggle widget */
  704. char  info[];
  705. int   num;    
  706. char  *tgl[10];
  707. int   toggle;
  708. int   line;
  709. {
  710.     int         length = 0;
  711.     struct tglwid    *list;
  712.     struct tglwid    *temp;
  713.     int         xtgl;
  714.     int         max = 0;
  715.     int         i, j, x;
  716.     
  717.     /* calculate maximum length of toggle */
  718.     for (i=0; i < num; i++)  
  719.         {
  720.         for (j=0, x=0; tgl[i][j] != '\0'; j++)
  721.                x++;
  722.         if ((x-1)>max)
  723.             max = x-1;
  724.         }
  725.     
  726.     while (info [length++] != '\0') 
  727.         ;    
  728.     xtgl = length + 3;
  729.     length = length + max + 5;
  730.  
  731.     if ((line == 1) || ((length + widx) > COLS-1) || (widx == COLS-1))
  732.         /* not enough room on existing line so go onto next */
  733.         if (widy + 3 == maxwidy)
  734.             return NULLWIDGET;
  735.     else {
  736.         widx = 0;
  737.         widy += 3;
  738.     }
  739.  
  740.     /* add char to activation list if not already in use */
  741.     if (!addtochlist (toggle, curid, 2)) 
  742.         return NULLWIDGET;
  743.  
  744.     /* find end of list and allocate memory for new entry */
  745.     temp = tgllist;
  746.     if (temp != NULLTGL) {
  747.         while (temp -> next != NULLTGL)
  748.             temp = temp -> next;
  749.         list = (struct tglwid *)malloc((size_t)sizeof(struct tglwid));
  750.         temp -> next = list;
  751.     }
  752.     else {
  753.         list = (struct tglwid *)malloc((size_t)sizeof(struct tglwid));
  754.         tgllist = list;
  755.     }
  756.  
  757.     /* create and display new widget */
  758.     list -> widget = newwin (3, length, widy, widx);
  759.  
  760.     drawtglwidget (list -> widget, info, tgl[0], toggle, length, FALSE);
  761.  
  762.     /* assign information to be withheld */
  763.     list -> x = widx;
  764.     list -> y = widy;
  765.     list -> id = curid;
  766.     strcpy (list -> msg ,info);
  767.     list -> xtgl = xtgl;
  768.     list -> total = num;
  769.     for (i=0; i<num; i++) 
  770.     strcpy (list -> tgl[i], tgl[i]);
  771.     list -> cur = 0;
  772.     list -> toggle = toggle;
  773.     list -> length = length;
  774.     list -> next = NULLTGL;
  775.     list -> active = TRUE;
  776.     curid += 1;
  777.     widx += length;
  778.     if (textwindowdefined)
  779.         wrefresh (screen);
  780.     return (curid-1);
  781. }
  782.  
  783. WIDGET mkinpwidget (info, acpt, input, lofs, length, line, exec)
  784. /* make a new input widget */
  785. char    info[];
  786. int     acpt;
  787. char    input[];
  788. int     lofs;
  789. int     length;
  790. int     line;
  791. int    exec;
  792. {
  793.     struct inpwid    *list;
  794.     struct inpwid    *temp;
  795.     int            count = 0;
  796.     int            offset;
  797.  
  798.     if (exec)
  799.           offset = 3;
  800.     else
  801.     offset = 5;
  802.  
  803.     while (info [count++] != '\0')
  804.     ;
  805.  
  806.     if (length <= 0)
  807.     if ((line == 1) || (widx == COLS-1))
  808.         length += COLS-offset-count;
  809.     else
  810.         length += COLS-offset-widx-count;
  811.     length += offset-1+count;
  812.     if ((line == 1) || ((length + widx) > COLS-1) || (widx == COLS -1))
  813.         /* if no room on existing line go onto next */
  814.         if (widy + 3 == maxwidy)
  815.             return NULLWIDGET;
  816.     else {
  817.         widx = 0;
  818.         widy += 3;
  819.     }
  820.  
  821.     /* add activation char to list if not already in use */
  822.     if (!addtochlist (acpt, curid, 3)) 
  823.         return NULLWIDGET;
  824.  
  825.     /* find end of list and allocate memory for new entry */
  826.     temp = inplist;
  827.     if (temp != NULLINP) {
  828.         while (temp -> next != NULLINP)
  829.             temp = temp -> next;
  830.         list = (struct inpwid *)malloc((size_t)sizeof(struct inpwid));
  831.         temp -> next = list;
  832.     }
  833.     else {
  834.         list = (struct inpwid *)malloc((size_t)sizeof(struct inpwid));
  835.         inplist = list;
  836.     }
  837.  
  838.     /* create and display new widget */
  839.     list -> widget = newwin (3, length, widy, widx);
  840.  
  841.     drawinpwidget (list -> widget, info, acpt, length, FALSE, exec);
  842.  
  843.     /* assign information to be withheld */
  844.     list -> x = widx;
  845.     list -> y = widy;
  846.     list -> id = curid;
  847.     strcpy (list -> msg ,info);
  848.     list -> acpt = acpt;
  849.     list -> input = input;
  850.     list -> lofs = lofs;
  851.  
  852.     if (exec)
  853.     list -> sofi = count+1;
  854.     else
  855.         list -> sofi = count+3;
  856.  
  857.     list -> length = length;
  858.     list -> next = NULLINP;
  859.     list -> exec = exec;
  860.     list -> active = TRUE;
  861.     curid += 1;
  862.     widx += length;
  863.     if (textwindowdefined)
  864.         wrefresh (screen);
  865.     if (exec)
  866.     getinput (curid-1);
  867.     return (curid-1);
  868. }
  869.  
  870. void cleartextwindow ()
  871. {
  872.     werase (screen);
  873.     wrefresh (screen);
  874.     scry = 0;
  875. }
  876.  
  877. void report (info)
  878. /* place given info into data screen */
  879. char    *info;
  880. {
  881.     int i, count = 0;
  882.  
  883.     if (textwindowdefined) {
  884.         if (scry == sizescreg)    /* scroll window if reached bottom */
  885.         {
  886.             scroll (screen);
  887.             scry -= 1;
  888.         }
  889.     for (i=0; info[i] != '\0'; i++)
  890.         if (info[i] == '\n')
  891.         count += 1;
  892.  
  893.         mvwaddstr (screen, scry, 0, info);
  894.         scry += 1+count;
  895.         wrefresh (screen);
  896.     }
  897. }
  898.  
  899. #ifdef __STDC__
  900. int tsttglwidget (WIDGET ptr)
  901. #else
  902. int tsttglwidget (ptr)
  903. /* return the index value of the current state of the given toggle widget */
  904. WIDGET ptr;
  905. #endif
  906. {
  907.     struct tglwid *list;
  908.     int          i=0;
  909.  
  910.     /* locate the record of the given toggle widget pointer */
  911.     list = tgllist;
  912.     while ((list != NULLTGL) && (list -> id != ptr)) 
  913.         list = list -> next;
  914.  
  915.     /* if it exists return index value else return error FALSE */
  916.     if (list -> id == ptr)
  917.         return list -> cur;
  918.     else
  919.         return FALSE;
  920. }
  921.  
  922. void deletechentry (ch)
  923. /* remove the entry from character list for killed widget */
  924. int ch;
  925. {
  926.     struct chentry    *chlist;
  927.     struct chentry    *previous;
  928.    
  929.     chlist = actlist;
  930.     if (chlist -> ch == ch) {        /* is required entry at head of list ? */
  931.     actlist = chlist -> next;    
  932.     free ((char*)chlist);        /* deallocate memory for deleted entry */
  933.     }
  934.     else {
  935.     while (chlist -> ch != ch) {  /* locate required entry in the list */
  936.         previous = chlist;
  937.         chlist = chlist -> next;
  938.     }
  939.     previous -> next = chlist -> next;  /* remove entry by skiping it */
  940.     free ((char*)chlist);        /* deallocate memory for deleted entry */
  941.     }
  942. }
  943.  
  944. #ifdef __STDC__
  945. void killcmdwidget (WIDGET ptr)
  946. #else
  947. void killcmdwidget (ptr)
  948. /* kill a command widget given a valid pointer */
  949. WIDGET ptr;
  950. #endif
  951. {
  952.     struct cmdwid    *clist;
  953.     struct cmdwid    *previous;
  954.  
  955.     clist = cmdlist;
  956.     if (clist -> id == ptr) {         /* required widget at head of list ? */
  957.     cmdlist = clist -> next;
  958.     werase (clist -> widget);
  959.     wrefresh (clist -> widget);
  960.     delwin (clist -> widget);
  961.     deletechentry (clist -> acpt);
  962.     if ((clist -> x + clist -> length) == widx)   /* if last widget added */
  963.         widx -= clist -> length;              /* pull back widx       */
  964.     free ((char*)clist);
  965.     }
  966.     else {
  967.     while (clist -> id != ptr) {    /* find widget in list */
  968.        previous = clist;
  969.        clist = clist -> next;
  970.     }
  971.     previous -> next = clist -> next;   /* skip unrequired widget in list */
  972.     werase (clist -> widget);
  973.     wrefresh (clist -> widget);
  974.     delwin (clist -> widget);
  975.     deletechentry (clist -> acpt);
  976.     if ((clist -> x + clist -> length) == widx)   /* if last widget added */
  977.         widx -= clist -> length;              /* pull back widx       */
  978.     free ((char*)clist);
  979.     }
  980. }
  981.  
  982. #ifdef __STDC__
  983. void killlblwidget (WIDGET ptr)
  984. #else
  985. void killlblwidget (ptr)
  986. /* kill label widget given a valid pointer */
  987. WIDGET ptr;
  988. #endif
  989. {
  990.     struct lblwid    *clist;
  991.     struct lblwid    *previous;
  992.  
  993.     clist = lbllist;
  994.     if (clist -> id == ptr) {         /* is widget at head of list ? */
  995.     lbllist = clist -> next;
  996.     werase (clist -> widget);
  997.     wrefresh (clist -> widget);
  998.     delwin (clist -> widget);
  999.     if ((clist -> x + clist -> length) == widx)  /* pull back widx if */
  1000.         widx -= clist -> length;             /* last widget added */
  1001.     free ((char*)clist);
  1002.     }
  1003.     else {
  1004.     while (clist -> id != ptr) {    /* find widget in linked list */
  1005.        previous = clist;
  1006.        clist = clist -> next;
  1007.     }
  1008.     previous -> next = clist -> next;   /* skip widget in list */
  1009.     werase (clist -> widget);
  1010.     wrefresh (clist -> widget);
  1011.     delwin (clist -> widget);
  1012.     if ((clist -> x + clist -> length) == widx)  /* pull back widx if */
  1013.         widx -= clist -> length;             /* last widget added */
  1014.     free ((char*)clist);
  1015.     }
  1016. }
  1017.  
  1018. #ifdef __STDC__
  1019. void killtglwidget (WIDGET ptr)
  1020. #else
  1021. void killtglwidget (ptr)
  1022. /* kill toggle widget given a valid pointer */
  1023. WIDGET ptr;
  1024. #endif
  1025. {
  1026.     struct tglwid    *clist;
  1027.     struct tglwid    *previous;
  1028.  
  1029.     clist = tgllist;
  1030.     if (clist -> id == ptr) {       /* is widget at head of list ? */
  1031.     tgllist = clist -> next;
  1032.     werase (clist -> widget);
  1033.     wrefresh (clist -> widget);
  1034.     delwin (clist -> widget);
  1035.     deletechentry (clist -> toggle);
  1036.     if ((clist -> x + clist -> length) == widx)  /* pull back widx if */
  1037.         widx -= clist -> length;             /* last widget added */
  1038.     free ((char*)clist);
  1039.     }
  1040.     else {
  1041.     while (clist -> id != ptr) {    /* find widget in linked list */
  1042.        previous = clist;
  1043.        clist = clist -> next;
  1044.     }
  1045.     previous -> next = clist -> next;   /* skip widget in list */
  1046.     werase (clist -> widget);
  1047.     wrefresh (clist -> widget);
  1048.     delwin (clist -> widget);
  1049.     deletechentry (clist -> toggle);
  1050.     if ((clist -> x + clist -> length) == widx)   /* pull back widx if */
  1051.         widx -= clist -> length;              /* last widget added */
  1052.     free ((char*)clist);
  1053.     }
  1054. }
  1055.  
  1056. #ifdef __STDC__
  1057. void killinpwidget (WIDGET ptr)
  1058. #else
  1059. void killinpwidget (ptr)
  1060. /* kill an input widget given a valid pointer */
  1061. WIDGET ptr;
  1062. #endif
  1063. {
  1064.     struct inpwid    *clist;
  1065.     struct inpwid    *previous;
  1066.  
  1067.     clist = inplist;
  1068.     if (clist -> id == ptr) {        /* is widget at head of list ? */
  1069.     inplist = clist -> next;
  1070.     werase (clist -> widget);
  1071.     wrefresh (clist -> widget);
  1072.     delwin (clist -> widget);
  1073.     deletechentry (clist -> acpt);
  1074.     if ((clist -> x + clist -> length) == widx)   /* pull back widx if */
  1075.         widx -= clist -> length;              /* last widget added */
  1076.     free ((char*)clist);
  1077.     }
  1078.     else {
  1079.     while (clist -> id != ptr) {   /* locate widget in linked list */
  1080.        previous = clist;
  1081.        clist = clist -> next;
  1082.     }
  1083.     previous -> next = clist -> next;   /* skip entry in linked list */
  1084.     werase (clist -> widget);
  1085.     wrefresh (clist -> widget);
  1086.     delwin (clist -> widget);
  1087.     deletechentry (clist -> acpt);
  1088.     if ((clist -> x + clist -> length) == widx)   /* pull back widx if */
  1089.         widx -= clist -> length;              /* last widget added */
  1090.     free ((char*)clist);
  1091.     }
  1092. }
  1093.     
  1094. #ifdef __STDC__
  1095. int killwidget (WIDGET ptr)
  1096. #else
  1097. int killwidget (ptr)
  1098. /* kills the widget identified by ptr */
  1099. WIDGET ptr;
  1100. #endif
  1101. {
  1102.     switch (widgettype (ptr)) {
  1103.         case CMD : killcmdwidget (ptr);    /* command widget */
  1104.          home ();
  1105.          return TRUE;
  1106.     case TGL : killtglwidget (ptr);    /* toggle widget */
  1107.          home ();
  1108.          return TRUE;
  1109.     case LBL : killlblwidget (ptr);    /* label widget */
  1110.          home ();
  1111.          return TRUE;
  1112.     case INP : killinpwidget (ptr);    /* input widget */
  1113.          home ();
  1114.          return TRUE;
  1115.     case FALSE : return FALSE;           /* doesn't exist */
  1116.     }
  1117. }
  1118.  
  1119. #ifdef __STDC__
  1120. int chactive (WIDGET ptr, int boolean, int blank)
  1121. #else
  1122. int chactive (ptr, boolean, blank)
  1123. /* given a widget ptr and a boolean value will activate/deactivate a widget */
  1124. WIDGET ptr;
  1125. int boolean;
  1126. int blank;
  1127. #endif
  1128. {
  1129.     struct cmdwid *clist;
  1130.     struct tglwid *tlist;
  1131.     struct inpwid *ilist;
  1132.     int          i;
  1133.  
  1134.     switch (widgettype (ptr)) {
  1135.     case CMD: for (clist = cmdlist; clist != NULLCMD; clist = clist -> next)
  1136.           if ((clist != NULLCMD) && (clist -> id == ptr)) {
  1137.             if ((!boolean) && (blank)) {
  1138.                 wmove (clist->widget, 1, 1);
  1139.                 for (i=0; i < clist->length-2; i++)
  1140.                 waddch (clist->widget, ' ');
  1141.                 wrefresh (clist->widget);
  1142.             }
  1143.               if (textwindowdefined)
  1144.                     wrefresh (screen);
  1145.             return(clist -> active = boolean);
  1146.           }
  1147.           break;
  1148.     case TGL: for (tlist = tgllist; tlist != NULLTGL; tlist = tlist -> next)
  1149.           if ((tlist != NULLTGL) && (tlist -> id == ptr)) {
  1150.             if ((!boolean) && (blank)) {
  1151.                 wmove (tlist->widget, 1, 1);
  1152.                 for (i=0; i < tlist->length-2; i++)
  1153.                 waddch (tlist->widget, ' ');
  1154.                 wrefresh (tlist->widget);
  1155.             }
  1156.               if (textwindowdefined)
  1157.                     wrefresh (screen);
  1158.             return(tlist -> active = boolean);
  1159.           }
  1160.           break;
  1161.     case INP: for (ilist = inplist; ilist != NULLINP; ilist = ilist -> next)
  1162.           if ((ilist != NULLINP) && (ilist -> id == ptr)) {
  1163.             if ((!boolean) && (blank)) {
  1164.                 wmove (ilist->widget, 1, 1);
  1165.                 for (i=0; i < ilist->length-2; i++)
  1166.                 waddch (ilist->widget, ' ');
  1167.                 wrefresh (ilist->widget);
  1168.             }
  1169.               if (textwindowdefined)
  1170.                     wrefresh (screen);
  1171.             return (ilist -> active = boolean);
  1172.           }
  1173.           break;
  1174.     default : return FALSE;
  1175.     }
  1176. }
  1177.  
  1178. #ifdef __STDC__
  1179. int activate (WIDGET ptr)
  1180. #else
  1181. int activate (ptr)
  1182. /* reactivate a widget given its ptr */
  1183. WIDGET ptr;
  1184. #endif
  1185. {
  1186.     int boolean;
  1187.  
  1188.     boolean = (chactive (ptr, TRUE, FALSE));
  1189.     light (ptr, FALSE);
  1190.     return boolean;
  1191. }
  1192.  
  1193. #ifdef __STDC__
  1194. int deactivate (WIDGET ptr, int blank)
  1195. #else
  1196. int deactivate (ptr, blank)
  1197. /* deactivates a widget given its ptr */
  1198. WIDGET ptr;
  1199. int    blank;
  1200. #endif
  1201. {
  1202.     return (chactive (ptr, FALSE, blank));
  1203. }
  1204.  
  1205. #ifdef __STDC__
  1206. int light (WIDGET ptr, int boolean)
  1207. #else
  1208. int light (ptr, boolean)
  1209. /* will highlight or dehighlight a given widget */
  1210. WIDGET ptr;
  1211. int boolean;
  1212. #endif
  1213. {
  1214.     struct cmdwid *clist;
  1215.     struct tglwid *tlist;
  1216.     struct lblwid *llist;
  1217.     struct inpwid *ilist;
  1218.  
  1219.     switch (widgettype (ptr)) {
  1220.     case CMD: for (clist = cmdlist; clist != NULLCMD; clist = clist -> next)
  1221.           if ((clist != NULLCMD) && (clist -> id == ptr)) {
  1222.               if (clist -> active)
  1223.                       drawcmdwidget (clist->widget,clist->msg,clist->acpt,clist->length,boolean);
  1224.           if (textwindowdefined)
  1225.                 wrefresh (screen);
  1226.           return (clist -> active);
  1227.           }
  1228.           break;
  1229.  
  1230.     case TGL: for (tlist = tgllist; tlist != NULLTGL; tlist = tlist -> next)
  1231.           if ((tlist != NULLTGL) && (tlist -> id == ptr)) {
  1232.               if (tlist -> active)
  1233.                     drawtglwidget (tlist->widget,tlist->msg,tlist->tgl[tlist->cur],tlist->toggle,tlist->length,boolean);
  1234.           if (textwindowdefined)
  1235.                 wrefresh (screen);
  1236.           return (tlist -> active);
  1237.           }
  1238.           break;
  1239.  
  1240.     case LBL: for (llist = lbllist; llist != NULLLBL; llist = llist -> next)
  1241.           if ((llist != NULLLBL) && (llist -> id == ptr))
  1242.               drawlblwidget (llist->widget,llist->msg,llist->pos,llist->difference,llist->length-2,boolean);
  1243.           if (textwindowdefined)
  1244.                 wrefresh (screen);
  1245.           return TRUE;
  1246.           break;
  1247.  
  1248.     case INP: for (ilist = inplist; ilist != NULLINP; ilist = ilist -> next)
  1249.           if ((ilist != NULLINP) && (ilist -> id == ptr)) {
  1250.               if (ilist -> active)
  1251.                     drawinpwidget (ilist->widget,ilist->msg,ilist->acpt,ilist->length,boolean,ilist->exec);
  1252.           if (textwindowdefined)
  1253.                 wrefresh (screen);
  1254.           return (ilist -> active);
  1255.           }
  1256.           break;
  1257.  
  1258.     }
  1259.     return FALSE;
  1260. }
  1261.  
  1262. #ifdef __STDC__
  1263. int highlight (WIDGET ptr)
  1264. #else
  1265. int highlight (ptr)
  1266. /* highlights the given ACTIVE widget */
  1267. WIDGET ptr;
  1268. #endif
  1269. {
  1270.     return (light (ptr, TRUE));
  1271. }
  1272.  
  1273. #ifdef __STDC__
  1274. int dehighlight (WIDGET ptr)
  1275. #else
  1276. int dehighlight (ptr)
  1277. /* dehighlights the given ACTIVE widget */
  1278. WIDGET ptr;
  1279. #endif
  1280. {
  1281.     return (light (ptr, FALSE));
  1282. }
  1283.  
  1284. void home ()
  1285. /* scans the current state of the screen and places the x,y cursor coordinates
  1286.    at the end of widget furthest down and to the right */
  1287. {
  1288.     struct cmdwid *clist = cmdlist;
  1289.     struct lblwid *llist = lbllist;
  1290.     struct tglwid *tlist = tgllist;
  1291.     struct inpwid *ilist = inplist;
  1292.     int           x, y;
  1293.  
  1294.     x = y = 0;
  1295.  
  1296.     /* look through command widgets */
  1297.     while (clist != NULLCMD) {
  1298.     if (clist -> y > y) {
  1299.         y = clist -> y;
  1300.         x = clist->x + clist->length;
  1301.     }
  1302.     else if ((clist->x + clist->length > x) && (clist -> y == y)) {
  1303.         x = clist->x + clist->length;
  1304. }
  1305.        clist = clist -> next;
  1306.     }
  1307.  
  1308.     /* look through toggle widgets */
  1309.     while (tlist != NULLTGL) {
  1310.     if (tlist -> y > y) {
  1311.         y = tlist -> y;
  1312.         x = tlist->x + tlist->length;
  1313.     }
  1314.     else if ((tlist->x + tlist->length > x) && (tlist -> y == y)) {
  1315.         x = tlist->x + tlist->length;
  1316. }
  1317.     tlist = tlist -> next;
  1318.     }
  1319.  
  1320.     /* look through label widgets */
  1321.     while (llist != NULLLBL) {
  1322.     if (llist -> y > y) {
  1323.         y = llist -> y;
  1324.         x = llist->x + llist->length;
  1325.     }
  1326.     else if ((llist->x + llist->length > x) && (llist -> y == y)) {
  1327.         x = llist->x + llist->length;
  1328. }
  1329.     llist = llist -> next;
  1330.     }
  1331.  
  1332.     /* look through input widgets */
  1333.     while (ilist != NULLINP) {
  1334.     if (ilist -> y > y) {
  1335.         y = ilist -> y;
  1336.         x = ilist->x + ilist->length;
  1337.     }
  1338.     else if ((ilist->x + ilist->length > x) && (ilist -> y == y)) {
  1339.         x = ilist->x + ilist->length;
  1340. }
  1341.     ilist = ilist -> next;
  1342.     }
  1343.    
  1344.     /* update screen x,y coordinates */
  1345.     widx = x;
  1346.     widy = y;
  1347. }
  1348.  
  1349. #ifdef __STDC__
  1350. int changelblwidget (WIDGET ptr, char info[], int pos)
  1351. #else
  1352. int changelblwidget (ptr, info, pos)
  1353. WIDGET ptr;
  1354. char   info[];
  1355. int    pos;
  1356. #endif
  1357. {
  1358.     struct lblwid *list = lbllist;
  1359.     int          length = 0;
  1360.  
  1361.     while ((list != NULLLBL) && (list->id != ptr))
  1362.     list = list -> next;
  1363.  
  1364.     if (list == NULLLBL)
  1365.     return FALSE;
  1366.  
  1367.     if (!((pos & CENTRE) || (pos & LEFTJUST) || (pos & RIGHTJUST)))
  1368.     pos = pos|LEFTJUST;
  1369.  
  1370.     /* calculate length of label widget */
  1371.     while (info [length++] != '\0')    
  1372.         ;    
  1373.     length -= 1;
  1374.     if (list->length-2 < length) /* not given enough room so error */
  1375.         return FALSE;
  1376.     
  1377.     list -> difference = list->length-2 - length;
  1378.  
  1379.     strcpy (list -> msg, info);
  1380.     list -> pos = pos;
  1381.     werase (list->widget);
  1382.     drawlblwidget (list->widget,info,pos,list->difference,list->length-2,!(pos & NOHIGH));
  1383.  
  1384.     if (textwindowdefined)
  1385.     wrefresh (screen);
  1386.     return (TRUE);
  1387. }
  1388.  
  1389. void endwidgets ()
  1390. /* tidy up at the end */
  1391. {
  1392.     struct cmdwid *clist = cmdlist;
  1393.     struct lblwid *llist = lbllist;
  1394.     struct tglwid *tlist = tgllist;
  1395.     struct inpwid *ilist = inplist;
  1396.  
  1397.     while (clist != NULLCMD) {
  1398.     killcmdwidget (clist -> id);
  1399.         clist = cmdlist;
  1400.     }
  1401.  
  1402.     while (llist != NULLLBL) {
  1403.     killlblwidget (llist -> id);
  1404.     llist = lbllist;
  1405.     }
  1406.  
  1407.     while (tlist != NULLTGL) {
  1408.     killtglwidget (tlist -> id);
  1409.     tlist = tgllist;
  1410.     }
  1411.  
  1412.     while (ilist != NULLINP) {
  1413.     killinpwidget (ilist -> id);
  1414.     ilist = inplist;
  1415.     }
  1416.  
  1417.     killtextwindow ();
  1418.     endwin ();
  1419.     exit (0);
  1420. }
  1421.  
  1422. void killtextwindow ()
  1423. /* destroy screen and any borders */
  1424. {
  1425.     if (textwindowdefined) {
  1426.     werase (screen);
  1427.     wrefresh (screen);
  1428.     delwin (screen);
  1429.     textwindowdefined = FALSE;
  1430.     if ((screenborder & VERTICAL) && (screenborder & HORIZONTAL)) {
  1431.         werase (screenbox);
  1432.         wrefresh (screenbox);
  1433.         delwin (screenbox);
  1434.      }
  1435.     else if ((screenborder & VERTICAL) || (screenborder & HORIZONTAL)) {
  1436.         werase (edge1);
  1437.         werase (edge2);
  1438.         wrefresh (edge1);
  1439.         wrefresh (edge2);
  1440.         delwin (edge1);
  1441.         delwin (edge2);
  1442.         }
  1443.     maxwidy = LINES - 2;
  1444.     screenborder = 0;
  1445.     }
  1446. }
  1447.