%{ /* * Copyright Martin von Loewis, 1994 * Copyright 1998 Bertho A. Stultiens (BS) * 1999 Juergen Schmied (JS) * * 6-Nov-1999 JS - see CHANGES * * 29-Dec-1998 AdH - Grammar and function extensions. * grammar: TOOLBAR resources, Named ICONs in * DIALOGS * functions: semantic actions for the grammar * changes, resource files can now be anywhere * on the include path instead of just in the * current directory * * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not * printed out correctly. * * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should * also accept a tSTRING as argument. * * 25-May-1998 BS - Found out that I need to support language, version * and characteristics in inline resources (bitmap, * cursor, etc) but they can also be specified with * a filename. This renders my filename-scanning scheme * worthless. Need to build newline parsing to solve * this one. * It will come with version 1.1.0 (sigh). * * 19-May-1998 BS - Started to build a builtin preprocessor * * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous * ideas had some serious flaws. * * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc * file. * * 21-Apr-1998 BS - Added correct behavior for cursors and icons. * - This file is growing too big. It is time to strip * things and put it in a support file. * * 19-Apr-1998 BS - Tagged the stringtable resource so that only one * resource will be created. This because the table * has a different layout than other resources. The * table has to be sorted, and divided into smaller * resource entries (see comment in source). * * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed * as string_t which include unicode strings upon * input. * - Parser now emits a warning when compiling win32 * extensions in win16 mode. * * 16-Apr-1998 BS - Raw data elements are now *optionally* seperated * by commas. Read the comments in file sq2dq.l. * - FIXME: there are instances in the source that rely * on the fact that int==32bit and pointers are int size. * - Fixed the conflict in menuex by changing a rule * back into right recursion. See note in source. * - UserType resources cannot have an expression as its * typeclass. See note in source. * * 15-Apr-1998 BS - Changed all right recursion into left recursion to * get reduction of the parsestack. * This also helps communication between bison and flex. * Main advantage is that the Empty rule gets reduced * first, which is used to allocate/link things. * It also added a shift/reduce conflict in the menuex * handling, due to expression/option possibility, * although not serious. * * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking * about making it more efficient, but readable (for me) * and slightly easier to expand/change. * This is done primarily by using more reduce states * with many (intuitive) types for the various resource * statements. * - Added expression handling for all resources where a * number is accepted (not only for win32). Also added * multiply and division (not MS compatible, but handy). * Unary minus introduced a shift/reduce conflict, but * it is not serious. * * 13-Apr-1998 BS - Reordered a lot of things * - Made the source more readable * - Added Win32 resource definitions * - Corrected syntax problems with an old yacc (;) * - Added extra comment about grammar */ #include "config.h" #include #include #include #include #include #include #ifdef HAVE_ALLOCA_H #include #endif #include "wrc.h" #include "utils.h" #include "newstruc.h" #include "dumpres.h" #include "preproc.h" #include "parser.h" #include "windef.h" #include "wingdi.h" #include "winuser.h" #ifdef __BORLANDC__ #pragma warn -sig #endif int indialog = 0; /* Signal flex that we're parsing a dialog */ int want_rscname = 0; /* Set when a resource's name is required */ stringtable_t *tagstt; /* Stringtable tag. * It is set while parsing a stringtable to one of * the stringtables in the sttres list or a new one * if the language was not parsed before. */ stringtable_t *sttres; /* Stringtable resources. This holds the list of * stringtables with different lanuages */ /* Set to the current options of the currently scanning stringtable */ static int *tagstt_memopt; static characts_t *tagstt_characts; static version_t *tagstt_version; /* Prototypes of here defined functions */ void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur); void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico); int alloc_cursor_id(language_t *); int alloc_icon_id(language_t *); void ins_stt_entry(stt_entry_t *ste); int check_stt_entry(stringtable_t *tabs, stt_entry_t *ste); event_t *get_event_head(event_t *p); control_t *get_control_head(control_t *p); ver_value_t *get_ver_value_head(ver_value_t *p); ver_block_t *get_ver_block_head(ver_block_t *p); resource_t *get_resource_head(resource_t *p); menuex_item_t *get_itemex_head(menuex_item_t *p); menu_item_t *get_item_head(menu_item_t *p); raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str); raw_data_t *merge_raw_data_int(raw_data_t *r1, int i); raw_data_t *merge_raw_data_long(raw_data_t *r1, int i); raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2); raw_data_t *str2raw_data(string_t *str); raw_data_t *int2raw_data(int i); raw_data_t *long2raw_data(int i); raw_data_t *load_file(string_t *name); itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid); event_t *add_string_event(string_t *key, int id, int flags, event_t *prev); event_t *add_event(int key, int id, int flags, event_t *prev); dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg); dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg); dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg); dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg); dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg); dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg); dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg); dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg); dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg); name_id_t *convert_ctlclass(name_id_t *cls); control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev); dialog_t *dialog_version(version_t *v, dialog_t *dlg); dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg); dialog_t *dialog_language(language_t *l, dialog_t *dlg); dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg); dialog_t *dialog_class(name_id_t *n, dialog_t *dlg); dialog_t *dialog_font(font_id_t *f, dialog_t *dlg); dialog_t *dialog_caption(string_t *s, dialog_t *dlg); dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg); dialog_t *dialog_style(style_t * st, dialog_t *dlg); resource_t *build_stt_resources(stringtable_t *stthead); stringtable_t *find_stringtable(lvc_t *lvc); toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec); toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems); %} %union{ string_t *str; int num; int *iptr; resource_t *res; accelerator_t *acc; bitmap_t *bmp; cursor_t *cur; cursor_group_t *curg; dialog_t *dlg; dialogex_t *dlgex; font_t *fnt; icon_t *ico; icon_group_t *icog; menu_t *men; menuex_t *menex; rcdata_t *rdt; stringtable_t *stt; stt_entry_t *stte; user_t *usr; messagetable_t *msg; versioninfo_t *veri; control_t *ctl; name_id_t *nid; font_id_t *fntid; language_t *lan; version_t *ver; characts_t *chars; event_t *event; menu_item_t *menitm; menuex_item_t *menexitm; itemex_opt_t *exopt; raw_data_t *raw; lvc_t *lvc; ver_value_t *val; ver_block_t *blk; ver_words_t *verw; toolbar_t *tlbar; toolbar_item_t *tlbarItems; dlginit_t *dginit; style_pair_t *styles; style_t *style; } %token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL %token tTYPEDEF tEXTERN %token NUMBER LNUMBER %token tSTRING IDENT FILENAME %token RAWDATA %token ACCELERATORS tBITMAP CURSOR DIALOG DIALOGEX MENU MENUEX MESSAGETABLE %token RCDATA VERSIONINFO STRINGTABLE FONT ICON %token AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON CHECKBOX DEFPUSHBUTTON %token PUSHBUTTON RADIOBUTTON STATE3 /* PUSHBOX */ %token GROUPBOX COMBOBOX LISTBOX SCROLLBAR %token CONTROL EDITTEXT %token RTEXT CTEXT LTEXT %token BLOCK VALUE %token SHIFT ALT ASCII VIRTKEY GRAYED CHECKED INACTIVE NOINVERT %token tPURE IMPURE DISCARDABLE LOADONCALL PRELOAD tFIXED MOVEABLE %token CLASS CAPTION CHARACTERISTICS EXSTYLE STYLE VERSION LANGUAGE %token FILEVERSION PRODUCTVERSION FILEFLAGSMASK FILEOS FILETYPE FILEFLAGS FILESUBTYPE %token MENUBARBREAK MENUBREAK MENUITEM POPUP SEPARATOR %token HELP %token tSTRING IDENT RAWDATA %token TOOLBAR BUTTON %token tBEGIN tEND %token DLGINIT %left LOGOR %left LOGAND %left '|' %left '^' %left '&' %left EQ NE %left '<' LTE '>' GTE %left '+' '-' %left '*' '/' %right '~' '!' NOT %type resource_file resource resources resource_definition %type stringtable strings %type font %type icon %type accelerators %type events %type bitmap %type cursor %type dialog dlg_attributes %type ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo %type helpid %type dialogex dlgex_attribs %type exctrls gen_exctrl lab_exctrl exctrl_desc %type rcdata %type raw_data raw_elements opt_data %type versioninfo fix_version %type ver_words %type ver_blocks ver_block %type ver_values ver_value %type menu %type item_definitions menu_body %type menuex %type itemex_definitions menuex_body %type itemex_p_options itemex_options %type messagetable %type userres %type item_options %type nameid nameid_s ctlclass usertype %type acc_opt %type loadmemopts lamo lama %type opt_font opt_exfont opt_expr %type opt_lvc %type opt_language %type opt_characts %type opt_version %type expr xpr %type e_expr %type pp_expr pp_constant %type toolbar %type toolbar_items %type dlginit %type optional_style_pair %type any_num %type