|
|
1.1 ! root 1: /* load_cfg.c */ ! 2: ! 3: /* Synchronet configuration load routines (exported) */ ! 4: ! 5: /* $Id: load_cfg.c,v 1.13 2000/11/28 02:42:16 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #include "sbbs.h" ! 39: ! 40: /****************************************************************************/ ! 41: /* Initializes system and node configuration information and data variables */ ! 42: /****************************************************************************/ ! 43: BOOL DLLCALL load_cfg(scfg_t* cfg, char* text[]) ! 44: { ! 45: char str[256],fname[13]; ! 46: int i; ! 47: long line=0L; ! 48: FILE *instream; ! 49: read_cfg_text_t txt; ! 50: ! 51: free_cfg(cfg); /* free allocated config parameters */ ! 52: ! 53: memset(&txt,0,sizeof(txt)); ! 54: txt.openerr= "!ERROR: opening %s for read."; ! 55: txt.error= "!ERROR: offset %lu in %s:"; ! 56: txt.allocerr= "!ERROR: allocating %u bytes of memory."; ! 57: ! 58: if(cfg->node_num<1) ! 59: cfg->node_num=1; ! 60: ! 61: backslash(cfg->ctrl_dir); ! 62: if(read_main_cfg(cfg, &txt)==FALSE) ! 63: return(FALSE); ! 64: sprintf(cfg->node_dir,"%.*s",sizeof(cfg->node_dir)-1,cfg->node_path[cfg->node_num-1]); ! 65: if(read_node_cfg(cfg, &txt)==FALSE) ! 66: return(FALSE); ! 67: if(read_msgs_cfg(cfg, &txt)==FALSE) ! 68: return(FALSE); ! 69: if(read_file_cfg(cfg, &txt)==FALSE) ! 70: return(FALSE); ! 71: if(read_xtrn_cfg(cfg, &txt)==FALSE) ! 72: return(FALSE); ! 73: if(read_chat_cfg(cfg, &txt)==FALSE) ! 74: return(FALSE); ! 75: if(read_attr_cfg(cfg, &txt)==FALSE) ! 76: return(FALSE); ! 77: ! 78: if(text!=NULL) { ! 79: ! 80: /* Free existing text if allocated */ ! 81: free_text(text); ! 82: ! 83: strcpy(fname,"text.dat"); ! 84: sprintf(str,"%s%s",cfg->ctrl_dir,fname); ! 85: if((instream=fnopen(NULL,str,O_RDONLY))==NULL) { ! 86: lprintf(txt.openerr,str); ! 87: return(FALSE); } ! 88: if(txt.reading && txt.reading[0]) ! 89: lprintf(txt.reading,fname); ! 90: ! 91: for(i=0;i<TOTAL_TEXT && !feof(instream) && !ferror(instream);i++) ! 92: if((text[i]=readtext(&line,instream))==NULL) { ! 93: i--; ! 94: break; ! 95: } ! 96: fclose(instream); ! 97: ! 98: if(i<TOTAL_TEXT) { ! 99: lprintf(txt.error,line,fname); ! 100: lprintf("Less than TOTAL_TEXT (%u) strings defined in %s." ! 101: ,TOTAL_TEXT,fname); ! 102: return(FALSE); } ! 103: ! 104: /****************************/ ! 105: /* Read in static text data */ ! 106: /****************************/ ! 107: if(txt.readit && txt.readit[0]) ! 108: lprintf(txt.readit,fname); ! 109: } ! 110: ! 111: /* Override com-port settings */ ! 112: cfg->com_base=0xf; /* All nodes use FOSSIL */ ! 113: cfg->com_port=1; /* All nodes use "COM1" */ ! 114: ! 115: return(TRUE); ! 116: } ! 117: ! 118: void DLLCALL free_cfg(scfg_t* cfg) ! 119: { ! 120: free_node_cfg(cfg); ! 121: free_main_cfg(cfg); ! 122: free_msgs_cfg(cfg); ! 123: free_file_cfg(cfg); ! 124: free_chat_cfg(cfg); ! 125: free_xtrn_cfg(cfg); ! 126: } ! 127: ! 128: void DLLCALL free_text(char* text[]) ! 129: { ! 130: int i; ! 131: ! 132: if(text==NULL) ! 133: return; ! 134: ! 135: for(i=0;i<TOTAL_TEXT;i++) { ! 136: FREE_AND_NULL(text[i]); ! 137: } ! 138: } ! 139: ! 140: /****************************************************************************/ ! 141: /* If the directory 'path' doesn't exist, create it. */ ! 142: /****************************************************************************/ ! 143: BOOL md(char *inpath) ! 144: { ! 145: DIR* dir; ! 146: char path[MAX_PATH+1]; ! 147: ! 148: sprintf(path,"%.*s",MAX_PATH,inpath); ! 149: ! 150: /* Truncate '.' if present */ ! 151: if(path[0]!=0 && path[strlen(path)-1]=='.') ! 152: path[strlen(path)-1]=0; ! 153: ! 154: dir=opendir(path); ! 155: if(dir==NULL) { ! 156: lprintf("Creating directory: %s",path); ! 157: if(_mkdir(path)) { ! 158: lprintf("!Error %d: Fix configuration or make directory by " ! 159: "hand.",errno); ! 160: return(FALSE); ! 161: } ! 162: } ! 163: else ! 164: closedir(dir); ! 165: ! 166: return(TRUE); ! 167: } ! 168: ! 169: /****************************************************************************/ ! 170: /* Reads special TEXT.DAT printf style text lines, splicing multiple lines, */ ! 171: /* replacing escaped characters, and allocating the memory */ ! 172: /****************************************************************************/ ! 173: char *readtext(long *line,FILE *stream) ! 174: { ! 175: char buf[2048],str[2048],tmp[256],*p,*p2; ! 176: int i,j,k; ! 177: ! 178: if(!fgets(buf,256,stream)) ! 179: return(NULL); ! 180: if(line) ! 181: (*line)++; ! 182: if(buf[0]=='#') ! 183: return(NULL); ! 184: p=strrchr(buf,'"'); ! 185: if(!p) { ! 186: if(line) { ! 187: lprintf("No quotation marks in line %d of text.dat",*line); ! 188: return(NULL); } ! 189: return(NULL); } ! 190: if(*(p+1)=='\\') /* merge multiple lines */ ! 191: while(strlen(buf)<2000) { ! 192: if(!fgets(str,255,stream)) ! 193: return(NULL); ! 194: if(line) ! 195: (*line)++; ! 196: p2=strchr(str,'"'); ! 197: if(!p2) ! 198: continue; ! 199: strcpy(p,p2+1); ! 200: p=strrchr(p,'"'); ! 201: if(p && *(p+1)=='\\') ! 202: continue; ! 203: break; } ! 204: *(p)=0; ! 205: k=strlen(buf); ! 206: for(i=1,j=0;i<k;j++) { ! 207: if(buf[i]=='\\') { /* escape */ ! 208: i++; ! 209: if(isdigit(buf[i])) { ! 210: str[j]=atoi(buf+i); /* decimal, NOT octal */ ! 211: if(isdigit(buf[++i])) /* skip up to 3 digits */ ! 212: if(isdigit(buf[++i])) ! 213: i++; ! 214: continue; } ! 215: switch(buf[i++]) { ! 216: case '\\': ! 217: str[j]='\\'; ! 218: break; ! 219: case '?': ! 220: str[j]='?'; ! 221: break; ! 222: case 'x': ! 223: tmp[0]=buf[i++]; /* skip next character */ ! 224: tmp[1]=0; ! 225: if(isxdigit(buf[i])) { /* if another hex digit, skip too */ ! 226: tmp[1]=buf[i++]; ! 227: tmp[2]=0; } ! 228: str[j]=(char)ahtoul(tmp); ! 229: break; ! 230: case '\'': ! 231: str[j]='\''; ! 232: break; ! 233: case '"': ! 234: str[j]='"'; ! 235: break; ! 236: case 'r': ! 237: str[j]=CR; ! 238: break; ! 239: case 'n': ! 240: str[j]=LF; ! 241: break; ! 242: case 't': ! 243: str[j]=TAB; ! 244: break; ! 245: case 'b': ! 246: str[j]=BS; ! 247: break; ! 248: case 'a': ! 249: str[j]=BEL; ! 250: break; ! 251: case 'f': ! 252: str[j]=FF; ! 253: break; ! 254: case 'v': ! 255: str[j]=11; /* VT */ ! 256: break; ! 257: default: ! 258: str[j]=buf[i]; ! 259: break; } ! 260: continue; } ! 261: str[j]=buf[i++]; } ! 262: str[j]=0; ! 263: if((p=(char *)MALLOC(j+1))==NULL) { ! 264: lprintf("Error allocating %u bytes of memory from text.dat",j); ! 265: return(NULL); } ! 266: strcpy(p,str); ! 267: return(p); ! 268: } ! 269: ! 270: /****************************************************************************/ ! 271: /* Reads in ATTR.CFG and initializes the associated variables */ ! 272: /****************************************************************************/ ! 273: BOOL read_attr_cfg(scfg_t* cfg, read_cfg_text_t* txt) ! 274: { ! 275: char str[256],fname[13]; ! 276: int i; ! 277: long offset=0; ! 278: FILE *instream; ! 279: ! 280: strcpy(fname,"attr.cfg"); ! 281: sprintf(str,"%s%s",cfg->ctrl_dir,fname); ! 282: if((instream=fnopen(NULL,str,O_RDONLY))==NULL) { ! 283: lprintf(txt->openerr,str); ! 284: return(FALSE); } ! 285: if(txt->reading && txt->reading[0]) ! 286: lprintf(txt->reading,fname); ! 287: for(i=0;i<TOTAL_COLORS && !feof(instream) && !ferror(instream);i++) { ! 288: readline(&offset,str,4,instream); ! 289: cfg->color[i]=attrstr(str); } ! 290: if(i<TOTAL_COLORS) { ! 291: lprintf(txt->error,offset,fname); ! 292: lprintf("Less than TOTAL_COLORS (%u) defined in %s" ! 293: ,TOTAL_COLORS,fname); ! 294: return(FALSE); } ! 295: fclose(instream); ! 296: if(txt->readit && txt->readit[0]) ! 297: lprintf(txt->readit,fname); ! 298: return(TRUE); ! 299: } ! 300:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.