nc v1.0.0
This commit is contained in:
parent
b68779f516
commit
a57f1badbe
6
Makefile
6
Makefile
@ -1,10 +1,10 @@
|
|||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
all: src/main.c src/printevents.c src/mkevent.c
|
all: src/nc.c src/printevents.c src/mkevent.c
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -c src/main.c -o src/main.o
|
$(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/printevents.c -o src/printevents.o
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -c src/mkevent.c -o src/mkevent.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
|
||||||
install src/nc $(PREFIX)/bin
|
install src/nc $(PREFIX)/bin
|
||||||
|
@ -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
|
|
35
src/main.c
35
src/main.c
@ -1,35 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
95
src/nc.c
Normal file
95
src/nc.c
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libcolor.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
5
src/nc.h
5
src/nc.h
@ -1,7 +1,12 @@
|
|||||||
#ifndef NC_H_
|
#ifndef NC_H_
|
||||||
#define 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 mkevent(int argc, char *argv[]);
|
||||||
char printevents();
|
char printevents();
|
||||||
|
|
||||||
|
#define NC_VERSION "1.0.0"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,14 +14,14 @@ char printevents() {
|
|||||||
|
|
||||||
fp = fopen(NC_EVENTS_FILE, "r");
|
fp = fopen(NC_EVENTS_FILE, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
printf(TXT_BOLD COL_RED "events file does not exist\n");
|
printf(COL_RED "events file does not exist\n");
|
||||||
printf("ensure the events file defined in config.h exists\n" COL_RESET TXT_RESET);
|
printf("ensure the events file defined in config.h exists\n" COL_RESET);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
printf(TXT_BOLD COL_BLUE "[:=] To do for %s", ctime(&t));
|
printf(COL_BLUE "[:=] To do for %s", ctime(&t));
|
||||||
printf(COL_RESET TXT_RESET "\n");
|
printf(COL_RESET"\n");
|
||||||
|
|
||||||
contents = fgetc(fp);
|
contents = fgetc(fp);
|
||||||
while (contents != EOF) {
|
while (contents != EOF) {
|
||||||
|
Loading…
Reference in New Issue
Block a user