📄 rcparse.y
字号:
%{ /* rcparse.y -- parser for Windows rc files Copyright 1997, 1998, 1999, 2000 Free Software Foundation, Inc. Written by Ian Lance Taylor, Cygnus Support. This file is part of GNU Binutils. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* This is a parser for Windows rc files. It is based on the parser by Gunther Ebert <gunther.ebert@ixos-leipzig.de>. */#include "bfd.h"#include "bucomm.h"#include "libiberty.h"#include "windres.h"#include <ctype.h>/* The current language. */static unsigned short language;/* The resource information during a sub statement. */static struct res_res_info sub_res_info;/* Dialog information. This is built by the nonterminals styles and controls. */static struct dialog dialog;/* This is used when building a style. It is modified by the nonterminal styleexpr. */static unsigned long style;/* These are used when building a control. They are set before using control_params. */static unsigned long base_style;static unsigned long default_style;static unsigned long class;%}%union{ struct accelerator acc; struct accelerator *pacc; struct dialog_control *dialog_control; struct menuitem *menuitem; struct { struct rcdata_item *first; struct rcdata_item *last; } rcdata; struct rcdata_item *rcdata_item; struct stringtable_data *stringtable; struct fixed_versioninfo *fixver; struct ver_info *verinfo; struct ver_stringinfo *verstring; struct ver_varinfo *vervar; struct res_id id; struct res_res_info res_info; struct { unsigned short on; unsigned short off; } memflags; struct { unsigned long val; /* Nonzero if this number was explicitly specified as long. */ int dword; } i; unsigned long il; unsigned short is; const char *s; struct { unsigned long length; const char *s; } ss;};%token BEG END%token ACCELERATORS VIRTKEY ASCII NOINVERT SHIFT CONTROL ALT%token BITMAP%token CURSOR%token DIALOG DIALOGEX EXSTYLE CAPTION CLASS STYLE%token AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON CHECKBOX COMBOBOX CTEXT%token DEFPUSHBUTTON EDITTEXT GROUPBOX LISTBOX LTEXT PUSHBOX PUSHBUTTON%token RADIOBUTTON RTEXT SCROLLBAR STATE3 USERBUTTON%token BEDIT HEDIT IEDIT%token FONT%token ICON%token LANGUAGE CHARACTERISTICS VERSIONK%token MENU MENUEX MENUITEM SEPARATOR POPUP CHECKED GRAYED HELP INACTIVE%token MENUBARBREAK MENUBREAK%token MESSAGETABLE%token RCDATA%token STRINGTABLE%token VERSIONINFO FILEVERSION PRODUCTVERSION FILEFLAGSMASK FILEFLAGS%token FILEOS FILETYPE FILESUBTYPE BLOCKSTRINGFILEINFO BLOCKVARFILEINFO%token VALUE%token <s> BLOCK%token MOVEABLE FIXED PURE IMPURE PRELOAD LOADONCALL DISCARDABLE%token NOT%token <s> QUOTEDSTRING STRING%token <i> NUMBER%token <ss> SIZEDSTRING%token IGNORED_TOKEN%type <pacc> acc_entries%type <acc> acc_entry acc_event%type <dialog_control> control control_params%type <menuitem> menuitems menuitem menuexitems menuexitem%type <rcdata> optrcdata_data optrcdata_data_int rcdata_data%type <rcdata_item> opt_control_data%type <fixver> fixedverinfo%type <verinfo> verblocks%type <verstring> vervals%type <vervar> vertrans%type <res_info> suboptions memflags_move_discard memflags_move%type <memflags> memflag%type <id> id resref%type <il> exstyle parennumber%type <il> numexpr posnumexpr cnumexpr optcnumexpr cposnumexpr%type <is> acc_options acc_option menuitem_flags menuitem_flag%type <s> optstringc file_name resname%type <i> sizednumexpr sizedposnumexpr%left '|'%left '^'%left '&'%left '+' '-'%left '*' '/' '%'%right '~' NEG%%input: /* empty */ | input newcmd accelerator | input newcmd bitmap | input newcmd cursor | input newcmd dialog | input newcmd font | input newcmd icon | input newcmd language | input newcmd menu | input newcmd menuex | input newcmd messagetable | input newcmd rcdata | input newcmd stringtable | input newcmd user | input newcmd versioninfo | input newcmd IGNORED_TOKEN ;newcmd: /* empty */ { rcparse_discard_strings (); } ;/* Accelerator resources. */accelerator: id ACCELERATORS suboptions BEG acc_entries END { define_accelerator ($1, &$3, $5); } ;acc_entries: /* empty */ { $$ = NULL; } | acc_entries acc_entry { struct accelerator *a; a = (struct accelerator *) res_alloc (sizeof *a); *a = $2; if ($1 == NULL) $$ = a; else { struct accelerator **pp; for (pp = &$1->next; *pp != NULL; pp = &(*pp)->next) ; *pp = a; $$ = $1; } } ;acc_entry: acc_event cposnumexpr { $$ = $1; $$.id = $2; } | acc_event cposnumexpr ',' acc_options { $$ = $1; $$.id = $2; $$.flags |= $4; if (($$.flags & ACC_VIRTKEY) == 0 && ($$.flags & (ACC_SHIFT | ACC_CONTROL | ACC_ALT)) != 0) rcparse_warning (_("inappropriate modifiers for non-VIRTKEY")); } ;acc_event: QUOTEDSTRING { const char *s = $1; char ch; $$.next = NULL; $$.id = 0; ch = *s; if (ch != '^') $$.flags = 0; else { $$.flags = ACC_CONTROL | ACC_VIRTKEY; ++s; ch = *s; ch = toupper ((unsigned char) ch); } $$.key = ch; if (s[1] != '\0') rcparse_warning (_("accelerator should only be one character")); } | posnumexpr { $$.next = NULL; $$.flags = 0; $$.id = 0; $$.key = $1; } ;acc_options: acc_option { $$ = $1; } | acc_options ',' acc_option { $$ = $1 | $3; } /* I've had one report that the comma is optional. */ | acc_options acc_option { $$ = $1 | $2; } ;acc_option: VIRTKEY { $$ = ACC_VIRTKEY; } | ASCII { /* This is just the absence of VIRTKEY. */ $$ = 0; } | NOINVERT { $$ = ACC_NOINVERT; } | SHIFT { $$ = ACC_SHIFT; } | CONTROL { $$ = ACC_CONTROL; } | ALT { $$ = ACC_ALT; } ;/* Bitmap resources. */bitmap: id BITMAP memflags_move file_name { define_bitmap ($1, &$3, $4); } ;/* Cursor resources. */cursor: id CURSOR memflags_move_discard file_name { define_cursor ($1, &$3, $4); } ;/* Dialog resources. */dialog: id DIALOG memflags_move exstyle posnumexpr cnumexpr cnumexpr cnumexpr { memset (&dialog, 0, sizeof dialog); dialog.x = $5; dialog.y = $6; dialog.width = $7; dialog.height = $8; dialog.style = WS_POPUP | WS_BORDER | WS_SYSMENU; dialog.exstyle = $4; dialog.menu.named = 1; dialog.class.named = 1; dialog.font = NULL; dialog.ex = NULL; dialog.controls = NULL; sub_res_info = $3; } styles BEG controls END { define_dialog ($1, &sub_res_info, &dialog); } | id DIALOGEX memflags_move exstyle posnumexpr cnumexpr cnumexpr cnumexpr { memset (&dialog, 0, sizeof dialog); dialog.x = $5; dialog.y = $6; dialog.width = $7; dialog.height = $8; dialog.style = WS_POPUP | WS_BORDER | WS_SYSMENU; dialog.exstyle = $4; dialog.menu.named = 1; dialog.class.named = 1; dialog.font = NULL; dialog.ex = ((struct dialog_ex *) res_alloc (sizeof (struct dialog_ex))); memset (dialog.ex, 0, sizeof (struct dialog_ex)); dialog.controls = NULL; sub_res_info = $3; } styles BEG controls END { define_dialog ($1, &sub_res_info, &dialog); } | id DIALOGEX memflags_move exstyle posnumexpr cnumexpr cnumexpr cnumexpr cnumexpr { memset (&dialog, 0, sizeof dialog); dialog.x = $5; dialog.y = $6; dialog.width = $7; dialog.height = $8; dialog.style = WS_POPUP | WS_BORDER | WS_SYSMENU; dialog.exstyle = $4; dialog.menu.named = 1; dialog.class.named = 1; dialog.font = NULL; dialog.ex = ((struct dialog_ex *) res_alloc (sizeof (struct dialog_ex))); memset (dialog.ex, 0, sizeof (struct dialog_ex)); dialog.ex->help = $9; dialog.controls = NULL; sub_res_info = $3; } styles BEG controls END { define_dialog ($1, &sub_res_info, &dialog); } ;exstyle: /* empty */ { $$ = 0; } | EXSTYLE '=' numexpr { $$ = $3; } ;styles: /* empty */ | styles CAPTION QUOTEDSTRING { unicode_from_ascii ((int *) NULL, &dialog.caption, $3); } | styles CLASS id { dialog.class = $3; } | styles STYLE { style = dialog.style; } styleexpr { dialog.style = style; } | styles EXSTYLE numexpr { dialog.exstyle = $3; } | styles FONT numexpr ',' QUOTEDSTRING { dialog.style |= DS_SETFONT; dialog.pointsize = $3; unicode_from_ascii ((int *) NULL, &dialog.font, $5); } | styles FONT numexpr ',' QUOTEDSTRING cnumexpr cnumexpr { dialog.style |= DS_SETFONT; dialog.pointsize = $3; unicode_from_ascii ((int *) NULL, &dialog.font, $5); if (dialog.ex == NULL) rcparse_warning (_("extended FONT requires DIALOGEX")); else { dialog.ex->weight = $6; dialog.ex->italic = $7; } } | styles MENU id { dialog.menu = $3; } | styles CHARACTERISTICS numexpr { sub_res_info.characteristics = $3; } | styles LANGUAGE numexpr cnumexpr { sub_res_info.language = $3 | ($4 << 8); } | styles VERSIONK numexpr { sub_res_info.version = $3; } ;controls: /* empty */ | controls control { struct dialog_control **pp; for (pp = &dialog.controls; *pp != NULL; pp = &(*pp)->next) ; *pp = $2; } ;control: AUTO3STATE { default_style = BS_AUTO3STATE | WS_TABSTOP; base_style = BS_AUTO3STATE; class = CTL_BUTTON; } control_params { $$ = $3; } | AUTOCHECKBOX { default_style = BS_AUTOCHECKBOX | WS_TABSTOP; base_style = BS_AUTOCHECKBOX; class = CTL_BUTTON; } control_params { $$ = $3; } | AUTORADIOBUTTON { default_style = BS_AUTORADIOBUTTON | WS_TABSTOP; base_style = BS_AUTORADIOBUTTON; class = CTL_BUTTON; } control_params { $$ = $3; } | BEDIT { default_style = ES_LEFT | WS_BORDER | WS_TABSTOP; base_style = ES_LEFT | WS_BORDER | WS_TABSTOP; class = CTL_EDIT; } control_params { $$ = $3; if (dialog.ex == NULL) rcparse_warning (_("IEDIT requires DIALOGEX")); res_string_to_id (&$$->class, "BEDIT"); } | CHECKBOX { default_style = BS_CHECKBOX | WS_TABSTOP; base_style = BS_CHECKBOX | WS_TABSTOP; class = CTL_BUTTON; } control_params { $$ = $3; } | COMBOBOX { default_style = CBS_SIMPLE | WS_TABSTOP; base_style = 0; class = CTL_COMBOBOX; } control_params { $$ = $3; } | CONTROL optstringc numexpr cnumexpr control_styleexpr cnumexpr cnumexpr cnumexpr cnumexpr optcnumexpr opt_control_data { $$ = define_control ($2, $3, $6, $7, $8, $9, $4, style, $10); if ($11 != NULL) { if (dialog.ex == NULL) rcparse_warning (_("control data requires DIALOGEX")); $$->data = $11; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -