Skip to content

Commit

Permalink
Merge pull request #5 from ronen25/cpp_fixes
Browse files Browse the repository at this point in the history
Fixes for Apple clang, C++, and notice update
  • Loading branch information
ronen25 authored Dec 9, 2022
2 parents 1fed70f + 2842e00 commit 3c84532
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests/c_test/c_test
tests/c_test/c_test.dSYM
tests/c_test/c_submenu
tests/c_test/c_submenu.dSYM

tests/cpp_test/cpp_test
tests/cpp_test/cpp_test.dSYM
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A simple library for writing command-line applications, inspired by Python's [cm

----------------------------------------------

***Latest version: v.1.3.1 (2022-11-18)***
***Latest version: v.1.4.0 (2022-12-09)***

----------------------------------------------

Expand All @@ -19,9 +19,9 @@ Features
Requirements
------------
1. **Any ANSI C/ISO C90-compliant compiler**
<br />*Tested on GCC 5.4+, clang 4.0+ and MSVC 14.0*
<br />*Tested on GCC 5.4+, clang 4.0+, Apple Clang 14, and MSVC 14.0*
2. **Linux/Windows**
<br />*Tested on Ubuntu 16.04 - 20.04, Fedora 26 - 30, and Windows 10 (all AMD64)*
<br />*Tested on Ubuntu 16.04 - 20.04, Fedora 26 - 30, Windows 10 (all AMD64) and Mac (M1)*
3. **GNU Readline development libraries (optional)**
<br />*Required for GNU Readline support, if enabled.*

Expand Down Expand Up @@ -139,11 +139,12 @@ initialization tricks that require deinitalization.

This might change in the future, though, so make sure to call <code>cmdf_quit</code> when you're done with it!

### Any plans to support Linenoise/anything else?
Yes! I'm planning to add support for it in the near future.
### Any plans to implement a proper C++ API, Linenoise/anything else?
I initially had plans to implement a lot of features.
However, I'm not working with C/C++ professionally anymore so my interest in these languages
and the ecosystem has somewhat dwindled.

### Any plans to implement a proper C++ API?
Yes! Near future, hopefully!
This does not affect the development status of this library - it will still be maintained and developed.

-------------------------------------------------------------------------------------------------------

Expand Down
20 changes: 12 additions & 8 deletions libcmdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* libcmdf.h - A library for writing command-line applications
* Public domain; no warrenty applied, use at your own risk!
* Authored by:
* Ronen Lapushner, 2017-2020.
* Ronen Lapushner, 2017-2022.
* Rull Deef, 2020.
*
* License:
Expand Down Expand Up @@ -230,7 +230,12 @@ static struct cmdf__settings_stack_s {
struct cmdf__settings_s stack[CMDF_MAX_SUBPROCESSES];
size_t size;
struct cmdf__settings_s *top; /* actual settings for currect process */
} cmdf__settings_stack = { 0 };
} cmdf__settings_stack =
#ifdef __cplusplus /* Required to avoid -Wmissing-braces on Apple clang and possibly others */
{{}};
#else
{ 0 };
#endif

static struct cmdf__entry_s {
const char *cmdname; /* Command name */
Expand Down Expand Up @@ -393,6 +398,7 @@ void cmdf_init(const char *prompt, const char *intro, const char *doc_header,
/* Create new settings to push them to stack */
struct cmdf__settings_s settings;
memset((void *)&settings, 0, sizeof(struct cmdf__settings_s));

/* Set properties */
settings.prompt = prompt ? prompt : cmdf__default_prompt;
settings.intro = intro ? intro : cmdf__default_intro;
Expand Down Expand Up @@ -845,7 +851,7 @@ void cmdf__default_commandloop(void) {
return cm_winsize;
}

#endif
#endif /* Utility functions */

/* readline-related utilities */
#ifdef CMDF_READLINE_SUPPORT
Expand All @@ -864,14 +870,12 @@ char *cmdf__command_name_iter(const char *text, int state) {
static size_t len;
const char *name = NULL;

if (!state)
{
if (!state) {
list_index = cmdf__settings_stack.top->entry_start;
len = strlen(text);
}

while (name = cmdf__entries[list_index].cmdname)
{
while (name = cmdf__entries[list_index].cmdname) {
list_index++;

if (strncmp (name, text, len) == 0)
Expand All @@ -881,7 +885,7 @@ char *cmdf__command_name_iter(const char *text, int state) {
return ((char*) NULL);
}

#endif
#endif /* CMDF_READLINE_SUPPORT */

#endif /* LIBCMDF_IMPL */

Expand Down
8 changes: 6 additions & 2 deletions tests/c_test/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
CFLAGS=-ansi -pedantic -Wall -Werror -ggdb -O0 -D_POSIX_SOURCE -I"../.."
CFLAGS=-ansi -pedantic -Wall -Werror -g -O0 -D_POSIX_SOURCE -I"../.."
LDLIBS=-lreadline

ALL: compile_c_test
ALL: compile_c_test compile_c_submenu

clean:
rm c_test
rm c_submenu

c_test: c_test.c
c_submenu: c_submenu.c
Expand Down
5 changes: 4 additions & 1 deletion tests/cpp_test/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
CXXFLAGS=-Wall -Werror -ggdb -O0 -I"../.."
CXXFLAGS=-Wall -Werror -g -O0 -I"../.."
LDLIBS=-lreadline

ALL: compile_cpp_test

clean:
rm cpp_test

cpp_test: cpp_test.cpp

compile_cpp_test: cpp_test

0 comments on commit 3c84532

Please sign in to comment.