Annotation of Amaya/amaya/AHTURLTools.c, revision 1.64

1.7       cvs         1: /*
                      2:  *
                      3:  *  (c) COPYRIGHT MIT and INRIA, 1996.
                      4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
1.9       cvs         7: 
1.10      cvs         8: /*
                      9:  * AHTURLTools.c: contains all the functions for testing, manipulating,
1.25      cvs        10:  * and normalizing URLs. It also contains a local copy of the libWWW
                     11:  * URL parsing functions.
1.10      cvs        12:  *
                     13:  * Authors: J. Kahan, I. Vatton
1.45      cvs        14:  *          R. Guetari (Stuff related to Windows).
1.10      cvs        15:  *
                     16:  */
1.7       cvs        17:  
1.15      cvs        18: #define THOT_EXPORT extern
1.3       cvs        19: #include "amaya.h"
                     20: 
1.8       cvs        21: #include "init_f.h"
                     22: #include "AHTURLTools_f.h"
                     23: 
1.24      cvs        24: #define MAX_PRINT_URL_LENGTH 50
1.29      cvs        25: typedef struct _HTURI {
                     26:     char * access;             /* Now known as "scheme" */
                     27:     char * host;
                     28:     char * absolute;
                     29:     char * relative;
                     30:     char * fragment;
                     31: } HTURI;
1.24      cvs        32: 
1.28      cvs        33: 
                     34: /*----------------------------------------------------------------------
                     35:   ConvertToLowerCase
                     36:   Converts a string to lowercase.
                     37:   ----------------------------------------------------------------------*/
1.22      cvs        38: #ifdef __STDC__
1.38      cvs        39: void         ConvertToLowerCase (char *string)
1.28      cvs        40: #else  /* __STDC__ */
1.38      cvs        41: void         ConvertToLowerCase (string)
1.28      cvs        42: char                *string;
                     43: 
                     44: #endif /* __STDC__ */
                     45: {
                     46:  int i;
                     47: 
                     48:  if (!string)
                     49:    return;
                     50: 
                     51:  for (i = 0; string[i] != EOS; i++)
                     52:    string[i] = tolower (string[i]);
                     53: }
1.22      cvs        54: 
1.8       cvs        55: /*----------------------------------------------------------------------
1.11      cvs        56:   ExplodeURL 
1.8       cvs        57:   ----------------------------------------------------------------------*/
                     58: #ifdef __STDC__
                     59: void                ExplodeURL (char *url, char **proto, char **host, char **dir, char **file)
                     60: #else
                     61: void                ExplodeURL (url, proto, host, dir, file)
                     62: char               *url;
                     63: char              **proto;
                     64: char              **host;
                     65: char              **dir;
                     66: char              **file;
                     67: 
                     68: #endif
                     69: {
1.33      cvs        70:    char            *curr, *temp;
                     71:    char             used_sep;
1.32      cvs        72: 
1.33      cvs        73:    if (url && strchr (url, URL_SEP))
                     74:      used_sep = URL_SEP;
                     75:    else
                     76:      used_sep = DIR_SEP;
1.8       cvs        77: 
                     78:    if ((url == NULL) || (proto == NULL) || (host == NULL) ||
                     79:        (dir == NULL) || (file == NULL))
                     80:       return;
                     81: 
                     82:    /* initialize every pointer */
                     83:    *proto = *host = *dir = *file = NULL;
                     84: 
                     85:    /* skip any leading space */
                     86:    while ((*url == SPACE) || (*url == TAB))
                     87:       url++;
1.9       cvs        88:    curr = url;
                     89:    if (*curr == 0)
1.8       cvs        90:       goto finished;
                     91: 
                     92:    /* go to the end of the URL */
1.9       cvs        93:    while ((*curr != 0) && (*curr != SPACE) && (*curr != '\b') &&
                     94:          (*curr != '\r') && (*curr != EOL))
                     95:       curr++;
1.8       cvs        96: 
                     97:    /* mark the end of the chain */
1.9       cvs        98:    *curr = EOS;
                     99:    curr--;
                    100:    if (curr <= url)
1.8       cvs       101:       goto finished;
                    102: 
                    103:    /* search the next DIR_SEP indicating the beginning of the file name */
                    104:    do
1.11      cvs       105:      curr--;
1.33      cvs       106:    while ((curr >= url) && (*curr != used_sep));
1.11      cvs       107: 
1.9       cvs       108:    if (curr < url)
1.8       cvs       109:       goto finished;
1.9       cvs       110:    *file = curr + 1;
1.8       cvs       111: 
                    112:    /* mark the end of the dir */
1.9       cvs       113:    *curr = EOS;
                    114:    curr--;
                    115:    if (curr < url)
1.8       cvs       116:       goto finished;
                    117: 
1.29      cvs       118:    /* search for the DIR_STR indicating the host name start */
1.33      cvs       119:    while ((curr > url) && ((*curr != used_sep) || (*(curr + 1) != used_sep)))
1.9       cvs       120:       curr--;
1.8       cvs       121: 
                    122:    /* if we found it, separate the host name from the directory */
1.33      cvs       123:    if ((*curr == DIR_SEP) && (*(curr + 1) == used_sep))
1.8       cvs       124:      {
1.9       cvs       125:        *host = temp = curr + 2;
1.33      cvs       126:        while ((*temp != 0) && (*temp != used_sep))
1.8       cvs       127:           temp++;
1.33      cvs       128:        if (*temp == used_sep)
1.8       cvs       129:          {
                    130:             *temp = EOS;
                    131:             *dir = temp + 1;
                    132:          }
                    133:      }
                    134:    else
1.11      cvs       135:      *dir = curr;
                    136: 
1.9       cvs       137:    if (curr <= url)
1.8       cvs       138:       goto finished;
                    139: 
                    140:    /* mark the end of the proto */
1.9       cvs       141:    *curr = EOS;
                    142:    curr--;
                    143:    if (curr < url)
1.8       cvs       144:       goto finished;
                    145: 
1.32      cvs       146:    if (*curr == ':')
1.8       cvs       147:      {
1.9       cvs       148:        *curr = EOS;
                    149:        curr--;
1.8       cvs       150:      }
                    151:    else
                    152:       goto finished;
1.11      cvs       153: 
1.9       cvs       154:    if (curr < url)
1.8       cvs       155:       goto finished;
1.9       cvs       156:    while ((curr > url) && (isalpha (*curr)))
                    157:       curr--;
                    158:    *proto = curr;
1.8       cvs       159: 
                    160:  finished:;
                    161: 
                    162: #ifdef AMAYA_DEBUG
                    163:    fprintf (stderr, "ExplodeURL(%s)\n\t", url);
                    164:    if (*proto)
                    165:       fprintf (stderr, "proto : %s, ", *proto);
                    166:    if (*host)
                    167:       fprintf (stderr, "host : %s, ", *host);
                    168:    if (*dir)
                    169:       fprintf (stderr, "dir : %s, ", *dir);
                    170:    if (*file)
                    171:       fprintf (stderr, "file : %s ", *file);
                    172:    fprintf (stderr, "\n");
                    173: #endif
                    174: 
                    175: }
1.3       cvs       176: 
1.61      cvs       177: 
                    178: /*----------------------------------------------------------------------
                    179:    ExtractSuffix extract suffix from document nane.                
                    180:   ----------------------------------------------------------------------*/
                    181: #ifdef __STDC__
                    182: void                ExtractSuffix (STRING aName, STRING aSuffix)
                    183: #else
                    184: void                ExtractSuffix (aName, aSuffix)
                    185: STRING              aName;
                    186: STRING              aSuffix;
                    187: 
                    188: #endif
                    189: {
                    190:    int                 lg, i;
                    191:    STRING              ptr, oldptr;
                    192: 
                    193:    if (!aSuffix || !aName)
                    194:      /* bad suffix */
                    195:      return;
                    196: 
                    197:    aSuffix[0] = EOS;
                    198:    lg = ustrlen (aName);
                    199:    if (lg)
                    200:      {
                    201:        /* the name is not empty */
                    202:        oldptr = ptr = &aName[0];
                    203:        do
                    204:          {
                    205:             ptr = ustrrchr (oldptr, '.');
                    206:             if (ptr)
                    207:                oldptr = &ptr[1];
                    208:          }
                    209:        while (ptr);
                    210: 
                    211:        i = (int) (oldptr) - (int) (aName);     /* name length */
                    212:        if (i > 1)
                    213:          {
                    214:             aName[i - 1] = EOS;
                    215:             if (i != lg)
                    216:                ustrcpy (aSuffix, oldptr);
                    217:          }
                    218:      }
                    219: }
                    220: 
1.4       cvs       221: /*----------------------------------------------------------------------
1.9       cvs       222:   IsHTMLName                                                         
                    223:   returns TRUE if path points to an HTML resource.
1.4       cvs       224:   ----------------------------------------------------------------------*/
1.3       cvs       225: #ifdef __STDC__
1.34      cvs       226: boolean             IsHTMLName (const char *path)
1.3       cvs       227: #else  /* __STDC__ */
                    228: boolean             IsHTMLName (path)
