home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / uucico / uuxqt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  2.8 KB  |  157 lines

  1.  
  2. /*
  3.  *  UUXQT.C by William Loftus
  4.  *  Copyright 1988 by William Loftus.    All rights reserved.
  5.  *  Changes Copyright 1990 by Matthew Dillon, All Rights Reserved
  6.  *
  7.  *  $Header: Beta:src/uucp/src/uucico/RCS/uuxqt.c,v 1.1 90/02/02 11:55:58 dillon Exp Locker: dillon $
  8.  *
  9.  *  3.7.90 Ingo Feulner: Added sorting.
  10.  * 23.8.90 Ingo Feulner: Changed command systax for sendmail.
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "version.h"
  16. #include "log.h"
  17.  
  18. static char *version20 = "$VER: uuxqt 1.06 (23 Aug 90)\n\r";
  19.  
  20. static char names[MAXFILES*16];
  21. static char *pointers[MAXFILES];
  22. static int file_pointer;
  23. static int error;
  24. static char *xfile;
  25. static char dfile[128];
  26. static char cmd[1024];
  27. static char ccmd[128];
  28. static char ccmd_args[128];
  29. static char buf[128];
  30. static char path[256];
  31.  
  32. #define DELIM " \t\n\r"
  33.  
  34. int
  35. brk()
  36. {
  37.     return(0);
  38. }
  39.  
  40. char *
  41. work_scan()
  42. {
  43.     static char name[128];
  44.     int count;
  45.  
  46.     file_pointer = 0;
  47.  
  48.     strcpy(name, MakeConfigPath(UUSPOOL, "X.#?"));
  49.  
  50.     count = getfnl(name, names, sizeof(names), 0);
  51.  
  52.     if (count > 0)
  53.     {
  54.     ulog(-1, "New files have arrived.");
  55.  
  56.     if (strbpl(pointers,MAXFILES,names) != count)
  57.         {
  58.         ulog(-1, "Too many execute files\n");
  59.         return (char *)NULL;
  60.     }
  61.         else
  62.         {
  63.           tqsort(pointers, count);
  64.         }
  65.     }
  66.     else
  67.     {
  68.     return (char *)NULL;
  69.     }
  70.     return (char *)1;
  71. }
  72.  
  73. char *
  74. work_next()
  75. {
  76.     return pointers[file_pointer++];
  77. }
  78.  
  79. parse(x)
  80. char *x;
  81. {
  82.     FILE *fp;
  83.     char *tmp;
  84.  
  85.     fp = fopen(x, "r");
  86.     if (fp == (char *)NULL)
  87.     {
  88.     ulog(-1, "Can't open file %s\n",x);
  89.     chdir(path);
  90.     return(0);
  91.     }
  92.     while (fgets(buf, sizeof buf, fp))
  93.     {
  94.     if (strncmp(buf, "F", 1) == 0)
  95.         strcpy(dfile, strtok(&buf[1],DELIM));
  96.     else if (strncmp(buf, "C", 1) == 0)
  97.         strcpy(ccmd, strtok(&buf[1],DELIM));
  98.     strcpy(ccmd_args, strtok(NULL, DELIM));
  99.     while ((tmp = (char *)strtok(NULL, DELIM)) != NULL)
  100.     {
  101.          strcat(ccmd_args, " ");
  102.          strcat(ccmd_args, tmp);
  103.     }
  104.     }
  105.  
  106.     if (strncmp(ccmd, "rmail", 5) == 0)
  107.     {
  108.     sprintf(cmd,"sendmail <%s -r %s", dfile, ccmd_args);
  109.         ulog(-1, "Executing rmail");
  110.     }
  111.     else if (strncmp(ccmd, "rnews", 5) == 0)
  112.     {
  113.     sprintf(cmd,"rnews <%s", dfile);
  114.         ulog(-1, "Executing rnews");
  115.     }
  116.     else
  117.     {
  118.     ulog(-1, "Unknown command request %s  - Operation Aborted -\n", ccmd);
  119.     error = 1;
  120.     }
  121.     fclose(fp);
  122.     return(1);
  123. }
  124.  
  125.  
  126. void main()
  127. {
  128.     LogProgram = "uuxqt";
  129.     onbreak(brk);
  130.  
  131.     getcwd(path, sizeof(path));
  132.     chdir(GetConfigDir(UUSPOOL));
  133.     LockFile("UUXQT");
  134.  
  135.     if (work_scan() != (char *)NULL)
  136.     {
  137.     while ((xfile = work_next()) != (char *)NULL)
  138.         {
  139.         LockFile(xfile);
  140.         if (parse(xfile))
  141.         {
  142.         int syserr;
  143.  
  144.         syserr = system(cmd);
  145.         if (syserr == 0 && error != 1)
  146.                 {
  147.             remove(xfile);
  148.             remove(dfile);
  149.         }
  150.         }
  151.         UnLockFile(xfile);
  152.     }
  153.     }
  154.     UnLockFile("UUXQT");
  155.     chdir(path);
  156. }
  157.