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

📄 uucp.c

📁 大量的汇编程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------*/
/*    u u c p . c                                                     */
/*                                                                    */
/*    UUCP lookalike for IBM PC.                                      */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
/*    Wonderworks.                                                    */
/*                                                                    */
/*    All rights reserved except those explicitly granted by the      */
/*    UUPC/extended license agreement.                                */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*                          RCS Information                           */
/*--------------------------------------------------------------------*/

/*
 *    $Id: uucp.c 1.9 1993/10/03 20:43:08 ahd Exp $
 *
 *    Revision history:
 *    $Log: uucp.c $
 * Revision 1.9  1993/10/03  20:43:08  ahd
 * Normalize comments to C++ double slash
 *
 * Revision 1.8  1993/10/02  19:07:49  ahd
 * Use 0644 permissions on files
 *
 * Revision 1.7  1993/09/20  04:48:25  ahd
 * TCP/IP support from Dave Watt
 * 't' protocol support
 * OS/2 2.x support (BC++ 1.0 for OS/2)
 *
 * Revision 1.6  1993/08/02  03:24:59  ahd
 * Further changes in support of Robert Denny's Windows 3.x support
 *
 * Revision 1.5  1993/07/31  16:27:49  ahd
 * Changes in support of Robert Denny's Windows support
 *
 * Revision 1.4  1993/04/11  00:35:46  ahd
 * Global edits for year, TEXT, etc.
 *
 * Revision 1.3  1993/04/05  04:35:40  ahd
 * Use timestamp/file size information returned by directory search
 *
 * Revision 1.2  1992/12/11  12:45:11  ahd
 * Normalize paths for files read
 *
 */

/*--------------------------------------------------------------------*/
/*                                                                    */
/*    Change history:                                                 */
/*                                                                    */
/*       02/08/81 H.A.E.Broomhall                                     */
/*                Hacked for UUPC/extended 1.09c                      */
/*       04/27/91 Drew Derbyshire                                     */
/*                Modified for UUPC/extended 1.10a                    */
/*       09/26/91 Mitch Mitchell                                      */
/*                Support for UUX                                     */
/*       01/26/92 Drew Derbyshire                                     */
/*                Various comment and error message clean up          */
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
/*                        system include files                        */
/*--------------------------------------------------------------------*/

#include  <ctype.h>
#include  <direct.h>
#include  <fcntl.h>
#include  <io.h>
#include  <stdio.h>
#include  <stdlib.h>
#include  <string.h>
#include  <sys/types.h>
#include  <sys/stat.h>

#ifdef _Windows
#include <windows.h>
#endif

/*--------------------------------------------------------------------*/
/*                    UUPC/extended include files                     */
/*--------------------------------------------------------------------*/

#include  "lib.h"
#include  "expath.h"
#include  "getopt.h"
#include  "getseq.h"
#include  "hlib.h"
#include  "hostable.h"
#include  "import.h"
#include  "uundir.h"
#include  "security.h"
#include  "timestmp.h"
#include  "execute.h"

#ifdef _Windows
#include "winutil.h"
#include "logger.h"
#endif

/*--------------------------------------------------------------------*/
/*                          Global variables                          */
/*--------------------------------------------------------------------*/

static boolean       spool_flag = FALSE;
static char          spool_file[FILENAME_MAX]; // alt spool file name
static boolean       dir_flag = TRUE;
static boolean       xeqt_flag = TRUE;    // Triggered by -r option
static char          grade = 'n';         // Default grade of service
static boolean       mail_me = FALSE;     // changes with -m
static boolean       mail_them = FALSE;   // changes with -n
static char  remote_user[10];             // user to mail with -n
static char  *destn_file;
static char  flags[16];

currentfile();

/*--------------------------------------------------------------------*/
/*    u s a g e                                                       */
/*                                                                    */
/*    Report flags used by program                                    */
/*--------------------------------------------------------------------*/

