Debian Codegraph @

skycpt/cpthelp.cpp

raw
1 #include "stdafx.h"
2 #include "cpthelp.h"
3
4 void assertEmpty(CptObj *cpt) {
5 assert((cpt->len == 0) && (cpt->data == NULL) && (cpt->dbgName == NULL) && (cpt->type == 0));
6 }
7
8 uint16 getInfo(char *line, char *type, char *nameDest) {
9 assert(*line == '\t');
10 line++;
11 assert(!memcmp(line, type, strlen(type)));
12 line += strlen(type);
13 assert((line[0] == ':') && (line[1] == ':'));
14 line += 2;
15 char *stopCh;
16 uint16 res = (uint16)strtoul(line, &stopCh, 16);
17 assert(line != stopCh);
18 assert((stopCh[0] == ':') && (stopCh[1] == ':'));
19 stopCh += 2;
20 strcpy(nameDest, stopCh);
21 assert(strlen(nameDest) < 32);
22 assert(res);
23 return res;
24 }
25
26 void dofgets(char *dest, int len, FILE *inf) {
27 fgets(dest, len, inf);
28 while (*dest)
29 if ((*dest == 0xA) || (*dest == 0xD))
30 *dest = '\0';
31 else
32 dest++;
33 }
34
35 bool lineMatchSection(char *line, char *sec) {
36 if (memcmp(line, "SECTION::", 9))
37 return false;
38 if (memcmp(line + 9, sec, strlen(sec)))
39 return false;
40 return true;
41 }
42
43 bool isEndOfSection(char *line) {
44 if (strcmp(line, "SECTION::ENDS"))
45 return false;
46 return true;
47 }
48
49 bool isEndOfObject(char *line, char *type, uint16 id) {
50 if (*line != '\t')
51 return false;
52 line++;
53 if (memcmp(line, type, strlen(type)))
54 return false;
55 line += strlen(type);
56 if ((line[0] != ':') || (line[1] != ':'))
57 return false;
58 line += 2;
59 char *stopCh;
60 uint16 idVal = (uint16)strtoul(line, &stopCh, 16);
61 assert(stopCh != line);
62 if (strcmp(stopCh, "::ENDS"))
63 return false;
64 assert(id == idVal);
65 return true;
66 }