summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-02-06 13:44:42 +0000
committerJoursoir <chat@joursoir.net>2021-02-06 13:44:42 +0000
commitb031f587ce0b6c37de3befef955970d160e90e5a (patch)
tree6590294e05f82e6128ccca491e4db1e0659b24cf
parentb0ff101f2d97cff3ce77af9cc68f55e2bf50e4f5 (diff)
downloadsnc-b031f587ce0b6c37de3befef955970d160e90e5a.tar.gz
snc-b031f587ce0b6c37de3befef955970d160e90e5a.tar.bz2
snc-b031f587ce0b6c37de3befef955970d160e90e5a.zip
add command line arguments handler
-rw-r--r--snc.c65
1 files changed, 57 insertions, 8 deletions
diff --git a/snc.c b/snc.c
index 818bc78..58aea38 100644
--- a/snc.c
+++ b/snc.c
@@ -20,9 +20,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <getopt.h>
#include "snc.h"
+void usage()
+{
+ printf("Simple numbers converter\n"
+ "\n"
+ "Synopsis: snc [OPTION] ... [NUMBER]\n"
+ "Option:\n"
+ "\t-h, --help\n"
+ "\t\tPrint this text.\n"
+ "\t-i, --input\n"
+ "\t\t****\n"
+ "\t-o, --output\n"
+ "\t\t****\n"
+ "\t-a, --alphabet\n"
+ "\t\t****\n"
+ "\t-A, --list-alphabets\n"
+ "\t\t****\n");
+}
+
int getRomanValue(char symbol)
{
switch(symbol) {
@@ -107,14 +126,44 @@ char *arabicToRoman(char *str)
int main(int argc, char *argv[])
{
- if(argc < 2)
- return printf("Simple numbers converter\n"
- "\n"
- "Synopsis: snc [number]\n");
-
- int answer = romanToArabic(argv[1]);
- if(answer == -1) printf("ERROR! %s is not roman number\n", argv[1]);
- else printf("answer: %d\n", answer);
+ if(argc == 1) {
+ usage();
+ return 0;
+ }
+
+ int result;
+ const char short_options[] = "hi:o:a:A";
+ const struct option long_options[] = {
+ {"help", no_argument, NULL, 'h'},
+ {"input", required_argument, NULL, 'i'},
+ {"output", required_argument, NULL, 'o'},
+ {"alphabet", required_argument, NULL, 'a'},
+ {"list-alphabets", required_argument, NULL, 'A'},
+ {NULL, 0, NULL, 0}
+ };
+
+ while((result = getopt_long(argc, argv, short_options,
+ long_options, NULL)) != -1) {
+ switch(result) {
+ case 'h': {
+ usage();
+ return 0;
+ }
+ case 'i': {
+ break;
+ }
+ case 'o': {
+ break;
+ }
+ case 'a': {
+ break;
+ }
+ case 'A': {
+ break;
+ }
+ default: break;
+ }
+ }
return 0;
} \ No newline at end of file