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

  1.  
  2. /*
  3.  *   UUCP.c written by William Loftus
  4.  *   Copyright 1988 by William Loftus.    All rights reserved.
  5.  *
  6.  *  $Header: Beta:src/uucp/src/uucico/RCS/uucp.c,v 1.1 90/02/02 11:56:13 dillon Exp Locker: dillon $
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include "version.h"
  14. #include "config.h"
  15.  
  16. #define VERDATE " 1.02 (26 Sep 90) "
  17.  
  18. static char *version20 = "$VER: uucp" VERDATE "\n\r";
  19. char to_buf[128];
  20. char from_buf[128];
  21. char path[128];
  22. char *user;
  23.  
  24. char command_file[128];
  25. int seq;
  26.  
  27. void BuildReceiveFile();
  28. void BuildSendFile();
  29. void read_ctl();
  30. char *expand_file();
  31. char *strchr();
  32. char *getcwd();
  33.  
  34. #define TRUE 1
  35. #define FALSE 0
  36.  
  37. CXBRK()
  38. {
  39.     return(0);
  40. }
  41.  
  42. void
  43. main(argc,argv)
  44. int argc;
  45. char **argv;
  46. {
  47.     int to_bang, from_bang;
  48.  
  49.     if (argc != 3)
  50.     {
  51.     printf("AmigaUUCP Plus: uucp" VERDATE "\n");
  52.     printf("Written by Ingo Feulner\n\n");
  53.     printf("Usage: UUCP from_file to_file\n");
  54.     exit(1);
  55.     } else {
  56.     strcat(from_buf, argv[1]);
  57.     strcat(to_buf, argv[2]);
  58.     }
  59.  
  60.     getcwd(path,128);
  61.  
  62.     if (chdir(GetConfigDir(UUSPOOL))) {
  63.     printf("Couldn't change current working directory to %s\n", GetConfigDir(UUSPOOL));
  64.     exit(1);
  65.     }
  66.  
  67.     read_ctl();
  68.  
  69.     seq = GetSequence(1);
  70.     if (seq < 0) {
  71.     chdir(path);
  72.     exit(1);
  73.     }
  74.  
  75.     from_bang = (int)strchr(from_buf,'!');
  76.     to_bang = (int)strchr(to_buf,'!');
  77.  
  78.     if (from_bang && to_bang) {
  79.     printf("Can not specify a remote system in both arguments.\n");
  80.     chdir(path);
  81.     exit(1);
  82.     }
  83.  
  84.     if (from_bang) {
  85.     BuildReceiveFile();
  86.     }
  87.  
  88.     if (to_bang) {
  89.     BuildSendFile();
  90.     }
  91.  
  92.     chdir(path);
  93.     exit(0);
  94. }
  95.  
  96. void
  97. BuildSendFile()
  98. {
  99.     FILE *fp;
  100.     char system_name[32];
  101.     int bang;
  102.  
  103.     strcpy(from_buf,expand_file(from_buf));
  104.  
  105.     bang = (int)strchr(to_buf,'!');
  106.     bang = bang - (int)to_buf;
  107.  
  108.     strncpy(system_name,to_buf,bang);
  109.  
  110.     system_name[bang] = '\0';
  111.  
  112.     if (!is_in_L_sys_file(system_name)) {
  113.     printf("System \"%s\" not in L.sys file.\n", system_name);
  114.     chdir(path);
  115.     exit(1);
  116.     }
  117.  
  118.     system_name[7] = '\0';
  119.  
  120.     sprintf(command_file,"C.%.6sA%04lx", system_name, seq);
  121.  
  122.     LockFile(command_file);
  123.  
  124.     fp = fopen(command_file,"w");
  125.  
  126.     if (fp) {
  127.     /* srcnam desnam who flags temp mode who */
  128.     fprintf(fp,"S %s %s %s %s %s %s %s\n",
  129.         from_buf,
  130.         to_buf + bang + 1,
  131.         user,
  132.         "-c",
  133.         from_buf,
  134.         "0666",
  135.         user
  136.     );
  137.     fclose(fp);
  138.     } else {
  139.     UnLockFile(command_file);
  140.     perror(command_file);
  141.     chdir(path);
  142.     exit(1);
  143.     }
  144.     UnLockFile(command_file);
  145.     printf("Command queue for transfer to %s.\n", system_name);
  146. }
  147.  
  148. void
  149. BuildReceiveFile()
  150. {
  151.     FILE *fp;
  152.     char system_name[32];
  153.     int bang;
  154.  
  155.     strcpy(to_buf,expand_file(to_buf));
  156.  
  157.     bang = (int)strchr(from_buf,'!');
  158.     bang = bang - (int)from_buf;
  159.  
  160.     strncpy(system_name,from_buf,bang);
  161.  
  162.     system_name[bang] = '\0';
  163.  
  164.     if (!is_in_L_sys_file(system_name)) {
  165.     printf("System \"%s\" not in L.sys file.\n", system_name);
  166.     chdir(path);
  167.     exit(1);
  168.     }
  169.  
  170.     system_name[7] = '\0';
  171.  
  172.     sprintf(command_file,"C.%.6sA%04lx", system_name, seq);
  173.  
  174.     LockFile(command_file);
  175.  
  176.     fp = fopen(command_file,"w");
  177.     if (fp) {
  178.     /* srcnam desnam who flags */
  179.     fprintf(fp,"R %s %s %s %s\n",
  180.         from_buf + bang + 1,
  181.         to_buf,
  182.         user,
  183.         "-c"
  184.     );
  185.     fclose(fp);
  186.     } else {
  187.     UnLockFile(command_file);
  188.     perror(command_file);
  189.     chdir(path);
  190.     exit(1);
  191.     }
  192.     UnLockFile(command_file);
  193.     printf("Command queue for transfer from %s.\n", system_name);
  194. }
  195.  
  196. static char name[128];
  197.  
  198. char *
  199. expand_file(file_name)
  200. char *file_name;
  201. {
  202.     char *colon;
  203.  
  204.     colon = strchr(file_name,':');
  205.     if ((colon != (char*)NULL) && (colon != file_name)) {
  206.     return(file_name);
  207.     } else {
  208.     if (path[strlen(path)-1] != ':') {
  209.         sprintf(name,"%s/%s",path,file_name);
  210.         return name;
  211.     } else {
  212.         sprintf(name,"%s%s",path,file_name);
  213.         return name;
  214.     }
  215.     }
  216. }
  217.  
  218. #define CTL_DELIM " \t\r\n"
  219.  
  220. /*
  221.  * Read the control file and grab a few parameters.
  222.  */
  223.  
  224. void
  225. read_ctl()
  226. {
  227.     user = FindConfig(USERNAME);
  228. }
  229.