Annotation of sbbs/sbbs2/initdata.c, revision 1.1

1.1     ! root        1: #line 1 "INITDATA.C"
        !             2: 
        !             3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
        !             4: 
        !             5: /**************************************************************************/
        !             6: /* This file contains the function initdata() and its exclusive functions */
        !             7: /**************************************************************************/
        !             8: 
        !             9: #include "sbbs.h"
        !            10: 
        !            11: /****************************************************************/
        !            12: /* Prototypes of functions that are called only by initdata()  */
        !            13: /****************************************************************/
        !            14: void md(char *path);
        !            15: char *readtext(long *line, FILE *stream);
        !            16: 
        !            17: /****************************************************************************/
        !            18: /* Initializes system and node configuration information and data variables */
        !            19: /****************************************************************************/
        !            20: void initdata()
        !            21: {
        !            22:        char    str[256],str2[LEN_ALIAS+1],fname[13];
        !            23:        int     file;
        !            24:        uint    i,j;
        !            25:        long    l,line=0L;
        !            26:        FILE    *instream;
        !            27:        read_cfg_text_t txt;
        !            28: 
        !            29: txt.openerr="\7\r\nError opening %s for read.\r\n";
        !            30: txt.reading="\r\nReading %s...";
        !            31: txt.readit="\rRead %s       ";
        !            32: txt.allocerr="\7\r\nError allocating %u bytes of memory\r\n";
        !            33: txt.error="\7\r\nERROR: Offset %lu in %s\r\n\r\n";
        !            34: 
        !            35: read_node_cfg(txt);
        !            36: read_main_cfg(txt);
        !            37: read_msgs_cfg(txt);
        !            38: read_file_cfg(txt);
        !            39: read_xtrn_cfg(txt);
        !            40: read_chat_cfg(txt);
        !            41: read_attr_cfg(txt);
        !            42: 
        !            43: strcpy(fname,"TEXT.DAT");
        !            44: sprintf(str,"%s%s",ctrl_dir,fname);
        !            45: if((instream=fnopen(&file,str,O_RDONLY))==NULL) {
        !            46:        lprintf(txt.openerr,str);
        !            47:        bail(1); }
        !            48: lprintf(txt.reading,fname);
        !            49: for(i=0;i<TOTAL_TEXT && !feof(instream) && !ferror(instream);i++)
        !            50:        if((text[i]=text_sav[i]=readtext(&line,instream))==NULL)
        !            51:                i--;
        !            52: if(i<TOTAL_TEXT) {
        !            53:        lprintf(txt.error,line,fname);
        !            54:        lprintf("Less than TOTAL_TEXT (%u) strings defined in %s\r\n"
        !            55:                ,TOTAL_TEXT,fname);
        !            56:        bail(1); }
        !            57: /****************************/
        !            58: /* Read in static text data */
        !            59: /****************************/
        !            60: fclose(instream);
        !            61: lprintf(txt.readit,fname);
        !            62: 
        !            63: strcpy(str,temp_dir);
        !            64: if(strcmp(str+1,":\\"))     /* not root directory */
        !            65:     str[strlen(str)-1]=0;   /* chop off '\' */
        !            66: md(str);
        !            67: 
        !            68: for(i=0;i<=sys_nodes;i++) {
        !            69:        sprintf(str,"%sDSTS.DAB",i ? node_path[i-1] : ctrl_dir);
        !            70:        if(flength(str)<DSTSDABLEN) {
        !            71:                if((file=nopen(str,O_WRONLY|O_CREAT|O_APPEND))==-1) {
        !            72:                        lprintf("\7\r\nError creating %s\r\n",str);
        !            73:                        bail(1); }
        !            74:                while(filelength(file)<DSTSDABLEN)
        !            75:                        if(write(file,"\0",1)!=1)
        !            76:                                break;                          /* Create NULL system dsts.dab */
        !            77:                close(file); } }
        !            78: 
        !            79: j=0;
        !            80: sprintf(str,"%sUSER\\USER.DAT",data_dir);
        !            81: if((l=flength(str))>0L) {
        !            82:        if(l%U_LEN) {
        !            83:                lprintf("\7\r\n%s is not evenly divisable by U_LEN (%d)\r\n"
        !            84:                        ,str,U_LEN);
        !            85:                bail(1); }
        !            86:        j=lastuser(); }
        !            87: if(node_valuser>j)     /* j still equals last user */
        !            88:        node_valuser=1;
        !            89: sys_status|=SS_INITIAL;
        !            90: #ifdef __MSDOS__
        !            91: freedosmem=farcoreleft();
        !            92: #endif
        !            93: }
        !            94: 
        !            95: /****************************************************************************/
        !            96: /* If the directory 'path' doesn't exist, create it.                           */
        !            97: /****************************************************************************/
        !            98: void md(char *path)
        !            99: {
        !           100:        struct ffblk ff;
        !           101: 
        !           102: if(findfirst(path,&ff,FA_DIREC)) {
        !           103:        lprintf("\r\nCreating Directory %s... ",path);
        !           104:        if(mkdir(path)) {
        !           105:                lprintf("\7failed!\r\nFix configuration or make directory by "
        !           106:                        "hand.\r\n");
        !           107:                bail(1); }
        !           108:        lputs(crlf); }
        !           109: }
        !           110: 
        !           111: /****************************************************************************/
        !           112: /* Reads special TEXT.DAT printf style text lines, splicing multiple lines, */
        !           113: /* replacing escaped characters, and allocating the memory                                     */
        !           114: /****************************************************************************/
        !           115: char *readtext(long *line,FILE *stream)
        !           116: {
        !           117:        char buf[2048],str[2048],*p,*p2;
        !           118:        int i,j,k;
        !           119: 
        !           120: if(!fgets(buf,256,stream))
        !           121:        return(NULL);
        !           122: if(line)
        !           123:        (*line)++;
        !           124: if(buf[0]=='#')
        !           125:        return(NULL);
        !           126: p=strrchr(buf,'"');
        !           127: if(!p) {
        !           128:        if(line) {
        !           129:                lprintf("\7\r\nNo quotation marks in line %d of TEXT.DAT\r\n",*line);
        !           130:                bail(1); }
        !           131:        return(NULL); }
        !           132: if(*(p+1)=='\\')       /* merge multiple lines */
        !           133:        while(strlen(buf)<2000) {
        !           134:                if(!fgets(str,255,stream))
        !           135:                        return(NULL);
        !           136:                if(line)
        !           137:                        (*line)++;
        !           138:                p2=strchr(str,'"');
        !           139:                if(!p2)
        !           140:                        continue;
        !           141:                strcpy(p,p2+1);
        !           142:                p=strrchr(p,'"');
        !           143:                if(p && *(p+1)=='\\')
        !           144:                        continue;
        !           145:                break; }
        !           146: *(p)=0;
        !           147: k=strlen(buf);
        !           148: for(i=1,j=0;i<k;j++) {
        !           149:        if(buf[i]=='\\')        { /* escape */
        !           150:                i++;
        !           151:                if(isdigit(buf[i])) {
        !           152:                        str[j]=atoi(buf+i);     /* decimal, NOT octal */
        !           153:                        if(isdigit(buf[++i]))   /* skip up to 3 digits */
        !           154:                                if(isdigit(buf[++i]))
        !           155:                                        i++;
        !           156:                        continue; }
        !           157:                switch(buf[i++]) {
        !           158:                        case '\\':
        !           159:                                str[j]='\\';
        !           160:                                break;
        !           161:                        case '?':
        !           162:                                str[j]='?';
        !           163:                                break;
        !           164:                        case 'x':
        !           165:                 tmp[0]=buf[i++];        /* skip next character */
        !           166:                 tmp[1]=0;
        !           167:                 if(isxdigit(buf[i])) {  /* if another hex digit, skip too */
        !           168:                     tmp[1]=buf[i++];
        !           169:                     tmp[2]=0; }
        !           170:                                str[j]=(char)ahtoul(tmp);
        !           171:                                break;
        !           172:                        case '\'':
        !           173:                                str[j]='\'';
        !           174:                                break;
        !           175:                        case '"':
        !           176:                                str[j]='"';
        !           177:                                break;
        !           178:                        case 'r':
        !           179:                                str[j]=CR;
        !           180:                                break;
        !           181:                        case 'n':
        !           182:                                str[j]=LF;
        !           183:                                break;
        !           184:                        case 't':
        !           185:                                str[j]=TAB;
        !           186:                                break;
        !           187:                        case 'b':
        !           188:                                str[j]=BS;
        !           189:                                break;
        !           190:                        case 'a':
        !           191:                                str[j]=7;       /* BEL */
        !           192:                                break;
        !           193:                        case 'f':
        !           194:                                str[j]=FF;
        !           195:                                break;
        !           196:                        case 'v':
        !           197:                                str[j]=11;      /* VT */
        !           198:                                break;
        !           199:                        default:
        !           200:                                str[j]=buf[i];
        !           201:                                break; }
        !           202:                continue; }
        !           203:        str[j]=buf[i++]; }
        !           204: str[j]=0;
        !           205: if((p=(char *)MALLOC(j+1))==NULL) {
        !           206:        lprintf("\7\r\nError allocating %u bytes of memory from TEXT.DAT\r\n",j);
        !           207:        bail(1); }
        !           208: strcpy(p,str);
        !           209: return(p);
        !           210: }
        !           211: 
        !           212: /****************************************************************************/
        !           213: /* Reads in ATTR.CFG and initializes the associated variables               */
        !           214: /****************************************************************************/
        !           215: void read_attr_cfg(read_cfg_text_t txt)
        !           216: {
        !           217:     char    str[256],fname[13];
        !           218:     int     file,i;
        !           219:        long    offset=0;
        !           220:     FILE    *instream;
        !           221: 
        !           222: strcpy(fname,"ATTR.CFG");
        !           223: sprintf(str,"%s%s",ctrl_dir,fname);
        !           224: if((instream=fnopen(&file,str,O_RDONLY))==NULL) {
        !           225:     lprintf(txt.openerr,str);
        !           226:     bail(1); }
        !           227: lprintf(txt.reading,fname);
        !           228: for(i=0;i<TOTAL_COLORS && !feof(instream) && !ferror(instream);i++) {
        !           229:        readline(&offset,str,4,instream);
        !           230:     color[i]=attrstr(str); }
        !           231: if(i<TOTAL_COLORS) {
        !           232:        lprintf(txt.error,offset,fname);
        !           233:     lprintf("Less than TOTAL_COLORS (%u) defined in %s\r\n"
        !           234:         ,TOTAL_COLORS,fname);
        !           235:     bail(1); }
        !           236: fclose(instream);
        !           237: lprintf(txt.readit,fname);
        !           238: }
        !           239: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.