-
Notifications
You must be signed in to change notification settings - Fork 3
/
cdata.c
70 lines (67 loc) · 1.89 KB
/
cdata.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
*******************************************************************
*** This software is copyright 2021 by Michael H Riley ***
*** You have permission to use, modify, copy, and distribute ***
*** this software so long as this copyright notice is retained. ***
*** This software may not be used in commercial applications ***
*** without express written permission from the author. ***
*******************************************************************
*/
#include "header.h"
char* cdata(char* line) {
word num;
char neg;
if (passNumber == 1) {
numDataLines++;
if (numDataLines == 1) {
dataLines = (word*)malloc(sizeof(word));
dataPositions = (word*)malloc(sizeof(word));
}
else {
dataLines = (word*)realloc(dataLines, sizeof(word) * numDataLines);
dataPositions = (word*)realloc(dataPositions, sizeof(word) * numDataLines);
}
dataLines[numDataLines-1] = lastLineNumber;
dataPositions[numDataLines-1] = numData;
}
line = trim(line);
while (*line != ':' && *line != 0) {
if ((*line < '0' || *line > '9') && *line != '-') {
showError("Syntax error");
*line = 0;
return line;
}
neg = 0;
num = 0;
if (*line == '-') {
neg = -1;
line++;
}
while (*line >= '0' && *line <= '9') {
num = (num * 10) + (*line - '0');
line++;
}
line = trim(line);
if (*line != ':' && *line != ',' && *line != 0) {
showError("Syntax error");
*line = 0;
return line;
}
if (neg) {
num = (num ^ 0xffff) + 1;
}
if (passNumber == 1) {
numData++;
if (numData == 1)
data = (dword*)malloc(sizeof(dword));
else
data = (dword*)realloc(data, sizeof(dword) * numData);
data[numData-1] = num;
}
if (*line == ',') {
line++;
line = trim(line);
}
}
return line;
}