1.34      cvs       229: const char         *path;
1.3       cvs       230: #endif /* __STDC__ */
                    231: {
1.5       cvs       232:    char                temppath[MAX_LENGTH];
                    233:    char                suffix[MAX_LENGTH];
                    234:    char                nsuffix[MAX_LENGTH];
                    235:    int                 i;
                    236: 
                    237:    if (!path)
1.37      cvs       238:       return (FALSE);
1.5       cvs       239: 
                    240:    strcpy (temppath, path);
                    241:    ExtractSuffix (temppath, suffix);
                    242: 
                    243:    /* Normalize the suffix */
                    244:    i = 0;
1.39      cvs       245:    while (suffix[i] != EOS && i < MAX_LENGTH -1)
1.13      cvs       246:      {
1.25      cvs       247:        nsuffix[i] = tolower (suffix[i]);
1.13      cvs       248:        i++;
                    249:      }
1.5       cvs       250:    nsuffix[i] = EOS;
1.60      cvs       251:    if (!strcmp (nsuffix, "html") ||
                    252:        !strcmp (nsuffix, "htm") ||
1.63      cvs       253:        !strcmp (nsuffix, "shtml") ||
                    254:        !strcmp (nsuffix, "xht") ||
                    255:        !strcmp (nsuffix, "xhtm") ||
                    256:        !strcmp (nsuffix, "xhtml"))
1.39      cvs       257:      return (TRUE);
1.22      cvs       258:    else if (!strcmp (nsuffix, "gz"))
1.13      cvs       259:      {
1.39      cvs       260:        /* take into account compressed files */
1.13      cvs       261:        ExtractSuffix (temppath, suffix);       
                    262:        /* Normalize the suffix */
                    263:        i = 0;
1.39      cvs       264:        while (suffix[i] != EOS && i < MAX_LENGTH -1)
1.13      cvs       265:         {
1.25      cvs       266:           nsuffix[i] = tolower (suffix[i]);
1.13      cvs       267:           i++;
                    268:         }
                    269:        nsuffix[i] = EOS;
1.60      cvs       270:        if (!strcmp (nsuffix, "html") ||
                    271:           !strcmp (nsuffix, "htm") ||
1.63      cvs       272:           !strcmp (nsuffix, "shtml") ||
                    273:           !strcmp (nsuffix, "xht") ||
                    274:           !strcmp (nsuffix, "xhtm") ||
                    275:           !strcmp (nsuffix, "xhtml"))
                    276:  
1.39      cvs       277:         return (TRUE);
                    278:        else
1.13      cvs       279:         return (FALSE);
                    280:      }
                    281:    else
1.39      cvs       282:      return (FALSE);
1.3       cvs       283: }
                    284: 
1.4       cvs       285: /*----------------------------------------------------------------------
1.56      cvs       286:   IsXMLName                                                         
                    287:   returns TRUE if path points to an XML resource.
                    288:   ----------------------------------------------------------------------*/
                    289: #ifdef __STDC__
                    290: boolean             IsXMLName (const char *path)
                    291: #else  /* __STDC__ */
                    292: boolean             IsXMLName (path)
                    293: const char         *path;
                    294: #endif /* __STDC__ */
                    295: {
                    296:    char                temppath[MAX_LENGTH];
                    297:    char                suffix[MAX_LENGTH];
                    298: 
                    299:    if (!path)
                    300:       return (FALSE);
                    301: 
                    302:    strcpy (temppath, path);
                    303:    ExtractSuffix (temppath, suffix);
                    304: 
1.64    ! cvs       305:    if (!strcasecmp (suffix, "xml") ||
        !           306:        !strcasecmp (suffix, "xht") ||
        !           307:        !strcmp (suffix, "xhtm") ||
        !           308:        !strcmp (suffix, "xhtml"))
1.56      cvs       309:      return (TRUE);
                    310:    else if (!strcmp (suffix, "gz"))
                    311:      {
                    312:        /* take into account compressed files */
                    313:        ExtractSuffix (temppath, suffix);       
1.64    ! cvs       314:        if (!strcasecmp (suffix, "xml") ||
        !           315:           !strcasecmp (suffix, "xht") ||
        !           316:           !strcmp (suffix, "xhtm") ||
        !           317:           !strcmp (suffix, "xhtml"))
1.60      cvs       318:         return (TRUE);
                    319:        else
                    320:         return (FALSE);
                    321:      }
                    322:    else
                    323:      return (FALSE);
                    324: }
                    325: 
                    326: /*----------------------------------------------------------------------
                    327:   IsCSSName                                                         
                    328:   returns TRUE if path points to an XML resource.
                    329:   ----------------------------------------------------------------------*/
                    330: #ifdef __STDC__
                    331: boolean             IsCSSName (const char *path)
                    332: #else  /* __STDC__ */
                    333: boolean             IsCSSName (path)
                    334: const char         *path;
                    335: #endif /* __STDC__ */
                    336: {
                    337:    char                temppath[MAX_LENGTH];
                    338:    char                suffix[MAX_LENGTH];
                    339: 
                    340:    if (!path)
                    341:       return (FALSE);
                    342: 
                    343:    strcpy (temppath, path);
                    344:    ExtractSuffix (temppath, suffix);
                    345: 
                    346:    if (!strcasecmp (suffix, "css"))
                    347:      return (TRUE);
                    348:    else if (!strcmp (suffix, "gz"))
                    349:      {
                    350:        /* take into account compressed files */
                    351:        ExtractSuffix (temppath, suffix);       
                    352:        if (!strcasecmp (suffix, "css"))
1.56      cvs       353:         return (TRUE);
                    354:        else
                    355:         return (FALSE);
                    356:      }
                    357:    else
                    358:      return (FALSE);
                    359: }
                    360: 
                    361: /*----------------------------------------------------------------------
1.9       cvs       362:   IsImageName                                
                    363:   returns TRUE if path points to an image resource.
1.4       cvs       364:   ----------------------------------------------------------------------*/
1.3       cvs       365: #ifdef __STDC__
1.34      cvs       366: boolean             IsImageName (const char *path)
1.3       cvs       367: #else  /* __STDC__ */
                    368: boolean             IsImageName (path)
1.34      cvs       369: const char         *path;
1.3       cvs       370: #endif /* __STDC__ */
                    371: {
1.5       cvs       372:    char                temppath[MAX_LENGTH];
                    373:    char                suffix[MAX_LENGTH];
                    374:    char                nsuffix[MAX_LENGTH];
                    375:    int                 i;
                    376: 
                    377:    if (!path)
1.13      cvs       378:       return (FALSE);
1.5       cvs       379: 
                    380:    strcpy (temppath, path);
                    381:    ExtractSuffix (temppath, suffix);
                    382: 
                    383:    /* Normalize the suffix */
                    384:    i = 0;
1.39      cvs       385:    while (suffix[i] != EOS && i < MAX_LENGTH -1)
1.13      cvs       386:      {
1.25      cvs       387:        nsuffix[i] = tolower (suffix[i]);
1.13      cvs       388:        i++;
                    389:      }
1.5       cvs       390:    nsuffix[i] = EOS;
1.39      cvs       391:    if ((!strcmp (nsuffix, "gif")) || (!strcmp (nsuffix, "xbm")) ||
                    392:        (!strcmp (nsuffix, "xpm")) || (!strcmp (nsuffix, "jpg")) ||
                    393:        (!strcmp (nsuffix, "png")) || (!strcmp (nsuffix, "au")))
                    394:       return (TRUE);
                    395:    return (FALSE);
1.3       cvs       396: }
                    397: 
1.4       cvs       398: /*----------------------------------------------------------------------
1.58      cvs       399:   IsImageType                                
                    400:   returns TRUE if type points to an image resource.
                    401:   ----------------------------------------------------------------------*/
                    402: #ifdef __STDC__
                    403: boolean             IsImageType (const char *type)
                    404: #else  /* __STDC__ */
                    405: boolean             IsImageType (type)
                    406: const char         *type;
                    407: #endif /* __STDC__ */
                    408: {
                    409:    char                temptype[MAX_LENGTH];
                    410:    int                 i;
                    411: 
                    412:    if (!type)
                    413:       return (FALSE);
                    414: 
                    415:    strcpy (temptype, type);
                    416:    /* Normalize the type */
                    417:    i = 0;
                    418:    while (temptype[i] != EOS)
                    419:      {
                    420:        temptype[i] = tolower (temptype[i]);
                    421:        i++;
                    422:      }
                    423:    if ((!strcmp (temptype, "gif")) || (!strcmp (temptype, "x-xbitmap")) ||
                    424:        (!strcmp (temptype, "x-xpixmap")) || (!strcmp (temptype, "jpeg")) ||
                    425:        (!strcmp (temptype, "png")))
                    426:       return (TRUE);
                    427:    return (FALSE);
                    428: }
                    429: 
                    430: /*----------------------------------------------------------------------
1.9       cvs       431:   IsTextName                                                         
1.4       cvs       432:   ----------------------------------------------------------------------*/
1.3       cvs       433: #ifdef __STDC__
1.34      cvs       434: boolean             IsTextName (const char *path)
1.3       cvs       435: #else  /* __STDC__ */
                    436: boolean             IsTextName (path)
