amath  1.8.5
Simple command line calculator
StandardLanguage Class Reference

#include <language_stdc.h>

Inheritance diagram for StandardLanguage:
Collaboration diagram for StandardLanguage:

Public Member Functions

 StandardLanguage ()
 
 ~StandardLanguage ()
 
char GetFractionPoint ()
 
bool CharIsAlNum (unsigned long character)
 
bool CharIsAlpha (unsigned long character)
 
bool CharIsDigit (unsigned long character)
 
bool CharIsPunct (unsigned long character)
 
bool CharIsSpace (unsigned long character)
 
bool CharIsCntrl (unsigned long character)
 
bool StrIsEqualLoc (const char *s1, const char *s2)
 
bool Validate (char c)
 
- Public Member Functions inherited from Language
 Language ()
 
virtual ~Language ()
 
char * GetText (int id)
 
char * GetHelpText (char *ident)
 
char * GetHelpText (Symbol symbol)
 
Symbol FindKeyword (const char *ident) const
 
virtual bool CharIsQuote (unsigned long character)
 
virtual bool CharIsBlank (unsigned long character)
 
virtual bool CharIsNewLine (unsigned long character)
 
virtual bool CharIsOperator (unsigned long character)
 
void SetAnsiMode (bool value)
 
- Public Member Functions inherited from CharValidator
virtual ~CharValidator ()
 

Protected Member Functions

char * Translate (textdef *def)
 
char * Translate (helptextdef *def)
 
char * Translate (identhelpdef *def)
 

Private Member Functions

void LoadCatalogs ()
 
void LoadCatalog (char **dest, const char *file)
 
void GetNextPair (const char **key, const char **value)
 
void GetNextLine ()
 
void SkipComments ()
 

Private Attributes

char * textbase
 
char * helpbase
 
char * identbase
 
char * kwordbase
 
char * ptr
 
textdeftextcatalog
 
helptextdefhelpcatalog
 
identhelpdefidentcatalog
 

Additional Inherited Members

- Protected Attributes inherited from Language
keyworddefkeywordsloc
 
unsigned int keywordcount
 
unsigned int textcount
 
unsigned int identcount
 
unsigned int helpcount
 
unsigned int aliascount
 

Detailed Description

Definition at line 41 of file language_stdc.h.

Constructor & Destructor Documentation

◆ StandardLanguage()

StandardLanguage::StandardLanguage ( )

Definition at line 43 of file language_stdc.cpp.

References Language::Language(), and LoadCatalogs().

Referenced by Program::Program().

43  :
44  Language()
45 {
46  LoadCatalogs();
47 }
Language()
Definition: language.cpp:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~StandardLanguage()

StandardLanguage::~StandardLanguage ( )

Definition at line 49 of file language_stdc.cpp.

References helpbase, identbase, kwordbase, and textbase.

50 {
51  if (textbase != nullptr)
52  {
53  delete textbase;
54  }
55 
56  if (helpbase != nullptr)
57  {
58  delete helpbase;
59  }
60 
61  if (identbase != nullptr)
62  {
63  delete identbase;
64  }
65 
66  if (kwordbase != nullptr)
67  {
68  delete kwordbase;
69  }
70 }

Member Function Documentation

◆ CharIsAlNum()

bool StandardLanguage::CharIsAlNum ( unsigned long  character)
virtual

Implements Language.

Definition at line 101 of file language_stdc.cpp.

102 {
103  return (character >= 'a' && character <= 'z') ||
104  (character >= 'A' && character <= 'Z') ||
105  (character >= '0' && character <= '9');
106 }

◆ CharIsAlpha()

bool StandardLanguage::CharIsAlpha ( unsigned long  character)
virtual

Implements Language.

Definition at line 108 of file language_stdc.cpp.

109 {
110  return (character >= 'a' && character <= 'z') ||
111  (character >= 'A' && character <= 'Z');
112 }

◆ CharIsCntrl()

bool StandardLanguage::CharIsCntrl ( unsigned long  character)
virtual

Implements Language.

Definition at line 129 of file language_stdc.cpp.

130 {
131  return (character < 32 || character > 125);
132 }

◆ CharIsDigit()

bool StandardLanguage::CharIsDigit ( unsigned long  character)
virtual

Implements Language.

Definition at line 114 of file language_stdc.cpp.

115 {
116  return (character >= '0' && character <= '9');
117 }

