version 1.27, 1997/04/22 08:36:11
|
version 1.28, 1997/05/26 09:01:50
|
Line 25
|
Line 25
|
|
|
#define MAX_PRINT_URL_LENGTH 50 |
#define MAX_PRINT_URL_LENGTH 50 |
|
|
/* Private functions */ |
|
|
/*---------------------------------------------------------------------- |
|
ConvertToLowerCase |
|
Converts a string to lowercase. |
|
----------------------------------------------------------------------*/ |
#ifdef __STDC__ |
#ifdef __STDC__ |
static void ConvertToLowerCase (char *string); |
static void ConvertToLowerCase (char *string) |
#else |
#else /* __STDC__ */ |
static void ConvertToLowerCase (/*char *string*/); |
static void ConvertToLowerCase (string) |
#endif |
char *string; |
|
|
|
#endif /* __STDC__ */ |
|
{ |
|
int i; |
|
|
|
if (!string) |
|
return; |
|
|
|
for (i = 0; string[i] != EOS; i++) |
|
string[i] = tolower (string[i]); |
|
} |
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
ExplodeURL |
ExplodeURL |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
|
|
#ifdef __STDC__ |
#ifdef __STDC__ |
void ExplodeURL (char *url, char **proto, char **host, char **dir, char **file) |
void ExplodeURL (char *url, char **proto, char **host, char **dir, char **file) |
#else |
#else |
Line 492 char *docName;
|
Line 506 char *docName;
|
TtaGiveTextAttributeValue (attrHREF, basename, &length); |
TtaGiveTextAttributeValue (attrHREF, basename, &length); |
/* base and orgName have to be separated by a DIR_SEP */ |
/* base and orgName have to be separated by a DIR_SEP */ |
length--; |
length--; |
if (basename[0] != EOS && basename[length] != '/') |
if (basename[0] != EOS && basename[length] != DIR_SEP) |
/* verify if the base has the form "protocol://server:port" */ |
/* verify if the base has the form "protocol://server:port" */ |
{ |
{ |
ptr = AmayaParseUrl (basename, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | |
ptr = AmayaParseUrl (basename, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | |
Line 581 char *docName;
|
Line 595 char *docName;
|
|
|
if (ptr) |
if (ptr) |
{ |
{ |
ptr = AmayaSimplifyUrl (&ptr); |
AmayaSimplifyUrl (&ptr); |
strcpy (newName, ptr); |
strcpy (newName, ptr); |
TtaFreeMemory (ptr); |
TtaFreeMemory (ptr); |
} |
} |
Line 658 char *path;
|
Line 672 char *path;
|
The caller has to free the new URL. |
The caller has to free the new URL. |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
#ifdef __STDC__ |
#ifdef __STDC__ |
char *AHTMakeRelativeName (char *url, char *base_url) |
char *AHTMakeRelativeName (char *url, char *base_url) |
#else /* __STDC__ */ |
#else /* __STDC__ */ |
char *AHTMakeRelativeName (url, base_url) |
char *AHTMakeRelativeName (url, base_url) |
char url; |
char url; |
char base_url; |
char base_url; |
|
|
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
{ |
{ |
char *base_ptr, *url_ptr; |
char *base_ptr, *url_ptr; |
char *result; |
char *result; |
|
|
/* verify if we are in the same host */ |
|
|
|
base_ptr = AmayaParseUrl (base_url, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION); |
|
url_ptr = AmayaParseUrl (url, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION); |
|
|
|
if (!strcmp (base_ptr, url_ptr)) |
|
{ |
|
TtaFreeMemory (base_ptr); |
|
TtaFreeMemory (url_ptr); |
|
|
|
/* Normalize the URLs */ |
|
|
|
base_ptr = AmayaParseUrl (base_url, "", AMAYA_PARSE_ALL); |
|
url_ptr = AmayaParseUrl (url, "", AMAYA_PARSE_ALL); |
|
|
|
/* Use libwww to make relative name */ |
/* verify if we are in the same host */ |
|
base_ptr = AmayaParseUrl (base_url, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION); |
result = AmayaRelativeUrl (url_ptr, base_ptr); |
url_ptr = AmayaParseUrl (url, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION); |
TtaFreeMemory (base_ptr); |
if (!strcmp (base_ptr, url_ptr)) |
TtaFreeMemory (url_ptr); |
{ |
} |
TtaFreeMemory (base_ptr); |
else |
TtaFreeMemory (url_ptr); |
result = (char *) NULL; |
|
|
/* Normalize the URLs */ |
return (result); |
base_ptr = AmayaParseUrl (base_url, "", AMAYA_PARSE_ALL); |
|
url_ptr = AmayaParseUrl (url, "", AMAYA_PARSE_ALL); |
|
|
|
/* Use libwww to make relative name */ |
|
result = AmayaRelativeUrl (url_ptr, base_ptr); |
|
TtaFreeMemory (base_ptr); |
|
TtaFreeMemory (url_ptr); |
|
} |
|
else |
|
result = (char *) NULL; |
|
|
|
return (result); |
} |
} |
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
HasKnownFileSuffix |
HasKnownFileSuffix |
Line 759 char *path;
|
Line 769 char *path;
|
|
|
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
ConvertToLowerCase |
|
Converts a string to lowercase. |
|
----------------------------------------------------------------------*/ |
|
#ifdef __STDC__ |
|
static void ConvertToLowerCase (char *string) |
|
#else /* __STDC__ */ |
|
static void ConvertToLowerCase (string) |
|
char *string; |
|
|
|
#endif /* __STDC__ */ |
|
{ |
|
int i; |
|
|
|
if (!string) |
|
return; |
|
|
|
for (i = 0; string[i] != EOS; i++) |
|
string[i] = tolower (string[i]); |
|
} |
|
|
|
|
|
/*---------------------------------------------------------------------- |
|
ChopURL |
ChopURL |
Gives back a URL no longer than MAX_PRINT_URL_LENGTH chars (outputURL). |
Gives back a URL no longer than MAX_PRINT_URL_LENGTH chars (outputURL). |
If inputURL is bigger than that size, outputURL receives |
If inputURL is bigger than that size, outputURL receives |
Line 819 char *inputURL;
|
Line 807 char *inputURL;
|
|
|
/************************************************************************ |
/************************************************************************ |
* * |
* * |
* Local Adaptation of the libWWW Library/src/AmayaParseUrl.c code. * |
* Local Adaptation of the libWWW Library/src/AmayaParseUrl.c code. * |
* * |
* * |
************************************************************************/ |
************************************************************************/ |
|
|
Line 859 HTURI *parts;
|
Line 847 HTURI *parts;
|
|
|
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
{ |
{ |
char * p; |
char * p; |
char * after_access = name; |
char * after_access = name; |
memset(parts, '\0', sizeof(HTURI)); |
|
|
|
/* Look for fragment identifier */ |
memset(parts, '\0', sizeof(HTURI)); |
if ((p = strrchr(name, '#')) != NULL) { |
/* Look for fragment identifier */ |
*p++ = '\0'; |
if ((p = strrchr(name, '#')) != NULL) |
parts->fragment = p; |
{ |
|
*p++ = '\0'; |
|
parts->fragment = p; |
} |
} |
|
|
for(p=name; *p; p++) { |
for (p=name; *p; p++) |
if (*p=='/' || *p=='#' || *p=='?') |
{ |
|
if (*p==DIR_SEP || *p=='#' || *p=='?') |
|
break; |
|
if (*p==':') |
|
{ |
|
*p = 0; |
|
parts->access = after_access; /* Scheme has been specified */ |
|
|
|
/* The combination of gcc, the "-O" flag and the HP platform is |
|
unhealthy. The following three lines is a quick & dirty fix, but is |
|
not recommended. Rather, turn off "-O". */ |
|
|
|
/* after_access = p;*/ |
|
/* while (*after_access == 0)*/ |
|
/* after_access++;*/ |
|
after_access = p+1; |
|
if (0==strcasecmp("URL", parts->access)) |
|
/* Ignore IETF's URL: pre-prefix */ |
|
parts->access = NULL; |
|
else |
break; |
break; |
if (*p==':') { |
|
*p = 0; |
|
parts->access = after_access; /* Scheme has been specified */ |
|
|
|
/* The combination of gcc, the "-O" flag and the HP platform is |
|
unhealthy. The following three lines is a quick & dirty fix, but is |
|
not recommended. Rather, turn off "-O". */ |
|
|
|
/* after_access = p;*/ |
|
/* while (*after_access == 0)*/ |
|
/* after_access++;*/ |
|
|
|
after_access = p+1; |
|
|
|
if (0==strcasecmp("URL", parts->access)) { |
|
parts->access = NULL; /* Ignore IETF's URL: pre-prefix */ |
|
} else break; |
|
} |
} |
} |
} |
|
|
p = after_access; |
p = after_access; |
if (*p=='/'){ |
if (*p==DIR_SEP) |
if (p[1]=='/') { |
{ |
|
if (p[1]==DIR_SEP) |
|
{ |
parts->host = p+2; /* host has been specified */ |
parts->host = p+2; /* host has been specified */ |
*p=0; /* Terminate access */ |
*p = 0; /* Terminate access */ |
p=strchr(parts->host,'/'); /* look for end of host name if any */ |
/* look for end of host name if any */ |
if(p) { |
p = strchr(parts->host,DIR_SEP); |
|
if (p) |
|
{ |
*p=0; /* Terminate host */ |
*p=0; /* Terminate host */ |
parts->absolute = p+1; /* Root has been found */ |
parts->absolute = p+1; /* Root has been found */ |
} |
} |
} else { |
} |
parts->absolute = p+1; /* Root found but no host */ |
else |
} |
/* Root found but no host */ |
} else { |
parts->absolute = p+1; |
|
} |
|
else |
|
{ |
parts->relative = (*after_access) ? after_access : 0; /* zero for "" */ |
parts->relative = (*after_access) ? after_access : 0; /* zero for "" */ |
} |
} |
} |
} |
|
|
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
AmayaParseUrl |
AmayaParseUrl: parse a Name relative to another name |
Parse a Name relative to another name |
|
------------------------------------- |
This returns those parts of a name which are given (and requested) |
|
substituting bits from the related name where necessary. |
This returns those parts of a name which are given (and requested) |
|
substituting bits from the related name where necessary. |
|
|
|
On entry, |
On entry, |
aName A filename given |
aName A filename given |
relatedName A name relative to which aName is to be parsed. Give |
relatedName A name relative to which aName is to be parsed. Give |
it an empty string if aName is absolute. |
it an empty string if aName is absolute. |
wanted A mask for the bits which are wanted. |
wanted A mask for the bits which are wanted. |
|
|
On exit, |
On exit, |
returns A pointer to a malloc'd string which MUST BE FREED |
returns A pointer to a malloc'd string which MUST BE FREED |
|
|
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
#ifdef __STDC__ |
#ifdef __STDC__ |
char * AmayaParseUrl (const char *aName, const char *relatedName, int wanted) |
char *AmayaParseUrl (char *aName, char *relatedName, int wanted) |
#else /* __STDC__ */ |
#else /* __STDC__ */ |
char * AmayaParseUrl (aName, relatedName, wanted) |
char *AmayaParseUrl (aName, relatedName, wanted) |
const char *aName; |
char *aName; |
const char *relatedName; |
char *relatedName; |
int wanted; |
int wanted; |
|
|
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
{ |
{ |
Line 999 int wanted;
|
Line 994 int wanted;
|
if (given.relative) { |
if (given.relative) { |
p = strchr(result, '?'); /* Search part? */ |
p = strchr(result, '?'); /* Search part? */ |
if (!p) p=result+strlen(result)-1; |
if (!p) p=result+strlen(result)-1; |
for (; *p!='/'; p--); /* last / */ |
for (; *p!=DIR_SEP; p--); /* last / */ |
p[1]=0; /* Remove filename */ |
p[1]=0; /* Remove filename */ |
strcat(result, given.relative); /* Add given one */ |
strcat(result, given.relative); /* Add given one */ |
#if 0 |
/*AmayaSimplifyUrl (&result);*/ |
result = AmayaSimplifyUrl (&result); |
|
#endif |
|
} |
} |
} else if(given.relative) { |
} else if(given.relative) { |
strcat(result, given.relative); /* what we've got */ |
strcat(result, given.relative); /* what we've got */ |
Line 1048 int wanted;
|
Line 1041 int wanted;
|
|
|
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
#ifdef __STDC__ |
#ifdef __STDC__ |
static char * HTCanon (char ** filename, char * host) |
static char *HTCanon (char ** filename, char * host) |
#else /* __STDC__ */ |
#else /* __STDC__ */ |
static char * HTCanon (filename,host) |
static char *HTCanon (filename, host) |
char **filename; |
char **filename; |
char *host; |
char *host; |
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
{ |
{ |
char *newname = NULL; |
char *newname = NULL; |
Line 1061 char *host;
|
Line 1054 char *host;
|
char *path; |
char *path; |
char *access = host-3; |
char *access = host-3; |
|
|
while (access>*filename && *(access-1)!='/') /* Find access method */ |
while (access>*filename && *(access-1)!=DIR_SEP) /* Find access method */ |
access--; |
access--; |
if ((path = strchr(host, '/')) == NULL) /* Find path */ |
if ((path = strchr(host, DIR_SEP)) == NULL) /* Find path */ |
path = host + strlen(host); |
path = host + strlen(host); |
if ((strptr = strchr(host, '@')) != NULL && strptr<path) /* UserId */ |
if ((strptr = strchr(host, '@')) != NULL && strptr<path) /* UserId */ |
host = strptr; |
host = strptr; |
Line 1090 char *host;
|
Line 1083 char *host;
|
} |
} |
/* Chop off port if `:', `:80' (http), `:70' (gopher), or `:21' (ftp) */ |
/* Chop off port if `:', `:80' (http), `:70' (gopher), or `:21' (ftp) */ |
if (port) { |
if (port) { |
if (!*(port+1) || *(port+1)=='/') { |
if (!*(port+1) || *(port+1)==DIR_SEP) { |
if (!newname) { |
if (!newname) { |
char *orig=port, *dest=port+1; |
char *orig=port, *dest=port+1; |
while((*orig++ = *dest++)); |
while((*orig++ = *dest++)); |
} |
} |
} else if ((!strncmp(access, "http", 4) && |
} else if ((!strncmp(access, "http", 4) && |
(*(port+1)=='8'&&*(port+2)=='0'&&(*(port+3)=='/'||!*(port+3)))) || |
(*(port+1)=='8'&&*(port+2)=='0'&&(*(port+3)==DIR_SEP||!*(port+3)))) || |
(!strncmp(access, "gopher", 6) && |
(!strncmp(access, "gopher", 6) && |
(*(port+1)=='7'&&*(port+2)=='0'&&(*(port+3)=='/'||!*(port+3)))) || |
(*(port+1)=='7'&&*(port+2)=='0'&&(*(port+3)==DIR_SEP||!*(port+3)))) || |
(!strncmp(access, "ftp", 3) && |
(!strncmp(access, "ftp", 3) && |
(*(port+1)=='2'&&*(port+2)=='1'&&(*(port+3)=='/'||!*(port+3))))) { |
(*(port+1)=='2'&&*(port+2)=='1'&&(*(port+3)==DIR_SEP||!*(port+3))))) { |
if (!newname) { |
if (!newname) { |
char *orig=port, *dest=port+3; |
char *orig=port, *dest=port+3; |
while((*orig++ = *dest++)); |
while((*orig++ = *dest++)); |
path -= 3; /* Update path position, Henry Minsky */ |
/* Update path position, Henry Minsky */ |
|
path -= 3; |
} |
} |
} else if (newname) |
} else if (newname) |
strncat(newname, port, (int) (path-port)); |
strncat(newname, port, (int) (path-port)); |
Line 1114 char *host;
|
Line 1108 char *host;
|
char *newpath = newname+strlen(newname); |
char *newpath = newname+strlen(newname); |
strcat(newname, path); |
strcat(newname, path); |
path = newpath; |
path = newpath; |
TtaFreeMemory(*filename); /* Free old copy */ |
/* Free old copy */ |
|
TtaFreeMemory(*filename); |
*filename = newname; |
*filename = newname; |
} |
} |
return path; |
return path; |
Line 1122 char *host;
|
Line 1117 char *host;
|
|
|
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
AmayaSimplifyUrl |
AmayaSimplifyUrl: simplify a URI |
Simplify a URI |
A URI is allowed to contain the seqeunce xxx/../ which may be |
-------------- |
replaced by "" , and the seqeunce "/./" which may be replaced by "/". |
A URI is allowed to contain the seqeunce xxx/../ which may be |
Simplification helps us recognize duplicate URIs. |
replaced by "" , and the seqeunce "/./" which may be replaced by "/". |
|
Simplification helps us recognize duplicate URIs. |
|
|
|
Thus, /etc/junk/../fred becomes /etc/fred |
Thus, /etc/junk/../fred becomes /etc/fred |
/etc/junk/./fred becomes /etc/junk/fred |
/etc/junk/./fred becomes /etc/junk/fred |
|
|
but we should NOT change |
but we should NOT change |
http://fred.xxx.edu/../.. |
http://fred.xxx.edu/../.. |
|
|
or ../../albert.html |
or ../../albert.html |
|
|
In order to avoid empty URLs the following URLs become: |
In order to avoid empty URLs the following URLs become: |
|
|
/fred/.. becomes /fred/.. |
/fred/.. becomes /fred/.. |
/fred/././.. becomes /fred/.. |
/fred/././.. becomes /fred/.. |
/fred/.././junk/.././ becomes /fred/.. |
/fred/.././junk/.././ becomes /fred/.. |
|
|
If more than one set of `://' is found (several proxies in cascade) then |
If more than one set of `://' is found (several proxies in cascade) then |
only the part after the last `://' is simplified. |
only the part after the last `://' is simplified. |
|
|
Returns: A string which might be the old one or a new one. |
|
|
|
|
Returns: A string which might be the old one or a new one. |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
#ifdef __STDC__ |
#ifdef __STDC__ |
char *AmayaSimplifyUrl (char ** url) |
void AmayaSimplifyUrl (char ** url) |
#else /* __STDC__ */ |
#else /* __STDC__ */ |
char *AmayaSimplifyUrl (url) |
void AmayaSimplifyUrl (url) |
char **url; |
char **url; |
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
{ |
{ |
char *path; |
char *path, *p; |
char *p; |
char *newptr, *access; |
if (!url || !*url) { |
char *orig, *dest, *end; |
return *url; |
|
|
if (!url || !*url) |
|
return; |
|
|
|
/* Find any scheme name */ |
|
if ((path = strstr(*url, "://")) != NULL) |
|
{ /* Find host name */ |
|
access = *url; |
|
while (access<path && (*access=tolower(*access))) |
|
access++; |
|
path += 3; |
|
while ((newptr = strstr(path, "://")) != NULL) |
|
/* For proxies */ |
|
path = newptr+3; |
|
/* We have a host name */ |
|
path = HTCanon(url, path); |
} |
} |
|
else if ((path = strstr(*url, ":/")) != NULL) |
|
path += 2; |
|
else |
|
path = *url; |
|
|
/* Find any scheme name */ |
if (*path == DIR_SEP && *(path+1)==DIR_SEP) |
if ((path = strstr(*url, "://")) != NULL) { /* Find host name */ |
/* Some URLs start //<foo> */ |
char *newptr; |
path += 1; |
char *access = *url; |
else if (!strncmp(path, "news:", 5)) |
while (access<path && (*access=tolower(*access))) access++; |
{ |
path += 3; |
newptr = strchr(path+5, '@'); |
while ((newptr = strstr(path, "://")) != NULL) /* For proxies */ |
if (!newptr) |
path = newptr+3; |
newptr = path + 5; |
path = HTCanon(url, path); /* We have a host name */ |
while (*newptr) |
} else if ((path = strstr(*url, ":/")) != NULL) { |
{ |
path += 2; |
/* Make group or host lower case */ |
} else |
*newptr = tolower (*newptr); |
path = *url; |
newptr++; |
if (*path == '/' && *(path+1)=='/') { /* Some URLs start //<foo> */ |
|
path += 1; |
|
} else if (!strncmp(path, "news:", 5)) { |
|
char *ptr = strchr(path+5, '@'); |
|
if (!ptr) ptr = path+5; |
|
while (*ptr) { /* Make group or host lower case */ |
|
*ptr = tolower(*ptr); |
|
ptr++; |
|
} |
} |
return *url; /* Doesn't need to do any more */ |
/* Doesn't need to do any more */ |
|
return; |
} |
} |
if ((p = path)) { |
|
char *end; |
if ((p = path)) |
if (!((end = strchr(path, ';')) || (end = strchr(path, '?')) || |
{ |
(end = strchr(path, '#')))) |
if (!((end = strchr (path, ';')) || (end = strchr (path, '?')) || |
end = path+strlen(path); |
(end = strchr (path, '#')))) |
|
end = path + strlen (path); |
/* Parse string second time to simplify */ |
|
p = path; |
/* Parse string second time to simplify */ |
while(p<end) { |
p = path; |
if (*p=='/') { |
while (p < end) |
if (p>*url && *(p+1)=='.' && (*(p+2)=='/' || !*(p+2))) { |
{ |
char *orig = p+1; |
if (*p==DIR_SEP) |
char *dest = (*(p+2)!='/') ? p+2 : p+3; |
{ |
while ((*orig++ = *dest++)); /* Remove a slash and a dot */ |
if (p > *url && *(p+1) == '.' && (*(p+2) == DIR_SEP || !*(p+2))) |
end = orig-1; |
{ |
} else if (*(p+1)=='.' && *(p+2)=='.' && (*(p+3)=='/' || !*(p+3))) { |
orig = p + 1; |
char *q = p; |
dest = (*(p+2)!=DIR_SEP) ? p+2 : p+3; |
while (q>path && *--q!='/'); /* prev slash */ |
while ((*orig++ = *dest++)); /* Remove a slash and a dot */ |
if (strncmp(q, "/../", 4)) { |
end = orig - 1; |
char *orig = q+1; |
} |
char *dest = (*(p+3)!='/') ? p+3 : p+4; |
else if (*(p+1)=='.' && *(p+2)=='.' && (*(p+3)==DIR_SEP || !*(p+3))) |
while ((*orig++ = *dest++)); /* Remove /xxx/.. */ |
{ |
end = orig-1; |
newptr = p; |
p = q; /* Start again with prev slash */ |
while (newptr>path && *--newptr!=DIR_SEP); /* prev slash */ |
} else |
if (strncmp(newptr, "/../", 4)) |
p++; |
{ |
} else if (*(p+1)=='/') { |
orig = newptr + 1; |
while (*(p+1)=='/') { |
dest = (*(p+3)!=DIR_SEP) ? p+3 : p+4; |
char *orig=p, *dest=p+1; |
while ((*orig++ = *dest++)); /* Remove /xxx/.. */ |
while ((*orig++ = *dest++)); /* Remove multiple /'s */ |
end = orig-1; |
end = orig-1; |
/* Start again with prev slash */ |
|
p = newptr; |
} |
} |
} else |
else |
p++; |
p++; |
} else |
} |
|
else if (*(p+1) == DIR_SEP) |
|
{ |
|
while (*(p+1) == DIR_SEP) |
|
{ |
|
orig = p; |
|
dest = p + 1; |
|
while ((*orig++ = *dest++)); /* Remove multiple /'s */ |
|
end = orig-1; |
|
} |
|
} |
|
else |
p++; |
p++; |
|
} |
|
else |
|
p++; |
} |
} |
} |
} |
return *url; |
return; |
|
} |
|
|
|
|
|
/*---------------------------------------------------------------------- |
|
NormalizeFile normalizes local names. |
|
Return TRUE if target and src differ. |
|
----------------------------------------------------------------------*/ |
|
#ifdef __STDC__ |
|
boolean NormalizeFile (char *src, char *target) |
|
#else |
|
boolean NormalizeFile (src, target) |
|
char *src; |
|
char *target; |
|
|
|
#endif |
|
{ |
|
char *s; |
|
boolean change; |
|
|
|
change = FALSE; |
|
if (src[0] == '~') |
|
{ |
|
/* replace ~ */ |
|
s = (char *) TtaGetEnvString ("HOME"); |
|
strcpy (target, s); |
|
strcat (target, &src[1]); |
|
change = TRUE; |
|
} |
|
else if (strncmp (src, "file:", 5) == 0) |
|
{ |
|
/* remove the prefix file: */ |
|
if (src[5] == EOS) |
|
strcpy (target, DIR_STR); |
|
else if (src[0] == '~') |
|
{ |
|
/* replace ~ */ |
|
s = (char *) TtaGetEnvString ("HOME"); |
|
strcpy (target, s); |
|
strcat (target, &src[5]); |
|
} |
|
else |
|
strcpy (target, &src[5]); |
|
change = TRUE; |
|
} |
|
else |
|
strcpy (target, src); |
|
|
|
/* remove /../ and /./ */ |
|
AmayaSimplifyUrl (&target); |
|
return (change); |
} |
} |
|
|
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
AmayaRelativeUrl |
AmayaRelativeUrl: make Relative Name |
Make Relative Name |
|
------------------ |
|
|
|
This function creates and returns a string which gives an expression of |
This function creates and returns a string which gives an expression of |
one address as related to another. Where there is no relation, an absolute |
one address as related to another. Where there is no relation, an absolute |
address is retured. |
address is retured. |
|
|
On entry, |
On entry, |
Both names must be absolute, fully qualified names of nodes |
Both names must be absolute, fully qualified names of nodes |
(no fragment bits) |
(no fragment bits) |
|
|
On exit, |
On exit, |
The return result points to a newly allocated name which, if |
The return result points to a newly allocated name which, if |
parsed by AmayaParseUrl relative to relatedName, will yield aName. |
parsed by AmayaParseUrl relative to relatedName, will yield aName. |
The caller is responsible for freeing the resulting name later. |
The caller is responsible for freeing the resulting name later. |
|
|
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
#ifdef __STDC__ |
#ifdef __STDC__ |
char *AmayaRelativeUrl (const char * aName, const char * relatedName) |
char *AmayaRelativeUrl (char *aName, char *relatedName) |
#else /* __STDC__ */ |
#else /* __STDC__ */ |
char *AmayaRelativeUrl (const char * aName, const char * relatedName) |
char *AmayaRelativeUrl (aName, relatedName) |
const char *aName; |
char *aName; |
|
char *relatedName; |
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
{ |
{ |
char *result = 0; |
char *result = 0; |
Line 1260 const char *aName;
|
Line 1328 const char *aName;
|
const char *last_slash = 0; |
const char *last_slash = 0; |
int slashes = 0; |
int slashes = 0; |
|
|
for(;*p; p++, q++) |
for (;*p; p++, q++) |
{ |
{ |
/* Find extent of match */ |
/* Find extent of match */ |
if (*p != *q) |
if (*p != *q) |
break; |
break; |
if (*p == ':') |
if (*p == ':') |
after_access = p+1; |
after_access = p+1; |
if (*p == '/') |
if (*p == DIR_SEP) |
{ |
{ |
last_slash = p; |
last_slash = p; |
slashes++; |
slashes++; |
Line 1290 const char *aName;
|
Line 1358 const char *aName;
|
/* Some path in common */ |
/* Some path in common */ |
int levels= 0; |
int levels= 0; |
for (; *q && (*q!='#'); q++) |
for (; *q && (*q!='#'); q++) |
if (*q=='/') |
if (*q==DIR_SEP) |
levels++; |
levels++; |
result = (char *) TtaGetMemory (3*levels + strlen(last_slash) + 1); |
result = (char *) TtaGetMemory (3*levels + strlen(last_slash) + 1); |
if (result == NULL) |
if (result == NULL) |