home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume18 / april-fool next >
Encoding:
Internet Message Format  |  1989-04-12  |  11.2 KB

  1. Subject:  v18i079:  Absolutely-portable remote interchange library 1
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Dave Taylor <taylor@hplabsz.hpl.hp.com>
  7. Posting-number: Volume 18, Issue 79
  8. Archive-name: april-fool
  9.  
  10. # This is a shell archive.  Remove anything before this line,
  11. # then unpack it by saving it in a file and typing "sh file".
  12. #
  13. # This archive contains:
  14. #    uuexpand.1    uuexpand.c    Makefile    
  15. #
  16. # Error checking via wc(1) will be performed.
  17.  
  18. LANG=""; export LANG
  19.  
  20. echo x - uuexpand.1
  21. cat >uuexpand.1 <<'@EOF'
  22. .TH UUEXPAND 1L "" ""
  23. .ad b
  24. .SH NAME
  25. uuexpand, uuunexpand \- make file representation independent
  26. .SH SYNOPSIS
  27. .B uuexpand
  28. [
  29. .B \-87?hAEdeuv
  30. ] [
  31. .B \-16
  32. ] [
  33. .B \-w
  34. .I width
  35. ]
  36. .br
  37. .B uuunexpand
  38. [
  39. .I uuexpand options
  40. .SH DESCRIPTION
  41. .I Uuexpand
  42. is a representation independent file archival and transportation
  43. mechanism for any operating system that has a "C" compiler available,
  44. including Unix, the Macintosh, MS-DOS, OS/2, VMS, and the like.
  45. .I Uuexpand
  46. also supports all international character sets, including 16-bit Asian,
  47. and 8-bit non-English, as required by the application.
  48. .PP
  49. The program pair are intended to be used to aid in the easy
  50. transportation of program and textual sources, data files, and
  51. binaries via electronic media.
  52. .PP
  53. .SS Options
  54. .PP
  55. There are many options:
  56. .TP 
  57. .B  \-16
  58. Specifies that 16-bit character sets are being used and to ensure 
  59. portability. (Note on non-standard character sets: you must ensure
  60. that when unexpanded the same parameter is specified to the 
  61. program!)
  62. .TP 
  63. .B  \-8 
  64. Specifies that 8-bit character sets are being used.  This is the
  65. default character set assumed (255 character extended ASCII)
  66. .TP 
  67. .B  \-7 
  68. Use a 7-bit ASCII representation for smaller output files.  This
  69. is useful if you are sure that you've not strayed beyond the 
  70. basic 128 ASCII characters.  (see the note under the '-16' option)
  71. .TP 
  72. .B  \-? 
  73. Output a summary of the starting options available.
  74. .TP
  75. .B \-A
  76. Use the ASCII character set for the output of the program.  This is
  77. the default character set assumed.
  78. .TP
  79. .B \-E
  80. Use the EBCDIC character set for the output of the program.  If you
  81. use this option you must ensure that the other end also uses this
  82. option when the file or software is unpacked.
  83. .TP
  84. .B \-d
  85. Turn on debugging for more output and some ending statistics.
  86. .TP
  87. .B \-e
  88. Expand the input -- act as if we'd invoked 
  89. .I uuexpand
  90. explicitly (for sites that choose to change the name).
  91. .TP
  92. .B \-h
  93. Output a summary of starting options; identical to '-?'
  94. .TP
  95. .B \-u
  96. Unexpand the input -- act as if we'd invoked
  97. .I uuunexpand
  98. explicitly (for sites that might not have the symbolic link
  99. between the two names installed)
  100. .TP
  101. .B \-v
  102. Enable verbose output including some ending statistics.
  103. .TP
  104. .B \-w N
  105. Set the expanded line output width to 
  106. .I N
  107. representational independent output elements.  The default, with
  108. the 8-bit characters, is 8 units per output line.
  109. including indirect blocks, is printed.
  110. .SH EXAMPLES
  111. A very typical usage of the program would be for a person at a
  112. site in, say, Hong Kong, to mail a Chinese (16-bit) data file to
  113. a fellow Unix-ite with:
  114. .PP
  115. .ti +.5i
  116. uuexpand -16 < data | mail -s "Data" user@farhost.com
  117. .ti -.5i
  118. .PP
  119. The user at the other end could then simply save the message
  120. int a file then invoke a command similar to:
  121. .PP
  122. .ti +.5i
  123. uuunexpand -16 < data.mailed > data
  124. .ti -.5i
  125. .PP
  126. And the data file would be intact regardless of transport
  127. hosts along the way.
  128. .SH AUTHOR 
  129. Dave Taylor, Intuitive Systems, Los Altos, California
  130. .SH SEE ALSO
  131. uuencode(1L), crypt(1), mail(1), uumail(1), shar(1L)
  132. .SH INTERNATIONAL SUPPORT
  133. 16-bit, 8-bit and 7-bit data.
  134. .SH BUGS
  135. The EBCDIC support is minimal and needs to be further developed
  136. by someone on an IBM or other EBCDIC machine.
  137. .PP
  138. The portability of the C code has not been completely
  139. verified; input from people on strange hardware, especially
  140. 386 Unix machines, would be a useful addition.
  141. .PP
  142. The program doesn't, but should, deal with machines that
  143. have peculiar byte sex problems.
  144. @EOF
  145. if test "`wc -lwc <uuexpand.1`" != '    123    595   3485'
  146. then
  147.     echo ERROR: wc results of uuexpand.1 are `wc -lwc <uuexpand.1` should be     123    595   3485
  148. fi
  149.  
  150. chmod 666 uuexpand.1
  151.  
  152. echo x - uuexpand.c
  153. cat >uuexpand.c <<'@EOF'
  154. /**                uuexpand.c            **/
  155.  
  156. /** This is a representation independent file archival and transportation
  157.     mechanism for any operating system that has a "C" compiler available,
  158.     including Unix, the Macintosh, MS-DOS, OS/2, VMS, and the like.  This
  159.     also supports all international character sets, including 16-bit Asian
  160.     characters as required by the application.
  161.  
  162.     (C) Copyright 1989 Dave Taylor, Intuitive Systems, Los Altos California
  163.  
  164.     >  Permission is hereby granted for the free distribution of this  <
  165.     >  software throughout the known world with the clause that it be  <
  166.     >  free and this version of the source code is always available.   <
  167.  
  168. **/
  169.  
  170. #include <stdio.h>
  171.  
  172. #define SLEN            2048    /* max length of an input line  */
  173.  
  174. #define DEFAULT_CHAR_WIDTH    8    /* 8 bit ASCII by default    */
  175. #define DEFAULT_BYTES_ON_LINE    8    /* default byte units / line    */
  176.  
  177. #define EXPAND            1
  178. #define UNEXPAND        2
  179.  
  180. #define ASCII            425
  181. #define EBCDIC            943
  182.  
  183. #define ON_CHAR            '1'
  184. #define OFF_CHAR        '0'
  185.  
  186. #define plural(n)        (n == 1? "" : "s")
  187.  
  188. int  width_of_line,        /* width of output block/line         */
  189.      action,            /* what are we doing? expand or unexpand */
  190.      lines = 0,            /* lines we've read in from stdin     */
  191.      chars = 0,            /* chars we've read in from stdin     */
  192.      lines_output = 0,        /* lines we've output to stdout         */
  193.      char_width;        /* are we using 7-bit, 8-bit, or 16-bit? */
  194.  
  195. extern char *optarg;
  196.  
  197. main(argc, argv)
  198. int  argc;
  199. char *argv[];
  200. {
  201.     register int i, bit;
  202.     char buffer[SLEN], char_buffer;
  203.     int  bytes_on_line, verbose, output_charset, c;
  204.  
  205.     /* first step: set up the defaults for the program */
  206.  
  207.     action = (strcmp(argv[0], "uuexpand") == 0? EXPAND: UNEXPAND);
  208.  
  209.     char_width     = DEFAULT_CHAR_WIDTH;
  210.     bytes_on_line  = DEFAULT_BYTES_ON_LINE;
  211.     output_charset = ASCII;            /* default */
  212.  
  213.     /* now let's parse the starting arguments */
  214.  
  215.     while ((c = getopt(argc, argv, "AEeu781:w:vdh?")) != EOF) {
  216.       switch (c) {
  217.        case 'A' : output_charset = ASCII;        break;
  218.        case 'E' : output_charset = EBCDIC;        break;
  219.        case '7' : char_width = 7;            break;
  220.        case '8' : char_width = 8;            break;
  221.        case '1' : char_width = 16;            break;
  222.        case 'w' : bytes_on_line = atoi(optarg);    break;
  223.        case 'v' : 
  224.        case 'd' : verbose++;            break;
  225.        case 'e' : action = EXPAND;            break;
  226.        case 'u' : action = UNEXPAND;        break;
  227.        case 'h' :
  228.        case '?' : help(0);                break;
  229.         default : usage("unknown starting option");
  230.       }
  231.     }
  232.  
  233.     /** a quick reality check on the bytes per line argument */
  234.  
  235.     if (bytes_on_line < 1 || (bytes_on_line * char_width > SLEN/2))
  236.       usage("invalid specification for line width");
  237.  
  238.     /** and we recompute the line width for output **/
  239.  
  240.     width_of_line = (char_width * bytes_on_line) - 1;
  241.     
  242.     /** now we're ready to go. **/
  243.     
  244.     if (verbose) {
  245.       fprintf(stderr, "%sexpand: %s character set %s with %d-bit chars\n",
  246.           action == EXPAND ? "" : "un",
  247.           action == UNEXPAND ? "input" : "output",
  248.           output_charset == ASCII ? "ASCII" : "EBCDIC",
  249.           char_width);
  250.     }
  251.  
  252.     /** Main switch here: expanding, or unexpanding? **/
  253.  
  254.     if (action == EXPAND) {
  255.       while (fgets(buffer, SLEN, stdin) != NULL) {
  256.         lines++; chars += strlen(buffer);
  257.         for (i=0; buffer[i] != '\0'; i++) {
  258.           char_buffer = buffer[i];        /* ease of use */
  259.           for (bit=0;bit < char_width; bit++, char_buffer >>= 1)
  260.             output( char_buffer & 01 );
  261.         }
  262.       }
  263.     }
  264.     else /* UNEXPAND */ {
  265.       while (gets(buffer) != NULL) {
  266.         lines++; chars += strlen(buffer);
  267.         for (i=0; i < strlen(buffer); i += char_width) {
  268.           char_buffer = 0;
  269.           for (bit=char_width;bit >= 0; bit--) {
  270.             char_buffer <<= 1;
  271.         char_buffer += (buffer[i+bit] == ON_CHAR ? 1 : 0);
  272.           }
  273.           putchar(char_buffer);
  274.           if (char_buffer == '\n' || char_buffer == '\r')
  275.             lines_output++;
  276.         }
  277.       }
  278.     }
  279.  
  280.     if (verbose) {
  281.       if (action == EXPAND) {
  282.         fprintf(stderr, "Read in %d character%s, %d line%s\n", 
  283.             chars, plural(chars), lines, plural(lines));
  284.         fprintf(stderr, 
  285.            "Output %d representation independent element%s in %d line%s.\n",
  286.         chars * char_width, plural(chars * char_width),
  287.         lines_output, plural(lines_output));
  288.       }
  289.       else {
  290.         fprintf(stderr, 
  291.          "Read in %d representation independent element%s in %d line%s\n",
  292.         chars, plural(chars), lines, plural(lines));
  293.         fprintf(stderr, 
  294.         "Output %d character%s in %d line%s.\n",
  295.         (int) (chars / char_width),
  296.         plural(chars / char_width),
  297.         lines_output, plural(lines_output));
  298.       }
  299.     }
  300. }
  301.  
  302. output(bitvalue)
  303. int bitvalue;
  304. {
  305.     /** Outputs the ON or OFF value based on what we've
  306.         been handed.  No return value.
  307.     **/
  308.  
  309.     static int location_on_line = 0;
  310.  
  311.     if (location_on_line > width_of_line) {
  312.       putchar('\n');
  313.       lines_output++;
  314.       location_on_line = 0;
  315.     }
  316.  
  317.     putchar(bitvalue ? ON_CHAR : OFF_CHAR);
  318.  
  319.     location_on_line++;
  320. }
  321.  
  322. usage(errmsg)
  323. char *errmsg;
  324. {
  325.     /** Output the error message and call help() for a usage **/
  326.  
  327.     fprintf(stderr, "\n**** Error: %s ****\n", errmsg);
  328.  
  329.     help(1);
  330. }
  331.  
  332. help(exitcode)
  333. int exitcode;
  334. {
  335.     /** output some starting parameter help and exit with
  336.         the code specified by the calling routine.
  337.     **/
  338.  
  339.     fprintf(stderr,"\nUsage: uuexpand [opts]\n");
  340.     fprintf(stderr,"   or: uuunexpand [opts]\n\n");
  341.     fprintf(stderr,"Where [opts] can be:\n\n");
  342.     fprintf(stderr,
  343. "\t-16  \tEnsure 16-bit portability\n\
  344. \t-8   \tEnsure 8-bit portability (the default)\n\
  345. \t-7   \tEnsure 7-bit portability\n");
  346.     fprintf(stderr,
  347. "\t-?     \tList the starting options (this information)\n\
  348. \t-h     \tIdentical in functionality to '-?'\n");
  349.     fprintf(stderr,
  350. "\t-A   \tUse the ASCII character set for expanded output\n\
  351. \t-E     \tUse the EBCDIC character set for expanded output\n");
  352.     fprintf(stderr,
  353. "\t-d   \tEnable debugging output (to stderr)\n");
  354.     fprintf(stderr,
  355. "\t-e   \tExpand output (same as invoking 'uuexpand')\n\
  356. \t-u     \tUnExpand output (same as invoking 'uuunexpand')\n");
  357.     fprintf(stderr,
  358. "\t-v   \tEnable verbose output (to stderr)\n");
  359.     fprintf(stderr,
  360. "\t-w N   \tSet expanded line output width to 'N' representational elements\n\
  361. \t     \tper line (default is 8 per 8-bit represented line)\n\n");
  362.  
  363.     exit(exitcode);
  364. }
  365. @EOF
  366. if test "`wc -lwc <uuexpand.c`" != '    211    842   6118'
  367. then
  368.     echo ERROR: wc results of uuexpand.c are `wc -lwc <uuexpand.c` should be     211    842   6118
  369. fi
  370.  
  371. chmod 666 uuexpand.c
  372.  
  373. echo x - Makefile
  374. cat >Makefile <<'@EOF'
  375.  
  376. #
  377. # Makefile for the uuexpand program
  378. #
  379. # (C) 1989 Dave Taylor
  380. #
  381.  
  382. SRC        = uuexpand.c
  383. EXECUTABLE = uuexpand
  384. OTHERNAME  = uuunexpand
  385. MANPAGE       = uuexpand.1
  386.  
  387. INSTALLDIR = /usr/local/bin
  388. MANDIR       = /usr/man/man1
  389.  
  390. CC       = cc
  391. CFLAGS       = -O
  392. DEFINES       = 
  393.  
  394.  
  395. $(EXECUTABLE) : $(SRC)
  396.     $(CC) $(CFLAGS) $(DEFINES) $(SRC) -o $(EXECUTABLE)
  397.  
  398. install: $(EXECUTABLE)
  399.     strip $(EXECUTABLE)
  400.     cp $(EXECUTABLE) $(INSTALLDIR)/$(EXECUTABLE)
  401.     ln -s $(EXECUTABLE) $(OTHERNAME)
  402.     cp $(MANPAGE) $(MANDIR)/$(MANPAGE)
  403.     ln -s $(MANDIR)/$(MANPAGE) $(MANDIR)/$(OTHERNAME).1
  404.  
  405. lint:    $(SRC)
  406.     lint $(DEFINES) $(SRC) > LINT.OUT
  407.  
  408. clean:    
  409.     rm -f a.out core
  410. @EOF
  411. if test "`wc -lwc <Makefile`" != '     35     79    621'
  412. then
  413.     echo ERROR: wc results of Makefile are `wc -lwc <Makefile` should be      35     79    621
  414. fi
  415.  
  416. chmod 666 Makefile
  417.  
  418. exit 0
  419.  
  420.