next up previous contents
Next: Sobre este documento... Up: Código CGI Ejemplo Previous: El fichero echoPost.c   Índice General

El fichero cgi_util.c

indentation

#include $<$stdio.h$>$

#define LF 10
#define CR 13

void getword(char $\ast$word, char $\ast$line, char stop) {
int x = 0,y;

for(x=0;((line[x]) && (line[x] $\neq$ stop));x++)
word[x] = line[x];

word[x] = '$\backslash$ 0';
if(line[x]) ++x;
y=0;

while(line[y++] = line[x++]);
}

char $\ast$makeword(char $\ast$line, char stop) {
int x = 0,y;
char $\ast$word = (char $\ast$) malloc(sizeof(char) $\ast$ (strlen(line) + 1));

for(x=0;((line[x]) && (line[x] $\neq$ stop));x++)
word[x] = line[x];

word[x] = '$\backslash$0';
if(line[x]) ++x;
y=0;

while(line[y++] = line[x++]);
return word;
}

char $\ast$fmakeword(FILE $\ast$f, char stop, int $\ast$cl) {
int wsize;
char $\ast$word;
int ll;

wsize = 102400;
ll=0;
word = (char $\ast$) malloc(sizeof(char) $\ast$ (wsize + 1));

while(1) {
word[ll] = (char)fgetc(f);
if(ll==wsize) {
word[ll+1] = '$\backslash$0';
wsize+=102400;
word = (char $\ast$)realloc(word,sizeof(char)$\ast$(wsize+1));
}
-($\ast$cl);
if((word[ll] == stop) $\mid\mid$ (feof(f)) $\mid\mid$ (!($\ast$cl))) {
if(word[ll] $\neq$ stop) ll++;
word[ll] = '$\backslash$0';
return word;
}
++ll;
}
}

char x2c(char $\ast$what) {
register char digit;

digit = (what[0] $\geq$ 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
digit $\ast=$ 16;
digit += (what[1] $\geq$ 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
return(digit);
}

void unescape_url(char $\ast$url) {
register int x,y;

for(x=0,y=0;url[y];++x,++y) {
if((url[x] = url[y]) == '%') {
url[x] = x2c(&url[y+1]);
y+=2;
}
}
url[x] = '$\backslash$0';
}

void plustospace(char $\ast$str) {
register int x;

for(x=0;str[x];x++) if(str[x] == '$+$') str[x] = ' ';
}

int rind(char $\ast$s, char c) {
register int x;
for(x=strlen(s) - 1;x $\neq$ -1; x-)
if(s[x] == c) return x;
return -1;
}

int getline(char $\ast$s, int n, FILE $\ast$f) {
register int i=0;

while(1) {
s[i] = (char)fgetc(f);

if(s[i] == CR)
s[i] = fgetc(f);

if((s[i] == 0x4) $\mid\mid$ (s[i] == LF) $\mid\mid$ (i == (n-1))) {
s[i] = '$\backslash$0';
return (feof(f) ? 1 : 0);
}
++i;
}
}

void send_fd(FILE $\ast$f, FILE $\ast$fd)
{
int num_chars=0;
char c;

while (1) {
c = fgetc(f);
if(feof(f))
return;
fputc(c,fd);
}
}

next up previous contents
Next: Sobre este documento... Up: Código CGI Ejemplo Previous: El fichero echoPost.c   Índice General
Jesús Vegas 2003-03-13