home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / BBS / NEWSGATE.ZIP / NGSTRUCT.ZIP / SAVECFG.CPP < prev   
Encoding:
C/C++ Source or Header  |  1997-10-13  |  2.4 KB  |  98 lines

  1. #include "loadcfg.h"
  2. #include <direct.h>
  3. #include <dos.h>
  4. #include <fcntl.h>
  5. #include <io.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <sys\stat.h>
  9. #include <sys\types.h>
  10.  
  11. void InitCfg()
  12.  {
  13.   char buf[512] ;
  14.  
  15.   getcurdir(0,buf) ;
  16.   sprintf(Config.MainDir,"%c:\\%s",getdisk()+'A',buf) ;
  17.   sprintf(Config.WorkDir,"%s\\WORK",Config.MainDir) ;
  18.   sprintf(Config.PKTInDir,"%s\\PKTIN",Config.MainDir) ;
  19.   sprintf(Config.PKTOutDir,"%s\\PKTOUT",Config.MainDir) ;
  20.   sprintf(Config.UserFile,"%s\\NEWSGATE.USR",Config.MainDir) ;
  21.   sprintf(Config.LogFile,"%s\\NEWSGATE.LOG",Config.MainDir) ;
  22.   sprintf(Config.BadGuys,"%s\\NEWSGATE.BAD",Config.MainDir) ;
  23.   Config.MsgSize = 2048 ;
  24.   Config.SplitSize = 16 ;
  25.   Config.FirstNo = 30 ;
  26.   Config.FidoFlags = FIDOFL_SEENBY|FIDOFL_ORIGIN ;
  27.   Config.LogItems = LOG_ERR|LOG_WAR|LOG_TRA|LOG_INF ;
  28.   Config.RasFlags = RASFL_BEFWAIT|RASFL_MINIM ;
  29.   Config.Retries = 1 ;
  30.   Config.BadFlags = BADFL_ASTERISK ;
  31.  }
  32.  
  33. SaveCfg()
  34.  {
  35.   struct NwsgHdr nh ;
  36.   struct NNTPServer *nntp ;
  37.   struct Group *grp ;
  38.   int file ;
  39.  
  40.   memset(&nh,0,sizeof(nh)) ;
  41.   nh.Version = VERSION ;
  42.   nh.CfgSize = sizeof(struct NwsgCfg)-sizeof(struct NNTPServer *) ;
  43.   nh.NNTPSize = sizeof(struct NNTPServer)-sizeof(struct NNTPServer *)-
  44.                 sizeof(struct Group *) ;
  45.   nh.GroupSize = sizeof(struct Group)-sizeof(struct Group *) ;
  46.   nh.Magic = CONFIG_MAGIC ;
  47.  
  48.   Config.NNTPNo = 0 ;
  49.   nntp = Config.NNTP ;
  50.   while(nntp)
  51.    {
  52.     nntp->GroupsNo = 0 ;
  53.     grp = nntp->GroupList ;
  54.     while(grp)
  55.      {
  56.       nntp->GroupsNo++ ;
  57.       grp = grp->Next ;
  58.      }
  59.     Config.NNTPNo++ ;
  60.     nntp = nntp->Next ;
  61.    }
  62.   file = _open("NEWSGATE.CFG",_O_CREAT|_O_BINARY|_O_TRUNC|_O_WRONLY,_S_IWRITE|_S_IREAD) ;
  63.   if(file == -1)
  64.    return(0) ;
  65.   if(_write(file,&nh,sizeof(nh)) != sizeof(nh))
  66.    {
  67.     _close(file) ;
  68.     return(0) ;
  69.    }
  70.   if(_write(file,&Config,nh.CfgSize) != nh.CfgSize)
  71.    {
  72.     _close(file) ;
  73.     return(0) ;
  74.    }
  75.   nntp = Config.NNTP ;
  76.   while(nntp)
  77.    {
  78.     if(_write(file,nntp,nh.NNTPSize) != nh.NNTPSize)
  79.      {
  80.       _close(file) ;
  81.       return(0) ;
  82.      }
  83.     grp = nntp->GroupList ;
  84.     while(grp)
  85.      {
  86.       if(_write(file,grp,nh.GroupSize) != nh.GroupSize)
  87.        {
  88.         _close(file) ;
  89.         return(0) ;
  90.        }
  91.       grp = grp->Next ;
  92.      }
  93.     nntp = nntp->Next ;
  94.    }
  95.   _close(file) ;
  96.   return(1) ;
  97.  }
  98.