hsf2rc.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. hsf2RC
  3. Copyright (C) 2002 Loïc YHUEL (hwti)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. //#define WIN32_LEAN_AND_MEAN // Exclure les en-têtes Windows rarement utilisés
  17. #include <stdio.h>
  18. #include <io.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <malloc.h>
  22. void WriteInfo(char *str1,char *str2);
  23. FILE *os,*doorsos,*alias;
  24. bool MakeDB92INFO;
  25. char *(*table)[2000];
  26. int Highest=-1;
  27. int main(int argc, char *argv[])
  28. {
  29. _finddata_t data;
  30. long file, folder;
  31. FILE *f1,*db92;
  32. char dummy[100],dummy2[100],path[50];
  33. char * s,* c;
  34. int b;
  35. puts("Builds os.h, doorsos.h [and db92 rom_call info] from TIGCC sources\nhsf2RC [/db92]");
  36. if ((argc > 1) && (!(stricmp("/db92",argv[1])))) {
  37. MakeDB92INFO = true;
  38. if (!(table = (char*(*)[2000])calloc(2000,sizeof(char *)))) {
  39. puts("Out of memory");
  40. return 1;
  41. }
  42. db92 = fopen("Romcalls.bin","wt");
  43. }
  44. else MakeDB92INFO = false;
  45. folder = _findfirst("*.h",&data);
  46. if (folder == -1) {
  47. puts("No directory found. Run hsf2rc in doc\\system\\include directory of TIGCC sources.");
  48. return 1;
  49. }
  50. os = fopen("os.h","wt");
  51. doorsos = fopen("doorsos.h","wt");
  52. alias = fopen("db92_alias","a+t");
  53. do {
  54. if (!(data.attrib && _A_SUBDIR)) continue;
  55. strcpy(path,data.name);
  56. strcat(path,"\\");
  57. c = strchr(path,0);
  58. strcpy(c,"*.hsf");
  59. file = _findfirst(path,&data);
  60. if (file == -1) continue;
  61. do {
  62. strcpy(c,data.name);
  63. f1 = fopen(path, "rt");
  64. do {
  65. if (!fgets(dummy,100,f1)) goto nextfile;
  66. } while (strncmp("Name=",dummy,5));
  67. do {
  68. if (!fgets(dummy2,100,f1)) goto nextfile;
  69. } while (strcmp("[ROM Call]\n",dummy2));
  70. fgets(dummy2,100,f1);
  71. *strchr(dummy+5,'\n') = 0;
  72. WriteInfo(dummy+5,dummy2);
  73. nextfile :
  74. fclose(f1);
  75. } while (!_findnext(file,&data));
  76. _findclose(file);
  77. } while (!_findnext(folder,&data));
  78. _findclose(folder);
  79. if (f1 = fopen("notdefinedrom_calls","rt")) {
  80. while (fgets(dummy,100,f1)) {
  81. if (dummy[0] == ';') continue;
  82. *(s = strchr(dummy,' ')) = 0;
  83. WriteInfo(dummy,s+1);
  84. }
  85. fclose(f1);
  86. }
  87. if (f1 = fopen("os.h.end","rt")) {
  88. while (fgets(dummy,100,f1)) fputs(dummy,os);
  89. fclose(f1);
  90. }
  91. if (f1 = fopen("doorsos.h.end","rt")) {
  92. while (fgets(dummy,100,f1)) fputs(dummy,doorsos);
  93. fclose(f1);
  94. }
  95. fclose(os);
  96. fclose(doorsos);
  97. if (MakeDB92INFO) {
  98. for (b = 0;b <= Highest;b++) {
  99. if (!((*table)[b] == 0)) {
  100. fputs((*table)[b],db92);
  101. free((*table)[b]);
  102. }
  103. else printf("Warning : ROM_CALL %i not defined\n",b);
  104. fputc(0,db92);
  105. }
  106. f1 = fopen("romcalls.h","w");
  107. fprintf(f1,";Include file automatically generated by hsf2RC.\n"
  108. ";Copyright (C) 2002 Loïc YHUEL (hwti)\n"
  109. "RCNum equ %i\n"
  110. "ROM_CALLs_Names\n"
  111. " incbin romcalls.bin",b-1);
  112. fclose(f1);
  113. free(table);
  114. fclose(db92);
  115. }
  116. fclose(alias);
  117. return 0;
  118. }
  119. void WriteInfo(char *str1,char *str2)
  120. {
  121. int a,b;
  122. char dummy[100];
  123. str2 = strchr(str2,'$');
  124. fprintf(os,"%s\t\tequ\t%s",str1,str2);
  125. fprintf(doorsos,"doorsos::%s\tequ\t_ROM_CALL_%s",str1,str2 + 1);
  126. if (MakeDB92INFO) {
  127. str2 = strchr(str2,0) - 1;
  128. if (*str2 == '\n') str2--;
  129. a = 1;
  130. b = 0;
  131. while (1) {
  132. if ((*str2 >= '0') && (*str2 <= '9')) b += a * (*str2 - '0');
  133. else if ((*str2 >= 'A') && (*str2 <= 'F')) b += a * (*str2 - 'A' + 10);
  134. else break;
  135. a *= 16;
  136. str2--;
  137. }
  138. if (!((*table)[b] == NULL)) {
  139. if (alias) {
  140. rewind(alias);
  141. while (fgets(dummy,100,alias)) {
  142. if ((atoi(dummy) == b)) {
  143. if (*(strchr(dummy,' ')+1) == 'n') return;
  144. else goto overw;
  145. }
  146. }
  147. }
  148. printf("ROM_CALL %i is already named %s. Name it %s ?",b,(*table)[b],str1);
  149. do {
  150. a = getchar();
  151. if (a == 'n') {
  152. if (alias) fprintf(alias,"%i n\n",b);
  153. return;
  154. }
  155. } while (!(a == 'y'));
  156. if (alias) fprintf(alias,"%i y\n",b);
  157. }
  158. overw :
  159. if (!((*table)[b] = (char *)realloc((*table)[b],strlen(str1)+1))) {
  160. puts("Out of memory");
  161. exit(1);
  162. }
  163. strcpy((*table)[b],str1);
  164. if (b > Highest) Highest = b;
  165. }
  166. }