OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [Open8 Tools/] [open8_src/] [open8_link/] [parse.c] - Blame information for rev 289

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 178 jshamlet
 
2
#include <ctype.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
 
7
#include "defines.h"
8
 
9
 
10
 
11
int get_next_token(char *in, char *out, int *pos) {
12
 
13
  int i, t;
14
 
15
 
16
  /* skip white space */
17
  for (i = 0; in[i] == ' ' || in[i] == 0x09; i++);
18
  if (in[i] == 0)
19
    return FAILED;
20
 
21
  for (t = 0; in[i] != ' ' && in[i] != 0x09 && in[i] != 0; i++, t++)
22
    out[t] = in[i];
23
 
24
  out[t] = 0;
25
  *pos += i;
26
 
27
  return SUCCEEDED;
28
}
29
 
30
 
31
int get_next_number(char *in, int *out, int *pos) {
32
 
33
  int i, o, n;
34
 
35
 
36
  /* skip white space */
37
  for (i = 0; in[i] == ' ' || in[i] == 0x09; i++);
38
  if (in[i] == 0)
39
    return FAILED;
40
 
41
  if (in[i] >= '0' && in[i] <= '9') {
42
    /* is it hex after all? */
43
    n = 0;
44
    for (o = 0; 1; o++) {
45
      if (in[i+o] >= '0' && in[i+o] <= '9')
46
        continue;
47
      if (in[i+o] >= 'a' && in[i+o] <= 'f') {
48
        n = 1;
49
        break;
50
      }
51
      if (in[i+o] >= 'A' && in[i+o] <= 'F') {
52
        n = 1;
53
        break;
54
      }
55
      if (in[i+o] == 'h' || in[i+o] == 'H') {
56
        n = 1;
57
        break;
58
      }
59
      break;
60
    }
61
 
62
    if (n == 1) {
63
      /* hex */
64
      o = 0;
65
      while (TRUE) {
66
        if (in[i] >= '0' && in[i] <= '9')
67
          o = (o * 16) + in[i] - '0';
68
        else if (in[i] >= 'a' && in[i] <= 'f')
69
          o = (o * 16) + in[i] - 'a' + 0xA;
70
        else if (in[i] >= 'A' && in[i] <= 'F')
71
          o = (o * 16) + in[i] - 'A' + 0xA;
72
        else if (in[i] == 'h' || in[i] == 'H')
73
          break;
74
        else if (in[i] == ' ' || in[i] == 0x09 || in[i] == 0)
75
          break;
76
        else
77
          return FAILED;
78
        i++;
79
      }
80
    }
81
    else {
82
      /* decimal */
83
      for (o = 0; in[i] >= '0' && in[i] <= '9'; i++)
84
        o = (o * 10) + in[i] - '0';
85
      if (!(in[i] == ' ' || in[i] == 0x09 || in[i] == 0))
86
        return FAILED;
87
    }
88
  }
89
  else if (in[i] == '$') {
90
    i++;
91
    o = 0;
92
    while (TRUE) {
93
      if (in[i] >= '0' && in[i] <= '9')
94
        o = (o * 16) + in[i] - '0';
95
      else if (in[i] >= 'a' && in[i] <= 'f')
96
        o = (o * 16) + in[i] - 'a' + 0xA;
97
      else if (in[i] >= 'A' && in[i] <= 'F')
98
        o = (o * 16) + in[i] - 'A' + 0xA;
99
      else if (in[i] == ' ' || in[i] == 0x09 || in[i] == 0)
100
        break;
101
      else
102
        return FAILED;
103
      i++;
104
    }
105
  }
106
  else
107
    return FAILED;
108
 
109
  *out = o;
110
  *pos += i;
111
 
112
  return SUCCEEDED;
113
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.