home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************/
- /*** ***/
- /*** oMMM - The Outbound Matrix Message Masher ***/
- /*** Copyright 1989 BS Software ***/
- /*** ***/
- /*** FILENAME: MISC.C ***/
- /*** ***/
- /*** Miscellaneous routines ***/
- /*** ***/
- /*** 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/MISC.C_V $
- *
- * Rev 1.40 12 Feb 1989 4:55:24 Marshall Presnell
- * Public Release Version 1.40
- *
- * Rev 1.35 01 Feb 1989 15:20:10 Marshall Presnell
- * Solves (hopefully) the year and misformatting problems permanently!
- *
- * Rev 1.34 31 Jan 1989 0:57:34 Marshall Presnell
- * oMMM 1.35 Beta Release Version
- *
- * Rev 1.33 30 Jan 1989 21:40:30 Marshall Presnell
- * Month and year in packet header now to FTSC specification
- *
- * Rev 1.32 23 Jan 1989 18:00:06 Marshall Presnell
- * Net number now being inserted into header
- *
- * Rev 1.31 23 Jan 1989 17:57:56 Marshall Presnell
- * Output line while scanning messages cleared of debris
- *
- * Rev 1.30 23 Jan 1989 17:53:50 Marshall Presnell
- * Public Source Code Release - Version 1.30
-
- */
-
- /*--------------------------------------------------------------------------*/
- /* Include files */
- /*--------------------------------------------------------------------------*/
-
- #include "ommm.h"
- #include <errno.h>
-
-
- /* #include <sys\stat.h> */
- #include <ctype.h>
- #include <string.h>
- /* #include <io.h> */
- #include <fcntl.h>
- #include <time.h>
-
- #include <dos.h>
- #include <stdlib.h>
-
- /*--------------------------------------------------------------------------*/
- /* Static function declarations */
- /*--------------------------------------------------------------------------*/
-
- /* ... NONE ... */
-
- /*--------------------------------------------------------------------------*/
- /* Static variable definitions */
- /*--------------------------------------------------------------------------*/
-
- static struct _pkthdr packet_header;
-
- /*--------------------------------------------------------------------------*/
- /* External variable declarations */
- /*--------------------------------------------------------------------------*/
-
- extern ADDRESS ctlnet[];
- extern PW_PTR pw[];
- extern int num_pw;
-
- #ifdef ZTC
- extern volatile int errno;
- #else
- extern int errno;
- #endif
-
- /*--------------------------------------------------------------------------*/
- /* Localally defined globals */
- /*--------------------------------------------------------------------------*/
-
- int num_addrs;
-
- /*--------------------------------------------------------------------------*/
- /* Local constants */
- /*--------------------------------------------------------------------------*/
-
- #ifdef ZTC
- int access(char *fn, int mode);
- # define O_BINARY 0
- # define ENMFILE 18
- #endif
-
- /****************************************************************************/
-
-
- /*--------------------------------------------------------------------------*/
- /* OPEN OUTFILE */
- /*--------------------------------------------------------------------------*/
-
- int
- open_outfile(int flagchar, unsigned int tonet, unsigned int tonode, unsigned int tozone, unsigned int verbose)
- {
- int i;
- short i_s;
-
- /*--------------------------------------------------------------*/
- /* Open an OUT file */
- /*--------------------------------------------------------------*/
-
- if (outfile)
- fclose(outfile);
-
- if (verbose) {
- printf(" ... To: %d:%d/%d",tozone,tonet,tonode);
- switch (flagchar) {
- case 'O':
- printf(" (NORM)");
- break;
- case 'H':
- printf(" (HOLD)");
- break;
- case 'C':
- printf(" (CM)");
- break;
- }
- fflush(stdout);
- }
-
- sprintf(template, "%s%04x%04x.%cUT", adjust_packet_path(tozone), tonet, tonode, flagchar);
-
- if (access(template,0) == 0) {
- outfile = fopen(template,"r+b");
- fseek(outfile, -2L, SEEK_END);
- if (verbose)
- printf(" (APPEND)");
- fflush(stdout);
- return (0);
- }
-
- if ((outfile = fopen(template,"w+b")) == NULL) {
- printf("\nCan't create OUT file\n");
- exit(1);
- }
-
- printf(" ");
- fflush(stdout);
-
- packet_header.orig_net = OURNET;
- packet_header.orig_node = OURNODE;
- packet_header.dest_node = tonode;
- packet_header.dest_net = tonet;
- dosdate(&packet_header.month, &packet_header.day, &packet_header.year, &i_s);
- packet_header.year -= 1900;
- dostime(&packet_header.hour, &packet_header.minute, &packet_header.second);
- packet_header.rate = 0;
- packet_header.ver = 2;
- packet_header.product = isOPUS;
-
- for (i = 0; i < num_pw; i++) {
- /* Find out if we have a password for this guy */
- if ((pw[i]->net == tonet) && (pw[i]->node == tonode) && (pw[i]->zone == tozone)) {
- strncpy(packet_header.password, pw[i]->password, 8);
- break;
- }
- }
-
- swap_pkthdr(&packet_header);
- fwrite((char *) &packet_header, sizeof(struct _pkthdr), 1, outfile);
- swap_pkthdr(&packet_header);
- return (1);
- }
-
- /*--------------------------------------------------------------------------*/
- /* FANCY STR */
- /*--------------------------------------------------------------------------*/
-
- char *
- fancy_str(char * value)
- {
- register char * sptr;
- char lower = 0;
-
- sptr = value;
-
- if (sptr) { /* don't touch any NULL pointers */
- while (*sptr) {
- if (lower)
- *sptr = tolower(*sptr);
- else
- *sptr = toupper(*sptr);
- lower = (isalnum(*sptr++));
- }
- }
- return (value);
- }
-
- /*--------------------------------------------------------------------------*/
- /* ADD SLASH */
- /*--------------------------------------------------------------------------*/
-
- void
- add_backslash(char * path)
- {
- register int i;
-
- i = strlen(path) - 1;
- if ((path[0] > ' ') && (path[i] != '/'))
- path[++i] = '/';
- path[i + 1] = '\0';
-
- fancy_str(path);
- }
-
- /*--------------------------------------------------------------------------*/
- /* CONVERT DATE */
- /*--------------------------------------------------------------------------*/
-
- void
- convert_date(char *str)
- {
- int mo;
- int d;
- int y;
- int h;
- int m;
- int s;
-
- if (((str[19] & (char) 0xff) == (char) 0xff) && (sscanf(str, "%d-%d-%d %d:%d:%d", &mo, &d, &y, &h, &m, &s) == 6)) {
- sprintf(str, "%02d %s %02d %02d:%02d:%02d", d, _months[mo - 1], y, h, m, s);
- }
- }
-
- /*--------------------------------------------------------------------------*/
- /* EXTRACT PARTS */
- /*--------------------------------------------------------------------------*/
-
- void
- extract_parts(char * file_path, char * file_name, char * flist, char * file_attached)
- {
- char * p;
- char * s;
- char * t;
-
- strcpy(file_path, file_attached);
- p = strrchr(file_path, '/');
- if (p == NULL)
- p = strrchr(file_path, ':');
- if (p == NULL) {
- strcat(flist, file_attached);
- strcat(flist, " ");
- file_path[0] = 0;
- strcpy(file_name, file_attached);
- return;
- };
- p++;
- s = p;
- t = file_name;
-
- while (*s) {
- if (isspace(*s))
- break;
- *t++ = *s++;
- }
- *t = 0;
-
- strcat(flist, p);
- strcat(flist, " ");
- *p = 0;
- }
-
- /*--------------------------------------------------------------------------*/
- /* STRMFE */
- /*--------------------------------------------------------------------------*/
- /*
- int
- strmfe(char * s1, char * s2, char * s3)
- {
- char *q;
-
- strcpy(s1, s2);
- q = s1 + strlen(s1);
- while ((q >= s1) && (*q != '.') && (*q != '/') && (*q != ':'))
- --q;
- if (q < s1)
- q = s1;
- if (*q != '.')
- q = s1 + strlen(s1);
- *q++ = '.';
- strcpy(q, s3);
- return (0);
- }
- */ /* is already defined in library ! */
- /*--------------------------------------------------------------------------*/
- /* STPBLK */
- /*--------------------------------------------------------------------------*/
-
- char *
- stpblk(char * s)
- {
- while ((*s) && isspace(*s))
- ++s;
- return (s);
- }
-
- /*--------------------------------------------------------------------------*/
- /* GETNET */
- /*--------------------------------------------------------------------------*/
-
- void
- getnet(char *prm_name)
- {
- FILE *fh;
- char buf[120];
- int i;
-
- fh=fopen(prm_name,"r");
- if(!fh)
- {
- printf(" can't open Ommm Infofile: %s - exiting !\n",prm_name);
- exit(1);
- }
- i=0;
- while(fgets(buf,100,fh)!=NULL)
- {
- if(buf[0]==0) break;
- if(buf[0]==';' || buf[0]=='\n') continue;
- sscanf(buf,"%d:%d/%d",&ctlnet[i].zone,
- &ctlnet[i].net,&ctlnet[i].node);
- if(ctlnet[i].zone==0)
- {
- printf(" illegal fidoadr in infofile : %s\n",buf);
- break;
- }
- i++;
- }
- if(!i)
- {
- printf(" no valid fido address in infofile ! - exiting !\n");
- fclose(fh);
- exit(1);
- }
- fclose(fh);
-
- num_addrs=i;
- /*
- ctlnet[0].zone=2;
- ctlnet[0].net=2462;
- ctlnet[0].node=19;
- num_addrs=1;
- */
-
- }
-
-
-
- #if NOTDEF
- void
- not_getnet(char * prm_name)
- {
- FILE * fh;
- int i;
- int ver;
- struct {
- int node;
- int net;
- } part_addr;
-
- struct {
- int zone;
- int net;
- int node;
- int point;
- } full_addr;
-
-
- errno = 0;
- if ((fh = fopen(prm_name, "rb")) == NULL) {
- printf("Could not open '%s' - exiting\n", prm_name);
- exit(1);
- }
-
- ver = fgetc(fh);
-
- if (ver == EOF) {
- printf("Could not read from '%s' - exiting\n", prm_name);
- exit(1);
- }
-
- if (ver < 14) {
- /* Could be wrong control file version number. */
- /* Less than 14 won't work. Over 14 MAY work. */
- printf("Wrong control file version found in '%s' - exiting\n", prm_name);
- exit(1);
- }
-
- if (ver < 16) {
- fseek(fh,301l,SEEK_SET);
- for (i = 0; i < ALIAS_CNT; i++) {
- fread(&part_addr,sizeof(part_addr),1,fh);
- ctlnet[i].zone = our_zone;
- ctlnet[i].net = part_addr.net;
- ctlnet[i].node = part_addr.node;
- if (ctlnet[i].net == 0)
- break;
- }
- } else {
- fgetc(fh);
- for (i = 0; i < ALIAS_CNT; i++) {
- fread(&full_addr,sizeof(full_addr),1,fh);
- ctlnet[i].zone = full_addr.zone;
- ctlnet[i].net = full_addr.net;
- ctlnet[i].node = full_addr.node;
- if (ctlnet[i].net == 0)
- break;
- }
- }
-
- num_addrs = i;
- fclose(fh);
-
- }
- #endif
-
- /*--------------------------------------------------------------------------*/
- /* DOSTIME */
- /*--------------------------------------------------------------------------*/
-
- void
- dostime(short * hr, short * min, short * sec)
- {
- time_t timer;
- struct tm *tms;
-
- time(&timer);
- tms = localtime(&timer);
-
- *hr = tms->tm_hour;
- *min = tms->tm_min;
- *sec = tms->tm_sec;
- }
-
- /*--------------------------------------------------------------------------*/
- /* DOSDATE */
- /*--------------------------------------------------------------------------*/
-
- void
- dosdate(short * month, short * mday, short * year, short * wday)
- {
- time_t timer;
- struct tm *tms;
-
- time(&timer);
- tms = localtime(&timer);
-
- *month = tms->tm_mon;
- *mday = tms->tm_mday;
- *year = tms->tm_year + 1900;
- *wday = tms->tm_wday;
- }
-
- /*--------------------------------------------------------------------------*/
- /* DIR_FINDFIRST FOR PORTABILITY */
- /*--------------------------------------------------------------------------*/
-
- extern int msflag;
-
- int
- dir_findfirst(char * filename, int attribute, struct _dta * dta)
- {
- msflag=1;
- if (dta->fib)
- free(dta->fib);
- dta->fib=malloc(sizeof(struct FILEINFO));
- if(!dta->fib) return -1;
- if(dfind(dta->fib,filename,attribute)) return -1;
- strupr(dta->fib->fib_FileName);
- strncpy(dta->name,dta->fib->fib_FileName,13);
- dta->size=dta->fib->fib_Size;
- return 0;
-
- /*
- union REGS ir;
- union REGS or;
-
- ir.h.ah = 0x1a;
- ir.x.dx = (unsigned int) dta;
- intdos(&ir,&or);
- ir.h.ah = 0x4e;
- ir.x.cx = (unsigned int) attribute;
- ir.x.dx = (unsigned int) filename;
- intdos(&ir,&or);
- if (or.x.cflag) {
- errno = ENOENT;
- return (-1);
- } else {
- errno = 0;
- return (0);
- }
- */
- }
-
- /*--------------------------------------------------------------------------*/
- /* DIR_FINDNEXT FOR PORTABILITY */
- /*--------------------------------------------------------------------------*/
-
- int
- dir_findnext(struct _dta * dta)
- {
- msflag=1;
- if(!dta->fib) return -1;
- if(dnext(dta->fib)) return -1;
- strupr(dta->fib->fib_FileName);
- strncpy(dta->name,dta->fib->fib_FileName,13);
- dta->size=dta->fib->fib_Size;
- return 0;
-
- /*
- union REGS ir, or;
-
- ir.h.ah = 0x1a;
- ir.x.dx = (unsigned int) dta;
- intdos(&ir,&or);
-
- ir.h.ah = 0x4f;
- intdos(&ir,&or);
-
- if (or.x.cflag) {
- errno = ENOENT;
- return (-1);
- } else {
- errno = 0;
- return (0);
- }
- */
- }
-
- /*--------------------------------------------------------------------------*/
- /* GET PACKET NAME */
- /*--------------------------------------------------------------------------*/
-
- char *
- get_packet_name(int zone, int net, int node)
- {
- static char name[80];
- static long int timer = 0;
-
- if (timer == 0)
- timer = (time(NULL) << 5);
- else
- timer++;
-
- memset(name, 0, sizeof(name));
- sprintf(name, "%s%08lx.pkt", adjust_packet_path(zone), timer);
-
- return (name);
- }
-
-
- /*-------------------------------------------------------------------------*/
- /* ID: 572.5@14926 Last Changed: 08 Apr 1990 15:56:09 by max */
-