◆ CharIsPunct()

bool StandardLanguage::CharIsPunct ( unsigned long  character)
virtual

Implements Language.

Definition at line 119 of file language_stdc.cpp.

120 {
121  return (character == '.');
122 }

◆ CharIsSpace()

bool StandardLanguage::CharIsSpace ( unsigned long  character)
virtual

Implements Language.

Definition at line 124 of file language_stdc.cpp.

125 {
126  return (character == 32);
127 }

◆ GetFractionPoint()

char StandardLanguage::GetFractionPoint ( )
virtual

Implements Language.

Definition at line 96 of file language_stdc.cpp.

97 {
98  return '.';
99 }

◆ GetNextLine()

void StandardLanguage::GetNextLine ( )
private

Definition at line 225 of file language_stdc.cpp.

References ptr.

Referenced by GetNextPair(), and SkipComments().

226 {
227  while ((*ptr) != '\0' && (*ptr) != '\n')
228  {
229  ptr++;
230  }
231 
232  if ((*ptr) == '\n')
233  {
234  *ptr++ = '\0';
235  }
236 }
Here is the caller graph for this function:

◆ GetNextPair()

void StandardLanguage::GetNextPair ( const char **  key,
const char **  value 
)
private

Definition at line 215 of file language_stdc.cpp.

References GetNextLine(), ptr, and SkipComments().

216 {
217  SkipComments();
218  *key = ptr;
219  GetNextLine();
220  SkipComments();
221  *value = ptr;
222  GetNextLine();
223 }
Here is the call graph for this function:

◆ LoadCatalog()

void StandardLanguage::LoadCatalog ( char **  dest,
const char *  file 
)
private

Definition at line 196 of file language_stdc.cpp.

References AllocAndCopy(), CharBuffer::GetString(), FilesystemBase::LoadTextFile(), and ptr.

197 {
198  FilesystemBase* filesystem = new StandardFilesystem();
199  CharBuffer* cbuf = filesystem->LoadTextFile(file);
200 
201  if (cbuf != nullptr)
202  {
203  AllocAndCopy(dest, cbuf->GetString());
204  ptr = *dest;
205  delete cbuf;
206  }
207  else
208  {
209  *dest = nullptr;
210  }
211 
212  delete filesystem;
213 }
char * GetString() const
Definition: charbuf.cpp:306
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
virtual CharBuffer * LoadTextFile(const char *name)=0
Abstract base class encapsulating file system calls.
Definition: filesystem.h:45
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
Here is the call graph for this function:

◆ LoadCatalogs()

void StandardLanguage::LoadCatalogs ( )
private

Definition at line 144 of file language_stdc.cpp.

Referenced by StandardLanguage().

145 {
146  /* Just use english for now
147 
148  const char* key;
149  const char* value;
150 
151  LoadCatalog(&textbase, "utext/dk-text.dict");
152  if (textbase != nullptr) {
153  textcatalog = new textdef[textcount];
154  for (unsigned int j = 0; j < textcount; j++) {
155  GetNextPair(&key, &value);
156  textcatalog[j].id = j;
157  textcatalog[j].text = value;
158  }
159  }
160 
161  LoadCatalog(&helpbase, "utext/dk-help.dict");
162  if (helpbase != nullptr) {
163  helpcatalog = new helptextdef[helpcount];
164  for (unsigned int j = 0; j < helpcount; j++) {
165  GetNextPair(&key, &value);
166  helpcatalog[j].id = j;
167  helpcatalog[j].symbol = helptexts[j].symbol;
168  helpcatalog[j].text = value;
169  }
170  }
171 
172  LoadCatalog(&identbase, "utext/dk-ident.dict");
173  if (identbase != nullptr) {
174  identcatalog = new identhelpdef[identcount];
175  for (unsigned int j = 0; j < identcount; j++) {
176  GetNextPair(&key, &value);
177  identcatalog[j].id = j;
178  identcatalog[j].ident = key;
179  identcatalog[j].text = value;
180  }
181  }
182 
183  LoadCatalog(&kwordbase, "utext/dk-keyword.dict");
184  if (kwordbase != nullptr) {
185  keywordsloc = new keyworddef[keywordcount];
186  for (unsigned int j = 0; j < keywordcount; j++) {
187  GetNextPair(&key, &value);
188  keywordsloc[j].id = j;
189  keywordsloc[j].name = value;
190  keywordsloc[j].symbol = keywords[j].symbol;
191  }
192  }
193  */
194 }
Here is the caller graph for this function:

