home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD2.mdf
/
doc
/
mir
/
debloc_a.c
< prev
next >
Wrap
Text File
|
1992-07-02
|
6KB
|
206 lines
/*
* Usage - debloc_a ASCII_blocked_file > unblocked_version
*
* DEBLOC_A Remove blocking, insert line feeds in ASCII blocked file.
*
* input: ASCII file with four byte inclusive line lengths at the
* beginning of every line, no line feeds at end.
*
* output: Same data with counts out, line feeds/carriage returns in.
*
* writeup: MIR TUTORIAL ONE, topic 9
*
* Written: Douglas Lowry May 11 92
* Copyright (C) 1992 Marpex Inc.
*
* The MIR (Mass Indexing and Retrieval) Tutorials explain detailed
* usage and co-ordination of the MIR family of programs to analyze,
* prepare and index databases (small through gigabyte size), and
* how to build integrated retrieval software around the MIR search
* engine. The fifth of the five MIR tutorial series explains how
* to extend indexing capability into leading edge search-related
* technologies. For more information, GO IBMPRO on CompuServe;
* MIR files are in the DBMS library. The same files are on the
* Canada Remote Systems BBS. A diskette copy of the Introduction
* is available by mail ($10 US... check, Visa or Mastercard);
* diskettes with Introduction, Tutorial ONE software and the
* shareware Tutorial ONE text cost $29. Shareware registration
* for a tutorial is also $29.
*
* E-mail...
* Compuserve 71431,1337
* Internet doug.lowry%canrem.com
* UUCP canrem!doug.lowry
* Others: doug.lowry@canrem.uucp
*
* FAX... 416 963-5677
*
* "Snail mail"... Douglas Lowry, Ph.D.
* Marpex Inc.
* 5334 Yonge Street, #1102
* North York, Ontario
* Canada M2N 6M2
*
* Related database consultation and preparation services are
* available through:
* Innotech Inc., 2001 Sheppard Avenue E., Suite #118,
* North York, Ontario Canada M2J 4Z7
* Tel. 416 492-3838 FAX 416 492-3843
*
* This program is free software; you may redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* (file 05LICENS) along with this program; if not, write to the
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX_BYTES 2048
#define repeat for(;;)
/*
* declarations
*/
typedef enum _bool
{ FALSE = 0, TRUE = 1 } Bool;
void Usage_(), process();
int get_data();
char *Cmdname_() { return( "debloc_a" ); }
static long int offset ;
/*
* MAIN -
*/
main( argc, argv )
int argc;
char **argv;
{
char c10 ;
FILE *fp ;
if( argc != 2 )
Usage_() ;
c10 = argv[1][0] ;
if( c10 == '/' || c10 == '-' || c10 == '?' )
Usage_() ;
if (( fp = fopen( argv[ 1 ], "r" )) == NULL )
{
fprintf( stderr, "Unable to open file %s\n", argv[ 1 ] );
Usage_() ;
}
process( fp );
fclose( fp );
exit( 0 );
}
/*
* Usage
*/
void
Usage_()
{
fprintf( stderr,
"\nUsage: %s ASCII_blocked_file > unblocked_version\n\n\
Remove blocking, insert line feeds in ASCII blocked file.\n\n\
input: ASCII file with four byte inclusive line lengths at the\n\
beginning of every line, no line feeds at end.\n\n",
Cmdname_() );
fprintf( stderr,
"output: Same data with counts out, line feeds/carriage returns in.\n\n\
writeup: MIR TUTORIAL ONE, topic 9\n\n" ) ;
exit( 1 ) ;
}
/*
* PROCESS -
*/
void
process( fp )
FILE *fp ;
{
char buf[ MAX_BYTES ] ;
int length; /* length of current line */
int j;
offset = 0 ;
while( ( length= get_data( fp, buf )) > -1 )
{
for( j= 0; j < length; j++ )
putchar( buf[ j ] );
if( putchar( '\n' ) != '\n' )
{
fprintf( stderr, "FATAL... Unable to write.\n\n" ) ;
exit( 1 ) ;
}
}
return;
}
/*
* GET_DATA
*/
int
get_data( fp, buf )
FILE *fp;
char buf[ MAX_BYTES ] ;
{
char lil[5];
int length, /* bytes in current line */
i;
lil[ 4 ] = '\0' ;
/* ...Read in the line size */
for( i = 0 ; i < 4 ; i++ )
{
if(( lil[i] = fgetc( fp )) == EOF )
return( -1 );
if( !isdigit( lil[i] ))
{
fprintf( stderr, "Line size out of sync at byte %ld\n",
offset ) ;
exit( 1 ) ;
}
}
length = atoi( lil ) - 4;
offset += 4;
/* Now load the data stream */
if ( length > MAX_BYTES )
{
fprintf( stderr, "Oversize line at byte %ld\n", offset );
exit( 1 ) ;
}
if ( fread( buf, sizeof(char), length, fp ) < length )
{
fprintf( stderr,"Failure reading line data starting at byte %ld\n",
offset );
exit( 1 ) ;
}
offset += length;
return( length );
}