@@ 1,5 1,5 @@
/* Lin6
- Version 1.0
+ Version 1.1
https://wiki.xxiivv.com/lin6
*/
@@ 29,7 29,8 @@
#include <stdlib.h>
#include <string.h>
-#define VERSION "1.0"
+#define VERSION "1.1"
+#define BUFLEN 256
char *OPCODES[] = {"ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI",
"BNE", "BPL", "BRK", "BVC", "BVS", "CLC", "CLD", "CLI",
@@ 258,9 259,9 @@ void lint(char *filepath, char *output, bool do_debug) {
int id = 0, len, count = 0, opcodes = 0, directives = 0, spacers = 0,
labels = 0, variables = 0, constants = 0, comments = 0;
bool skipped_last = false;
- char line[128];
- char trimed[128];
- while (fgets(line, 128, fr)) {
+ char line[BUFLEN];
+ char trimed[BUFLEN];
+ while (fgets(line, BUFLEN, fr)) {
id++;
trimstr(line, trimed);
swapcstr(trimed, '\t', ' ');
@@ 269,12 270,13 @@ void lint(char *filepath, char *output, bool do_debug) {
continue;
}
if (is_label(trimed)) {
- char key[80];
- char comment[80];
+ char key[BUFLEN];
+ char comment[BUFLEN];
set_line_key(trimed, key);
set_line_comment(trimed, comment);
if (!is_capital(key)) {
- printf("Error: Label %s is not capitalized, at line %d.\n", key, id);
+ printf("Error: Label %s is not capitalized, at %s:%d.\n", key, filepath,
+ id);
fclose(fr);
exit(0);
}
@@ 292,9 294,9 @@ void lint(char *filepath, char *output, bool do_debug) {
skipped_last = false;
labels++;
} else if (is_opcode(trimed)) {
- char key[80];
- char value[80];
- char comment[80];
+ char key[BUFLEN];
+ char value[BUFLEN];
+ char comment[BUFLEN];
set_line_key(trimed, key);
set_line_value(trimed, value);
set_line_comment(trimed, comment);
@@ 313,9 315,9 @@ void lint(char *filepath, char *output, bool do_debug) {
skipped_last = false;
opcodes++;
} else if (is_directive(trimed)) {
- char key[80];
- char value[80];
- char comment[80];
+ char key[BUFLEN];
+ char value[BUFLEN];
+ char comment[BUFLEN];
set_line_key(trimed, key);
set_line_value(trimed, value);
set_line_comment(trimed, comment);
@@ 344,15 346,16 @@ void lint(char *filepath, char *output, bool do_debug) {
skipped_last = true;
spacers++;
} else if (is_variable(trimed)) {
- char key[80];
- char value[80];
- char comment[80];
+ char key[BUFLEN];
+ char value[BUFLEN];
+ char comment[BUFLEN];
set_line_key(trimed, key);
set_line_value(trimed, value);
set_line_comment(trimed, comment);
fillstr(key, 24, ' ');
if (!is_lower(key)) {
- printf("Error: Variable %s is not lowercase, at line %d.\n", key, id);
+ printf("Error: Variable %s is not lowercase, at %s:%d.\n", key,
+ filepath, id);
fclose(fr);
exit(0);
}
@@ 363,15 366,16 @@ void lint(char *filepath, char *output, bool do_debug) {
skipped_last = false;
variables++;
} else if (is_constant(trimed)) {
- char key[80];
- char value[80];
- char comment[80];
+ char key[BUFLEN];
+ char value[BUFLEN];
+ char comment[BUFLEN];
set_line_key(trimed, key);
set_line_value(trimed, value);
set_line_comment(trimed, comment);
fillstr(key, 20, ' ');
if (!is_upper(key)) {
- printf("Error: Constant %s is not uppercase, at line %d.\n", key, id);
+ printf("Error: Constant %s is not uppercase, at %s:%d.\n", key,
+ filepath, id);
fclose(fr);
exit(0);
}
@@ 382,7 386,7 @@ void lint(char *filepath, char *output, bool do_debug) {
skipped_last = false;
constants++;
} else {
- printf("Error: Unknown line-type[%s], at line %d.\n", trimed, id);
+ printf("Error: Unknown line-type, at %s:%d.\n", filepath, id);
fclose(fr);
exit(0);
}
@@ 408,16 412,16 @@ void show_help() {
puts("");
puts("A tool to format 6502 assembly code.\n");
puts("Usage: Lin6 [-options] [<file> ...]\n");
- puts(" -? Show this help");
- puts(" -v Show version");
- puts(" -i Inplace edit files");
- puts(" -d Show debug\n");
+ puts("\t-?\tShow this help");
+ puts("\t-v\tShow version");
+ puts("\t-i\tInplace edit files");
+ puts("\t-d\tShow debug\n");
puts("See README for more info.\n");
}
int main(int argc, char *argv[]) {
bool do_debug = false, do_inplace = false;
- int i;
+ int i;
if (argc < 2) {
show_help();
exit(0);
@@ 438,7 442,7 @@ int main(int argc, char *argv[]) {
}
/* do files */
else {
- char linted[4096];
+ char linted[32768];
if (!file_exists(argv[i])) {
printf("Error! File %s not found\n", argv[i]);
exit(0);