Browse Source

Add function

master
boisso 7 years ago
parent
commit
a3b470faf8
  1. 13
      CVSROOT/checkoutlist
  2. 15
      CVSROOT/commitinfo
  3. 11
      CVSROOT/config
  4. 23
      CVSROOT/cvswrappers
  5. 21
      CVSROOT/editinfo
  6. 26
      CVSROOT/loginfo
  7. 26
      CVSROOT/modules
  8. 12
      CVSROOT/notify
  9. 13
      CVSROOT/rcsinfo
  10. 20
      CVSROOT/taginfo
  11. 21
      CVSROOT/verifymsg
  12. 149
      k-meleon/macros2/functions.h
  13. 86
      k-meleon/macros2/macros.cpp
  14. 196
      k-meleon/macros2/object.h
  15. 197
      k-meleon/macros2/parser.h
  16. 43
      mozilla/.mozconfig
  17. 137
      mozilla/embedding/config/Makefile.in
  18. 413
      mozilla/embedding/config/basebrowser-win
  19. 57
      mozilla/kmeleon/build.mk
  20. 3
      mozilla/kmeleon/config/mozconfig
  21. 1
      mozilla/kmeleon/config/version.txt
  22. 54
      mozilla/kmeleon/confvars.sh
  23. 173
      mozilla/kmeleon/embed-replacements/content/global/about.xhtml
  24. BIN
      mozilla/kmeleon/embed-replacements/content/global/logo.gif
  25. 295
      mozilla/kmeleon/embed-replacements/content/global/netError.xhtml
  26. 151
      mozilla/kmeleon/embed-replacements/skin/classic/global/netError.css
  27. 63
      mozilla/kmeleon/flashblock/Makefile.in
  28. 10
      mozilla/kmeleon/flashblock/README
  29. BIN
      mozilla/kmeleon/flashblock/content/authorware.png
  30. 18
      mozilla/kmeleon/flashblock/content/contents.rdf
  31. BIN
      mozilla/kmeleon/flashblock/content/director.png
  32. BIN
      mozilla/kmeleon/flashblock/content/flash.png
  33. 98
      mozilla/kmeleon/flashblock/content/flashblock.css
  34. 619
      mozilla/kmeleon/flashblock/content/flashblock.xml
  35. BIN
      mozilla/kmeleon/flashblock/content/flashplay.png
  36. 8
      mozilla/kmeleon/flashblock/jar.mn
  37. 52
      mozilla/kmeleon/history/Makefile.in
  38. 53
      mozilla/kmeleon/history/public/Makefile.in
  39. 108
      mozilla/kmeleon/history/public/nsIBrowserHistory.idl
  40. 75
      mozilla/kmeleon/history/src/Makefile.in
  41. 4642
      mozilla/kmeleon/history/src/nsGlobalHistory.cpp
  42. 455
      mozilla/kmeleon/history/src/nsGlobalHistory.h
  43. 63
      mozilla/kmeleon/history/src/nsHistoryLoadListener.h
  44. 46
      mozilla/kmeleon/makefiles.sh
  45. 51
      mozilla/kmeleon/typeaheadfind/Makefile.in
  46. 44
      mozilla/kmeleon/typeaheadfind/makefiles.sh
  47. 50
      mozilla/kmeleon/typeaheadfind/public/Makefile.in
  48. 88
      mozilla/kmeleon/typeaheadfind/public/nsITypeAheadFind.idl
  49. 44
      mozilla/kmeleon/typeaheadfind/resources/Makefile.in
  50. BIN
      mozilla/kmeleon/typeaheadfind/resources/content/notfound.wav
  51. 41
      mozilla/kmeleon/typeaheadfind/resources/content/prefs/typeaheadfind.js
  52. 2
      mozilla/kmeleon/typeaheadfind/resources/jar.mn
  53. 99
      mozilla/kmeleon/typeaheadfind/src/Makefile.in
  54. 2993
      mozilla/kmeleon/typeaheadfind/src/nsTypeAheadFind.cpp
  55. 279
      mozilla/kmeleon/typeaheadfind/src/nsTypeAheadFind.h
  56. 102
      mozilla/kmeleon/typeaheadfind/src/nsTypeAheadFindRegistration.cpp
  57. 9
      mozilla/kmeleon/typeaheadfind/src/typeaheadfind.pkg
  58. 48
      mozilla/kmeleon/wallet/Makefile.in
  59. 82
      mozilla/kmeleon/wallet/build/Makefile.in
  60. 61
      mozilla/kmeleon/wallet/build/nsWalletViewerFactory.cpp
  61. 9
      mozilla/kmeleon/wallet/build/walletviewer.pkg
  62. 64
      mozilla/kmeleon/wallet/editor/Makefile.in
  63. 61
      mozilla/kmeleon/wallet/editor/nsIWalletEditor.idl
  64. 99
      mozilla/kmeleon/wallet/editor/nsWalletEditor.cpp
  65. 51
      mozilla/kmeleon/wallet/editor/nsWalletEditor.h
  66. 185
      mozilla/kmeleon/wallet/editor/resources/content/WalletAddress.xul
  67. 57
      mozilla/kmeleon/wallet/editor/resources/content/WalletBilling.xul
  68. 525
      mozilla/kmeleon/wallet/editor/resources/content/WalletConcatenated.xul
  69. 127
      mozilla/kmeleon/wallet/editor/resources/content/WalletCredit.xul
  70. 105
      mozilla/kmeleon/wallet/editor/resources/content/WalletEmploy.xul
  71. 191
      mozilla/kmeleon/wallet/editor/resources/content/WalletMisc.xul
  72. 129
      mozilla/kmeleon/wallet/editor/resources/content/WalletName.xul
  73. 57
      mozilla/kmeleon/wallet/editor/resources/content/WalletOther.xul
  74. 229
      mozilla/kmeleon/wallet/editor/resources/content/WalletPhone.xul
  75. 57
      mozilla/kmeleon/wallet/editor/resources/content/WalletPrimary.xul
  76. 57
      mozilla/kmeleon/wallet/editor/resources/content/WalletShipping.xul
  77. 168
      mozilla/kmeleon/wallet/editor/resources/content/WalletTree.xul
  78. 112
      mozilla/kmeleon/wallet/editor/resources/content/WalletUrlspecific.xul
  79. 479
      mozilla/kmeleon/wallet/editor/resources/content/WalletViewer.js
  80. 42
      mozilla/kmeleon/wallet/editor/resources/content/WalletViewer.xul
  81. 14
      mozilla/kmeleon/wallet/editor/resources/locale/en-US/WalletEditor.dtd
  82. 46
      mozilla/kmeleon/wallet/editor/resources/locale/en-US/WalletEditor.properties
  83. 178
      mozilla/kmeleon/wallet/editor/resources/locale/en-US/WalletViewer.dtd
  84. 53
      mozilla/kmeleon/wallet/jar.mn
  85. 47
      mozilla/kmeleon/wallet/makefiles.sh
  86. 61
      mozilla/kmeleon/wallet/public/Makefile.in
  87. 49
      mozilla/kmeleon/wallet/public/nsCPassword.h
  88. 79
      mozilla/kmeleon/wallet/public/nsIPassword.idl
  89. 97
      mozilla/kmeleon/wallet/public/nsIWalletService.idl
  90. 38
      mozilla/kmeleon/wallet/resources/content/contents.rdf
  91. 109
      mozilla/kmeleon/wallet/resources/content/pref-passwords.xul
  92. 93
      mozilla/kmeleon/wallet/resources/content/pref-wallet.xul
  93. 9
      mozilla/kmeleon/wallet/resources/content/walletContextOverlay.xul
  94. 191
      mozilla/kmeleon/wallet/resources/content/walletNavigatorOverlay.xul
  95. 386
      mozilla/kmeleon/wallet/resources/content/walletOverlay.js
  96. 54
      mozilla/kmeleon/wallet/resources/content/walletPrefsOverlay.xul
  97. 102
      mozilla/kmeleon/wallet/resources/content/walletTasksOverlay.xul
  98. 26
      mozilla/kmeleon/wallet/resources/locale/en-US/contents.rdf
  99. 15
      mozilla/kmeleon/wallet/resources/locale/en-US/pref-passwords.dtd
  100. 10
      mozilla/kmeleon/wallet/resources/locale/en-US/pref-wallet.dtd
  101. Some files were not shown because too many files have changed in this diff Show More

