- if (strlen(operand) == 1) {
- if ( (strchr("ABCXYZIJ", *operand))
- || (strchr("abcxyzij", *operand)) ) {
- DEBUG_NOTIFY("register\n");
- retval = register_enumerate_(*operand);
- goto done;
- }
+ /* this is a very stupid parser */
+
+ /* first, let's trim all whitespace out of string at once to make parsing easier */
+ buf_strip_chars_(operand, " \t\n");
+
+ /* single character might match a register */
+ if (strlen(operand) == 1
+ && strchr("AaBbCcXxYyZzIiJj", *operand)) {
+ DEBUG_PRINTF("is register %c\n", *operand);
+ return register_enumerate_(*operand);
+ }
+
+ /* easy matches */
+ if (strcasecmp(operand, "POP") == 0) {
+ DEBUG_PRINTF("is POP\n");
+ return 0x18;
+ }
+ if (strcasecmp(operand, "PUSH") == 0) {
+ DEBUG_PRINTF("is PUSH\n");
+ return 0x19;
+ }
+ if (strcasecmp(operand, "PEEK") == 0) {
+ DEBUG_PRINTF("is PEEK\n");
+ return 0x1a;
+ }
+ if (strcasecmp(operand, "SP") == 0) {
+ DEBUG_PRINTF("is register SP\n");
+ return 0x1b;
+ }
+ if (strcasecmp(operand, "PC") == 0) {
+ DEBUG_PRINTF("is register PC\n");
+ return 0x1c;
+ }
+ if (strcasecmp(operand, "O") == 0) {
+ DEBUG_PRINTF("is register O\n");
+ return 0x1d;