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

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

Webmaster