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

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.87      cvs        14:  *          R. Guetari: Windows & Unicode.
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"
1.100     kahan      23: #include "query_f.h"
1.8       cvs        24: 
1.24      cvs        25: #define MAX_PRINT_URL_LENGTH 50
1.29      cvs        26: typedef struct _HTURI {
1.67      cvs        27:     STRING  access;            /* Now known as "scheme" */
                     28:     STRING  host;
                     29:     STRING  absolute;
                     30:     STRING  relative;
                     31:     STRING  fragment;
1.29      cvs        32: } HTURI;
1.24      cvs        33: 
1.28      cvs        34: 
                     35: /*----------------------------------------------------------------------
                     36:   ConvertToLowerCase
                     37:   Converts a string to lowercase.
                     38:   ----------------------------------------------------------------------*/
1.22      cvs        39: #ifdef __STDC__
1.67      cvs        40: void         ConvertToLowerCase (STRING string)
1.28      cvs        41: #else  /* __STDC__ */
1.38      cvs        42: void         ConvertToLowerCase (string)
1.67      cvs        43: STRING       string;
1.28      cvs        44: 
                     45: #endif /* __STDC__ */
                     46: {
                     47:  int i;
1.93      cvs        48:  
1.28      cvs        49:  if (!string)
                     50:    return;
                     51: 
1.87      cvs        52:  for (i = 0; string[i] != WC_EOS; i++)
1.67      cvs        53:    string[i] = utolower (string[i]);
1.28      cvs        54: }
1.22      cvs        55: 
1.8       cvs        56: /*----------------------------------------------------------------------
1.75      cvs        57:   EscapeChar
                     58:   writes the equivalent escape code of a char in a string
                     59:   ----------------------------------------------------------------------*/
                     60: #ifdef __STDC__
                     61: void         EscapeChar (STRING string, UCHAR_T c)
                     62: #else
                     63: void         EscapeChar (string, c)
                     64: STRING              string;
                     65: UCHAR_T               c;
                     66: 
                     67: #endif
                     68: {
                     69:    c &= 0xFF;                   /* strange behavior under solaris? */
                     70:    usprintf (string, TEXT("%02x"), (unsigned int) c);
                     71: }
                     72: 
                     73: /*----------------------------------------------------------------------
1.96      cvs        74:   UnEscapeChar
                     75:   writes the equivalent hex code to a %xx coded char
                     76:   ----------------------------------------------------------------------*/
                     77: #ifdef __STDC__
                     78: static CHAR_T UnEscapeChar (CHAR_T c)
                     79: #else
                     80: static CHAR_T UnEscapeChar (c)
                     81: CHAR_T               c;
                     82: #endif
                     83: {
                     84:     return  c >= TEXT('0') && c <= TEXT('9') ?  c - TEXT('0')
                     85:             : c >= TEXT('A') && c <= TEXT('F') ? c - TEXT('A') + 10
                     86:             : c - TEXT('a') + 10;   /* accept small letters just in case */
                     87: }
                     88: 
                     89: /*----------------------------------------------------------------------
1.75      cvs        90:   EscapeURL
                     91:   Takes a URL and escapes all protected chars into
                     92:   %xx sequences. Also, removes any leading white spaces
                     93:   Returns either NULL or a new buffer, which must be freed by the caller
                     94:   ----------------------------------------------------------------------*/
                     95: #ifdef __STDC__
                     96: STRING EscapeURL (const STRING url)
                     97: #else
                     98: STRING EscapeURL (url)
                     99: STRING url;
                    100: #endif /* __STDC__ */
                    101: {
                    102:   STRING buffer;
                    103:   int buffer_len;
                    104:   int buffer_free_mem;
                    105:   PCHAR_T ptr;
                    106:   int new_chars;
                    107:   void *status;
                    108: 
                    109:   if (url && *url)
                    110:     {
1.76      cvs       111:       buffer_free_mem = ustrlen (url) + 20;
                    112:       buffer = TtaAllocString (buffer_free_mem + 1);
1.75      cvs       113:       ptr = url;
                    114:       buffer_len = 0;
                    115: 
                    116:       while (*ptr)
                    117:         {
                    118:           switch (*ptr)
                    119:             {
                    120:               /* put here below all the chars that need to
                    121:                  be escaped into %xx */
1.81      cvs       122:             case 0x27: /* &amp */
                    123:             case 0x20: /* space */
1.75      cvs       124:               new_chars = 3; 
                    125:               break;
                    126: 
                    127:             default:
                    128:               new_chars = 1; 
                    129:               break;
                    130:             }
                    131: 
                    132:           /* see if we need extra room in the buffer */
                    133:           if (new_chars > buffer_free_mem)
                    134:             {
1.76      cvs       135:               buffer_free_mem = 20;
1.75      cvs       136:               status = TtaRealloc (buffer, sizeof (CHAR_T) 
                    137:                                   * (buffer_len + buffer_free_mem + 1));
                    138:               if (status)
                    139:                 buffer = (STRING) status;
                    140:               else {
                    141:                 /* @@ maybe we should do some other behavior here, like
                    142:                    freeing the buffer and return a void thing */
1.87      cvs       143:                 buffer[buffer_len] = WC_EOS;
1.75      cvs       144:                 break;
                    145:               }
                    146:             }
                    147:          /* escape the char */
                    148:           if (new_chars == 3)
                    149:             {
                    150:               buffer[buffer_len] = TEXT('%');
                    151:               EscapeChar (&buffer[buffer_len+1], *ptr);
                    152:             }
                    153:           else
                    154:             buffer[buffer_len] = *ptr;
                    155: 
                    156:           /* update the status */
                    157:           buffer_len += new_chars;
                    158:           buffer_free_mem -= new_chars;
                    159:           /* examine the next char */
                    160:           ptr++;
                    161:         }
1.87      cvs       162:       buffer[buffer_len] = WC_EOS;
1.75      cvs       163:     }
1.76      cvs       164:   else
                    165:     buffer = NULL;
                    166: 
1.75      cvs       167:   return (buffer);
                    168: }
                    169: 
                    170: 
                    171: /*----------------------------------------------------------------------
1.11      cvs       172:   ExplodeURL 
1.8       cvs       173:   ----------------------------------------------------------------------*/
                    174: #ifdef __STDC__
                    175: void                ExplodeURL (char *url, char **proto, char **host, char **dir, char **file)
                    176: #else
                    177: void                ExplodeURL (url, proto, host, dir, file)
                    178: char               *url;
                    179: char              **proto;
                    180: char              **host;
                    181: char              **dir;
                    182: char              **file;
                    183: 
                    184: #endif
                    185: {
1.33      cvs       186:    char            *curr, *temp;
                    187:    char             used_sep;
1.32      cvs       188: 
1.33      cvs       189:    if (url && strchr (url, URL_SEP))
                    190:      used_sep = URL_SEP;
                    191:    else
                    192:      used_sep = DIR_SEP;
1.8       cvs       193: 
                    194:    if ((url == NULL) || (proto == NULL) || (host == NULL) ||
                    195:        (dir == NULL) || (file == NULL))
                    196:       return;
                    197: 
                    198:    /* initialize every pointer */
                    199:    *proto = *host = *dir = *file = NULL;
                    200: 
                    201:    /* skip any leading space */
                    202:    while ((*url == SPACE) || (*url == TAB))
                    203:       url++;
1.9       cvs       204:    curr = url;
                    205:    if (*curr == 0)
1.8       cvs       206:       goto finished;
                    207: 
                    208:    /* go to the end of the URL */
1.68      cvs       209:    while ((*curr != EOS) && (*curr != SPACE) && (*curr != BSPACE) &&
                    210:          (*curr != __CR__) && (*curr != EOL))
1.9       cvs       211:       curr++;
1.8       cvs       212: 
                    213:    /* mark the end of the chain */
1.9       cvs       214:    *curr = EOS;
                    215:    curr--;
                    216:    if (curr <= url)
1.8       cvs       217:       goto finished;
                    218: 
                    219:    /* search the next DIR_SEP indicating the beginning of the file name */
                    220:    do
1.11      cvs       221:      curr--;
1.33      cvs       222:    while ((curr >= url) && (*curr != used_sep));
1.11      cvs       223: 
1.9       cvs       224:    if (curr < url)
1.8       cvs       225:       goto finished;
1.9       cvs       226:    *file = curr + 1;
1.8       cvs       227: 
                    228:    /* mark the end of the dir */
1.9       cvs       229:    *curr = EOS;
                    230:    curr--;
                    231:    if (curr < url)
1.8       cvs       232:       goto finished;
                    233: 
1.29      cvs       234:    /* search for the DIR_STR indicating the host name start */
1.33      cvs       235:    while ((curr > url) && ((*curr != used_sep) || (*(curr + 1) != used_sep)))
1.9       cvs       236:       curr--;
1.8       cvs       237: 
                    238:    /* if we found it, separate the host name from the directory */
1.33      cvs       239:    if ((*curr == DIR_SEP) && (*(curr + 1) == used_sep))
1.8       cvs       240:      {
1.9       cvs       241:        *host = temp = curr + 2;
1.33      cvs       242:        while ((*temp != 0) && (*temp != used_sep))
1.8       cvs       243:           temp++;
1.33      cvs       244:        if (*temp == used_sep)
1.8       cvs       245:          {
                    246:             *temp = EOS;
                    247:             *dir = temp + 1;
                    248:          }
                    249:      }
                    250:    else
1.11      cvs       251:      *dir = curr;
                    252: 
1.9       cvs       253:    if (curr <= url)
1.8       cvs       254:       goto finished;
                    255: 
                    256:    /* mark the end of the proto */
1.9       cvs       257:    *curr = EOS;
                    258:    curr--;
                    259:    if (curr < url)
1.8       cvs       260:       goto finished;
                    261: 
1.67      cvs       262:    if (*curr == TEXT(':'))
1.8       cvs       263:      {
1.9       cvs       264:        *curr = EOS;
                    265:        curr--;
1.8       cvs       266:      }
                    267:    else
                    268:       goto finished;
1.11      cvs       269: 
1.9       cvs       270:    if (curr < url)
1.8       cvs       271:       goto finished;
1.9       cvs       272:    while ((curr > url) && (isalpha (*curr)))
                    273:       curr--;
                    274:    *proto = curr;
1.8       cvs       275: 
                    276:  finished:;
                    277: 
                    278: #ifdef AMAYA_DEBUG
                    279:    fprintf (stderr, "ExplodeURL(%s)\n\t", url);
                    280:    if (*proto)
                    281:       fprintf (stderr, "proto : %s, ", *proto);
                    282:    if (*host)
                    283:       fprintf (stderr, "host : %s, ", *host);
                    284:    if (*dir)
                    285:       fprintf (stderr, "dir : %s, ", *dir);
                    286:    if (*file)
                    287:       fprintf (stderr, "file : %s ", *file);
                    288:    fprintf (stderr, "\n");
                    289: #endif
                    290: 
                    291: }
1.3       cvs       292: 
1.61      cvs       293: 
                    294: /*----------------------------------------------------------------------
                    295:    ExtractSuffix extract suffix from document nane.                
                    296:   ----------------------------------------------------------------------*/
                    297: #ifdef __STDC__
1.91      cvs       298: void                ExtractSuffix (CHAR_T* aName, CHAR_T* aSuffix)
1.61      cvs       299: #else
                    300: void                ExtractSuffix (aName, aSuffix)
1.91      cvs       301: CHAR_T*             aName;
                    302: CHAR_T*             aSuffix;
1.61      cvs       303: 
                    304: #endif
                    305: {
                    306:    int                 lg, i;
                    307:    STRING              ptr, oldptr;
                    308: 
                    309:    if (!aSuffix || !aName)
                    310:      /* bad suffix */
                    311:      return;
                    312: 
1.87      cvs       313:    aSuffix[0] = WC_EOS;
1.61      cvs       314:    lg = ustrlen (aName);
                    315:    if (lg)
                    316:      {
                    317:        /* the name is not empty */
                    318:        oldptr = ptr = &aName[0];
                    319:        do
                    320:          {
1.67      cvs       321:             ptr = ustrrchr (oldptr, TEXT('.'));
1.61      cvs       322:             if (ptr)
                    323:                oldptr = &ptr[1];
                    324:          }
                    325:        while (ptr);
                    326: 
                    327:        i = (int) (oldptr) - (int) (aName);     /* name length */
                    328:        if (i > 1)
                    329:          {
1.87      cvs       330:             aName[i - 1] = WC_EOS;
1.61      cvs       331:             if (i != lg)
                    332:                ustrcpy (aSuffix, oldptr);
                    333:          }
                    334:      }
                    335: }
                    336: 
