Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spelling of _USE_CTLR_C (warning: depends on PR #18) #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Microrl library is designed to help implement command line interface in small an

2. FEATURE

** config.h file
** microrl_config.h file
- Turn on/off feature for add functional/decrease memory via config files.

** hot keys support
Expand Down Expand Up @@ -35,7 +35,8 @@ Microrl library is designed to help implement command line interface in small an
src/ - library source
microrl.c - microrl routines
microrl.h - lib interface and data type
config.h - customisation config-file
microrl_config.h.template
- customisation config-file
examples/ - library usage examples
avr_misc/ - avr specific routines for avr example
unix_misc/ - unix specific routines for desktop example
Expand Down Expand Up @@ -66,7 +67,7 @@ c) Call 'microrl_set_execute_callback' with pointer to you routine, what will be

d) If you want completion support if user press TAB key, call 'microrl_set_complete_callback' and set you callback. It also give 'argc' and 'argv' arguments, so iterate through it and return set of complete variants.

e) Look at 'config.h' file, for tune library for you requiring.
e) Copy 'microrl_config.h.template' into your project and edit as necessary, removing the .template extension. Ensure 'microrl_config.h' is your quoted include path (`#include "microrl_config."`).

f) Now you just call 'microrl_insert_char' on each char received from input stream (usart, network, etc).

Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CC = gcc
CPPFLAGS = $(DEBUG)
CCFLAGS = -Wall $(DEBUG) -std=gnu99
CCFLAGS = -Wall $(DEBUG) -std=gnu99 -I../src -iquote unix_misc
LDFLAGS =

TARGET=microrl_test
Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile.avr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MCU = atmega8
#DEBUG = -g
TARGET = microrl_test

CCFLAGS = -mmcu=$(MCU) -Wall $(DEBUG) -std=gnu99 -Os -ffunction-sections -Wa,-adhlns=$(<:.c=.lst)
CCFLAGS = -mmcu=$(MCU) -Wall $(DEBUG) -std=gnu99 -Os -ffunction-sections -Wa,-adhlns=$(<:.c=.lst) -I../src -iquote avr_misc
LDFLAGS = -Wl,-Map,$(TARGET).map,--gc-sections -mmcu=$(MCU)

all: $(TARGET).elf
Expand Down
2 changes: 1 addition & 1 deletion examples/avr_misc/avr_misc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../src/config.h"
#include <microrl.h>
#include <string.h>
#include <stdlib.h>
#include <avr/io.h>
Expand Down
2 changes: 1 addition & 1 deletion src/config.h → examples/avr_misc/microrl_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Try to build with and without, and compare total code size for tune library.

/*
Enable 'interrupt signal' callback, if user press Ctrl+C */
#define _USE_CTLR_C
#define _USE_CTRL_C

/*
Print prompt at 'microrl_init', if enable, prompt will print at startup,
Expand Down
2 changes: 1 addition & 1 deletion examples/example.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>
#include <string.h>
#include "../src/microrl.h"
#include <microrl.h>
#include "example_misc.h"

// create microrl object and pointer on it
Expand Down
104 changes: 104 additions & 0 deletions examples/unix_misc/microrl_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Microrl library config files
Autor: Eugene Samoylov aka Helius (ghelius@gmail.com)
*/
#ifndef _MICRORL_CONFIG_H_
#define _MICRORL_CONFIG_H_

#define MICRORL_LIB_VER "1.5.1"

/*********** CONFIG SECTION **************/
/*
Command line length, define cmdline buffer size. Set max number of chars + 1,
because last byte of buffer need to contain '\0' - NULL terminator, and
not use for storing inputed char.
If user input chars more then it parametrs-1, chars not added to command line.*/
#define _COMMAND_LINE_LEN (1+100) // for 32 chars

/*
Command token number, define max token it command line, if number of token
typed in command line exceed this value, then prints message about it and
command line not to be parced and 'execute' callback will not calls.
Token is word separate by white space, for example 3 token line:
"IRin> set mode test" */
#define _COMMAND_TOKEN_NMB 8

/*
Define you prompt string here. You can use colors escape code, for highlight you prompt,
for example this prompt will green color (if you terminal supports color)*/
//#define _PROMPT_DEFAULT "\033[32mIRin >\033[0m " // green color
#define _PROMPT_DEFAULT "\033[32mIRin >\033[0m " // green color
//#define _PROMPT_DEFAULT "IRin > "

