mktables.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. */
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #ifndef NORCSID
  11. static char rcs_id[] = "$Id$" ;
  12. #endif
  13. char *fname = 0 ;
  14. char dname[200] ;
  15. char *tail ;
  16. FILE *intab ;
  17. FILE *dmach ;
  18. int offset ;
  19. main(argc,argv) char **argv ; {
  20. register i ;
  21. start(argv[1]) ;
  22. for ( i=2 ; i<argc ; i++ ) {
  23. fname= argv[i] ;
  24. readm() ;
  25. }
  26. stop(argc>2) ;
  27. return 0 ;
  28. }
  29. start(dir) char *dir ; {
  30. tail= dname ;
  31. while ( *dir ) {
  32. *tail++ = *dir ++ ;
  33. }
  34. if ( tail!=dname ) *tail++= '/' ;
  35. offset=0 ;
  36. intab= fopen("intable.c","w");
  37. dmach= fopen("dmach.c","w");
  38. if ( intab==NULL || dmach==NULL ) {
  39. fprintf(stderr,"Couln't create output file(s)\n");
  40. exit ( 1) ;
  41. }
  42. fprintf(dmach,"#include \"dmach.h\"\n\ndmach\tmassoc[] = {\n") ;
  43. fprintf(intab,"char intable[] = {\n") ;
  44. }
  45. stop(filled) {
  46. fprintf(dmach,"\t{\"\",\t-1\t}\n} ;\n") ;
  47. if ( !filled ) fprintf(intab,"\t0\n") ;
  48. fprintf(intab,"\n} ;\n") ;
  49. fclose(dmach); fclose(intab) ;
  50. }
  51. FILE *do_open(file) char *file ; {
  52. FILE *fd;
  53. strcpy(tail,file) ;
  54. strcat(tail,"/");
  55. strcat(tail,"descr");
  56. if ((fd = fopen(dname,"r")) != NULL) return fd;
  57. strcpy(tail,"descr/");
  58. strcat(tail,file);
  59. return fopen(dname,"r");
  60. }
  61. readm() {
  62. register int i ;
  63. register int token ;
  64. register FILE *in ;
  65. in=do_open(fname) ;
  66. if ( in==NULL ) {
  67. fprintf(stderr,"Cannot open %s\n",fname) ;
  68. return ;
  69. }
  70. i=0 ;
  71. fprintf(dmach,"\t{\"%s\",\t%d\t},\n",fname,offset) ;
  72. fprintf(intab,"\n/* %s */\n\t",fname) ;
  73. for (;;) {
  74. token=getc(in) ;
  75. offset++ ;
  76. if ( ++i == 10 ) {
  77. fprintf(intab,"\n\t") ;
  78. i=0 ;
  79. } else {
  80. fprintf(intab," ") ;
  81. }
  82. if ( !isascii(token) || !(isprint(token) || isspace(token)) ){
  83. if ( token!=EOF ) {
  84. fprintf(stderr,"warning: non-ascii in %s\n",fname) ;
  85. fprintf(intab,"%4d,",token) ;
  86. } else {
  87. fprintf(intab," 0,",token) ;
  88. break ;
  89. }
  90. } else if ( isprint(token) ) {
  91. switch ( token ) {
  92. case '\'': fprintf(intab,"'\\''") ; break ;
  93. case '\\': fprintf(intab,"'\\\\'") ; break ;
  94. default: fprintf(intab," '%c'",token) ; break ;
  95. }
  96. } else switch ( token ) {
  97. case '\n' : fprintf(intab,"'\\n'") ; break ;
  98. case '\t' : fprintf(intab,"'\\t'") ; break ;
  99. case '\r' : fprintf(intab,"'\\r'") ; break ;
  100. case '\f' : fprintf(intab,"'\\f'") ; break ;
  101. case ' ' : fprintf(intab," ' '") ; break ;
  102. default : fprintf(stderr,"warning: unrec. %d\n",
  103. token) ;
  104. fprintf(intab,"%4d",token) ;
  105. break ;
  106. }
  107. fprintf(intab,",") ;
  108. }
  109. fclose(in) ;
  110. }