source: trunk/gsdl/src/w32server/parse.cpp@ 2501

Last change on this file since 2501 was 2286, checked in by sjboddie, 23 years ago

Had a bit of a tidy up in the fnord webserver code. The main change of note
was the removal of our reliance on the MAX_URL_SIZE constant. URLs and post
data of any length should now work.

  • 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(char *DestStr, const char *SourceStr, const int Start, int &End) {
87 int i, Len;
88
89 Len = 0;
90 i = Start;
91 while ((SourceStr[i] != ' ') && (SourceStr[i] != '\t') && (SourceStr[i] != 0)) {
92 Len++;
93 i++;
94 }
95 //Create the substring
96 memcpy(DestStr, SourceStr + Start, Len);
97 DestStr[Len] = 0;
98 //Set End
99 while ((SourceStr[i] != 0) &&
100 ((SourceStr[i] == ' ') || (SourceStr[i] == '\t'))) {
101 i ++;
102 }
103 End = i;
104}
105/******************************************************************************/
106void GetLastWord(char *DestString, const char *SourceStr, int &Start) {
107 int SourceLen, i, Len;
108
109 Len = 0;
110 SourceLen = strlen(SourceStr);
111 i = SourceLen - 1;
112 while ((i >= 0) && (SourceStr[i] != ' ') && (SourceStr[i] != '\t')) {
113 Len++;
114 i--;
115 }
116 //Create the substring
117 memcpy(DestString, SourceStr + SourceLen - Len, Len);
118 DestString[Len] = 0;
119 Start = i + 1;
120}
121/******************************************************************************/
122void SplitPath(char *Path, char *Dir, char *FileName) {
123 int SplitPoint;
124 SplitPoint = strlen(Path) - 1;
125 while ((SplitPoint > 0) && (Path[SplitPoint] != '\\')) {
126 SplitPoint--;
127 }
128 if ((SplitPoint == 0) && (Path[SplitPoint] != '\\')) {
129 //No directory, just a file name
130 Dir[0] = 0;
131 strcpy(FileName, Path);
132 }
133 else {
134 //Move past the last slash
135 SplitPoint++;
136
137 //Directory
138 int i = 0;
139 while (i < SplitPoint) {
140 Dir[i] = Path[i];
141 i++;
142 }
143 Dir[i] = 0;
144
145 //File name
146 int j = 0;
147 while (Path[i] != 0) {
148 FileName[j] = Path[i];
149 j++;
150 i++;
151 }
152 FileName[j] = 0;
153 }
154}
155/******************************************************************************/
156void GetExtention(char *Path, char *Extention) {
157 int Dot;
158 int PathLen;
159
160 PathLen = strlen(Path) - 1;
161 Dot = PathLen;
162 while ((Dot > 0) && (Path[Dot] != '.')) {
163 Dot--;
164 }
165 if (Dot > 0) {
166 strcpy(Extention, Path + Dot + 1);
167 }
168 else {
169 Extention[0] = 0;
170 }
171}
172/******************************************************************************/
173void TranslateEscapeString(char *TargetStr) {
174 int i = 0;
175 int j = 0;
176
177 while (TargetStr[i] != 0) {
178 if ((TargetStr[i] == '%') && (TargetStr[i+1] != 0) && (TargetStr[i+2] != 0)) {
179 //Escaped value (did checking to make sure there are 2 more chars)
180 // #pragma warn -sig //Suppress significant digit loss warning (BC++)
181 TargetStr[j] = 16 * HexVal(TargetStr[i+1]) + HexVal(TargetStr[i+2]);
182 // #pragma warn +sig //Restore significant digit loss warning (BC++)
183 i += 3;
184 }
185 else {
186 TargetStr[j] = TargetStr[i];
187 i++;
188 }
189 j++;
190 }
191 TargetStr[j] = 0;
192}
193/******************************************************************************/
194int HexVal(char c) {
195 // #pragma warn -sig //Suppress significant digit loss warning (BC++)
196 if (c >= '0' && c <= '9') return c - '0';
197 else if (c >= 'a' && c <= 'f') return c - 'a' + 10;
198 else if (c >= 'A' && c <= 'F') return c - 'A' + 10;
199 else return 0;
200 // #pragma warn +sig //Restore significant digit loss warning (BC++)
201}
202/******************************************************************************/
Note: See TracBrowser for help on using the repository browser.