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

  1.  
  2. /*
  3.  *  UUX.C
  4.  *
  5.  *  $Header: Beta:src/uucp/src/uucico/RCS/uux.c,v 1.1 90/02/02 11:56:20 dillon Exp Locker: dillon $
  6.  *
  7.  *  Copyright 1988 by William Loftus.    All rights reserved.
  8.  *
  9.  *  Example: 1> uux mail-message "burdvax!rmail wpl"
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "version.h"
  16.  
  17. #define  VERDATE  " 1.06 (18 Sep 90) "
  18.  
  19. static char *version20 = "$VER: uux" VERDATE "\n\r";
  20.  
  21. char user[128];
  22. char file_name[128];
  23. char command[128];
  24.  
  25. char exec_file[128];
  26. char x_exec_file[128];
  27. char command_file[128];
  28. char data_file[128];
  29. int seq;
  30.  
  31. char path[128];
  32.  
  33. void GetTo();
  34. void GetSubject();
  35.  
  36. #define TRUE 1
  37. #define FALSE 0
  38.  
  39. int
  40. brk()
  41. {
  42.     return(0);
  43. }
  44.  
  45. void
  46. main(argc, argv)
  47. int argc;
  48. char **argv;
  49. {
  50.     int error;
  51.     char *up = FindConfig(USERNAME);
  52.  
  53.     onbreak(brk);
  54.     if (up == NULL) {
  55.     printf("couldn't find config entry for %s\n", USERNAME);
  56.     exit(1);
  57.     }
  58.     strcpy(user, up);
  59.  
  60.     getcwd(path,128);
  61.     chdir(GetConfigDir(UUSPOOL));
  62.     if (argc == 3) {
  63.     strcpy(file_name, argv[1]);
  64.     strcpy(command, argv[2]);
  65.     }
  66.     else
  67.     {
  68.     printf("AmigaUUCP Plus: uux" VERDATE "\n");
  69.     printf("Written by Ingo Feulner\n\n");
  70.     printf("Usage: uux file-name command\n");
  71.     printf("Example: 1> uux mail-message \"burdvax!rmail wpl\"\n");
  72.     chdir(path);
  73.     exit(1);
  74.     }
  75.     seq = GetSequence(1);
  76.     if (seq >= 0)
  77.     error = Queue();
  78.     UnLockFile(exec_file);
  79.     UnLockFile(x_exec_file);
  80.     UnLockFile(command_file);
  81.     UnLockFile(data_file);
  82.     chdir(path);
  83.     if (seq < 0 || error < 0)
  84.     exit(1);
  85. }
  86.  
  87. Queue()
  88. {
  89.     FILE *fp;
  90.     char system_name[32];
  91.     int bang;
  92.     int error;
  93.     int rnews = 0; /* -IF- */
  94.  
  95.     bang = (int)strchr(command,'!');
  96.     bang = bang - (int)command;
  97.  
  98.     strncpy(system_name,command,bang);
  99.  
  100.     system_name[bang] = '\0';
  101.  
  102.     if (!is_in_L_sys_file(system_name)) {
  103.     printf ("System \"%s\" not in L.sys file.\n", system_name);
  104.     return(-1);
  105.     }
  106.  
  107.     system_name[7] = '\0';
  108.  
  109.     /* Will we build a rnews command? -IF- */
  110.     if((strcmp(((char *)command + bang + 1), "rnews")) == 0)
  111.       rnews = 1; /* Yes! */
  112.  
  113.     sprintf(exec_file,   "D.%.6sX%04lx", system_name, seq);
  114.     sprintf(x_exec_file, "X.%.6sX%04lx", system_name, seq);
  115.     sprintf(command_file,"C.%.6sA%04lx", system_name, seq);
  116.     sprintf(data_file,   "D.%.6sB%04lx", system_name, seq);
  117.  
  118.     LockFile(exec_file);
  119.     LockFile(x_exec_file);
  120.     LockFile(command_file);
  121.     LockFile(data_file);
  122.  
  123.     fp = fopen(exec_file,"w");
  124.     if(fp)
  125.     {
  126.         fprintf(fp,"U %s %s\n", (rnews == 0) ? user : "news",
  127.                                  FindConfig(NODENAME));
  128.       fprintf(fp,"F %s\n", data_file);
  129.     fprintf(fp,"I %s\n", data_file);
  130.     fprintf(fp,"C %s\n", (char *)command + bang + 1);
  131.     fclose(fp);
  132.     }
  133.     else
  134.     {
  135.     perror(exec_file);
  136.     return(-1);
  137.     }
  138.  
  139.     fp = fopen(command_file,"w");
  140.     if (fp) {
  141.     fprintf(fp,"S %s %s %s - %s 0666\n",
  142.         data_file,
  143.         data_file,
  144.         (rnews == 0) ? user : "news", /* -IF- */
  145.         data_file
  146.     );
  147.     fprintf(fp,"S %s %s %s - %s 0666\n",
  148.         exec_file,
  149.         x_exec_file,
  150.         (rnews == 0) ? user : "news", /* -IF- */
  151.         exec_file
  152.     );
  153.     fclose(fp);
  154.     } else {
  155.     perror(command_file);
  156.     return(-1);
  157.     }
  158.     chdir(path);
  159.     error = Copy(file_name, data_file);
  160.     chdir(GetConfigDir(UUSPOOL));
  161.     return(error);
  162. }
  163.  
  164. /*
  165.  * Read the control file and grab a few parameters.
  166.  */
  167.  
  168. Copy(from, to)
  169. char *from;
  170. char *to;
  171. {
  172.     FILE *fd;
  173.     FILE *td;
  174.     int c;
  175.     static char to_buf[128];
  176.  
  177.     fd = fopen(from, "r");
  178.     if (!fd) {
  179.     printf("Could not open %s.\n", from);
  180.     perror(from);
  181.     return(-1);
  182.     }
  183.  
  184.     strcpy(to_buf, MakeConfigPath(UUSPOOL, to));
  185.  
  186.     td = fopen(to_buf, "w");
  187.     if (!td) {
  188.     printf("Could not open %s.\n", to_buf);
  189.     perror(to);
  190.     return(-1);
  191.     }
  192.     while ((c = fgetc(fd)) != EOF) {
  193.     fputc((char)c, td);
  194.     }
  195.     fclose(fd);
  196.     fclose(td);
  197.     return(1);
  198. }
  199.