home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES3.ZIP / UUCP / uucp.c next >
Encoding:
C/C++ Source or Header  |  1993-10-31  |  29.9 KB  |  765 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u c p . c                                                     */
  3. /*                                                                    */
  4. /*    UUCP lookalike for IBM PC.                                      */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: uucp.c 1.13 1993/10/31 22:07:05 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: uucp.c $
  24.  * Revision 1.13  1993/10/31  22:07:05  ahd
  25.  * Issue messages if opens during copies fail
  26.  * Don't close directory after copy failure if never open
  27.  * Automatically build spool data directory as required
  28.  *
  29.  * Revision 1.12  1993/10/30  17:19:50  rhg
  30.  * Additional clean-up for UUX support
  31.  *
  32.  * Revision 1.12  1993/10/30  17:19:50  rhg
  33.  * Additional clean-up for UUX support
  34.  *
  35.  * Revision 1.11  1993/10/25  01:21:22  ahd
  36.  * Force directory for destination when input is wildcarded
  37.  *
  38.  * Revision 1.10  1993/10/12  01:34:47  ahd
  39.  * Normalize comments to PL/I style
  40.  *
  41.  * Revision 1.9  1993/10/03  20:43:08  ahd
  42.  * Normalize comments to C++ double slash
  43.  *
  44.  * Revision 1.8  1993/10/02  19:07:49  ahd
  45.  * Use 0644 permissions on files
  46.  *
  47.  * Revision 1.7  1993/09/20  04:48:25  ahd
  48.  * TCP/IP support from Dave Watt
  49.  * 't' protocol support
  50.  * OS/2 2.x support (BC++ 1.0 for OS/2)
  51.  *
  52.  * Revision 1.6  1993/08/02  03:24:59  ahd
  53.  * Further changes in support of Robert Denny's Windows 3.x support
  54.  *
  55.  * Revision 1.5  1993/07/31  16:27:49  ahd
  56.  * Changes in support of Robert Denny's Windows support
  57.  *
  58.  * Revision 1.4  1993/04/11  00:35:46  ahd
  59.  * Global edits for year, TEXT, etc.
  60.  *
  61.  * Revision 1.3  1993/04/05  04:35:40  ahd
  62.  * Use timestamp/file size information returned by directory search
  63.  *
  64.  * Revision 1.2  1992/12/11  12:45:11  ahd
  65.  * Normalize paths for files read
  66.  *
  67.  */
  68.  
  69. /*--------------------------------------------------------------------*/
  70. /*                                                                    */
  71. /*    Change history:                                                 */
  72. /*                                                                    */
  73. /*       02/08/81 H.A.E.Broomhall                                     */
  74. /*                Hacked for UUPC/extended 1.09c                      */
  75. /*       04/27/91 Drew Derbyshire                                     */
  76. /*                Modified for UUPC/extended 1.10a                    */
  77. /*       09/26/91 Mitch Mitchell                                      */
  78. /*                Support for UUX                                     */
  79. /*       01/26/92 Drew Derbyshire                                     */
  80. /*                Various comment and error message clean up          */
  81. /*--------------------------------------------------------------------*/
  82.  
  83. /*--------------------------------------------------------------------*/
  84. /*                        system include files                        */
  85. /*--------------------------------------------------------------------*/
  86.  
  87. #include  <ctype.h>
  88. #include  <direct.h>
  89. #include  <fcntl.h>
  90. #include  <io.h>
  91. #include  <stdio.h>
  92. #include  <stdlib.h>
  93. #include  <string.h>
  94. #include  <sys/types.h>
  95. #include  <sys/stat.h>
  96.  
  97. #ifdef _Windows
  98. #include <windows.h>
  99. #endif
  100.  
  101. /*--------------------------------------------------------------------*/
  102. /*                    UUPC/extended include files                     */
  103. /*--------------------------------------------------------------------*/
  104.  
  105. #include  "lib.h"
  106. #include  "expath.h"
  107. #include  "getopt.h"
  108. #include  "getseq.h"
  109. #include  "hlib.h"
  110. #include  "hostable.h"
  111. #include  "import.h"
  112. #include  "uundir.h"
  113. #include  "security.h"
  114. #include  "timestmp.h"
  115. #include  "execute.h"
  116.  
  117. #ifdef _Windows
  118. #include "winutil.h"
  119. #include "logger.h"
  120. #endif
  121.  
  122. /*--------------------------------------------------------------------*/
  123. /*                          Global variables                          */
  124. /*--------------------------------------------------------------------*/
  125.  
  126. static boolean       spool_flag = FALSE;
  127. static char          spool_file[FILENAME_MAX] = ""; /* alt spool file name */
  128. static boolean       dir_flag = TRUE;
  129. static boolean       xeqt_flag = TRUE;    /* Triggered by -r option   */
  130. static boolean       j_flag = FALSE;      /* set by -j option */
  131. static char          grade = 'n';         /* Default grade of service  */
  132. static boolean       mail_me = FALSE;     /* changes with -m           */
  133. static boolean       mail_them = FALSE;   /* changes with -n           */
  134. static char  remote_user[10];             /* user to mail with -n     */
  135.  
  136. static char  flags[16];
  137.  
  138. currentfile();
  139.  
  140. /*--------------------------------------------------------------------*/
  141. /*                          Local prototypes                          */
  142. /*--------------------------------------------------------------------*/
  143.  
  144. static void appendSlash( char *s );
  145.  
  146. /*--------------------------------------------------------------------*/
  147. /*    u s a g e                                                       */
  148. /*                                                                    */
  149. /*    Report flags used by program                                    */
  150. /*--------------------------------------------------------------------*/
  151.  
  152. static void usage(void)
  153. {
  154.    fprintf(stderr, "Usage: uucp\t[-c|-C] [-d|-f] [-gGRADE] [-j]"
  155.                    "[-m] [-nUSER] [-r] [-sFILE]\\\n"
  156.                    "\t\t[-xDEBUG_LEVEL] source-files destination-file\n");
  157. } /* usage */
  158.  
  159. /*--------------------------------------------------------------------*/
  160. /*    c p                                                             */
  161. /*                                                                    */
  162. /*    Copy a file                                                     */
  163. /*--------------------------------------------------------------------*/
  164.  
  165. static int cp(char *from, char *to)
  166. {
  167.       int         fd_from, fd_to;
  168.       int         nr, nw = -1;
  169.       char        buf[BUFSIZ*4]; /* faster if we alloc a big buffer   */
  170.  
  171.       if ((fd_from = open(from, O_RDONLY | O_BINARY)) == -1)
  172.       {
  173.          printerr(from);
  174.          return(1);        /* failed                                   */
  175.       }
  176.       /* what if the to is a directory? */
  177.       /* possible with local source & dest uucp */
  178.       if ((fd_to = open(to, O_CREAT | O_BINARY | O_WRONLY, S_IWRITE | S_IREAD)) == -1)
  179.       {
  180.          printerr(to);
  181.          close(fd_from);
  182.          return(1);        /* failed                                   */
  183.          /* NOTE - this assumes all the required directories exist!  */
  184.       }
  185.       while  ((nr = read(fd_from, buf, sizeof buf)) > 0 &&
  186.          (nw = write(fd_to, buf, nr)) == nr)
  187.          ;
  188.       close(fd_to);
  189.       close(fd_from);
  190.       if (nr != 0 || nw == -1)
  191.          return(1);        /* failed in copy                          */
  192.       return(0);
  193.  
  194. } /* cp */
  195.  
  196. /*--------------------------------------------------------------------*/
  197. /*    s p l i t _ p a t h                                             */
  198. /*                                                                    */
  199. /*    split_path splits a path into 3 components.                     */
  200. /*    1)  The system next in line                                     */
  201. /*    2)  Any intermediate systems as a bang path                     */
  202. /*    3)  The actual file name/path                                   */
  203. /*                                                                    */
  204. /*    It tries to be a little clever with idiots, in recognizing      */
  205. /*    system=this machine                                             */
  206. /*--------------------------------------------------------------------*/
  207.  
  208. static         void    split_path(char *path,
  209.                                   char *system,
  210.                                   char *inter,
  211.                                   char *file)
  212. {
  213.       char    *p_left, *p_right, *p;
  214.  
  215.       *system = *inter = *file = '\0';    /* init to nothing           */
  216.       for (p = path;; p = p_left + 1)  {
  217.          p_left = strchr(p, '!');         /* look for the first bang  */
  218.          if (p_left == NULL)  {           /* not a remote path        */
  219.             strcpy(file, p);              /* so just return filename  */
  220.             return;
  221.          }
  222.          /* now check if the system was in fact us.
  223.        If so strip it and restart */
  224.          if (equaln(E_nodename, p, p_left - p) &&
  225.             (E_nodename[p_left - p] == '\0'))
  226.             continue;
  227.  
  228.          p_right = strrchr(p, '!');      /* look for the last bang     */
  229.          strcpy(file, p_right + 1);      /* and thats our filename     */
  230.          strncpy(system, p, p_left - p); /* and we have a system thats not us  */
  231.          system[p_left - p] = '\0';
  232.          /* now see if there is an intermediate path */
  233.          if (p_left != p_right)  {        /* yup - there is           */
  234.             strncpy(inter, p_left + 1, p_right - p_left - 1);
  235.             inter[p_right - p_left - 1] = '\0';
  236.          }
  237.          return;                 /* and we're done                    */
  238.       }        /* never get here :-)  */
  239.  
  240. } /* split_path */
  241.  
  242. /*--------------------------------------------------------------------*/
  243. /*    d o _ u u x                                                     */
  244. /*                                                                    */
  245. /*    Generate & execute UUX command                                  */
  246. /*--------------------------------------------------------------------*/
  247.  
  248. int   do_uux(char *remote,
  249.              char *src_syst,
  250.              char *src_file,
  251.              char *dest_syst,
  252.              char *dest_inter,
  253.              char *dest_file)
  254. {
  255.       char        xcmd[BUFSIZ];        /* buffer for assembling the UUX command  */
  256.       int         len;
  257.  
  258. /*--------------------------------------------------------------------*/
  259. /*                 First - lets get the basic command                 */
  260. /*--------------------------------------------------------------------*/
  261.  
  262.       len = sprintf(xcmd, "-x%d -g%c -%c%s%s%s%s %s!uucp -C%s%s%s ",
  263.                           debuglevel, grade,
  264.                           spool_flag ? 'C' : 'c',
  265.                           xeqt_flag ? "" : " -r",
  266.                           j_flag ? " -j" : "",
  267.                           *spool_file ? " -s" : "",
  268.                           *spool_file ? spool_file : "",
  269.                           remote,
  270.                           dir_flag ? "" : " -f",
  271.                           mail_them ? " -n" : "",
  272.                           mail_them ? remote_user : "");
  273.                               /* but what about mailing the guy (-m)? */
  274.  
  275. /*--------------------------------------------------------------------*/
  276. /*                  Now we sort out the source name                   */
  277. /*--------------------------------------------------------------------*/
  278.  
  279.       if ((*src_syst == '\0') || equal(src_syst, E_nodename))
  280.          len += sprintf(xcmd + len, " !%s ", src_file);
  281.       else  {
  282.          if (!equal(remote, src_syst))
  283.             len += sprintf(xcmd + len, " (%s!%s) ", src_syst, src_file);
  284.          else
  285.             len += sprintf(xcmd + len, " (%s) ", src_file);
  286.       } /* else */
  287.  
  288. /*--------------------------------------------------------------------*/
  289. /*                   Now to do the destination name                   */
  290. /*--------------------------------------------------------------------*/
  291.  
  292.       if (*dest_inter != '\0')  {
  293.          if (*dest_syst != '\0')
  294.             len += sprintf(xcmd + len, " (%s!%s!%s) ", dest_syst, dest_inter, dest_file);
  295.          else
  296.             len += sprintf(xcmd + len, " (%s!%s) ", dest_inter, dest_file);
  297.       }
  298.       else  {
  299.          if ((*dest_syst == '\0') || equal(dest_syst, E_nodename))
  300.             len += sprintf(xcmd + len, " (%s!%s) ", E_nodename, dest_file);
  301.       }
  302.       printmsg(2, "xcmd: %s", xcmd);
  303.  
  304. /*--------------------------------------------------------------------*/
  305. /*                              OK - GO!                              */
  306. /*--------------------------------------------------------------------*/
  307.  
  308.    execute("uux", xcmd, NULL, NULL, TRUE, FALSE);
  309.  
  310.    return(1);
  311.  
  312. } /* do_uux */
  313.  
  314. /*--------------------------------------------------------------------*/
  315. /*    d o _ c o p y                                                   */
  316. /*                                                                    */
  317. /*    At this point only one of the systems can be remote and only    */
  318. /*    1 hop away.  All the rest have been filtered out                */
  319. /*--------------------------------------------------------------------*/
  320.  
  321. int   do_copy(char *src_syst,
  322.               char *src_file,
  323.               char *dest_syst,
  324.               char *dest_file)
  325. {
  326.       char        *p;
  327.       boolean wild_flag = FALSE;
  328.       boolean write_flag;
  329.       char        tmfile[15];       /* Unix style name for c file     */
  330.       char        idfile[15];       /* Unix style name for data file copy  */
  331.       char        work[FILENAME_MAX];   /* temp area for filename hacking  */
  332.       char        search_file[FILENAME_MAX];
  333.       char        source_path[FILENAME_MAX];
  334.       char        icfilename[FILENAME_MAX]; /* our hacked c file path  */
  335.       char        idfilename[FILENAME_MAX]; /* our hacked d file path  */
  336.  
  337.       struct  stat    statbuf;
  338.       DIR *dirp = NULL;
  339.       struct direct *dp = NULL;
  340.       char subseq = 'A';
  341.       boolean makeDirectory = TRUE;    /* May need to build spool dir  */
  342.  
  343.       long    int     sequence;
  344.       char    *remote_syst;   /* Non-local system in copy              */
  345.       char    *sequence_s;
  346.       FILE        *cfile;
  347.       static  char    *spool_fmt = SPOOLFMT;
  348.  
  349.       sequence = getseq();
  350.       sequence_s = JobNumber( sequence );
  351.       remote_syst =  equal(src_syst, E_nodename) ? dest_syst : src_syst;
  352.       sprintf(tmfile, spool_fmt, 'C', remote_syst, grade, sequence_s);
  353.       importpath(work, tmfile, remote_syst);
  354.       mkfilename(icfilename, E_spooldir, work);
  355.  
  356.       if (!equal(src_syst, E_nodename))
  357.       {
  358.          if (expand_path(dest_file, NULL, E_homedir, NULL) == NULL)
  359.             exit(1);
  360.          strcpy( dest_file, normalize( dest_file ));
  361.          p  = src_file;
  362.          while (*p)
  363.          {
  364.             if (*p ==  '\\')
  365.                *p = '/';
  366.             p++;
  367.          }
  368.          printmsg(1, "uucp - from \"%s\" - control = %s", src_syst,
  369.                   tmfile);
  370.  
  371.          if ((cfile = FOPEN(icfilename, "a",TEXT_MODE )) == NULL)
  372.          {
  373.             printerr( icfilename );
  374.             fprintf(stderr, "uucp: cannot append to %s\n", icfilename);
  375.             panic();
  376.          }
  377.  
  378.          fprintf(cfile, "R %s %s %s -%s %s 0777 %s\n", src_file, dest_file,
  379.                E_mailbox, flags, *spool_file ? spool_file : "dummy", remote_user);
  380.          fclose(cfile);
  381.          return(1);
  382.       }
  383.       else if (!equal(dest_syst, E_nodename))  {
  384.          printmsg(1,"uucp - spool %s - mkdir %s - execute %s",
  385.                 spool_flag ? "on" : "off",
  386.                   dir_flag ? "on" : "off", xeqt_flag ? "do" : "don't");
  387.  
  388.          printmsg(1,"     - dest m/c = %s  sequence = %ld  control = %s",
  389.                   dest_syst, sequence, tmfile);
  390.  
  391.          if (expand_path(src_file, NULL, E_homedir, NULL) == NULL)
  392.             exit(1);
  393.          normalize( src_file );
  394.  
  395.          p  = dest_file;
  396.  
  397.          while (*p)
  398.          {
  399.             if (*p ==  '\\')
  400.                *p = '/';
  401.             p++;
  402.          }
  403.  
  404.          if (strcspn(src_file, "*?") == strlen(src_file))
  405.          {
  406.             wild_flag = FALSE;
  407.  
  408.             if (stat(src_file, &statbuf) != 0)
  409.             {
  410.                printerr( src_file );
  411.                exit(1);
  412.             }
  413.  
  414.             if (statbuf.st_mode & S_IFDIR)
  415.             {
  416.                printf("uucp - directory name \"%s\" illegal\n",
  417.                        src_file );
  418.                exit(1);
  419.             }
  420.          } /* if (strcspn(src_file, "*?") == strlen(src_file))  */
  421.          else  {
  422.             wild_flag = TRUE;
  423.  
  424.             appendSlash(dest_file); /* Target must be directory   */
  425.  
  426.             strcpy(source_path, src_file);
  427.             p = strrchr(source_path, '/');
  428.             strcpy(search_file, p+1);
  429.             *++p = '\0';
  430.  
  431.             dirp = opendirx(source_path,search_file);
  432.             if (dirp == NULL)
  433.             {
  434.                printf("uucp - unable to open directory %s\n",source_path);
  435.                exit(1);
  436.             } /* if */
  437.  
  438.             if ((dp = readdir(dirp)) == nil(struct direct))
  439.             {
  440.                printf("uucp - can't find any file %s\n", search_file);
  441.                exit(1);
  442.             }
  443.          } /* else */
  444.  
  445.          write_flag = TRUE;
  446.  
  447.          while (write_flag)
  448.          {
  449.             if (wild_flag)
  450.             {
  451.                strcpy(src_file, source_path);
  452.                strlwr( dp->d_name );
  453.                strcat( strcpy(src_file, source_path), dp->d_name );
  454.                strcpy( src_file, normalize( src_file ));
  455.                printf("Queueing file %s for %s!%s\n", src_file, dest_syst,
  456.                         dest_file);
  457.             }
  458.  
  459.             if (spool_flag)
  460.             {
  461.                sprintf(idfile, spool_fmt, 'D', E_nodename, (char) subseq++,
  462.                            sequence_s);
  463.                importpath(work, idfile, remote_syst);
  464.                mkfilename(idfilename, E_spooldir, work);
  465.  
  466.                if ( makeDirectory )
  467.                {
  468.                   char *lastPath = strrchr( idfilename , '/' );
  469.  
  470.                   if ( lastPath != NULL )
  471.                   {
  472.                      *lastPath = '\0';
  473.                      MKDIR( idfilename );
  474.                      *lastPath = '/';     /* Restore last segment of name  */
  475.                      makeDirectory = FALSE;
  476.                   } /* if ( lastPath != NULL ) */
  477.  
  478.                } /* if ( makeDirectory ) */
  479.  
  480.                if (cp(src_file, idfilename) != 0)
  481.                {
  482.                   printmsg(0, "copy \"%s\" to \"%s\" failed",
  483.                               src_file,
  484.                               idfilename);
  485.                   if (dirp != NULL )
  486.                      closedir( dirp );
  487.                   exit(1);
  488.                }
  489.             }
  490.             else
  491.                strcpy(idfile, "D.0");
  492.  
  493.             if ((cfile = FOPEN(icfilename, "a",TEXT_MODE)) == NULL)  {
  494.                printerr( icfilename );
  495.                printf("uucp: cannot append to %s\n", icfilename);
  496.                if (dirp != NULL )
  497.                   closedir( dirp );
  498.                exit(1);
  499.             }
  500.             fprintf(cfile, "S %s %s %s -%s %s 0644 %s\n", src_file, dest_file,
  501.                      E_mailbox, flags, idfile, remote_user);
  502.             fclose(cfile);
  503.             if (wild_flag)  {
  504.                dp = readdir(dirp);
  505.                if ( dp == NULL )
  506.                   write_flag = FALSE;
  507.             }
  508.             else
  509.                write_flag = FALSE;
  510.          }
  511.          if (dirp != NULL )
  512.             closedir( dirp );
  513.          return(1);
  514.       }
  515.       else  {
  516.          if (expand_path(src_file, NULL, E_homedir, NULL) == NULL)
  517.             exit(1);
  518.          if (expand_path(dest_file, NULL, E_homedir, NULL) == NULL)
  519.             exit(1);
  520.          if (strcmp(src_file, dest_file) == 0)
  521.          {
  522.             fprintf(stderr, "%s %s - same file; can't copy\n",
  523.                   src_file, dest_file);
  524.             exit(1);
  525.          }
  526.          cp(src_file, dest_file);
  527.          return(1);
  528.       }
  529.  
  530. } /* do_copy */
  531.  
  532. /*--------------------------------------------------------------------*/
  533. /*    m a i n                                                         */
  534. /*                                                                    */
  535. /*    main program, of course                                         */
  536. /*--------------------------------------------------------------------*/
  537.  
  538. void  main(int argc, char *argv[])
  539. {
  540.       int         i;
  541.       int         option;
  542.       char        src_system[100], dest_system[100];
  543.       char        src_inter[100],  dest_inter[100];
  544.       char        src_file[FILENAME_MAX],   dest_file[FILENAME_MAX];
  545.  
  546. /*--------------------------------------------------------------------*/
  547. /*                             Initialize                             */
  548. /*--------------------------------------------------------------------*/
  549.  
  550.       debuglevel = 0;
  551.  
  552.       banner( argv );
  553.       if (!configure(B_UUCP))
  554.          exit(1);
  555.  
  556. /*--------------------------------------------------------------------*/
  557. /*                        Process option flags                        */
  558. /*--------------------------------------------------------------------*/
  559.  
  560.       while ((option = getopt(argc, argv, "Ccdfg:jmn:rs:x:")) != EOF)  {
  561.          switch(option)  {
  562.             case 'c':               /* don't spool                    */
  563.                spool_flag = FALSE;
  564.                break;
  565.             case 'C':               /* force spool                    */
  566.                spool_flag = TRUE;
  567.                break;
  568.             case 'd':               /* make directories               */
  569.                dir_flag = TRUE;
  570.                break;
  571.             case 'e':               /* send uucp command to sys        */
  572.                /* This one is in Sams but nowhere else - I'm ignoring it */
  573.                break;
  574.             case 'f':               /* don't make directories         */
  575.                dir_flag = FALSE;
  576.                break;
  577.             case 'g':               /* set grade of transfer           */
  578.                grade = *optarg;
  579.                break;
  580.             case 'j':               /* output job id to stdout        */
  581.                j_flag = TRUE;
  582.                break;
  583.             case 'm':               /* send mail when copy completed  */
  584.                mail_me = TRUE;
  585.                break;
  586.             case 'n':               /* notify remote user file was sent  */
  587.                mail_them = TRUE;
  588.                sprintf(remote_user, "%.8s", optarg);
  589.                break;
  590.             case 'r':               /* queue job only                 */
  591.                xeqt_flag = FALSE;
  592.                break;
  593.             case 's':               /* report status of transfer to file  */
  594.                strcpy( spool_file, optarg);
  595.                expand_path( spool_file, NULL, E_pubdir , NULL);
  596.                break;
  597.             case 'x':               /* set debug level                 */
  598.                debuglevel = atoi(optarg);
  599.                break;
  600.             default:
  601.                usage();
  602.                exit(1);
  603.                break;
  604.          }
  605.       }
  606.       flags[0] = (char)(dir_flag ? 'd' : 'f');
  607.       flags[1] = (char)(spool_flag ? 'C' : 'c');
  608.       i = 2;
  609.       if (mail_them)
  610.          flags[i++] = 'n';
  611.       flags[i] = '\0';
  612.  
  613.       if (remote_user[0] == '\0')
  614.       {
  615.          /* copy the string taking care not to overrun the buffer */
  616.          strncpy(remote_user, E_mailbox, sizeof(remote_user) - 1 );
  617.          remote_user[sizeof(remote_user) - 1] = '\0';
  618.       }
  619.  
  620.       if (argc - optind < 2)
  621.       {
  622.          usage();
  623.          exit(1);
  624.       }
  625.  
  626. #if defined(_Windows)
  627.    openlog( NULL );
  628.    atexit( CloseEasyWin );               /* Auto-close EasyWin on exit  */
  629. #endif
  630.  
  631. /*--------------------------------------------------------------------*/
  632. /*       Now - posibilities:                                          */
  633. /*       Sources - 1 or more, local or 1 hop away (NOT > 1 hop!)      */
  634. /*       Dest    - normal cp rules, single only, local, 1 hop or >1   */
  635. /*                 hop                                                */
  636. /*       Wildcards possible on sources.                               */
  637. /*                                                                    */
  638. /*    Actions depend on these - so we need to split the pathnames     */
  639. /*    for more info.                                                  */
  640. /*--------------------------------------------------------------------*/
  641.  
  642.       split_path(argv[argc - 1], dest_system, dest_inter, dest_file);
  643.  
  644. /*--------------------------------------------------------------------*/
  645. /*        OK - we have a destination system - do we know him?         */
  646. /*--------------------------------------------------------------------*/
  647.  
  648.       if (*dest_system != '\0')  {
  649.          if (checkreal(dest_system) == BADHOST)  {
  650.             fprintf(stderr, "uucp - bad system: %s\n", dest_system);
  651.             exit(1);
  652.          }
  653.       }
  654.       else        /* make sure we have a system name for destination */
  655.          strcpy(dest_system, E_nodename);
  656.       printmsg(9, "destination: system \"%s\", inter \"%s\", file \"%s\"",
  657.             dest_system, dest_inter, dest_file);
  658.  
  659. /*--------------------------------------------------------------------*/
  660. /*    Now - if there is more than 1 source then normal cp rules,      */
  661. /*          i.e. dest must be a directory                             */
  662. /*--------------------------------------------------------------------*/
  663.  
  664.       if (argc - optind > 2)
  665.          appendSlash(dest_file);
  666.  
  667.       for (i = optind; i < (argc - 1); i++)  {
  668.          split_path(argv[i], src_system, src_inter, src_file);
  669.  
  670. /*--------------------------------------------------------------------*/
  671. /*            We need to winnow out various combinations -            */
  672. /*                        so lets get at them                         */
  673. /*                                                                    */
  674. /*                   Do we know the source system?                    */
  675. /*--------------------------------------------------------------------*/
  676.  
  677.          if (*src_system != '\0')  {
  678.             if (checkreal(src_system) == BADHOST)  {
  679.                fprintf(stderr, "uucp - bad system %s\n", src_system);
  680.                exit(1);
  681.             }
  682.          }
  683.  
  684. /*--------------------------------------------------------------------*/
  685. /*                    Source can't be >1 hop away                     */
  686. /*--------------------------------------------------------------------*/
  687.  
  688.          if (*src_inter != '\0')  {
  689.             fprintf(stderr, "uucp - illegal syntax %s\n", argv[i]);
  690.             exit(1);
  691.          }
  692.  
  693. /*--------------------------------------------------------------------*/
  694. /*        if source is remote AND wildcarded then we need uux         */
  695. /*--------------------------------------------------------------------*/
  696.  
  697.          if ((*src_system != '\0') && (strcspn(src_file, "*?[") < strlen(src_file)))  {
  698.             do_uux(src_system, src_system, src_file, dest_system, dest_inter, dest_file);
  699.             continue;
  700.          }
  701.  
  702. /*--------------------------------------------------------------------*/
  703. /*            if dest requires forwarding then we need uux            */
  704. /*--------------------------------------------------------------------*/
  705.  
  706.          if (*dest_inter != '\0')  {
  707.             do_uux(dest_system, src_system, src_file, "", dest_inter, dest_file);
  708.             continue;
  709.          }
  710.  
  711. /*--------------------------------------------------------------------*/
  712. /*         if both source & dest are remote then we need uux          */
  713. /*--------------------------------------------------------------------*/
  714.  
  715.          if ((*src_system != '\0') && (!equal(src_system, E_nodename)) &&
  716.                (*dest_system != '\0') && (!equal(dest_system, E_nodename)))  {
  717.             do_uux(dest_system, src_system, src_file, "", dest_inter, dest_file);
  718.             continue;
  719.          }
  720. /*--------------------------------------------------------------------*/
  721. /*          We have left 3 options:                                   */
  722. /*          1) src remote (non-wild) & dest local                     */
  723. /*          2) src local & dest remote 1 hop                          */
  724. /*          3) src & dest both local                                  */
  725. /*                                                                    */
  726. /*               fill up the src system if not already                */
  727. /*--------------------------------------------------------------------*/
  728.          if (*src_system == '\0')
  729.             strcpy(src_system, E_nodename);
  730.          printmsg(4, "source: system \"%s\", file \"%s\"", src_system,
  731.                      src_file);
  732.          do_copy(src_system, src_file, dest_system, dest_file);
  733.       }
  734.       if (xeqt_flag)
  735.          printmsg(1, "Call uucico");
  736.       if (j_flag)
  737.          printmsg(1,"j_flag");
  738.  
  739.       exit(0);
  740.  
  741. } /* main */
  742.  
  743. /*--------------------------------------------------------------------*/
  744. /*       a p p p e n d  S l a s h                                     */
  745. /*                                                                    */
  746. /*       Insure a path name ends in a slash                           */
  747. /*--------------------------------------------------------------------*/
  748.  
  749. static void appendSlash( char *s )
  750. {
  751.    size_t last = strlen( s );
  752.  
  753.    if ( last )
  754.    {
  755.       last--;                    /* Step back to last character */
  756.       if ( s[last] != '/' )
  757.          strcat( s + last, "/");
  758.    }
  759.    else {
  760.       printmsg(0,"Empty string for file destination");
  761.       panic();
  762.    } /* else */
  763.  
  764. }  /* appendSlash */
  765.