wml.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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[] = "$TOG: wml.c /main/8 1999/04/16 09:41:47 mgreess $"
  36. #endif
  37. #endif
  38. /*
  39. * (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
  40. /*
  41. * This is the main program for WML. It declares all global data structures
  42. * used during a compilation, and during output.
  43. */
  44. /*
  45. * WML is a semi-standard Unix application. It reads its input from
  46. * stdin, which is expected to be a stream containing a WML description
  47. * of a UIL language. If this stream is successfully parsed and semantically
  48. * validated, then WML writes a series of standard .h and .dat files into
  49. * the user directory. The .h files will be used directly to construct
  50. * the UIL compiler. The .dat files are used by other phases of UIL
  51. * table generation.
  52. *
  53. * The files created by WML are:
  54. *
  55. * .h files:
  56. * UilSymGen.h
  57. * UilSymArTy.h
  58. * UilSymRArg.h
  59. * UilDrmClas.h
  60. * UilConst.h
  61. * UilSymReas.h
  62. * UilSymArTa.h
  63. * UilSymCtl.h
  64. * UilSymNam.h
  65. * .dat files
  66. * argument.dat
  67. * reason.dat
  68. * grammar.dat
  69. * .mm files
  70. * wml-uil.mm
  71. */
  72. #include "wml.h"
  73. #if defined(SYSV) || defined(SVR4)
  74. #include <fcntl.h>
  75. #else
  76. #include <sys/file.h>
  77. #endif
  78. #include <stdio.h>
  79. /*
  80. * Globals used during WML parsing.
  81. *
  82. * WML uses globals exclusively to communicate data during parsing. The
  83. * current object being constructed is held by these globals, and all
  84. * routines called from the parse assume correct setting of these globals.
  85. * This simplisitic approach is possible since the WML description language
  86. * has no recursive constructs requiring a frame stack.
  87. */
  88. /*
  89. * Error and other counts
  90. */
  91. int wml_err_count = 0; /* total errors */
  92. int wml_line_count = 0; /* lines read from input */
  93. /*
  94. * Dynamic ordered vector of all objects encountered during parse. This
  95. * is used to detect name collisions, and is the primary order vector
  96. * used for all other vectors constructed curing the semantic resolution
  97. * phase of processing.
  98. */
  99. DynamicHandleListDef wml_synobj;
  100. DynamicHandleListDefPtr wml_synobj_ptr = &wml_synobj;
  101. /*
  102. * Dynamic vectors of vectors partitioned and ordered
  103. * as required by the semantic processing and output routines. All
  104. * point to resolved objects rather than syntactic objects.
  105. */
  106. DynamicHandleListDef wml_obj_datatype; /* datatype objects */
  107. DynamicHandleListDefPtr wml_obj_datatype_ptr = &wml_obj_datatype;
  108. DynamicHandleListDef wml_obj_enumval; /* enumeration value objects */
  109. DynamicHandleListDefPtr wml_obj_enumval_ptr = &wml_obj_enumval;
  110. DynamicHandleListDef wml_obj_enumset; /* enumeration set objects */
  111. DynamicHandleListDefPtr wml_obj_enumset_ptr = &wml_obj_enumset;
  112. DynamicHandleListDef wml_obj_reason; /* reason resource objects */
  113. DynamicHandleListDefPtr wml_obj_reason_ptr = &wml_obj_reason;
  114. DynamicHandleListDef wml_obj_arg; /* argument resource objects */
  115. DynamicHandleListDefPtr wml_obj_arg_ptr = &wml_obj_arg;
  116. DynamicHandleListDef wml_obj_child; /* argument resource objects */
  117. DynamicHandleListDefPtr wml_obj_child_ptr = &wml_obj_child;
  118. DynamicHandleListDef wml_obj_allclass; /* metaclass, widget, gadget */
  119. DynamicHandleListDefPtr wml_obj_allclass_ptr = &wml_obj_allclass;
  120. DynamicHandleListDef wml_obj_class; /* widget & gadget objects */
  121. DynamicHandleListDefPtr wml_obj_class_ptr = &wml_obj_class;
  122. DynamicHandleListDef wml_obj_ctrlist; /* controls list objects */
  123. DynamicHandleListDefPtr wml_obj_ctrlist_ptr = &wml_obj_ctrlist;
  124. DynamicHandleListDef wml_obj_charset; /* charset objects */
  125. DynamicHandleListDefPtr wml_obj_charset_ptr = &wml_obj_charset;
  126. DynamicHandleListDef wml_tok_sens; /* case-sensitive tokens */
  127. DynamicHandleListDefPtr wml_tok_sens_ptr = &wml_tok_sens;
  128. DynamicHandleListDef wml_tok_insens; /* case-insensitive tokens */
  129. DynamicHandleListDefPtr wml_tok_insens_ptr = &wml_tok_insens;
  130. /*
  131. * Routines only accessible in this module
  132. */
  133. void wmlInit ();
  134. /*
  135. * External variables
  136. */
  137. extern int yyleng;
  138. /*
  139. * The WML main routine:
  140. *
  141. * 1. Initialize global storage
  142. * 2. Open the input file if there is one
  143. * 3. Parse the WML description in stdin. Exit on errors
  144. * 4. Perform semantic validation and resolution. Exit on errors.
  145. * 5. Output files
  146. */
  147. int main (argc, argv)
  148. int argc;
  149. char **argv;
  150. {
  151. int done;
  152. int fd; /* input file descriptor */
  153. /*
  154. * Initialize storage
  155. */
  156. wmlInit ();
  157. /*
  158. * Assume that anything in argv must be an input file. Open it, and
  159. * dup it to stdin
  160. */
  161. if ( argc > 1 )
  162. {
  163. if ( (fd=open(argv[1],O_RDONLY)) == -1 )
  164. printf ("\nCouldn't open file %s", argv[1]);
  165. else
  166. dup2 (fd, 0);
  167. }
  168. /*
  169. * Process the input
  170. */
  171. done = 0;
  172. while (!done)
  173. {
  174. /*
  175. * Parse the input stream
  176. */
  177. yyleng = 0; /* initialization safety */
  178. yyparse ();
  179. if ( wml_err_count > 0 ) break;
  180. printf ("\nParse of WML input complete");
  181. /*
  182. * Perform semantic validation, and construct resolved data structures
  183. */
  184. wmlResolveDescriptors ();
  185. if ( wml_err_count > 0 ) break;
  186. printf ("\nSemantic validation and resolution complete");
  187. /*
  188. * Output
  189. */
  190. wmlOutput ();
  191. if ( wml_err_count > 0 ) break;
  192. printf ("\nWML Uil*.h and wml-uil.mm file creation complete\n");
  193. done = 1;
  194. }
  195. /*
  196. * Report inaction on errors
  197. */
  198. if ( wml_err_count > 0 )
  199. {
  200. printf ("\nWML found %d errors, no or incomplete output produced\n",
  201. wml_err_count);
  202. /* Begin fixing the bug CR 4748 */
  203. exit(1);
  204. /* End fixing the bug CR 4748 */
  205. }
  206. return (0);
  207. }
  208. /*
  209. * Routine to initialize WML.
  210. *
  211. * The main job is to dynamically allocate any dynamic lists to a reasonable
  212. * initial state.
  213. */
  214. void wmlInit ()
  215. {
  216. /*
  217. * Initialize the list of all syntactic objects
  218. */
  219. wmlInitHList (wml_synobj_ptr, 1000, TRUE);
  220. }
  221. yywrap()
  222. {
  223. return(1);
  224. }