13
CVSROOT/checkoutlist

@ -0,0 +1,13 @@
# The "checkoutlist" file is used to support additional version controlled
# administrative files in $CVSROOT/CVSROOT, such as template files.
#
# The first entry on a line is a filename which will be checked out from
# the corresponding RCS file in the $CVSROOT/CVSROOT directory.
# The remainder of the line is an error message to use if the file cannot
# be checked out.
#
# File format:
#
# [<whitespace>]<filename><whitespace><error message><end-of-line>
#
# comment lines begin with '#'

15
CVSROOT/commitinfo

@ -0,0 +1,15 @@
# The "commitinfo" file is used to control pre-commit checks.
# The filter on the right is invoked with the repository and a list
# of files to check. A non-zero exit of the filter program will
# cause the commit to be aborted.
#
# The first entry on a line is a regular expression which is tested
# against the directory that the change is being committed to, relative
# to the $CVSROOT. For the first match that is found, then the remainder
# of the line is the name of the filter to run.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name "ALL" appears as a regular expression it is always used
# in addition to the first matching regex or "DEFAULT".

11
CVSROOT/config

@ -0,0 +1,11 @@
# Set this to "no" if pserver shouldn't check system users/passwords
#SystemAuth=no
# Set `PreservePermissions' to `yes' to save file status information
# in the repository.
#PreservePermissions=no
# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top
# level of the new working directory when using the `cvs checkout'
# command.
#TopLevelAdmin=no

23
CVSROOT/cvswrappers

@ -0,0 +1,23 @@
# This file affects handling of files based on their names.
#
# The -t/-f options allow one to treat directories of files
# as a single file, or to transform a file in other ways on
# its way in and out of CVS.
#
# The -m option specifies whether CVS attempts to merge files.
#
# The -k option specifies keyword expansion (e.g. -kb for binary).
#
# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)
#
# wildcard [option value][option value]...
#
# where option is one of
# -f from cvs filter value: path to filter
# -t to cvs filter value: path to filter
# -m update methodology value: MERGE or COPY
# -k expansion mode value: b, o, kkv, &c
#
# and value is a single-quote delimited value.
# For example:
#*.gif -k 'b'

21
CVSROOT/editinfo

