From f30729980e6f2c0e7be430b5af3cc8b878984588 Mon Sep 17 00:00:00 2001 From: llsth Date: Thu, 9 Apr 2015 14:42:16 +0200 Subject: [PATCH] Alias in function help --- Makefile.vcxproj | 3 +- Makefile.vcxproj.filters | 5 ++- app/localize/ialias.h | 67 +++++++++++++++++++++++++++++++++++ app/system/language.cpp | 13 +++++++ app/system/language.h | 1 + app/system/language_amiga.cpp | 4 ++- 6 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 app/localize/ialias.h diff --git a/Makefile.vcxproj b/Makefile.vcxproj index f7512742..a3bfb4c5 100644 --- a/Makefile.vcxproj +++ b/Makefile.vcxproj @@ -143,6 +143,7 @@ + @@ -268,4 +269,4 @@ - \ No newline at end of file + diff --git a/Makefile.vcxproj.filters b/Makefile.vcxproj.filters index f3f5d845..3149134a 100644 --- a/Makefile.vcxproj.filters +++ b/Makefile.vcxproj.filters @@ -428,6 +428,9 @@ app\localize + + app\localize + app\localize @@ -594,4 +597,4 @@ lib\real - \ No newline at end of file + diff --git a/app/localize/ialias.h b/app/localize/ialias.h new file mode 100644 index 00000000..ad6e783c --- /dev/null +++ b/app/localize/ialias.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015 Carsten Larsen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef AMATH_TEXT_IDENT_ALIAS_H +#define AMATH_TEXT_IDENT_ALIAS_H + +struct identalias { + const char *ident; + const char *alias; +}; + +static const identalias identaliases[] = { + { "sqrt", "sqr" }, + { "cbrt", "cbr" }, + { "log2", "lb" }, + { "log", "lg" }, + { "log10", "lg" }, + { "arsin", "asin" }, + { "arcos", "acos" }, + { "artan", "atan" }, + { "arcot", "acot" }, + { "arsec", "asec" }, + { "arcsc", "acsc" }, + { "arcsin", "asin" }, + { "arccos", "acos" }, + { "arctan", "atan" }, + { "arccot", "acot" }, + { "arcsec", "asec" }, + { "arccsc", "acsc" }, + { "arsinh", "asinh" }, + { "arcosh", "acosh" }, + { "artanh", "atanh" }, + { "arcoth", "acoth" }, + { "arsech", "asech" }, + { "arcsch", "acsch" }, + { "arcsinh", "asinh" }, + { "arccosh", "acosh" }, + { "arctanh", "atanh" }, + { "arccoth", "acoth" }, + { "arcsech", "asech" }, + { "arccsch", "acsch" } +} + +#endif diff --git a/app/system/language.cpp b/app/system/language.cpp index d792d364..488eef90 100644 --- a/app/system/language.cpp +++ b/app/system/language.cpp @@ -26,6 +26,7 @@ #include "clib.h" #include "localize/tags.h" +#include "localize/ialias.h" #include "system/language.h" Language::Language() @@ -40,6 +41,18 @@ Language::~Language() } } +char* Language::FindAlias(const char* ident) +{ + static const unsigned int count = sizeof(identaliases) / sizeof(identalias); + for (unsigned int i = 0; i < count; i++) { + if (StrIsEqual(identaliases[i].ident == ident)) { + return (char*)identaliases[i].alias; + } + } + + return (char*)ident; +} + char* Language::UntagText(const char* text) { if (lastText != NOMEM) { diff --git a/app/system/language.h b/app/system/language.h index 8798bc4e..92be18bf 100644 --- a/app/system/language.h +++ b/app/system/language.h @@ -48,6 +48,7 @@ public: virtual bool StrIsEqualLoc(const char *s1, const char *s2) = 0; protected: + char* FindAlias(const char *ident); char* UntagText(const char *text); char* lastText; }; diff --git a/app/system/language_amiga.cpp b/app/system/language_amiga.cpp index 9af5fb52..c6704054 100644 --- a/app/system/language_amiga.cpp +++ b/app/system/language_amiga.cpp @@ -86,10 +86,12 @@ char* AmigaLanguage::GetText(int id) char* AmigaLanguage::GetHelpText(char* ident) { + char *s = FindAlias(ident); + identhelpdef *def = NOMEM; static const unsigned int count = sizeof(identtexts) / sizeof(identhelpdef); for (unsigned int i = 0; i < count; i++) { - if (StrIsEqual(identtexts[i].ident, ident)) { + if (StrIsEqual(identtexts[i].ident, s)) { def = (identhelpdef*)&identtexts[i]; break; }