1.34      cvs       437: const char         *path;
1.3       cvs       438: 
                    439: #endif /* __STDC__ */
                    440: {
1.5       cvs       441:    char                temppath[MAX_LENGTH];
                    442:    char                suffix[MAX_LENGTH];
                    443:    char                nsuffix[MAX_LENGTH];
                    444:    int                 i;
                    445: 
                    446:    if (!path)
1.13      cvs       447:      return (FALSE);
1.5       cvs       448: 
                    449:    strcpy (temppath, path);
                    450:    ExtractSuffix (temppath, suffix);
                    451: 
                    452:    /* Normalize the suffix */
                    453:    i = 0;
1.39      cvs       454:    while (suffix[i] != EOS && i < MAX_LENGTH -1)
1.5       cvs       455:      {
1.25      cvs       456:        nsuffix[i] = tolower (suffix[i]);
1.5       cvs       457:        i++;
                    458:      }
                    459:    nsuffix[i] = EOS;
                    460: 
1.39      cvs       461:    if ((!strcmp (nsuffix, "txt")) || (!strcmp (nsuffix, "dtd")))
1.13      cvs       462:       return (TRUE);
1.22      cvs       463:    else if (!strcmp (nsuffix, "gz"))
1.13      cvs       464:      {
1.39      cvs       465:        /* take into account compressed files */
1.13      cvs       466:        ExtractSuffix (temppath, suffix);       
                    467:        /* Normalize the suffix */
                    468:        i = 0;
1.39      cvs       469:        while (suffix[i] != EOS && i < MAX_LENGTH -1)
1.13      cvs       470:         {
1.25      cvs       471:           nsuffix[i] = tolower (suffix[i]);
1.13      cvs       472:           i++;
                    473:         }
                    474:        nsuffix[i] = EOS;
1.39      cvs       475:        if ((!strcmp (nsuffix, "txt")) || (!strcmp (nsuffix, "dtd")))
1.13      cvs       476:         return (TRUE);
                    477:        else
                    478:         return (FALSE);
                    479:      }
                    480:    else
                    481:      return (FALSE);
1.3       cvs       482: }
                    483: 
1.4       cvs       484: /*----------------------------------------------------------------------
1.9       cvs       485:   IsHTTPPath                                     
                    486:   returns TRUE if path is in fact an http URL.
1.4       cvs       487:   ----------------------------------------------------------------------*/
1.3       cvs       488: #ifdef __STDC__
1.34      cvs       489: boolean             IsHTTPPath (const char *path)
1.3       cvs       490: #else  /* __STDC__ */
                    491: boolean             IsHTTPPath (path)
1.34      cvs       492: const char         *path;
1.3       cvs       493: #endif /* __STDC__ */
                    494: {
1.5       cvs       495:    if (!path)
                    496:       return FALSE;
1.3       cvs       497: 
1.58      cvs       498:    if ((!strncmp (path, "http:", 5) != 0)
                    499:        || !strncmp (path, "internal:", 9))
                    500:       return TRUE;
                    501:    return FALSE;
1.3       cvs       502: }
                    503: 
1.4       cvs       504: /*----------------------------------------------------------------------
1.9       cvs       505:   IsWithParameters                           
                    506:   returns TRUE if url has a concatenated query string.
1.4       cvs       507:   ----------------------------------------------------------------------*/
1.3       cvs       508: #ifdef __STDC__
1.34      cvs       509: boolean             IsWithParameters (const char *url)
1.3       cvs       510: #else  /* __STDC__ */
1.9       cvs       511: boolean             IsWithParameters (url)
1.34      cvs       512: const char         *url;
1.3       cvs       513: #endif /* __STDC__ */
                    514: {
1.5       cvs       515:    int                 i;
1.3       cvs       516: 
1.9       cvs       517:    if ((!url) || (url[0] == EOS))
1.5       cvs       518:       return FALSE;
1.3       cvs       519: 
1.9       cvs       520:    i = strlen (url) - 1;
                    521:    while (i > 0 && url[i--] != '?')
1.5       cvs       522:       if (i < 0)
                    523:         return FALSE;
1.3       cvs       524: 
1.5       cvs       525:    /* There is a parameter */
                    526:    return TRUE;
1.3       cvs       527: }
                    528: 
1.4       cvs       529: /*----------------------------------------------------------------------
1.9       cvs       530:   IsW3Path                                           
                    531:   returns TRUE if path is in fact a URL.
1.4       cvs       532:   ----------------------------------------------------------------------*/
1.3       cvs       533: #ifdef __STDC__
1.34      cvs       534: boolean             IsW3Path (const char *path)
1.3       cvs       535: #else  /* __STDC__ */
                    536: boolean             IsW3Path (path)
1.34      cvs       537: const char               *path;
1.3       cvs       538: #endif /* __STDC__ */
                    539: {
1.5       cvs       540:    if ((strncmp (path, "http:", 5)) && (strncmp (path, "ftp:", 4)) &&
                    541:        (strncmp (path, "telnet:", 7)) && (strncmp (path, "wais:", 5)) &&
                    542:        (strncmp (path, "news:", 5)) && (strncmp (path, "gopher:", 7)) &&
                    543:        (strncmp (path, "mailto:", 7)) && (strncmp (path, "archie:", 7)))
                    544:       return FALSE;
                    545:    return TRUE;
1.3       cvs       546: }
                    547: 
1.4       cvs       548: /*----------------------------------------------------------------------
1.9       cvs       549:   IsValidProtocol                                                    
                    550:   returns true if the url protocol is supported by Amaya.
1.4       cvs       551:   ----------------------------------------------------------------------*/
1.3       cvs       552: #ifdef __STDC__
1.34      cvs       553: boolean             IsValidProtocol (const char *url)
1.3       cvs       554: #else  /* __STDC__ */
1.9       cvs       555: boolean             IsValidProtocol (url)
1.34      cvs       556: const char         *url;
1.3       cvs       557: #endif /* __STDC__ */
                    558: {
1.58      cvs       559:    if (!strncmp (url, "http:", 5)
                    560:       || !strncmp (url, "internal:", 9))
1.22      cvs       561:        /* experimental */
1.58      cvs       562:       /***  || !strncmp (url, "ftp:", 4) ***/
1.24      cvs       563:      /*** || !strncmp (path, "news:", 5)***/ 
1.8       cvs       564:       return (TRUE);
1.5       cvs       565:    else
1.8       cvs       566:       return (FALSE);
1.3       cvs       567: }
                    568: 
1.31      cvs       569: 
                    570: /*----------------------------------------------------------------------
                    571:    GetBaseURL
                    572:    normalizes orgName according to a base associated with doc, and
                    573:    following the standard URL format rules.
                    574:    The function returns the base used to solve relative URL and SRC:
                    575:       - the base of the document,
                    576:       - or the document path (without document name).
                    577:   ----------------------------------------------------------------------*/
                    578: #ifdef __STDC__
                    579: char               *GetBaseURL (Document doc)
                    580: #else  /* __STDC__ */
                    581: char               *GetBaseURL (doc)
                    582: Document            doc;
                    583: #endif /* __STDC__ */
                    584: {
                    585:   Element             el;
                    586:   ElementType         elType;
                    587:   AttributeType       attrType;
                    588:   Attribute           attr;
                    589:   char               *ptr, *basename;
                    590:   int                 length;
                    591: 
1.57      cvs       592:   /* @@@ irene */
                    593:   if (!DocumentURLs[doc])
                    594:          return NULL;
1.31      cvs       595:   basename = TtaGetMemory (MAX_LENGTH);
1.39      cvs       596:   strncpy (basename, DocumentURLs[doc], MAX_LENGTH-1);
                    597:   basename[MAX_LENGTH-1] = EOS;
1.31      cvs       598:   length = MAX_LENGTH -1;
                    599:   /* get the root element    */
                    600:   el = TtaGetMainRoot (doc);
                    601:   /* search the BASE element */
                    602:   elType.ElSSchema = TtaGetDocumentSSchema (doc);
                    603:   elType.ElTypeNum = HTML_EL_BASE;
                    604:   el = TtaSearchTypedElement (elType, SearchInTree, el);
                    605:   if (el)
                    606:     {
                    607:       /*  The document has a BASE element -> Get the HREF attribute */
                    608:       attrType.AttrSSchema = elType.ElSSchema;
                    609:       attrType.AttrTypeNum = HTML_ATTR_HREF_;
                    610:       attr = TtaGetAttribute (el, attrType);
                    611:       if (attr)
                    612:        {
                    613:          /* Use the base path of the document */
                    614:          TtaGiveTextAttributeValue (attr, basename, &length);
                    615:          /* base and orgName have to be separated by a DIR_SEP */
                    616:          length--;
1.43      cvs       617:          if (basename[0] != EOS && basename[length] != URL_SEP && basename[length] != DIR_SEP) 
1.31      cvs       618:            /* verify if the base has the form "protocol://server:port" */
                    619:            {
1.33      cvs       620:              ptr = AmayaParseUrl (basename, "", AMAYA_PARSE_ACCESS |
                    621:                                                 AMAYA_PARSE_HOST |
                    622:                                                 AMAYA_PARSE_PUNCTUATION);
1.31      cvs       623:              if (ptr && !strcmp (ptr, basename))
                    624:                {
1.43      cvs       625:                  /* it has this form, we complete it by adding a URL_STR  */
                    626:                  if (strchr (basename, DIR_SEP))
                    627:                    strcat (basename, DIR_STR);
                    628:                  else
                    629:                    strcat (basename, URL_STR);
1.31      cvs       630:                  length++;
                    631:                }
                    632:              if (ptr)
                    633:                TtaFreeMemory (ptr);
                    634:            }
                    635:        }
1.33      cvs       636:       }
                    637:   
1.31      cvs       638:   /* Remove anything after the last DIR_SEP char. If no such char is found,
                    639:    * then search for the first ":" char, hoping that what's before that is a
                    640:    * protocol. If found, end the string there. If neither char is found,
                    641:    * then discard the whole base element.
                    642:    */
                    643:   length = strlen (basename) - 1;
                    644:   /* search for the last DIR_SEP char */
1.43      cvs       645:   while (length >= 0  && basename[length] != URL_SEP && basename[length] != DIR_SEP)
1.31      cvs       646:     length--;
                    647:   if (length >= 0)
                    648:     /* found the last DIR_SEP char, end the string there */
                    649:     basename[length + 1] = EOS;                   
                    650:   else
                    651:     /* search for the first PATH_STR char */
                    652:     {
1.32      cvs       653:       for (length = 0; basename[length] != ':' && 
1.31      cvs       654:             basename[length] != EOS; length ++);
1.32      cvs       655:       if (basename[length] == ':')
1.31      cvs       656:        /* found, so end the string there */
                    657:        basename[length + 1] = EOS;
                    658:       else
                    659:        /* not found, discard the base */
                    660:        basename[0] = EOS;
                    661:     }
                    662:   return (basename);
                    663: }
                    664: 
                    665: 
