From 392eb61e519a602b99d6d0c1245666eb2b928c08 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 24 Oct 2013 19:06:31 +0900 Subject: [PATCH] show help with command line arg -h --- tools/main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/main.c b/tools/main.c index f5484550..0cbf46ff 100644 --- a/tools/main.c +++ b/tools/main.c @@ -1,4 +1,5 @@ #include +#include #include "picrin.h" @@ -12,6 +13,34 @@ #define CODE_MAX_LENGTH 1024 #define LINE_MAX_LENGTH 256 +void +print_help(void) +{ + const char *help = + "picrin scheme\n" + "\n" + "Usage: picrin [options]\n" + "\n" + "Options:\n" + " -h show this help"; + + puts(help); +} + +void +parse_opt(int argc, char *argv[]) +{ + int r; + + while (~(r = getopt(argc, argv, "h"))) { + switch (r) { + case 'h': + print_help(); + exit(0); + } + } +} + int main(int argc, char *argv[], char **envp) { @@ -28,6 +57,8 @@ main(int argc, char *argv[], char **envp) int char_index; #endif + parse_opt(argc, argv); + pic = pic_open(argc, argv, envp); ai = pic_gc_arena_preserve(pic);