/*
Define prompt text (without ESC sequence, only text) prompt length, it needs because if you use
ESC sequence, it's not possible detect only text length*/
#define _PROMPT_LEN 7

/*Define it, if you wanna use completion functional, also set completion callback in you code,
now if user press TAB calls 'copmlitetion' callback. If you no need it, you can just set
NULL to callback ptr and do not use it, but for memory saving tune,
if you are not going to use it - disable this define.*/
#define _USE_COMPLETE

/*Define it, if you wanna use history. It s work's like bash history, and
set stored value to cmdline, if UP and DOWN key pressed. Using history add
memory consuming, depends from _RING_HISTORY_LEN parametr */
#define _USE_HISTORY

/*
History ring buffer length, define static buffer size.
For saving memory, each entered cmdline store to history in ring buffer,
so we can not say, how many line we can store, it depends from cmdline len,
but memory using more effective. We not prefer dinamic memory allocation for
small and embedded devices. Overhead is 2 char on each saved line*/
#define _RING_HISTORY_LEN 64

/*
Enable Handling terminal ESC sequence. If disabling, then cursor arrow, HOME, END will not work,
use Ctrl+A(B,F,P,N,A,E,H,K,U,C) see README, but decrease code memory.*/
#define _USE_ESC_SEQ

/*
Use snprintf from you standard complier library, but it gives some overhead.
If not defined, use my own u16int_to_str variant, it's save about 800 byte of code size
on AVR (avr-gcc build).
Try to build with and without, and compare total code size for tune library.
*/
#define _USE_LIBC_STDIO

/*
Enable 'interrupt signal' callback, if user press Ctrl+C */
#define _USE_CTRL_C

/*
Print prompt at 'microrl_init', if enable, prompt will print at startup,
otherwise first prompt will print after first press Enter in terminal
NOTE!: Enable it, if you call 'microrl_init' after your communication subsystem
already initialize and ready to print message */
#undef _ENABLE_INIT_PROMPT

/*
New line symbol */
#define _ENDL_LF

#if defined(_ENDL_CR)
#define ENDL "\r"
#elif defined(_ENDL_CRLF)
#define ENDL "\r\n"
#elif defined(_ENDL_LF)
#define ENDL "\n"
#elif defined(_ENDL_LFCR)
#define ENDL "\n\r"
#else
#error "You must define new line symbol."
#endif

/********** END CONFIG SECTION ************/


#if _RING_HISTORY_LEN > 256
#error "This history implementation (ring buffer with 1 byte iterator) allow 256 byte buffer size maximum"
#endif

#endif
2 changes: 1 addition & 1 deletion examples/unix_misc/unix_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>
#include "../../src/config.h"
#include <microrl.h>

