Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tadd committed Jan 29, 2025
1 parent 6385e79 commit cc1170f
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ static void opt_error(const char *fmt, ...)
}

typedef struct {
const char *path;
const char *script;
const char *src;
bool script;
bool print;
bool parse_only;
bool cputime;
Expand All @@ -45,18 +45,18 @@ typedef struct {
static Option parse_opt(int argc, char *const *argv)
{
Option o = {
.path = NULL,
.script = NULL,
.src = NULL,
.script = false,
.print = false,
.parse_only = false,
.cputime = false,
.memory = false,
};
int opt;
while ((opt = getopt(argc, argv, "e:hPpTM")) != -1) {
while ((opt = getopt(argc, argv, "ehPpTM")) != -1) {
switch (opt) {
case 'e':
o.script = optarg;
o.script = true;
break;
case 'h':
usage(stdout);
Expand All @@ -76,11 +76,9 @@ static Option parse_opt(int argc, char *const *argv)
usage(stderr);
}
}
o.path = argv[optind];
if (o.path == NULL && o.script == NULL)
o.src = argv[optind];
if (o.src == NULL)
opt_error("no program provided");
if (o.path != NULL && o.script != NULL)
opt_error("filename %s given while option '-e' passed", o.path);
return o;
}

Expand Down Expand Up @@ -117,9 +115,9 @@ int main(int argc, char **argv)
Option o = parse_opt(argc, argv);
Value v;
if (o.parse_only)
v = o.script ? parse_string(o.script) : parse(o.path);
v = o.script ? parse_string(o.src) : parse(o.src);
else
v = o.script ? eval_string(o.script) : load(o.path);
v = o.script ? eval_string(o.src) : load(o.src);
if (v == Qundef)
error("%s", error_message());
if (o.print) {
Expand Down

0 comments on commit cc1170f

Please sign in to comment.