home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / concat.zip / ConCat.C next >
C/C++ Source or Header  |  1995-06-27  |  5KB  |  101 lines

  1.  
  2. /***********************************************************************
  3.  *                                                                     *
  4.  *   ConCat - concatenates multiple lines of file description in the   *
  5.  *            file ALLFILES.TXT downloaded from Pete Norloff's OS/2    *
  6.  *            Shareware BBS.                                           *
  7.  *                                                                     *
  8.  *   Input file format is expected to be a sequence of lines, some     *
  9.  *   of which begin with 29 spaces.  ConCat removes any sequence of    *
  10.  *   CR/LF followed by 28 spaces, leaving the one space and the text   *
  11.  *   of this line following the text of the previous line.             *
  12.  *                                                                     *
  13.  *   Pretty dumb algorithm (can you say 'brute-force?') but works      *
  14.  *   relatively fast.  11.6 seconds on a 486DX2-66 on ALLFILES.TXT     *
  15.  *                                                                     *
  16.  *   This is definitely a filter, so use something like                *
  17.  *                                                                     *
  18.  *     ConCat < AllFiles.Txt > AllFiles.Txt.Concat                     *
  19.  *                                                                     *
  20.  *   J. Daniel Ashton -- 06/27/95  Rev 1.0                             *
  21.  *                                                                     *
  22.  *   Copyright (c) 1995 J. Daniel Ashton                               *
  23.  *                                                                     *
  24.  *   You are free to redistribute this code in its present format.     *
  25.  *   If you use this code in your program, please give appropriate     *
  26.  *   credit somewhere in your package, and please drop a note to me.   *
  27.  *   (I could use the ego boost!)                                      *
  28.  *                                                                     *
  29.  *   If you see any bugs or design issues, please let me know--I'm     *
  30.  *   still growing in the language (as are most of us ;-)  I'd like    *
  31.  *   to hear how you react to this program.                            *
  32.  *                                                                     *
  33.  *   jdashton@southern.edu                                             *
  34.  *   72401,1667@compuserve.com                                         *
  35.  *   (615) 238-7111 x2319 days (Eastern Time)                          *
  36.  *   (615) 559-1026       nights                                       *
  37.  *                                                                     *
  38.  *   J. Daniel Ashton                                                  *
  39.  *   PO Box 1327                                                       *
  40.  *   Collegedale, TN  37315-1327                                       *
  41.  *                                                                     *
  42.  *   Note: This executable was compiled with C Set++ v2.1, with the    *
  43.  *         following command-line.                                     *
  44.  *                                                                     *
  45.  *         icc /W2 /Q /G4 /O /Ol ConCat.C                              *
  46.  *                                                                     *
  47.  ***********************************************************************/
  48.  
  49. #include <stdio.h>
  50.  
  51. void CheckLine(void);
  52. void main (void)
  53. {
  54.   unsigned char ucMyChar;
  55.   FILE *fp;
  56.  
  57.   fp = freopen ("", "rb", stdin);
  58.   fp = freopen ("", "wb", stdout);
  59.  
  60.   while ((ucMyChar = (unsigned char) _fgetchar()) != '\xFF')
  61.     switch (ucMyChar)
  62.     {
  63.       case '\x0D' : 
  64.         CheckLine();
  65.         break;
  66.       default :
  67.         _fputchar (ucMyChar);
  68.         break;
  69.     }
  70. }
  71.  
  72. void CheckLine(void)
  73. {
  74.   unsigned char ucIndex;
  75.   unsigned char ucIndex2;
  76.   unsigned char ucMyChar;
  77.   unsigned char ucHoldIt[30];
  78.  
  79.   ucHoldIt[0] = '\x0D';
  80.   ucHoldIt[1] = (unsigned char) _fgetchar(); /* read the '\10' */
  81.   ucIndex = 1;
  82.   while ((ucMyChar = (unsigned char) _fgetchar()) != '\xFF')
  83.   {
  84.     ucHoldIt[++ucIndex] = ucMyChar;
  85.     switch (ucMyChar)
  86.     {
  87.       case ' ' : 
  88.         if (ucIndex == 29) return;
  89.         break;
  90.       default :
  91.         for (ucIndex2 = 0; ucIndex2 <= ucIndex; ucIndex2++)
  92.           _fputchar (ucHoldIt[ucIndex2]);
  93.         return;
  94.         break;
  95.     }
  96.   }
  97.   for (ucIndex2 = 0; ucIndex2 <= ucIndex; ucIndex2++)
  98.     _fputchar (ucHoldIt[ucIndex2]);
  99.   return;
  100. }
  101.