home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
OS2OMMM.SRC
/
ARCHIVE.C
next >
Wrap
Text File
|
1989-06-01
|
9KB
|
321 lines
/***************************************************************************/
/*** ***/
/*** 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.40BP 2 June 1989 23:22:00 Bill Andrus
* Public Release Version 1.40BP (OS/2 Protect Mode, Bound)
*
* 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"
#ifdef MSC
# include <sys\types.h>
# include <memory.h>
#endif
#include <sys\stat.h>
#include <string.h>
#ifdef ZTC
# include <stdlib.h>
# include <process.h>
# include <io.h>
#endif
/*--------------------------------------------------------------------------*/
/* 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 * pkarc1 = "PKARC";
static char * pkarc2 = "-OCT";
static char * pkarc3 = "M";
static char templ2[80];
/*--------------------------------------------------------------------------*/
/* External variable declarations */
/*--------------------------------------------------------------------------*/
extern NETADDRESS 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);
/*
* 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);
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,
ctlnet[0].node - dest.node);
} else {
sprintf(filename, "%04x%04x.%s1",
ctlnet[0].net - dest.net,
ctlnet[0].node - dest.node,
(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);
return;
}
}
}
sprintf(filename, "%04x%04x.MO1", ctlnet[0].net - dest.net, ctlnet[0].node - dest.node);
sprintf(arcname, "%s%s", adjust_packet_path(dest.zone), filename);
printf("New archive `%s'\n", arcname);
}
/*--------------------------------------------------------------------------*/
/* ARCHIVE */
/*--------------------------------------------------------------------------*/
void
archive(char * parm)
{
register int i;
char filename[80];
char tstring[80];
char arcname[80];
FILE * flowfile;
FILE * flow1;
int newone;
static char * flow_ext = "FLO";
struct stat StatBuf;
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) {
case 0:
if (pkarc) {
i = spawnlp(P_WAIT, pkarc1, pkarc1, pkarc2, pkarc3, arcname, parm, NULL);
} else {
i = spawnlp(P_WAIT, arca, arca, arcname, parm, "/D", NULL);
}
break;
default:
i = spawnlp(P_WAIT, "zoo", "zoo", "-move", arcname, parm, NULL);
break;
}
if (i)
printf("\nARC err#%d\n", i);
#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);
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");
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);
break;
}
#endif
parm[0] = 0;
}
/*--------------------------------------------------------------------------*/
/* END OF FILE */
/*--------------------------------------------------------------------------*/