home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / osrc_149.lzh / archive.c next >
Encoding:
C/C++ Source or Header  |  1990-04-08  |  10.2 KB  |  351 lines

  1. /***************************************************************************/
  2. /***                                                                     ***/
  3. /***               oMMM - The Outbound Matrix Message Masher             ***/
  4. /***                      Copyright 1989 BS Software                     ***/
  5. /***                                                                     ***/
  6. /***                         FILENAME: ARCHIVE.C                         ***/
  7. /***                                                                     ***/
  8. /***                      Handles ARCMail type files                     ***/
  9. /***                                                                     ***/
  10. /***                 Based on the original oMMM, a portion of            ***/
  11. /***               the Opus Computer-Based Conversation System           ***/
  12. /***                     Copyright 1986, Wynn Wagner III                 ***/
  13. /***                                                                     ***/
  14. /***************************************************************************/
  15. /***                                                                     ***/
  16. /***                    Tabs set at every 4th column                     ***/
  17. /***                                                                     ***/
  18. /***************************************************************************/
  19.  
  20. /*
  21.     Polytron Version Control System Comments:
  22.  
  23.     The revision of this file is *** $Revision:   1.40  $ ***
  24.  
  25.     History of changes from 1.30 release version
  26.  
  27.     $Log:   C:/OMMM/PROJFILE/ARCHIVE.C_V  $
  28.  * 
  29.  *    Rev 1.40   12 Feb 1989  4:55:14   Marshall Presnell
  30.  * Public Release Version 1.40
  31.  * 
  32.  *    Rev 1.31   31 Jan 1989  0:57:24   Marshall Presnell
  33.  * oMMM 1.35 Beta Release Version
  34.  * 
  35.  *    Rev 1.30   23 Jan 1989 17:54:10   Marshall Presnell
  36.  * Public Source Code Release - Version 1.30
  37.  
  38. */
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /* Include files                                                            */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. #include    "ommm.h"
  45.  
  46.  
  47. #include    "stat.h"
  48. #include    <string.h>
  49. #include    <stdlib.h>
  50.  
  51. #    include    <stdlib.h>
  52. /* #    include    <process.h> */
  53. /* #    include    <io.h> */
  54.  
  55. #include    <exec/types.h>
  56. #include    <libraries/dos.h>
  57.  
  58. #include    <proto/dos.h>
  59.  
  60. /*--------------------------------------------------------------------------*/
  61. /* Static function declarations                                             */
  62. /*--------------------------------------------------------------------------*/
  63.  
  64. static void get_archivename(char *filename, char *arcname);
  65.  
  66. /*--------------------------------------------------------------------------*/
  67. /* Static variable definitions                                              */
  68. /*--------------------------------------------------------------------------*/
  69.  
  70. static char *    extchars[]    =    { "SU","MO","TU","WE","TH","FR","SA",NULL };
  71. /*static char *    arca        = "ARCA"; */
  72. static char *    arca        = "ARC";
  73. static char *    pkarc1        = "PKARC";
  74. static char *    pkarc2        = "-OCT";
  75. static char *    pkarc3        = "M";
  76. static char        templ2[80];
  77.  
  78. /*--------------------------------------------------------------------------*/
  79. /* External variable declarations                                           */
  80. /*--------------------------------------------------------------------------*/
  81.  
  82. extern ADDRESS            ctlnet[];
  83.  
  84. #ifdef ZTC
  85.     extern volatile int    errno;
  86. #else
  87.     extern int            errno;
  88. #endif
  89.  
  90. /*--------------------------------------------------------------------------*/
  91. /* Local constants                                                          */
  92. /*--------------------------------------------------------------------------*/
  93.  
  94. #ifdef ZTC
  95. #    define    stricmp        strcmpl
  96. #    define    P_WAIT        0
  97. #endif
  98.  
  99. /****************************************************************************/
  100.  
  101. /*--------------------------------------------------------------------------*/
  102. /* GET ARCHIVENAME                                          LOCAL FUNCTION  */
  103. /*--------------------------------------------------------------------------*/
  104.  
  105.  static void
  106. get_archivename(char * filename, char * arcname)
  107. {
  108.     struct stat    status;
  109.     int            i;
  110.     int            j;
  111.  
  112.     memset(filename, 0, 30);
  113.     printf("\nArchive is to %d:%d/%d\n", dest.zone,dest.net, dest.node);
  114.     fflush(stdout);
  115.  
  116.     /*
  117.      * determine which archive name was used last and delete any
  118.      * zero length arcs that might be laying about
  119.      */
  120.  
  121.     for (j = 0; extchars[j] != NULL; j++) { /* days of the week */
  122.         for (i = '0'; i <= '9'; i++) {    /* trailing digit */
  123.             sprintf(filename, "%04x%04x.%s%c",
  124.                 ctlnet[0].net - dest.net, ctlnet[0].node - dest.node,
  125.                 extchars[j], i);
  126.             sprintf(arcname, "%s%s", adjust_packet_path(dest.zone), filename);
  127.  
  128.             if (!stat(arcname, &status)) {
  129.                 if (status.st_size == 0L) {
  130.  
  131.                     printf("Deleting old truncated `%s'\n", arcname);
  132.                     fflush(stdout);
  133.  
  134.                     errno = 0;
  135.                     unlink(arcname);
  136.                     if (errno)
  137.                         perror("Can't delete");
  138.  
  139.                     i = strlen(arcname) - 1;
  140.                     if (arcname[i] == '0') {
  141.                         if (oldstyle) {
  142.                             sprintf(filename, "%04x%04x.MO1",
  143.                                 (ctlnet[0].net - dest.net)&0xffff,
  144.                                 (ctlnet[0].node - dest.node)&0xffff);
  145.                         } else {
  146.                             sprintf(filename, "%04x%04x.%s1",
  147.                                 (ctlnet[0].net - dest.net)&0xffff,
  148.                                 (ctlnet[0].node - dest.node)&0xffff,
  149.                                 (extchars[j + 1] != NULL) ? extchars[j + 1] : "SU");
  150.                         }
  151.                         sprintf(arcname, "%s%s", adjust_packet_path(dest.zone), filename);
  152.                     } else {
  153.                         arcname[i]++;
  154.                         if (arcname[i] > '9') {
  155.                             arcname[i] = '0';
  156.                             filename[strlen(filename) - 1] = '0';
  157.                         }
  158.                     }
  159.                     return;
  160.  
  161.                 }
  162.                 printf("Adding bundle to `%s'\n", arcname);
  163.                 fflush(stdout);
  164.                 return;
  165.             }
  166.         }
  167.     }
  168.  
  169.     sprintf(filename, "%04x%04x.MO1",
  170.         (ctlnet[0].net - dest.net)&0xffff,
  171.         (ctlnet[0].node - dest.node)&0xffff);
  172.     sprintf(arcname, "%s%s", adjust_packet_path(dest.zone), filename);
  173.  
  174.     printf("New archive `%s'\n", arcname);
  175.     fflush(stdout);
  176. }
  177.  
  178. /*--------------------------------------------------------------------------*/
  179. /* ARCHIVE                                                                  */
  180. /*--------------------------------------------------------------------------*/
  181.  
  182.  void
  183. archive(char * parm)
  184. {
  185.     register int    i;
  186.     int i1;
  187.     char            filename[80];
  188.     char            tstring[80];
  189.     char            arcname[80];
  190.     FILE *            flowfile;
  191.     FILE *            flow1;
  192.     int                newone;
  193.     static char *    flow_ext = "FLO";
  194.     struct stat        StatBuf;
  195.  
  196.     struct ProcID procid;
  197.  
  198.     if (*parm == '\0')
  199.         return;
  200.     get_archivename(filename, arcname);
  201.     sprintf(templ2, "%s%04x%04x.FLO", adjust_packet_path(dest.zone), dest.net, dest.node);
  202.  
  203.     /*
  204.      * Here's the theory on how to do ArcAddHold style verbs:  They
  205.      * use another global - AddFlag.  If AddFlag is 0, things work just as
  206.      * they do now.  However, if AddFlag is non-zero, then at this point,
  207.      * we test for the existance of the archive file.  Later on, at the
  208.      * flow file stuff, if the archive existed and AddFlag is set, we
  209.      * DO NOT mess around with the existing flow file.
  210.      *
  211.      * This works on the blatant assumption that zero length files do not
  212.      * exist 
  213.      *
  214.      * I think that's a valid assumption, I hope someone will tell me if
  215.      * not. 
  216.      *
  217.      * It's also DOS (probably msc) dependent.
  218.      * Oh, AddFlag is set and cleared in do_route()
  219.      * There will be problems if you are using old style naming (i.e.,TU).
  220.      * 
  221.      * The "Add-Verbs" may be disabled by undefining ADD_STUFF in oMMM.H.
  222.      * 
  223.      */
  224.  
  225. #ifdef ADD_STUFF
  226.     if (AddFlag)
  227.         AddFlag = !stat(arcname, &StatBuf);
  228. #endif
  229.  
  230.     switch ('z' == ArcType) {
  231.     char str[150];
  232.     case 0:
  233.         if (pkarc) {
  234.             sprintf(str,"%s %s %s %s %s",pkarc1,pkarc2,pkarc3,arcname,parm);
  235.             i=system(str);
  236. /*            i=!Execute(str,NULL,NULL);    */
  237.             i1=0;
  238. /*            i=forkl(pkarc1,pkarc1,pkarc2,pkarc3,arcname,parm,NULL,NULL,&procid);
  239.             i1=wait(&procid);*/
  240.         } else {
  241.             sprintf(str,"arc m %s %s",arcname,parm);
  242. /*            printf("I call arc using \"%s\"\n", str);    */
  243.             i=system(str);
  244. /*            i=!Execute(str,NULL,NULL);    */
  245.             i1=0;
  246. /*            i=forkl("arc","arc","-m",arcname,parm,NULL,NULL,&procid);
  247.             i1=wait(&procid); */
  248.         }
  249.         break;
  250.     default:
  251.         sprintf(str, "zoo -move %s %s",arcname,parm);
  252.         i=system(str);
  253. /*        i=!Execute(str,NULL,NULL);    */
  254.         i1=0;
  255. /*        i=forkl("zoo","zoo","-move",arcname,parm,NULL,NULL,&procid);
  256.         i1=wait(&procid); */
  257.         break;
  258.     }
  259.     if (i||i1)
  260.         printf("\nARC err#%d  %d\n", i,i1);
  261.  
  262. #ifdef ADD_STUFF
  263.     switch (AddFlag) {
  264.     case 0:
  265. #endif
  266.         *flow_ext = (char) mode;
  267.         strncpy(tstring, parm, sizeof(tstring) - 1);
  268.         strmfe(parm, templ2, flow_ext);
  269.  
  270.         errno = 0;
  271.         flowfile = fopen(parm, "r+t");
  272.         newone = 0;
  273.         if (errno) {
  274.             errno = 0;
  275.             printf("New FLO file `%s' for %d:%d/%d\n", parm, dest.zone,dest.net, dest.node);
  276.             fflush(stdout);
  277.             if ((flowfile = fopen(parm, "wt")) == NULL)
  278.                 perror("Can't create FLO file");
  279.             newone = 1;
  280.         }
  281.         errno = 0;
  282.         fseek(flowfile, 0L, SEEK_END);
  283.         if (errno)
  284.             perror("SEEKEND");
  285.  
  286.         strmfe(tstring, templ2, "FLO");
  287.  
  288.         errno = 0;
  289.         flow1 = fopen(tstring, "rt");
  290.  
  291.         if (flow1 != NULL) {
  292.             while (fgets(filename, sizeof filename, flow1))
  293.                 fputs(filename, flowfile);
  294.             fclose(flow1);
  295.             flow1 = NULL;
  296.             unlink(tstring);
  297.             newone = 0;
  298.         }
  299.  
  300.         fclose(flowfile);
  301.         flowfile = fopen(parm, "r+t");
  302.  
  303.         if (!newone) {
  304.             while (fgets(filename, sizeof filename, flowfile)) {
  305.                 for (i = 0; filename[i]; i++) {
  306.                     if (filename[i] <= ' ')
  307.                         filename[i] = 0;
  308.                 }
  309.                 if (!stricmp(filename + 1, arcname)) {
  310.                     printf("File already listed for transmission.  \n");
  311.                     fflush(stdout);
  312.                     fclose(flowfile);
  313.                     flowfile = NULL;
  314.                     parm[0] = 0;
  315.                     return;
  316.                 }
  317.             }
  318.         }
  319.  
  320.         errno = 0;
  321.         rewind(flowfile);
  322.         if (errno)
  323.             perror("REWIND");
  324.         fseek(flowfile, 0L, SEEK_END);
  325.         if (errno)
  326.             perror("SEEKEND");
  327.         fprintf(flowfile, "#%s\n", arcname);
  328.         if (errno)
  329.             perror("PRINT");
  330.         fclose(flowfile);
  331.         flowfile = NULL;
  332.         if (errno)
  333.             perror("CLOSE");
  334. #ifdef ADD_STUFF
  335.         break;
  336.     default:
  337.         printf("Add mode for %d:%d/%d\n", dest.zone,dest.net, dest.node);
  338.         fflush(stdout);
  339.         break;
  340.     }
  341. #endif
  342.     parm[0] = 0;
  343. }
  344.  
  345. /*--------------------------------------------------------------------------*/
  346. /*                                END OF FILE                               */
  347. /*--------------------------------------------------------------------------*/
  348.  
  349. /*-------------------------------------------------------------------------*/
  350. /* ID: 338.22@10363  Last Changed: 08 Apr 1990 15:55:12 by max */
  351.