Implemented new Wine startup sequence, separating startup into
[wine] / programs / winhelp / macro.lex.l
1 %{
2 /*
3  * Help Viewer
4  *
5  * Copyright 1996 Ulrich Schmid
6  */
7 %}
8 %x quote dquote
9 %{
10 #include "macro.h"
11 #include "y.tab.h"
12
13 static LPCSTR  macroptr;
14 static LPSTR   strptr;
15 static HGLOBAL hStringBuffer = 0;
16 static INT     nested_quotes = 0;
17
18 #define YY_INPUT(buf,result,max_size)\
19   if ((result = *macroptr ? 1 : 0)) buf[0] = *macroptr++;
20
21 #define YY_NO_UNPUT
22 %}
23 %%
24 About                   yylval = (YYSTYPE)MACRO_About;                  return VOID_FUNCTION_VOID;
25 AddAccelerator|AA       yylval = (YYSTYPE)MACRO_AddAccelerator;         return VOID_FUNCTION_2UINT_STRING;
26 ALink|AL                yylval = (YYSTYPE)MACRO_ALink;                  return VOID_FUNCTION_STRING_UINT_STRING;
27 Annotate                yylval = (YYSTYPE)MACRO_Annotate;               return VOID_FUNCTION_VOID;
28 AppendItem              yylval = (YYSTYPE)MACRO_AppendItem;             return VOID_FUNCTION_4STRING;
29 Back                    yylval = (YYSTYPE)MACRO_Back;                   return VOID_FUNCTION_VOID;
30 BackFlush|BF            yylval = (YYSTYPE)MACRO_BackFlush;              return VOID_FUNCTION_VOID;
31 BookmarkDefine          yylval = (YYSTYPE)MACRO_BookmarkDefine;         return VOID_FUNCTION_VOID;
32 BookmarkMore            yylval = (YYSTYPE)MACRO_BookmarkMore;           return VOID_FUNCTION_VOID;
33 BrowseButtons           yylval = (YYSTYPE)MACRO_BrowseButtons;          return VOID_FUNCTION_VOID;
34 ChangeButtonBinding|CBB yylval = (YYSTYPE)MACRO_ChangeButtonBinding;    return VOID_FUNCTION_2STRING;
35 ChangeEnable|CE         yylval = (YYSTYPE)MACRO_ChangeEnable;           return VOID_FUNCTION_2STRING;
36 ChangeItemBinding|CIB   yylval = (YYSTYPE)MACRO_ChangeItemBinding;      return VOID_FUNCTION_2STRING;
37 CheckItem|CI            yylval = (YYSTYPE)MACRO_CheckItem;              return VOID_FUNCTION_STRING;
38 CloseSecondarys|CS      yylval = (YYSTYPE)MACRO_CloseSecondarys;                return VOID_FUNCTION_VOID;
39 CloseWindow|CW          yylval = (YYSTYPE)MACRO_CloseWindow;            return VOID_FUNCTION_STRING;
40 Compare                 yylval = (YYSTYPE)MACRO_Compare;                        return VOID_FUNCTION_STRING;
41 Contents                yylval = (YYSTYPE)MACRO_Contents;               return VOID_FUNCTION_VOID;
42 ControlPanel            yylval = (YYSTYPE)MACRO_ControlPanel;           return VOID_FUNCTION_2STRING_UINT;
43 CopyDialog              yylval = (YYSTYPE)MACRO_CopyDialog;             return VOID_FUNCTION_VOID;
44 CopyTopic|CT            yylval = (YYSTYPE)MACRO_CopyTopic;              return VOID_FUNCTION_VOID;
45 CreateButton|CB         yylval = (YYSTYPE)MACRO_CreateButton;           return VOID_FUNCTION_3STRING;
46 DeleteItem              yylval = (YYSTYPE)MACRO_DeleteItem;             return VOID_FUNCTION_STRING;
47 DeleteMark              yylval = (YYSTYPE)MACRO_DeleteMark;             return VOID_FUNCTION_STRING;
48 DestroyButton           yylval = (YYSTYPE)MACRO_DestroyButton;          return VOID_FUNCTION_STRING;
49 DisableButton|DB        yylval = (YYSTYPE)MACRO_DisableButton;          return VOID_FUNCTION_STRING;
50 DisableItem|DI          yylval = (YYSTYPE)MACRO_DisableItem;            return VOID_FUNCTION_STRING;
51 EnableButton|EB         yylval = (YYSTYPE)MACRO_EnableButton;           return VOID_FUNCTION_STRING;
52 EnableItem|EI           yylval = (YYSTYPE)MACRO_EnableItem;             return VOID_FUNCTION_STRING;
53 EndMPrint               yylval = (YYSTYPE)MACRO_EndMPrint;              return VOID_FUNCTION_VOID;
54 ExecFile|EF             yylval = (YYSTYPE)MACRO_ExecFile;               return VOID_FUNCTION_2STRING_UINT_STRING;
55 ExecProgram|EP          yylval = (YYSTYPE)MACRO_ExecProgram;            return VOID_FUNCTION_STRING_UINT;
56 Exit                    yylval = (YYSTYPE)MACRO_Exit;                   return VOID_FUNCTION_VOID;
57 ExtAbleItem             yylval = (YYSTYPE)MACRO_ExtAbleItem;            return VOID_FUNCTION_STRING_UINT;
58 ExtInsertItem           yylval = (YYSTYPE)MACRO_ExtInsertItem;          return VOID_FUNCTION_4STRING_2UINT;
59 ExtInsertMenu           yylval = (YYSTYPE)MACRO_ExtInsertMenu;          return VOID_FUNCTION_3STRING_2UINT;
60 FileExist|FE            yylval = (YYSTYPE)MACRO_FileExist;              return BOOL_FUNCTION_STRING;
61 FileOpen|FO             yylval = (YYSTYPE)MACRO_FileOpen;               return VOID_FUNCTION_VOID;
62 Find                    yylval = (YYSTYPE)MACRO_Find;                   return VOID_FUNCTION_VOID;
63 Finder|FD               yylval = (YYSTYPE)MACRO_Finder;                 return VOID_FUNCTION_VOID;
64 FloatingMenu            yylval = (YYSTYPE)MACRO_FloatingMenu;           return VOID_FUNCTION_VOID;
65 Flush|FH                yylval = (YYSTYPE)MACRO_Flush;                  return VOID_FUNCTION_VOID;
66 FocusWindow             yylval = (YYSTYPE)MACRO_FocusWindow;            return VOID_FUNCTION_STRING;
67 Generate                yylval = (YYSTYPE)MACRO_Generate;               return VOID_FUNCTION_STRING_WPARAM_LPARAM;
68 GotoMark                yylval = (YYSTYPE)MACRO_GotoMark;               return VOID_FUNCTION_STRING;
69 HelpOn                  yylval = (YYSTYPE)MACRO_HelpOn;                 return VOID_FUNCTION_VOID;
70 HelpOnTop               yylval = (YYSTYPE)MACRO_HelpOnTop;              return VOID_FUNCTION_VOID;
71 History                 yylval = (YYSTYPE)MACRO_History;                        return VOID_FUNCTION_VOID;
72 IfThen|IF                                                       return IF_THEN;
73 IfThenElse|IE                                                   return IF_THEN_ELSE;
74 InitMPrint              yylval = (YYSTYPE)MACRO_InitMPrint;             return BOOL_FUNCTION_VOID;
75 InsertItem              yylval = (YYSTYPE)MACRO_InsertItem;             return VOID_FUNCTION_4STRING_UINT;
76 InsertMenu              yylval = (YYSTYPE)MACRO_InsertMenu;             return VOID_FUNCTION_2STRING_UINT;
77 IsBook                  yylval = (YYSTYPE)MACRO_IsBook;                 return BOOL_FUNCTION_VOID;
78 IsMark                  yylval = (YYSTYPE)MACRO_IsMark;                 return BOOL_FUNCTION_STRING;
79 IsNotMark|NM            yylval = (YYSTYPE)MACRO_IsNotMark;              return BOOL_FUNCTION_STRING;
80 JumpContents            yylval = (YYSTYPE)MACRO_JumpContents;           return VOID_FUNCTION_FILE_WIN;
81 JumpContext|JC          yylval = (YYSTYPE)MACRO_JumpContext;            return VOID_FUNCTION_FILE_WIN_UINT;
82 JumpHash|JH             yylval = (YYSTYPE)MACRO_JumpHash;               return VOID_FUNCTION_FILE_WIN_UINT;
83 JumpHelpOn              yylval = (YYSTYPE)MACRO_JumpHelpOn;             return VOID_FUNCTION_VOID;
84 JumpID|JI               yylval = (YYSTYPE)MACRO_JumpID;                 return VOID_FUNCTION_FILE_WIN_STRING;
85 JumpKeyword|JK          yylval = (YYSTYPE)MACRO_JumpKeyword;            return VOID_FUNCTION_FILE_WIN_STRING;
86 KLink|KL                yylval = (YYSTYPE)MACRO_KLink;                  return VOID_FUNCTION_STRING_UINT_2STRING;
87 Menu|MU                 yylval = (YYSTYPE)MACRO_Menu;                   return VOID_FUNCTION_VOID;
88 MPrintHash              yylval = (YYSTYPE)MACRO_MPrintHash;             return VOID_FUNCTION_UINT;
89 MPrintID                yylval = (YYSTYPE)MACRO_MPrintID;               return VOID_FUNCTION_STRING;
90 Next                    yylval = (YYSTYPE)MACRO_Next;                   return VOID_FUNCTION_VOID;
91 NoShow                  yylval = (YYSTYPE)MACRO_NoShow;                 return VOID_FUNCTION_VOID;
92 Not                                                             return NOT;
93 PopupContext|PC         yylval = (YYSTYPE)MACRO_PopupContext;           return VOID_FUNCTION_STRING_UINT;
94 PopupHash               yylval = (YYSTYPE)MACRO_PopupHash;              return VOID_FUNCTION_STRING_UINT;
95 PopupId|PI              yylval = (YYSTYPE)MACRO_PopupId;                        return VOID_FUNCTION_2STRING;
96 PositionWindow|PW       yylval = (YYSTYPE)MACRO_PositionWindow;         return VOID_FUNCTION_2INT_3UINT_STRING;
97 Prev                    yylval = (YYSTYPE)MACRO_Prev;                   return VOID_FUNCTION_VOID;
98 Print                   yylval = (YYSTYPE)MACRO_Print;                  return VOID_FUNCTION_VOID;
99 PrinterSetup            yylval = (YYSTYPE)MACRO_PrinterSetup;           return VOID_FUNCTION_VOID;
100 RegisterRoutine|RR      yylval = (YYSTYPE)MACRO_RegisterRoutine;                return VOID_FUNCTION_3STRING;
101 RemoveAccelerator|RA    yylval = (YYSTYPE)MACRO_RemoveAccelerator;      return VOID_FUNCTION_2UINT;
102 ResetMenu               yylval = (YYSTYPE)MACRO_ResetMenu;              return VOID_FUNCTION_VOID;
103 SaveMark                yylval = (YYSTYPE)MACRO_SaveMark;               return VOID_FUNCTION_STRING;
104 Search                  yylval = (YYSTYPE)MACRO_Search;                 return VOID_FUNCTION_VOID;
105 SetContents             yylval = (YYSTYPE)MACRO_SetContents;            return VOID_FUNCTION_STRING_UINT;
106 SetHelpOnFile           yylval = (YYSTYPE)MACRO_SetHelpOnFile;          return VOID_FUNCTION_STRING;
107 SetPopupColor|SPC       yylval = (YYSTYPE)MACRO_SetPopupColor;          return VOID_FUNCTION_3UINT;
108 ShellExecute|SE         yylval = (YYSTYPE)MACRO_ShellExecute;           return VOID_FUNCTION_2STRING_2UINT_2STRING;
109 ShortCut|SH             yylval = (YYSTYPE)MACRO_ShortCut;               return VOID_FUNCTION_2STRING_WPARAM_LPARAM_STRING;
110 TCard                   yylval = (YYSTYPE)MACRO_TCard;                  return VOID_FUNCTION_UINT;
111 Test                    yylval = (YYSTYPE)MACRO_Test;                   return VOID_FUNCTION_UINT;
112 TestALink               yylval = (YYSTYPE)MACRO_TestALink;              return BOOL_FUNCTION_STRING;
113 TestKLink               yylval = (YYSTYPE)MACRO_TestKLink;              return BOOL_FUNCTION_STRING;
114 UncheckItem|UI          yylval = (YYSTYPE)MACRO_UncheckItem;            return VOID_FUNCTION_STRING;
115 UpdateWindow|UW         yylval = (YYSTYPE)MACRO_UpdateWindow;           return VOID_FUNCTION_2STRING;
116
117 [-+]?[0-9]+             yylval.integer = strtol(yytext, NULL, 10);      return INTEGER;
118 [-+]?0[xX][0-9a-f]+     yylval.integer = strtol(yytext, NULL, 16);      return INTEGER;
119
120 \`                      |
121 \"                      {
122                           if (!hStringBuffer)
123                             {
124                               hStringBuffer = GlobalAlloc(GMEM_FIXED, strlen(macroptr));
125                               strptr = GlobalLock(hStringBuffer);
126                             }
127                           yylval = (YYSTYPE)strptr;
128                           BEGIN (yytext[0] == '`' ? quote : dquote);
129                         }
130
131 <quote>\`               {
132                           *strptr++ = yytext[0];
133                           nested_quotes++;
134                         }
135
136 <quote>\'               |
137 <dquote>\"              {
138                           if (nested_quotes)
139                             {
140                               nested_quotes--;
141                               *strptr++ = yytext[0];
142                             }
143                           else
144                             {
145                               BEGIN INITIAL;
146                               *strptr++ = '\0';
147                               return tSTRING;
148                             }
149                         }
150
151 <quote,dquote>.         *strptr++ = yytext[0];
152 <quote,dquote>\\.       *strptr++ = yytext[1];
153
154 <quote,dquote><<EOF>>   return 0;
155
156
157 " "
158
159 .                       return yytext[0];
160 %%
161 #include "winhelp.h"
162 static CHAR szTestMacro[256];
163
164 static LRESULT MACRO_TestDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
165 {
166   if (msg == WM_COMMAND && wParam == IDOK)
167     {
168       GetDlgItemText(hDlg, 99, szTestMacro, sizeof(szTestMacro));
169       EndDialog(hDlg, IDOK);
170       return TRUE;
171     }
172   return FALSE;
173 }
174
175 VOID MACRO_ExecuteMacro(LPCSTR macro)
176 {
177   if (!lstrcmpi(macro, "MacroTest"))
178     {
179       WNDPROC lpfnDlg = MakeProcInstance(MACRO_TestDialogProc, Globals.hInstance);
180       DialogBox(Globals.hInstance, STRING_DIALOG_TEST, Globals.active_win->hMainWnd, lpfnDlg);
181       FreeProcInstance(lpfnDlg);
182       macro = szTestMacro;
183     }
184
185   macroptr = macro;
186
187   yyparse();
188
189   if (hStringBuffer) GlobalFree(hStringBuffer);
190   hStringBuffer = 0;
191 }
192
193 void yyerror (const char *s)
194 {
195   fprintf(stderr, "%s\n", s);
196   nested_quotes = 0;
197   BEGIN INITIAL;
198   yyrestart(yyin);
199 }
200
201 #ifndef yywrap
202 int yywrap(void) { return 1; }
203 #endif