1.4       cvs       666: /*----------------------------------------------------------------------
1.40      cvs       667:    GetLocalPath
                    668:    Allocate and return the local document path associated to the url
                    669:   ----------------------------------------------------------------------*/
                    670: #ifdef __STDC__
                    671: char      *GetLocalPath (Document doc, char *url)
                    672: #else  /* __STDC__ */
                    673: char      *GetLocalPath (doc, url)
                    674: Document   doc;
                    675: char      *url;
                    676: #endif /* __STDC__ */
                    677: {
1.46      cvs       678:   char    *ptr, *n;
1.40      cvs       679:   char    *documentname;
1.41      cvs       680:   char     url_sep;
1.40      cvs       681:   int      len;
                    682:   boolean  noFile;
                    683: 
                    684:   if (url != NULL)
                    685:     {
                    686:       /* check whether the file name exists */
                    687:       len = strlen (url) - 1;
1.41      cvs       688:       if (IsW3Path)
                    689:        url_sep = '/';
                    690:       else 
                    691:        url_sep = DIR_SEP;
                    692:       noFile = (url[len] == url_sep);
1.40      cvs       693:       if (noFile)
                    694:        url[len] = EOS;
1.47      cvs       695:       ptr = TtaGetMemory (MAX_LENGTH);
                    696:       documentname = TtaGetMemory (MAX_LENGTH);
1.40      cvs       697:       TtaExtractName (url, ptr, documentname);
                    698:       sprintf (ptr, "%s%s%d%s", TempFileDirectory, DIR_STR, doc, DIR_STR);
                    699:       if (!TtaCheckDirectory (ptr))
                    700:        /* directory did not exist */
1.59      cvs       701: #   ifdef _WINDOWS
                    702:        _mkdir (ptr);
                    703: #   else  /* !_WINDOWS */
1.40      cvs       704:        mkdir (ptr, S_IRWXU);
1.59      cvs       705: #   endif /* !_WINDOWS */
1.47      cvs       706: 
                    707:       /* don't include the query string within document name */
                    708:       n = strrchr(documentname, '?');
                    709:       if (n != NULL)
                    710:        *n = EOS;
1.46      cvs       711:       /* don't include ':' within document name */
                    712:       n = strchr (documentname, ':');
                    713:       if (n != NULL)
                    714:        *n = EOS;
1.40      cvs       715:       strcat (ptr, documentname);
                    716:       TtaFreeMemory (documentname);
                    717:       /* restore the url */
                    718:       if (noFile)
1.41      cvs       719:        url[len] = url_sep;
1.40      cvs       720:       return (ptr);
                    721:     }
                    722:   else
                    723:     return (NULL);
                    724: }
                    725: 
                    726: 
                    727: /*----------------------------------------------------------------------
1.9       cvs       728:    NormalizeURL
                    729:    normalizes orgName according to a base associated with doc, and
                    730:    following the standard URL format rules.
1.53      cvs       731:    if doc is 0 and otherPath not NULL, normalizes orgName according to this
                    732:    other path.
1.9       cvs       733:    The function returns the new complete and normalized URL 
1.12      cvs       734:    or file name path (newName) and the name of the document (docName).        
1.9       cvs       735:    N.B. If the function can't find out what's the docName, it assigns
                    736:    the name "noname.html".
1.4       cvs       737:   ----------------------------------------------------------------------*/
1.3       cvs       738: #ifdef __STDC__
1.53      cvs       739: void                NormalizeURL (char *orgName, Document doc, char *newName, char *docName, char *otherPath)
1.3       cvs       740: #else  /* __STDC__ */
1.53      cvs       741: void                NormalizeURL (orgName, doc, newName, docName, otherPath)
1.3       cvs       742: char               *orgName;
                    743: Document            doc;
                    744: char               *newName;
                    745: char               *docName;
