home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / s!x / bgcheck / System / filecheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-04  |  2.6 KB  |  119 lines

  1. #define PROGNAME "Filecheck"         /***/
  2.  
  3. #include "aedoor.h"
  4. #include"bbs:bgcheck/bgcheck.h"
  5. #include "env:timedate.h"
  6.  
  7.  
  8. static const char VersionTag[] = "\0$VER: "PROGNAME" "REVISION" "REVDATE" "REVTIME;
  9.  
  10. void Start(int node);
  11. void main(int argc, char *argv[])
  12. {
  13.     int    Node=0;
  14.     
  15.     if (argc<2)    {printf("Sorry, %s must be called from S!X or /X\n",argv[0]);exit(0);}
  16.     Node=atoi(argv[1]);
  17.     Register(Node);
  18.     XIM_Msg->Command=140;                    
  19.     CheckMessage();
  20.     SetTaskPri(FindTask(0),atol(XIM_Msg->String));
  21.     Start(Node);
  22.     ShutDown();
  23. }
  24. void Start(Node)
  25. {
  26.  
  27.     char    buffer[255]="",
  28.             file[255]="",
  29.             filepath[255]="",
  30.             **main_config=NULL,
  31.             *p=NULL;
  32.     BPTR    readfh=NULL;
  33.     ULONG    len=0,
  34.             pos=0;
  35.     struct    Filedata    *filedata=NULL;
  36.     BOOL    msgbase=FALSE;
  37.  
  38.     SendStrDataCmd(BB_MAINLINE,"",1);
  39.     strcpy(buffer,XIM_Msg->String);
  40.  
  41.     p=strchr(buffer,' ');
  42.     strcpy(file,p+1);    
  43.     upperstring(file);
  44.     
  45.     sprintf(buffer,"FC: %s",file);
  46.     SendStrDataCmd(177,buffer,0);
  47.  
  48.     Forbid();
  49.     filedata=(struct Filedata *)FindSemaphore(file);
  50.     Permit();
  51.  
  52.     if (filedata)
  53.     {
  54.         ObtainSemaphore((struct SignalSemaphore *)filedata);
  55.         if (filedata->MsgBase) msgbase=TRUE; 
  56.         strcpy(filepath,filedata->filepath);
  57.         ReleaseSemaphore((struct SignalSemaphore *)filedata);
  58.  
  59.         main_config=(char **)realloc(main_config,sizeof(char *));
  60.         main_config[0]=NULL;
  61.  
  62.         strcpy(buffer,"bbs:bgcheck/bgfilehandler.config");
  63.         readfh=Open(buffer,MODE_OLDFILE);
  64.         pos=0;
  65.         if (!readfh && pos!=60)
  66.         {
  67.             pos++;
  68.             readfh=Open(buffer,MODE_OLDFILE);
  69.             if (!readfh) Delay(TICKS_PER_SECOND);
  70.         }
  71.         if (readfh)
  72.         {
  73.             for (pos=0;FGets(readfh,buffer,254);pos++)
  74.             {
  75.                 main_config=(char **) realloc(main_config,(pos+1)*sizeof(char *));
  76.                 main_config[pos]=NULL;
  77.                 len=strlen(buffer);
  78.                 if (buffer[len-1]=='\n') buffer[--len]='\0';
  79.                 upperstring(buffer);
  80.                 main_config[pos]=(char *) malloc (len+1);
  81.                 if (main_config[pos]) strcpy(main_config[pos],buffer);
  82.             }
  83.         }
  84.         if (readfh) Close(readfh);
  85.         main_config=(char **) realloc(main_config,(pos+1)*sizeof(char *));
  86.         main_config[pos]=NULL;
  87.  
  88.         pos=0;    
  89.         sprintf(buffer,"FILECHECK.%d",pos);
  90.         while (p=getconfig(main_config,buffer))
  91.         {
  92.             if (p[0]!=0)
  93.             {
  94.                 sprintf(buffer,"%s %d",p,Node);
  95.                 System(buffer,NULL);
  96.             }        
  97.             pos++;
  98.             sprintf(buffer,"FILECHECK.%d",pos);    
  99.         }
  100.  
  101.  
  102.         for (pos=0;main_config[pos]!=NULL;pos++)
  103.             free(main_config[pos]);
  104.         if (main_config) free (main_config);
  105.  
  106.         RemSemaphore((struct SignalSemaphore *)filedata);
  107.         ObtainSemaphore((struct SignalSemaphore *)filedata);
  108.         ReleaseSemaphore((struct SignalSemaphore *)filedata);
  109.         FreeMem(filedata,sizeof(struct Filedata));
  110.     }
  111.  
  112.     if (!msgbase)
  113.     {
  114.         sprintf(buffer,"%s%s",filepath,file);
  115.         DeleteFile(buffer);
  116.         SendDataCmd(DT_GOODFILE,3);
  117.     }
  118. }
  119.