#include <string.h>
#include <stdlib.h>
#include "extern.h"

config_read()
     {  int i;
	*(fname) = NULL;
	strcpy(fname,getenv("BBS"));
	if ( getenv("BBS") )  strcat(fname,"\\");
	strcat(fname,CONFIG_FIL);
        fp1 = fopen(fname,"r");

        if ( fp1 == NULL ) { printf("CONFIG.BBSがありません\n");
                             exit(1); }

        for ( i = 1 ; i <= 13 ; i++ )
        { if ( fgets( fbuff,255,fp1) == NULL )
                           { fclose(fp1);
                             conf_err(i);
                           }
        
          switch(i)
	     {
                case 1: strncpy(bbsname,fbuff,strlen(fbuff) - 1);
						*(bbsname + strlen(bbsname) ) = NULL; break;
                case 2: strncpy(sysop,fbuff,strlen(fbuff) - 1);
						*(sysop + strlen(sysop) ) = NULL; break;
                case 4: strcpy(fname,"cd "); strcat(fname,fbuff);
			system(fname);
			strncpy(fname,fbuff,2); *(fname + 2) = NULL;
			system(fname);  break;
                case 5: strncpy(msgpass,fbuff,strlen(fbuff) - 1);
			*(msgpass + strlen(msgpass) ) = NULL; break;
                case 6: strncpy(pdspass,fbuff,strlen(fbuff) - 1);
			*(pdspass + strlen(pdspass) ) = NULL; break;
                case 7: strncpy(datpass,fbuff,strlen(fbuff) - 1);
			*(datpass + strlen(datpass) ) = NULL; break;
                case 8: strncpy(fname,fbuff,strlen(fbuff) - 1);
			*(fname + strlen(fname) ) = NULL;
     		 	sprintf(temp_fil,"%s\\TMP%d",fname,getpid());
     		 	sprintf(rcv_fil,"%s\\RCV%d",fname,getpid());
      			sprintf(forward_fil,"%s\\FWD%d",fname,getpid());
			break;
                case 9:  fnumb_max = atoi(fbuff); break;
                case 12: moniflg   = atoi(fbuff); break;
				case 13: fcyclic   = atoi(fbuff); break;
                default: break;
             }
        }
        fclose(fp1);
        
	return(0);
     }

