home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / cxl-1.zip / CXLDEMO.C < prev    next >
C/C++ Source or Header  |  1989-03-27  |  44KB  |  1,355 lines

  1. /* ┌┬───────────────────────────────────────────────────────────────────┬┐
  2.    ││                                                                   ││
  3.    ││                     CXL Demonstration Program                     ││
  4.    ││                                                                   ││
  5.    ││              CXL is Copyright (c) 1987-1989 by Mike Smedley       ││
  6.    ││                                                                   ││
  7.    ││               Syntax:  CXLDEMO [-switches]                        ││
  8.    ││                                                                   ││
  9.    ││                        -c = CGA snow reduction                    ││
  10.    ││                        -b = BIOS screen writing                   ││
  11.    ││                        -m = force monochrome text attributes      ││
  12.    ││                                                                   ││
  13.    ││               Compiler command lines:                             ││
  14.    ││                                                                   ││
  15.    ││                MSC:    cl -Ox cxldemo.c cxlmss.lib                ││
  16.    ││                PC:     pc -c -d__POWERC__ myfile.c                ││
  17.    ││                        pcl myfile.mix ;cxlpcm.mix                 ││
  18.    ││                QC:     qcl -Ox cxldemo.c cxlmss.lib               ││
  19.    ││                TC:     tcc -Z -O cxldemo.c cxltcs.lib             ││
  20.    ││                ZTC:    ztc -msi -o cxldemo.c cxlzts.lib           ││
  21.    ││                                                                   ││
  22.    └┴───────────────────────────────────────────────────────────────────┴┘ */
  23.  
  24. /*---------------------------------------------------------------------------*/
  25.  
  26. /* header files */
  27. #include <conio.h>
  28. #include <ctype.h>
  29. #include <dos.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include "cxldef.h"
  34. #include "cxlkey.h"
  35. #include "cxlmou.h"
  36. #include "cxlstr.h"
  37. #include "cxlvid.h"
  38. #include "cxlwin.h"
  39.  
  40. #if defined(__TURBOC__)                             /* Turbo C */
  41.     #include <dir.h>
  42. #else
  43.     #include <direct.h>                             /* all others */
  44. #endif
  45.  
  46. #if defined(M_I86) && !defined(__ZTC__)             /* MSC/QuickC */
  47.     #define bioskey(a)       _bios_keybrd(a)
  48.     #define findfirst(a,b,c) _dos_findfirst(a,c,b)
  49.     #define findnext(a)      _dos_findnext(a)
  50.     #define ffblk            find_t
  51.     #define ff_name          name
  52. #elif defined(__ZTC__)                              /* Zortech C/C++ */
  53.     #define ffblk             FIND
  54.     #define ff_name           name
  55.     #define ff_attrib         attribute
  56. #endif
  57.  
  58. /*---------------------------------------------------------------------------*/
  59.  
  60. /* function prototypes */
  61. static void activate_demo (void);
  62. static void add_shadow    (void);
  63. static void chg_attr_demo (void);
  64. static void chg_bord_demo (void);
  65. static void chg_wind_attr (int battr,int wattr);
  66. static int  check_date    (char *buf);
  67. static void close_windows (void);
  68. static void confirm_quit  (void);
  69. static void copy_demo     (void);
  70. static void cxlinfo       (void);
  71. static void datademo      (void);
  72. static void directory     (void);
  73. static void display_date  (void);
  74. static void disp_sure_msg (void);
  75. static void display_title (int tpos);
  76. static void do_nothing    (void);
  77. static void error_exit    (int errnum);
  78. static void execute       (void);
  79. static int  find_first    (char *filespec,struct ffblk *ffblk);
  80. static int  find_next     (struct ffblk *ffblk);
  81. static void hide_demo     (void);
  82. static void horz_line     (int wrow,int wcol,int count,int attr);
  83. static void initialize    (void);
  84. static void line_inp_demo (void);
  85. static void main_menu     (void);
  86. static void menudemo      (void);
  87. static void move_bar_down (void);
  88. static void move_demo     (void);
  89. static void move_window   (int nsrow,int nscol);
  90. static void normal_exit   (void);
  91. static void open_back_wind(void);
  92. static void open_stat_wind(void);
  93. static void open_titl_wind(void);
  94. static void os_shell      (void);
  95. static void parse_cmd_line(int argc,char *argv[]);
  96. static void parse_date    (char *buf,int *month,int *day,int *year);
  97. static void pick_compiler (void);
  98. static void pickdemo      (void);
  99. static void popup_demo    (void);
  100. static void pre_menu1     (void);
  101. static void pre_menu2     (void);
  102. static void pre_pick1     (void);
  103. static void press_a_key   (int wrow);
  104. static void pulldown_demo (void);
  105. static void quit_window   (void);
  106. static void resize_demo   (void);
  107. static void restore_cursor(void);
  108. static void scroll_demo   (void);
  109. static void setup_menu    (void);
  110. static void short_delay   (void);
  111. static void size_window   (int nerow,int necol);
  112. static void text_line_demo(void);
  113. static void title_demo    (void);
  114. static void toggle_yn     (void);
  115. static void update_clock  (void);
  116. static void vert_line     (int wrow,int wcol,int count,int attr);
  117. static void you_selected  (char *str);
  118. static void windemo       (void);
  119.  
  120. /*---------------------------------------------------------------------------*/
  121.  
  122. /* miscellaneous global variables */
  123. static int *savescrn,crow,ccol;
  124. static WINDOW w[10];
  125.  
  126. /*---------------------------------------------------------------------------*/
  127.  
  128. /* fields used in data entry demo */
  129. static char date[7],firstname[16],initial[2],lastname[26],address[41],city[21],
  130.             state[3],zipcode[10],phone[11],compiler[16],amtenc[8],comments[41],
  131.             ssan[10];
  132.  
  133. /*---------------------------------------------------------------------------*/
  134.  
  135. /* months table */
  136. static char *months[]= {
  137.     "January","February","March","April","May","June","July","August",
  138.     "September","October","November","December",NULL
  139. };
  140.  
  141. /* printer ports table */
  142. static char *prn_ports[]= { "PRN","LPT1","LPT2","COM1","COM2",NULL };
  143.  
  144. /* error message table */
  145. static char *error_text[]= {
  146.     NULL,   /* errnum =  0, no error        */
  147.     NULL,   /* errnum == 1, windowing error */
  148.     "Syntax:  CXLDEMO [-switches]\n\n"
  149.         "\t -c = CGA snow reduction\n"
  150.         "\t -b = BIOS screen writing\n"
  151.         "\t -m = force monochrome text attributes",
  152.     "Memory allocation error"
  153. };
  154.  
  155. /* compiler table */
  156. static char *compilers[]=
  157.     { "Microsoft C","Power C","Quick C","Turbo C","Zortech C/C++" };
  158.  
  159. /*---------------------------------------------------------------------------*/
  160.  
  161. /* help category numbers */
  162. #define H_GLOBAL    1
  163. #define H_WINDOWING 2
  164. #define H_MENUING   3
  165. #define H_LISTPICK  4
  166. #define H_STRPICK   5
  167. #define H_FILEPICK  6
  168. #define H_DATAENTRY 7
  169. #define H_EDITKEYS  8
  170. #define H_DATE      9
  171. #define H_FIRSTNAME 10
  172. #define H_INITIAL   11
  173. #define H_LASTNAME  12
  174. #define H_CITY      13
  175. #define H_STATE     14
  176. #define H_ZIPCODE   15
  177. #define H_COMPILER  16
  178. #define H_AMOUNT    17
  179. #define H_NUMERIC   18
  180. #define H_PULLDOWN  19
  181. #define H_FILE      20
  182. #define H_EDITING   21
  183. #define H_LOAD      22
  184. #define H_SAVE      23
  185. #define H_RENAME    24
  186. #define H_NEW       25
  187. #define H_DIRECTORY 26
  188. #define H_EXECUTE   27
  189. #define H_OSSHELL   28
  190. #define H_QUIT      29
  191. #define H_SCROLL    30
  192. #define H_CHGATTR   31
  193. #define H_CHGBORD   32
  194. #define H_WINTITLE  33
  195. #define H_RESIZE    34
  196. #define H_TEXTLINE  35
  197. #define H_WINMOVE   36
  198. #define H_WINHIDE   37
  199. #define H_ACTIVATE  38
  200. #define H_WINCOPY   39
  201.  
  202. /*---------------------------------------------------------------------------*/
  203.  
  204. /* miscellaneous defines */
  205. #define SHORT_DELAY 11
  206.  
  207. /*---------------------------------------------------------------------------*/
  208.  
  209. void main(int argc,char *argv[])
  210. {
  211.     initialize();
  212.     parse_cmd_line(argc,argv);
  213.     open_back_wind();
  214.     open_stat_wind();
  215.     open_titl_wind();
  216.     main_menu();
  217.     normal_exit();
  218. }
  219.  
  220. /*---------------------------------------------------------------------------*/
  221.  
  222. static void activate_demo(void)
  223. {
  224.     register int i;
  225.  
  226.     if((w[5]=wopen(9,44,22,78,1,LCYAN|_CYAN,WHITE|_CYAN))==0) error_exit(1);
  227.     whelpcat(H_ACTIVATE);
  228.     wputs("\n  CXL's wactiv() is used to"
  229.           "\n  activate a window, making"
  230.           "\n  it available for windowing"
  231.           "\n  operations.");
  232.     press_a_key(6);
  233.  
  234.     /* activate windows 0 thru 5 in order, back to front */
  235.     for(i=0;i<6;i++) {
  236.         wactiv(w[i]);
  237.         short_delay();
  238.     }
  239. }
  240.  
  241. /*---------------------------------------------------------------------------*/
  242.  
  243. /* this function will add a shadow to the active window */
  244.  
  245. static void add_shadow(void)
  246. {
  247.     wshadow(LGREY|_BLACK);
  248. }
  249.  
  250. /*---------------------------------------------------------------------------*/
  251.  
  252. static void chg_attr_demo(void)
  253. {
  254.     if((w[1]=wopen(9,35,22,65,0,YELLOW|_BLUE,LCYAN|_BLUE))==0) error_exit(1);
  255.     whelpcat(H_CHGATTR);
  256.     wputs("\n  The wchgattr() function"
  257.           "\n  allows you to change the"
  258.           "\n  attribute of the active"
  259.           "\n  window.");
  260.     press_a_key(6);
  261.     chg_wind_attr(LMAGENTA|_BLUE,WHITE|_GREEN);
  262.     chg_wind_attr(LGREEN|_LGREY,LMAGENTA|_RED);
  263.     chg_wind_attr(YELLOW|_BROWN,LCYAN|_BLUE);
  264.     chg_wind_attr(YELLOW|_MAGENTA,YELLOW|_MAGENTA);
  265.     chg_wind_attr(LRED|_MAGENTA,WHITE|_MAGENTA);
  266. }
  267.  
  268. /*---------------------------------------------------------------------------*/
  269.  
  270. static void chg_bord_demo(void)
  271. {
  272.     register int i;
  273.  
  274.     whelpcat(H_CHGBORD);
  275.     wtextattr(LGREEN|_MAGENTA);
  276.     wputs("\n\n  The wborder() function is"
  277.             "\n  used to change the style"
  278.             "\n  of the window's border.");
  279.     press_a_key(10);
  280.     for(i=5;i>=0;i--) {
  281.         short_delay();
  282.         wborder(i);
  283.     }
  284.     short_delay();
  285. }
  286.  
  287. /*---------------------------------------------------------------------------*/
  288.  
  289. static void chg_wind_attr(int battr,int wattr)
  290. {
  291.     wchgattr(battr,wattr);
  292.     short_delay();
  293. }
  294.  
  295. /*---------------------------------------------------------------------------*/
  296.  
  297. /* this function validates the Date field in the data entry window */
  298.  
  299. static int check_date(char *buf)
  300. {
  301.     int year,month,day;
  302.  
  303.     if(!strblank(buf)) {
  304.         parse_date(buf,&month,&day,&year);
  305.  
  306.         /* validate numeric values */
  307.         if(month<1 || month>12) {
  308.             wperror("Invalid month");
  309.             return(1);
  310.         }
  311.         if(day<1 || day>31) {
  312.             wperror("Invalid day");
  313.             return(3);
  314.         }
  315.     }
  316.  
  317.     /* return normally */
  318.     return(0);
  319. }
  320.  
  321. /*---------------------------------------------------------------------------*/
  322.  
  323. static void close_windows(void)
  324. {
  325.     register int i;
  326.  
  327.     for(i=0;i<8;i++) {
  328.         wclose();
  329.         short_delay();
  330.     }
  331. }
  332.  
  333. /*---------------------------------------------------------------------------*/
  334.  
  335. /* this function pops open a window and confirms that the user really */
  336. /* wants to quit the demo.  If so, it terminates the demo program.    */
  337.  
  338. static void confirm_quit(void)
  339. {
  340.     int ch;
  341.     static int busy=NO;
  342.  
  343.     if(busy) return; else busy=YES;     /* avoid recursion */
  344.     if(_mouse&MS_CURS) mshidecur();
  345.     if(!wopen(9,26,13,55,0,WHITE|_BROWN,WHITE|_BROWN)) error_exit(1);
  346.     add_shadow();
  347.     wputs("\n Quit demo, are you sure? \033A\156Y\b");
  348.     clearkeys();
  349.     showcur();
  350.     ch=wgetchf("YyNn",'Y');
  351.     if(toupper(ch)=='Y') normal_exit();
  352.     wclose();
  353.     hidecur();
  354.     if(_mouse&MS_CURS) msshowcur();
  355.     busy=NO;
  356. }
  357.  
  358. /*---------------------------------------------------------------------------*/
  359.  
  360. static void copy_demo(void)
  361. {
  362.     whelpcat(H_WINCOPY);
  363.     wtextattr(LCYAN|_CYAN);
  364.     wputs("\n\n  The wcopy() function is used"
  365.             "\n  to copy the active window.");
  366.     press_a_key(9);
  367.     if(!wcopy(1,1)) error_exit(1);
  368.     short_delay();
  369.     if(!wcopy(3,40)) error_exit(1);
  370.     short_delay();
  371.     short_delay();
  372. }
  373.  
  374. /*---------------------------------------------------------------------------*/
  375.  
  376. static void cxlinfo(void)
  377. {
  378.     if(!wopen(4,6,20,72,0,LMAGENTA|_RED,LMAGENTA|_RED)) error_exit(1);
  379.     add_shadow();
  380.     wcenters(1,LCYAN|_RED,"CXL Version 5.0");
  381.     wcenters(2,LCYAN|_RED,"Written by Mike Smedley");
  382.     wcenters(3,LCYAN|_RED,"Copyright (c) 1987-1989  All Rights Reserved");
  383.     wgotoxy(5,0);
  384.     wputs("    CXL is a User-Supported C function library  that supports\n");
  385.     wputs("    Microsoft C, QuickC, Turbo C, Power C, and Zortech C/C++.\n");
  386.     wputs("    There are  over 230  functions  available for  your  use.\n");
  387.     wputs("    When  you  register you  get  the remaining memory models\n");
  388.     wputs("    supported by  your  compiler  and the  full  source code!\n");
  389.     wputs("    CXL's  routines  are  written  in  100%  well-documented,\n");
  390.     wputs("    easy-to-modify  C code.  See  documentation  for details.\n\n");
  391.     press_a_key(13);
  392.     wclose();
  393.     move_bar_down();
  394. }
  395.  
  396. /*---------------------------------------------------------------------------*/
  397.  
  398. static void datademo(void)
  399. {
  400.     register int ch,mode=0;
  401.  
  402.     if(!wopen(2,8,20,70,1,LCYAN|_BLUE,LCYAN|_BLUE)) error_exit(1);
  403.     add_shadow();
  404.     wtitle("[ CXL Order Form ]",TLEFT,LCYAN|_BLUE);
  405.     wmessage(" [Esc]=Exit ",1,45,LCYAN|_BLUE);
  406.     whelpushc(H_EDITKEYS);
  407.     do {
  408.         winpbeg(LGREEN|_LGREY,WHITE|_LGREY);
  409.         wprints( 1, 3,WHITE|_BLUE,"Date");
  410.         winpdef( 1,16,date,"<01>#'/'<0123>#'/'<89>#",0,mode,check_date,H_DATE);
  411.         winpfba(NULL,display_date);
  412.         wprints( 3, 3,WHITE|_BLUE,"First Name");
  413.         winpdef( 3,16,firstname,"MMMMMMMMMMMMMMM",0,mode,NULL,H_FIRSTNAME);
  414.         wprints( 3,37,WHITE|_BLUE,"Initial");
  415.         winpdef( 3,47,initial,"U'.'",0,mode,NULL,H_INITIAL);
  416.         wprints( 5, 3,WHITE|_BLUE,"Last Name");
  417.         winpdef( 5,16,lastname,"MMMMMMMMMMMMMMMMMMMMMMMMM",0,mode,NULL
  418.             ,H_LASTNAME);
  419.         wprints( 7, 3,WHITE|_BLUE,"Address");
  420.         winpdef( 7,16,address,"****************************************",'M'
  421.             ,mode,NULL,0);
  422.         wprints( 9, 3,WHITE|_BLUE,"City");
  423.         winpdef( 9,16,city,"MMMMMMMMMMMMMMMMMMMM",0,mode,NULL,H_CITY);
  424.         wprints( 9,41,WHITE|_BLUE,"State");
  425.         winpdef( 9,50,state,"UU",0,mode,NULL,H_STATE);
  426.         wprints(11, 3,WHITE|_BLUE,"Zip Code");
  427.         winpdef(11,16,zipcode,"#####'-'%%%%",0,mode,NULL,H_ZIPCODE);
  428.         wprints(11,31,WHITE|_BLUE,"Phone");
  429.         winpdef(11,40,phone,"'('###') '###'-'####",0,mode,NULL,0);
  430.         wprints(13, 3,WHITE|_BLUE,"Compiler");
  431.         winpdef(13,16,compiler,"***************",'M',mode,NULL,H_COMPILER);
  432.         winpfba(pick_compiler,NULL);
  433.         wprints(13,37,WHITE|_BLUE,"Amount");
  434.         winpdef(13,46,amtenc,"'$'99999.99",'9',mode,NULL,H_AMOUNT);
  435.         wprints(15, 3,WHITE|_BLUE,"Comments");
  436.         winpdef(15,16,comments,"****************************************",0
  437.             ,mode,NULL,0);
  438.         if(winpread()) break;
  439.         if(!wopen(9,24,13,57,0,WHITE|_CYAN,WHITE|_CYAN)) error_exit(1);
  440.         add_shadow();
  441.         wputs("\n Is this information correct? \033A\076Y\b");
  442.         clearkeys();
  443.         ch=wgetchf("YyNn",'Y');
  444.         wclose();
  445.         mode=1;
  446.     } while(toupper(ch)!='Y');
  447.     whelpopc();
  448.     line_inp_demo();
  449.     wclose();
  450.     hidecur();
  451.     move_bar_down();
  452. }
  453.  
  454. /*---------------------------------------------------------------------------*/
  455.  
  456. /* this function displays a quick 'n' dirty directory of current path */
  457.  
  458. static void directory(void)
  459. {
  460.     static int busy=NO;
  461.     char filespec[41],file1[13],file2[13];
  462.     int i,done,lines,files;
  463.     struct ffblk ffblk;
  464.  
  465.     if(busy) return; else busy=YES;     /* avoid recursion */
  466.     strcpy(filespec,"*.*");
  467.     if(_mouse) mshidecur();
  468.     showcur();
  469.     if(!wopen(4,14,20,59,0,LRED|_MAGENTA,LCYAN|_BLUE)) error_exit(1);
  470.     wtitle("[ Directory ]",TCENTER,LRED|_MAGENTA);
  471.     if(!wopen(6,6,8,49,0,LMAGENTA|_RED,LMAGENTA|_RED)) error_exit(1);
  472.     wtitle("[ Filespec ]",TCENTER,LMAGENTA|_RED);
  473.     winpbeg(BLUE|_LGREY,BLUE|_LGREY);
  474.     winpdef(0,1,filespec,"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",'U',2
  475.         ,NULL,H_EDITKEYS);
  476.     i=winpread();
  477.     wclose();
  478.     if(!i) {
  479.         wclear();
  480.         wtextattr(LCYAN|_BLUE);
  481.         lines=files=0;
  482.         done=find_first(filespec,&ffblk);
  483.         for(;;) {
  484.             if(done) break;
  485.             files++;
  486.             strcpy(file1,ffblk.ff_name);
  487.             if(!done) done=find_next(&ffblk);
  488.             strcpy(file2,ffblk.ff_name);
  489.             if(done)
  490.                 file2[0]='\0';
  491.             else {
  492.                 files++;
  493.                 done=find_next(&ffblk);
  494.             }
  495.             if(done)
  496.                 ffblk.ff_name[0]='\0';
  497.             else
  498.                 files++;
  499.             wprintf(" %-15s%-15s%s\n",file1,file2,ffblk.ff_name);
  500.             lines++;
  501.             if(lines>=14) {
  502.                 wtextattr(LGREEN|_BLUE);
  503.                 wprintf(" Press a key to continue....");
  504.                 wtextattr(LCYAN|_BLUE);
  505.                 i=waitkey();
  506.                 wprintf("\r");
  507.                 if(i==ESC) break;
  508.                 lines=0;
  509.             }
  510.             if(!done) done=find_next(&ffblk);
  511.         }
  512.         wtextattr(LGREEN|_BLUE);
  513.         wprintf(" Files found:  %d  Press a key....",files);
  514.         waitkey();
  515.     }
  516.     hidecur();
  517.     wclose();
  518.     if(_mouse) msshowcur();
  519.     busy=NO;
  520. }
  521.  
  522. /*---------------------------------------------------------------------------*/
  523.  
  524. /* this function displays the literal equivalent of the MMDDYY */
  525. /* date that the user entered into the Date field.  It is      */
  526. /* called immediately after the user leaves the Date field.    */
  527.  
  528. static void display_date(void)
  529. {
  530.     struct _field_t *field;
  531.     int month,day,year;
  532.  
  533.     /* find address of Date field's record */
  534.     if((field=winpffind(1,16))==NULL) error_exit(1);
  535.  
  536.     /* set cursor and clear to end of window's line */
  537.     hidecur();
  538.     wgotoxy(1,37);
  539.     wclreol();
  540.  
  541.     /* don't display date string if Date field is empty */
  542.     if(!strblank(field->buf)) {
  543.  
  544.         /* parse string date into numeric values */
  545.         parse_date(field->buf,&month,&day,&year);
  546.  
  547.         /* display date */
  548.         wprintf("%s %d, %d",months[month-1],day,year);
  549.     }
  550.     showcur();
  551. }
  552.  
  553. /*---------------------------------------------------------------------------*/
  554.  
  555. /* this function is called by the pull-down demo for a prompt */
  556.  
  557. static void disp_sure_msg(void)
  558. {
  559.     wprints(0,2,WHITE|_BLUE,"Are you sure?");
  560. }
  561.  
  562. /*---------------------------------------------------------------------------*/
  563.  
  564. static void display_title(int tpos)
  565. {
  566.     wtitle("[ My Title ]",tpos,LCYAN|_GREEN);
  567.     short_delay();
  568. }
  569.  
  570. /*---------------------------------------------------------------------------*/
  571.  
  572. /* this function is used as a dummy function for */
  573. /* several menu items in the pull-down demo      */
  574.  
  575. static void do_nothing(void)
  576. {
  577. }
  578.  
  579. /*---------------------------------------------------------------------------*/
  580.  
  581. /* this function handles abnormal termination.  If it is passed an  */
  582. /* error code of 1, then it is a windowing system error.  Otherwise */
  583. /* the error message is looked up in the error message table.       */
  584.  
  585. static void error_exit(int errnum)
  586. {
  587.     if(errnum) {
  588.         printf("\n%s\n",(errnum==1)?werrmsg():error_text[errnum]);
  589.     exit(errnum);
  590.     }
  591. }
  592.  
  593. /*---------------------------------------------------------------------------*/
  594.  
  595. /* this function is used by the pull-down demo. */
  596. /* It is used to execute a DOS command.         */
  597.  
  598. static void execute(void)
  599. {
  600.     static int busy=NO;
  601.     char command[61];
  602.     int *scrn;
  603.  
  604.     if(busy) return; else busy=YES;     /* avoid recursion */
  605.     showcur();
  606.     if(_mouse) mshidecur();
  607.     if(!wopen(8,7,10,70,0,LMAGENTA|_RED,LMAGENTA|_RED)) error_exit(1);
  608.     wtitle("[ Execute DOS Command ]",TCENTER,LMAGENTA|_RED);
  609.     winpbeg(BLUE|_LGREY,BLUE|_LGREY);
  610.     winpdef(0,1,command,"****************************************"
  611.         "********************",0,0,NULL,H_EDITKEYS);
  612.     if(!winpread()) {
  613.         if((scrn=ssave())==NULL) error_exit(3);
  614.         cclrscrn(LGREY|_BLACK);
  615.         system(command);
  616.         printf("\nPress any key to continue....");
  617.         waitkey();
  618.         srestore(scrn);
  619.     }
  620.     hidecur();
  621.     if(_mouse) msshowcur();
  622.     wclose();
  623.     busy=NO;
  624. }
  625.  
  626. /*---------------------------------------------------------------------------*/
  627.  
  628. static int find_first(char *filespec,struct ffblk *ffblk)
  629. {
  630.     register int done;
  631.  
  632. #if defined(__ZTC__)
  633.     struct ffblk *pffblk;
  634.     pffblk=findfirst(filespec,0);
  635.     if(pffblk==NULL)
  636.         done=YES;
  637.     else {
  638.         *ffblk=*pffblk;
  639.         done=NO;
  640.     }
  641. #else
  642.     done=findfirst(filespec,ffblk,0);
  643. #endif
  644.     return(done);
  645. }
  646.  
  647. /*---------------------------------------------------------------------------*/
  648.  
  649. static int find_next(struct ffblk *ffblk)
  650. {
  651.     register int done;
  652.  
  653. #if defined(__ZTC__)
  654.     struct ffblk *pffblk;
  655.     pffblk=findnext();
  656.     if(pffblk==NULL)
  657.         done=YES;
  658.     else
  659.         *ffblk=*pffblk;
  660. #else
  661.     done=findnext(ffblk);
  662. #endif
  663.     return(done);
  664. }
  665.  
  666. /*---------------------------------------------------------------------------*/
  667.  
  668. static void hide_demo(void)
  669. {
  670.     register int i;
  671.  
  672.     whelpcat(H_WINHIDE);
  673.     wtextattr(LCYAN|_BROWN);
  674.     wputs("\n\n   The whide() and wunhide()"
  675.             "\n   functions are used to hide"
  676.             "\n   and unhide windows.");
  677.     press_a_key(9);
  678.  
  679.     /* hide all windows, front to back */
  680.     for(i=0;i<5;i++) {
  681.         if(whide()) error_exit(1);
  682.         short_delay();
  683.     }
  684.  
  685.     /* unhide most recently hidden first */
  686.     for(i=0;i<5;i++) {
  687.         if(wunhide(0)) error_exit(1);
  688.         short_delay();
  689.     }
  690. }
  691.  
  692. /*---------------------------------------------------------------------------*/
  693.  
  694. static void horz_line(int wrow,int wcol,int count,int attr)
  695. {
  696.     whline(wrow,wcol,count,3,attr);
  697.     short_delay();
  698. }
  699.  
  700. /*---------------------------------------------------------------------------*/
  701.  
  702. /* this function initializes CXL's video, mouse, keyboard, and help systems */
  703.  
  704. static void initialize(void)
  705. {
  706.     /* initialize the CXL video system and save current screen info */
  707.     videoinit();
  708.     readcur(&crow,&ccol);
  709.     if((savescrn=ssave())==NULL) error_exit(3);
  710.  
  711.     /* if mouse exists, turn on full mouse support */
  712.     if(msinit()) {
  713.         mssupport(MS_FULL);
  714.         msgotoxy(12,49);
  715.     }
  716.  
  717.     /* attach [Alt-X] to the confirm_quit() function */
  718.     setonkey(0x2d00,confirm_quit,0);
  719.  
  720.     /* initialize help system, help key = [F1] */
  721.     whelpdef("CXLDEMO.HLP",0x3b00,YELLOW|_RED,LRED|_RED,WHITE|_RED,RED|_LGREY
  722.         ,add_shadow);
  723. }
  724.  
  725. /*---------------------------------------------------------------------------*/
  726.  
  727. static void line_inp_demo(void)
  728. {
  729.     if(!wopen(5,21,15,58,3,LGREEN|_MAGENTA,LGREEN|_MAGENTA)) error_exit(1);
  730.     wtitle("[ Single-Line Input ]",TCENTER,LGREEN|_MAGENTA);
  731.     whelpcat(H_DATAENTRY);
  732.     add_shadow();
  733.     restore_cursor();
  734.     if(winputsf(phone,"'\n\n  Phone Number?    '!R--!"
  735.         "'('!+!###!-!') '!+!###!-!'-'!+!####")) confirm_quit();
  736.     restore_cursor();
  737.     if(winputsf(ssan,"'\n\n  Soc Sec Number?  '!R-!"
  738.         "<0123456>##!-!'-'!+!##!-!'-'!+!####")) confirm_quit();
  739.     restore_cursor();
  740.     if(winputsf(date,"\"\n\n  Today's Date?    \"!R-!"
  741.         "<01>#!-!'/'!+!<0123>#!-!'/'!+!'19'<89>#")) confirm_quit();
  742.     wclose();
  743. }
  744.  
  745. /*---------------------------------------------------------------------------*/
  746.  
  747. static void main_menu(void)
  748. {
  749.     /* push global help category onto help stack, so when   */
  750.     /* [F1] is pressed while selection bar is on an item    */
  751.     /* without help, the global help category will be used. */
  752.     whelpushc(H_GLOBAL);
  753.  
  754.     /* define and process the main menu */
  755.     wmenubeg(9,27,16,53,0,LBLUE|_BLUE,LBLUE|_BLUE,pre_menu1);
  756.     wmenuitem(0,0,"Windowing"   ,'W',1,0,windemo ,0,H_WINDOWING);
  757.     wmenuitem(1,0,"Menuing"     ,'M',2,0,menudemo,0,H_MENUING);
  758.     wmenuitem(2,0,"List picking",'L',3,0,pickdemo,0,H_LISTPICK);
  759.     wmenuitem(3,0,"Data entry"  ,'D',4,0,datademo,0,H_DATAENTRY);
  760.     wmenuitem(4,0,"Information" ,'I',5,0,cxlinfo ,0,0);
  761.     wmenuitem(5,0,"Exit demo"   ,'E',6,0,NULL    ,0,0);
  762.     wmenuend(1,M_VERT,25,6,LCYAN|_BLUE,WHITE|_BLUE,0,BLUE|_LGREY);
  763.     if(wmenuget()==-1) if(_winfo.errno>W_ESCPRESS) error_exit(1);
  764.  
  765.     /* pop the global help category off of the stack, and into the void */
  766.     whelpopc();
  767. }
  768.  
  769. /*---------------------------------------------------------------------------*/
  770.  
  771. static void menudemo(void)
  772. {
  773.     pulldown_demo();
  774.     move_bar_down();
  775. }
  776.  
  777. /*---------------------------------------------------------------------------*/
  778.  
  779. static void move_bar_down(void)
  780. {
  781.     wmenumcurr()->tagcurr=wmenuicurr()->tagid+1;
  782. }
  783.  
  784. /*---------------------------------------------------------------------------*/
  785.  
  786. static void move_demo(void)
  787. {
  788.     if((w[4]=wopen(4,2,16,35,2,LGREEN|_BROWN,WHITE|_BROWN))==0) error_exit(1);
  789.     whelpcat(H_WINMOVE);
  790.     wputs("\n   To move the active window,"
  791.           "\n   the wmove() function is"
  792.           "\n   used.");
  793.     press_a_key(5);
  794.     move_window(0,0);
  795.     move_window(10,4);
  796.     move_window(6,19);
  797.     move_window(1,13);
  798.     move_window(11,35);
  799.     move_window(2,39);
  800. }
  801.  
  802. /*---------------------------------------------------------------------------*/
  803.  
  804. static void move_window(int nsrow,int nscol)
  805. {
  806.     if(wmove(nsrow,nscol)) error_exit(1);
  807.     short_delay();
  808. }
  809.  
  810. /*---------------------------------------------------------------------------*/
  811.  
  812. /* this function handles normal termination.  The original screen and cursor */
  813. /* coordinates are restored before exiting to DOS with ERRORLEVEL 0.         */
  814.  
  815. static void normal_exit(void)
  816. {
  817.     srestore(savescrn);
  818.     gotoxy_(crow,ccol);
  819.     if(_mouse) mshidecur();
  820.     showcur();
  821.     exit(0);
  822. }
  823.  
  824. /*---------------------------------------------------------------------------*/
  825.  
  826. static void open_back_wind(void)
  827. {
  828.     register int i;
  829.  
  830.     if(!wopen(0,0,23,79,5,0,LGREEN|_GREEN)) error_exit(1);
  831.     for(i=1;i<320;i++) wprintf("\033F%cCXL   ",i);
  832. }
  833.  
  834. /*---------------------------------------------------------------------------*/
  835.  
  836. static void open_stat_wind(void)
  837. {
  838.     wfillch('\260');
  839.     wopen(24,0,24,79,5,0,LGREY|_RED);
  840.     wprints( 0, 1,LGREY|_RED,"[F1]=Help");
  841.     wcenters(0   ,LGREY|_RED,"Select demonstration to view.");
  842.     wrjusts( 0,78,LGREY|_RED,"[Alt-X]=Quit");
  843.     wfillch(' ');
  844. }
  845.  
  846. /*---------------------------------------------------------------------------*/
  847.  
  848. static void open_titl_wind(void)
  849. {
  850.     if(!wopen(1,12,5,67,0,LRED|_MAGENTA,LRED|_MAGENTA)) error_exit(1);
  851.     add_shadow();
  852.     wcenters(0,WHITE|_MAGENTA,"Welcome to the CXL Demonstration Program!");
  853.     wcenters(2,LCYAN|_MAGENTA,"CXL is Copyright (c) 1987-1989 by Mike Smedley");
  854. }
  855.  
  856. /*---------------------------------------------------------------------------*/
  857.  
  858. /* this is used by the pull-down demo.  It is the */
  859. /* [O]S Shell function under the [F]ile menu      */
  860.  
  861. static void os_shell(void)
  862. {
  863.     int *scrn;
  864.  
  865.     showcur();
  866.     if(_mouse) mshidecur();
  867.     if((scrn=ssave())==NULL) error_exit(3);
  868.     cclrscrn(LGREY|_BLACK);
  869.     printf("Type EXIT to return....\n");
  870.     system("COMMAND");
  871.     srestore(scrn);
  872.     hidecur();
  873.     if(_mouse) msshowcur();
  874. }
  875.  
  876. /*---------------------------------------------------------------------------*/
  877.  
  878. /* this function parses the command line for valid invocation switches.  If  */
  879. /* any valid switches are found, the appropriate video variable will be      */
  880. /* set.  If any invalid parameters are found, a syntax message is displayed. */
  881.  
  882. static void parse_cmd_line(int argc,char *argv[])
  883. {
  884.     register int i,j;
  885.     char *p;
  886.  
  887.     for(i=1;i<argc;i++) {
  888.         p=argv[i];
  889.         if(*p=='-'||*p=='/') {
  890.             for(j=1;*(p+j);j++) {
  891.                 switch(tolower(*(p+j))) {
  892.                     case 'c':
  893.                         if(_vinfo.adapter==V_CGA) {
  894.                             _vinfo.cgasnow=1;
  895.                             _vinfo.usebios=0;
  896.                         }
  897.                         break;
  898.                     case 'b':
  899.                         _vinfo.usebios=1;
  900.                         _vinfo.cgasnow=0;
  901.                         break;
  902.                     case 'm':
  903.                         _vinfo.mapattr=1;
  904.                         break;
  905.                     default:
  906.                         error_exit(2);
  907.                 }
  908.             }
  909.         }
  910.         else
  911.             error_exit(2);
  912.     }
  913. }
  914.  
  915. /*---------------------------------------------------------------------------*/
  916.  
  917. /* this function parses a MMDDYY date string into separate numeric values */
  918.  
  919. static void parse_date(char *buf,int *month,int *day,int *year)
  920. {
  921.     char date[7];
  922.  
  923.     strcpy(date,buf);
  924.     *year=1900+atoi(date+4);
  925.     *(date+4)='\0';
  926.     *day=atoi(date+2);
  927.     *(date+2)='\0';
  928.     *month=atoi(date);
  929. }
  930.  
  931. /*---------------------------------------------------------------------------*/
  932.  
  933. static void pick_compiler(void)
  934. {
  935.     register int subscr,i;
  936.  
  937.     whelpush();
  938.     wmenubeg(8,22,14,38,0,LMAGENTA|_MAGENTA,LMAGENTA|_MAGENTA,pre_menu2);
  939.     for(i=0;i<=4;i++) wmenuitem(i,0,compilers[i],*compilers[i],i,0,NULL,0,0);
  940.     wmenuend(0,M_VERT,15,1,LMAGENTA|_MAGENTA,LCYAN|_MAGENTA,0,BLUE|_LGREY);
  941.     if((subscr=wmenuget())==-1) if(_winfo.errno>W_ESCPRESS) error_exit(1);
  942.     kbput(0x4700);  /* [Home] */
  943.     if(subscr!=-1) {
  944.         kbputs(compilers[subscr]);
  945.         kbput(0x1615);  /* [Ctrl-U] */
  946.     }
  947.     kbput(0x1c0d);  /* [Enter] */
  948.     whelpop();
  949. }
  950.  
  951. /*---------------------------------------------------------------------------*/
  952.  
  953. /* this function demonstrates the string picker, the file */
  954. /* picker, and the in-place string selector functions.    */
  955.  
  956. static void pickdemo(void)
  957. {
  958.     register int *scrn;
  959.  
  960.     if((scrn=ssave())==NULL) error_exit(3);
  961.     cclrscrn(LGREY|_BLUE);
  962.     if(!wopen(4,11,14,68,3,LMAGENTA|_RED,LRED|_MAGENTA)) error_exit(1);
  963.     add_shadow();
  964.     wprintf("\033R\001\033C\003Select a month =>\033R\001\033C\003");
  965.     whelpcat(H_STRPICK);
  966.     you_selected(months[wpickstr(0,32,5,-1,0,LGREEN|_RED,LCYAN|_RED,RED|_LGREY
  967.         ,months,pre_pick1)]);
  968.     wprintf("\033R\003\033C\003Now, select a file.\033R\003\033C\003");
  969.     whelpcat(H_FILEPICK);
  970.     you_selected(wpickfile(10,10,20,65,0,LCYAN|_RED,LGREY|_RED,RED|_LGREY
  971.         ,1,"*.*",add_shadow));
  972.     wprintf("\033R\005\033C\003Select a printer port:\033R\005\033C\003");
  973.     showcur();
  974.     you_selected(prn_ports[wselstr(5,27,LMAGENTA|_MAGENTA,prn_ports)]);
  975.     hidecur();
  976.     wclose();
  977.     srestore(scrn);
  978.     move_bar_down();
  979. }
  980.  
  981. /*---------------------------------------------------------------------------*/
  982.  
  983. static void popup_demo(void)
  984. {
  985.     whelpush();
  986.     wmenubeg(7,15,10,65,0,YELLOW,LCYAN|_BLUE,NULL);
  987.     wmenuitem(0, 0,"Add",   'A',55,0,NULL,0,NULL);
  988.     wmenuitxt(1,0,LGREEN|_BLUE,"Create a new record                 ");
  989.     wmenuitem(0, 8,"Delete",'D',56,0,NULL,0,NULL);
  990.     wmenuitxt(1,0,LGREEN|_BLUE,"Delete an existing record           ");
  991.     wmenuitem(0,19,"Print", 'P',57,0,NULL,0,NULL);
  992.     wmenuitxt(1,0,LGREEN|_BLUE,"Print hardcopy of existing record   ");
  993.     wmenuitem(0,28,"Show",  'S',58,0,NULL,0,NULL);
  994.     wmenuitxt(1,0,LGREEN|_BLUE,"Display an existing record on screen");
  995.     wmenuitem(0,36,"Update",'U',59,0,NULL,0,NULL);
  996.     wmenuitxt(1,0,LGREEN|_BLUE,"Modify an existing record           ");
  997.     wmenuitem(0,45,"Quit",  'Q',60,0,NULL,0,NULL);
  998.     wmenuitxt(1,0,LGREEN|_BLUE,"Quit and return to pulldown menu    ");
  999.     wmenuend(13,M_HORZ,0,0,LMAGENTA|_BLUE,WHITE|_BLUE,0,YELLOW|_LGREY);
  1000.     wmenuget();
  1001.     whelpop();
  1002. }
  1003.  
  1004. /*---------------------------------------------------------------------------*/
  1005.  
  1006. /* this function is called during the setup of the main menu.  It is  */
  1007. /* called by wmenuget() right after the main menu's window is opened. */
  1008.  
  1009. static void pre_menu1(void)
  1010. {
  1011.     hidecur();
  1012.     add_shadow();
  1013. }
  1014.  
  1015. /*---------------------------------------------------------------------------*/
  1016.  
  1017. /* this function is called during the Data Entry demo when */
  1018. /* the user enters the Compiler field.  It is called by    */
  1019. /* wmenuget() after the compiler choice menu is opened.    */
  1020.  
  1021. static void pre_menu2(void)
  1022. {
  1023.     add_shadow();
  1024.     gotoxy_(16,25);
  1025.     if(_mouse) msgotoxy(11,34);
  1026. }
  1027.  
  1028. /*---------------------------------------------------------------------------*/
  1029.  
  1030. /* this function is called during the List Picking demo.  It is called */
  1031. /* by wpickstr() right after the string picker's window is opened.     */
  1032.  
  1033. static void pre_pick1(void)
  1034. {
  1035.     wmessage("┐ ┌",1,4,LGREEN|_RED);
  1036.     add_shadow();
  1037.     gotoxy_(6,37);
  1038.     showcur();
  1039. }
  1040.  
  1041. /*---------------------------------------------------------------------------*/
  1042.  
  1043. /* this function displays a pause message then pauses for a keypress */
  1044.  
  1045. static void press_a_key(int wrow)
  1046. {
  1047.     register int attr;
  1048.  
  1049.     attr=(BLINK|YELLOW)|((_winfo.active->wattr>>4)<<4);
  1050.     wcenters(wrow,attr,"Press a key");
  1051.     hidecur();
  1052.     if(waitkey()==ESC) confirm_quit();
  1053.     wcenters(wrow,attr,"           ");
  1054. }
  1055.  
  1056. /*---------------------------------------------------------------------------*/
  1057.  
  1058. static void pulldown_demo(void)
  1059. {
  1060.     int selection;
  1061.  
  1062.     whelpushc(H_PULLDOWN);
  1063.     if(!wopen(0,0,24,79,0,CYAN,CYAN)) error_exit(1);
  1064.     whline(1,0,78,0,CYAN);
  1065.     setkbloop(update_clock);
  1066.     wgotoxy(2,0);
  1067.     wtextattr(YELLOW);
  1068.     wputs("This is a sample editor interface to demonstrate how CXL's "
  1069.           "menuing functions\n");
  1070.     wputs("can be used to create a pull-down menu system.  Use the arr"
  1071.           "ow keys to move\n");
  1072.     wputs("selection bar around and use the [Esc] key to back up to th"
  1073.           "e previous menu.\n");
  1074.     wputs("Pressing [F1] will bring up context-sensitive help.  Select"
  1075.           " [Q]uit from any\n");
  1076.     wputs("menu to exit the pull-down demo.  Be sure to try some of th"
  1077.           "e menu options in\n");
  1078.     wputs("the pull-down menus.");
  1079.     if(_mouse)
  1080.         wputs("  Since you have a mouse, you can use it to "
  1081.               "move around\nand select options!");
  1082.  
  1083.     /* define menu structure */
  1084.     wmenubeg(1,1,1,78,5,CYAN,CYAN|_BLUE,NULL);
  1085.     wmenuitem(0,2,"File",'F',19,M_HASPD,NULL,0,H_FILE);
  1086.         wmenubeg(2,1,11,17,0,LGREY|_BLUE,_BLUE,NULL);
  1087.         wmenuitem(0,0,"Load"         ,'L',20,0,do_nothing,0,H_LOAD);
  1088.         wmenuitem(1,0,"Save"         ,'S',21,0,do_nothing,0,H_SAVE);
  1089.         wmenuitem(2,0,"Rename"       ,'R',22,0,do_nothing,0,H_RENAME);
  1090.         wmenuitem(3,0,"New"          ,'N',23,0,do_nothing,0,H_NEW);
  1091.         wmenuitem(4,0,"Directory  F5",'D',24,0,directory ,0x3f00,H_DIRECTORY);
  1092.         wmenuitem(5,0,"Execute    F6",'E',25,0,execute   ,0x4000,H_EXECUTE);
  1093.         wmenuitem(6,0,"OS Shell   F7",'O',26,0,os_shell  ,0x4100,H_OSSHELL);
  1094.         wmenuitem(7,0,"Quit"         ,'Q',27,M_CLALL,NULL,0,H_QUIT);
  1095.         wmenuiba(quit_window,quit_window);
  1096.         wmenuend(20,M_PD|M_SAVE,15,1,YELLOW|_BLUE,LCYAN|_BLUE,0
  1097.             ,YELLOW|_MAGENTA);
  1098.     wmenuitem(0,15,"Editing",'E',28,M_HASPD,NULL,0,H_EDITING);
  1099.         wmenubeg(2,14,10,28,0,LGREY|_BLUE,_BLUE,NULL);
  1100.         wmenuitem(0,0,"Cut"        ,'C',29,0      ,do_nothing,0,0);
  1101.         wmenuitem(1,0,"Paste"      ,'P',30,M_NOSEL,do_nothing,0,0);
  1102.         wmenuitem(2,0,"cOpy"       ,'O',31,M_NOSEL,do_nothing,0,0);
  1103.         wmenuitem(3,0,"block Begin",'B',32,0      ,do_nothing,0,0);
  1104.         wmenuitem(4,0,"block End"  ,'E',33,M_NOSEL,do_nothing,0,0);
  1105.         wmenuitem(5,0,"Insert line",'I',34,0      ,do_nothing,0,0);
  1106.         wmenuitem(6,0,"Delete line",'D',35,0      ,do_nothing,0,0);
  1107.         wmenuend(29,M_PD|M_SAVE,13,1,YELLOW|_BLUE,LCYAN|_BLUE,CYAN|_BLUE
  1108.             ,YELLOW|_MAGENTA);
  1109.     wmenuitem(0,31,"Defaults",'D',36,M_HASPD,NULL,0,0);
  1110.         wmenubeg(2,30,13,52,0,LGREY|_BLUE,_BLUE,setup_menu);
  1111.         wmenuitem(0,0,"Left margin       0",'L',37,0,do_nothing,0,0);
  1112.         wmenuitem(1,0,"Right margin     72",'R',38,0,do_nothing,0,0);
  1113.         wmenuitem(2,0,"Tab width         4",'T',39,0,do_nothing,0,0);
  1114.         wmenuitem(4,0,"tab eXpansion   yes",'X',40,0,toggle_yn ,0,0);
  1115.         wmenuitem(5,0,"Insert mode     yes",'I',41,0,toggle_yn ,0,0);
  1116.         wmenuitem(6,0,"iNdent mode     yes",'N',42,0,toggle_yn ,0,0);
  1117.         wmenuitem(7,0,"Word wrap mode   no",'W',43,0,toggle_yn ,0,0);
  1118.         wmenuitem(9,0,"Save defaults"      ,'S',44,0,do_nothing,0,0);
  1119.         wmenuend(37,M_PD|M_SAVE,21,1,YELLOW|_BLUE,LCYAN|_BLUE,0
  1120.             ,YELLOW|_MAGENTA);
  1121.     wmenuitem(0,47,"Run"    ,'R',45,0      ,popup_demo,0,0);
  1122.     wmenuitem(0,59,"Options",'O',46,M_HASPD,NULL,0,0);
  1123.         wmenubeg(2,56,8,77,0,LGREY|_BLUE,_BLUE,NULL);
  1124.         wmenuitem(0,0,"screen siZe     43",'Z',47,0,do_nothing,0,0);
  1125.         wmenuitem(1,0,"Backup files   yes",'B',48,0,toggle_yn ,0,0);
  1126.         wmenuitem(2,0,"bOxed display   no",'O',49,0,toggle_yn ,0,0);
  1127.         wmenuitem(3,0,"Load options"      ,'L',50,0,do_nothing,0,0);
  1128.         wmenuitem(4,0,"Save options"      ,'S',51,0,do_nothing,0,0);
  1129.         wmenuend(47,M_PD|M_SAVE,20,1,YELLOW|_BLUE,LCYAN|_BLUE,0
  1130.             ,YELLOW|_MAGENTA);
  1131.     wmenuitem(0,73,"Quit",'Q',52,M_HASPD,NULL,0,0);
  1132.     wmenuiba(quit_window,quit_window);
  1133.         wmenubeg(2,60,7,78,0,LGREY|_BLUE,_BLUE,disp_sure_msg);
  1134.         wmenuitem(2,0,"No" ,'N',53,M_CLOSE,NULL,0,0);
  1135.         wmenuitem(3,0,"Yes",'Y',54,M_CLALL,NULL,0,0);
  1136.         wmenuend(53,M_PD,17,7,YELLOW|_BLUE,LCYAN|_BLUE,WHITE|_BLUE
  1137.             ,YELLOW|_MAGENTA);
  1138.     wmenuend(19,M_HORZ,0,0,YELLOW|_BLUE,LCYAN|_BLUE,0,YELLOW|_MAGENTA);
  1139.  
  1140.     /* process the menu */
  1141.     selection=wmenuget();
  1142.     if(selection==-1&&_winfo.errno>W_ESCPRESS) error_exit(1);
  1143.     wclose();
  1144.     setkbloop(NULL);
  1145.     whelpopc();
  1146. }
  1147.  
  1148. /*---------------------------------------------------------------------------*/
  1149.  
  1150. /* this function is called by the pull-down menu demo anytime */
  1151. /* the  selection bar moves on or off the [Q]uit menu items.  */
  1152.  
  1153. static void quit_window(void)
  1154. {
  1155.     static WINDOW handle=0;
  1156.  
  1157.     if(handle) {
  1158.         wactiv(handle);
  1159.         wclose();
  1160.         handle=0;
  1161.     }
  1162.     else {
  1163.         handle=wopen(14,41,17,70,0,YELLOW|_RED,WHITE|_RED);
  1164.         wputs(" Quit takes you back to the\n demo program's main menu.");
  1165.     }
  1166. }
  1167.  
  1168. /*---------------------------------------------------------------------------*/
  1169.  
  1170. static void resize_demo(void)
  1171. {
  1172.     whelpcat(H_RESIZE);
  1173.     wtextattr(LGREEN|_GREEN);
  1174.     wputs("\n\n\n  The wsize() function"
  1175.               "\n  allows you to resize"
  1176.               "\n  the active window.");
  1177.     press_a_key(10);
  1178.     size_window(19,60);
  1179.     size_window(19,75);
  1180.     size_window(24,75);
  1181.     size_window(24,60);
  1182.     size_window(24,45);
  1183.     size_window(19,45);
  1184. }
  1185.  
  1186. /*---------------------------------------------------------------------------*/
  1187.  
  1188. static void restore_cursor(void)
  1189. {
  1190.     wtextattr(WHITE|_MAGENTA);
  1191.     showcur();
  1192. }
  1193.  
  1194. /*---------------------------------------------------------------------------*/
  1195.  
  1196. static void scroll_demo(void)
  1197. {
  1198.     register int i,j;
  1199.  
  1200.     if((w[0]=wopen(1,1,11,41,2,LMAGENTA|_RED,LCYAN|_RED))==0) error_exit(1);
  1201.     whelpcat(H_SCROLL);
  1202.     wprintf("\n  CXL's window TTY output functions"
  1203.             "\n  such as wputs() and wprintf() allow"
  1204.             "\n  scrolling and ANSI-like Escape code"
  1205.             "\n  sequences from inside of windows.");
  1206.     press_a_key(6);
  1207.     wgotoxy(8,0);
  1208.     for(i=0;i<10;i++) {
  1209.         for(j=DGREY;j<=WHITE;j++) {
  1210.             wprintf("\033F%cCXL   ",j);
  1211.             delay_(1);
  1212.         }
  1213.     }
  1214. }
  1215.  
  1216. /*---------------------------------------------------------------------------*/
  1217.  
  1218. /* this function sets up the [D]efaults menu for the pull-down demo */
  1219.  
  1220. static void setup_menu(void)
  1221. {
  1222.     whline(3,0,21,0,LGREY|_BLUE);
  1223.     whline(8,0,21,0,LGREY|_BLUE);
  1224. }
  1225.  
  1226. /*---------------------------------------------------------------------------*/
  1227.  
  1228. static void short_delay(void)
  1229. {
  1230.     delay_(SHORT_DELAY);
  1231. }
  1232.  
  1233. /*---------------------------------------------------------------------------*/
  1234.  
  1235. static void size_window(int nerow,int necol)
  1236. {
  1237.     wsize(nerow,necol);
  1238.     short_delay();
  1239. }
  1240.  
  1241. /*---------------------------------------------------------------------------*/
  1242.  
  1243. static void text_line_demo(void)
  1244. {
  1245.     if((w[3]=wopen(10,3,23,41,3,YELLOW|_BLUE,LMAGENTA|_BLUE))==0)
  1246.         error_exit(1);
  1247.     whelpcat(H_TEXTLINE);
  1248.     wputs("\n  The whline() & wvline() functions"
  1249.           "\n  are used for drawing \"smart\" text"
  1250.           "\n  lines which will even make their "
  1251.           "\n  own corners and intersections!   ");
  1252.     press_a_key(6);
  1253.     horz_line(6,6,24,LCYAN|_BLUE);
  1254.     vert_line(6,6,4,LCYAN|_BLUE);
  1255.     horz_line(10,6,24,LCYAN|_BLUE);
  1256.     vert_line(6,30,5,LRED|_BLUE);
  1257.     vert_line(6,18,5,LRED|_BLUE);
  1258.     horz_line(7,6,25,LRED|_BLUE);
  1259.     horz_line(9,6,25,LGREEN|_BLUE);
  1260.     vert_line(6,11,5,LGREEN|_BLUE);
  1261.     vert_line(6,23,5,LGREEN|_BLUE);
  1262.     horz_line(8,6,25,LMAGENTA|_BLUE);
  1263. }
  1264.  
  1265. /*---------------------------------------------------------------------------*/
  1266.  
  1267. static void title_demo(void)
  1268. {
  1269.     if((w[2]=wopen(5,20,19,45,3,LCYAN|_GREEN,WHITE|_GREEN))==0) error_exit(1);
  1270.     whelpcat(H_WINTITLE);
  1271.     wputs("\n  The wtitle() function"
  1272.           "\n  allows you to give a"
  1273.           "\n  window a title.");
  1274.     press_a_key(5);
  1275.     display_title(TLEFT);
  1276.     display_title(TRIGHT);
  1277.     display_title(TCENTER);
  1278. }
  1279.  
  1280. /*---------------------------------------------------------------------------*/
  1281.  
  1282. /* this function toggles the y/n status of some pull-down menu items */
  1283.  
  1284. static void toggle_yn(void)
  1285. {
  1286.     struct _item_t *citem;
  1287.     char *str,*yn;
  1288.  
  1289.     citem=wmenuicurr();
  1290.     str=citem->str;
  1291.     yn=str+strlen(str)-3;
  1292.     strcpy(yn,strcmp(yn,"yes")?"yes":" no");
  1293.     citem->redisp=1;
  1294. }
  1295.  
  1296. /*---------------------------------------------------------------------------*/
  1297.  
  1298. /* this function updates the on-screen clock in the pull-down demo. */
  1299.  
  1300. static void update_clock(void)
  1301. {
  1302.     prints(0,70,LGREEN,systime(1));
  1303. }
  1304.  
  1305. /*---------------------------------------------------------------------------*/
  1306.  
  1307. static void vert_line(int wrow,int wcol,int count,int attr)
  1308. {
  1309.     wvline(wrow,wcol,count,3,attr);
  1310.     short_delay();
  1311. }
  1312.  
  1313. /*---------------------------------------------------------------------------*/
  1314.  
  1315. /* this function is used by the List Picking demo to display a selected    */
  1316. /* string, or display an error message if an error occurred.  It also      */
  1317. /* prompts the user for a keypress 2 lines below the string/error message. */
  1318.  
  1319. static void you_selected(char *str)
  1320. {
  1321.     int wrow,wcol;
  1322.  
  1323.     if(_winfo.errno)
  1324.         wprintf("\033EL%s",werrmsg());
  1325.     else
  1326.         wprintf("\033ELYou selected:  \033F\005%s\033F\004",str);
  1327.     whelpcat(H_LISTPICK);
  1328.     wreadcur(&wrow,&wcol);
  1329.     press_a_key(wrow+2);
  1330. }
  1331.  
  1332. /*---------------------------------------------------------------------------*/
  1333.  
  1334. static void windemo(void)
  1335. {
  1336.     int *scrn;
  1337.  
  1338.     if((scrn=ssave())==NULL) error_exit(3);
  1339.     cclrscrn(LGREY|_BLACK);
  1340.     scroll_demo();
  1341.     chg_attr_demo();
  1342.     chg_bord_demo();
  1343.     title_demo();
  1344.     resize_demo();
  1345.     text_line_demo();
  1346.     move_demo();
  1347.     hide_demo();
  1348.     activate_demo();
  1349.     copy_demo();
  1350.     close_windows();
  1351.     srestore(scrn);
  1352.     clearkeys();
  1353.     move_bar_down();
  1354. }
  1355.