home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
concat.zip
/
ConCat.C
next >
Wrap
C/C++ Source or Header
|
1995-06-27
|
5KB
|
101 lines
/***********************************************************************
* *
* ConCat - concatenates multiple lines of file description in the *
* file ALLFILES.TXT downloaded from Pete Norloff's OS/2 *
* Shareware BBS. *
* *
* Input file format is expected to be a sequence of lines, some *
* of which begin with 29 spaces. ConCat removes any sequence of *
* CR/LF followed by 28 spaces, leaving the one space and the text *
* of this line following the text of the previous line. *
* *
* Pretty dumb algorithm (can you say 'brute-force?') but works *
* relatively fast. 11.6 seconds on a 486DX2-66 on ALLFILES.TXT *
* *
* This is definitely a filter, so use something like *
* *
* ConCat < AllFiles.Txt > AllFiles.Txt.Concat *
* *
* J. Daniel Ashton -- 06/27/95 Rev 1.0 *
* *
* Copyright (c) 1995 J. Daniel Ashton *
* *
* You are free to redistribute this code in its present format. *
* If you use this code in your program, please give appropriate *
* credit somewhere in your package, and please drop a note to me. *
* (I could use the ego boost!) *
* *
* If you see any bugs or design issues, please let me know--I'm *
* still growing in the language (as are most of us ;-) I'd like *
* to hear how you react to this program. *
* *
* jdashton@southern.edu *
* 72401,1667@compuserve.com *
* (615) 238-7111 x2319 days (Eastern Time) *
* (615) 559-1026 nights *
* *
* J. Daniel Ashton *
* PO Box 1327 *
* Collegedale, TN 37315-1327 *
* *
* Note: This executable was compiled with C Set++ v2.1, with the *
* following command-line. *
* *
* icc /W2 /Q /G4 /O /Ol ConCat.C *
* *
***********************************************************************/
#include <stdio.h>
void CheckLine(void);
void main (void)
{
unsigned char ucMyChar;
FILE *fp;
fp = freopen ("", "rb", stdin);
fp = freopen ("", "wb", stdout);
while ((ucMyChar = (unsigned char) _fgetchar()) != '\xFF')
switch (ucMyChar)
{
case '\x0D' :
CheckLine();
break;
default :
_fputchar (ucMyChar);
break;
}
}
void CheckLine(void)
{
unsigned char ucIndex;
unsigned char ucIndex2;
unsigned char ucMyChar;
unsigned char ucHoldIt[30];
ucHoldIt[0] = '\x0D';
ucHoldIt[1] = (unsigned char) _fgetchar(); /* read the '\10' */
ucIndex = 1;
while ((ucMyChar = (unsigned char) _fgetchar()) != '\xFF')
{
ucHoldIt[++ucIndex] = ucMyChar;
switch (ucMyChar)
{
case ' ' :
if (ucIndex == 29) return;
break;
default :
for (ucIndex2 = 0; ucIndex2 <= ucIndex; ucIndex2++)
_fputchar (ucHoldIt[ucIndex2]);
return;
break;
}
}
for (ucIndex2 = 0; ucIndex2 <= ucIndex; ucIndex2++)
_fputchar (ucHoldIt[ucIndex2]);
return;
}