UilCmd.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these librararies and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * @OSF_COPYRIGHT@
  25. * COPYRIGHT NOTICE
  26. * Copyright (c) 1990, 1991, 1992, 1993 Open Software Foundation, Inc.
  27. * ALL RIGHTS RESERVED (MOTIF). See the file named COPYRIGHT.MOTIF for
  28. * the full copyright text.
  29. */
  30. /*
  31. * HISTORY
  32. */
  33. #ifdef REV_INFO
  34. #ifndef lint
  35. static char rcsid[] = "$XConsortium: UilCmd.c /main/11 1995/07/14 09:32:29 drk $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. **++
  42. ** FACILITY:
  43. **
  44. ** User Interface Language Compiler (UIL)
  45. **
  46. ** ABSTRACT:
  47. **
  48. ** Command line interpreter for the
  49. **
  50. **--
  51. **/
  52. /*
  53. **
  54. ** INCLUDE FILES
  55. **
  56. **/
  57. #include "UilDefI.h"
  58. #include "UilCmdDef.h"
  59. /*
  60. **
  61. ** GLOBAL DECLARATIONS
  62. **
  63. **/
  64. externaldef(uil_comp_glbl) cmd_command_line_type Uil_cmd_z_command;
  65. /*
  66. **++
  67. ** FUNCTIONAL DESCRIPTION:
  68. **
  69. ** This procedure parses the command line and places the
  70. ** results of the parse in the global structure "Uil_cmd_z_command".
  71. **
  72. ** FORMAL PARAMETERS:
  73. **
  74. ** l_arg_count: number of command arguments
  75. ** rac_arg_value: array of pointers to null terminated character strings
  76. ** each of which is one of the command line arguments
  77. **
  78. ** IMPLICIT INPUTS:
  79. **
  80. ** none
  81. **
  82. ** IMPLICIT OUTPUTS:
  83. **
  84. ** Uil_cmd_z_command: respository for command line info
  85. **
  86. ** FUNCTION VALUE:
  87. **
  88. ** void
  89. **
  90. ** SIDE EFFECTS:
  91. **
  92. ** Uil_cmd_z_command is set
  93. **
  94. **--
  95. **/
  96. void cmd_decode_command_line( l_arg_count, rac_arg_value )
  97. int l_arg_count;
  98. char *rac_arg_value[ ];
  99. {
  100. static char *include_list [Uil_k_max_include_dir_count];
  101. int i;
  102. Uil_cmd_z_command.ac_source_file = NULL;
  103. Uil_cmd_z_command.ac_resource_file = NULL;
  104. Uil_cmd_z_command.ac_listing_file = NULL;
  105. Uil_cmd_z_command.include_dir_count = 0;
  106. Uil_cmd_z_command.ac_include_dir = (char **)include_list;
  107. Uil_cmd_z_command.v_resource_file = TRUE;
  108. Uil_cmd_z_command.v_listing_file = FALSE;
  109. Uil_cmd_z_command.v_show_machine_code = FALSE;
  110. Uil_cmd_z_command.v_report_info_msg = TRUE;
  111. Uil_cmd_z_command.v_report_warn_msg = TRUE;
  112. Uil_cmd_z_command.v_parse_tree = FALSE;
  113. Uil_cmd_z_command.v_use_setlocale = FALSE;
  114. Uil_cmd_z_command.status_update_delay = 0;
  115. Uil_cmd_z_command.message_cb = (Uil_continue_type(*)())NULL;
  116. Uil_cmd_z_command.status_cb = (Uil_continue_type(*)())NULL;
  117. Uil_cmd_z_command.ac_database = NULL;
  118. Uil_cmd_z_command.v_database = FALSE;
  119. #if debug_version
  120. uil_v_dump_tokens = FALSE;
  121. uil_v_dump_symbols = FALSE;
  122. #endif
  123. /* traverse the options on the command line */
  124. for (i = 1; i < l_arg_count; i++)
  125. {
  126. /* check for an output file */
  127. if ( strcmp("-o", rac_arg_value[ i ]) == 0 )
  128. {
  129. /* the next argument is the output file name */
  130. /* check next field is not an option */
  131. if (((i+1) >= l_arg_count) ||
  132. ( '-' == rac_arg_value[ i+1 ][ 0 ] ))
  133. {
  134. diag_issue_diagnostic
  135. ( d_miss_opt_arg,
  136. diag_k_no_source, diag_k_no_column,
  137. rac_arg_value[ i ],
  138. "output file"
  139. );
  140. continue;
  141. }
  142. if (Uil_cmd_z_command.ac_resource_file == NULL)
  143. Uil_cmd_z_command.ac_resource_file = rac_arg_value[ i+1 ];
  144. else
  145. diag_issue_diagnostic
  146. ( d_dupl_opt,
  147. diag_k_no_source, diag_k_no_column,
  148. rac_arg_value[ i ]
  149. );
  150. i = i + 1;
  151. }
  152. /* check for a binary database file */
  153. else if ( strcmp("-wmd", rac_arg_value[ i ]) == 0 )
  154. {
  155. /* the next argument is the binary database file name */
  156. /* check next field is not an option */
  157. if (((i+1) >= l_arg_count) ||
  158. ( '-' == rac_arg_value[ i+1 ][ 0 ] ))
  159. {
  160. diag_issue_diagnostic
  161. ( d_miss_opt_arg,
  162. diag_k_no_source, diag_k_no_column,
  163. rac_arg_value[ i ],
  164. "binary database file"
  165. );
  166. continue;
  167. }
  168. if (!Uil_cmd_z_command.v_database)
  169. {
  170. Uil_cmd_z_command.v_database = TRUE;
  171. Uil_cmd_z_command.ac_database = rac_arg_value[ i+1 ];
  172. }
  173. else
  174. diag_issue_diagnostic
  175. ( d_dupl_opt,
  176. diag_k_no_source, diag_k_no_column,
  177. rac_arg_value[ i ]
  178. );
  179. i = i + 1;
  180. }
  181. /* check for an listing file */
  182. else if ( strcmp("-v", rac_arg_value[ i ]) == 0 )
  183. {
  184. /* the next argument is the listing file name */
  185. /* check next field is not an option */
  186. if (((i+1) >= l_arg_count) ||
  187. ( '-' == rac_arg_value[ i+1 ][ 0 ] ))
  188. {
  189. diag_issue_diagnostic
  190. ( d_miss_opt_arg,
  191. diag_k_no_source, diag_k_no_column,
  192. rac_arg_value[ i ],
  193. "listing file"
  194. );
  195. continue;
  196. }
  197. if (!Uil_cmd_z_command.v_listing_file)
  198. {
  199. Uil_cmd_z_command.v_listing_file = TRUE;
  200. Uil_cmd_z_command.ac_listing_file = rac_arg_value[ i+1 ];
  201. }
  202. else
  203. diag_issue_diagnostic
  204. ( d_dupl_opt,
  205. diag_k_no_source, diag_k_no_column,
  206. rac_arg_value[ i ]
  207. );
  208. i = i + 1;
  209. }
  210. /* check for the machine code option */
  211. else if ( strcmp("-m", rac_arg_value[ i ]) == 0 )
  212. {
  213. Uil_cmd_z_command.v_show_machine_code = TRUE;
  214. }
  215. /* check if warnings are to be supressed */
  216. else if ( strcmp("-w", rac_arg_value[ i ]) == 0 )
  217. {
  218. Uil_cmd_z_command.v_report_info_msg = FALSE;
  219. Uil_cmd_z_command.v_report_warn_msg = FALSE;
  220. }
  221. /* check if setlocale is to be enabled */
  222. else if ( strcmp("-s", rac_arg_value[ i ]) == 0 )
  223. {
  224. Uil_cmd_z_command.v_use_setlocale = TRUE;
  225. }
  226. /* check for an unexpected option */
  227. else if ( '-' == rac_arg_value[ i ][ 0 ] )
  228. {
  229. /* check for an include directory */
  230. if ( 'I' == rac_arg_value[ i ][ 1 ] )
  231. {
  232. if (Uil_cmd_z_command.include_dir_count < Uil_k_max_include_dir_count)
  233. include_list[Uil_cmd_z_command.include_dir_count++] =
  234. & rac_arg_value[i] [2];
  235. else
  236. diag_issue_diagnostic
  237. ( d_too_many_dirs,
  238. diag_k_no_source, diag_k_no_column,
  239. rac_arg_value[ i ], Uil_k_max_include_dir_count
  240. );
  241. } else
  242. {
  243. diag_issue_diagnostic
  244. ( d_unknown_opt,
  245. diag_k_no_source, diag_k_no_column,
  246. rac_arg_value[ i ]
  247. );
  248. }
  249. }
  250. /* assume it is a UIL source file specification
  251. * validation of the file spec is done when file is opened */
  252. else
  253. {
  254. if (Uil_cmd_z_command.ac_source_file == NULL)
  255. Uil_cmd_z_command.ac_source_file = rac_arg_value[ i ];
  256. else
  257. diag_issue_diagnostic
  258. ( d_add_source,
  259. diag_k_no_source, diag_k_no_column,
  260. rac_arg_value[ i ]
  261. );
  262. }
  263. }
  264. /*
  265. ** Check for a source file - otherwise issue a diagnostic.
  266. */
  267. if (Uil_cmd_z_command.ac_source_file == NULL)
  268. diag_issue_diagnostic
  269. ( d_no_source, diag_k_no_source, diag_k_no_column );
  270. if (Uil_cmd_z_command.ac_resource_file == NULL)
  271. {
  272. Uil_cmd_z_command.ac_resource_file = XtMalloc (strlen ("a.uid") + 1);
  273. strcpy (Uil_cmd_z_command.ac_resource_file,"a.uid");
  274. }
  275. /*
  276. ** Machine code listing only makes sense if listing is set.
  277. */
  278. Uil_cmd_z_command.v_show_machine_code =
  279. ( Uil_cmd_z_command.v_listing_file &
  280. Uil_cmd_z_command.v_show_machine_code);
  281. }