Advertisement
DavidsonDFGL

maybe.c

Aug 22nd, 2020
2,319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. /**
  2.  *
  3.  */
  4. static int insn_two_params(char **insn, struct insn_tbl *tbl)
  5. {
  6.     long number;
  7.     char *nptr = NULL;
  8.     char *p = *insn;
  9.  
  10.     /*
  11.      * We already have the first register, let us check
  12.      * if is correct.
  13.      */
  14.     if (tolower(*p) != 'r' || *(p+1) < '0' || *(p+1) > '7')
  15.     {
  16.         fprintf(stderr, "file.c:%d: Error: first operand '%c%c' of "
  17.             "instruction '%s' is invalid!\n", 0, *p, *(p+1), tbl->name);
  18.         return (-1);
  19.     }
  20.  
  21.     p += 2;
  22.  
  23.     /* Skip white-spaces. */
  24.     while (isblank(*p))
  25.         p++;
  26.  
  27.     /* Check if separator exists. */
  28.     if (*p != ',')
  29.     {
  30.         fprintf(stderr, "file.c:%d: Error: expected ',' found '%c'\n",
  31.             0, *p);
  32.         return (-1);
  33.     }
  34.  
  35.     p++;
  36.  
  37.     /* Skip white-spaces again. */
  38.     while (isblank(*p))
  39.         p++;
  40.  
  41.     /*
  42.      * If Reg/Reg
  43.      */
  44.     if (tolower(*p) == 'r')
  45.     {
  46.         if (*(p+1) < '0' || *(p+1) > '7')
  47.         {
  48.             fprintf(stderr, "file.c:%d: Error: second operand '%c%c' of "
  49.                 "instruction '%s' is invalid!\n", 0, *p, *(p+1), tbl->name);
  50.             return (-1);
  51.         }
  52.  
  53.         p += 2;
  54.  
  55.         /* Do something. */
  56.  
  57.         /* Skip white-spaces. */
  58.         while (isblank(*p))
  59.             p++;
  60.  
  61.         /* Check again. */
  62.         if (*p != '#' && *p != ';' && *p != '\n' && *p != '\0')
  63.         {
  64.             fprintf(stderr, "file.c:%d Error: unexpected character (%c)!\n", 0, *p);
  65.             return (-1);
  66.         }
  67.     }
  68.  
  69.     /* Reg/Imm. */
  70.     else
  71.     {
  72.         nptr = NULL;
  73.         number = strtol(p, &nptr, 0);
  74.         if (p == nptr || errno != 0)
  75.         {
  76.             fprintf(stderr, "file.c:%d Error: second operand of"
  77.                 "instruction '%s' is invalid!\n", 0, tbl->name);
  78.         }
  79.  
  80.         p = nptr;
  81.  
  82.         /* Skip white-spaces. */
  83.         while (isblank(*p))
  84.             p++;
  85.  
  86.         /* Check again. */
  87.         if (*p != '#' && *p != ';' && *p != '\n' && *p != '\0')
  88.         {
  89.             fprintf(stderr, "file.c:%d Error: unexpected character (%c)!\n", 0, *p);
  90.             return (-1);
  91.         }
  92.  
  93.         if (*p == ';')
  94.             p++;
  95.  
  96.         printf("p inside: %p / num: %ld\n", p, number);
  97.     }
  98.  
  99.     /* Update the pointer. */
  100.     *insn = p;
  101.  
  102.     return (0);
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement