source: main/trunk/greenstone2/runtime-src/src/w32server/parse.cpp@ 28762

Last change on this file since 28762 was 9598, checked in by kjdon, 19 years ago

added some x++ -> ++x changes submitted by Emanuel Dejanu

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