Ignore:
Timestamp:
02/02/03 14:06:10 (21 years ago)
Author:
Nicholas Riley
Message:

ICeCoffEE 1.3b3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEE.m

    r75 r79  
    77  for both files and text
    88- if it's not a URL, try using TextExtras' open list
    9 - John Hayes' suggestions
    10 - Menu on command-option-click: add bookmark, open with other helper, pass to configurable service, ...?
    119- TXNClick - MLTE has its own support in Jaguar and later, but it's lousy
    1210
     
    1917- app exclusion list - make a pref pane (see AquaShade config)
    2018- _LSCopyApplicationURLsForItemURL - list apps
     19- Menu on command-option-click: add bookmark, open with other helper, pass to configurable service, ...?
    2120
    2221*/
     
    130129}
    131130
    132 ConstStringPtr ICCF_GetHint(ICInstance inst, const char *urlData, long startIndex, long endIndex) {
     131ConstStringPtr ICCF_GetHint(ICInstance inst, const char *urlData, Size length, long *selStart, long *selEnd, Boolean *needsSlashes) {
    133132    Handle h = NewHandle(0);
    134133    OSStatus err;
    135     long tmpStartIndex = startIndex, tmpEndIndex = endIndex;
    136    
     134
    137135    if (h == NULL) return NULL;
    138136
    139137    // parse the URL providing a bogus protocol, to get rid of escaped forms
    140     err = ICParseURL(inst, "\p*", urlData + startIndex, endIndex - startIndex + 1,
    141                      &tmpStartIndex, &tmpEndIndex, h);
     138    err = ICParseURL(inst, "\p*", urlData, length, selStart, selEnd, h);
    142139    if (err != noErr) return NULL;
    143140
     
    149146    long i = 0;
    150147    Boolean sawAt = false;
    151     if (urlParsed[0] == '*' && urlParsed[1] == ':') {
     148    if (hSize >= 2 && urlParsed[0] == '*' && urlParsed[1] == ':') {
    152149        // this is an IC-inserted protocol; skip over it
    153150        i = 2;
    154     }
     151        *needsSlashes = (hSize < i + 2 || urlParsed[i] != '/' || urlParsed[i + 1] != '/');
     152    } else *needsSlashes = false;
    155153    for ( ; i < hSize ; i++) {
    156154        char c = urlParsed[i];
     
    164162    }
    165163    DisposeHandle(h);
    166     return (sawAt ? "\pmailto" : "\phttp");
     164    if (sawAt) {
     165        *needsSlashes = false;
     166        return "\pmailto";
     167    }
     168    return "\phttp";
     169}
     170
     171static const char *kICSlashes = "//";
     172
     173void ICCF_AddSlashes(Handle h, ConstStringPtr hint) {
     174    Size sizeBefore = GetHandleSize(h);
     175    unsigned char hintLength = StrLength(hint);
     176    char *copy = (char *)malloc(sizeBefore);
     177    memcpy(copy, *h, sizeBefore);
     178    ICLog(@"ICCF_AddSlashes before: |%s|\n", *h);
     179    ReallocateHandle(h, sizeBefore + 2);
     180
     181    // if *h begins with '<hint>:', then copy the slashes after it
     182    if (sizeBefore > hintLength + 1 && strncmp(&hint[1], copy, hintLength) == 0 && copy[hintLength] == ':') {
     183        memcpy(*h, copy, hintLength + 1);
     184        memcpy(*h + hintLength + 1, kICSlashes, 2);
     185        memcpy(*h + hintLength + 3, &copy[hintLength + 1], sizeBefore - hintLength - 1);
     186    } else {
     187        memcpy(*h, kICSlashes, 2);
     188        memcpy(*h + 2, copy, sizeBefore);
     189    }
     190       
     191    free(copy);
     192    ICLog(@"ICCF_AddSlashes after: |%s|\n", *h);
    167193}
    168194
     
    215241    unsigned len = [string length];
    216242
    217     char *urlData = NULL;
     243    Handle h = NULL;
    218244   
    219245    NS_DURING
    220         urlData = (char *)malloc( (len + 1) * sizeof(char));
    221         NSCAssert(urlData != NULL, @"Internal error: canÕt allocate memory for URL string");
    222 
    223         [string getCString: urlData];
     246        h = NewHandle(len);
     247        if (h == NULL)
     248            ICCF_OSErrCAssert(MemError(), @"NewHandle");
     249
     250        if (CFStringGetBytes((CFStringRef)string, CFRangeMake(0, len), kCFStringEncodingASCII, '\0', false, *h, len, NULL) != len)
     251            ICCF_OSErrCAssert(kTECNoConversionPathErr, @"CFStringGetBytes");
    224252
    225253        selStart = 0; selEnd = len;
    226254
    227         ConstStringPtr hint = ICCF_GetHint(ICCF_GetInst(), urlData, selStart, selEnd);
     255        Boolean needsSlashes;
     256        ConstStringPtr hint = ICCF_GetHint(ICCF_GetInst(), *h, len, &selStart, &selEnd, &needsSlashes);
    228257        NSCAssert(hint != NULL, @"Internal error: canÕt get protocol hint for URL");
    229258
     259        if (needsSlashes) {
     260            ICCF_AddSlashes(h, hint);
     261            len = selEnd = GetHandleSize(h);
     262        }
     263
    230264        if (chooseApp) {
    231             err = ICCF_DoURLActionMenu(ICCF_GetInst(), hint, urlData, selStart, selEnd);
     265            err = ICCF_DoURLActionMenu(ICCF_GetInst(), hint, *h, selStart, selEnd);
    232266            ICCF_OSErrCAssert(err, @"ICCF_DoURLActionMenu");
    233267        } else {
    234             err = ICLaunchURL(ICCF_GetInst(), hint, urlData, len, &selStart, &selEnd);
     268            err = ICLaunchURL(ICCF_GetInst(), hint, *h, len, &selStart, &selEnd);
    235269            ICCF_OSErrCAssert(err, @"ICLaunchURL");
    236270        }
    237271       
    238272    NS_HANDLER
    239         free(urlData);
     273        DisposeHandle(h);
    240274        [localException raise];
    241275    NS_ENDHANDLER
    242276
    243     free(urlData);   
     277    DisposeHandle(h);   
    244278}
    245279
     
    404438@implementation ICeCoffEE
    405439
    406 + (NSString *)IC_version;
    407 {
    408     // XXX get from bundle if possible: centralize
    409     return [NSString stringWithCString: ICCF_VERSION];
    410 }
    411 
    412440+ (void)IC_addRemoveServicesMenu;
    413441{
Note: See TracChangeset for help on using the changeset viewer.