@ -0,0 +1,21 @@
# The "editinfo" file is used to allow verification of logging
# information. It works best when a template (as specified in the
# rcsinfo file) is provided for the logging procedure. Given a
# template with locations for, a bug-id number, a list of people who
# reviewed the code before it can be checked in, and an external
# process to catalog the differences that were code reviewed, the
# following test can be applied to the code:
#
# Making sure that the entered bug-id number is correct.
# Validating that the code that was reviewed is indeed the code being
# checked in (using the bug-id number or a seperate review
# number to identify this particular code set.).
#
# If any of the above test failed, then the commit would be aborted.
#
# Actions such as mailing a copy of the report to each reviewer are
# better handled by an entry in the loginfo file.
#
# One thing that should be noted is the the ALL keyword is not
# supported. There can be only one entry that matches a given
# repository.

26
CVSROOT/loginfo

@ -0,0 +1,26 @@
# The "loginfo" file controls where "cvs commit" log information
# is sent. The first entry on a line is a regular expression which must match
# the directory that the change is being made to, relative to the
# $CVSROOT. If a match is found, then the remainder of the line is a filter
# program that should expect log information on its standard input.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name ALL appears as a regular expression it is always used
# in addition to the first matching regex or DEFAULT.
#
# You may specify a format string as part of the
# filter. The string is composed of a `%' followed
# by a single format character, or followed by a set of format
# characters surrounded by `{' and `}' as separators. The format
# characters are:
#
# s = file name
# V = old version number (pre-checkin)
# v = new version number (post-checkin)
#
# For example:
#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
# or
#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog

26
CVSROOT/modules

@ -0,0 +1,26 @@
# Three different line formats are valid:
# key -a aliases...
# key [options] directory
# key [options] directory files...
#
# Where "options" are composed of:
# -i prog Run "prog" on "cvs commit" from top-level of module.
# -o prog Run "prog" on "cvs checkout" of module.
# -e prog Run "prog" on "cvs export" of module.
# -t prog Run "prog" on "cvs rtag" of module.
# -u prog Run "prog" on "cvs update" of module.
# -d dir Place module in directory "dir" instead of module name.
# -l Top-level directory only -- do not recurse.
#
# NOTE: If you change any of the "Run" options above, you'll have to
# release and re-checkout any working directories of these modules.
#
# And "directory" is a path to a directory relative to $CVSROOT.
#
# The "-a" option specifies an alias. An alias is interpreted as if
# everything on the right of the "-a" had been typed on the command line.
#
# You can encode a module within a module by using the special '&'
# character to interpose another module into the current module. This
# can be useful for creating a module that consists of many directories
# spread out over the entire source repository.

12
CVSROOT/notify

@ -0,0 +1,12 @@
# The "notify" file controls where notifications from watches set by
# "cvs watch add" or "cvs edit" are sent. The first entry on a line is
# a regular expression which is tested against the directory that the
# change is being made to, relative to the $CVSROOT. If it matches,
# then the remainder of the line is a filter program that should contain
# one occurrence of %s for the user to notify, and information on its
# standard input.
#
# "ALL" or "DEFAULT" can be used in place of the regular expression.
#
# For example:
#ALL mail %s -s "CVS notification"

13
CVSROOT/rcsinfo

@ -0,0 +1,13 @@
# The "rcsinfo" file is used to control templates with which the editor
# is invoked on commit and import.
#
# The first entry on a line is a regular expression which is tested
# against the directory that the change is being made to, relative to the
# $CVSROOT. For the first match that is found, then the remainder of the
# line is the name of the file that contains the template.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name "ALL" appears as a regular expression it is always used
# in addition to the first matching regex or "DEFAULT".

20
CVSROOT/taginfo

@ -0,0 +1,20 @@
# The "taginfo" file is used to control pre-tag checks.
# The filter on the right is invoked with the following arguments:
#
# $1 -- tagname
# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d
# $3 -- repository
# $4-> file revision [file revision ...]
#
# A non-zero exit of the filter program will cause the tag to be aborted.
#
# The first entry on a line is a regular expression which is tested
# against the directory that the change is being committed to, relative
# to the $CVSROOT. For the first match that is found, then the remainder
# of the line is the name of the filter to run.
#
# If the repository name does not match any of the regular expressions in this
# file, the "DEFAULT" line is used, if it is specified.
#
# If the name "ALL" appears as a regular expression it is always used
# in addition to the first matching regex or "DEFAULT".

21
CVSROOT/verifymsg

@ -0,0 +1,21 @@
# The "verifymsg" file is used to allow verification of logging
# information. It works best when a template (as specified in the
# rcsinfo file) is provided for the logging procedure. Given a
# template with locations for, a bug-id number, a list of people who
# reviewed the code before it can be checked in, and an external
# process to catalog the differences that were code reviewed, the
# following test can be applied to the code:
#
# Making sure that the entered bug-id number is correct.
# Validating that the code that was reviewed is indeed the code being
# checked in (using the bug-id number or a seperate review
# number to identify this particular code set.).
#
# If any of the above test failed, then the commit would be aborted.
#
# Actions such as mailing a copy of the report to each reviewer are
# better handled by an entry in the loginfo file.
#
# One thing that should be noted is the the ALL keyword is not
# supported. There can be only one entry that matches a given
# repository.

149
k-meleon/macros2/functions.h

