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