42 lines
704 B
C
42 lines
704 B
C
/*
|
|
* 65b2js.c
|
|
*
|
|
* Created on: May 19, 2011
|
|
* Author: Scott Duensing
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
if (argc != 2) {
|
|
printf("usage: %s filename\n", argv[0]);
|
|
return 1;
|
|
} else {
|
|
FILE *file = fopen(argv[1], "r");
|
|
if (file == 0) {
|
|
printf("Could not open file\n");
|
|
return 2;
|
|
} else {
|
|
int c;
|
|
int count = 0;
|
|
int first = 1;
|
|
printf("var PROGRAM = [\n");
|
|
while ((c = fgetc(file)) != EOF) {
|
|
if (first == 1)
|
|
first = 0;
|
|
else
|
|
printf(", ");
|
|
if (++count > 15) {
|
|
printf("\n");
|
|
count = 0;
|
|
}
|
|
printf("0x%02x", c);
|
|
}
|
|
if (count != 0)
|
|
printf("\n");
|
|
printf("];\n");
|
|
fclose(file);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|