home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / uucico / uuxqt.c.old < prev    next >
Encoding:
Text File  |  1990-11-21  |  2.6 KB  |  133 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.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "version.h"
  13.  
  14. IDENT(".03");
  15.  
  16. static char names[MAXFILES*16];
  17. static char *pointers[MAXFILES];
  18. static int file_pointer;
  19. static int error;
  20. static char *xfile;
  21. static char dfile[128];
  22. static char cmd[1024];
  23. static char ccmd[128];
  24. static char ccmd_args[128];
  25. static char buf[128];
  26. static char path[256];
  27.  
  28. #define DELIM " \t\n\r"
  29.  
  30. int
  31. brk()
  32. {
  33.     return(0);
  34. }
  35.  
  36. char *
  37. work_scan()
  38. {
  39.     static char name[128];
  40.     int count;
  41.  
  42.     file_pointer = 0;
  43.  
  44.     strcpy(name, MakeConfigPath(UUSPOOL, "X.#?"));
  45.  
  46.     count = getfnl(name,names,sizeof(names),0);
  47.  
  48.     if (count > 0) {
  49.     printf("New files have arrived.\n");
  50.  
  51.     if (strbpl(pointers,MAXFILES,names) != count) {
  52.         printf("Too many execute files\n");
  53.         return (char *)NULL;
  54.     }
  55.     } else {
  56.     return (char *)NULL;
  57.     }
  58.     return (char *)1;
  59. }
  60.  
  61. char *
  62. work_next()
  63. {
  64.     return pointers[file_pointer++];
  65. }
  66.  
  67. parse(x)
  68. char *x;
  69. {
  70.     FILE *fp;
  71.     char *tmp;
  72.  
  73.     fp = fopen(x, "r");
  74.     if (fp == (char *)NULL) {
  75.     printf("Can't open file %s\n",x);
  76.     chdir(path);
  77.     return(0);
  78.     }
  79.     while (fgets(buf, sizeof buf, fp)) {
  80.     if (strncmp(buf, "F", 1) == 0)
  81.         strcpy(dfile, strtok(&buf[1],DELIM));
  82.     else if (strncmp(buf, "C", 1) == 0)
  83.         strcpy(ccmd, strtok(&buf[1],DELIM));
  84.     strcpy(ccmd_args, strtok(NULL, DELIM));
  85.     while ((tmp = (char *)strtok(NULL, DELIM)) != NULL) {
  86.          strcat(ccmd_args, " ");
  87.          strcat(ccmd_args, tmp);
  88.     }
  89.     }
  90.  
  91.     if (strncmp(ccmd, "rmail", 5) == 0) {
  92.     sprintf(cmd,"%s < %s %s", GetConfigProgram(RMAIL), dfile, ccmd_args);
  93.     } else if (strncmp(ccmd, "cunbatch", 5) == 0) {
  94.     sprintf(cmd,"%s < %s %s", GetConfigProgram(CUNBATCH), dfile, ccmd_args);
  95.     } else if (strncmp(ccmd, "rnews", 5) == 0) {
  96.     sprintf(cmd,"%s < %s %s", GetConfigProgram(RNEWS), dfile, "UseNet");
  97.     } else {
  98.     printf("Unknown command request %s  - Operation Aborted -\n", ccmd);
  99.     error = 1;
  100.     }
  101.     fclose(fp);
  102.     return(1);
  103. }
  104.  
  105.  
  106. void
  107. main()
  108. {
  109.     onbreak(brk);
  110.  
  111.     getcwd(path,sizeof(path));
  112.     chdir(GetConfigDir(UUSPOOL));
  113.     LockFile("UUXQT");
  114.     if (work_scan() != (char *)NULL) {
  115.     while ((xfile = work_next()) != (char *)NULL) {
  116.         LockFile(xfile);
  117.         if (parse(xfile)) {
  118.         int syserr;
  119.  
  120.         syserr = system(cmd);
  121.         if (syserr == 0 && error != 1) {
  122.             remove(xfile);
  123.             remove(dfile);
  124.         }
  125.         }
  126.         UnLockFile(xfile);
  127.     }
  128.     }
  129.     UnLockFile("UUXQT");
  130.     chdir(path);
  131. }
  132.  
  133.