GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — minor code improvements · sirogosig/Shell@7890d2a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Shell.c
  • Shell.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Shell.c‎

Copy file name to clipboardExpand all lines: Shell.c
+40-32Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool shell_init(shell_reader_t reader, shell_writer_t writer, char * msg)
116116

117117
bool shell_register(shell_program_t program, const char * string)
118118
{
119-
unsigned char i;
119+
uint8_t i;
120120

121121
for (i = 0; i < CONFIG_SHELL_MAX_COMMANDS; i++) {
122122
if (list[i].shell_program != 0 || list[i].shell_command_string != 0)
@@ -130,7 +130,7 @@ bool shell_register(shell_program_t program, const char * string)
130130

131131
void shell_unregister_all()
132132
{
133-
unsigned char i;
133+
uint8_t i;
134134

135135
for (i = 0; i < CONFIG_SHELL_MAX_COMMANDS; i++) {
136136
list[i].shell_program = 0;
@@ -140,14 +140,14 @@ void shell_unregister_all()
140140

141141
void shell_putc(char c)
142142
{
143-
if (initialized && shell_writer)
143+
if (initialized != false && shell_writer != 0)
144144
shell_writer(c);
145145
}
146146

147147
void shell_print(const char * string)
148148
{
149149
while (* string != '\0')
150-
shell_writer(* string++);
150+
shell_putc(* string++);
151151
}
152152

153153
void shell_println(const char * string)
@@ -170,8 +170,12 @@ void shell_printf(const char * fmt, ...)
170170

171171
void shell_print_commands()
172172
{
173-
unsigned char i;
174-
173+
uint8_t i;
174+
#ifdef ARDUINO
175+
shell_println_pm(PSTR("Available Commands:"));
176+
#else
177+
shell_println((const char *) "Available Commands:");
178+
#endif
175179
for (i = 0; i < CONFIG_SHELL_MAX_COMMANDS; i++) {
176180
if (list[i].shell_program != 0 || list[i].shell_command_string != 0) {
177181
shell_println(list[i].shell_command_string);
@@ -253,13 +257,13 @@ void shell_print_error(int error, const char * field)
253257

254258
void shell_task()
255259
{
256-
unsigned int i = 0, retval = 0;
260+
// Number of characters written to buffer (this should be static var)
261+
static uint16_t count = 0;
262+
uint8_t i = 0;
263+
bool cc = 0;
264+
int retval = 0;
257265
int argc = 0;
258266
char rxchar = 0;
259-
char finished = 0;
260-
261-
// Number of characters written to buffer (this should be static var)
262-
static unsigned short count = 0;
263267

264268
if (!initialized)
265269
return;
@@ -273,38 +277,40 @@ void shell_task()
273277
break;
274278

275279
case SHELL_ASCII_DEL:
276-
shell_writer(SHELL_ASCII_BEL);
280+
shell_putc(SHELL_ASCII_BEL);
277281
break;
278282

279283
case SHELL_ASCII_HT:
280-
shell_writer(SHELL_ASCII_BEL);
284+
shell_putc(SHELL_ASCII_BEL);
281285
break;
282286

283287
case SHELL_ASCII_CR: // Enter key pressed
284288
shellbuf[count] = '\0';
285289
shell_println("");
286-
finished = 1;
290+
cc = true;
287291
break;
288292

289293
case SHELL_ASCII_BS: // Backspace pressed
290294
if (count > 0) {
291295
count--;
292-
shell_writer(SHELL_ASCII_BS);
293-
shell_writer(SHELL_ASCII_SP);
294-
shell_writer(SHELL_ASCII_BS);
296+
shell_putc(SHELL_ASCII_BS);
297+
shell_putc(SHELL_ASCII_SP);
298+
shell_putc(SHELL_ASCII_BS);
295299
} else
296-
shell_writer(SHELL_ASCII_BEL);
300+
shell_putc(SHELL_ASCII_BEL);
297301
break;
298302
default:
299303
// Process printable characters, but ignore other ASCII chars
300304
if (count < (CONFIG_SHELL_MAX_INPUT - 1) && rxchar >= 0x20 && rxchar < 0x7F) {
301305
shellbuf[count] = rxchar;
302-
shell_writer(rxchar);
306+
shell_putc(rxchar);
303307
count++;
308+
} else {
309+
shell_putc(SHELL_ASCII_BEL);
304310
}
305311
}
306312
// Check if a full command is available on the buffer to process
307-
if (finished) {
313+
if (cc) {
308314
argc = shell_parse(shellbuf, argv_list, CONFIG_SHELL_MAX_COMMAND_ARGS);
309315
// Process escape sequences before giving args to command implementation
310316
shell_process_escape(argc, argv_list);
@@ -314,23 +320,26 @@ void shell_task()
314320
continue;
315321
// If string matches one on the list
316322
#ifdef ARDUINO
317-
if (!strcmp_P(argv_list[0], list[i].shell_command_string)) {
323+
if (!strcmp_P(argv_list[0], list[i].shell_command_string))
318324
#else
319-
if (!strcmp(argv_list[0], list[i].shell_command_string)) {
325+
if (!strcmp(argv_list[0], list[i].shell_command_string))
320326
#endif
327+
{
321328
// Run the appropriate function
322329
retval = list[i].shell_program(argc, argv_list);
323-
finished = 0;
330+
cc = false;
324331
}
325332
}
326-
if (finished != 0 && count != 0) // If no command found and buffer not empty
333+
// If no command found and buffer not empty
334+
if (cc != false && count != 0) {
327335
#ifdef ARDUINO
328336
shell_println_pm(PSTR("Command NOT found."));
329337
#else
330338
shell_println((const char *) "Command NOT found."); // Print not found!!
331339
#endif
332-
340+
}
333341
count = 0;
342+
cc = false;
334343
shell_println("");
335344
shell_prompt();
336345
}
@@ -346,7 +355,7 @@ void shell_print_pm(const char * string)
346355
c = pgm_read_byte(string++);
347356
if (!c)
348357
break;
349-
shell_writer(c);
358+
shell_putc(c);
350359
} while (1);
351360
}
352361

@@ -471,7 +480,6 @@ static void shell_prompt()
471480
* Shell formatted print support *
472481
*-------------------------------------------------------------*/
473482
#ifdef SHELL_PRINTF_LONG_SUPPORT
474-
475483
static void uli2a(unsigned long int num, unsigned int base, int uc, char * bf)
476484
{
477485
int n = 0;
@@ -561,9 +569,9 @@ static void putchw(int n, char z, char* bf)
561569
while (*p++ && n > 0)
562570
n--;
563571
while (n-- > 0)
564-
shell_writer(fc);
572+
shell_putc(fc);
565573
while ((ch = *bf++))
566-
shell_writer(ch);
574+
shell_putc(ch);
567575
}
568576

569577
static void shell_format(const char * fmt, va_list va)
@@ -574,7 +582,7 @@ static void shell_format(const char * fmt, va_list va)
574582

575583
while ((ch = *(fmt++))) {
576584
if (ch != '%')
577-
shell_writer(ch);
585+
shell_putc(ch);
578586
else {
579587
char lz = 0;
580588
#ifdef PRINTF_LONG_SUPPORT
@@ -630,13 +638,13 @@ static void shell_format(const char * fmt, va_list va)
630638
putchw(w, lz, bf);
631639
break;
632640
case 'c':
633-
shell_writer((char) (va_arg(va, int)));
641+
shell_putc((char) (va_arg(va, int)));
634642
break;
635643
case 's':
636644
putchw(w, 0, va_arg(va, char*));
637645
break;
638646
case '%':
639-
shell_writer(ch);
647+
shell_putc(ch);
640648
default:
641649
break;
642650
}
Collapse file

‎Shell.h‎

Copy file name to clipboardExpand all lines: Shell.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extern "C" {
192192
/**
193193
* @brief Unregister all commands
194194
*
195-
* Erases all entries on the command list, returning it to it´s default status.
195+
* Erases all entries on the command list, returning it to it's default status.
196196
*/
197197
void shell_unregister_all();
198198

@@ -233,7 +233,7 @@ extern "C" {
233233
* following format string are formatted and inserted in the resulting string
234234
* replacing their respective specifiers.
235235
*
236-
* This function implements its own mechanism for text formatting. It does not
236+
* This function implements it's own mechanism for text formatting. It does not
237237
* rely on the native print functions.
238238
*
239239
* @param fmt The string to send to the terminal, the string can include format
@@ -306,7 +306,7 @@ extern "C" {
306306
*
307307
* This function is designed to be used with strings stored in flash.
308308
*
309-
* This function implements it´s own mechanism for text formatting. It doesn´t
309+
* This function implements it's own mechanism for text formatting. It doesn't
310310
* rely on the native print functions.
311311
*
312312
* @param fmt The string to send to the terminal, the string can include format

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.