1.4       cvs       337: /*----------------------------------------------------------------------
1.9       cvs       338:   IsHTMLName                                                         
                    339:   returns TRUE if path points to an HTML resource.
1.4       cvs       340:   ----------------------------------------------------------------------*/
1.3       cvs       341: #ifdef __STDC__
1.84      cvs       342: ThotBool             IsHTMLName (const CHAR_T* path)
1.3       cvs       343: #else  /* __STDC__ */
1.67      cvs       344: ThotBool             IsHTMLName (path)
1.84      cvs       345: const CHAR_T*        path;
1.3       cvs       346: #endif /* __STDC__ */
                    347: {
1.101   ! cvs       348:   CHAR_T            temppath[MAX_LENGTH];
        !           349:   CHAR_T            suffix[MAX_LENGTH];
        !           350:   CHAR_T            nsuffix[MAX_LENGTH];
        !           351:   int               i; 
1.5       cvs       352: 
1.101   ! cvs       353:   if (!path)
        !           354:     return (FALSE);
1.5       cvs       355: 
1.101   ! cvs       356:   ustrcpy (temppath, path);
        !           357:   ExtractSuffix (temppath, suffix);
        !           358:   i = 0;
        !           359:   while (suffix[i] != WC_EOS)
        !           360:     {
        !           361:       /* Normalize the suffix */
        !           362:       i = 0;
        !           363:       while (suffix[i] != WC_EOS && i < MAX_LENGTH -1)
        !           364:        {
        !           365:          nsuffix[i] = utolower (suffix[i]);
        !           366:          i++;
        !           367:        }
        !           368:       nsuffix[i] = WC_EOS;
        !           369:       if (!ustrcmp (nsuffix, TEXT("html")) ||
        !           370:          !ustrcmp (nsuffix, TEXT("htm")) ||
        !           371:          !ustrcmp (nsuffix, TEXT("shtml")) ||
        !           372:          !ustrcmp (nsuffix, TEXT("jsp")) ||
        !           373:          !ustrcmp (nsuffix, TEXT("xht")) ||
        !           374:          !ustrcmp (nsuffix, TEXT("xhtm")) ||
        !           375:          !ustrcmp (nsuffix, TEXT("xhtml")))
        !           376:        return (TRUE);
        !           377:       else if (!ustrcmp (nsuffix, TEXT("gz")))
        !           378:        {
        !           379:          /* take into account compressed files */
        !           380:          ExtractSuffix (temppath, suffix);       
        !           381:          /* Normalize the suffix */
        !           382:          i = 0;
        !           383:          while (suffix[i] != WC_EOS && i < MAX_LENGTH -1)
        !           384:            {
        !           385:              nsuffix[i] = utolower (suffix[i]);
        !           386:              i++;
        !           387:            }
        !           388:          nsuffix[i] = WC_EOS;
        !           389:          if (!ustrcmp (nsuffix, TEXT("html")) ||
        !           390:              !ustrcmp (nsuffix, TEXT("htm")) ||
        !           391:              !ustrcmp (nsuffix, TEXT("shtml")) ||
        !           392:              !ustrcmp (nsuffix, TEXT("jsp")) ||
        !           393:              !ustrcmp (nsuffix, TEXT("xht")) ||
        !           394:              !ustrcmp (nsuffix, TEXT("xhtm")) ||
        !           395:              !ustrcmp (nsuffix, TEXT("xhtml")))
        !           396:            return (TRUE);
        !           397:          else
        !           398:            return (FALSE);
        !           399:        }
        !           400:       else
        !           401:        /* check if there is another suffix */
        !           402:        ExtractSuffix (temppath, suffix);
        !           403:     }
1.88      cvs       404:    return (FALSE);
1.3       cvs       405: }
                    406: 
1.4       cvs       407: /*----------------------------------------------------------------------
1.56      cvs       408:   IsXMLName                                                         
                    409:   returns TRUE if path points to an XML resource.
                    410:   ----------------------------------------------------------------------*/
                    411: #ifdef __STDC__
1.67      cvs       412: ThotBool             IsXMLName (const STRING path)
1.56      cvs       413: #else  /* __STDC__ */
1.67      cvs       414: ThotBool             IsXMLName (path)
                    415: const STRING        path;
1.56      cvs       416: #endif /* __STDC__ */
                    417: {
1.67      cvs       418:    CHAR_T              temppath[MAX_LENGTH];
                    419:    CHAR_T              suffix[MAX_LENGTH];
1.56      cvs       420: 
                    421:    if (!path)
                    422:       return (FALSE);
                    423: 
1.67      cvs       424:    ustrcpy (temppath, path);
1.56      cvs       425:    ExtractSuffix (temppath, suffix);
                    426: 
1.67      cvs       427:    if (!ustrcasecmp (suffix, TEXT("xml")) ||
                    428:        !ustrcasecmp (suffix, TEXT("xht")) ||
                    429:        !ustrcmp (suffix, TEXT("xhtm")) ||
                    430:        !ustrcmp (suffix, TEXT("xhtml")))
1.56      cvs       431:      return (TRUE);
1.67      cvs       432:    else if (!ustrcmp (suffix, TEXT("gz")))
1.56      cvs       433:      {
                    434:        /* take into account compressed files */
                    435:        ExtractSuffix (temppath, suffix);       
1.67      cvs       436:        if (!ustrcasecmp (suffix, TEXT("xml")) ||
                    437:           !ustrcasecmp (suffix, TEXT("xht")) ||
                    438:           !ustrcmp (suffix, TEXT("xhtm")) ||
                    439:           !ustrcmp (suffix, TEXT("xhtml")))
1.60      cvs       440:         return (TRUE);
                    441:        else
                    442:         return (FALSE);
                    443:      }
                    444:    else
                    445:      return (FALSE);
                    446: }
                    447: 
                    448: /*----------------------------------------------------------------------
                    449:   IsCSSName                                                         
                    450:   returns TRUE if path points to an XML resource.
                    451:   ----------------------------------------------------------------------*/
                    452: #ifdef __STDC__
1.67      cvs       453: ThotBool             IsCSSName (const STRING path)
1.60      cvs       454: #else  /* __STDC__ */
1.67      cvs       455: ThotBool             IsCSSName (path)
                    456: const STRING        path;
1.60      cvs       457: #endif /* __STDC__ */
                    458: {
1.67      cvs       459:    CHAR_T              temppath[MAX_LENGTH];
                    460:    CHAR_T              suffix[MAX_LENGTH];
1.60      cvs       461: 
                    462:    if (!path)
                    463:       return (FALSE);
                    464: 
1.67      cvs       465:    ustrcpy (temppath, path);
1.60      cvs       466:    ExtractSuffix (temppath, suffix);
                    467: 
1.67      cvs       468:    if (!ustrcasecmp (suffix, TEXT("css")))
1.60      cvs       469:      return (TRUE);
1.67      cvs       470:    else if (!ustrcmp (suffix, TEXT("gz")))
1.60      cvs       471:      {
                    472:        /* take into account compressed files */
                    473:        ExtractSuffix (temppath, suffix);       
1.67      cvs       474:        if (!ustrcasecmp (suffix, TEXT("css")))
1.56      cvs       475:         return (TRUE);
                    476:        else
                    477:         return (FALSE);
                    478:      }
                    479:    else
                    480:      return (FALSE);
                    481: }
                    482: 
                    483: /*----------------------------------------------------------------------
1.9       cvs       484:   IsImageName                                
                    485:   returns TRUE if path points to an image resource.
1.4       cvs       486:   ----------------------------------------------------------------------*/
1.3       cvs       487: #ifdef __STDC__
1.67      cvs       488: ThotBool             IsImageName (const STRING path)
1.3       cvs       489: #else  /* __STDC__ */
1.67      cvs       490: ThotBool             IsImageName (path)
                    491: const STRING        path;
1.3       cvs       492: #endif /* __STDC__ */
                    493: {
1.67      cvs       494:    CHAR_T                temppath[MAX_LENGTH];
                    495:    CHAR_T                suffix[MAX_LENGTH];
                    496:    CHAR_T                nsuffix[MAX_LENGTH];
1.5       cvs       497:    int                 i;
                    498: 
                    499:    if (!path)
1.13      cvs       500:       return (FALSE);
1.5       cvs       501: 
1.67      cvs       502:    ustrcpy (temppath, path);
1.5       cvs       503:    ExtractSuffix (temppath, suffix);
                    504: 
                    505:    /* Normalize the suffix */
                    506:    i = 0;
1.87      cvs       507:    while (suffix[i] != WC_EOS && i < MAX_LENGTH -1)
1.13      cvs       508:      {
1.67      cvs       509:        nsuffix[i] = utolower (suffix[i]);
1.13      cvs       510:        i++;
                    511:      }
1.87      cvs       512:    nsuffix[i] = WC_EOS;
1.67      cvs       513:    if ((!ustrcmp (nsuffix, TEXT("gif"))) || (!ustrcmp (nsuffix, TEXT("xbm"))) ||
                    514:        (!ustrcmp (nsuffix, TEXT("xpm"))) || (!ustrcmp (nsuffix, TEXT("jpg"))) ||
                    515:        (!ustrcmp (nsuffix, TEXT("png"))) || (!ustrcmp (nsuffix, TEXT("au"))))
1.39      cvs       516:       return (TRUE);
                    517:    return (FALSE);
1.3       cvs       518: }
                    519: 
1.4       cvs       520: /*----------------------------------------------------------------------
1.58      cvs       521:   IsImageType                                
                    522:   returns TRUE if type points to an image resource.
                    523:   ----------------------------------------------------------------------*/
                    524: #ifdef __STDC__
1.67      cvs       525: ThotBool             IsImageType (const STRING type)
1.58      cvs       526: #else  /* __STDC__ */
1.67      cvs       527: ThotBool             IsImageType (type)
                    528: const STRING     type;
1.58      cvs       529: #endif /* __STDC__ */
                    530: {
1.67      cvs       531:    CHAR_T              temptype[MAX_LENGTH];
1.58      cvs       532:    int                 i;
                    533: 
                    534:    if (!type)
                    535:       return (FALSE);
                    536: 
1.67      cvs       537:    ustrcpy (temptype, type);
1.58      cvs       538:    /* Normalize the type */
                    539:    i = 0;
1.87      cvs       540:    while (temptype[i] != WC_EOS)
1.58      cvs       541:      {
                    542:        temptype[i] = tolower (temptype[i]);
                    543:        i++;
                    544:      }
1.67      cvs       545:    if ((!ustrcmp (temptype, TEXT("gif"))) || (!ustrcmp (temptype, TEXT("x-xbitmap"))) ||
                    546:        (!ustrcmp (temptype, TEXT("x-xpixmap"))) || (!ustrcmp (temptype, TEXT("jpeg"))) ||
                    547:        (!ustrcmp (temptype, TEXT("png"))))
1.58      cvs       548:       return (TRUE);
                    549:    return (FALSE);
                    550: }
                    551: 
                    552: /*----------------------------------------------------------------------
1.9       cvs       553:   IsTextName                                                         
1.4       cvs       554:   ----------------------------------------------------------------------*/
1.3       cvs       555: #ifdef __STDC__
1.67      cvs       556: ThotBool             IsTextName (const STRING path)
1.3       cvs       557: #else  /* __STDC__ */
1.67      cvs       558: ThotBool             IsTextName (path)
                    559: const STRING        path;
