amath  1.8.5
Simple command line calculator
help.cpp
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2014-2018 Carsten Sonne Larsen <cs@innolan.net>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * Project homepage:
26  * https://amath.innolan.net
27  *
28  */
29 
30 #include "help.h"
31 #include "amath.h"
32 #include "amathc.h"
33 #include "loc/help.h"
34 #include "loc/text.h"
35 #include "system/program.h"
36 
39 {
40  argument = static_cast<Symbol>(0);
41  ident = nullptr;
42 }
43 
44 HelpStatement::HelpStatement(Symbol argument) :
45  StatementNode(), argument(argument)
46 {
47  ident = nullptr;
48 }
49 
50 HelpStatement::HelpStatement(const char* ident)
51 {
53  AllocAndCopy(&this->ident, ident);
54 }
55 
57 {
58  if (ident != nullptr)
59  {
60  delete [] ident;
61  }
62 }
63 
65 {
66  if (argument == symstatement)
67  {
68  return StatementHelp();
69  }
70  else if (argument == symident)
71  {
72  char* text = Program->Language->GetHelpText(ident);
74  return output->GetString();
75  }
76 
77  char* text = Program->Language->GetHelpText(argument);
79  return output->GetString();
80 }
81 
82 #define APPENDHELP(x)
83  text = x;
84  output->EnsureGrowth(StrLen(text));
85  output->Append(text);
86 
88 {
89  char* text;
91 
94 #if defined(AMIGA) || defined(TERMIOS) || defined(WINDOWS)
96 #endif
106 #if defined(UNIX) || defined(HAIKU) || defined(AMIGA)
108 #endif
119 
120  return output->GetString();
121 }
#define TERMIOS
Definition: amath.h:89
#define STATEMENTINPUT
Definition: text.h:57
#define STATEMENTFUNCS
Definition: text.h:56
#define STATEMENTVERSION
Definition: text.h:65
char * ident
Definition: help.h:52
Logic related to the help statement.
Definition: help.h:39
char * GetString() const
Definition: charbuf.cpp:306
HelpStatement(const char *ident)
Definition: help.cpp:50
Base class for all statements in a syntax tree.
Definition: node.h:40
#define STATEMENTLICENSE
Definition: text.h:66
#define STATEMENTSAVE
Definition: text.h:63
~HelpStatement()
Definition: help.cpp:56
#define STATEMENTDEF
Definition: text.h:51
#define STATEMENTVARS
Definition: text.h:64
char * GetHelpText(Symbol symbol)
Definition: language.cpp:177
#define STATEMENTABOUT
Definition: text.h:49
char * Execute()
Definition: help.cpp:64
void ClearBuffer()
Release memory in buffer.
Definition: charbuf.cpp:65
#define STATEMENTLINE
Definition: text.h:48
#define STATEMENTMEMORY
Definition: text.h:67
HelpStatement(Symbol argument)
Definition: help.cpp:44
#define STATEMENTDELETE
Definition: text.h:52
#define STATEMENTDIGITS
Definition: text.h:53
#define STATEMENTSHOW
Definition: text.h:61
#define STATEMENTOUTPUT
Definition: text.h:59
#define STATEMENTHELP
Definition: text.h:58
#define STATEMENTEXIT
Definition: text.h:68
char * StatementHelp() const
Definition: help.cpp:87
Symbol argument
Definition: help.h:51
StatementNode()
Definition: node.cpp:34
#define STATEMENTLOAD
Definition: text.h:62
#define STATEMENTFOOTER
Definition: text.h:69
#define STATEMENTLIST
Definition: text.h:60
#define STATEMENTEXECUTE
Definition: text.h:55
char * GetHelpText(char *ident)
Definition: language.cpp:154
#define APPENDHELP(x)
Definition: help.cpp:82
CharBuffer * output
Definition: nodes.h:85
HelpStatement()
Definition: help.cpp:37
void ClearAndCopy(const char *source)
Release memory, allocate and copy source.
Definition: charbuf.cpp:81
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
#define STATEMENTCLEAR
Definition: text.h:50
#define STATEMENTEVAL
Definition: text.h:54