чување 1996daf34997281d76b186508c439029c318796c
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Wed, 16 Sep 2020 18:36:52 +0200
Initial commit
Diffstat:
измењених датотека: 5, додавања: 109(+), брисања: 0(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,5 @@
+*~
+*.bak
+*.orig
+*.rej
+*.o
diff --git a/Makefile b/Makefile
@@ -0,0 +1,9 @@
+all: table
+
+table: table.o
+
+clean: table.o table
+ rm table.o table 2>/dev/null
+
+.PHONY: clean all
+
diff --git a/defs.h b/defs.h
@@ -0,0 +1,13 @@
+#ifndef __DEFS_H
+#define __DEFS_H
+
+#define PROGRAMNAME "table"
+#define VERSION "0.1"
+
+#define BUFSIZE 4096
+
+#define CMD_NONE 0
+#define CMD_VERSION 1
+
+#endif
+
diff --git a/table b/table
Бинарне датотеке се разликују.
diff --git a/table.c b/table.c
@@ -0,0 +1,82 @@
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include "defs.h"
+
+int
+version()
+{
+ printf("%s v%s\n", PROGRAMNAME, VERSION);
+ return 0;
+}
+
+int
+usage()
+{
+ printf("Usage: %s [-v|--version]\n", PROGRAMNAME);
+ return 0;
+}
+
+int
+error(int code, char *fmt, ...)
+{
+ char buf[BUFSIZE];
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, args);
+ va_end(args);
+ fprintf(stderr, "%s: %s", PROGRAMNAME, buf);
+ return code;
+}
+
+int
+main(int argc, char **argv)
+{
+ if (argc == 1)
+ {
+ return usage();
+ }
+
+ char *arg;
+ int cmd = CMD_NONE;
+ while (arg = *argv++) {
+ if (*arg++ == '-')
+ {
+ char c = *arg++;
+ if (c == '-')
+ {
+ if (!strcmp(arg, "version"))
+ {
+ cmd = CMD_VERSION;
+ }
+ else
+ {
+ error(1, "Invalid argument: --%s\n", arg);
+ return usage();
+ }
+ }
+ else
+ {
+ switch (c)
+ {
+ case 'v':
+ cmd = CMD_VERSION;
+ break;
+ default:
+ error(1, "Invalid argument: -%c\n", c);
+ return usage();
+ }
+ }
+ }
+ arg++;
+ }
+
+ if (cmd == CMD_VERSION)
+ {
+ return version();
+ }
+
+ error(2, "Invalid arguments\n");
+ return usage();
+}
+