home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
XGRP_000.SZH
/
START.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-22
|
8KB
|
267 lines
/* XBBS Group/Echo/Netmail processor */
#include "xgroup.h"
#define DO_EXPORT 1
#define DO_IMPORT 2
#define DO_CLEANUP 4
#define DO_ALL 0
#define DO_MAKE 8
#define DO_NOGROUP 64
#define DO_NOECHO 128
#define XVERSION 0
#define XSUBVERSION 0
/* global variables created here */
HSEM SemHandle;
HSEM XMSemHandle;
char machstate;
/* local-only functions */
#ifdef TSC
void deinitialize(void);
#else
void _cdecl deinitialize(void); /* atexit */
#endif
void _fastcall send_help (void);
/* external functions called only from this module */
extern void _fastcall clean_up(void);
extern void _fastcall make_requests(void);
extern int _fastcall do_route(void);
extern void _fastcall rescan_echo_mail(ECHOREC *currecho,ADDR *addr,
unsigned int startat);
/* external var references */
extern GROUP *group;
extern CONTROLS control;
extern ADDR *myaddr;
extern ECHOREC *echos;
extern ASSHOLE *assholes;
extern char *groupin;
extern char *groupout;
extern char *grouphold;
extern char *msgdir;
extern char *outbound;
extern char *inbound;
extern char *archive;
extern char *unarchive;
extern word packsize;
extern word netarea;
extern char buffer[1024];
extern int logfilehandle;
int _cdecl main (int argc,char *argv[]) {
int dowhat = DO_ALL,ptr = 2;
time_t t;
t = time(NULL);
fprintf(stderr,"\n\x1b[2J\rXGROUP (XBBS Groupmail/Echomail Processor) %u.%02u\n%s %s\n\n",
XVERSION,XSUBVERSION,__DATE__,__TIME__);
DosGetMachineMode(&machstate);
if(argc == 1) fprintf(stderr," XGROUP ? > TEMP for a brief helpfile\n\n");
if(argv[1] && *argv[1]=='?') {
send_help();
return 0;
}
if(machstate) {
if(!DosOpenSem(&SemHandle,"\\SEM\\XGROUP.RUN")) {
DosCloseSem(SemHandle);
printf("\nAn instance of XGroup is already running...aborting.\n");
exit(2);
}
else {
if(DosCreateSem(1,&SemHandle,"\\SEM\\XGROUP.RUN")) {
printf("\nCouldn't create XGroup semaphore\n");
}
DosSemSet(SemHandle);
}
if(!DosOpenSem(&XMSemHandle,"\\SEM\\XMSG.RUN")) {
printf("\nWaiting for XMsg run to complete.\n");
DosSemRequest(XMSemHandle,-1L);
DosCloseSem(XMSemHandle);
}
}
atexit(deinitialize);
if (argc < 2) {
if(config(NULL)) return 1;
}
else {
if(config(argv[1])) return 1;
}
/* set command line switch defaults */
control.fullok = 0; /* fully moderated groups not ok */
control.partialok = 0; /* partially moderated groups not ok */
control.noassholes = 0; /* use asshole.### files */
control.assexport = 0; /* don't use asshole.### to abort export */
/* don't talk to me about policy complaints */
/* I write it, not abuse it */
while(argc > ptr && argv[ptr]) {
ReSwitch:
switch(toupper(*argv[ptr])) {
case 0: break;
case '/':
case '-': memmove(argv[ptr],&argv[ptr][1],strlen(argv[ptr]));
goto ReSwitch;
case 'E': dowhat |= DO_EXPORT;
break;
case 'I': dowhat |= DO_IMPORT;
break;
case 'C': dowhat |= DO_CLEANUP;
break;
case 'A': dowhat |= DO_ALL;
break;
case 'M': dowhat |= DO_MAKE;
break;
case 'N': switch(toupper(argv[ptr][1])) {
case 'G': dowhat |= DO_NOGROUP;
break;
case 'E': dowhat |= DO_NOECHO;
break;
default: printf("\nUnknown N option \"%c\"\n",
toupper(argv[ptr][1]));
send_help();
return 1;
}
break;
case 'F': control.fullok = 1;
break;
case 'P': control.partialok = 1;
break;
case 'X': control.assexport = 1;
break;
case 'S': control.noassholes = 1;
break;
case '?': send_help();
return 0;
case 'R': {
ADDR addr;
char *p = argv[ptr + 1];
ECHOREC *currecho;
unsigned int startat = 1;
if(!p || !argv[ptr + 2] || parse_addr(&p,&addr,NULL)) {
printf("\nInvalid Rescan command syntax.\n");
return 2;
}
p = argv[ptr + 2];
if(*p == '\"') p++;
if(p[strlen(p) - 1] == '\"') p[strlen(p) - 1] = 0;
currecho = echos;
while(currecho) {
if(!stricmp(currecho->tag,p)) break;
currecho = currecho->next;
}
if(currecho) {
if(argv[ptr + 3]) startat = atoi(argv[ptr + 3]);
rescan_echo_mail(currecho,&addr,startat);
}
goto RunTime;
}
default: printf("\nUnknown command \"%c\"\n",
toupper(*argv[ptr]));
send_help();
return 1;
}
ptr++;
}
if(dowhat == DO_ALL) {
echo_import_mail();
if(group) {
group_import_mail();
group_export_mail();
}
net_export_mail();
if(echos) {
echo_export_mail();
}
do_route();
clean_up();
}
else {
if(dowhat & DO_IMPORT) {
if(!(dowhat & DO_NOECHO)) if(echos) echo_import_mail();
if(!(dowhat & DO_NOGROUP)) if(group) group_import_mail();
}
if(dowhat & DO_EXPORT) {
if(!(dowhat & DO_NOECHO)) if(echos) echo_export_mail();
if(!(dowhat & DO_NOGROUP)) if(group) group_export_mail();
net_export_mail();
do_route();
}
if(dowhat & DO_CLEANUP) {
clean_up();
}
if(dowhat & DO_MAKE) {
make_requests();
}
}
RunTime:
printf("\nRuntime: %lu mins %lu secs\n",(time(NULL) - t) / 60L,
(time(NULL) - t) - (((time(NULL) - t) / 60L) * 60L));
return 0;
}
#ifdef TSC
void deinitialize (void) {
#else
void _cdecl deinitialize (void) {
#endif
if(logfilehandle != -1) {
close(logfilehandle);
}
if(machstate) {
DosSemClear(SemHandle);
printf("Closing XGroup semaphore\n");
DosCloseSem(SemHandle);
}
}