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