@ -255,8 +255,7 @@
Value _(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 1);
checkArgs(__FUNCTION__, data, 1);
return kFuncs->Translate(data->getstr(1)) ;
}
@ -537,7 +536,7 @@
Value alert(FunctionData* data)
{
checkArgs(__FUNCTION__, data, 2, 3);
checkArgs(__FUNCTION__, data, 1, 3);
int icon = 0;
MString type = data->getstr(3);
if(strcmpi(type,"EXCLAIM")==0) icon=MB_ICONEXCLAMATION;
@ -1408,78 +1407,84 @@
{
checkArgs(__FUNCTION__, data, 1);
MString name = data->getstr(1);
WindowVarType type;
/*if (name == "SelectedText") {
int l = kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_SelectedText, NULL);
if (l<1) return "";
wchar_t* buf = new wchar_t[l];
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_SelectedText, buf);
std::string ret = CUTF16_to_UTF8(buf);
delete [] buf;
return ret;
}*/
if (name == "VERSION") {
return kPlugin.kFuncs->GetKmeleonVersion();
}
if (name == "TextZoom") {
int zoom;
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_TextZoom, &zoom);
char buf[34];
_itoa(zoom, buf, 10);
return buf;
}
if (name == "WindowNumber")
{
int nb;
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_Number, &nb);
return nb;
}
if (name == "TabNumber")
{
int nb;
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_Tab_Number, &nb);
return nb;
}
if (name == "SelectedText")
type = Window_SelectedText;
else if (name == "URLBAR")
type = Window_UrlBar;
else if (name == "URL")
type = Window_URL;
else if (name == "TITLE")
type = Window_Title;
else if (name == "LinkURL")
type = Window_LinkURL;
else if (name == "ImageURL")
type = Window_ImageURL;
else if (name == "FrameURL")
type = Window_FrameURL;
else if (name == "CHARSET")
type = Window_Charset;
else if (name == "SEARCHURL")
type = Search_URL;
else if (name == "CommandLine")
return CT_to_UTF8(::GetCommandLine());
else if (name == "LANG")
type = Window_Lang;
else return "";
int l = kPlugin.kFuncs->GetWindowVar(data->c.hWnd, type, NULL);
MString name = data->getstr(1);
WindowVarType type;
/*if (name == "SelectedText") {
int l = kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_SelectedText, NULL);
if (l<1) return "";
char* buf = new char[l];
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, type, buf);
MString ret = buf;
wchar_t* buf = new wchar_t[l];
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_SelectedText, buf);
std::string ret = CUTF16_to_UTF8(buf);
delete [] buf;
return ret;
}*/
if (name == "VERSION") {
return kPlugin.kFuncs->GetKmeleonVersion();
}
if (name == "TextZoom") {
int zoom;
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_TextZoom, &zoom);
char buf[34];
_itoa(zoom, buf, 10);
return buf;
}
if (name == "WindowNumber")
{
int nb;
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_Number, &nb);
return nb;
}
if (name == "TabNumber")
{
int nb;
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, Window_Tab_Number, &nb);
return nb;
}
if (name == "SelectedText")
type = Window_SelectedText;
else if (name == "URLBAR")
type = Window_UrlBar;
else if (name == "URL")
type = Window_URL;
else if (name == "TITLE")
type = Window_Title;
else if (name == "LinkURL")
type = Window_LinkURL;
else if (name == "ImageURL")
type = Window_ImageURL;
else if (name == "FrameURL")
type = Window_FrameURL;
else if (name == "CHARSET")
type = Window_Charset;
else if (name == "SEARCHURL")
type = Search_URL;
else if (name == "CommandLine")
return CT_to_UTF8(::GetCommandLine());
else if (name == "LANG")
type = Window_Lang;
else return "";
int l = kPlugin.kFuncs->GetWindowVar(data->c.hWnd, type, NULL);
if (l<1) return "";
char* buf = new char[l];
kPlugin.kFuncs->GetWindowVar(data->c.hWnd, type, buf);
MString ret = buf;
delete [] buf;
return ret;
}
Value w(FunctionData* data)
{
return getwinvar(data);
}
Value setwinvar(FunctionData* data)
{
@ -1780,8 +1785,10 @@
return std::time(nullptr);
}
#define FUNCSYMBOL(X) "!"#X
#ifndef MACROSFUNC_ADD
#define MACROSFUNC_ADD(entry) m->AddSymbol(#entry, ValueFunc((MacroFunction)&entry));
#define MACROSFUNC_ADD(entry) m->AddSymbol(FUNCSYMBOL(entry), ValueFunc((MacroFunction)&entry));
#endif
void InitFunctions(Mac* m)

86
k-meleon/macros2/macros.cpp