1.3       cvs       560: 
                    561: #endif /* __STDC__ */
                    562: {
1.67      cvs       563:    CHAR_T                temppath[MAX_LENGTH];
                    564:    CHAR_T                suffix[MAX_LENGTH];
                    565:    CHAR_T                nsuffix[MAX_LENGTH];
1.5       cvs       566:    int                 i;
                    567: 
                    568:    if (!path)
1.13      cvs       569:      return (FALSE);
1.5       cvs       570: 
1.67      cvs       571:    ustrcpy (temppath, path);
1.5       cvs       572:    ExtractSuffix (temppath, suffix);
                    573: 
                    574:    /* Normalize the suffix */
                    575:    i = 0;
1.87      cvs       576:    while (suffix[i] != WC_EOS && i < MAX_LENGTH -1)
1.5       cvs       577:      {
1.25      cvs       578:        nsuffix[i] = tolower (suffix[i]);
1.5       cvs       579:        i++;
                    580:      }
1.87      cvs       581:    nsuffix[i] = WC_EOS;
1.5       cvs       582: 
1.67      cvs       583:    if ((!ustrcmp (nsuffix, TEXT("txt"))) || (!ustrcmp (nsuffix, TEXT("dtd"))))
1.13      cvs       584:       return (TRUE);
1.67      cvs       585:    else if (!ustrcmp (nsuffix, TEXT("gz")))
1.13      cvs       586:      {
1.39      cvs       587:        /* take into account compressed files */
1.13      cvs       588:        ExtractSuffix (temppath, suffix);       
                    589:        /* Normalize the suffix */
                    590:        i = 0;
1.87      cvs       591:        while (suffix[i] != WC_EOS && i < MAX_LENGTH -1)
1.13      cvs       592:         {
1.25      cvs       593:           nsuffix[i] = tolower (suffix[i]);
1.13      cvs       594:           i++;
                    595:         }
1.87      cvs       596:        nsuffix[i] = WC_EOS;
1.67      cvs       597:        if ((!ustrcmp (nsuffix, TEXT("txt"))) || (!ustrcmp (nsuffix, TEXT("dtd"))))
1.13      cvs       598:         return (TRUE);
                    599:        else
                    600:         return (FALSE);
                    601:      }
                    602:    else
                    603:      return (FALSE);
1.3       cvs       604: }
                    605: 
1.4       cvs       606: /*----------------------------------------------------------------------
1.9       cvs       607:   IsHTTPPath                                     
                    608:   returns TRUE if path is in fact an http URL.
1.4       cvs       609:   ----------------------------------------------------------------------*/
1.3       cvs       610: #ifdef __STDC__
1.67      cvs       611: ThotBool             IsHTTPPath (const STRING path)
1.3       cvs       612: #else  /* __STDC__ */
1.67      cvs       613: ThotBool             IsHTTPPath (path)
                    614: const STRING       path;
1.3       cvs       615: #endif /* __STDC__ */
                    616: {
1.5       cvs       617:    if (!path)
                    618:       return FALSE;
1.3       cvs       619: 
1.67      cvs       620:    if ((!ustrncmp (path, TEXT("http:"), 5) != 0)
1.100     kahan     621:        || (AHTFTPURL_flag () && !ustrncmp (path, TEXT("ftp:"), 4))
1.67      cvs       622:        || !ustrncmp (path, TEXT("internal:"), 9))
1.58      cvs       623:       return TRUE;
                    624:    return FALSE;
1.3       cvs       625: }
                    626: 
1.4       cvs       627: /*----------------------------------------------------------------------
1.9       cvs       628:   IsWithParameters                           
                    629:   returns TRUE if url has a concatenated query string.
1.4       cvs       630:   ----------------------------------------------------------------------*/
1.3       cvs       631: #ifdef __STDC__
1.66      cvs       632: ThotBool            IsWithParameters (const char *url)
1.3       cvs       633: #else  /* __STDC__ */
1.66      cvs       634: ThotBool            IsWithParameters (url)
1.34      cvs       635: const char         *url;
1.3       cvs       636: #endif /* __STDC__ */
                    637: {
1.5       cvs       638:    int                 i;
1.3       cvs       639: 
1.9       cvs       640:    if ((!url) || (url[0] == EOS))
1.5       cvs       641:       return FALSE;
1.3       cvs       642: 
1.9       cvs       643:    i = strlen (url) - 1;
                    644:    while (i > 0 && url[i--] != '?')
1.5       cvs       645:       if (i < 0)
                    646:         return FALSE;
1.3       cvs       647: 
1.5       cvs       648:    /* There is a parameter */
                    649:    return TRUE;
1.3       cvs       650: }
                    651: 
1.4       cvs       652: /*----------------------------------------------------------------------
1.9       cvs       653:   IsW3Path                                           
                    654:   returns TRUE if path is in fact a URL.
1.4       cvs       655:   ----------------------------------------------------------------------*/
1.3       cvs       656: #ifdef __STDC__
1.84      cvs       657: ThotBool             IsW3Path (const CHAR_T* path)
1.3       cvs       658: #else  /* __STDC__ */
1.67      cvs       659: ThotBool             IsW3Path (path)
1.84      cvs       660: const CHAR_T*        path;
1.3       cvs       661: #endif /* __STDC__ */
                    662: {
1.84      cvs       663:   if (ustrncmp (path, TEXT("http:"), 5)   && 
                    664:       ustrncmp (path, TEXT("ftp:"), 4)    &&
                    665:       ustrncmp (path, TEXT("telnet:"), 7) && 
                    666:       ustrncmp (path, TEXT("wais:"), 5)   &&
                    667:       ustrncmp (path, TEXT("news:"), 5)   && 
                    668:       ustrncmp (path, TEXT("gopher:"), 7) &&
                    669:       ustrncmp (path, TEXT("mailto:"), 7) && 
                    670:       ustrncmp (path, TEXT("archie:"), 7))
1.72      cvs       671:     return FALSE;
                    672:   return TRUE;
1.3       cvs       673: }
                    674: 
1.4       cvs       675: /*----------------------------------------------------------------------
1.90      cvs       676:   IsFilePath                                           
                    677:   returns TRUE if path is in fact a URL.
                    678:   ----------------------------------------------------------------------*/
                    679: #ifdef __STDC__
1.98      kahan     680: ThotBool             IsFilePath (const CHAR_T* path)
1.90      cvs       681: #else  /* __STDC__ */
1.98      kahan     682: ThotBool             IsFilePath (path)
1.90      cvs       683: const CHAR_T*        path;
                    684: #endif /* __STDC__ */
                    685: {
                    686:   if (ustrncmp (path, TEXT("file:"), 5))
                    687:     return FALSE;
                    688:   return TRUE;
                    689: }
                    690: 
                    691: /*----------------------------------------------------------------------
1.9       cvs       692:   IsValidProtocol                                                    
                    693:   returns true if the url protocol is supported by Amaya.
1.4       cvs       694:   ----------------------------------------------------------------------*/
1.3       cvs       695: #ifdef __STDC__
1.67      cvs       696: ThotBool             IsValidProtocol (const STRING url)
1.3       cvs       697: #else  /* __STDC__ */
1.67      cvs       698: ThotBool             IsValidProtocol (url)
                    699: const STRING       url;
1.3       cvs       700: #endif /* __STDC__ */
                    701: {
1.67      cvs       702:    if (!ustrncmp (url, TEXT("http:"), 5)
1.69      cvs       703:       || !ustrncmp (url, TEXT("internal:"), 9)
1.100     kahan     704:       || (AHTFTPURL_flag () && !ustrncmp (url, TEXT("ftp:"), 4)))
1.22      cvs       705:        /* experimental */
1.24      cvs       706:      /*** || !strncmp (path, "news:", 5)***/ 
1.8       cvs       707:       return (TRUE);
1.5       cvs       708:    else
1.8       cvs       709:       return (FALSE);
1.3       cvs       710: }
                    711: 
1.31      cvs       712: 
                    713: /*----------------------------------------------------------------------
                    714:    GetBaseURL
                    715:    normalizes orgName according to a base associated with doc, and
                    716:    following the standard URL format rules.
                    717:    The function returns the base used to solve relative URL and SRC:
                    718:       - the base of the document,
                    719:       - or the document path (without document name).
                    720:   ----------------------------------------------------------------------*/
                    721: #ifdef __STDC__
1.84      cvs       722: CHAR_T*             GetBaseURL (Document doc)
1.31      cvs       723: #else  /* __STDC__ */
1.84      cvs       724: CHAR_T*             GetBaseURL (doc)
1.31      cvs       725: Document            doc;
                    726: #endif /* __STDC__ */
                    727: {
                    728:   Element             el;
                    729:   ElementType         elType;
                    730:   AttributeType       attrType;
                    731:   Attribute           attr;
1.84      cvs       732:   CHAR_T              *ptr, *basename;
1.31      cvs       733:   int                 length;
                    734: 
1.57      cvs       735:   /* @@@ irene */
                    736:   if (!DocumentURLs[doc])
                    737:          return NULL;
1.67      cvs       738:   basename = TtaAllocString (MAX_LENGTH);
                    739:   ustrncpy (basename, DocumentURLs[doc], MAX_LENGTH-1);
1.84      cvs       740:   basename[MAX_LENGTH-1] = WC_EOS;
1.31      cvs       741:   length = MAX_LENGTH -1;
                    742:   /* get the root element    */
                    743:   el = TtaGetMainRoot (doc);
                    744:   /* search the BASE element */
                    745:   elType.ElSSchema = TtaGetDocumentSSchema (doc);
1.65      cvs       746:   elType.ElTypeNum = HTML_EL_HEAD;
                    747:   el = TtaSearchTypedElement (elType, SearchForward, el);
                    748:   if (el)
                    749:     {
                    750:       elType.ElTypeNum = HTML_EL_BASE;
                    751:       el = TtaSearchTypedElement (elType, SearchInTree, el);
                    752:     }
1.31      cvs       753:   if (el)
                    754:     {
                    755:       /*  The document has a BASE element -> Get the HREF attribute */
                    756:       attrType.AttrSSchema = elType.ElSSchema;
                    757:       attrType.AttrTypeNum = HTML_ATTR_HREF_;
                    758:       attr = TtaGetAttribute (el, attrType);
                    759:       if (attr)
                    760:        {
                    761:          /* Use the base path of the document */
                    762:          TtaGiveTextAttributeValue (attr, basename, &length);
                    763:          /* base and orgName have to be separated by a DIR_SEP */
                    764:          length--;
1.84      cvs       765:          if (basename[0] != WC_EOS && basename[length] != WC_URL_SEP && basename[length] != WC_DIR_SEP) 
1.31      cvs       766:            /* verify if the base has the form "protocol://server:port" */
                    767:            {
1.84      cvs       768:              ptr = AmayaParseUrl (basename, TEXT(""), AMAYA_PARSE_ACCESS |
1.33      cvs       769:                                                 AMAYA_PARSE_HOST |
                    770:                                                 AMAYA_PARSE_PUNCTUATION);
1.67      cvs       771:              if (ptr && !ustrcmp (ptr, basename))
1.31      cvs       772:                {
1.43      cvs       773:                  /* it has this form, we complete it by adding a URL_STR  */
1.84      cvs       774:                  if (ustrchr (basename, WC_DIR_SEP))
                    775:                    ustrcat (basename, WC_DIR_STR);
1.43      cvs       776:                  else
1.84      cvs       777:                    ustrcat (basename, WC_URL_STR);
1.31      cvs       778:                  length++;
                    779:                }
                    780:              if (ptr)
                    781:                TtaFreeMemory (ptr);
                    782:            }
                    783:        }
1.33      cvs       784:       }
                    785:   
1.31      cvs       786:   /* Remove anything after the last DIR_SEP char. If no such char is found,
                    787:    * then search for the first ":" char, hoping that what's before that is a
                    788:    * protocol. If found, end the string there. If neither char is found,
                    789:    * then discard the whole base element.
                    790:    */
1.67      cvs       791:   length = ustrlen (basename) - 1;
1.31      cvs       792:   /* search for the last DIR_SEP char */
1.84      cvs       793:   while (length >= 0  && basename[length] != WC_URL_SEP && basename[length] != WC_DIR_SEP)
1.31      cvs       794:     length--;
                    795:   if (length >= 0)
                    796:     /* found the last DIR_SEP char, end the string there */
1.84      cvs       797:     basename[length + 1] = WC_EOS;                
1.31      cvs       798:   else
                    799:     /* search for the first PATH_STR char */
                    800:     {
1.67      cvs       801:       for (length = 0; basename[length] != TEXT(':') && 
1.84      cvs       802:             basename[length] != WC_EOS; length ++);
1.67      cvs       803:       if (basename[length] == TEXT(':'))
1.31      cvs       804:        /* found, so end the string there */
1.84      cvs       805:        basename[length + 1] = WC_EOS;
1.31      cvs       806:       else
                    807:        /* not found, discard the base */
1.84      cvs       808:        basename[0] = WC_EOS;
1.31      cvs       809:     }
                    810:   return (basename);
                    811: }
                    812: 
                    813: 
1.4       cvs       814: /*----------------------------------------------------------------------
1.40      cvs       815:    GetLocalPath
                    816:    Allocate and return the local document path associated to the url
                    817:   ----------------------------------------------------------------------*/
                    818: #ifdef __STDC__
