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 / ENTERPRS / CPM / TERMS / RZMP-SRC.LZH / RZMP.C < prev    next >
Text File  |  2000-06-30  |  12KB  |  349 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*            RZMP: Remote ZMODEM program            */
  4. /*                                    */
  5. /*    Developed from Hal Maney's HMODEM II via ZMP by Ron Murray    */
  6. /*                                    */
  7. /*        Usage: RZMP [options] [count]                */
  8. /*        Options are:                        */
  9. /*            R - Receive files                */
  10. /*            S - Send files                    */
  11. /*            F - Send files listed in RZMP.DAT        */
  12. /*            Q - Shutup flag: No non-error messages        */
  13. /*                                    */
  14. /*        count is number of files in RZMP.DAT (F option only)    */
  15. /*                                    */
  16. /*    V1.0 rjm 7/9/88                            */
  17. /*                                    */
  18. /*    Finally released as v1.3 (after extensive debugging)        */
  19. /*        rjm 12/10/88                        */
  20. /*                                    */
  21. /*    v1.4 rjm 15/10/88                        */
  22. /*        - Read a file to determine files to send to work with    */
  23. /*            ZMSELECT                    */
  24. /*        - Shutup flag                        */
  25. /*        - produces output file of fils transferred for use by    */
  26. /*            RZMPLOG                        */
  27. /*                                    */
  28. /************************************************************************/
  29. /*                                                                      */
  30. /*  This source code may be distributed freely without restriction      */
  31. /*  for the express purpose of promoting the use of the ZMODEM          */
  32. /*  file transfer protocol.  Programmers are requested to include       */
  33. /*  credit (in the source code) to the developers for any code          */
  34. /*  incorporated from this program.                                     */
  35. /*                                                                      */
  36. /************************************************************************/
  37. /*                                    */
  38. /* The following files in this library are required to compile RZMP:    */
  39. /*                                    */
  40. /*    rzmp.c        -- This file. Contains nucleus routines        */
  41. /*                common to both send and receive.    */
  42. /*    rzmp2.c        -- Second half of nucleus routines.        */
  43. /*    rzmp3.c        -- Send routines.                */
  44. /*    rzmp4.c        -- Receive routines.                */
  45. /*                                    */
  46. /* The following files are also necessary to compile RZMP, but are    */
  47. /*   not contained in this library. They are in ZMP-SRC.LBR, as they    */
  48. /*   are common to both ZMP and RZMP:                    */
  49. /*                                    */
  50. /*    zmp.h        -- Header file. Contains #defines etc. for    */
  51. /*                both ZMP and RZMP.            */
  52. /*    zmodem.h    -- zmodem header file                */
  53. /*    zzm.c        -- Chuck Forsberg's zm.c modified for cp/m by    */
  54. /*                Hal Maney and Ron Murray        */
  55. /*    zzm2.c        -- Part 2 of the above                */
  56. /*                                    */
  57. /*                                    */
  58. /*    These files are designed to be compiled by Hi-Tech C.        */
  59. /*                                    */
  60. /************************************************************************/
  61.  
  62.  
  63. #define MAIN
  64. #define RZMP
  65.  
  66. #include "zmp.h"
  67. #include <stdio.h>
  68. #include <signal.h>
  69.  
  70. main(argc,argv)
  71. int argc;
  72. char **argv;
  73. {
  74.     char *p, *r, filename[18], *malloc(), *list, *index();
  75.     int fd;
  76.     short i, drive, user, nactim, count, size;
  77.     unsigned short bytes;
  78.  
  79.     signal(SIGINT,SIG_IGN);        /* Ignore control-c's */
  80.  
  81.     setup(argc,argv[1]); /* Set up globals from overlay and command line */
  82.     userin();            /* user-defined entry routine */
  83.  
  84.     if (!Shutup)
  85.         printf("\nRZMP %s\n\n",Version);
  86.  
  87.         /* abort if he hasn't typed RZMP R or RZMP S */
  88.  
  89.     if (!Receive && !Transmit) {
  90.         dohelp();    /* tell him what he SHOULD have said */
  91.         doexit();        /* then quit */
  92.     }
  93.     if(bdos(32,241) != 77) {    /* BYE existence test */
  94.         printf("BYE not running: aborted.\n");
  95.         doexit();
  96.     }
  97.  
  98.     Current.cbaudindex = *Mspeed; /* set current baud rate */
  99.     Invokdrive = bdos(GETCUR) + 'A'; /* current drive .. */
  100.     Invokuser = getuid();    /* .. and user area */
  101.     drive = Currdrive = Invokdrive; /* set default du: to current */
  102.     user = Curruser = Invokuser;
  103.     MAdrive = bdos(69,255) + 'A';    /* set max drive and user */
  104.     MAuser = bdos(70,255);
  105.     nactim = bdos(71,255);    /* get current value of no-activity timer */
  106.     bdos(71,254);        /* disable non-activity timeout */
  107.     bdos(89,1);        /* disable non-activity beeps */
  108.     openlog();        /* try to open .LOG file */
  109.  
  110.     if (Receive) {    /* receive files */
  111.         if (!(*Wheel))
  112.             if (!Private) { /* Non-wheels get B0: */
  113.                 drive = Currdrive = Upldrive;
  114.                 user = Curruser = Upluser;
  115.                 bdos(SELDSK,Currdrive - 'A');
  116.                 setuid(Curruser);
  117.             }
  118.             else {  /* private area upload */
  119.                 drive = Uprivdrive;
  120.                 user = Uprivuser;
  121.             }
  122.         if (!Shutup)
  123.             printf("File will be received on %c%d:\n",
  124.                 drive,user);
  125.         repready();
  126.         bringin();
  127.     }
  128.  
  129.     if (Transmit) {            /* send files */
  130.         if (!Filemode) {    /* send from command line */
  131.             if (argc < 3)
  132.                 printf("You must specify filenames.\n");
  133.             else {
  134.                 Pathname[0] = '\0';    /* Put filenames in Pathname */
  135.                 for (i = 2; i < argc; i++) {
  136.                 strcat(Pathname,argv[i]);
  137.                     if (i != argc-1) /* separate with spaces */
  138.                         strcat(Pathname," "); /* except the last*/
  139.                 }
  140.                 sendout(Pathname);
  141.             }
  142.         }
  143.         else if (argc > 2) { /* list of send files from disk file */
  144.             strcat(filename,Infile);    /* get filename */
  145.             addu(filename,Tempdrive,Tempuser);    /* add du: */
  146.             if ((fd = open(filename,0)) != UBIOT) {    /* open file */
  147.                 sscanf(argv[2],"%d",&count);
  148.                 size = count * 18 + 1;
  149.                     /* now get some memory to put it in */
  150.                 if (count && !allocerror(r = list = malloc(size))) {
  151.                     if (bytes = read(fd,list,size)) {
  152.  
  153.         /* need to go through buffer and change cr/lf to space */
  154.             /* then move rest of file down */
  155.                         list[bytes - 1] = '\0';
  156.                         for (i = 0; i < count; i++)
  157.                             if (p = index(list, '\r')) {
  158.                                 *p = ' ';
  159.                                 strcpy(p + 1, p + 2);
  160.                                 r = p;
  161.                             }
  162.                             else
  163.                                 break;
  164.                             *r = '\0'; /* terminate */
  165.                         sendout(list);    /* send it all */
  166.                     }
  167.                     free(list);
  168.                 }
  169.                 fclose(fd);
  170.                 unlink(filename);    /* erase the file */
  171.             }
  172.             else
  173.                 printf("Command file not found.\n");
  174.         }
  175.     }
  176.     closelog();            /* close output log */
  177.     bdos(SELDSK,Invokdrive - 'A');
  178.     setuid(Invokuser);
  179.     bdos(71,nactim);        /* re-enable non-activity timeout */
  180.     bdos(89,0);            /* and bells */
  181.     doexit();
  182. }
  183.  
  184. /* Set up global variables */
  185. setup(i,options)
  186. short i;
  187. char *options;
  188. {
  189.     char *p;
  190.     int *q, *getvarsr();
  191.  
  192.     q = getvarsr();            /* pointer to data */
  193.     Wheel = (char *) *q++;
  194.     Mspeed = (char *) *q++;
  195.     Uploads = (char *) *q++;    /* and upload/download count */
  196.     Downloads = (char *) *q++;
  197.     Badtypes = (char *) *q++;    /* Pointer to bad filetype list */
  198.     p = (char *) (q + 5);        /* 5 spares */
  199.     Upldrive = (int) *p++;        /* system configuration */
  200.     Upluser = (int) *p++;        /* non-wheel upload area */
  201.     Logdrive = (int) *p++;        /* .LOG area */
  202.     Loguser = (int) *p++;
  203.     Uprivdrive = (int) *p++;    /* private upload area */
  204.     Uprivuser = (int) *p++;
  205.     Dprivdrive = (int) *p++;    /* private download area */
  206.     Dprivuser = (int) *p++;
  207.     Tempdrive = (int) *p++;        /* scratch area */
  208.     Tempuser = (int) *p++;
  209.  
  210.     Filemode = Private = Shutup = Receive = Transmit = FALSE;
  211.     if (i > 1) {        /* get options */
  212.         Filemode = (int) index(options,'F');
  213.         Private = (int) index(options,'P');
  214.         Shutup = (int) index(options,'Q');
  215.         Receive = (int) index(options,'R');
  216.         Transmit = (int) index(options,'S');
  217.     }
  218. }
  219.  
  220. /* Done. */
  221. doexit()
  222. {
  223.     userout();        /* user-defined exit routine */
  224.     exit(0);
  225. }
  226.  
  227. /* User is confused: tell him off */
  228. dohelp()
  229. {
  230.     printf("\n\tRZMP commands:\n\n");
  231.     printf("RZMP R -- Receive files using ZMODEM\n");
  232.     printf("RZMP S <filename list> -- Send files\n");
  233.     printf("RZMP RP -- Receive files to the private area\n");
  234.     printf("RZMP SP <filename list > -- Send files from the private area\n");
  235.     printf("  Filenames in <filename list> should be separated ");
  236.     printf("by spaces.\n");
  237.     printf("  Wildcards and du:references are allowed.\n");
  238. }
  239.  
  240. sendout(list)
  241. char *list;
  242. {
  243.     static int count, result;
  244.  
  245.     result = NERROR;
  246.     flush();
  247.     count = linetolist(list);    /* process filenames */
  248.     if (count) {
  249.         Zmodem = TRUE;
  250.         Xmodem = FALSE;
  251.         if ((result = checktime(count,Pathlist)) != NERROR) {
  252.             repready();
  253.             result = wcsend(count,Pathlist);
  254.         }
  255.     }
  256.     endstat(result,count);
  257.     return result;
  258. }
  259.  
  260. bringin()
  261. {
  262.     static int result;
  263.  
  264.     result = NERROR;
  265.     flush();
  266.     Zmodem = TRUE;
  267.     Nozmodem = Xmodem = FALSE;
  268.     result = wcreceive(NULL);
  269.     endstat(result, 0);
  270.     return result;
  271. }
  272.  
  273. /* Report to user that we're ready */
  274. repready()
  275. {
  276.     if (!Shutup) {
  277.         printf("Ready to %s. Repeated control-X to abort.\n",
  278.             Transmit ? "send" : "receive");
  279.         wait(2);
  280.     }
  281. }
  282.  
  283. /* Clean up at end and report status */
  284. endstat(result, count)
  285. int result, count;
  286. {
  287.     freepath(count);
  288.     LOCATE(BR+2,1);
  289.     if (!Shutup)
  290.         printf("\nTransfer %s\n",result==OK?"Successful":"Aborted");
  291.     flush();
  292. }
  293.  
  294. /* crctab calculated by Mark G. Mendel, Network Systems Corporation */
  295. static unsigned crctab[256] = {
  296.     0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,
  297.     0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,
  298.     0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,
  299.     0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,
  300.     0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,
  301.     0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,
  302.     0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,
  303.     0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,
  304.     0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,
  305.     0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,
  306.     0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,
  307.     0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,
  308.     0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,
  309.     0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,
  310.     0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,
  311.     0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,
  312.     0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,
  313.     0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,
  314.     0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,
  315.     0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,
  316.     0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,
  317.     0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,
  318.     0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,
  319.     0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,
  320.     0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,
  321.     0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,
  322.     0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,
  323.     0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,
  324.     0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,
  325.     0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,
  326.     0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,
  327.     0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0
  328. };
  329.  
  330. /*
  331.  * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
  332.  *  NOTE: First argument must be in range 0 to 255.
  333.  *        Second argument is referenced twice.
  334.  * 
  335.  * Programmers may incorporate any or all code into their programs, 
  336.  * giving proper credit within the source. Publication of the 
  337.  * source routines is permitted so long as proper credit is given 
  338.  * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, 
  339.  * Omen Technology.
  340.  */
  341.  
  342. updcrc(cp, crc)
  343. unsigned cp, crc;
  344. {
  345.    return ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp);
  346. }
  347.  
  348. /*            End of RZMP file #1                */
  349.