@ -171,35 +171,6 @@ int bStartup = 1;
std::string sGlobalArg;
class Mac {
public:
TDS tds;
StatList root;
Value* AddSymbol(const std::string& name, const Value& v)
{
TDS::iterator it;
it = tds.insert(tds.end(), TDS::value_type(name, v));
return &it->second;
}
Value* FindSymbol(const std::string& name)
{
TDS::iterator it = tds.find(name);
if (it == tds.end())
return NULL;
return &it->second;
}
std::string FindSymbol(const Value* val)
{
for (TDS::iterator it = tds.begin(); it!= tds.end(); it++)
if (val == &it->second)
return it->first;
return "";
}
};
Mac *M;
#include "parser.h"
@ -278,8 +249,28 @@ public:
if (expr->v->md)
Evaluate(expr->v->md);
else
EvalError( "Call to the undefined macro.");
EvalError( "Call to an undefined macro.");
}
else if (expr->v->t == VALUE_UFUNCTION) {
if (expr->v->uf) {
// You don't want users to use the fact that currently
// everything is static
expr->v->uf->tds.emptyvar();
Expression* param = static_cast<Expression*>(expr->firstParam);
for (auto it = expr->v->uf->params.begin(); it != expr->v->uf->params.end(); it++) {
if (!param) break;
**it = EvalExpr(param);
param = static_cast<Expression*>(param->next);
}
Value v;
Evaluate(expr->v->uf, &v);
return v;
}
else
EvalError("Call to an undefined function.");
}
else
EvalError("Invalid macro or function call.");
return "";
@ -310,40 +301,52 @@ public:
case EXPR_MINUS: return -EvalExpr(expr->A);
case EXPR_CONCAT: return EvalExpr(expr->A).concat(EvalExpr(expr->B));
case EXPR_COND: if (EvalExpr(expr->A).boolval()) return EvalExpr(expr->B); else return EvalExpr(expr->C);
case EXPR_ASSIGN: *(((ExprValue*)expr->A)->v) = EvalExpr(expr->B); return *(((ExprValue*)expr->A)->v);
case EXPR_ASSIGN: ((ExprValue*)expr->A)->Set(EvalExpr(expr->B)); return *(((ExprValue*)expr->A)->Get());
case EXPR_CALL: return EvalCall(node);
case EXPR_VALUE:
if (!((ExprValue*)node)->v->isvalid())
EvalError(("The variable '" + M->FindSymbol(((ExprValue*)node)->v) + "' is used without being initialized").c_str());
return *(((ExprValue*)node)->v);
if (!((ExprValue*)node)->Get()->isvalid())
EvalError(("The variable '" + M->FindSymbol(((ExprValue*)node)->Get()) + "' is used without being initialized").c_str());
return *(((ExprValue*)node)->Get());
default: return 0;
}
}
void EvalStat(MacroNode* node)
bool EvalStat(MacroNode* node, Value* v = nullptr)
{
bool stop = false;
assert(ISSTAT(node));
Statement* stat = static_cast<Statement*>(node);
currentStat = stat;
switch (stat->st) {
case STAT_EXPR: EvalExpr(stat->A); break;
case STAT_WHILE: while (EvalExpr(stat->A).boolval()) if (stat->B) Evaluate(stat->B); break;
case STAT_IF: if (EvalExpr(stat->A).boolval()) {if (stat->B) Evaluate(stat->B);} else if (stat->C) Evaluate(stat->C);
case STAT_RETURN:
if (!v) {
EvalError("return outside a function");
break;
}
*v = EvalExpr(stat->A);
stop = true;
break;
case STAT_WHILE: while (EvalExpr(stat->A).boolval() && !stop) if (stat->B) stop = Evaluate(stat->B, v); break;
case STAT_IF: if (EvalExpr(stat->A).boolval()) {if (stat->B) stop = Evaluate(stat->B, v);} else if (stat->C) stop = Evaluate(stat->C, v);
}
currentStat = NULL;
return stop;
}
void Evaluate(MacroNode* node)
bool Evaluate(MacroNode* node, Value* v = nullptr)
{
assert(ISLIST(node));
StatList* snode = static_cast<StatList*>(node);
node = snode->child;
while (node) {
bool stop = false;
while (node && !stop) {
switch (node->t) {
case NODE_STAT: EvalStat(node); break;
case NODE_STAT:
stop = EvalStat(node, v);
break;
case NODE_MACRO:
Value* v = m->FindSymbol(static_cast<MacroDef*>(node)->name);
if (!v)
@ -353,6 +356,7 @@ public:
}
node = node->next;
}
return stop;
}
};

196
k-meleon/macros2/object.h

