Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- static int insn_two_params(char **insn, struct insn_tbl *tbl)
- {
- long number;
- char *nptr = NULL;
- char *p = *insn;
- /*
- * We already have the first register, let us check
- * if is correct.
- */
- if (tolower(*p) != 'r' || *(p+1) < '0' || *(p+1) > '7')
- {
- fprintf(stderr, "file.c:%d: Error: first operand '%c%c' of "
- "instruction '%s' is invalid!\n", 0, *p, *(p+1), tbl->name);
- return (-1);
- }
- p += 2;
- /* Skip white-spaces. */
- while (isblank(*p))
- p++;
- /* Check if separator exists. */
- if (*p != ',')
- {
- fprintf(stderr, "file.c:%d: Error: expected ',' found '%c'\n",
- 0, *p);
- return (-1);
- }
- p++;
- /* Skip white-spaces again. */
- while (isblank(*p))
- p++;
- /*
- * If Reg/Reg
- */
- if (tolower(*p) == 'r')
- {
- if (*(p+1) < '0' || *(p+1) > '7')
- {
- fprintf(stderr, "file.c:%d: Error: second operand '%c%c' of "
- "instruction '%s' is invalid!\n", 0, *p, *(p+1), tbl->name);
- return (-1);
- }
- p += 2;
- /* Do something. */
- /* Skip white-spaces. */
- while (isblank(*p))
- p++;
- /* Check again. */
- if (*p != '#' && *p != ';' && *p != '\n' && *p != '\0')
- {
- fprintf(stderr, "file.c:%d Error: unexpected character (%c)!\n", 0, *p);
- return (-1);
- }
- }
- /* Reg/Imm. */
- else
- {
- nptr = NULL;
- number = strtol(p, &nptr, 0);
- if (p == nptr || errno != 0)
- {
- fprintf(stderr, "file.c:%d Error: second operand of"
- "instruction '%s' is invalid!\n", 0, tbl->name);
- }
- p = nptr;
- /* Skip white-spaces. */
- while (isblank(*p))
- p++;
- /* Check again. */
- if (*p != '#' && *p != ';' && *p != '\n' && *p != '\0')
- {
- fprintf(stderr, "file.c:%d Error: unexpected character (%c)!\n", 0, *p);
- return (-1);
- }
- if (*p == ';')
- p++;
- printf("p inside: %p / num: %ld\n", p, number);
- }
- /* Update the pointer. */
- *insn = p;
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement