almost done
This commit is contained in:
33
src/main.c
33
src/main.c
@@ -1,17 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../include/argparse.h"
|
||||
int main(int argc, char *argv[]) {
|
||||
int opt;
|
||||
|
||||
static const char *const usages[] = {
|
||||
"nc -c -r DATE EVENT_NAME",
|
||||
NULL,
|
||||
};
|
||||
while ((opt = getopt(argc, argv, ":if:nl")) != -1) {
|
||||
switch(opt) {
|
||||
case 'n':
|
||||
mkevent();
|
||||
break;
|
||||
case 'l':
|
||||
printevents();
|
||||
break;
|
||||
case '?':
|
||||
printf("unknown option: %c\n", optopt);
|
||||
printf("usage: %c -l -n DATE EVENT_NAME\n", argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define PERM_READ (1<<0)
|
||||
#define PERM_WRITE (1<<1)
|
||||
#define PERM_EXEC (1<<2)
|
||||
for (; optind < argc; optind++) {
|
||||
printf("extra arguments: %s\n", argv[optind]);
|
||||
}
|
||||
|
||||
int main (int argc, const char **argv) {
|
||||
int
|
||||
return 0;
|
||||
}
|
||||
|
||||
51
src/main.c.old
Normal file
51
src/main.c.old
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h> /* for printf */
|
||||
#include <stdlib.h> /* for exit */
|
||||
#include <unistd.h> /* for getopt */
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
int digit_optind = 0;
|
||||
int aopt = 0, bopt = 0;
|
||||
char *copt = 0, *dopt = 0;
|
||||
while ((c = getopt(argc, argv, "abc:d:012")) != -1) {
|
||||
int this_option_optind = optind ? optind : 1;
|
||||
switch (c) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
if (digit_optind != 0 && digit_optind != this_option_optind) {
|
||||
printf ("digits occur in two different argv-elements.\n");
|
||||
}
|
||||
digit_optind = this_option_optind;
|
||||
printf ("option %c\n", c);
|
||||
break;
|
||||
case 'a':
|
||||
printf ("option a\n");
|
||||
aopt = 1;
|
||||
break;
|
||||
case 'b':
|
||||
printf ("option b\n");
|
||||
bopt = 1;
|
||||
break;
|
||||
case 'c':
|
||||
printf ("option c with value '%s'\n", optarg);
|
||||
copt = optarg;
|
||||
break;
|
||||
case 'd':
|
||||
printf ("option d with value '%s'\n", optarg);
|
||||
dopt = optarg;
|
||||
break;
|
||||
case '?':
|
||||
break;
|
||||
default:
|
||||
printf ("?? getopt returned character code 0%o ??\n", c);
|
||||
}
|
||||
}
|
||||
if (optind < argc) {
|
||||
printf ("non-option ARGV-elements: ");
|
||||
while (optind < argc) {
|
||||
printf ("%s ", argv[optind++]);
|
||||
}
|
||||
printf ("\n");
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
@@ -5,3 +5,17 @@
|
||||
#include "../include/libcolor.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
char mkevent(int argc, char *argv[]) {
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(NC_EVENTS_FILE, "a+");
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
fprintf(fp, "%s", argv[2]); /* print date */
|
||||
fprintf(fp, "%s", argv[3]); /* print name */
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user