@ -1,5 +1,6 @@
#include <assert.h>
#include <map>
#include <vector>
#include "../strconv.h"
enum Type {
@ -7,7 +8,8 @@ enum Type {
VALUE_STRING,
VALUE_INT,
VALUE_MACRO,
VALUE_FUNCTION
VALUE_FUNCTION,
VALUE_UFUNCTION
};
typedef int MInt;
@ -22,6 +24,7 @@ public:
};
class MacroDef;
class FunctionDef;
class Value;
class MacroFile;
struct FunctionData;
@ -51,6 +54,7 @@ public:
union {
MInt i;
MacroDef* md;
FunctionDef* uf;
MacroFunction mf;
MString* str; // XXX
};
@ -74,6 +78,11 @@ public:
}
}
Value(FunctionDef* def) {
t = VALUE_UFUNCTION;
uf = def;
}
Value(MacroDef* def) {
t = VALUE_MACRO;
md = def;
@ -109,7 +118,7 @@ public:
str.assign(buf);*/
}
MInt intval() {
MInt intval() const {
switch (t) {
case VALUE_INT: return i;
case VALUE_STRING: return str->compare("true")==0?1:atoi(str->c_str());
@ -125,7 +134,7 @@ public:
}
}
*/
MString strval() {
MString strval() const {
switch (t) {
case VALUE_INT:{ char buf[34];_itoa(i, buf, 10); return buf;}
case VALUE_STRING: return *str;
@ -133,7 +142,7 @@ public:
}
}
MInt boolval() {
MInt boolval() const {
switch (t) {
case VALUE_INT: return i;
case VALUE_STRING:
@ -142,11 +151,11 @@ public:
}
}
bool isint() {return t == VALUE_INT;}
bool isstring() {return t == VALUE_STRING;}
bool ismacro() {return t == VALUE_MACRO;}
bool isfunction() {return t == VALUE_FUNCTION;}
bool isvalid() {return t!= VALUE_NONE;}
bool isint() const { return t == VALUE_INT; }
bool isstring() const{ return t == VALUE_STRING; }
bool ismacro() const { return t == VALUE_MACRO; }
bool isfunction() const { return t == VALUE_FUNCTION; }
bool isvalid() const { return t != VALUE_NONE; }
MInt operator +(Value& right ){ return intval() + right.intval(); }
MInt operator -(Value& right ){ return intval() - right.intval(); }
@ -199,7 +208,7 @@ public:
}
}
Value operator =(Value& right ){
Value operator =(const Value& right ){
if (right.t == VALUE_STRING) {
if (t == VALUE_STRING)
*str = *right.str;
@ -222,7 +231,7 @@ public:
}
}*/
Value operator =(MString& right ) {
Value operator =(const MString& right ) {
if (t!=VALUE_STRING) {
t = VALUE_STRING;
str = new MString(right);
@ -232,14 +241,14 @@ public:
return *this;
}
Value operator =(MInt right ) {
Value operator =(const MInt right) {
if (t == VALUE_STRING) delete str;
t = VALUE_INT;
i = right;
return i;
}
MString concat(Value& right ) {
MString concat(const Value& right) {
return strval() + right.strval();
}
@ -274,13 +283,46 @@ typedef Value ValueMacro;
typedef Value ValueStr;
typedef Value ValueInt;
typedef std::map<std::string, Value> TDS;
class TDS : public std::map < std::string, Value >
{
public:
void emptyvar()
{
for (TDS::iterator it = begin(); it != end(); it++)
it->second = Value();
}
Value* add(const std::string& name, const Value& v)
{
TDS::iterator it;
it = insert(end(), TDS::value_type(name, v));
return &it->second;
}
Value* find(const std::string& name)
{
TDS::iterator it = __super::find(name);
if (it == end())
return nullptr;
return &it->second;
}
std::string find(const Value* val)
{
for (TDS::iterator it = begin(); it != end(); it++)
if (val == &it->second)
return it->first;
return "";
}
};
typedef enum {
NODE_STATLIST,
NODE_STAT,
NODE_EXPR,
NODE_MACRO,
NODE_FUNCTION,
NODE_VALUE
} NodeType;
@ -289,7 +331,8 @@ typedef enum {
STAT_WHILE,
STAT_EXPR,
STAT_IF,
STAT_RETURN,
STAT_BREAK
} StatType;
typedef enum {
@ -318,7 +361,7 @@ typedef enum {
#define ISEXPR(node) (node->t == NODE_EXPR)
#define ISSTAT(node) (node->t == NODE_STAT)
#define ISLIST(node) (node->t == NODE_STATLIST ||node->t == NODE_MACRO)
#define ISLIST(node) (node->t == NODE_STATLIST || node->t == NODE_MACRO || node->t == NODE_FUNCTION)
/*
typedef struct Statement {
@ -360,7 +403,7 @@ public:
MacroNode() {
t = NODE_STATLIST;
next = NULL;
next = nullptr;
}
virtual ~MacroNode() {
@ -384,7 +427,7 @@ public:
MacroNode* child;
StatList() {
child = last = NULL;
child = last = nullptr;
t = NODE_STATLIST;
}
@ -419,16 +462,29 @@ public:
};
class ExprValue : public Expression {
public:
protected:
Value* v;
public:
ExprValue() : Expression() {
v = NULL;
v = nullptr;
et = EXPR_VALUE;
}
virtual ~ExprValue() {
}
const Value* Get() {
return v;
}
void Set(Value* av) {
v = av;
}
void Set(const Value& av) {
assert(v);
*v = av;
}
};
class ExprCall : public Expression {
@ -440,9 +496,9 @@ public:
Expression* firstParam;
ExprCall() : Expression() {
v = NULL;
v = nullptr;
et = EXPR_CALL;
firstParam = lastParam = NULL;
firstParam = lastParam = nullptr;
}
void AddParam(Expression* p) {
@ -475,49 +531,37 @@ public:
Expr(ExprType type) : Expression() {
et = type;
A = B = C = NULL;
A = B = C = nullptr;
}
Expr(ExprType type, Expression* l) : Expression() {
et = type;
A = l;
B = NULL;
C = NULL;
B = nullptr;
C = nullptr;
}
Expr(ExprType type, Expression* l, Expression* r) : Expression() {
et = type;
A = l;
B = r;
C = NULL;
C = nullptr;
}
};
class MacroFile {
class FunctionDef : public StatList {
public:
std::string name;
std::string desc;
std::string file;
std::wstring wfile;
bool user;
bool loaded;
bool trusted;
MacroFile(wchar_t* afile) {
wfile = afile;
file = CUTF16_to_UTF8(afile);
CharLowerBuff(afile, wcslen(afile));
wchar_t* ext = wcsrchr(afile, L'.');
if (ext) *ext = 0;
wchar_t* pos = wcsrchr(afile, L'\\');
name = (const char*)CT_to_UTF8(pos?pos+1:afile);
*ext = L'.';
std::vector<Value*> params;
MacroFile* mf;
TDS tds;
user = false;
loaded = false;
trusted = false;
FunctionDef(MacroFile* amf) : StatList() {
t = NODE_FUNCTION;
mf = amf;
}
virtual ~FunctionDef() {}
};
class MacroDef : public StatList {
@ -556,7 +600,7 @@ public:
Statement(StatType type) : MacroNode() {
st = type;
t = NODE_STAT;
A = B = C = next = NULL;
A = B = C = next = nullptr;
}
virtual int getLine() { return -1;}
@ -570,6 +614,60 @@ public:
}
};
class Mac {
public:
TDS tds;
StatList root;
Value* AddSymbol(const std::string& name, const Value& v)
{
TDS::iterator it;
it = tds.insert(tds.end(), TDS::value_type(name, v));
return &it->second;
}
Value* FindSymbol(const std::string& name)
{
return tds.find(name);
}
std::string FindSymbol(const Value* val)
{
for (TDS::iterator it = tds.begin(); it != tds.end(); it++)
if (val == &it->second)
return it->first;
return "";
}
};
class MacroFile {
public:
std::string name;
std::string desc;
std::string file;
std::wstring wfile;
bool user;
bool loaded;
bool trusted;
Mac m;
MacroFile(wchar_t* afile) {
wfile = afile;
file = CUTF16_to_UTF8(afile);
CharLowerBuff(afile, wcslen(afile));
wchar_t* ext = wcsrchr(afile, L'.');
if (ext) *ext = 0;
wchar_t* pos = wcsrchr(afile, L'\\');
name = (const char*)CT_to_UTF8(pos ? pos + 1 : afile);
*ext = L'.';
user = false;
loaded = false;
trusted = false;
}
};
class DebugStatement : public Statement {
int mLine;
MacroFile* mMf;

197
k-meleon/macros2/parser.h

@ -1,6 +1,4 @@
/*
macros --> stmtlist | macrodef
macrodef --> name { stmtlist }
stmtlist --> stmt; {| stmlist}
@ -20,7 +18,7 @@ stmt --> var = expr | macrodef |
macros --> tata {tata}
tata --> stmtlist | macrodef
stmtlist --> stmt; {stmtlist}
*/
*/
#include <ctype.h>
#include <string.h>
@ -29,69 +27,7 @@ stmtlist --> stmt; {stmtlist}
#include <assert.h>
#include <sys/stat.h>
typedef enum {
OP_MOVE,
OP_ADD,
OP_SUB,
OP_MULT,
OP_DIV,
OP_REM,
OP_CONCAT,
OP_EQ,
OP_NEQ,
OP_GT,
OP_LT,
OP_GE,
OP_LE,
OP_NOT,
OP_JMP,
OP_TEST,
OP_CALL,
OP_PUSH,
OP_POP
} OpCode;
typedef struct Instruction {
OpCode opcode;
long A;
long B;
long C;
} Instruction;
typedef struct Program {
Instruction* inst;
int size;
int nbinstr;
Program() {
inst = new Instruction[5];
size = 5;
nbinstr = 0;
}
~Program() {
if (inst) delete inst;
}
Instruction* AddInstr() {
if (!inst) return NULL;
if (nbinstr == size) {
Instruction* newset = new Instruction[size+5];
if (newset) {
memcpy(newset, inst, sizeof(Instruction)*size);
size += 5;
Instruction* oldinst = inst;
inst = newset;
delete oldinst;
}
}
return &inst[nbinstr++];
}
} Program;
static char* reservedwords[] = { "while", "if", "else", "and", "or", "not", "menu", "menuchecked", "menugrayed", "macroinfo", "buttonchecked" };
static char* reservedwords[] = { "while", "if", "else", "and", "or", "not", "menu", "menuchecked", "menugrayed", "macroinfo", "buttonchecked", "null", "function", "return", "const", "break" };
#define MAXRESERVED sizeof(reservedwords) / sizeof(char*)
static char* windowvars[] = { "URL", "URLBAR", "SelectedText", "FrameURL", "LinkURL", "ImageURL", "CHARSET", "TextZoom", "TITLE", "WindowNumber", "TabNumber", "CommandLine", "SEARCHURL", "LANG", "VERSION" };
@ -111,6 +47,11 @@ enum TOKEN {
TK_MENUGRAY,
TK_MACROINFO,
TK_BUTTONCHECK,
TK_NULL,
TK_FUNCTION,
TK_RETURN,
TK_CONST,
TK_BREAK,
TK_EQ,
@ -540,8 +481,9 @@ public:
char *input;
MacroDef* currentMd; //XXX
bool debug;
TDS* ltds;
Parser() { input = NULL; currentMd = NULL; m = NULL; }
Parser() { input = nullptr; currentMd = nullptr; m = nullptr; ltds = nullptr; }
~Parser() { if (input) delete [] input; }
bool init(Mac* mac, MacroFile &srcFile, bool enableDebug = false) {
@ -667,7 +609,7 @@ public:
case TK_NAME:
if (lex.lookahead() != TK_OPEN) {
e = (Expression*)new ExprValue();
((ExprValue*)e)->v = m->AddSymbol(std::string("##") + lex.data.strval(), Value(lex.data));
((ExprValue*)e)->Set(m->AddSymbol(std::string("##") + lex.data.strval(), Value(lex.data)));
}
else {
return callfunc();
@ -683,11 +625,11 @@ public:
for (int i=0; i<MAXWINDOWVARS; i++)
if (strcmp(lex.data.strval(), windowvars[i]) == 0) {
ExprCall* ec = new ExprCall();
ec->v = m->FindSymbol("getwinvar");
ec->v = m->FindSymbol("!getwinvar");
assert(ec->v);
ExprValue* ename = new ExprValue();
ename->v = m->AddSymbol(std::string("##") + lex.data.strval(), lex.data.strval());
ename->Set(m->AddSymbol(std::string("##") + lex.data.strval(), lex.data.strval()));
ec->AddParam(ename);
lex.nexttoken();
@ -695,26 +637,35 @@ public:
return ec;
}
e = (Expression*)new ExprValue();
Value* v = m->FindSymbol(std::string("$") + lex.data.strval());
if (!v) v = m->AddSymbol(std::string("$") + lex.data.strval(), Value());
((ExprValue*)e)->v = v; lex.nexttoken();
break;
e = (Expression*)new ExprValue();
std::string name = std::string("$") + lex.data.strval();
Value* v = ltds ? ltds->find(name) : nullptr;
if (!v) v = m->FindSymbol(name);
if (!v) ltds ? v = ltds->add(name, Value()) : v = m->AddSymbol(name, Value());
((ExprValue*)e)->Set(v);
lex.nexttoken();
break;
}
case TK_NUMBER:
e = (Expression*)new ExprValue();
((ExprValue*)e)->v = m->AddSymbol(std::string("%%") + lex.data.strval(), lex.data.intval());
((ExprValue*)e)->Set(m->AddSymbol(std::string("%%") + lex.data.strval(), lex.data.intval()));
break;
case TK_STRING:
e = (Expression*)new ExprValue();
((ExprValue*)e)->v = m->AddSymbol(std::string("##") + lex.data.strval(), lex.data.strval());
((ExprValue*)e)->Set(m->AddSymbol(std::string("##") + lex.data.strval(), lex.data.strval()));
break;
case TK_MACRO:
return macrocall();
case TK_NULL:
e = (Expression*)new ExprValue();
((ExprValue*)e)->Set(m->AddSymbol(std::string("#NULL"), Value()));
break;
default :
error("Invalid expression.", lex.token);
while (lex.token != TK_NONE && lex.token != TK_SEP)
@ -789,11 +740,11 @@ public:
for (int i=0; i<MAXWINDOWVARS; i++)
if (stricmp(varname.c_str(), windowvars[i]) == 0) {
ExprCall* e = new ExprCall();
e->v = m->FindSymbol("setwinvar");
e->v = m->FindSymbol("!setwinvar");
assert(e->v);
ExprValue* ename = new ExprValue();
ename->v = m->AddSymbol(std::string("##") + varname, varname);
ename->Set(m->AddSymbol(std::string("##") + varname, varname));
e->AddParam(ename);
e->AddParam(evalexpr());
return e;
@ -801,19 +752,19 @@ public:
varname = std::string("$") + varname;
Value* v = m->FindSymbol(varname);
Value* v = ltds ? ltds->find(varname) : nullptr;
if (!v) v = m->FindSymbol(varname);
if (v && (v->ismacro() || v->isfunction())) {
error(("Symbol '"+ varname +"' already defined as a macro or function.").c_str());
error(("Symbol '" + varname + "' already defined as a macro or function.").c_str());
return NULL;
}
if (!v) v = ltds ? ltds->add(varname, Value()) : m->AddSymbol(varname, Value());
Expr* e = new Expr(EXPR_ASSIGN);
e->B = evalexpr();
e->B = evalexpr();
e->A = new ExprValue();
if (!v) v = m->AddSymbol(varname, Value());
((ExprValue*)e->A)->v = v;
((ExprValue*)e->A)->Set(v);
return e;
}
@ -839,15 +790,15 @@ public:
return NULL;
ExprCall* e = new ExprCall();
e->v = m->FindSymbol(funcname);
e->v = m->FindSymbol("!"+funcname);
if (!e->v) error(("Function " + funcname + " is not defined.").c_str());
while (lex.token != TK_NONE && lex.token != TK_CLOSE) {
e->AddParam(evalexpr());
if (lex.token != TK_COMMA )
if (lex.token != TK_COMMA)
break;
lex.nexttoken();
}
}
skip(TK_CLOSE);
return (Expression*)e;
@ -873,23 +824,67 @@ public:
skip(TK_NAME);
skip(TK_BEGIN);
MacroDef* md = new MacroDef(mf);
currentMd = md;
md->name = macroname;
Value* v = m->FindSymbol(macroname);
if (v && !v->ismacro()) {
error(("Symbol '" + macroname + "' already defined.").c_str());
return NULL;
}
MacroDef* md = new MacroDef(mf);
md->name = macroname;
m->AddSymbol(macroname, ValueMacro(md));
currentMd = md;
TDS* old = ltds;
ltds = nullptr;
stmtlist(static_cast<StatList*>(md));
currentMd = NULL;
ltds = old;
skip(TK_END);
return md;
}
FunctionDef* functiondef() {
skip(TK_FUNCTION);
std::string funcname = lex.data.strval();
std::string symbolname = "!" + funcname;
skip(TK_NAME);
Value* v = m->FindSymbol(symbolname);
if (v) {
error(("Function '" + symbolname + "' already defined.").c_str());
return NULL;
}
skip(TK_OPEN);
FunctionDef* fd = new FunctionDef(mf);
fd->name = funcname;
m->AddSymbol(symbolname, ValueFunc(fd));
while (lex.token != TK_NONE && lex.token != TK_CLOSE) {
skip(TK_VAR);
skip(TK_NAME);
fd->params.push_back(fd->tds.add("$" + lex.data.strval(), Value()));
if (lex.token != TK_COMMA)
break;
lex.nexttoken();
}
fd->params.shrink_to_fit();
skip(TK_CLOSE);
skip(TK_BEGIN);
TDS* old = ltds;
ltds = &fd->tds;
stmtlist(static_cast<StatList*>(fd));
ltds = old;
skip(TK_END);
return fd;
}
Statement* whilestat() {
Statement* s = newStatement(STAT_WHILE);
skip(TK_WHILE);
@ -934,6 +929,14 @@ public:
r