tomwalters@0: /* tomwalters@0: atob (binary-to-ascii) conversion. tomwalters@0: tomwalters@0: Read ascii numbers from the input stream until eof. tomwalters@0: Write each number on the stdout in the given type. tomwalters@0: tomwalters@0: Bugs: tomwalters@0: 1. When converting binary floats to ascii, and then back to binary, there tomwalters@0: will be some difference between the binary files because the ascii tomwalters@0: floats are printed with limited precision. tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "options.h" tomwalters@0: tomwalters@0: tomwalters@0: char applic[] = "ascii to binary conversion." ; tomwalters@0: tomwalters@0: static char *helpstr, *debugstr, *shortstr, *intstr, *floatstr, *typestr ; tomwalters@0: tomwalters@0: static Options option[] = { tomwalters@0: { "help" , "off" , &helpstr , "help" , DEBUG }, tomwalters@0: { "debug" , "off" , &debugstr , "debugging" , DEBUG }, tomwalters@0: { "type" , "short" , &typestr , "output data type" , VAL }, tomwalters@0: { "short" , "off" , &shortstr , "data type" , STOG }, tomwalters@0: { "int" , "off" , &intstr , "data type" , STOG }, tomwalters@0: { "float" , "off" , &floatstr , "data type" , STOG }, tomwalters@0: ( char * ) 0 } ; tomwalters@0: tomwalters@0: tomwalters@0: int itype ; /* input datatype index */ tomwalters@0: int otype ; /* output datatype index */ tomwalters@0: tomwalters@0: main(argc, argv) tomwalters@0: int argc ; tomwalters@0: char *argv[] ; tomwalters@0: { tomwalters@0: FILE *fp ; tomwalters@0: float y ; tomwalters@0: tomwalters@0: fp = openopts( option,argc,argv ) ; tomwalters@0: if ( !isoff( helpstr ) ) tomwalters@0: helpopts( helpstr, argv[0], applic, option ) ; tomwalters@0: tomwalters@0: itype = typeindex( "ascii" ) ; tomwalters@0: tomwalters@0: if ( ( otype = typeindex( typestr ) ) < 0 ) { tomwalters@0: fprintf( stderr, "atob: bad type [%s]\n", typestr ) ; tomwalters@0: exit( 1 ) ; tomwalters@0: } tomwalters@0: tomwalters@0: if ( ison( shortstr ) ) otype = 1 ; /* compatibility */ tomwalters@0: else if ( ison( intstr ) ) otype = 2 ; tomwalters@0: else if ( ison( floatstr ) ) otype = 3 ; tomwalters@0: tomwalters@0: while ( readitem( &y, itype, 1, fp ) ) tomwalters@0: writeitem( &y, otype, 1, stdout ) ; tomwalters@0: tomwalters@0: fclose(fp); tomwalters@0: } tomwalters@0: tomwalters@0: