swissChili | 97b5d8b | 2020-08-15 20:00:54 -0700 | [diff] [blame] | 1 | #include "as.h" |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <bits/getopt_core.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | int main(int argc, char **argv) |
| 9 | { |
| 10 | char c; |
| 11 | FILE *in = stdin, |
| 12 | *out = stdout; |
| 13 | |
| 14 | while ((c = getopt(argc, argv, "i:o:")) != -1) |
| 15 | { |
| 16 | switch (c) |
| 17 | { |
| 18 | case 'i': |
| 19 | in = fopen(optarg, "r"); |
| 20 | break; |
| 21 | case 'o': |
| 22 | out = fopen(optarg, "w"); |
| 23 | break; |
| 24 | case 'h': |
| 25 | case '?': |
| 26 | printf("6502 assembler\n" |
| 27 | "Usage:\n" |
| 28 | " -i <input> set input file (default stdin)\n" |
| 29 | " -o <output> set output file (default stdout)\n"); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | fseek(in, 0, SEEK_END); |
| 34 | ssize_t len = ftell(in); |
| 35 | fseek(in, 0, SEEK_SET); |
| 36 | |
| 37 | char *text = malloc(len + 1); |
| 38 | fread(text, len, 1, in); |
| 39 | text[len] = 0; |
| 40 | |
| 41 | uint32_t built = assemble(text, out); |
| 42 | |
| 43 | free(text); |
| 44 | } |