2008-02-19 15:42:49 +01:00
|
|
|
%{ /* -*-C-*- */
|
1996-05-06 18:06:24 +02:00
|
|
|
/*
|
|
|
|
* Help Viewer
|
|
|
|
*
|
|
|
|
* Copyright 1996 Ulrich Schmid
|
2008-07-12 10:37:19 +02:00
|
|
|
* Copyright 2002,2008 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1996-05-06 18:06:24 +02:00
|
|
|
*/
|
|
|
|
%}
|
2012-10-01 12:19:25 +02:00
|
|
|
%option noinput nounput never-interactive 8bit
|
2002-07-16 03:46:29 +02:00
|
|
|
%x quote
|
1996-05-06 18:06:24 +02:00
|
|
|
%{
|
2008-02-19 15:42:49 +01:00
|
|
|
#include "config.h"
|
2002-07-16 03:46:29 +02:00
|
|
|
#include <assert.h>
|
2009-05-30 14:26:33 +02:00
|
|
|
#include <stdarg.h>
|
2008-02-19 15:42:49 +01:00
|
|
|
|
|
|
|
#define YY_NO_UNISTD_H
|
2009-05-30 14:26:33 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winhelp.h"
|
1996-05-06 18:06:24 +02:00
|
|
|
|
2002-07-16 03:46:29 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
|
|
|
|
|
2008-07-12 10:37:19 +02:00
|
|
|
struct lex_data {
|
|
|
|
LPCSTR macroptr;
|
|
|
|
LPSTR strptr;
|
|
|
|
int quote_stack[32];
|
|
|
|
unsigned quote_stk_idx;
|
|
|
|
LPSTR cache_string[32];
|
|
|
|
int cache_used;
|
2009-05-30 14:26:33 +02:00
|
|
|
WINHELP_WINDOW* window;
|
2008-07-12 10:37:19 +02:00
|
|
|
};
|
|
|
|
static struct lex_data* lex_data = NULL;
|
|
|
|
|
2002-11-15 02:34:57 +01:00
|
|
|
struct lexret yylval;
|
1996-05-06 18:06:24 +02:00
|
|
|
|
|
|
|
#define YY_INPUT(buf,result,max_size)\
|
2008-07-12 10:37:19 +02:00
|
|
|
if ((result = *lex_data->macroptr ? 1 : 0)) buf[0] = *lex_data->macroptr++;
|
1996-05-06 18:06:24 +02:00
|
|
|
|
|
|
|
%}
|
|
|
|
%%
|
2002-11-15 02:34:57 +01:00
|
|
|
|
|
|
|
[-+]?[0-9]+ yylval.integer = strtol(yytext, NULL, 10); return INTEGER;
|
1996-05-06 18:06:24 +02:00
|
|
|
[-+]?0[xX][0-9a-f]+ yylval.integer = strtol(yytext, NULL, 16); return INTEGER;
|
|
|
|
|
2002-11-15 02:34:57 +01:00
|
|
|
[a-zA-Z][_0-9a-zA-Z]* return MACRO_Lookup(yytext, &yylval);
|
|
|
|
|
|
|
|
\` |
|
|
|
|
\" |
|
|
|
|
\' |
|
|
|
|
<quote>\` |
|
|
|
|
<quote>\" |
|
|
|
|
<quote>\' {
|
2008-07-12 10:37:19 +02:00
|
|
|
if (lex_data->quote_stk_idx == 0 ||
|
|
|
|
(yytext[0] == '\"' && lex_data->quote_stack[lex_data->quote_stk_idx - 1] != '\"') ||
|
2002-11-15 02:34:57 +01:00
|
|
|
(yytext[0] == '`'))
|
|
|
|
{
|
|
|
|
/* opening a new one */
|
2008-07-12 10:37:19 +02:00
|
|
|
if (lex_data->quote_stk_idx == 0)
|
2002-11-15 02:34:57 +01:00
|
|
|
{
|
2018-08-10 12:27:55 +02:00
|
|
|
assert(lex_data->cache_used < ARRAY_SIZE(lex_data->cache_string));
|
2008-07-12 10:37:19 +02:00
|
|
|
lex_data->strptr = lex_data->cache_string[lex_data->cache_used] = HeapAlloc(GetProcessHeap(), 0, strlen(lex_data->macroptr) + 1);
|
|
|
|
yylval.string = lex_data->strptr;
|
|
|
|
lex_data->cache_used++;
|
2002-11-15 02:34:57 +01:00
|
|
|
BEGIN(quote);
|
|
|
|
}
|
2008-07-12 10:37:19 +02:00
|
|
|
else *lex_data->strptr++ = yytext[0];
|
|
|
|
lex_data->quote_stack[lex_data->quote_stk_idx++] = yytext[0];
|
2018-08-10 12:27:55 +02:00
|
|
|
assert(lex_data->quote_stk_idx < ARRAY_SIZE(lex_data->quote_stack));
|
2002-11-15 02:34:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (yytext[0] == '`') assert(0);
|
|
|
|
/* close the current quote */
|
2008-07-12 10:37:19 +02:00
|
|
|
if (--lex_data->quote_stk_idx == 0)
|
2002-11-15 02:34:57 +01:00
|
|
|
{
|
|
|
|
BEGIN INITIAL;
|
2008-07-12 10:37:19 +02:00
|
|
|
*lex_data->strptr++ = '\0';
|
2002-11-15 02:34:57 +01:00
|
|
|
return STRING;
|
|
|
|
}
|
2008-07-12 10:37:19 +02:00
|
|
|
else *lex_data->strptr++ = yytext[0];
|
2002-11-15 02:34:57 +01:00
|
|
|
}
|
|
|
|
}
|
1996-05-06 18:06:24 +02:00
|
|
|
|
2008-07-12 10:37:19 +02:00
|
|
|
<quote>. *lex_data->strptr++ = yytext[0];
|
|
|
|
<quote>\\. *lex_data->strptr++ = yytext[1];
|
2002-11-15 02:34:57 +01:00
|
|
|
<quote><<EOF>> return 0;
|
1996-05-06 18:06:24 +02:00
|
|
|
|
|
|
|
" "
|
2002-11-15 02:34:57 +01:00
|
|
|
. return yytext[0];
|
1996-05-06 18:06:24 +02:00
|
|
|
%%
|
2002-11-15 02:34:57 +01:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* all code for testing macros */
|
1996-05-06 18:06:24 +02:00
|
|
|
#include "winhelp.h"
|
|
|
|
static CHAR szTestMacro[256];
|
|
|
|
|
2000-06-20 22:34:11 +02:00
|
|
|
static LRESULT CALLBACK MACRO_TestDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
1996-05-06 18:06:24 +02:00
|
|
|
{
|
2002-07-16 03:46:29 +02:00
|
|
|
if (msg == WM_COMMAND && wParam == IDOK)
|
1996-05-06 18:06:24 +02:00
|
|
|
{
|
2002-07-16 03:46:29 +02:00
|
|
|
GetDlgItemText(hDlg, 99, szTestMacro, sizeof(szTestMacro));
|
|
|
|
EndDialog(hDlg, IDOK);
|
|
|
|
return TRUE;
|
1996-05-06 18:06:24 +02:00
|
|
|
}
|
2002-07-16 03:46:29 +02:00
|
|
|
return FALSE;
|
1996-05-06 18:06:24 +02:00
|
|
|
}
|
|
|
|
|
2002-11-15 02:34:57 +01:00
|
|
|
void macro_test(void)
|
1996-05-06 18:06:24 +02:00
|
|
|
{
|
2002-11-15 02:34:57 +01:00
|
|
|
WNDPROC lpfnDlg = MakeProcInstance(MACRO_TestDialogProc, Globals.hInstance);
|
|
|
|
DialogBox(Globals.hInstance, STRING_DIALOG_TEST, Globals.active_win->hMainWnd, (DLGPROC)lpfnDlg);
|
|
|
|
FreeProcInstance(lpfnDlg);
|
|
|
|
macro = szTestMacro;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* small helper function for debug messages */
|
|
|
|
static const char* ts(int t)
|
|
|
|
{
|
|
|
|
static char c[2] = {0,0};
|
|
|
|
|
|
|
|
switch (t)
|
1996-05-06 18:06:24 +02:00
|
|
|
{
|
2002-11-15 02:34:57 +01:00
|
|
|
case EMPTY: return "EMPTY";
|
|
|
|
case VOID_FUNCTION: return "VOID_FUNCTION";
|
|
|
|
case BOOL_FUNCTION: return "BOOL_FUNCTION";
|
|
|
|
case INTEGER: return "INTEGER";
|
|
|
|
case STRING: return "STRING";
|
|
|
|
case IDENTIFIER: return "IDENTIFIER";
|
|
|
|
default: c[0] = (char)t; return c;
|
1996-05-06 18:06:24 +02:00
|
|
|
}
|
2002-11-15 02:34:57 +01:00
|
|
|
}
|
1996-05-06 18:06:24 +02:00
|
|
|
|
2009-10-07 13:40:00 +02:00
|
|
|
static int MACRO_CallBoolFunc(void *fn, const char* args, void** ret);
|
1996-05-06 18:06:24 +02:00
|
|
|
|
2002-11-15 02:34:57 +01:00
|
|
|
/******************************************************************
|
|
|
|
* MACRO_CheckArgs
|
|
|
|
*
|
|
|
|
* checks number of arguments against prototype, and stores arguments on
|
|
|
|
* stack pa for later call
|
|
|
|
* returns -1 on error, otherwise the number of pushed parameters
|
|
|
|
*/
|
|
|
|
static int MACRO_CheckArgs(void* pa[], unsigned max, const char* args)
|
|
|
|
{
|
2007-05-21 23:19:04 +02:00
|
|
|
int t;
|
|
|
|
unsigned int len = 0, idx = 0;
|
1996-05-06 18:06:24 +02:00
|
|
|
|
2016-04-21 22:03:57 +02:00
|
|
|
WINE_TRACE("Checking %s\n", debugstr_a(args));
|
2002-11-15 02:34:57 +01:00
|
|
|
|
|
|
|
if (yylex() != '(') {WINE_WARN("missing (\n");return -1;}
|
|
|
|
|
|
|
|
if (*args)
|
2002-07-16 03:46:29 +02:00
|
|
|
{
|
2005-01-25 21:08:46 +01:00
|
|
|
len = strlen(args);
|
2002-11-15 02:34:57 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
t = yylex();
|
2016-04-21 22:03:57 +02:00
|
|
|
WINE_TRACE("Got %s <=> %c\n", debugstr_a(ts(t)), *args);
|
2002-11-15 02:34:57 +01:00
|
|
|
|
|
|
|
switch (*args)
|
|
|
|
{
|
|
|
|
case 'S':
|
|
|
|
if (t != STRING)
|
|
|
|
{WINE_WARN("missing S\n");return -1;}
|
|
|
|
pa[idx] = (void*)yylval.string;
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
case 'I':
|
|
|
|
if (t != INTEGER)
|
|
|
|
{WINE_WARN("missing U\n");return -1;}
|
2008-04-09 14:24:07 +02:00
|
|
|
pa[idx] = LongToPtr(yylval.integer);
|
2002-11-15 02:34:57 +01:00
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
if (t != BOOL_FUNCTION)
|
|
|
|
{WINE_WARN("missing B\n");return -1;}
|
2004-12-13 22:06:46 +01:00
|
|
|
if (MACRO_CallBoolFunc(yylval.function, yylval.proto, &pa[idx]) == 0)
|
2002-11-15 02:34:57 +01:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
default:
|
2016-04-21 22:03:57 +02:00
|
|
|
WINE_WARN("unexpected %s while args is %c\n", debugstr_a(ts(t)), *args);
|
2002-11-15 02:34:57 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
if (*++args == '\0') break;
|
2005-01-25 21:08:46 +01:00
|
|
|
t = yylex();
|
|
|
|
if (t == ')') goto CheckArgs_end;
|
|
|
|
if (t != ',') {WINE_WARN("missing ,\n");return -1;}
|
|
|
|
if (idx >= max) {WINE_FIXME("stack overflow (%d)\n", max);return -1;}
|
2002-11-15 02:34:57 +01:00
|
|
|
}
|
2002-07-16 03:46:29 +02:00
|
|
|
}
|
2002-11-15 02:34:57 +01:00
|
|
|
if (yylex() != ')') {WINE_WARN("missing )\n");return -1;}
|
2005-01-25 21:08:46 +01:00
|
|
|
|
|
|
|
CheckArgs_end:
|
|
|
|
while (len > idx) pa[--len] = NULL;
|
2002-11-15 02:34:57 +01:00
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* MACRO_CallBoolFunc
|
|
|
|
*
|
|
|
|
* Invokes boolean function fn, which arguments are defined by args
|
|
|
|
* stores bool result into ret
|
|
|
|
*/
|
2009-10-07 13:40:00 +02:00
|
|
|
static int MACRO_CallBoolFunc(void *fn, const char* args, void** ret)
|
2002-11-15 02:34:57 +01:00
|
|
|
{
|
|
|
|
void* pa[2];
|
2018-08-10 12:27:55 +02:00
|
|
|
int idx = MACRO_CheckArgs(pa, ARRAY_SIZE(pa), args);
|
2002-11-15 02:34:57 +01:00
|
|
|
|
2005-01-25 21:08:46 +01:00
|
|
|
if (idx < 0) return 0;
|
|
|
|
if (!fn) return 1;
|
2002-11-15 02:34:57 +01:00
|
|
|
|
|
|
|
WINE_TRACE("calling with %u pmts\n", idx);
|
|
|
|
|
2005-01-25 21:08:46 +01:00
|
|
|
switch (strlen(args))
|
2002-11-15 02:34:57 +01:00
|
|
|
{
|
2009-10-07 13:40:00 +02:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL (WINAPI *func)(void) = fn;
|
|
|
|
*ret = (void *)(ULONG_PTR)func();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
BOOL (WINAPI *func)(void *) = fn;
|
|
|
|
*ret = (void *)(ULONG_PTR)func( pa[0]);
|
|
|
|
break;
|
|
|
|
}
|
2002-11-15 02:34:57 +01:00
|
|
|
default: WINE_FIXME("NIY\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
1996-05-06 18:06:24 +02:00
|
|
|
}
|
|
|
|
|
2002-11-15 02:34:57 +01:00
|
|
|
/******************************************************************
|
|
|
|
* MACRO_CallVoidFunc
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2009-10-07 13:40:00 +02:00
|
|
|
static int MACRO_CallVoidFunc(void *fn, const char* args)
|
1996-05-06 18:06:24 +02:00
|
|
|
{
|
2002-11-15 02:34:57 +01:00
|
|
|
void* pa[6];
|
2018-08-10 12:27:55 +02:00
|
|
|
int idx = MACRO_CheckArgs(pa, ARRAY_SIZE(pa), args);
|
2002-11-15 02:34:57 +01:00
|
|
|
|
2005-01-25 21:08:46 +01:00
|
|
|
if (idx < 0) return 0;
|
|
|
|
if (!fn) return 1;
|
2002-11-15 02:34:57 +01:00
|
|
|
|
2004-12-13 22:06:46 +01:00
|
|
|
WINE_TRACE("calling %p with %u pmts\n", fn, idx);
|
2002-11-15 02:34:57 +01:00
|
|
|
|
2005-01-25 21:08:46 +01:00
|
|
|
switch (strlen(args))
|
2002-11-15 02:34:57 +01:00
|
|
|
{
|
2009-10-07 13:40:00 +02:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
void (WINAPI *func)(void) = fn;
|
|
|
|
func();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
void (WINAPI *func)(void*) = fn;
|
|
|
|
func( pa[0] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
void (WINAPI *func)(void*,void*) = fn;
|
|
|
|
func( pa[0], pa[1] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
void (WINAPI *func)(void*,void*,void*) = fn;
|
|
|
|
func( pa[0], pa[1], pa[2] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
void (WINAPI *func)(void*,void*,void*,void*) = fn;
|
|
|
|
func( pa[0], pa[1], pa[2], pa[3] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
void (WINAPI *func)(void*,void*,void*,void*,void*) = fn;
|
|
|
|
func( pa[0], pa[1], pa[2], pa[3], pa[4] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
void (WINAPI *func)(void*,void*,void*,void*,void*,void*) = fn;
|
|
|
|
func( pa[0], pa[1], pa[2], pa[3], pa[4], pa[5] );
|
|
|
|
break;
|
|
|
|
}
|
2002-11-15 02:34:57 +01:00
|
|
|
default: WINE_FIXME("NIY\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-30 14:26:33 +02:00
|
|
|
BOOL MACRO_ExecuteMacro(WINHELP_WINDOW* window, LPCSTR macro)
|
2002-11-15 02:34:57 +01:00
|
|
|
{
|
2008-07-12 10:37:19 +02:00
|
|
|
struct lex_data curr_lex_data, *prev_lex_data;
|
2008-07-12 10:36:55 +02:00
|
|
|
BOOL ret = TRUE;
|
2002-11-15 02:34:57 +01:00
|
|
|
int t;
|
|
|
|
|
2016-04-21 22:03:57 +02:00
|
|
|
WINE_TRACE("%s\n", debugstr_a(macro));
|
2002-11-15 02:34:57 +01:00
|
|
|
|
2008-07-12 10:37:19 +02:00
|
|
|
prev_lex_data = lex_data;
|
|
|
|
lex_data = &curr_lex_data;
|
|
|
|
|
|
|
|
memset(lex_data, 0, sizeof(*lex_data));
|
|
|
|
lex_data->macroptr = macro;
|
2009-05-30 14:27:04 +02:00
|
|
|
lex_data->window = WINHELP_GrabWindow(window);
|
2002-11-15 02:34:57 +01:00
|
|
|
|
|
|
|
while ((t = yylex()) != EMPTY)
|
|
|
|
{
|
|
|
|
switch (t)
|
|
|
|
{
|
|
|
|
case VOID_FUNCTION:
|
2016-04-21 22:03:57 +02:00
|
|
|
WINE_TRACE("got type void func(%s)\n", debugstr_a(yylval.proto));
|
2004-12-13 22:06:46 +01:00
|
|
|
MACRO_CallVoidFunc(yylval.function, yylval.proto);
|
2002-11-15 02:34:57 +01:00
|
|
|
break;
|
|
|
|
case BOOL_FUNCTION:
|
2016-04-21 22:03:57 +02:00
|
|
|
WINE_WARN("got type bool func(%s)\n", debugstr_a(yylval.proto));
|
2002-11-15 02:34:57 +01:00
|
|
|
break;
|
|
|
|
default:
|
2016-04-21 22:03:57 +02:00
|
|
|
WINE_WARN("got unexpected type %s\n", debugstr_a(ts(t)));
|
2009-05-30 14:26:21 +02:00
|
|
|
YY_FLUSH_BUFFER;
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
2002-11-15 02:34:57 +01:00
|
|
|
}
|
|
|
|
switch (t = yylex())
|
|
|
|
{
|
2008-07-12 10:36:55 +02:00
|
|
|
case EMPTY: goto done;
|
2002-11-15 02:34:57 +01:00
|
|
|
case ';': break;
|
2009-05-30 14:26:21 +02:00
|
|
|
default: ret = FALSE; YY_FLUSH_BUFFER; goto done;
|
2002-11-15 02:34:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-12 10:36:55 +02:00
|
|
|
done:
|
2008-07-12 10:37:19 +02:00
|
|
|
for (t = 0; t < lex_data->cache_used; t++)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lex_data->cache_string[t]);
|
|
|
|
lex_data = prev_lex_data;
|
2009-05-30 14:27:04 +02:00
|
|
|
WINHELP_ReleaseWindow(window);
|
2002-11-15 02:34:57 +01:00
|
|
|
|
2008-07-12 10:36:55 +02:00
|
|
|
return ret;
|
1996-05-06 18:06:24 +02:00
|
|
|
}
|
1996-05-21 17:01:41 +02:00
|
|
|
|
2009-05-30 14:26:33 +02:00
|
|
|
WINHELP_WINDOW* MACRO_CurrentWindow(void)
|
|
|
|
{
|
|
|
|
return lex_data ? lex_data->window : Globals.active_win;
|
|
|
|
}
|
|
|
|
|
1996-05-21 17:01:41 +02:00
|
|
|
#ifndef yywrap
|
|
|
|
int yywrap(void) { return 1; }
|
|
|
|
#endif
|