mips/masm/main.c

53 lines
865 B
C
Raw Normal View History

2024-09-10 22:23:46 +00:00
#include <unistd.h>
#include <merror.h>
#include <string.h>
#include "asm.h"
2024-09-10 22:23:46 +00:00
void help(void) {
printf("usage: masm [options] source.asm\n\n");
printf("options:\n");
printf("\t-h\t\tprints this help message\n");
printf("\t-o <output>\tselect a output file destination\n");
2024-09-10 22:23:46 +00:00
}
int main(int argc, char **argv) {
2024-09-10 22:23:46 +00:00
struct assembler_arguments args = {
.in_file = NULL,
.out_file = "out.o",
2024-09-10 22:23:46 +00:00
};
int c;
2024-09-11 16:06:09 +00:00
while ((c = getopt(argc, argv, "ho:")) != 1) {
2024-09-10 22:23:46 +00:00
switch(c) {
case 'h':
help();
return M_SUCCESS;
case 'o':
args.out_file = optarg;
break;
case '?':
return M_ERROR;
default:
goto next;
}
}
next:
if (optind < argc - 1) {
ERROR("too many source files passed");
return M_ERROR;
}
if (optind >= argc) {
ERROR("no source files passed");
return M_ERROR;
}
args.in_file = argv[optind];
return assemble_file(args);
}