uuenview.c

来自「UUDeview是一个编码解码器」· C语言 代码 · 共 1,348 行 · 第 1/3 页

C
1,348
字号
	    p1++;	  myargv[myargc++] = p1;	}	else {	  p1++;	}	break;      case '"':      case '\'':	if (!quote) {	  quote = *p1++;	}	else if (quote == *p1++) {	  quote = 0;	}	break;	      default:	p1++;      }    }  }  for (index=1; index<argc; index++) {    myargv[myargc++] = argv[index];  }  /*   * browse command line flags   */  for (index=1; index<myargc; index++) {    if (*myargv[index] == '-') {      switch (myargv[index][1]) {      case '\0': /* read from stdin */	if (attach) {	  fprintf (stderr, "error: stdin already in use for attachment\n");	  return 1;	}	if (stdinused) {	  fprintf (stderr, "warning: can only use stdin once\n");	  stdinused--;	}	stdinused++;	files++;	break;      case 'b': encoding = B64ENCODED; break;      case 'u': encoding = UU_ENCODED; break;      case 'x': encoding = XX_ENCODED; break;      case 't': encoding = PT_ENCODED; break;      case 'q': encoding = QP_ENCODED; break;      case 'y': encoding = YENC_ENCODED; break;#ifdef HAVE_POPEN      case 'm': 	if (index+1<myargc && myargv[index+1][0] != '-') {	  outflags[UUE_MAILTO] = ++index; 	  tostdout             = 0;	}	else	  fprintf (stderr, "error: -m requires a parameter\n");	break;      case 'p':	if (index+1<myargc && myargv[index+1][0] != '-') {	  outflags[UUE_POSTTO] = ++index;	  tostdout             = 0;	}	else	  fprintf (stderr, "error: -p requires a parameter\n");	break;#endif      case 'o':	if (myargv[index][2] == 'd') {	  if (index+1<myargc && myargv[index+1][0] != '-') {	    strcpy (outdir, myargv[++index]);	    outflags[UUE_TOFILE] = index;	    tostdout             = 0;	    if (strlen(outdir)>0) {	      if (outdir[strlen(outdir)-1]!=DIRSEPARATOR[0]) {		strcat (outdir, DIRSEPARATOR);	      }	    }	    UUSetOption (UUOPT_SAVEPATH, 0, outdir);	  }	  else {	    fprintf (stderr, "error: -od requires a parameter\n");	  }	}	else {	  outflags[UUE_TOFILE] = index;	  tostdout             = 0;	}	break;      case 's':	if (index+1<myargc && myargv[index+1][0] != '-') {	  subject   = ++index;	}	else	  fprintf (stderr, "error: -s requires a parameter\n");	break;      case 'f':	if (index+1<myargc && myargv[index+1][0] != '-') {	  from = ++index;	}	else	  fprintf (stderr, "error: -f requires a parameter\n");	break;      case 'r':	if (index+1<myargc && myargv[index+1][0] != '-') {	  replyto = ++index;	}	else	  fprintf (stderr, "error: -r requires a parameter\n");	break;      case 'v':	UUSetOption (UUOPT_VERBOSE, 1, NULL);	break;      case 'a':	if (linperfile) {	  fprintf (stderr, "error: cannot attach to splitfile\n");	  return 1;	}	attach = 1;	break;      case 'h':      case '?':	usage(myargv[0]);	return 0;      case 'V':	fprintf (stdout, "uuenview %spl%s compiled on %s\n",		 VERSION, PATCH, __DATE__);	return 0;      default:	/* should be a line count of the form -1000 or a forced line count	 * like --100 which disables the sanity check	 */	if (myargv[index][1]>='0' && myargv[index][1]<='9') {	  if (attach) {	    fprintf (stderr, "error: cannot attach to splitfile\n");	    return 1;	  }	  linperfile = atoi (myargv[index] + 1);	  if (linperfile != 0 && linperfile < 200) {	    fprintf (stderr,		     "warning: lines per file must be >= 200 (ignored).\n");	    linperfile=0;	  }	}	else if (myargv[index][1]=='-' &&		 myargv[index][2]>='0' && myargv[index][2]<='9') {	  if (attach) {	    fprintf (stderr, "error: cannot attach to splitfile\n");	    return 1;	  }	  linperfile = atoi (myargv[index] + 2);	}	else if (myargv[index][1]=='-') {	  usage(myargv[0]);	  return 0;	}	else {	  fprintf (stderr, "warning: unknown option '%s' ignored.\n",		   myargv[index]);	}      }    }    else {      files++;    }  }  if (_FP_stristr (myargv[0], "uuencode") != NULL) {    uuencode = 1; /* uuencode compatibility */    if (encoding == -1) {      encoding = UU_ENCODED;    }    if (files == 1) {      stdinused = 1;    }    else if (files > 2) {      fprintf (stderr, "usage: %s [infile] destname\n", myargv[0]);      return 0;    }  }  /*   * check integrity   */  if (linperfile != 0 && tostdout) {    fprintf (stderr, "warning: cannot split file on standard output (use -o)\n");    linperfile=0;  }  if (subject>0 && tostdout && !attach) {    fprintf (stderr, "warning: -s not possible on standard output\n");    subject = -1;  }  if (encoding == -1) {    if (attach || outflags[UUE_POSTTO]>0 || outflags[UUE_MAILTO]>0) {      encoding = B64ENCODED;    }    else {      encoding = UU_ENCODED;    }  }  if (encoding!=UU_ENCODED && encoding!=XX_ENCODED &&      encoding!=B64ENCODED && encoding!=PT_ENCODED &&      encoding!=QP_ENCODED && encoding!=YENC_ENCODED) {    fprintf (stderr, "warning: unknown encoding method (%d)?\n",	     encoding);    encoding=UU_ENCODED;  }#ifdef SYSTEM_DOS  if (tostdout==0 && outflags[UUE_TOFILE] == -1) {    fprintf (stderr, "error: no output defined?\n");    exit    (2);  }#endif  /*   * In Attach mode, first open the pipe and copy the existing article   */  if (attach) {    if (outflags[UUE_POSTTO]==0 && outflags[UUE_MAILTO]==0 && !tostdout) {      fprintf (stderr, "error: attach only possible to mail, news or stdout\n");      exit (2);    }    if (outflags[UUE_POSTTO]>0 && outflags[UUE_MAILTO]>0) {      fprintf (stderr, "warning: can attach only to one destination (sending mail only)\n");      outflags[UUE_POSTTO] = 0;    }    if (outflags[UUE_POSTTO]>0) {      AttachFiles (myargv[outflags[UUE_POSTTO]],		   (subject>0)?myargv[subject]:NULL,		   (from>0)?myargv[from]:NULL,		   (replyto>0)?myargv[replyto]:NULL,		   0, encoding, myargc, myargv);    }    else if (outflags[UUE_MAILTO]>0) {      AttachFiles (myargv[outflags[UUE_MAILTO]],		   (subject>0)?myargv[subject]:NULL,		   (from>0)?myargv[from]:NULL,		   (replyto>0)?myargv[replyto]:NULL,		   1, encoding, myargc, myargv);    }    else /* tostdout */ {      AttachFiles (NULL,		   (subject>0)?myargv[subject]:NULL,		   (from>0)?myargv[from]:NULL,		   (replyto>0)?myargv[replyto]:NULL,		   0, encoding, myargc, myargv);    }    /* finished here */    count=1;    goto uuenview_end;  }  /*   * okay, now process the files   */  for (index=1, iskipflag=0; index<myargc; index+=iskipflag+1) {    iskipflag = 0;    if (*myargv[index] == '-' && myargv[index][1] != '\0') {      switch (myargv[index][1]) {      case 'm': /* skip parameters of options */      case 'p':      case 's':      case 'i':      case 'f':      case 'r':	if (index+1 < myargc && myargv[index+1][0] != '-')	  index++;	break;      case 'o': /* may or may have not a parameter */	if (myargv[index][2]=='d' && index+1<myargc && myargv[index+1][0]!='-')	  index++;	break;      case 'b': encoding = B64ENCODED; break;      case 'u': encoding = UU_ENCODED; break;      case 'x': encoding = XX_ENCODED; break;      case 't': encoding = PT_ENCODED; break;      case 'q': encoding = QP_ENCODED; break;      case 'y': encoding = YENC_ENCODED; break;      default:  /* parameter without option */	break;      }    }    else /* this is a filename */ {      if (uuencode) {	/*	 * we're in uuencode compatibility mode. This means the actual	 * parameter is the file name on disk, the next parameter, if	 * it exists and is not an option, is the name for the encoded	 * file. If there is no next parameter, we shall read from stdin	 * and use the given name as output filename	 */	if (index+1<myargc && myargv[index+1][0] != '-') {	  if (myargv[index][0] != '-' || myargv[index][1] != '\0') {	    strcpy (filename, myargv[index]);	  }	  else {	    filename[0] = '\0';	    stdinused--;	  }	  strcpy (usename, myargv[index+1]);	  iskipflag = 1; /* ignore next argument */	}	else {	  if (stdinused == 0) {	    /* oops, stdin already used up */	    continue;	  }	  stdinused--;	  filename[0] = '\0';	  strcpy (usename, myargv[index]);	}      }      else if (myargv[index][0]=='-' && myargv[index][1]=='\0') {	/*	 * supposed to read from stdin. we expect the next parameter to be	 * the name to be used	 */	if (stdinused == 0) {	  /* oops, stdin already used up */	  continue;	}	stdinused--;	if (index+1<myargc && myargv[index+1][0] != '-') {	  strcpy (usename, myargv[index+1]);	  filename[0] = '\0';	  iskipflag = 1; /* ignore next argument */	}	else {	  fprintf (stderr, "error: need additional name for file from standard input\n");	  continue;	}      }      else {	strcpy (filename, myargv[index]);	strcpy (usename,  filename);      }      if (filename[0] == '\0') {	if (((outflags[UUE_POSTTO] > 0) ? 1 : 0) +	    ((outflags[UUE_MAILTO] > 0) ? 1 : 0) +	    ((outflags[UUE_TOFILE] > 0) ? 1 : 0) > 1) {	  fprintf (stderr, "error: can use standard input only once\n");	  continue;	}      }      else if ((testit = fopen (myargv[index], "r")) == NULL) {	fprintf (stderr, "error: '%s' unreadable.\n", myargv[index]);	continue;      }      else	fclose (testit);      fileflag = 0;#ifdef HAVE_POPEN      /*       * post it       */      if (outflags[UUE_POSTTO] > 0) {	fileflag++;	SendAFile ((filename[0])?NULL:stdin,		   (filename[0])?filename:NULL,		   encoding, linperfile, usename,		   myargv[outflags[UUE_POSTTO]],		   (subject>0)?myargv[subject]:NULL,		   (from>0)?myargv[from]:NULL,		   (replyto>0)?myargv[replyto]:NULL,		   0);      }      /*       * mail it separately to each recepient       */      if (outflags[UUE_MAILTO] > 0) {	fileflag++;	SendAFile ((filename[0])?NULL:stdin,		   (filename[0])?filename:NULL,		   encoding, linperfile, usename,		   myargv[outflags[UUE_MAILTO]],		   (subject>0)?myargv[subject]:NULL,		   (from>0)?myargv[from]:NULL,		   (replyto>0)?myargv[replyto]:NULL,		   1);      }#endif      /*       * store output into a file       */      if (outflags[UUE_TOFILE] > 0 || outflags[UUE_TOFILE] == -42) {	fileflag++;	UUEncodeToFile ((filename[0])?NULL:stdin,			(filename[0])?filename:NULL,			encoding, usename,			NULL, linperfile);      }      /*       * send it to stdout       */      if (tostdout) {	fileflag++;	UUEncodeToStream (stdout,			  (filename[0])?NULL:stdin,			  (filename[0])?filename:NULL,			  encoding, usename, 0);      }      if (fileflag > 0)	count++;    } /* end file processing */  } /* end loop */uuenview_end:  if (UUISATTY(stderr)) {    fprintf (stderr, "%70s\r", "");    fflush  (stderr);  }  if (count==0) {    fprintf (stderr, "error: no files.\n");  }  UUCleanUp ();  return 0;}

⌨️ 快捷键说明

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