add menu output for reference searches

changed command:

  docfind <pattern> <silent>

    Searches for pattern in all reference entries. If <silent> is zero or
    omitted, all found references are listed.

    A table of all found entries is returned as result. For each entry,
    the index of the doc entry string that contains the pattern is listed.

new command:

  getdoc <ref> <idx>

    Returns a string of the doc entry specified by <ref>. String index
    numbers match with the result of docfind.

      0   name
      1   description
      2-  remarks

DOCREF docfind getdoc
This commit is contained in:
ac-stef
2017-04-24 19:51:40 +02:00
parent 78380dc45d
commit 066c820231
2 changed files with 60 additions and 17 deletions
+16 -7
View File
@@ -99,15 +99,24 @@ newmenu help
menuitem "AssaultCube reference" [ showmenu reference ]
menuitem "Search the reference" [ showmenu [Reference search] ]
// menuitem "Keyboard controls" [ showmenu controls ] // This was never implemented or something? - Bukz
menuitem "View the FAQ" [ load_faq ; showmenu faq ]
menuitem "" -1
menuitem "...for further information/help see the README" [ echo "\f2The readme can be found in the base AssaultCube directory."]
menuitem "Keyboard controls" [ showmenu Keyboard ]
menuitem "View the FAQ\t\t\t\t\t\t" [ load_faq ; showmenu faq ]
menuheader "" "...for further information/help see the README.\n\f4The readme can be found in the base AssaultCube directory."
tempalias __docsearchstring ""
newmenu [Reference search]
menuinit [ docsearchstring = [] ]
menuitemtextinput "Search reference for: " [] [ docsearchstring = $arg1 ]
menuitem "\f2\t \t [ Search ]\t\t\t" [ docfind $docsearchstring ]
menuitemtextinput "Search reference for: " "result $__docsearchstring" [ __docsearchstring = $arg1 ; showmenu [Reference search results] ]
newmenu [Reference search results]
menuinit [
resetcurmenu
if (strlen $__docsearchstring) [
menuheader "" (concatword "search results for keyword \f2" $__docsearchstring)
looplist (docfind $__docsearchstring 1) [n l] [
menuitem (concatword "\fs\f1" $n "\fr \t" (getdoc $n 1)) (concatword "saycommand /" $n)
]
] closecurmenu
]
// Show quit dialog if enabled
newmenu quit
+44 -10
View File
@@ -218,27 +218,61 @@ void docinvalid()
}
COMMAND(docinvalid, "");
void docfind(char *search)
void docfind(char *search, int *silent)
{
enumerate(docidents, docident, i,
vector<char> res;
vector<const char *> inames;
enumerate(docidents, docident, i, inames.add(i.name));
inames.sort(stringsort);
loopvj(inames)
{
docident &i = *docidents.access(inames[j]);
vector<char *> srch;
srch.add(i.name);
srch.add(i.desc);
srch.add(i.name); // 0
srch.add(i.desc); // 1
loopvk(i.remarks) srch.add(i.remarks[k]);
char *r;
int rline;
if((r = cvecstr(srch, search, &rline)))
{
const int matchchars = 200;
string match;
copystring(match, r-srch[rline] > matchchars/2 ? r-matchchars/2 : srch[rline], matchchars/2);
conoutf("%-20s%s", i.name, match);
cvecprintf(res, "%s %d\n", escapestring(i.name, false), rline);
if(!rline) r = srch[(rline = 1)];
if(!*silent)
{
const int showchars = 100;
string match;
int pos = r - srch[rline];
copystring(match, srch[rline] + (pos < showchars - 10 ? 0 : pos - 10), showchars);
conoutf("%-20s%s", i.name, match);
}
}
});
}
if(res.length()) res.last() = '\0';
else res.add('\0');
result(res.getbuf());
}
COMMAND(docfind, "s");
COMMAND(docfind, "si");
void getdoc(char *name, int *line)
{
const char *res = "";
docident *d = docidents.access(name);
if(d)
{
switch(*line)
{
case 0: res = d->name; break;
case 1: res = d->desc; break;
default:
if(d->remarks.inrange(*line - 2)) res = d->remarks[*line - 2];
break;
}
}
else conoutf("\f3getdoc: \"%s\" not found", name);
result(res);
}
COMMAND(getdoc, "si");
char *xmlstringenc(char *d, const char *s, size_t len)
{