lin2txt.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  3. * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
  4. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  5. */
  6. /*$Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/lin2txt.c,v 1.1 1994/10/21 20:52:11 jutta Exp $*/
  7. #include <stdio.h>
  8. #include "gsm.h"
  9. #include "proto.h"
  10. char * pname;
  11. int debug = 0;
  12. int verbosity = 0;
  13. int error = 0;
  14. usage P0()
  15. {
  16. fprintf(stderr, "Usage: %s [-v] [files...]\n", pname);
  17. exit(1);
  18. }
  19. void process P2((f, filename), FILE * f, char * filename)
  20. {
  21. short source[160];
  22. int cc, j, k;
  23. gsm r;
  24. if (!(r = gsm_create())) {
  25. perror("gsm_create");
  26. error = 1;
  27. return ;
  28. }
  29. gsm_option(r, GSM_OPT_VERBOSE, &verbosity);
  30. for (;;) {
  31. if ((cc = fread((char *)source, 1, sizeof(source), f)) == 0) {
  32. gsm_destroy(r);
  33. #ifdef COUNT_OVERFLOW
  34. dump_overflow(stderr);
  35. #endif
  36. return;
  37. }
  38. printf("{\t");
  39. for (j = 0; j < 4; j++) {
  40. printf("{\t");
  41. for (k = 0; k < 40; k++) {
  42. printf("%d", (int)source[ j * 40 + k ]);
  43. if (k < 39) {
  44. printf(", ");
  45. if (k % 4 == 3) printf("\n\t\t");
  46. } else {
  47. printf("\t}");
  48. if (j == 3) printf("\t},\n");
  49. else printf(",\n\t");
  50. }
  51. }
  52. }
  53. }
  54. }
  55. main P2((ac, av), int ac, char ** av)
  56. {
  57. int opt;
  58. extern char * optarg;
  59. extern int optind;
  60. FILE * f;
  61. if (!(pname = av[0])) pname = "inp2txt";
  62. while ((opt = getopt(ac, av, "v")) != EOF) switch (opt) {
  63. case 'v': verbosity++; break;
  64. default: usage();
  65. }
  66. ac -= optind;
  67. av += optind;
  68. if (!ac) process(stdin, "*stdin*");
  69. else for (; *av; av++) {
  70. if (!(f = fopen(*av, "r"))) perror(*av);
  71. else {
  72. process(f, *av);
  73. fclose(f);
  74. }
  75. }
  76. exit(error);
  77. }