home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / uucp_mods.lha.30.12.93 / uucp_mods / uucico / mailq.c next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  3.2 KB  |  137 lines

  1.  
  2. /*
  3.  *  MAILQ.C
  4.  *
  5.  *  (c) Copyright 1990 Kriton Kyrimis
  6.  *  uunet.uu.net!theseas.ntua.gr!kriton!kyrimis
  7.  *
  8.  *  Hierarchical Spool Conversion 1 Dec 93,
  9.  *                    Mike J.Bruins     bruins@hal9000.apana.org.au
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <ctype.h>
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17. #include <libraries/dos.h>
  18. #include "config.h"
  19. #include "version.h"
  20. #ifdef LATTICE
  21. #include <proto/dos.h>
  22. #include <proto/exec.h>
  23. #endif
  24.  
  25. IDENT(".03");
  26.  
  27. main(int argc,char **argv){
  28. /* find the system directories in the spool */
  29.  
  30.   BPTR lk;
  31.   struct FileInfoBlock *fb = 0;
  32.   char path[256], datadir[256];
  33.   int i;
  34.   void ReadSystemD(char *path,char *sys);
  35.  
  36.   if (argc<1)                                               /* Workbench */
  37.     exit(0);
  38.   if (argc==1){
  39.     fb = (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock), 0);
  40.     if (!fb) {
  41.       fprintf(stderr, "Can't allocate memory for file info block\n");
  42.       exit(1);
  43.     }
  44.     strcpy(path,GetConfigDir(UUSPOOL));
  45.     lk = Lock(path, ACCESS_READ);
  46.   
  47.     if (!lk) {
  48.       fprintf(stderr, "Can't lock %s\n", path);
  49.       FreeMem(fb, sizeof(struct FileInfoBlock));
  50.       exit(1);
  51.     }
  52.  
  53.     if (!Examine(lk, fb)) {
  54.       fprintf(stderr, "Can't examine %s\n", path);
  55.       FreeMem(fb, sizeof(struct FileInfoBlock));
  56.       UnLock(lk);
  57.       exit(1);
  58.     }
  59.  
  60.     while (ExNext(lk, fb)) {             /* step through directory */
  61.       if (fb->fib_DirEntryType > 0) {  /* is a directory */
  62.         if(is_in_L_sys_file(fb->fib_FileName)){
  63.           sprintf(datadir,"%s%s",path, fb->fib_FileName);
  64.           ReadSystemD(datadir, fb->fib_FileName);
  65.         }
  66.       }
  67.     }
  68.  
  69.     FreeMem(fb, sizeof(struct FileInfoBlock));
  70.     UnLock(lk);
  71.   }else{
  72.     strcpy(path,GetConfigDir(UUSPOOL));
  73.     for(i=0;i<argc;i++)
  74.       if(is_in_L_sys_file(argv[i])){
  75.         sprintf(datadir,"%s%s",path, argv[i]);
  76.         ReadSystemD(datadir, argv[i]);
  77.       }
  78.   }
  79.   exit(0);
  80. }
  81.  
  82. void ReadSystemD(char *path, char *sys){
  83. /* read a data directory of a system and feed to whereto() */
  84.   BPTR lk;
  85.   char datadir[256];
  86.   struct FileInfoBlock *fb = 0;
  87.   void whereto(char *sys, char *file);
  88.  
  89.   fb = (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock), 0);
  90.   if (!fb) {
  91.     fprintf(stderr, "Can't allocate memory for file info block\n");
  92.     return;
  93.   }
  94.   lk = Lock(path, ACCESS_READ);
  95.   if (!lk) {
  96.     fprintf(stderr, "Can't lock %s\n", path);
  97.     FreeMem(fb, sizeof(struct FileInfoBlock));
  98.     return;
  99.   }
  100.   if (!Examine(lk, fb)) {
  101.     fprintf(stderr, "Can't examine %s\n", path);
  102.     FreeMem(fb, sizeof(struct FileInfoBlock));
  103.     UnLock(lk);
  104.     return;
  105.   }
  106.  
  107.   while (ExNext(lk, fb)) {            /* step through directory */
  108.     if (fb->fib_DirEntryType < 0) {  /* not a directory */
  109.       sprintf(datadir,"%s/%s",path,fb->fib_FileName);
  110.       whereto(datadir, sys);
  111.     }
  112.   }
  113.  
  114.   FreeMem(fb, sizeof(struct FileInfoBlock));
  115.   UnLock(lk);
  116. }
  117.  
  118. void whereto(char *path, char *sys){
  119. /* print the system name and where the mail is going to */
  120.   char tmp[132];
  121.   FILE *f;
  122.  
  123.   f = fopen(path, "r");
  124.   if (!f) {
  125.     fprintf(stderr, "Can't open %s\n", tmp);
  126.     return;
  127.   }
  128.   while (fgets(tmp, sizeof(tmp), f)) {
  129.     if (!strncmp(tmp, "C rmail ", 8)) {
  130.       printf("%s %s!%s", path, sys, &tmp[8]);
  131.       break;
  132.     }
  133.   }
  134.   fclose(f);
  135.   return;
  136. }
  137.