home *** CD-ROM | disk | FTP | other *** search
- /*
- * usage: ebc_asc ebcdic_input ascii_output
- *
- * EBC_ASC Converts an EBCDIC file to ASCII. EBCDIC (Extended Binary
- * Coded Decimal Interchange Code) data is commonly produced
- * by IBM mainframe computers. ASCII (American Standard Code
- * for Information Interchange) is used on personal computers
- * and computers produced by the majority of manufacturers.
- *
- * input: Any EBCDIC file
- *
- * output: ASCII equivalent
- *
- * writeup: MIR TUTORIAL ONE, topic 4
- *
- * Written: Douglas Lowry Feb 17 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>
-
- #define repeat for(;;)
- #define MAX_BYTES 2048
-
- /*
- * declarations
- */
-
- typedef enum _bool
- { FALSE = 0, TRUE = 1 } Bool;
-
- void Usage_(), process();
- char *Cmdname_() { return( "ebc_asc" ); }
-
- /*
- * MAIN
- */
-
- main( argc, argv )
- int argc;
- char **argv;
- {
- FILE *fp, *fp_out ;
- char c10 ;
-
- if( argc != 3 )
- Usage_() ;
- c10 = argv[1][0] ;
- if( c10 == '-' || c10 == '/' || c10 == '?' )
- Usage_() ;
-
- if(( fp = fopen( argv[1], "rb" )) == NULL )
- {
- fprintf( stderr, "\nUnable to open file %s.\n", argv[1] );
- Usage_();
- }
-
- if(( fp_out = fopen( argv[2], "wb" )) == NULL )
- {
- fprintf( stderr, "\nUnable to open file %s.\n", argv[2] );
- Usage_();
- }
-
- process( fp, fp_out ) ;
-
- fclose( fp );
- fclose( fp_out );
- exit( 0 );
- }
- /*
- * Usage
- */
- void
- Usage_()
- {
- fprintf( stderr,
- "\nUsage: %s ebcdic_input ascii_output\n\n\
- Converts an EBCDIC file to ASCII. EBCDIC (Extended Binary\n\
- Coded Decimal Interchange Code) data is commonly produced\n\
- by IBM mainframe computers. ASCII (American Standard Code\n",
- Cmdname_() );
- fprintf( stderr,
- " for Information Interchange) is used on personal computers\n\
- and computers produced by the majority of manufacturers.\n\n\
- input: Any EBCDIC file\n\n\
- output: ASCII equivalent\n\n\
- writeup: MIR TUTORIAL ONE, topic 4\n\n" ) ;
- exit( 1 ) ;
- }
- /*
- * PROCESS
- */
- void
- process( fp_in, fp_out )
- FILE *fp_in, *fp_out ;
- {
- short table[ 256 ] = {
- 0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15,
- 16, 17, 18, 19,157,133, 8,135, 24, 25,146,143, 28, 29, 30, 31,
- 128,129,130,131,132, 10, 23, 27,136,137,138,139,140, 5, 6, 7,
- 144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26,
- 32,160,161,162,163,164,165,166,167,168, 91, 46, 60, 40, 43, 33,
- 38,169,170,171,172,173,174,175,176,177, 93, 36, 42, 41, 59, 94,
- 45, 47,178,179,180,181,182,183,184,185,124, 44, 37, 95, 62, 63,
- 186,187,188,189,190,191,192,193,194, 96, 58, 35, 64, 39, 61, 34,
- 195, 97, 98, 99,100,101,102,103,104,105,196,197,198,199,200,201,
- 202,106,107,108,109,110,111,112,113,114,203,204,205,206,207,208,
- 209,126,115,116,117,118,119,120,121,122,210,211,212,213,214,215,
- 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,
- 123, 65, 66, 67, 68, 69, 70, 71, 72, 73,232,233,234,235,236,237,
- 125, 74, 75, 76, 77, 78, 79, 80, 81, 82,238,239,240,241,242,243,
- 92,159, 83, 84, 85, 86, 87, 88, 89, 90,244,245,246,247,248,249,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,250,251,252,253,254,255 } ;
-
- unsigned char buf[ MAX_BYTES ],
- out;
- int len, i ;
-
- while(( len = fread( buf, sizeof( char ), MAX_BYTES, fp_in )) > 0 )
- {
- for( i = 0; i < len ; i++ )
- {
- out = table[ buf[ i ] ];
- if( fputc( out, fp_out ) != out )
- {
- fprintf( stderr, "FATAL... Unable to write.\n\n" ) ;
- exit( 1 ) ;
- }
- }
- }
-
- return ;
- }