📄 uucp.c
字号:
}
else if (!equal(dest_syst, E_nodename)) {
printmsg(1,"uucp - spool %s - mkdir %s - execute %s",
spool_flag ? "on" : "off",
dir_flag ? "on" : "off", xeqt_flag ? "do" : "don't");
printmsg(1," - dest m/c = %s sequence = %ld control = %s",
dest_syst, sequence, tmfile);
if (expand_path(src_file, NULL, E_homedir, NULL) == NULL)
exit(1);
normalize( src_file );
p = dest_file;
while (*p)
{
if (*p == '\\')
*p = '/';
p++;
}
if (strcspn(src_file, "*?") == strlen(src_file))
{
wild_flag = FALSE;
if (stat(src_file, &statbuf) != 0)
{
printerr( src_file );
exit(1);
}
if (statbuf.st_mode & S_IFDIR)
{
printf("uucp - directory name \"%s\" illegal\n",
src_file );
exit(1);
}
} /* if (strcspn(src_file, "*?") == strlen(src_file)) */
else {
wild_flag = TRUE;
strcpy(source_path, src_file);
p = strrchr(source_path, '/');
strcpy(search_file, p+1);
*++p = '\0';
dirp = opendirx(source_path,search_file);
if (dirp == NULL)
{
printf("uucp - unable to open directory %s\n",source_path);
exit(1);
} /* if */
if ((dp = readdir(dirp)) == nil(struct direct))
{
printf("uucp - can't find any file %s\n", search_file);
exit(1);
}
} /* else */
write_flag = TRUE;
while (write_flag)
{
if (wild_flag)
{
strcpy(src_file, source_path);
strlwr( dp->d_name );
strcat( strcpy(src_file, source_path), dp->d_name );
strcpy( src_file, normalize( src_file ));
printf("Queueing file %s for %s!%s\n", src_file, dest_syst,
dest_file);
}
if (spool_flag) {
sprintf(idfile , spool_fmt, 'D', E_nodename, (char) subseq++,
sequence_s);
importpath(work, idfile, remote_syst);
mkfilename(idfilename, E_spooldir, work);
/* Do we need a MKDIR here for the system? */
if (cp(src_file, idfilename) != 0) {
printmsg(0, "copy \"%s\" to \"%s\" failed",
src_file, idfilename); // copy data
closedir( dirp );
exit(1);
}
}
else
strcpy(idfile, "D.0");
if ((cfile = FOPEN(icfilename, "a",TEXT_MODE)) == NULL) {
printerr( icfilename );
printf("uucp: cannot append to %s\n", icfilename);
if (dirp != NULL )
closedir( dirp );
exit(1);
}
fprintf(cfile, "S %s %s %s -%s %s 0644 %s\n", src_file, dest_file,
E_mailbox, flags, idfile, remote_user);
fclose(cfile);
if (wild_flag) {
dp = readdir(dirp);
if ( dp == NULL )
write_flag = FALSE;
}
else
write_flag = FALSE;
}
if (dirp != NULL )
closedir( dirp );
return(1);
}
else {
if (expand_path(src_file, NULL, E_homedir, NULL) == NULL)
exit(1);
if (expand_path(dest_file, NULL, E_homedir, NULL) == NULL)
exit(1);
if (strcmp(src_file, dest_file) == 0)
{
fprintf(stderr, "%s %s - same file; can't copy\n",
src_file, dest_file);
exit(1);
}
cp(src_file, dest_file);
return(1);
}
}
/*--------------------------------------------------------------------*/
/* m a i n */
/* */
/* main program, of course */
/*--------------------------------------------------------------------*/
void main(int argc, char *argv[])
{
int i;
int option;
boolean j_flag = FALSE;
char src_system[100], dest_system[100];
char src_inter[100], dest_inter[100];
char src_file[FILENAME_MAX], dest_file[FILENAME_MAX];
/*--------------------------------------------------------------------*/
/* Initialize */
/*--------------------------------------------------------------------*/
debuglevel = 0;
banner( argv );
if (!configure(B_UUCP))
exit(1);
/*--------------------------------------------------------------------*/
/* Process option flags */
/*--------------------------------------------------------------------*/
while ((option = getopt(argc, argv, "Ccdfg:jmn:rs:x:")) != EOF) {
switch(option) {
case 'c': // don't spool
spool_flag = FALSE;
break;
case 'C': // force spool
spool_flag = TRUE;
break;
case 'd': // make directories
dir_flag = TRUE;
break;
case 'e': // send uucp command to sys
/* This one is in Sams but nowhere else - I'm ignoring it */
break;
case 'f': // don't make directories
dir_flag = FALSE;
break;
case 'g': // set grade of transfer
grade = *optarg;
break;
case 'j': // output job id to stdout
j_flag = TRUE;
break;
case 'm': // send mail when copy completed
mail_me = TRUE;
break;
case 'n': // notify remote user file was sent
mail_them = TRUE;
sprintf(remote_user, "%.8s", optarg);
break;
case 'r': // queue job only
xeqt_flag = FALSE;
break;
case 's': // report status of transfer to file
strcpy( spool_file, optarg);
expand_path( spool_file, NULL, E_pubdir , NULL);
break;
case 'x': // set debug level
debuglevel = atoi(optarg);
break;
default:
usage();
exit(1);
break;
}
}
flags[0] = (char)(dir_flag ? 'd' : 'f');
flags[1] = (char)(spool_flag ? 'C' : 'c');
i = 2;
if (mail_them)
flags[i++] = 'n';
flags[i] = '\0';
if (remote_user[0] == '\0')
{
/* copy the string taking care not to overrun the buffer */
strncpy(remote_user, E_mailbox, sizeof(remote_user) - 1 );
remote_user[sizeof(remote_user) - 1] = '\0';
}
if (argc - optind < 2)
{
usage();
exit(1);
}
#if defined(_Windows)
openlog( NULL );
atexit( CloseEasyWin ); // Auto-close EasyWin on exit
#endif
/*--------------------------------------------------------------------*/
/* Now - posibilities: */
/* Sources - 1 or more, local or 1 hop away (NOT > 1 hop!) */
/* Dest - normal cp rules, single only, local, 1 hop or >1 */
/* hop */
/* Wildcards possible on sources. */
/* */
/* Actions depend on these - so we need to split the pathnames */
/* for more info. */
/*--------------------------------------------------------------------*/
split_path(argv[argc - 1], dest_system, dest_inter, dest_file);
/*--------------------------------------------------------------------*/
/* OK - we have a destination system - do we know him? */
/*--------------------------------------------------------------------*/
if (*dest_system != '\0') {
if (checkreal(dest_system) == BADHOST) {
fprintf(stderr, "uucp - bad system: %s\n", dest_system);
exit(1);
}
}
else /* make sure we have a system name for destination */
strcpy(dest_system, E_nodename);
printmsg(9, "destination: system \"%s\", inter \"%s\", file \"%s\"",
dest_system, dest_inter, dest_file);
/*--------------------------------------------------------------------*/
/* Now - if there is more than 1 source then normal cp rules, */
/* i.e. dest must be a directory */
/*--------------------------------------------------------------------*/
if (argc - optind > 2)
strcat(dest_file, "/");
destn_file = argv[argc - 1];
for (i = optind; i < (argc - 1); i++) {
split_path(argv[i], src_system, src_inter, src_file);
/*--------------------------------------------------------------------*/
/* We need to winnow out various combinations - */
/* so lets get at them */
/* */
/* Do we know the source system? */
/*--------------------------------------------------------------------*/
if (*src_system != '\0') {
if (checkreal(src_system) == BADHOST) {
fprintf(stderr, "uucp - bad system %s\n", src_system);
exit(1);
}
}
/*--------------------------------------------------------------------*/
/* Source can't be >1 hop away */
/*--------------------------------------------------------------------*/
if (*src_inter != '\0') {
fprintf(stderr, "uucp - illegal syntax %s\n", argv[i]);
exit(1);
}
/*--------------------------------------------------------------------*/
/* if source is remote AND wildcarded then we need uux */
/*--------------------------------------------------------------------*/
if ((*src_system != '\0') && (strcspn(src_file, "*?[") < strlen(src_file))) {
do_uux(src_system, src_system, src_file, dest_system, dest_inter, dest_file);
continue;
}
/*--------------------------------------------------------------------*/
/* if dest requires forwarding then we need uux */
/*--------------------------------------------------------------------*/
if (*dest_inter != '\0') {
do_uux(dest_system, src_system, src_file, "", dest_inter, dest_file);
continue;
}
/*--------------------------------------------------------------------*/
/* if both source & dest are remote then we need uux */
/*--------------------------------------------------------------------*/
if ((*src_system != '\0') && (!equal(src_system, E_nodename)) &&
(*dest_system != '\0') && (!equal(dest_system, E_nodename))) {
do_uux(dest_system, src_system, src_file, "", dest_inter, dest_file);
continue;
}
/*--------------------------------------------------------------------*/
/* We have left 3 options: */
/* 1) src remote (non-wild) & dest local */
/* 2) src local & dest remote 1 hop */
/* 3) src & dest both local */
/* */
/* fill up the src system if not already */
/*--------------------------------------------------------------------*/
if (*src_system == '\0')
strcpy(src_system, E_nodename);
printmsg(4, "source: system \"%s\", file \"%s\"", src_system,
src_file);
do_copy(src_system, src_file, dest_system, dest_file);
}
if (xeqt_flag)
printmsg(1, "Call uucico");
if (j_flag)
printmsg(1,"j_flag");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -