Changeset 6588 for trunk/AWT/AWT_www.cxx

Show
Ignore:
Timestamp:
10/04/10 19:24:24 (22 months ago)
Author:
westram
Message:
  • changed default browse-url-command to 'xdg-open' ('open' on DARWIN). [thx elmar]
    • renamed AWAR_WWW_BROWSER to force update in userland
  • added 2 additional example URLs (SILVA + google) [thx elmar]
  • parse existing URLs and force insertion of missing examples if there are unused WWW patterns
  • fixed mismatched delete
  • updated WWW help
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/AWT/AWT_www.cxx

    r6490 r6588  
    1515#include <aw_awars.hxx> 
    1616#include <arbdbt.h> 
     17#include <inline.h> 
     18#include <static_assert.h> 
    1719 
    1820#define WWW_COUNT                10 
    19 // #define AWAR_WWW_BROWSER "www/browser" // now defined by ARB_init_global_awars() 
    2021#define AWAR_WWW_SELECT          "www/url_select" 
    21 #define AWAR_WWW_0               "www/url_0/srt" 
    22 #define AWAR_WWW_1               "www/url_0/srt" 
    23 #define AWAR_WWW_2               "www/url_0/srt" 
    2422#define AWAR_WWW_SELECT_TEMPLATE "www/url_%i/select" 
    2523#define AWAR_WWW_TEMPLATE        "www/url_%i/srt" 
    2624#define AWAR_WWW_DESC_TEMPLATE   "www/url_%i/desc" 
    2725 
    28  
     26inline char *extract_url_host(const char *templ) { 
     27    const char *url_start = strstr(templ, "\"http://"); 
     28    if (url_start) { 
     29        const char *host_start = url_start+8; 
     30        const char *slash      = strchr(host_start, '/'); 
     31 
     32        if (slash) return GB_strpartdup(host_start, slash-1); 
     33    } 
     34    return NULL; 
     35} 
     36 
     37inline bool url_host_matches(const char *templ1, const char *templ2) { 
     38    bool  matches = false; 
     39    char *url1    = extract_url_host(templ1); 
     40    if (url1) { 
     41        char *url2 = extract_url_host(templ2); 
     42        matches = url1 && url2 && ARB_stricmp(url1, url2) == 0; 
     43        free(url2); 
     44    } 
     45    free(url1); 
     46    return matches; 
     47} 
    2948 
    3049void awt_create_aww_vars(AW_root *aw_root, AW_default aw_def) { 
    31     int i; 
    32     for (i=0; i<WWW_COUNT; i++) { 
    33         const char *awar_name; 
    34  
    35         awar_name = GBS_global_string(AWAR_WWW_TEMPLATE, i);        aw_root->awar_string(awar_name, i==WWW_COUNT-1 ? "\"http://www.ebi.ac.uk/cgi-bin/emblfetch?\";readdb(acc)" : "", aw_def); 
    36         awar_name = GBS_global_string(AWAR_WWW_DESC_TEMPLATE, i);   aw_root->awar_string(awar_name, i==WWW_COUNT-1 ? "EMBL example" : "", aw_def); 
    37         awar_name = GBS_global_string(AWAR_WWW_SELECT_TEMPLATE, i); aw_root->awar_int(awar_name, 0, aw_def); 
    38     } 
    39  
    40     aw_root->awar_int(AWAR_WWW_SELECT, 0, aw_def); 
    41  
     50    struct Example { 
     51        const char *descr; 
     52        const char *templ; 
     53    } example[] = { 
     54        { "EMBL example",   "\"http://www.ebi.ac.uk/ena/data/view/\";readdb(acc)" }, 
     55        { "SILVA example",  "\"http://www.arb-silva.de/browser/ssu/\";readdb(acc)" }, 
     56        { "Google example", "\"http://www.google.com/search?q=\";readdb(full_name);|srt(\": =+\")" } 
     57    }, empty = { "", "" }; 
     58 
     59    const int DEFAULT_SELECT = 1; // SILVA 
     60    const int EXAMPLE_COUNT  = sizeof(example)/sizeof(*example); 
     61    COMPILE_ASSERT(EXAMPLE_COUNT <= WWW_COUNT); 
     62 
     63    bool example_url_seen[EXAMPLE_COUNT]; 
     64    for (int x = 0; x<EXAMPLE_COUNT; ++x) example_url_seen[x] = false; 
     65 
     66    AW_awar *awar_templ[WWW_COUNT]; 
     67    AW_awar *awar_descr[WWW_COUNT]; 
     68    bool     is_empty[WWW_COUNT]; 
     69 
     70    for (int i = 0; i<WWW_COUNT; ++i) { 
     71        const Example&  curr = i<EXAMPLE_COUNT ? example[i] : empty; 
     72        const char     *awar_name; 
     73 
     74        awar_name     = GBS_global_string(AWAR_WWW_TEMPLATE, i); 
     75        awar_templ[i] = aw_root->awar_string(awar_name, curr.templ, aw_def); 
     76 
     77        awar_name     = GBS_global_string(AWAR_WWW_DESC_TEMPLATE, i); 
     78        awar_descr[i] = aw_root->awar_string(awar_name, curr.descr, aw_def); 
     79 
     80        const char *templ = awar_templ[i]->read_char_pntr(); 
     81        const char *descr = awar_descr[i]->read_char_pntr(); 
     82 
     83        is_empty[i] = !templ[0] && !descr[0]; 
     84        if (!is_empty[i]) { 
     85            for (int x = 0; x<EXAMPLE_COUNT; ++x) { 
     86                if (!example_url_seen[x]) { 
     87                    example_url_seen[x] = url_host_matches(templ, example[x].templ); 
     88                } 
     89            } 
     90        } 
     91 
     92        awar_name = GBS_global_string(AWAR_WWW_SELECT_TEMPLATE, i); 
     93        aw_root->awar_int(awar_name, 0, aw_def); 
     94    } 
     95 
     96    // insert missing examples 
     97    for (int x = 0; x<EXAMPLE_COUNT; ++x) { 
     98        if (!example_url_seen[x]) { 
     99            for (int i = 0; i<WWW_COUNT; ++i) { 
     100                if (is_empty[i]) { 
     101                    awar_templ[i]->write_string(example[x].templ); 
     102                    awar_descr[i]->write_string(example[x].descr); 
     103                    is_empty[i] = false; 
     104                    break; 
     105                } 
     106            } 
     107        } 
     108    } 
     109 
     110    aw_root->awar_int(AWAR_WWW_SELECT, DEFAULT_SELECT, aw_def); 
    42111    awt_assert(ARB_global_awars_initialized()); 
    43112} 
     
    64133    error                        = awt_open_ACISRT_URL_by_gbd(aw_root, gb_main, gbd, name, url_srt); 
    65134 
    66     delete url_srt; 
     135    free(url_srt); 
    67136    return error; 
    68137} 
     
    76145 
    77146    if (!gb_species) { 
    78         error = GB_export_errorf("Cannot find species '%s'", selected_species); 
     147        error = GBS_global_string("Cannot find species '%s'", selected_species); 
    79148    } 
    80149    else {