mktables.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. void start(char *dir);
  20. void stop(int filled);
  21. void readm();
  22. int main(int argc, char *argv[])
  23. {
  24. int i ;
  25. start(argv[1]) ;
  26. for ( i=2 ; i<argc ; i++ ) {
  27. fname= argv[i] ;
  28. readm() ;
  29. }
  30. stop(argc>2) ;
  31. return 0 ;
  32. }
  33. void start(char *dir)
  34. {
  35. tail= dname ;
  36. while ( *dir ) {
  37. *tail++ = *dir ++ ;
  38. }
  39. if ( tail!=dname ) *tail++= '/' ;
  40. offset=0 ;
  41. intab= fopen("intable.c","w");
  42. dmach= fopen("dmach.c","w");
  43. if ( intab==NULL || dmach==NULL ) {
  44. fprintf(stderr,"Couln't create output file(s)\n");
  45. exit ( 1) ;
  46. }
  47. fprintf(dmach,"#include \"dmach.h\"\n\ndmach\tmassoc[] = {\n") ;
  48. fprintf(intab,"char intable[] = {\n") ;
  49. }
  50. void stop(int filled)
  51. {
  52. fprintf(dmach,"\t{\"\",\t-1\t}\n} ;\n") ;
  53. if ( !filled ) fprintf(intab,"\t0\n") ;
  54. fprintf(intab,"\n} ;\n") ;
  55. fclose(dmach); fclose(intab) ;
  56. }
  57. FILE *do_open(char *file)
  58. {
  59. FILE *fd;
  60. strcpy(tail,file) ;
  61. strcat(tail,"/");
  62. strcat(tail,"descr");
  63. if ((fd = fopen(dname,"r")) != NULL) return fd;
  64. strcpy(tail,"descr/");
  65. strcat(tail,file);
  66. return fopen(dname,"r");
  67. }
  68. void readm()
  69. {
  70. register int i ;
  71. register int token ;
  72. register FILE *in ;
  73. in=do_open(fname) ;
  74. if ( in==NULL ) {
  75. fprintf(stderr,"Cannot open %s\n",fname) ;
  76. return ;
  77. }
  78. i=0 ;
  79. fprintf(dmach,"\t{\"%s\",\t%d\t},\n",fname,offset) ;
  80. fprintf(intab,"\n/* %s */\n\t",fname) ;
  81. for (;;) {
  82. token=getc(in) ;
  83. offset++ ;
  84. if ( ++i == 10 ) {
  85. fprintf(intab,"\n\t") ;
  86. i=0 ;
  87. } else {
  88. fprintf(intab," ") ;
  89. }
  90. if ( !isascii(token) || !(isprint(token) || isspace(token)) ){
  91. if ( token!=EOF ) {
  92. fprintf(stderr,"warning: non-ascii in %s\n",fname) ;
  93. fprintf(intab,"%4d,",token) ;
  94. } else {
  95. fprintf(intab," 0,");
  96. break ;
  97. }
  98. } else if ( isprint(token) ) {
  99. switch ( token ) {
  100. case '\'': fprintf(intab,"'\\''") ; break ;
  101. case '\\': fprintf(intab,"'\\\\'") ; break ;
  102. default: fprintf(intab," '%c'",token) ; break ;
  103. }
  104. } else switch ( token ) {
  105. case '\n' : fprintf(intab,"'\\n'") ; break ;
  106. case '\t' : fprintf(intab,"'\\t'") ; break ;
  107. case '\r' : fprintf(intab,"'\\r'") ; break ;
  108. case '\f' : fprintf(intab,"'\\f'") ; break ;
  109. case ' ' : fprintf(intab," ' '") ; break ;
  110. default : fprintf(stderr,"warning: unrec. %d\n",
  111. token) ;
  112. fprintf(intab,"%4d",token) ;
  113. break ;
  114. }
  115. fprintf(intab,",") ;
  116. }
  117. fclose(in) ;
  118. }