⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uux.c

📁 汇编源代码大全
💻 C
📖 第 1 页 / 共 3 页
字号:
             strcat(command," ");
             strcat(command,argv[optind]);
             printmsg(9, "prm -> %s", argv[optind]);
             continue;

             case '<':
             if (i_remote) {
                 printmsg(0, "uux - multiple input files specified");
                 return FALSE;
             }
             else
                 i_remote = TRUE;
             f_remote = INPUT_FILE;
             printmsg(9, "prm -> %c", *argv[optind]);
             if (!*++argv[optind])
                 if (++optind >= argc)
                 {
                 printmsg(0, "uux - no input file specified after <");
                 return FALSE;
                 }
             break;

             case '>':
             if (o_remote) {
                 printmsg(0, "uux - multiple output files specified");
                 return FALSE;
             } else
                 o_remote = TRUE;
             f_remote = OUTPUT_FILE;
             printmsg(9, "prm -> %c", *argv[optind]);
             if (!*++argv[optind])
                 if (++optind >= argc)
                 {
                 printmsg(0, "uux - no output file specified after >");
                 return FALSE;
                 }
             break;

             case '|':
             printmsg(9, "prm -> %c", *argv[optind]);
             if (!*++argv[optind])
                 if (++optind >= argc)
                 {
                 printmsg(0, "uux - no command specified after |");
                 return FALSE;
                 }
             if (strchr(argv[optind], '!'))
                 {
                 printmsg(0, "uux - no host name allowed after |");
                 return FALSE;
                 }
             strcat(command," | ");
             strcat(command, argv[optind]);
             continue;

             case '(':
             {
                 size_t len = strlen(argv[optind] + 1);

                 if (argv[optind][len] != ')')
                 {
                 printmsg(0, "uux - missing close parenthesis in %s",
                         argv[optind] + 1);
                 return FALSE;
                 }
                 argv[optind][len] = '\0';
             }

             printmsg(9, "prm -> %s", argv[optind]);
             strcat(command," ");
             strcat(command, argv[optind] + 1);
             continue;

             /* default: fall through */
         } /* switch (*argv[optind]) */


         printmsg(9, "prm -> %s", argv[optind]);

/*--------------------------------------------------------------------*/
/*        Hmmm.  Do we want the remote to have DOS style path?        */
/*--------------------------------------------------------------------*/

         if (!split_path(argv[optind], src_system, src_file, FALSE, dest_system))
         {
            printmsg(0, "uux - illegal syntax %s", argv[optind]);
            return FALSE;
         } /* if (!split_path()) */

         s_remote = equal(src_system, E_nodename) ? FALSE : TRUE ;

/*--------------------------------------------------------------------*/
/*                   Do we know the source system?                    */
/*--------------------------------------------------------------------*/

         if ((s_remote) && (checkreal(src_system) == BADHOST))
         {
            printmsg(0, "uux - bad system %s\n", src_system);
            return FALSE;
         } /* if ((s_remote) && (checkreal(src_system) == BADHOST)) */

         if (f_remote == OUTPUT_FILE)
         {
            fprintf(stream, "O %s %s\n", src_file,
                (equal(src_system, dest_system) ? " " : src_system) );
            continue;
         } /* if (f_remote == OUTPUT_FILE) */

         remote_file = src_file;
         if (!equal(src_system, dest_system))
         {
             remote_file += strlen(src_file);
             while (remote_file > src_file  // Keep trailing / and :
             && (*--remote_file == '/'
                 /* || *remote_file == '\\' */
                 || *remote_file == ':'))
            ;
             while (remote_file > src_file  // Stop at other / and :
                && remote_file[-1] != '/'
                /* && remote_file[-1] != '\\' */
                && remote_file[-1] != ':')
            --remote_file;
             /* remote_file is now src_file without any leading drive/path */
        } /* if (!equal(src_system, dest_system)) */

        if (f_remote == DATA_FILE)
        {

           strcat(command, " ");
           strcat(command, remote_file);

        } /* if (f_remote == DATA_FILE) */
        else if (f_remote == INPUT_FILE)
           fprintf(stream, "I %s\n", remote_file);

