parser.y 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883
  1. %{
  2. /*
  3. * Copyright 1994 Martin von Loewis
  4. * Copyright 1998-2000 Bertho A. Stultiens (BS)
  5. * 1999 Juergen Schmied (JS)
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  20. *
  21. * History:
  22. * 24-Jul-2000 BS - Made a fix for broken Berkeley yacc on
  23. * non-terminals (see cjunk rule).
  24. * 21-May-2000 BS - Partial implementation of font resources.
  25. * - Corrected language propagation for binary
  26. * resources such as bitmaps, icons, cursors,
  27. * userres and rcdata. The language is now
  28. * correct in .res files.
  29. * - Fixed reading the resource name as ident,
  30. * so that it may overlap keywords.
  31. * 20-May-2000 BS - Implemented animated cursors and icons
  32. * resource types.
  33. * 30-Apr-2000 BS - Reintegration into the wine-tree
  34. * 14-Jan-2000 BS - Redid the usertype resources so that they
  35. * are compatible.
  36. * 02-Jan-2000 BS - Removed the preprocessor from the grammar
  37. * except for the # command (line numbers).
  38. *
  39. * 06-Nov-1999 JS - see CHANGES
  40. *
  41. * 29-Dec-1998 AdH - Grammar and function extensions.
  42. * grammar: TOOLBAR resources, Named ICONs in
  43. * DIALOGS
  44. * functions: semantic actions for the grammar
  45. * changes, resource files can now be anywhere
  46. * on the include path instead of just in the
  47. * current directory
  48. *
  49. * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
  50. * printed out correctly.
  51. *
  52. * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
  53. * also accept a tSTRING as argument.
  54. *
  55. * 25-May-1998 BS - Found out that I need to support language, version
  56. * and characteristics in inline resources (bitmap,
  57. * cursor, etc) but they can also be specified with
  58. * a filename. This renders my filename-scanning scheme
  59. * worthless. Need to build newline parsing to solve
  60. * this one.
  61. * It will come with version 1.1.0 (sigh).
  62. *
  63. * 19-May-1998 BS - Started to build a builtin preprocessor
  64. *
  65. * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
  66. * ideas had some serious flaws.
  67. *
  68. * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
  69. * file.
  70. *
  71. * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
  72. * - This file is growing too big. It is time to strip
  73. * things and put it in a support file.
  74. *
  75. * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
  76. * resource will be created. This because the table
  77. * has a different layout than other resources. The
  78. * table has to be sorted, and divided into smaller
  79. * resource entries (see comment in source).
  80. *
  81. * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
  82. * as string_t which include unicode strings upon
  83. * input.
  84. * - Parser now emits a warning when compiling win32
  85. * extensions in win16 mode.
  86. *
  87. * 16-Apr-1998 BS - Raw data elements are now *optionally* separated
  88. * by commas. Read the comments in file sq2dq.l.
  89. * - FIXME: there are instances in the source that rely
  90. * on the fact that int==32bit and pointers are int size.
  91. * - Fixed the conflict in menuex by changing a rule
  92. * back into right recursion. See note in source.
  93. * - UserType resources cannot have an expression as its
  94. * typeclass. See note in source.
  95. *
  96. * 15-Apr-1998 BS - Changed all right recursion into left recursion to
  97. * get reduction of the parsestack.
  98. * This also helps communication between bison and flex.
  99. * Main advantage is that the Empty rule gets reduced
  100. * first, which is used to allocate/link things.
  101. * It also added a shift/reduce conflict in the menuex
  102. * handling, due to expression/option possibility,
  103. * although not serious.
  104. *
  105. * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
  106. * about making it more efficient, but readable (for me)
  107. * and slightly easier to expand/change.
  108. * This is done primarily by using more reduce states
  109. * with many (intuitive) types for the various resource
  110. * statements.
  111. * - Added expression handling for all resources where a
  112. * number is accepted (not only for win32). Also added
  113. * multiply and division (not MS compatible, but handy).
  114. * Unary minus introduced a shift/reduce conflict, but
  115. * it is not serious.
  116. *
  117. * 13-Apr-1998 BS - Reordered a lot of things
  118. * - Made the source more readable
  119. * - Added Win32 resource definitions
  120. * - Corrected syntax problems with an old yacc (;)
  121. * - Added extra comment about grammar
  122. */
  123. #include "config.h"
  124. #include "wine/port.h"
  125. #include <stdio.h>
  126. #include <stdlib.h>
  127. #include <stdarg.h>
  128. #include <assert.h>
  129. #include <ctype.h>
  130. #include <string.h>
  131. #include "wrc.h"
  132. #include "utils.h"
  133. #include "newstruc.h"
  134. #include "dumpres.h"
  135. #include "wine/wpp.h"
  136. #include "parser.h"
  137. #include "windef.h"
  138. #include "winbase.h"
  139. #include "wingdi.h"
  140. #include "winuser.h"
  141. int want_nl = 0; /* Signal flex that we need the next newline */
  142. int want_id = 0; /* Signal flex that we need the next identifier */
  143. static stringtable_t *tagstt; /* Stringtable tag.
  144. * It is set while parsing a stringtable to one of
  145. * the stringtables in the sttres list or a new one
  146. * if the language was not parsed before.
  147. */
  148. static stringtable_t *sttres; /* Stringtable resources. This holds the list of
  149. * stringtables with different lanuages
  150. */
  151. static int dont_want_id = 0; /* See language parsing for details */
  152. /* Set to the current options of the currently scanning stringtable */
  153. static int *tagstt_memopt;
  154. static characts_t *tagstt_characts;
  155. static version_t *tagstt_version;
  156. static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
  157. /* Prototypes of here defined functions */
  158. static event_t *get_event_head(event_t *p);
  159. static control_t *get_control_head(control_t *p);
  160. static ver_value_t *get_ver_value_head(ver_value_t *p);
  161. static ver_block_t *get_ver_block_head(ver_block_t *p);
  162. static resource_t *get_resource_head(resource_t *p);
  163. static menu_item_t *get_item_head(menu_item_t *p);
  164. static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
  165. static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
  166. static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
  167. static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
  168. static raw_data_t *str2raw_data(string_t *str);
  169. static raw_data_t *int2raw_data(int i);
  170. static raw_data_t *long2raw_data(int i);
  171. static raw_data_t *load_file(string_t *name, language_t *lang);
  172. static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
  173. static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
  174. static event_t *add_event(int key, int id, int flags, event_t *prev);
  175. static name_id_t *convert_ctlclass(name_id_t *cls);
  176. static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
  177. static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
  178. static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
  179. static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
  180. static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
  181. static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
  182. static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
  183. static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
  184. static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
  185. static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
  186. static resource_t *build_stt_resources(stringtable_t *stthead);
  187. static stringtable_t *find_stringtable(lvc_t *lvc);
  188. static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
  189. static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
  190. static string_t *make_filename(string_t *s);
  191. static resource_t *build_fontdirs(resource_t *tail);
  192. static resource_t *build_fontdir(resource_t **fnt, int nfnt);
  193. static int rsrcid_to_token(int lookahead);
  194. %}
  195. %union{
  196. string_t *str;
  197. int num;
  198. int *iptr;
  199. char *cptr;
  200. resource_t *res;
  201. accelerator_t *acc;
  202. bitmap_t *bmp;
  203. dialog_t *dlg;
  204. font_t *fnt;
  205. fontdir_t *fnd;
  206. menu_t *men;
  207. html_t *html;
  208. rcdata_t *rdt;
  209. stringtable_t *stt;
  210. stt_entry_t *stte;
  211. user_t *usr;
  212. messagetable_t *msg;
  213. versioninfo_t *veri;
  214. control_t *ctl;
  215. name_id_t *nid;
  216. font_id_t *fntid;
  217. language_t *lan;
  218. version_t *ver;
  219. characts_t *chars;
  220. event_t *event;
  221. menu_item_t *menitm;
  222. itemex_opt_t *exopt;
  223. raw_data_t *raw;
  224. lvc_t *lvc;
  225. ver_value_t *val;
  226. ver_block_t *blk;
  227. ver_words_t *verw;
  228. toolbar_t *tlbar;
  229. toolbar_item_t *tlbarItems;
  230. dlginit_t *dginit;
  231. style_pair_t *styles;
  232. style_t *style;
  233. ani_any_t *ani;
  234. }
  235. %token tNL
  236. %token <num> tNUMBER tLNUMBER
  237. %token <str> tSTRING tIDENT
  238. %token <raw> tRAWDATA
  239. %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
  240. %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON tHTML
  241. %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
  242. %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
  243. %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
  244. %token tCONTROL tEDITTEXT
  245. %token tRTEXT tCTEXT tLTEXT
  246. %token tBLOCK tVALUE
  247. %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
  248. %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
  249. %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
  250. %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
  251. %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
  252. %token tHELP
  253. %token tTOOLBAR tBUTTON
  254. %token tBEGIN tEND
  255. %token tDLGINIT
  256. %left '|'
  257. %left '^'
  258. %left '&'
  259. %left '+' '-'
  260. %left '*' '/'
  261. %right '~' tNOT
  262. %left pUPM
  263. %type <res> resource_file resource resources resource_definition
  264. %type <stt> stringtable strings
  265. %type <fnt> font
  266. %type <fnd> fontdir
  267. %type <acc> accelerators
  268. %type <event> events
  269. %type <bmp> bitmap
  270. %type <ani> cursor icon
  271. %type <dlg> dialog dlg_attributes dialogex dlgex_attribs
  272. %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
  273. %type <iptr> helpid
  274. %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
  275. %type <html> html
  276. %type <rdt> rcdata
  277. %type <raw> raw_data raw_elements opt_data file_raw
  278. %type <veri> versioninfo fix_version
  279. %type <verw> ver_words
  280. %type <blk> ver_blocks ver_block
  281. %type <val> ver_values ver_value
  282. %type <men> menu menuex
  283. %type <menitm> item_definitions menu_body itemex_definitions menuex_body
  284. %type <exopt> itemex_p_options itemex_options
  285. %type <msg> messagetable
  286. %type <usr> userres
  287. %type <num> item_options
  288. %type <nid> nameid nameid_s ctlclass usertype
  289. %type <num> acc_opt acc accs
  290. %type <iptr> loadmemopts lamo lama
  291. %type <fntid> opt_font opt_exfont opt_expr
  292. %type <lvc> opt_lvc
  293. %type <lan> opt_language
  294. %type <chars> opt_characts
  295. %type <ver> opt_version
  296. %type <num> expr xpr
  297. %type <iptr> e_expr
  298. %type <tlbar> toolbar
  299. %type <tlbarItems> toolbar_items
  300. %type <dginit> dlginit
  301. %type <styles> optional_style_pair
  302. %type <num> any_num
  303. %type <style> style
  304. %type <str> filename
  305. %%
  306. resource_file
  307. : resources {
  308. resource_t *rsc, *head;
  309. /* First add stringtables to the resource-list */
  310. rsc = build_stt_resources(sttres);
  311. /* 'build_stt_resources' returns a head and $1 is a tail */
  312. if($1)
  313. {
  314. $1->next = rsc;
  315. if(rsc)
  316. rsc->prev = $1;
  317. }
  318. else
  319. $1 = rsc;
  320. /* Find the tail again */
  321. while($1 && $1->next)
  322. $1 = $1->next;
  323. /* Now add any fontdirectory */
  324. rsc = build_fontdirs($1);
  325. /* 'build_fontdir' returns a head and $1 is a tail */
  326. if($1)
  327. {
  328. $1->next = rsc;
  329. if(rsc)
  330. rsc->prev = $1;
  331. }
  332. else
  333. $1 = rsc;
  334. /* Final statements before we're done */
  335. if ((head = get_resource_head($1)) != NULL)
  336. {
  337. if (resource_top) /* append to existing resources */
  338. {
  339. resource_t *tail = resource_top;
  340. while (tail->next) tail = tail->next;
  341. tail->next = head;
  342. head->prev = tail;
  343. }
  344. else resource_top = head;
  345. }
  346. sttres = NULL;
  347. }
  348. ;
  349. /* Resources are put into a linked list */
  350. resources
  351. : /* Empty */ { $$ = NULL; want_id = 1; }
  352. | resources resource {
  353. if($2)
  354. {
  355. resource_t *tail = $2;
  356. resource_t *head = $2;
  357. while(tail->next)
  358. tail = tail->next;
  359. while(head->prev)
  360. head = head->prev;
  361. head->prev = $1;
  362. if($1)
  363. $1->next = head;
  364. $$ = tail;
  365. /* Check for duplicate identifiers */
  366. while($1 && head)
  367. {
  368. resource_t *rsc = $1;
  369. while(rsc)
  370. {
  371. if(rsc->type == head->type
  372. && rsc->lan->id == head->lan->id
  373. && rsc->lan->sub == head->lan->sub
  374. && !compare_name_id(rsc->name, head->name)
  375. && (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type)))
  376. {
  377. yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
  378. }
  379. rsc = rsc->prev;
  380. }
  381. head = head->next;
  382. }
  383. }
  384. else if($1)
  385. {
  386. resource_t *tail = $1;
  387. while(tail->next)
  388. tail = tail->next;
  389. $$ = tail;
  390. }
  391. else
  392. $$ = NULL;
  393. if(!dont_want_id) /* See comments in language parsing below */
  394. want_id = 1;
  395. dont_want_id = 0;
  396. }
  397. /*
  398. * The following newline rule will never get reduced because we never
  399. * get the tNL token, unless we explicitly set the 'want_nl'
  400. * flag, which we don't.
  401. * The *ONLY* reason for this to be here is because Berkeley
  402. * yacc (byacc), at least version 1.9, has a bug.
  403. * (identified in the generated parser on the second
  404. * line with:
  405. * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
  406. * )
  407. * This extra rule fixes it.
  408. * The problem is that the expression handling rule "expr: xpr"
  409. * is not reduced on non-terminal tokens, defined above in the
  410. * %token declarations. Token tNL is the only non-terminal that
  411. * can occur. The error becomes visible in the language parsing
  412. * rule below, which looks at the look-ahead token and tests it
  413. * for tNL. However, byacc already generates an error upon reading
  414. * the token instead of keeping it as a lookahead. The reason
  415. * lies in the lack of a $default transition in the "expr : xpr . "
  416. * state (currently state 25). It is probably omitted because tNL
  417. * is a non-terminal and the state contains 2 s/r conflicts. The
  418. * state enumerates all possible transitions instead of using a
  419. * $default transition.
  420. * All in all, it is a bug in byacc. (period)
  421. */
  422. | resources tNL
  423. ;
  424. /* Parse top level resource definitions etc. */
  425. resource
  426. : expr usrcvt resource_definition {
  427. $$ = $3;
  428. if($$)
  429. {
  430. if($1 > 65535 || $1 < -32768)
  431. yyerror("Resource's ID out of range (%d)", $1);
  432. $$->name = new_name_id();
  433. $$->name->type = name_ord;
  434. $$->name->name.i_name = $1;
  435. chat("Got %s (%d)\n", get_typename($3), $$->name->name.i_name);
  436. }
  437. }
  438. | tIDENT usrcvt resource_definition {
  439. $$ = $3;
  440. if($$)
  441. {
  442. $$->name = new_name_id();
  443. $$->name->type = name_str;
  444. $$->name->name.s_name = $1;
  445. chat("Got %s (%s)\n", get_typename($3), $$->name->name.s_name->str.cstr);
  446. }
  447. }
  448. | stringtable {
  449. /* Don't do anything, stringtables are converted to
  450. * resource_t structures when we are finished parsing and
  451. * the final rule of the parser is reduced (see above)
  452. */
  453. $$ = NULL;
  454. chat("Got STRINGTABLE\n");
  455. }
  456. | tLANGUAGE {want_nl = 1; } expr ',' expr {
  457. /* We *NEED* the newline to delimit the expression.
  458. * Otherwise, we would not be able to set the next
  459. * want_id anymore because of the token-lookahead.
  460. *
  461. * However, we can test the lookahead-token for
  462. * being "non-expression" type, in which case we
  463. * continue. Fortunately, tNL is the only token that
  464. * will break expression parsing and is implicitly
  465. * void, so we just remove it. This scheme makes it
  466. * possible to do some (not all) fancy preprocessor
  467. * stuff.
  468. * BTW, we also need to make sure that the next
  469. * reduction of 'resources' above will *not* set
  470. * want_id because we already have a lookahead that
  471. * cannot be undone.
  472. */
  473. if(yychar != YYEMPTY && yychar != tNL)
  474. dont_want_id = 1;
  475. if(yychar == tNL)
  476. yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
  477. /* direct access to yychar in rule 'usrcvt' below. */
  478. else if(yychar == tIDENT)
  479. parser_warning("LANGUAGE statement not delimited with newline; next identifier might be wrong\n");
  480. want_nl = 0; /* We don't want it anymore if we didn't get it */
  481. if(!win32)
  482. parser_warning("LANGUAGE not supported in 16-bit mode\n");
  483. free(currentlanguage);
  484. if (get_language_codepage($3, $5) == -1)
  485. yyerror( "Language %04x is not supported", ($5<<10) + $3);
  486. currentlanguage = new_language($3, $5);
  487. $$ = NULL;
  488. chat("Got LANGUAGE %d,%d (0x%04x)\n", $3, $5, ($5<<10) + $3);
  489. }
  490. ;
  491. /*
  492. * Remapping of numerical resource types
  493. * (see also comment of called function below)
  494. */
  495. usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
  496. ;
  497. /*
  498. * Get a valid name/id
  499. */
  500. nameid : expr {
  501. if($1 > 65535 || $1 < -32768)
  502. yyerror("Resource's ID out of range (%d)", $1);
  503. $$ = new_name_id();
  504. $$->type = name_ord;
  505. $$->name.i_name = $1;
  506. }
  507. | tIDENT {
  508. $$ = new_name_id();
  509. $$->type = name_str;
  510. $$->name.s_name = $1;
  511. }
  512. ;
  513. /*
  514. * Extra string recognition for CLASS statement in dialogs
  515. */
  516. nameid_s: nameid { $$ = $1; }
  517. | tSTRING {
  518. $$ = new_name_id();
  519. $$->type = name_str;
  520. $$->name.s_name = $1;
  521. }
  522. ;
  523. /* get the value for a single resource*/
  524. resource_definition
  525. : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
  526. | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
  527. | cursor {
  528. resource_t *rsc;
  529. if($1->type == res_anicur)
  530. {
  531. $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
  532. }
  533. else if($1->type == res_curg)
  534. {
  535. cursor_t *cur;
  536. $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
  537. for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
  538. {
  539. rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
  540. rsc->prev->next = rsc;
  541. rsc = rsc->prev;
  542. rsc->name = new_name_id();
  543. rsc->name->type = name_ord;
  544. rsc->name->name.i_name = cur->id;
  545. }
  546. }
  547. else
  548. internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource\n", $1->type);
  549. free($1);
  550. }
  551. | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
  552. | dialogex {
  553. if(win32)
  554. $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language);
  555. else
  556. $$ = NULL;
  557. }
  558. | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
  559. | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
  560. | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
  561. | icon {
  562. resource_t *rsc;
  563. if($1->type == res_aniico)
  564. {
  565. $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
  566. }
  567. else if($1->type == res_icog)
  568. {
  569. icon_t *ico;
  570. $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
  571. for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
  572. {
  573. rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
  574. rsc->prev->next = rsc;
  575. rsc = rsc->prev;
  576. rsc->name = new_name_id();
  577. rsc->name->type = name_ord;
  578. rsc->name->name.i_name = ico->id;
  579. }
  580. }
  581. else
  582. internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource\n", $1->type);
  583. free($1);
  584. }
  585. | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
  586. | menuex {
  587. if(win32)
  588. $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language);
  589. else
  590. $$ = NULL;
  591. }
  592. | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
  593. | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
  594. | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
  595. | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
  596. | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
  597. | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
  598. ;
  599. filename: tIDENT { $$ = make_filename($1); }
  600. | tSTRING { $$ = make_filename($1); }
  601. ;
  602. /* ------------------------------ Bitmap ------------------------------ */
  603. bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
  604. ;
  605. /* ------------------------------ Cursor ------------------------------ */
  606. cursor : tCURSOR loadmemopts file_raw {
  607. $$ = new_ani_any();
  608. if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
  609. {
  610. $$->type = res_anicur;
  611. $$->u.ani = new_ani_curico(res_anicur, $3, $2);
  612. }
  613. else
  614. {
  615. $$->type = res_curg;
  616. $$->u.curg = new_cursor_group($3, $2);
  617. }
  618. }
  619. ;
  620. /* ------------------------------ Icon ------------------------------ */
  621. icon : tICON loadmemopts file_raw {
  622. $$ = new_ani_any();
  623. if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
  624. {
  625. $$->type = res_aniico;
  626. $$->u.ani = new_ani_curico(res_aniico, $3, $2);
  627. }
  628. else
  629. {
  630. $$->type = res_icog;
  631. $$->u.icog = new_icon_group($3, $2);
  632. }
  633. }
  634. ;
  635. /* ------------------------------ Font ------------------------------ */
  636. /*
  637. * The reading of raw_data for fonts is a Borland BRC
  638. * extension. MS generates an error. However, it is
  639. * most logical to support this, considering how wine
  640. * enters things in CVS (ascii).
  641. */
  642. font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
  643. ;
  644. /*
  645. * The fontdir is a Borland BRC extension which only
  646. * reads the data as 'raw_data' from the file.
  647. * I don't know whether it is interpreted.
  648. * The fontdir is generated if it was not present and
  649. * fonts are defined in the source.
  650. */
  651. fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
  652. ;
  653. /* ------------------------------ MessageTable ------------------------------ */
  654. /* It might be interesting to implement the MS Message compiler here as well
  655. * to get everything in one source. Might be a future project.
  656. */
  657. messagetable
  658. : tMESSAGETABLE loadmemopts file_raw {
  659. if(!win32)
  660. parser_warning("MESSAGETABLE not supported in 16-bit mode\n");
  661. $$ = new_messagetable($3, $2);
  662. }
  663. ;
  664. /* ------------------------------ HTML ------------------------------ */
  665. html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
  666. ;
  667. /* ------------------------------ RCData ------------------------------ */
  668. rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
  669. ;
  670. /* ------------------------------ DLGINIT ------------------------------ */
  671. dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
  672. ;
  673. /* ------------------------------ UserType ------------------------------ */
  674. userres : usertype loadmemopts file_raw {
  675. #ifdef WORDS_BIGENDIAN
  676. if(pedantic && byteorder != WRC_BO_LITTLE)
  677. #else
  678. if(pedantic && byteorder == WRC_BO_BIG)
  679. #endif
  680. parser_warning("Byteordering is not little-endian and type cannot be interpreted\n");
  681. $$ = new_user($1, $3, $2);
  682. }
  683. ;
  684. usertype: tNUMBER {
  685. $$ = new_name_id();
  686. $$->type = name_ord;
  687. $$->name.i_name = $1;
  688. }
  689. | tIDENT {
  690. $$ = new_name_id();
  691. $$->type = name_str;
  692. $$->name.s_name = $1;
  693. }
  694. ;
  695. /* ------------------------------ Accelerator ------------------------------ */
  696. accelerators
  697. : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
  698. $$ = new_accelerator();
  699. if($2)
  700. {
  701. $$->memopt = *($2);
  702. free($2);
  703. }
  704. else
  705. {
  706. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
  707. }
  708. if(!$5)
  709. yyerror("Accelerator table must have at least one entry");
  710. $$->events = get_event_head($5);
  711. if($3)
  712. {
  713. $$->lvc = *($3);
  714. free($3);
  715. }
  716. if(!$$->lvc.language)
  717. $$->lvc.language = dup_language(currentlanguage);
  718. }
  719. ;
  720. events : /* Empty */ { $$=NULL; }
  721. | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
  722. | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
  723. ;
  724. /*
  725. * The empty rule generates a s/r conflict because of {bi,u}nary expr
  726. * on - and +. It cannot be solved in any way because it is the same as
  727. * the if/then/else problem (LALR(1) problem). The conflict is moved
  728. * away by forcing it to be in the expression handling below.
  729. */
  730. acc_opt : /* Empty */ { $$ = 0; }
  731. | ',' accs { $$ = $2; }
  732. ;
  733. accs : acc { $$ = $1; }
  734. | accs ',' acc { $$ = $1 | $3; }
  735. ;
  736. acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
  737. | tSHIFT { $$ = WRC_AF_SHIFT; }
  738. | tCONTROL { $$ = WRC_AF_CONTROL; }
  739. | tALT { $$ = WRC_AF_ALT; }
  740. | tASCII { $$ = WRC_AF_ASCII; }
  741. | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
  742. ;
  743. /* ------------------------------ Dialog ------------------------------ */
  744. /* FIXME: Support EXSTYLE in the dialog line itself */
  745. dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
  746. tBEGIN ctrls tEND {
  747. if($2)
  748. {
  749. $10->memopt = *($2);
  750. free($2);
  751. }
  752. else
  753. $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  754. $10->x = $3;
  755. $10->y = $5;
  756. $10->width = $7;
  757. $10->height = $9;
  758. $10->controls = get_control_head($12);
  759. $$ = $10;
  760. if(!$$->gotstyle)
  761. {
  762. $$->style = new_style(0,0);
  763. $$->style->or_mask = WS_POPUP;
  764. $$->gotstyle = TRUE;
  765. }
  766. if($$->title)
  767. $$->style->or_mask |= WS_CAPTION;
  768. if($$->font)
  769. $$->style->or_mask |= DS_SETFONT;
  770. $$->style->or_mask &= ~($$->style->and_mask);
  771. $$->style->and_mask = 0;
  772. if(!$$->lvc.language)
  773. $$->lvc.language = dup_language(currentlanguage);
  774. }
  775. ;
  776. dlg_attributes
  777. : /* Empty */ { $$=new_dialog(); }
  778. | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
  779. | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
  780. | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
  781. | dlg_attributes opt_font { $$=dialog_font($2,$1); }
  782. | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
  783. | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
  784. | dlg_attributes opt_language { $$=dialog_language($2,$1); }
  785. | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
  786. | dlg_attributes opt_version { $$=dialog_version($2,$1); }
  787. ;
  788. ctrls : /* Empty */ { $$ = NULL; }
  789. | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
  790. | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
  791. | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
  792. | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
  793. | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
  794. | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
  795. | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
  796. | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
  797. | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
  798. /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
  799. | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
  800. | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
  801. | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
  802. | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
  803. | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
  804. | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
  805. | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
  806. | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
  807. /* special treatment for icons, as the extent is optional */
  808. | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
  809. $10->title = $3;
  810. $10->id = $5;
  811. $10->x = $7;
  812. $10->y = $9;
  813. $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
  814. }
  815. ;
  816. lab_ctrl
  817. : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
  818. $$=new_control();
  819. $$->title = $1;
  820. $$->id = $3;
  821. $$->x = $5;
  822. $$->y = $7;
  823. $$->width = $9;
  824. $$->height = $11;
  825. if($12)
  826. {
  827. $$->style = $12->style;
  828. $$->gotstyle = TRUE;
  829. if ($12->exstyle)
  830. {
  831. $$->exstyle = $12->exstyle;
  832. $$->gotexstyle = TRUE;
  833. }
  834. free($12);
  835. }
  836. }
  837. ;
  838. ctrl_desc
  839. : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
  840. $$ = new_control();
  841. $$->id = $1;
  842. $$->x = $3;
  843. $$->y = $5;
  844. $$->width = $7;
  845. $$->height = $9;
  846. if($10)
  847. {
  848. $$->style = $10->style;
  849. $$->gotstyle = TRUE;
  850. if ($10->exstyle)
  851. {
  852. $$->exstyle = $10->exstyle;
  853. $$->gotexstyle = TRUE;
  854. }
  855. free($10);
  856. }
  857. }
  858. ;
  859. iconinfo: /* Empty */
  860. { $$ = new_control(); }
  861. | ',' expr ',' expr {
  862. $$ = new_control();
  863. $$->width = $2;
  864. $$->height = $4;
  865. }
  866. | ',' expr ',' expr ',' style {
  867. $$ = new_control();
  868. $$->width = $2;
  869. $$->height = $4;
  870. $$->style = $6;
  871. $$->gotstyle = TRUE;
  872. }
  873. | ',' expr ',' expr ',' style ',' style {
  874. $$ = new_control();
  875. $$->width = $2;
  876. $$->height = $4;
  877. $$->style = $6;
  878. $$->gotstyle = TRUE;
  879. $$->exstyle = $8;
  880. $$->gotexstyle = TRUE;
  881. }
  882. ;
  883. gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
  884. $$=new_control();
  885. $$->title = $1;
  886. $$->id = $3;
  887. $$->ctlclass = convert_ctlclass($5);
  888. $$->style = $7;
  889. $$->gotstyle = TRUE;
  890. $$->x = $9;
  891. $$->y = $11;
  892. $$->width = $13;
  893. $$->height = $15;
  894. $$->exstyle = $17;
  895. $$->gotexstyle = TRUE;
  896. }
  897. | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
  898. $$=new_control();
  899. $$->title = $1;
  900. $$->id = $3;
  901. $$->ctlclass = convert_ctlclass($5);
  902. $$->style = $7;
  903. $$->gotstyle = TRUE;
  904. $$->x = $9;
  905. $$->y = $11;
  906. $$->width = $13;
  907. $$->height = $15;
  908. }
  909. ;
  910. opt_font
  911. : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
  912. ;
  913. /* ------------------------------ style flags ------------------------------ */
  914. optional_style_pair
  915. : /* Empty */ { $$ = NULL; }
  916. | ',' style { $$ = new_style_pair($2, 0); }
  917. | ',' style ',' style { $$ = new_style_pair($2, $4); }
  918. ;
  919. style
  920. : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
  921. | '(' style ')' { $$ = $2; }
  922. | any_num { $$ = new_style($1, 0); }
  923. | tNOT any_num { $$ = new_style(0, $2); }
  924. ;
  925. ctlclass
  926. : expr {
  927. $$ = new_name_id();
  928. $$->type = name_ord;
  929. $$->name.i_name = $1;
  930. }
  931. | tSTRING {
  932. $$ = new_name_id();
  933. $$->type = name_str;
  934. $$->name.s_name = $1;
  935. }
  936. ;
  937. /* ------------------------------ DialogEx ------------------------------ */
  938. dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
  939. tBEGIN exctrls tEND {
  940. if(!win32)
  941. parser_warning("DIALOGEX not supported in 16-bit mode\n");
  942. if($2)
  943. {
  944. $11->memopt = *($2);
  945. free($2);
  946. }
  947. else
  948. $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  949. $11->x = $3;
  950. $11->y = $5;
  951. $11->width = $7;
  952. $11->height = $9;
  953. if($10)
  954. {
  955. $11->helpid = *($10);
  956. $11->gothelpid = TRUE;
  957. free($10);
  958. }
  959. $11->controls = get_control_head($13);
  960. $$ = $11;
  961. assert($$->style != NULL);
  962. if(!$$->gotstyle)
  963. {
  964. $$->style->or_mask = WS_POPUP;
  965. $$->gotstyle = TRUE;
  966. }
  967. if($$->title)
  968. $$->style->or_mask |= WS_CAPTION;
  969. if($$->font)
  970. $$->style->or_mask |= DS_SETFONT;
  971. $$->style->or_mask &= ~($$->style->and_mask);
  972. $$->style->and_mask = 0;
  973. if(!$$->lvc.language)
  974. $$->lvc.language = dup_language(currentlanguage);
  975. }
  976. ;
  977. dlgex_attribs
  978. : /* Empty */ { $$=new_dialog(); $$->is_ex = TRUE; }
  979. | dlgex_attribs tSTYLE style { $$=dialog_style($3,$1); }
  980. | dlgex_attribs tEXSTYLE style { $$=dialog_exstyle($3,$1); }
  981. | dlgex_attribs tCAPTION tSTRING { $$=dialog_caption($3,$1); }
  982. | dlgex_attribs opt_font { $$=dialog_font($2,$1); }
  983. | dlgex_attribs opt_exfont { $$=dialog_font($2,$1); }
  984. | dlgex_attribs tCLASS nameid_s { $$=dialog_class($3,$1); }
  985. | dlgex_attribs tMENU nameid { $$=dialog_menu($3,$1); }
  986. | dlgex_attribs opt_language { $$=dialog_language($2,$1); }
  987. | dlgex_attribs opt_characts { $$=dialog_characteristics($2,$1); }
  988. | dlgex_attribs opt_version { $$=dialog_version($2,$1); }
  989. ;
  990. exctrls : /* Empty */ { $$ = NULL; }
  991. | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
  992. | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
  993. | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
  994. | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
  995. | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
  996. | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
  997. | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
  998. | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
  999. | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
  1000. /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
  1001. | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
  1002. | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
  1003. | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
  1004. | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
  1005. | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
  1006. | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
  1007. | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
  1008. | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
  1009. /* special treatment for icons, as the extent is optional */
  1010. | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
  1011. $10->title = $3;
  1012. $10->id = $5;
  1013. $10->x = $7;
  1014. $10->y = $9;
  1015. $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
  1016. }
  1017. ;
  1018. gen_exctrl
  1019. : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
  1020. expr ',' style helpid opt_data {
  1021. $$=new_control();
  1022. $$->title = $1;
  1023. $$->id = $3;
  1024. $$->ctlclass = convert_ctlclass($5);
  1025. $$->style = $7;
  1026. $$->gotstyle = TRUE;
  1027. $$->x = $9;
  1028. $$->y = $11;
  1029. $$->width = $13;
  1030. $$->height = $15;
  1031. if($17)
  1032. {
  1033. $$->exstyle = $17;
  1034. $$->gotexstyle = TRUE;
  1035. }
  1036. if($18)
  1037. {
  1038. $$->helpid = *($18);
  1039. $$->gothelpid = TRUE;
  1040. free($18);
  1041. }
  1042. $$->extra = $19;
  1043. }
  1044. | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
  1045. $$=new_control();
  1046. $$->title = $1;
  1047. $$->id = $3;
  1048. $$->style = $7;
  1049. $$->gotstyle = TRUE;
  1050. $$->ctlclass = convert_ctlclass($5);
  1051. $$->x = $9;
  1052. $$->y = $11;
  1053. $$->width = $13;
  1054. $$->height = $15;
  1055. $$->extra = $16;
  1056. }
  1057. ;
  1058. lab_exctrl
  1059. : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
  1060. $$=new_control();
  1061. $$->title = $1;
  1062. $$->id = $3;
  1063. $$->x = $5;
  1064. $$->y = $7;
  1065. $$->width = $9;
  1066. $$->height = $11;
  1067. if($12)
  1068. {
  1069. $$->style = $12->style;
  1070. $$->gotstyle = TRUE;
  1071. if ($12->exstyle)
  1072. {
  1073. $$->exstyle = $12->exstyle;
  1074. $$->gotexstyle = TRUE;
  1075. }
  1076. free($12);
  1077. }
  1078. $$->extra = $14;
  1079. }
  1080. ;
  1081. exctrl_desc
  1082. : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
  1083. $$ = new_control();
  1084. $$->id = $1;
  1085. $$->x = $3;
  1086. $$->y = $5;
  1087. $$->width = $7;
  1088. $$->height = $9;
  1089. if($10)
  1090. {
  1091. $$->style = $10->style;
  1092. $$->gotstyle = TRUE;
  1093. if ($10->exstyle)
  1094. {
  1095. $$->exstyle = $10->exstyle;
  1096. $$->gotexstyle = TRUE;
  1097. }
  1098. free($10);
  1099. }
  1100. $$->extra = $12;
  1101. }
  1102. ;
  1103. opt_data: /* Empty */ { $$ = NULL; }
  1104. | raw_data { $$ = $1; }
  1105. ;
  1106. helpid : /* Empty */ { $$ = NULL; }
  1107. | ',' expr { $$ = new_int($2); }
  1108. ;
  1109. opt_exfont
  1110. : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
  1111. ;
  1112. /*
  1113. * FIXME: This odd expression is here to nullify an extra token found
  1114. * in some appstudio produced resources which appear to do nothing.
  1115. */
  1116. opt_expr: /* Empty */ { $$ = NULL; }
  1117. | ',' expr { $$ = NULL; }
  1118. ;
  1119. /* ------------------------------ Menu ------------------------------ */
  1120. menu : tMENU loadmemopts opt_lvc menu_body {
  1121. if(!$4)
  1122. yyerror("Menu must contain items");
  1123. $$ = new_menu();
  1124. if($2)
  1125. {
  1126. $$->memopt = *($2);
  1127. free($2);
  1128. }
  1129. else
  1130. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  1131. $$->items = get_item_head($4);
  1132. if($3)
  1133. {
  1134. $$->lvc = *($3);
  1135. free($3);
  1136. }
  1137. if(!$$->lvc.language)
  1138. $$->lvc.language = dup_language(currentlanguage);
  1139. }
  1140. ;
  1141. menu_body
  1142. : tBEGIN item_definitions tEND { $$ = $2; }
  1143. ;
  1144. item_definitions
  1145. : /* Empty */ {$$ = NULL;}
  1146. | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
  1147. $$=new_menu_item();
  1148. $$->prev = $1;
  1149. if($1)
  1150. $1->next = $$;
  1151. $$->id = $5;
  1152. $$->state = $6;
  1153. $$->name = $3;
  1154. }
  1155. | item_definitions tMENUITEM tSEPARATOR {
  1156. $$=new_menu_item();
  1157. $$->prev = $1;
  1158. if($1)
  1159. $1->next = $$;
  1160. }
  1161. | item_definitions tPOPUP tSTRING item_options menu_body {
  1162. $$ = new_menu_item();
  1163. $$->prev = $1;
  1164. if($1)
  1165. $1->next = $$;
  1166. $$->popup = get_item_head($5);
  1167. $$->name = $3;
  1168. }
  1169. ;
  1170. /* NOTE: item_options is right recursive because it would introduce
  1171. * a shift/reduce conflict on ',' in itemex_options due to the
  1172. * empty rule here. The parser is now forced to look beyond the ','
  1173. * before reducing (force shift).
  1174. * Right recursion here is not a problem because we cannot expect
  1175. * more than 7 parserstack places to be occupied while parsing this
  1176. * (who would want to specify a MF_x flag twice?).
  1177. */
  1178. item_options
  1179. : /* Empty */ { $$ = 0; }
  1180. | ',' item_options { $$ = $2; }
  1181. | tCHECKED item_options { $$ = $2 | MF_CHECKED; }
  1182. | tGRAYED item_options { $$ = $2 | MF_GRAYED; }
  1183. | tHELP item_options { $$ = $2 | MF_HELP; }
  1184. | tINACTIVE item_options { $$ = $2 | MF_DISABLED; }
  1185. | tMENUBARBREAK item_options { $$ = $2 | MF_MENUBARBREAK; }
  1186. | tMENUBREAK item_options { $$ = $2 | MF_MENUBREAK; }
  1187. ;
  1188. /* ------------------------------ MenuEx ------------------------------ */
  1189. menuex : tMENUEX loadmemopts opt_lvc menuex_body {
  1190. if(!win32)
  1191. parser_warning("MENUEX not supported in 16-bit mode\n");
  1192. if(!$4)
  1193. yyerror("MenuEx must contain items");
  1194. $$ = new_menu();
  1195. $$->is_ex = TRUE;
  1196. if($2)
  1197. {
  1198. $$->memopt = *($2);
  1199. free($2);
  1200. }
  1201. else
  1202. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  1203. $$->items = get_item_head($4);
  1204. if($3)
  1205. {
  1206. $$->lvc = *($3);
  1207. free($3);
  1208. }
  1209. if(!$$->lvc.language)
  1210. $$->lvc.language = dup_language(currentlanguage);
  1211. }
  1212. ;
  1213. menuex_body
  1214. : tBEGIN itemex_definitions tEND { $$ = $2; }
  1215. ;
  1216. itemex_definitions
  1217. : /* Empty */ {$$ = NULL; }
  1218. | itemex_definitions tMENUITEM tSTRING itemex_options {
  1219. $$ = new_menu_item();
  1220. $$->prev = $1;
  1221. if($1)
  1222. $1->next = $$;
  1223. $$->name = $3;
  1224. $$->id = $4->id;
  1225. $$->type = $4->type;
  1226. $$->state = $4->state;
  1227. $$->helpid = $4->helpid;
  1228. $$->gotid = $4->gotid;
  1229. $$->gottype = $4->gottype;
  1230. $$->gotstate = $4->gotstate;
  1231. $$->gothelpid = $4->gothelpid;
  1232. free($4);
  1233. }
  1234. | itemex_definitions tMENUITEM tSEPARATOR {
  1235. $$ = new_menu_item();
  1236. $$->prev = $1;
  1237. if($1)
  1238. $1->next = $$;
  1239. }
  1240. | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
  1241. $$ = new_menu_item();
  1242. $$->prev = $1;
  1243. if($1)
  1244. $1->next = $$;
  1245. $$->popup = get_item_head($5);
  1246. $$->name = $3;
  1247. $$->id = $4->id;
  1248. $$->type = $4->type;
  1249. $$->state = $4->state;
  1250. $$->helpid = $4->helpid;
  1251. $$->gotid = $4->gotid;
  1252. $$->gottype = $4->gottype;
  1253. $$->gotstate = $4->gotstate;
  1254. $$->gothelpid = $4->gothelpid;
  1255. free($4);
  1256. }
  1257. ;
  1258. itemex_options
  1259. : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
  1260. | ',' expr {
  1261. $$ = new_itemex_opt($2, 0, 0, 0);
  1262. $$->gotid = TRUE;
  1263. }
  1264. | ',' e_expr ',' e_expr item_options {
  1265. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
  1266. $$->gotid = TRUE;
  1267. $$->gottype = TRUE;
  1268. $$->gotstate = TRUE;
  1269. free($2);
  1270. free($4);
  1271. }
  1272. | ',' e_expr ',' e_expr ',' expr {
  1273. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
  1274. $$->gotid = TRUE;
  1275. $$->gottype = TRUE;
  1276. $$->gotstate = TRUE;
  1277. free($2);
  1278. free($4);
  1279. }
  1280. ;
  1281. itemex_p_options
  1282. : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
  1283. | ',' expr {
  1284. $$ = new_itemex_opt($2, 0, 0, 0);
  1285. $$->gotid = TRUE;
  1286. }
  1287. | ',' e_expr ',' expr {
  1288. $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
  1289. free($2);
  1290. $$->gotid = TRUE;
  1291. $$->gottype = TRUE;
  1292. }
  1293. | ',' e_expr ',' e_expr ',' expr {
  1294. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
  1295. free($2);
  1296. free($4);
  1297. $$->gotid = TRUE;
  1298. $$->gottype = TRUE;
  1299. $$->gotstate = TRUE;
  1300. }
  1301. | ',' e_expr ',' e_expr ',' e_expr ',' expr {
  1302. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
  1303. free($2);
  1304. free($4);
  1305. free($6);
  1306. $$->gotid = TRUE;
  1307. $$->gottype = TRUE;
  1308. $$->gotstate = TRUE;
  1309. $$->gothelpid = TRUE;
  1310. }
  1311. ;
  1312. /* ------------------------------ StringTable ------------------------------ */
  1313. /* Stringtables are parsed differently than other resources because their
  1314. * layout is substantially different from other resources.
  1315. * The table is parsed through a _global_ variable 'tagstt' which holds the
  1316. * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
  1317. * list of stringtables of different languages.
  1318. */
  1319. stringtable
  1320. : stt_head tBEGIN strings tEND {
  1321. if(!$3)
  1322. {
  1323. yyerror("Stringtable must have at least one entry");
  1324. }
  1325. else
  1326. {
  1327. stringtable_t *stt;
  1328. /* Check if we added to a language table or created
  1329. * a new one.
  1330. */
  1331. for(stt = sttres; stt; stt = stt->next)
  1332. {
  1333. if(stt == tagstt)
  1334. break;
  1335. }
  1336. if(!stt)
  1337. {
  1338. /* It is a new one */
  1339. if(sttres)
  1340. {
  1341. sttres->prev = tagstt;
  1342. tagstt->next = sttres;
  1343. sttres = tagstt;
  1344. }
  1345. else
  1346. sttres = tagstt;
  1347. }
  1348. /* Else, we're done */
  1349. }
  1350. free(tagstt_memopt);
  1351. tagstt_memopt = NULL;
  1352. $$ = tagstt;
  1353. }
  1354. ;
  1355. /* This is to get the language of the currently parsed stringtable */
  1356. stt_head: tSTRINGTABLE loadmemopts opt_lvc {
  1357. if((tagstt = find_stringtable($3)) == NULL)
  1358. tagstt = new_stringtable($3);
  1359. tagstt_memopt = $2;
  1360. tagstt_version = $3->version;
  1361. tagstt_characts = $3->characts;
  1362. free($3);
  1363. }
  1364. ;
  1365. strings : /* Empty */ { $$ = NULL; }
  1366. | strings expr opt_comma tSTRING {
  1367. int i;
  1368. assert(tagstt != NULL);
  1369. if($2 > 65535 || $2 < -32768)
  1370. yyerror("Stringtable entry's ID out of range (%d)", $2);
  1371. /* Search for the ID */
  1372. for(i = 0; i < tagstt->nentries; i++)
  1373. {
  1374. if(tagstt->entries[i].id == $2)
  1375. yyerror("Stringtable ID %d already in use", $2);
  1376. }
  1377. /* If we get here, then we have a new unique entry */
  1378. tagstt->nentries++;
  1379. tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
  1380. tagstt->entries[tagstt->nentries-1].id = $2;
  1381. tagstt->entries[tagstt->nentries-1].str = $4;
  1382. if(tagstt_memopt)
  1383. tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
  1384. else
  1385. tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
  1386. tagstt->entries[tagstt->nentries-1].version = tagstt_version;
  1387. tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
  1388. if(pedantic && !$4->size)
  1389. parser_warning("Zero length strings make no sense\n");
  1390. if(!win32 && $4->size > 254)
  1391. yyerror("Stringtable entry more than 254 characters");
  1392. if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
  1393. yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
  1394. $$ = tagstt;
  1395. }
  1396. ;
  1397. opt_comma /* There seem to be two ways to specify a stringtable... */
  1398. : /* Empty */
  1399. | ','
  1400. ;
  1401. /* ------------------------------ VersionInfo ------------------------------ */
  1402. versioninfo
  1403. : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
  1404. $$ = $3;
  1405. if($2)
  1406. {
  1407. $$->memopt = *($2);
  1408. free($2);
  1409. }
  1410. else
  1411. $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
  1412. $$->blocks = get_ver_block_head($5);
  1413. /* Set language; there is no version or characteristics */
  1414. $$->lvc.language = dup_language(currentlanguage);
  1415. }
  1416. ;
  1417. fix_version
  1418. : /* Empty */ { $$ = new_versioninfo(); }
  1419. | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
  1420. if($1->gotit.fv)
  1421. yyerror("FILEVERSION already defined");
  1422. $$ = $1;
  1423. $$->filever_maj1 = $3;
  1424. $$->filever_maj2 = $5;
  1425. $$->filever_min1 = $7;
  1426. $$->filever_min2 = $9;
  1427. $$->gotit.fv = 1;
  1428. }
  1429. | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
  1430. if($1->gotit.pv)
  1431. yyerror("PRODUCTVERSION already defined");
  1432. $$ = $1;
  1433. $$->prodver_maj1 = $3;
  1434. $$->prodver_maj2 = $5;
  1435. $$->prodver_min1 = $7;
  1436. $$->prodver_min2 = $9;
  1437. $$->gotit.pv = 1;
  1438. }
  1439. | fix_version tFILEFLAGS expr {
  1440. if($1->gotit.ff)
  1441. yyerror("FILEFLAGS already defined");
  1442. $$ = $1;
  1443. $$->fileflags = $3;
  1444. $$->gotit.ff = 1;
  1445. }
  1446. | fix_version tFILEFLAGSMASK expr {
  1447. if($1->gotit.ffm)
  1448. yyerror("FILEFLAGSMASK already defined");
  1449. $$ = $1;
  1450. $$->fileflagsmask = $3;
  1451. $$->gotit.ffm = 1;
  1452. }
  1453. | fix_version tFILEOS expr {
  1454. if($1->gotit.fo)
  1455. yyerror("FILEOS already defined");
  1456. $$ = $1;
  1457. $$->fileos = $3;
  1458. $$->gotit.fo = 1;
  1459. }
  1460. | fix_version tFILETYPE expr {
  1461. if($1->gotit.ft)
  1462. yyerror("FILETYPE already defined");
  1463. $$ = $1;
  1464. $$->filetype = $3;
  1465. $$->gotit.ft = 1;
  1466. }
  1467. | fix_version tFILESUBTYPE expr {
  1468. if($1->gotit.fst)
  1469. yyerror("FILESUBTYPE already defined");
  1470. $$ = $1;
  1471. $$->filesubtype = $3;
  1472. $$->gotit.fst = 1;
  1473. }
  1474. ;
  1475. ver_blocks
  1476. : /* Empty */ { $$ = NULL; }
  1477. | ver_blocks ver_block {
  1478. $$ = $2;
  1479. $$->prev = $1;
  1480. if($1)
  1481. $1->next = $$;
  1482. }
  1483. ;
  1484. ver_block
  1485. : tBLOCK tSTRING tBEGIN ver_values tEND {
  1486. $$ = new_ver_block();
  1487. $$->name = $2;
  1488. $$->values = get_ver_value_head($4);
  1489. }
  1490. ;
  1491. ver_values
  1492. : /* Empty */ { $$ = NULL; }
  1493. | ver_values ver_value {
  1494. $$ = $2;
  1495. $$->prev = $1;
  1496. if($1)
  1497. $1->next = $$;
  1498. }
  1499. ;
  1500. ver_value
  1501. : ver_block {
  1502. $$ = new_ver_value();
  1503. $$->type = val_block;
  1504. $$->value.block = $1;
  1505. }
  1506. | tVALUE tSTRING ',' tSTRING {
  1507. $$ = new_ver_value();
  1508. $$->type = val_str;
  1509. $$->key = $2;
  1510. $$->value.str = $4;
  1511. }
  1512. | tVALUE tSTRING ',' ver_words {
  1513. $$ = new_ver_value();
  1514. $$->type = val_words;
  1515. $$->key = $2;
  1516. $$->value.words = $4;
  1517. }
  1518. ;
  1519. ver_words
  1520. : expr { $$ = new_ver_words($1); }
  1521. | ver_words ',' expr { $$ = add_ver_words($1, $3); }
  1522. ;
  1523. /* ------------------------------ Toolbar ------------------------------ */
  1524. toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
  1525. int nitems;
  1526. toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
  1527. $$ = new_toolbar($3, $5, items, nitems);
  1528. if($2)
  1529. {
  1530. $$->memopt = *($2);
  1531. free($2);
  1532. }
  1533. else
  1534. {
  1535. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
  1536. }
  1537. if($6)
  1538. {
  1539. $$->lvc = *($6);
  1540. free($6);
  1541. }
  1542. if(!$$->lvc.language)
  1543. {
  1544. $$->lvc.language = dup_language(currentlanguage);
  1545. }
  1546. }
  1547. ;
  1548. toolbar_items
  1549. : /* Empty */ { $$ = NULL; }
  1550. | toolbar_items tBUTTON expr {
  1551. toolbar_item_t *idrec = new_toolbar_item();
  1552. idrec->id = $3;
  1553. $$ = ins_tlbr_button($1, idrec);
  1554. }
  1555. | toolbar_items tSEPARATOR {
  1556. toolbar_item_t *idrec = new_toolbar_item();
  1557. idrec->id = 0;
  1558. $$ = ins_tlbr_button($1, idrec);
  1559. }
  1560. ;
  1561. /* ------------------------------ Memory options ------------------------------ */
  1562. loadmemopts
  1563. : /* Empty */ { $$ = NULL; }
  1564. | loadmemopts lamo {
  1565. if($1)
  1566. {
  1567. *($1) |= *($2);
  1568. $$ = $1;
  1569. free($2);
  1570. }
  1571. else
  1572. $$ = $2;
  1573. }
  1574. | loadmemopts lama {
  1575. if($1)
  1576. {
  1577. *($1) &= *($2);
  1578. $$ = $1;
  1579. free($2);
  1580. }
  1581. else
  1582. {
  1583. *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
  1584. $$ = $2;
  1585. }
  1586. }
  1587. ;
  1588. lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD);
  1589. if (win32 && pedantic) parser_warning("PRELOAD is ignored in 32-bit mode\n"); }
  1590. | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE);
  1591. if (win32 && pedantic) parser_warning("MOVEABLE is ignored in 32-bit mode\n"); }
  1592. | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE);
  1593. if (win32 && pedantic) parser_warning("DISCARDABLE is ignored in 32-bit mode\n"); }
  1594. | tPURE { $$ = new_int(WRC_MO_PURE);
  1595. if (win32 && pedantic) parser_warning("PURE is ignored in 32-bit mode\n"); }
  1596. ;
  1597. lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD);
  1598. if (win32 && pedantic) parser_warning("LOADONCALL is ignored in 32-bit mode\n"); }
  1599. | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE);
  1600. if (win32 && pedantic) parser_warning("FIXED is ignored in 32-bit mode\n"); }
  1601. | tIMPURE { $$ = new_int(~WRC_MO_PURE);
  1602. if (win32 && pedantic) parser_warning("IMPURE is ignored in 32-bit mode\n"); }
  1603. ;
  1604. /* ------------------------------ Win32 options ------------------------------ */
  1605. opt_lvc : /* Empty */ { $$ = new_lvc(); }
  1606. | opt_lvc opt_language {
  1607. if(!win32)
  1608. parser_warning("LANGUAGE not supported in 16-bit mode\n");
  1609. if($1->language)
  1610. yyerror("Language already defined");
  1611. $$ = $1;
  1612. $1->language = $2;
  1613. }
  1614. | opt_lvc opt_characts {
  1615. if(!win32)
  1616. parser_warning("CHARACTERISTICS not supported in 16-bit mode\n");
  1617. if($1->characts)
  1618. yyerror("Characteristics already defined");
  1619. $$ = $1;
  1620. $1->characts = $2;
  1621. }
  1622. | opt_lvc opt_version {
  1623. if(!win32)
  1624. parser_warning("VERSION not supported in 16-bit mode\n");
  1625. if($1->version)
  1626. yyerror("Version already defined");
  1627. $$ = $1;
  1628. $1->version = $2;
  1629. }
  1630. ;
  1631. /*
  1632. * This here is another s/r conflict on {bi,u}nary + and -.
  1633. * It is due to the look-ahead which must determine when the
  1634. * rule opt_language ends. It could be solved with adding a
  1635. * tNL at the end, but that seems unreasonable to do.
  1636. * The conflict is now moved to the expression handling below.
  1637. */
  1638. opt_language
  1639. : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
  1640. if (get_language_codepage($2, $4) == -1)
  1641. yyerror( "Language %04x is not supported", ($4<<10) + $2);
  1642. }
  1643. ;
  1644. opt_characts
  1645. : tCHARACTERISTICS expr { $$ = new_characts($2); }
  1646. ;
  1647. opt_version
  1648. : tVERSION expr { $$ = new_version($2); }
  1649. ;
  1650. /* ------------------------------ Raw data handling ------------------------------ */
  1651. raw_data: opt_lvc tBEGIN raw_elements tEND {
  1652. if($1)
  1653. {
  1654. $3->lvc = *($1);
  1655. free($1);
  1656. }
  1657. if(!$3->lvc.language)
  1658. $3->lvc.language = dup_language(currentlanguage);
  1659. $$ = $3;
  1660. }
  1661. ;
  1662. raw_elements
  1663. : tRAWDATA { $$ = $1; }
  1664. | tNUMBER { $$ = int2raw_data($1); }
  1665. | '-' tNUMBER { $$ = int2raw_data(-($2)); }
  1666. | tLNUMBER { $$ = long2raw_data($1); }
  1667. | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
  1668. | tSTRING { $$ = str2raw_data($1); }
  1669. | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
  1670. | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
  1671. | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
  1672. | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
  1673. | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
  1674. | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
  1675. ;
  1676. /* File data or raw data */
  1677. file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
  1678. | raw_data { $$ = $1; }
  1679. ;
  1680. /* ------------------------------ Win32 expressions ------------------------------ */
  1681. /* All win16 numbers are also handled here. This is inconsistent with MS
  1682. * resource compiler, but what the heck, it's just handy to have.
  1683. */
  1684. e_expr : /* Empty */ { $$ = 0; }
  1685. | expr { $$ = new_int($1); }
  1686. ;
  1687. /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
  1688. expr : xpr { $$ = ($1); }
  1689. ;
  1690. xpr : xpr '+' xpr { $$ = ($1) + ($3); }
  1691. | xpr '-' xpr { $$ = ($1) - ($3); }
  1692. | xpr '|' xpr { $$ = ($1) | ($3); }
  1693. | xpr '&' xpr { $$ = ($1) & ($3); }
  1694. | xpr '*' xpr { $$ = ($1) * ($3); }
  1695. | xpr '/' xpr { $$ = ($1) / ($3); }
  1696. | xpr '^' xpr { $$ = ($1) ^ ($3); }
  1697. | '~' xpr { $$ = ~($2); }
  1698. | '-' xpr %prec pUPM { $$ = -($2); }
  1699. | '+' xpr %prec pUPM { $$ = $2; }
  1700. | '(' xpr ')' { $$ = $2; }
  1701. | any_num { $$ = $1; }
  1702. | tNOT any_num { $$ = ~($2); }
  1703. ;
  1704. any_num : tNUMBER { $$ = $1; }
  1705. | tLNUMBER { $$ = $1; }
  1706. ;
  1707. %%
  1708. /* Dialog specific functions */
  1709. static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
  1710. {
  1711. assert(dlg != NULL);
  1712. if(dlg->style == NULL)
  1713. {
  1714. dlg->style = new_style(0,0);
  1715. }
  1716. if(dlg->gotstyle)
  1717. {
  1718. parser_warning("Style already defined, or-ing together\n");
  1719. }
  1720. else
  1721. {
  1722. dlg->style->or_mask = 0;
  1723. dlg->style->and_mask = 0;
  1724. }
  1725. dlg->style->or_mask |= st->or_mask;
  1726. dlg->style->and_mask |= st->and_mask;
  1727. dlg->gotstyle = TRUE;
  1728. free(st);
  1729. return dlg;
  1730. }
  1731. static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
  1732. {
  1733. assert(dlg != NULL);
  1734. if(dlg->exstyle == NULL)
  1735. {
  1736. dlg->exstyle = new_style(0,0);
  1737. }
  1738. if(dlg->gotexstyle)
  1739. {
  1740. parser_warning("ExStyle already defined, or-ing together\n");
  1741. }
  1742. else
  1743. {
  1744. dlg->exstyle->or_mask = 0;
  1745. dlg->exstyle->and_mask = 0;
  1746. }
  1747. dlg->exstyle->or_mask |= st->or_mask;
  1748. dlg->exstyle->and_mask |= st->and_mask;
  1749. dlg->gotexstyle = TRUE;
  1750. free(st);
  1751. return dlg;
  1752. }
  1753. static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
  1754. {
  1755. assert(dlg != NULL);
  1756. if(dlg->title)
  1757. yyerror("Caption already defined");
  1758. dlg->title = s;
  1759. return dlg;
  1760. }
  1761. static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
  1762. {
  1763. assert(dlg != NULL);
  1764. if(dlg->font)
  1765. yyerror("Font already defined");
  1766. dlg->font = f;
  1767. return dlg;
  1768. }
  1769. static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
  1770. {
  1771. assert(dlg != NULL);
  1772. if(dlg->dlgclass)
  1773. yyerror("Class already defined");
  1774. dlg->dlgclass = n;
  1775. return dlg;
  1776. }
  1777. static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
  1778. {
  1779. assert(dlg != NULL);
  1780. if(dlg->menu)
  1781. yyerror("Menu already defined");
  1782. dlg->menu = m;
  1783. return dlg;
  1784. }
  1785. static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
  1786. {
  1787. assert(dlg != NULL);
  1788. if(dlg->lvc.language)
  1789. yyerror("Language already defined");
  1790. dlg->lvc.language = l;
  1791. return dlg;
  1792. }
  1793. static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
  1794. {
  1795. assert(dlg != NULL);
  1796. if(dlg->lvc.characts)
  1797. yyerror("Characteristics already defined");
  1798. dlg->lvc.characts = c;
  1799. return dlg;
  1800. }
  1801. static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
  1802. {
  1803. assert(dlg != NULL);
  1804. if(dlg->lvc.version)
  1805. yyerror("Version already defined");
  1806. dlg->lvc.version = v;
  1807. return dlg;
  1808. }
  1809. /* Controls specific functions */
  1810. static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
  1811. {
  1812. /* Hm... this seems to be jammed in at all time... */
  1813. int defaultstyle = WS_CHILD | WS_VISIBLE;
  1814. assert(ctrl != NULL);
  1815. ctrl->prev = prev;
  1816. if(prev)
  1817. prev->next = ctrl;
  1818. /* Check for duplicate identifiers */
  1819. while (prev)
  1820. {
  1821. if (ctrl->id != -1 && ctrl->id == prev->id)
  1822. parser_warning("Duplicate dialog control id %d\n", ctrl->id);
  1823. prev = prev->prev;
  1824. }
  1825. if(type != -1)
  1826. {
  1827. ctrl->ctlclass = new_name_id();
  1828. ctrl->ctlclass->type = name_ord;
  1829. ctrl->ctlclass->name.i_name = type;
  1830. }
  1831. switch(type)
  1832. {
  1833. case CT_BUTTON:
  1834. if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
  1835. defaultstyle |= WS_TABSTOP;
  1836. break;
  1837. case CT_EDIT:
  1838. defaultstyle |= WS_TABSTOP | WS_BORDER;
  1839. break;
  1840. case CT_LISTBOX:
  1841. defaultstyle |= LBS_NOTIFY | WS_BORDER;
  1842. break;
  1843. case CT_COMBOBOX:
  1844. if (!ctrl->gotstyle || !(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
  1845. defaultstyle |= CBS_SIMPLE;
  1846. break;
  1847. case CT_STATIC:
  1848. if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
  1849. defaultstyle |= WS_GROUP;
  1850. break;
  1851. }
  1852. if(!ctrl->gotstyle) /* Handle default style setting */
  1853. {
  1854. switch(type)
  1855. {
  1856. case CT_EDIT:
  1857. defaultstyle |= ES_LEFT;
  1858. break;
  1859. case CT_LISTBOX:
  1860. defaultstyle |= LBS_NOTIFY;
  1861. break;
  1862. case CT_COMBOBOX:
  1863. defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
  1864. break;
  1865. case CT_SCROLLBAR:
  1866. defaultstyle |= SBS_HORZ;
  1867. break;
  1868. case CT_BUTTON:
  1869. switch(special_style)
  1870. {
  1871. case BS_CHECKBOX:
  1872. case BS_DEFPUSHBUTTON:
  1873. case BS_PUSHBUTTON:
  1874. /* case BS_PUSHBOX: */
  1875. case BS_AUTORADIOBUTTON:
  1876. case BS_AUTO3STATE:
  1877. case BS_3STATE:
  1878. case BS_AUTOCHECKBOX:
  1879. defaultstyle |= WS_TABSTOP;
  1880. break;
  1881. default:
  1882. parser_warning("Unknown default button control-style 0x%08x\n", special_style);
  1883. case BS_GROUPBOX:
  1884. case BS_RADIOBUTTON:
  1885. break;
  1886. }
  1887. break;
  1888. case CT_STATIC:
  1889. switch(special_style)
  1890. {
  1891. case SS_LEFT:
  1892. case SS_RIGHT:
  1893. case SS_CENTER:
  1894. defaultstyle |= WS_GROUP;
  1895. break;
  1896. case SS_ICON: /* Special case */
  1897. break;
  1898. default:
  1899. parser_warning("Unknown default static control-style 0x%08x\n", special_style);
  1900. break;
  1901. }
  1902. break;
  1903. case -1: /* Generic control */
  1904. goto byebye;
  1905. default:
  1906. yyerror("Internal error (report this): Got weird control type 0x%08x", type);
  1907. }
  1908. }
  1909. /* The SS_ICON flag is always forced in for icon controls */
  1910. if(type == CT_STATIC && special_style == SS_ICON)
  1911. defaultstyle |= SS_ICON;
  1912. if (!ctrl->gotstyle)
  1913. ctrl->style = new_style(0,0);
  1914. /* combine all styles */
  1915. ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
  1916. ctrl->gotstyle = TRUE;
  1917. byebye:
  1918. /* combine with NOT mask */
  1919. if (ctrl->gotstyle)
  1920. {
  1921. ctrl->style->or_mask &= ~(ctrl->style->and_mask);
  1922. ctrl->style->and_mask = 0;
  1923. }
  1924. if (ctrl->gotexstyle)
  1925. {
  1926. ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
  1927. ctrl->exstyle->and_mask = 0;
  1928. }
  1929. return ctrl;
  1930. }
  1931. static int get_class_idW(const WCHAR *cc)
  1932. {
  1933. static const WCHAR szBUTTON[] = {'B','U','T','T','O','N',0};
  1934. static const WCHAR szCOMBOBOX[] = {'C','O','M','B','O','B','O','X',0};
  1935. static const WCHAR szLISTBOX[] = {'L','I','S','T','B','O','X',0};
  1936. static const WCHAR szEDIT[] = {'E','D','I','T',0};
  1937. static const WCHAR szSTATIC[] = {'S','T','A','T','I','C',0};
  1938. static const WCHAR szSCROLLBAR[] = {'S','C','R','O','L','L','B','A','R',0};
  1939. if(!compare_striW(szBUTTON, cc)) return CT_BUTTON;
  1940. if(!compare_striW(szCOMBOBOX, cc)) return CT_COMBOBOX;
  1941. if(!compare_striW(szLISTBOX, cc)) return CT_LISTBOX;
  1942. if(!compare_striW(szEDIT, cc)) return CT_EDIT;
  1943. if(!compare_striW(szSTATIC, cc)) return CT_STATIC;
  1944. if(!compare_striW(szSCROLLBAR, cc)) return CT_SCROLLBAR;
  1945. return -1;
  1946. }
  1947. static int get_class_idA(const char *cc)
  1948. {
  1949. if(!compare_striA("BUTTON", cc)) return CT_BUTTON;
  1950. if(!compare_striA("COMBOBOX", cc)) return CT_COMBOBOX;
  1951. if(!compare_striA("LISTBOX", cc)) return CT_LISTBOX;
  1952. if(!compare_striA("EDIT", cc)) return CT_EDIT;
  1953. if(!compare_striA("STATIC", cc)) return CT_STATIC;
  1954. if(!compare_striA("SCROLLBAR", cc)) return CT_SCROLLBAR;
  1955. return -1;
  1956. }
  1957. static name_id_t *convert_ctlclass(name_id_t *cls)
  1958. {
  1959. int iclass;
  1960. if(cls->type == name_ord)
  1961. return cls;
  1962. assert(cls->type == name_str);
  1963. if(cls->name.s_name->type == str_unicode)
  1964. iclass = get_class_idW(cls->name.s_name->str.wstr);
  1965. else
  1966. iclass = get_class_idA(cls->name.s_name->str.cstr);
  1967. if (iclass == -1)
  1968. return cls; /* No default, return user controlclass */
  1969. free(cls->name.s_name->str.cstr);
  1970. free(cls->name.s_name);
  1971. cls->type = name_ord;
  1972. cls->name.i_name = iclass;
  1973. return cls;
  1974. }
  1975. /* Accelerator specific functions */
  1976. static event_t *add_event(int key, int id, int flags, event_t *prev)
  1977. {
  1978. event_t *ev = new_event();
  1979. if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
  1980. yyerror("Cannot use both ASCII and VIRTKEY");
  1981. ev->key = key;
  1982. ev->id = id;
  1983. ev->flags = flags & ~WRC_AF_ASCII;
  1984. ev->prev = prev;
  1985. if(prev)
  1986. prev->next = ev;
  1987. return ev;
  1988. }
  1989. static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
  1990. {
  1991. event_t *ev = new_event();
  1992. ev->str = key;
  1993. ev->id = id;
  1994. ev->flags = flags & ~WRC_AF_ASCII;
  1995. ev->prev = prev;
  1996. if(prev)
  1997. prev->next = ev;
  1998. return ev;
  1999. }
  2000. /* MenuEx specific functions */
  2001. static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
  2002. {
  2003. itemex_opt_t *opt = xmalloc(sizeof(itemex_opt_t));
  2004. memset( opt, 0, sizeof(*opt) );
  2005. opt->id = id;
  2006. opt->type = type;
  2007. opt->state = state;
  2008. opt->helpid = helpid;
  2009. return opt;
  2010. }
  2011. /* Raw data functions */
  2012. static raw_data_t *load_file(string_t *filename, language_t *lang)
  2013. {
  2014. FILE *fp = NULL;
  2015. char *path, *name;
  2016. raw_data_t *rd;
  2017. if (filename->type == str_unicode)
  2018. name = convert_string_utf8( filename, 0 );
  2019. else
  2020. name = xstrdup( filename->str.cstr );
  2021. if (!(path = wpp_find_include(name, input_name)))
  2022. yyerror("Cannot open file %s", name);
  2023. if (!(fp = fopen( path, "rb" )))
  2024. yyerror("Cannot open file %s", name);
  2025. free( path );
  2026. rd = new_raw_data();
  2027. fseek(fp, 0, SEEK_END);
  2028. rd->size = ftell(fp);
  2029. fseek(fp, 0, SEEK_SET);
  2030. if (rd->size)
  2031. {
  2032. rd->data = xmalloc(rd->size);
  2033. fread(rd->data, rd->size, 1, fp);
  2034. }
  2035. else rd->data = NULL;
  2036. fclose(fp);
  2037. rd->lvc.language = lang;
  2038. free(name);
  2039. return rd;
  2040. }
  2041. static raw_data_t *int2raw_data(int i)
  2042. {
  2043. raw_data_t *rd;
  2044. if( ( i >= 0 && (int)((unsigned short)i) != i) ||
  2045. ( i < 0 && (int)((short)i) != i) )
  2046. parser_warning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
  2047. rd = new_raw_data();
  2048. rd->size = sizeof(short);
  2049. rd->data = xmalloc(rd->size);
  2050. switch(byteorder)
  2051. {
  2052. #ifdef WORDS_BIGENDIAN
  2053. default:
  2054. #endif
  2055. case WRC_BO_BIG:
  2056. rd->data[0] = HIBYTE(i);
  2057. rd->data[1] = LOBYTE(i);
  2058. break;
  2059. #ifndef WORDS_BIGENDIAN
  2060. default:
  2061. #endif
  2062. case WRC_BO_LITTLE:
  2063. rd->data[1] = HIBYTE(i);
  2064. rd->data[0] = LOBYTE(i);
  2065. break;
  2066. }
  2067. return rd;
  2068. }
  2069. static raw_data_t *long2raw_data(int i)
  2070. {
  2071. raw_data_t *rd;
  2072. rd = new_raw_data();
  2073. rd->size = sizeof(int);
  2074. rd->data = xmalloc(rd->size);
  2075. switch(byteorder)
  2076. {
  2077. #ifdef WORDS_BIGENDIAN
  2078. default:
  2079. #endif
  2080. case WRC_BO_BIG:
  2081. rd->data[0] = HIBYTE(HIWORD(i));
  2082. rd->data[1] = LOBYTE(HIWORD(i));
  2083. rd->data[2] = HIBYTE(LOWORD(i));
  2084. rd->data[3] = LOBYTE(LOWORD(i));
  2085. break;
  2086. #ifndef WORDS_BIGENDIAN
  2087. default:
  2088. #endif
  2089. case WRC_BO_LITTLE:
  2090. rd->data[3] = HIBYTE(HIWORD(i));
  2091. rd->data[2] = LOBYTE(HIWORD(i));
  2092. rd->data[1] = HIBYTE(LOWORD(i));
  2093. rd->data[0] = LOBYTE(LOWORD(i));
  2094. break;
  2095. }
  2096. return rd;
  2097. }
  2098. static raw_data_t *str2raw_data(string_t *str)
  2099. {
  2100. raw_data_t *rd;
  2101. rd = new_raw_data();
  2102. rd->size = str->size * (str->type == str_char ? 1 : 2);
  2103. rd->data = xmalloc(rd->size);
  2104. if(str->type == str_char)
  2105. memcpy(rd->data, str->str.cstr, rd->size);
  2106. else if(str->type == str_unicode)
  2107. {
  2108. int i;
  2109. switch(byteorder)
  2110. {
  2111. #ifdef WORDS_BIGENDIAN
  2112. default:
  2113. #endif
  2114. case WRC_BO_BIG:
  2115. for(i = 0; i < str->size; i++)
  2116. {
  2117. rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
  2118. rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
  2119. }
  2120. break;
  2121. #ifndef WORDS_BIGENDIAN
  2122. default:
  2123. #endif
  2124. case WRC_BO_LITTLE:
  2125. for(i = 0; i < str->size; i++)
  2126. {
  2127. rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
  2128. rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
  2129. }
  2130. break;
  2131. }
  2132. }
  2133. else
  2134. internal_error(__FILE__, __LINE__, "Invalid stringtype\n");
  2135. return rd;
  2136. }
  2137. static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
  2138. {
  2139. r1->data = xrealloc(r1->data, r1->size + r2->size);
  2140. memcpy(r1->data + r1->size, r2->data, r2->size);
  2141. r1->size += r2->size;
  2142. return r1;
  2143. }
  2144. static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
  2145. {
  2146. raw_data_t *t = int2raw_data(i);
  2147. merge_raw_data(r1, t);
  2148. free(t->data);
  2149. free(t);
  2150. return r1;
  2151. }
  2152. static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
  2153. {
  2154. raw_data_t *t = long2raw_data(i);
  2155. merge_raw_data(r1, t);
  2156. free(t->data);
  2157. free(t);
  2158. return r1;
  2159. }
  2160. static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
  2161. {
  2162. raw_data_t *t = str2raw_data(str);
  2163. merge_raw_data(r1, t);
  2164. free(t->data);
  2165. free(t);
  2166. return r1;
  2167. }
  2168. /* Function the go back in a list to get the head */
  2169. static menu_item_t *get_item_head(menu_item_t *p)
  2170. {
  2171. if(!p)
  2172. return NULL;
  2173. while(p->prev)
  2174. p = p->prev;
  2175. return p;
  2176. }
  2177. static resource_t *get_resource_head(resource_t *p)
  2178. {
  2179. if(!p)
  2180. return NULL;
  2181. while(p->prev)
  2182. p = p->prev;
  2183. return p;
  2184. }
  2185. static ver_block_t *get_ver_block_head(ver_block_t *p)
  2186. {
  2187. if(!p)
  2188. return NULL;
  2189. while(p->prev)
  2190. p = p->prev;
  2191. return p;
  2192. }
  2193. static ver_value_t *get_ver_value_head(ver_value_t *p)
  2194. {
  2195. if(!p)
  2196. return NULL;
  2197. while(p->prev)
  2198. p = p->prev;
  2199. return p;
  2200. }
  2201. static control_t *get_control_head(control_t *p)
  2202. {
  2203. if(!p)
  2204. return NULL;
  2205. while(p->prev)
  2206. p = p->prev;
  2207. return p;
  2208. }
  2209. static event_t *get_event_head(event_t *p)
  2210. {
  2211. if(!p)
  2212. return NULL;
  2213. while(p->prev)
  2214. p = p->prev;
  2215. return p;
  2216. }
  2217. /* Find a stringtable with given language */
  2218. static stringtable_t *find_stringtable(lvc_t *lvc)
  2219. {
  2220. stringtable_t *stt;
  2221. assert(lvc != NULL);
  2222. if(!lvc->language)
  2223. lvc->language = dup_language(currentlanguage);
  2224. for(stt = sttres; stt; stt = stt->next)
  2225. {
  2226. if(stt->lvc.language->id == lvc->language->id
  2227. && stt->lvc.language->sub == lvc->language->sub)
  2228. {
  2229. /* Found a table with the same language */
  2230. /* The version and characteristics are now handled
  2231. * in the generation of the individual stringtables.
  2232. * This enables localized analysis.
  2233. if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
  2234. || (!stt->lvc.version && lvc->version)
  2235. || (stt->lvc.version && !lvc->version))
  2236. parser_warning("Stringtable's versions are not the same, using first definition\n");
  2237. if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
  2238. || (!stt->lvc.characts && lvc->characts)
  2239. || (stt->lvc.characts && !lvc->characts))
  2240. parser_warning("Stringtable's characteristics are not the same, using first definition\n");
  2241. */
  2242. return stt;
  2243. }
  2244. }
  2245. return NULL;
  2246. }
  2247. /* qsort sorting function for string table entries */
  2248. #define STE(p) ((const stt_entry_t *)(p))
  2249. static int sort_stt_entry(const void *e1, const void *e2)
  2250. {
  2251. return STE(e1)->id - STE(e2)->id;
  2252. }
  2253. #undef STE
  2254. static resource_t *build_stt_resources(stringtable_t *stthead)
  2255. {
  2256. stringtable_t *stt;
  2257. stringtable_t *newstt;
  2258. resource_t *rsc;
  2259. resource_t *rsclist = NULL;
  2260. resource_t *rsctail = NULL;
  2261. int i;
  2262. int j;
  2263. DWORD andsum;
  2264. DWORD orsum;
  2265. characts_t *characts;
  2266. version_t *version;
  2267. if(!stthead)
  2268. return NULL;
  2269. /* For all languages defined */
  2270. for(stt = stthead; stt; stt = stt->next)
  2271. {
  2272. assert(stt->nentries > 0);
  2273. /* Sort the entries */
  2274. if(stt->nentries > 1)
  2275. qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
  2276. for(i = 0; i < stt->nentries; )
  2277. {
  2278. newstt = new_stringtable(&stt->lvc);
  2279. newstt->entries = xmalloc(16 * sizeof(stt_entry_t));
  2280. memset( newstt->entries, 0, 16 * sizeof(stt_entry_t) );
  2281. newstt->nentries = 16;
  2282. newstt->idbase = stt->entries[i].id & ~0xf;
  2283. for(j = 0; j < 16 && i < stt->nentries; j++)
  2284. {
  2285. if(stt->entries[i].id - newstt->idbase == j)
  2286. {
  2287. newstt->entries[j] = stt->entries[i];
  2288. i++;
  2289. }
  2290. }
  2291. andsum = ~0;
  2292. orsum = 0;
  2293. characts = NULL;
  2294. version = NULL;
  2295. /* Check individual memory options and get
  2296. * the first characteristics/version
  2297. */
  2298. for(j = 0; j < 16; j++)
  2299. {
  2300. if(!newstt->entries[j].str)
  2301. continue;
  2302. andsum &= newstt->entries[j].memopt;
  2303. orsum |= newstt->entries[j].memopt;
  2304. if(!characts)
  2305. characts = newstt->entries[j].characts;
  2306. if(!version)
  2307. version = newstt->entries[j].version;
  2308. }
  2309. if(andsum != orsum)
  2310. {
  2311. warning("Stringtable's memory options are not equal (idbase: %d)\n", newstt->idbase);
  2312. }
  2313. /* Check version and characteristics */
  2314. for(j = 0; j < 16; j++)
  2315. {
  2316. if(characts
  2317. && newstt->entries[j].characts
  2318. && *newstt->entries[j].characts != *characts)
  2319. warning("Stringtable's characteristics are not the same (idbase: %d)\n", newstt->idbase);
  2320. if(version
  2321. && newstt->entries[j].version
  2322. && *newstt->entries[j].version != *version)
  2323. warning("Stringtable's versions are not the same (idbase: %d)\n", newstt->idbase);
  2324. }
  2325. rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
  2326. rsc->name = new_name_id();
  2327. rsc->name->type = name_ord;
  2328. rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
  2329. rsc->memopt = andsum; /* Set to least common denominator */
  2330. newstt->memopt = andsum;
  2331. newstt->lvc.characts = characts;
  2332. newstt->lvc.version = version;
  2333. if(!rsclist)
  2334. {
  2335. rsclist = rsc;
  2336. rsctail = rsc;
  2337. }
  2338. else
  2339. {
  2340. rsctail->next = rsc;
  2341. rsc->prev = rsctail;
  2342. rsctail = rsc;
  2343. }
  2344. }
  2345. }
  2346. return rsclist;
  2347. }
  2348. static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
  2349. {
  2350. idrec->prev = prev;
  2351. if(prev)
  2352. prev->next = idrec;
  2353. return idrec;
  2354. }
  2355. static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
  2356. {
  2357. if(!p)
  2358. {
  2359. *nitems = 0;
  2360. return NULL;
  2361. }
  2362. *nitems = 1;
  2363. while(p->prev)
  2364. {
  2365. (*nitems)++;
  2366. p = p->prev;
  2367. }
  2368. return p;
  2369. }
  2370. static string_t *make_filename(string_t *str)
  2371. {
  2372. int i;
  2373. if(str->type == str_char)
  2374. {
  2375. char *dst = str->str.cstr;
  2376. /* Remove escaped backslash and convert to forward */
  2377. for (i = 0; i < str->size; i++)
  2378. {
  2379. if (str->str.cstr[i] == '\\')
  2380. {
  2381. if (i < str->size - 1 && str->str.cstr[i + 1] == '\\') i++;
  2382. *dst++ = '/';
  2383. }
  2384. else *dst++ = str->str.cstr[i];
  2385. }
  2386. *dst = 0;
  2387. str->size = dst - str->str.cstr;
  2388. }
  2389. else
  2390. {
  2391. WCHAR *dst = str->str.wstr;
  2392. /* Remove escaped backslash and convert to forward */
  2393. for (i = 0; i < str->size; i++)
  2394. {
  2395. if (str->str.wstr[i] == '\\')
  2396. {
  2397. if (i < str->size - 1 && str->str.wstr[i + 1] == '\\') i++;
  2398. *dst++ = '/';
  2399. }
  2400. else *dst++ = str->str.wstr[i];
  2401. }
  2402. *dst = 0;
  2403. str->size = dst - str->str.wstr;
  2404. }
  2405. return str;
  2406. }
  2407. /*
  2408. * Process all resources to extract fonts and build
  2409. * a fontdir resource.
  2410. *
  2411. * Note: MS' resource compiler (build 1472) does not
  2412. * handle font resources with different languages.
  2413. * The fontdir is generated in the last active language
  2414. * and font identifiers must be unique across the entire
  2415. * source.
  2416. * This is not logical considering the localization
  2417. * constraints of all other resource types. MS has,
  2418. * most probably, never testet localized fonts. However,
  2419. * using fontresources is rare, so it might not occur
  2420. * in normal applications.
  2421. * Wine does require better localization because a lot
  2422. * of languages are coded into the same executable.
  2423. * Therefore, I will generate fontdirs for *each*
  2424. * localized set of fonts.
  2425. */
  2426. static resource_t *build_fontdir(resource_t **fnt, int nfnt)
  2427. {
  2428. static int once = 0;
  2429. if(!once)
  2430. {
  2431. warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)\n", fnt, nfnt);
  2432. once++;
  2433. }
  2434. return NULL;
  2435. }
  2436. static resource_t *build_fontdirs(resource_t *tail)
  2437. {
  2438. resource_t *rsc;
  2439. resource_t *lst = NULL;
  2440. resource_t **fnt = NULL; /* List of all fonts */
  2441. int nfnt = 0;
  2442. resource_t **fnd = NULL; /* List of all fontdirs */
  2443. int nfnd = 0;
  2444. resource_t **lanfnt = NULL;
  2445. int nlanfnt = 0;
  2446. int i;
  2447. name_id_t nid;
  2448. string_t str;
  2449. int fntleft;
  2450. nid.type = name_str;
  2451. nid.name.s_name = &str;
  2452. str.type = str_char;
  2453. str.str.cstr = xstrdup("FONTDIR");
  2454. str.size = 7;
  2455. /* Extract all fonts and fontdirs */
  2456. for(rsc = tail; rsc; rsc = rsc->prev)
  2457. {
  2458. if(rsc->type == res_fnt)
  2459. {
  2460. nfnt++;
  2461. fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
  2462. fnt[nfnt-1] = rsc;
  2463. }
  2464. else if(rsc->type == res_fntdir)
  2465. {
  2466. nfnd++;
  2467. fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
  2468. fnd[nfnd-1] = rsc;
  2469. }
  2470. }
  2471. /* Verify the name of the present fontdirs */
  2472. for(i = 0; i < nfnd; i++)
  2473. {
  2474. if(compare_name_id(&nid, fnd[i]->name))
  2475. {
  2476. warning("User supplied FONTDIR entry has an invalid name '%s', ignored\n",
  2477. get_nameid_str(fnd[i]->name));
  2478. fnd[i] = NULL;
  2479. }
  2480. }
  2481. /* Sanity check */
  2482. if(nfnt == 0)
  2483. {
  2484. if(nfnd != 0)
  2485. warning("Found %d FONTDIR entries without any fonts present\n", nfnd);
  2486. goto clean;
  2487. }
  2488. /* Copy space */
  2489. lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
  2490. memset( lanfnt, 0, nfnt * sizeof(*lanfnt));
  2491. /* Get all fonts covered by fontdirs */
  2492. for(i = 0; i < nfnd; i++)
  2493. {
  2494. int j;
  2495. WORD cnt;
  2496. int isswapped = 0;
  2497. if(!fnd[i])
  2498. continue;
  2499. for(j = 0; j < nfnt; j++)
  2500. {
  2501. if(!fnt[j])
  2502. continue;
  2503. if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
  2504. {
  2505. lanfnt[nlanfnt] = fnt[j];
  2506. nlanfnt++;
  2507. fnt[j] = NULL;
  2508. }
  2509. }
  2510. cnt = *(WORD *)fnd[i]->res.fnd->data->data;
  2511. if(nlanfnt == cnt)
  2512. isswapped = 0;
  2513. else if(nlanfnt == BYTESWAP_WORD(cnt))
  2514. isswapped = 1;
  2515. else
  2516. error("FONTDIR for language %d,%d has wrong count (%d, expected %d)\n",
  2517. fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
  2518. #ifdef WORDS_BIGENDIAN
  2519. if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
  2520. #else
  2521. if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
  2522. #endif
  2523. {
  2524. internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping\n");
  2525. }
  2526. }
  2527. /* We now have fonts left where we need to make a fontdir resource */
  2528. for(i = fntleft = 0; i < nfnt; i++)
  2529. {
  2530. if(fnt[i])
  2531. fntleft++;
  2532. }
  2533. while(fntleft)
  2534. {
  2535. /* Get fonts of same language in lanfnt[] */
  2536. for(i = nlanfnt = 0; i < nfnt; i++)
  2537. {
  2538. if(fnt[i])
  2539. {
  2540. if(!nlanfnt)
  2541. {
  2542. addlanfnt:
  2543. lanfnt[nlanfnt] = fnt[i];
  2544. nlanfnt++;
  2545. fnt[i] = NULL;
  2546. fntleft--;
  2547. }
  2548. else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
  2549. goto addlanfnt;
  2550. }
  2551. }
  2552. /* and build a fontdir */
  2553. rsc = build_fontdir(lanfnt, nlanfnt);
  2554. if(rsc)
  2555. {
  2556. if(lst)
  2557. {
  2558. lst->next = rsc;
  2559. rsc->prev = lst;
  2560. }
  2561. lst = rsc;
  2562. }
  2563. }
  2564. free(lanfnt);
  2565. clean:
  2566. free(fnt);
  2567. free(fnd);
  2568. free(str.str.cstr);
  2569. return lst;
  2570. }
  2571. /*
  2572. * This gets invoked to determine whether the next resource
  2573. * is to be of a standard-type (e.g. bitmaps etc.), or should
  2574. * be a user-type resource. This function is required because
  2575. * there is the _possibility_ of a lookahead token in the
  2576. * parser, which is generated from the "expr" state in the
  2577. * "nameid" parsing.
  2578. *
  2579. * The general resource format is:
  2580. * <identifier> <type> <flags> <resourcebody>
  2581. *
  2582. * The <identifier> can either be tIDENT or "expr". The latter
  2583. * will always generate a lookahead, which is the <type> of the
  2584. * resource to parse. Otherwise, we need to get a new token from
  2585. * the scanner to determine the next step.
  2586. *
  2587. * The problem arrises when <type> is numerical. This case should
  2588. * map onto default resource-types and be parsed as such instead
  2589. * of being mapped onto user-type resources.
  2590. *
  2591. * The trick lies in the fact that yacc (bison) doesn't care about
  2592. * intermediate changes of the lookahead while reducing a rule. We
  2593. * simply replace the lookahead with a token that will result in
  2594. * a shift to the appropriate rule for the specific resource-type.
  2595. */
  2596. static int rsrcid_to_token(int lookahead)
  2597. {
  2598. int token;
  2599. /* Get a token if we don't have one yet */
  2600. if(lookahead == YYEMPTY)
  2601. lookahead = yylex();
  2602. /* Only numbers are possibly interesting */
  2603. switch(lookahead)
  2604. {
  2605. case tNUMBER:
  2606. case tLNUMBER:
  2607. break;
  2608. default:
  2609. return lookahead;
  2610. }
  2611. token = lookahead;
  2612. switch(yylval.num)
  2613. {
  2614. case WRC_RT_CURSOR:
  2615. token = tCURSOR;
  2616. break;
  2617. case WRC_RT_ICON:
  2618. token = tICON;
  2619. break;
  2620. case WRC_RT_BITMAP:
  2621. token = tBITMAP;
  2622. break;
  2623. case WRC_RT_FONT:
  2624. token = tFONT;
  2625. break;
  2626. case WRC_RT_FONTDIR:
  2627. token = tFONTDIR;
  2628. break;
  2629. case WRC_RT_RCDATA:
  2630. token = tRCDATA;
  2631. break;
  2632. case WRC_RT_MESSAGETABLE:
  2633. token = tMESSAGETABLE;
  2634. break;
  2635. case WRC_RT_DLGINIT:
  2636. token = tDLGINIT;
  2637. break;
  2638. case WRC_RT_ACCELERATOR:
  2639. token = tACCELERATORS;
  2640. break;
  2641. case WRC_RT_MENU:
  2642. token = tMENU;
  2643. break;
  2644. case WRC_RT_DIALOG:
  2645. token = tDIALOG;
  2646. break;
  2647. case WRC_RT_VERSION:
  2648. token = tVERSIONINFO;
  2649. break;
  2650. case WRC_RT_TOOLBAR:
  2651. token = tTOOLBAR;
  2652. break;
  2653. case WRC_RT_HTML:
  2654. token = tHTML;
  2655. break;
  2656. case WRC_RT_STRING:
  2657. break;
  2658. case WRC_RT_ANICURSOR:
  2659. case WRC_RT_ANIICON:
  2660. case WRC_RT_GROUP_CURSOR:
  2661. case WRC_RT_GROUP_ICON:
  2662. parser_warning("Usertype uses reserved type ID %d, which is auto-generated\n", yylval.num);
  2663. return lookahead;
  2664. case WRC_RT_DLGINCLUDE:
  2665. case WRC_RT_PLUGPLAY:
  2666. case WRC_RT_VXD:
  2667. parser_warning("Usertype uses reserved type ID %d, which is not supported by wrc yet\n", yylval.num);
  2668. default:
  2669. return lookahead;
  2670. }
  2671. return token;
  2672. }