home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /*** ***/
- /*** oMMM - The Outbound Matrix Message Masher ***/
- /*** Copyright 1989 BS Software ***/
- /*** ***/
- /*** FILENAME: ARCHIVE.C ***/
- /*** ***/
- /*** Handles ARCMail type files ***/
- /*** ***/
- /*** Based on the original oMMM, a portion of ***/
- /*** the Opus Computer-Based Conversation System ***/
- /*** Copyright 1986, Wynn Wagner III ***/
- /*** ***/
- /***************************************************************************/
- /*** ***/
- /*** Tabs set at every 4th column ***/
- /*** ***/
- /***************************************************************************/
-
- /*
- Polytron Version Control System Comments:
-
- The revision of this file is *** $Revision: 1.40 $ ***
-
- History of changes from 1.30 release version
-
- $Log: C:/OMMM/PROJFILE/ARCHIVE.C_V $
- *
- * Rev 1.40 12 Feb 1989 4:55:14 Marshall Presnell
- * Public Release Version 1.40
- *
- * Rev 1.31 31 Jan 1989 0:57:24 Marshall Presnell
- * oMMM 1.35 Beta Release Version
- *
- * Rev 1.30 23 Jan 1989 17:54:10 Marshall Presnell
- * Public Source Code Release - Version 1.30
-
- */
-
- /*--------------------------------------------------------------------------*/
- /* Include files */
- /*--------------------------------------------------------------------------*/
-
- #include "ommm.h"
-
-
- #include "stat.h"
- #include <string.h>
- #include <stdlib.h>
-
- # include <stdlib.h>
- /* # include <process.h> */
- /* # include <io.h> */
-
- #include <exec/types.h>
- #include <libraries/dos.h>
-
- #include <proto/dos.h>
-
- /*--------------------------------------------------------------------------*/
- /* Static function declarations */
- /*--------------------------------------------------------------------------*/
-
- static void get_archivename(char *filename, char *arcname);
-
- /*--------------------------------------------------------------------------*/
- /* Static variable definitions */
- /*--------------------------------------------------------------------------*/
-
- static char * extchars[] = { "SU","MO","TU","WE","TH","FR","SA",NULL };
- /*static char * arca = "ARCA"; */
- static char * arca = "ARC";
- static char * pkarc1 = "PKARC";
- static char * pkarc2 = "-OCT";
- static char * pkarc3 = "M";
- static char templ2[80];
-
- /*--------------------------------------------------------------------------*/
- /* External variable declarations */
- /*--------------------------------------------------------------------------*/
-
- extern ADDRESS ctlnet[];
-
- #ifdef ZTC
- extern volatile int errno;
- #else
- extern int errno;
- #endif
-
- /*--------------------------------------------------------------------------*/
- /* Local constants */
- /*--------------------------------------------------------------------------*/
-
- #ifdef ZTC
- # define stricmp strcmpl
- # define P_WAIT 0
- #endif
-
- /****************************************************************************/
-
- /*--------------------------------------------------------------------------*/
- /* GET ARCHIVENAME LOCAL FUNCTION */
- /*--------------------------------------------------------------------------*/
-
- static void
- get_archivename(char * filename, char * arcname)
- {
- struct stat status;
- int i;
- int j;
-
- memset(filename, 0, 30);
- printf("\nArchive is to %d:%d/%d\n", dest.zone,dest.net, dest.node);
- fflush(stdout);
-
- /*
- * determine which archive name was used last and delete any
- * zero length arcs that might be laying about
- */
-
- for (j = 0; extchars[j] != NULL; j++) { /* days of the week */
- for (i = '0'; i <= '9'; i++) { /* trailing digit */
- sprintf(filename, "%04x%04x.%s%c",
- ctlnet[0].net - dest.net, ctlnet[0].node - dest.node,
- extchars[j], i);
- sprintf(arcname, "%s%s", adjust_packet_path(dest.zone), filename);
-
- if (!stat(arcname, &status)) {
- if (status.st_size == 0L) {
-
- printf("Deleting old truncated `%s'\n", arcname);
- fflush(stdout);
-
- errno = 0;
- unlink(arcname);
- if (errno)
- perror("Can't delete");
-
- i = strlen(arcname) - 1;
- if (arcname[i] == '0') {
- if (oldstyle) {
- sprintf(filename, "%04x%04x.MO1",
- (ctlnet[0].net - dest.net)&0xffff,
- (ctlnet[0].node - dest.node)&0xffff);
- } else {
- sprintf(filename, "%04x%04x.%s1",
- (ctlnet[0].net - dest.net)&0xffff,
- (ctlnet[0].node - dest.node)&0xffff,
- (extchars[j + 1] != NULL) ? extchars[j + 1] : "SU");
- }
- sprintf(arcname, "%s%s", adjust_packet_path(dest.zone), filename);
- } else {
- arcname[i]++;
- if (arcname[i] > '9') {
- arcname[i] = '0';
- filename[strlen(filename) - 1] = '0';
- }
- }
- return;
-
- }
- printf("Adding bundle to `%s'\n", arcname);
- fflush(stdout);
- return;
- }
- }
- }
-
- sprintf(filename, "%04x%04x.MO1",
- (ctlnet[0].net - dest.net)&0xffff,
- (ctlnet[0].node - dest.node)&0xffff);
- sprintf(arcname, "%s%s", adjust_packet_path(dest.zone), filename);
-
- printf("New archive `%s'\n", arcname);
- fflush(stdout);
- }
-
- /*--------------------------------------------------------------------------*/
- /* ARCHIVE */
- /*--------------------------------------------------------------------------*/
-
- void
- archive(char * parm)
- {
- register int i;
- int i1;
- char filename[80];
- char tstring[80];
- char arcname[80];
- FILE * flowfile;
- FILE * flow1;
- int newone;
- static char * flow_ext = "FLO";
- struct stat StatBuf;
-
- struct ProcID procid;
-
- if (*parm == '\0')
- return;
- get_archivename(filename, arcname);
- sprintf(templ2, "%s%04x%04x.FLO", adjust_packet_path(dest.zone), dest.net, dest.node);
-
- /*
- * Here's the theory on how to do ArcAddHold style verbs: They
- * use another global - AddFlag. If AddFlag is 0, things work just as
- * they do now. However, if AddFlag is non-zero, then at this point,
- * we test for the existance of the archive file. Later on, at the
- * flow file stuff, if the archive existed and AddFlag is set, we
- * DO NOT mess around with the existing flow file.
- *
- * This works on the blatant assumption that zero length files do not
- * exist
- *
- * I think that's a valid assumption, I hope someone will tell me if
- * not.
- *
- * It's also DOS (probably msc) dependent.
- * Oh, AddFlag is set and cleared in do_route()
- * There will be problems if you are using old style naming (i.e.,TU).
- *
- * The "Add-Verbs" may be disabled by undefining ADD_STUFF in oMMM.H.
- *
- */
-
- #ifdef ADD_STUFF
- if (AddFlag)
- AddFlag = !stat(arcname, &StatBuf);
- #endif
-
- switch ('z' == ArcType) {
- char str[150];
- case 0:
- if (pkarc) {
- sprintf(str,"%s %s %s %s %s",pkarc1,pkarc2,pkarc3,arcname,parm);
- i=system(str);
- /* i=!Execute(str,NULL,NULL); */
- i1=0;
- /* i=forkl(pkarc1,pkarc1,pkarc2,pkarc3,arcname,parm,NULL,NULL,&procid);
- i1=wait(&procid);*/
- } else {
- sprintf(str,"arc m %s %s",arcname,parm);
- /* printf("I call arc using \"%s\"\n", str); */
- i=system(str);
- /* i=!Execute(str,NULL,NULL); */
- i1=0;
- /* i=forkl("arc","arc","-m",arcname,parm,NULL,NULL,&procid);
- i1=wait(&procid); */
- }
- break;
- default:
- sprintf(str, "zoo -move %s %s",arcname,parm);
- i=system(str);
- /* i=!Execute(str,NULL,NULL); */
- i1=0;
- /* i=forkl("zoo","zoo","-move",arcname,parm,NULL,NULL,&procid);
- i1=wait(&procid); */
- break;
- }
- if (i||i1)
- printf("\nARC err#%d %d\n", i,i1);
-
- #ifdef ADD_STUFF
- switch (AddFlag) {
- case 0:
- #endif
- *flow_ext = (char) mode;
- strncpy(tstring, parm, sizeof(tstring) - 1);
- strmfe(parm, templ2, flow_ext);
-
- errno = 0;
- flowfile = fopen(parm, "r+t");
- newone = 0;
- if (errno) {
- errno = 0;
- printf("New FLO file `%s' for %d:%d/%d\n", parm, dest.zone,dest.net, dest.node);
- fflush(stdout);
- if ((flowfile = fopen(parm, "wt")) == NULL)
- perror("Can't create FLO file");
- newone = 1;
- }
- errno = 0;
- fseek(flowfile, 0L, SEEK_END);
- if (errno)
- perror("SEEKEND");
-
- strmfe(tstring, templ2, "FLO");
-
- errno = 0;
- flow1 = fopen(tstring, "rt");
-
- if (flow1 != NULL) {
- while (fgets(filename, sizeof filename, flow1))
- fputs(filename, flowfile);
- fclose(flow1);
- flow1 = NULL;
- unlink(tstring);
- newone = 0;
- }
-
- fclose(flowfile);
- flowfile = fopen(parm, "r+t");
-
- if (!newone) {
- while (fgets(filename, sizeof filename, flowfile)) {
- for (i = 0; filename[i]; i++) {
- if (filename[i] <= ' ')
- filename[i] = 0;
- }
- if (!stricmp(filename + 1, arcname)) {
- printf("File already listed for transmission. \n");
- fflush(stdout);
- fclose(flowfile);
- flowfile = NULL;
- parm[0] = 0;
- return;
- }
- }
- }
-
- errno = 0;
- rewind(flowfile);
- if (errno)
- perror("REWIND");
- fseek(flowfile, 0L, SEEK_END);
- if (errno)
- perror("SEEKEND");
- fprintf(flowfile, "#%s\n", arcname);
- if (errno)
- perror("PRINT");
- fclose(flowfile);
- flowfile = NULL;
- if (errno)
- perror("CLOSE");
- #ifdef ADD_STUFF
- break;
- default:
- printf("Add mode for %d:%d/%d\n", dest.zone,dest.net, dest.node);
- fflush(stdout);
- break;
- }
- #endif
- parm[0] = 0;
- }
-
- /*--------------------------------------------------------------------------*/
- /* END OF FILE */
- /*--------------------------------------------------------------------------*/
-
- /*-------------------------------------------------------------------------*/
- /* ID: 338.22@10363 Last Changed: 08 Apr 1990 15:55:12 by max */
-