Mercurial > hg > aim92
comparison tools/atob.c @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5242703e91d3 |
---|---|
1 /* | |
2 atob (binary-to-ascii) conversion. | |
3 | |
4 Read ascii numbers from the input stream until eof. | |
5 Write each number on the stdout in the given type. | |
6 | |
7 Bugs: | |
8 1. When converting binary floats to ascii, and then back to binary, there | |
9 will be some difference between the binary files because the ascii | |
10 floats are printed with limited precision. | |
11 */ | |
12 | |
13 | |
14 #include <stdio.h> | |
15 #include <math.h> | |
16 #include "options.h" | |
17 | |
18 | |
19 char applic[] = "ascii to binary conversion." ; | |
20 | |
21 static char *helpstr, *debugstr, *shortstr, *intstr, *floatstr, *typestr ; | |
22 | |
23 static Options option[] = { | |
24 { "help" , "off" , &helpstr , "help" , DEBUG }, | |
25 { "debug" , "off" , &debugstr , "debugging" , DEBUG }, | |
26 { "type" , "short" , &typestr , "output data type" , VAL }, | |
27 { "short" , "off" , &shortstr , "data type" , STOG }, | |
28 { "int" , "off" , &intstr , "data type" , STOG }, | |
29 { "float" , "off" , &floatstr , "data type" , STOG }, | |
30 ( char * ) 0 } ; | |
31 | |
32 | |
33 int itype ; /* input datatype index */ | |
34 int otype ; /* output datatype index */ | |
35 | |
36 main(argc, argv) | |
37 int argc ; | |
38 char *argv[] ; | |
39 { | |
40 FILE *fp ; | |
41 float y ; | |
42 | |
43 fp = openopts( option,argc,argv ) ; | |
44 if ( !isoff( helpstr ) ) | |
45 helpopts( helpstr, argv[0], applic, option ) ; | |
46 | |
47 itype = typeindex( "ascii" ) ; | |
48 | |
49 if ( ( otype = typeindex( typestr ) ) < 0 ) { | |
50 fprintf( stderr, "atob: bad type [%s]\n", typestr ) ; | |
51 exit( 1 ) ; | |
52 } | |
53 | |
54 if ( ison( shortstr ) ) otype = 1 ; /* compatibility */ | |
55 else if ( ison( intstr ) ) otype = 2 ; | |
56 else if ( ison( floatstr ) ) otype = 3 ; | |
57 | |
58 while ( readitem( &y, itype, 1, fp ) ) | |
59 writeitem( &y, otype, 1, stdout ) ; | |
60 | |
61 fclose(fp); | |
62 } | |
63 | |
64 |