commit 09ac5574897529ff957a84f1884e3de160550e43
parent 10cac72f8ed0cc08849a9f776af7ec1aa57c6c0b
Author: Frederic Cambus <fcambus@users.sourceforge.net>
Date: Wed, 17 Jun 2015 22:48:32 +0200
Initial getopt support and allowing '-v' flag to print version number
Diffstat:
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/logswan.c b/src/logswan.c
@@ -4,7 +4,7 @@
/* https://github.com/fcambus/logswan */
/* */
/* Created: 2015/05/31 */
-/* Last Updated: 2015/06/11 */
+/* Last Updated: 2015/06/17 */
/* */
/* Logswan is released under the BSD 3-Clause license. */
/* See LICENSE file for details. */
@@ -15,12 +15,14 @@
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <getopt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#define VERSION "Logswan"
#define LINE_MAX_LENGTH 4096
clock_t begin, end;
@@ -45,6 +47,7 @@ struct stat logFileSize;
FILE *logFile;
char *endptr;
+int getoptFlag;
int main (int argc, char *argv[]) {
printf("-------------------------------------------------------------------------------\n" \
@@ -56,6 +59,14 @@ int main (int argc, char *argv[]) {
return EXIT_FAILURE;
}
+ while ((getoptFlag = getopt(argc, argv, "v")) != -1) {
+ switch(getoptFlag) {
+ case 'v':
+ printf(VERSION);
+ return 0;
+ }
+ }
+
/* Starting timer */
begin = clock();