home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / dos / sbbs_src.exe / UIFC / UIFC.C next >
Encoding:
C/C++ Source or Header  |  1997-04-26  |  44.7 KB  |  1,737 lines

  1. #line 1 "UIFC.C"
  2.  
  3. /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
  4.  
  5. #include "UIFC.h"
  6. #include <share.h>
  7.  
  8. #if defined(__OS2__)
  9.  
  10. #define INCL_BASE
  11. #include <os2.h>
  12.  
  13. void mswait(int msec)
  14. {
  15. DosSleep(msec ? msec : 1);
  16. }
  17.  
  18. #elif defined(__FLAT__)
  19.     #define mswait(x) delay(x)
  20. #endif
  21.  
  22.                             /* Bottom line elements */
  23. #define BL_INS      (1<<0)  /* INS key */
  24. #define BL_DEL      (1<<1)  /* DEL key */
  25. #define BL_GET      (1<<2)  /* Get key */
  26. #define BL_PUT      (1<<3)  /* Put key */
  27.  
  28. #define HELP 1
  29.  
  30. char hclr,lclr,bclr,cclr,scrn_len,savnum=0,show_free_mem=0
  31.     ,helpdatfile[256]=""
  32.     ,helpixbfile[256]=""
  33.     ,*helpfile=0,*helpbuf=0
  34.     ,blk_scrn[MAX_BFLN],savdepth=0,changes=0,uifc_status=0;
  35. win_t sav[MAX_BUFS];
  36. uint cursor,helpline=0,max_opts=MAX_OPTS;
  37.  
  38. extern int daylight=0;
  39. extern long timezone=0;
  40.  
  41. void bottomline(int line);
  42.  
  43. #ifdef __FLAT__
  44. int inkey(int mode)
  45. {
  46.     int c;
  47.  
  48. if(mode)
  49.     return(kbhit());
  50. c=getch();
  51. if(!c)
  52.     c=(getch()<<8);
  53. return(c);
  54. }
  55. #else
  56. int inkey(int mode)
  57. {
  58. if(mode)
  59.     return(bioskey(1));
  60. while(!bioskey(1));
  61. return(bioskey(0));
  62. }
  63. #endif
  64.  
  65. uint mousecursor=0x28;
  66.  
  67. void uifcini()
  68. {
  69.     int     i;
  70.     struct    text_info txtinfo;
  71. #ifndef __FLAT__
  72.     union    REGS r;
  73. #endif
  74.  
  75. putenv("TZ=UCT0");  /* Fix for Watcom C++ EDT default */
  76.  
  77. gettextinfo(&txtinfo);
  78.  
  79. scrn_len=txtinfo.screenheight;
  80. scrn_len--;
  81. clrscr();
  82. if(scrn_len>50) {
  83.     cputs("\7UIFC: Can't operate in video modes beyond 80x50\r\n");
  84.     exit(1); }
  85.  
  86. if(txtinfo.screenwidth<80) {
  87.     cputs("\7UIFC: Can't operate in video modes less than 80x25\r\n");
  88.     exit(1); }
  89.  
  90. #ifndef __FLAT__
  91.  
  92. r.w.ax=0x0000;                /* reset mouse and get driver status */
  93. INT_86(0x33,&r,&r);
  94.  
  95. if(r.w.ax==0xffff) {        /* mouse driver installed */
  96.     uifc_status|=UIFC_MOUSE;
  97.  
  98.  
  99.     r.w.ax=0x0020;            /* enable mouse driver */
  100.     INT_86(0x33,&r,&r);
  101.  
  102.     r.w.ax=0x000a;            /* set text pointer type */
  103.     r.w.bx=0x0000;            /* software cursor */
  104.     r.w.cx=0x77ff;
  105.     r.w.dx=mousecursor<<8;
  106.     INT_86(0x33,&r,&r);
  107.  
  108.     r.w.ax=0x0013;            /* set double speed threshold */
  109.     r.w.dx=32;                /* double speed threshold */
  110.     INT_86(0x33,&r,&r);
  111.  
  112.     r.w.ax=0x0001;            /* show mouse pointer */
  113.     INT_86(0x33,&r,&r); }
  114.  
  115. #endif
  116.  
  117.  
  118. if(!(uifc_status&UIFC_COLOR)
  119.     && (uifc_status&UIFC_MONO
  120.         || txtinfo.currmode==MONO || txtinfo.currmode==BW80)) {
  121.     bclr=BLACK;
  122.     hclr=WHITE;
  123.     lclr=LIGHTGRAY;
  124.     cclr=LIGHTGRAY; }
  125. else {
  126.     textmode(C80);
  127.     bclr=BLUE;
  128.     hclr=YELLOW;
  129.     lclr=WHITE;
  130.     cclr=CYAN; }
  131. for(i=0;i<8000;i+=2) {
  132.     blk_scrn[i]='░';
  133.     blk_scrn[i+1]=cclr|(bclr<<4); }
  134.  
  135. cursor=_NOCURSOR;
  136. _setcursortype(cursor);
  137.  
  138. }
  139.  
  140. void hidemouse(void)
  141. {
  142. #ifndef __FLAT__
  143.     union  REGS r;
  144.  
  145. if(uifc_status&UIFC_MOUSE) {
  146.     r.w.ax=0x0002;            /* hide mouse pointer */
  147.     INT_86(0x33,&r,&r); }
  148. #endif
  149. }
  150.  
  151. void showmouse(void)
  152. {
  153. #ifndef __FLAT__
  154.     union  REGS r;
  155.  
  156. if(uifc_status&UIFC_MOUSE) {
  157.     r.w.ax=0x0001;            /* show mouse pointer */
  158.     INT_86(0x33,&r,&r); }
  159. #endif
  160. }
  161.  
  162.  
  163. void uifcbail(void)
  164. {
  165.  
  166. hidemouse();
  167. _setcursortype(_NORMALCURSOR);
  168. textattr(LIGHTGRAY);
  169. clrscr();
  170. }
  171.  
  172. int uscrn(char *str)
  173. {
  174.  
  175. textattr(bclr|(cclr<<4));
  176. gotoxy(1,1);
  177. clreol();
  178. gotoxy(3,1);
  179. cputs(str);
  180. if(!puttext(1,2,80,scrn_len,blk_scrn))
  181.     return(-1);
  182. gotoxy(1,scrn_len+1);
  183. clreol();
  184. return(0);
  185. }
  186.  
  187. void scroll_text(int x1, int y1, int x2, int y2, int down)
  188. {
  189.     uchar buf[MAX_BFLN];
  190.  
  191. gettext(x1,y1,x2,y2,buf);
  192. if(down)
  193.     puttext(x1,y1+1,x2,y2,buf);
  194. else
  195.     puttext(x1,y1,x2,y2-1,buf+(((x2-x1)+1)*2));
  196. }
  197.  
  198. /**************************************************************************/
  199. /* General menu display function. SCRN_* macros define virtual screen     */
  200. /* limits. *cur is a pointer to the current option. Returns option number */
  201. /* positive value for selected option or -1 for ESC, -2 for INS or -3 for */
  202. /* DEL. Menus can centered left to right and top to bottom automatically. */
  203. /* mode bits are set with macros WIN_*                                      */
  204. /* option is an array of char arrays, first element of last char array    */
  205. /* must be NULL.                                                          */
  206. /**************************************************************************/
  207. int ulist(int mode, char left, int top, char width, int *cur, int *bar
  208.     , char *title, char **option)
  209. {
  210.     uchar line[256],shade[256],win[MAX_BFLN],*ptr,a,b,c,longopt
  211.         ,search[MAX_OPLN],bline=0;
  212.     int height,y;
  213.     int i,j,opts=0,s=0; /* s=search index into options */
  214.  
  215. #ifndef __FLAT__
  216.     union REGS reg,r;
  217.  
  218. hidemouse();
  219.  
  220. r.w.ax=0x0006;    /* Get button release info */
  221. r.w.bx=0x0000;    /* Left button */
  222. INT_86(0x33,&r,&r);  /* Clears any buffered mouse clicks */
  223.  
  224. r.w.ax=0x0006;    /* Get button release info */
  225. r.w.bx=0x0001;    /* Right button */
  226. INT_86(0x33,&r,&r);  /* Clears any buffered mouse clicks */
  227.  
  228. #endif
  229.  
  230. if(mode&WIN_SAV && savnum>=MAX_BUFS-1)
  231.     putch(7);
  232. i=0;
  233. if(mode&WIN_INS) bline|=BL_INS;
  234. if(mode&WIN_DEL) bline|=BL_DEL;
  235. if(mode&WIN_GET) bline|=BL_GET;
  236. if(mode&WIN_PUT) bline|=BL_PUT;
  237. bottomline(bline);
  238. while(opts<max_opts && opts<MAX_OPTS)
  239.     if(option[opts][0]==0)
  240.         break;
  241.     else opts++;
  242. if(mode&WIN_XTR && opts<max_opts && opts<MAX_OPTS)
  243.     option[opts++][0]=0;
  244. height=opts+4;
  245. if(top+height>scrn_len-3)
  246.     height=(scrn_len-3)-top;
  247. if(!width || width<strlen(title)+6) {
  248.     width=strlen(title)+6;
  249.     for(i=0;i<opts;i++) {
  250.         truncsp(option[i]);
  251.         if((j=strlen(option[i])+5)>width)
  252.             width=j; } }
  253. if(width>(SCRN_RIGHT+1)-SCRN_LEFT)
  254.     width=(SCRN_RIGHT+1)-SCRN_LEFT;
  255. if(mode&WIN_L2R)
  256.     left=36-(width/2);
  257. else if(mode&WIN_RHT)
  258.     left=SCRN_RIGHT-(width+4+left);
  259. if(mode&WIN_T2B)
  260.     top=(scrn_len/2)-(height/2)-2;
  261. else if(mode&WIN_BOT)
  262.     top=scrn_len-height-3-top;
  263. if(mode&WIN_SAV && savdepth==savnum) {
  264.     if((sav[savnum].buf=(char *)MALLOC((width+3)*(height+2)*2))==NULL) {
  265.         cprintf("UIFC: error allocating %u bytes.",(width+3)*(height+2)*2);
  266.         return(-1); }
  267.     gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT+left+width+1
  268.         ,SCRN_TOP+top+height,sav[savnum].buf);
  269.     sav[savnum].left=SCRN_LEFT+left;
  270.     sav[savnum].top=SCRN_TOP+top;
  271.     sav[savnum].right=SCRN_LEFT+left+width+1;
  272.     sav[savnum].bot=SCRN_TOP+top+height;
  273.     savdepth++; }
  274. else if(mode&WIN_SAV
  275.     && (sav[savnum].left!=SCRN_LEFT+left
  276.     || sav[savnum].top!=SCRN_TOP+top
  277.     || sav[savnum].right!=SCRN_LEFT+left+width+1
  278.     || sav[savnum].bot!=SCRN_TOP+top+height)) { /* dimensions have changed */
  279.     puttext(sav[savnum].left,sav[savnum].top,sav[savnum].right,sav[savnum].bot
  280.         ,sav[savnum].buf);    /* put original window back */
  281.     FREE(sav[savnum].buf);
  282.     if((sav[savnum].buf=(char *)MALLOC((width+3)*(height+2)*2))==NULL) {
  283.         cprintf("UIFC: error allocating %u bytes.",(width+3)*(height+2)*2);
  284.         return(-1); }
  285.     gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT+left+width+1
  286.         ,SCRN_TOP+top+height,sav[savnum].buf);      /* save again */
  287.     sav[savnum].left=SCRN_LEFT+left;
  288.     sav[savnum].top=SCRN_TOP+top;
  289.     sav[savnum].right=SCRN_LEFT+left+width+1;
  290.     sav[savnum].bot=SCRN_TOP+top+height; }
  291.  
  292.  
  293. #ifndef __OS2__
  294. if(show_free_mem) {
  295.     #if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  296.     uprintf(58,1,bclr|(cclr<<4),"%10ld bytes free",farcoreleft());
  297.     #else
  298.     uprintf(58,1,bclr|(cclr<<4),"%10u bytes free",coreleft());
  299.     #endif
  300.     }
  301. #endif
  302.  
  303.  
  304. if(mode&WIN_ORG) { /* Clear around menu */
  305.     if(top)
  306.         puttext(SCRN_LEFT,SCRN_TOP,SCRN_RIGHT+2,SCRN_TOP+top-1,blk_scrn);
  307.     if(SCRN_TOP+height+top<=scrn_len)
  308.         puttext(SCRN_LEFT,SCRN_TOP+height+top,SCRN_RIGHT+2,scrn_len,blk_scrn);
  309.     if(left)
  310.         puttext(SCRN_LEFT,SCRN_TOP+top,SCRN_LEFT+left-1,SCRN_TOP+height+top
  311.             ,blk_scrn);
  312.     if(SCRN_LEFT+left+width<=SCRN_RIGHT)
  313.         puttext(SCRN_LEFT+left+width,SCRN_TOP+top,SCRN_RIGHT+2
  314.             ,SCRN_TOP+height+top,blk_scrn); }
  315. ptr=win;
  316. *(ptr++)='╔';
  317. *(ptr++)=hclr|(bclr<<4);
  318.  
  319. if(uifc_status&UIFC_MOUSE) {
  320.     *(ptr++)='[';
  321.     *(ptr++)=hclr|(bclr<<4);
  322.     *(ptr++)='■';
  323.     *(ptr++)=lclr|(bclr<<4);
  324.     *(ptr++)=']';
  325.     *(ptr++)=hclr|(bclr<<4);
  326.     *(ptr++)='[';
  327.     *(ptr++)=hclr|(bclr<<4);
  328.     *(ptr++)='?';
  329.     *(ptr++)=lclr|(bclr<<4);
  330.     *(ptr++)=']';
  331.     *(ptr++)=hclr|(bclr<<4);
  332.     i=6; }
  333. else
  334.     i=0;
  335. for(;i<width-2;i++) {
  336.     *(ptr++)='═';
  337.     *(ptr++)=hclr|(bclr<<4); }
  338. *(ptr++)='╗';
  339. *(ptr++)=hclr|(bclr<<4);
  340. *(ptr++)='║';
  341. *(ptr++)=hclr|(bclr<<4);
  342. a=strlen(title);
  343. b=(width-a-1)/2;
  344. for(i=0;i<b;i++) {
  345.     *(ptr++)=' ';
  346.     *(ptr++)=hclr|(bclr<<4); }
  347. for(i=0;i<a;i++) {
  348.     *(ptr++)=title[i];
  349.     *(ptr++)=hclr|(bclr<<4); }
  350. for(i=0;i<width-(a+b)-2;i++) {
  351.     *(ptr++)=' ';
  352.     *(ptr++)=hclr|(bclr<<4); }
  353. *(ptr++)='║';
  354. *(ptr++)=hclr|(bclr<<4);
  355. *(ptr++)='╠';
  356. *(ptr++)=hclr|(bclr<<4);
  357. for(i=0;i<width-2;i++) {
  358.     *(ptr++)='═';
  359.     *(ptr++)=hclr|(bclr<<4); }
  360. *(ptr++)='╣';
  361. *(ptr++)=hclr|(bclr<<4);
  362.  
  363. if((*cur)>=opts)
  364.     (*cur)=opts-1;            /* returned after scrolled */
  365.  
  366. if(!bar) {
  367.     if((*cur)>height-5)
  368.         (*cur)=height-5;
  369.     i=0; }
  370. else {
  371.     if((*bar)>=opts)
  372.         (*bar)=opts-1;
  373.     if((*bar)>height-5)
  374.         (*bar)=height-5;
  375.     if((*cur)==opts-1)
  376.         (*bar)=height-5;
  377.     if((*bar)<0)
  378.         (*bar)=0;
  379.     if((*cur)<(*bar))
  380.         (*cur)=(*bar);
  381.     i=(*cur)-(*bar);
  382. //
  383.     if(i+(height-5)>=opts) {
  384.         i=opts-(height-4);
  385.         (*cur)=i+(*bar);
  386.         }
  387.     }
  388. if((*cur)<0)
  389.     (*cur)=0;
  390.  
  391. j=0;
  392. if(i<0) i=0;
  393. longopt=0;
  394. while(j<height-4 && i<opts) {
  395.     *(ptr++)='║';
  396.     *(ptr++)=hclr|(bclr<<4);
  397.     *(ptr++)=' ';
  398.     *(ptr++)=hclr|(bclr<<4);
  399.     *(ptr++)='│';
  400.     *(ptr++)=lclr|(bclr<<4);
  401.     if(i==(*cur))
  402.         a=bclr|(LIGHTGRAY<<4);
  403.     else
  404.         a=lclr|(bclr<<4);
  405.     b=strlen(option[i]);
  406.     if(b>longopt)
  407.         longopt=b;
  408.     if(b+4>width)
  409.         b=width-4;
  410.     for(c=0;c<b;c++) {
  411.         *(ptr++)=option[i][c];
  412.         *(ptr++)=a; }
  413.     while(c<width-4) {
  414.         *(ptr++)=' ';
  415.         *(ptr++)=a;
  416.         c++; }
  417.     *(ptr++)='║';
  418.     *(ptr++)=hclr|(bclr<<4);
  419.     i++;
  420.     j++; }
  421. *(ptr++)='╚';
  422. *(ptr++)=hclr|(bclr<<4);
  423. for(i=0;i<width-2;i++) {
  424.     *(ptr++)='═';
  425.     *(ptr++)=hclr|(bclr<<4); }
  426. *(ptr++)='╝';
  427. *(ptr++)=hclr|(bclr<<4);
  428. puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT+left+width-1
  429.     ,SCRN_TOP+top+height-1,win);
  430. if(bar)
  431.     y=top+3+(*bar);
  432. else
  433.     y=top+3+(*cur);
  434. if(opts+4>height && ((!bar && (*cur)!=opts-1)
  435.     || (bar && ((*cur)-(*bar))+(height-4)<opts))) {
  436.     gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  437.     textattr(lclr|(bclr<<4));
  438.     putch(31);       /* put down arrow */
  439.     textattr(hclr|(bclr<<4)); }
  440.  
  441. if(bar && (*bar)!=(*cur)) {
  442.     gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3);
  443.     textattr(lclr|(bclr<<4));
  444.     putch(30);       /* put the up arrow */
  445.     textattr(hclr|(bclr<<4)); }
  446.  
  447. if(bclr==BLUE) {
  448.     gettext(SCRN_LEFT+left+width,SCRN_TOP+top+1,SCRN_LEFT+left+width+1
  449.         ,SCRN_TOP+top+height-1,shade);
  450.     for(i=1;i<height*4;i+=2)
  451.         shade[i]=DARKGRAY;
  452.     puttext(SCRN_LEFT+left+width,SCRN_TOP+top+1,SCRN_LEFT+left+width+1
  453.         ,SCRN_TOP+top+height-1,shade);
  454.     gettext(SCRN_LEFT+left+2,SCRN_TOP+top+height,SCRN_LEFT+left+width+1
  455.         ,SCRN_TOP+top+height,shade);
  456.     for(i=1;i<width*2;i+=2)
  457.         shade[i]=DARKGRAY;
  458.     puttext(SCRN_LEFT+left+2,SCRN_TOP+top+height,SCRN_LEFT+left+width+1
  459.         ,SCRN_TOP+top+height,shade); }
  460. showmouse();
  461. while(1) {
  462. #if 0                    /* debug */
  463.     gotoxy(30,1);
  464.     cprintf("y=%2d h=%2d c=%2d b=%2d s=%2d o=%2d"
  465.         ,y,height,*cur,bar ? *bar :0xff,savdepth,opts);
  466. #endif
  467.     if(!show_free_mem)
  468.         timedisplay();
  469. #ifndef __FLAT__
  470.     if(uifc_status&UIFC_MOUSE) {
  471.  
  472.         r.w.ax=0x0003;        /* Get button status and mouse position */
  473.         INT_86(0x33,&r,&r);
  474.  
  475.         if(r.w.bx&1) {        /* Left button down */
  476.  
  477.             if(r.w.cx/8>=SCRN_LEFT+left
  478.                 && r.w.cx/8<=SCRN_LEFT+left+width
  479.                 && r.w.dx/8>=SCRN_TOP+top+2
  480.                 && r.w.dx/8<=(SCRN_TOP+top+height)-3) {
  481.  
  482.                 hidemouse();
  483.                 gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  484.                     ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  485.                 for(i=1;i<width*2;i+=2)
  486.                     line[i]=lclr|(bclr<<4);
  487.                 puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  488.                     ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  489.  
  490.                 (*cur)=(r.w.dx/8)-(SCRN_TOP+top+2);
  491.                 if(bar)
  492.                     (*bar)=(*cur);
  493.                 y=top+3+((r.w.dx/8)-(SCRN_TOP+top+2));
  494.  
  495.                 gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  496.                     ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  497.                 for(i=1;i<width*2;i+=2)
  498.                     line[i]=bclr|(LIGHTGRAY<<4);
  499.                 puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  500.                     ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  501.                 showmouse(); } }
  502.  
  503.         r.w.ax=0x0006;        /* Get button release information */
  504.         r.w.bx=0x0000;        /* left button */
  505.         INT_86(0x33,&r,&r);
  506.  
  507.         if(r.w.bx) {      /* Left button release same as CR */
  508.  
  509.             if(r.w.cx/8>=SCRN_LEFT+left
  510.                 && r.w.cx/8<=SCRN_LEFT+left+width
  511.                 && r.w.dx/8>=SCRN_TOP+top+2
  512.                 && r.w.dx/8<=(SCRN_TOP+top+height)-3) {
  513.  
  514.                 (*cur)=(r.w.dx/8)-(SCRN_TOP+top+2);
  515.                 if(bar)
  516.                     (*bar)=(*cur);
  517.                 y=top+3+((r.w.dx/8)-(SCRN_TOP+top+2));
  518.  
  519.                 if(!opts || (mode&WIN_XTR && (*cur)==opts-1))
  520.                     continue;
  521.  
  522.                 if(mode&WIN_ACT) {
  523.                     hidemouse();
  524.                     gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  525.                         +left+width-1,SCRN_TOP+top+height-1,win);
  526.                     for(i=1;i<(width*height*2);i+=2)
  527.                         win[i]=lclr|(cclr<<4);
  528.                     j=(((y-top)*width)*2)+7+((width-4)*2);
  529.                     for(i=(((y-top)*width)*2)+7;i<j;i+=2)
  530.                         win[i]=hclr|(cclr<<4);
  531.  
  532.                     puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  533.                         +left+width-1,SCRN_TOP+top+height-1,win);
  534.                     showmouse(); }
  535.                 else if(mode&WIN_SAV) {
  536.                     hidemouse();
  537.                     puttext(sav[savnum].left,sav[savnum].top
  538.                         ,sav[savnum].right,sav[savnum].bot
  539.                         ,sav[savnum].buf);
  540.                     showmouse();
  541.                     FREE(sav[savnum].buf);
  542.                     savdepth--; }
  543.                 return(*cur); }
  544.             else if(r.w.cx/8>=SCRN_LEFT+left+3
  545.                 && r.w.cx/8<=SCRN_LEFT+left+5
  546.                 && r.w.dx/8==(SCRN_TOP+top)-1)        /* Clicked help icon */
  547.                 help();
  548.             else
  549.                 goto hitesc; }
  550.  
  551.         r.w.ax=0x0006;        /* Get button release information */
  552.         r.w.bx=0x0001;        /* right button */
  553.         INT_86(0x33,&r,&r);
  554.  
  555.         if(r.w.bx) {      /* Right button down, same as ESC */
  556. hitesc:
  557.             if(mode&WIN_ESC || (mode&WIN_CHE && changes)
  558.                 && !(mode&WIN_SAV)) {
  559.                 hidemouse();
  560.                 gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  561.                     +left+width-1,SCRN_TOP+top+height-1,win);
  562.                 for(i=1;i<(width*height*2);i+=2)
  563.                     win[i]=lclr|(cclr<<4);
  564.                 puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  565.                     +left+width-1,SCRN_TOP+top+height-1,win);
  566.                 showmouse(); }
  567.             else if(mode&WIN_SAV) {
  568.                 hidemouse();
  569.                 puttext(sav[savnum].left,sav[savnum].top
  570.                     ,sav[savnum].right,sav[savnum].bot
  571.                     ,sav[savnum].buf);
  572.                 showmouse();
  573.                 FREE(sav[savnum].buf);
  574.                 savdepth--; }
  575.             return(-1); }
  576.                 }
  577. #endif
  578.  
  579.     if(inkey(1)) {
  580.         i=inkey(0);
  581.         if(!(i&0xff)) {
  582.             s=0;
  583.             switch(i>>8) {
  584.                 case 71:    /* home */
  585.                     if(!opts)
  586.                         break;
  587.                     if(opts+4>height) {
  588.                         hidemouse();
  589.                         gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3);
  590.                         textattr(lclr|(bclr<<4));
  591.                         putch(' ');    /* Delete the up arrow */
  592.                         gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  593.                         putch(31);       /* put the down arrow */
  594.                         uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3
  595.                             ,bclr|(LIGHTGRAY<<4)
  596.                             ,"%-*.*s",width-4,width-4,option[0]);
  597.                         for(i=1;i<height-4;i++)    /* re-display options */
  598.                             uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3+i
  599.                                 ,lclr|(bclr<<4)
  600.                                 ,"%-*.*s",width-4,width-4,option[i]);
  601.                         (*cur)=0;
  602.                         if(bar)
  603.                             (*bar)=0;
  604.                         y=top+3;
  605.                         showmouse();
  606.                         break; }
  607.                     hidemouse();
  608.                     gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  609.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  610.                     for(i=1;i<width*2;i+=2)
  611.                         line[i]=lclr|(bclr<<4);
  612.                     puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  613.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  614.                     (*cur)=0;
  615.                     if(bar)
  616.                         (*bar)=0;
  617.                     y=top+3;
  618.                     gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  619.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  620.                     for(i=1;i<width*2;i+=2)
  621.                         line[i]=bclr|(LIGHTGRAY<<4);
  622.                     puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  623.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  624.                     showmouse();
  625.                     break;
  626.                 case 72:    /* up arrow */
  627.                     if(!opts)
  628.                         break;
  629.                     if(!(*cur) && opts+4>height) {
  630.                         hidemouse();
  631.                         gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3); /* like end */
  632.                         textattr(lclr|(bclr<<4));
  633.                         putch(30);       /* put the up arrow */
  634.                         gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  635.                         putch(' ');    /* delete the down arrow */
  636.                         for(i=(opts+4)-height,j=0;i<opts;i++,j++)
  637.                             uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3+j
  638.                                 ,i==opts-1 ? bclr|(LIGHTGRAY<<4)
  639.                                     : lclr|(bclr<<4)
  640.                                 ,"%-*.*s",width-4,width-4,option[i]);
  641.                         (*cur)=opts-1;
  642.                         if(bar)
  643.                             (*bar)=height-5;
  644.                         y=top+height-2;
  645.                         showmouse();
  646.                         break; }
  647.                     hidemouse();
  648.                     gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  649.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  650.                     for(i=1;i<width*2;i+=2)
  651.                         line[i]=lclr|(bclr<<4);
  652.                     puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  653.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  654.                     showmouse();
  655.                     if(!(*cur)) {
  656.                         y=top+height-2;
  657.                         (*cur)=opts-1;
  658.                         if(bar)
  659.                             (*bar)=height-5; }
  660.                     else {
  661.                         (*cur)--;
  662.                         y--;
  663.                         if(bar && *bar)
  664.                             (*bar)--; }
  665.                     if(y<top+3) {    /* scroll */
  666.                         hidemouse();
  667.                         if(!(*cur)) {
  668.                             gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3);
  669.                             textattr(lclr|(bclr<<4));
  670.                             putch(' '); }  /* delete the up arrow */
  671.                         if((*cur)+height-4==opts-1) {
  672.                             gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  673.                             textattr(lclr|(bclr<<4));
  674.                             putch(31); }   /* put the dn arrow */
  675.                         y++;
  676.                         scroll_text(SCRN_LEFT+left+2,SCRN_TOP+top+3
  677.                             ,SCRN_LEFT+left+width-3,SCRN_TOP+top+height-2,1);
  678.                         uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3
  679.                             ,bclr|(LIGHTGRAY<<4)
  680.                             ,"%-*.*s",width-4,width-4,option[*cur]);
  681.                         showmouse(); }
  682.                     else {
  683.                         hidemouse();
  684.                         gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  685.                             ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  686.                         for(i=1;i<width*2;i+=2)
  687.                             line[i]=bclr|(LIGHTGRAY<<4);
  688.                         puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  689.                             ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  690.                         showmouse(); }
  691.                     break;
  692. /*
  693.                 case 0x49;    /* PgUp */
  694.                 case 0x51;    /* PgDn */
  695.                     if(!opts || (*cur)==(opts-1))
  696.                         break;
  697.                     (*cur)+=(height-4);
  698.                     if((*cur)>(opts-1))
  699.                         (*cur)=(opts-1);
  700.  
  701.                     hidemouse();
  702.                     gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  703.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  704.                     for(i=1;i<width*2;i+=2)
  705.                         line[i]=lclr|(bclr<<4);
  706.                     puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  707.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  708.  
  709.                     for(i=(opts+4)-height,j=0;i<opts;i++,j++)                          uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3+j
  710.                         uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3+j
  711.                             ,i==(*cur) bclr|(LIGHTGRAY<<4) : lclr|(bclr<<4)
  712.                             ,"%-*.*s",width-4,width-4,option[i]);
  713.                     y=top+height-2;
  714.                     if(bar)
  715.                         (*bar)=height-5;
  716.                     gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  717.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  718.                     for(i=1;i<148;i+=2)
  719.                         line[i]=bclr|(LIGHTGRAY<<4);
  720.                     puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  721.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  722.                     showmouse();
  723.                     break;
  724. */
  725.                 case 79:    /* end */
  726.                     if(!opts)
  727.                         break;
  728.                     if(opts+4>height) {    /* Scroll mode */
  729.                         hidemouse();
  730.                         gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3);
  731.                         textattr(lclr|(bclr<<4));
  732.                         putch(30);       /* put the up arrow */
  733.                         gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  734.                         putch(' ');    /* delete the down arrow */
  735.                         for(i=(opts+4)-height,j=0;i<opts;i++,j++)
  736.                             uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3+j
  737.                                 ,i==opts-1 ? bclr|(LIGHTGRAY<<4)
  738.                                     : lclr|(bclr<<4)
  739.                                 ,"%-*.*s",width-4,width-4,option[i]);
  740.                         (*cur)=opts-1;
  741.                         y=top+height-2;
  742.                         if(bar)
  743.                             (*bar)=height-5;
  744.                         showmouse();
  745.                         break; }
  746.                     hidemouse();
  747.                     gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  748.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  749.                     for(i=1;i<width*2;i+=2)
  750.                         line[i]=lclr|(bclr<<4);
  751.                     puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  752.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  753.                     (*cur)=opts-1;
  754.                     y=top+height-2;
  755.                     if(bar)
  756.                         (*bar)=height-5;
  757.                     gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  758.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  759.                     for(i=1;i<148;i+=2)
  760.                         line[i]=bclr|(LIGHTGRAY<<4);
  761.                     puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  762.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  763.                     showmouse();
  764.                     break;
  765.                 case 80:    /* dn arrow */
  766.                     if(!opts)
  767.                         break;
  768.                     if((*cur)==opts-1 && opts+4>height) { /* like home */
  769.                         hidemouse();
  770.                         gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3);
  771.                         textattr(lclr|(bclr<<4));
  772.                         putch(' ');    /* Delete the up arrow */
  773.                         gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  774.                         putch(31);       /* put the down arrow */
  775.                         uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3
  776.                             ,bclr|(LIGHTGRAY<<4)
  777.                             ,"%-*.*s",width-4,width-4,option[0]);
  778.                         for(i=1;i<height-4;i++)    /* re-display options */
  779.                             uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3+i
  780.                                 ,lclr|(bclr<<4)
  781.                                 ,"%-*.*s",width-4,width-4,option[i]);
  782.                         (*cur)=0;
  783.                         y=top+3;
  784.                         if(bar)
  785.                             (*bar)=0;
  786.                         showmouse();
  787.                         break; }
  788.                     hidemouse();
  789.                     gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  790.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  791.                     for(i=1;i<width*2;i+=2)
  792.                         line[i]=lclr|(bclr<<4);
  793.                     puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  794.                         ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  795.                     showmouse();
  796.                     if((*cur)==opts-1) {
  797.                         (*cur)=0;
  798.                         y=top+3;
  799.                         if(bar) {
  800.                             /* gotoxy(1,1); cprintf("bar=%08lX ",bar); */
  801.                             (*bar)=0; } }
  802.                     else {
  803.                         (*cur)++;
  804.                         y++;
  805.                         if(bar && (*bar)<height-5) {
  806.                             /* gotoxy(1,1); cprintf("bar=%08lX ",bar); */
  807.                             (*bar)++; } }
  808.                     if(y==top+height-1) {    /* scroll */
  809.                         hidemouse();
  810.                         if(*cur==opts-1) {
  811.                             gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  812.                             textattr(lclr|(bclr<<4));
  813.                             putch(' '); }  /* delete the down arrow */
  814.                         if((*cur)+4==height) {
  815.                             gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3);
  816.                             textattr(lclr|(bclr<<4));
  817.                             putch(30); }   /* put the up arrow */
  818.                         y--;
  819.                         /* gotoxy(1,1); cprintf("\rdebug: %4d ",__LINE__); */
  820.                         scroll_text(SCRN_LEFT+left+2,SCRN_TOP+top+3
  821.                             ,SCRN_LEFT+left+width-3,SCRN_TOP+top+height-2,0);
  822.                         /* gotoxy(1,1); cprintf("\rdebug: %4d ",__LINE__); */
  823.                         uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+height-2
  824.                             ,bclr|(LIGHTGRAY<<4)
  825.                             ,"%-*.*s",width-4,width-4,option[*cur]);
  826.                         showmouse(); }
  827.                     else {
  828.                         hidemouse();
  829.                         gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  830.                             ,SCRN_LEFT+left+width-2,SCRN_TOP+y
  831.                             ,line);
  832.                         for(i=1;i<width*2;i+=2)
  833.                             line[i]=bclr|(LIGHTGRAY<<4);
  834.                         puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  835.                             ,SCRN_LEFT+left+width-2,SCRN_TOP+y
  836.                             ,line);
  837.                         showmouse(); }
  838.                     break;
  839.                 case 0x3b:    /* F1 */
  840. #if !HELP
  841.                     umsg("Help Not Yet Implemented");
  842.                     bottomline(bline);
  843. #else
  844.                     help();
  845. #endif
  846.                     break;
  847.                 case 0x3f:    /* F5 */
  848.                     if(mode&WIN_GET && !(mode&WIN_XTR && (*cur)==opts-1))
  849.                         return((*cur)|MSK_GET);
  850.                     break;
  851.                 case 0x40:    /* F6 */
  852.                     if(mode&WIN_PUT && !(mode&WIN_XTR && (*cur)==opts-1))
  853.                         return((*cur)|MSK_PUT);
  854.                     break;
  855.                 case 82:    /* insert */
  856.                     if(mode&WIN_INS) {
  857.                         if(mode&WIN_INSACT) {
  858.                             hidemouse();
  859.                             gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  860.                                 +left+width-1,SCRN_TOP+top+height-1,win);
  861.                             for(i=1;i<(width*height*2);i+=2)
  862.                                 win[i]=lclr|(cclr<<4);
  863.                             if(opts) {
  864.                                 j=(((y-top)*width)*2)+7+((width-4)*2);
  865.                                 for(i=(((y-top)*width)*2)+7;i<j;i+=2)
  866.                                     win[i]=hclr|(cclr<<4); }
  867.                             puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  868.                                 +left+width-1,SCRN_TOP+top+height-1,win);
  869.                             showmouse(); }
  870.                         if(!opts)
  871.                             return(MSK_INS);
  872.                         return((*cur)|MSK_INS); }
  873.                     break;
  874.                 case 83:    /* delete */
  875.                     if(mode&WIN_XTR && (*cur)==opts-1)    /* can't delete */
  876.                         break;                            /* extra line */
  877.                     if(mode&WIN_DEL) {
  878.                         if(mode&WIN_DELACT) {
  879.                             hidemouse();
  880.                             gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  881.                                 +left+width-1,SCRN_TOP+top+height-1,win);
  882.                             for(i=1;i<(width*height*2);i+=2)
  883.                                 win[i]=lclr|(cclr<<4);
  884.                             j=(((y-top)*width)*2)+7+((width-4)*2);
  885.                             for(i=(((y-top)*width)*2)+7;i<j;i+=2)
  886.                                 win[i]=hclr|(cclr<<4);
  887.                             puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  888.                                 +left+width-1,SCRN_TOP+top+height-1,win);
  889.                             showmouse(); }
  890.                         return((*cur)|MSK_DEL); }
  891.                     break;    } }
  892.         else {
  893.             i&=0xff;
  894.             if(isalnum(i) && opts && option[0][0]) {
  895.                 search[s]=i;
  896.                 search[s+1]=0;
  897.                 for(j=(*cur)+1,a=b=0;a<2;j++) {   /* a = search count */
  898.                     if(j==opts) {                    /* j = option count */
  899.                         j=-1;                        /* b = letter count */
  900.                         continue; }
  901.                     if(j==(*cur)) {
  902.                         b++;
  903.                         continue; }
  904.                     if(b>=longopt) {
  905.                         b=0;
  906.                         a++; }
  907.                     if(a==1 && !s)
  908.                         break;
  909.                     if(strlen(option[j])>b
  910.                         && ((!a && s && !strncmpi(option[j]+b,search,s+1))
  911.                         || ((a || !s) && toupper(option[j][b])==toupper(i)))) {
  912.                         if(a) s=0;
  913.                         else s++;
  914.                         if(y+(j-(*cur))+2>height+top) {
  915.                             (*cur)=j;
  916.                             gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3);
  917.                             textattr(lclr|(bclr<<4));
  918.                             putch(30);       /* put the up arrow */
  919.                             if((*cur)==opts-1) {
  920.                                 gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  921.                                 putch(' '); }  /* delete the down arrow */
  922.                             for(i=((*cur)+5)-height,j=0;i<(*cur)+1;i++,j++)
  923.                                 uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3+j
  924.                                     ,i==(*cur) ? bclr|(LIGHTGRAY<<4)
  925.                                         : lclr|(bclr<<4)
  926.                                     ,"%-*.*s",width-4,width-4,option[i]);
  927.                             y=top+height-2;
  928.                             if(bar)
  929.                                 (*bar)=height-5;
  930.                             break; }
  931.                         if(y-((*cur)-j)<top+3) {
  932.                             (*cur)=j;
  933.                             gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+3);
  934.                             textattr(lclr|(bclr<<4));
  935.                             if(!(*cur))
  936.                                 putch(' ');    /* Delete the up arrow */
  937.                             gotoxy(SCRN_LEFT+left+1,SCRN_TOP+top+height-2);
  938.                             putch(31);       /* put the down arrow */
  939.                             uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3
  940.                                 ,bclr|(LIGHTGRAY<<4)
  941.                                 ,"%-*.*s",width-4,width-4,option[(*cur)]);
  942.                             for(i=1;i<height-4;i++)     /* re-display options */
  943.                                 uprintf(SCRN_LEFT+left+3,SCRN_TOP+top+3+i
  944.                                     ,lclr|(bclr<<4)
  945.                                     ,"%-*.*s",width-4,width-4
  946.                                     ,option[(*cur)+i]);
  947.                             y=top+3;
  948.                             if(bar)
  949.                                 (*bar)=0;
  950.                             break; }
  951.                         hidemouse();
  952.                         gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  953.                             ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  954.                         for(i=1;i<width*2;i+=2)
  955.                             line[i]=lclr|(bclr<<4);
  956.                         puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  957.                             ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  958.                         if((*cur)>j)
  959.                             y-=(*cur)-j;
  960.                         else
  961.                             y+=j-(*cur);
  962.                         if(bar) {
  963.                             if((*cur)>j)
  964.                                 (*bar)-=(*cur)-j;
  965.                             else
  966.                                 (*bar)+=j-(*cur); }
  967.                         (*cur)=j;
  968.                         gettext(SCRN_LEFT+3+left,SCRN_TOP+y
  969.                             ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  970.                         for(i=1;i<width*2;i+=2)
  971.                             line[i]=bclr|(LIGHTGRAY<<4);
  972.                         puttext(SCRN_LEFT+3+left,SCRN_TOP+y
  973.                             ,SCRN_LEFT+left+width-2,SCRN_TOP+y,line);
  974.                         showmouse();
  975.                         break; } }
  976.                 if(a==2)
  977.                     s=0; }
  978.             else
  979.                 switch(i) {
  980.                     case CR:
  981.                         if(!opts || (mode&WIN_XTR && (*cur)==opts-1))
  982.                             break;
  983.                         if(mode&WIN_ACT) {
  984.                             hidemouse();
  985.                             gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  986.                                 +left+width-1,SCRN_TOP+top+height-1,win);
  987.                             for(i=1;i<(width*height*2);i+=2)
  988.                                 win[i]=lclr|(cclr<<4);
  989.                             j=(((y-top)*width)*2)+7+((width-4)*2);
  990.                             for(i=(((y-top)*width)*2)+7;i<j;i+=2)
  991.                                 win[i]=hclr|(cclr<<4);
  992.  
  993.                             puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  994.                                 +left+width-1,SCRN_TOP+top+height-1,win);
  995.                             showmouse(); }
  996.                         else if(mode&WIN_SAV) {
  997.                             hidemouse();
  998.                             puttext(sav[savnum].left,sav[savnum].top
  999.                                 ,sav[savnum].right,sav[savnum].bot
  1000.                                 ,sav[savnum].buf);
  1001.                             showmouse();
  1002.                             FREE(sav[savnum].buf);
  1003.                             savdepth--; }
  1004.                         return(*cur);
  1005.                     case ESC:
  1006.                         if(mode&WIN_ESC || (mode&WIN_CHE && changes)
  1007.                             && !(mode&WIN_SAV)) {
  1008.                             hidemouse();
  1009.                             gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  1010.                                 +left+width-1,SCRN_TOP+top+height-1,win);
  1011.                             for(i=1;i<(width*height*2);i+=2)
  1012.                                 win[i]=lclr|(cclr<<4);
  1013.                             puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT
  1014.                                 +left+width-1,SCRN_TOP+top+height-1,win);
  1015.                             showmouse(); }
  1016.                         else if(mode&WIN_SAV) {
  1017.                             hidemouse();
  1018.                             puttext(sav[savnum].left,sav[savnum].top
  1019.                                 ,sav[savnum].right,sav[savnum].bot
  1020.                                 ,sav[savnum].buf);
  1021.                             showmouse();
  1022.                             FREE(sav[savnum].buf);
  1023.                             savdepth--; }
  1024.                         return(-1); } } }
  1025.     else
  1026.         mswait(0);
  1027.     }
  1028. }
  1029.  
  1030.  
  1031. /*************************************************************************/
  1032. /* This function is a windowed input string input routine.               */
  1033. /*************************************************************************/
  1034. int uinput(int mode, char left, char top, char *prompt, char *str,
  1035.     char max, int kmode)
  1036. {
  1037.     unsigned char c,tmp[81],save_buf[2048],in_win[2048]
  1038.         ,shade[160],width,height=3;
  1039.     int i,j,plen,slen;
  1040.  
  1041. hidemouse();
  1042. plen=strlen(prompt);
  1043. if(!plen)
  1044.     slen=4;
  1045. else
  1046.     slen=6;
  1047. width=plen+slen+max;
  1048. if(mode&WIN_T2B)
  1049.     top=(scrn_len/2)-(height/2)-2;
  1050. if(mode&WIN_L2R)
  1051.     left=36-(width/2);
  1052. if(mode&WIN_SAV)
  1053.     gettext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT+left+width+1
  1054.         ,SCRN_TOP+top+height,save_buf);
  1055. i=0;
  1056. in_win[i++]='╔';
  1057. in_win[i++]=hclr|(bclr<<4);
  1058. for(c=1;c<width-1;c++) {
  1059.     in_win[i++]='═';
  1060.     in_win[i++]=hclr|(bclr<<4); }
  1061. in_win[i++]='╗';
  1062. in_win[i++]=hclr|(bclr<<4);
  1063. in_win[i++]='║';
  1064. in_win[i++]=hclr|(bclr<<4);
  1065.  
  1066. if(plen) {
  1067.     in_win[i++]=SP;
  1068.     in_win[i++]=lclr|(bclr<<4); }
  1069.  
  1070. for(c=0;prompt[c];c++) {
  1071.     in_win[i++]=prompt[c];
  1072.     in_win[i++]=lclr|(bclr<<4); }
  1073.  
  1074. if(plen) {
  1075.     in_win[i++]=':';
  1076.     in_win[i++]=lclr|(bclr<<4);
  1077.     c++; }
  1078.  
  1079. for(c=0;c<max+2;c++) {
  1080.     in_win[i++]=SP;
  1081.     in_win[i++]=lclr|(bclr<<4); }
  1082.  
  1083. in_win[i++]='║';
  1084. in_win[i++]=hclr|(bclr<<4);
  1085. in_win[i++]='╚';
  1086. in_win[i++]=hclr|(bclr<<4);
  1087. for(c=1;c<width-1;c++) {
  1088.     in_win[i++]='═';
  1089.     in_win[i++]=hclr|(bclr<<4); }
  1090. in_win[i++]='╝';
  1091. in_win[i++]=hclr|(bclr<<4);
  1092. puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT+left+width-1
  1093.     ,SCRN_TOP+top+height-1,in_win);
  1094.  
  1095. if(bclr==BLUE) {
  1096.     gettext(SCRN_LEFT+left+width,SCRN_TOP+top+1,SCRN_LEFT+left+width+1
  1097.         ,SCRN_TOP+top+(height-1),shade);
  1098.     for(c=1;c<12;c+=2)
  1099.         shade[c]=DARKGRAY;
  1100.     puttext(SCRN_LEFT+left+width,SCRN_TOP+top+1,SCRN_LEFT+left+width+1
  1101.         ,SCRN_TOP+top+(height-1),shade);
  1102.     gettext(SCRN_LEFT+left+2,SCRN_TOP+top+3,SCRN_LEFT+left+width+1
  1103.         ,SCRN_TOP+top+height,shade);
  1104.     for(c=1;c<width*2;c+=2)
  1105.         shade[c]=DARKGRAY;
  1106.     puttext(SCRN_LEFT+left+2,SCRN_TOP+top+3,SCRN_LEFT+left+width+1
  1107.         ,SCRN_TOP+top+height,shade); }
  1108.  
  1109. textattr(lclr|(bclr<<4));
  1110. if(!plen)
  1111.     gotoxy(SCRN_LEFT+left+2,SCRN_TOP+top+1);
  1112. else
  1113.     gotoxy(SCRN_LEFT+left+plen+4,SCRN_TOP+top+1);
  1114. i=getstr(str,max,kmode);
  1115. if(mode&WIN_SAV)
  1116.     puttext(SCRN_LEFT+left,SCRN_TOP+top,SCRN_LEFT+left+width+1
  1117.         ,SCRN_TOP+top+height,save_buf);
  1118. showmouse();
  1119. return(i);
  1120. }
  1121.  
  1122. /****************************************************************************/
  1123. /* Displays the message 'str' and waits for the user to select "OK"         */
  1124. /****************************************************************************/
  1125. void umsg(char *str)
  1126. {
  1127.     int i=0;
  1128.     char *ok[2]={"OK",""};
  1129.  
  1130. if(uifc_status&UIFC_INMSG)    /* non-cursive */
  1131.     return;
  1132. uifc_status|=UIFC_INMSG;
  1133. if(savdepth) savnum++;
  1134. ulist(WIN_SAV|WIN_MID,0,0,0,&i,0,str,ok);
  1135. if(savdepth) savnum--;
  1136. uifc_status&=~UIFC_INMSG;
  1137. }
  1138.  
  1139. /****************************************************************************/
  1140. /* Updates time in upper left corner of screen with current time in ASCII/  */
  1141. /* Unix format                                                                */
  1142. /****************************************************************************/
  1143. void timedisplay()
  1144. {
  1145.     static time_t savetime;
  1146.     time_t now;
  1147.  
  1148. now=time(NULL);
  1149. if(difftime(now,savetime)>=60) {
  1150.     uprintf(55,1,bclr|(cclr<<4),timestr(&now));
  1151.     savetime=now; }
  1152. }
  1153.  
  1154. /****************************************************************************/
  1155. /* Gets a string of characters from the user. Turns cursor on. Allows         */
  1156. /* Different modes - K_* macros. ESC aborts input.                          */
  1157. /* Cursor should be at END of where string prompt will be placed.           */
  1158. /****************************************************************************/
  1159. int getstr(char *outstr, int max, long mode)
  1160. {
  1161.     uchar str[256],ch,ins=0,buf[256],y;
  1162.     int i,j,k,f=0;    /* i=offset, j=length */
  1163. #ifndef __FLAT__
  1164.     union  REGS r;
  1165. #endif
  1166.  
  1167. cursor=_NORMALCURSOR;
  1168. _setcursortype(cursor);
  1169. y=wherey();
  1170. if(mode&K_EDIT) {
  1171. /***
  1172.     truncsp(outstr);
  1173. ***/
  1174.     outstr[max]=0;
  1175.     textattr(bclr|(LIGHTGRAY<<4));
  1176.     cputs(outstr);
  1177.     textattr(lclr|(bclr<<4));
  1178.     strcpy(str,outstr);
  1179.     i=j=strlen(str);
  1180.     while(inkey(1)==0) {
  1181. #ifndef __FLAT__
  1182.         if(uifc_status&UIFC_MOUSE) {
  1183.             r.w.ax=0x0006;        /* Get button release information */
  1184.             r.w.bx=0x0000;        /* Left button */
  1185.             INT_86(0x33,&r,&r);
  1186.             if(r.w.bx) {        /* Left button release same as CR */
  1187.                 cursor=_NOCURSOR;
  1188.                 _setcursortype(cursor);
  1189.                 return(i); }
  1190.             r.w.ax=0x0006;        /* Get button release information */
  1191.             r.w.bx=0x0001;        /* Right button */
  1192.             INT_86(0x33,&r,&r);
  1193.             if(r.w.bx) {        /* Right button release same as ESC */
  1194.                 cursor=_NOCURSOR;
  1195.                 _setcursortype(cursor);
  1196.                 return(-1); } }
  1197. #endif
  1198.         mswait(0);
  1199.         }
  1200.     f=inkey(0);
  1201.     gotoxy(wherex()-i,y);
  1202.     if(!isprint(f&0xff) && f!=0x5300)
  1203.         cputs(outstr);
  1204.     else {
  1205.         cprintf("%*s",i,"");
  1206.         gotoxy(wherex()-i,y);
  1207.         i=j=0; } }
  1208. else
  1209.     i=j=0;
  1210.  
  1211.  
  1212. while(1) {
  1213.  
  1214.  
  1215.     if(i>j) j=i;
  1216. #ifndef __FLAT__
  1217.     if(uifc_status&UIFC_MOUSE) {
  1218.         r.w.ax=0x0006;        /* Get button release information */
  1219.         r.w.bx=0x0000;        /* Left button */
  1220.         INT_86(0x33,&r,&r);
  1221.         if(r.w.bx)            /* Left button release same as CR */
  1222.             break;
  1223.         r.w.ax=0x0006;        /* Get button release information */
  1224.         r.w.bx=0x0001;        /* Right button */
  1225.         INT_86(0x33,&r,&r);
  1226.         if(r.w.bx) {        /* Right button release same as ESC */
  1227.             cursor=_NOCURSOR;
  1228.             _setcursortype(cursor);
  1229.             return(-1); } }
  1230. #endif
  1231.     if(f || inkey(1)) {
  1232.         if(f) k=f;            /* First key */
  1233.         else k=inkey(0);
  1234.         f=0;
  1235.         ch=k&0xff;
  1236.         if(!ch) {
  1237.             switch(k>>8) {
  1238.                 case 0x3b:    /* F1 Help */
  1239.                     #if HELP
  1240.                     help();
  1241.                     #endif
  1242.                     continue;
  1243.                 case 0x4b:    /* left arrow */
  1244.                     if(i) {
  1245.                         gotoxy(wherex()-1,y);
  1246.                         i--; }
  1247.                     continue;
  1248.                 case 0x4d:    /* right arrow */
  1249.                     if(i<j) {
  1250.                         gotoxy(wherex()+1,y);
  1251.                         i++; }
  1252.                     continue;
  1253.                 case 0x47:    /* home */
  1254.                     if(i) {
  1255.                         gotoxy(wherex()-i,y);
  1256.                         i=0; }
  1257.                     continue;
  1258.                 case 0x4f:    /* end */
  1259.                     if(i<j) {
  1260.                         gotoxy(wherex()+(j-i),y);
  1261.                         i=j; }
  1262.                     continue;
  1263.                 case 0x52:    /* insert */
  1264.                     ins=!ins;
  1265.                     if(ins)
  1266.                         cursor=_SOLIDCURSOR;
  1267.                     else
  1268.                         cursor=_NORMALCURSOR;
  1269.                     _setcursortype(cursor);
  1270.                     continue;
  1271.                 case 0x53:    /* delete */
  1272.                     if(i<j) {
  1273.                         gettext(wherex()+1,y,wherex()+(j-i),y,buf);
  1274.                         puttext(wherex(),y,wherex()+(j-i)-1,y,buf);
  1275.                         gotoxy(wherex()+(j-i),y);
  1276.                         putch(SP);
  1277.                         gotoxy(wherex()-((j-i)+1),y);
  1278.                         for(k=i;k<j;k++)
  1279.                             str[k]=str[k+1];
  1280.                         j--; }
  1281.                     continue; }
  1282.             continue; }
  1283.         if(ch==03 || ch==ESC) {
  1284.             cursor=_NOCURSOR;
  1285.             _setcursortype(cursor);
  1286.             return(-1); }
  1287.         if(ch==BS && i) {
  1288.             if(i==j) {
  1289.                 cputs("\b \b");
  1290.                 j--;
  1291.                 i--; }
  1292.             else {
  1293.                 gettext(wherex(),y,wherex()+(j-i),y,buf);
  1294.                 puttext(wherex()-1,y,wherex()+(j-i)-1,y,buf);
  1295.                 gotoxy(wherex()+(j-i),y);
  1296.                 putch(SP);
  1297.                 gotoxy(wherex()-((j-i)+2),y);
  1298.                 i--;
  1299.                 j--;
  1300.                 for(k=i;k<j;k++)
  1301.                     str[k]=str[k+1]; }
  1302.             continue; }
  1303.         if(ch==CR)
  1304.             break;
  1305.         if(ch==24) {  /* ctrl-x  */
  1306.             if(j) {
  1307.                 gotoxy(wherex()-i,y);
  1308.                 cprintf("%*s",j,"");
  1309.                 gotoxy(wherex()-j,y);
  1310.                 i=j=0; }
  1311.             continue; }
  1312.         if(ch==25) {  /* ctrl-y */
  1313.             if(i<j) {
  1314.                 cprintf("%*s",(j-i),"");
  1315.                 gotoxy(wherex()-(j-i),y);
  1316.                 j=i; }
  1317.             continue; }
  1318.         if(mode&K_NUMBER && !isdigit(ch))
  1319.             continue;
  1320.         if(mode&K_ALPHA && !isalpha(ch))
  1321.             continue;
  1322.         if((ch>=SP || (ch==1 && mode&K_MSG)) && i<max && (!ins || j<max)) {
  1323.             if(mode&K_UPPER)
  1324.                 ch=toupper(ch);
  1325.             if(ins) {
  1326.                 gettext(wherex(),y,wherex()+(j-i),y,buf);
  1327.                 puttext(wherex()+1,y,wherex()+(j-i)+1,y,buf);
  1328.                 for(k=++j;k>i;k--)
  1329.                     str[k]=str[k-1]; }
  1330.             putch(ch);
  1331.             str[i++]=ch; } }
  1332.     else
  1333.         mswait(0);
  1334.     }
  1335. str[j]=0;
  1336. if(mode&K_EDIT) {
  1337.     truncsp(str);
  1338.     if(strcmp(outstr,str))
  1339.         changes=1; }
  1340. else {
  1341.     if(j)
  1342.         changes=1; }
  1343. strcpy(outstr,str);
  1344. cursor=_NOCURSOR;
  1345. _setcursortype(cursor);
  1346. return(j);
  1347. }
  1348.  
  1349. #if defined(SCFG)
  1350. /****************************************************************************/
  1351. /* Performs printf() through local assembly routines                        */
  1352. /* Called from everywhere                                                   */
  1353. /****************************************************************************/
  1354. int lprintf(char *fmat, ...)
  1355. {
  1356.     va_list argptr;
  1357.     char sbuf[512];
  1358.     int chcount;
  1359.  
  1360. va_start(argptr,fmat);
  1361. chcount=vsprintf(sbuf,fmat,argptr);
  1362. va_end(argptr);
  1363. cputs(sbuf);
  1364. return(chcount);
  1365. }
  1366.  
  1367. #endif
  1368.  
  1369. /****************************************************************************/
  1370. /* Performs printf() through puttext() routine                                */
  1371. /****************************************************************************/
  1372. int uprintf(char x, char y, char attr, char *fmat, ...)
  1373. {
  1374.     va_list argptr;
  1375.     char str[256],buf[512];
  1376.     int i,j;
  1377.  
  1378. va_start(argptr,fmat);
  1379. vsprintf(str,fmat,argptr);
  1380. va_end(argptr);
  1381. for(i=j=0;str[i];i++) {
  1382.     buf[j++]=str[i];
  1383.     buf[j++]=attr; }
  1384. puttext(x,y,x+(i-1),y,buf);
  1385. return(i);
  1386. }
  1387.  
  1388.  
  1389. /****************************************************************************/
  1390. /* display bottom line of screen in inverse                                 */
  1391. /****************************************************************************/
  1392. void bottomline(int line)
  1393. {
  1394.     int i=4;
  1395. uprintf(i,scrn_len+1,bclr|(cclr<<4),"F1 ");
  1396. i+=3;
  1397. uprintf(i,scrn_len+1,BLACK|(cclr<<4),"Help  ");
  1398. i+=6;
  1399. if(line&BL_GET) {
  1400.     uprintf(i,scrn_len+1,bclr|(cclr<<4),"F5 ");
  1401.     i+=3;
  1402.     uprintf(i,scrn_len+1,BLACK|(cclr<<4),"Get Item  ");
  1403.     i+=10; }
  1404. if(line&BL_PUT) {
  1405.     uprintf(i,scrn_len+1,bclr|(cclr<<4),"F6 ");
  1406.     i+=3;
  1407.     uprintf(i,scrn_len+1,BLACK|(cclr<<4),"Put Item  ");
  1408.     i+=10; }
  1409. if(line&BL_INS) {
  1410.     uprintf(i,scrn_len+1,bclr|(cclr<<4),"INS ");
  1411.     i+=4;
  1412.     uprintf(i,scrn_len+1,BLACK|(cclr<<4),"Add Item  ");
  1413.     i+=10; }
  1414. if(line&BL_DEL) {
  1415.     uprintf(i,scrn_len+1,bclr|(cclr<<4),"DEL ");
  1416.     i+=4;
  1417.     uprintf(i,scrn_len+1,BLACK|(cclr<<4),"Delete Item  ");
  1418.     i+=13; }
  1419. uprintf(i,scrn_len+1,bclr|(cclr<<4),"ESC ");
  1420. i+=4;
  1421. uprintf(i,scrn_len+1,BLACK|(cclr<<4),"Exit");
  1422. i+=4;
  1423. gotoxy(i,scrn_len+1);
  1424. textattr(BLACK|(cclr<<4));
  1425. clreol();
  1426. }
  1427.  
  1428.  
  1429. /*****************************************************************************/
  1430. /* Generates a 24 character ASCII string that represents the time_t pointer  */
  1431. /* Used as a replacement for ctime()                                         */
  1432. /*****************************************************************************/
  1433. char *timestr(time_t *intime)
  1434. {
  1435.     static char str[25];
  1436.     char wday[4],mon[4],mer[3],hour;
  1437.     struct tm *gm;
  1438.  
  1439. gm=localtime(intime);
  1440. switch(gm->tm_wday) {
  1441.     case 0:
  1442.         strcpy(wday,"Sun");
  1443.         break;
  1444.     case 1:
  1445.         strcpy(wday,"Mon");
  1446.         break;
  1447.     case 2:
  1448.         strcpy(wday,"Tue");
  1449.         break;
  1450.     case 3:
  1451.         strcpy(wday,"Wed");
  1452.         break;
  1453.     case 4:
  1454.         strcpy(wday,"Thu");
  1455.         break;
  1456.     case 5:
  1457.         strcpy(wday,"Fri");
  1458.         break;
  1459.     case 6:
  1460.         strcpy(wday,"Sat");
  1461.         break; }
  1462. switch(gm->tm_mon) {
  1463.     case 0:
  1464.         strcpy(mon,"Jan");
  1465.         break;
  1466.     case 1:
  1467.         strcpy(mon,"Feb");
  1468.         break;
  1469.     case 2:
  1470.         strcpy(mon,"Mar");
  1471.         break;
  1472.     case 3:
  1473.         strcpy(mon,"Apr");
  1474.         break;
  1475.     case 4:
  1476.         strcpy(mon,"May");
  1477.         break;
  1478.     case 5:
  1479.         strcpy(mon,"Jun");
  1480.         break;
  1481.     case 6:
  1482.         strcpy(mon,"Jul");
  1483.         break;
  1484.     case 7:
  1485.         strcpy(mon,"Aug");
  1486.         break;
  1487.     case 8:
  1488.         strcpy(mon,"Sep");
  1489.         break;
  1490.     case 9:
  1491.         strcpy(mon,"Oct");
  1492.         break;
  1493.     case 10:
  1494.         strcpy(mon,"Nov");
  1495.         break;
  1496.     case 11:
  1497.         strcpy(mon,"Dec");
  1498.         break; }
  1499. if(gm->tm_hour>12) {
  1500.     strcpy(mer,"pm");
  1501.     hour=gm->tm_hour-12; }
  1502. else {
  1503.     if(!gm->tm_hour)
  1504.         hour=12;
  1505.     else
  1506.         hour=gm->tm_hour;
  1507.     strcpy(mer,"am"); }
  1508. sprintf(str,"%s %s %02d %4d %02d:%02d %s",wday,mon,gm->tm_mday,1900+gm->tm_year
  1509.     ,hour,gm->tm_min,mer);
  1510. return(str);
  1511. }
  1512.  
  1513. /****************************************************************************/
  1514. /* Truncates white-space chars off end of 'str' and terminates at first tab */
  1515. /****************************************************************************/
  1516. void truncsp(char *str)
  1517. {
  1518.     char c,tmp[256];
  1519.  
  1520. tmp[0]=TAB;
  1521. tmp[1]=0;
  1522. str[strcspn(str,tmp)]=0;
  1523. c=strlen(str);
  1524. while(c && (uchar)str[c-1]<=SP) c--;
  1525. str[c]=0;
  1526. }
  1527.  
  1528. void upop(char *str)
  1529. {
  1530.     static char sav[26*3*2];
  1531.     char buf[26*3*2];
  1532.     int i,j,k;
  1533.  
  1534. hidemouse();
  1535. if(!str) {
  1536.     puttext(28,12,53,14,sav);
  1537.     showmouse();
  1538.     return; }
  1539. gettext(28,12,53,14,sav);
  1540. memset(buf,SP,25*3*2);
  1541. for(i=1;i<26*3*2;i+=2)
  1542.     buf[i]=(hclr|(bclr<<4));
  1543. buf[0]='┌';
  1544. for(i=2;i<25*2;i+=2)
  1545.     buf[i]='─';
  1546. buf[i]='┐'; i+=2;
  1547. buf[i]='│'; i+=2;
  1548. i+=2;
  1549. k=strlen(str);
  1550. i+=(((23-k)/2)*2);
  1551. for(j=0;j<k;j++,i+=2) {
  1552.     buf[i]=str[j];
  1553.     buf[i+1]|=BLINK; }
  1554. i=((25*2)+1)*2;
  1555. buf[i]='│'; i+=2;
  1556. buf[i]='└'; i+=2;
  1557. for(;i<((26*3)-1)*2;i+=2)
  1558.     buf[i]='─';
  1559. buf[i]='┘';
  1560.  
  1561. puttext(28,12,53,14,buf);
  1562. showmouse();
  1563. }
  1564.  
  1565. #if HELP
  1566. /************************************************************/
  1567. /* Help (F1) key function. Uses helpbuf as the help input.    */
  1568. /************************************************************/
  1569. void help()
  1570. {
  1571.     char *savscrn,*buf,inverse=0,high=0
  1572.         ,hbuf[HELPBUF_SIZE],str[256];
  1573.     uint i,j,k,len;
  1574.     long l;
  1575.     FILE *fp;
  1576. #ifndef __FLAT__
  1577.     union  REGS r;
  1578. #endif
  1579.  
  1580. _setcursortype(_NOCURSOR);
  1581.  
  1582. if((savscrn=(char *)MALLOC(80*25*2))==NULL) {
  1583.     cprintf("UIFC: error allocating %u bytes\r\n",80*25*2);
  1584.     _setcursortype(cursor);
  1585.     return; }
  1586. if((buf=(char *)MALLOC(76*21*2))==NULL) {
  1587.     cprintf("UIFC: error allocating %u bytes\r\n",76*21*2);
  1588.     FREE(savscrn);
  1589.     _setcursortype(cursor);
  1590.     return; }
  1591. hidemouse();
  1592. gettext(1,1,80,25,savscrn);
  1593. memset(buf,SP,76*21*2);
  1594. for(i=1;i<76*21*2;i+=2)
  1595.     buf[i]=(hclr|(bclr<<4));
  1596. buf[0]='┌';
  1597. for(i=2;i<30*2;i+=2)
  1598.     buf[i]='─';
  1599. buf[i]='┤'; i+=4;
  1600. buf[i]='O'; i+=2;
  1601. buf[i]='n'; i+=2;
  1602. buf[i]='l'; i+=2;
  1603. buf[i]='i'; i+=2;
  1604. buf[i]='n'; i+=2;
  1605. buf[i]='e'; i+=4;
  1606. buf[i]='H'; i+=2;
  1607. buf[i]='e'; i+=2;
  1608. buf[i]='l'; i+=2;
  1609. buf[i]='p'; i+=4;
  1610. buf[i]='├'; i+=2;
  1611. for(j=i;j<i+(30*2);j+=2)
  1612.     buf[j]='─';
  1613. i=j;
  1614. buf[i]='┐'; i+=2;
  1615. j=i;    /* leave i alone */
  1616. for(k=0;k<19;k++) {         /* the sides of the box */
  1617.     buf[j]='│'; j+=2;
  1618.     j+=(74*2);
  1619.     buf[j]='│'; j+=2; }
  1620. buf[j]='└'; j+=2;
  1621. for(k=j;k<j+(23*2);k+=2)
  1622.     buf[k]='─';
  1623. buf[k]='┤'; k+=4;
  1624. buf[k]='H'; k+=2;
  1625. buf[k]='i'; k+=2;
  1626. buf[k]='t'; k+=4;
  1627. buf[k]='a'; k+=2;
  1628. buf[k]='n'; k+=2;
  1629. buf[k]='y'; k+=4;
  1630. buf[k]='k'; k+=2;
  1631. buf[k]='e'; k+=2;
  1632. buf[k]='y'; k+=4;
  1633. buf[k]='t'; k+=2;
  1634. buf[k]='o'; k+=4;
  1635. buf[k]='c'; k+=2;
  1636. buf[k]='o'; k+=2;
  1637. buf[k]='n'; k+=2;
  1638. buf[k]='t'; k+=2;
  1639. buf[k]='i'; k+=2;
  1640. buf[k]='n'; k+=2;
  1641. buf[k]='u'; k+=2;
  1642. buf[k]='e'; k+=4;
  1643. buf[k]='├'; k+=2;
  1644. for(j=k;j<k+(24*2);j+=2)
  1645.     buf[j]='─';
  1646. buf[j]='┘';
  1647.  
  1648. if(!helpbuf) {
  1649.     if((fp=_fsopen(helpixbfile,"rb",SH_DENYWR))==NULL)
  1650.         sprintf(hbuf," ERROR  Cannot open help index:\r\n          %s"
  1651.             ,helpixbfile);
  1652.     else {
  1653.         l=-1L;
  1654.         while(!feof(fp)) {
  1655.             fread(str,12,1,fp);
  1656.             str[12]=0;
  1657.             fread(&k,2,1,fp);
  1658.             if(stricmp(str,helpfile) || k!=helpline) {
  1659.                 fseek(fp,4,SEEK_CUR);
  1660.                 continue; }
  1661.             fread(&l,4,1,fp);
  1662.             break; }
  1663.         fclose(fp);
  1664.         if(l==-1L)
  1665.             sprintf(hbuf," ERROR  Cannot locate help key (%s:%u) in:\r\n"
  1666.                 "         %s",helpfile,helpline,helpixbfile);
  1667.         else {
  1668.             if((fp=_fsopen(helpdatfile,"rb",SH_DENYWR))==NULL)
  1669.                 sprintf(hbuf," ERROR  Cannot open help file:\r\n          %s"
  1670.                     ,helpdatfile);
  1671.             else {
  1672.                 fseek(fp,l,SEEK_SET);
  1673.                 fread(hbuf,HELPBUF_SIZE,1,fp);
  1674.                 fclose(fp); } } } }
  1675. else
  1676.     strcpy(hbuf,helpbuf);
  1677.  
  1678. len=strlen(hbuf);
  1679.  
  1680. i+=78*2;
  1681. for(j=0;j<len;j++,i+=2) {
  1682.     if(hbuf[j]==LF) {
  1683.         while(i%(76*2)) i++;
  1684.         i+=2; }
  1685.     else if(hbuf[j]==2) {         /* Ctrl-b toggles inverse */
  1686.         inverse=!inverse;
  1687.         i-=2; }
  1688.     else if(hbuf[j]==1) {         /* Ctrl-a toggles high intensity */
  1689.         high=!high;
  1690.         i-=2; }
  1691.     else if(hbuf[j]!=CR) {
  1692.         buf[i]=hbuf[j];
  1693.         buf[i+1]=inverse ? (bclr|(cclr<<4))
  1694.             : high ? (hclr|(bclr<<4)) : (lclr|(bclr<<4)); } }
  1695. puttext(3,3,78,23,buf);
  1696. showmouse();
  1697. while(1) {
  1698.     if(inkey(1)) {
  1699.         inkey(0);
  1700.         break; }
  1701. #ifndef __FLAT__
  1702.     if(uifc_status&UIFC_MOUSE) {
  1703.         r.w.ax=0x0006;        /* Get button release information */
  1704.         r.w.bx=0x0000;        /* Left button */
  1705.         INT_86(0x33,&r,&r);
  1706.         if(r.w.bx)            /* Left button release same as CR */
  1707.             break;
  1708.         r.w.ax=0x0006;        /* Get button release information */
  1709.         r.w.bx=0x0001;        /* Right button */
  1710.         INT_86(0x33,&r,&r);
  1711.         if(r.w.bx)            /* Left button release same as CR */
  1712.             break; }
  1713. #endif
  1714.     mswait(0);
  1715.     }
  1716.  
  1717. hidemouse();
  1718. puttext(1,1,80,25,savscrn);
  1719. showmouse();
  1720. FREE(savscrn);
  1721. FREE(buf);
  1722. _setcursortype(cursor);
  1723. }
  1724. #endif
  1725.  
  1726. #if defined(__WIN32__) && !defined(__DPMI32__)
  1727.  
  1728. int delay(int ms)
  1729. {
  1730.     clock_t start;
  1731.  
  1732. start=clock();
  1733. while(clock()-start<ms)
  1734.     ;
  1735. }
  1736. #endif
  1737.