mips/masm/main.c

57 lines
921 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");
}
int main(int argc, char **argv) {
2024-09-10 22:23:46 +00:00
struct assembler_arguments args = {
.in_file = NULL,
.out_file = NULL,
};
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];
if (args.out_file == NULL) {
args.out_file = "out.o";
}
2024-09-10 22:23:46 +00:00
return assemble_file(args);
}