Skip to content
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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
CC=gcc
LDFLAGS=-lreadline
CFLAGS :=
SYSH :=

ifeq ($(OS),Windows_NT)
CFLAGS := $(CFLAGS) -I./windeps -DWINNT=1
endif

OUTPUT=example
CFILE=example.c
Expand All @@ -17,4 +23,4 @@ $(OUTPUT): $(CFILE) libtalaris.a
gcc $(CFLAGS) $^ -o $(OUTPUT) $(LDFLAGS)

clean:
trash *.o *.a
rm *.o *.a *.exe
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ You can also run `make libtalaris.a` to create the .a file, which you can copy a

Note: Since this library uses `readline.h`, you will need to include the -lreadline flag when compiling your project if you use libtaralis.

MinGW Note: Because MinGW does not include any of the *nix `sys` headers, a drop-in replacement is included in the `windeps` folder in this distribution. Windows also lacks `fork()`, so the code in the example that uses this is disabled when compiling with on Windows.

## Usage

Make sure to add the line `#include "libtaralis.h" in your .c file after copying libtalaris.a into your folder. Also don't forget to use the -lreadline flag when compiling in gcc.
Expand Down
17 changes: 16 additions & 1 deletion example.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ int arguments(int argc, char **argv, LT_Parser *parser) {
}
}

#ifndef WINNT
int exec(int argc, char **argv, LT_Parser *parser) {
if (argc < 2) {
printf("You must specify a binary\n");
Expand All @@ -154,6 +155,7 @@ int exec(int argc, char **argv, LT_Parser *parser) {
wait(NULL);
return 0;
}
#endif

int main(void) {
LT_Parser *parser = lt_create_parser();
Expand All @@ -166,11 +168,24 @@ int main(void) {
{"secret", "This is a secret command. It does not show up in help, but you can run it", "Usage: secret", LT_EXEC, secret, NULL},
{"silent", "This is a silent command. It does not show up in help, and you can not run it", "Usage: silent", LT_HIDE, silent, NULL},
{"?", "A link to help", "Usage: ? [COMMAND]...", LT_EXEC | LT_SPEC, lt_help, NULL},
#ifndef WINNT
{"exec", "execute a binary", "Usage: exec [BINARY]", LT_UNIV, exec, NULL},
#endif
{0}
};

char *matches[] = {"echo", "cat", "quiet", "help", "exit", "math", "args", "exec", NULL};

char *matches[] = {"echo",
"cat",
"quiet",
"help",
"exit",
"math",
"args",
#ifndef WINNT
"exec",
#endif
NULL};

lt_add_commands(parser, commands);

Expand Down
Loading