parser.y 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804
  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 <stdio.h>
  125. #include <stdlib.h>
  126. #include <stdarg.h>
  127. #include <assert.h>
  128. #include <ctype.h>
  129. #include <string.h>
  130. #include "../tools.h"
  131. #include "wrc.h"
  132. #include "utils.h"
  133. #include "newstruc.h"
  134. #include "dumpres.h"
  135. #include "wpp_private.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 /* 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. free($1);
  548. }
  549. | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
  550. | dialogex {
  551. if(win32)
  552. $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language);
  553. else
  554. $$ = NULL;
  555. }
  556. | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
  557. | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
  558. | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
  559. | icon {
  560. resource_t *rsc;
  561. if($1->type == res_aniico)
  562. {
  563. $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
  564. }
  565. else /* res_icog */
  566. {
  567. icon_t *ico;
  568. $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
  569. for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
  570. {
  571. rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
  572. rsc->prev->next = rsc;
  573. rsc = rsc->prev;
  574. rsc->name = new_name_id();
  575. rsc->name->type = name_ord;
  576. rsc->name->name.i_name = ico->id;
  577. }
  578. }
  579. free($1);
  580. }
  581. | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
  582. | menuex {
  583. if(win32)
  584. $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language);
  585. else
  586. $$ = NULL;
  587. }
  588. | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
  589. | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
  590. | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
  591. | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
  592. | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
  593. | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
  594. ;
  595. filename: tIDENT { $$ = make_filename($1); }
  596. | tSTRING { $$ = make_filename($1); }
  597. ;
  598. /* ------------------------------ Bitmap ------------------------------ */
  599. bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
  600. ;
  601. /* ------------------------------ Cursor ------------------------------ */
  602. cursor : tCURSOR loadmemopts file_raw {
  603. $$ = new_ani_any();
  604. if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
  605. {
  606. $$->type = res_anicur;
  607. $$->u.ani = new_ani_curico(res_anicur, $3, $2);
  608. }
  609. else
  610. {
  611. $$->type = res_curg;
  612. $$->u.curg = new_cursor_group($3, $2);
  613. }
  614. }
  615. ;
  616. /* ------------------------------ Icon ------------------------------ */
  617. icon : tICON loadmemopts file_raw {
  618. $$ = new_ani_any();
  619. if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
  620. {
  621. $$->type = res_aniico;
  622. $$->u.ani = new_ani_curico(res_aniico, $3, $2);
  623. }
  624. else
  625. {
  626. $$->type = res_icog;
  627. $$->u.icog = new_icon_group($3, $2);
  628. }
  629. }
  630. ;
  631. /* ------------------------------ Font ------------------------------ */
  632. /*
  633. * The reading of raw_data for fonts is a Borland BRC
  634. * extension. MS generates an error. However, it is
  635. * most logical to support this, considering how wine
  636. * enters things in CVS (ascii).
  637. */
  638. font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
  639. ;
  640. /*
  641. * The fontdir is a Borland BRC extension which only
  642. * reads the data as 'raw_data' from the file.
  643. * I don't know whether it is interpreted.
  644. * The fontdir is generated if it was not present and
  645. * fonts are defined in the source.
  646. */
  647. fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
  648. ;
  649. /* ------------------------------ MessageTable ------------------------------ */
  650. /* It might be interesting to implement the MS Message compiler here as well
  651. * to get everything in one source. Might be a future project.
  652. */
  653. messagetable
  654. : tMESSAGETABLE loadmemopts file_raw {
  655. if(!win32)
  656. parser_warning("MESSAGETABLE not supported in 16-bit mode\n");
  657. $$ = new_messagetable($3, $2);
  658. }
  659. ;
  660. /* ------------------------------ HTML ------------------------------ */
  661. html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
  662. ;
  663. /* ------------------------------ RCData ------------------------------ */
  664. rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
  665. ;
  666. /* ------------------------------ DLGINIT ------------------------------ */
  667. dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
  668. ;
  669. /* ------------------------------ UserType ------------------------------ */
  670. userres : usertype loadmemopts file_raw {
  671. $$ = new_user($1, $3, $2);
  672. }
  673. ;
  674. usertype: tNUMBER {
  675. $$ = new_name_id();
  676. $$->type = name_ord;
  677. $$->name.i_name = $1;
  678. }
  679. | tIDENT {
  680. $$ = new_name_id();
  681. $$->type = name_str;
  682. $$->name.s_name = $1;
  683. }
  684. ;
  685. /* ------------------------------ Accelerator ------------------------------ */
  686. accelerators
  687. : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
  688. $$ = new_accelerator();
  689. if($2)
  690. {
  691. $$->memopt = *($2);
  692. free($2);
  693. }
  694. else
  695. {
  696. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
  697. }
  698. if(!$5)
  699. yyerror("Accelerator table must have at least one entry");
  700. $$->events = get_event_head($5);
  701. if($3)
  702. {
  703. $$->lvc = *($3);
  704. free($3);
  705. }
  706. if(!$$->lvc.language)
  707. $$->lvc.language = dup_language(currentlanguage);
  708. }
  709. ;
  710. events : /* Empty */ { $$=NULL; }
  711. | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
  712. | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
  713. ;
  714. /*
  715. * The empty rule generates a s/r conflict because of {bi,u}nary expr
  716. * on - and +. It cannot be solved in any way because it is the same as
  717. * the if/then/else problem (LALR(1) problem). The conflict is moved
  718. * away by forcing it to be in the expression handling below.
  719. */
  720. acc_opt : /* Empty */ { $$ = 0; }
  721. | ',' accs { $$ = $2; }
  722. ;
  723. accs : acc { $$ = $1; }
  724. | accs ',' acc { $$ = $1 | $3; }
  725. ;
  726. acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
  727. | tSHIFT { $$ = WRC_AF_SHIFT; }
  728. | tCONTROL { $$ = WRC_AF_CONTROL; }
  729. | tALT { $$ = WRC_AF_ALT; }
  730. | tASCII { $$ = WRC_AF_ASCII; }
  731. | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
  732. ;
  733. /* ------------------------------ Dialog ------------------------------ */
  734. /* FIXME: Support EXSTYLE in the dialog line itself */
  735. dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
  736. tBEGIN ctrls tEND {
  737. if($2)
  738. {
  739. $10->memopt = *($2);
  740. free($2);
  741. }
  742. else
  743. $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  744. $10->x = $3;
  745. $10->y = $5;
  746. $10->width = $7;
  747. $10->height = $9;
  748. $10->controls = get_control_head($12);
  749. $$ = $10;
  750. if(!$$->gotstyle)
  751. {
  752. $$->style = new_style(0,0);
  753. $$->style->or_mask = WS_POPUP;
  754. $$->gotstyle = TRUE;
  755. }
  756. if($$->title)
  757. $$->style->or_mask |= WS_CAPTION;
  758. if($$->font)
  759. $$->style->or_mask |= DS_SETFONT;
  760. $$->style->or_mask &= ~($$->style->and_mask);
  761. $$->style->and_mask = 0;
  762. if(!$$->lvc.language)
  763. $$->lvc.language = dup_language(currentlanguage);
  764. }
  765. ;
  766. dlg_attributes
  767. : /* Empty */ { $$=new_dialog(); }
  768. | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
  769. | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
  770. | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
  771. | dlg_attributes opt_font { $$=dialog_font($2,$1); }
  772. | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
  773. | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
  774. | dlg_attributes opt_language { $$=dialog_language($2,$1); }
  775. | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
  776. | dlg_attributes opt_version { $$=dialog_version($2,$1); }
  777. ;
  778. ctrls : /* Empty */ { $$ = NULL; }
  779. | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
  780. | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
  781. | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
  782. | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
  783. | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
  784. | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
  785. | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
  786. | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
  787. | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
  788. /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
  789. | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
  790. | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
  791. | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
  792. | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
  793. | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
  794. | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
  795. | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
  796. | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
  797. /* special treatment for icons, as the extent is optional */
  798. | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
  799. $10->title = $3;
  800. $10->id = $5;
  801. $10->x = $7;
  802. $10->y = $9;
  803. $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
  804. }
  805. ;
  806. lab_ctrl
  807. : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
  808. $$=new_control();
  809. $$->title = $1;
  810. $$->id = $3;
  811. $$->x = $5;
  812. $$->y = $7;
  813. $$->width = $9;
  814. $$->height = $11;
  815. if($12)
  816. {
  817. $$->style = $12->style;
  818. $$->gotstyle = TRUE;
  819. if ($12->exstyle)
  820. {
  821. $$->exstyle = $12->exstyle;
  822. $$->gotexstyle = TRUE;
  823. }
  824. free($12);
  825. }
  826. }
  827. ;
  828. ctrl_desc
  829. : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
  830. $$ = new_control();
  831. $$->id = $1;
  832. $$->x = $3;
  833. $$->y = $5;
  834. $$->width = $7;
  835. $$->height = $9;
  836. if($10)
  837. {
  838. $$->style = $10->style;
  839. $$->gotstyle = TRUE;
  840. if ($10->exstyle)
  841. {
  842. $$->exstyle = $10->exstyle;
  843. $$->gotexstyle = TRUE;
  844. }
  845. free($10);
  846. }
  847. }
  848. ;
  849. iconinfo: /* Empty */
  850. { $$ = new_control(); }
  851. | ',' expr ',' expr {
  852. $$ = new_control();
  853. $$->width = $2;
  854. $$->height = $4;
  855. }
  856. | ',' expr ',' expr ',' style {
  857. $$ = new_control();
  858. $$->width = $2;
  859. $$->height = $4;
  860. $$->style = $6;
  861. $$->gotstyle = TRUE;
  862. }
  863. | ',' expr ',' expr ',' style ',' style {
  864. $$ = new_control();
  865. $$->width = $2;
  866. $$->height = $4;
  867. $$->style = $6;
  868. $$->gotstyle = TRUE;
  869. $$->exstyle = $8;
  870. $$->gotexstyle = TRUE;
  871. }
  872. ;
  873. gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
  874. $$=new_control();
  875. $$->title = $1;
  876. $$->id = $3;
  877. $$->ctlclass = convert_ctlclass($5);
  878. $$->style = $7;
  879. $$->gotstyle = TRUE;
  880. $$->x = $9;
  881. $$->y = $11;
  882. $$->width = $13;
  883. $$->height = $15;
  884. $$->exstyle = $17;
  885. $$->gotexstyle = TRUE;
  886. }
  887. | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
  888. $$=new_control();
  889. $$->title = $1;
  890. $$->id = $3;
  891. $$->ctlclass = convert_ctlclass($5);
  892. $$->style = $7;
  893. $$->gotstyle = TRUE;
  894. $$->x = $9;
  895. $$->y = $11;
  896. $$->width = $13;
  897. $$->height = $15;
  898. }
  899. ;
  900. opt_font
  901. : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
  902. ;
  903. /* ------------------------------ style flags ------------------------------ */
  904. optional_style_pair
  905. : /* Empty */ { $$ = NULL; }
  906. | ',' style { $$ = new_style_pair($2, 0); }
  907. | ',' style ',' style { $$ = new_style_pair($2, $4); }
  908. ;
  909. style
  910. : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
  911. | '(' style ')' { $$ = $2; }
  912. | any_num { $$ = new_style($1, 0); }
  913. | tNOT any_num { $$ = new_style(0, $2); }
  914. ;
  915. ctlclass
  916. : expr {
  917. $$ = new_name_id();
  918. $$->type = name_ord;
  919. $$->name.i_name = $1;
  920. }
  921. | tSTRING {
  922. $$ = new_name_id();
  923. $$->type = name_str;
  924. $$->name.s_name = $1;
  925. }
  926. ;
  927. /* ------------------------------ DialogEx ------------------------------ */
  928. dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
  929. tBEGIN exctrls tEND {
  930. if(!win32)
  931. parser_warning("DIALOGEX not supported in 16-bit mode\n");
  932. if($2)
  933. {
  934. $11->memopt = *($2);
  935. free($2);
  936. }
  937. else
  938. $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  939. $11->x = $3;
  940. $11->y = $5;
  941. $11->width = $7;
  942. $11->height = $9;
  943. if($10)
  944. {
  945. $11->helpid = *($10);
  946. $11->gothelpid = TRUE;
  947. free($10);
  948. }
  949. $11->controls = get_control_head($13);
  950. $$ = $11;
  951. assert($$->style != NULL);
  952. if(!$$->gotstyle)
  953. {
  954. $$->style->or_mask = WS_POPUP;
  955. $$->gotstyle = TRUE;
  956. }
  957. if($$->title)
  958. $$->style->or_mask |= WS_CAPTION;
  959. if($$->font)
  960. $$->style->or_mask |= DS_SETFONT;
  961. $$->style->or_mask &= ~($$->style->and_mask);
  962. $$->style->and_mask = 0;
  963. if(!$$->lvc.language)
  964. $$->lvc.language = dup_language(currentlanguage);
  965. }
  966. ;
  967. dlgex_attribs
  968. : /* Empty */ { $$=new_dialog(); $$->is_ex = TRUE; }
  969. | dlgex_attribs tSTYLE style { $$=dialog_style($3,$1); }
  970. | dlgex_attribs tEXSTYLE style { $$=dialog_exstyle($3,$1); }
  971. | dlgex_attribs tCAPTION tSTRING { $$=dialog_caption($3,$1); }
  972. | dlgex_attribs opt_font { $$=dialog_font($2,$1); }
  973. | dlgex_attribs opt_exfont { $$=dialog_font($2,$1); }
  974. | dlgex_attribs tCLASS nameid_s { $$=dialog_class($3,$1); }
  975. | dlgex_attribs tMENU nameid { $$=dialog_menu($3,$1); }
  976. | dlgex_attribs opt_language { $$=dialog_language($2,$1); }
  977. | dlgex_attribs opt_characts { $$=dialog_characteristics($2,$1); }
  978. | dlgex_attribs opt_version { $$=dialog_version($2,$1); }
  979. ;
  980. exctrls : /* Empty */ { $$ = NULL; }
  981. | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
  982. | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
  983. | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
  984. | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
  985. | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
  986. | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
  987. | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
  988. | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
  989. | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
  990. /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
  991. | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
  992. | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
  993. | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
  994. | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
  995. | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
  996. | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
  997. | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
  998. | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
  999. /* special treatment for icons, as the extent is optional */
  1000. | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
  1001. $10->title = $3;
  1002. $10->id = $5;
  1003. $10->x = $7;
  1004. $10->y = $9;
  1005. $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
  1006. }
  1007. ;
  1008. gen_exctrl
  1009. : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
  1010. expr ',' style helpid opt_data {
  1011. $$=new_control();
  1012. $$->title = $1;
  1013. $$->id = $3;
  1014. $$->ctlclass = convert_ctlclass($5);
  1015. $$->style = $7;
  1016. $$->gotstyle = TRUE;
  1017. $$->x = $9;
  1018. $$->y = $11;
  1019. $$->width = $13;
  1020. $$->height = $15;
  1021. if($17)
  1022. {
  1023. $$->exstyle = $17;
  1024. $$->gotexstyle = TRUE;
  1025. }
  1026. if($18)
  1027. {
  1028. $$->helpid = *($18);
  1029. $$->gothelpid = TRUE;
  1030. free($18);
  1031. }
  1032. $$->extra = $19;
  1033. }
  1034. | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
  1035. $$=new_control();
  1036. $$->title = $1;
  1037. $$->id = $3;
  1038. $$->style = $7;
  1039. $$->gotstyle = TRUE;
  1040. $$->ctlclass = convert_ctlclass($5);
  1041. $$->x = $9;
  1042. $$->y = $11;
  1043. $$->width = $13;
  1044. $$->height = $15;
  1045. $$->extra = $16;
  1046. }
  1047. ;
  1048. lab_exctrl
  1049. : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
  1050. $$=new_control();
  1051. $$->title = $1;
  1052. $$->id = $3;
  1053. $$->x = $5;
  1054. $$->y = $7;
  1055. $$->width = $9;
  1056. $$->height = $11;
  1057. if($12)
  1058. {
  1059. $$->style = $12->style;
  1060. $$->gotstyle = TRUE;
  1061. if ($12->exstyle)
  1062. {
  1063. $$->exstyle = $12->exstyle;
  1064. $$->gotexstyle = TRUE;
  1065. }
  1066. free($12);
  1067. }
  1068. $$->extra = $14;
  1069. }
  1070. ;
  1071. exctrl_desc
  1072. : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
  1073. $$ = new_control();
  1074. $$->id = $1;
  1075. $$->x = $3;
  1076. $$->y = $5;
  1077. $$->width = $7;
  1078. $$->height = $9;
  1079. if($10)
  1080. {
  1081. $$->style = $10->style;
  1082. $$->gotstyle = TRUE;
  1083. if ($10->exstyle)
  1084. {
  1085. $$->exstyle = $10->exstyle;
  1086. $$->gotexstyle = TRUE;
  1087. }
  1088. free($10);
  1089. }
  1090. $$->extra = $12;
  1091. }
  1092. ;
  1093. opt_data: /* Empty */ { $$ = NULL; }
  1094. | raw_data { $$ = $1; }
  1095. ;
  1096. helpid : /* Empty */ { $$ = NULL; }
  1097. | ',' expr { $$ = new_int($2); }
  1098. ;
  1099. opt_exfont
  1100. : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
  1101. ;
  1102. /*
  1103. * FIXME: This odd expression is here to nullify an extra token found
  1104. * in some appstudio produced resources which appear to do nothing.
  1105. */
  1106. opt_expr: /* Empty */ { $$ = NULL; }
  1107. | ',' expr { $$ = NULL; }
  1108. ;
  1109. /* ------------------------------ Menu ------------------------------ */
  1110. menu : tMENU loadmemopts opt_lvc menu_body {
  1111. if(!$4)
  1112. yyerror("Menu must contain items");
  1113. $$ = new_menu();
  1114. if($2)
  1115. {
  1116. $$->memopt = *($2);
  1117. free($2);
  1118. }
  1119. else
  1120. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  1121. $$->items = get_item_head($4);
  1122. if($3)
  1123. {
  1124. $$->lvc = *($3);
  1125. free($3);
  1126. }
  1127. if(!$$->lvc.language)
  1128. $$->lvc.language = dup_language(currentlanguage);
  1129. }
  1130. ;
  1131. menu_body
  1132. : tBEGIN item_definitions tEND { $$ = $2; }
  1133. ;
  1134. item_definitions
  1135. : /* Empty */ {$$ = NULL;}
  1136. | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
  1137. $$=new_menu_item();
  1138. $$->prev = $1;
  1139. if($1)
  1140. $1->next = $$;
  1141. $$->id = $5;
  1142. $$->state = $6;
  1143. $$->name = $3;
  1144. }
  1145. | item_definitions tMENUITEM tSEPARATOR {
  1146. $$=new_menu_item();
  1147. $$->prev = $1;
  1148. if($1)
  1149. $1->next = $$;
  1150. }
  1151. | item_definitions tPOPUP tSTRING item_options menu_body {
  1152. $$ = new_menu_item();
  1153. $$->prev = $1;
  1154. if($1)
  1155. $1->next = $$;
  1156. $$->popup = get_item_head($5);
  1157. $$->name = $3;
  1158. }
  1159. ;
  1160. /* NOTE: item_options is right recursive because it would introduce
  1161. * a shift/reduce conflict on ',' in itemex_options due to the
  1162. * empty rule here. The parser is now forced to look beyond the ','
  1163. * before reducing (force shift).
  1164. * Right recursion here is not a problem because we cannot expect
  1165. * more than 7 parserstack places to be occupied while parsing this
  1166. * (who would want to specify a MF_x flag twice?).
  1167. */
  1168. item_options
  1169. : /* Empty */ { $$ = 0; }
  1170. | ',' item_options { $$ = $2; }
  1171. | tCHECKED item_options { $$ = $2 | MF_CHECKED; }
  1172. | tGRAYED item_options { $$ = $2 | MF_GRAYED; }
  1173. | tHELP item_options { $$ = $2 | MF_HELP; }
  1174. | tINACTIVE item_options { $$ = $2 | MF_DISABLED; }
  1175. | tMENUBARBREAK item_options { $$ = $2 | MF_MENUBARBREAK; }
  1176. | tMENUBREAK item_options { $$ = $2 | MF_MENUBREAK; }
  1177. ;
  1178. /* ------------------------------ MenuEx ------------------------------ */
  1179. menuex : tMENUEX loadmemopts opt_lvc menuex_body {
  1180. if(!win32)
  1181. parser_warning("MENUEX not supported in 16-bit mode\n");
  1182. if(!$4)
  1183. yyerror("MenuEx must contain items");
  1184. $$ = new_menu();
  1185. $$->is_ex = TRUE;
  1186. if($2)
  1187. {
  1188. $$->memopt = *($2);
  1189. free($2);
  1190. }
  1191. else
  1192. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  1193. $$->items = get_item_head($4);
  1194. if($3)
  1195. {
  1196. $$->lvc = *($3);
  1197. free($3);
  1198. }
  1199. if(!$$->lvc.language)
  1200. $$->lvc.language = dup_language(currentlanguage);
  1201. }
  1202. ;
  1203. menuex_body
  1204. : tBEGIN itemex_definitions tEND { $$ = $2; }
  1205. ;
  1206. itemex_definitions
  1207. : /* Empty */ {$$ = NULL; }
  1208. | itemex_definitions tMENUITEM tSTRING itemex_options {
  1209. $$ = new_menu_item();
  1210. $$->prev = $1;
  1211. if($1)
  1212. $1->next = $$;
  1213. $$->name = $3;
  1214. $$->id = $4->id;
  1215. $$->type = $4->type;
  1216. $$->state = $4->state;
  1217. $$->helpid = $4->helpid;
  1218. $$->gotid = $4->gotid;
  1219. $$->gottype = $4->gottype;
  1220. $$->gotstate = $4->gotstate;
  1221. $$->gothelpid = $4->gothelpid;
  1222. free($4);
  1223. }
  1224. | itemex_definitions tMENUITEM tSEPARATOR {
  1225. $$ = new_menu_item();
  1226. $$->prev = $1;
  1227. if($1)
  1228. $1->next = $$;
  1229. }
  1230. | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
  1231. $$ = new_menu_item();
  1232. $$->prev = $1;
  1233. if($1)
  1234. $1->next = $$;
  1235. $$->popup = get_item_head($5);
  1236. $$->name = $3;
  1237. $$->id = $4->id;
  1238. $$->type = $4->type;
  1239. $$->state = $4->state;
  1240. $$->helpid = $4->helpid;
  1241. $$->gotid = $4->gotid;
  1242. $$->gottype = $4->gottype;
  1243. $$->gotstate = $4->gotstate;
  1244. $$->gothelpid = $4->gothelpid;
  1245. free($4);
  1246. }
  1247. ;
  1248. itemex_options
  1249. : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
  1250. | ',' expr {
  1251. $$ = new_itemex_opt($2, 0, 0, 0);
  1252. $$->gotid = TRUE;
  1253. }
  1254. | ',' e_expr ',' e_expr item_options {
  1255. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
  1256. $$->gotid = TRUE;
  1257. $$->gottype = TRUE;
  1258. $$->gotstate = TRUE;
  1259. free($2);
  1260. free($4);
  1261. }
  1262. | ',' e_expr ',' e_expr ',' expr {
  1263. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
  1264. $$->gotid = TRUE;
  1265. $$->gottype = TRUE;
  1266. $$->gotstate = TRUE;
  1267. free($2);
  1268. free($4);
  1269. }
  1270. ;
  1271. itemex_p_options
  1272. : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
  1273. | ',' expr {
  1274. $$ = new_itemex_opt($2, 0, 0, 0);
  1275. $$->gotid = TRUE;
  1276. }
  1277. | ',' e_expr ',' expr {
  1278. $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
  1279. free($2);
  1280. $$->gotid = TRUE;
  1281. $$->gottype = TRUE;
  1282. }
  1283. | ',' e_expr ',' e_expr ',' expr {
  1284. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
  1285. free($2);
  1286. free($4);
  1287. $$->gotid = TRUE;
  1288. $$->gottype = TRUE;
  1289. $$->gotstate = TRUE;
  1290. }
  1291. | ',' e_expr ',' e_expr ',' e_expr ',' expr {
  1292. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
  1293. free($2);
  1294. free($4);
  1295. free($6);
  1296. $$->gotid = TRUE;
  1297. $$->gottype = TRUE;
  1298. $$->gotstate = TRUE;
  1299. $$->gothelpid = TRUE;
  1300. }
  1301. ;
  1302. /* ------------------------------ StringTable ------------------------------ */
  1303. /* Stringtables are parsed differently than other resources because their
  1304. * layout is substantially different from other resources.
  1305. * The table is parsed through a _global_ variable 'tagstt' which holds the
  1306. * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
  1307. * list of stringtables of different languages.
  1308. */
  1309. stringtable
  1310. : stt_head tBEGIN strings tEND {
  1311. if(!$3)
  1312. {
  1313. yyerror("Stringtable must have at least one entry");
  1314. }
  1315. else
  1316. {
  1317. stringtable_t *stt;
  1318. /* Check if we added to a language table or created
  1319. * a new one.
  1320. */
  1321. for(stt = sttres; stt; stt = stt->next)
  1322. {
  1323. if(stt == tagstt)
  1324. break;
  1325. }
  1326. if(!stt)
  1327. {
  1328. /* It is a new one */
  1329. if(sttres)
  1330. {
  1331. sttres->prev = tagstt;
  1332. tagstt->next = sttres;
  1333. sttres = tagstt;
  1334. }
  1335. else
  1336. sttres = tagstt;
  1337. }
  1338. /* Else, we're done */
  1339. }
  1340. free(tagstt_memopt);
  1341. tagstt_memopt = NULL;
  1342. $$ = tagstt;
  1343. }
  1344. ;
  1345. /* This is to get the language of the currently parsed stringtable */
  1346. stt_head: tSTRINGTABLE loadmemopts opt_lvc {
  1347. if((tagstt = find_stringtable($3)) == NULL)
  1348. tagstt = new_stringtable($3);
  1349. tagstt_memopt = $2;
  1350. tagstt_version = $3->version;
  1351. tagstt_characts = $3->characts;
  1352. free($3);
  1353. }
  1354. ;
  1355. strings : /* Empty */ { $$ = NULL; }
  1356. | strings expr opt_comma tSTRING {
  1357. int i;
  1358. assert(tagstt != NULL);
  1359. if($2 > 65535 || $2 < -32768)
  1360. yyerror("Stringtable entry's ID out of range (%d)", $2);
  1361. /* Search for the ID */
  1362. for(i = 0; i < tagstt->nentries; i++)
  1363. {
  1364. if(tagstt->entries[i].id == $2)
  1365. yyerror("Stringtable ID %d already in use", $2);
  1366. }
  1367. /* If we get here, then we have a new unique entry */
  1368. tagstt->nentries++;
  1369. tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
  1370. tagstt->entries[tagstt->nentries-1].id = $2;
  1371. tagstt->entries[tagstt->nentries-1].str = $4;
  1372. if(tagstt_memopt)
  1373. tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
  1374. else
  1375. tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
  1376. tagstt->entries[tagstt->nentries-1].version = tagstt_version;
  1377. tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
  1378. if(pedantic && !$4->size)
  1379. parser_warning("Zero length strings make no sense\n");
  1380. if(!win32 && $4->size > 254)
  1381. yyerror("Stringtable entry more than 254 characters");
  1382. if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
  1383. yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
  1384. $$ = tagstt;
  1385. }
  1386. ;
  1387. opt_comma /* There seem to be two ways to specify a stringtable... */
  1388. : /* Empty */
  1389. | ','
  1390. ;
  1391. /* ------------------------------ VersionInfo ------------------------------ */
  1392. versioninfo
  1393. : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
  1394. $$ = $3;
  1395. if($2)
  1396. {
  1397. $$->memopt = *($2);
  1398. free($2);
  1399. }
  1400. else
  1401. $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
  1402. $$->blocks = get_ver_block_head($5);
  1403. /* Set language; there is no version or characteristics */
  1404. $$->lvc.language = dup_language(currentlanguage);
  1405. }
  1406. ;
  1407. fix_version
  1408. : /* Empty */ { $$ = new_versioninfo(); }
  1409. | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
  1410. if($1->gotit.fv)
  1411. yyerror("FILEVERSION already defined");
  1412. $$ = $1;
  1413. $$->filever_maj1 = $3;
  1414. $$->filever_maj2 = $5;
  1415. $$->filever_min1 = $7;
  1416. $$->filever_min2 = $9;
  1417. $$->gotit.fv = 1;
  1418. }
  1419. | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
  1420. if($1->gotit.pv)
  1421. yyerror("PRODUCTVERSION already defined");
  1422. $$ = $1;
  1423. $$->prodver_maj1 = $3;
  1424. $$->prodver_maj2 = $5;
  1425. $$->prodver_min1 = $7;
  1426. $$->prodver_min2 = $9;
  1427. $$->gotit.pv = 1;
  1428. }
  1429. | fix_version tFILEFLAGS expr {
  1430. if($1->gotit.ff)
  1431. yyerror("FILEFLAGS already defined");
  1432. $$ = $1;
  1433. $$->fileflags = $3;
  1434. $$->gotit.ff = 1;
  1435. }
  1436. | fix_version tFILEFLAGSMASK expr {
  1437. if($1->gotit.ffm)
  1438. yyerror("FILEFLAGSMASK already defined");
  1439. $$ = $1;
  1440. $$->fileflagsmask = $3;
  1441. $$->gotit.ffm = 1;
  1442. }
  1443. | fix_version tFILEOS expr {
  1444. if($1->gotit.fo)
  1445. yyerror("FILEOS already defined");
  1446. $$ = $1;
  1447. $$->fileos = $3;
  1448. $$->gotit.fo = 1;
  1449. }
  1450. | fix_version tFILETYPE expr {
  1451. if($1->gotit.ft)
  1452. yyerror("FILETYPE already defined");
  1453. $$ = $1;
  1454. $$->filetype = $3;
  1455. $$->gotit.ft = 1;
  1456. }
  1457. | fix_version tFILESUBTYPE expr {
  1458. if($1->gotit.fst)
  1459. yyerror("FILESUBTYPE already defined");
  1460. $$ = $1;
  1461. $$->filesubtype = $3;
  1462. $$->gotit.fst = 1;
  1463. }
  1464. ;
  1465. ver_blocks
  1466. : /* Empty */ { $$ = NULL; }
  1467. | ver_blocks ver_block {
  1468. $$ = $2;
  1469. $$->prev = $1;
  1470. if($1)
  1471. $1->next = $$;
  1472. }
  1473. ;
  1474. ver_block
  1475. : tBLOCK tSTRING tBEGIN ver_values tEND {
  1476. $$ = new_ver_block();
  1477. $$->name = $2;
  1478. $$->values = get_ver_value_head($4);
  1479. }
  1480. ;
  1481. ver_values
  1482. : /* Empty */ { $$ = NULL; }
  1483. | ver_values ver_value {
  1484. $$ = $2;
  1485. $$->prev = $1;
  1486. if($1)
  1487. $1->next = $$;
  1488. }
  1489. ;
  1490. ver_value
  1491. : ver_block {
  1492. $$ = new_ver_value();
  1493. $$->type = val_block;
  1494. $$->value.block = $1;
  1495. }
  1496. | tVALUE tSTRING ',' tSTRING {
  1497. $$ = new_ver_value();
  1498. $$->type = val_str;
  1499. $$->key = $2;
  1500. $$->value.str = $4;
  1501. }
  1502. | tVALUE tSTRING ',' ver_words {
  1503. $$ = new_ver_value();
  1504. $$->type = val_words;
  1505. $$->key = $2;
  1506. $$->value.words = $4;
  1507. }
  1508. ;
  1509. ver_words
  1510. : expr { $$ = new_ver_words($1); }
  1511. | ver_words ',' expr { $$ = add_ver_words($1, $3); }
  1512. ;
  1513. /* ------------------------------ Toolbar ------------------------------ */
  1514. toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
  1515. int nitems;
  1516. toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
  1517. $$ = new_toolbar($3, $5, items, nitems);
  1518. if($2)
  1519. {
  1520. $$->memopt = *($2);
  1521. free($2);
  1522. }
  1523. else
  1524. {
  1525. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
  1526. }
  1527. if($6)
  1528. {
  1529. $$->lvc = *($6);
  1530. free($6);
  1531. }
  1532. if(!$$->lvc.language)
  1533. {
  1534. $$->lvc.language = dup_language(currentlanguage);
  1535. }
  1536. }
  1537. ;
  1538. toolbar_items
  1539. : /* Empty */ { $$ = NULL; }
  1540. | toolbar_items tBUTTON expr {
  1541. toolbar_item_t *idrec = new_toolbar_item();
  1542. idrec->id = $3;
  1543. $$ = ins_tlbr_button($1, idrec);
  1544. }
  1545. | toolbar_items tSEPARATOR {
  1546. toolbar_item_t *idrec = new_toolbar_item();
  1547. idrec->id = 0;
  1548. $$ = ins_tlbr_button($1, idrec);
  1549. }
  1550. ;
  1551. /* ------------------------------ Memory options ------------------------------ */
  1552. loadmemopts
  1553. : /* Empty */ { $$ = NULL; }
  1554. | loadmemopts lamo {
  1555. if($1)
  1556. {
  1557. *($1) |= *($2);
  1558. $$ = $1;
  1559. free($2);
  1560. }
  1561. else
  1562. $$ = $2;
  1563. }
  1564. | loadmemopts lama {
  1565. if($1)
  1566. {
  1567. *($1) &= *($2);
  1568. $$ = $1;
  1569. free($2);
  1570. }
  1571. else
  1572. {
  1573. *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
  1574. $$ = $2;
  1575. }
  1576. }
  1577. ;
  1578. lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD);
  1579. if (win32 && pedantic) parser_warning("PRELOAD is ignored in 32-bit mode\n"); }
  1580. | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE);
  1581. if (win32 && pedantic) parser_warning("MOVEABLE is ignored in 32-bit mode\n"); }
  1582. | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE);
  1583. if (win32 && pedantic) parser_warning("DISCARDABLE is ignored in 32-bit mode\n"); }
  1584. | tPURE { $$ = new_int(WRC_MO_PURE);
  1585. if (win32 && pedantic) parser_warning("PURE is ignored in 32-bit mode\n"); }
  1586. ;
  1587. lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD);
  1588. if (win32 && pedantic) parser_warning("LOADONCALL is ignored in 32-bit mode\n"); }
  1589. | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE);
  1590. if (win32 && pedantic) parser_warning("FIXED is ignored in 32-bit mode\n"); }
  1591. | tIMPURE { $$ = new_int(~WRC_MO_PURE);
  1592. if (win32 && pedantic) parser_warning("IMPURE is ignored in 32-bit mode\n"); }
  1593. ;
  1594. /* ------------------------------ Win32 options ------------------------------ */
  1595. opt_lvc : /* Empty */ { $$ = new_lvc(); }
  1596. | opt_lvc opt_language {
  1597. if(!win32)
  1598. parser_warning("LANGUAGE not supported in 16-bit mode\n");
  1599. if($1->language)
  1600. yyerror("Language already defined");
  1601. $$ = $1;
  1602. $1->language = $2;
  1603. }
  1604. | opt_lvc opt_characts {
  1605. if(!win32)
  1606. parser_warning("CHARACTERISTICS not supported in 16-bit mode\n");
  1607. if($1->characts)
  1608. yyerror("Characteristics already defined");
  1609. $$ = $1;
  1610. $1->characts = $2;
  1611. }
  1612. | opt_lvc opt_version {
  1613. if(!win32)
  1614. parser_warning("VERSION not supported in 16-bit mode\n");
  1615. if($1->version)
  1616. yyerror("Version already defined");
  1617. $$ = $1;
  1618. $1->version = $2;
  1619. }
  1620. ;
  1621. /*
  1622. * This here is another s/r conflict on {bi,u}nary + and -.
  1623. * It is due to the look-ahead which must determine when the
  1624. * rule opt_language ends. It could be solved with adding a
  1625. * tNL at the end, but that seems unreasonable to do.
  1626. * The conflict is now moved to the expression handling below.
  1627. */
  1628. opt_language
  1629. : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
  1630. if (get_language_codepage($2, $4) == -1)
  1631. yyerror( "Language %04x is not supported", ($4<<10) + $2);
  1632. }
  1633. ;
  1634. opt_characts
  1635. : tCHARACTERISTICS expr { $$ = new_characts($2); }
  1636. ;
  1637. opt_version
  1638. : tVERSION expr { $$ = new_version($2); }
  1639. ;
  1640. /* ------------------------------ Raw data handling ------------------------------ */
  1641. raw_data: opt_lvc tBEGIN raw_elements tEND {
  1642. if($1)
  1643. {
  1644. $3->lvc = *($1);
  1645. free($1);
  1646. }
  1647. if(!$3->lvc.language)
  1648. $3->lvc.language = dup_language(currentlanguage);
  1649. $$ = $3;
  1650. }
  1651. ;
  1652. raw_elements
  1653. : tRAWDATA { $$ = $1; }
  1654. | tNUMBER { $$ = int2raw_data($1); }
  1655. | '-' tNUMBER { $$ = int2raw_data(-($2)); }
  1656. | tLNUMBER { $$ = long2raw_data($1); }
  1657. | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
  1658. | tSTRING { $$ = str2raw_data($1); }
  1659. | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
  1660. | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
  1661. | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
  1662. | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
  1663. | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
  1664. | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
  1665. ;
  1666. /* File data or raw data */
  1667. file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
  1668. | raw_data { $$ = $1; }
  1669. ;
  1670. /* ------------------------------ Win32 expressions ------------------------------ */
  1671. /* All win16 numbers are also handled here. This is inconsistent with MS
  1672. * resource compiler, but what the heck, it's just handy to have.
  1673. */
  1674. e_expr : /* Empty */ { $$ = 0; }
  1675. | expr { $$ = new_int($1); }
  1676. ;
  1677. /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
  1678. expr : xpr { $$ = ($1); }
  1679. ;
  1680. xpr : xpr '+' xpr { $$ = ($1) + ($3); }
  1681. | xpr '-' xpr { $$ = ($1) - ($3); }
  1682. | xpr '|' xpr { $$ = ($1) | ($3); }
  1683. | xpr '&' xpr { $$ = ($1) & ($3); }
  1684. | xpr '*' xpr { $$ = ($1) * ($3); }
  1685. | xpr '/' xpr { $$ = ($1) / ($3); }
  1686. | xpr '^' xpr { $$ = ($1) ^ ($3); }
  1687. | '~' xpr { $$ = ~($2); }
  1688. | '-' xpr %prec pUPM { $$ = -($2); }
  1689. | '+' xpr %prec pUPM { $$ = $2; }
  1690. | '(' xpr ')' { $$ = $2; }
  1691. | any_num { $$ = $1; }
  1692. | tNOT any_num { $$ = ~($2); }
  1693. ;
  1694. any_num : tNUMBER { $$ = $1; }
  1695. | tLNUMBER { $$ = $1; }
  1696. ;
  1697. %%
  1698. /* Dialog specific functions */
  1699. static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
  1700. {
  1701. assert(dlg != NULL);
  1702. if(dlg->style == NULL)
  1703. {
  1704. dlg->style = new_style(0,0);
  1705. }
  1706. if(dlg->gotstyle)
  1707. {
  1708. parser_warning("Style already defined, or-ing together\n");
  1709. }
  1710. else
  1711. {
  1712. dlg->style->or_mask = 0;
  1713. dlg->style->and_mask = 0;
  1714. }
  1715. dlg->style->or_mask |= st->or_mask;
  1716. dlg->style->and_mask |= st->and_mask;
  1717. dlg->gotstyle = TRUE;
  1718. free(st);
  1719. return dlg;
  1720. }
  1721. static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
  1722. {
  1723. assert(dlg != NULL);
  1724. if(dlg->exstyle == NULL)
  1725. {
  1726. dlg->exstyle = new_style(0,0);
  1727. }
  1728. if(dlg->gotexstyle)
  1729. {
  1730. parser_warning("ExStyle already defined, or-ing together\n");
  1731. }
  1732. else
  1733. {
  1734. dlg->exstyle->or_mask = 0;
  1735. dlg->exstyle->and_mask = 0;
  1736. }
  1737. dlg->exstyle->or_mask |= st->or_mask;
  1738. dlg->exstyle->and_mask |= st->and_mask;
  1739. dlg->gotexstyle = TRUE;
  1740. free(st);
  1741. return dlg;
  1742. }
  1743. static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
  1744. {
  1745. assert(dlg != NULL);
  1746. if(dlg->title)
  1747. yyerror("Caption already defined");
  1748. dlg->title = s;
  1749. return dlg;
  1750. }
  1751. static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
  1752. {
  1753. assert(dlg != NULL);
  1754. if(dlg->font)
  1755. yyerror("Font already defined");
  1756. dlg->font = f;
  1757. return dlg;
  1758. }
  1759. static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
  1760. {
  1761. assert(dlg != NULL);
  1762. if(dlg->dlgclass)
  1763. yyerror("Class already defined");
  1764. dlg->dlgclass = n;
  1765. return dlg;
  1766. }
  1767. static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
  1768. {
  1769. assert(dlg != NULL);
  1770. if(dlg->menu)
  1771. yyerror("Menu already defined");
  1772. dlg->menu = m;
  1773. return dlg;
  1774. }
  1775. static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
  1776. {
  1777. assert(dlg != NULL);
  1778. if(dlg->lvc.language)
  1779. yyerror("Language already defined");
  1780. dlg->lvc.language = l;
  1781. return dlg;
  1782. }
  1783. static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
  1784. {
  1785. assert(dlg != NULL);
  1786. if(dlg->lvc.characts)
  1787. yyerror("Characteristics already defined");
  1788. dlg->lvc.characts = c;
  1789. return dlg;
  1790. }
  1791. static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
  1792. {
  1793. assert(dlg != NULL);
  1794. if(dlg->lvc.version)
  1795. yyerror("Version already defined");
  1796. dlg->lvc.version = v;
  1797. return dlg;
  1798. }
  1799. /* Controls specific functions */
  1800. static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
  1801. {
  1802. /* Hm... this seems to be jammed in at all time... */
  1803. int defaultstyle = WS_CHILD | WS_VISIBLE;
  1804. assert(ctrl != NULL);
  1805. ctrl->prev = prev;
  1806. if(prev)
  1807. prev->next = ctrl;
  1808. /* Check for duplicate identifiers */
  1809. while (prev)
  1810. {
  1811. if (ctrl->id != -1 && ctrl->id == prev->id)
  1812. parser_warning("Duplicate dialog control id %d\n", ctrl->id);
  1813. prev = prev->prev;
  1814. }
  1815. if(type != -1)
  1816. {
  1817. ctrl->ctlclass = new_name_id();
  1818. ctrl->ctlclass->type = name_ord;
  1819. ctrl->ctlclass->name.i_name = type;
  1820. }
  1821. switch(type)
  1822. {
  1823. case CT_BUTTON:
  1824. if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
  1825. defaultstyle |= WS_TABSTOP;
  1826. break;
  1827. case CT_EDIT:
  1828. defaultstyle |= WS_TABSTOP | WS_BORDER;
  1829. break;
  1830. case CT_LISTBOX:
  1831. defaultstyle |= LBS_NOTIFY | WS_BORDER;
  1832. break;
  1833. case CT_COMBOBOX:
  1834. if (!ctrl->gotstyle || !(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
  1835. defaultstyle |= CBS_SIMPLE;
  1836. break;
  1837. case CT_STATIC:
  1838. if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
  1839. defaultstyle |= WS_GROUP;
  1840. break;
  1841. }
  1842. if(!ctrl->gotstyle) /* Handle default style setting */
  1843. {
  1844. switch(type)
  1845. {
  1846. case CT_EDIT:
  1847. defaultstyle |= ES_LEFT;
  1848. break;
  1849. case CT_LISTBOX:
  1850. defaultstyle |= LBS_NOTIFY;
  1851. break;
  1852. case CT_COMBOBOX:
  1853. defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
  1854. break;
  1855. case CT_SCROLLBAR:
  1856. defaultstyle |= SBS_HORZ;
  1857. break;
  1858. case CT_BUTTON:
  1859. switch(special_style)
  1860. {
  1861. case BS_CHECKBOX:
  1862. case BS_DEFPUSHBUTTON:
  1863. case BS_PUSHBUTTON:
  1864. /* case BS_PUSHBOX: */
  1865. case BS_AUTORADIOBUTTON:
  1866. case BS_AUTO3STATE:
  1867. case BS_3STATE:
  1868. case BS_AUTOCHECKBOX:
  1869. defaultstyle |= WS_TABSTOP;
  1870. break;
  1871. default:
  1872. parser_warning("Unknown default button control-style 0x%08x\n", special_style);
  1873. case BS_GROUPBOX:
  1874. case BS_RADIOBUTTON:
  1875. break;
  1876. }
  1877. break;
  1878. case CT_STATIC:
  1879. switch(special_style)
  1880. {
  1881. case SS_LEFT:
  1882. case SS_RIGHT:
  1883. case SS_CENTER:
  1884. defaultstyle |= WS_GROUP;
  1885. break;
  1886. case SS_ICON: /* Special case */
  1887. break;
  1888. default:
  1889. parser_warning("Unknown default static control-style 0x%08x\n", special_style);
  1890. break;
  1891. }
  1892. break;
  1893. case -1: /* Generic control */
  1894. goto byebye;
  1895. default:
  1896. yyerror("Internal error (report this): Got weird control type 0x%08x", type);
  1897. }
  1898. }
  1899. /* The SS_ICON flag is always forced in for icon controls */
  1900. if(type == CT_STATIC && special_style == SS_ICON)
  1901. defaultstyle |= SS_ICON;
  1902. if (!ctrl->gotstyle)
  1903. ctrl->style = new_style(0,0);
  1904. /* combine all styles */
  1905. ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
  1906. ctrl->gotstyle = TRUE;
  1907. byebye:
  1908. /* combine with NOT mask */
  1909. if (ctrl->gotstyle)
  1910. {
  1911. ctrl->style->or_mask &= ~(ctrl->style->and_mask);
  1912. ctrl->style->and_mask = 0;
  1913. }
  1914. if (ctrl->gotexstyle)
  1915. {
  1916. ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
  1917. ctrl->exstyle->and_mask = 0;
  1918. }
  1919. return ctrl;
  1920. }
  1921. static int get_class_idW(const WCHAR *cc)
  1922. {
  1923. static const WCHAR szBUTTON[] = {'B','U','T','T','O','N',0};
  1924. static const WCHAR szCOMBOBOX[] = {'C','O','M','B','O','B','O','X',0};
  1925. static const WCHAR szLISTBOX[] = {'L','I','S','T','B','O','X',0};
  1926. static const WCHAR szEDIT[] = {'E','D','I','T',0};
  1927. static const WCHAR szSTATIC[] = {'S','T','A','T','I','C',0};
  1928. static const WCHAR szSCROLLBAR[] = {'S','C','R','O','L','L','B','A','R',0};
  1929. if(!compare_striW(szBUTTON, cc)) return CT_BUTTON;
  1930. if(!compare_striW(szCOMBOBOX, cc)) return CT_COMBOBOX;
  1931. if(!compare_striW(szLISTBOX, cc)) return CT_LISTBOX;
  1932. if(!compare_striW(szEDIT, cc)) return CT_EDIT;
  1933. if(!compare_striW(szSTATIC, cc)) return CT_STATIC;
  1934. if(!compare_striW(szSCROLLBAR, cc)) return CT_SCROLLBAR;
  1935. return -1;
  1936. }
  1937. static int get_class_idA(const char *cc)
  1938. {
  1939. if(!compare_striA("BUTTON", cc)) return CT_BUTTON;
  1940. if(!compare_striA("COMBOBOX", cc)) return CT_COMBOBOX;
  1941. if(!compare_striA("LISTBOX", cc)) return CT_LISTBOX;
  1942. if(!compare_striA("EDIT", cc)) return CT_EDIT;
  1943. if(!compare_striA("STATIC", cc)) return CT_STATIC;
  1944. if(!compare_striA("SCROLLBAR", cc)) return CT_SCROLLBAR;
  1945. return -1;
  1946. }
  1947. static name_id_t *convert_ctlclass(name_id_t *cls)
  1948. {
  1949. int iclass;
  1950. if(cls->type == name_ord)
  1951. return cls;
  1952. assert(cls->type == name_str);
  1953. if(cls->name.s_name->type == str_unicode)
  1954. iclass = get_class_idW(cls->name.s_name->str.wstr);
  1955. else
  1956. iclass = get_class_idA(cls->name.s_name->str.cstr);
  1957. if (iclass == -1)
  1958. return cls; /* No default, return user controlclass */
  1959. free(cls->name.s_name->str.cstr);
  1960. free(cls->name.s_name);
  1961. cls->type = name_ord;
  1962. cls->name.i_name = iclass;
  1963. return cls;
  1964. }
  1965. /* Accelerator specific functions */
  1966. static event_t *add_event(int key, int id, int flags, event_t *prev)
  1967. {
  1968. event_t *ev = new_event();
  1969. if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
  1970. yyerror("Cannot use both ASCII and VIRTKEY");
  1971. ev->key = key;
  1972. ev->id = id;
  1973. ev->flags = flags & ~WRC_AF_ASCII;
  1974. ev->prev = prev;
  1975. if(prev)
  1976. prev->next = ev;
  1977. return ev;
  1978. }
  1979. static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
  1980. {
  1981. event_t *ev = new_event();
  1982. ev->str = key;
  1983. ev->id = id;
  1984. ev->flags = flags & ~WRC_AF_ASCII;
  1985. ev->prev = prev;
  1986. if(prev)
  1987. prev->next = ev;
  1988. return ev;
  1989. }
  1990. /* MenuEx specific functions */
  1991. static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
  1992. {
  1993. itemex_opt_t *opt = xmalloc(sizeof(itemex_opt_t));
  1994. memset( opt, 0, sizeof(*opt) );
  1995. opt->id = id;
  1996. opt->type = type;
  1997. opt->state = state;
  1998. opt->helpid = helpid;
  1999. return opt;
  2000. }
  2001. /* Raw data functions */
  2002. static raw_data_t *load_file(string_t *filename, language_t *lang)
  2003. {
  2004. FILE *fp = NULL;
  2005. char *path, *name;
  2006. raw_data_t *rd;
  2007. if (filename->type == str_unicode)
  2008. name = convert_string_utf8( filename, 0 );
  2009. else
  2010. name = xstrdup( filename->str.cstr );
  2011. if (!(path = wpp_find_include(name, input_name)))
  2012. yyerror("Cannot open file %s", name);
  2013. if (!(fp = fopen( path, "rb" )))
  2014. yyerror("Cannot open file %s", name);
  2015. free( path );
  2016. rd = new_raw_data();
  2017. fseek(fp, 0, SEEK_END);
  2018. rd->size = ftell(fp);
  2019. fseek(fp, 0, SEEK_SET);
  2020. if (rd->size)
  2021. {
  2022. rd->data = xmalloc(rd->size);
  2023. fread(rd->data, rd->size, 1, fp);
  2024. }
  2025. else rd->data = NULL;
  2026. fclose(fp);
  2027. rd->lvc.language = lang;
  2028. free(name);
  2029. return rd;
  2030. }
  2031. static raw_data_t *int2raw_data(int i)
  2032. {
  2033. raw_data_t *rd;
  2034. if( ( i >= 0 && (int)((unsigned short)i) != i) ||
  2035. ( i < 0 && (int)((short)i) != i) )
  2036. parser_warning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
  2037. rd = new_raw_data();
  2038. rd->size = sizeof(short);
  2039. rd->data = xmalloc(rd->size);
  2040. rd->data[0] = i;
  2041. rd->data[1] = i >> 8;
  2042. return rd;
  2043. }
  2044. static raw_data_t *long2raw_data(int i)
  2045. {
  2046. raw_data_t *rd;
  2047. rd = new_raw_data();
  2048. rd->size = sizeof(int);
  2049. rd->data = xmalloc(rd->size);
  2050. rd->data[0] = i;
  2051. rd->data[1] = i >> 8;
  2052. rd->data[2] = i >> 16;
  2053. rd->data[3] = i >> 24;
  2054. return rd;
  2055. }
  2056. static raw_data_t *str2raw_data(string_t *str)
  2057. {
  2058. raw_data_t *rd;
  2059. rd = new_raw_data();
  2060. rd->size = str->size * (str->type == str_char ? 1 : 2);
  2061. rd->data = xmalloc(rd->size);
  2062. switch (str->type)
  2063. {
  2064. case str_char:
  2065. memcpy(rd->data, str->str.cstr, rd->size);
  2066. break;
  2067. case str_unicode:
  2068. {
  2069. int i;
  2070. for(i = 0; i < str->size; i++)
  2071. {
  2072. rd->data[2*i + 0] = str->str.wstr[i];
  2073. rd->data[2*i + 1] = str->str.wstr[i] >> 8;
  2074. }
  2075. }
  2076. }
  2077. return rd;
  2078. }
  2079. static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
  2080. {
  2081. r1->data = xrealloc(r1->data, r1->size + r2->size);
  2082. memcpy(r1->data + r1->size, r2->data, r2->size);
  2083. r1->size += r2->size;
  2084. return r1;
  2085. }
  2086. static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
  2087. {
  2088. raw_data_t *t = int2raw_data(i);
  2089. merge_raw_data(r1, t);
  2090. free(t->data);
  2091. free(t);
  2092. return r1;
  2093. }
  2094. static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
  2095. {
  2096. raw_data_t *t = long2raw_data(i);
  2097. merge_raw_data(r1, t);
  2098. free(t->data);
  2099. free(t);
  2100. return r1;
  2101. }
  2102. static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
  2103. {
  2104. raw_data_t *t = str2raw_data(str);
  2105. merge_raw_data(r1, t);
  2106. free(t->data);
  2107. free(t);
  2108. return r1;
  2109. }
  2110. /* Function the go back in a list to get the head */
  2111. static menu_item_t *get_item_head(menu_item_t *p)
  2112. {
  2113. if(!p)
  2114. return NULL;
  2115. while(p->prev)
  2116. p = p->prev;
  2117. return p;
  2118. }
  2119. static resource_t *get_resource_head(resource_t *p)
  2120. {
  2121. if(!p)
  2122. return NULL;
  2123. while(p->prev)
  2124. p = p->prev;
  2125. return p;
  2126. }
  2127. static ver_block_t *get_ver_block_head(ver_block_t *p)
  2128. {
  2129. if(!p)
  2130. return NULL;
  2131. while(p->prev)
  2132. p = p->prev;
  2133. return p;
  2134. }
  2135. static ver_value_t *get_ver_value_head(ver_value_t *p)
  2136. {
  2137. if(!p)
  2138. return NULL;
  2139. while(p->prev)
  2140. p = p->prev;
  2141. return p;
  2142. }
  2143. static control_t *get_control_head(control_t *p)
  2144. {
  2145. if(!p)
  2146. return NULL;
  2147. while(p->prev)
  2148. p = p->prev;
  2149. return p;
  2150. }
  2151. static event_t *get_event_head(event_t *p)
  2152. {
  2153. if(!p)
  2154. return NULL;
  2155. while(p->prev)
  2156. p = p->prev;
  2157. return p;
  2158. }
  2159. /* Find a stringtable with given language */
  2160. static stringtable_t *find_stringtable(lvc_t *lvc)
  2161. {
  2162. stringtable_t *stt;
  2163. assert(lvc != NULL);
  2164. if(!lvc->language)
  2165. lvc->language = dup_language(currentlanguage);
  2166. for(stt = sttres; stt; stt = stt->next)
  2167. {
  2168. if(stt->lvc.language->id == lvc->language->id
  2169. && stt->lvc.language->sub == lvc->language->sub)
  2170. {
  2171. /* Found a table with the same language */
  2172. /* The version and characteristics are now handled
  2173. * in the generation of the individual stringtables.
  2174. * This enables localized analysis.
  2175. if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
  2176. || (!stt->lvc.version && lvc->version)
  2177. || (stt->lvc.version && !lvc->version))
  2178. parser_warning("Stringtable's versions are not the same, using first definition\n");
  2179. if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
  2180. || (!stt->lvc.characts && lvc->characts)
  2181. || (stt->lvc.characts && !lvc->characts))
  2182. parser_warning("Stringtable's characteristics are not the same, using first definition\n");
  2183. */
  2184. return stt;
  2185. }
  2186. }
  2187. return NULL;
  2188. }
  2189. /* qsort sorting function for string table entries */
  2190. #define STE(p) ((const stt_entry_t *)(p))
  2191. static int sort_stt_entry(const void *e1, const void *e2)
  2192. {
  2193. return STE(e1)->id - STE(e2)->id;
  2194. }
  2195. #undef STE
  2196. static resource_t *build_stt_resources(stringtable_t *stthead)
  2197. {
  2198. stringtable_t *stt;
  2199. stringtable_t *newstt;
  2200. resource_t *rsc;
  2201. resource_t *rsclist = NULL;
  2202. resource_t *rsctail = NULL;
  2203. int i;
  2204. int j;
  2205. DWORD andsum;
  2206. DWORD orsum;
  2207. characts_t *characts;
  2208. version_t *version;
  2209. if(!stthead)
  2210. return NULL;
  2211. /* For all languages defined */
  2212. for(stt = stthead; stt; stt = stt->next)
  2213. {
  2214. assert(stt->nentries > 0);
  2215. /* Sort the entries */
  2216. if(stt->nentries > 1)
  2217. qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
  2218. for(i = 0; i < stt->nentries; )
  2219. {
  2220. newstt = new_stringtable(&stt->lvc);
  2221. newstt->entries = xmalloc(16 * sizeof(stt_entry_t));
  2222. memset( newstt->entries, 0, 16 * sizeof(stt_entry_t) );
  2223. newstt->nentries = 16;
  2224. newstt->idbase = stt->entries[i].id & ~0xf;
  2225. for(j = 0; j < 16 && i < stt->nentries; j++)
  2226. {
  2227. if(stt->entries[i].id - newstt->idbase == j)
  2228. {
  2229. newstt->entries[j] = stt->entries[i];
  2230. i++;
  2231. }
  2232. }
  2233. andsum = ~0;
  2234. orsum = 0;
  2235. characts = NULL;
  2236. version = NULL;
  2237. /* Check individual memory options and get
  2238. * the first characteristics/version
  2239. */
  2240. for(j = 0; j < 16; j++)
  2241. {
  2242. if(!newstt->entries[j].str)
  2243. continue;
  2244. andsum &= newstt->entries[j].memopt;
  2245. orsum |= newstt->entries[j].memopt;
  2246. if(!characts)
  2247. characts = newstt->entries[j].characts;
  2248. if(!version)
  2249. version = newstt->entries[j].version;
  2250. }
  2251. if(andsum != orsum)
  2252. {
  2253. warning("Stringtable's memory options are not equal (idbase: %d)\n", newstt->idbase);
  2254. }
  2255. /* Check version and characteristics */
  2256. for(j = 0; j < 16; j++)
  2257. {
  2258. if(characts
  2259. && newstt->entries[j].characts
  2260. && *newstt->entries[j].characts != *characts)
  2261. warning("Stringtable's characteristics are not the same (idbase: %d)\n", newstt->idbase);
  2262. if(version
  2263. && newstt->entries[j].version
  2264. && *newstt->entries[j].version != *version)
  2265. warning("Stringtable's versions are not the same (idbase: %d)\n", newstt->idbase);
  2266. }
  2267. rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
  2268. rsc->name = new_name_id();
  2269. rsc->name->type = name_ord;
  2270. rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
  2271. rsc->memopt = andsum; /* Set to least common denominator */
  2272. newstt->memopt = andsum;
  2273. newstt->lvc.characts = characts;
  2274. newstt->lvc.version = version;
  2275. if(!rsclist)
  2276. {
  2277. rsclist = rsc;
  2278. rsctail = rsc;
  2279. }
  2280. else
  2281. {
  2282. rsctail->next = rsc;
  2283. rsc->prev = rsctail;
  2284. rsctail = rsc;
  2285. }
  2286. }
  2287. }
  2288. return rsclist;
  2289. }
  2290. static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
  2291. {
  2292. idrec->prev = prev;
  2293. if(prev)
  2294. prev->next = idrec;
  2295. return idrec;
  2296. }
  2297. static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
  2298. {
  2299. if(!p)
  2300. {
  2301. *nitems = 0;
  2302. return NULL;
  2303. }
  2304. *nitems = 1;
  2305. while(p->prev)
  2306. {
  2307. (*nitems)++;
  2308. p = p->prev;
  2309. }
  2310. return p;
  2311. }
  2312. static string_t *make_filename(string_t *str)
  2313. {
  2314. int i;
  2315. if(str->type == str_char)
  2316. {
  2317. char *dst = str->str.cstr;
  2318. /* Remove escaped backslash and convert to forward */
  2319. for (i = 0; i < str->size; i++)
  2320. {
  2321. if (str->str.cstr[i] == '\\')
  2322. {
  2323. if (i < str->size - 1 && str->str.cstr[i + 1] == '\\') i++;
  2324. *dst++ = '/';
  2325. }
  2326. else *dst++ = str->str.cstr[i];
  2327. }
  2328. *dst = 0;
  2329. str->size = dst - str->str.cstr;
  2330. }
  2331. else
  2332. {
  2333. WCHAR *dst = str->str.wstr;
  2334. /* Remove escaped backslash and convert to forward */
  2335. for (i = 0; i < str->size; i++)
  2336. {
  2337. if (str->str.wstr[i] == '\\')
  2338. {
  2339. if (i < str->size - 1 && str->str.wstr[i + 1] == '\\') i++;
  2340. *dst++ = '/';
  2341. }
  2342. else *dst++ = str->str.wstr[i];
  2343. }
  2344. *dst = 0;
  2345. str->size = dst - str->str.wstr;
  2346. }
  2347. return str;
  2348. }
  2349. /*
  2350. * Process all resources to extract fonts and build
  2351. * a fontdir resource.
  2352. *
  2353. * Note: MS' resource compiler (build 1472) does not
  2354. * handle font resources with different languages.
  2355. * The fontdir is generated in the last active language
  2356. * and font identifiers must be unique across the entire
  2357. * source.
  2358. * This is not logical considering the localization
  2359. * constraints of all other resource types. MS has,
  2360. * most probably, never testet localized fonts. However,
  2361. * using fontresources is rare, so it might not occur
  2362. * in normal applications.
  2363. * Wine does require better localization because a lot
  2364. * of languages are coded into the same executable.
  2365. * Therefore, I will generate fontdirs for *each*
  2366. * localized set of fonts.
  2367. */
  2368. static resource_t *build_fontdir(resource_t **fnt, int nfnt)
  2369. {
  2370. static int once = 0;
  2371. if(!once)
  2372. {
  2373. warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)\n", fnt, nfnt);
  2374. once++;
  2375. }
  2376. return NULL;
  2377. }
  2378. static resource_t *build_fontdirs(resource_t *tail)
  2379. {
  2380. resource_t *rsc;
  2381. resource_t *lst = NULL;
  2382. resource_t **fnt = NULL; /* List of all fonts */
  2383. int nfnt = 0;
  2384. resource_t **fnd = NULL; /* List of all fontdirs */
  2385. int nfnd = 0;
  2386. resource_t **lanfnt = NULL;
  2387. int nlanfnt = 0;
  2388. int i;
  2389. name_id_t nid;
  2390. string_t str;
  2391. int fntleft;
  2392. nid.type = name_str;
  2393. nid.name.s_name = &str;
  2394. str.type = str_char;
  2395. str.str.cstr = xstrdup("FONTDIR");
  2396. str.size = 7;
  2397. /* Extract all fonts and fontdirs */
  2398. for(rsc = tail; rsc; rsc = rsc->prev)
  2399. {
  2400. if(rsc->type == res_fnt)
  2401. {
  2402. nfnt++;
  2403. fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
  2404. fnt[nfnt-1] = rsc;
  2405. }
  2406. else if(rsc->type == res_fntdir)
  2407. {
  2408. nfnd++;
  2409. fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
  2410. fnd[nfnd-1] = rsc;
  2411. }
  2412. }
  2413. /* Verify the name of the present fontdirs */
  2414. for(i = 0; i < nfnd; i++)
  2415. {
  2416. if(compare_name_id(&nid, fnd[i]->name))
  2417. {
  2418. warning("User supplied FONTDIR entry has an invalid name '%s', ignored\n",
  2419. get_nameid_str(fnd[i]->name));
  2420. fnd[i] = NULL;
  2421. }
  2422. }
  2423. /* Sanity check */
  2424. if(nfnt == 0)
  2425. {
  2426. if(nfnd != 0)
  2427. warning("Found %d FONTDIR entries without any fonts present\n", nfnd);
  2428. goto clean;
  2429. }
  2430. /* Copy space */
  2431. lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
  2432. memset( lanfnt, 0, nfnt * sizeof(*lanfnt));
  2433. /* Get all fonts covered by fontdirs */
  2434. for(i = 0; i < nfnd; i++)
  2435. {
  2436. int j;
  2437. if(!fnd[i])
  2438. continue;
  2439. for(j = 0; j < nfnt; j++)
  2440. {
  2441. if(!fnt[j])
  2442. continue;
  2443. if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
  2444. {
  2445. lanfnt[nlanfnt] = fnt[j];
  2446. nlanfnt++;
  2447. fnt[j] = NULL;
  2448. }
  2449. }
  2450. }
  2451. /* We now have fonts left where we need to make a fontdir resource */
  2452. for(i = fntleft = 0; i < nfnt; i++)
  2453. {
  2454. if(fnt[i])
  2455. fntleft++;
  2456. }
  2457. while(fntleft)
  2458. {
  2459. /* Get fonts of same language in lanfnt[] */
  2460. for(i = nlanfnt = 0; i < nfnt; i++)
  2461. {
  2462. if(fnt[i])
  2463. {
  2464. if(!nlanfnt)
  2465. {
  2466. addlanfnt:
  2467. lanfnt[nlanfnt] = fnt[i];
  2468. nlanfnt++;
  2469. fnt[i] = NULL;
  2470. fntleft--;
  2471. }
  2472. else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
  2473. goto addlanfnt;
  2474. }
  2475. }
  2476. /* and build a fontdir */
  2477. rsc = build_fontdir(lanfnt, nlanfnt);
  2478. if(rsc)
  2479. {
  2480. if(lst)
  2481. {
  2482. lst->next = rsc;
  2483. rsc->prev = lst;
  2484. }
  2485. lst = rsc;
  2486. }
  2487. }
  2488. free(lanfnt);
  2489. clean:
  2490. free(fnt);
  2491. free(fnd);
  2492. free(str.str.cstr);
  2493. return lst;
  2494. }
  2495. /*
  2496. * This gets invoked to determine whether the next resource
  2497. * is to be of a standard-type (e.g. bitmaps etc.), or should
  2498. * be a user-type resource. This function is required because
  2499. * there is the _possibility_ of a lookahead token in the
  2500. * parser, which is generated from the "expr" state in the
  2501. * "nameid" parsing.
  2502. *
  2503. * The general resource format is:
  2504. * <identifier> <type> <flags> <resourcebody>
  2505. *
  2506. * The <identifier> can either be tIDENT or "expr". The latter
  2507. * will always generate a lookahead, which is the <type> of the
  2508. * resource to parse. Otherwise, we need to get a new token from
  2509. * the scanner to determine the next step.
  2510. *
  2511. * The problem arrises when <type> is numerical. This case should
  2512. * map onto default resource-types and be parsed as such instead
  2513. * of being mapped onto user-type resources.
  2514. *
  2515. * The trick lies in the fact that yacc (bison) doesn't care about
  2516. * intermediate changes of the lookahead while reducing a rule. We
  2517. * simply replace the lookahead with a token that will result in
  2518. * a shift to the appropriate rule for the specific resource-type.
  2519. */
  2520. static int rsrcid_to_token(int lookahead)
  2521. {
  2522. int token;
  2523. /* Get a token if we don't have one yet */
  2524. if(lookahead == YYEMPTY)
  2525. lookahead = yylex();
  2526. /* Only numbers are possibly interesting */
  2527. switch(lookahead)
  2528. {
  2529. case tNUMBER:
  2530. case tLNUMBER:
  2531. break;
  2532. default:
  2533. return lookahead;
  2534. }
  2535. token = lookahead;
  2536. switch(yylval.num)
  2537. {
  2538. case WRC_RT_CURSOR:
  2539. token = tCURSOR;
  2540. break;
  2541. case WRC_RT_ICON:
  2542. token = tICON;
  2543. break;
  2544. case WRC_RT_BITMAP:
  2545. token = tBITMAP;
  2546. break;
  2547. case WRC_RT_FONT:
  2548. token = tFONT;
  2549. break;
  2550. case WRC_RT_FONTDIR:
  2551. token = tFONTDIR;
  2552. break;
  2553. case WRC_RT_RCDATA:
  2554. token = tRCDATA;
  2555. break;
  2556. case WRC_RT_MESSAGETABLE:
  2557. token = tMESSAGETABLE;
  2558. break;
  2559. case WRC_RT_DLGINIT:
  2560. token = tDLGINIT;
  2561. break;
  2562. case WRC_RT_ACCELERATOR:
  2563. token = tACCELERATORS;
  2564. break;
  2565. case WRC_RT_MENU:
  2566. token = tMENU;
  2567. break;
  2568. case WRC_RT_DIALOG:
  2569. token = tDIALOG;
  2570. break;
  2571. case WRC_RT_VERSION:
  2572. token = tVERSIONINFO;
  2573. break;
  2574. case WRC_RT_TOOLBAR:
  2575. token = tTOOLBAR;
  2576. break;
  2577. case WRC_RT_HTML:
  2578. token = tHTML;
  2579. break;
  2580. case WRC_RT_STRING:
  2581. break;
  2582. case WRC_RT_ANICURSOR:
  2583. case WRC_RT_ANIICON:
  2584. case WRC_RT_GROUP_CURSOR:
  2585. case WRC_RT_GROUP_ICON:
  2586. parser_warning("Usertype uses reserved type ID %d, which is auto-generated\n", yylval.num);
  2587. return lookahead;
  2588. case WRC_RT_DLGINCLUDE:
  2589. case WRC_RT_PLUGPLAY:
  2590. case WRC_RT_VXD:
  2591. parser_warning("Usertype uses reserved type ID %d, which is not supported by wrc yet\n", yylval.num);
  2592. default:
  2593. return lookahead;
  2594. }
  2595. return token;
  2596. }