/*--------------------------------------------------------------------*/
/*    if both source & dest are not the same we must copy src_file    */
/*--------------------------------------------------------------------*/

         if ( !equal(src_system, dest_system) )
         {

            sprintf(dest_file, dataf_fmt, 'D', src_system, sequence_s,
                    subseq());

            fprintf(stream, "F %s %s\n", dest_file, remote_file );

/*--------------------------------------------------------------------*/
/*      if source is remote and dest is local copy source to local    */
/*      if source is local and dest is remote copy source to remote   */
/*--------------------------------------------------------------------*/

            if ((s_remote && !d_remote) || (!s_remote && d_remote))
            {
               if (!do_copy(src_system, src_file, dest_system, dest_file))
                   return FALSE;
            } /* if ((s_remote && !d_remote) || (!s_remote && d_remote)) */

/*--------------------------------------------------------------------*/
/*      if both source & dest are on remote nodes we need uuxqt       */
/*--------------------------------------------------------------------*/

            else if (s_remote && d_remote)
            {
               if (!do_uuxqt(job_id,
                             src_system,
                             remote_file,
                             dest_system,
                             dest_file))
                   return FALSE;

               if (!do_copy(src_system, src_file, E_nodename, dest_file))
                   return FALSE;

            } /* else if (s_remote && d_remote) */

            continue;
         } /* if ( !equal(src_system, dest_system) ) */

         printmsg(4, "system \"%s\", rest \"%s\"", src_system, src_file);

      } /* for (; optind < argc; optind++) */

/*--------------------------------------------------------------------*/
/*  Create the data file if any to send to the remote system          */
/*--------------------------------------------------------------------*/

      if (flags[FLG_READ_STDIN]) {
          if (i_remote) {
              printmsg(0, "uux - multiple input files specified");
              return FALSE;
          }

          sprintf(rifile, dataf_fmt, 'D', E_nodename, sequence_s,
                  subseq());
          sprintf(lifile, dataf_fmt, 'D', E_nodename, sequence_s,
                  subseq());

          importpath(msname, lifile, dest_system);
          mkfilename(msfile, E_spooldir, msname);

          if (!CopyData( NULL, msfile )) {
              remove( msfile );
              return FALSE;
          }

          fprintf(stream, "F %s\n", rifile);
          fprintf(stream, "I %s\n", rifile);
      }

/*--------------------------------------------------------------------*/
/*           here finish writing parameters to the X file             */
/*--------------------------------------------------------------------*/

      printmsg(4, "command \"%s\"", command);


      fprintf(stream, "C %s\n", command);
      fclose(stream);

/*--------------------------------------------------------------------*/
/*                     create local C (call) file                     */
/*--------------------------------------------------------------------*/

     if (d_remote) {
          sprintf(tmfile, spool_fmt, 'C', dest_system,  grade, sequence_s);
          importpath( msname, tmfile, dest_system);
          mkfilename( msfile, E_spooldir, msname);

          if ( (stream = FOPEN(msfile, "a",TEXT_MODE)) == NULL) {
             printerr( msname );
             printmsg(0, "uux: cannot write/append to C file %s", msfile);
             return FALSE;
          }

          if (flags[FLG_READ_STDIN])
              fprintf(stream, send_cmd, lifile, rifile, E_mailbox, lifile);

          fprintf(stream, send_cmd, lxfile, rxfile, E_mailbox, lxfile);

          fclose(stream);
     }
     return TRUE;
} /* do_remote */

/*--------------------------------------------------------------------*/
/*    m a i n                                                         */
/*                                                                    */
/*    main program                                                    */
/*--------------------------------------------------------------------*/