//*****************************************************************************
//dummy function, no need on linux-PC
Expand Down
6 changes: 3 additions & 3 deletions src/microrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void microrl_init (microrl_t * pThis, void (*print) (const char *))
pThis->cursor = 0;
pThis->execute = NULL;
pThis->get_completion = NULL;
#ifdef _USE_CTLR_C
#ifdef _USE_CTRL_C
pThis->sigint = NULL;
#endif
pThis->prompt_str = prompt_default;
Expand All @@ -350,7 +350,7 @@ void microrl_set_execute_callback (microrl_t * pThis, int (*execute)(int, const
{
pThis->execute = execute;
}
#ifdef _USE_CTLR_C
#ifdef _USE_CTRL_C
//*****************************************************************************
void microrl_set_sigint_callback (microrl_t * pThis, void (*sigintf)(void))
{
Expand Down Expand Up @@ -663,7 +663,7 @@ void microrl_insert_char (microrl_t * pThis, int ch)
microrl_backspace (pThis);
terminal_print_line (pThis, pThis->cursor, pThis->cursor);
break;
#ifdef _USE_CTLR_C
#ifdef _USE_CTRL_C
case KEY_ETX:
if (pThis->sigint != NULL)
pThis->sigint();
Expand Down
6 changes: 3 additions & 3 deletions src/microrl.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _MICRORL_H_
#define _MICRORL_H_

#include "config.h"
#include "microrl_config.h"

#define true 1
#define false 0
Expand Down Expand Up @@ -82,7 +82,7 @@ typedef struct {
int (*execute) (int argc, const char * const * argv ); // ptr to 'execute' callback
char ** (*get_completion) (int argc, const char * const * argv ); // ptr to 'completion' callback
void (*print) (const char *); // ptr to 'print' callback
#ifdef _USE_CTLR_C
#ifdef _USE_CTRL_C
void (*sigint) (void);
#endif
} microrl_t;
Expand All @@ -107,7 +107,7 @@ void microrl_set_complete_callback (microrl_t * pThis, char ** (*get_completion)
void microrl_set_execute_callback (microrl_t * pThis, int (*execute)(int, const char* const*));

// set callback for Ctrl+C terminal signal
#ifdef _USE_CTLR_C
#ifdef _USE_CTRL_C
void microrl_set_sigint_callback (microrl_t * pThis, void (*sigintf)(void));
#endif

Expand Down
104 changes: 104 additions & 0 deletions src/microrl_config.h.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Microrl library config files
Autor: Eugene Samoylov aka Helius (ghelius@gmail.com)
*/
#ifndef _MICRORL_CONFIG_H_
#define _MICRORL_CONFIG_H_

#define MICRORL_LIB_VER "1.5.1"

/*********** CONFIG SECTION **************/
/*
Command line length, define cmdline buffer size. Set max number of chars + 1,
because last byte of buffer need to contain '\0' - NULL terminator, and
not use for storing inputed char.
If user input chars more then it parametrs-1, chars not added to command line.*/
#define _COMMAND_LINE_LEN (1+100) // for 32 chars

/*
Command token number, define max token it command line, if number of token
typed in command line exceed this value, then prints message about it and
command line not to be parced and 'execute' callback will not calls.
Token is word separate by white space, for example 3 token line:
"IRin> set mode test" */
#define _COMMAND_TOKEN_NMB 8

/*
Define you prompt string here. You can use colors escape code, for highlight you prompt,
for example this prompt will green color (if you terminal supports color)*/
//#define _PROMPT_DEFAULT "\033[32mIRin >\033[0m " // green color
#define _PROMPT_DEFAULT "\033[32mIRin >\033[0m " // green color
//#define _PROMPT_DEFAULT "IRin > "

/*
Define prompt text (without ESC sequence, only text) prompt length, it needs because if you use
ESC sequence, it's not possible detect only text length*/
#define _PROMPT_LEN 7

/*Define it, if you wanna use completion functional, also set completion callback in you code,
now if user press TAB calls 'copmlitetion' callback. If you no need it, you can just set
NULL to callback ptr and do not use it, but for memory saving tune,
if you are not going to use it - disable this define.*/
#define _USE_COMPLETE

/*Define it, if you wanna use history. It s work's like bash history, and
set stored value to cmdline, if UP and DOWN key pressed. Using history add
memory consuming, depends from _RING_HISTORY_LEN parametr */
#define _USE_HISTORY

/*
History ring buffer length, define static buffer size.
For saving memory, each entered cmdline store to history in ring buffer,
so we can not say, how many line we can store, it depends from cmdline len,
but memory using more effective. We not prefer dinamic memory allocation for
small and embedded devices. Overhead is 2 char on each saved line*/
#define _RING_HISTORY_LEN 64

/*
Enable Handling terminal ESC sequence. If disabling, then cursor arrow, HOME, END will not work,
use Ctrl+A(B,F,P,N,A,E,H,K,U,C) see README, but decrease code memory.*/
#define _USE_ESC_SEQ

/*
Use snprintf from you standard complier library, but it gives some overhead.
If not defined, use my own u16int_to_str variant, it's save about 800 byte of code size
on AVR (avr-gcc build).
Try to build with and without, and compare total code size for tune library.
*/
#define _USE_LIBC_STDIO

/*
Enable 'interrupt signal' callback, if user press Ctrl+C */
#define _USE_CTRL_C

/*
Print prompt at 'microrl_init', if enable, prompt will print at startup,
otherwise first prompt will print after first press Enter in terminal
NOTE!: Enable it, if you call 'microrl_init' after your communication subsystem
already initialize and ready to print message */
#undef _ENABLE_INIT_PROMPT

/*
New line symbol */
#define _ENDL_LF

#if defined(_ENDL_CR)
#define ENDL "\r"
#elif defined(_ENDL_CRLF)
#define ENDL "\r\n"
#elif defined(_ENDL_LF)
#define ENDL "\n"
#elif defined(_ENDL_LFCR)
#define ENDL "\n\r"
#else
#error "You must define new line symbol."
#endif

/********** END CONFIG SECTION ************/


#if _RING_HISTORY_LEN > 256
#error "This history implementation (ring buffer with 1 byte iterator) allow 256 byte buffer size maximum"
#endif

#endif