52 lines
865 B
C
52 lines
865 B
C
#include <unistd.h>
|
|
#include <merror.h>
|
|
#include <string.h>
|
|
|
|
#include "asm.h"
|
|
|
|
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) {
|
|
|
|
struct assembler_arguments args = {
|
|
.in_file = NULL,
|
|
.out_file = "out.o",
|
|
};
|
|
|
|
int c;
|
|
|
|
while ((c = getopt(argc, argv, "ho:")) != 1) {
|
|
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);
|
|
}
|