static         void    usage(void)
{
      fprintf(stderr, "Usage: uucp\t[-c|-C] [-d|-f] [-gGRADE] [-j] [-m] [-nUSER] [-r] [-sFILE]\\\n\
\t\t[-xDEBUG_LEVEL] source-files destination-file\n");
}

/*--------------------------------------------------------------------*/
/*    c p                                                             */
/*                                                                    */
/*    Copy a file                                                     */
/*--------------------------------------------------------------------*/

static int cp(char *from, char *to)
{
      int         fd_from, fd_to;
      int         nr, nw = -1;
      char        buf[BUFSIZ*4]; // faster if we alloc a big buffer

      if ((fd_from = open(from, O_RDONLY | O_BINARY)) == -1)
         return(1);        // failed
      /* what if the to is a directory? */
      /* possible with local source & dest uucp */
      if ((fd_to = open(to, O_CREAT | O_BINARY | O_WRONLY, S_IWRITE | S_IREAD)) == -1) {
         close(fd_from);
         return(1);        // failed
         /* NOTE - this assumes all the required directories exist!  */
      }
      while  ((nr = read(fd_from, buf, sizeof buf)) > 0 &&
         (nw = write(fd_to, buf, nr)) == nr)
         ;
      close(fd_to);
      close(fd_from);
      if (nr != 0 || nw == -1)
         return(1);        // failed in copy
      return(0);
} /* cp */

/*--------------------------------------------------------------------*/
/*    s p l i t _ p a t h                                             */
/*                                                                    */
/*    split_path splits a path into 3 components.                     */
/*    1)  The system next in line                                     */
/*    2)  Any intermediate systems as a bang path                     */
/*    3)  The actual file name/path                                   */
/*                                                                    */
/*    It tries to be a little clever with idiots, in recognizing      */
/*    system=this machine                                             */
/*--------------------------------------------------------------------*/

static         void    split_path(char *path,
                                  char *system,
                                  char *inter,
                                  char *file)
{
      char    *p_left, *p_right, *p;

      *system = *inter = *file = '\0';    // init to nothing
      for (p = path;; p = p_left + 1)  {
         p_left = strchr(p, '!');         // look for the first bang
         if (p_left == NULL)  {           // not a remote path
            strcpy(file, p);              // so just return filename
            return;
         }
         /* now check if the system was in fact us.
       If so strip it and restart */
         if (equaln(E_nodename, p, p_left - p) &&
            (E_nodename[p_left - p] == '\0'))
            continue;

         p_right = strrchr(p, '!');      // look for the last bang
         strcpy(file, p_right + 1);      // and thats our filename
         strncpy(system, p, p_left - p); // and we have a system thats not us
         system[p_left - p] = '\0';
         /* now see if there is an intermediate path */
         if (p_left != p_right)  {        // yup - there is
            strncpy(inter, p_left + 1, p_right - p_left - 1);
            inter[p_right - p_left - 1] = '\0';
         }
         return;                 // and we're done
      }        /* never get here :-)  */
}

/*--------------------------------------------------------------------*/
/*    d o _ u u x                                                     */
/*                                                                    */
/*    Generate & execute UUX command                                  */
/*--------------------------------------------------------------------*/

