?? ship.c
字號:
/* ship.c -- Not copyrighted 1991 Mark Adler */#define SHIPVER "ship version 1.1 November 4, 1991 Mark Adler"/* Command for mailing (-m): the %s's are, in order, the subject prefix, the part number (always of the form "partnnnn"), the subject suffix (empty or " (last)" if the last part), the mailing address, and the name of the temporary file begin mailed. The command "Mail" is for BSD systems. You may need to change it to "mailx" for System V Unix, using the compile option "-DMAILX". Also, on Sperry (Unisys?) SysV.3 systems, you might try the command name "v6mail". */#ifdef DIRENT /* If compiled with zip, DIRENT implies System V */# define MAILX#endif /* DIRENT */#ifdef sun /* Except Sun's use DIRENT, but have Mail */# ifdef MAILX# undef MAILX# endif /* MAILX */#endif /* sun */#ifdef sgi /* Silicon Graphics that way too */# ifdef MAILX# undef MAILX# endif /* MAILX */#endif /* sgi */#ifdef VMS# define TMPNAME "_SXXXXXX."# define MAILCMD "mail %s /subj=\"%s %s%s\" \"%s\""# define PATHCUT ']'#else /* !VMS */# define TMPNAME "_SXXXXXX"# ifdef MAILX# define MAILCMD "mailx -s \"%s %s%s\" \"%s\" < %s"# else /* !MAILX */# ifdef M_XENIX# define MAILCMD "mail -s \"%s %s%s\" \"%s\" < %s"# else /* !M_XENIX */# define MAILCMD "Mail -s \"%s %s%s\" \"%s\" < %s"# endif /* ?M_XENIX */# endif /* ?MAILX */# ifdef MSDOS# define PATHCUT '\\'# else /* !MSDOS */# define PATHCUT '/'# endif /* ?MSDOS */#endif /* ?VMS *//*SHIP - Ship is a program for sending binary files through email. It is designed to supplant uuencode and uudecode. Ship encodes approximately 6.32 bits per character mailed, compared to uuencode's 5.81 bits per character. Ship also has these features: a 32-bit CRC check on each file; automatic splitting of the ship output into multiple, smaller files for speedier mailing; automatic mailing of ship's output, with subject lines for multiple parts; and a check on the sequence of parts when unshipping. Usage: ship [-nnn] [-m address] [-s subject] file ... where nnn is the maximum number of K bytes for each output file, address is the address to send mail to, subject is a Subject" line prefix, and file ... is a list of files to ship. If no options are given, ship outputs to stdout. The simplest use is: ship foo > x where foo is converted into the mailable file, x. When -nnn is specified, but -m is not, ship writes to the files part0001, part0002, etc., where each file has nnn or less K bytes. For example: ship -25 bigfoo will write however many 25K byte or less ship files is needed to contain bigfoo. If, say, six files are needed, then the files part0001 to part0006 will be written. When using -m, nothing is written, either to files or to stdout; rather, the output is mailed to the specified address. If -nnn is also specified, then the parts are mailed separately with the subject lines part0001, etc. If -nnn is not specified, then only one part (the whole thing) is mailed with the subject line "part0001". For example: ship -25 -m fred bigfoo will mail the six parts of bigfoo to fred. Any number of files can be shipped at once. They become part of one long ship stream, so if, for example -25 is specified, all but the last part will have about 25K bytes. For example: ship -25 -m fred fee fi fo fum will send the files fee, fi, fo, and fum to fred. Fred will get several mail messages with the subject lines part0001, etc. He can then save those messages as the files, say, p1, p2, p3, ... Then he can use the command: ship -u p? to recreate bigfoo, or fee fi fo and fum, depending on what he was sent. If Fred saved the wrong numbers, ship will detect this and report a sequence error. Note: there is enough information in the shipped parts to determine the correct sequence. A future version of ship will prescan the files to determine the sequence, and then process them in the correct order. If a file being received already exists, ship -u will report an error and exit. The -o option avoids this and allows ship to overwrite existing files. The -o option must follow the -u option: ship -u -o p? In addition to the -u option, ship will unship if it sees that its name is unship. On Unix systems, this can be done simply by linking the executable to unship: ln ship unship Ship can also be used as a filter. The special file name "-" means stdin. For example: tar covf - foodir | compress | ship -25 -m fred - will tar the directory foodir, compress it, and ship it to fred in 25K byte pieces. Then, after Fred saves the files as p01, etc. at the other, end, he can: ship -u p? | zcat | tar xovf - which will recreate the directory foobar and its contents. ship -u knows to write to stdout, since the original ship put the special file name "-" in the first part. Ship uses a base 85 coding that needs 32-bit multiplication and division. This can be slow on 16-bit machines, so ship provides a fast encoding method by specifying the -f option. This method is somewhat faster even on 32-bit machines, and has approximately a 1% penalty in the size of the encoded result (-f gives 6.26 bits per character, on the average). The -f option need only be used when shipping--unshipping (ship -u) automatically detects the encoding used. For example: ship -f -25 -m fred foo will send foo to fred in 25K byte pieces using the fast encoding method. You don't need to tell Fred, since ship -u will figure that out for him. The fast encoding method is probabilistic, so it's possible for the size penalty to be worse than 1%, and it's also possible for the fast encoding to produce a smaller result than base 85 encoding would, all depending on the data. The -q option can be used with either ship or unship (ship -u) for quiet operation--informational messages are inhibited. You can find out the version of ship and get the command usage by using "ship -h" or "ship -?". The version number and date and help will be printed, and ship will exit (the rest of the command line is ignored). Acknowledgements: The hard-arithmetic coding algorithm was blatantly stolen from Peter Gutmann's pgencode/pgdecode programs posted on comp.compression, with modifications to use 86 instead of 94 characters, and to make zeros encode better than, rather than worse than other bytes. (As Stravinsky once said: "Mediocre composers plagiarize. Great composers steal.")*//* tailor.h -- Not copyrighted 1991 Mark Adler *//* const's are inconsistently used across ANSI libraries--kill for all header files. */#define const/* Use prototypes and ANSI libraries if __STDC__ */#ifdef __STDC__# ifndef PROTO# define PROTO# endif /* !PROTO */# define MODERN#endif /* __STDC__ *//* Use prototypes and ANSI libraries if Silicon Graphics */#ifdef sgi# ifndef PROTO# define PROTO# endif /* !PROTO */# define MODERN#endif /* sgi *//* Define MSDOS for Turbo C as well as Microsoft C */#ifdef __POWERC /* For Power C too */# define __TURBOC__#endif /* __POWERC */#ifdef __TURBOC__# ifndef MSDOS# define MSDOS# endif /* !MSDOS */#endif /* __TURBOC__ *//* Use prototypes and ANSI libraries if Microsoft or Borland C */#ifdef MSDOS# ifndef PROTO# define PROTO# endif /* !PROTO */# define MODERN#endif /* MSDOS *//* Turn off prototypes if requested */#ifdef NOPROTO# ifdef PROTO# undef PROTO# endif /* PROTO */#endif /* NOPROT *//* Used to remove arguments in function prototypes for non-ANSI C */#ifdef PROTO# define OF(a) a#else /* !PROTO */# define OF(a) ()#endif /* ?PROTO *//* Allow far and huge allocation for small model (Microsoft C or Turbo C) */#ifdef MSDOS# ifdef __TURBOC__# include <alloc.h># else /* !__TURBOC__ */# include <malloc.h># define farmalloc _fmalloc# define farfree _ffree# endif /* ?__TURBOC__ */#else /* !MSDOS */# define huge# define far# define near# define farmalloc malloc# define farfree free#endif /* ?MSDOS *//* Define MSVMS if either MSDOS or VMS defined */#ifdef MSDOS# define MSVMS#else /* !MSDOS */# ifdef VMS# define MSVMS# endif /* VMS */#endif /* ?MSDOS *//* Define void, voidp, and extent (size_t) */#include <stdio.h>#ifdef MODERN# if !defined(M_XENIX) && !(defined(__GNUC__) && defined(sun))# include <stddef.h># endif# include <stdlib.h> typedef size_t extent; typedef void voidp;#else /* !MODERN */ typedef unsigned int extent;# define void int typedef char voidp;#endif /* ?MODERN *//* Get types and stat */#ifdef VMS# include <types.h># include <stat.h>#else /* !VMS */# include <sys/types.h># include <sys/stat.h>#endif /* ?VMS *//* Cheap fix for unlink on VMS */#ifdef VMS# define unlink delete#endif /* VMS *//* For Pyramid */#ifdef pyr# define strrchr rindex# define ZMEM#endif /* pyr *//* File operations--use "b" for binary if allowed */#ifdef MODERN# define FOPR "rb"# define FOPM "r+b"# define FOPW "w+b"#else /* !MODERN */# define FOPR "r"# define FOPM "r+"# define FOPW "w+"#endif /* ?MODERN *//* Fine tuning */#ifndef MSDOS# define BSZ 8192 /* Buffer size for files */#else /* !MSDOS */# define BSZ 4096 /* Keep precious NEAR space */ /* BSZ can't be 8192 even for compact model because of 64K limitation * in im_lmat.c. If you run out of memory when processing a large number * files, use the compact model and reduce BSZ to 2048 here and in * im_lm.asm. */#endif /* ?MSDOS *//* end of tailor.h */#ifdef MODERN# include <string.h>#else /* !MODERN */ voidp *malloc(); long atol(); char *strcpy(); char *strrchr();#endif /* ?MODERN *//* Library functions not in (most) header files */char *mktemp OF((char *));int unlink OF((char *));#ifdef MSDOS /* Use binary mode for binary files */# include <io.h># include <fcntl.h>#endif /* MSDOS */#define LNSZ 1025 /* size of line buffer */typedef unsigned long ulg; /* 32-bit unsigned integer */typedef struct { /* associates a CRC with a file */ FILE *f; /* pointer to associated file stream */ ulg c; /* CRC register */ ulg b; /* four byte buffer */ int n; /* buffer count */} cfile;/* Function prototypes */#ifdef MODERN void err(int, char *); cfile *chook(FILE *); char *nopath(char *); void newship(void); void endship(int); void newline(char *); void ship(char *, FILE *); void mkinv(void); void decode(unsigned char *, cfile *); void unship(char **, int, int); void help(void); void main(int, char **);#endif /* MODERN *//* Globals for ship() */char sname[9]; /* current ship file name */FILE *sfile; /* current ship file */ulg slns; /* number of lines written to ship file */ulg slmax; /* maximum number of lines per ship file */int fast; /* true for arithmetic coding, else base 85 */int mail; /* true if mailing */char mpspc[9]; /* prealloced space for prefix */char *mprefix = mpspc; /* identification for this mailing */char *mdest; /* mail destination */char mname[10]; /* temporary file name if mailing */ulg ccnt; /* count of bytes read or written */int noisy = 1; /* false to inhibit informational messages *//* Errors */#define SE_ARG 1#define SE_FIND 2#define SE_NONE 3#define SE_PART 4#define SE_FORM 5#define SE_CONT 6#define SE_CRC 7#define SE_MAIL 8#define SE_OVER 9#define SE_FULL 10#define SE_MANY 11#define SE_MEM 12char *errors[] = { /* 1 */ "invalid argument ", /* 2 */ "could not find ", /* 3 */ "no files received", /* 4 */ "unfinished file ", /* 5 */ "invalid ship format in ", /* 6 */ "wrong sequence for ", /* 7 */ "CRC check failed on ", /* 8 */ "mail command failed: ", /* 9 */ "attempted to overwrite ", /* 10 */ "could not write to ", /* 11 */ "too many output files!", /* 12 */ "out of memory"};/* Set of 86 characters used for the base 85 digits (last one not used), and the 86 character arithmetic coding. Selected to be part of both the ASCII printable characters, and the common EBCDIC printable characters whose
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -