diff --git a/Makefile b/Makefile index 8037a76..696fdb2 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ include config.mk -all: src/main.c src/printevents.c src/mkevent.c - $(CC) $(CFLAGS) $(LDFLAGS) -c src/main.c -o src/main.o +all: src/nc.c src/printevents.c src/mkevent.c + $(CC) $(CFLAGS) $(LDFLAGS) -c src/nc.c -o src/nc.o $(CC) $(CFLAGS) $(LDFLAGS) -c src/printevents.c -o src/printevents.o $(CC) $(CFLAGS) $(LDFLAGS) -c src/mkevent.c -o src/mkevent.o - $(CC) $(CFLAGS) $(LDFLAGS) -o src/nc src/main.o src/printevents.o src/mkevent.o + $(CC) $(CFLAGS) $(LDFLAGS) -o src/nc src/nc.o src/printevents.o src/mkevent.o install: src/nc install src/nc $(PREFIX)/bin diff --git a/include/libcolor.h b/include/libcolor.h deleted file mode 100644 index 09ff2f9..0000000 --- a/include/libcolor.h +++ /dev/null @@ -1,17 +0,0 @@ -/* libcolor.h - header file to define colors */ - -#ifndef LIBCOLOR_H_ -#define LIBCOLOR_H_ - -#define TXT_BOLD "\e[1m" -#define TXT_RESET "\e[m" - -#define COL_RED "\x1b[31m" -#define COL_GREEN "\x1b[32m" -#define COL_YELLOW "\x1b[33m" -#define COL_BLUE "\x1b[34m" -#define COL_MAGENTA "\x1b[35m" -#define COL_CYAN "\x1b[36m" -#define COL_RESET "\x1b[0m" - -#endif diff --git a/src/main.c b/src/main.c deleted file mode 100644 index df47339..0000000 --- a/src/main.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include - -#include "../include/libcolor.h" - -#include "nc.h" - -int main(int argc, char *argv[]) { - - if (argc < 2) { - printf("not enough options\n"); - printf("usage: %s -l -n DATE EVENT_NAME\n", argv[0]); - return 1; - } - - int opt; - - while ((opt = getopt(argc, argv, ":if:nl")) != -1) { - switch(opt) { - case 'n': - mkevent(argc, argv); - break; - case 'l': - printevents(); - break; - case '?': - printf("unknown option: %c\n", optopt); - printf("usage: %s -l -n DATE EVENT_NAME\n", argv[0]); - break; - } - } - - return 0; -} diff --git a/src/nc.c b/src/nc.c new file mode 100644 index 0000000..94f9cdb --- /dev/null +++ b/src/nc.c @@ -0,0 +1,95 @@ +/* + nc.c - simple CLI to-do list + + This file is part of nc. + + nc is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + nc is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with nc. If not, see . +*/ + +#include +#include +#include +#include + +#include "nc.h" + +#include "config.h" /* for outputting NC_EVENTS_FILE */ + +static void +usage(int argc, char *argv[]) +{ + printf("%s - simple CLI to-do list\n", argv[0]); + printf("usage: %s [-h] [-v] [-s] [-n] [-l]\n", argv[0]); + printf("\n"); + printf("%s {-h} Show this message\n", argv[0]); + printf("%s {-v} Show the current version\n", argv[0]); + printf("%s {-s} View compile-time settings\n", argv[0]); + printf("%s {-n} DATE NAME Create a new event\n", argv[0]); + printf("%s {-l} Show current events\n", argv[0]); + printf("\n"); + printf("Nc is free software.\n"); + printf("See the GNU GPL version 3 for details.\n"); +} + +static void +usage_small(int argc, char *argv[]) +{ + printf("usage: %s [-h] [-v] [-s] [-n] [-l]\n", argv[0]); +} + +static void +view_compile_time_settings(int argc, char *argv[]) +{ + printf("Compile-time settings for %s\n", argv[0]); + printf("Events file: " NC_EVENTS_FILE "\n"); +} + +int main(int argc, char *argv[]) { + + if (argc < 2) { + usage_small(argc, argv); + exit(1); + } + + int opt; + + while ((opt = getopt(argc, argv, ":if:hvsnl")) != -1) { + switch(opt) { + case 'h': + usage(argc, argv); + exit(0); + break; + case 'v': + printf(NC_VERSION "\n"); + exit(0); + break; + case 's': + view_compile_time_settings(argc, argv); + exit(0); + break; + case 'n': + mkevent(argc, argv); + break; + case 'l': + printevents(); + break; + case '?': + usage_small(argc, argv); + exit(1); + break; + } + } + + return 0; +} diff --git a/src/nc.h b/src/nc.h index 752d471..7b3eccd 100644 --- a/src/nc.h +++ b/src/nc.h @@ -1,7 +1,12 @@ #ifndef NC_H_ #define NC_H_ +static void usage(int argc, char *argv[]); +static void usage_small(int argc, char *argv[]); +static void view_compile_time_settings(int argc, char *argv[]); char mkevent(int argc, char *argv[]); char printevents(); +#define NC_VERSION "1.0.0" + #endif diff --git a/src/printevents.c b/src/printevents.c index f1663bf..a3e483d 100644 --- a/src/printevents.c +++ b/src/printevents.c @@ -14,14 +14,14 @@ char printevents() { fp = fopen(NC_EVENTS_FILE, "r"); if (fp == NULL) { - printf(TXT_BOLD COL_RED "events file does not exist\n"); - printf("ensure the events file defined in config.h exists\n" COL_RESET TXT_RESET); + printf(COL_RED "events file does not exist\n"); + printf("ensure the events file defined in config.h exists\n" COL_RESET); exit(1); } time_t t = time(NULL); - printf(TXT_BOLD COL_BLUE "[:=] To do for %s", ctime(&t)); - printf(COL_RESET TXT_RESET "\n"); + printf(COL_BLUE "[:=] To do for %s", ctime(&t)); + printf(COL_RESET"\n"); contents = fgetc(fp); while (contents != EOF) {