1 | /*
|
---|
2 | Copyright (C) 1996
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
17 |
|
---|
18 | The author can be contacted via Email at [email protected]
|
---|
19 | */
|
---|
20 | #include <windows.h>
|
---|
21 | #include <stdlib.h>
|
---|
22 | #include <stdio.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <memory.h>
|
---|
25 | #pragma hdrstop
|
---|
26 |
|
---|
27 | #include "parse.h"
|
---|
28 |
|
---|
29 | //Public Functions
|
---|
30 | /******************************************************************************/
|
---|
31 | void Left(char *DestStr, const char *SourceStr, const int Len) {
|
---|
32 | memcpy(DestStr, SourceStr, Len);
|
---|
33 | DestStr[Len] = 0;
|
---|
34 | }
|
---|
35 | /******************************************************************************/
|
---|
36 | void Right(char *DestStr, const char *SourceStr, const int Len) {
|
---|
37 | int SourceLen, Offset;
|
---|
38 |
|
---|
39 | SourceLen = strlen(SourceStr);
|
---|
40 | Offset = SourceLen - Len;
|
---|
41 |
|
---|
42 | memcpy(DestStr, SourceStr + Offset, Len + 1);
|
---|
43 | //The null is already copied
|
---|
44 | }
|
---|
45 | /******************************************************************************/
|
---|
46 | void TrimLeft(char *TargetStr) {
|
---|
47 | int i, NewStrSize;
|
---|
48 |
|
---|
49 | i = 0;
|
---|
50 | //Find the first non-space charactor
|
---|
51 | while ( (TargetStr[i] == ' ') || (TargetStr[i] == '\t') ) {
|
---|
52 | i++;
|
---|
53 | }
|
---|
54 | //If we have space to get rid of, move the string
|
---|
55 | if (i > 0) {
|
---|
56 | NewStrSize = strlen(TargetStr) - i + 1; //Include the NULL in the size
|
---|
57 | memmove(TargetStr, TargetStr + i, NewStrSize);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | /******************************************************************************/
|
---|
61 | void TrimRight(char *TargetStr) {
|
---|
62 | int i;
|
---|
63 |
|
---|
64 | //Find the last non-space charactor (index i)
|
---|
65 | i = strlen(TargetStr) - 1;
|
---|
66 | while ((i >= 0) && ((TargetStr[i] == ' ') || (TargetStr[i] == '\t')) ) {
|
---|
67 | i--;
|
---|
68 | }
|
---|
69 | //Set the NULL 1 after the last non-space charactor
|
---|
70 | TargetStr[i+1] = 0;
|
---|
71 | }
|
---|
72 | /******************************************************************************/
|
---|
73 | void Trim(char *TargetStr) {
|
---|
74 | TrimRight(TargetStr);
|
---|
75 | TrimLeft(TargetStr);
|
---|
76 | }
|
---|
77 | /******************************************************************************/
|
---|
78 | void GetWord(char *DestStr, const char *SourceStr, const int Start, int &End) {
|
---|
79 | int i, Len;
|
---|
80 |
|
---|
81 | Len = 0;
|
---|
82 | i = Start;
|
---|
83 | while ((SourceStr[i] != ' ') && (SourceStr[i] != '\t') && (SourceStr[i] != 0)) {
|
---|
84 | Len++;
|
---|
85 | i++;
|
---|
86 | }
|
---|
87 | //Create the substring
|
---|
88 | memcpy(DestStr, SourceStr + Start, Len);
|
---|
89 | DestStr[Len] = 0;
|
---|
90 | //Set End
|
---|
91 | while ((SourceStr[i] != 0) &&
|
---|
92 | ((SourceStr[i] == ' ') || (SourceStr[i] == '\t'))) {
|
---|
93 | i ++;
|
---|
94 | }
|
---|
95 | End = i;
|
---|
96 | }
|
---|
97 | /******************************************************************************/
|
---|
98 | void GetLastWord(char *DestString, const char *SourceStr, int &Start) {
|
---|
99 | int SourceLen, i, Len;
|
---|
100 |
|
---|
101 | Len = 0;
|
---|
102 | SourceLen = strlen(SourceStr);
|
---|
103 | i = SourceLen - 1;
|
---|
104 | while ((i >= 0) && (SourceStr[i] != ' ') && (SourceStr[i] != '\t')) {
|
---|
105 | Len++;
|
---|
106 | i--;
|
---|
107 | }
|
---|
108 | //Create the substring
|
---|
109 | memcpy(DestString, SourceStr + SourceLen - Len, Len);
|
---|
110 | DestString[Len] = 0;
|
---|
111 | Start = i + 1;
|
---|
112 | }
|
---|
113 | /******************************************************************************/
|
---|
114 | void SplitPath(char *Path, char *Dir, char *FileName) {
|
---|
115 | int SplitPoint;
|
---|
116 | SplitPoint = strlen(Path) - 1;
|
---|
117 | while ((SplitPoint > 0) && (Path[SplitPoint] != '\\')) {
|
---|
118 | SplitPoint--;
|
---|
119 | }
|
---|
120 | if ((SplitPoint == 0) && (Path[SplitPoint] != '\\')) {
|
---|
121 | //No directory, just a file name
|
---|
122 | Dir[0] = 0;
|
---|
123 | strcpy(FileName, Path);
|
---|
124 | }
|
---|
125 | else {
|
---|
126 | //Move past the last slash
|
---|
127 | SplitPoint++;
|
---|
128 |
|
---|
129 | //Directory
|
---|
130 | int i = 0;
|
---|
131 | while (i < SplitPoint) {
|
---|
132 | Dir[i] = Path[i];
|
---|
133 | i++;
|
---|
134 | }
|
---|
135 | Dir[i] = 0;
|
---|
136 |
|
---|
137 | //File name
|
---|
138 | int j = 0;
|
---|
139 | while (Path[i] != 0) {
|
---|
140 | FileName[j] = Path[i];
|
---|
141 | j++;
|
---|
142 | i++;
|
---|
143 | }
|
---|
144 | FileName[j] = 0;
|
---|
145 | }
|
---|
146 | }
|
---|
147 | /******************************************************************************/
|
---|
148 | void GetExtention(char *Path, char *Extention) {
|
---|
149 | int Dot;
|
---|
150 | int PathLen;
|
---|
151 |
|
---|
152 | PathLen = strlen(Path) - 1;
|
---|
153 | Dot = PathLen;
|
---|
154 | while ((Dot > 0) && (Path[Dot] != '.')) {
|
---|
155 | Dot--;
|
---|
156 | }
|
---|
157 | if (Dot > 0) {
|
---|
158 | strcpy(Extention, Path + Dot + 1);
|
---|
159 | }
|
---|
160 | else {
|
---|
161 | Extention[0] = 0;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | /******************************************************************************/
|
---|
165 | void TranslateEscapeString(char *TargetStr) {
|
---|
166 | int i = 0;
|
---|
167 | int j = 0;
|
---|
168 |
|
---|
169 | while (TargetStr[i] != 0) {
|
---|
170 | if ((TargetStr[i] == '%') && (TargetStr[i+1] != 0) && (TargetStr[i+2] != 0)) {
|
---|
171 | //Escaped value (did checking to make sure there are 2 more chars)
|
---|
172 | // #pragma warn -sig //Suppress significant digit loss warning (BC++)
|
---|
173 | TargetStr[j] = 16 * HexVal(TargetStr[i+1]) + HexVal(TargetStr[i+2]);
|
---|
174 | // #pragma warn +sig //Restore significant digit loss warning (BC++)
|
---|
175 | i += 3;
|
---|
176 | }
|
---|
177 | else {
|
---|
178 | TargetStr[j] = TargetStr[i];
|
---|
179 | i++;
|
---|
180 | }
|
---|
181 | j++;
|
---|
182 | }
|
---|
183 | TargetStr[j] = 0;
|
---|
184 | }
|
---|
185 | /******************************************************************************/
|
---|
186 | int HexVal(char c) {
|
---|
187 | // #pragma warn -sig //Suppress significant digit loss warning (BC++)
|
---|
188 | if (c >= '0' && c <= '9') return c - '0';
|
---|
189 | else if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
---|
190 | else if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
---|
191 | else return 0;
|
---|
192 | // #pragma warn +sig //Restore significant digit loss warning (BC++)
|
---|
193 | }
|
---|
194 | /******************************************************************************/
|
---|