/*
- * Copyright (C) 2012
+ * Copyright (C) 2012
* Dale Weiler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* SOFTWARE.
*/
#include "gmqcc.h"
+
+static const char *output = "progs.dat";
+static const char *input = NULL;
+
+#define OptReq(opt, body) \
+ case opt: \
+ if (argv[0][2]) argarg = argv[0]+2; \
+ else { \
+ if (argc < 2) { \
+ printf("option -%c requires an argument\n", opt); \
+ exit(1); \
+ } \
+ argarg = argv[1]; \
+ --argc; \
+ ++argv; \
+ } \
+ do { body } while (0); \
+ break;
+
+#define LongReq(opt, body) \
+ if (!strcmp(argv[0], opt)) { \
+ if (argc < 2) { \
+ printf("option " opt " requires an argument\n"); \
+ exit(1); \
+ } \
+ argarg = argv[1]; \
+ --argc; \
+ ++argv; \
+ do { body } while (0); \
+ break; \
+ } else if (!strncmp(argv[0], opt "=", sizeof(opt "="))) \
+ { \
+ argarg = argv[0] + sizeof(opt "="); \
+ do { body } while (0); \
+ break; \
+ }
+
+bool parser_compile(const char *filename, const char *datfile);
int main(int argc, char **argv) {
- argc--;
- argv++;
-
- //const char *ifile = argv[0];
- FILE *fp;
-
- /*TODO: proper interface swith switches*/
-
- asm_init ("test.qs", &fp);
- asm_parse(fp);
- asm_close(fp);
+ const char *argarg;
+ char opt;
+
+ util_debug("COM", "starting ...\n");
+
+ --argc;
+ ++argv;
+ while (argc > 0) {
+ if (argv[0][0] == '-') {
+ opt = argv[0][1];
+ switch (opt)
+ {
+ OptReq('o', output = argarg; );
+ case '-':
+ LongReq("--output", output = argarg; );
+ default:
+ printf("Unrecognized option: %s\n", argv[0]);
+ break;
+ }
+ }
+ else
+ {
+ if (input) {
+ printf("Onlyh 1 input file allowed\n");
+ exit(1);
+ }
+ input = argv[0];
+ }
+ --argc;
+ ++argv;
+ }
+
+ if (!input) {
+ printf("must specify an input file\n");
+ }
+
+ if (!parser_compile(input, output)) {
+ printf("There were compile errors\n");
+ }
+
+ util_debug("COM", "cleaning ...\n");
+
+ util_meminfo();
return 0;
}