1.53      cvs       746: char               *otherPath;
1.3       cvs       747: #endif /* __STDC__ */
                    748: {
1.31      cvs       749:    char               *basename;
1.18      cvs       750:    char                tempOrgName[MAX_LENGTH];
1.5       cvs       751:    char               *ptr;
1.49      cvs       752:    char                used_sep;
1.5       cvs       753:    int                 length;
1.49      cvs       754:    boolean             check;
1.5       cvs       755: 
1.44      cvs       756: #  ifdef _WINDOWS
                    757:    int ndx;
                    758: #  endif /* _WINDOWS */
                    759: 
1.5       cvs       760:    if (!newName || !docName)
                    761:       return;
1.18      cvs       762: 
1.32      cvs       763:    if (doc != 0)
1.53      cvs       764:      basename = GetBaseURL (doc);
                    765:    else if (otherPath != NULL)
                    766:      basename = TtaStrdup (otherPath);
1.32      cvs       767:    else
1.53      cvs       768:      basename = NULL;
1.32      cvs       769: 
1.18      cvs       770:    /*
1.31      cvs       771:     * Clean orgName
                    772:     * Make sure we have a complete orgName, without any leading or trailing
                    773:     * white spaces, or trailinbg new lines
                    774:     */
1.5       cvs       775:    ptr = orgName;
1.18      cvs       776:    /* skip leading white space and new line characters */
1.19      cvs       777:    while ((*ptr == ' ' || *ptr == EOL) && *ptr++ != EOS);
1.39      cvs       778:    strncpy (tempOrgName, ptr, MAX_LENGTH -1);
                    779:    tempOrgName[MAX_LENGTH -1] = EOS;
1.18      cvs       780:    /*
1.31      cvs       781:     * Make orgName a complete URL
                    782:     * If the URL does not include a protocol, then try to calculate
                    783:     * one using the doc's base element (if it exists),
                    784:     */
1.53      cvs       785:    if (tempOrgName[0] == EOS)
                    786:      {
                    787:        newName[0] = EOS;
                    788:        TtaFreeMemory (basename);
                    789:        return;
                    790:      }
1.49      cvs       791: 
                    792:    /* clean trailing white space */
                    793:    length = strlen (tempOrgName) - 1;
1.53      cvs       794:    while (tempOrgName[length] == SPACE && tempOrgName[length] == EOL)
                    795:      {
                    796:        tempOrgName[length] = EOS;
                    797:        length--;
                    798:      }
1.50      cvs       799: 
1.55      cvs       800:    /* remove extra dot (which dot???) */
                    801:    /* ugly, but faster than a strcmp */
                    802:    if (tempOrgName[length] == '.'
                    803:        && (length == 0 || tempOrgName[length-1] != '.'))
                    804:         tempOrgName[length] = EOS;
1.50      cvs       805: 
1.53      cvs       806:    if (IsW3Path (tempOrgName))
                    807:      {
                    808:        /* the name is complete, go to the Sixth Step */
                    809:        strcpy (newName, tempOrgName);
                    810:        SimplifyUrl (&newName);
                    811:        /* verify if the URL has the form "protocol://server:port" */
                    812:        ptr = AmayaParseUrl (newName, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
                    813:        if (ptr && !strcmp (ptr, newName)) /* it has this form, we complete it by adding a DIR_STR  */
1.50      cvs       814:          strcat (newName, URL_STR);
1.49      cvs       815: 
1.53      cvs       816:        if (ptr)
1.50      cvs       817:          TtaFreeMemory (ptr);
1.53      cvs       818:      }
                    819:    else if ( basename == NULL)
                    820:      /* the name is complete, go to the Sixth Step */
1.18      cvs       821:      strcpy (newName, tempOrgName);
1.53      cvs       822:    else
                    823:      {
1.31      cvs       824:        /* Calculate the absolute URL, using the base or document URL */
1.44      cvs       825: #      ifdef _WINDOWS
1.53      cvs       826:        if (!IsW3Path (basename))
                    827:         {
                    828:           length = strlen (tempOrgName);
                    829:           for (ndx = 0; ndx < length; ndx++)
                    830:             if (tempOrgName [ndx] == '/')
                    831:               tempOrgName [ndx] = '\\';
                    832:         }
1.44      cvs       833: #      endif /* _WINDOWS */
1.25      cvs       834:        ptr = AmayaParseUrl (tempOrgName, basename, AMAYA_PARSE_ALL);
1.53      cvs       835:        if (ptr)
                    836:         {
                    837:           SimplifyUrl (&ptr);
                    838:           strcpy (newName, ptr);
                    839:           TtaFreeMemory (ptr);
                    840:         }
                    841:        else
                    842:         newName[0] = EOS;
                    843:      }
1.36      cvs       844: 
                    845:    TtaFreeMemory (basename);
1.18      cvs       846:    /*
1.31      cvs       847:     * Prepare the docname that will refer to this ressource in the
                    848:     * .amaya directory. If the new URL finishes on DIR_SEP, then use
                    849:     * noname.html as a default ressource name
1.18      cvs       850:    */
1.53      cvs       851:    if (newName[0] != EOS)
                    852:      {
                    853:        length = strlen (newName) - 1;
                    854:        if (newName[length] == URL_SEP || newName[length] == DIR_SEP)
                    855:         {
                    856:           used_sep = newName[length];
                    857:           check = TRUE;
                    858:           while (check)
                    859:             {
1.50      cvs       860:                length--;
                    861:                while (length >= 0 && newName[length] != used_sep)
1.53      cvs       862:                 length--;
                    863:                if (!strncmp (&newName[length+1], "..", 2))
                    864:                 {
                    865:                   newName[length+1] = EOS;
                    866:                   /* remove also previous directory */
                    867:                   length--;
                    868:                   while (length >= 0 && newName[length] != used_sep)
                    869:                     length--;
                    870:                   if (strncmp (&newName[length+1], "//", 2))
                    871:                     /* don't remove server name */
1.50      cvs       872:                      newName[length+1] = EOS;
1.53      cvs       873:                 }
                    874:               else if (!strncmp (&newName[length+1], ".", 1))
                    875:                 newName[length+1] = EOS;
1.50      cvs       876:                else
1.53      cvs       877:                 check = FALSE;
                    878:             }
                    879:           strcpy (docName, "noname.html");            
                    880:           /* docname was not comprised inside the URL, so let's */
                    881:           /* assign the default ressource name */
                    882:           strcpy (docName, "noname.html");
                    883:         }
                    884:        else
                    885:         { /* docname is comprised inside the URL */
1.50      cvs       886:            while (length >= 0 && newName[length] != URL_SEP && newName[length] != DIR_SEP)
1.53      cvs       887:             length--;
                    888:           if (length < 0)
1.50      cvs       889:              strcpy (docName, newName);
1.53      cvs       890:           else
                    891:             strcpy (docName, &newName[length+1]);
                    892:         }
                    893:      }
                    894:    else
                    895:      docName[0] = EOS;
1.18      cvs       896: } 
1.3       cvs       897: 
1.4       cvs       898: /*----------------------------------------------------------------------
1.9       cvs       899:   IsSameHost                                                         
1.4       cvs       900:   ----------------------------------------------------------------------*/
1.3       cvs       901: #ifdef __STDC__
1.34      cvs       902: boolean             IsSameHost (const char *url1, const char *url2)
1.3       cvs       903: #else  /* __STDC__ */
                    904: boolean             IsSameHost (url1, url2)
1.34      cvs       905: const char         *url1;
                    906: const char         *url2;
1.3       cvs       907: #endif /* __STDC__ */
                    908: {
1.34      cvs       909:    char            *basename_ptr1, *basename_ptr2;
                    910:    boolean          result;
1.3       cvs       911: 
1.25      cvs       912:    basename_ptr1 = AmayaParseUrl (url1, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
                    913:    basename_ptr2 = AmayaParseUrl (url2, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
1.3       cvs       914: 
1.5       cvs       915:    if (strcmp (basename_ptr1, basename_ptr2))
1.8       cvs       916:       result = FALSE;
1.5       cvs       917:    else
1.8       cvs       918:       result = TRUE;
1.3       cvs       919: 
1.25      cvs       920:    TtaFreeMemory (basename_ptr1);
                    921:    TtaFreeMemory (basename_ptr2);
1.5       cvs       922:    return (result);
1.3       cvs       923: }
                    924: 
                    925: 
1.4       cvs       926: /*----------------------------------------------------------------------
1.22      cvs       927:   HasKnownFileSuffix
                    928:   returns TRUE if path points to a file ending with a suffix.
                    929:   ----------------------------------------------------------------------*/
                    930: #ifdef __STDC__
1.34      cvs       931: boolean             HasKnownFileSuffix (const char *path)
1.22      cvs       932: #else  /* __STDC__ */
                    933: boolean             HasKnownFileSuffix (path)
1.34      cvs       934: const char         *path;
1.22      cvs       935: #endif /* __STDC__ */
                    936: {
1.29      cvs       937:    char            *root;
                    938:    char             temppath[MAX_LENGTH];
                    939:    char             suffix[MAX_LENGTH];
1.22      cvs       940: 
1.24      cvs       941:    if (!path || path[0] == EOS || path[strlen(path)] == DIR_SEP)
1.22      cvs       942:      return (FALSE);
                    943: 
1.29      cvs       944:    root = AmayaParseUrl(path, "", AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);
1.22      cvs       945: 
                    946:    if (root) 
                    947:      {
                    948:        strcpy (temppath, root);
1.25      cvs       949:        TtaFreeMemory (root);
1.22      cvs       950:        /* Get the suffix */
                    951:        ExtractSuffix (temppath, suffix); 
                    952: 
                    953:        if( suffix[0] == EOS)
                    954:         /* no suffix */
                    955:         return (FALSE);
                    956: 
                    957:        /* Normalize the suffix */
                    958:        ConvertToLowerCase (suffix);
                    959: 
1.23      cvs       960:        if (!strcmp (suffix, "gz"))
1.22      cvs       961:         /* skip the compressed suffix */
                    962:         {
                    963:         ExtractSuffix (temppath, suffix);
                    964:         if(suffix[0] == EOS)
                    965:           /* no suffix */
                    966:           return (FALSE);
                    967:          /* Normalize the suffix */
                    968:          ConvertToLowerCase (suffix);
                    969:         }
                    970: 
1.63      cvs       971:        if (strcmp (suffix, "gif") &&
                    972:           strcmp (suffix, "xbm") &&
                    973:           strcmp (suffix, "xpm") &&
                    974:           strcmp (suffix, "jpg") &&
                    975:           strcmp (suffix, "pdf") &&
                    976:           strcmp (suffix, "png") &&
                    977:           strcmp (suffix, "tgz") &&
                    978:           strcmp (suffix, "xpg") &&
                    979:           strcmp (suffix, "xpd") &&
                    980:           strcmp (suffix, "ps") &&
                    981:           strcmp (suffix, "au") &&
                    982:           strcmp (suffix, "html") &&
                    983:           strcmp (suffix, "htm") &&
                    984:           strcmp (suffix, "shtml") &&
                    985:           strcmp (suffix, "xht") &&
                    986:           strcmp (suffix, "xhtm") &&
                    987:           strcmp (suffix, "xhtml") &&
                    988:           strcmp (suffix, "txt") &&
                    989:           strcmp (suffix, "css") &&
                    990:           strcmp (suffix, "eps"))
1.22      cvs       991:         return (FALSE);
                    992:        else
                    993:         return (TRUE);
                    994:      }
                    995:    else
                    996:      return (FALSE);
                    997: }
                    998: 
                    999: 
                   1000: /*----------------------------------------------------------------------
1.24      cvs      1001:   ChopURL
                   1002:   Gives back a URL no longer than MAX_PRINT_URL_LENGTH chars (outputURL). 
                   1003:   If inputURL is  bigger than that size, outputURL receives
                   1004:   MAX_PRINT_URL_LENGTH / 2 chars from the beginning of inputURL, "...", 
                   1005:   and MAX_PRINT_URL_LENGTH / 2 chars from the end of inputURL.
                   1006:   If inputURL is not longer than MAX_PRINT_URL_LENGTH chars, it gets
                   1007:   copied into outputURL. 
                   1008:   N.B.: outputURL must point to a memory block of MAX_PRINT_URL_LENGTH
                   1009:   chars.
                   1010:   ----------------------------------------------------------------------*/
                   1011: #ifdef __STDC__
1.34      cvs      1012: void ChopURL (char *outputURL, const char *inputURL)
1.24      cvs      1013: #else
                   1014: void ChopURL (outputURL, inputURL)
1.34      cvs      1015: char       *outputURL;
                   1016: const char *inputURL;
1.24      cvs      1017: #endif
1.22      cvs      1018: 
1.24      cvs      1019: {
                   1020:   int len;
1.9       cvs      1021: 
1.24      cvs      1022:   len = strlen (inputURL);
                   1023:   if (len <= MAX_PRINT_URL_LENGTH) 
1.29      cvs      1024:     strcpy (outputURL, inputURL);
1.24      cvs      1025:   else
                   1026:     /* make a truncated urlName on the status window */
                   1027:     {
                   1028:       strncpy (outputURL, inputURL, MAX_PRINT_URL_LENGTH / 2);
                   1029:       outputURL [MAX_PRINT_URL_LENGTH / 2] = EOS;
                   1030:       strcat (outputURL, "...");
                   1031:       strcat (outputURL, &(inputURL[len - MAX_PRINT_URL_LENGTH / 2 ]));
                   1032:     }
1.25      cvs      1033: }
                   1034: 
                   1035: 
                   1036: /*----------------------------------------------------------------------
                   1037:    scan
1.47      cvs      1038:        Scan a filename for its constituents
1.25      cvs      1039:        -----------------------------------
                   1040:   
                   1041:    On entry,
                   1042:        name    points to a document name which may be incomplete.
                   1043:    On exit,
                   1044:         absolute or relative may be nonzero (but not both).
                   1045:        host, fragment and access may be nonzero if they were specified.
                   1046:        Any which are nonzero point to zero terminated strings.
                   1047:   ----------------------------------------------------------------------*/
                   1048: #ifdef __STDC__
                   1049: static void scan (char * name, HTURI * parts)
                   1050: #else  /* __STDC__ */
                   1051: static void scan (name, parts)
                   1052: char                *name;
                   1053: HTURI               *parts;
                   1054: 
                   1055: #endif /* __STDC__ */
                   1056: {
1.43      cvs      1057:   char      *p;
                   1058:   char      *after_access = name;
1.32      cvs      1059: 
1.43      cvs      1060:   memset (parts, '\0', sizeof (HTURI));
1.28      cvs      1061:   /* Look for fragment identifier */
1.52      cvs      1062:   if ((p = strchr(name, '#')) != NULL)
1.28      cvs      1063:     {
                   1064:       *p++ = '\0';
                   1065:       parts->fragment = p;
1.25      cvs      1066:     }
                   1067:     
1.28      cvs      1068:   for (p=name; *p; p++)
                   1069:     {
1.43      cvs      1070:       if (*p == URL_SEP || *p == DIR_SEP || *p=='#' || *p=='?')
1.28      cvs      1071:        break;
1.32      cvs      1072:       if (*p==':')
1.28      cvs      1073:        {
                   1074:          *p = 0;
                   1075:          parts->access = after_access; /* Scheme has been specified */
                   1076: 
                   1077:          /* The combination of gcc, the "-O" flag and the HP platform is
                   1078:             unhealthy. The following three lines is a quick & dirty fix, but is
                   1079:             not recommended. Rather, turn off "-O". */
                   1080: 
                   1081:          /*            after_access = p;*/
                   1082:          /*            while (*after_access == 0)*/
                   1083:          /*                after_access++;*/
                   1084:          after_access = p+1;
1.43      cvs      1085:          if (!strcasecmp("URL", parts->access))
1.28      cvs      1086:            /* Ignore IETF's URL: pre-prefix */
                   1087:            parts->access = NULL;
                   1088:          else
1.25      cvs      1089:            break;
                   1090:        }
                   1091:     }
                   1092:     
                   1093:     p = after_access;
1.43      cvs      1094:     if (*p == URL_SEP || *p == DIR_SEP)
1.28      cvs      1095:       {
1.43      cvs      1096:        if (p[1] == URL_SEP)
1.28      cvs      1097:          {
1.25      cvs      1098:            parts->host = p+2;          /* host has been specified      */
1.28      cvs      1099:            *p = 0;                     /* Terminate access             */
                   1100:            /* look for end of host name if any */
1.43      cvs      1101:            p = strchr (parts->host, URL_SEP);
1.28      cvs      1102:            if (p)
                   1103:              {
1.43      cvs      1104:                *p = EOS;                       /* Terminate host */
1.25      cvs      1105:                parts->absolute = p+1;          /* Root has been found */
1.28      cvs      1106:              }
                   1107:          }
                   1108:        else
                   1109:          /* Root found but no host */
                   1110:          parts->absolute = p+1;
                   1111:       }
                   1112:     else
                   1113:       {
1.25      cvs      1114:         parts->relative = (*after_access) ? after_access : 0; /* zero for "" */
1.28      cvs      1115:       }
1.25      cvs      1116: }
                   1117: 
                   1118: 
                   1119: /*----------------------------------------------------------------------
1.28      cvs      1120:   AmayaParseUrl: parse a Name relative to another name
                   1121: 
                   1122:   This returns those parts of a name which are given (and requested)
                   1123:   substituting bits from the related name where necessary.
1.25      cvs      1124:   
1.28      cvs      1125:   On entry,
1.25      cvs      1126:        aName           A filename given
                   1127:         relatedName     A name relative to which aName is to be parsed. Give
                   1128:                         it an empty string if aName is absolute.
                   1129:         wanted          A mask for the bits which are wanted.
                   1130:   
1.28      cvs      1131:   On exit,
1.25      cvs      1132:        returns         A pointer to a malloc'd string which MUST BE FREED
                   1133:   ----------------------------------------------------------------------*/
                   1134: #ifdef __STDC__
1.34      cvs      1135: char          *AmayaParseUrl (const char *aName, char *relatedName, int wanted)
1.25      cvs      1136: #else  /* __STDC__ */
1.28      cvs      1137: char          *AmayaParseUrl (aName, relatedName, wanted)
1.34      cvs      1138: const char    *aName;
1.28      cvs      1139: char          *relatedName;
                   1140: int            wanted;
1.25      cvs      1141: 
                   1142: #endif /* __STDC__ */
                   1143: {
1.29      cvs      1144:   char      *return_value;
                   1145:   char       result[MAX_LENGTH];
                   1146:   char       name[MAX_LENGTH];
                   1147:   char       rel[MAX_LENGTH];
                   1148:   char      *p, *access;
                   1149:   HTURI      given, related;
                   1150:   int        len;
1.33      cvs      1151:   char       used_sep;
                   1152:   char      *used_str;
1.32      cvs      1153: 
1.43      cvs      1154:   if (strchr (aName, DIR_SEP) || strchr (relatedName, DIR_SEP))
1.33      cvs      1155:     {
1.42      cvs      1156:       used_str = DIR_STR;
                   1157:       used_sep = DIR_SEP;
1.33      cvs      1158:     }
1.32      cvs      1159:   else
1.33      cvs      1160:     {
1.42      cvs      1161:       used_str = URL_STR;
                   1162:       used_sep = URL_SEP;
1.33      cvs      1163:     }
1.32      cvs      1164: 
1.29      cvs      1165:   /* Make working copies of input strings to cut up: */
                   1166:   return_value = NULL;
                   1167:   result[0] = 0;               /* Clear string  */
                   1168:   strcpy (name, aName);
                   1169:   if (relatedName != NULL)  
                   1170:     strcpy (rel, relatedName);
                   1171:   else
                   1172:     relatedName[0] = EOS;
                   1173:   
                   1174:   scan (name, &given);
                   1175:   scan (rel,  &related); 
                   1176:   access = given.access ? given.access : related.access;
                   1177:   if (wanted & AMAYA_PARSE_ACCESS)
                   1178:     if (access)
                   1179:       {
                   1180:        strcat (result, access);
                   1181:        if(wanted & AMAYA_PARSE_PUNCTUATION)
1.32      cvs      1182:                strcat (result, ":");
1.29      cvs      1183:       }
                   1184:   
                   1185:   if (given.access && related.access)
                   1186:     /* If different, inherit nothing. */
                   1187:     if (strcmp (given.access, related.access) != 0)
                   1188:       {
                   1189:        related.host = 0;
                   1190:        related.absolute = 0;
                   1191:        related.relative = 0;
                   1192:        related.fragment = 0;
                   1193:       }
                   1194:   
                   1195:   if (wanted & AMAYA_PARSE_HOST)
                   1196:     if(given.host || related.host)
                   1197:       {
                   1198:        if(wanted & AMAYA_PARSE_PUNCTUATION)
                   1199:          strcat (result, "//");
                   1200:        strcat (result, given.host ? given.host : related.host);
                   1201:       }
                   1202:   
                   1203:   if (given.host && related.host)
                   1204:     /* If different hosts, inherit no path. */
                   1205:     if (strcmp(given.host, related.host) != 0)
                   1206:       {
                   1207:        related.absolute = 0;
                   1208:        related.relative = 0;
                   1209:        related.fragment = 0;
                   1210:       }
                   1211:   
                   1212:   if (wanted & AMAYA_PARSE_PATH)
                   1213:     {
                   1214:       if (given.absolute)
                   1215:        {
                   1216:          /* All is given */
                   1217:          if (wanted & AMAYA_PARSE_PUNCTUATION)
1.33      cvs      1218:            strcat (result, used_str);
1.29      cvs      1219:          strcat (result, given.absolute);
1.25      cvs      1220:        }
1.29      cvs      1221:       else if (related.absolute)
                   1222:        {
                   1223:          /* Adopt path not name */
1.33      cvs      1224:          strcat (result, used_str);
1.29      cvs      1225:          strcat (result, related.absolute);
                   1226:          if (given.relative)
                   1227:            {
                   1228:              /* Search part? */
                   1229:              p = strchr (result, '?');
                   1230:              if (!p)
                   1231:                p=result+strlen(result)-1;
1.33      cvs      1232:              for (; *p!=used_sep; p--);        /* last / */
1.29      cvs      1233:              /* Remove filename */
                   1234:              p[1]=0;
                   1235:              /* Add given one */
                   1236:              strcat (result, given.relative);
1.25      cvs      1237:            }
                   1238:        }
1.29      cvs      1239:       else if (given.relative)
                   1240:        /* what we've got */
                   1241:        strcat (result, given.relative);
                   1242:       else if (related.relative)
                   1243:        strcat (result, related.relative);
                   1244:       else
                   1245:        /* No inheritance */
1.33      cvs      1246:        strcat (result, used_str);
1.25      cvs      1247:     }
1.29      cvs      1248:   
                   1249:   if (wanted & AMAYA_PARSE_ANCHOR)
                   1250:     if (given.fragment || related.fragment)
                   1251:       {
                   1252:        if (given.absolute && given.fragment)
                   1253:          {
                   1254:            /*Fixes for relURLs...*/
                   1255:            if (wanted & AMAYA_PARSE_PUNCTUATION)
                   1256:              strcat (result, "#");
                   1257:            strcat (result, given.fragment); 
                   1258:          }
                   1259:        else if (!(given.absolute) && !(given.fragment))
                   1260:          strcat (result, "");
                   1261:        else
                   1262:          {
                   1263:            if (wanted & AMAYA_PARSE_PUNCTUATION)
                   1264:              strcat (result, "#");
                   1265:            strcat (result, given.fragment ? given.fragment : related.fragment); 
                   1266:          }
                   1267:       }
                   1268:   len = strlen (result);
                   1269:   if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)
                   1270:     strcpy (return_value, result);
                   1271:   return (return_value);               /* exactly the right length */
1.25      cvs      1272: }
                   1273: 
                   1274: /*----------------------------------------------------------------------
                   1275:      HTCanon
                   1276:        Canonicalizes the URL in the following manner starting from the host
                   1277:        pointer:
                   1278:   
                   1279:        1) The host name is converted to lowercase
                   1280:        2) Chop off port if `:80' (http), `:70' (gopher), or `:21' (ftp)
                   1281:   
                   1282:        Return: OK      The position of the current path part of the URL
                   1283:                        which might be the old one or a new one.
                   1284:   
                   1285:   ----------------------------------------------------------------------*/
                   1286: #ifdef __STDC__
1.28      cvs      1287: static char *HTCanon (char ** filename, char * host)
1.25      cvs      1288: #else  /* __STDC__ */
1.28      cvs      1289: static char *HTCanon (filename, host)
                   1290: char       **filename;
                   1291: char        *host;
1.25      cvs      1292: #endif /* __STDC__ */
                   1293: {
                   1294:     char *newname = NULL;
                   1295:     char *port;
                   1296:     char *strptr;
                   1297:     char *path;
                   1298:     char *access = host-3;
1.33      cvs      1299:     char       used_sep;
1.32      cvs      1300: 
                   1301:   
1.33      cvs      1302:      if (*filename && strchr (*filename, URL_SEP))
                   1303:        {
                   1304:         used_sep = URL_SEP;
                   1305:        }
                   1306:      else
                   1307:        {
                   1308:         used_sep = DIR_SEP;
                   1309:        }
1.32      cvs      1310:   
1.33      cvs      1311:     while (access>*filename && *(access-1)!= used_sep)       /* Find access method */
1.25      cvs      1312:        access--;
1.33      cvs      1313:     if ((path = strchr(host, used_sep)) == NULL)                       /* Find path */
1.25      cvs      1314:        path = host + strlen(host);
                   1315:     if ((strptr = strchr(host, '@')) != NULL && strptr<path)      /* UserId */
                   1316:        host = strptr;
1.32      cvs      1317:     if ((port = strchr(host, ':')) != NULL && port>path)      /* Port number */
1.25      cvs      1318:        port = NULL;
                   1319: 
                   1320:     strptr = host;                                 /* Convert to lower-case */
1.33      cvs      1321:     while (strptr<path)
                   1322:       {
1.25      cvs      1323:        *strptr = tolower(*strptr);
                   1324:        strptr++;
1.33      cvs      1325:       }
1.25      cvs      1326:     
                   1327:     /* Does the URL contain a full domain name? This also works for a
                   1328:        numerical host name. The domain name is already made lower-case
                   1329:        and without a trailing dot. */
                   1330:     {
1.33      cvs      1331:       char *dot = port ? port : path;
                   1332:       if (dot > *filename && *--dot=='.')
                   1333:        {
                   1334:          char *orig=dot, *dest=dot+1;
                   1335:          while((*orig++ = *dest++));
                   1336:          if (port) port--;
                   1337:          path--;
1.25      cvs      1338:        }
                   1339:     }
                   1340:     /* Chop off port if `:', `:80' (http), `:70' (gopher), or `:21' (ftp) */
1.33      cvs      1341:     if (port)
                   1342:       {
                   1343:        if (!*(port+1) || *(port+1)==used_sep)
                   1344:          {
                   1345:            if (!newname)
                   1346:              {
1.25      cvs      1347:                char *orig=port, *dest=port+1;
                   1348:                while((*orig++ = *dest++));
1.33      cvs      1349:              }
                   1350:          }
                   1351:        else if ((!strncmp(access, "http", 4) &&
                   1352:                  (*(port+1)=='8'&&*(port+2)=='0'&&(*(port+3)==used_sep||!*(port+3)))) ||
                   1353:                 (!strncmp(access, "gopher", 6) &&
                   1354:                  (*(port+1)=='7'&&*(port+2)=='0'&&(*(port+3)==used_sep||!*(port+3)))) ||
                   1355:                 (!strncmp(access, "ftp", 3) &&
                   1356:                  (*(port+1)=='2'&&*(port+2)=='1'&&(*(port+3)==used_sep||!*(port+3))))) {
                   1357:          if (!newname)
                   1358:            {
                   1359:              char *orig=port, *dest=port+3;
                   1360:              while((*orig++ = *dest++));
                   1361:              /* Update path position, Henry Minsky */
                   1362:              path -= 3;
1.25      cvs      1363:            }
1.33      cvs      1364:        }
                   1365:        else if (newname)
                   1366:          strncat(newname, port, (int) (path-port));
                   1367:       }
1.25      cvs      1368: 
1.33      cvs      1369:     if (newname)
                   1370:       {
1.25      cvs      1371:        char *newpath = newname+strlen(newname);
                   1372:        strcat(newname, path);
                   1373:        path = newpath;
1.28      cvs      1374:        /* Free old copy */
                   1375:        TtaFreeMemory(*filename);
1.25      cvs      1376:        *filename = newname;
1.33      cvs      1377:       }
1.25      cvs      1378:     return path;
                   1379: }
                   1380: 
                   1381: 
                   1382: /*----------------------------------------------------------------------
1.29      cvs      1383:   SimplifyUrl: simplify a URI
1.32      cvs      1384:   A URI is allowed to contain the sequence xxx/../ which may be
                   1385:   replaced by "" , and the sequence "/./" which may be replaced by DIR_STR.
1.28      cvs      1386:   Simplification helps us recognize duplicate URIs. 
1.25      cvs      1387:   
1.28      cvs      1388:   Thus,        /etc/junk/../fred       becomes /etc/fred
                   1389:                 /etc/junk/./fred       becomes /etc/junk/fred
1.25      cvs      1390:   
1.28      cvs      1391:   but we should NOT change
                   1392:                 http://fred.xxx.edu/../..
1.25      cvs      1393:   
                   1394:        or      ../../albert.html
                   1395:   
1.28      cvs      1396:   In order to avoid empty URLs the following URLs become:
1.25      cvs      1397:   
                   1398:                /fred/..                becomes /fred/..
                   1399:                /fred/././..            becomes /fred/..
                   1400:                /fred/.././junk/.././   becomes /fred/..
                   1401:   
1.28      cvs      1402:   If more than one set of `://' is found (several proxies in cascade) then
                   1403:   only the part after the last `://' is simplified.
1.25      cvs      1404:   
1.28      cvs      1405:   Returns: A string which might be the old one or a new one.
1.25      cvs      1406:   ----------------------------------------------------------------------*/
                   1407: #ifdef __STDC__
1.29      cvs      1408: void         SimplifyUrl (char ** url)
1.25      cvs      1409: #else  /* __STDC__ */
1.29      cvs      1410: void         SimplifyUrl (url)
1.28      cvs      1411: char        **url;
1.25      cvs      1412: #endif /* __STDC__ */
                   1413: {
1.28      cvs      1414:   char *path, *p;
                   1415:   char *newptr, *access;
                   1416:   char *orig, *dest, *end;
                   1417: 
1.33      cvs      1418:   char       used_sep;
1.32      cvs      1419: 
                   1420: 
1.28      cvs      1421:   if (!url || !*url)
                   1422:     return;
                   1423: 
1.33      cvs      1424:   if (strchr (*url, URL_SEP))
                   1425:     {
                   1426:       used_sep = URL_SEP;
                   1427:     }
1.32      cvs      1428:   else
1.33      cvs      1429:     {
                   1430:       used_sep = DIR_SEP;
                   1431:     }
1.32      cvs      1432: 
1.28      cvs      1433:   /* Find any scheme name */
                   1434:   if ((path = strstr(*url, "://")) != NULL)
1.33      cvs      1435:     {
                   1436:       /* Find host name */
1.28      cvs      1437:       access = *url;
                   1438:       while (access<path && (*access=tolower(*access)))
                   1439:        access++;
                   1440:       path += 3;
                   1441:       while ((newptr = strstr(path, "://")) != NULL)
                   1442:         /* For proxies */
                   1443:        path = newptr+3;
                   1444:       /* We have a host name */
                   1445:       path = HTCanon(url, path);
1.25      cvs      1446:     }
1.28      cvs      1447:   else if ((path = strstr(*url, ":/")) != NULL)
                   1448:     path += 2;
                   1449:   else
                   1450:     path = *url;
1.25      cvs      1451: 
1.33      cvs      1452:   if (*path == used_sep && *(path+1)==used_sep)
1.28      cvs      1453:     /* Some URLs start //<foo> */
                   1454:     path += 1;
                   1455:   else if (!strncmp(path, "news:", 5))
                   1456:     {
                   1457:       newptr = strchr(path+5, '@');
                   1458:       if (!newptr)
                   1459:        newptr = path + 5;
                   1460:       while (*newptr)
                   1461:        {
                   1462:          /* Make group or host lower case */
                   1463:          *newptr = tolower (*newptr);
                   1464:          newptr++;
1.25      cvs      1465:        }
1.28      cvs      1466:       /* Doesn't need to do any more */
                   1467:       return;
1.25      cvs      1468:     }
1.28      cvs      1469: 
                   1470:   if ((p = path))
                   1471:     {
                   1472:       if (!((end = strchr (path, ';')) || (end = strchr (path, '?')) ||
                   1473:            (end = strchr (path, '#'))))
                   1474:        end = path + strlen (path);
                   1475:       
                   1476:       /* Parse string second time to simplify */
                   1477:       p = path;
                   1478:       while (p < end)
                   1479:        {
1.33      cvs      1480:          if (*p==used_sep)
1.28      cvs      1481:            {
1.33      cvs      1482:              if (p > *url && *(p+1) == '.' && (*(p+2) == used_sep || !*(p+2)))
1.28      cvs      1483:                {
                   1484:                  orig = p + 1;
1.33      cvs      1485:                  dest = (*(p+2)!=used_sep) ? p+2 : p+3;
1.52      cvs      1486:                  while ((*orig++ = *dest++)); /* Remove a used_sep and a dot*/
1.28      cvs      1487:                  end = orig - 1;
                   1488:                }
1.33      cvs      1489:              else if (*(p+1)=='.' && *(p+2)=='.' && (*(p+3)==used_sep || !*(p+3)))
1.28      cvs      1490:                {
                   1491:                  newptr = p;
1.52      cvs      1492:                  while (newptr>path && *--newptr!=used_sep); /* prev used_sep */
                   1493:                  if (*newptr == used_sep)
                   1494:                    orig = newptr + 1;
1.28      cvs      1495:                  else
1.52      cvs      1496:                    orig = newptr;
                   1497: 
                   1498:                  dest = (*(p+3) != used_sep) ? p+3 : p+4;
                   1499:                  while ((*orig++ = *dest++)); /* Remove /xxx/.. */
                   1500:                  end = orig-1;
                   1501:                  /* Start again with prev slash */
                   1502:                  p = newptr;
1.28      cvs      1503:                }
1.33      cvs      1504:              else if (*(p+1) == used_sep)
1.28      cvs      1505:                {
1.33      cvs      1506:                  while (*(p+1) == used_sep)
1.28      cvs      1507:                    {
                   1508:                      orig = p;
                   1509:                      dest = p + 1;
                   1510:                      while ((*orig++ = *dest++));  /* Remove multiple /'s */
                   1511:                      end = orig-1;
                   1512:                    }
                   1513:                }
                   1514:              else
1.25      cvs      1515:                p++;
1.28      cvs      1516:            }
                   1517:          else
                   1518:            p++;
1.25      cvs      1519:        }
                   1520:     }
1.51      cvs      1521: 
                   1522:     /*
                   1523:     **  Check for host/../.. kind of things
                   1524:     */
1.52      cvs      1525:     if (*path==used_sep && *(path+1)=='.' && *(path+2)=='.' && (!*(path+3) || *(path+3)==used_sep))
1.51      cvs      1526:        *(path+1) = EOS;
                   1527: 
1.28      cvs      1528:   return;
                   1529: }
                   1530: 
                   1531: 
                   1532: /*----------------------------------------------------------------------
                   1533:    NormalizeFile normalizes  local names.                             
                   1534:    Return TRUE if target and src differ.                           
                   1535:   ----------------------------------------------------------------------*/
                   1536: #ifdef __STDC__
                   1537: boolean             NormalizeFile (char *src, char *target)
                   1538: #else
                   1539: boolean             NormalizeFile (src, target)
                   1540: char               *src;
                   1541: char               *target;
                   1542: 
                   1543: #endif
                   1544: {
                   1545:    char               *s;
                   1546:    boolean             change;
                   1547: 
1.54      cvs      1548:    change = FALSE;
1.53      cvs      1549:    if (strncmp (src, "file:", 5) == 0)
1.28      cvs      1550:      {
                   1551:        /* remove the prefix file: */
                   1552:        if (src[5] == EOS)
                   1553:           strcpy (target, DIR_STR);
                   1554:        else if (src[0] == '~')
                   1555:          {
                   1556:            /* replace ~ */
                   1557:            s = (char *) TtaGetEnvString ("HOME");
                   1558:            strcpy (target, s);
                   1559:            strcat (target, &src[5]);
                   1560:          }
                   1561:        else
                   1562:           strcpy (target, &src[5]);
1.54      cvs      1563:        change = TRUE;
1.28      cvs      1564:      }
1.53      cvs      1565: #  ifndef _WINDOWS
                   1566:    else if (src[0] == '~')
                   1567:      {
                   1568:        /* replace ~ */
                   1569:        s = (char *) TtaGetEnvString ("HOME");
                   1570:        strcpy (target, s);
                   1571:        if (src[1] != DIR_SEP)
                   1572:          strcat (target, DIR_STR);
                   1573:        strcat (target, &src[1]);
1.54      cvs      1574:        change = TRUE;
1.53      cvs      1575:      }
                   1576: #   endif /* _WINDOWS */
1.28      cvs      1577:    else
                   1578:       strcpy (target, src);
                   1579: 
                   1580:    /* remove /../ and /./ */
1.29      cvs      1581:    SimplifyUrl (&target);
1.54      cvs      1582:    if (!change)
                   1583:      change = strcmp (src, target);
1.28      cvs      1584:    return (change);
1.25      cvs      1585: }
                   1586: 
1.28      cvs      1587: 
1.25      cvs      1588: /*----------------------------------------------------------------------
1.31      cvs      1589:   MakeRelativeURL: make relative name
1.25      cvs      1590:   
1.28      cvs      1591:   This function creates and returns a string which gives an expression of
                   1592:   one address as related to another. Where there is no relation, an absolute
                   1593:   address is retured.
1.25      cvs      1594:   
1.28      cvs      1595:   On entry,
1.25      cvs      1596:        Both names must be absolute, fully qualified names of nodes
                   1597:        (no fragment bits)
                   1598:   
1.28      cvs      1599:   On exit,
1.25      cvs      1600:        The return result points to a newly allocated name which, if
                   1601:        parsed by AmayaParseUrl relative to relatedName, will yield aName.
                   1602:        The caller is responsible for freeing the resulting name later.
                   1603:   ----------------------------------------------------------------------*/
                   1604: #ifdef __STDC__
1.31      cvs      1605: char            *MakeRelativeURL (char *aName, char *relatedName)
1.25      cvs      1606: #else  /* __STDC__ */
1.31      cvs      1607: char            *MakeRelativeURL (aName, relatedName)
1.28      cvs      1608: char            *aName;
                   1609: char            *relatedName;
1.25      cvs      1610: #endif  /* __STDC__ */
                   1611: {
1.39      cvs      1612:   char          *return_value;
                   1613:   char           result[MAX_LENGTH];
1.29      cvs      1614:   char          *p;
1.34      cvs      1615:   char          *q;
1.29      cvs      1616:   char          *after_access;
                   1617:   char          *last_slash = NULL;
                   1618:   int            slashes, levels, len;
                   1619: 
1.44      cvs      1620: # ifdef _WINDOWS
                   1621:   int ndx;
                   1622: # endif /* _WINDOWS */
                   1623: 
1.29      cvs      1624:   if (aName == NULL || relatedName == NULL)
                   1625:     return (NULL);
                   1626: 
                   1627:   slashes = 0;
                   1628:   after_access = NULL;
                   1629:   p = aName;
                   1630:   q = relatedName;
                   1631:   for (; *p && (*p == *q); p++, q++)
1.27      cvs      1632:     {
                   1633:       /* Find extent of match */
1.32      cvs      1634:       if (*p == ':')
1.29      cvs      1635:        after_access = p + 1;
1.28      cvs      1636:       if (*p == DIR_SEP)
1.27      cvs      1637:        {
1.29      cvs      1638:          /* memorize the last slash position and count them */
1.27      cvs      1639:          last_slash = p;
                   1640:          slashes++;
1.25      cvs      1641:        }
                   1642:     }
                   1643:     
1.31      cvs      1644:   /* q, p point to the first non-matching character or zero */
                   1645:   if (*q == EOS)
                   1646:     {
                   1647:       /* New name is a subset of the related name */
                   1648:       /* exactly the right length */
                   1649:       len = strlen (p);
                   1650:       if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)
                   1651:        strcpy (return_value, p);
                   1652:     }
                   1653:   else if ((slashes < 2 && after_access == NULL)
                   1654:       || (slashes < 3 && after_access != NULL))
                   1655:     {
                   1656:       /* Two names whitout common path */
                   1657:       /* exactly the right length */
                   1658:       len = strlen (aName);
                   1659:       if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)
                   1660:        strcpy (return_value, aName);
                   1661:     }
                   1662:   else
                   1663:     {
                   1664:       /* Some path in common */
                   1665:       if (slashes == 3 && strncmp (aName, "http:", 5) == 0)
                   1666:        /* just the same server */
                   1667:        strcpy (result, last_slash);
                   1668:       else
                   1669:        {
                   1670:          levels= 0; 
1.52      cvs      1671:          for (; *q && *q != '#' && *q!=';' && *q!='?'; q++)
1.31      cvs      1672:            if (*q == DIR_SEP)
                   1673:              levels++;
                   1674:          
1.52      cvs      1675:          result[0] = EOS;
1.31      cvs      1676:          for (;levels; levels--)
                   1677:            strcat (result, "../");
                   1678:          strcat (result, last_slash+1);
                   1679:        } 
1.52      cvs      1680: 
                   1681:       if (!*result)
                   1682:        strcat (result, "./");
                   1683: 
1.31      cvs      1684:       /* exactly the right length */
                   1685:       len = strlen (result);
                   1686:       if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)
                   1687:        strcpy (return_value, result);
1.52      cvs      1688: 
1.25      cvs      1689:     }
1.44      cvs      1690: # ifdef _WINDOWS
                   1691:   len = strlen (return_value);
                   1692:   for (ndx = 0; ndx < len; ndx ++)
                   1693:          if (return_value[ndx] == '\\')
                   1694:             return_value[ndx] = '/' ;
                   1695: # endif /* _WINDOWS */
1.29      cvs      1696:   return (return_value);
1.24      cvs      1697: }
1.35      cvs      1698: 
                   1699: 

Webmaster