ccNOos  v0.0.0
Build Portable Microcontroller Applications!
console_menu.c
Go to the documentation of this file.
1 /** \file console_menu.c
2 * \brief <a href="https://www.inmechasol.org/" target="_blank">IMS</a>:
3  <a href="https://github.com/InMechaSol/ccNOos" target="_blank">ccNOos</a>,
4  Implementation for straight C
5 
6  Copyright 2021 <a href="https://www.inmechasol.org/" target="_blank">InMechaSol, Inc</a>
7 
8  Licensed under the Apache License, Version 2.0(the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 Notes:
21  (.c includes .h) - for straight C or
22  (.cpp includes .c which includes .h) - for C++ wrapped straight C
23  *Always compiled to a single compilation unit, either C or CPP, not both
24 
25 */
26 
27 #ifdef __USINGCONSOLEMENU
28 
29 #include "console_menu.h"
30 #include "execution_system.h"
31 
32 const char* cursorString(UI_8 showCursor)
33 {
34  if (showCursor == ui8TRUE)
35  return "->";
36  else
37  return " ";
38 }
39 const char* terminalClearString()
40 {
41  return "\033[2J\033[0;0H";
42 }
43 const char* terminalSlashes()
44 {
45  return "\\\\\\\\\\";
46 }
47 
48 // Console UI Data Structure
49 struct uiStruct createuiStruct()
50 {
51  struct uiStruct outStruct;
52  outStruct.currentMenuIndex = 0;
53  outStruct.cursorIndex = 0;
54  outStruct.currentUserLevel = 0;
55  outStruct.viewFormatIndex = 0;
56  outStruct.devptr = nullptr;
57  outStruct.lines2print = 0;
58  outStruct.linesprinted = 0;
59  outStruct.clearScreen = ui8FALSE;
60  outStruct.parseIndex = 0;
61  outStruct.showHelp = ui8FALSE;
62  outStruct.showPrompt = ui8FALSE;
63  return outStruct;
64 }
65 
66 
67 // Logging Interface Data Structure
68 struct logStruct createlogStruct()
69 {
70  struct logStruct outStruct;
71  outStruct.devptr = nullptr;
72  return outStruct;
73 }
74 
75 
76 // Config Interface Data Structure
77 struct configStruct createconfigStruct()
78 {
79  struct configStruct outStruct;
80  outStruct.devptr = nullptr;
81  return outStruct;
82 }
83 
84 
85 
86 
87 UI_8 isASCIIchar(char inChar) { return ((inChar >= ASCII_space && inChar <= ASCII_tilda) || inChar == ASCII_lf || inChar == ASCII_cr || inChar == ASCII_tab || inChar == 0x00); }
88 UI_8 isLetterchar(char inChar) { return ((inChar >= ASCII_A && inChar <= ASCII_Z) || (inChar >= ASCII_a && inChar <= ASCII_z)); }
89 UI_8 isNumberchar(char inChar) { return ((inChar >= ASCII_0 && inChar <= ASCII_9) || inChar == ASCII_plus || inChar == ASCII_minus || inChar == ASCII_dot); }
90 UI_8 isIntegerchar(char inChar) { return ((inChar >= ASCII_0 && inChar <= ASCII_9) || inChar == ASCII_plus || inChar == ASCII_minus); }
91 UI_8 isUnsignedIntegerchar(char inChar) { return ((inChar >= ASCII_0 && inChar <= ASCII_9)); }
92 UI_8 isDelimiterchar(char inChar) { return (inChar == ASCII_colon); }
93 UI_8 isTerminatorchar(char inChar) { return (inChar == ASCII_semicolon); }
94 UI_8 isASCIIString(char* inStringPtr) { int index = 0; while (inStringPtr[index] != 0x00) if (!isASCIIchar(inStringPtr[index++])) return ui8FALSE; return ui8TRUE; }
95 UI_8 isLetterString(char* inStringPtr) { int index = 0; while (inStringPtr[index] != 0x00) if (!isLetterchar(inStringPtr[index++])) return ui8FALSE; return ui8TRUE; }
96 UI_8 isNumberString(char* inStringPtr) { int index = 0; while (inStringPtr[index] != 0x00) if (!isNumberchar(inStringPtr[index++])) return ui8FALSE; return ui8TRUE; }
97 UI_8 isIntegerString(char* inStringPtr) { int index = 0; while (inStringPtr[index] != 0x00) if (!isIntegerchar(inStringPtr[index++])) return ui8FALSE; return ui8TRUE; }
98 UI_8 isUnsignedIntegerString(char* inStringPtr) { int index = 0; while (inStringPtr[index] != 0x00) if (!isUnsignedIntegerchar(inStringPtr[index++])) return ui8FALSE; return ui8TRUE; }
99 UI_8 stringMatchCaseSensitive(char* inStringPtr, const char* matchString)
100 {
101  int i = 0;
102  while (matchString[i] != 0x00)
103  {
104  if (inStringPtr[i] != matchString[i])
105  return ui8FALSE;
106  i++;
107  }
108  return ui8TRUE;
109 }
110 void stringInit(char* stringPtr, const char* initString)
111 {
112  int idx = -1;
113  do {
114  idx++;
115  stringPtr[idx] = initString[idx];
116  } while (initString[idx] != 0x00);
117 }
118 UI_16 stringLength(const char* stringPtr)
119 {
120  UI_16 lenOut = 0;
121  while (lenOut < charBuffMax) {
122  if (stringPtr[lenOut] == 0x00)
123  break;
124  lenOut++;
125  }
126  return lenOut;
127 
128 }
129 #endif
130 
console_menu.h
IMS: ccNOos, Declarations for straight C and C++
ui8FALSE
#define ui8FALSE
Definition: version_config.h:190
execution_system.h
IMS: ccNOos, Declarations for straight C and C++
ui8TRUE
#define ui8TRUE
Definition: version_config.h:191
charBuffMax
#define charBuffMax
Definition: version_config.h:78
idx
int idx
Definition: Platform_Arduino.h:56