int   do_uux(char *remote,
             char *src_syst,
             char *src_file,
             char *dest_syst,
             char *dest_inter,
             char *dest_file)
{
      char        xcmd[BUFSIZ];        // buffer for assembling the UUX command
      char        *ex_flg;

/*--------------------------------------------------------------------*/
/*                 First - lets get the basic command                 */
/*--------------------------------------------------------------------*/

      ex_flg = xeqt_flag ? "" : "-r";
      sprintf(xcmd, "-C %s %s!uucp -C ", ex_flg, remote);
                              // but what about mailing the guy?

/*--------------------------------------------------------------------*/
/*                  Now we sort out the source name                   */
/*--------------------------------------------------------------------*/

      if ((*src_syst == '\0') || equal(src_syst, E_nodename))
         sprintf(xcmd + strlen(xcmd), " !%s ", src_file);
      else  {
         if (!equal(remote, src_syst))
            sprintf(xcmd + strlen(xcmd), " (%s!%s) ", src_syst, src_file);
         else
            sprintf(xcmd + strlen(xcmd), " (%s) ", src_file);
      } /* else */

/*--------------------------------------------------------------------*/
/*                   Now to do the destination name                   */
/*--------------------------------------------------------------------*/

      if (*dest_inter != '\0')  {
         if (*dest_syst != '\0')
            sprintf(xcmd + strlen(xcmd), " (%s!%s!%s) ", dest_syst, dest_inter, dest_file);
         else
            sprintf(xcmd + strlen(xcmd), " (%s!%s) ", dest_inter, dest_file);
      }
      else  {
         if ((*dest_syst == '\0') || equal(dest_syst, E_nodename))
            sprintf(xcmd + strlen(xcmd), " (%s!%s) ", E_nodename, dest_file);
      }
      printmsg(2, "xcmd: %s", xcmd);

/*--------------------------------------------------------------------*/
/*                              OK - GO!                              */
/*--------------------------------------------------------------------*/

   execute("uux", xcmd, NULL, NULL, FALSE, TRUE);

   return(1);

} /* do_uux */

/*--------------------------------------------------------------------*/
/*    d o _ c o p y                                                   */
/*                                                                    */
/*    At this point only one of the systems can be remote and only    */
/*    1 hop away.  All the rest have been filtered out                */
/*--------------------------------------------------------------------*/

int   do_copy(char *src_syst,
              char *src_file,
              char *dest_syst,
              char *dest_file)
{
      char        *p;
      boolean wild_flag = FALSE;
      boolean write_flag;
      char        tmfile[15];       // Unix style name for c file
      char        idfile[15];       // Unix style name for data file copy
      char        work[FILENAME_MAX];   // temp area for filename hacking
      char        search_file[FILENAME_MAX];
      char        source_path[FILENAME_MAX];
      char        icfilename[FILENAME_MAX]; // our hacked c file path
      char        idfilename[FILENAME_MAX]; // our hacked d file path

      struct  stat    statbuf;
      DIR *dirp = NULL;
      struct direct *dp = NULL;
      char subseq = 'A';

      long    int     sequence;
      char    *remote_syst;   // Non-local system in copy
      char    *sequence_s;
      FILE        *cfile;
      static  char    *spool_fmt = SPOOLFMT;

      sequence = getseq();
      sequence_s = JobNumber( sequence );
      remote_syst =  equal(src_syst, E_nodename) ? dest_syst : src_syst;
      sprintf(tmfile, spool_fmt, 'C', remote_syst, grade, sequence_s);
      importpath(work, tmfile, remote_syst);
      mkfilename(icfilename, E_spooldir, work);

      if (!equal(src_syst, E_nodename))
      {
         if (expand_path(dest_file, NULL, E_homedir, NULL) == NULL)
            exit(1);
         strcpy( dest_file, normalize( dest_file ));
         p  = src_file;
         while (*p)
         {
            if (*p ==  '\\')
               *p = '/';
            p++;
         }
         printmsg(1, "uucp - from \"%s\" - control = %s", src_syst,
                  tmfile);
         if ((cfile = FOPEN(icfilename, "a",TEXT_MODE )) == NULL)  {
            printerr( icfilename );
            fprintf(stderr, "uucp: cannot append to %s\n", icfilename);
            panic();
         }
         fprintf(cfile, "R %s %s %s -%s %s 0777 %s\n", src_file, dest_file,
               E_mailbox, flags, *spool_file ? spool_file : "dummy", remote_user);
         fclose(cfile);
         return(1);

⌨️ 快捷键说明

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