home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / util / mailq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-12  |  1.9 KB  |  126 lines

  1. /*
  2.  *  MAILQ.C
  3.  *
  4.  *  (c) Copyright 1990 Kriton Kyrimis
  5.  *
  6.  *  uunet.uu.net!theseas.ntua.gr!kriton!kyrimis
  7.  */
  8.  
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "config.h"
  13. #include "version.h"
  14.  
  15. #undef NULL
  16. #define NULL 0
  17.  
  18. #include <clib/dos_protos.h>
  19. #include <clib/exec_protos.h>
  20.  
  21. #include <pragmas/dos_pragmas.h>
  22. #include <pragmas/exec_pragmas.h>
  23.  
  24. IDENT (".05");
  25.  
  26. BPTR
  27.     lk = NULL;
  28. struct FileInfoBlock
  29.     *fb = NULL;
  30.  
  31. void whereto (char *, const int);
  32.  
  33. void
  34. cleanup (void)
  35. {
  36.     if (lk) {
  37.         UnLock (lk);
  38.         lk = NULL;
  39.     }
  40.     if (fb) {
  41.         FreeMem (fb, sizeof (struct FileInfoBlock));
  42.         fb = NULL;
  43.     }
  44.  
  45.     return;
  46. }
  47.  
  48. int
  49. main (int ac, char **av)
  50. {
  51.     int
  52.         end;
  53.  
  54.  
  55.     atexit (cleanup);
  56.  
  57.     fb = (struct FileInfoBlock *) AllocMem (sizeof (struct FileInfoBlock), MEMF_ANY);
  58.     if (!fb) {
  59.         fprintf (stderr, "Can't allocate memory for file info block\n");
  60.         exit (20);
  61.     }
  62.  
  63.     lk = Lock ((UBYTE *) GetConfigDir (UUSPOOL), ACCESS_READ);
  64.     if (!lk) {
  65.         fprintf (stderr, "Can't lock %s\n", GetConfigDir (UUSPOOL));
  66.         exit (20);
  67.     }
  68.  
  69.     if (!Examine (lk, fb)) {
  70.         fprintf (stderr, "Can't examine %s\n", GetConfigDir (UUSPOOL));
  71.         exit (20);
  72.     }
  73.  
  74. #define fname fb->fib_FileName
  75.  
  76.     while (ExNext (lk, fb)) {
  77.         if (CheckSignal (SIGBREAKF_CTRL_C))
  78.             break;
  79.  
  80.         if (fb->fib_DirEntryType < 0) {
  81.             if ((fname [0] != 'D') || (fname [1] != '.')) {
  82.                 continue;
  83.             }
  84.  
  85.             end = strlen (fname) - 5;
  86.             if (fname [end] != 'X') {
  87.                 continue;
  88.             }
  89.  
  90.             whereto (fname, end);
  91.         }
  92.     }
  93.  
  94. #undef fname
  95.  
  96.     exit (0);
  97. }
  98.  
  99. void
  100. whereto (char *fname, const int end)
  101. {
  102.     char
  103.         *path,
  104.         tmp [132];
  105.     FILE
  106.         *f;
  107.  
  108.     path = MakeConfigPath (UUSPOOL, fname);
  109.     f = fopen (path, "r");
  110.     if (!f) {
  111.         fprintf (stderr, "Can't open %s\n", tmp);
  112.         return;
  113.     }
  114.  
  115.     while (fgets (tmp, sizeof (tmp), f)) {
  116.         if (strncmp (tmp, "C rmail ", 8) == NULL) {
  117.             fname [end] = '\0';
  118.             printf ("%s %s!%s", path, &fname [2], &tmp [8]);
  119.             break;
  120.         }
  121.     }
  122.     fclose (f);
  123.  
  124.     return;
  125. }
  126.