home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / MODEMS / ZMODEM / ZMP-SRC.LBR / ZMTERM2.CZ / ZMTERM2.C
Text File  |  2000-06-30  |  9KB  |  448 lines

  1. /*            TERM module File 2                */
  2.  
  3.  
  4. #include "zmp.h"
  5.  
  6. #ifdef   AZTEC_C
  7. #include "libc.h"
  8. #else
  9. #include <stdio.h>
  10. #endif
  11.  
  12.  
  13. /* Display current keyboard macros */
  14. keydisp()
  15. {
  16.     short i;
  17.  
  18.     cls();
  19.     printf("\r\t\t");
  20.     stndout();
  21.     printf(" KEYPAD MACRO LIST \n\n");
  22.     stndend();
  23.     for (i=0; i<10; i++)
  24.         printf("\t%d - %s\n",i,KbMacro[i]);
  25.     printf("\n\n");
  26. }
  27.  
  28. /* Save a buffer to a file. If flag set, send ctl-s/ctl-q to stop remote */
  29. keep(filename,flag)
  30. char *filename;
  31. short flag;
  32. {
  33.     short fl;
  34.  
  35.     if (!BFlag)
  36.         return;
  37.     if (!TxtPtr)
  38.         goto cleanup;
  39.     if (flag)
  40.         mcharout(CTRLS);
  41.     while (TxtPtr % 128)
  42.         MainBuffer[TxtPtr++] = 0;
  43.     strcpy(Pathname,filename);
  44.     addu(Pathname,Invokdrive,Invokuser);
  45.     if ((fl = open(Pathname,1)) == UBIOT)
  46.         if ((fl = creat(Pathname,0)) == UBIOT)
  47.             openerror(fl,Pathname,UBIOT);
  48.     if (fl != UBIOT) {
  49.         lseek(fl,0L,2);       
  50.         write(fl,MainBuffer,TxtPtr);
  51.         close(fl);
  52.     }
  53.     if (flag)
  54.         mcharout(CTRLQ);
  55.     TxtPtr = 0;
  56.  
  57. cleanup:
  58.     free(MainBuffer);
  59. }
  60.  
  61. startcapture()     /* allocate capture buffer */
  62. {
  63.     char *grabmem();
  64.  
  65.     if (!BFlag)
  66.         return;
  67.     MainBuffer = grabmem(&Bufsize);
  68.     Buftop = Bufsize - 1;
  69.     TxtPtr = 0;
  70.  
  71. #ifdef DEBUG
  72.     printf("\ncapture Bufsize = %u\n",Bufsize);
  73. #endif
  74.  
  75. }
  76.  
  77. /* Allow user to change things */
  78. docmd()
  79. {
  80.     char c,parity,databits,stopbits;
  81.     int i,oldfdx,oldremecho,oldbaud;
  82.     unsigned baud;
  83.  
  84. start:
  85.     cls();
  86.     printf("\t\t");
  87.     stndout();
  88.     printf(" CHANGE LINE PARAMETERS \n");
  89.     stndend();
  90.     printf("\n\tB - Change Baud Rate (now %u)\n",
  91.         Baudtable[Current.cbaudindex]);
  92.     printf("\tD - Set Half/Full Duplex/Echo\n");
  93.     printf("\tF - Turn Control Character Filter %s\n",
  94.         Filter ? "OFF" : "ON");
  95.     printf("\tI - Initialise Modem\n");
  96.     printf("\tP - %s Parity Bit in Terminal Mode\n",
  97.         ParityMask ? "Pass" : "Strip");
  98.     printf("\tU - Set up UART: Parity, Stop Bits, Data Bits\n");
  99.     printf("\tZ - Exit\n");
  100.     printf("\n Select: ");
  101.     switch (c = toupper(bdos(CONIN))) {
  102.     
  103.         case 'B' :
  104.             do {
  105.                 printf("\nEnter new baud rate: ");
  106.                 scanf("%d",&baud);
  107.                 while(getchar() != '\n');    /* flush */
  108.                 for (i = 0; i < 13; i++)
  109.                     if (Baudtable[i] == baud)
  110.                         break;
  111.             }
  112.                 while (i > 12); /* Don't leave till it's right */
  113.             oldbaud = Current.cbaudindex;
  114.             Current.cbaudindex = i;
  115.             updateace();
  116.  
  117.                 /* error if change is intended but rejected */
  118.             if ((*Mspeed == oldbaud) && (i != oldbaud)) {
  119.                 Current.cbaudindex = oldbaud;
  120.                 printf("\nBaud rate %u not available.\n",baud);
  121.                 waitakey();
  122.             }
  123.             break;
  124.  
  125.         case 'D':
  126.             oldfdx = FDx;    /* Save original */
  127.             oldremecho = RemEcho;
  128.             FDx = TRUE;
  129.             RemEcho = FALSE;
  130.             printf("\n<F>ull Duplex, <H>alf Duplex or Remote <E>cho? ");
  131.             switch (c = toupper(bdos(CONIN))) {
  132.  
  133.                 case 'H' :
  134.                     FDx = FALSE;
  135.                     break;
  136.  
  137.                 case 'E' :
  138.                     FDx = FALSE;
  139.                     RemEcho = TRUE;
  140.                     break;
  141.  
  142.                 case 'F' :
  143.                     break;
  144.  
  145.                 default  :
  146.                     FDx = oldfdx;    /* no change */
  147.                     RemEcho = oldremecho;
  148.                 break;
  149.             }
  150.             break;
  151.  
  152.         case 'F':
  153.             Filter = !Filter;
  154.             break;
  155.  
  156.         case 'P':
  157.             ParityMask = !ParityMask;
  158.             break;
  159.  
  160.         case 'I':
  161.             initace(Current.cbaudindex,Current.cparity,
  162.                 Current.cdatabits,Current.cstopbits);
  163.             mstrout("\n\n",FALSE);
  164.             mstrout(Modem.init,FALSE);
  165.             while (readline(10) != TIMEOUT);
  166.             break;
  167.  
  168.         case 'U':
  169.             do {
  170.                 printf("\nEnter new parity (E, O, N): ");
  171.                 parity = toupper(bdos(CONIN));
  172.             }
  173.                 while ((parity != 'E') && (parity != 'O')
  174.                     && (parity != 'N'));
  175.             Current.cparity = parity;
  176.             do {
  177.                 printf("\nEnter number of data bits (7,8): ");
  178.                 databits = toupper(bdos(CONIN));
  179.             }
  180.                 while ((databits != '7') && (databits != '8'));
  181.             Current.cdatabits = databits - '0';
  182.             do {
  183.                 printf("\nEnter number of stop bits (1,2): ");
  184.                 stopbits = toupper(bdos(CONIN));
  185.             }
  186.                 while ((stopbits != '1') && (stopbits != '2'));
  187.             Current.cstopbits = stopbits - '0';
  188.             updateace();
  189.             break;
  190.  
  191.  
  192.         case ESC:
  193.         case 'Z':
  194.             return;
  195.  
  196.         default:
  197.             break;
  198.  
  199.     }        /* End of main switch */
  200.     goto start;    /* Loop till esc or Z */
  201. }
  202.  
  203. capturetog(filename)
  204. char *filename;
  205. {
  206.     if (!BFlag) {
  207.         BFlag = TRUE;
  208.         startcapture();
  209.         if (allocerror(MainBuffer))
  210.             BFlag = FALSE;
  211.         else {
  212.             printf("\nEnter capture filename (cr = %s): ",filename);
  213.             if (getline(Buf,16))
  214.                 strcpy(Lastlog,Buf);
  215.             else
  216.                 strcpy(Lastlog,filename);
  217.             printf("\nCapture ON\n");
  218.         }
  219.     }
  220.     else {
  221.         keep(Lastlog,FALSE);    /* assume remote not running */
  222.         BFlag = FALSE;
  223.         printf("\nCapture OFF\n");
  224.     }      
  225. }
  226.  
  227. comlabel() /*print level 2 labels*/
  228. {
  229. /*                    ** Removed for now
  230.    killlabel();
  231.    printf(
  232.    "%s2> \033p   Dial%sHost%sConfigure%sPrint%sDisk%sHangup%s Level %s",
  233.     Stline,Vl,Vl,Vl,Vl,Vl,Vl,Vl);
  234.    printf("Help%sQuit%s   %02d%c%d%d%s%s%s%s%s%s\033q%s",Vl,Vl,
  235.     Baudtable[Current.cbaudindex]/100,Current.cparity,Current.cdatabits,
  236.     Current.cstopbits,Vl,BFlag?"LG":"--",Vl,PFlag?"PR":"--",Vl,
  237.     FDx?"FDX":"HDX",Endline);
  238. */
  239. }
  240.  
  241. scplabel()
  242. {
  243.     /*        removed
  244.            putlabel("READING THE SCREEN -> Please wait...");
  245.     */
  246. }
  247.  
  248. diskstuff()
  249. {
  250.     static int c,drive,user;
  251.     char newname[20];
  252.     char q, *j;
  253.  
  254.     for (;;) {
  255.         cls();
  256.         printf("\r\t\t");
  257.         stndout();
  258.         printf(" FILE AND DISK COMMANDS \n");
  259.         stndend();
  260.         printf("\n\tC - Change disk in default drive\n");
  261.         printf("\tD - Directory of current disk\n");
  262.         printf("\tE - Erase file on default drive\n");
  263.         printf("\tF - Change default name of capture file (currently %s)\n",
  264.             Logfile);
  265.         printf("\tL - Log into new du: (currently %c%d:)\n",Currdrive,Curruser);
  266.         printf("\tP - Print a file on default drive\n");
  267.         printf("\tR - Rename a file on default drive\n");
  268.         printf("\tV - View a file on default drive\n");
  269.         printf("\tZ - Exit\n");
  270.         printf("\n Select: ");
  271.         flush();
  272.         c = toupper(chrin());
  273.         switch (c) {
  274.  
  275.     case 'C':
  276.         printf("\nChange disk in %c: then press any key...",Currdrive);
  277.         flush();
  278.         chrin();
  279.         reset(Currdrive,Curruser);
  280.         break;
  281.  
  282.     case 'D':
  283.         directory();
  284.         waitakey();
  285.         break;
  286.  
  287.     case 'E':
  288.         if (!possdirectory("Erase"))
  289.             break;
  290.         printf("\nAre you sure? (Y/N) <N>  ");
  291.         flush();
  292.         c = toupper(chrin());
  293.         if (c == 'Y')
  294.             unlink(Pathname);
  295.         break;
  296.  
  297.     case 'F':
  298.         if (!BFlag) {
  299.             printf("\nEnter new filename: ");
  300.             scanf("%s",Logfile);
  301.         }
  302.         else {
  303.             printf("\nNot while capture on!\n");
  304.             waitakey();
  305.         }
  306.         break;
  307.  
  308.     case 'L':
  309.         printf("\nEnter the new default du:  ");
  310.         flush();
  311.         if (!getline(Pathname,10))
  312.             break;
  313.         drive = Currdrive;
  314.         user = Curruser;
  315.         j = Pathname;
  316.         if (isalpha(q = toupper(j[0]))) {
  317.             drive = q;
  318.             j++;
  319.         }
  320.         if (isdigit(q = j[0]))
  321.             user = q - '0';
  322.         if (isdigit(q = j[1]))
  323.             user = user * 10 + q - '0';
  324.         reset(drive,user);
  325.         break;
  326.  
  327.     case 'P':
  328.         if (!possdirectory("Print"))
  329.             break;
  330.         addu(Pathname,Currdrive,Curruser);
  331.         printfile(Pathname);
  332.         break;
  333.  
  334.     case 'R':
  335.         if (!possdirectory("Rename"))
  336.             break;
  337.         flush();
  338.         printf("New name for %s: ",Pathname);
  339.         if (!getline(newname,16))
  340.             break;
  341.         rename(Pathname,newname);
  342.         break;
  343.  
  344.     case 'V':
  345.         if (!possdirectory("View"))
  346.             break;
  347.         addu(Pathname,Currdrive,Curruser);
  348.         cls();
  349.         viewfile(Pathname);
  350.         waitakey();
  351.         break;
  352.  
  353.     case 'Z':
  354.     case ESC:
  355.         return;
  356.  
  357.     default:
  358.         break;
  359.       }
  360.    }
  361. }
  362.  
  363. /* Prompt user and possibly give directory */
  364. possdirectory(prompt)
  365. char *prompt;
  366. {
  367.     short x;
  368.  
  369.     do {
  370.         printf("\n%s which file (CR = quit, ? = directory)? ",prompt);
  371.         if (!getline(Pathname,16))
  372.             return FALSE;
  373.         if (x = (Pathname[0] == '?'))
  374.             directory();
  375.     }
  376.     while (x);
  377.     return TRUE;
  378. }
  379.  
  380. help()
  381. {
  382.     int c;
  383.  
  384.     cls();
  385.     printf("\r\t\t\t\t");
  386.     stndout();
  387.     printf(" ZMP HELP \n\n");
  388.     stndend();
  389.     strcpy(Pathname,"ZMP.HLP");
  390.     addu(Pathname,Overdrive,Overuser);
  391.     viewfile(Pathname);
  392.     printf("\nEnter function (cr to abort): ");
  393.     return ((c = dio()) == CR ? 0 : c);
  394. }
  395.  
  396. /* View a file set up in Pathname */
  397. viewfile()
  398. {
  399.     int i;
  400.     char c, kbdata;
  401.     FILE *fd;
  402.  
  403.     fd = fopen(Pathname,"rb");    /* Use binary or it ignores CR */
  404.     if (openerror(fd,Pathname,BUFIOT))
  405.         return;
  406. newpage:
  407.     for (i = 0; (i < 21) && ((c=getc(fd)) != EOF) && (c != CTRLZ); ) {
  408.         if (c != LF)
  409.             putchar(c);
  410.         if (c == CR) {        /* This will even print TRS80 files */
  411.             putchar(LF);
  412.             ++i;
  413.         }
  414.     }
  415.     if ((c == EOF) || (c == CTRLZ))
  416.         goto viewend;
  417.     printf("\n\n Typing %s - ",Pathname);
  418.     flush();
  419.     if (((kbdata = bdos(CONIN)) == CTRLC) || (kbdata == CTRLX))
  420.         goto viewend;
  421.     printf("\n");
  422.     goto newpage;
  423. viewend:
  424.     fclose(fd);
  425. }
  426.  
  427. /* Print a file set up in Pathname */
  428. printfile()
  429. {
  430.     char c;
  431.     FILE *fd;
  432.  
  433.     fd = fopen(Pathname,"rb");    /* Use binary or it ignores CR */
  434.     if (openerror(fd,Pathname,BUFIOT))
  435.         return;
  436.     printf("\nAny key to abort..\n");
  437.     while (((c=getc(fd)) != EOF) && (c != CTRLZ)
  438.         && !(bdos(DIRCTIO,INPUT))) {
  439.         if (c != LF)
  440.             bdos(5,c);    /* list output */
  441.         if (c == CR)        /* This will even print TRS80 files */
  442.             bdos(5,LF);
  443.     }
  444.     fclose(fd);
  445. }
  446.  
  447. /*            End of TERM module File 2            */
  448.