PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/brlcad/tags/rel-7-10-2/src/util/plstat.c

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git
C | 287 lines | 208 code | 37 blank | 42 comment | 27 complexity | f27c1e7033ab784ca57b63aee438d3c2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, LGPL-2.1, Apache-2.0, AGPL-3.0, LGPL-3.0, GPL-3.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, 0BSD, BSD-3-Clause
  1. /* P L S T A T . C
  2. * BRL-CAD
  3. *
  4. * Copyright (c) 1990-2007 United States Government as represented by
  5. * the U.S. Army Research Laboratory.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * version 2.1 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this file; see the file named COPYING for more
  18. * information.
  19. */
  20. /** @file plstat.c
  21. *
  22. * Print statistics about a Plot3(5) format file.
  23. *
  24. * Author -
  25. * Phillip Dykstra
  26. *
  27. */
  28. #ifndef lint
  29. static const char RCSid[] = "@(#)$Header$ (BRL)";
  30. #endif
  31. #include "common.h"
  32. #include <stdio.h>
  33. #ifdef HAVE_STRING_H
  34. #include <string.h>
  35. #else
  36. #include <strings.h>
  37. #endif
  38. #include <unistd.h>
  39. #include <stdlib.h>
  40. #include "common.h"
  41. #include "machine.h"
  42. #include "bu.h"
  43. #define TBAD 0 /* no such command */
  44. #define TNONE 1 /* no arguments */
  45. #define TSHORT 2 /* Vax 16-bit short */
  46. #define TIEEE 3 /* IEEE 64-bit floating */
  47. #define TCHAR 4 /* unsigned chars */
  48. #define TSTRING 5 /* linefeed terminated string */
  49. #define COORD 0x10 /* these values are coordinates */
  50. struct uplot {
  51. int targ; /* type of args */
  52. int narg; /* number or args */
  53. char *desc; /* description */
  54. };
  55. struct uplot uerror = { 0, 0, 0 };
  56. struct uplot letters[] = {
  57. /*A*/ { 0, 0, 0 },
  58. /*B*/ { 0, 0, 0 },
  59. /*C*/ { TCHAR, 3, "color" },
  60. /*D*/ { 0, 0, 0 },
  61. /*E*/ { 0, 0, 0 },
  62. /*F*/ { TNONE, 0, "flush" },
  63. /*G*/ { 0, 0, 0 },
  64. /*H*/ { 0, 0, 0 },
  65. /*I*/ { 0, 0, 0 },
  66. /*J*/ { 0, 0, 0 },
  67. /*K*/ { 0, 0, 0 },
  68. /*L*/ { TSHORT, 6, "3line" },
  69. /*M*/ { TSHORT, 3, "3move" },
  70. /*N*/ { TSHORT, 3, "3cont" },
  71. /*O*/ { TIEEE, 3, "d_3move" },
  72. /*P*/ { TSHORT, 3, "3point" },
  73. /*Q*/ { TIEEE, 3, "d_3cont" },
  74. /*R*/ { 0, 0, 0 },
  75. /*S*/ { TSHORT, 6, "3space" },
  76. /*T*/ { 0, 0, 0 },
  77. /*U*/ { 0, 0, 0 },
  78. /*V*/ { TIEEE, 6, "d_3line" },
  79. /*W*/ { TIEEE, 6, "d_3space" },
  80. /*X*/ { TIEEE, 3, "d_3point" },
  81. /*Y*/ { 0, 0, 0 },
  82. /*Z*/ { 0, 0, 0 },
  83. /*[*/ { 0, 0, 0 },
  84. /*\*/ { 0, 0, 0 },
  85. /*]*/ { 0, 0, 0 },
  86. /*^*/ { 0, 0, 0 },
  87. /*_*/ { 0, 0, 0 },
  88. /*`*/ { 0, 0, 0 },
  89. /*a*/ { TSHORT, 6, "arc" },
  90. /*b*/ { 0, 0, 0 },
  91. /*c*/ { TSHORT, 3, "circle" },
  92. /*d*/ { 0, 0, 0 },
  93. /*e*/ { TNONE, 0, "erase" },
  94. /*f*/ { TSTRING, 1, "linmod" },
  95. /*g*/ { 0, 0, 0 },
  96. /*h*/ { 0, 0, 0 },
  97. /*i*/ { TIEEE, 3, "d_circle" },
  98. /*j*/ { 0, 0, 0 },
  99. /*k*/ { 0, 0, 0 },
  100. /*l*/ { TSHORT, 4, "line" },
  101. /*m*/ { TSHORT, 2, "move" },
  102. /*n*/ { TSHORT, 2, "cont" },
  103. /*o*/ { TIEEE, 2, "d_move" },
  104. /*p*/ { TSHORT, 2, "point" },
  105. /*q*/ { TIEEE, 2, "d_cont" },
  106. /*r*/ { TIEEE, 6, "d_arc" },
  107. /*s*/ { TSHORT, 4, "space" },
  108. /*t*/ { TSTRING, 1, "label" },
  109. /*u*/ { 0, 0, 0 },
  110. /*v*/ { TIEEE, 4, "d_line" },
  111. /*w*/ { TIEEE, 4, "d_space" },
  112. /*x*/ { TIEEE, 2, "d_point" },
  113. /*y*/ { 0, 0, 0 },
  114. /*z*/ { 0, 0, 0 }
  115. };
  116. int verbose;
  117. long counts['z'-'A'+1]; /* for counting command usage */
  118. FILE *fp;
  119. void outchar(int n);
  120. void outstring(int n);
  121. void outshort(int n);
  122. void outfloat(int n);
  123. static char usage[] = "\
  124. Usage: pldebug [-v] [unix_plot]\n";
  125. int
  126. getshort(void)
  127. {
  128. register long v, w;
  129. v = getc(fp);
  130. v |= (getc(fp)<<8); /* order is important! */
  131. /* worry about sign extension - sigh */
  132. if( v <= 0x7FFF ) return(v);
  133. w = -1;
  134. w &= ~0x7FFF;
  135. return( w | v );
  136. }
  137. int
  138. main(int argc, char **argv)
  139. {
  140. register int c;
  141. struct uplot *up;
  142. int i;
  143. while( argc > 1 ) {
  144. if( strcmp(argv[1], "-v") == 0 ) {
  145. verbose++;
  146. } else
  147. break;
  148. argc--;
  149. argv++;
  150. }
  151. if( argc == 2 ) {
  152. if( (fp = fopen(argv[1],"r")) == NULL ) {
  153. perror( "pldebug" );
  154. exit( 1 );
  155. }
  156. } else {
  157. fp = stdin;
  158. if( argc > 1 || isatty(fileno(stdin)) ) {
  159. fprintf( stderr, usage );
  160. exit( 1 );
  161. }
  162. }
  163. while( (c = getc(fp)) != EOF ) {
  164. /* look it up */
  165. if( c < 'A' || c > 'z' ) {
  166. up = &uerror;
  167. } else {
  168. up = &letters[ c - 'A' ];
  169. }
  170. if( up->targ == TBAD ) {
  171. fprintf( stderr, "Bad command '%c' (0x%02x)\n", c, c );
  172. continue;
  173. }
  174. counts[ c - 'A' ]++;
  175. if( up->narg > 0 ) {
  176. switch( up->targ ) {
  177. case TNONE:
  178. break;
  179. case TSHORT:
  180. outshort( up->narg );
  181. break;
  182. case TIEEE:
  183. outfloat( up->narg );
  184. break;
  185. case TSTRING:
  186. outstring( up->narg );
  187. break;
  188. case TCHAR:
  189. outchar( up->narg );
  190. break;
  191. }
  192. }
  193. if( verbose )
  194. printf( " %s", up->desc );
  195. }
  196. /* write command usage summary */
  197. for( i = 0; i < 'z'-'A'+1; i++ ) {
  198. if( counts[i] != 0 ) {
  199. fprintf( stderr, "%s %ld\n", letters[i].desc, counts[i] );
  200. }
  201. }
  202. return 0;
  203. }
  204. void
  205. outchar(int n)
  206. {
  207. int i;
  208. for( i = 0; i < n; i++ ) {
  209. (void)getc(fp);
  210. /*printf("%3d", c );*/
  211. }
  212. }
  213. void
  214. outstring(int n)
  215. {
  216. int c;
  217. while( (c = getc(fp)) != '\n' && c != EOF )
  218. ;
  219. /*putchar(c);*/
  220. }
  221. void
  222. outshort(int n)
  223. {
  224. int i;
  225. for( i = 0; i < n; i++ ) {
  226. (void)getshort();
  227. }
  228. }
  229. void
  230. outfloat(int n)
  231. {
  232. int i;
  233. unsigned char in[8*16];
  234. double out[16];
  235. fread( in, 8, n, fp );
  236. ntohd( (unsigned char *)out, in, n );
  237. for( i = 0; i < n; i++ ) {
  238. /*printf("%g", out[i] );*/
  239. ;
  240. }
  241. }
  242. /*
  243. * Local Variables:
  244. * mode: C
  245. * tab-width: 8
  246. * c-basic-offset: 4
  247. * indent-tabs-mode: t
  248. * End:
  249. * ex: shiftwidth=4 tabstop=8
  250. */