Skip to content

Commit

Permalink
[new] Initial help
Browse files Browse the repository at this point in the history
  • Loading branch information
Southern committed Jun 19, 2013
1 parent 1c648d1 commit 02167f8
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -19,10 +19,10 @@ all: libuv aeternum
debug: libuv aeternum_g

aeternum_g:
gcc -O0 -ggdb $(CFLAGS) -o aeternum_g aeternum.c options.c deps/libuv/libuv.a $(LDFLAGS)
gcc -O0 -ggdb $(CFLAGS) -o aeternum_g aeternum.c options.c help.c deps/libuv/libuv.a $(LDFLAGS)

aeternum:
gcc -O2 $(CFLAGS) -o aeternum aeternum.c options.c deps/libuv/libuv.a $(LDFLAGS)
gcc -O2 $(CFLAGS) -o aeternum aeternum.c options.c help.c deps/libuv/libuv.a $(LDFLAGS)

libuv:
$(MAKE) -C deps/libuv/
Expand Down
21 changes: 20 additions & 1 deletion aeternum.c
Expand Up @@ -10,6 +10,7 @@
#include <errno.h>
#include "uv.h"
#include "options.h"
#include "help.h"

#ifdef __WIN32
#include <shellapi.h>
Expand Down Expand Up @@ -190,8 +191,26 @@ int main(int argc, char *argv[]) {

loop = uv_default_loop();

add_help("start", "file", "Run a file to be monitored and daemonize it", (char*[]) {
"Test"
});

add_help("run", "file", "Run a file to be monitored", (char*[]) {
"Test",
"test2",
"test3"
});

add_help("-i", "file", "Input file", (char*[]) {
"Input file"
});

add_help("-o", "file", "Output file", (char*[]) {
"Output file"
});

if (argc == 1) {
printf("Usage: aeternum [action] [options] -- program\n");
print_help();
return 1;
}

Expand Down
73 changes: 73 additions & 0 deletions help.c
@@ -0,0 +1,73 @@
#include <stdlib.h>
#include <stdio.h>
#include "help.h"

char *BANNER[] = {
// aeternum ascii art
" __ ",
" ____ ____ / /____ _________ __ ______ ___ ",
" / __ `/ _ \\/ __/ _ \\/ ___/ __ \\/ / / / __ `__ \\",
"/ /_/ / __/ /_/ __/ / / / / / /_/ / / / / / /",
"\\__,_/\\___/\\__/\\___/_/ /_/ /_/\\__,_/_/ /_/ /_/"
};

help_list_t help_list;

void init_help() {
if (help_list.length > 0) return;

help_list.commands = (help_t*) malloc(sizeof(help_t*));
}

void add_help(char *name, char *syntax, char *desc, char **text) {
init_help();

help_t help;
help.name = name;
help.syntax = syntax;
help.desc = desc;
help.text = text;

// Get help text length
int i = 0;
while (text[i] != NULL) i++;

help.length = i;

help_list.commands[help_list.length++] = help;
}

void print_help() {
int i;
print_help_header();
for (i = 0; i < help_list.length; i++) {
printf("aeternum %s\t\t\t%s\n", help_list.commands[i].syntax, help_list.commands[i].desc);
}
}

void print_help_for(char *name) {
int i, j;
for (i = 0; i < help_list.length; i++) {
if (help_list.commands[i].name == name) {
print_help_header();
printf("%s\n", help_list.commands[i].syntax);
printf("----------------------------------\n");
for (j = 0; j < help_list.commands[i].length; j++) {
printf("%s\n", help_list.commands[i].text[j]);
}
}
}
}

void print_help_header() {
print_header();
printf("Usage: aeternum [action] [options] -- program\n\n");
}

void print_header() {
int i = 0, length = sizeof(BANNER) / sizeof(char**);
for (i = 0; i < length; i++) {
printf("%s\n", BANNER[i]);
}
printf("\n");
}
25 changes: 25 additions & 0 deletions help.h
@@ -0,0 +1,25 @@
#ifndef _help_h
#define _help_h

#define VERSION "0.1.4"

typedef struct help_s {
char *name;
char *syntax;
char *desc;
char **text;
int length;
} help_t;

typedef struct help_list_s {
int length;
help_t *commands;
} help_list_t;

void add_help(char *name, char *syntax, char *desc, char **text);
void print_help_for(char *name);
void print_help();
void print_help_header();
void print_header();

#endif

0 comments on commit 02167f8

Please sign in to comment.