1.84      cvs       819: CHAR_T*    GetLocalPath (Document doc, CHAR_T* url)
1.40      cvs       820: #else  /* __STDC__ */
1.84      cvs       821: CHAR_T*    GetLocalPath (doc, url)
1.40      cvs       822: Document   doc;
1.84      cvs       823: CHAR_T*    url;
1.40      cvs       824: #endif /* __STDC__ */
                    825: {
1.84      cvs       826:   CHAR_T*   ptr;
                    827:   CHAR_T*   n;
                    828:   CHAR_T*   documentname;
                    829:   CHAR_T    url_sep;
1.83      cvs       830:   int       len;
1.67      cvs       831:   ThotBool  noFile;
1.40      cvs       832: 
                    833:   if (url != NULL)
                    834:     {
                    835:       /* check whether the file name exists */
1.84      cvs       836:       len = ustrlen (url) - 1;
1.71      cvs       837:       if (IsW3Path (url))
1.84      cvs       838:          url_sep = TEXT('/');
1.41      cvs       839:       else 
1.84      cvs       840:           url_sep = WC_DIR_SEP;
1.41      cvs       841:       noFile = (url[len] == url_sep);
1.40      cvs       842:       if (noFile)
1.84      cvs       843:          url[len] = WC_EOS;
                    844:       ptr = TtaAllocString (MAX_LENGTH);
                    845:       documentname = TtaAllocString (MAX_LENGTH);
1.78      cvs       846:       TtaExtractName (url, ptr, documentname);
1.84      cvs       847:       usprintf (ptr, TEXT("%s%s%d%s"), TempFileDirectory, WC_DIR_STR, doc, WC_DIR_STR);
1.40      cvs       848:       if (!TtaCheckDirectory (ptr))
                    849:        /* directory did not exist */
1.72      cvs       850:        TtaMakeDirectory (ptr);
1.47      cvs       851: 
                    852:       /* don't include the query string within document name */
1.84      cvs       853:       n = ustrrchr (documentname, TEXT('?'));
1.47      cvs       854:       if (n != NULL)
1.84      cvs       855:          *n = WC_EOS;
1.46      cvs       856:       /* don't include ':' within document name */
1.84      cvs       857:       n = ustrchr (documentname, TEXT(':'));
1.46      cvs       858:       if (n != NULL)
1.84      cvs       859:          *n = WC_EOS;
1.69      cvs       860:       /* if after all this operations document name
                    861:         is empty, let's use noname.html instead */
1.84      cvs       862:       if (documentname[0] == WC_EOS)
                    863:          ustrcat (ptr, TEXT("noname.html"));
1.69      cvs       864:       else
1.84      cvs       865:           ustrcat (ptr, documentname);
1.40      cvs       866:       TtaFreeMemory (documentname);
                    867:       /* restore the url */
                    868:       if (noFile)
1.41      cvs       869:        url[len] = url_sep;
1.40      cvs       870:       return (ptr);
                    871:     }
                    872:   else
                    873:     return (NULL);
                    874: }
                    875: 
1.73      cvs       876: /*----------------------------------------------------------------------
1.79      cvs       877:    ExtractTarget extract the target name from document nane.        
                    878:   ----------------------------------------------------------------------*/
                    879: #ifdef __STDC__
1.84      cvs       880: void         ExtractTarget (CHAR_T* aName, CHAR_T* target)
1.79      cvs       881: #else
                    882: void         ExtractTarget (aName, target)
1.84      cvs       883: CHAR_T*      aName;
                    884: CHAR_T*      target;
1.79      cvs       885: #endif
                    886: {
1.82      cvs       887:    int       lg, i;
1.84      cvs       888:    CHAR_T*   ptr;
                    889:    CHAR_T*   oldptr;
1.79      cvs       890: 
                    891:    if (!target || !aName)
                    892:      /* bad target */
                    893:      return;
                    894: 
1.84      cvs       895:    target[0] = WC_EOS;
                    896:    lg = ustrlen (aName);
1.79      cvs       897:    if (lg)
                    898:      {
                    899:        /* the name is not empty */
                    900:        oldptr = ptr = &aName[0];
                    901:        do
                    902:          {
1.84      cvs       903:             ptr = ustrrchr (oldptr, TEXT('#'));
1.79      cvs       904:             if (ptr)
                    905:                oldptr = &ptr[1];
                    906:          }
                    907:        while (ptr);
                    908: 
                    909:        i = (int) (oldptr) - (int) (aName);     /* name length */
                    910:        if (i > 1)
                    911:          {
1.84      cvs       912:             aName[i - 1] = WC_EOS;
1.79      cvs       913:             if (i != lg)
1.84      cvs       914:                ustrcpy (target, oldptr);
1.79      cvs       915:          }
                    916:      }
                    917: }
                    918: 
                    919: /*----------------------------------------------------------------------
1.90      cvs       920:    RemoveNewLines (text)
                    921:    Removes any '\n' chars that are found in text. 
                    922:    Returns TRUE if it did the operation, FALSE otherwise.
1.73      cvs       923:   ----------------------------------------------------------------------*/
                    924: #ifdef __STDC__
1.90      cvs       925: ThotBool RemoveNewLines (CHAR_T *text)
1.73      cvs       926: #else
1.90      cvs       927: ThotBool RemoveNewLines (text)
                    928: CHAR_T *text;
                    929: 
1.73      cvs       930: #endif /* __STDC__ */
                    931: {
1.90      cvs       932:   ThotBool change = FALSE;
                    933:   CHAR_T *src;
                    934:   CHAR_T *dest;
                    935: 
                    936:   src = text;
                    937:   dest = text;
                    938: 
                    939:   while (*src)
                    940:     {
                    941:       switch (*src)
                    942:        {
                    943:        case TEXT('\n'):
                    944:          /* don't copy the newline */
                    945:          change = 1;
                    946:          break;
                    947:        default:
                    948:          *dest = *src;
                    949:          dest++;
                    950:          break;
                    951:        }
                    952:       src++;
                    953:     }
                    954:   /* copy the last EOS char */
                    955:   *dest = *src;
                    956: 
                    957:   return (change);
                    958: }
                    959: 
                    960: /*----------------------------------------------------------------------
                    961:    CleanCopyFileURL
                    962:    Copies a file url from a src string to destination string.
1.97      cvs       963:    convertion says which type of convertion (none, %xx, URL_SEP into DIR_SEP
                    964:    we want to do).
1.90      cvs       965:   ----------------------------------------------------------------------*/
                    966: #ifdef __STDC__
1.97      cvs       967: static void CleanCopyFileURL (CHAR_T *dest, CHAR_T *src, ConvertionType convertion)
1.90      cvs       968: #else
1.97      cvs       969: static void CleanCopyFileURL (dest, src, convertion)
1.90      cvs       970: CHAR_T* dest;
                    971: CHAR_T* src;
1.97      cvs       972: ConvertionType convertion;
1.89      cvs       973: 
1.90      cvs       974: #endif /* __STDC__ */
                    975: {
                    976:   while (*src)
1.89      cvs       977:     {
1.90      cvs       978:       switch (*src)
1.89      cvs       979:        {
                    980: #ifdef _WINDOWS
1.90      cvs       981:        case WC_URL_SEP:
1.96      cvs       982:          /* make DIR_SEP transformation */
1.97      cvs       983:          if (convertion & AM_CONV_URL_SEP)
1.96      cvs       984:            *dest = WC_DIR_SEP;
                    985:          else
                    986:            *dest = *src;
1.90      cvs       987:          dest++;
1.96      cvs       988:          src++;
1.90      cvs       989:          break;
1.89      cvs       990: #endif /* _WINDOWS */
1.96      cvs       991: 
                    992:        case TEXT('%'):
1.97      cvs       993:          if (convertion & AM_CONV_PERCENT)
1.96      cvs       994:            {
1.97      cvs       995:              /* (code adapted from libwww's HTUnEscape function */
1.96      cvs       996:              src++;
1.97      cvs       997:              if (*src != WC_EOS)
                    998:                {
                    999:                  *dest = UnEscapeChar (*src) * 16;
                   1000:                  src++;
                   1001:                }
                   1002:              if (*src != WC_EOS)
                   1003:                {
                   1004:                  *dest = *dest + UnEscapeChar (*src);
                   1005:                  src++;
                   1006:                }
                   1007:              dest++;
1.96      cvs      1008:            }
1.97      cvs      1009:          else
1.96      cvs      1010:            {
1.97      cvs      1011:              *dest = *src;
                   1012:              dest++;
1.96      cvs      1013:              src++;
                   1014:            }
                   1015:          break;
                   1016: 
1.90      cvs      1017:        default:
                   1018:          *dest = *src;
1.89      cvs      1019:          dest++;
1.96      cvs      1020:          src++;
1.90      cvs      1021:          break;
1.89      cvs      1022:        }
                   1023:     }
1.90      cvs      1024:   /* copy the EOS char */
                   1025:   *dest = *src;
1.73      cvs      1026: }
1.40      cvs      1027: 
                   1028: /*----------------------------------------------------------------------
1.9       cvs      1029:    NormalizeURL
                   1030:    normalizes orgName according to a base associated with doc, and
                   1031:    following the standard URL format rules.
1.53      cvs      1032:    if doc is 0 and otherPath not NULL, normalizes orgName according to this
                   1033:    other path.
1.9       cvs      1034:    The function returns the new complete and normalized URL 
1.12      cvs      1035:    or file name path (newName) and the name of the document (docName).        
1.9       cvs      1036:    N.B. If the function can't find out what's the docName, it assigns
                   1037:    the name "noname.html".
1.4       cvs      1038:   ----------------------------------------------------------------------*/
1.3       cvs      1039: #ifdef __STDC__
1.84      cvs      1040: void                NormalizeURL (CHAR_T* orgName, Document doc, CHAR_T* newName, CHAR_T* docName, CHAR_T* otherPath)
1.3       cvs      1041: #else  /* __STDC__ */
1.53      cvs      1042: void                NormalizeURL (orgName, doc, newName, docName, otherPath)
1.84      cvs      1043: CHAR_T*             orgName;
1.3       cvs      1044: Document            doc;
1.84      cvs      1045: CHAR_T*             newName;
                   1046: CHAR_T*             docName;
                   1047: CHAR_T*             otherPath;
