home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / f / futi14as.zip / CAT.C < prev    next >
C/C++ Source or Header  |  1992-02-22  |  19KB  |  778 lines

  1. /* cat -- concatenate files and print on the standard output.
  2.    Copyright (C) 1988, 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  19.    This port is also distributed under the terms of the
  20.    GNU General Public License as published by the
  21.    Free Software Foundation.
  22.  
  23.    Please note that this file is not identical to the
  24.    original GNU release, you should have received this
  25.    code as patch to the official release.  */
  26.  
  27. #ifdef MSDOS
  28. static char RCS_Id[] =
  29.   "$Header: e:/gnu/fileutil/RCS/cat.c 1.4.0.2 90/09/19 11:17:40 tho Exp $";
  30.  
  31. static char Program_Id[] = "cat";
  32. static char RCS_Revision[] = "$Revision: 1.4.0.2 $";
  33.  
  34. #define VERSION \
  35.   "GNU %s, Version %.*s (compiled %s %s for MS-DOS)\n", Program_Id, \
  36.   (sizeof RCS_Revision - 14), (RCS_Revision + 11), __DATE__, __TIME__
  37.  
  38. #define COPYING \
  39.   "This is free software, distributed under the terms of the\n" \
  40.   "GNU General Public License.  For details, see the file COPYING.\n"
  41. #endif /* MSDOS */
  42.  
  43. /* Differences from the Unix cat:
  44.    * Always unbuffered, -u is ignored.
  45.    * 100 times faster with -v -u.
  46.    * 20 times faster with -v.
  47.  
  48.    By tege@sics.se, Torbjorn Granlund, advised by rms, Richard Stallman. */
  49.  
  50. #include <stdio.h>
  51. #include <getopt.h>
  52. #include <errno.h>
  53. #include <sys/types.h>
  54. #ifndef _POSIX_SOURCE
  55. #ifndef MSDOS
  56. #include <sys/ioctl.h>
  57. #endif
  58. #endif
  59. #include "system.h"
  60.  
  61. #ifdef STDC_HEADERS
  62. #include <stdlib.h>
  63. #else
  64. char *malloc ();
  65. void free ();
  66.  
  67. extern int errno;
  68. #endif
  69.  
  70. #ifdef MSDOS
  71.  
  72. #include <string.h>
  73. #include <fcntl.h>
  74. #include <malloc.h>
  75. #include <io.h>
  76.  
  77. extern void main (int, char **);
  78. extern void error (int status, int errnum, char *message, ...);
  79. extern void usage (char *);
  80. extern void simple_cat (unsigned char *, int);
  81. extern void cat (unsigned char *, int, unsigned char *,\
  82.          int, int, int, int, int, int, int);
  83. extern void next_line_num (void);
  84. extern char *copystring (char *, char *);
  85.  
  86. #else /* not MSDOS */
  87.  
  88. #define max(h,i) ((h) > (i) ? (h) : (i))
  89.  
  90. char *copystring ();
  91. void cat ();
  92. void error ();
  93. void next_line_num ();
  94. void simple_cat ();
  95.  
  96. #endif /* not MSDOS */
  97.  
  98. typedef unsigned char uchar;
  99.  
  100. /* Name under which this program was invoked.  */
  101. char *program_name;
  102.  
  103. /* Name of input file.  May be "-".  */
  104. char *infile;
  105.  
  106. /* Descriptor on which input file is open.  */
  107. int input_desc;
  108.  
  109. /* Descriptor on which output file is open.  Always is 1.  */
  110. int output_desc;
  111.  
  112. /* Buffer for line numbers.  */
  113. char line_buf[13] =
  114. {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '0', '\t', '\0'};
  115.  
  116. /* Position in `line_buf' where printing starts.  This will not change
  117.    unless the number of lines are more than 999999.  */
  118. char *line_num_print = line_buf + 5;
  119.  
  120. /* Position of the first digit in `line_buf'.  */
  121. char *line_num_start = line_buf + 10;
  122.  
  123. /* Position of the last digit in `line_buf'.  */
  124. char *line_num_end = line_buf + 10;
  125.  
  126. /* Preserves the `cat' function's local `newlines' between invocations.  */
  127. int newlines2 = 0;
  128.  
  129. /* Count of non-fatal error conditions.  */
  130. int exit_stat = 0;
  131.  
  132. void
  133. usage (reason)
  134.      char *reason;
  135. {
  136.   if (reason != NULL)
  137.     fprintf (stderr, "%s: %s\n", program_name, reason);
  138.  
  139. #ifdef MSDOS
  140.   fprintf (stderr, "\
  141. Usage: %s [-benstuvABET] [+number] [+number-nonblank] [+squeeze-blank]\n\
  142.        [+show-nonprinting] [+show-ends] [+show-tabs] [+show-all] [+binary]\n\
  143.        [+copying] [+version] [file...]\n", program_name);
  144. #else /* not MSDOS */
  145.   fprintf (stderr, "\
  146. Usage: %s [-benstuvAET] [+number] [+number-nonblank] [+squeeze-blank]\n\
  147.        [+show-nonprinting] [+show-ends] [+show-tabs] [+show-all] [file...]\n",
  148.        program_name);
  149. #endif /* not MSDOS */
  150.  
  151.   exit (2);
  152. }
  153.  
  154.  
  155. void
  156. main (argc, argv)
  157.      int argc;
  158.      char *argv[];
  159. {
  160.   /* Optimal size of i/o operations of output.  */
  161.   int outsize;
  162.  
  163.   /* Optimal size of i/o operations of input.  */
  164.   int insize;
  165.  
  166.   /* Pointer to the input buffer.  */
  167.   uchar *inbuf;
  168.  
  169.   /* Pointer to the output buffer.  */
  170.   uchar *outbuf;
  171.  
  172.   int c;
  173.  
  174.   /* Index in argv to processed argument.  */
  175.   int argind;
  176.  
  177.   /* Device number of the output (file or whatever).  */
  178.   int out_dev;
  179.  
  180.   /* I-node number of the output.  */
  181.   int out_ino;
  182.  
  183.   /* Nonzero if the output file should not be the same as any input file. */
  184.   int check_redirection = 1;
  185.  
  186.   struct stat stat_buf;
  187.  
  188.   /* Variables that are set according to the specified options.  */
  189.   int numbers = 0;
  190.   int numbers_at_empty_lines = 1;
  191.   int squeeze_empty_lines = 0;
  192.   int mark_line_ends = 0;
  193.   int quote = 0;
  194.   int output_tabs = 1;
  195.   int options = 0;
  196.   int longind;
  197. #ifdef MSDOS
  198.   int binary = 0;
  199. #endif
  200.  
  201.   static struct option long_options[] =
  202.   {
  203. #ifdef MSDOS
  204.     {"binary", 0, NULL, 'B'},
  205.     {"copying", 0, NULL, 30},
  206.     {"version", 0, NULL, 31},
  207. #endif
  208.     {"number-nonblank", 0, NULL, 'b'},
  209.     {"number", 0, NULL, 'n'},
  210.     {"squeeze-blank", 0, NULL, 's'},
  211.     {"show-nonprinting", 0, NULL, 'v'},
  212.     {"show-ends", 0, NULL, 'E'},
  213.     {"show-tabs", 0, NULL, 'T'},
  214.     {"show-all", 0, NULL, 'A'},
  215.     {NULL, 0, NULL, 0}
  216.   };
  217.  
  218.   program_name = argv[0];
  219.  
  220.   /* Parse command line options.  */
  221.  
  222. #ifdef MSDOS
  223.   while ((c = getopt_long (argc, argv, "benstuvABET", long_options, &longind))
  224. #else
  225.   while ((c = getopt_long (argc, argv, "benstuvAET", long_options, &longind))
  226. #endif
  227.      != EOF)
  228.     {
  229.       options++;
  230.       switch (c)
  231.     {
  232.     case 'b':
  233.       numbers = 1;
  234.       numbers_at_empty_lines = 0;
  235.       break;
  236.  
  237.     case 'e':
  238.       mark_line_ends = 1;
  239.       quote = 1;
  240.       break;
  241.  
  242.     case 'n':
  243.       numbers = 1;
  244.       break;
  245.  
  246.     case 's':
  247.       squeeze_empty_lines = 1;
  248.       break;
  249.  
  250.     case 't':
  251.       output_tabs = 0;
  252.       quote = 1;
  253.       break;
  254.  
  255.     case 'u':
  256.       /* We provide the -u feature unconditionally.  */
  257.       options--;
  258.       break;
  259.  
  260.     case 'v':
  261.       quote = 1;
  262.       break;
  263.  
  264.     case 'A':
  265.       quote = 1;
  266.       mark_line_ends = 1;
  267.       output_tabs = 0;
  268.       break;
  269.  
  270. #ifdef MSDOS
  271.     case 'B':
  272.       binary++;
  273.       options--;    /* stdout will be binary iff no other option!  */
  274.       break;
  275.  
  276.     case 30:
  277.       fprintf (stderr, COPYING);
  278.       exit (0);
  279.       break;
  280.  
  281.     case 31:
  282.       fprintf (stderr, VERSION);
  283.       exit (0);
  284.       break;
  285. #endif
  286.  
  287.     case 'E':
  288.       mark_line_ends = 1;
  289.       break;
  290.  
  291.     case 'T':
  292.       output_tabs = 0;
  293.       break;
  294.  
  295.     default:
  296.       usage ((char *) 0);
  297.     }
  298.     }
  299.  
  300.   output_desc = fileno (stdout);
  301.  
  302.   /* Get device, i-node number, and optimal blocksize of output.  */
  303.  
  304.   if (fstat (output_desc, &stat_buf) < 0)
  305.     error (1, errno, "standard output");
  306.  
  307.   outsize = ST_BLKSIZE (stat_buf);
  308.   switch (stat_buf.st_mode & S_IFMT)
  309.     {
  310.       /* Input file can be output file for non-regular files.
  311.      fstat on pipes returns S_IFSOCK on some systems, S_IFIFO
  312.      on others, so the checking should not be done for those types,
  313.      and to allow things like cat < /dev/tty > /dev/tty, checking
  314.      is not done for device files either. */
  315.     case S_IFREG:
  316.       out_dev = stat_buf.st_dev;
  317.       out_ino = stat_buf.st_ino;
  318.       break;
  319.     default:
  320.       check_redirection = 0;
  321.       break;
  322.     }
  323.  
  324.   /* Check if any of the input files are the same as the output file.  */
  325.  
  326.   /* Main loop.  */
  327.  
  328.   infile = "-";
  329.   argind = optind;
  330.  
  331.   do
  332.     {
  333.       if (argind < argc)
  334.     infile = argv[argind];
  335.  
  336.       if (infile[0] == '-' && infile[1] == 0)
  337.     input_desc = fileno (stdin);
  338.       else
  339.     {
  340.       input_desc = open (infile, O_RDONLY);
  341.       if (input_desc < 0)
  342.         {
  343.           error (0, errno, "%s", infile);
  344.           exit_stat = 1;
  345.           continue;
  346.         }
  347.     }
  348.  
  349. #ifdef MSDOS
  350.       if (binary)
  351.     {
  352.       setmode (input_desc, O_BINARY);
  353.  
  354.       /* We will not set the output to binary mode if we have
  355.          another (verbose) option active.  */
  356.       if (options == 0)
  357.         setmode (output_desc, O_BINARY);
  358.     }
  359. #endif
  360.  
  361.       if (fstat (input_desc, &stat_buf) < 0)
  362.     {
  363.       error (0, errno, "%s", infile);
  364.       close (input_desc);
  365.       exit_stat = 1;
  366.       continue;
  367.     }
  368.       insize = ST_BLKSIZE (stat_buf);
  369.  
  370.       /* Compare the device and i-node numbers of this input file with
  371.      the corresponding values of the (output file associated with)
  372.      stdout, and skip this input file if they coincide.  Input
  373.      files cannot be redirected to themselves.  */
  374.  
  375.       if (check_redirection
  376.       && stat_buf.st_dev == out_dev && stat_buf.st_ino == out_ino)
  377.     {
  378.       error (0, 0, "%s: input file is output file", infile);
  379.       exit_stat = 1;
  380.       continue;
  381.     }
  382.  
  383.       /* Select which version of `cat' to use. If any options (more than -u)
  384.      were specified, use `cat', otherwise use `simple_cat'.  */
  385.  
  386.       if (options == 0)
  387.     {
  388.       insize = max (insize, outsize);
  389.       inbuf = (uchar *) malloc (insize);
  390.       if (inbuf == NULL)
  391.         error (1, 0, "virtual memory exhausted");
  392.  
  393.       simple_cat (inbuf, insize);
  394.     }
  395.       else
  396.     {
  397. #ifdef MSDOS            /* the user wants it slow, he can get it! */
  398.       insize = outsize = 0x1000;
  399. #endif
  400.       inbuf = (uchar *) malloc (insize + 1);
  401.       if (inbuf == NULL)
  402.         error (1, 0, "virtual memory exhausted");
  403.  
  404.       /* Why are (OUTSIZE  - 1 + INSIZE * 4 + 13) bytes allocated for
  405.          the output buffer?
  406.  
  407.          A test whether output needs to be written is done when the input
  408.          buffer empties or when a newline appears in the input.  After
  409.          output is written, at most (OUTSIZE - 1) bytes will remain in the
  410.          buffer.  Now INSIZE bytes of input is read.  Each input character
  411.          may grow by a factor of 4 (by the prepending of M-^).  If all
  412.          characters do, and no newlines appear in this block of input, we
  413.          will have at most (OUTSIZE - 1 + INSIZE) bytes in the buffer.  If
  414.          the last character in the preceeding block of input was a
  415.          newline, a line number may be written (according to the given
  416.          options) as the first thing in the output buffer. (Done after the
  417.          new input is read, but before processing of the input begins.)  A
  418.          line number requires seldom more than 13 positions.  */
  419.  
  420.       outbuf = (uchar *) malloc (outsize - 1 + insize * 4 + 13);
  421.       if (outbuf == NULL)
  422.         error (1, 0, "virtual memory exhausted");
  423.  
  424.       cat (inbuf, insize, outbuf, outsize, quote,
  425.            output_tabs, numbers, numbers_at_empty_lines, mark_line_ends,
  426.            squeeze_empty_lines);
  427.  
  428.       free (outbuf);
  429.     }
  430.  
  431.       free (inbuf);
  432.       if (input_desc)
  433.     close (input_desc);
  434.     }
  435.   while (++argind < argc);
  436.  
  437.   exit (exit_stat);
  438. }
  439.  
  440. /* Plain cat.  Copies the file behind `input_desc' to the file behind
  441.    `output_desc'.  */
  442.  
  443. void
  444. simple_cat (buf, bufsize)
  445.      /* Pointer to the buffer, used by reads and writes.  */
  446.      uchar *buf;
  447.  
  448.      /* Number of characters preferably read or written by each read and write
  449.         call.  */
  450.      int bufsize;
  451. {
  452.   /* Actual number of characters read, and therefore written.  */
  453.   int n_read;
  454.  
  455.   /* Loop until the end of the file.  */
  456.  
  457.   for (;;)
  458.     {
  459.       /* Read a block of input.  */
  460.  
  461.       n_read = read (input_desc, buf, bufsize);
  462.       if (n_read < 0)
  463.     {
  464.       error (0, errno, "%s", infile);
  465.       exit_stat = 1;
  466.       return;
  467.     }
  468.  
  469.       /* End of this file?  */
  470.  
  471.       if (n_read == 0)
  472.     break;
  473.  
  474.       /* Write this block out.  */
  475.  
  476.       if (write (output_desc, buf, n_read) != n_read)
  477.     error (1, errno, "write error");
  478.     }
  479. }
  480.  
  481. /* Cat the file behind INPUT_DESC to the file behind OUTPUT_DESC.
  482.    Called if any option more than -u was specified.
  483.  
  484.    A newline character is always put at the end of the buffer, to make
  485.    an explicit test for buffer end unnecessary.  */
  486.  
  487. void
  488. cat (inbuf, insize, outbuf, outsize, quote,
  489.      output_tabs, numbers, numbers_at_empty_lines,
  490.      mark_line_ends, squeeze_empty_lines)
  491.  
  492.      /* Pointer to the beginning of the input buffer.  */
  493.      uchar *inbuf;
  494.  
  495.      /* Number of characters read in each read call.  */
  496.      int insize;
  497.  
  498.      /* Pointer to the beginning of the output buffer.  */
  499.      uchar *outbuf;
  500.  
  501.      /* Number of characters written by each write call.  */
  502.      int outsize;
  503.  
  504.      /* Variables that have values according to the specified options.  */
  505.      int quote;
  506.      int output_tabs;
  507.      int numbers;
  508.      int numbers_at_empty_lines;
  509.      int mark_line_ends;
  510.      int squeeze_empty_lines;
  511. {
  512.   /* Last character read from the input buffer.  */
  513.   uchar ch;
  514.  
  515.   /* Pointer to the next character in the input buffer.  */
  516.   uchar *bpin;
  517.  
  518.   /* Pointer to the first non-valid byte in the input buffer, i.e. the
  519.      current end of the buffer.  */
  520.   uchar *eob;
  521.  
  522.   /* Pointer to the position where the next character shall be written.  */
  523.   uchar *bpout;
  524.  
  525.   /* Number of characters read by the last read call.  */
  526.   int n_read;
  527.  
  528.   /* Determines how many consequtive newlines there have been in the
  529.      input.  0 newlines makes NEWLINES -1, 1 newline makes NEWLINES 1,
  530.      etc.  Initially 0 to indicate that we are at the beginning of a
  531.      new line.  The "state" of the procedure is determined by
  532.      NEWLINES.  */
  533.   int newlines = newlines2;
  534.  
  535. #ifdef FIONREAD
  536.   /* If nonzero, use the FIONREAD ioctl, as an optimization.
  537.      (On Ultrix, it is not supported on NFS filesystems.)  */
  538.   int use_fionread = 1;
  539. #endif
  540.  
  541.   /* The inbuf pointers are initialized so that BPIN > EOB, and thereby input
  542.      is read immediately.  */
  543.  
  544.   eob = inbuf;
  545.   bpin = eob + 1;
  546.  
  547.   bpout = outbuf;
  548.  
  549.   for (;;)
  550.     {
  551.       do
  552.     {
  553.       /* Write if there are at least OUTSIZE bytes in OUTBUF.  */
  554.  
  555.       if (bpout - outbuf >= outsize)
  556.         {
  557.           uchar *wp = outbuf;
  558.           do
  559.         {
  560.           if (write (output_desc, wp, outsize) != outsize)
  561.             error (1, errno, "write error");
  562.           wp += outsize;
  563.         }
  564.           while (bpout - wp >= outsize);
  565.  
  566.           /* Move the remaining bytes to the beginning of the
  567.          buffer.  */
  568.  
  569.           bcopy (wp, outbuf, bpout - wp);
  570.           bpout = outbuf + (bpout - wp);
  571.         }
  572.  
  573.       /* Is INBUF empty?  */
  574.  
  575.       if (bpin > eob)
  576.         {
  577. #ifdef FIONREAD
  578.           int n_to_read = 0;
  579.  
  580.           /* Is there any input to read immediately?
  581.          If not, we are about to wait,
  582.          so write all buffered output before waiting.  */
  583.  
  584.           if (use_fionread
  585.           && ioctl (input_desc, FIONREAD, &n_to_read) < 0)
  586.         {
  587.           if (errno == EOPNOTSUPP)
  588.             use_fionread = 0;
  589.           else
  590.             {
  591.               error (0, errno, "cannot do ioctl on `%s'", infile);
  592.               exit_stat = 1;
  593.               newlines2 = newlines;
  594.               return;
  595.             }
  596.         }
  597.           if (n_to_read == 0)
  598. #endif
  599.         {
  600.           int n_write = bpout - outbuf;
  601.  
  602.           if (write (output_desc, outbuf, n_write) != n_write)
  603.             error (1, errno, "write error");
  604.           bpout = outbuf;
  605.         }
  606.  
  607.           /* Read more input into INBUF.  */
  608.  
  609.           n_read = read (input_desc, inbuf, insize);
  610.           if (n_read < 0)
  611.         {
  612.           error (0, errno, "%s", infile);
  613.           exit_stat = 1;
  614.           newlines2 = newlines;
  615.           return;
  616.         }
  617.           if (n_read == 0)
  618.         {
  619.           newlines2 = newlines;
  620.           return;
  621.         }
  622.  
  623.           /* Update the pointers and insert a sentinel at the buffer
  624.          end.  */
  625.  
  626.           bpin = inbuf;
  627.           eob = bpin + n_read;
  628.           *eob = '\n';
  629.         }
  630.       else
  631.         {
  632.           /* It was a real (not a sentinel) newline.  */
  633.  
  634.           /* Was the last line empty?
  635.          (i.e. have two or more consecutive newlines been read?)  */
  636.  
  637.           if (++newlines > 0)
  638.         {
  639.           /* Are multiple adjacent empty lines to be substituted by
  640.              single ditto (-s), and this was the second empty line?  */
  641.  
  642.           if (squeeze_empty_lines && newlines >= 2)
  643.             {
  644.               ch = *bpin++;
  645.               continue;
  646.             }
  647.  
  648.           /* Are line numbers to be written at empty lines (-n)?  */
  649.  
  650.           if (numbers && numbers_at_empty_lines)
  651.             {
  652.               next_line_num ();
  653.               bpout = (uchar *) copystring (bpout, line_num_print);
  654.             }
  655.         }
  656.  
  657.           /* Output a currency symbol if requested (-e).  */
  658.  
  659.           if (mark_line_ends)
  660.         *bpout++ = '$';
  661.  
  662.           /* Output the newline.  */
  663.  
  664.           *bpout++ = '\n';
  665.         }
  666.       ch = *bpin++;
  667.     }
  668.       while (ch == '\n');
  669.  
  670.       /* Are we at the beginning of a line, and line numbers are requested?  */
  671.  
  672.       if (newlines >= 0 && numbers)
  673.     {
  674.       next_line_num ();
  675.       bpout = (uchar *) copystring (bpout, line_num_print);
  676.     }
  677.  
  678.       /* Here CH cannot contain a newline character.  */
  679.  
  680.       /* The loops below continue until a newline character is found,
  681.      which means that the buffer is empty or that a proper newline
  682.      has been found.  */
  683.  
  684.       /* If quoting, i.e. at least one of -v, -e, or -t specified,
  685.      scan for chars that need conversion.  */
  686.       if (quote)
  687.     for (;;)
  688.       {
  689.         if (ch >= 32)
  690.           {
  691.         if (ch < 127)
  692.           *bpout++ = ch;
  693.         else if (ch == 127)
  694.           *bpout++ = '^',
  695.             *bpout++ = '?';
  696.         else
  697.           {
  698.             *bpout++ = 'M',
  699.               *bpout++ = '-';
  700.             if (ch >= 128 + 32)
  701.               if (ch < 128 + 127)
  702.             *bpout++ = ch - 128;
  703.               else
  704.             *bpout++ = '^',
  705.               *bpout++ = '?';
  706.             else
  707.               *bpout++ = '^',
  708.             *bpout++ = ch - 128 + 64;
  709.           }
  710.           }
  711.         else if (ch == '\t' && output_tabs)
  712.           *bpout++ = '\t';
  713.         else if (ch == '\n')
  714.           {
  715.         newlines = -1;
  716.         break;
  717.           }
  718.         else
  719.           *bpout++ = '^',
  720.         *bpout++ = ch + 64;
  721.  
  722.         ch = *bpin++;
  723.       }
  724.       else
  725.     /* Not quoting, neither of -v, -e, or -t specified.  */
  726.     for (;;)
  727.       {
  728.         if (ch == '\t' && !output_tabs)
  729.           *bpout++ = '^',
  730.         *bpout++ = ch + 64;
  731.         else if (ch != '\n')
  732.           *bpout++ = ch;
  733.         else
  734.           {
  735.         newlines = -1;
  736.         break;
  737.           }
  738.  
  739.         ch = *bpin++;
  740.       }
  741.     }
  742. }
  743.  
  744. /* Compute the next line number.  */
  745.  
  746. void
  747. next_line_num ()
  748. {
  749.   char *endp = line_num_end;
  750.   do
  751.     {
  752.       if ((*endp)++ < '9')
  753.     return;
  754.       *endp-- = '0';
  755.     }
  756.   while (endp >= line_num_start);
  757.   *--line_num_start = '1';
  758.   if (line_num_start < line_num_print)
  759.     line_num_print--;
  760. }
  761.  
  762. /* A less stupid strcpy.  Returns a pointer to the end of the destination
  763.    string, instead of to the beginning.  Doesn't null-terminate the
  764.    destination.  */
  765.  
  766. char *
  767. copystring (dst, src)
  768.      char *dst;
  769.      char *src;
  770. {
  771.   char c;
  772.  
  773.   while (c = *src++)
  774.     *dst++ = c;
  775.  
  776.   return dst;
  777. }
  778.