home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tel2305s.zip / ENGINE / MENU.C < prev    next >
C/C++ Source or Header  |  1992-03-08  |  17KB  |  489 lines

  1. /***********************************************************************/
  2. /*  menu support
  3. *   New 5/22/88 - TK
  4. *   Provide menus with a reasonable user interface for the user to
  5. *   select colors or other parameters.
  6. *
  7. *   This menu system provides two types of entries.
  8. *   1. Up to nine static choices, 0-8.  Each static choice is encoded
  9. *      into the data structure and automatically rotated by the user.
  10. *      The user cannot select an illegal value.
  11. *   2. A string choice.  A maximum string length is honored.
  12. *   There must be at least 20 characters open for each field, longer
  13. *   if the field is longer.  Static choices cannot be longer than 20 chars.
  14. *
  15. *    Code Cleanup for 2.3 release - 6/89 QK
  16. */
  17.  
  18. /*
  19. *    Includes
  20. */
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #ifdef MSC
  26. #ifdef __TURBOC__
  27. #include <alloc.h>
  28. #else
  29. #include <malloc.h>
  30. #endif
  31. #endif
  32. #include "whatami.h"
  33. #include "nkeys.h"
  34. #include "windat.h"
  35. #include "hostform.h"
  36. #include "menu.h"
  37. #include "telopts.h"
  38. #include "externs.h"
  39.  
  40. extern unsigned char s[550],
  41.     ncsa_version[];
  42. extern struct config def;
  43. extern int ftpok, rcpok, temptek, viewmode;
  44.  
  45. #define noalpha                /* for alpha test, both alpha and beta must be defined */
  46. #define nobeta
  47.  
  48. #define LO 4
  49. static struct pt pc[]={        /* session colors */
  50.     {LO+0,44,0,0,"black","blue","green","cyan","red","magenta","yellow","white","BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","YELLOW","WHITE",NULL},
  51.     {LO+1,44,0,0,"black","blue","green","cyan","red","magenta","yellow","white","BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","YELLOW","WHITE",NULL},
  52.     {LO+2,44,0,0,"black","blue","green","cyan","red","magenta","yellow","white","BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","YELLOW","WHITE",NULL},
  53.     {LO+3,44,0,0,"black","blue","green","cyan","red","magenta","yellow","white","BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","YELLOW","WHITE",NULL},
  54.     {LO+4,44,0,0,"black","blue","green","cyan","red","magenta","yellow","white","BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","YELLOW","WHITE",NULL},
  55.     {LO+5,44,0,0,"black","blue","green","cyan","red","magenta","yellow","white","BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","YELLOW","WHITE",NULL},
  56. /* things which also apply to this session */
  57.     {LO+6,44,0,0,"Local echo","Remote echo",NULL},
  58.     {LO+7,44,1,0,"Backspace","Delete",NULL},
  59.     {LO+8,44,0,20,NULL,"                    ",NULL},
  60.     {LO+9,44,0,0,"VT102 and Tek4014","Dumb TTY","VT102 only",NULL},
  61.     {LO+10,44,0,0,"Wrapping Off","Wrapping On",NULL},
  62.     {LO+11,44,0,0,"Mapping Off","Mapping On",NULL},
  63. /* things which apply over all of telnet */
  64.     {LO+13,44,0,35,NULL,"                                   ",NULL},
  65.     {LO+14,44,1,0,"Use BIOS","Direct to screen",NULL},
  66.     {LO+15,44,0,0,"Disabled","Enabled",NULL},
  67.     {LO+16,44,0,0,"Disabled","Enabled",NULL},
  68.     {LO+17,44,0,0,"Disabled","Enabled",NULL},
  69.     {LO+0,0}
  70. };
  71.  
  72. /************************************************************************/
  73. /* menuit
  74. *  draw the current line at the required position.
  75. *  If the field length (replen) is longer than 20 chars, fill in the
  76. *  entire field width.  All fields are padded with spaces to their
  77. *  length when printed, but stored without padding.
  78. */
  79. void menuit(struct pt p[],int n)
  80. {
  81.     int i;
  82.     char fmt[12];
  83.  
  84.     n_cur(p[n].posx,p[n].posy);
  85.     if((i=p[n].replen)<20)             /* i=larger of replen and 20 */
  86.         i=20;
  87.     sprintf(fmt,"%%-%d.%ds",i,i);                /* create format string */
  88.     sprintf(s,fmt,p[n].vals[p[n].choice]);        /* put out value */
  89.     n_puts(s);
  90. }
  91.  
  92. /************************************************************************/
  93. /*  makechoice
  94. *   Allow the user to travel between choices on the screen, selecting
  95. *   from a list of legal options.
  96. *   Arrow keys change the selections on the screen.  The data structure
  97. *   must be set up before entering this procedure.
  98. */
  99. int makechoice(struct pt p[],int maxp,int spec)
  100. {
  101.     int i,oldln,ln,c;
  102.     
  103.     oldln=ln=0;
  104.     n_color(7);
  105.     for(i=1; i<maxp; i++)         /* print the opening selections */
  106.         menuit(p,i);
  107. /*
  108. *  For each keystroke, repaint the current line and travel around the
  109. *  data structure until the exit key is hit.
  110. */
  111.     do {
  112.         if(oldln!=ln) {
  113.             n_color(7);                    /* re-write old line in normal color */
  114.             menuit(p,oldln);
  115.           }
  116.         n_color(0x70);
  117.         menuit(p,ln);                    /* write the current line in reverse */
  118.         if(spec)
  119.             makespecial();                /* display special requirements */
  120.         n_cur(p[ln].posx,p[ln].posy);    /* reset cursor to current entry */
  121.         oldln=ln;
  122.         c=nbgetch();
  123.         switch (c) {            /* act on user's key */
  124.             case CURUP:
  125.             case E_CURUP:
  126.                 if(ln)
  127.                     ln--;
  128.                 else
  129.                     ln=maxp-1;
  130.                 break;
  131.  
  132.             case CURDN:            /* up and down change current field */
  133.             case E_CURDN:
  134.                 if(++ln>=maxp)
  135.                     ln=0;
  136.                 break;
  137.  
  138.             case PGUP:
  139.             case HOME:
  140.             case E_PGUP:
  141.             case E_HOME:
  142.                 ln=0;
  143.                 break;
  144.  
  145.             case PGDN:
  146.             case ENDKEY:
  147.             case E_PGDN:
  148.             case E_ENDKEY:
  149.                 ln=maxp-1;
  150.                 break;
  151.  
  152.             case 32:                /* space, tab and arrows change field contents */
  153.             case TAB:
  154.             case CURRT:
  155.             case E_CURRT:
  156.                 i=++p[ln].choice;        /* if blank or non-existant, reset to 0 */
  157.                 if(!p[ln].vals[i] || !(*p[ln].vals[i]) || ' '==*p[ln].vals[i])
  158.                     p[ln].choice=0;
  159.                 break;
  160.  
  161.             case CURLF:
  162.             case E_CURLF:
  163.                 if(p[ln].choice)
  164.                     p[ln].choice--;
  165.                 else {                /* if at zero, search for highest valid value */
  166.                     i=0;
  167.                     while(p[ln].vals[i] && *p[ln].vals[i] && ' ' != *p[ln].vals[i])
  168.                         i++;
  169.                     if(i)
  170.                         p[ln].choice=i-1;
  171.                   }
  172.                 break;
  173.  
  174.             case BACKSPACE:
  175.             case 21:
  176.             case 13:                     /* BS, Ctrl-U, or return */
  177. /*
  178. *  if allowed, the user can enter a string value.
  179. *  prepare the field, by printing in a different color to set it apart.
  180. */
  181.                 if(p[ln].replen) {
  182.                     char *temp_val;        /* temporary storage for the field value */
  183.  
  184.                     p[ln].choice=1;
  185.                     n_color(1);                        /* underline color */
  186.                     n_cur(p[ln].posx,p[ln].posy);
  187.                     for(i=0; i<p[ln].replen; i++)  /* blank out field */
  188.                         n_putchar(' '); 
  189.                     n_cur(p[ln].posx,p[ln].posy);
  190.                     temp_val=(char *)malloc((unsigned int)p[ln].replen+1);    /* allocate space for the temporary field */
  191.                     if(temp_val!=NULL) {
  192.                         strcpy(temp_val,p[ln].vals[1]);     /* store copy of old line */
  193.                         if(nbgets(p[ln].vals[1],p[ln].replen)==NULL)    /* check for user escaping */
  194.                             strcpy(p[ln].vals[1],temp_val); /* restore backup copy */
  195.                         free(temp_val);
  196.                       } /* end if */
  197.                   }
  198.                 break;
  199.  
  200.             default:
  201.                 break;
  202.              }
  203.       } while(c!=F1 && c!=F10 && c!=27);
  204.     return(c==F1);
  205. }
  206.  
  207. /************************************************************************/
  208. /*  makespecial
  209. *  Apart from standard menuing, we want to show an example of what the
  210. *  text is going to look like in each of the three attributes.
  211. */
  212. void makespecial(void)
  213. {
  214.     n_cur(LO-1,15);
  215.     n_color(pc[0].choice+(pc[1].choice <<4));
  216.     n_puts("normal");
  217.     n_cur(LO-1,25);
  218.     n_color(pc[2].choice+(pc[3].choice <<4));
  219.     n_puts("reverse");
  220.     n_cur(LO-1,35);
  221.     n_color(pc[4].choice+(pc[5].choice <<4));
  222.     n_puts("underline");
  223. }
  224.  
  225. /************************************************************************/
  226. /*  parmchange
  227. *   ALT-P from the user calls this routine to prompt the user for
  228. *   telnet parameter values.
  229. *   Set up the menuing system with the current values for this session.
  230. *   Call the menuing routines, then analyze the results when it returns.
  231. *
  232. *   Affects the settings of:
  233. *   session color, name, local echo, backspace/del, terminal type
  234. *   overall file transfer enable, capture file name, screen access method
  235. *
  236. */
  237. void parmchange(void)
  238. {
  239.     int i,colsave;
  240. /*
  241. *  set up the screen for the menus
  242. *  Positions of text interlock with fields of menu routines
  243. */
  244.     leavetek();
  245.     colsave=n_color(7);
  246.     n_clear();
  247.     n_cur(0,0);
  248.     n_puts("ALT-P                         Parameter menu ");
  249.     n_puts("   <      Select parameters, F1 to accept, ESC to leave unchanged      >");
  250.     n_puts("   --------------- Color setup and session parameters ----------------- ");
  251.     n_puts(" Text: ");
  252.     n_puts("          Normal Foreground (nfcolor) - ");
  253.     n_puts("          Normal Background (nbcolor) - ");
  254.     n_puts("         Reverse Foreground (rfcolor) - ");
  255.     n_puts("         Reverse Background (rbcolor) - ");
  256.     n_puts("       Underline Foreground (ufcolor) - ");
  257.     n_puts("       Underline Background (ubcolor) - ");
  258.     n_puts("        Use remote echo or local echo - ");
  259.     n_puts("                  Backspace key sends - ");
  260.     n_puts("                         Session name *>");
  261.     n_puts("                        Terminal type - ");
  262.     n_puts("                        Line wrapping - ");
  263.     n_puts("                       Output Mapping - ");
  264.     n_puts("   -------------- Parameters which apply to all sessions -------------- ");
  265.     n_puts("                    Capture file name *>");
  266.     n_puts(" Screen mode (for BIOS compatibility) - ");
  267.     n_puts("                     File transfer is - ");
  268.     n_puts("                    Remote Copying is - ");
  269.     n_puts("                             Clock is - ");
  270.     n_puts("Use arrow keys to select, Enter clears changeable field (*>)");
  271. /*
  272. *  set values for menus from our telnet-stored values
  273. */
  274.     i=current->colors[0];        /* session colors */
  275.     pc[0].choice=i&15;
  276.     pc[1].choice=i>>4;
  277.     i=current->colors[2];
  278.     pc[2].choice=i&15;
  279.     pc[3].choice=i>>4;
  280.     i=current->colors[1];
  281.     pc[4].choice=i&15;
  282.     pc[5].choice=i>>4;
  283.     pc[6].choice=current->echo;
  284.     if(current->bksp==8)        /* backspace setting */
  285.         pc[7].choice=0;
  286.     else
  287.         pc[7].choice=1;
  288.     pc[8].vals[0]=current->mname;        /* session name */
  289.     pc[9].choice=current->termstate-1;  /* terminal type */
  290.     pc[10].choice=current->vtwrap;      /*line wrapping */
  291.     pc[11].choice=current->mapoutput;    /* output mapping on for this session */
  292.     pc[12].vals[0]=def.capture;     /* capture file name */
  293.     pc[13].choice=Scmode();         /* screen write mode */
  294.     pc[14].choice=ftpok;            /* filetransfer enable */
  295.     pc[15].choice=rcpok;            /* remote copying enable */
  296.     pc[16].choice=def.clock;        /* is the clock on? */
  297.     if(makechoice(pc,17,1)) {        /* call it and check the results */
  298. /*
  299. *  Work on results, only if user pressed 'F1', if ESC, this is skipped.
  300. */
  301. /*
  302. *  assign new colors
  303. */
  304.         i=pc[0].choice+(pc[1].choice<<4);   /* normal color */
  305.         if(i!=(int)(current->colors[0])) {
  306.             current->colors[0]=i;
  307.             RSsetatt(127,current->vs);        /* seed the current screen */
  308.             n_color(current->colors[0]);    /* seed ncolor */
  309.           } /* end if */
  310.         current->colors[1]=pc[4].choice+(pc[5].choice<<4);
  311.         current->colors[2]=pc[2].choice+(pc[3].choice<<4);
  312. /*
  313. *  check remote or local echo mode
  314. */
  315.         if((pc[6].choice)!=(int)(current->echo)) {
  316.             if(current->echo=pc[6].choice) {        /* assign=is on purpose */
  317.                 netpush(current->pnum);
  318.                 netprintf(current->pnum,"%c%c%c",IAC,DOTEL,ECHO);   /* telnet negotiation */
  319.               } /* end if */
  320.             else {
  321.                 netpush(current->pnum);
  322.                 netprintf(current->pnum,"%c%c%c",IAC,DONTTEL,ECHO);
  323.               } /* end else */
  324.           } /* end if */
  325. /*
  326. *  check function of backspace or delete
  327. */
  328.         if(pc[7].choice) {
  329.             current->bksp=127;        /* backspace/delete are swapped */
  330.             current->del=8;
  331.           } /* end if */
  332.         else {
  333.             current->bksp=8;            /* are normal */
  334.             current->del=127;
  335.           } /* end else */
  336. /*
  337. *  check new session name
  338. */
  339.         if(pc[8].choice) {
  340.             strcpy(s,pc[8].vals[1]);
  341.             if(s[0]!=' ' && s[0]) {        /* limit of 14 chars stored */
  342.                 strncpy(current->mname,s,15);
  343.                 current->mname[14]=0;
  344.               } /* end if */
  345.             *pc[8].vals[1]=0;
  346.             pc[8].choice=0;
  347.           } /* end if */
  348. /*
  349. *  check terminal type
  350. */
  351.         if(pc[9].choice!=current->termstate-1) 
  352.             current->termstate=pc[9].choice+1;
  353. /*
  354. *    check for line wrapping
  355. */
  356.         if((pc[10].choice)!=(int)(current->vtwrap)) {
  357.             current->vtwrap=(unsigned char)pc[10].choice;
  358.             if(pc[10].choice)
  359.                 VSwrite(current->vs,"\033[?7h",5);
  360.             else     
  361.                 VSwrite(current->vs,"\033[?7l",5);
  362.           } /* end if */
  363. /*
  364. *     check for output mapping
  365. */
  366.         if((pc[11].choice)!=(int)(current->mapoutput)) {
  367.             netpush(current->pnum);
  368.             if(current->mapoutput=pc[11].choice) {   /* assign=is on purpose */
  369.                 netprintf(current->pnum,"%c%c%c",IAC,DOTEL,BINARY);   /* telnet negotiation */
  370.                 netprintf(current->pnum,"%c%c%c",IAC,WILLTEL,BINARY);
  371.               } /* end if */
  372.             else {
  373.                 netprintf(current->pnum,"%c%c%c",IAC,DONTTEL,BINARY);
  374.                 netprintf(current->pnum,"%c%c%c",IAC,WONTTEL,BINARY);
  375.               } /* end else */
  376.             current->uwantbinary=1;  /* set the flag indicating we wanted server to start transmitting binary */
  377.             current->iwantbinary=1;  /* set the flag indicating we want to start transmitting binary */
  378.           } /* end if */
  379. /*
  380. *  check for new capture file name
  381. */
  382.         if(pc[12].choice) {
  383.             strcpy(s,pc[12].vals[1]);
  384.             if(s[0] && s[0]!=' ') {    /* no NULL names */
  385.                 Snewcap(s);
  386.                 Sgetconfig(&def);
  387.               } /* end if */
  388.             *pc[12].vals[1]=0;
  389.             pc[12].choice=0;
  390.           } /* end if */
  391. /*
  392. *  check for new screen mode, BIOS or not
  393. */
  394.         if(pc[13].choice!=Scmode())
  395.             Scwritemode(pc[13].choice); /* set to whatever choice is */
  396. /*
  397. *  check whether to enable or disable file transfers
  398. */
  399.         if(pc[14].choice!=ftpok) {
  400.             ftpok=pc[14].choice;
  401.             Sftpmode(ftpok);
  402.           } /* end if */
  403.         if(pc[15].choice!=rcpok) {
  404.             rcpok=pc[15].choice;
  405.             Srcpmode(rcpok);
  406.           } /* end if */
  407. /*
  408. *    check whether to enable or disable the clock
  409. */
  410.         if((pc[16].choice)!=(int)(def.clock))
  411.             def.clock=pc[16].choice;
  412.       } /* end if */
  413. /*
  414. *  go back to telnet
  415. */
  416.     n_color(colsave);
  417.     wrest(current);
  418. }   /* end parmchange() */
  419.  
  420. /*********************************************************************/
  421. void helpmsg(void )
  422. {
  423.     int i;
  424.  
  425. /*  leavetek();  */
  426.     i=n_color(current->colors[0]); 
  427.  
  428.     n_clear();
  429.     n_cur(0,0);
  430.     n_puts("Keyboard usage for NCSA telnet: \n");
  431.     n_puts("Alt-A     Add a Session                    Alt-Y     Interrupt Process");
  432.     n_puts("Alt-N     Next Session                     Alt-B     Previous Session");
  433.     n_puts("Alt-D     Dump Screen to Capture File      Alt-O     Abort Output");
  434.     n_puts("Alt-M     Toggle mouse control             Alt-Q     Are you there?");
  435.     n_puts("Alt-E     Escape to COMMAND shell          Alt-U     Erase line");
  436.     n_puts("Alt-G     Graphics Menu                    Alt-K     Erase Kharacter");
  437.     n_puts("Alt-C     Toggle Capture On/Off            Alt-V     Paste Capture to session");
  438.     n_puts("Alt-R     Reset VT102 Screen               HOME      Exit Graphics Mode");
  439.     n_puts("Alt-H     This Help Screen                 Ctrl-HOME Clear/Enter Graphics mode");
  440.     n_puts("ScrLock   Enter/Exit Scroll-Back Mode- also pauses/restarts screen");
  441.     n_puts("Alt-Z     Messages Screen");
  442.     n_puts("Alt-F     Start File Transfer as if typed: ftp [internet address]");
  443.     n_puts("Alt-I     Send My Internet Address to host as if typed");
  444.     n_puts("Alt-S     Skip Scrolling, Jump Ahead");
  445.     n_puts("Alt-P     Change a Parameter, one of:");
  446.     n_puts("          color, capture file name, backspace, session name, screen mode");
  447.     n_puts("Alt-X      Close Connection");
  448.     n_puts("Ctrl-Shift-F3    Abort program completely.  STRONGLY discouraged");
  449.     n_puts("\n\nPress ESC for information page, space bar to return to session:");
  450.     n_color(i);
  451. }   /* end helpmsg() */
  452.  
  453. void help2(void )
  454. {
  455.     int i;
  456.  
  457.     i=n_color(current->colors[0]); 
  458.     n_clear();
  459.     n_cur(0,0);
  460.     n_puts("NCSA Telnet for the IBM PC version 2.3.05 3/1/92");
  461.     n_puts("\nNational Center for Supercomputing Applications, University of Illinois");
  462.     n_puts("written by Tim Krauskopf, Gaige B. Paulsen, Aaron Contorer, Heeren Pathak");
  463.     n_puts("    Kurt Mahan, Quincey Koziol, Chris Wilson & Jeff Wiedemeier\n");
  464. #ifndef beta
  465.     n_puts("This program is in the public domain.");
  466.     n_puts("Please retain the following notice:");
  467.     n_puts("\n  Portions developed by the National Center for Supercomputing Applications");
  468.     n_puts("  at the University of Illinois, Urbana-Champaign.");
  469. #else
  470. #ifndef alpha
  471.     n_puts("Authorized beta test version - open to technical users at your own risk.");
  472.     n_puts("Please report all problems that you wish fixed before Dec 31");
  473.     n_puts("All rights reserved.");
  474. #else
  475.     n_puts("Authorized alpha test version - open to technical users at your own risk.");
  476.     n_puts("Please report all problems that you wish fixed before September 22");
  477.     n_puts("All rights reserved.");
  478. #endif
  479. #endif
  480.     n_puts("\n\nFor information or for disks and manuals (there is a handling fee),");
  481.     n_puts("contact NCSA at:");
  482.     n_puts("152 Computing Applications Building");
  483.     n_puts("605 E. Springfield Ave.");
  484.     n_puts("Champaign, IL 61820");
  485.     n_puts("\nbugs and suggestions to pctelbug@ncsa.uiuc.edu");
  486.     n_puts("\nPress space bar to return to session");
  487.     n_color(i);
  488. }   /* end help2() */
  489.