Allows to change case of directives and mnemonics

This commit is contained in:
nanochess 2017-11-06 13:55:00 -06:00
parent e1c0f0bacf
commit f3b66b8a31
2 changed files with 65 additions and 4 deletions

4
README
View File

@ -26,6 +26,10 @@ Arguments:
-n4 Nesting spacing (can be any number -n4 Nesting spacing (can be any number
of spaces or multiple of tab size) of spaces or multiple of tab size)
-l Put labels in its own line -l Put labels in its own line
-dl Change directives to lowercase
-du Change directives to uppercase
-ml Change mnemonics to lowercase
-mu Change mnemonics to uppercase
Assumes all your labels are at start of line and there is space Assumes all your labels are at start of line and there is space
before mnemonic. before mnemonic.

View File

@ -6,7 +6,10 @@
** © Copyright 2017 Oscar Toledo G. ** © Copyright 2017 Oscar Toledo G.
** **
** Creation date: Nov/03/2017. ** Creation date: Nov/03/2017.
** Revision date: Nov/06/2017. Processor selection. Indents nested IF/ENDIF. Tries to preserve vertical structure of comments. Allows label in its own line. ** Revision date: Nov/06/2017. Processor selection. Indents nested IF/ENDIF.
** Tries to preserve vertical structure of comments.
** Allows label in its own line. Allows to change case
** of mnemonics and directives.
*/ */
#include <stdio.h> #include <stdio.h>
@ -174,12 +177,15 @@ int main(int argc, char *argv[])
char *p; char *p;
char *p1; char *p1;
char *p2; char *p2;
char *p3;
int current_column; int current_column;
int request; int request;
int current_level; int current_level;
int prev_comment_original_location; int prev_comment_original_location;
int prev_comment_final_location; int prev_comment_final_location;
int flags; int flags;
int mnemonics_case;
int directives_case;
/* /*
** Show usage if less than 3 arguments (program name counts as one) ** Show usage if less than 3 arguments (program name counts as one)
@ -212,6 +218,10 @@ int main(int argc, char *argv[])
fprintf(stderr, " -n4 Nesting spacing (can be any number\n"); fprintf(stderr, " -n4 Nesting spacing (can be any number\n");
fprintf(stderr, " of spaces or multiple of tab size)\n"); fprintf(stderr, " of spaces or multiple of tab size)\n");
fprintf(stderr, " -l Puts labels in its own line\n"); fprintf(stderr, " -l Puts labels in its own line\n");
fprintf(stderr, " -dl Change directives to lowercase\n");
fprintf(stderr, " -du Change directives to uppercase\n");
fprintf(stderr, " -ml Change mnemonics to lowercase\n");
fprintf(stderr, " -mu Change mnemonics to uppercase\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fprintf(stderr, "Assumes all your labels are at start of line and there is space\n"); fprintf(stderr, "Assumes all your labels are at start of line and there is space\n");
fprintf(stderr, "before mnemonic.\n"); fprintf(stderr, "before mnemonic.\n");
@ -233,6 +243,8 @@ int main(int argc, char *argv[])
align_comment = 1; align_comment = 1;
nesting_space = 4; nesting_space = 4;
labels_own_line = 0; labels_own_line = 0;
mnemonics_case = 0;
directives_case = 0;
/* /*
** Process arguments ** Process arguments
@ -243,7 +255,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Bad argument\n"); fprintf(stderr, "Bad argument\n");
exit(1); exit(1);
} }
switch (argv[c][1]) { switch (tolower(argv[c][1])) {
case 's': /* Style */ case 's': /* Style */
style = atoi(&argv[c][2]); style = atoi(&argv[c][2]);
if (style != 0 && style != 1) { if (style != 0 && style != 1) {
@ -259,7 +271,13 @@ int main(int argc, char *argv[])
} }
break; break;
case 'm': /* Mnemonic start */ case 'm': /* Mnemonic start */
start_mnemonic = atoi(&argv[c][2]); if (tolower(argv[c][2]) == 'l') {
mnemonics_case = 1;
} else if (tolower(argv[c][2]) == 'u') {
mnemonics_case = 2;
} else {
start_mnemonic = atoi(&argv[c][2]);
}
break; break;
case 'o': /* Operand start */ case 'o': /* Operand start */
start_operand = atoi(&argv[c][2]); start_operand = atoi(&argv[c][2]);
@ -283,6 +301,15 @@ int main(int argc, char *argv[])
case 'l': /* Labels in own line */ case 'l': /* Labels in own line */
labels_own_line = 1; labels_own_line = 1;
break; break;
case 'd': /* Directives */
if (tolower(argv[c][2]) == 'l') {
directives_case = 1;
} else if (tolower(argv[c][2]) == 'u') {
directives_case = 2;
} else {
fprintf(stderr, "Unknown argument: %c%c\n", argv[c][1], argv[c][2]);
}
break;
default: /* Other */ default: /* Other */
fprintf(stderr, "Unknown argument: %c\n", argv[c][1]); fprintf(stderr, "Unknown argument: %c\n", argv[c][1]);
exit(1); exit(1);
@ -414,7 +441,7 @@ int main(int argc, char *argv[])
if (processor == 1) { if (processor == 1) {
c = check_opcode(p1, p2); c = check_opcode(p1, p2);
if (c == 0) { if (c == 0) {
request = start_mnemonic; request = start_mnemonic;
} else if (c < 0) { } else if (c < 0) {
request = start_mnemonic; request = start_mnemonic;
} else { } else {
@ -426,6 +453,36 @@ int main(int argc, char *argv[])
} }
} else { } else {
request = start_mnemonic; request = start_mnemonic;
c = 0;
}
if (c <= 0) {
if (mnemonics_case == 1) {
p3 = p1;
while (p3 < p2) {
*p3 = tolower(*p3);
p3++;
}
} else if (mnemonics_case == 2) {
p3 = p1;
while (p3 < p2) {
*p3 = toupper(*p3);
p3++;
}
}
} else {
if (directives_case == 1) {
p3 = p1;
while (p3 < p2) {
*p3 = tolower(*p3);
p3++;
}
} else if (directives_case == 2) {
p3 = p1;
while (p3 < p2) {
*p3 = toupper(*p3);
p3++;
}
}
} }
/* /*