home *** CD-ROM | disk | FTP | other *** search
- /* ============================================================= */
- /* Rob Hamerling's MAXIMUS download file scan and sort utility. */
- /* -> DOWNPAR.C */
- /* -> Parameter processing routines for DOWNSORT. */
- /* ============================================================= */
-
- #define INCL_BASE
- #define INCL_DOSNLS
- #include <os2.h>
-
- #include <ctype.h>
- #include <memory.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
-
- #include "..\max\mstruct.h"
- #include "downsort.h"
- #include "downfpro.h"
-
- /* Symbolic names of keyword parameters */
- #define K_CMT 0
- #define K_TIT 1
- #define K_FNT 2
- #define K_DAT 3
- #define K_ALL 4
- #define K_NEW 5
- #define K_GBL 6
- #define K_BBS 7
- #define K_FIL 8
- #define K_ORP 9
- #define K_NNN 10
- #define K_PRE 11
- #define K_SUB 12
- #define K_BOT 13
- #define K_NDS 14
- #define K_ODS 15
- #define K_IPF 16
- #define K_OFF 17
- #define K_AIN 18
- #define K_AEX 19
- #define K_DUP 20
- #define K_OK 21
- #define K_IP2 22
- #define K_ASQ 23
- #define K_EMI 24
- #define K_AVA 25
- #define K_END 255
-
- /* prototypes of local functions */
-
- void add_sel_area(char *, char [][MAXANAME]);
- short int conv_priv(char [], short int [], unsigned short int);
- void list_parm(short int, char *, short int);
- short int parse_keyword(char [], char **);
- void read_cfg(char *);
- void title_line(char *, char *[]);
-
-
- /* ----------------------------------------- */
- /* Process commandline and system parameters */
- /* ----------------------------------------- */
- void get_parm(unsigned short int k,
- char *p[])
- {
- #ifndef __32BIT__
- unsigned short int x; //
- #else
- unsigned long int x; //
- #endif
- unsigned short int i,j,n; // counters
- char c; // option letter
-
- #ifndef __32BIT__
- DosGetCtryInfo(sizeof(struct _COUNTRYINFO), &c_code, &c_info, &x);
- #else
- DosQueryCtryInfo(sizeof(struct _COUNTRYINFO), &c_code, &c_info, &x);
- #endif
- // for date format, etc
- sys_date(today); // start timestamp
-
- for (i=1; i<k; ++i) { // pre-scan
- if (p[i][0]=='@') // config filespec
- strncpy(cfg_path,strupr(&p[i][1]),127); // copy filespec
- else if (p[i][0] == '/' || p[i][0] == '-') { // options
- switch(c = (char) toupper(p[i][1])) {
- case VERBOSE : oper_mode = VERBOSE; break;
- case QUIET : oper_mode = QUIET; break;
- case HELP : oper_mode = HELP; break;
- case QMARK : oper_mode = HELP; break;
- }
- }
- }
-
- if (oper_mode == HELP)
- show_help(); // display help and exit
- else if (oper_mode != QUIET)
- show_welcome(); // display DOWNSORT 'logo'
-
- read_cfg(cfg_path); // process configuration file
-
- for (i=1; i<k; i++) { // all commandline parms
- strupr(p[i]); // make string upper case
-
- if (strcmp(p[i],"ORP") == 0) // ORP-list requested
- lp[P_ORP].priv[0] = SYSOP; // first/only default: SYSOP
-
- else if (strcmp(p[i],"BBS") == 0 ||
- strncmp(p[i],"BBS:",4) == 0) { // BBS-list requested
- lp[P_BBS].priv[0] = SYSOP; // default: SYSOP
- if (p[i][3] == ':')
- if (conv_priv(&p[i][4],lp[P_BBS].priv,1) <= 0) // convert
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"NEW") == 0 ||
- strncmp(p[i],"NEW:",4) == 0) { // NEW-list requested
- lp[P_NEW].priv[0] = SYSOP; // first/only default: SYSOP
- if (p[i][3] == ':')
- if (conv_priv(&p[i][4],lp[P_NEW].priv,10) <= 0) // convert to int
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"EMI") == 0 ||
- strncmp(p[i],"EMI:",4) == 0) { // EMI-list requested
- lp[P_EMI].priv[0] = SYSOP; // first/only default: SYSOP
- if (p[i][3] == ':')
- if (conv_priv(&p[i][4],lp[P_EMI].priv,10) <= 0) // convert to int
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"ALL") == 0 ||
- strncmp(p[i],"ALL:",4) == 0) { // ALL-list requested
- lp[P_ALL].priv[0] = SYSOP; // first/only default: SYSOP
- if (p[i][3] == ':')
- if (conv_priv(&p[i][4],lp[P_ALL].priv,10) <= 0) // convert to int
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"IPF") == 0 ||
- strncmp(p[i],"IPF:",4) == 0) { // IPF-list requested
- lp[P_IPF].priv[0] = SYSOP; // first/only default: SYSOP
- if (p[i][3] == ':')
- if (conv_priv(&p[i][4],lp[P_IPF].priv,10) <= 0) // convert to int
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"IP2") == 0 ||
- strncmp(p[i],"IP2:",4) == 0) { // IPF2-list requested
- lp[P_IP2].priv[0] = SYSOP; // first/only default: SYSOP
- if (p[i][3] == ':')
- if (conv_priv(&p[i][4],lp[P_IP2].priv,10) <= 0) // convert to int
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"GBL") == 0 ||
- strncmp(p[i],"GBL:",4) == 0) { // GBL-list requested
- lp[P_GBL].priv[0] = SYSOP; // first/only default: SYSOP
- if (p[i][3] == ':')
- if (conv_priv(&p[i][4],lp[P_GBL].priv,10) <= 0) // convert to int
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"DUP") == 0 ||
- strncmp(p[i],"DUP:",4) == 0) { // DUP-list requested
- lp[P_DUP].priv[0] = SYSOP; // default: SYSOP
- if (p[i][3] == ':')
- if (conv_priv(&p[i][4],lp[P_DUP].priv,1) <= 0) // convert
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"OK") == 0 ||
- strncmp(p[i],"OK:",3) == 0) { // OK-file requested
- lp[P_OK].priv[0] = SYSOP; // default: SYSOP
- if (p[i][2] == ':')
- if (conv_priv(&p[i][3],lp[P_OK].priv,10) <= 0) // convert
- oper_mode = HELP;
- }
-
- else if (strcmp(p[i],"FIL") == 0 ||
- strncmp(p[i],"FIL:",4) == 0) { // FILES.BBS to be generated
- lp[P_FIL].priv[0] = SYSOP;
- if (p[i][3] == ':') { // path specified?
- strncpy(filesbbs_path,&p[i][4],79);
- j = strlen(filesbbs_path);
- if (j>0 && filesbbs_path[j-1] != '\\')
- filesbbs_path[j] = '\\'; // add backslash if needed
- }
- }
-
- else if (p[i][0] == '/' || p[i][0] == '-') { // option flag
- switch(c = (char) toupper(p[i][1])) {
- case TRUNC :
- case WRAP : for (j=0; j<P_MAX; ++j)
- lp[j].wrapflag = c;
- break;
- case ALPHA :
- case TIMESTAMP :
- case KEEPSEQ : for (j=0; j<P_MAX; ++j)
- lp[j].sortflag = c;
- break;
- case LONGLIST : for (j=0; j<P_MAX; ++j)
- lp[j].longflag = c;
- break;
- case EXCLPRIV : for (j=0; j<P_MAX; ++j)
- lp[j].exclflag = c;
- break;
- case QUIET :
- case VERBOSE :
- case HELP : oper_mode = c; break;
- case QMARK : oper_mode = HELP; break;
-
- default : oper_mode = HELP; break;
- }
- }
-
- else if (0 < (n = atoi(p[i]))) { // num_value: list length
- lp[P_BBS].max_fil = n; // BBS-list length
- lp[P_BBS].listflag = ' '; // no period (yet?)
- lp[P_NEW].max_fil = n; // NEW-list length
- lp[P_NEW].listflag = ' '; // no period (yet?)
- lp[P_EMI].max_fil = n; // NEW-list length
- lp[P_EMI].listflag = ' '; // no period (yet?)
- j = strlen(p[i]) - 1; // offset to last character
- c = p[i][j]; // last character
- if (c == 'D' || c == 'W' || c == 'M') {
- lp[P_BBS].listflag = c; // BBS-list flag
- lp[P_NEW].listflag = c; // NEW-list flag
- lp[P_EMI].listflag = c; // EMI-list flag
- }
- }
-
- else if (p[i][0] == '@') // config filespec
- ; // skip (processed in pre-scan)
-
- else
- printf("\nUnknown Parameter: %-50.50s",p[i]);
- }
-
- for (i=0; i<=P_MAX; i++) // all report entries
- for (j=0; j<10; j++) // all privilege entries
- if (ABS_MAX_priv < lp[i].priv[j] && // higher than before
- HIDDEN+1 > lp[i].priv[j]) // but only requested reports
- ABS_MAX_priv = lp[i].priv[j]; // revise if needed
- }
-
- /* --------------------------------- */
- /* Process privilege parameterstring */
- /* --------------------------------- */
- short int conv_priv(char c[],
- short int p[],
- unsigned short int n)
- {
- unsigned short int i,j,k; // counters
-
- for (i=j=0; i<n && c[i]!='\0' && c[i]!=' '; ++i) {
- if (c[i] == '*') // asterisk specified?
- p[j] = SYSOP; // system default
- else {
- for (k=0; k<HIDDEN-TWIT+1 && // search table
- priv_name[k][0] != (char) toupper(c[i]);
- k++);
- p[j] = k + TWIT; // store real privilege
- } // endif
- if (p[j]<=HIDDEN) // hidden or below?
- ++j; // count only valid privs
- } // endfor
- for (i=j; i<n; ++i) // remaining priv-values
- p[i] = HIDDEN + 1; // undo any previous settings
- return(j); // number of valid privs
- }
-
- /* =================================== */
- /* Process DOWNSORT Configuration File */
- /* =================================== */
- void read_cfg(char ds_cfg[])
- {
- FILE *prm;
- char buf[256], c;
- char *value; // ptr to parameter value
- short int i,j,t;
-
- if ((prm = fopen(ds_cfg,"r")) == NULL )
- printf(OPEN_FAIL, ds_cfg, 2); // dummy rc 'file not found'!
-
- else {
- if (oper_mode != QUIET)
- printf("\nReading configuration file: %s",cfg_path);
-
- while (fgets(buf,255,prm)) { // process 1 line at a time
-
- switch(parse_keyword(buf,&value)) {
-
- case K_CMT: // Comment and empty lines
- break;
-
- case K_TIT: // list title (ALL, NEW, GBL)
- for (j=0; j<20 && value[j]!='\0'; j++)
- if (value[j] == '~') // replace tilde by blank
- value[j] = ' ';
- strncpy(list_title,value,20);
- break;
-
- case K_PRE: // pre-title
- title_line(value,pre_title);
- break;
-
- case K_SUB: // sub-title
- title_line(value,sub_title);
- break;
-
- case K_BOT: // bottom line
- title_line(value,bot_lines);
- break;
-
- case K_ODS: // Orphan Description
- strncpy(ORPHAN,value,45); // copy file text
- break;
-
- case K_NDS: // Missing Description
- strncpy(NDS,value,45); // copy file text
- break;
-
- case K_OFF: // Offline Description
- OFFLINE[0] = '\0'; // erase default string
- strncat(OFFLINE,value,14); // copy(!) text
- strcat(OFFLINE," "); // 1 trailing blank
- break;
-
- case K_FNT: // Font for all lists
- t = atoi(value); // convert to integer
- if (t < FONT0 || t > FONT4) // range check
- printf("\n!Error: TitleFont out of range");
- else
- for (i=0; i<P_MAX; i++)
- lp[i].tfont = t; // to all parmlist entries
- break;
-
- case K_DAT: // Area.Dat
- strncpy(areadat_path,strupr(value),80); // copy file specification
- break;
-
- case K_AIN: // AreaINclude
- area_IN_EX = +1; // inclusion
- add_sel_area(value, selected_area); // area codes to array
- break;
-
- case K_AEX: // AreaEXclude
- area_IN_EX = -1; // exclusion
- add_sel_area(value, selected_area); // area codes to array
- break;
-
- case K_ASQ: // AreaSequence
- area_seq = (char) toupper(value[0]); // take 1st char uppercase
- break;
-
- case K_AVA: // Strip AVATAR graphics
- strip_ava = (char) toupper(value[0]); // set switch
- break;
-
- case K_NNN:
- if (0 < (t = atoi(value))) { // NEW- & BBS-list length
- lp[P_BBS].max_fil = t; // BBS-list length
- lp[P_BBS].listflag = ' '; // no period (yet?)
- lp[P_NEW].max_fil = t; // NEW-list length
- lp[P_NEW].listflag = ' '; // no period (yet?)
- lp[P_EMI].max_fil = t; // EMI-list length
- lp[P_EMI].listflag = ' '; // no period (yet?)
- strupr(value); // all upper case
- c = value[strlen(asciiz(value))-1]; // last character
- if (c == 'D' || c == 'W' || c == 'M') {
- lp[P_BBS].listflag = c; // BBS-list flag
- lp[P_NEW].listflag = c; // NEW-list flag
- lp[P_EMI].listflag = c; // EMI-list flag
- }
- }
- break;
-
- case K_ALL: // create ALL-list(s)
- list_parm(P_ALL,value,10);
- break;
-
- case K_IPF: // create IPF-list(s)
- list_parm(P_IPF,value,10);
- break;
-
- case K_IP2: // create IPF2-list(s)
- list_parm(P_IP2,value,10);
- break;
-
- case K_BBS: // create BBS-list
- list_parm(P_BBS,value,1);
- break;
-
- case K_GBL: // create GBL-list
- list_parm(P_GBL,value,10);
- break;
-
- case K_NEW: // create NEW-list(s)
- list_parm(P_NEW,value,10);
- break;
-
- case K_EMI: // create EMI-list(s)
- list_parm(P_EMI,value,10);
- break;
-
- case K_DUP: // naming of DUP-list
- list_parm(P_DUP,value,1);
- break;
-
- case K_OK: // create OKfile(s)
- list_parm(P_OK,value,10);
- break;
-
- case K_ORP: // naming of ORP-list
- list_parm(P_ORP,value,1);
- break;
-
- case K_FIL: // create FILES.bbs files
- strupr(value); // all upper case
- conv_priv(value,lp[P_FIL].priv,1);
- while ((value = next_word(value)) != NULL) { // remaining parm(s)
- if (value[0] == '/' || value[0] == '-') { // option flag
- switch(value[1]) {
- case ALPHA : lp[P_FIL].sortflag = ALPHA; break;
- case TIMESTAMP : lp[P_FIL].sortflag = TIMESTAMP; break;
- case KEEPSEQ : lp[P_FIL].sortflag = KEEPSEQ; break;
- case EXCLPRIV : lp[P_FIL].exclflag = EXCLPRIV; break;
- case INCLUDE : lp[P_FIL].incl_fspec =
- (char *)malloc(strlen(asciiz(value+2))+1);
- if (lp[P_FIL].incl_fspec == NULL) {
- printf(MSG_MEM,PROGNAME);
- exit(14);
- }
- else
- strcpy(lp[P_FIL].incl_fspec,
- asciiz(value+2));
- break;
- default : break;
- }
- }
- else { /* assume 'value' is pathname */
- strncpy(filesbbs_path,asciiz(value),80); // spec'd PATH
- j = strlen(filesbbs_path);
- if (j>0 && filesbbs_path[j-1] != '\\')
- filesbbs_path[j] = '\\'; // add backslash if needed
- }
- }
- break;
-
- case K_END: // Keyword not found
- default: // undefined
- printf("\nUnknown Configuration keyword: %-50.50s",buf);
- break;
- }
- }
- fclose(prm); // close downsort.cfg
- }
- }
-
- /* =============================== */
- /* Process xxxFileList parameters. */
- /* =============================== */
- void list_parm(short int k,
- char *v,
- short int n)
- {
- short int t,j; // intermediate int value
- char *nv; // moving string pointer
- char c; // single input character
-
- strupr(v); // whole string uppercase
- conv_priv(v, lp[k].priv, n); // privilege string
- if ((nv = next_word(v)) != NULL && // 1st expected: filename
- strcmp(nv,"*") != 0) // not asterisk
- strncpy(lp[k].name,asciiz(nv),8); // customised filename
- while ((nv = next_word(nv)) != NULL) { // remaining parm(s)
- if (nv[0] == '/' || nv[0] == '-') { // option flag
- switch(nv[1]) {
- case TRUNC : lp[k].wrapflag = TRUNC; break;
- case WRAP : lp[k].wrapflag = WRAP; break;
- case ALPHA : lp[k].sortflag = ALPHA; break;
- case TIMESTAMP : lp[k].sortflag = TIMESTAMP; break;
- case KEEPSEQ : lp[k].sortflag = KEEPSEQ; break;
- case LONGLIST : lp[k].longflag = LONGLIST; break;
- case FONT : t = atoi(nv+2);
- if (t >= FONT0 && t <= FONT4) // range check
- lp[k].tfont = t;
- break;
- case EXCLPRIV : lp[k].exclflag = EXCLPRIV; break;
- case INCLUDE : lp[k].incl_fspec =
- (char *)malloc(strlen(asciiz(nv+2))+1);
- if (lp[k].incl_fspec == NULL) {
- printf(MSG_MEM,PROGNAME); // not enough memory
- exit(14);
- }
- else
- strcpy(lp[k].incl_fspec, asciiz(nv+2));
- break;
- default : break; // invalid parms ignored
- }
- }
- else if (0 < atoi(nv)) { // numeric: NEW-list length
- lp[k].max_fil = atoi(nv); // (for IPF-list: pagesize)
- lp[k].listflag = ' '; // set to (nullify previous) period
- j = strlen(asciiz(nv)) - 1; // offset to last character
- c = nv[j]; // last character
- if (c == 'D' || c == 'W' || c == 'M')
- lp[k].listflag = c; // copy listflag
- }
- }
- }
-
- /* ============================ */
- /* Process xxxTitle parameters. */
- /* ============================ */
- void title_line(char *v,
- char *t[])
- {
- short int i,j; // counters
-
- for (i=0; i<MAXTIT && t[i]!=NULL; ++i); // search 1st free place
- if (i<MAXTIT) { // not too many subtitles?
- t[i] = (char *)malloc(strlen(v)+2); // obtain memory (1 too many?)
- if (t[i] == NULL) {
- printf(MSG_MEM,PROGNAME); // not enough memory
- exit(14);
- }
- else {
- for (j=0; v[j]; j++) // whole line
- t[i][j] = (char)((v[j] == '~') ? ' ' : v[j]); // copy/translate
- t[i][j] = '\0'; // end of string
- }
- }
- }
-
- /* ============================ */
- /* Process AreaSelect line */
- /* ============================ */
- void add_sel_area(char *v,
- char s[][MAXANAME])
- {
- short int i,j; // counters
-
- for (i=0; s[i][0] != '\0'; ++i); // search first empty place
-
- for ( ; v!=NULL && i<200; i++) { // all entries in array bounds
- for (j=0; v[j] != ' ' && v[j] != '\0' && j < MAXANAME-1; ++j)
- s[i][j] = v[j]; // copy area name to array
- for ( ; j < MAXANAME; ++j)
- s[i][j] = '\0'; // trailing zero's
- v = next_word(v); // search next code
- }
-
- s[i][0] = '\0'; // last entry marker
-
- }
-
- /* ===================================== */
- /* Find the number of the config options */
- /* Returns the keyword symbolic number, */
- /* and pointer to the keyword value. */
- /* ===================================== */
- short int parse_keyword(char line[],
- char **value)
- {
- short int i,p; // counters
-
- static struct parse_config { // Keyword Parameter Spec
- unsigned char id; // parameter identifier
- unsigned char len; // keyword length
- char *key; // keyword
- } cfg[] = { // table of keyword parameters
- // NOTE: most significant first!
- {K_ALL, 11, "AllFileList"},
- {K_DAT, 7, "AreaDat"},
- {K_AEX, 11, "AreaEXclude"},
- {K_AIN, 11, "AreaINclude"},
- {K_ASQ, 9, "AreaOrder"},
- {K_AVA, 8, "AVAstrip"},
- {K_BBS, 11, "BbsFileList"},
- {K_BOT, 10, "BottomLine"},
- {K_DUP, 11, "DupFileList"},
- {K_FIL, 11, "FilFilePath"},
- {K_GBL, 11, "GblFileList"},
- {K_IPF, 11, "IpfFileList"},
- {K_IP2, 11, "Ip2FileList"},
- {K_NNN, 11, "MaxNewFiles"},
- {K_NEW, 11, "NewFileList"},
- {K_EMI, 11, "EmiFileList"},
- {K_OK , 10, "OKFileList"},
- {K_NDS, 12, "NotFoundDesc"},
- {K_OFF, 11, "OfflineDesc"},
- {K_ORP, 11, "OrpFileList"},
- {K_ODS, 10, "OrphanDesc"},
- {K_PRE, 8, "PreTitle"},
- {K_SUB, 8, "SubTitle"},
- {K_FNT, 9, "TitleFont"},
- {K_TIT, 5, "Title"},
- {K_END, 0, ""}, // end of table: keyw. not found
- };
-
- *value = NULL; // init: default return
-
- for (i=0; line[i]==' '; ++i); // skip leading blanks
- line = line+i; // new local pointer
-
- if (line[0] == '%' || // comment
- line[0] == ';' || // comment
- line[0] == '*' || // comment
- line[0] == '\r' || // CR character
- line[0] == '\n' || // LF character
- line[0] == '\0') // end of string
- return(K_CMT); // return as comment line
-
- for (i=0; cfg[i].id < K_END && // not end of table
- strnicmp(line,cfg[i].key,cfg[i].len) != 0 ; i++);
- p = cfg[i].id; // return identification value
-
- *value = next_word(line); // search value string
- if (*value == NULL) // no keyword value
- return(K_CMT); // treat as comment
-
- i = strlen(*value); // length of value string
- if ((*value)[i-1] == '\n' || // line feed or
- (*value)[i-1] == '\r') // carriage return
- (*value)[i-1] = '\0'; // by end of string
-
- return(p); // return the keyword number
- }
-
-