home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / bbs / fil_lis / fil_lis.c next >
C/C++ Source or Header  |  1993-01-10  |  10KB  |  388 lines

  1. /* Forem-File Tester by W.Zweygart */
  2.  
  3. #define VERSION "0.1"
  4. #define FOR_DX 1
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <tos.h>
  10. #include <ext.h>
  11. #include <ctype.h>
  12. #include <time.h>
  13. #include "turbo.h"
  14. #include "tin_door.c"
  15.  
  16. char mesage[30];
  17. char datas[30];
  18. char oldpath[64];
  19. char conf_name[64];
  20. CONFIG xmbuf;
  21. int device;  /* AUX: */
  22. char drive[3], dir[40], filename[9], ext[5];
  23. char new_drivelist[40];
  24. int main_level;
  25. int main_function;        /* bit weise: 1 console, 2 listing 4 debug */
  26. FILE *flist;
  27.  
  28. void fnsplit (const char *path,
  29.               char *drive, char *dir, char *fname, char *ext)
  30. {
  31.     char *h_path;
  32.     size_t len;
  33.  
  34.     /* I know it's not the fine way but I have to stay compatible */
  35.     /* with the PC declaration */
  36.     h_path = (char *)path;
  37.     drive[0] = '\0';
  38.     dir[0] = '\0';
  39.     fname[0] = '\0';
  40.     ext[0] = '\0';
  41.     if (h_path[1] == ':') {
  42.         strncpy(drive, h_path, 2);
  43.         drive[2] = '\0';
  44.         h_path += 2;
  45.     }
  46.     if (h_path[0] == '\\')
  47.     {
  48.         strncpy (dir, h_path, (len = (size_t)((strrchr(h_path, '\\') - h_path) + 1)) );
  49.         dir[len] = '\0';
  50.     }
  51.     else
  52.     {
  53.         dir[0] = '\\';
  54.         strncpy (dir+1, h_path, (len = (size_t)((strrchr(h_path, '\\') - h_path) + 1)) );
  55.         dir[len+1] = '\0';
  56.     }
  57.     h_path += len;
  58.     if (strchr(h_path, '.') == NULL) {
  59.         strncpy(fname, h_path, 9);
  60.         fname[8] = '\0';
  61.     } else {
  62.         strncpy(fname, h_path, (len = (size_t)(strchr(h_path, '.') - h_path)));
  63.         fname[len] = '\0';
  64.         h_path += len;
  65.         strncpy(ext, h_path, 4);
  66.         ext[4] = '\0';
  67.     }
  68. }
  69.  
  70. /*    search a file in the default path on every drive online in config.dat */
  71. /* return 0 if found -1 otherwise */
  72.  
  73. int findfile (char *path, int cont) {
  74.     static char fname[81], orig_path[81];
  75.     static int drv;
  76.     static struct ffblk ffb;    /* for find_first(), find_next() */
  77.     int first;
  78.  
  79.     first = !cont;
  80.     if (!cont) {
  81.         drv = 0;
  82.         strcpy (orig_path, path); /* save original path */
  83.     }
  84.     while (drv < strlen(new_drivelist)) {
  85.         if (cont) {    /* find next one */
  86.             if (!findnext(&ffb)) {
  87.                 strcpy(path, drive);
  88.                 strcat(path, dir);
  89.                 strcat(path, ffb.ff_name);
  90.                 fnsplit(path, drive, dir, filename, ext);
  91.                 return (0);
  92.             } else {
  93.                 drv++;    /* continue on next drive */
  94.                 cont = 0;
  95.                 strcpy (path, orig_path); /* restore original path */
  96.                 if(!(drv < strlen(new_drivelist))) break;    /* not found */
  97.             }
  98.         }
  99.         if (!cont) {    /* find first one on this drive */
  100.             sprintf(fname, "%c:%s%s", new_drivelist[drv], xmbuf.defdir, path);
  101.             fnsplit(fname, drive, dir, filename, ext);
  102.             if (!findfirst(fname, &ffb, 0)) {
  103.                 strcpy(path, drive);
  104.                 strcat(path, dir);
  105.                 strcat(path, ffb.ff_name);    /* construct path of file found */
  106.                 fnsplit(path, drive, dir, filename, ext);
  107.                 return (0);
  108.             } else drv++;
  109.         if(!(drv < strlen(new_drivelist))) break;    /* not found */
  110.         }
  111.     } /* while */
  112.     if (first) {
  113. printf("ff_f: could not find file %s\r\n", orig_path);
  114.     } else {
  115. printf("ff_n: no more %s\r\n", orig_path);
  116.     }
  117.     return (-1);    /* not found */
  118. }
  119.  
  120. void this_printf(int mask, const char *format, ...)
  121. {
  122.  va_list arg_point;
  123.  char temp[255];
  124.  
  125.  va_start(arg_point, format);
  126.  vsprintf(temp, format, arg_point);
  127.  va_end(arg_point);
  128.  
  129.  if((mask & 1) && (main_function & 1)) cd_puts(temp, device);
  130.  if((mask & 2) && (main_function & 2)) fprintf(flist, temp);
  131.  if(((mask & 4) && !(mask & 1)) || (main_function == 0)) printf(temp);
  132. }
  133.  
  134.  
  135. void check_arg(int argc, char *argv[])
  136. {     /* Commandlineparameter cheken */
  137.  if(argc>1) if(stricmp(argv[1],"LOCAL")==0) device=2;
  138.  if(argc>2) if(sscanf(argv[2],"%d",&main_level)==0) main_level=32767;
  139.  if(argc>3) if(sscanf(argv[3],"%d",&main_function)==0) main_function=0;
  140. }
  141.  
  142. void
  143. les_opt(void )
  144. {
  145.  FILE *fp;
  146.  char tmp[82];
  147.  int i;
  148.  
  149.  fp = fopen("TURBO.OPT","rb");
  150.  if (fp > 0)
  151.   {
  152.   for(i=0; i<47; i++)
  153.     {
  154.     fgets(tmp,80,fp);
  155.     if (i==4)
  156.       {
  157.         strcpy(new_drivelist,strtok(tmp," "));
  158.         this_printf(5,"Drive List :<%s>\n",new_drivelist);
  159.       }
  160.     if (i==31)
  161.       {
  162.         strcpy(mesage,strtok(tmp," "));
  163.         this_printf(5,"Message Subdirectory :<%s>\n",mesage);
  164.       }
  165.     if (i==34)
  166.       {
  167.         strcpy(datas,strtok(tmp," "));
  168.         this_printf(5,"Alternate Dir for Dat-Files :<%s>\n",datas);
  169.       }
  170.     }
  171.   fclose(fp);
  172.   }
  173.  else
  174.   {
  175.     this_printf(5," TURBO.OPT not found!\n");
  176.   }
  177. }
  178.  
  179. void
  180. test_dir( char *direct)
  181. {
  182.  FILE *fp;
  183.  TFILE dl_dir;
  184.  char f_n_dll[65];
  185.  short ft,i;
  186.  long summe;
  187.  short counter;
  188.  
  189.  this_printf(3,"\n=============================================================================\n",direct);
  190.  this_printf(3,"\nFile Directory of %s\n\n",direct);
  191.  
  192.  sprintf(f_n_dll,"%s%s%s",datas,direct,".FIL");
  193.  if (findfile(f_n_dll, 0))
  194.   {
  195.     this_printf(5,"Could not find %s.\n", f_n_dll);
  196.     return;
  197.   }
  198.  else
  199.   {
  200.     summe = 0;
  201.     counter = 0;
  202.     this_printf(5," Turbo-File %s testing\n\n",f_n_dll);
  203.     fp = fopen(f_n_dll,"rb");
  204.     if (fp == 0)
  205.      {
  206.         this_printf(5," Fehler!!\n");
  207.         return;
  208.      }
  209.     if (fp > 0)
  210.      {
  211.       do
  212.        {
  213.             fread((char*)&dl_dir,sizeof(dl_dir),1,fp);
  214.             ft=feof(fp);
  215.             if(ft==0)
  216.              {
  217.                 if(dl_dir.flevel<=main_level)
  218.                  {
  219.                     this_printf(3,"%-13s %6ld %2d-%2d-%2d [%2ld] ",
  220.                             dl_dir.fname,dl_dir.flength,
  221.                             dl_dir.fdate[1],dl_dir.fdate[0],dl_dir.fdate[2],
  222.                             dl_dir.frd_cnt);
  223.                     this_printf(3,"%s\n",&dl_dir.fdesc[0]);
  224.                     for(i=1; i<5; i++) if(strlen(dl_dir.fdesc[i])>1)
  225.                                 this_printf(3,"\t\t\t\t   %s\n",&dl_dir.fdesc[i]);
  226.                     summe += dl_dir.flength;
  227.                     counter++;
  228.                  }
  229.               }
  230.          } while(!ft);
  231.       fclose(fp);
  232.     }
  233.     this_printf(3,"\n %5d Files, %4ld KBytes\n",counter,summe/1024L);
  234.   }
  235. }
  236.  
  237. void
  238. test_config(void)
  239. {
  240.  short i;
  241.  long fl;
  242.  
  243.  this_printf(5,"Analyse des Forem-Files CONFIG.DAT\n\n");
  244.  this_printf(5,"Zahl der Anrufer : %ld \n",xmbuf.callno);
  245.  this_printf(5,"Zahl der Nachrichten  : %ld \n",xmbuf.nmess);
  246.  this_printf(5,"Drives : %d \n",xmbuf.ndrives);
  247.  this_printf(5,"File-Systeme : %d \n",xmbuf.ndirect);
  248.  for(i=0; i<xmbuf.ndirect; i++)
  249.   {
  250.     this_printf(5,"No %3d : %-9s \n",i+1,xmbuf.subdir[i]);
  251.   }
  252.  this_printf(5,"Pwnum : %d \n",xmbuf.pwnum);
  253.  this_printf(5,"Message Bases : %d \n",xmbuf.nbbs);
  254.  for(i=0; i<=xmbuf.nbbs; i++)
  255.     {
  256.     this_printf(5,"z.Z Msgs %-2d next %-2d nconf max %-2d hmess rec %-2d Name %s \n",
  257.      xmbuf.mconf[i],xmbuf.cmess[i],xmbuf.nconf[i],xmbuf.hmess[i],
  258.      xmbuf.conf[i]);
  259.     if(xmbuf.hmess[i]<0 || xmbuf.cmess[i]<0)
  260.         this_printf(5,"Schwerer Fehler! Negative Msg-Nummer!\n\n");
  261.     }
  262.  this_printf(5,"Textcolor     : %d \n",xmbuf.textcolor);
  263.  this_printf(5,"Backcolor     : %d \n",xmbuf.backcolor);
  264.  this_printf(5,"Old Drives : %s \n",xmbuf.drvlist);
  265.  this_printf(5,"Path  : %s \n",xmbuf.defdir);
  266.  fl = xmbuf.flags;
  267.  if ((fl&(1<<1))>0)
  268.   {
  269.     this_printf(5," Chat mode on\n");
  270.   }
  271.  if ((fl&(1<<2))>0)
  272.   {
  273.     this_printf(5," Log to disk\n");
  274.   }
  275.  if ((fl&(1<<3))>0)
  276.   {
  277.     this_printf(5," Guest login\n");
  278.   }
  279.  if ((fl&(1<<4))>0)
  280.   {
  281.     this_printf(5," Accounting\n");
  282.   }
  283.  if ((fl&(1<<5))>0)
  284.   {
  285.     this_printf(5," New User Acc\n");
  286.   }
  287.  if ((fl&(1<<7))>0)
  288.   {
  289.     this_printf(5," Color Monitor\n");
  290.   }
  291.  if ((fl&(1<<8))>0)
  292.   {
  293.     this_printf(5," Survey on\n");
  294.   }
  295.  if ((fl&(1<<9))>0)
  296.   {
  297.     this_printf(5," EMail delete after User\n");
  298.   }
  299.  if ((fl&(1<<10))>0)
  300.   {
  301.     this_printf(5," Mes to Sysop\n");
  302.   }
  303.  if ((fl&(1<<11))>0)
  304.   {
  305.     this_printf(5," Upload to Sysop\n");
  306.   }
  307.  if ((fl&(1<<12))>0)
  308.   {
  309.     this_printf(5," Bulletins on\n");
  310.   }
  311.  if ((fl&(1<<13))>0)
  312.   {
  313.     this_printf(5," Upload nocharge\n");
  314.   }
  315.  this_printf(5,"UL/DL : %d \n",xmbuf.counters[0]);
  316.  this_printf(5,"timeout: %d \n",xmbuf.counters[1]);
  317.  this_printf(5,"F-Mail : %d \n",xmbuf.counters[2]);
  318.  this_printf(5,"FNmsgb : %d \n",xmbuf.counters[3]);
  319.  this_printf(5,"FNreci : %d \n",xmbuf.counters[4]);
  320.  this_printf(5,"Fnum  : %d \n",xmbuf.fnum);
  321. }
  322.  
  323. void main(int argc, char *argv[])
  324. {
  325.  short num = 0;
  326.  FILE *confp;
  327.  char timestring[40];
  328.  time_t tim = time(NULL);
  329.  struct tm *tp;
  330.  
  331.  device = 1;
  332.  if(argc<=1)
  333.   {
  334.     printf("Usage: [local|remote] level function\nCiao\n");
  335.     exit(2);
  336.   }
  337.  check_arg(argc,argv);
  338.  if (device == 2) printf("This is only local.\n\n");
  339.  else printf("This is remote.\n\n");
  340.  
  341.  if(main_function & 2)
  342.   {
  343.    flist=fopen("temp.lst","w");
  344.    if(flist==NULL) exit(-2);
  345.   }
  346.  tp = localtime(&tim);
  347.  strftime(timestring, 40, " %a %d-%b-%Y  %H:%M",tp);
  348.  this_printf(1,"Ee\n");
  349.  this_printf(1,"TurboBoard BBS v2.x File-Lister\n");
  350.  this_printf(2,"\nGenerated by Fil_Lis V. %s on %s\n\n", VERSION,timestring);
  351.  this_printf(1,"V %s  %s\n", VERSION, __DATE__);
  352.  this_printf(1,"\nCopyright by Wolfgang Zweygart.\n");
  353. #if defined(LATTICE)
  354.  this_printf(1,"Compiled with Lattice C5\n");
  355. #elif defined(__PUREC__)
  356.  this_printf(1,"Compiled with Pure C V%x.%02x\n",
  357.         __PUREC__ / 0x100, __PUREC__ & 0xff);
  358. #elif defined(__TURBOC__)
  359.  this_printf(1,"Compiled with Turbo C V%x.%02x\n",
  360.         __TURBOC__ / 0x100, __TURBOC__ & 0xff);
  361. #endif
  362.  this_printf(1,"Call microTalk for support.");
  363.  this_printf(1,"  +49 711 628456");
  364.  this_printf(1,"\n\n");
  365.  
  366.  les_opt();
  367.  Dgetpath(oldpath,0);
  368.  
  369.  sprintf(conf_name,"%c:%s\\%sCONFIG.DAT",Dgetdrv()+'A',oldpath,datas);
  370.  confp = fopen(conf_name,"rb");
  371.  if (confp == 0)
  372.  {
  373.   sprintf(conf_name,"%c:%s\\CONFIG.DAT",Dgetdrv()+'A',oldpath);
  374.   confp = fopen(conf_name,"rb");
  375.  }
  376.  if (confp > 0)
  377.  {
  378.   this_printf(5,"CONFIG-path    %s \n",conf_name);
  379.   fread((char*)&xmbuf,sizeof(xmbuf),1,confp);
  380.     for(num = 0; num < xmbuf.ndirect; num++)
  381.             test_dir((char*)&xmbuf.subdir[num]);
  382.   fclose(confp);
  383.  }
  384.  else this_printf(5,"\n %s nicht gefunden. Abbruch.",conf_name);
  385.  if(main_function & 2) fclose(flist);
  386.  exit(0);
  387. }
  388.