void main(int  argc, char  **argv)
{
   int         c;
   extern char *optarg;
   extern int   optind;

/*--------------------------------------------------------------------*/
/*     Report our version number and date/time compiled               */
/*--------------------------------------------------------------------*/

   debuglevel = 0;
   banner( argv );

#if defined(__CORE__)
   copywrong = strdup(copyright);
   checkref(copywrong);
#endif

   if (!configure( B_UUCP ))
      exit(1);   /* system configuration failed */

   user_id = E_mailbox;

/*--------------------------------------------------------------------*/
/*        Process our arguments                                       */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*
 *
 *   -aname    Use name as the user identification replacing the initiator
 *   -b        Return whatever standard input was provided to the uux command
 *   -c        Do not copy local file to the spool directory for transfer to
 *   -C        Force the copy of local files to the spool directory for
 *   -E        run job using exec
 *   -e        run job using sh
 *   -ggrade   Grade is a single letter number; lower ASCII sequence
 *   -j        Output the jobid ASCII string on the standard output which is
 *   -n        Do not notify the user if the command fails.
 *   -p        Same as -:  The standard input to uux is made the standard
 *   -r        Do not start the file transfer, just queue the job.
 *   -sfile    Report status of the transfer in file.
 *   -xdebug_level
 *   -z        Send success notification to the user.
 *
/*--------------------------------------------------------------------*/

   while ((c = getopt(argc, argv, "-a:bcCEejg:nprs:x:z")) !=  EOF)
      switch(c) {
      case '-':
         flags[FLG_READ_STDIN] = TRUE;
         break;
      case 'a':
         flags[FLG_USE_USERID] = TRUE;
         user_id = optarg;
         break;
      case 'b':
         flags[FLG_RETURN_STDIN] = TRUE;
         break;
      case 'c':               // don't spool
         flags[FLG_COPY_SPOOL] = FALSE;
         break;
      case 'C':               // force spool
         flags[FLG_COPY_SPOOL] = TRUE;
         break;
      case 'E':               // use exec to execute
         flags[FLG_USE_EXEC] = TRUE;
         break;
      case 'e':               // use sh to execute
         flags[FLG_USE_EXEC] = FALSE;
         break;
      case 'j':               // output job id to stdout
         flags[FLG_OUTPUT_JOBID] = TRUE;
         break;
      case 'n':               // do not notify user if command fails
         flags[FLG_NONOTIFY_FAIL] = TRUE;
         break;
      case 'p':
         flags[FLG_READ_STDIN] = TRUE;
         break;
      case 'r':               // queue job only
         flags[FLG_QUEUE_ONLY] = TRUE;
         break;
      case 'z':
         flags[FLG_NOTIFY_SUCCESS] = TRUE;
         break;
      case 'g':               // set grade of transfer
         grade = *optarg;
         break;
      case 's':               // report status of transfer to file
         flags[FLG_STATUS_FILE] = TRUE;
         st_out = optarg;
         break;
      case 'x':
         debuglevel = atoi( optarg );
         break;
      case '?':
         usage();
         exit(1);
         break;
      default:
         printmsg(0, "uux - bad argument from getopt \"%c\"", c);
         exit(1);
         break;
   }

   if (argc - optind < 1)     // Verify we have at least a command
   {
      printmsg(0,"uux - no command to execute!");
      usage();
      exit(1);
   }

#if defined(_Windows)
   openlog( NULL );
   atexit( CloseEasyWin );               // Auto-close EasyWin on exit
#endif

   if (!do_remote(optind, argc, argv))
   {
      printmsg(0, "uux command failed");
      exit(1);
   };

   if (flags[FLG_OUTPUT_JOBID])
       printf("%s\n", job_id);

   exit(0);
} /* main */

/*--------------------------------------------------------------------*/
/*    s u b s e q                                                    */
/*                                                                    */
/*    Generate a valid sub-sequence number                            */
/*--------------------------------------------------------------------*/

static char subseq( void )
{
   static char next = '0' - 1;

   switch( next )
   {
      case '9':
         next = 'A';
         break;

      case 'Z':
         next = 'a';
         break;

      default:
         next += 1;
   } /* switch */

   return next;

} /* subseq */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -