home *** CD-ROM | disk | FTP | other *** search
- #include "rausm.h"
- #include <time.h>
- #include <io.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
-
- void _Err_Handler(char *file, int line, char *date, char *time, int errlevel)
- {
- if (logfp != NULL)
- fprintf(logfp, "\nAbort: %s(%d) %s %s\r\n", strupr(file), line, date, time);
- fprintf(stderr, "\nAbort: %s(%d) %s %s\r\n", strupr(file), line, date, time);
- exit(errlevel);
- }
-
- static FILE *fp;
- static char *p;
-
- static char *SkipSpace(void)
- {
- while ((*p == ' ' || *p == '\t') && *p != '\0' && *p != '\n') p++;
- if (*p == '\0' || *p == '\n') return NULL;
- return p;
- }
-
- static int TokenType(char *s)
- {
- if (stricmp(s, "LogFile") == 0) return 1;
- if (stricmp(s, "UserBbsPath") == 0) return 2;
- if (stricmp(s, "ReportOnly") == 0) return 3;
- if (stricmp(s, "UploadCredit") == 0) return 4;
- if (stricmp(s, "UploadKCredit") == 0) return 5;
- if (stricmp(s, "DownloadCredit") == 0) return 6;
- if (stricmp(s, "DownloadKCredit") == 0) return 7;
- if (stricmp(s, "MessageCredit") == 0) return 8;
- if (stricmp(s, "CallOnCredit") == 0) return 9;
- if (stricmp(s, "SysOpCredit") == 0) return 10;
- if (stricmp(s, "LoginDayCredit") == 0) return 11;
- if (stricmp(s, "ProtectFlag") == 0) return 12;
- if (stricmp(s, "MaxSecurity") == 0) return 13;
- if (stricmp(s, "MinSecurity") == 0) return 14;
- if (stricmp(s, "BaseCredit") == 0) return 15;
- if (stricmp(s, "Security") == 0) return 16;
- if (stricmp(s, "ListFile") == 0) return 17;
- if (stricmp(s, "Hidden") == 0) return 18;
- if (stricmp(s, "SortFile") == 0) return 19;
- return 0;
- }
-
- static char *GetToken(void)
- {
- static char name[512];
- char *p2;
-
- p2 = name;
- while (*p != ' ' && *p != '\r' && *p != '\n' && *p != '\t' && *p != '\0')
- *p2++ = *p++;
- *p2 = '\0';
- return &name[0];
- }
-
- void ReadCTL(char *path)
- {
- char str[1024];
- char name[80];
- int line = 0;
- unsigned int table[] = { 0x01, 0x02, 0x04, 0x08,
- 0x10, 0x20, 0x40, 0x80
- };
- time_t beg;
- SortList *stail, *stemp;
- Hidden *htail, *htemp;
- int i;
-
- logfp = NULL;
- UserBbsPath[0] = '\0';
- ListName[0] = '\0';
- ReportOnly = 0;
- UploadCredit = 0L;
- UploadKCredit = 0L;
- DownloadCredit = 0L;
- DownloadKCredit = 0L;
- MessageCredit = 0L;
- CallOnCredit = 0L;
- SysOpCredit = 0L;
- BaseCredit = 0L;
- LoginDayCredit = 0L;
- memset(UserFlag, '\0', 4);
- MaxSecurity = 0U;
- MinSecurity = 0U;
- SecCount = 0;
- HiddenHead = NULL;
- SortHead = NULL;
- htail = NULL;
- stail = NULL;
-
- if (access("RAUSM.CTL", 0) == 0)
- strcpy(name, "RAUSM.CTL");
- else {
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char file[_MAX_FNAME];
- char ext[_MAX_EXT];
-
- _splitpath(path, drive, dir, file, ext);
- _makepath(name, drive, dir, "RAUSM", ".CTL");
- }
-
- printf(" ■ Reading control file [%s].\n", name);
- if ((fp = fopen(name, "rt")) == NULL) {
- fprintf(stderr, "Failed to open control file [%s].\n", name);
- ERR_EXIT(1);
- }
-
- while (1) {
- line++;
- fgets(str, 1024, fp);
- if (feof(fp)) break;
- p = str;
- if (SkipSpace() == NULL || *p == ';') continue;
- strcpy(name, GetToken());
- if (SkipSpace() == NULL || *p == ';') {
- if (logfp != NULL)
- fprintf(logfp, " ! %s setup error at line %d.\n", name, line);
- fprintf(stderr, " ! %s setup error at line %d.\n", name, line);
- continue;
- }
- switch (TokenType(name)) {
- case 1: // LogFile
- strcpy(name, GetToken());
- if ((logfp = fopen(name, "at")) == NULL)
- fprintf(stderr, " ! Failed to open %s.\n", name);
- if (logfp != NULL) {
- time(&beg);
- strcpy(name, ctime(&beg));
- name[strlen(name)-1] = '\0';
- fprintf(logfp, " ------ %s ------\n", name);
- fprintf(logfp, " ■ RAUSM %s fire up.\n", Version);
- }
- break;
- case 2: // UserBBSPath
- strcpy(UserBbsPath, GetToken());
- break;
- case 3: // ReportOnly
- strcpy(name, GetToken());
- if (stricmp(name, "Yes") == 0)
- ReportOnly = 1;
- else if (stricmp(name, "No") == 0)
- ReportOnly = 0;
- else {
- if (logfp != NULL)
- fprintf(logfp, " ! Definition error at line %d.\n", line);
- fprintf(stderr, " ! Definition error at line %d.\n", line);
- continue;
- }
- break;
- case 4: // UploadCredit
- strcpy(name, GetToken());
- UploadCredit = atol(name);
- break;
- case 5: // UploadKCredit
- strcpy(name, GetToken());
- UploadKCredit = atol(name);
- break;
- case 6: // DownloadCredit
- strcpy(name, GetToken());
- DownloadCredit = atol(name);
- break;
- case 7: // DownloadKCredit
- strcpy(name, GetToken());
- DownloadKCredit = atol(name);
- break;
- case 8: // MessageCredit
- strcpy(name, GetToken());
- MessageCredit = atol(name);
- break;
- case 9: // CallOnCredit
- strcpy(name, GetToken());
- CallOnCredit = atol(name);
- break;
- case 10: // SysOpCredit
- strcpy(name, GetToken());
- SysOpCredit = atol(name);
- break;
- case 11: // LoginDayCredit
- strcpy(name, GetToken());
- LoginDayCredit = atol(name);
- break;
- case 12: // ProtectFlag
- strcpy(name, GetToken());
- UserFlag[toupper(name[0])-'A'] |= table[name[1]-'1'];
- break;
- case 13: // MaxSecurity
- strcpy(name, GetToken());
- MaxSecurity = (unsigned int)atol(name);
- break;
- case 14: // MinSecurity
- strcpy(name, GetToken());
- MinSecurity = (unsigned int)atol(name);
- break;
- case 15: // BaseCredit
- strcpy(name, GetToken());
- BaseCredit = atol(name);
- break;
- case 16: // Security
- if (SecCount == 200) {
- if (logfp != NULL)
- fprintf(logfp, " ! Security too many definition.\n");
- fprintf(stderr, " ! Security too many definition.\n");
- continue;
- }
- strcpy(name, GetToken());
- Security[SecCount].Security = (unsigned int)atol(name);
- if (SkipSpace() == NULL || *p == ';') {
- if (logfp != NULL)
- fprintf(logfp, " ! Security definition error at line %d.\n", line);
- fprintf(stderr, " ! Security definition error at line %d.\n", line);
- continue;
- }
- strcpy(name, GetToken());
- Security[SecCount++].Credit = atol(name);
- break;
- case 17: // ListFile
- strcpy(ListName, GetToken());
- break;
- case 18: // Hidden
- if (*p != '\"') {
- if (logfp != NULL)
- fprintf(logfp, " ! Hidden name definition error at line %d.\n", line);
- fprintf(stderr, " ! Hidden name definition error at line %d.\n", line);
- continue;
- }
- p++;
- i = 0;
- while (*p != '\"' && *p != '\0') {
- if (*p == '\\')
- name[i++] = *p++;
- name[i++] = *p++;
- }
- name[i] = '\0';
- if (*p == '\0') {
- if (logfp != NULL)
- fprintf(logfp, " ! Hidden name definition error at line %d.\n", line);
- fprintf(stderr, " ! Hidden name definition error at line %d.\n", line);
- continue;
- }
- htemp = (Hidden *)malloc(sizeof(Hidden));
- if (htemp == NULL) {
- if (logfp != NULL)
- fprintf(logfp, " ! Memory not enough at line %d.\n", line);
- fprintf(stderr, " ! Memory not enough at line %d.\n", line);
- ERR_EXIT(1);
- }
- htemp->name = (char *)malloc(sizeof(char) * (strlen(name)+1));
- if (htemp->name == NULL) {
- if (logfp != NULL)
- fprintf(logfp, " ! Memory not enough at line %d.\n", line);
- fprintf(stderr, " ! Memory not enough at line %d.\n", line);
- ERR_EXIT(1);
- }
- strcpy(htemp->name, name);
- htemp->next = NULL;
- if (htail == NULL)
- HiddenHead = htemp;
- else
- htail->next = htemp;
- htail = htemp;
- break;
- case 19: // SortFile
- strcpy(name, GetToken());
- stemp = (SortList *)malloc(sizeof(SortList));
- if (stemp == NULL) {
- if (logfp != NULL)
- fprintf(logfp, " ! Memory not enough at line %d.\n", line);
- fprintf(stderr, " ! Memory not enough at line %d.\n", line);
- ERR_EXIT(1);
- }
- stemp->SourceName = (char *)malloc(sizeof(char) * (strlen(name)+1));
- if (stemp->SourceName == NULL) {
- if (logfp != NULL)
- fprintf(logfp, " ! Memory not enough at line %d.\n", line);
- fprintf(stderr, " ! Memory not enough at line %d.\n", line);
- ERR_EXIT(1);
- }
- strcpy(stemp->SourceName, name);
- if (SkipSpace() == NULL || *p == ';') {
- if (logfp != NULL)
- fprintf(logfp, " ! Security definition error at line %d.\n", line);
- fprintf(stderr, " ! Security definition error at line %d.\n", line);
- continue;
- }
- strcpy(name, GetToken());
- stemp->TargetName = (char *)malloc(sizeof(char) * (strlen(name)+1));
- if (stemp->TargetName == NULL) {
- if (logfp != NULL)
- fprintf(logfp, " ! Memory not enough at line %d.\n", line);
- fprintf(stderr, " ! Memory not enough at line %d.\n", line);
- ERR_EXIT(1);
- }
- strcpy(stemp->TargetName, name);
- stemp->Next = NULL;
- if (stail == NULL)
- SortHead = stemp;
- else
- stail->Next = stemp;
- stail = stemp;
- break;
- default:
- printf(" ! Unknown control file token (%s) at line %d.\n",
- name, line);
- break;
- }
- }
- fclose(fp);
- return;
- }
-
-