◆ SkipComments()

void StandardLanguage::SkipComments ( )
private

Definition at line 238 of file language_stdc.cpp.

References GetNextLine(), and ptr.

Referenced by GetNextPair().

239 {
240  bool skipping;
241  do
242  {
243  if ((*ptr) == ';')
244  {
245  GetNextLine();
246  skipping = true;
247  }
248  else if ((*ptr) == '#' && *(ptr + sizeof(char)) == '#')
249  {
250  GetNextLine();
251  skipping = true;
252  }
253  else
254  {
255  skipping = false;
256  }
257  }
258  while (skipping);
259 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ StrIsEqualLoc()

bool StandardLanguage::StrIsEqualLoc ( const char *  s1,
const char *  s2 
)
virtual

Implements Language.

Definition at line 134 of file language_stdc.cpp.

References StrIsEqual().

135 {
136  return StrIsEqual(s1, s2);
137 }
bool StrIsEqual(const char *s1, const char *s2)
Compare two null terminated strings to each other.
Definition: strcmp.c:50
Here is the call graph for this function:

◆ Translate() [1/3]

char * StandardLanguage::Translate ( textdef def)
protectedvirtual

Implements Language.

Definition at line 72 of file language_stdc.cpp.

References textdef::id, textdef::text, and textcatalog.

73 {
74  if (textcatalog == nullptr)
75  return const_cast<char*>(def->text);
76 
77  return const_cast<char*>(textcatalog[def->id].text);
78 }
const char * text
Definition: amatht.h:36
textdef * textcatalog
Definition: language_stdc.h:74
int id
Definition: amatht.h:35

◆ Translate() [2/3]

char * StandardLanguage::Translate ( helptextdef def)
protectedvirtual

Implements Language.

Definition at line 80 of file language_stdc.cpp.

References helpcatalog, helptextdef::id, and helptextdef::text.

81 {
82  if (helpcatalog == nullptr)
83  return const_cast<char*>(def->text);
84 
85  return const_cast<char*>(helpcatalog[def->id].text);
86 }
int id
Definition: help.h:50
const char * text
Definition: help.h:52
helptextdef * helpcatalog
Definition: language_stdc.h:75

◆ Translate() [3/3]

char * StandardLanguage::Translate ( identhelpdef def)
protectedvirtual

Implements Language.

Definition at line 88 of file language_stdc.cpp.

References identhelpdef::id, identcatalog, and identhelpdef::text.

89 {
90  if (identcatalog == nullptr)
91  return const_cast<char*>(def->text);
92 
93  return const_cast<char*>(identcatalog[def->id].text);
94 }
int id
Definition: amatht.h:47
const char * text
Definition: amatht.h:49
identhelpdef * identcatalog
Definition: language_stdc.h:76

◆ Validate()

bool StandardLanguage::Validate ( char  c)
virtual

Implements Language.

Definition at line 139 of file language_stdc.cpp.

140 {
141  return (c >= 32 && c <= 126);
142 }

Member Data Documentation

◆ helpbase

char* StandardLanguage::helpbase
private

Definition at line 69 of file language_stdc.h.

Referenced by ~StandardLanguage().

◆ helpcatalog

helptextdef* StandardLanguage::helpcatalog
private

Definition at line 75 of file language_stdc.h.

Referenced by Translate().

◆ identbase

char* StandardLanguage::identbase
private

Definition at line 70 of file language_stdc.h.

Referenced by ~StandardLanguage().

◆ identcatalog

identhelpdef* StandardLanguage::identcatalog
private

Definition at line 76 of file language_stdc.h.

Referenced by Translate().

◆ kwordbase

char* StandardLanguage::kwordbase
private

Definition at line 71 of file language_stdc.h.

Referenced by ~StandardLanguage().

◆ ptr

char* StandardLanguage::ptr
private

Definition at line 73 of file language_stdc.h.

Referenced by GetNextLine(), GetNextPair(), LoadCatalog(), and SkipComments().

◆ textbase

char* StandardLanguage::textbase
private

Definition at line 68 of file language_stdc.h.

Referenced by ~StandardLanguage().

◆ textcatalog

textdef* StandardLanguage::textcatalog
private

Definition at line 74 of file language_stdc.h.

Referenced by Translate().


The documentation for this class was generated from the following files: