Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
8.0 KiB

  1. /************************************************************************/
  2. /* */
  3. /* RCPP - Resource Compiler Pre-Processor for NT system */
  4. /* */
  5. /* MAIN.C - Main Program */
  6. /* */
  7. /* 27-Nov-90 w-BrianM Update for NT from PM SDK RCPP */
  8. /* */
  9. /************************************************************************/
  10. #include <windows.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "rcpptype.h"
  15. #include "rcppdecl.h"
  16. #include "rcppext.h"
  17. #include "grammar.h"
  18. #include "getflags.h"
  19. #ifdef DBCS
  20. #include "charmap.h"
  21. #endif // DBCS
  22. /************************************************************************/
  23. /* Global Varialbes */
  24. /************************************************************************/
  25. char *Unknown = NULL; /* holder for bad flags */
  26. int Argc;
  27. char **Argv;
  28. /************************************************************************/
  29. /* Local Function Prototypes */
  30. /************************************************************************/
  31. char *nextword(void);
  32. void __cdecl main(int, char **);
  33. void to_human(void);
  34. BOOL WINAPI Handler(ULONG CtrlType);
  35. struct subtab Ztab[] = {
  36. 'a', UNFLAG, &Extension,
  37. 'e', FLAG, &Extension,
  38. 'E', FLAG, &Ehxtension,
  39. 'i', FLAG, &Symbolic_debug,
  40. 'g', FLAG, &Out_funcdef,
  41. 'p', FLAG, &Cmd_pack_size,
  42. 'I', FLAG, &Inteltypes,
  43. 'c', FLAG, &ZcFlag,
  44. 0, 0, 0,
  45. };
  46. struct cmdtab cmdtab[] = {
  47. "-pc#", (char *)&Path_chars, 1, STRING,
  48. "-pf", (char *)&NoPasFor, 1, FLAG,
  49. "-C", (char *)&Cflag, 1, FLAG,
  50. "-CP#", (char *)&gpszNLSoptions, 1, STRING,
  51. "-D#", (char *)&Defs, 1, PSHSTR,
  52. "-E", (char *)&Eflag, 1, FLAG,
  53. "-I#", (char *)&Includes, 1, PSHSTR,
  54. "-P", (char *)&Pflag, 1, FLAG,
  55. "-f", (char *)&Input_file, 1, STRING,
  56. "-g", (char *)&Output_file, 1, STRING,
  57. "-J", (char *)&Jflag, 1, FLAG,
  58. "-Zp", (char *)&Cmd_pack_size, 1, FLAG,
  59. "-Zp#", (char *)&Cmd_pack_size, 1, NUMBER,
  60. "-Z*", (char *)Ztab, 1, SUBSTR,
  61. "-Oi", (char *)&Cmd_intrinsic, 1, FLAG,
  62. "-Ol", (char *)&Cmd_loop_opt, 1, FLAG,
  63. "-db#", (char *)&Debug, 1, STRING,
  64. "-ef#", (char *)&ErrFilName, 1, STRING,
  65. "-il#", (char *)&Basename, 1, STRING,
  66. "-xc", (char *)&Cross_compile, 1, FLAG,
  67. "-H", (char *)&HugeModel, 1, FLAG,
  68. "-V#", (char *)&Version, 1, STRING,
  69. "-Gs", (char *)&Cmd_stack_check, 1, UNFLAG,
  70. "-Gc", (char *)&Plm, 1, FLAG,
  71. "-char#", (char *)&Char_align, 1, NUMBER,
  72. "-A#", (char *)&A_string, 1, STRING,
  73. "-Q#", (char *)&Q_string, 1, STRING,
  74. "-Fs", (char *)&Srclist, 1, FLAG,
  75. "-R", (char *)&Rflag, 1, FLAG,
  76. "*", (char *)&Unknown, 0, STRING,
  77. 0, 0, 0, 0,
  78. };
  79. /************************************************************************/
  80. /* nextword - */
  81. /************************************************************************/
  82. char *nextword(void)
  83. {
  84. return((--Argc > 0) ? (*++Argv) : 0);
  85. }
  86. #ifdef DBCS
  87. /************************************************************************/
  88. /* vReConfigureLeadByteInfo - */
  89. /************************************************************************/
  90. void vReConfigureLeadByteInfo( unsigned int uiCodePage )
  91. {
  92. CPINFO CPInfo;
  93. PUCHAR pLeadByte;
  94. BYTE i;
  95. /* Following instruction should be success */
  96. /* because CodePage should be checked by RC.exe */
  97. GetCPInfo( uiCodePage , &CPInfo );
  98. /* Fill Charmap table with LX_LEADBYTE */
  99. pLeadByte = CPInfo.LeadByte;
  100. while( *pLeadByte != 0 && *(pLeadByte+1) != 0 ) {
  101. for( i = *pLeadByte ; i <= *(pLeadByte+1) ; i++ ) {
  102. Charmap[i] = LX_LEADBYTE;
  103. }
  104. pLeadByte += 2;
  105. }
  106. }
  107. #ifdef HIVEPP
  108. void vReConfigureCharTable( void )
  109. {
  110. Charmap[0x40] = LX_ID;
  111. Charmap[0x60] = LX_ID;
  112. }
  113. #endif // HIVEPP
  114. #endif // DBCS
  115. /************************************************************************/
  116. /* main - */
  117. /************************************************************************/
  118. void __cdecl main(int argc, char **argv)
  119. {
  120. Argc = argc;
  121. Argv = argv;
  122. while(crack_cmd(cmdtab, nextword(), nextword, 0)) ;
  123. #ifdef DBCS
  124. {
  125. int CodePage;
  126. // To modify charmap info
  127. if( gpszNLSoptions != NULL )
  128. CodePage = atoi( gpszNLSoptions );
  129. else
  130. CodePage = GetACP();
  131. #ifdef FIREWALLS
  132. fprintf( stderr , "RCPP:CodePage - %s - %d \n",gpszNLSoptions , CodePage );
  133. #endif
  134. vReConfigureLeadByteInfo(CodePage);
  135. }
  136. #endif // DBCS
  137. #ifdef DBCS
  138. #ifdef HIVEPP
  139. vReConfigureCharTable();
  140. #endif // HIVEPP
  141. #endif // DBCS
  142. if(Unknown) {
  143. Msg_Temp = GET_MSG (1007);
  144. SET_MSG (Msg_Text, Msg_Temp, Unknown, "c1");
  145. fatal(1007); /* unknown flag */
  146. }
  147. if( ! Input_file) {
  148. Msg_Temp = GET_MSG (1008);
  149. SET_MSG (Msg_Text, Msg_Temp);
  150. fatal(1008); /* no input file specified */
  151. }
  152. if( ! Output_file) {
  153. Msg_Temp = GET_MSG (1011);
  154. SET_MSG (Msg_Text, Msg_Temp);
  155. fatal(1011); /* no input file specified */
  156. }
  157. Prep = TRUE;
  158. if( !Eflag && !Pflag ) {
  159. Eflag = TRUE;
  160. }
  161. strncpy(Filename,Input_file,128);
  162. SetConsoleCtrlHandler(Handler, TRUE);
  163. p0_init(Input_file, Output_file, &Defs);
  164. to_human();
  165. SetConsoleCtrlHandler(Handler, FALSE);
  166. if( Prep_ifstack >= 0 ) {
  167. Msg_Temp = GET_MSG (1022);
  168. SET_MSG (Msg_Text, Msg_Temp);
  169. fatal(1022); /* expected #endif */
  170. }
  171. exit(Nerrors);
  172. }
  173. BOOL WINAPI Handler(ULONG CtrlType)
  174. {
  175. /*
  176. ** Unreferenced
  177. */
  178. (void)CtrlType;
  179. /* Close ALL files. */
  180. _fcloseall();
  181. exit(1);
  182. return 1;
  183. }
  184. /************************************************************************/
  185. /* to_human : outputs preprocessed text in human readable form. */
  186. /************************************************************************/
  187. void to_human(void)
  188. {
  189. PCHAR value;
  190. for(;;) {
  191. switch(yylex()) {
  192. case 0:
  193. return;
  194. case L_NOTOKEN:
  195. break;
  196. default:
  197. if (Basic_token == 0) {
  198. Msg_Temp = GET_MSG(1068);
  199. SET_MSG(Msg_Text, Msg_Temp);
  200. fatal(1068);
  201. }
  202. value = Tokstrings[Basic_token - L_NOTOKEN].k_text;
  203. fwrite(value, strlen(value), 1, OUTPUTFILE);
  204. break;
  205. }
  206. }
  207. }