hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 22:30:59 +0200
committerhachem <im@hachem.wtf>2026-09-19 22:30:59 +0200
commit612d65d57f5287094f363b77df9f90eb645eb266 (patch)
treea4936cdce6ff2d22feb4ad55d4b8331e5d28c568 /main.c
parent4bcc54914d059e950cab79164fb13ed67376ee5d (diff)
feat: add version/helpHEADmain
Diffstat (limited to 'main.c')
-rw-r--r--main.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/main.c b/main.c
index db2c879..a3d1caa 100644
--- a/main.c
+++ b/main.c
@@ -1,9 +1,13 @@
+#include <stdbool.h>
#include <stdio.h>
+#include <string.h>
#include "ast.h"
#include "eval.h"
#include "lexer.h"
+#define VERSION "0.1.0"
+
extern struct Node* program_root;
int yyparse(void);
@@ -24,14 +28,49 @@ static int run_program(void)
return status;
}
+static void print_usage(FILE* stream)
+{
+ (void)fprintf(stream,
+ "usage: sfinae <file.sfinae>\n"
+ " sfinae [-v | -h]\n");
+}
+
+static void print_help(void)
+{
+ (void)printf("sfinae " VERSION " - substitution failure is not an error\n\n"
+ "a toy language inspired by c++ template meta programming\n\n");
+ print_usage(stdout);
+ (void)printf("\noptions:\n"
+ " -v, --version print version\n"
+ " -h, --help print this\n\n"
+ "by hachem <im@hachem.wtf>\n");
+}
+
+static bool is_flag(const char* argument, const char* brief, const char* full)
+{
+ return strcmp(argument, brief) == 0 || strcmp(argument, full) == 0;
+}
+
int main(int argc, char** argv)
{
if (argc != 2)
{
- (void)fprintf(stderr, "usage: sfinae <file.sfinae>\n");
+ print_usage(stderr);
return 2;
}
+ if (is_flag(argv[1], "-h", "--help"))
+ {
+ print_help();
+ return 0;
+ }
+
+ if (is_flag(argv[1], "-v", "--version"))
+ {
+ (void)printf("sfinae " VERSION "\n");
+ return 0;
+ }
+
yyin = fopen(argv[1], "r");
if (yyin == NULL)
{