1.3       cvs      1048: #endif /* __STDC__ */
                   1049: {
1.84      cvs      1050:    CHAR_T*        basename;
                   1051:    CHAR_T         tempOrgName[MAX_LENGTH];
                   1052:    CHAR_T*        ptr;
                   1053:    CHAR_T         used_sep;
                   1054:    int            length;
                   1055:    ThotBool       check;
1.5       cvs      1056: 
1.44      cvs      1057: #  ifdef _WINDOWS
                   1058:    int ndx;
                   1059: #  endif /* _WINDOWS */
                   1060: 
1.5       cvs      1061:    if (!newName || !docName)
                   1062:       return;
1.18      cvs      1063: 
1.32      cvs      1064:    if (doc != 0)
1.53      cvs      1065:      basename = GetBaseURL (doc);
                   1066:    else if (otherPath != NULL)
1.84      cvs      1067:      basename = TtaWCSdup (otherPath);
1.32      cvs      1068:    else
1.53      cvs      1069:      basename = NULL;
1.32      cvs      1070: 
1.18      cvs      1071:    /*
1.31      cvs      1072:     * Clean orgName
                   1073:     * Make sure we have a complete orgName, without any leading or trailing
                   1074:     * white spaces, or trailinbg new lines
                   1075:     */
1.5       cvs      1076:    ptr = orgName;
1.18      cvs      1077:    /* skip leading white space and new line characters */
1.84      cvs      1078:    while ((*ptr == WC_SPACE || *ptr == WC_EOL) && *ptr++ != WC_EOS);
                   1079:    ustrncpy (tempOrgName, ptr, MAX_LENGTH -1);
                   1080:    tempOrgName[MAX_LENGTH -1] = WC_EOS;
1.18      cvs      1081:    /*
1.31      cvs      1082:     * Make orgName a complete URL
                   1083:     * If the URL does not include a protocol, then try to calculate
                   1084:     * one using the doc's base element (if it exists),
                   1085:     */
1.84      cvs      1086:    if (tempOrgName[0] == WC_EOS)
1.53      cvs      1087:      {
1.84      cvs      1088:        newName[0] = WC_EOS;
1.53      cvs      1089:        TtaFreeMemory (basename);
                   1090:        return;
                   1091:      }
1.49      cvs      1092: 
                   1093:    /* clean trailing white space */
1.84      cvs      1094:    length = ustrlen (tempOrgName) - 1;
                   1095:    while (tempOrgName[length] == WC_SPACE && tempOrgName[length] == WC_EOL)
1.53      cvs      1096:      {
1.84      cvs      1097:        tempOrgName[length] = WC_EOS;
1.53      cvs      1098:        length--;
                   1099:      }
1.50      cvs      1100: 
1.55      cvs      1101:    /* remove extra dot (which dot???) */
                   1102:    /* ugly, but faster than a strcmp */
1.84      cvs      1103:    if (tempOrgName[length] == TEXT('.')
                   1104:        && (length == 0 || tempOrgName[length-1] != TEXT('.')))
                   1105:         tempOrgName[length] = WC_EOS;
1.50      cvs      1106: 
1.94      cvs      1107:    if (IsW3Path (tempOrgName))
1.53      cvs      1108:      {
                   1109:        /* the name is complete, go to the Sixth Step */
1.84      cvs      1110:        ustrcpy (newName, tempOrgName);
1.53      cvs      1111:        SimplifyUrl (&newName);
                   1112:        /* verify if the URL has the form "protocol://server:port" */
1.84      cvs      1113:        ptr = AmayaParseUrl (newName, TEXT(""), AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
                   1114:        if (ptr && !ustrcmp (ptr, newName)) /* it has this form, we complete it by adding a DIR_STR  */
                   1115:          ustrcat (newName, WC_URL_STR);
1.49      cvs      1116: 
1.53      cvs      1117:        if (ptr)
1.50      cvs      1118:          TtaFreeMemory (ptr);
1.53      cvs      1119:      }
                   1120:    else if ( basename == NULL)
                   1121:      /* the name is complete, go to the Sixth Step */
1.84      cvs      1122:      ustrcpy (newName, tempOrgName);
1.53      cvs      1123:    else
                   1124:      {
1.31      cvs      1125:        /* Calculate the absolute URL, using the base or document URL */
1.44      cvs      1126: #      ifdef _WINDOWS
1.53      cvs      1127:        if (!IsW3Path (basename))
                   1128:         {
1.67      cvs      1129:           length = ustrlen (tempOrgName);
1.53      cvs      1130:           for (ndx = 0; ndx < length; ndx++)
1.67      cvs      1131:             if (tempOrgName [ndx] == TEXT('/'))
                   1132:               tempOrgName [ndx] = TEXT('\\');
1.53      cvs      1133:         }
1.44      cvs      1134: #      endif /* _WINDOWS */
1.25      cvs      1135:        ptr = AmayaParseUrl (tempOrgName, basename, AMAYA_PARSE_ALL);
1.53      cvs      1136:        if (ptr)
                   1137:         {
                   1138:           SimplifyUrl (&ptr);
1.84      cvs      1139:           ustrcpy (newName, ptr);
1.53      cvs      1140:           TtaFreeMemory (ptr);
                   1141:         }
                   1142:        else
1.84      cvs      1143:         newName[0] = WC_EOS;
1.53      cvs      1144:      }
1.36      cvs      1145: 
                   1146:    TtaFreeMemory (basename);
1.18      cvs      1147:    /*
1.31      cvs      1148:     * Prepare the docname that will refer to this ressource in the
                   1149:     * .amaya directory. If the new URL finishes on DIR_SEP, then use
                   1150:     * noname.html as a default ressource name
1.18      cvs      1151:    */
1.84      cvs      1152:    if (newName[0] != WC_EOS)
1.53      cvs      1153:      {
1.84      cvs      1154:        length = ustrlen (newName) - 1;
                   1155:        if (newName[length] == WC_URL_SEP || newName[length] == WC_DIR_SEP)
1.53      cvs      1156:         {
                   1157:           used_sep = newName[length];
                   1158:           check = TRUE;
                   1159:           while (check)
                   1160:             {
1.50      cvs      1161:                length--;
                   1162:                while (length >= 0 && newName[length] != used_sep)
1.53      cvs      1163:                 length--;
1.84      cvs      1164:                if (!ustrncmp (&newName[length+1], TEXT(".."), 2))
1.53      cvs      1165:                 {
1.84      cvs      1166:                   newName[length+1] = WC_EOS;
1.53      cvs      1167:                   /* remove also previous directory */
                   1168:                   length--;
                   1169:                   while (length >= 0 && newName[length] != used_sep)
                   1170:                     length--;
1.84      cvs      1171:                   if (ustrncmp (&newName[length+1], TEXT("//"), 2))
1.53      cvs      1172:                     /* don't remove server name */
1.84      cvs      1173:                      newName[length+1] = WC_EOS;
1.53      cvs      1174:                 }
1.84      cvs      1175:               else if (!ustrncmp (&newName[length+1], TEXT("."), 1))
                   1176:                 newName[length+1] = WC_EOS;
1.50      cvs      1177:                else
1.53      cvs      1178:                 check = FALSE;
                   1179:             }
1.84      cvs      1180:           ustrcpy (docName, TEXT("noname.html"));             
1.53      cvs      1181:           /* docname was not comprised inside the URL, so let's */
                   1182:           /* assign the default ressource name */
1.84      cvs      1183:           ustrcpy (docName, TEXT("noname.html"));
1.53      cvs      1184:         }
                   1185:        else
                   1186:         { /* docname is comprised inside the URL */
1.84      cvs      1187:            while (length >= 0 && newName[length] != WC_URL_SEP && newName[length] != WC_DIR_SEP)
1.53      cvs      1188:             length--;
                   1189:           if (length < 0)
1.84      cvs      1190:              ustrcpy (docName, newName);
1.53      cvs      1191:           else
1.84      cvs      1192:             ustrcpy (docName, &newName[length+1]);
1.53      cvs      1193:         }
                   1194:      }
                   1195:    else
1.84      cvs      1196:      docName[0] = WC_EOS;
1.18      cvs      1197: } 
1.3       cvs      1198: 
1.4       cvs      1199: /*----------------------------------------------------------------------
1.9       cvs      1200:   IsSameHost                                                         
1.4       cvs      1201:   ----------------------------------------------------------------------*/
1.3       cvs      1202: #ifdef __STDC__
1.67      cvs      1203: ThotBool             IsSameHost (const STRING url1, const STRING url2)
1.3       cvs      1204: #else  /* __STDC__ */
1.67      cvs      1205: ThotBool             IsSameHost (url1, url2)
                   1206: const STRING       url1;
                   1207: const STRING       url2;
1.3       cvs      1208: #endif /* __STDC__ */
                   1209: {
1.67      cvs      1210:    STRING           basename_ptr1, basename_ptr2;
                   1211:    ThotBool          result;
1.3       cvs      1212: 
1.84      cvs      1213:    basename_ptr1 = AmayaParseUrl (url1, TEXT(""), AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
1.86      cvs      1214:    basename_ptr2 = AmayaParseUrl (url2, TEXT(""), AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | AMAYA_PARSE_PUNCTUATION);
1.3       cvs      1215: 
1.67      cvs      1216:    if (ustrcmp (basename_ptr1, basename_ptr2))
1.8       cvs      1217:       result = FALSE;
1.5       cvs      1218:    else
1.8       cvs      1219:       result = TRUE;
1.3       cvs      1220: 
1.25      cvs      1221:    TtaFreeMemory (basename_ptr1);
                   1222:    TtaFreeMemory (basename_ptr2);
1.5       cvs      1223:    return (result);
1.3       cvs      1224: }
                   1225: 
                   1226: 
1.4       cvs      1227: /*----------------------------------------------------------------------
1.22      cvs      1228:   HasKnownFileSuffix
                   1229:   returns TRUE if path points to a file ending with a suffix.
                   1230:   ----------------------------------------------------------------------*/
                   1231: #ifdef __STDC__
1.67      cvs      1232: ThotBool             HasKnownFileSuffix (const STRING path)
1.22      cvs      1233: #else  /* __STDC__ */
1.67      cvs      1234: ThotBool             HasKnownFileSuffix (path)
                   1235: const STRING    path;
1.22      cvs      1236: #endif /* __STDC__ */
                   1237: {
1.67      cvs      1238:    STRING      root;
                   1239:    CHAR_T      temppath[MAX_LENGTH];
                   1240:    CHAR_T      suffix[MAX_LENGTH];
1.22      cvs      1241: 
1.87      cvs      1242:    if (!path || path[0] == WC_EOS || path[ustrlen(path)] == WC_DIR_SEP)
1.22      cvs      1243:      return (FALSE);
                   1244: 
1.84      cvs      1245:    root = AmayaParseUrl(path, TEXT(""), AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);
1.22      cvs      1246: 
                   1247:    if (root) 
                   1248:      {
1.67      cvs      1249:        ustrcpy (temppath, root);
1.25      cvs      1250:        TtaFreeMemory (root);
1.22      cvs      1251:        /* Get the suffix */
                   1252:        ExtractSuffix (temppath, suffix); 
                   1253: 
1.87      cvs      1254:        if( suffix[0] == WC_EOS)
1.22      cvs      1255:         /* no suffix */
                   1256:         return (FALSE);
                   1257: 
                   1258:        /* Normalize the suffix */
                   1259:        ConvertToLowerCase (suffix);
                   1260: 
1.67      cvs      1261:        if (!ustrcmp (suffix, TEXT("gz")))
1.22      cvs      1262:         /* skip the compressed suffix */
                   1263:         {
                   1264:         ExtractSuffix (temppath, suffix);
1.87      cvs      1265:         if(suffix[0] == WC_EOS)
1.22      cvs      1266:           /* no suffix */
                   1267:           return (FALSE);
                   1268:          /* Normalize the suffix */
                   1269:          ConvertToLowerCase (suffix);
                   1270:         }
                   1271: 
1.67      cvs      1272:        if (ustrcmp (suffix, TEXT("gif")) &&
                   1273:           ustrcmp (suffix, TEXT("xbm")) &&
                   1274:           ustrcmp (suffix, TEXT("xpm")) &&
                   1275:           ustrcmp (suffix, TEXT("jpg")) &&
                   1276:           ustrcmp (suffix, TEXT("pdf")) &&
                   1277:           ustrcmp (suffix, TEXT("png")) &&
                   1278:           ustrcmp (suffix, TEXT("tgz")) &&
                   1279:           ustrcmp (suffix, TEXT("xpg")) &&
                   1280:           ustrcmp (suffix, TEXT("xpd")) &&
                   1281:           ustrcmp (suffix, TEXT("ps")) &&
                   1282:           ustrcmp (suffix, TEXT("au")) &&
                   1283:           ustrcmp (suffix, TEXT("html")) &&
                   1284:           ustrcmp (suffix, TEXT("htm")) &&
                   1285:           ustrcmp (suffix, TEXT("shtml")) &&
                   1286:           ustrcmp (suffix, TEXT("xht")) &&
                   1287:           ustrcmp (suffix, TEXT("xhtm")) &&
                   1288:           ustrcmp (suffix, TEXT("xhtml")) &&
                   1289:           ustrcmp (suffix, TEXT("txt")) &&
                   1290:           ustrcmp (suffix, TEXT("css")) &&
                   1291:           ustrcmp (suffix, TEXT("eps")))
1.22      cvs      1292:         return (FALSE);
                   1293:        else
                   1294:         return (TRUE);
                   1295:      }
                   1296:    else
                   1297:      return (FALSE);
                   1298: }
                   1299: 
                   1300: 
                   1301: /*----------------------------------------------------------------------
1.24      cvs      1302:   ChopURL
                   1303:   Gives back a URL no longer than MAX_PRINT_URL_LENGTH chars (outputURL). 
                   1304:   If inputURL is  bigger than that size, outputURL receives
                   1305:   MAX_PRINT_URL_LENGTH / 2 chars from the beginning of inputURL, "...", 
                   1306:   and MAX_PRINT_URL_LENGTH / 2 chars from the end of inputURL.
                   1307:   If inputURL is not longer than MAX_PRINT_URL_LENGTH chars, it gets
                   1308:   copied into outputURL. 
                   1309:   N.B.: outputURL must point to a memory block of MAX_PRINT_URL_LENGTH
                   1310:   chars.
                   1311:   ----------------------------------------------------------------------*/
                   1312: #ifdef __STDC__
1.86      cvs      1313: void ChopURL (CHAR_T* outputURL, const CHAR_T* inputURL)
1.24      cvs      1314: #else
                   1315: void ChopURL (outputURL, inputURL)
1.86      cvs      1316: CHAR_T*       outputURL;
                   1317: const CHAR_T* inputURL;
1.24      cvs      1318: #endif
1.22      cvs      1319: 
1.24      cvs      1320: {
                   1321:   int len;
1.9       cvs      1322: 
1.86      cvs      1323:   len = ustrlen (inputURL);
1.24      cvs      1324:   if (len <= MAX_PRINT_URL_LENGTH) 
1.86      cvs      1325:     ustrcpy (outputURL, inputURL);
1.24      cvs      1326:   else
                   1327:     /* make a truncated urlName on the status window */
                   1328:     {
1.86      cvs      1329:       ustrncpy (outputURL, inputURL, MAX_PRINT_URL_LENGTH / 2);
                   1330:       outputURL [MAX_PRINT_URL_LENGTH / 2] = WC_EOS;
                   1331:       ustrcat (outputURL, TEXT("..."));
                   1332:       ustrcat (outputURL, &(inputURL[len - MAX_PRINT_URL_LENGTH / 2 ]));
1.24      cvs      1333:     }
1.25      cvs      1334: }
                   1335: 
                   1336: 
                   1337: /*----------------------------------------------------------------------
                   1338:    scan
1.47      cvs      1339:        Scan a filename for its constituents
1.25      cvs      1340:        -----------------------------------
                   1341:   
                   1342:    On entry,
                   1343:        name    points to a document name which may be incomplete.
                   1344:    On exit,
                   1345:         absolute or relative may be nonzero (but not both).
                   1346:        host, fragment and access may be nonzero if they were specified.
                   1347:        Any which are nonzero point to zero terminated strings.
                   1348:   ----------------------------------------------------------------------*/
                   1349: #ifdef __STDC__
1.67      cvs      1350: static void scan (STRING name, HTURI * parts)
1.25      cvs      1351: #else  /* __STDC__ */
                   1352: static void scan (name, parts)
1.67      cvs      1353: STRING      name;
                   1354: HTURI       *parts;
1.25      cvs      1355: 
                   1356: #endif /* __STDC__ */
                   1357: {
1.67      cvs      1358:   STRING    p;
                   1359:   STRING    after_access = name;
1.32      cvs      1360: 
1.43      cvs      1361:   memset (parts, '\0', sizeof (HTURI));
1.28      cvs      1362:   /* Look for fragment identifier */
1.67      cvs      1363:   if ((p = ustrchr(name, TEXT('#'))) != NULL)
1.28      cvs      1364:     {
1.67      cvs      1365:       *p++ = TEXT('\0');
1.28      cvs      1366:       parts->fragment = p;
1.25      cvs      1367:     }
                   1368:     
1.28      cvs      1369:   for (p=name; *p; p++)
                   1370:     {
1.67      cvs      1371:       if (*p == URL_SEP || *p == DIR_SEP || *p == TEXT('#') || *p == TEXT('?'))
1.28      cvs      1372:        break;
1.67      cvs      1373:       if (*p == TEXT(':'))
1.28      cvs      1374:        {
                   1375:          *p = 0;
                   1376:          parts->access = after_access; /* Scheme has been specified */
                   1377: 
                   1378:          /* The combination of gcc, the "-O" flag and the HP platform is
                   1379:             unhealthy. The following three lines is a quick & dirty fix, but is
                   1380:             not recommended. Rather, turn off "-O". */
                   1381: 
                   1382:          /*            after_access = p;*/
                   1383:          /*            while (*after_access == 0)*/
                   1384:          /*                after_access++;*/
                   1385:          after_access = p+1;
1.67      cvs      1386:          if (!ustrcasecmp(TEXT("URL"), parts->access))
1.28      cvs      1387:            /* Ignore IETF's URL: pre-prefix */
                   1388:            parts->access = NULL;
                   1389:          else
1.25      cvs      1390:            break;
                   1391:        }
                   1392:     }
                   1393:     
                   1394:     p = after_access;
1.43      cvs      1395:     if (*p == URL_SEP || *p == DIR_SEP)
1.28      cvs      1396:       {
1.43      cvs      1397:        if (p[1] == URL_SEP)
1.28      cvs      1398:          {
1.25      cvs      1399:            parts->host = p+2;          /* host has been specified      */
1.28      cvs      1400:            *p = 0;                     /* Terminate access             */
                   1401:            /* look for end of host name if any */
1.67      cvs      1402:            p = ustrchr (parts->host, URL_SEP);
1.28      cvs      1403:            if (p)
                   1404:              {
1.87      cvs      1405:                *p = WC_EOS;                    /* Terminate host */
1.25      cvs      1406:                parts->absolute = p+1;          /* Root has been found */
1.28      cvs      1407:              }
                   1408:          }
                   1409:        else
                   1410:          /* Root found but no host */
                   1411:          parts->absolute = p+1;
                   1412:       }
                   1413:     else
                   1414:       {
1.25      cvs      1415:         parts->relative = (*after_access) ? after_access : 0; /* zero for "" */
1.28      cvs      1416:       }
1.25      cvs      1417: }
                   1418: 
                   1419: 
                   1420: /*----------------------------------------------------------------------
1.28      cvs      1421:   AmayaParseUrl: parse a Name relative to another name
                   1422: 
                   1423:   This returns those parts of a name which are given (and requested)
                   1424:   substituting bits from the related name where necessary.
1.25      cvs      1425:   
1.28      cvs      1426:   On entry,
1.25      cvs      1427:        aName           A filename given
                   1428:         relatedName     A name relative to which aName is to be parsed. Give
                   1429:                         it an empty string if aName is absolute.
                   1430:         wanted          A mask for the bits which are wanted.
                   1431:   
1.28      cvs      1432:   On exit,
1.25      cvs      1433:        returns         A pointer to a malloc'd string which MUST BE FREED
                   1434:   ----------------------------------------------------------------------*/
                   1435: #ifdef __STDC__
1.84      cvs      1436: CHAR_T*        AmayaParseUrl (const CHAR_T* aName, CHAR_T* relatedName, int wanted)
1.25      cvs      1437: #else  /* __STDC__ */
1.84      cvs      1438: CHAR_T*        AmayaParseUrl (aName, relatedName, wanted)
                   1439: const CHAR_T*  aName;
                   1440: CHAR_T*        relatedName;
1.28      cvs      1441: int            wanted;
1.25      cvs      1442: 
                   1443: #endif /* __STDC__ */
                   1444: {
1.84      cvs      1445:   CHAR_T*    return_value;
1.67      cvs      1446:   CHAR_T     result[MAX_LENGTH];
                   1447:   CHAR_T     name[MAX_LENGTH];
                   1448:   CHAR_T     rel[MAX_LENGTH];
1.84      cvs      1449:   CHAR_T     *p, *access;
1.29      cvs      1450:   HTURI      given, related;
                   1451:   int        len;
1.67      cvs      1452:   CHAR_T     used_sep;
1.84      cvs      1453:   CHAR_T*    used_str;
1.32      cvs      1454: 
1.84      cvs      1455:   if (ustrchr (aName, WC_DIR_SEP) || ustrchr (relatedName, WC_DIR_SEP))
1.33      cvs      1456:     {
1.84      cvs      1457:       used_str = WC_DIR_STR;
                   1458:       used_sep = WC_DIR_SEP;
1.33      cvs      1459:     }
1.32      cvs      1460:   else
1.33      cvs      1461:     {
1.84      cvs      1462:       used_str = WC_URL_STR;
                   1463:       used_sep = WC_URL_SEP;
1.33      cvs      1464:     }
1.32      cvs      1465: 
1.29      cvs      1466:   /* Make working copies of input strings to cut up: */
                   1467:   return_value = NULL;
                   1468:   result[0] = 0;               /* Clear string  */
1.67      cvs      1469:   ustrcpy (name, aName);
1.29      cvs      1470:   if (relatedName != NULL)  
1.67      cvs      1471:     ustrcpy (rel, relatedName);
1.29      cvs      1472:   else
1.84      cvs      1473:     relatedName[0] = WC_EOS;
1.29      cvs      1474:   
                   1475:   scan (name, &given);
                   1476:   scan (rel,  &related); 
                   1477:   access = given.access ? given.access : related.access;
                   1478:   if (wanted & AMAYA_PARSE_ACCESS)
                   1479:     if (access)
                   1480:       {
1.67      cvs      1481:        ustrcat (result, access);
1.29      cvs      1482:        if(wanted & AMAYA_PARSE_PUNCTUATION)
1.67      cvs      1483:                ustrcat (result, TEXT(":"));
1.29      cvs      1484:       }
                   1485:   
                   1486:   if (given.access && related.access)
                   1487:     /* If different, inherit nothing. */
1.67      cvs      1488:     if (ustrcmp (given.access, related.access) != 0)
1.29      cvs      1489:       {
                   1490:        related.host = 0;
                   1491:        related.absolute = 0;
                   1492:        related.relative = 0;
                   1493:        related.fragment = 0;
                   1494:       }
                   1495:   
                   1496:   if (wanted & AMAYA_PARSE_HOST)
                   1497:     if(given.host || related.host)
                   1498:       {
                   1499:        if(wanted & AMAYA_PARSE_PUNCTUATION)
1.67      cvs      1500:          ustrcat (result, TEXT("//"));
                   1501:        ustrcat (result, given.host ? given.host : related.host);
1.29      cvs      1502:       }
                   1503:   
                   1504:   if (given.host && related.host)
                   1505:     /* If different hosts, inherit no path. */
1.67      cvs      1506:     if (ustrcmp (given.host, related.host) != 0)
1.29      cvs      1507:       {
                   1508:        related.absolute = 0;
                   1509:        related.relative = 0;
                   1510:        related.fragment = 0;
                   1511:       }
                   1512:   
                   1513:   if (wanted & AMAYA_PARSE_PATH)
                   1514:     {
                   1515:       if (given.absolute)
                   1516:        {
                   1517:          /* All is given */
                   1518:          if (wanted & AMAYA_PARSE_PUNCTUATION)
1.67      cvs      1519:            ustrcat (result, used_str);
                   1520:          ustrcat (result, given.absolute);
1.25      cvs      1521:        }
1.29      cvs      1522:       else if (related.absolute)
                   1523:        {
                   1524:          /* Adopt path not name */
1.67      cvs      1525:          ustrcat (result, used_str);
                   1526:          ustrcat (result, related.absolute);
1.29      cvs      1527:          if (given.relative)
                   1528:            {
                   1529:              /* Search part? */
1.67      cvs      1530:              p = ustrchr (result, TEXT('?'));
1.29      cvs      1531:              if (!p)
1.67      cvs      1532:                p=result+ustrlen(result)-1;
1.33      cvs      1533:              for (; *p!=used_sep; p--);        /* last / */
1.29      cvs      1534:              /* Remove filename */
                   1535:              p[1]=0;
                   1536:              /* Add given one */
1.67      cvs      1537:              ustrcat (result, given.relative);
1.25      cvs      1538:            }
                   1539:        }
1.29      cvs      1540:       else if (given.relative)
                   1541:        /* what we've got */
1.67      cvs      1542:        ustrcat (result, given.relative);
1.29      cvs      1543:       else if (related.relative)
1.67      cvs      1544:        ustrcat (result, related.relative);
1.29      cvs      1545:       else
                   1546:        /* No inheritance */
1.67      cvs      1547:        ustrcat (result, used_str);
1.25      cvs      1548:     }
1.29      cvs      1549:   
                   1550:   if (wanted & AMAYA_PARSE_ANCHOR)
                   1551:     if (given.fragment || related.fragment)
                   1552:       {
                   1553:        if (given.absolute && given.fragment)
                   1554:          {
                   1555:            /*Fixes for relURLs...*/
                   1556:            if (wanted & AMAYA_PARSE_PUNCTUATION)
1.67      cvs      1557:              ustrcat (result, TEXT("#"));
                   1558:            ustrcat (result, given.fragment); 
1.29      cvs      1559:          }
                   1560:        else if (!(given.absolute) && !(given.fragment))
1.84      cvs      1561:          ustrcat (result, TEXT(""));
1.29      cvs      1562:        else
                   1563:          {
                   1564:            if (wanted & AMAYA_PARSE_PUNCTUATION)
1.67      cvs      1565:              ustrcat (result, TEXT("#"));
                   1566:            ustrcat (result, given.fragment ? given.fragment : related.fragment); 
1.29      cvs      1567:          }
                   1568:       }
1.67      cvs      1569:   len = ustrlen (result);
                   1570:   if ((return_value = TtaAllocString (len + 1)) != NULL)
                   1571:     ustrcpy (return_value, result);
1.29      cvs      1572:   return (return_value);               /* exactly the right length */
1.25      cvs      1573: }
                   1574: 
                   1575: /*----------------------------------------------------------------------
                   1576:      HTCanon
                   1577:        Canonicalizes the URL in the following manner starting from the host
                   1578:        pointer:
                   1579:   
                   1580:        1) The host name is converted to lowercase
                   1581:        2) Chop off port if `:80' (http), `:70' (gopher), or `:21' (ftp)
                   1582:   
                   1583:        Return: OK      The position of the current path part of the URL
                   1584:                        which might be the old one or a new one.
                   1585:   
                   1586:   ----------------------------------------------------------------------*/
                   1587: #ifdef __STDC__
1.84      cvs      1588: static CHAR_T* HTCanon (CHAR_T** filename, CHAR_T* host)
1.25      cvs      1589: #else  /* __STDC__ */
1.67      cvs      1590: static STRING HTCanon (filename, host)
1.84      cvs      1591: CHAR_T** filename;
                   1592: CHAR_T*  host;
1.25      cvs      1593: #endif /* __STDC__ */
                   1594: {
1.84      cvs      1595:     CHAR_T* newname = NULL;
                   1596:     CHAR_T  used_sep;
                   1597:     CHAR_T* path;
                   1598:     CHAR_T* strptr;
                   1599:     CHAR_T* port;
                   1600:     CHAR_T* access = host-3;
1.32      cvs      1601: 
                   1602:   
1.84      cvs      1603:      if (*filename && ustrchr (*filename, WC_URL_SEP))
1.33      cvs      1604:        {
1.84      cvs      1605:         used_sep = WC_URL_SEP;
1.33      cvs      1606:        }
                   1607:      else
                   1608:        {
1.84      cvs      1609:         used_sep = WC_DIR_SEP;
1.33      cvs      1610:        }
1.32      cvs      1611:   
1.82      cvs      1612:     while (access > *filename && *(access - 1) != used_sep)       /* Find access method */
1.25      cvs      1613:        access--;
1.84      cvs      1614:     if ((path = ustrchr (host, used_sep)) == NULL)                     /* Find path */
                   1615:        path = host + ustrlen (host);
                   1616:     if ((strptr = ustrchr (host, TEXT('@'))) != NULL && strptr < path)    /* UserId */
1.82      cvs      1617:        host = strptr;
1.84      cvs      1618:     if ((port = ustrchr (host, TEXT(':'))) != NULL && port > path)      /* Port number */
1.82      cvs      1619:        port = NULL;
1.25      cvs      1620: 
                   1621:     strptr = host;                                 /* Convert to lower-case */
1.82      cvs      1622:     while (strptr < path)
1.33      cvs      1623:       {
1.84      cvs      1624:          *strptr = utolower (*strptr);
1.82      cvs      1625:          strptr++;
1.33      cvs      1626:       }
1.25      cvs      1627:     
                   1628:     /* Does the URL contain a full domain name? This also works for a
                   1629:        numerical host name. The domain name is already made lower-case
                   1630:        and without a trailing dot. */
                   1631:     {
1.84      cvs      1632:       CHAR_T* dot = port ? port : path;
                   1633:       if (dot > *filename && *--dot == TEXT('.'))
1.33      cvs      1634:        {
1.84      cvs      1635:          CHAR_T* orig = dot;
                   1636:       CHAR_T* dest = dot + 1;
1.82      cvs      1637:          while ((*orig++ = *dest++));
                   1638:             if (port) port--;
1.33      cvs      1639:          path--;
1.25      cvs      1640:        }
                   1641:     }
                   1642:     /* Chop off port if `:', `:80' (http), `:70' (gopher), or `:21' (ftp) */
1.33      cvs      1643:     if (port)
                   1644:       {
1.82      cvs      1645:        if (!*(port+1) || *(port+1) == used_sep)
1.33      cvs      1646:          {
                   1647:            if (!newname)
                   1648:              {
1.84      cvs      1649:                CHAR_T* orig = port; 
                   1650:         CHAR_T* dest = port + 1;
1.82      cvs      1651:                while ((*orig++ = *dest++));
1.33      cvs      1652:              }
                   1653:          }
1.84      cvs      1654:        else if ((!ustrncmp (access, TEXT("http"), 4)   &&
                   1655:              (*(port + 1) == TEXT('8')                    && 
                   1656:              *(port+2) == TEXT('0')                       && 
1.82      cvs      1657:              (*(port+3) == used_sep || !*(port + 3))))       ||
1.84      cvs      1658:              (!ustrncmp (access, TEXT("gopher"), 6) &&
                   1659:              (*(port+1) == TEXT('7')                      && 
                   1660:              *(port+2) == TEXT('0')                       && 
1.82      cvs      1661:              (*(port+3) == used_sep || !*(port+3))))         ||
1.84      cvs      1662:              (!ustrncmp (access, TEXT("ftp"), 3)    &&
                   1663:              (*(port+1) == TEXT('2')                      && 
                   1664:              *(port + 2) == TEXT('1')                     && 
1.82      cvs      1665:              (*(port+3) == used_sep || !*(port+3))))) {
1.33      cvs      1666:          if (!newname)
                   1667:            {
1.84      cvs      1668:              CHAR_T* orig = port; 
                   1669:           CHAR_T* dest = port + 3;
1.33      cvs      1670:              while((*orig++ = *dest++));
                   1671:              /* Update path position, Henry Minsky */
                   1672:              path -= 3;
1.25      cvs      1673:            }
1.33      cvs      1674:        }
                   1675:        else if (newname)
1.84      cvs      1676:          ustrncat (newname, port, (int) (path - port));
1.33      cvs      1677:       }
1.25      cvs      1678: 
1.33      cvs      1679:     if (newname)
                   1680:       {
1.84      cvs      1681:        CHAR_T* newpath = newname + ustrlen (newname);
                   1682:        ustrcat (newname, path);
1.25      cvs      1683:        path = newpath;
1.28      cvs      1684:        /* Free old copy */
                   1685:        TtaFreeMemory(*filename);
1.25      cvs      1686:        *filename = newname;
1.33      cvs      1687:       }
1.25      cvs      1688:     return path;
                   1689: }
                   1690: 
                   1691: 
                   1692: /*----------------------------------------------------------------------
1.29      cvs      1693:   SimplifyUrl: simplify a URI
1.32      cvs      1694:   A URI is allowed to contain the sequence xxx/../ which may be
                   1695:   replaced by "" , and the sequence "/./" which may be replaced by DIR_STR.
1.28      cvs      1696:   Simplification helps us recognize duplicate URIs. 
1.25      cvs      1697:   
1.28      cvs      1698:   Thus,        /etc/junk/../fred       becomes /etc/fred
                   1699:                 /etc/junk/./fred       becomes /etc/junk/fred
1.25      cvs      1700:   
1.28      cvs      1701:   but we should NOT change
                   1702:                 http://fred.xxx.edu/../..
1.25      cvs      1703:   
                   1704:        or      ../../albert.html
                   1705:   
1.28      cvs      1706:   In order to avoid empty URLs the following URLs become:
1.25      cvs      1707:   
                   1708:                /fred/..                becomes /fred/..
                   1709:                /fred/././..            becomes /fred/..
                   1710:                /fred/.././junk/.././   becomes /fred/..
                   1711:   
1.28      cvs      1712:   If more than one set of `://' is found (several proxies in cascade) then
                   1713:   only the part after the last `://' is simplified.
1.25      cvs      1714:   
1.28      cvs      1715:   Returns: A string which might be the old one or a new one.
1.25      cvs      1716:   ----------------------------------------------------------------------*/
                   1717: #ifdef __STDC__
1.84      cvs      1718: void         SimplifyUrl (CHAR_T** url)
1.25      cvs      1719: #else  /* __STDC__ */
1.29      cvs      1720: void         SimplifyUrl (url)
1.84      cvs      1721: CHAR_T**     url;
1.25      cvs      1722: #endif /* __STDC__ */
                   1723: {
1.84      cvs      1724:   CHAR_T*   path;
                   1725:   CHAR_T*   access;
                   1726:   CHAR_T*   newptr; 
                   1727:   CHAR_T*   p;
                   1728:   CHAR_T   *orig, *dest, *end;
1.28      cvs      1729: 
1.85      cvs      1730:   CHAR_T    used_sep;
1.77      cvs      1731:   ThotBool ddot_simplify; /* used to desactivate the double dot simplifcation:
                   1732:                             something/../ simplification in relative URLs when they start with a ../ */
1.32      cvs      1733: 
                   1734: 
1.28      cvs      1735:   if (!url || !*url)
                   1736:     return;
                   1737: 
1.84      cvs      1738:   if (ustrchr (*url, WC_URL_SEP))
1.33      cvs      1739:     {
1.84      cvs      1740:       used_sep = WC_URL_SEP;
1.33      cvs      1741:     }
1.32      cvs      1742:   else
1.33      cvs      1743:     {
1.84      cvs      1744:       used_sep = WC_DIR_SEP;
1.33      cvs      1745:     }
1.32      cvs      1746: 
1.77      cvs      1747:   /* should we simplify double dot? */
                   1748:   path = *url;
1.84      cvs      1749:   if (*path == TEXT('.') && *(path + 1) == TEXT('.'))
1.77      cvs      1750:     ddot_simplify = FALSE;
                   1751:   else
                   1752:     ddot_simplify = TRUE;
                   1753: 
1.28      cvs      1754:   /* Find any scheme name */
1.84      cvs      1755:   if ((path = ustrstr (*url, TEXT("://"))) != NULL)
1.33      cvs      1756:     {
                   1757:       /* Find host name */
1.28      cvs      1758:       access = *url;
1.84      cvs      1759:       while (access < path && (*access = utolower (*access)))
1.82      cvs      1760:             access++;
1.28      cvs      1761:       path += 3;
1.84      cvs      1762:       while ((newptr = ustrstr (path, TEXT ("://"))) != NULL)
1.82      cvs      1763:             /* For proxies */
                   1764:             path = newptr+3;
                   1765:      /* We have a host name */
1.84      cvs      1766:       path = HTCanon (url, path);
1.25      cvs      1767:     }
1.84      cvs      1768:   else if ((path = ustrstr (*url, TEXT(":/"))) != NULL)
1.28      cvs      1769:     path += 2;
                   1770:   else
                   1771:     path = *url;
1.25      cvs      1772: 
1.84      cvs      1773:   if (*path == used_sep && *(path+1) == used_sep)
1.28      cvs      1774:     /* Some URLs start //<foo> */
                   1775:     path += 1;
1.94      cvs      1776:   else if (IsFilePath (path))
                   1777:     {
                   1778:       /* doesn't need to do anything more */
                   1779:       return;
                   1780:     }
1.84      cvs      1781:   else if (!ustrncmp (path, TEXT("news:"), 5))
1.28      cvs      1782:     {
1.84      cvs      1783:       newptr = ustrchr (path+5, TEXT('@'));
1.28      cvs      1784:       if (!newptr)
                   1785:        newptr = path + 5;
                   1786:       while (*newptr)
                   1787:        {
                   1788:          /* Make group or host lower case */
1.84      cvs      1789:          *newptr = utolower (*newptr);
1.28      cvs      1790:          newptr++;
1.25      cvs      1791:        }
1.28      cvs      1792:       /* Doesn't need to do any more */
                   1793:       return;
1.25      cvs      1794:     }
1.28      cvs      1795: 
                   1796:   if ((p = path))
                   1797:     {
1.67      cvs      1798:       if (!((end = ustrchr (path, TEXT(';'))) || (end = ustrchr (path, TEXT('?'))) ||
                   1799:            (end = ustrchr (path, TEXT('#')))))
                   1800:        end = path + ustrlen (path);
1.28      cvs      1801:       
                   1802:       /* Parse string second time to simplify */
                   1803:       p = path;
                   1804:       while (p < end)
                   1805:        {
1.77      cvs      1806:          /* if we're pointing to a char, it's safe to reactivate the ../ convertion */
                   1807:          if (!ddot_simplify && *p != TEXT('.') && *p != used_sep)
                   1808:            ddot_simplify = TRUE;
                   1809: 
1.33      cvs      1810:          if (*p==used_sep)
1.28      cvs      1811:            {
1.67      cvs      1812:              if (p > *url && *(p+1) == TEXT('.') && (*(p+2) == used_sep || !*(p+2)))
1.28      cvs      1813:                {
                   1814:                  orig = p + 1;
1.84      cvs      1815:                  dest = (*(p+2) != used_sep) ? p+2 : p+3;
1.52      cvs      1816:                  while ((*orig++ = *dest++)); /* Remove a used_sep and a dot*/
1.28      cvs      1817:                  end = orig - 1;
                   1818:                }
1.77      cvs      1819:              else if (ddot_simplify && *(p+1) == TEXT('.') && *(p+2) == TEXT('.') 
                   1820:                       && (*(p+3) == used_sep || !*(p+3)))
1.28      cvs      1821:                {
                   1822:                  newptr = p;
1.52      cvs      1823:                  while (newptr>path && *--newptr!=used_sep); /* prev used_sep */
                   1824:                  if (*newptr == used_sep)
                   1825:                    orig = newptr + 1;
1.28      cvs      1826:                  else
1.52      cvs      1827:                    orig = newptr;
                   1828: 
                   1829:                  dest = (*(p+3) != used_sep) ? p+3 : p+4;
                   1830:                  while ((*orig++ = *dest++)); /* Remove /xxx/.. */
                   1831:                  end = orig-1;
                   1832:                  /* Start again with prev slash */
                   1833:                  p = newptr;
1.28      cvs      1834:                }
1.33      cvs      1835:              else if (*(p+1) == used_sep)
1.28      cvs      1836:                {
1.33      cvs      1837:                  while (*(p+1) == used_sep)
1.28      cvs      1838:                    {
                   1839:                      orig = p;
                   1840:                      dest = p + 1;
                   1841:                      while ((*orig++ = *dest++));  /* Remove multiple /'s */
                   1842:                      end = orig-1;
                   1843:                    }
                   1844:                }
                   1845:              else
1.25      cvs      1846:                p++;
1.28      cvs      1847:            }
                   1848:          else
                   1849:            p++;
1.25      cvs      1850:        }
                   1851:     }
1.51      cvs      1852: 
                   1853:     /*
                   1854:     **  Check for host/../.. kind of things
                   1855:     */
1.77      cvs      1856:     if (*path == used_sep && *(path+1) == TEXT('.') && *(path+2) == TEXT('.') 
                   1857:        && (!*(path+3) || *(path+3) == used_sep))
1.87      cvs      1858:        *(path+1) = WC_EOS;
1.51      cvs      1859: 
1.28      cvs      1860:   return;
                   1861: }
                   1862: 
                   1863: 
                   1864: /*----------------------------------------------------------------------
1.96      cvs      1865:    NormalizeFile normalizes local names.                             
1.28      cvs      1866:    Return TRUE if target and src differ.                           
                   1867:   ----------------------------------------------------------------------*/
                   1868: #ifdef __STDC__
1.97      cvs      1869: ThotBool     NormalizeFile (CHAR_T* src, CHAR_T* target, ConvertionType convertion)
1.28      cvs      1870: #else
1.97      cvs      1871: ThotBool     NormalizeFile (src, target, convertion)
1.84      cvs      1872: CHAR_T*              src;
                   1873: CHAR_T*              target;
1.97      cvs      1874: ConvertionType       convertion;
1.28      cvs      1875: 
                   1876: #endif
                   1877: {
1.93      cvs      1878: #  ifndef _WINDOWS
1.90      cvs      1879:    CHAR_T            *s;
1.93      cvs      1880:    int               i;
                   1881: #  endif /* !_WINDOWS */
1.82      cvs      1882:    ThotBool          change;
1.90      cvs      1883:    int               start_index; /* the first char that we'll copy */
1.28      cvs      1884: 
1.54      cvs      1885:    change = FALSE;
1.90      cvs      1886:    start_index = 0;
                   1887: 
                   1888:    if (!src || src[0] == WC_EOS)
1.96      cvs      1889:      {
                   1890:        target[0] = WC_EOS;
                   1891:        return FALSE;
                   1892:      }
1.90      cvs      1893: 
                   1894:    /* @@ do I need file: or file:/ here? */
1.84      cvs      1895:    if (ustrncmp (src, TEXT("file:"), 5) == 0)
1.28      cvs      1896:      {
1.90      cvs      1897:        /* remove the prefix file: */
                   1898:        start_index += 5;
                   1899:    
                   1900:        /* remove the localhost prefix */
1.94      cvs      1901:        if (ustrncmp (&src[start_index], TEXT("//localhost/"), 12) == 0)
                   1902:           start_index += 11;
                   1903:        
                   1904:        /* remove the first two slashes in / / /path */
                   1905:        while (src[start_index] &&
                   1906:              src[start_index] == TEXT('/') 
                   1907:              && src[start_index + 1] == TEXT('/'))
                   1908:         start_index++;
                   1909: 
                   1910: #ifdef _WINDOWS
                   1911:        /* remove any extra slash before the drive name */
                   1912:        if (src[start_index] == TEXT('/')
                   1913:           &&src[start_index+2] == TEXT(':'))
                   1914:         start_index++;
                   1915: #endif /* _WINDOWS */
1.90      cvs      1916: 
                   1917:        if (src[start_index] == WC_EOS)
                   1918:        /* if there's nothing afterwards, add a DIR_STR */
                   1919:         ustrcpy (target, WC_DIR_STR);
                   1920:        else
1.97      cvs      1921:         /* as we're inside a file: URL, we'll apply all the convertions
                   1922:            we know */
                   1923:         CleanCopyFileURL (target, &src[start_index], AM_CONV_ALL);
1.96      cvs      1924: 
                   1925:        change = TRUE;
                   1926:      }
1.97      cvs      1927:    else if (convertion != AM_CONV_NONE)
1.96      cvs      1928:      {
                   1929:        /* we are following a "local" relative link, we do all the
                   1930:          convertions except for the HOME_DIR ~ one */
1.97      cvs      1931:        CleanCopyFileURL (target, src, convertion);
1.28      cvs      1932:      }
1.90      cvs      1933: #ifndef _WINDOWS
1.84      cvs      1934:    else if (src[0] == TEXT('~'))
1.53      cvs      1935:      {
1.96      cvs      1936:        /* it must be a URL typed in a text input field */
                   1937:        /* do the HOME_DIR ~ substitution */
1.82      cvs      1938:        s = TtaGetEnvString ("HOME");
1.84      cvs      1939:        ustrcpy (target, s);
1.90      cvs      1940: #if 0
1.96      cvs      1941:        /* JK: invalidated this part of the code as it's simpler
                   1942:           to add the DIR_SEP whenever we have something to add
                   1943:           to the path rather than adding it systematically */
1.84      cvs      1944:        if (src[1] != WC_DIR_SEP)
                   1945:          ustrcat (target, WC_DIR_STR);
1.90      cvs      1946: #endif
                   1947:        i = ustrlen (target);
1.92      cvs      1948:        ustrcpy (&target[i], &src[1]);
1.54      cvs      1949:        change = TRUE;
1.53      cvs      1950:      }
1.90      cvs      1951: #endif /* _WINDOWS */
1.28      cvs      1952:    else
1.96      cvs      1953:    /* leave it as it is */
1.92      cvs      1954:      ustrcpy (target, src);
1.96      cvs      1955:    
1.28      cvs      1956:    /* remove /../ and /./ */
1.29      cvs      1957:    SimplifyUrl (&target);
1.54      cvs      1958:    if (!change)
1.84      cvs      1959:      change = ustrcmp (src, target);
1.28      cvs      1960:    return (change);
1.25      cvs      1961: }
                   1962: 
1.28      cvs      1963: 
1.25      cvs      1964: /*----------------------------------------------------------------------
1.31      cvs      1965:   MakeRelativeURL: make relative name
1.25      cvs      1966:   
1.28      cvs      1967:   This function creates and returns a string which gives an expression of
                   1968:   one address as related to another. Where there is no relation, an absolute
                   1969:   address is retured.
1.25      cvs      1970:   
1.28      cvs      1971:   On entry,
1.25      cvs      1972:        Both names must be absolute, fully qualified names of nodes
                   1973:        (no fragment bits)
                   1974:   
1.28      cvs      1975:   On exit,
1.25      cvs      1976:        The return result points to a newly allocated name which, if
                   1977:        parsed by AmayaParseUrl relative to relatedName, will yield aName.
                   1978:        The caller is responsible for freeing the resulting name later.
                   1979:   ----------------------------------------------------------------------*/
                   1980: #ifdef __STDC__
1.67      cvs      1981: STRING           MakeRelativeURL (STRING aName, STRING relatedName)
1.25      cvs      1982: #else  /* __STDC__ */
1.67      cvs      1983: STRING           MakeRelativeURL (aName, relatedName)
                   1984: STRING           aName;
                   1985: STRING           relatedName;
1.25      cvs      1986: #endif  /* __STDC__ */
                   1987: {
1.87      cvs      1988:   CHAR_T*        return_value;
1.67      cvs      1989:   CHAR_T         result[MAX_LENGTH];
1.87      cvs      1990:   CHAR_T*        p;
                   1991:   CHAR_T*        q;
                   1992:   CHAR_T*        after_access;
                   1993:   CHAR_T*        last_slash = NULL;
1.29      cvs      1994:   int            slashes, levels, len;
                   1995: 
1.44      cvs      1996: # ifdef _WINDOWS
                   1997:   int ndx;
                   1998: # endif /* _WINDOWS */
                   1999: 
1.29      cvs      2000:   if (aName == NULL || relatedName == NULL)
                   2001:     return (NULL);
                   2002: 
                   2003:   slashes = 0;
                   2004:   after_access = NULL;
                   2005:   p = aName;
                   2006:   q = relatedName;
                   2007:   for (; *p && (*p == *q); p++, q++)
1.27      cvs      2008:     {
                   2009:       /* Find extent of match */
1.67      cvs      2010:       if (*p == TEXT(':'))
1.29      cvs      2011:        after_access = p + 1;
1.28      cvs      2012:       if (*p == DIR_SEP)
1.27      cvs      2013:        {
1.29      cvs      2014:          /* memorize the last slash position and count them */
1.27      cvs      2015:          last_slash = p;
                   2016:          slashes++;
1.25      cvs      2017:        }
                   2018:     }
                   2019:     
1.31      cvs      2020:   /* q, p point to the first non-matching character or zero */
1.87      cvs      2021:   if (*q == WC_EOS)
1.31      cvs      2022:     {
                   2023:       /* New name is a subset of the related name */
                   2024:       /* exactly the right length */
1.67      cvs      2025:       len = ustrlen (p);
                   2026:       if ((return_value = TtaAllocString (len + 1)) != NULL)
                   2027:        ustrcpy (return_value, p);
1.31      cvs      2028:     }
                   2029:   else if ((slashes < 2 && after_access == NULL)
                   2030:       || (slashes < 3 && after_access != NULL))
                   2031:     {
                   2032:       /* Two names whitout common path */
                   2033:       /* exactly the right length */
1.67      cvs      2034:       len = ustrlen (aName);
                   2035:       if ((return_value = TtaAllocString (len + 1)) != NULL)
                   2036:        ustrcpy (return_value, aName);
1.31      cvs      2037:     }
                   2038:   else
                   2039:     {
                   2040:       /* Some path in common */
1.67      cvs      2041:       if (slashes == 3 && ustrncmp (aName, TEXT("http:"), 5) == 0)
1.31      cvs      2042:        /* just the same server */
1.67      cvs      2043:        ustrcpy (result, last_slash);
1.31      cvs      2044:       else
                   2045:        {
                   2046:          levels= 0; 
1.67      cvs      2047:          for (; *q && *q != TEXT('#') && *q != TEXT(';') && *q != TEXT('?'); q++)
1.31      cvs      2048:            if (*q == DIR_SEP)
                   2049:              levels++;
                   2050:          
1.87      cvs      2051:          result[0] = WC_EOS;
1.31      cvs      2052:          for (;levels; levels--)
1.67      cvs      2053:            ustrcat (result, TEXT("../"));
                   2054:          ustrcat (result, last_slash+1);
1.31      cvs      2055:        } 
1.52      cvs      2056: 
                   2057:       if (!*result)
1.67      cvs      2058:        ustrcat (result, TEXT("./"));
1.52      cvs      2059: 
1.31      cvs      2060:       /* exactly the right length */
1.67      cvs      2061:       len = ustrlen (result);
                   2062:       if ((return_value = TtaAllocString (len + 1)) != NULL)
                   2063:        ustrcpy (return_value, result);
1.52      cvs      2064: 
1.25      cvs      2065:     }
1.44      cvs      2066: # ifdef _WINDOWS
1.67      cvs      2067:   len = ustrlen (return_value);
1.44      cvs      2068:   for (ndx = 0; ndx < len; ndx ++)
1.67      cvs      2069:          if (return_value[ndx] == TEXT('\\'))
                   2070:             return_value[ndx] = TEXT('/') ;
1.44      cvs      2071: # endif /* _WINDOWS */
1.29      cvs      2072:   return (return_value);
1.24      cvs      2073: }
1.35      cvs      2074: 
                   2075: 

Webmaster