home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / researchmachines.zip / rmlpar.c < prev    next >
Text File  |  1985-07-11  |  14KB  |  443 lines

  1.  
  2. /***************************************************************************/
  3.  
  4. /*  File KPARM.C for RML Kermit,
  5.     Chris Kennington,        8th July 1985.            */
  6.  
  7. #define     DEFS1    1
  8. #define     DEFS3    1
  9.  
  10. #include    "stdio.h"
  11. #include    "b:kext.h"
  12.  
  13.  
  14. /* Structure for handling parameters in set/show:-            */
  15.  
  16. struct  parm  {                /* parameter-description    */
  17.     int        (*p_action)();    /* action-routine        */
  18.     CHAR        p_key;        /* key-letter (inverse capital)    */
  19.     char        *p_name;    /* parameter-name        */
  20.     unsigned    *p_value;    /* pointer to variable        */
  21.     CHAR        p_vtype;    /* code for type of value    */
  22.     char        *p_vtexts[10];    /* descriptions of up to 10 values */
  23.     char        *p_help[5];    /* up to 5 lines of help-text    */
  24. } ;
  25. /* N.B.  The actual variable holding the value is not a structure member,
  26.      but is the object of p_value.  If it is int, then bit0 of p_vtype = 0;
  27.      if it is char, bit0 of p_vtype = 1.  Where it is char, if it takes
  28.      values 0-9 corresponding to p_vtexts, then bits 1/2 = 00; if it takes
  29.      character values, then bits 1/2 = 01; if it takes hex values, = 11.
  30.    p_action() is the routine which gives effect to a change in the setting
  31.      of p_value; for unimplemented parameters or values is pmnyi().    */
  32.  
  33.     
  34. extern  int    chkbaud(), no_op(), pmnyi(), set8(), setlen(), setflow(), setpar();
  35. extern    unsigned  int    getval();
  36. /* these declared here to prevent "undeclared" errors in initializations */
  37.  
  38.  
  39. /* static global variables (local to this file)            */
  40. #ifdef MPUZ80
  41. static  char    flowcode = 1;        /* CTS/RTS default for 480Z    */
  42. #else
  43. static  char    flowcode = 0;        /*  but not for Nimbus        */
  44. #endif
  45. static    char    *pointc;
  46. static  char    firston, laston, /* first & last entries on display    */
  47.         index;        /* current parameter-number        */
  48. static  int    psiz = 0, line, *pointi;
  49. static  struct  parm  *pm;         /* pointer to current parm    */
  50. static    CHAR    ptype;            /* type of current parm    */
  51.  
  52. /* Local strings                        */
  53. static char off[]    = "0 = OFF";
  54. static char on[]    = "1 = ON";
  55. static char arros[]    = "  Arrows set parameters  ";
  56. static char hfor[]    = "  H for Help  ";
  57. static char toexit[]    = "  RETURN to Continue  ";
  58. static char hdr1[]    = "Key";
  59. static char hdr2[]    = "Parameter";
  60. static char hdr3[]    = "Current Setting";
  61. static char maychange[]    = "This parameter needs agreement from remote Kermit and may therefore change. ";
  62.  
  63. static  char  *genhelp[] = {
  64. "Parameter Setting:   Use up \136 & down \036 arrows to find the parameter to be",
  65. "-----------------    changed, or F1 & F3 to find another page of parameters.",
  66. "                     Use right \035 & left \033 arrows to change setting of the",
  67. "        parameter you have selected.  \"?\" for help on the current parameter.",
  68. kqhelp};
  69.  
  70.  
  71. /* structures for controllable parameters            */
  72.  
  73. static  struct  parm  pecho =    {&no_op,0xc5,"Local Echo",&echo,0,
  74.                 off,on,0,0,0,0,0,0,0,0,
  75. "Local Echo:   If ON, all characters sent to mainframe in Connect Mode will also",
  76. "-----------   be displayed on the screen.  Required for \"half-duplex\" working.",0};
  77.  
  78. static  struct  parm  pavoid =    {&no_op,0x20,"File Collision",&nmavoid,1,
  79.                 "Overwrite","Rename","Refuse","Ask user",
  80.                 0,0,0,0,0,0,
  81. "Collision Avoidance:  If the name of an incoming file matches one already on",
  82. "--------------------  the disk, it will overwrite the old one, be renamed to",
  83. "                      avoid overwriting, or be rejected, or the user will be",
  84. "asked for permission to overwrite, according to value of this parameter.",0};
  85.  
  86. static  struct  parm  pimage = {&set8,0x20,"8th-bit mode",&image,0,
  87.                 "7-bit stripped","8-bit image","8-bit prefixed",
  88.                 0,0,0,0,0,0,0,
  89. "8th-Bit Handling:   Normally OFF; all data sent/received as 7-bit characters",
  90. "-----------------   (top bit zero).  In IMAGE, all 8 bits sent and received,",
  91. "                    but this may not always work; PREFIXED gets around",
  92. "this problem, but not all Kermits can cope.",0};
  93.  
  94. static  struct  parm  ppkt = {&setlen,0x20,"Packet-Size",&psiz,0,
  95.                 "94 bytes","86 bytes","78 bytes","70 bytes",
  96.                 "62 bytes","54 bytes","46 bytes","38 bytes",
  97.                 0,0,    /* reduce in 8s to ease calculation */    
  98. "Size of Packet:   Maximum length of data-packets on line; 95 should normally",
  99. "---------------   be used since shorter packets mean slower transfers.",0};
  100.  
  101. static  struct  parm  ppage = {&no_op,0x20,"Page-Wait",&pager,1,
  102.                 off,"4 lines","8 lines","12 lines","16 lines",
  103.                 "20 lines","24 lines",0,0,0,
  104. "Page-Wait:   If turned ON, mainframe output in Connect Mode, and data listing",
  105. "----------   in Disk Maintenance, will be held up every screenfull.",0};
  106.  
  107. static  struct  parm  plist = {&no_op,0xcc,"List/Debug",&list,0,
  108.                 off,"Dot-per-Block","Data-Listing","Debug Trace",
  109.                 "Debug Data","Debug Overkill",0,0,0,0,
  110. "List - Debug:   Normally ON, a dot will be printed for each good data-block",
  111. "-------------   to/from the mainframe (with D, C, T for duplicates,",
  112. "                checksum-errors & timeouts); alternatively all data sent or",
  113. "received may be listed.  Debug settings give increasing amounts of trace",
  114. "information."};
  115.  
  116. static  struct  parm  pnslow = {&no_op,0xce,"Slow-Network",&netslow,1,
  117.                 off,on,0,0,0,0,0,0,0,0,
  118. "Slow-Network:   If ON, steps taken so that duplicate blocks held in the",
  119. "-------------   communications network are discarded.  Use if many duplicates",
  120. "                are reported.",0};
  121.  
  122. static  struct  parm  ppar = {&setpar,0x20,"Parity Generation",&parity,0,
  123.                 off,"1 = Odd","2 = Even","3 = Mark",
  124.                 0,0,0,0,0,0,
  125. "Parity:   Controls the addition of parity to all characters sent to mainframe;",
  126. "-------   normally OFF, but can be set to give Odd, Even or Mark parity.",
  127. "          Must always be off during IMAGE transfers.",
  128. "Parity of incoming data is not checked; characters received are stripped to",
  129. "7 bits (except in IMAGE)."};
  130.  
  131. static  struct  parm  pbaud = {&chkbaud,0x20,"Baud-Rate",&spdcode,1,
  132.                 sp0,sp1,sp2,sp3,sp4,sp5,sp6,sp7,0,0,
  133. "Baud-Rate:   Speed (in baud) to which the communications line is set.",
  134. "----------",0};
  135.  
  136. static  struct  parm  pflow = {&setflow,0x20,"Flow-Control",&flowcode,1,
  137.                 "None","CTS-RTS","XON/XOFF","CTS & XON/XOFF",
  138.                 "ENQ-ACK","CTS & ENQ/ACK",0,0,0,0,
  139. "Flow-Control:  CTS/RTS is hardware control using control lines; XON/XOFF, alias",
  140. "-------------  Tandem, uses these chars (11H & 13H) to hold up and reenable",
  141. "               transmission; ENQ/ACK sends an ACK (06H) whenever an ENQ (05H)",
  142. "or an ETX (03H) is received and processed.  The first two work in both",
  143. "directions.  Kermit works OK without flow-control in most cases.";
  144.  
  145. static  struct  parm  *pmlist[] = {&pbaud,&ppar,&plist,&pimage,&ppage,
  146.                     &pavoid,&ppkt,&pnslow,&pecho,
  147.                     &pflow,0};
  148.  
  149. #define     PMCOUNT    10        /* number of entries in pmlist[] */
  150.  
  151.  
  152.  
  153. /* Procedures for handling parameter-structures            */
  154.  
  155. static chkbaud()    /* validate baud-rate            */
  156. {
  157.     if (getval() <= MAXSPD)
  158.     setbaud();
  159.     else
  160.     pmnyi();
  161.     return;
  162. }            /* end of chkbaud()            */
  163.  
  164.  
  165.  
  166. static down1()        /* go down one parm            */
  167. /* returns -1 if already at bottom, else 0            */
  168. {
  169.     if (index == (PMCOUNT-1))    /* already on last parm        */
  170.     return(-1);
  171.     else {            /* move down to next parm    */
  172.     vtout( (line+PA2COL), SP );    /* wipe arrow        */
  173.     pm = pmlist[++index];
  174.     if (index > laston) {        /* is bottom entry    */
  175.         scroll(2);
  176.         pmdisp(line);
  177.         ++laston;
  178.         ++firston;
  179.     }
  180.     else                /* another below    */
  181.         line += 512;        /*  so down 2 lines    */
  182.     vtout( (line+PA2COL), LARROW );  /* point to new entry    */
  183.     }
  184.     return(0);
  185. }            /* End of down1()            */
  186.  
  187.  
  188.  
  189. static unsigned getval()    /* return value of parm        */
  190. {
  191.     unsigned    val;
  192.  
  193.     ptype = pm->p_vtype & (char)0x01; /* update parm-type    */
  194.     pointc = pointi = pm->p_value;    /*  & typed value-pointers*/
  195.     if (ptype == 0)        /* integer            */
  196.     val = *pointi;
  197.     else            /* char                */
  198.     val = *pointc & 0xff;
  199.     return(val);
  200. }            /* end of getval()            */
  201.  
  202.  
  203. static pmnyi()        /* tell user not yet implemented    */
  204. {
  205.     vtline( (line+256), "This parameter (or value) not yet implemented." );
  206.     return;
  207. }            /* end of pmnyi()            */
  208.  
  209.  
  210. static  pmdisp(ln)        /* display parameter settings    */
  211. /* ln is number of line-on-screen * 256                */
  212. int    ln;
  213. {
  214.     int      pos;
  215.     unsigned  i;
  216.     char  *t;
  217.  
  218.     cursor(0);
  219.     vtline(ln,blanx);        /* clear garbage    */
  220.     pos = ln + PKCOL;        /* position for letter  */
  221.     vtout(pos,pm->p_key);
  222.     pos = ln + PNMCOL;
  223.     vtline(pos,pm->p_name);    /*  name of parameter    */
  224.     pos = ln + PVCOL;
  225.     i = getval();
  226.     t = pm->p_vtexts[i];
  227.     if ( (i > 9 ) || (t == 0 ) )
  228.     bell();
  229.     else
  230.     vtline(pos,t);        /* value of parmeter    */
  231.     return;
  232. }        /* end of pmdisp()            */
  233.  
  234.  
  235.  
  236. scrdiv()        /* divide screen for menu        */
  237. {
  238.     int     i;
  239.  
  240.     keyinit();
  241.     for (i=SCRTOP-2; i< SCRLEN; ++i)
  242.     vtline((int)i*256,blanx);
  243.     vtline((SCRBOT+1)*256,divisor);
  244.     vtline((SCRBOT+1)*256+9,arros);
  245.     vtline((SCRBOT+1)*256+38,hfor);
  246.     vtline((SCRBOT+1)*256+55,toexit);
  247.  
  248.     screen(SCRTOP,SCRBOT);
  249.     curset(SCRTOP,0);        /* cursor @ home        */
  250.     cursor(0);            /* but switched off        */
  251.     return;
  252. }            /* End of scrdiv()            */
  253.  
  254.  
  255.  
  256. static set8()        /* check 8th-bit handling        */
  257. {
  258.     if (image > 1)
  259.     vtline((line+256),maychange);
  260.     oldimage = image;
  261.     return;
  262. }            /* end of set8                */    
  263.  
  264.  
  265. static setflow()    /* set flowcontrol from flowcode    */
  266. {
  267. #ifdef MPUZ80
  268.   /* 480Z - all working except enq/ack    */
  269.     if (flowcode > 3)
  270. #else
  271.   /* Nimbus - only XON/OFF working    */
  272.     if ( (flowcode & 0x0d) != 0 )
  273. #endif
  274.     pmnyi();
  275.     else {
  276.     commode &= 0xfc;
  277.     commode |= flowcode;
  278.     s4set(commode,comctrl);
  279.     }
  280.     return;
  281. }            /* end of setflow()            */
  282.  
  283.  
  284.  
  285. static setlen()        /* set receive & send lengths        */
  286. {
  287.     rpsiz = 94- (psiz << 3);
  288.     if (spsiz > rpsiz)
  289.     spsiz = rpsiz;
  290.     vtline((line+256),maychange);
  291.     return;
  292. }            /* end of setlen()            */
  293.  
  294.  
  295. setshow()        /* set & show parameter values            */
  296. /* Used in PARM mode to allow display of current parameter settings and
  297.      manipulation of them, with help displays.                */
  298. {
  299.     CHAR    c, d;
  300.     char    i, *text;
  301.     int        lin2;
  302.     unsigned    value;        /* value of current parameter        */
  303.  
  304.     scrdiv();
  305.     vtline((SCRTOP-2)*256+PKCOL-1,hdr1);
  306.     vtline((SCRTOP-2)*256+PNMCOL+1,hdr2);
  307.     vtline((SCRTOP-2)*256+PVCOL-2,hdr3);
  308.  
  309.     line = FIRSTLINE;
  310.     for (i=0; i<SCRSIZE; ++i) {        /* display parms 0-4        */
  311.     pm = pmlist[i];
  312.     pmdisp(line);
  313.     line += 256;
  314.     vtline(line,blanx);
  315.     line += 256;
  316.     }
  317.     firston = 0;
  318.     laston = SCRSIZE-1;
  319.  
  320.     line = FIRSTLINE;
  321.     index = 0;
  322.     pm = pmlist[0];
  323.     vtout( (line+PA2COL), LARROW );    /* arrow parm 0            */
  324.  
  325.     forever {                /* until broken out        */
  326.     while (keyget(&c) == 0)
  327.         ;
  328.     c &= 0x5f;            /* strip top & l.c. bits    */
  329.   /* c is now an upper-case char corresponding to an arrow-key or whatever */
  330.     vtline((line+256),blanx);    /* clear line below        */
  331.  
  332.     switch (c) {            /*  and take action on it    */
  333.  
  334.       case 'D':            /* down-arrow            */
  335.       case LF:
  336.         if (down1() != 0)
  337.         bell();
  338.         break;
  339.  
  340.       case 'U':            /* up-arrow            */
  341.       case 0x5e:            /*  carat            */
  342.         if (up1() != 0)
  343.         bell();
  344.         break;
  345.  
  346.       case 'R':        /* right arrow - next value        */
  347.       case 0:        /* SP & 0x5f                */
  348.         value = getval() + 1;
  349.         text = pm->p_vtexts[value];
  350.         if ( (text == 0) || (value > 9) ) /* increment value    */
  351.         value = 0;            /* cycle values        */
  352.         goto Update;
  353.  
  354.       case 'L':        /* left arrow - previous value        */
  355.         value = getval();
  356.         if (value == 0) {            /* if first value    */
  357.         while ( (pm->p_vtexts[++value] != 0)
  358.           && (value < 10) )
  359.             ;                /* find first invalid    */
  360.         }
  361.         --value;
  362. Update:
  363.         if (ptype == 0)             /* if => int        */
  364.         *pointi = value;
  365.         else                /* if => char        */
  366.         *pointc = (char)value;
  367.         pmdisp(line);            /* update display    */
  368.         (*pm->p_action)();            /* call routine        */
  369.         vtout( (line+PA2COL), LARROW );
  370.         break;
  371.  
  372.       case 'N':        /* next page of values            */
  373.         for (i=0; i<(SCRSIZE-1); ++i)
  374.         if (down1() != 0)
  375.             break;
  376.         break;
  377.  
  378.       case 'B':        /* back one page of values        */
  379.         for (i=0; i<(SCRSIZE-1); ++i) 
  380.         if (up1() != 0)
  381.             break;
  382.         break;
  383.  
  384.       case 'Q':        /* quit from Kermit (after check)    */
  385.         screen(5,23);
  386.         clear5();
  387.         curset(19,5);
  388.         kermkill(0);
  389. /* fall thro into 'K'if not confirmed                    */
  390.       case 'K':            /* return to Kermit        */
  391.         abtflag = 1;
  392.       case CR:
  393.         screen(5,23);
  394.         clrscrn();
  395.         curset(6,0);
  396.         cursor(1);
  397.         return;
  398.  
  399.       case '?':            /* help on current param    */
  400.       case 0x1f:            /* '?' & 0x5f            */
  401.       case 0x0f:            /* '/' & 0x5f            */
  402.         clear5();
  403.         show5(pm->p_help);
  404.         break;
  405.  
  406.       default:
  407.         bell();
  408.       case 'H':
  409.         clear5();
  410.         show5(genhelp);        /* general help            */
  411.  
  412.     }            /* end switch                */
  413.     }                /* end while                */
  414. }            /* end setshow()                */
  415.  
  416.  
  417.  
  418. static up1()        /* up one parm                */
  419. /* returns -1 if already at top, else 0                */
  420. {
  421.     if (index == 0)        /* already on first parm    */
  422.     return(-1);
  423.     else {            /* move up to next parm        */
  424.     vtout( (line+PA2COL), SP );    /* wipe arrow        */
  425.     pm = pmlist[--index];
  426.     if (firston > index ) {        /* is top entry        */
  427.         scroll(-2);
  428.         pmdisp(line);
  429.         --firston;
  430.         --laston;
  431.     }
  432.     else                /* another below    */
  433.         line -= 512;        /*  so up 2 lines    */
  434.     vtout( (line+PA2COL), LARROW );  /* point to new entry    */
  435.     return(0);
  436.     }
  437. }            /* End of up1()                */
  438.  
  439.  
  440.  
  441. /************** END of File KPARM.C ********************************/
  442.  
  443.