Changeset 8224

Show
Ignore:
Timestamp:
17/11/11 22:48:48 (6 months ago)
Author:
epruesse
Message:

merge from trunk (disabled some pt server patches)

Location:
branches/dev_elmar
Files:
8 removed
186 modified
18 copied

Legend:

Unmodified
Added
Removed
  • branches/dev_elmar

    • Property svn:mergeinfo changed from /trunk:7699-7998 to /trunk:7699-8223
  • branches/dev_elmar/AISC_COM/C/aisc_extern.c

    r7415 r8224  
    22#include <string.h> 
    33#include <aisc.h> 
     4#include <attributes.h> 
    45#include <server.h> 
    56#include "aisc_extern_privat.h" 
  • branches/dev_elmar/AISC_COM/C/aisc_server.h

    r7415 r8224  
    1212#include <aisc_com.h> 
    1313 
     14#ifndef ATTRIBUTES_H 
     15#include <attributes.h> 
     16#endif 
    1417#include <server.h> 
    1518#include <aisc_server_proto.h> 
  • branches/dev_elmar/AISC_COM/C/server.c

    r7945 r8224  
    2929#include "aisc_com.h" 
    3030// AISC_MKPT_PROMOTE:#include <aisc_func_types.h> 
     31#include <attributes.h> 
    3132#include "server.h" 
    3233#include "aisc_global.h" 
     
    186187} 
    187188 
    188 static void aisc_server_sigsegv(int /*sig*/) { 
     189static SigHandler old_sigsegv_handler; 
     190 
     191static void aisc_server_sigsegv(int sig) { 
    189192    sigsegv_occurred = true; 
    190  
    191193    if (catch_sigsegv) { 
    192194        siglongjmp(return_after_segv, 666); // never returns 
    193195    } 
    194  
    195     UNINSTALL_SIGHANDLER(SIGSEGV, aisc_server_sigsegv, SIG_DFL, "aisc_server_sigsegv"); 
     196    // unexpected SEGV 
     197 
     198    UNINSTALL_SIGHANDLER(SIGSEGV, aisc_server_sigsegv, old_sigsegv_handler, "aisc_server_sigsegv"); 
     199    old_sigsegv_handler(sig); // 
     200    arb_assert(0);            // oops - old handler returned 
     201    abort(); 
    196202} 
    197203 
     
    444450    } 
    445451 
    446     // install signal handlers (asserting none have been installed yet!) 
    447     ASSERT_RESULT(SigHandler, SIG_DFL, INSTALL_SIGHANDLER(SIGSEGV, aisc_server_sigsegv, "open_aisc_server")); 
     452    // install signal handlers 
     453    fprintf(stderr, "Installing signal handler from open_aisc_server\n"); fflush(stderr); 
     454    old_sigsegv_handler = INSTALL_SIGHANDLER(SIGSEGV, aisc_server_sigsegv, "open_aisc_server"); 
    448455    ASSERT_RESULT_PREDICATE(is_default_or_ignore_sighandler, INSTALL_SIGHANDLER(SIGPIPE, aisc_server_sigpipe, "open_aisc_server")); 
    449456 
  • branches/dev_elmar/AISC_COM/C/server.h

    r7415 r8224  
    88/* define ARB attributes: */ 
    99#ifndef ATTRIBUTES_H 
    10 # include <attributes.h> 
     10#error You have to include attributes.h before including server.h 
     11// it's not possible to include attributes here due to link problems  
    1112#endif 
    1213 
  • branches/dev_elmar/AISC_MKPTPS/Makefile

    r7623 r8224  
    3939mkptypes.o: $(ARBHOME)/INCLUDE/arbtools.h 
    4040mkptypes.o: $(ARBHOME)/INCLUDE/attributes.h 
     41mkptypes.o: $(ARBHOME)/INCLUDE/dupstr.h 
    4142mkptypes.o: $(ARBHOME)/INCLUDE/test_global.h 
    4243mkptypes.o: $(ARBHOME)/INCLUDE/test_unit.h 
  • branches/dev_elmar/AISC_MKPTPS/mkptypes.cxx

    r7945 r8224  
    130130}; 
    131131 
    132 static void setSymParts(SymPart*& symParts, const char *parts) { 
    133     mp_assert(!symParts); 
    134  
     132static void addSymParts(SymPart*& symParts, const char *parts) { 
    135133    char       *p   = strdup(parts); 
    136134    const char *sep = ","; 
     
    189187static SymPart *excludedSymParts = 0; // DONT create prototypes if function-name matches one of these parts 
    190188 
    191 inline void setRequiredSymParts(const char *parts) { setSymParts(requiredSymParts, parts); } 
    192 inline void setExcludedSymParts(const char *parts) { setSymParts(excludedSymParts, parts); } 
     189inline void addRequiredSymParts(const char *parts) { addSymParts(requiredSymParts, parts); } 
     190inline void addExcludedSymParts(const char *parts) { addSymParts(excludedSymParts, parts); } 
    193191 
    194192inline void freeRequiredSymParts() { freeSymParts(requiredSymParts); } 
     
    11641162            count ++; 
    11651163            if      (strcmp(w->string, "static") == 0) isstatic = 1; 
    1166             else if (strcmp(w->string, "main") == 0) ismain = 1; 
     1164            else if (strcmp(w->string, "main")   == 0) ismain = 1; 
    11671165        } 
    11681166    } 
     
    14531451          "\n   -m               promote declaration of 'main()' (default is to skip it)" 
    14541452          "\n   -F part[,part]*  only promote declarations for functionnames containing one of the parts" 
    1455           "                      if 'part' starts with a '^' functionname has to start with rest of part\n" 
    1456           "     -S (like -F)     do NOT promote matching declarations (defaults to -S '^TEST_')\n" 
     1453          "\n                    if 'part' starts with a '^' functionname has to start with rest of part" 
     1454          "\n   -S (like -F)     do NOT promote matching declarations (defaults to -S '^TEST_')" 
    14571455          "\n" 
    14581456          "\n   -W               don't promote types in old style declarations" 
     
    14681466          "\n   -g               search for GNU extension __attribute__ in comment behind function header" 
    14691467          "\n   -G               search for ARB macro     __ATTR__      in comment behind function header" 
    1470           "                      and detect and ignore STATIC/INLINE_ATTRIBUTED() declarations\n" 
     1468          "\n                    and detect and ignore STATIC/INLINE_ATTRIBUTED() declarations" 
    14711469          "\n" 
    14721470          "\n   -P               promote /*AISC_MKPT_PROMOTE:forHeader*/ to header" 
     
    14991497    argv++; argc--; 
    15001498 
    1501     setExcludedSymParts("^TEST_"); 
     1499    addExcludedSymParts("^TEST_,^NOTEST_"); // exclude unit tests 
    15021500 
    15031501    iobuf = (char *)malloc(NEWBUFSIZ); 
     
    15421540                t = *argv++; --argc; 
    15431541                if (!t) Usage(); 
    1544                 setRequiredSymParts(t); 
     1542                addRequiredSymParts(t); 
    15451543                break; 
    15461544            } 
     
    15491547                if (!t) Usage(); 
    15501548                freeExcludedSymParts(); 
    1551                 setExcludedSymParts(t); 
     1549                addExcludedSymParts(t); 
    15521550                break; 
    15531551            } 
  • branches/dev_elmar/ARBDB/Makefile

    r7945 r8224  
    183183ad_load.o: $(ARBHOME)/INCLUDE/arb_core.h 
    184184ad_load.o: $(ARBHOME)/INCLUDE/arb_error.h 
     185ad_load.o: $(ARBHOME)/INCLUDE/arb_file.h 
    185186ad_load.o: $(ARBHOME)/INCLUDE/arb_msg.h 
     187ad_load.o: $(ARBHOME)/INCLUDE/arb_str.h 
    186188ad_load.o: $(ARBHOME)/INCLUDE/arb_string.h 
    187189ad_load.o: $(ARBHOME)/INCLUDE/arbtools.h 
     
    209211ad_save_load.o: $(ARBHOME)/INCLUDE/arb_core.h 
    210212ad_save_load.o: $(ARBHOME)/INCLUDE/arb_error.h 
     213ad_save_load.o: $(ARBHOME)/INCLUDE/arb_file.h 
    211214ad_save_load.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    212215ad_save_load.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    317320adcomm.o: $(ARBHOME)/INCLUDE/arb_core.h 
    318321adcomm.o: $(ARBHOME)/INCLUDE/arb_error.h 
     322adcomm.o: $(ARBHOME)/INCLUDE/arb_file.h 
    319323adcomm.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    320324adcomm.o: $(ARBHOME)/INCLUDE/arb_signal.h 
     
    383387adfile.o: $(ARBHOME)/INCLUDE/arb_core.h 
    384388adfile.o: $(ARBHOME)/INCLUDE/arb_error.h 
     389adfile.o: $(ARBHOME)/INCLUDE/arb_file.h 
    385390adfile.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    386391adfile.o: $(ARBHOME)/INCLUDE/arb_sort.h 
     
    528533adlang1.o: $(ARBHOME)/INCLUDE/arb_defs.h 
    529534adlang1.o: $(ARBHOME)/INCLUDE/arb_error.h 
     535adlang1.o: $(ARBHOME)/INCLUDE/arb_file.h 
    530536adlang1.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    531537adlang1.o: $(ARBHOME)/INCLUDE/arb_strbuf.h 
     
    598604admap.o: $(ARBHOME)/INCLUDE/arb_core.h 
    599605admap.o: $(ARBHOME)/INCLUDE/arb_error.h 
     606admap.o: $(ARBHOME)/INCLUDE/arb_file.h 
    600607admap.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    601608admap.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    790797adsocket.o: $(ARBHOME)/INCLUDE/arb_cs.h 
    791798adsocket.o: $(ARBHOME)/INCLUDE/arb_error.h 
     799adsocket.o: $(ARBHOME)/INCLUDE/arb_file.h 
    792800adsocket.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    793801adsocket.o: $(ARBHOME)/INCLUDE/arb_str.h 
  • branches/dev_elmar/ARBDB/ad_load.cxx

    r7945 r8224  
    1515 
    1616#include <arbdbt.h> 
     17#include <arb_str.h> 
     18#include <arb_file.h> 
    1719 
    1820#include "gb_storage.h" 
     
    13581360     * - 'c' create (if not found) 
    13591361     * - 's'     read only ??? 
    1360      * - 'd' look for default (if create) in $ARBHOME/lib (any leading '.' is removed ) 
    1361      * - 'D' look for default (if create) in $ARBHOME/lib/arb_default (any leading '.' is removed ) 
     1362     * - 'D' looks for default in $ARBHOME/lib/arb_default if file is not found in ~/.arb_prop 
     1363     *       (only work combined with mode 'c')  
    13621364     * - memory usage: 
    13631365     *   - 't' small memory usage 
     
    13841386    bool           dbCreated           = false; 
    13851387 
     1388    gb_assert(strchr(opent, 'd') == NULL); // mode 'd' is deprecated. You have to use 'D' and store your defaults inside ARBHOME/lib/arb_default 
     1389 
    13861390    if (!opent) opentype = gb_open_all; 
    13871391    else if (strchr(opent, 'w')) opentype = gb_open_all; 
     
    15041508                    GB_disable_quicksave((GBDATA *)gbd, "Database Created"); 
    15051509 
    1506                     if (strchr(opent, 'd')||strchr(opent, 'D')) { 
    1507                         // use default settings 
    1508                         const char *pre; 
    1509                         char       *found_path; 
    1510  
    1511                         GB_clear_error();           // with default-files gb_scan_directory (used above) 
    1512                         // creates an error, cause the path is a fake path 
    1513  
    1514                         if (strchr(opent, 'd')) pre = ""; 
    1515                         else                    pre = "arb_default/"; 
    1516  
    1517                         found_path = GBS_find_lib_file(path, pre, false); 
     1510                    if (strchr(opent, 'D')) { // use default settings 
     1511                        GB_clear_error(); // with default-files gb_scan_directory (used above) has created an error, cause the path was a fake path 
     1512                         
     1513                        gb_assert(ARB_strscmp(path, ".arb_prop/") != 0); // do no longer pass path-prefix [deprecated!]   
     1514                        char *found_path = GB_property_file(false, path); 
     1515 
    15181516                        if (!found_path) { 
    15191517                            fprintf(stderr, "file %s not found\n", path); 
     
    15211519                        } 
    15221520                        else { 
    1523 #if defined(DEBUG) 
    1524                             fprintf(stderr, "Using properties from %s\n", found_path); 
    1525 #endif // DEBUG 
     1521                            fprintf(stderr, "Using properties from '%s'\n", found_path); 
    15261522                            freeset(path, found_path); 
    15271523                            input = fopen(path, "rb"); 
  • branches/dev_elmar/ARBDB/ad_prot.h

    r7945 r8224  
    3030/* ad_save_load.cxx */ 
    3131GB_ERROR GB_save(GBDATA *gb, const char *path, const char *savetype); 
     32GB_ERROR GB_create_parent_directory(const char *path); 
    3233GB_ERROR GB_create_directory(const char *path); 
    33 GB_ERROR GB_save_in_home(GBDATA *gb, const char *path, const char *savetype); 
     34GB_ERROR GB_save_in_arbprop(GBDATA *gb, const char *path, const char *savetype); 
    3435GB_ERROR GB_save_as(GBDATA *gb, const char *path, const char *savetype); 
    3536GB_ERROR GB_delete_database(GB_CSTR filename); 
     
    4647bool GB_is_client(GBDATA *gbd); 
    4748GBDATA *GBCMC_find(GBDATA *gbd, const char *key, GB_TYPES type, const char *str, GB_CASE case_sens, GB_SEARCH_TYPE gbs); 
    48 int GBCMC_system(GBDATA *gbd, const char *ss) __ATTR__USERESULT_TODO; 
    4949GB_ERROR GB_tell_server_dont_wait(GBDATA *gbd); 
    5050GB_ERROR GB_install_pid(int mode); 
     
    163163char *GB_find_all_files(const char *dir, const char *mask, bool filename_only); 
    164164char *GB_find_latest_file(const char *dir, const char *mask); 
    165 char *GBS_find_lib_file(const char *filename, const char *libprefix, bool warn_when_not_found); 
     165const char *GB_existing_file(const char *file, bool warn_when_not_found); 
     166char *GB_lib_file(bool warn_when_not_found, const char *libprefix, const char *filename); 
     167char *GB_property_file(bool warn_when_not_found, const char *filename); 
    166168void GBS_read_dir(StrArray &names, const char *dir, const char *mask); 
    167169bool GB_test_textfile_difflines(const char *file1, const char *file2, int expected_difflines, int special_mode); 
     170size_t GB_test_mem_equal(const unsigned char *buf1, const unsigned char *buf2, size_t common); 
    168171bool GB_test_files_equal(const char *file1, const char *file2); 
    169172void GBT_transform_names(StrArray &dest, const StrArray &source, char *transform (const char *, void *), void *client_data); 
     
    175178 
    176179/* adtcp.cxx */ 
     180char *GB_arbtcpdat_path(void); 
    177181const char *GBS_scan_arb_tcp_param(const char *ipPort, const char *wantedParam); 
    178182 
    179183#ifdef UNIT_TESTS 
    180184#define TEST_SERVER_ID (-666) 
     185#define TEST_GENESERVER_ID (-667) 
    181186#endif 
    182187 
     
    277282char *GB_get_subfields(GBDATA *gbd); 
    278283bool GB_allow_compression(GBDATA *gb_main, bool allow_compression); 
    279 GB_ERROR GB_set_temporary(GBDATA *gbd); 
     284GB_ERROR GB_set_temporary(GBDATA *gbd) __ATTR__USERESULT; 
    280285GB_ERROR GB_clear_temporary(GBDATA *gbd); 
    281286bool GB_is_temporary(GBDATA *gbd); 
     
    380385 
    381386/* adindex.cxx */ 
    382 GB_ERROR GB_create_index(GBDATA *gbd, const char *key, GB_CASE case_sens, long estimated_size); 
     387GB_ERROR GB_create_index(GBDATA *gbd, const char *key, GB_CASE case_sens, long estimated_size) __ATTR__USERESULT; 
    383388NOT4PERL void GB_dump_indices(GBDATA *gbd); 
    384389GB_ERROR GB_request_undo_type(GBDATA *gb_main, GB_UNDO_TYPE type) __ATTR__USERESULT_TODO; 
     
    387392char *GB_undo_info(GBDATA *gb_main, GB_UNDO_TYPE type); 
    388393GB_ERROR GB_set_undo_mem(GBDATA *gbd, long memsize); 
     394 
     395/* admap.cxx */ 
     396bool GB_supports_mapfile(void); 
    389397 
    390398/* adquery.cxx */ 
     
    415423/* adsocket.cxx */ 
    416424void GB_usleep(long usec); 
    417 GB_ULONG GB_time_of_file(const char *path); 
    418 long GB_size_of_file(const char *path); 
    419 long GB_mode_of_file(const char *path); 
    420 long GB_mode_of_link(const char *path); 
    421 bool GB_is_regularfile(const char *path); 
    422 bool GB_is_link(const char *path); 
    423 bool GB_is_executablefile(const char *path); 
    424 bool GB_is_privatefile(const char *path, bool read_private); 
    425 bool GB_is_readablefile(const char *filename); 
    426 bool GB_is_directory(const char *path); 
    427 long GB_getuid_of_file(const char *path); 
    428 int GB_unlink(const char *path); 
    429 void GB_unlink_or_warn(const char *path, GB_ERROR *error); 
    430 char *GB_follow_unix_link(const char *path); 
    431 GB_ERROR GB_symlink(const char *target, const char *link); 
    432 GB_ERROR GB_set_mode_of_file(const char *path, long mode); 
    433 GB_ERROR GB_rename_file(const char *oldpath, const char *newpath); 
    434425char *GB_read_fp(FILE *in); 
    435426char *GB_read_file(const char *path); 
    436427char *GB_map_FILE(FILE *in, int writeable); 
    437428char *GB_map_file(const char *path, int writeable); 
    438 long GB_size_of_FILE(FILE *in); 
    439429GB_ULONG GB_time_of_day(void); 
    440430long GB_last_saved_clock(GBDATA *gb_main); 
    441431GB_ULONG GB_last_saved_time(GBDATA *gb_main); 
    442432GB_ERROR GB_textprint(const char *path) __ATTR__USERESULT; 
    443 GB_ERROR GB_system(const char *system_command) __ATTR__USERESULT; 
    444433GB_ERROR GB_xterm(void) __ATTR__USERESULT; 
    445434GB_ERROR GB_xcmd(const char *cmd, bool background, bool wait_only_if_error) __ATTR__USERESULT_TODO; 
     
    472461GB_CSTR GB_path_in_ARBHOME(const char *relative_path); 
    473462GB_CSTR GB_path_in_ARBLIB(const char *relative_path); 
     463GB_CSTR GB_path_in_arbprop(const char *relative_path); 
    474464GB_CSTR GB_path_in_ARBHOME(const char *relative_path_left, const char *anypath_right); 
    475465GB_CSTR GB_path_in_ARBLIB(const char *relative_path_left, const char *anypath_right); 
  • branches/dev_elmar/ARBDB/ad_save_load.cxx

    r7945 r8224  
    1313#include <netinet/in.h> 
    1414 
     15#include <arb_file.h> 
     16 
    1517#include "gb_map.h" 
    1618#include "gb_load.h" 
     
    184186    if (Main) Main->qs.last_index = -1; 
    185187 
    186     gb_assert(!GB_have_error()); // dont export 
    187     return error; 
     188    RETURN_ERROR(error); 
    188189} 
    189190 
     
    192193    if (!error) GB_unlink_or_warn(gb_mapfile_name(path), &error); // delete old mapfile 
    193194 
    194     gb_assert(!GB_have_error());                    // dont export 
    195     return error; 
     195    RETURN_ERROR(error); 
    196196} 
    197197 
     
    833833} 
    834834 
     835GB_ERROR GB_create_parent_directory(const char *path) { 
     836    GB_ERROR error = NULL; 
     837    char *parent; 
     838    GB_split_full_path(path, &parent, NULL, NULL, NULL); 
     839    if (parent) { 
     840        if (!GB_is_directory(parent)) error = GB_create_directory(parent); 
     841        free(parent); 
     842    } 
     843    return error; 
     844} 
     845 
    835846GB_ERROR GB_create_directory(const char *path) { 
    836847    GB_ERROR error = 0; 
    837848    if (!GB_is_directory(path)) { 
    838         char *parent; 
    839         GB_split_full_path(path, &parent, NULL, NULL, NULL); 
    840         if (parent) { 
    841             if (!GB_is_directory(parent)) error = GB_create_directory(parent); 
    842             free(parent); 
    843         } 
    844  
     849        error = GB_create_parent_directory(path); 
    845850        if (!error) { 
    846851            int res = mkdir(path, ACCESSPERMS); 
    847852            if (res) error = GB_IO_error("creating directory", path); 
    848853        } 
    849  
    850         gb_assert(error || GB_is_directory(path)); 
    851  
    852854        error = GB_failedTo_error("GB_create_directory", path, error); 
    853855    } 
     
    855857} 
    856858 
    857 GB_ERROR GB_save_in_home(GBDATA *gb, const char *path, const char *savetype) { 
     859GB_ERROR GB_save_in_arbprop(GBDATA *gb, const char *path, const char *savetype) { 
    858860    /* savetype 
    859861     *      'a'    ascii 
    860862     *      'b'    binary 
    861863     *      'bm'   binary + mapfile 
    862      *      0=ascii 
    863864     * 
    864865     * automatically creates subdirectories 
    865866     */ 
    866     GB_ERROR    error = 0; 
    867     char       *buffer; 
    868     const char *env; 
    869     char       *slash; 
    870  
    871     env = GB_getenvHOME(); 
    872     if (!path) path = GB_MAIN(gb)->path; 
    873  
    874     buffer = (char *)GB_calloc(sizeof(char), strlen(env) + strlen(path) + 2); 
    875  
    876     sprintf(buffer, "%s/%s", env, path); 
    877     slash             = strrchr(buffer, '/'); 
    878     *slash            = 0; 
    879     error             = GB_create_directory(buffer); 
    880     *slash            = '/'; 
    881     if (!error) error = GB_save_as(gb, buffer, savetype); 
    882     if (buffer) free(buffer); 
     867 
     868    char     *fullname = strdup(GB_path_in_arbprop(path ? path : GB_MAIN(gb)->path)); 
     869    GB_ERROR  error    = GB_create_parent_directory(fullname); 
     870    if (!error) error = GB_save_as(gb, fullname, savetype); 
     871    free(fullname); 
     872 
    883873    return error; 
    884874} 
     
    938928 
    939929                    bool outOfOrderSave     = strchr(savetype, 'f'); 
    940                     bool deleteQuickAllowed = !outOfOrderSave; 
     930                    bool deleteQuickAllowed = !outOfOrderSave && !dump_to_stdout; 
    941931                    { 
    942932                        int result = 0; 
     
    10181008    } 
    10191009 
    1020     gb_assert(!GB_have_error());                    // dont export 
    1021     return error; 
     1010    RETURN_ERROR(error); 
    10221011} 
    10231012 
     
    11291118    } 
    11301119 
    1131     gb_assert(!GB_have_error());                    // dont export 
    1132     return error; 
     1120    RETURN_ERROR(error); 
    11331121} 
    11341122 
     
    12001188    } 
    12011189 
    1202     gb_assert(!GB_have_error());                    // dont export 
    1203     return error; 
     1190    RETURN_ERROR(error); 
    12041191} 
    12051192 
     
    13121299 
    13131300// #define TEST_AUTO_UPDATE // uncomment to auto-update binary and quicksave testfiles (needed once after changing ascii testfile or modify_db()) 
    1314 #define TEST_copy(src, dst) TEST_ASSERT(system(GBS_global_string("cp '%s' '%s'", src, dst)) == 0) 
    13151301 
    13161302#define TEST_loadsave_CLEANUP() TEST_ASSERT(system("rm -f [ab]2[ab]*.* master.* slave.* renamed.* fast.* fast2b.* TEST_loadsave.ARF") == 0) 
     
    13881374 
    13891375#if defined(TEST_AUTO_UPDATE) 
    1390         TEST_copy("a2b.a00", "TEST_loadsave_quick.a00"); 
     1376        TEST_COPY_FILE("a2b.a00", "TEST_loadsave_quick.a00"); 
    13911377#endif // TEST_AUTO_UPDATE 
    13921378 
  • branches/dev_elmar/ARBDB/ad_t_prot.h

    r7945 r8224  
    128128GB_ERROR GBT_write_float(GBDATA *gb_container, const char *fieldpath, double content); 
    129129GBDATA *GB_test_link_follower(GBDATA *gb_main, GBDATA *gb_link, const char *link); 
    130 GBDATA *GBT_open(const char *path, const char *opent, const char *disabled_path); 
     130GBDATA *GBT_open(const char *path, const char *opent); 
    131131GB_ERROR GBT_remote_action(GBDATA *gb_main, const char *application, const char *action_name); 
    132132GB_ERROR GBT_remote_awar(GBDATA *gb_main, const char *application, const char *awar_name, const char *value); 
  • branches/dev_elmar/ARBDB/adcomm.cxx

    r7945 r8224  
    2727#include <SigHandler.h> 
    2828#include <arb_signal.h> 
     29#include <arb_file.h> 
    2930 
    3031static GBCM_ServerResult gbcms_talking(int con, long *hs, void *sin); 
     
    4849#define GBCM_COMMAND_FIND               (GBTUM_MAGIC_NUMBER+8) 
    4950#define GBCM_COMMAND_CLOSE              (GBTUM_MAGIC_NUMBER+9) 
    50 #define GBCM_COMMAND_SYSTEM             (GBTUM_MAGIC_NUMBER+10) 
    5151#define GBCM_COMMAND_KEY_ALLOC          (GBTUM_MAGIC_NUMBER+11) 
    5252#define GBCM_COMMAND_UNDO               (GBTUM_MAGIC_NUMBER+12) 
     
    6565#define GBCM_COMMAND_FIND_ERG           (GBTUM_MAGIC_NUMBER+0x108000) 
    6666#define GBCM_COMMAND_KEY_ALLOC_RES      (GBTUM_MAGIC_NUMBER+0x10b000) 
    67 #define GBCM_COMMAND_SYSTEM_RETURN      (GBTUM_MAGIC_NUMBER+0x10a0000) 
    6867#define GBCM_COMMAND_UNDO_CMD           (GBTUM_MAGIC_NUMBER+0x10a0001) 
    6968 
     
    968967    // command: GBCM_COMMAND_CLOSE 
    969968    return GBCM_SERVER_ABORTED; 
    970 } 
    971  
    972 static GBCM_ServerResult gbcms_talking_system(int socket, long */*hsin*/, void */*sin*/, GBDATA */*gbd*/) { 
    973     // command: GBCM_COMMAND_SYSTEM 
    974     char *comm = gbcm_read_string(socket); 
    975  
    976     gbcm_read_flush(); 
    977  
    978     GB_ERROR error = GB_system(comm); 
    979     if (error) { 
    980         GB_warning(error); 
    981         return GBCM_SERVER_FAULT; 
    982     } 
    983  
    984     if (gbcm_write_two(socket, GBCM_COMMAND_SYSTEM_RETURN, 0)) { 
    985         return GBCM_SERVER_FAULT; 
    986     } 
    987     return gbcm_write_flush(socket); 
    988969} 
    989970 
     
    11341115} 
    11351116 
     1117static GBCM_ServerResult gbcms_talking_obsolete(int /*socket*/, long */*hsin*/, void */*sin*/, GBDATA */*gbd*/) { 
     1118    fputs("Obsolete server function called\n", stderr); 
     1119    return GBCM_SERVER_FAULT; 
     1120} 
     1121 
    11361122// ----------------------- 
    11371123//      server talking 
     
    11501136    gbcms_talking_find,                             // GBCM_COMMAND_FIND 
    11511137    gbcms_talking_close,                            // GBCM_COMMAND_CLOSE 
    1152     gbcms_talking_system,                           // GBCM_COMMAND_SYSTEM 
     1138    gbcms_talking_obsolete, 
    11531139    gbcms_talking_key_alloc,                        // GBCM_COMMAND_KEY_ALLOC 
    11541140    gbcms_talking_undo,                             // GBCM_COMMAND_UNDO 
     
    17811767} 
    17821768 
    1783 #if defined(WARN_TODO) 
    1784 #warning GBCMC_system should return GB_ERROR! 
    1785 #endif 
    1786  
    1787 int GBCMC_system(GBDATA *gbd, const char *ss) { // goes to header: __ATTR__USERESULT_TODO 
    1788     int           socket; 
    1789     long          gb_result[2]; 
    1790     GB_MAIN_TYPE *Main = GB_MAIN(gbd); 
    1791  
    1792     if (Main->local_mode) { 
    1793         GB_ERROR error = GB_system(ss); 
    1794         if (error) GB_export_error(error); 
    1795         return error != 0; 
    1796     } 
    1797     socket = Main->c_link->socket; 
    1798  
    1799     if (gbcm_write_two(socket, GBCM_COMMAND_SYSTEM, gbd->server_id)) { 
    1800         GB_export_error(SEND_ERROR()); 
    1801         GB_print_error(); 
    1802         return -1; 
    1803     } 
    1804  
    1805     gbcm_write_string(socket, ss); 
    1806     if (gbcm_write_flush(socket)) { 
    1807         GB_export_error("ARB_DB CLIENT ERROR send failed"); 
    1808         GB_print_error(); 
    1809         return -1; 
    1810     } 
    1811     gbcm_read_two(socket, GBCM_COMMAND_SYSTEM_RETURN, 0, (long *)gb_result); 
    1812     gbcm_read_flush(); 
    1813     return 0; 
    1814 } 
    1815  
    18161769GB_ERROR gbcmc_send_undo_commands(GBDATA *gbd, enum gb_undo_commands command) { // goes to header: __ATTR__USERESULT 
    18171770    // send an undo command 
  • branches/dev_elmar/ARBDB/adfile.cxx

    r7945 r8224  
    2222#include <arb_str.h> 
    2323#include <arb_strarray.h> 
     24#include <arb_file.h> 
    2425 
    2526#include "gb_local.h" 
     
    194195} 
    195196 
    196 char *GBS_find_lib_file(const char *filename, const char *libprefix, bool warn_when_not_found) { 
    197     // Searches files in current dir, $HOME, $ARBHOME/lib/libprefix 
    198  
    199     char *result = 0; 
    200  
    201     if (GB_is_readablefile(filename)) { 
    202         result = strdup(filename); 
    203     } 
    204     else { 
    205         const char *slash = strrchr(filename, '/'); // look for last slash 
    206  
    207         if (slash && filename[0] != '.') { // have absolute path 
    208             filename = slash+1; // only use filename part 
    209             slash    = 0; 
    210         } 
    211  
    212         const char *fileInHome = GB_concat_full_path(GB_getenvHOME(), filename); 
    213  
    214         if (fileInHome && GB_is_readablefile(fileInHome)) { 
    215             result = strdup(fileInHome); 
    216         } 
    217         else { 
    218             if (slash) filename = slash+1; // now use filename only, even if path starts with '.' 
    219  
    220             const char *fileInLib = GB_path_in_ARBLIB(libprefix, filename); 
    221  
    222             if (fileInLib && GB_is_readablefile(fileInLib)) { 
    223                 result = strdup(fileInLib); 
    224             } 
    225             else { 
    226                 if (warn_when_not_found) { 
    227                     GB_warningf("Don't know where to find '%s'\n" 
    228                                 "  searched in '.'\n" 
    229                                 "  searched in $(HOME) (for '%s')\n" 
    230                                 "  searched in $(ARBHOME)/lib/%s (for '%s')\n", 
    231                                 filename, fileInHome, libprefix, fileInLib); 
    232                 } 
    233             } 
    234         } 
    235     } 
    236  
     197const char *GB_existing_file(const char *file, bool warn_when_not_found) { 
     198    // return 'file' if it's an existing readable file 
     199    // return NULL otherwise 
     200 
     201    gb_assert(file); 
     202    if (GB_is_readablefile(file)) return file; 
     203    if (warn_when_not_found) GB_warningf("Could not find '%s'", file); 
     204    return NULL; 
     205} 
     206 
     207char *GB_lib_file(bool warn_when_not_found, const char *libprefix, const char *filename) { 
     208    // Search a file in '$ARBHOME/lib/libprefix' 
     209    // Return NULL if not found 
     210    return nulldup(GB_existing_file(GB_path_in_ARBLIB(libprefix, filename), warn_when_not_found)); 
     211} 
     212 
     213char *GB_property_file(bool warn_when_not_found, const char *filename) { 
     214    // Search a file in '~/.arb_prop' or its default in '$ARBHOME/lib/arb_default' 
     215    // Return NULL if neighter found 
     216 
     217    char *result = nulldup(GB_existing_file(GB_path_in_arbprop(filename), warn_when_not_found)); 
     218    if (!result) result = GB_lib_file(warn_when_not_found, "arb_default", filename); 
    237219    return result; 
    238220} 
     
    585567} 
    586568 
     569size_t GB_test_mem_equal(const unsigned char *buf1, const unsigned char *buf2, size_t common) { 
     570    size_t equal_bytes; 
     571    if (memcmp(buf1, buf2, common) == 0) { 
     572        equal_bytes = common; 
     573    } 
     574    else { 
     575        equal_bytes = 0; 
     576        size_t x    = 0;    // position inside memory 
     577        while (buf1[x] == buf2[x]) { 
     578            x++; 
     579            equal_bytes++; 
     580        } 
     581 
     582        const size_t DUMP       = 7; 
     583        size_t       y1         = x >= DUMP ? x-DUMP : 0; 
     584        size_t       y2         = (x+DUMP)>common ? common : (x+DUMP); 
     585        size_t       blockstart = equal_bytes-x; 
     586 
     587        for (size_t y = y1; y <= y2; y++) { 
     588            fprintf(stderr, "[0x%04zx]", blockstart+y); 
     589            arb_test::print_pair(buf1[y], buf2[y]); 
     590            fputc(' ', stderr); 
     591            arb_test::print_hex_pair(buf1[y], buf2[y]); 
     592            if (x == y) fputs("                     <- diff", stderr); 
     593            fputc('\n', stderr); 
     594        } 
     595        if (y2 == common) { 
     596            fputs("[end of block - truncated]\n", stderr); 
     597        } 
     598    } 
     599    return equal_bytes; 
     600} 
     601 
    587602bool GB_test_files_equal(const char *file1, const char *file2) { 
    588603    const char        *error = NULL; 
     
    606621 
    607622            while (!error) { 
    608                 int read1  = fread(buf1, 1, BLOCKSIZE, fp1); 
    609                 int read2  = fread(buf2, 1, BLOCKSIZE, fp2); 
    610                 int common = read1<read2 ? read1 : read2; 
     623                int    read1  = fread(buf1, 1, BLOCKSIZE, fp1); 
     624                int    read2  = fread(buf2, 1, BLOCKSIZE, fp2); 
     625                size_t common = read1<read2 ? read1 : read2; 
    611626 
    612627                if (!common) { 
     
    615630                } 
    616631 
    617                 if (memcmp(buf1, buf2, common) == 0) { 
    618                     equal_bytes += common; 
    619                 } 
    620                 else { 
    621                     int x = 0; 
    622                     while (buf1[x] == buf2[x]) { 
    623                         x++; 
    624                         equal_bytes++; 
    625                     } 
     632                size_t thiseq = GB_test_mem_equal(buf1, buf2, common); 
     633                if (thiseq != common) { 
    626634                    error = "content differs"; 
    627  
    628                     // x is the position inside the current block 
    629                     const int DUMP       = 7; 
    630                     int       y1         = x >= DUMP ? x-DUMP : 0; 
    631                     int       y2         = (x+DUMP)>common ? common : (x+DUMP); 
    632                     int       blockstart = equal_bytes-x; 
    633  
    634                     for (int y = y1; y <= y2; y++) { 
    635                         fprintf(stderr, "[0x%04x]", blockstart+y); 
    636                         arb_test::print_pair(buf1[y], buf2[y]); 
    637                         fputc(' ', stderr); 
    638                         arb_test::print_hex_pair(buf1[y], buf2[y]); 
    639                         if (x == y) fputs("                     <- diff", stderr); 
    640                         fputc('\n', stderr); 
    641                     } 
    642                     if (y2 == common) { 
    643                         fputs("[end of block - truncated]\n", stderr); 
    644                     } 
    645                 } 
     635                } 
     636                equal_bytes += thiseq; 
    646637            } 
    647638 
     
    708699} 
    709700 
     701void TEST_find_file() { 
     702    TEST_ASSERT_EQUAL(GB_existing_file("min_ascii.arb", false), "min_ascii.arb"); 
     703    TEST_ASSERT_EQUAL(GB_existing_file("nosuchfile", false), NULL); 
     704     
     705    char *tcporg = GB_lib_file(false, "", "arb_tcp_org.dat"); 
     706    TEST_ASSERT_EQUAL(tcporg, GB_path_in_ARBHOME("lib/arb_tcp_org.dat")); 
     707    TEST_ASSERT_EQUAL(GB_lib_file(true, "bla", "blub"), NULL); 
     708    free(tcporg); 
     709 
     710    char *status = GB_property_file(false, "status.arb"); 
     711    TEST_ASSERT_EQUAL(status, GB_path_in_ARBHOME("lib/arb_default/status.arb")); 
     712    TEST_ASSERT_EQUAL(GB_property_file(true, "undhepp"), NULL); 
     713    free(status); 
     714} 
     715 
    710716// -------------------------------------------------------------------------------- 
    711717// tests for global code included from central ARB headers (located in $ARBHOME/TEMPLATES) 
     
    755761 
    756762            TEST_ASSERT(correlated( 
    757                                   correlated(kermitIsGreen, kermitIsFrog),  
    758                                   allFrogsAreGreen && onlyFrogsAreGreen 
    759                                   )); 
    760         } 
    761     } 
    762 } 
     763                            correlated(kermitIsGreen, kermitIsFrog),  
     764                            allFrogsAreGreen && onlyFrogsAreGreen 
     765                            )); 
     766        } 
     767    } 
     768} 
     769 
    763770 
    764771#endif // UNIT_TESTS 
  • branches/dev_elmar/ARBDB/adindex.cxx

    r7945 r8224  
    120120} 
    121121 
    122 GB_ERROR GB_create_index(GBDATA *gbd, const char *key, GB_CASE case_sens, long estimated_size) { 
     122GB_ERROR GB_create_index(GBDATA *gbd, const char *key, GB_CASE case_sens, long estimated_size) { // goes to header: __ATTR__USERESULT 
    123123    /* Create an index for a database. 
    124124     * Uses hash tables - collisions are avoided by using linked lists. 
     
    127127 
    128128    if (GB_TYPE(gbd) != GB_DB) { 
    129         error = GB_export_error("GB_create_index used on non CONTAINER Type"); 
     129        error = "GB_create_index used on non CONTAINER Type"; 
    130130    } 
    131131    else if (GB_read_clients(gbd)<0) { 
    132         error = GB_export_error("No index tables in DB clients allowed"); 
     132        error = "No index tables in DB clients allowed"; 
    133133    } 
    134134    else { 
     
    171171        } 
    172172    } 
    173     return error; 
     173    RETURN_ERROR(error); 
    174174} 
    175175 
  • branches/dev_elmar/ARBDB/adlang1.cxx

    r7945 r8224  
    1919#include <arb_defs.h> 
    2020#include <arb_strbuf.h> 
     21#include <arb_file.h> 
    2122#include <aw_awar_defs.hxx> 
    2223 
  • branches/dev_elmar/ARBDB/admap.cxx

    r7945 r8224  
    1212#include "gb_storage.h" 
    1313#include "gb_index.h" 
     14#include <arb_file.h> 
    1415 
    1516#include <static_assert.h> 
     
    674675} 
    675676 
     677bool GB_supports_mapfile() { 
     678#if (MEMORY_TEST == 1) 
     679    return false; 
     680#else 
     681    return true; 
     682#endif 
     683} 
     684 
    676685int gb_is_valid_mapfile(const char *path, gb_map_header *mheader, int verbose) { 
    677686    /* Test whether mapfile is valid 
  • branches/dev_elmar/ARBDB/adsocket.cxx

    r7945 r8224  
    1111#include <unistd.h> 
    1212 
    13 #include <cerrno> 
    1413#include <climits> 
    1514#include <cstdarg> 
     
    2827#include <arb_str.h> 
    2928#include <arb_strbuf.h> 
     29#include <arb_file.h> 
    3030 
    3131#include "gb_comm.h" 
     
    301301} 
    302302 
     303inline bool is_default_or_ignore_or_own_sighandler(SigHandler sh) { 
     304    return sh == gbcmc_suppress_sigpipe || is_default_or_ignore_sighandler(sh); 
     305} 
     306 
    303307gbcmc_comm *gbcmc_open(const char *path) { 
    304308    gbcmc_comm *link = (gbcmc_comm *)GB_calloc(sizeof(gbcmc_comm), 1); 
     
    313317        return 0; 
    314318    } 
    315     ASSERT_RESULT_PREDICATE(is_default_or_ignore_sighandler, INSTALL_SIGHANDLER(SIGPIPE, gbcmc_suppress_sigpipe, "gbcmc_open")); 
     319    ASSERT_RESULT_PREDICATE(is_default_or_ignore_or_own_sighandler, INSTALL_SIGHANDLER(SIGPIPE, gbcmc_suppress_sigpipe, "gbcmc_open")); 
    316320    gb_local->iamclient = 1; 
    317321    return link; 
     
    405409} 
    406410 
    407  
    408 static struct stat gb_global_stt; 
    409  
    410 GB_ULONG GB_time_of_file(const char *path) 
    411 { 
    412     if (path) { 
    413         char *path2 = GBS_eval_env(path); 
    414         if (stat(path2, &gb_global_stt)) { 
    415             free(path2); 
    416             return 0; 
    417         } 
    418         free(path2); 
    419     } 
    420     return gb_global_stt.st_mtime; 
    421 } 
    422  
    423 long GB_size_of_file(const char *path) { 
    424     if (!path || stat(path, &gb_global_stt)) return -1; 
    425     return gb_global_stt.st_size; 
    426 } 
    427  
    428 long GB_mode_of_file(const char *path) 
    429 { 
    430     if (path) if (stat(path, &gb_global_stt)) return -1; 
    431     return gb_global_stt.st_mode; 
    432 } 
    433  
    434 long GB_mode_of_link(const char *path) 
    435 { 
    436     if (path) if (lstat(path, &gb_global_stt)) return -1; 
    437     return gb_global_stt.st_mode; 
    438 } 
    439  
    440 bool GB_is_regularfile(const char *path) { 
    441     // Warning : returns true for symbolic links to files (use GB_is_link() to test) 
    442     struct stat stt; 
    443     return stat(path, &stt) == 0 && S_ISREG(stt.st_mode); 
    444 } 
    445  
    446 bool GB_is_link(const char *path) { 
    447     struct stat stt; 
    448     return lstat(path, &stt) == 0 && S_ISLNK(stt.st_mode); 
    449 } 
    450  
    451 bool GB_is_executablefile(const char *path) { 
    452     struct stat stt; 
    453     bool        executable = false; 
    454  
    455     if (stat(path, &stt) == 0) { 
    456         uid_t my_userid = geteuid(); // effective user id 
    457         if (stt.st_uid == my_userid) { // I am the owner of the file 
    458             executable = !!(stt.st_mode&S_IXUSR); // owner execution permission 
    459         } 
    460         else { 
    461             gid_t my_groupid = getegid(); // effective group id 
    462             if (stt.st_gid == my_groupid) { // I am member of the file's group 
    463                 executable = !!(stt.st_mode&S_IXGRP); // group execution permission 
    464             } 
    465             else { 
    466                 executable = !!(stt.st_mode&S_IXOTH); // others execution permission 
    467             } 
    468         } 
    469     } 
    470  
    471     return executable; 
    472 } 
    473  
    474 bool GB_is_privatefile(const char *path, bool read_private) { 
    475     // return true, if nobody but user has write permission 
    476     // if 'read_private' is true, only return true if nobody but user has read permission 
    477     // 
    478     // Note: Always returns true for missing files! 
    479     // 
    480     // GB_is_privatefile is mainly used to assert that files generated in /tmp have secure permissions 
    481  
    482     struct stat stt; 
    483     bool        isprivate = true; 
    484  
    485     if (stat(path, &stt) == 0) { 
    486         if (read_private) { 
    487             isprivate = (stt.st_mode & (S_IWGRP|S_IWOTH|S_IRGRP|S_IROTH)) == 0; 
    488         } 
    489         else { 
    490             isprivate = (stt.st_mode & (S_IWGRP|S_IWOTH)) == 0; 
    491         } 
    492     } 
    493     return isprivate; 
    494 } 
    495  
    496 bool GB_is_readablefile(const char *filename) { 
    497     FILE *in = fopen(filename, "r"); 
    498  
    499     if (in) { 
    500         fclose(in); 
    501         return true; 
    502     } 
    503     return false; 
    504 } 
    505  
    506 bool GB_is_directory(const char *path) { 
    507     // Warning : returns true for symbolic links to directories (use GB_is_link()) 
    508     struct stat stt; 
    509     return stat(path, &stt) == 0 && S_ISDIR(stt.st_mode); 
    510 } 
    511  
    512 long GB_getuid_of_file(const char *path) { 
    513     struct stat stt; 
    514     if (stat(path, &stt)) return -1; 
    515     return stt.st_uid; 
    516 } 
    517  
    518 int GB_unlink(const char *path) 
    519 {   /*! unlink a file 
    520      * @return 
    521      *  0   success 
    522      *  1   File did not exist 
    523      * -1   Error (use GB_await_error() to retrieve message) 
    524      */ 
    525  
    526     if (unlink(path) != 0) { 
    527         if (errno == ENOENT) { 
    528             return 1; 
    529         } 
    530         GB_export_error(GB_IO_error("removing", path)); 
    531         return -1; 
    532     } 
    533     return 0; 
    534 } 
    535  
    536 void GB_unlink_or_warn(const char *path, GB_ERROR *error) { 
    537     /* Unlinks 'path' 
    538      * 
    539      * In case of a real unlink failure: 
    540      * - if 'error' is given -> set error if not already set 
    541      * - otherwise only warn 
    542      */ 
    543  
    544     if (GB_unlink(path)<0) { 
    545         GB_ERROR unlink_error = GB_await_error(); 
    546         if (error && *error == NULL) *error = unlink_error; 
    547         else GB_warning(unlink_error); 
    548     } 
    549 } 
    550  
    551 char *GB_follow_unix_link(const char *path) {   // returns the real path of a file 
    552     char buffer[1000]; 
    553     char *path2; 
    554     char *pos; 
    555     char *res; 
    556     int len = readlink(path, buffer, 999); 
    557     if (len<0) return 0; 
    558     buffer[len] = 0; 
    559     if (path[0] == '/') return strdup(buffer); 
    560  
    561     path2 = strdup(path); 
    562     pos = strrchr(path2, '/'); 
    563     if (!pos) { 
    564         free(path2); 
    565         return strdup(buffer); 
    566     } 
    567     *pos = 0; 
    568     res  = GBS_global_string_copy("%s/%s", path2, buffer); 
    569     free(path2); 
    570     return res; 
    571 } 
    572  
    573 GB_ERROR GB_symlink(const char *target, const char *link) { 
    574     if (symlink(target, link)<0) { 
    575         return GBS_global_string("Cannot create symlink '%s' to file '%s'", link, target); 
    576     } 
    577     return 0; 
    578 } 
    579  
    580 GB_ERROR GB_set_mode_of_file(const char *path, long mode) { 
    581     if (chmod(path, (int)mode)) return GBS_global_string("Cannot change mode of '%s'", path); 
    582     return 0; 
    583 } 
    584  
    585 GB_ERROR GB_rename_file(const char *oldpath, const char *newpath) { 
    586     long old_mod               = GB_mode_of_file(newpath); // keep filemode for existing files 
    587     if (old_mod == -1) old_mod = GB_mode_of_file(oldpath); 
    588  
    589     GB_ERROR error = NULL; 
    590     if (rename(oldpath, newpath) != 0) { 
    591         error = GB_IO_error("renaming", GBS_global_string("%s into %s", oldpath, newpath)); 
    592     } 
    593     else { 
    594         error = GB_set_mode_of_file(newpath, old_mod); 
    595     } 
    596      
    597     sync();                                         // why ? 
    598     return error; 
    599 } 
    600  
    601411char *GB_read_fp(FILE *in) { 
    602412    /*! like GB_read_file(), but works on already open file 
     
    685495} 
    686496 
    687 long GB_size_of_FILE(FILE *in) { 
    688     int         fi = fileno(in); 
    689     struct stat st; 
    690     if (fstat(fi, &st)) { 
    691         GB_export_error("GB_size_of_FILE: sorry file is not readable"); 
    692         return -1; 
    693     } 
    694     return st.st_size; 
    695 } 
    696  
    697  
    698497GB_ULONG GB_time_of_day() { 
    699498    timeval tp; 
     
    714513    char       *fpath   = GBS_eval_env(path); 
    715514    const char *command = GBS_global_string("arb_textprint '%s' &", fpath); 
    716     GB_ERROR    error   = GB_system(command); 
     515    GB_ERROR    error   = GBK_system(command); 
    717516    free(fpath); 
    718517    return GB_failedTo_error("print textfile", fpath, error); 
    719 } 
    720  
    721 #if defined(WARN_TODO) 
    722 #warning search for '\b(system)\b\s*\(' and use GB_system instead 
    723 #endif 
    724 GB_ERROR GB_system(const char *system_command) { 
    725     // goes to header: __ATTR__USERESULT 
    726     fprintf(stderr, "[Action: '%s']\n", system_command); 
    727     int      res   = system(system_command); 
    728     GB_ERROR error = NULL; 
    729     if (res) { 
    730         error = GBS_global_string("System call failed (result=%i)\n" 
    731                                   "System call was '%s'\n" 
    732                                   "(Note: console window may contain additional information)", res, system_command); 
    733     } 
    734     return error; 
    735518} 
    736519 
     
    739522    const char *xt      = GB_getenvARB_XTERM(); 
    740523    const char *command = GBS_global_string("%s &", xt); 
    741     return GB_system(command); 
     524    return GBK_system(command); 
    742525} 
    743526 
     
    776559    } 
    777560 
    778     GB_ERROR error = GB_system(GBS_mempntr(strstruct)); 
     561    GB_ERROR error = GBK_system(GBS_mempntr(strstruct)); 
    779562    GBS_strforget(strstruct); 
    780563 
     
    1001784GB_CSTR GB_getenvARBMACROHOME() { 
    1002785    static const char *amh = 0; 
    1003     if (!amh) amh = getenv_autodirectory("ARBMACROHOME", "$(HOME)/.arb_prop/macros");  // doc in ../HELP_SOURCE/oldhelp/arb_envar.hlp@ARBMACROHOME 
     786    if (!amh) amh = getenv_autodirectory("ARBMACROHOME", GB_path_in_arbprop("macros"));  // doc in ../HELP_SOURCE/oldhelp/arb_envar.hlp@ARBMACROHOME 
    1004787    return amh; 
    1005788} 
     
    1007790GB_CSTR GB_getenvARBCONFIG() { 
    1008791    static const char *ac = 0; 
    1009     if (!ac) ac = getenv_autodirectory("ARBCONFIG", "$(HOME)/.arb_prop/cfgSave"); // doc in ../HELP_SOURCE/oldhelp/arb_envar.hlp@ARBCONFIG 
     792    if (!ac) ac = getenv_autodirectory("ARBCONFIG", GB_path_in_arbprop("cfgSave")); // doc in ../HELP_SOURCE/oldhelp/arb_envar.hlp@ARBCONFIG 
    1010793    return ac; 
    1011794} 
     
    1194977    GB_ULONG usedmemsize = (MIN(net_memsize, max_malloc)*95)/100; // arb uses max. 95 % of available memory (was 70% in the past) 
    1195978 
    1196 #if defined(DEBUG) 
     979#if defined(DEBUG) && 0 
    1197980    printf("- memsize(real)        = %20lu k\n", memsize); 
    1198981    printf("- memsize(net)         = %20lu k\n", net_memsize); 
    1199982    printf("- memsize(max_malloc)  = %20lu k\n", max_malloc); 
     983    printf("- memsize(used by ARB) = %20lu k\n", usedmemsize); 
    1200984#endif // DEBUG 
    1201     printf("- memsize(used by ARB) = %20lu k\n", usedmemsize); 
    1202985 
    1203986    arb_assert(usedmemsize != 0); 
     
    1208991// --------------------------------------------- 
    1209992// path completion (parts former located in AWT) 
     993// @@@ whole section (+ corresponding tests) should move to adfile.cxx 
    1210994 
    1211995static int  path_toggle = 0; 
     
    13411125GB_CSTR GB_path_in_ARBLIB(const char *relative_path) { 
    13421126    return GB_path_in_ARBHOME("lib", relative_path); 
     1127} 
     1128GB_CSTR GB_path_in_arbprop(const char *relative_path) { 
     1129    return GB_unfold_path("HOME", GB_concat_path(".arb_prop", relative_path)); 
    13431130} 
    13441131GB_CSTR GB_path_in_ARBHOME(const char *relative_path_left, const char *anypath_right) { 
  • branches/dev_elmar/ARBDB/adstring.cxx

    r7945 r8224  
    118118    long len; 
    119119 
    120     if (!key || key[0] == 0) return GB_export_error("Empty key is not allowed"); 
     120    if (!key || key[0] == 0) return "Empty key is not allowed"; 
    121121    len = strlen(key); 
    122     if (len>GB_KEY_LEN_MAX) return GB_export_errorf("Invalid key '%s': too long", key); 
    123     if (len < GB_KEY_LEN_MIN) return GB_export_errorf("Invalid key '%s': too short", key); 
     122    if (len>GB_KEY_LEN_MAX) return GBS_global_string("Invalid key '%s': too long", key); 
     123    if (len < GB_KEY_LEN_MIN) return GBS_global_string("Invalid key '%s': too short", key); 
    124124 
    125125    for (i = 0; key[i]; ++i) { 
     
    129129        if ((c>='0') && (c<='9')) continue; 
    130130        if ((c=='_')) continue; 
    131         return GB_export_errorf("Invalid character '%c' in '%s'; allowed: a-z A-Z 0-9 '_' ", c, key); 
     131        return GBS_global_string("Invalid character '%c' in '%s'; allowed: a-z A-Z 0-9 '_' ", c, key); 
    132132    } 
    133133 
     
    563563    char    last      = *data++; 
    564564 
    565     do { 
     565    while (last) { 
    566566        char curr = *data++; 
    567567        if (curr == last) { 
     
    569569        } 
    570570        else { 
    571             if (repeat >= 10) { 
     571            if (repeat >= 5) { 
    572572                dest += sprintf(dest, "%c{%zu}", last, repeat); // insert repeat count 
    573573            } 
     
    580580        } 
    581581    } 
    582     while (last); 
    583582 
    584583    *dest = 0; 
     
    11591158} 
    11601159 
     1160#define TEST_SHORTENED_EQUALS(Long,Short) do {  \ 
     1161        char *buf = strdup(Long);               \ 
     1162        GBS_shorten_repeated_data(buf);         \ 
     1163        TEST_ASSERT_EQUAL(buf, Short);          \ 
     1164        free(buf);                              \ 
     1165    } while(0) 
     1166 
     1167void TEST_GBS_shorten_repeated_data() { 
     1168    TEST_SHORTENED_EQUALS("12345", "12345");  
     1169    TEST_SHORTENED_EQUALS("aaaaaaaaaaaabc", "a{12}bc");  
     1170    TEST_SHORTENED_EQUALS("aaaaaaaaaaabc", "a{11}bc");  
     1171    TEST_SHORTENED_EQUALS("aaaaaaaaaabc", "a{10}bc");  
     1172    TEST_SHORTENED_EQUALS("aaaaaaaaabc", "a{9}bc");  
     1173    TEST_SHORTENED_EQUALS("aaaaaaaabc", "a{8}bc");  
     1174    TEST_SHORTENED_EQUALS("aaaaaaabc", "a{7}bc");  
     1175    TEST_SHORTENED_EQUALS("aaaaaabc", "a{6}bc");  
     1176    TEST_SHORTENED_EQUALS("aaaaabc", "a{5}bc");  
     1177    TEST_SHORTENED_EQUALS("aaaabc", "aaaabc");  
     1178    TEST_SHORTENED_EQUALS("aaabc", "aaabc");  
     1179    TEST_SHORTENED_EQUALS("aabc", "aabc");  
     1180    TEST_SHORTENED_EQUALS("", ""); 
     1181     
     1182} 
    11611183#endif 
    11621184 
  • branches/dev_elmar/ARBDB/adsystem.cxx

    r7945 r8224  
    215215} 
    216216 
    217 GB_ERROR gb_load_key_data_and_dictionaries(GBDATA *gb_main) { 
    218     GB_MAIN_TYPE *Main = GB_MAIN(gb_main); 
     217GB_ERROR gb_load_key_data_and_dictionaries(GBDATA *gb_main) { // goes to header: __ATTR__USERESULT 
     218    GB_MAIN_TYPE *Main  = GB_MAIN(gb_main); 
     219    GB_ERROR      error = NULL; 
     220 
    219221    GBDATA *gb_key_data = gb_search(gb_main, GB_SYSTEM_FOLDER "/" GB_SYSTEM_KEY_DATA, GB_CREATE_CONTAINER, 1); 
    220     GBDATA *gb_key, *gb_next_key=0; 
    221     int key; 
    222  
    223     Main->gb_key_data = gb_key_data; 
    224     if (!Main->local_mode) return 0;    // do not create anything at the client side 
    225  
    226     GB_push_my_security(gb_main); 
    227  
    228     // First step: search unused keys and delete them 
    229     for (gb_key = GB_entry(gb_key_data, "@key"); 
    230          gb_key; 
    231          gb_key = gb_next_key) 
    232     { 
    233         GBDATA     *gb_name = GB_entry(gb_key, "@name"); 
    234         const char *name    = GB_read_char_pntr(gb_name); 
    235         GBQUARK     quark   = gb_key_2_quark(Main, name); 
    236  
    237         gb_next_key = GB_nextEntry(gb_key); 
    238  
    239         if (quark<=0 || quark >= Main->sizeofkeys || !Main->keys[quark].key) { 
    240             GB_delete(gb_key);  // delete unused key 
    241         } 
    242     } 
    243     GB_create_index(gb_key_data, "@name", GB_MIND_CASE, Main->sizeofkeys*2); 
    244  
    245     gb_key_2_quark(Main, "@name"); 
    246     gb_key_2_quark(Main, "@key"); 
    247     gb_key_2_quark(Main, "@dictionary"); 
    248     gb_key_2_quark(Main, "compression_mask"); 
    249  
    250     for (key=1; key<Main->sizeofkeys; key++) { 
    251         char *k = Main->keys[key].key; 
    252         if (!k) continue; 
    253         gb_load_single_key_data(gb_main, key); 
    254     } 
    255  
    256  
    257     GB_pop_my_security(gb_main); 
    258     return 0; 
     222    if (!gb_key_data) { 
     223        error = GB_await_error(); 
     224    } 
     225    else { 
     226        Main->gb_key_data = gb_key_data; 
     227        if (Main->local_mode) { // do not create anything at the client side 
     228            GB_push_my_security(gb_main); 
     229 
     230            // search unused keys and delete them 
     231            for (GBDATA *gb_key = GB_entry(gb_key_data, "@key"); gb_key && !error;) { 
     232                GBDATA *gb_next_key = GB_nextEntry(gb_key); 
     233                GBDATA *gb_name     = GB_entry(gb_key, "@name"); 
     234                if (!gb_name) error = GB_await_error(); 
     235                else { 
     236                    const char *name = GB_read_char_pntr(gb_name); 
     237                    if (!name) error = GB_await_error(); 
     238                    else { 
     239                        GBQUARK quark = gb_key_2_quark(Main, name); 
     240                        if (quark<=0 || quark >= Main->sizeofkeys || !Main->keys[quark].key) { 
     241                            error = GB_delete(gb_key);  // delete unused key 
     242                        } 
     243                    } 
     244                } 
     245                gb_key = gb_next_key; 
     246            } 
     247 
     248            if (!error) error = GB_create_index(gb_key_data, "@name", GB_MIND_CASE, Main->sizeofkeys*2); // create key index 
     249            if (!error) { 
     250                gb_key_2_quark(Main, "@name"); 
     251                gb_key_2_quark(Main, "@key"); 
     252                gb_key_2_quark(Main, "@dictionary"); 
     253                gb_key_2_quark(Main, "compression_mask"); 
     254 
     255                for (int key=1; key<Main->sizeofkeys; key++) { 
     256                    char *k = Main->keys[key].key; 
     257                    if (!k) continue; 
     258                    gb_load_single_key_data(gb_main, key); 
     259                } 
     260            } 
     261            GB_pop_my_security(gb_main); 
     262        } 
     263    } 
     264    RETURN_ERROR(error); 
    259265} 
    260266 
  • branches/dev_elmar/ARBDB/adtables.cxx

    r7945 r8224  
    9090 
    9191    gb_table_data = GB_search(gb_table_root, "table_data", GB_CREATE_CONTAINER); 
    92     GB_create_index(gb_table_data, "name", GB_IGNORE_CASE, 256); 
     92    ASSERT_NO_ERROR(GB_create_index(gb_table_data, "name", GB_IGNORE_CASE, 256)); 
    9393 
    9494    gb_table_name = GB_find_string(gb_table_data, "name", table_name, GB_IGNORE_CASE, SEARCH_GRANDCHILD); 
     
    123123    GBDATA *gb_table; 
    124124    gb_table_data = GB_search(gb_main, "table_data", GB_CREATE_CONTAINER); 
    125     GB_create_index(gb_table_data, "name", GB_IGNORE_CASE, 256); 
     125    ASSERT_NO_ERROR(GB_create_index(gb_table_data, "name", GB_IGNORE_CASE, 256)); 
    126126    gb_table = GB_entry(gb_table_data, "table"); 
    127127    return gb_table; 
  • branches/dev_elmar/ARBDB/adtcp.cxx

    r7945 r8224  
    220220} 
    221221 
     222char *GB_arbtcpdat_path() { 
     223    return GB_lib_file(true, "", "arb_tcp.dat"); 
     224} 
     225 
    222226GB_ERROR ArbTcpDat::update() { 
    223227    // read arb_tcp.dat (once or if changed on disk) 
    224228    GB_ERROR error = 0; 
    225229 
    226     if (!filename) filename = GBS_find_lib_file("arb_tcp.dat", "", true); 
     230    if (!filename) filename = GB_arbtcpdat_path(); 
    227231 
    228232    if (!filename) { 
    229         error = GBS_global_string("File $ARBHOME/lib/arb_tcp.dat not found"); 
     233        error = "File $ARBHOME/lib/arb_tcp.dat missing or unreadable"; 
    230234    } 
    231235    else { 
     
    300304// AISC_MKPT_PROMOTE:#ifdef UNIT_TESTS 
    301305// AISC_MKPT_PROMOTE:#define TEST_SERVER_ID (-666) 
     306// AISC_MKPT_PROMOTE:#define TEST_GENESERVER_ID (-667) 
    302307// AISC_MKPT_PROMOTE:#endif 
    303308 
     
    313318const char *GBS_ptserver_tag(int id) { 
    314319#ifdef UNIT_TESTS 
    315     if (id == TEST_SERVER_ID) { 
    316         return "ARB_TEST_PT_SERVER"; 
    317     } 
     320    if (id == TEST_SERVER_ID) return "ARB_TEST_PT_SERVER"; 
     321    if (id == TEST_GENESERVER_ID) return "ARB_TEST_PT_SERVER_GENE"; 
    318322#endif // UNIT_TESTS 
    319323    gb_assert(id >= 0); 
  • branches/dev_elmar/ARBDB/adtools.cxx

    r7945 r8224  
    1717#include <arb_str.h> 
    1818#include <arb_strarray.h> 
     19 
     20#include <algorithm> 
     21 
     22using namespace std; 
    1923 
    2024GBDATA *GBT_find_or_create(GBDATA *Main, const char *key, long delete_level) 
     
    418422     */ 
    419423 
     424    gb_assert(default_value == default_value); // !nan 
     425     
    420426    GBDATA *gb_float; 
    421427    double *result = NULL; 
     
    428434        result     = &result_var; 
    429435    } 
     436    else { 
     437        gb_assert(0); 
     438    } 
    430439    GB_pop_transaction(gb_container); 
    431440    return result; 
     
    492501     * but for fields of type GB_FLOAT 
    493502     */ 
     503 
     504    gb_assert(content == content); // !nan 
     505 
    494506    GB_ERROR  error = GB_push_transaction(gb_container); 
    495507    GBDATA   *gbd   = GB_search(gb_container, fieldpath, GB_FLOAT); 
     
    513525//      save & load 
    514526 
    515 GBDATA *GBT_open(const char *path, const char *opent, const char *disabled_path) { 
    516     /*! Open a database and create an index for species and extended names. 
     527GBDATA *GBT_open(const char *path, const char *opent) { 
     528    /*! Open a database, 
     529     *  create an index for species and extended names (server only!) and 
     530     *  disable saving in the PT_SERVER directory. 
    517531     * 
    518532     * @param path filename of the DB 
    519533     * @param opent see GB_login() 
    520      * @param disabled_path disable saving in this path. 
    521      * if disabled_path is NULL, disable saving in the PT_SERVER directory. 
     534     * @return database handle (or NULL in which case an error is exported) 
    522535     * @see GB_open() 
    523536     */ 
    524537 
    525538    GBDATA *gbd = GB_open(path, opent); 
    526     GBDATA *species_data; 
    527     GBDATA *extended_data; 
    528     GBDATA *gb_tmp; 
    529     long    hash_size; 
    530  
    531     if (!gbd) return gbd; 
    532     if (!disabled_path) disabled_path = "$(ARBHOME)/lib/pts/*"; 
    533     GB_disable_path(gbd, disabled_path); 
    534     GB_begin_transaction(gbd); 
    535  
    536     if (!strchr(path, ':')) { 
    537         species_data = GB_search(gbd, "species_data", GB_FIND); 
    538         if (species_data) { 
    539             hash_size = GB_number_of_subentries(species_data); 
    540             if (hash_size < GBT_SPECIES_INDEX_SIZE) hash_size = GBT_SPECIES_INDEX_SIZE; 
    541             GB_create_index(species_data, "name", GB_IGNORE_CASE, hash_size); 
    542  
    543             extended_data = GBT_get_SAI_data(gbd); 
    544             hash_size = GB_number_of_subentries(extended_data); 
    545             if (hash_size < GBT_SAI_INDEX_SIZE) hash_size = GBT_SAI_INDEX_SIZE; 
    546             GB_create_index(extended_data, "name", GB_IGNORE_CASE, hash_size); 
    547         } 
    548     } 
    549     gb_tmp = GB_search(gbd, "tmp", GB_CREATE_CONTAINER); 
    550     GB_set_temporary(gb_tmp); 
    551     { 
    552         GB_MAIN_TYPE *Main = GB_MAIN(gbd); 
    553         Main->table_hash = GBS_create_hash(256, GB_MIND_CASE); 
    554         GB_install_link_follower(gbd, "REF", GB_test_link_follower); 
    555     } 
    556     GBT_install_table_link_follower(gbd); 
    557     GB_commit_transaction(gbd); 
     539    if (gbd) { 
     540        GB_disable_path(gbd, GB_path_in_ARBLIB("pts/*")); 
     541        GB_ERROR error = NULL; 
     542        { 
     543            GB_transaction ta(gbd); 
     544 
     545            if (!strchr(path, ':')) { 
     546                GBDATA *species_data = GB_search(gbd, "species_data", GB_FIND); 
     547                if (species_data) { 
     548                    long hash_size = max(GB_number_of_subentries(species_data), GBT_SPECIES_INDEX_SIZE); 
     549                    error          = GB_create_index(species_data, "name", GB_IGNORE_CASE, hash_size); 
     550 
     551                    if (!error) { 
     552                        GBDATA *extended_data = GBT_get_SAI_data(gbd); 
     553                        hash_size             = max(GB_number_of_subentries(extended_data), GBT_SAI_INDEX_SIZE); 
     554                        error                 = GB_create_index(extended_data, "name", GB_IGNORE_CASE, hash_size); 
     555                    } 
     556                } 
     557            } 
     558            if (!error) { 
     559                GBDATA *gb_tmp = GB_search(gbd, "tmp", GB_CREATE_CONTAINER); 
     560                if (gb_tmp) error = GB_set_temporary(gb_tmp); 
     561            } 
     562 
     563            if (!error) { 
     564                { 
     565                    GB_MAIN_TYPE *Main = GB_MAIN(gbd); 
     566                    Main->table_hash = GBS_create_hash(256, GB_MIND_CASE); 
     567                    GB_install_link_follower(gbd, "REF", GB_test_link_follower); 
     568                } 
     569                GBT_install_table_link_follower(gbd); 
     570            } 
     571        } 
     572        if (error) { 
     573            GB_close(gbd); 
     574            gbd = NULL; 
     575            GB_export_error(error); 
     576        } 
     577    } 
     578    gb_assert(contradicted(gbd, GB_have_error())); 
    558579    return gbd; 
    559580} 
     
    727748 
    728749static void notify_cb(GBDATA *gb_message, int *cb_info, GB_CB_TYPE cb_type) { 
    729     GB_remove_callback(gb_message, GB_CB_TYPE(GB_CB_CHANGED|GB_CB_DELETE), notify_cb, cb_info); // @@@ cbproblematic 
     750    if (cb_type != GB_CB_DELETE) { 
     751        GB_remove_callback(gb_message, GB_CB_TYPE(GB_CB_CHANGED|GB_CB_DELETE), notify_cb, cb_info); 
     752    } 
    730753 
    731754    int       cb_done = 0; 
  • branches/dev_elmar/ARBDB/arbdb.cxx

    r7945 r8224  
    426426void GB_shell::ensure_inside()  { if (!inside_shell) GBK_terminate("Not inside GB_shell"); } 
    427427 
     428bool GB_shell::in_shell() { 
     429    if (!inside_shell) { 
     430        return false; 
     431    } 
     432    return true; 
     433} 
     434 
    428435struct GB_test_shell_closed { 
    429436    ~GB_test_shell_closed() { 
     
    676683double GB_read_float(GBDATA *gbd) 
    677684{ 
    678     XDR xdrs; 
     685    XDR          xdrs; 
    679686    static float f; 
     687     
    680688    GB_TEST_READ(gbd, GB_FLOAT, "GB_read_float"); 
    681689    xdrmem_create(&xdrs, &gbd->info.in.data[0], SIZOFINTERN, XDR_DECODE); 
    682690    xdr_float(&xdrs, &f); 
    683691    xdr_destroy(&xdrs); 
     692 
     693    gb_assert(f == f); // !nan 
     694 
    684695    return (double)f; 
    685696} 
     
    10281039GB_ERROR GB_write_float(GBDATA *gbd, double f) 
    10291040{ 
    1030     XDR xdrs; 
     1041    gb_assert(f == f); // !nan 
     1042 
     1043    XDR          xdrs; 
    10311044    static float f2; 
    10321045 
     
    19211934//      temporary entries 
    19221935 
    1923 GB_ERROR GB_set_temporary(GBDATA *gbd) { 
     1936GB_ERROR GB_set_temporary(GBDATA *gbd) { // goes to header: __ATTR__USERESULT 
    19241937    /*! if the temporary flag is set, then that entry (including all subentries) will not be saved 
    19251938     * @see GB_clear_temporary() and GB_is_temporary() 
    19261939     */ 
    19271940 
     1941    GB_ERROR error = NULL; 
    19281942    GB_test_transaction(gbd); 
    1929     if (GB_GET_SECURITY_DELETE(gbd)>GB_MAIN(gbd)->security_level) 
    1930         return GB_export_errorf("Security error in GB_set_temporary: %s", GB_read_key_pntr(gbd)); 
    1931     gbd->flags.temporary = 1; 
    1932     gb_touch_entry(gbd, GB_NORMAL_CHANGE); 
    1933     return 0; 
     1943 
     1944    if (GB_GET_SECURITY_DELETE(gbd)>GB_MAIN(gbd)->security_level) { 
     1945        error = GBS_global_string("Security error in GB_set_temporary: %s", GB_read_key_pntr(gbd)); 
     1946    } 
     1947    else { 
     1948        gbd->flags.temporary = 1; 
     1949        gb_touch_entry(gbd, GB_NORMAL_CHANGE); 
     1950    } 
     1951    RETURN_ERROR(error); 
    19341952} 
    19351953 
  • branches/dev_elmar/ARBDB/arbdb.h

    r7945 r8224  
    137137 
    138138    static void ensure_inside(); 
     139    static bool in_shell(); 
    139140}; 
    140141 
  • branches/dev_elmar/ARBDB/arbdbt.h

    r6490 r8224  
    66#endif 
    77 
    8 #define GBT_SPECIES_INDEX_SIZE       10000 
    9 #define GBT_SAI_INDEX_SIZE           1000 
     8#define GBT_SPECIES_INDEX_SIZE       10000L 
     9#define GBT_SAI_INDEX_SIZE           1000L 
    1010 
    1111#define GB_GROUP_NAME_MAX 256 
  • branches/dev_elmar/ARBDB/gb_memory.h

    r7201 r8224  
    2727#if defined(UNIT_TESTS) 
    2828#undef MEMORY_TEST 
    29 #define MEMORY_TEST 0 // test mmapped-DB version in unittests 
     29#define MEMORY_TEST 0 // test mmapped-DB version in unittests (recommended setting) 
    3030// #define MEMORY_TEST 1 // test DEBUG DB version in unittests 
    3131#endif 
  • branches/dev_elmar/ARBDB/gb_prot.h

    r7945 r8224  
    113113void gb_load_single_key_data(GBDATA *gb_main, GBQUARK q); 
    114114GB_ERROR gb_save_dictionary_data(GBDATA *gb_main, const char *key, const char *dict, int size); 
    115 GB_ERROR gb_load_key_data_and_dictionaries(GBDATA *gb_main); 
     115GB_ERROR gb_load_key_data_and_dictionaries(GBDATA *gb_main) __ATTR__USERESULT; 
    116116 
    117117/* arbdb.cxx */ 
  • branches/dev_elmar/AWT/AWT_canio.cxx

    r7945 r8224  
    1919#include <arb_defs.h> 
    2020#include <arb_strbuf.h> 
     21#include <arb_file.h> 
    2122 
    2223using namespace AW; 
     
    542543// -------------------------------------------------------------------------------- 
    543544 
    544 static GB_ERROR canvas_to_xfig(AWT_canvas *ntw, const char *xfig_name, bool add_invisibles) { 
    545     // if 'add_invisibles' is true => print 2 invisible dots to make fig2dev center correctly  
    546  
    547     GB_transaction ta(ntw->gb_main); 
    548  
    549     AW_root *awr       = ntw->awr; 
    550     bool     draw_all  = awr->awar(AWAR_CANIO_CLIP)->read_int(); 
    551     bool     handles   = awr->awar(AWAR_CANIO_HANDLES)->read_int(); 
    552     bool     use_color = awr->awar(AWAR_CANIO_COLOR)->read_int(); 
    553     double   border    = awr->awar(AWAR_CANIO_BORDERSIZE)->read_float(); 
     545static GB_ERROR canvas_to_xfig(AWT_canvas *ntw, const char *xfig_name, bool add_invisibles, double border) { 
     546    // if 'add_invisibles' is true => print 2 invisible dots to make fig2dev center correctly 
     547 
     548    GB_transaction  ta(ntw->gb_main); 
     549    AW_root        *awr = ntw->awr; 
     550 
     551    bool draw_all  = awr->awar(AWAR_CANIO_CLIP)->read_int(); 
     552    bool handles   = awr->awar(AWAR_CANIO_HANDLES)->read_int(); 
     553    bool use_color = awr->awar(AWAR_CANIO_COLOR)->read_int(); 
    554554 
    555555    AW_device_print *device = ntw->aww->get_print_device(AW_MIDDLE_AREA); 
     
    632632    } 
    633633    else { 
    634         error = canvas_to_xfig(ntw, xfig, true); 
     634        error = canvas_to_xfig(ntw, xfig, true, 0.0); 
    635635        if (!error) { 
    636636            awr->awar(AWAR_CANIO_FILE_DIR)->touch(); // reload dir to show created xfig 
    637             error = GB_system(GBS_global_string("xfig %s &", xfig)); 
     637            error = GBK_system(GBS_global_string("xfig %s &", xfig)); 
    638638        } 
    639639    } 
     
    680680 
    681681        if (!xfig) error = GB_await_error(); 
    682         if (!error) error = canvas_to_xfig(ntw, xfig, true); 
     682        if (!error) { 
     683            double border = awr->awar(AWAR_CANIO_BORDERSIZE)->read_float(); 
     684            error         = canvas_to_xfig(ntw, xfig, true, border); 
     685        } 
    683686 
    684687        if (!error) { 
     
    711714                cmd.put(' '); cmd.cat(dest); // output 
    712715 
    713                 error = GB_system(cmd.get_data()); 
     716                error = GBK_system(cmd.get_data()); 
    714717            } 
    715718 
     
    724727                        GB_CSTR gs      = GB_getenvARB_GS(); 
    725728                        GB_CSTR command = GBS_global_string("(%s %s;rm -f %s) &", gs, dest, dest); 
    726                         error           = GB_system(command); 
     729                        error           = GBK_system(command); 
    727730                        break; 
    728731                    } 
     
    732735                    case PDEST_PRINTER: { 
    733736                        char *prt = awr->awar(AWAR_CANIO_PRINTER)->read_string(); 
    734                         error     = GB_system(GBS_global_string("%s %s", prt, dest)); 
     737                        error     = GBK_system(GBS_global_string("%s %s", prt, dest)); 
    735738                        free(prt); 
    736739                        GB_unlink_or_warn(dest, &error); 
     
    743746#if defined(DEBUG) && 0 
    744747            // show intermediate xfig and unlink it 
    745             GB_system(GBS_global_string("( xfig %s; rm %s) &", xfig, xfig)); 
     748            GBK_system(GBS_global_string("( xfig %s; rm %s) &", xfig, xfig)); 
    746749#else // !defined(DEBUG) 
    747750            GB_unlink_or_warn(xfig, &error); 
     
    798801        aws->create_toggle(AWAR_CANIO_COLOR); 
    799802 
    800  
    801803        aws->at("xfig"); aws->callback(canvas_to_xfig_and_run_xfig, cl_canvas); 
    802         aws->create_button("START_XFIG", "EXPORT to XFIG", "X"); 
    803  
    804         aws->at("cancel"); aws->callback((AW_CB0)AW_POPDOWN); 
    805         aws->create_button("CLOSE", "CANCEL", "C"); 
     804        aws->create_autosize_button("START_XFIG", "EXPORT to XFIG", "X"); 
    806805    } 
    807806 
     
    820819        aws->init(awr, "EXPORT_TREE_AS_XFIG", "EXPORT STRUCTURE TO XFIG"); 
    821820        aws->load_xfig("awt/secExport.fig"); 
     821 
     822        aws->at("close"); aws->callback((AW_CB0)AW_POPDOWN); 
     823        aws->create_button("CLOSE", "CLOSE", "C"); 
    822824 
    823825        aws->at("help"); aws->callback(AW_POPUP_HELP, (AW_CL)"tree2file.hlp"); 
     
    839841 
    840842        aws->at("xfig"); aws->callback(canvas_to_xfig_and_run_xfig, cl_canvas); 
    841         aws->create_button("START_XFIG", "EXPORT to XFIG", "X"); 
    842  
    843         aws->at("close"); aws->callback((AW_CB0)AW_POPDOWN); 
    844         aws->create_button("CLOSE", "CLOSE", "C"); 
    845  
    846         aws->at("cancel"); aws->callback((AW_CB0)AW_POPDOWN); 
    847         aws->create_button("CLOSE", "CANCEL", "C"); 
     843        aws->create_autosize_button("START_XFIG", "EXPORT to XFIG", "X"); 
    848844    } 
    849845 
  • branches/dev_elmar/AWT/AWT_db_browser.cxx

    r7945 r8224  
    1313 
    1414#include "awt.hxx" 
    15  
     15#include "awt_hexdump.hxx" 
     16 
     17#include <aw_window.hxx> 
     18#include <aw_msg.hxx> 
     19#include <aw_awar.hxx> 
     20 
     21#include <arb_msg.h> 
    1622#include <arb_str.h> 
    17 #include <AP_Tree.hxx> 
    18 #include <aw_window.hxx> 
    19 #include <aw_awar.hxx> 
    20 #include <aw_msg.hxx> 
    21 #include <aw_root.hxx> 
     23 
     24#include <arbdb.h> 
    2225 
    2326#include <string> 
     
    4447#define AWAR_DBB_INFO   AWAR_DBB_TMP_BASE "/info" 
    4548 
     49#define AWAR_DUMP_HEX   AWAR_DBB_BASE "/hex" 
     50#define AWAR_DUMP_ASCII AWAR_DBB_BASE "/ascii" 
     51#define AWAR_DUMP_SPACE AWAR_DBB_BASE "/space" 
     52#define AWAR_DUMP_WIDTH AWAR_DBB_BASE "/width" 
     53#define AWAR_DUMP_BLOCK AWAR_DBB_BASE "/block" 
     54 
    4655#define HISTORY_PSEUDO_PATH "*history*" 
    4756#define ENTRY_MAX_LENGTH    1000 
     
    5160    SORT_NONE, 
    5261    SORT_NAME, 
    53     SORT_NAME_DB, 
     62    SORT_CONTAINER, 
     63    SORT_OCCUR, 
    5464    SORT_TYPE, 
    5565    SORT_CONTENT, 
     
    5969 
    6070const char *sort_order_name[SORT_COUNT] = { 
    61     "None", 
     71    "Unsorted", 
    6272    "Name", 
    63     "Name (DB)", 
     73    "Name (Container)", 
     74    "Name (Occur)", 
    6475    "Type", 
    6576    "Content", 
    6677}; 
    67  
    68  
    6978 
    7079// used to sort entries in list 
     
    8493    } 
    8594 
    86     inline int cmp_by_container(const list_entry& other) const { 
    87         return int(type != GB_DB) - int(other.type != GB_DB); 
    88     } 
    89  
    90     inline bool less_than_by_name_container(const list_entry& other) const { 
     95    inline int cmp_by_container(const list_entry& other) const { return int(type != GB_DB) - int(other.type != GB_DB); } 
     96    inline int cmp_by_childcount(const list_entry& other) const { return childCount - other.childCount; } 
     97 
     98    inline bool less_than_by_container_name(const list_entry& other) const { 
    9199        int cmp = cmp_by_container(other); 
    92100        if (cmp == 0) return less_than_by_name(other); 
    93101        return cmp<0; 
    94102    } 
     103    inline bool less_than_by_childcount_name(const list_entry& other) const { 
     104        int cmp = cmp_by_childcount(other); 
     105        if (cmp == 0) return less_than_by_name(other); 
     106        return cmp<0; 
     107    } 
    95108 
    96109    bool operator<(const list_entry& other) const { 
    97110        bool is_less = false; 
    98111        switch (sort_order) { 
     112            case SORT_COUNT: break; 
    99113            case SORT_NONE: 
    100114                awt_assert(0);  // not possible 
     
    105119                break; 
    106120 
    107             case SORT_NAME_DB: 
    108                 is_less = less_than_by_name_container(other); 
     121            case SORT_CONTAINER: 
     122                is_less = less_than_by_container_name(other); 
     123                break; 
     124 
     125            case SORT_OCCUR: 
     126                is_less = less_than_by_childcount_name(other); 
    109127                break; 
    110128 
     
    113131 
    114132                if (cmp != 0) is_less = cmp<0; 
    115                 else is_less          = less_than_by_name_container(other); 
     133                else is_less          = less_than_by_container_name(other); 
    116134 
    117135                break; 
     
    125143                break; 
    126144            } 
    127             default: 
    128                 awt_assert(0);  // illegal 'sort_order' 
    129                 break; 
    130145        } 
    131146        return is_less; 
     
    139154// --------------------- 
    140155 
     156MemDump make_userdefined_MemDump(AW_root *awr) { 
     157    bool   hex      = awr->awar(AWAR_DUMP_HEX)->read_int(); 
     158    bool   ascii    = awr->awar(AWAR_DUMP_ASCII)->read_int(); 
     159    bool   space    = awr->awar(AWAR_DUMP_SPACE)->read_int(); 
     160    size_t width    = awr->awar(AWAR_DUMP_WIDTH)->read_int(); 
     161    size_t separate = awr->awar(AWAR_DUMP_BLOCK)->read_int(); 
     162     
     163    bool offset = (hex||ascii) && width; 
     164 
     165    return MemDump(offset, hex, ascii, width, separate, space); 
     166} 
     167 
     168static void hexmode_changed_cb(AW_root *aw_root) { 
     169    aw_root->awar(AWAR_DBB_BROWSE)->touch(); 
     170} 
     171 
    141172void AWT_create_db_browser_awars(AW_root *aw_root, AW_default aw_def) { 
    142     aw_root->awar_int(AWAR_DBB_DB, 0, aw_def); // index to internal order of announced databases 
    143     aw_root->awar_int(AWAR_DBB_ORDER, SORT_NAME_DB, aw_def); // sort order for "browse"-box 
    144     aw_root->awar_string(AWAR_DBB_PATH, "/", aw_def); // path in database 
    145     aw_root->awar_string(AWAR_DBB_BROWSE, "", aw_def); // selection in browser (= child name) 
    146     aw_root->awar_string(AWAR_DBB_INFO, "<select an element>", aw_def); // information about selected item 
    147     aw_root->awar_string(AWAR_DBB_HISTORY, "", aw_def); // '\n'-separated string containing visited nodes 
     173    aw_root->awar_int   (AWAR_DBB_DB,      0,                     aw_def); // index to internal order of announced databases 
     174    aw_root->awar_int   (AWAR_DBB_ORDER,   SORT_CONTAINER,        aw_def); // sort order for "browse"-box 
     175    aw_root->awar_string(AWAR_DBB_PATH,    "/",                   aw_def); // path in database 
     176    aw_root->awar_string(AWAR_DBB_BROWSE,  "",                    aw_def); // selection in browser (= child name) 
     177    aw_root->awar_string(AWAR_DBB_INFO,    "<select an element>", aw_def); // information about selected item 
     178    aw_root->awar_string(AWAR_DBB_HISTORY, "",                    aw_def); // '\n'-separated string containing visited nodes 
     179 
     180    // hex-dump-options 
     181    aw_root->awar_int(AWAR_DUMP_HEX,   1,  aw_def)->add_callback(hexmode_changed_cb); // show hex ? 
     182    aw_root->awar_int(AWAR_DUMP_ASCII, 1,  aw_def)->add_callback(hexmode_changed_cb); // show ascii ? 
     183    aw_root->awar_int(AWAR_DUMP_SPACE, 1,  aw_def)->add_callback(hexmode_changed_cb); // space bytes 
     184    aw_root->awar_int(AWAR_DUMP_WIDTH, 16, aw_def)->add_callback(hexmode_changed_cb); // bytes/line 
     185    aw_root->awar_int(AWAR_DUMP_BLOCK, 8,  aw_def)->add_callback(hexmode_changed_cb); // separate each bytes 
    148186} 
    149187 
     
    470508} 
    471509 
    472 static void path_changed_cb(AW_root *aw_root); // prototype 
    473  
     510static void child_changed_cb(AW_root *aw_root); // prototype 
    474511static void browsed_node_changed_cb(GBDATA *, int *cl_aw_root, GB_CB_TYPE) { 
    475     path_changed_cb((AW_root*)cl_aw_root); 
     512    child_changed_cb((AW_root*)cl_aw_root); 
    476513} 
    477514 
     
    496533        aww->insert_selection(sel, colon+1, colon+1); 
    497534    } 
     535} 
     536 
     537 
     538static char *get_container_description(GBDATA *gbd) { 
     539    char *content = NULL; 
     540    const char *known_children[] = { "@name", "name", "key_name", "alignment_name", "group_name", "key_text", 0 }; 
     541    for (int i = 0; known_children[i]; ++i) { 
     542        GBDATA *gb_known = GB_entry(gbd, known_children[i]); 
     543        if (gb_known && GB_read_type(gb_known) != GB_DB && GB_nextEntry(gb_known) == 0) { // exactly one child exits 
     544            char *asStr = GB_read_as_string(gb_known); 
     545            content     = GBS_global_string_copy("[%s=%s]", known_children[i], asStr); 
     546            free(asStr); 
     547            break; 
     548        } 
     549    } 
     550 
     551    return content; 
     552} 
     553 
     554static char *get_dbentry_content(GBDATA *gbd, GB_TYPES type, bool shorten_repeats, const MemDump& dump) { 
     555    awt_assert(type != GB_DB); 
     556     
     557    char *content = NULL; 
     558    if (!dump.wrapped()) content = GB_read_as_string(gbd); 
     559    if (!content) { // use dumper 
     560        long      size = GB_read_count(gbd); 
     561        const int plen = 30; 
     562 
     563        GBS_strstruct buf(dump.mem_needed_for_dump(size)+plen); 
     564 
     565        if (!dump.wrapped()) buf.nprintf(plen, "<%li bytes>: ", size); 
     566        dump.dump_to(buf, GB_read_pntr(gbd), size); 
     567 
     568        content         = buf.release(); 
     569        shorten_repeats = false; 
     570    } 
     571    size_t len = shorten_repeats ? GBS_shorten_repeated_data(content) : strlen(content); 
     572    if (!dump.wrapped() && len>(ENTRY_MAX_LENGTH+15)) { 
     573        content[ENTRY_MAX_LENGTH] = 0; 
     574        freeset(content, GBS_global_string_copy("%s [rest skipped]", content)); 
     575    } 
     576    return content; 
    498577} 
    499578 
     
    569648        } 
    570649 
    571         if (!is_root) aww->insert_selection(id, GBS_global_string("%-*s   parent container", maxkeylen, ".."), BROWSE_CMD_GO_UP); 
    572  
     650        if (!is_root) { 
     651            aww->insert_selection(id, GBS_global_string("%-*s   parent container", maxkeylen, ".."), BROWSE_CMD_GO_UP); 
     652            aww->insert_selection(id, GBS_global_string("%-*s   container", maxkeylen, "."), ""); 
     653        } 
     654        else { 
     655            aww->insert_selection(id, GBS_global_string("%-*s   root container", maxkeylen, "/"), ""); 
     656        } 
     657         
    573658        // collect children and sort them 
    574659 
    575660        vector<list_entry> sorted_children; 
    576661 
     662        MemDump simpleDump(false, true, false); 
    577663        for (GBDATA *child = GB_child(node); child; child = GB_nextChild(child)) { 
    578664            list_entry entry; 
     
    587673                child_count[entry.key_name].count++; 
    588674            } 
    589  
    590             char *content = 0; 
     675            char *display = NULL; 
    591676            if (entry.type == GB_DB) { 
    592                 // the children listed here are displayed behind the container entry 
    593                 const char *known_children[] = { "@name", "name", "key_name", "alignment_name", "group_name", "key_text", 0 }; 
    594                 for (int i = 0; known_children[i]; ++i) { 
    595                     GBDATA *gb_known = GB_entry(entry.gbd, known_children[i]); 
    596  
    597                     if (gb_known && GB_read_type(gb_known) != GB_DB && GB_nextEntry(gb_known) == 0) { // exactly one child exits 
    598                         content = GBS_global_string_copy("[%s=%s]", known_children[i], GB_read_as_string(gb_known)); 
    599                         break; 
    600                     } 
    601                 } 
    602  
    603                 if (!content) content = strdup(""); 
     677                display = get_container_description(entry.gbd); 
    604678            } 
    605679            else { 
    606                 content = GB_read_as_string(entry.gbd); 
    607                 if (!content) { 
    608                     long size = GB_read_count(entry.gbd); 
    609                     content = GBS_global_string_copy("<%li bytes binary data>", size); 
    610                 } 
    611             } 
    612  
    613             if (strlen(content)>(ENTRY_MAX_LENGTH+15)) { 
    614                 content[ENTRY_MAX_LENGTH] = 0; 
    615                 freeset(content, GBS_global_string_copy("%s [rest skipped]", content)); 
    616             } 
    617  
    618             entry.content = content; 
    619             free(content); 
    620  
     680                display = get_dbentry_content(entry.gbd, entry.type, true, simpleDump); 
     681            } 
     682            if (display) entry.content = display; 
    621683            sorted_children.push_back(entry); 
    622684        } 
     
    652714    DB_browser *browser = get_the_browser(); 
    653715    update_browser_selection_list(aw_root, (AW_CL)browser->get_window(aw_root), (AW_CL)browser->get_browser_id()); 
    654 } 
    655  
    656 static void child_changed_cb(AW_root *aw_root) { 
    657     static bool avoid_recursion = false; 
    658  
    659     if (!avoid_recursion) { 
    660         avoid_recursion = true; 
    661  
    662         char *child = aw_root->awar(AWAR_DBB_BROWSE)->read_string(); 
    663         if (strncmp(child, BROWSE_CMD_PREFIX, sizeof(BROWSE_CMD_PREFIX)-1) == 0) { 
    664             // a symbolic browser command 
    665             execute_browser_command(get_the_browser()->get_window(aw_root), child); 
    666         } 
    667         else { 
    668             char *path = aw_root->awar(AWAR_DBB_PATH)->read_string(); 
    669  
    670             char *fullpath; 
    671             if (strcmp(path, "/") == 0) { 
    672                 fullpath = GBS_global_string_copy("/%s", child); 
    673             } 
    674             else if (strcmp(path, HISTORY_PSEUDO_PATH) == 0) { 
    675                 fullpath = strdup(child); 
    676             } 
    677             else if (child[0] == 0) { 
    678                 fullpath = strdup(path); 
    679             } 
    680             else { 
    681                 fullpath = GBS_global_string_copy("%s/%s", path, child); 
    682             } 
    683  
    684             DB_browser     *browser          = get_the_browser(); 
    685             GBDATA         *gb_main          = browser->get_db(); 
    686             GB_transaction  dummy(gb_main); 
    687             GBDATA         *gb_selected_node = GB_search_numbered(gb_main, fullpath, GB_FIND); 
    688  
    689             string info; 
    690             info += GBS_global_string("fullpath='%s'\n", fullpath); 
    691  
    692             if (gb_selected_node == 0) { 
    693                 info += "Node does not exist.\n"; 
    694             } 
    695             else { 
    696                 info += GBS_global_string("Node exists [address=%p]\n", gb_selected_node); 
    697                 info += GBS_global_string("key index=%i\n", GB_get_quark(gb_selected_node)); 
    698  
    699                 if (GB_read_type(gb_selected_node) == GB_DB) { 
    700                     info += "Node type: container\n"; 
    701  
    702                     aw_root->awar(AWAR_DBB_BROWSE)->write_string(""); 
    703                     aw_root->awar(AWAR_DBB_PATH)->write_string(fullpath); 
    704                 } 
    705                 else { 
    706                     info += GBS_global_string("Node type: data [type=%s]\n", GB_get_type_name(gb_selected_node)); 
    707                 } 
    708  
    709                 info += GBS_global_string("Security: read=%i write=%i delete=%i\n", 
    710                                           GB_read_security_read(gb_selected_node), 
    711                                           GB_read_security_write(gb_selected_node), 
    712                                           GB_read_security_delete(gb_selected_node)); 
    713  
    714                 char *callback_info = GB_get_callback_info(gb_selected_node); 
    715                 if (callback_info) { 
    716                     info = info+"Callbacks:\n"+callback_info+'\n'; 
    717                 } 
    718             } 
    719  
    720             aw_root->awar(AWAR_DBB_INFO)->write_string(info.c_str()); 
    721  
    722             free(fullpath); 
    723             free(path); 
    724         } 
    725         free(child); 
    726  
    727         avoid_recursion = false; 
    728     } 
    729716} 
    730717 
     
    789776} 
    790777 
     778static void child_changed_cb(AW_root *aw_root) { 
     779    char *child = aw_root->awar(AWAR_DBB_BROWSE)->read_string(); 
     780    if (strncmp(child, BROWSE_CMD_PREFIX, sizeof(BROWSE_CMD_PREFIX)-1) == 0) { // a symbolic browser command 
     781        execute_browser_command(get_the_browser()->get_window(aw_root), child); 
     782    } 
     783    else { 
     784        char *path = aw_root->awar(AWAR_DBB_PATH)->read_string(); 
     785 
     786        if (strcmp(path, HISTORY_PSEUDO_PATH) == 0) { 
     787            if (child[0]) aw_root->awar(AWAR_DBB_PATH)->write_string(child); 
     788        } 
     789        else { 
     790            static bool avoid_recursion = false; 
     791            if (!avoid_recursion) { 
     792                avoid_recursion = true; 
     793 
     794                char *fullpath; 
     795                if (strcmp(path, "/") == 0) { 
     796                    fullpath = GBS_global_string_copy("/%s", child); 
     797                } 
     798                else if (child[0] == 0) { 
     799                    fullpath = strdup(path); 
     800                } 
     801                else { 
     802                    fullpath = GBS_global_string_copy("%s/%s", path, child); 
     803                } 
     804 
     805                DB_browser     *browser          = get_the_browser(); 
     806                GBDATA         *gb_main          = browser->get_db(); 
     807                GB_transaction  dummy(gb_main); 
     808                GBDATA         *gb_selected_node = GB_search_numbered(gb_main, fullpath, GB_FIND); 
     809 
     810                string info; 
     811                info += GBS_global_string("fullpath='%s'\n", fullpath); 
     812 
     813                if (gb_selected_node == 0) { 
     814                    info += "Node does not exist.\n"; 
     815                } 
     816                else { 
     817                    add_to_history(aw_root, fullpath); 
     818                 
     819                    info += GBS_global_string("Node exists [address=%p]\n", gb_selected_node); 
     820                    info += GBS_global_string("Key index | %i\n", GB_get_quark(gb_selected_node)); 
     821 
     822                    GB_TYPES type = GB_read_type(gb_selected_node); 
     823                    if (type == GB_DB) { 
     824                        info += "Node type | container\n"; 
     825                        info += GBS_global_string("Entries   | %li\n", GB_number_of_subentries(gb_selected_node)); 
     826 
     827                        aw_root->awar(AWAR_DBB_BROWSE)->write_string(""); 
     828                        aw_root->awar(AWAR_DBB_PATH)->write_string(fullpath); 
     829                    } 
     830                    else { 
     831                        info += GBS_global_string("Node type | data [type=%s]\n", GB_get_type_name(gb_selected_node)); 
     832                        info += GBS_global_string("Data size | %li\n", GB_read_count(gb_selected_node)); 
     833                        info += GBS_global_string("Memory    | %li\n", GB_read_memuse(gb_selected_node)); 
     834                    } 
     835 
     836                    info += GBS_global_string("Security  | read=%i write=%i delete=%i\n", 
     837                                              GB_read_security_read(gb_selected_node), 
     838                                              GB_read_security_write(gb_selected_node), 
     839                                              GB_read_security_delete(gb_selected_node)); 
     840 
     841                    char *callback_info = GB_get_callback_info(gb_selected_node); 
     842                    if (callback_info) { 
     843                        info = info+"Callbacks |\n"+callback_info+'\n'; 
     844                        free(callback_info); 
     845                    } 
     846 
     847                    if (type != GB_DB) { 
     848                        MemDump  dump    = make_userdefined_MemDump(aw_root); 
     849                        char    *content = get_dbentry_content(gb_selected_node, GB_read_type(gb_selected_node), false, dump); 
     850                        info             = info+"Content |\n"+content+'\n'; 
     851                        free(content); 
     852                    } 
     853                } 
     854 
     855                aw_root->awar(AWAR_DBB_INFO)->write_string(info.c_str()); 
     856 
     857                free(fullpath); 
     858                avoid_recursion = false; 
     859            } 
     860        } 
     861 
     862        free(path); 
     863    } 
     864    free(child); 
     865} 
     866 
    791867static void path_changed_cb(AW_root *aw_root) { 
    792868    static bool avoid_recursion = false; 
     
    812888            } 
    813889 
    814             add_to_history(aw_root, path); 
     890            if (found) { 
     891                add_to_history(aw_root, goto_child ? GBS_global_string("%s/%s", path, goto_child) : path); 
     892            } 
    815893            browser->set_path(path); 
    816894            free(path); 
     
    899977        browse_id = aws->create_selection_list(AWAR_DBB_BROWSE); 
    900978        update_browser_selection_list(aw_root, (AW_CL)aws, (AW_CL)browse_id); 
     979 
     980        aws->at("infoopt"); 
     981        aws->label("ASCII"); aws->create_toggle     (AWAR_DUMP_ASCII); 
     982        aws->label("Hex");   aws->create_toggle     (AWAR_DUMP_HEX); 
     983        aws->label("Sep?");  aws->create_toggle     (AWAR_DUMP_SPACE); 
     984        aws->label("Width"); aws->create_input_field(AWAR_DUMP_WIDTH, 3); 
     985        aws->label("Block"); aws->create_input_field(AWAR_DUMP_BLOCK, 3); 
    901986 
    902987        aws->at("info"); 
  • branches/dev_elmar/AWT/AWT_input_mask.cxx

    r7669 r8224  
    1616 
    1717#include <arbdbt.h> 
     18#include <arb_file.h> 
    1819#include <awt_www.hxx> 
    1920#include <aw_edit.hxx> 
     
    927928    if (local) { 
    928929        static char *local_mask_dir; 
    929         if (!local_mask_dir) local_mask_dir = AW_unfold_path("HOME", ".arb_prop/inputMasks"); 
     930        if (!local_mask_dir) local_mask_dir = strdup(GB_path_in_arbprop("inputMasks")); 
    930931        return local_mask_dir; 
    931932    } 
  • branches/dev_elmar/AWT/AWT_macro.cxx

    r7625 r8224  
    1515 
    1616#include <arbdb.h> 
     17#include <arb_file.h> 
    1718 
    1819#include <aw_window.hxx> 
  • branches/dev_elmar/AWT/AWT_sel_boxes.cxx

    r7945 r8224  
    1818#include <aw_msg.hxx> 
    1919#include <aw_root.hxx> 
     20#include <aw_edit.hxx> 
    2021 
    2122#include <ad_config.h> 
     
    2425#include <arb_strbuf.h> 
    2526#include <arb_strarray.h> 
     27#include <arb_file.h> 
    2628 
    2729#include <list> 
     
    203205 
    204206 
    205  
     207static void arb_tcp_dat_changed_cb(const char * /* path */, bool fileChanged, bool /* editorTerminated */) { 
     208    if (fileChanged) { 
     209        awt_refresh_all_pt_server_selection_lists(); 
     210    } 
     211} 
     212 
     213void awt_edit_arbtcpdat_cb(AW_window *aww, AW_CL cl_gb_main) {  
     214    GBDATA *gb_main  = (GBDATA*)cl_gb_main; 
     215    char   *filename = GB_arbtcpdat_path(); 
     216 
     217    AW_edit(filename, arb_tcp_dat_changed_cb, aww, gb_main); 
     218    free(filename); 
     219} 
    206220 
    207221static char *readable_pt_servername(int index, int maxlength) { 
  • branches/dev_elmar/AWT/Makefile

    r7945 r8224  
    8080AWT_canio.o: $(ARBHOME)/INCLUDE/arb_defs.h 
    8181AWT_canio.o: $(ARBHOME)/INCLUDE/arb_error.h 
     82AWT_canio.o: $(ARBHOME)/INCLUDE/arb_file.h 
    8283AWT_canio.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    8384AWT_canio.o: $(ARBHOME)/INCLUDE/arb_progress.h 
     
    153154 
    154155AWT_db_browser.o: awt.hxx 
     156AWT_db_browser.o: awt_hexdump.hxx 
    155157AWT_db_browser.o: $(ARBHOME)/INCLUDE/ad_prot.h 
    156 AWT_db_browser.o: $(ARBHOME)/INCLUDE/ad_t_prot.h 
    157 AWT_db_browser.o: $(ARBHOME)/INCLUDE/AliView.hxx 
    158 AWT_db_browser.o: $(ARBHOME)/INCLUDE/AP_sequence.hxx 
    159 AWT_db_browser.o: $(ARBHOME)/INCLUDE/AP_Tree.hxx 
    160158AWT_db_browser.o: $(ARBHOME)/INCLUDE/arb_assert.h 
    161159AWT_db_browser.o: $(ARBHOME)/INCLUDE/arb_core.h 
     
    163161AWT_db_browser.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    164162AWT_db_browser.o: $(ARBHOME)/INCLUDE/arb_str.h 
     163AWT_db_browser.o: $(ARBHOME)/INCLUDE/arb_strbuf.h 
    165164AWT_db_browser.o: $(ARBHOME)/INCLUDE/arb_string.h 
    166 AWT_db_browser.o: $(ARBHOME)/INCLUDE/ARB_Tree.hxx 
    167165AWT_db_browser.o: $(ARBHOME)/INCLUDE/arbdb.h 
    168166AWT_db_browser.o: $(ARBHOME)/INCLUDE/arbdb_base.h 
    169 AWT_db_browser.o: $(ARBHOME)/INCLUDE/arbdbt.h 
    170167AWT_db_browser.o: $(ARBHOME)/INCLUDE/arbtools.h 
    171168AWT_db_browser.o: $(ARBHOME)/INCLUDE/attributes.h 
    172169AWT_db_browser.o: $(ARBHOME)/INCLUDE/aw_awar.hxx 
    173170AWT_db_browser.o: $(ARBHOME)/INCLUDE/aw_base.hxx 
    174 AWT_db_browser.o: $(ARBHOME)/INCLUDE/aw_color_groups.hxx 
    175171AWT_db_browser.o: $(ARBHOME)/INCLUDE/aw_keysym.hxx 
    176172AWT_db_browser.o: $(ARBHOME)/INCLUDE/aw_msg.hxx 
     
    178174AWT_db_browser.o: $(ARBHOME)/INCLUDE/aw_window.hxx 
    179175AWT_db_browser.o: $(ARBHOME)/INCLUDE/cb.h 
    180 AWT_db_browser.o: $(ARBHOME)/INCLUDE/downcast.h 
    181176AWT_db_browser.o: $(ARBHOME)/INCLUDE/dupstr.h 
    182177AWT_db_browser.o: $(ARBHOME)/INCLUDE/smartptr.h 
    183178AWT_db_browser.o: $(ARBHOME)/INCLUDE/test_global.h 
     179 
     180AWT_hexdump.o: awt.hxx 
     181AWT_hexdump.o: awt_hexdump.hxx 
     182AWT_hexdump.o: $(ARBHOME)/INCLUDE/arb_assert.h 
     183AWT_hexdump.o: $(ARBHOME)/INCLUDE/arb_core.h 
     184AWT_hexdump.o: $(ARBHOME)/INCLUDE/arb_error.h 
     185AWT_hexdump.o: $(ARBHOME)/INCLUDE/arb_strbuf.h 
     186AWT_hexdump.o: $(ARBHOME)/INCLUDE/arbdb_base.h 
     187AWT_hexdump.o: $(ARBHOME)/INCLUDE/arbtools.h 
     188AWT_hexdump.o: $(ARBHOME)/INCLUDE/attributes.h 
     189AWT_hexdump.o: $(ARBHOME)/INCLUDE/aw_base.hxx 
     190AWT_hexdump.o: $(ARBHOME)/INCLUDE/aw_root.hxx 
     191AWT_hexdump.o: $(ARBHOME)/INCLUDE/cb.h 
     192AWT_hexdump.o: $(ARBHOME)/INCLUDE/dupstr.h 
     193AWT_hexdump.o: $(ARBHOME)/INCLUDE/smartptr.h 
     194AWT_hexdump.o: $(ARBHOME)/INCLUDE/test_global.h 
     195AWT_hexdump.o: $(ARBHOME)/INCLUDE/test_unit.h 
    184196 
    185197AWT_hotkeys.o: awt_hotkeys.hxx 
     
    195207AWT_input_mask.o: $(ARBHOME)/INCLUDE/arb_core.h 
    196208AWT_input_mask.o: $(ARBHOME)/INCLUDE/arb_error.h 
     209AWT_input_mask.o: $(ARBHOME)/INCLUDE/arb_file.h 
    197210AWT_input_mask.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    198211AWT_input_mask.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    220233AWT_macro.o: $(ARBHOME)/INCLUDE/arb_core.h 
    221234AWT_macro.o: $(ARBHOME)/INCLUDE/arb_error.h 
     235AWT_macro.o: $(ARBHOME)/INCLUDE/arb_file.h 
    222236AWT_macro.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    223237AWT_macro.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    264278AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/arb_core.h 
    265279AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/arb_error.h 
     280AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/arb_file.h 
    266281AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    267282AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/arb_strarray.h 
     
    277292AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/aw_awars.hxx 
    278293AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/aw_base.hxx 
     294AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/aw_edit.hxx 
    279295AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/aw_file.hxx 
    280296AWT_sel_boxes.o: $(ARBHOME)/INCLUDE/aw_keysym.hxx 
  • branches/dev_elmar/AWT/awt_sel_boxes.hxx

    r7945 r8224  
    3232void awt_create_selection_list_on_pt_servers(AW_window *aws, const char *varname, bool popup); 
    3333void awt_refresh_all_pt_server_selection_lists(); 
     34void awt_edit_arbtcpdat_cb(AW_window *aww, AW_CL cl_gb_main); 
    3435 
    3536void awt_create_selection_list_on_tables(GBDATA *gb_main, AW_window *aws, const char *varname); 
  • branches/dev_elmar/AWTC/AWTC_next_neighbours.cxx

    r7415 r8224  
    161161    ff_assert(!com && !link); 
    162162 
    163     if (arb_look_and_start_server(AISC_MAGIC_NUMBER, servername, gb_main)) { 
     163    if (arb_look_and_start_server(AISC_MAGIC_NUMBER, servername)) { 
    164164        error = "Cannot contact PT  server"; 
    165165    } 
  • branches/dev_elmar/AWTI/AWTI_export.cxx

    r7945 r8224  
    2222#include <arbdbt.h> 
    2323#include <arb_str.h> 
     24#include <arb_file.h> 
    2425 
    2526#define AWAR_EXPORT_FILE           "tmp/export_db/file" 
  • branches/dev_elmar/AWTI/AWTI_import.cxx

    r7945 r8224  
    2626#include <arb_progress.h> 
    2727#include <arb_strbuf.h> 
     28#include <arb_file.h> 
    2829 
    2930#include <climits> 
     
    397398                arb_progress::show_comment(GBS_global_string("exec '%s'", awtcig.ifo2->system)); 
    398399 
    399                 error                        = GB_system(sys); 
     400                error                        = GBK_system(sys); 
    400401                if (!error) origin_file_name = mid_file_name; 
    401402 
     
    425426                arb_progress::show_comment(GBS_global_string("Converting File %s", awtcig.ifo->system)); 
    426427 
    427                 error                        = GB_system(sys); 
     428                error                        = GBK_system(sys); 
    428429                if (!error) origin_file_name = dest_file_name; 
    429430 
  • branches/dev_elmar/AWTI/Makefile

    r7945 r8224  
    3939AWTI_export.o: $(ARBHOME)/INCLUDE/arb_core.h 
    4040AWTI_export.o: $(ARBHOME)/INCLUDE/arb_error.h 
     41AWTI_export.o: $(ARBHOME)/INCLUDE/arb_file.h 
    4142AWTI_export.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    4243AWTI_export.o: $(ARBHOME)/INCLUDE/arb_progress.h 
     
    7273AWTI_import.o: $(ARBHOME)/INCLUDE/arb_core.h 
    7374AWTI_import.o: $(ARBHOME)/INCLUDE/arb_error.h 
     75AWTI_import.o: $(ARBHOME)/INCLUDE/arb_file.h 
    7476AWTI_import.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    7577AWTI_import.o: $(ARBHOME)/INCLUDE/arb_progress.h 
  • branches/dev_elmar/CONVERTALN/Makefile

    r7945 r8224  
    108108fconv.o: $(ARBHOME)/INCLUDE/arb_defs.h 
    109109fconv.o: $(ARBHOME)/INCLUDE/arb_error.h 
     110fconv.o: $(ARBHOME)/INCLUDE/arb_file.h 
    110111fconv.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    111112fconv.o: $(ARBHOME)/INCLUDE/arb_string.h 
  • branches/dev_elmar/CONVERTALN/fconv.cxx

    r7945 r8224  
    5959#ifdef UNIT_TESTS 
    6060#include <arbdbt.h> // before test_unit.h! 
     61#include <arb_file.h> 
    6162#include <test_unit.h> 
     63 
    6264 
    6365#define TEST_THROW // comment out to temp. disable intentional throws 
  • branches/dev_elmar/CORE/Makefile

    r7945 r8224  
    11 
    2 .SUFFIXES: .o .cxx .depend .h .genh 
     2.SUFFIXES: .o .cxx .depend .h .genh  
    33 
    44OBJECTS=$(subst .cxx,.o,$(wildcard *.cxx)) 
     5 
     6GENERATED_HEADERS= \ 
     7        arb_msg.h \ 
     8        arb_string.h \ 
     9        arb_signal.h \ 
     10        arb_file.h \ 
    511 
    612$(MAIN): $(OBJECTS) 
     
    1117        $(CPPLIB) $(cflags) -c $< $(AINCLUDES) $(POST_COMPILE) 
    1218 
    13 proto:  
    14         ../AISC_MKPTPS/aisc_mkpt -P -G -A -w arb_msg.h    arb_msg.cxx    > arb_msg.genh 
    15         ../AISC_MKPTPS/aisc_mkpt -P -G -A -w arb_string.h arb_string.cxx > arb_string.genh 
    16         ../AISC_MKPTPS/aisc_mkpt -P -G -A -w arb_signal.h arb_signal.cxx > arb_signal.genh 
    17         ../SOURCE_TOOLS/mv_if_diff arb_msg.genh    arb_msg.h 
    18         ../SOURCE_TOOLS/mv_if_diff arb_string.genh arb_string.h 
    19         ../SOURCE_TOOLS/mv_if_diff arb_signal.genh arb_signal.h 
     19.cxx.genh: 
     20        ../AISC_MKPTPS/aisc_mkpt -P -G -A -w $(subst .genh,.h,$@) $< > $@ 
     21 
     22%.genheader: %.genh 
     23        ../SOURCE_TOOLS/mv_if_diff $< $(subst .genheader,.h,$@) 
     24 
     25proto: $(subst .h,.genheader,$(GENERATED_HEADERS)) 
    2026 
    2127clean: 
     
    4854arb_cs.o: $(ARBHOME)/INCLUDE/smartptr.h 
    4955arb_cs.o: $(ARBHOME)/INCLUDE/test_global.h 
     56 
     57arb_file.o: arb_core.h 
     58arb_file.o: arb_file.h 
     59arb_file.o: arb_msg.h 
     60arb_file.o: $(ARBHOME)/INCLUDE/attributes.h 
     61arb_file.o: $(ARBHOME)/INCLUDE/dupstr.h 
    5062 
    5163arb_handlers.o: arb_core.h 
     
    122134arb_string.o: arb_string.h 
    123135arb_string.o: $(ARBHOME)/INCLUDE/arb_assert.h 
     136arb_string.o: $(ARBHOME)/INCLUDE/arbtools.h 
    124137arb_string.o: $(ARBHOME)/INCLUDE/attributes.h 
    125138arb_string.o: $(ARBHOME)/INCLUDE/dupstr.h 
    126139arb_string.o: $(ARBHOME)/INCLUDE/test_global.h 
     140arb_string.o: $(ARBHOME)/INCLUDE/test_unit.h 
  • branches/dev_elmar/CORE/arb_core.h

    r7084 r8224  
    3939void GBK_terminate(const char *error); 
    4040 
     41GB_ERROR GBK_system(const char *system_command); 
     42 
    4143#else 
    4244#error arb_core.h included twice 
  • branches/dev_elmar/CORE/arb_msg.cxx

    r7945 r8224  
    2323// AISC_MKPT_PROMOTE:#include "arb_core.h" 
    2424// AISC_MKPT_PROMOTE:#endif 
     25// AISC_MKPT_PROMOTE: 
     26// AISC_MKPT_PROMOTE:// return error and ensure none is exported  
     27// AISC_MKPT_PROMOTE:#define RETURN_ERROR(err)  arb_assert(!GB_have_error()); return (err) 
    2528 
    2629 
     
    495498} 
    496499 
     500#if defined(WARN_TODO) 
     501#warning search for '\b(system)\b\s*\(' and use GBK_system instead 
     502#endif 
     503GB_ERROR GBK_system(const char *system_command) { 
     504    // goes to header: __ATTR__USERESULT 
     505    fprintf(stderr, "[Action: '%s']\n", system_command); 
     506    int      res   = system(system_command); 
     507    GB_ERROR error = NULL; 
     508    if (res) { 
     509        error = GBS_global_string("System call failed (result=%i)\n" 
     510                                  "System call was '%s'\n" 
     511                                  "(Note: console window may contain additional information)", res, system_command); 
     512    } 
     513    return error; 
     514} 
     515 
  • branches/dev_elmar/CORE/arb_msg.h

    r7945 r8224  
    2020#include "arb_core.h" 
    2121#endif 
     22 
     23// return error and ensure none is exported 
     24#define RETURN_ERROR(err)  arb_assert(!GB_have_error()); return (err) 
    2225 
    2326const char *GBS_global_string_to_buffer(char *buffer, size_t bufsize, const char *templat, ...) __ATTR__FORMAT(3); 
     
    5053void GB_informationf(const char *templat, ...) __ATTR__FORMAT(1); 
    5154void GBS_reuse_buffer(const char *global_buffer); 
     55GB_ERROR GBK_system(const char *system_command) __ATTR__USERESULT; 
    5256 
    5357#else 
  • branches/dev_elmar/CORE/arb_sort.cxx

    • Property svn:mergeinfo changed from /trunk/CORE/arb_sort.cxx:7771-7998 to /trunk/CORE/arb_sort.cxx:7771-8223
  • branches/dev_elmar/CORE/arb_strarray.cxx

    • Property svn:mergeinfo changed from /trunk/CORE/arb_strarray.cxx:7771-7998 to /trunk/CORE/arb_strarray.cxx:7771-8223
  • branches/dev_elmar/CORE/arb_strbuf.cxx

    r7667 r8224  
    1313 
    1414void GBS_strstruct::vnprintf(size_t maxlen, const char *templat, va_list& parg) { 
    15     ensure_mem(maxlen); 
     15    ensure_mem(maxlen+1); 
    1616 
    1717    char *buffer = data+pos; 
     
    1919 
    2020#ifdef LINUX 
    21     printed = vsnprintf(buffer, maxlen, templat, parg); 
     21    printed = vsnprintf(buffer, maxlen+1, templat, parg); 
    2222#else 
    2323    printed = vsprintf(buffer, templat, parg); 
  • branches/dev_elmar/CORE/arb_string.cxx

    r7314 r8224  
    6969 
    7070 
    71  
    72  
     71// -------------------------------------------------------------------------------- 
     72 
     73 
     74#ifdef UNIT_TESTS 
     75 
     76#include <string> 
     77#include <climits> 
     78 
     79#ifndef TEST_UNIT_H 
     80#include <test_unit.h> 
     81#endif 
     82 
     83using namespace std; 
     84 
     85// ---------------------------------------------- 
     86//      some tests for unit-test-code itself 
     87 
     88#define TEST_ASSERT_HEAPCOPY_EQUAL(copy,expected) do {  \ 
     89        char *theCopy = (copy);                         \ 
     90        TEST_ASSERT_EQUAL(theCopy, expected);           \ 
     91        free(theCopy);                                  \ 
     92    } while(0) 
     93 
     94void TEST_arbtest_strf() { 
     95    // tests string formatter from test_unit.h 
     96    using namespace arb_test; 
     97    TEST_ASSERT_HEAPCOPY_EQUAL(StaticCode::strf("<%i>", 7), "<7>"); 
     98    TEST_ASSERT_HEAPCOPY_EQUAL(StaticCode::strf("<%0*i>", 3, 7), "<007>"); 
     99} 
     100 
     101void TEST_arbtest_readable() { 
     102    using namespace arb_test; 
     103 
     104    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy('x')), "'x'"); 
     105    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(static_cast<unsigned char>('x'))), "'x'"); 
     106    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(static_cast<signed char>('x'))), "'x'"); 
     107 
     108    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(true)), "true"); 
     109    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(false)), "false"); 
     110     
     111    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(1)), "1"); 
     112    TEST_ASSERT_HEAPCOPY_EQUAL(val2hex(make_copy(2)), "0x2"); 
     113 
     114    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(3L)), "3"); 
     115    TEST_ASSERT_HEAPCOPY_EQUAL(val2hex(make_copy(4L)), "0x4"); 
     116 
     117    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(5U)), "5"); 
     118    TEST_ASSERT_HEAPCOPY_EQUAL(val2hex(make_copy(6U)), "0x6"); 
     119     
     120    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy("some\ntext\twhich\"special\\chars")), "\"some\\ntext\\twhich\\\"special\\\\chars\""); 
     121    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy("a\1\2\x1a\x7e\x7f\x80\xfe\xff")), "\"a\\1\\2\\x1a~\\x7f\\x80\\xfe\\xff\""); 
     122    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy((const char *)NULL)), "(null)"); 
     123    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy((const unsigned char *)NULL)), "(null)"); 
     124    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy((const signed char *)NULL)), "(null)"); 
     125 
     126    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(1.7)), "1.700000"); 
     127    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(177.0e20)),  "17699999999999998951424.000000"); 
     128    TEST_ASSERT_HEAPCOPY_EQUAL(val2readable(make_copy(177.0e20F)), "17699999967695435988992.000000"); 
     129} 
     130 
     131void TEST_arbtest_copyable() { 
     132    using namespace arb_test; 
     133 
     134    int         i = 7; 
     135    const char *s = "servas"; 
     136 
     137    TEST_ASSERT(make_copy(i) == make_copy(7)); 
     138 
     139    TEST_ASSERT(strcmp(make_copy(s), make_copy("servas")) == 0); 
     140} 
     141 
     142#define TEST_DESCRIPTIONS(d, tt, tf, ft, ff) do {               \ 
     143        TEST_ASSERT_EQUAL((d).make(true, true), (tt));   \ 
     144        TEST_ASSERT_EQUAL((d).make(true, false), (tf));  \ 
     145        TEST_ASSERT_EQUAL((d).make(false, true), (ft));  \ 
     146        TEST_ASSERT_EQUAL((d).make(false, false), (ff)); \ 
     147    } while(0) 
     148 
     149#define TEST_SIMPLE_DESCRIPTIONS(d, ae, nae) TEST_DESCRIPTIONS(d, ae, nae, nae, ae) 
     150 
     151void TEST_arbtest_predicate_description() { 
     152    TEST_SIMPLE_DESCRIPTIONS(predicate_description("similar"), "is similar", "isnt similar"); 
     153    TEST_SIMPLE_DESCRIPTIONS(predicate_description("repairs"), "repairs", "doesnt repair"); 
     154 
     155    TEST_DESCRIPTIONS(predicate_description("equals", "differs"), 
     156                      "equals", "doesnt equal", 
     157                      "doesnt differ", "differs"); 
     158 
     159    TEST_DESCRIPTIONS(predicate_description("less_than", "more_than"), 
     160                      "is less_than", "isnt less_than", 
     161                      "isnt more_than", "is more_than"); 
     162} 
     163 
     164void TEST_arbtest_expectations() { 
     165    // used to TDD expectations 
     166    using namespace arb_test; 
     167 
     168    string apple       = "Apfel"; 
     169    string pear        = "Birne"; 
     170    string boskop      = apple; 
     171    string pomegranate = "Granatapfel"; 
     172 
     173    TEST_EXPECT(that(apple).equals("Apfel")); 
     174     
     175    TEST_EXPECT(that(apple).differs(pear)); 
     176    TEST_EXPECT(that(apple).equals(boskop)); 
     177    TEST_EXPECT(wrong(that(pomegranate).equals(apple))); 
     178 
     179    match_expectation ff1 = that(1.0).equals(2-1); 
     180    match_expectation ff2 = that(boskop).equals(apple); 
     181    match_expectation ff3 = that(apple).equals(apple); 
     182 
     183    match_expectation nf1 = that(apple).equals(pear); 
     184    match_expectation nf2 = that(pomegranate).equals(apple); 
     185    match_expectation nf3 = that(apple).differs(boskop); 
     186 
     187    match_expectation a1 = all().of(ff1); 
     188    match_expectation a2 = all().of(ff1, ff2); 
     189    match_expectation a3 = all().of(ff1, ff2, ff3); 
     190 
     191    TEST_EXPECT(a1); 
     192    TEST_EXPECT(a2); 
     193    TEST_EXPECT(a3); 
     194 
     195    match_expectation n1 = none().of(ff1); 
     196    match_expectation n2 = none().of(ff1, ff2); 
     197    match_expectation n3 = none().of(ff1, ff2, ff3); 
     198 
     199    TEST_EXPECT(wrong(none().of(that(boskop).equals(apple)))); 
     200    TEST_EXPECT(wrong(n1)); 
     201    TEST_EXPECT(wrong(n2)); 
     202    TEST_EXPECT(wrong(n3)); 
     203 
     204    TEST_EXPECT(atleast(1).of(a1)); 
     205    TEST_EXPECT(atleast(1).of(a1, n1)); 
     206    TEST_EXPECT(atleast(1).of(n2, a1, n1)); 
     207 
     208    TEST_EXPECT(wrong(atleast(2).of(a1, n1, n2))); 
     209    TEST_EXPECT(wrong(atleast(2).of(a1, n1))); 
     210    TEST_EXPECT(wrong(atleast(2).of(a1))); // impossible 
     211 
     212    TEST_EXPECT(atmost(2).of(a1)); 
     213    TEST_EXPECT(atmost(2).of(a1, a2)); 
     214    TEST_EXPECT(atmost(2).of(a1, a2, n1)); 
     215    TEST_EXPECT(atmost(2).of(a1, n1, n2)); 
     216    TEST_EXPECT(atmost(2).of(n1, n2)); 
     217    TEST_EXPECT(wrong(atmost(2).of(a1, a2, a3))); 
     218 
     219    TEST_EXPECT(exacly(1).of(ff1, nf1, nf2)); 
     220    TEST_EXPECT(wrong(exacly(1).of(nf1, nf2))); 
     221    TEST_EXPECT(wrong(exacly(1).of(nf1, nf2, nf3))); 
     222    TEST_EXPECT(wrong(exacly(1).of(ff1, ff2, nf2))); 
     223    TEST_EXPECT(wrong(exacly(1).of(ff1, ff2, ff3))); 
     224 
     225} 
     226 
     227void TEST_replace_old_TEST_ASSERTS_by_expectations() { 
     228    // test various string-types are matchable (w/o casts) 
     229    { 
     230        const char *car_ccp = "Alfa"; 
     231        char       *car_cp  = strdup("Alfa"); 
     232        string      car_str("Alfa"); 
     233 
     234        TEST_ASSERT_EQUAL(car_ccp, "Alfa"); 
     235        TEST_ASSERT_EQUAL(car_cp, "Alfa"); 
     236        TEST_ASSERT_EQUAL(car_str, "Alfa"); 
     237 
     238        TEST_ASSERT_EQUAL("Alfa", car_ccp); 
     239        TEST_ASSERT_EQUAL("Alfa", car_cp); 
     240        TEST_ASSERT_EQUAL("Alfa", car_str); 
     241 
     242        TEST_ASSERT_EQUAL(car_cp, car_ccp); 
     243        TEST_ASSERT_EQUAL(car_cp, car_str); 
     244        TEST_ASSERT_EQUAL(car_ccp, car_cp); 
     245        TEST_ASSERT_EQUAL(car_ccp, car_str); 
     246        TEST_ASSERT_EQUAL(car_str, car_cp); 
     247        TEST_ASSERT_EQUAL(car_str, car_ccp); 
     248 
     249        char *null = NULL; 
     250        TEST_ASSERT_NULL(NULL); 
     251        TEST_ASSERT_NULL(null); 
     252 
     253        TEST_ASSERT_CONTAINS(car_ccp, "lf"); 
     254        TEST_ASSERT_CONTAINS(car_cp, "fa"); 
     255        TEST_ASSERT_CONTAINS(car_str, "Al"); 
     256 
     257        free(car_cp); 
     258    } 
     259 
     260    // test various numeric types are matchable 
     261 
     262    { 
     263        short unsigned su = 7; 
     264        short          s  = -su; 
     265 
     266        unsigned iu = su; 
     267        int      i  = -iu; 
     268 
     269        long unsigned lu = (long unsigned)INT_MAX+3; 
     270        long          l  = -lu; 
     271 
     272        float  f = s; 
     273        double d = i; 
     274 
     275        TEST_ASSERT_EQUAL(s, -7); 
     276        TEST_ASSERT_EQUAL(i, -7); 
     277 
     278        TEST_ASSERT_EQUAL(su, 7);  TEST_ASSERT_EQUAL(iu, 7); 
     279        TEST_ASSERT_EQUAL(su, 7U); TEST_ASSERT_EQUAL(iu, 7U); 
     280        TEST_ASSERT_EQUAL(su, 7L); TEST_ASSERT_EQUAL(iu, 7L); 
     281 
     282        TEST_ASSERT_EQUAL(s, -su); TEST_ASSERT_EQUAL(s, -iu); 
     283        TEST_ASSERT_EQUAL(i, -iu); TEST_ASSERT_EQUAL(i, -su); 
     284        TEST_ASSERT_EQUAL(l, -lu); 
     285 
     286        TEST_ASSERT_EQUAL(f, d); 
     287        TEST_ASSERT_EQUAL(d, f); 
     288    } 
     289 
     290    TEST_ASSERT_ZERO(7-7); 
     291} 
     292 
     293// --- simulate user_type (which may be defined anywhere) --- 
     294class user_type { 
     295    int x, y; 
     296public: 
     297    user_type(int X, int Y) : x(X), y(Y) {} 
     298 
     299    int get_x() const { return x; } 
     300    int get_y() const { return y; } 
     301 
     302    user_type flipped() const { return user_type(y,x); } 
     303 
     304    int quadrant() const { 
     305        if (x == 0 || y == 0) return 0; // on axis 
     306        if (y>0) return x<0 ? 2 : 1; 
     307        return x<0 ? 3 : 4; 
     308    } 
     309}; 
     310// --- end of user_type --- 
     311 
     312// helpers needed for tests: 
     313inline bool operator == (const user_type& u1, const user_type& u2) { return u1.get_x() == u2.get_x() && u1.get_y() == u2.get_y(); } 
     314inline char *val2readable(const user_type& u) { return arb_test::StaticCode::strf("user_type(%i,%i)", u.get_x(), u.get_y()); } 
     315inline bool in_same_quadrant(const user_type& u1, const user_type& u2) { return u1.quadrant() == u2.quadrant(); } 
     316 
     317void TEST_user_type_with_expectations() { 
     318    user_type ut1(3, 4); 
     319    user_type ut12(4, 4); 
     320    user_type ut2(-4, 4); 
     321    user_type ut3(-4, -8); 
     322    user_type ut4(4, -8); 
     323 
     324    TEST_EXPECT(that(ut1).differs(ut12)); 
     325    TEST_EXPECT(that(ut12).equals(ut12.flipped())); 
     326    TEST_EXPECT(that(ut1).differs(ut1.flipped())); 
     327 
     328    TEST_EXPECT(that(ut1).is(in_same_quadrant, ut12)); 
     329    TEST_EXPECT(none().of(that(ut1).is(in_same_quadrant, ut2), 
     330                          that(ut2).is(in_same_quadrant, ut3), 
     331                          that(ut3).is(in_same_quadrant, ut4))); 
     332} 
     333 
     334void TEST_similarity() { 
     335    double d1      = 0.7531; 
     336    double epsilon = 0.00001; 
     337    double d2      = d1-epsilon*0.6; 
     338    double d3      = d1+epsilon*0.6; 
     339 
     340    TEST_EXPECT(that(d1).is(epsilon_similar(epsilon), d2)); 
     341    TEST_EXPECT(that(d1).is(epsilon_similar(epsilon), d3)); 
     342    TEST_EXPECT(that(d2).is_not(epsilon_similar(epsilon), d3)); 
     343 
     344    TEST_ASSERT_SIMILAR(d1, d2, epsilon); 
     345    TEST_ASSERT_SIMILAR(d1, d3, epsilon); 
     346} 
     347 
     348void TEST_less_equal() { 
     349    int x = 7; 
     350    int y = 8; 
     351    int z = 9; 
     352 
     353    // less/more etc 
     354 
     355    TEST_EXPECT(that(x).less_than(y)); 
     356    TEST_EXPECT(that(x).less_or_equal(y)); 
     357    TEST_EXPECT(that(x).less_or_equal(x)); 
     358     
     359    TEST_EXPECT(that(y).more_than(x)); 
     360    TEST_EXPECT(that(y).more_or_equal(x)); 
     361    TEST_EXPECT(that(y).more_or_equal(y)); 
     362 
     363    TEST_ASSERT_LOWER_EQUAL(x, y); 
     364    TEST_ASSERT_LOWER_EQUAL(x, x); 
     365    TEST_ASSERT_LOWER(x, y); 
     366    TEST_ASSERT_IN_RANGE(y, x, z); 
     367} 
     368 
     369#endif // UNIT_TESTS 
     370 
     371// -------------------------------------------------------------------------------- 
     372 
     373 
  • branches/dev_elmar/DBSERVER/Makefile

    r7183 r8224  
    3333db_server.o: $(ARBHOME)/INCLUDE/arb_core.h 
    3434db_server.o: $(ARBHOME)/INCLUDE/arb_error.h 
     35db_server.o: $(ARBHOME)/INCLUDE/arb_file.h 
    3536db_server.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    3637db_server.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    4344db_server.o: $(ARBHOME)/INCLUDE/smartptr.h 
    4445db_server.o: $(ARBHOME)/INCLUDE/test_global.h 
     46db_server.o: $(ARBHOME)/INCLUDE/test_unit.h 
     47db_server.o: $(ARBHOME)/INCLUDE/ut_valgrinded.h 
  • branches/dev_elmar/DBSERVER/db_server.cxx

    r7945 r8224  
    22//                                                               // 
    33//   File      : db_server.cxx                                   // 
    4 //   Purpose   :                                                 // 
     4//   Purpose   : CL ARB database server                          // 
    55//                                                               // 
    66//   Institute of Microbiology (Technical University Munich)     // 
     
    1111#include <arbdb.h> 
    1212#include <servercntrl.h> 
     13#include <ut_valgrinded.h> 
     14#include <arb_file.h> 
    1315 
    1416#define TIMEOUT 1000*60*2       // save every 2 minutes 
    1517#define LOOPS   30              // wait 30*TIMEOUT (1 hour) till shutdown 
    1618 
    17 int main(int argc, char **argv) 
    18 { 
    19     arb_params *params; 
    20     GBDATA     *gb_extern; 
    21     GBDATA     *gb_main; 
    22     GB_ERROR    error; 
    23     int         timer; 
    24     int         last_update = 0; 
    25     int         clock; 
    26  
    27     if (argc <= 1 || strcmp(argv[1], "--help") == 0) { 
    28         printf("Syntax of the arb_db_server:\n"); 
    29         printf("        arb_db_server [-D]database [-Tsocketid]\n"); 
    30         return -1; 
    31     } 
    32  
    33     params = arb_trace_argv(&argc, argv); 
    34     if (!params->tcp) { 
    35         static char arg[] = ":"; 
    36         params->tcp = arg; 
    37     } 
    38  
    39     if (argc==2) { 
    40         params->db_server = (char *)strdup(argv[1]); 
    41         argc--; 
    42     } 
    43  
    44     // 
    45  
    46     gb_extern = GB_open(params->tcp, "rwc"); 
     19inline GBDATA *dbserver_container(GBDATA *gb_main) { 
     20    return GB_search(gb_main, "/tmp/dbserver", GB_CREATE_CONTAINER); 
     21} 
     22inline GBDATA *dbserver_entry(GBDATA *gb_main, const char *entry) { 
     23    GBDATA *gb_entry = GB_searchOrCreate_string(dbserver_container(gb_main), entry, "<undefined>"); 
     24    if (gb_entry) { 
     25        GBDATA *gb_brother = GB_nextEntry(gb_entry); 
     26        arb_assert(!gb_brother); 
     27    } 
     28    return gb_entry; 
     29} 
     30 
     31inline GBDATA *get_command_entry(GBDATA *gb_main) { return dbserver_entry(gb_main, "cmd"); } 
     32inline GBDATA *get_param_entry(GBDATA *gb_main) { return dbserver_entry(gb_main, "param"); } 
     33inline GBDATA *get_result_entry(GBDATA *gb_main) { return dbserver_entry(gb_main, "result"); } 
     34 
     35inline GB_ERROR init_data(GBDATA *gb_main) { 
     36    GB_ERROR error = NULL; 
     37 
     38    if (!get_command_entry(gb_main) || !get_param_entry(gb_main) || !get_result_entry(gb_main)) { 
     39        error = GB_await_error(); 
     40    } 
     41     
     42    return error; 
     43} 
     44 
     45inline bool served(GBDATA *gb_main) { 
     46    GB_begin_transaction(gb_main); 
     47    GB_commit_transaction(gb_main); 
     48    return GBCMS_accept_calls(gb_main, false); 
     49} 
     50 
     51static bool do_shutdown       = false; 
     52static bool command_triggered = false; 
     53 
     54static const char *savemode = "b"; 
     55 
     56static void command_cb(GBDATA *, int*, GB_CB_TYPE ) { 
     57    command_triggered = true; 
     58} 
     59 
     60static void react_to_command(GBDATA *gb_main) { 
     61    static bool in_reaction = false; 
     62 
     63    if (!in_reaction) { 
     64        in_reaction = true; 
     65 
     66        command_triggered = false; 
     67 
     68        GB_ERROR  error        = NULL; 
     69 
     70        GB_begin_transaction(gb_main); 
     71        GBDATA   *gb_cmd_entry = get_command_entry(gb_main); 
     72        GB_commit_transaction(gb_main); 
     73 
     74        char *command; 
     75        { 
     76            GB_transaction ta(gb_main); 
     77 
     78            command = GB_read_string(gb_cmd_entry); 
     79            if (command[0]) { 
     80                error             = GB_write_string(gb_cmd_entry, ""); 
     81                if (!error) error = GB_write_string(get_result_entry(gb_main), "busy"); 
     82            } 
     83        } 
     84 
     85        if (command[0]) { 
     86            if      (strcmp(command, "shutdown") == 0) do_shutdown = true; 
     87            else if (strcmp(command, "ping")     == 0) {} // ping is a noop 
     88            else if (strcmp(command, "save")     == 0) { 
     89                fprintf(stdout, "arb_db_server: save requested (savemode is \"%s\")\n", savemode); 
     90 
     91                char *param = NULL; 
     92                { 
     93                    GB_transaction  ta(gb_main); 
     94                    GBDATA         *gb_param = get_param_entry(gb_main); 
     95                    if (!gb_param) error     = GB_await_error(); 
     96                    else { 
     97                        param             = GB_read_string(gb_param); 
     98                        if (!param) error = GB_await_error(); 
     99                        else error        = GB_write_string(gb_param, ""); 
     100                    } 
     101                } 
     102 
     103                if (!error) { 
     104                    if (param[0]) error = GB_save(gb_main, param, savemode); 
     105                    else error          = "No savename specified"; 
     106                } 
     107 
     108                printf("arb_db_server: save returns '%s'\n", error); 
     109 
     110                free(param); 
     111            } 
     112            else { 
     113                error = GBS_global_string("Unknown command '%s'", command); 
     114            } 
     115        } 
     116        { 
     117            GB_transaction ta(gb_main); 
     118 
     119            GB_ERROR err2             = GB_write_string(get_result_entry(gb_main), error ? error : "ok"); 
     120            if (!error && err2) error = GBS_global_string("could not write result (reason: %s)", err2); 
     121            if (error) fprintf(stderr, "arb_db_server: failed to react to command '%s' (reason: %s)\n", command, error); 
     122        } 
     123        free(command); 
     124        in_reaction = false; 
     125    } 
     126} 
     127 
     128static GB_ERROR server_main_loop(GBDATA *gb_main) { 
     129    GB_ERROR error = NULL; 
     130    { 
     131        GB_transaction ta(gb_main); 
     132 
     133        GBDATA *cmd_entry = get_command_entry(gb_main); 
     134        error             = GB_add_callback(cmd_entry, GB_CB_CHANGED, command_cb, NULL); 
     135    } 
     136 
     137    while (!error) { 
     138        served(gb_main); 
     139        if (command_triggered) { 
     140            react_to_command(gb_main); 
     141        } 
     142        if (do_shutdown) { 
     143            int clients; 
     144            do { 
     145                clients = GB_read_clients(gb_main); 
     146                if (clients>0) { 
     147                    fprintf(stdout, "arb_db_server: shutdown requested (waiting for %i clients)\n", clients); 
     148                    served(gb_main); 
     149                } 
     150            } 
     151            while (clients>0); 
     152            fputs("arb_db_server: all clients left, performing shutdown\n", stdout); 
     153            break; 
     154        } 
     155    } 
     156    return error; 
     157} 
     158 
     159static GB_ERROR check_socket_available(const arb_params& params) { 
     160    GBDATA *gb_extern = GB_open(params.tcp, "rwc"); 
    47161    if (gb_extern) { 
    48162        GB_close(gb_extern); 
    49         return -1; 
    50     } 
    51     printf("Loading '%s'...\n", params->db_server); 
    52     gb_main = GB_open(params->db_server, "rw"); 
    53     if (!gb_main) { 
    54         printf("Error: File %s not found\n", params->db_server); 
    55         return -1; 
    56     } 
    57     error = GBCMS_open(params->tcp, TIMEOUT, gb_main); 
     163        return GBS_global_string("socket '%s' already in use", params.tcp); 
     164    } 
     165    GB_clear_error(); 
     166    return NULL; 
     167} 
     168 
     169static GB_ERROR run_server(const arb_params& params) { 
     170    GB_shell shell; 
     171    GB_ERROR error = check_socket_available(params); 
     172    if (!error) { 
     173        printf("Loading '%s'...\n", params.default_file); 
     174        GBDATA *gb_main     = GB_open(params.default_file, "rw"); 
     175        if (!gb_main) error = GBS_global_string("Can't open DB '%s' (reason: %s)", params.default_file, GB_await_error()); 
     176        else { 
     177            error = GBCMS_open(params.tcp, TIMEOUT, gb_main); 
     178            if (error) error = GBS_global_string("Error starting server: %s", error); 
     179        } 
     180 
     181        if (!error) { 
     182            GB_transaction ta(gb_main); 
     183            error = init_data(gb_main); 
     184        } 
     185        if (!error) { 
     186            error = server_main_loop(gb_main); 
     187            fprintf(stderr, "server_main_loop returns with '%s'\n", error); 
     188        } 
     189 
     190        if (gb_main) { 
     191            GBCMS_shutdown(gb_main); 
     192            GB_close(gb_main); 
     193        } 
     194    } 
     195    return error; 
     196} 
     197 
     198static GB_ERROR run_command(const arb_params& params, const char *command) { 
     199    GB_ERROR  error     = NULL; 
     200    GB_shell  shell; 
     201    GBDATA   *gb_main   = GB_open(params.tcp, "rw"); 
     202    if (!gb_main) error = GB_await_error(); 
     203    else { 
     204        { 
     205            GB_transaction ta(gb_main); 
     206 
     207            GBDATA *gb_cmd_entry = get_command_entry(gb_main); 
     208            error                = gb_cmd_entry ? GB_write_string(gb_cmd_entry, command) : GB_await_error(); 
     209 
     210            if (!error) { 
     211                if (strcmp(command, "save") == 0) { 
     212                    GBDATA *gb_param     = get_param_entry(gb_main); 
     213                    if (!gb_param) error = GB_await_error(); 
     214                    else    error        = GB_write_string(gb_param, params.default_file); // send save-name 
     215                } 
     216            } 
     217        } 
     218 
     219        if (!error) { 
     220            GB_transaction ta(gb_main); 
     221 
     222            GBDATA *gb_result_entry     = get_result_entry(gb_main); 
     223            if (!gb_result_entry) error = GB_await_error(); 
     224            else { 
     225                const char *result = GB_read_char_pntr(gb_result_entry); 
     226 
     227                if (strcmp(result, "ok") != 0) { 
     228                    error = GBS_global_string("Error from server: %s", result); 
     229                } 
     230            } 
     231        } 
     232 
     233        GB_close(gb_main); 
     234    } 
     235    return error; 
     236} 
     237 
     238static void show_help() { 
     239    fputs("arb_db_server 2.0 -- ARB-database server\n", stdout); 
     240    fputs("options:\n", stdout); 
     241    fputs("    -h         show this help\n", stdout); 
     242    fputs("    -A         use ASCII-DB-version\n", stdout); 
     243    fputs("    -Ccmd      execute command 'cmd' on running server\n", stdout); 
     244    fputs("               known command are:\n", stdout); 
     245    fputs("                   ping      test if server is up (crash or failure if not)\n", stdout); 
     246    fputs("                   save      save the database (use -d to change name)\n", stdout); 
     247    fputs("                   shutdown  shutdown running arb_db_server\n", stdout); 
     248    arb_print_server_params(); 
     249} 
     250 
     251int main(int argc, char **argv) { 
     252    arb_params *params = arb_trace_argv(&argc, argv); 
     253 
     254    bool        help  = false; 
     255    const char *cmd   = NULL;  // run server command 
     256 
     257    GB_ERROR error = NULL; 
     258    while (argc>1 && !error) { 
     259        const char *arg = argv[1]; 
     260        if (arg[0] == '-') { 
     261            char sw_char = arg[1]; 
     262            switch (sw_char) { 
     263                case 'h': help     = true; break; 
     264                case 'C': cmd      = arg+2; break; 
     265                case 'A': savemode = "a"; break; 
     266 
     267                default: 
     268                    error = GBS_global_string("Unknown switch '-%c'", sw_char); 
     269                    break; 
     270            } 
     271        } 
     272        else { 
     273            error = GBS_global_string("Unknown argument '%s'", arg); 
     274        } 
     275        argc--; argv++; 
     276    } 
     277 
     278    if (!error) { 
     279        if (help) show_help(); 
     280        else if (cmd) error = run_command(*params, cmd); 
     281        else          error = run_server(*params); 
     282    } 
     283 
    58284    if (error) { 
    59         printf("Cannot start your arb_db_server: %s\n", error); 
    60         return (-1); 
    61     } 
    62  
    63     printf("Database is saved after every transaction (one . one save)\n"); 
    64  
    65     for (timer = LOOPS; timer>0; timer--) { // the server ends 
    66         GB_begin_transaction(gb_main); 
    67         clock = GB_read_clock(gb_main); 
    68         if (GB_read_clients(gb_main) >0) { 
    69             timer = LOOPS; 
    70         } 
    71         GB_commit_transaction(gb_main); 
    72         if (clock>last_update) { 
    73             last_update = clock; 
    74             printf("."); fflush(stdout); 
    75             GB_save(gb_main, 0, "b"); 
    76             timer = LOOPS; 
    77         } 
    78         GBCMS_accept_calls(gb_main, false); 
    79     } 
    80     return (0); 
    81 } 
    82  
     285        fprintf(stderr, "Error in arb_db_server: %s\n", error); 
     286        return EXIT_FAILURE; 
     287    } 
     288    return EXIT_SUCCESS; 
     289} 
     290 
     291// -------------------------------------------------------------------------------- 
     292 
     293#ifdef UNIT_TESTS 
     294#ifndef TEST_UNIT_H 
     295#include <test_unit.h> 
     296#endif 
     297 
     298#include <unistd.h> 
     299#include <sys/wait.h> 
     300 
     301inline GB_ERROR valgrinded_system(const char *cmdline) { 
     302    char *cmddup = strdup(cmdline); 
     303    make_valgrinded_call(cmddup); 
     304 
     305    GB_ERROR error = GBK_system(cmddup); 
     306    free(cmddup); 
     307    return error; 
     308} 
     309 
     310#define RUN_TOOL(cmdline)            valgrinded_system(cmdline) 
     311#define TEST_RUN_TOOL(cmdline)       TEST_ASSERT_NO_ERROR(RUN_TOOL(cmdline)) 
     312#define TEST_RUN_TOOL_FAILS(cmdline) TEST_ASSERT_ERROR(RUN_TOOL(cmdline)) 
     313 
     314inline bool server_is_down(const char *tcp) { 
     315    char     *ping_cmd = strdup(GBS_global_string("arb_db_server -T%s -Cping", tcp)); 
     316    GB_ERROR  error    = GBK_system(ping_cmd); // causes a crash in called command (as long as server is not up) 
     317    free(ping_cmd); 
     318    return error; 
     319} 
     320 
     321static int entry_changed_cb_called = 0; 
     322static void entry_changed_cb(GBDATA *, int*, GB_CB_TYPE) { 
     323    entry_changed_cb_called++; 
     324} 
     325 
     326void TEST_SLOW_dbserver() { 
     327    // MISSING_TEST(TEST_dbserver); 
     328    TEST_RUN_TOOL("arb_db_server -h"); 
     329    TEST_RUN_TOOL_FAILS("arb_db_server -X"); 
     330    TEST_RUN_TOOL_FAILS("arb_db_server brzl"); 
     331 
     332    char *sock = strdup(GB_path_in_ARBHOME("UNIT_TESTER/sockets/dbserver.socket")); 
     333    char *tcp        = GBS_global_string_copy(":%s", sock); 
     334    char *db         = strdup(GB_path_in_ARBHOME("UNIT_TESTER/run/TEST_loadsave.arb")); 
     335 
     336    char *shutdown_cmd = strdup(GBS_global_string("arb_db_server -T%s -Cshutdown", tcp)); 
     337 
     338// #define DEBUG_SERVER // uncomment when debugging server manually 
     339 
     340#if !defined(DEBUG_SERVER) 
     341    TEST_ASSERT(server_is_down(tcp)); 
     342#endif 
     343 
     344    pid_t child_pid = fork(); 
     345    if (child_pid) { // parent ("the client") 
     346        bool down = true; 
     347        int max_wait = 2000/50; 
     348        while (down) { 
     349            GB_usleep(25*1000); 
     350            down = server_is_down(tcp); 
     351            TEST_ASSERT(max_wait-->0); 
     352        } 
     353        // ok - server is up 
     354 
     355        { 
     356            char *bad_cmd = strdup(GBS_global_string("arb_db_server -T%s -Cbad", tcp)); 
     357            TEST_RUN_TOOL_FAILS(bad_cmd); 
     358            free(bad_cmd); 
     359        } 
     360 
     361        { // now directly connect to server 
     362            GB_shell  shell; 
     363            GB_ERROR  error      = NULL; 
     364            GBDATA   *gb_main1   = GB_open(tcp, "rw"); // first client 
     365            if (!gb_main1) error = GB_await_error(); 
     366            else { 
     367                GBDATA *gb_main2     = GB_open(tcp, "rw"); // second client 
     368                if (!gb_main2) error = GB_await_error(); 
     369                else { 
     370                    // test existing entries 
     371                    { 
     372                        GB_transaction  ta(gb_main1); 
     373                        GBDATA         *gb_ecoli = GB_search(gb_main1, "/extended_data/extended/ali_16s/data", GB_FIND); 
     374 
     375                        TEST_ASSERT(gb_ecoli); 
     376 
     377                        const char *ecoli = GB_read_char_pntr(gb_ecoli); 
     378                        if (!ecoli) error = GB_await_error(); 
     379                        else        TEST_ASSERT_EQUAL(GBS_checksum(ecoli, 0, NULL), 0x3558760cU); 
     380                    } 
     381                    { 
     382                        GB_transaction  ta(gb_main2); 
     383                        GBDATA         *gb_alitype = GB_search(gb_main2, "/presets/alignment/alignment_type", GB_FIND); 
     384 
     385                        TEST_ASSERT(gb_alitype); 
     386 
     387                        const char *alitype = GB_read_char_pntr(gb_alitype); 
     388                        if (!alitype) error = GB_await_error(); 
     389                        else        TEST_ASSERT_EQUAL(alitype, "rna"); 
     390                    } 
     391 
     392                    // test value written in client1 is changed in client2 
     393                    const char *test_entry   = "/tmp/TEST_SLOW_dbserver"; 
     394                    const char *test_content = "hello world!"; 
     395 
     396                    GBDATA *gb_entry1; 
     397                    GBDATA *gb_entry2; 
     398 
     399                    if (!error) { 
     400                        GB_transaction ta(gb_main1); 
     401 
     402                        gb_entry1             = GB_search(gb_main1, test_entry, GB_STRING); 
     403                        if (!gb_entry1) error = GB_await_error(); 
     404                        else error            = GB_write_string(gb_entry1, test_content); 
     405                    } 
     406 
     407                    if (!error) { // test value arrived in other client 
     408                        GB_transaction ta(gb_main2); 
     409 
     410                        gb_entry2             = GB_search(gb_main2, test_entry, GB_STRING); 
     411                        if (!gb_entry2) error = GB_await_error(); 
     412                        else { 
     413                            const char *read_content = GB_read_char_pntr(gb_entry2); 
     414                            if (!read_content) { 
     415                                error = GB_await_error(); 
     416                            } 
     417                            else { 
     418                                TEST_ASSERT_EQUAL(read_content, test_content); 
     419                            } 
     420                        } 
     421                    } 
     422 
     423                    // test change-callback gets triggered 
     424                    if (!error) { 
     425 
     426                        TEST_ASSERT_EQUAL(entry_changed_cb_called, 0); 
     427                        { 
     428                            GB_transaction ta(gb_entry1); 
     429                            error = GB_add_callback(gb_entry1, GB_CB_CHANGED, entry_changed_cb, NULL); 
     430                        } 
     431                        TEST_ASSERT_EQUAL(entry_changed_cb_called, 0); 
     432                        { 
     433                            GB_transaction ta(gb_entry2); 
     434                            GB_touch(gb_entry2); 
     435                        } 
     436                        TEST_ASSERT_EQUAL(entry_changed_cb_called, 0); // client1 did not transact yet 
     437                        delete new GB_transaction(gb_main1); 
     438                        TEST_ASSERT_EQUAL(entry_changed_cb_called, 1);  
     439                    } 
     440 
     441                    GB_close(gb_main2); 
     442                } 
     443                GB_close(gb_main1); 
     444            } 
     445 
     446            TEST_ASSERT_NO_ERROR(error); 
     447        } 
     448 
     449        // test remote save 
     450        { 
     451            char *savename = strdup(GB_path_in_ARBHOME("UNIT_TESTER/run/TEST_arbdbserver_save.arb")); 
     452            char *expected = strdup(GB_path_in_ARBHOME("UNIT_TESTER/run/TEST_arbdbserver_save_expected.arb")); 
     453            char *save_cmd = strdup(GBS_global_string("arb_db_server -T%s -Csave -d%s", tcp, savename)); 
     454            char *bad_savecmd = strdup(GBS_global_string("arb_db_server -T%s -Csave", tcp)); 
     455 
     456            TEST_RUN_TOOL(save_cmd); 
     457            TEST_ASSERT(GB_is_regularfile(savename)); 
     458 
     459// #define TEST_AUTO_UPDATE 
     460#if defined(TEST_AUTO_UPDATE) 
     461            TEST_COPY_FILE(savename, expected); 
     462#else // !defined(TEST_AUTO_UPDATE) 
     463            TEST_ASSERT_FILES_EQUAL(savename, expected); 
     464#endif 
     465            TEST_ASSERT_ZERO_OR_SHOW_ERRNO(GB_unlink(savename)); 
     466 
     467            TEST_RUN_TOOL_FAILS(bad_savecmd); 
     468             
     469            free(bad_savecmd); 
     470            free(save_cmd); 
     471            free(expected); 
     472            free(savename); 
     473        } 
     474 
     475        // stop the server 
     476        TEST_RUN_TOOL(shutdown_cmd); 
     477        while (child_pid != wait(NULL)) {} // wait for child to finish = wait for server to terminate 
     478    } 
     479    else { // child ("the server") 
     480#if !defined(DEBUG_SERVER) 
     481        GB_usleep(100*1000); 
     482        TEST_RUN_TOOL(GBS_global_string("arb_db_server -T%s -d%s -A", tcp, db)); // start the server (in ASCII-mode) 
     483#endif 
     484        exit(EXIT_SUCCESS); 
     485    } 
     486 
     487    TEST_ASSERT(server_is_down(tcp)); 
     488     
     489#define socket_disappeared(sock) (GB_time_of_file(sock) == 0) 
     490 
     491    TEST_ASSERT(socket_disappeared(sock)); 
     492 
     493    free(shutdown_cmd); 
     494    free(db); 
     495    free(tcp); 
     496    free(sock); 
     497} 
     498 
     499#endif // UNIT_TESTS 
     500 
     501// -------------------------------------------------------------------------------- 
  • branches/dev_elmar/DIST/DI_main.cxx

    r7190 r8224  
    5454 
    5555    GB_shell shell; 
    56     AW_root *aw_root = AWT_create_root(".arb_prop/dist.arb", "ARB_DIST"); 
     56    AW_root *aw_root = AWT_create_root("dist.arb", "ARB_DIST"); 
    5757 
    5858    { 
  • branches/dev_elmar/DIST/DI_matr.cxx

    r7945 r8224  
    298298                if (!gb_species) { 
    299299                    if (show_warnings) { 
    300                         aw_message(GB_export_errorf("Species '%s' found in tree '%s' but NOT in database.", 
    301                                                     species_in_sort_tree[i], sort_tree_name)); 
     300                        aw_message(GBS_global_string("Species '%s' found in tree '%s' but NOT in database.", 
     301                                                     species_in_sort_tree[i], sort_tree_name)); 
    302302                    } 
    303303                    unknown_species_in_tree++; 
     
    340340 
    341341    if (unknown_species_in_tree && show_warnings) { 
    342         aw_message(GB_export_errorf("We found %i species in tree '%s' which are not in database.\n" 
    343                                     "This does not affect the current calculation, but you should think about it.", 
    344                                     unknown_species_in_tree, sort_tree_name)); 
     342        aw_message(GBS_global_string("We found %i species in tree '%s' which are not in database.\n" 
     343                                     "This does not affect the current calculation, but you should think about it.", 
     344                                     unknown_species_in_tree, sort_tree_name)); 
    345345    } 
    346346 
     
    14621462 
    14631463    aws->create_menu("Properties", "P", AWM_ALL); 
    1464     aws->insert_menu_topic("frame_props", "Frame ...",                                 "F", "props_frame.hlp", AWM_ALL, AW_POPUP, (AW_CL)AW_preset_window, 0); 
    1465     aws->insert_menu_topic("save_props",  "Save Properties (in ~/.arb_prop/dist.arb)", "S", "savedef.hlp",     AWM_ALL, (AW_CB)AW_save_properties, 0, 0); 
     1464    aws->insert_menu_topic("frame_props", "Frame ...",                  "F", "props_frame.hlp", AWM_ALL, AW_POPUP,(AW_CL)AW_preset_window,  0); 
     1465    aws->insert_menu_topic("save_props",  "Save Properties (dist.arb)", "S", "savedef.hlp",     AWM_ALL,          (AW_CB)AW_save_properties, 0, 0); 
    14661466 
    14671467    aws->insert_help_topic("help ...", "h", "dist.hlp", AWM_ALL, (AW_CB)AW_POPUP_HELP, (AW_CL)"dist.hlp", 0); 
  • branches/dev_elmar/DIST/Makefile

    r7945 r8224  
    1010        DI_main.o \ 
    1111        DI_matr.o \ 
    12         DI_mldist.o \ 
    1312        DI_protdist.o \ 
    1413        DI_save_matr.o \ 
     
    237236DI_matr.o: $(ARBHOME)/INCLUDE/test_global.h 
    238237 
    239 DI_mldist.o: di_matr.hxx 
    240 DI_mldist.o: di_mldist.hxx 
    241 DI_mldist.o: $(ARBHOME)/INCLUDE/ad_prot.h 
    242 DI_mldist.o: $(ARBHOME)/INCLUDE/ad_t_prot.h 
    243 DI_mldist.o: $(ARBHOME)/INCLUDE/AliView.hxx 
    244 DI_mldist.o: $(ARBHOME)/INCLUDE/AP_matrix.hxx 
    245 DI_mldist.o: $(ARBHOME)/INCLUDE/AP_pro_a_nucs.hxx 
    246 DI_mldist.o: $(ARBHOME)/INCLUDE/AP_seq_simple_pro.hxx 
    247 DI_mldist.o: $(ARBHOME)/INCLUDE/AP_sequence.hxx 
    248 DI_mldist.o: $(ARBHOME)/INCLUDE/AP_Tree.hxx 
    249 DI_mldist.o: $(ARBHOME)/INCLUDE/arb_assert.h 
    250 DI_mldist.o: $(ARBHOME)/INCLUDE/arb_core.h 
    251 DI_mldist.o: $(ARBHOME)/INCLUDE/arb_error.h 
    252 DI_mldist.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    253 DI_mldist.o: $(ARBHOME)/INCLUDE/arb_progress.h 
    254 DI_mldist.o: $(ARBHOME)/INCLUDE/arb_string.h 
    255 DI_mldist.o: $(ARBHOME)/INCLUDE/ARB_Tree.hxx 
    256 DI_mldist.o: $(ARBHOME)/INCLUDE/arbdb.h 
    257 DI_mldist.o: $(ARBHOME)/INCLUDE/arbdb_base.h 
    258 DI_mldist.o: $(ARBHOME)/INCLUDE/arbdbt.h 
    259 DI_mldist.o: $(ARBHOME)/INCLUDE/arbtools.h 
    260 DI_mldist.o: $(ARBHOME)/INCLUDE/attributes.h 
    261 DI_mldist.o: $(ARBHOME)/INCLUDE/aw_base.hxx 
    262 DI_mldist.o: $(ARBHOME)/INCLUDE/aw_color_groups.hxx 
    263 DI_mldist.o: $(ARBHOME)/INCLUDE/aw_msg.hxx 
    264 DI_mldist.o: $(ARBHOME)/INCLUDE/downcast.h 
    265 DI_mldist.o: $(ARBHOME)/INCLUDE/dupstr.h 
    266 DI_mldist.o: $(ARBHOME)/INCLUDE/smartptr.h 
    267 DI_mldist.o: $(ARBHOME)/INCLUDE/test_global.h 
    268  
    269238DI_protdist.o: di_matr.hxx 
    270239DI_protdist.o: di_protdist.hxx 
  • branches/dev_elmar/EDIT4/ED4_main.cxx

    r7945 r8224  
    464464 
    465465const char *ED4_propertyName(int mode) { 
    466     // mode == 0 -> alignment specific          (e.g. ".arb_prop/edit4_ali_16s.arb") 
    467     // mode == 1 -> alignment-type specific     (e.g. ".arb_prop/edit4_rna.arb") 
    468     // mode == 2 -> unspecific (normal)         (always ".arb_prop/edit4.arb") 
     466    // mode == 0 -> alignment specific          (e.g. "edit4_ali_16s.arb") 
     467    // mode == 1 -> alignment-type specific     (e.g. "edit4_rna.arb") 
     468    // mode == 2 -> unspecific (normal)         (always "edit4.arb") 
    469469    // 
    470470    // Note : result is only valid until next call 
     
    472472    e4_assert(mode >= 0 && mode <= 2); 
    473473 
    474     if (mode == 2) return ".arb_prop/edit4.arb"; 
     474    if (mode == 2) return "edit4.arb"; 
    475475 
    476476    static char *ali_name = 0; 
     
    485485    } 
    486486 
    487     sprintf(result, ".arb_prop/edit4_%s.arb", mode == 0 ? ali_name : ali_type); 
     487    sprintf(result, "edit4_%s.arb", mode == 0 ? ali_name : ali_type); 
    488488 
    489489    return result; 
  • branches/dev_elmar/EDIT4/ED4_root.cxx

    r7945 r8224  
    3737#include <aw_advice.hxx> 
    3838#include <arb_version.h> 
     39#include <arb_file.h> 
    3940#include <arbdbt.h> 
    4041 
     
    15871588        int default_mode = -1; 
    15881589        for (int mode = 0; mode <= 2; ++mode) { 
    1589             if (0 == strcmp(AW_root::property_DB_fullname(ED4_propertyName(mode)), db_name)) { 
     1590            if (strcmp(GB_path_in_arbprop(ED4_propertyName(mode)), db_name) == 0) { 
    15901591                default_mode = mode; 
    15911592                break; 
     
    15941595        e4_assert(default_mode != -1); 
    15951596 
    1596         const char *entry = GBS_global_string("Save loaded Properties (~/%s)", db_name); 
     1597        const char *entry = GBS_global_string("Save loaded Properties (%s)", ED4_propertyName(default_mode)); 
    15971598        awmm->insert_menu_topic("save_loaded_props", entry, "l", "e4_defaults.hlp", AWM_ALL, ED4_save_properties, (AW_CL)default_mode, 0); 
    15981599        SEP________________________SEP; 
     
    16011602            char hotkey[] = "x"; 
    16021603            hotkey[0]     = "Pta"[mode]; 
    1603             entry         = GBS_global_string("Save %sProperties (~/%s)", entry_type[mode], ED4_propertyName(mode)); 
     1604            entry         = GBS_global_string("Save %sProperties (%s)", entry_type[mode], ED4_propertyName(mode)); 
    16041605            awmm->insert_menu_topic(tag[mode], entry, hotkey, "e4_defaults.hlp", AWM_ALL, ED4_save_properties, (AW_CL)mode, 0); 
    16051606        } 
     
    18981899 
    18991900    for (int mode = 0; !propname && mode <= 2; ++mode) { // search for properties-database 
    1900         const char *fullprop = AW_root::property_DB_fullname(ED4_propertyName(mode)); 
     1901        const char *fullprop = GB_path_in_arbprop(ED4_propertyName(mode)); 
    19011902        if (mode == 2 || GB_is_regularfile(fullprop)) { 
    19021903            freedup(propname, fullprop); 
  • branches/dev_elmar/EDIT4/ED4_search.cxx

    r7945 r8224  
    809809    // awars to save/load search parameters: 
    810810    { 
    811         char *dir = GBS_global_string_copy("%s/.arb_prop/search_settings", GB_getenvHOME()); 
     811        char *dir = strdup(GB_path_in_arbprop("search_settings")); 
    812812        AW_create_fileselection_awars(root, ED4_SEARCH_SAVE_BASE, dir, ".asp", "noname.asp"); 
    813813        root->awar(ED4_SEARCH_SAVE_BASE"/directory")->write_string(dir); 
  • branches/dev_elmar/EDIT4/Makefile

    r7945 r8224  
    678678ED4_root.o: $(ARBHOME)/INCLUDE/arb_core.h 
    679679ED4_root.o: $(ARBHOME)/INCLUDE/arb_error.h 
     680ED4_root.o: $(ARBHOME)/INCLUDE/arb_file.h 
    680681ED4_root.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    681682ED4_root.o: $(ARBHOME)/INCLUDE/arb_progress.h 
  • branches/dev_elmar/EDIT4/graph_aligner_gui.cxx

    r7944 r8224  
    185185 
    186186        // start pt server if necessary 
    187         gb_error = arb_look_and_start_server(AISC_MAGIC_NUMBER, ptnam.str().c_str(), GLOBAL_gb_main); 
     187        gb_error = arb_look_and_start_server(AISC_MAGIC_NUMBER, ptnam.str().c_str()); 
    188188        if (gb_error) { 
    189189            std::stringstream tmp; 
  • branches/dev_elmar/GDE/Makefile

    r7428 r8224  
    33        CLUSTAL/CLUSTAL.dummy  \ 
    44        SUPPORT/SUPPORT.dummy \ 
    5         MOLPHY/MOLPHY.dummy \ 
    65        AxML/AxML.dummy \ 
    76        RAxML/RAxML.dummy \ 
     
    5453endif 
    5554 
    56 proto: MOLPHY/MOLPHY.proto 
    57  
    5855depends: $(ARCHS:.dummy=.depend) 
    5956 
  • branches/dev_elmar/GDEHELP/ARB_GDEmenus.source

    r7492 r8224  
    5151menumeta:X 
    5252#include <fastdnaml.genmenu> 
    53 #include <molphy.genmenu> 
    5453 
    5554menu:Phylogeny max. Likelyhood 
  • branches/dev_elmar/GDEHELP/Makefile.helpfiles

    r7409 r8224  
    3636 
    3737$(GENHELPDEST)/dnaml.help: $(AXML_HELP) $(FASTDNAML_DOC) 
    38         ./genhelptree.sh $@ "$(subst .help,,$(notdir $@))" $(HEADER) $^ 
    39  
    40 PROTML=$(GDE)/MOLPHY/doc 
    41 PROTML_DOC_NAMES=protml protml_cli 
    42 PROTML_DOCS=$(addsuffix .doc,$(addprefix $(PROTML)/,$(PROTML_DOC_NAMES))) 
    43  
    44 $(GENHELPDEST)/protml.help: $(PROTML_DOCS) 
    4538        ./genhelptree.sh $@ "$(subst .help,,$(notdir $@))" $(HEADER) $^ 
    4639 
  • branches/dev_elmar/GENOM/EXP_main.cxx

    r7945 r8224  
    114114} 
    115115 
    116 static void EXP_run_pgt(AW_window *aww, AW_CL cl_gb_main, AW_CL) { 
    117     AW_system(aww, (GBDATA*)cl_gb_main, "arb_pgt &", 0); 
     116static void EXP_run_pgt(AW_window *aww, AW_CL, AW_CL) { 
     117    AW_system(aww, "arb_pgt &", 0); 
    118118} 
    119119 
     
    137137 
    138138        awm->insert_separator(); 
    139         AWMIMT("pgt", "Proteom Genome Toolkit (PGT)", "P", "pgt.hlp", AWM_ALL, EXP_run_pgt, (AW_CL)gb_main, 0); 
     139        AWMIMT("pgt", "Proteom Genome Toolkit (PGT)", "P", "pgt.hlp", AWM_ALL, EXP_run_pgt, 0, 0); 
    140140    } 
    141141    if (submenu) awm->close_sub_menu(); 
  • branches/dev_elmar/GENOM/GEN_map.cxx

    r7945 r8224  
    16261626    insert_menu_topic("gene_options",      "Options",  "O", "gene_options.hlp", AWM_ALL, AW_POPUP, (AW_CL)GEN_create_options_window, 0); 
    16271627    insert_menu_topic("gene_nds",          "NDS ( Select Gene Information ) ...",      "N", "props_nds.hlp",   AWM_ALL, AW_POPUP, (AW_CL)GEN_open_nds_window, (AW_CL)gb_main); 
    1628     insert_menu_topic("gene_save_props",   "Save Defaults (in ~/.arb_prop/ntree.arb)", "D", "savedef.hlp", AWM_ALL, (AW_CB) AW_save_properties, 0, 0); 
     1628    insert_menu_topic("gene_save_props",   "Save Defaults (ntree.arb)", "D", "savedef.hlp", AWM_ALL, (AW_CB) AW_save_properties, 0, 0); 
    16291629 
    16301630    // --------------------- 
  • branches/dev_elmar/MERGE/MG_main.cxx

    r7621 r8224  
    1919#include <aw_file.hxx> 
    2020#include <aw_msg.hxx> 
     21#include <aw_root.hxx> 
     22 
    2123#include <arb_progress.h> 
    22 #include <aw_root.hxx> 
    23  
     24#include <arb_file.h> 
    2425 
    2526GBDATA *GLOBAL_gb_merge = NULL; 
     
    240241        } 
    241242 
    242         awm->insert_menu_topic("save_props", "Save properties (to ~/.arb_prop/ntree.arb)",              "p", "savedef.hlp", AWM_ALL,      (AW_CB)AW_save_properties, 0, 0); 
     243        awm->insert_menu_topic("save_props", "Save properties (ntree.arb)", "p", "savedef.hlp", AWM_ALL, (AW_CB)AW_save_properties, 0, 0); 
    243244 
    244245        awm->button_length(30); 
     
    325326#endif 
    326327            progress.subtitle("DATABASE I"); 
    327             GLOBAL_gb_merge             = GBT_open(merge, "rw", "$(ARBHOME)/lib/pts/*"); 
     328            GLOBAL_gb_merge             = GBT_open(merge, "rw"); 
    328329            if (!GLOBAL_gb_merge) error = GB_await_error(); 
    329330            else { 
     
    349350 
    350351                if (!error) { 
    351                     GLOBAL_gb_dest             = GBT_open(main, open_mode, "$(ARBHOME)/lib/pts/*"); 
     352                    GLOBAL_gb_dest             = GBT_open(main, open_mode); 
    352353                    if (!GLOBAL_gb_dest) error = GB_await_error(); 
    353354#if defined(DEBUG) 
  • branches/dev_elmar/MERGE/Makefile

    r7945 r8224  
    213213MG_main.o: $(ARBHOME)/INCLUDE/arb_core.h 
    214214MG_main.o: $(ARBHOME)/INCLUDE/arb_error.h 
     215MG_main.o: $(ARBHOME)/INCLUDE/arb_file.h 
    215216MG_main.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    216217MG_main.o: $(ARBHOME)/INCLUDE/arb_progress.h 
  • branches/dev_elmar/MULTI_PROBE/MP_noclass.cxx

    r7945 r8224  
    932932const char *MP_probe_pt_look_for_server() { 
    933933    const char *server_tag = GBS_ptserver_tag(mp_gl_awars.ptserver); 
    934     GB_ERROR    error      = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag, 0); 
     934    GB_ERROR    error      = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag); 
    935935 
    936936    if (error) { 
  • branches/dev_elmar/Makefile

    r7984 r8224  
    10391039                SERVERCNTRL/SERVERCNTRL.a \ 
    10401040                SL/HELIX/HELIX.a \ 
     1041                SL/PTCLEAN/PTCLEAN.a \ 
    10411042 
    10421043ARCHS_PROBE_LINK = \ 
     
    12291230SL/NEIGHBOURJOIN/NEIGHBOURJOIN.dummy:   links_non_perl 
    12301231SL/PRONUC/PRONUC.dummy:                 links_non_perl 
     1232SL/PTCLEAN/PTCLEAN.dummy:               links_non_perl link_db 
    12311233SL/SEQUENCE/SEQUENCE.dummy:             links_non_perl 
    12321234SL/TRANSLATE/TRANSLATE.dummy:           links_non_perl 
     
    14521454                $(ARCHS_PT_SERVER:.a=.proto) \ 
    14531455                SERVERCNTRL/SERVERCNTRL.proto \ 
    1454                 GDE/GDE.proto \ 
    14551456                SL/SL.proto \ 
    14561457 
     
    18371838        ALIV3/ALIV3.test \ 
    18381839        ARB_GDE/ARB_GDE.test \ 
    1839         AWT/AWT.test \ 
    18401840        CONSENSUS_TREE/CONSENSUS_TREE.test \ 
    1841         DBSERVER/DBSERVER.test \ 
    18421841        DIST/DIST.test \ 
    18431842        EISPACK/EISPACK.test \ 
     
    18521851        PHYLO/PHYLO.test \ 
    18531852        PRIMER_DESIGN/PRIMER_DESIGN.test \ 
    1854         PROBE/PROBE.test \ 
    18551853        PROBE_DESIGN/PROBE_DESIGN.test \ 
    18561854        ptpan/PROBE.test \ 
     
    19041902 
    19051903UNITS_TESTED = \ 
     1904        DBSERVER/DBSERVER.test \ 
    19061905        GENOM_IMPORT/GENOM_IMPORT.test \ 
     1906        AWT/AWT.test \ 
    19071907        CORE/CORE.test \ 
    19081908        SL/TREEDISP/TREEDISP.test \ 
     
    19191919        CONVERTALN/CONVERTALN.test \ 
    19201920        SL/SEQIO/SEQIO.test \ 
     1921        SL/PTCLEAN/PTCLEAN.test \ 
     1922        PROBE/PROBE.test \ 
    19211923 
    19221924TESTED_UNITS_MANUAL = \ 
  • branches/dev_elmar/NALIGNER/ali_other_stuff.hxx

    r6381 r8224  
    1212#define ALI_OTHER_STUFF_HXX 
    1313 
     14#ifndef PT_COM_H 
    1415#include <PT_com.h> 
    15  
     16#endif 
     17#ifndef ATTRIBUTES_H 
     18#include <attributes.h> 
     19#endif 
     20#ifndef SERVER_H 
    1621extern "C" { 
    1722#include <server.h> 
    1823} 
    19  
     24#endif 
     25#ifndef ARBDBT_H 
    2026#include <arbdbt.h> 
     27#endif 
     28#ifndef SERVERCNTRL_H 
    2129#include <servercntrl.h> 
     30#endif 
    2231 
    2332#else 
  • branches/dev_elmar/NALIGNER/ali_pt.cxx

    r7945 r8224  
    9696 
    9797 
    98 int ALI_PT::open(char *servername, GBDATA *gb_main) 
    99 { 
    100     if (arb_look_and_start_server(AISC_MAGIC_NUMBER, servername, gb_main)) { 
     98int ALI_PT::open(char *servername) 
     99{ 
     100    if (arb_look_and_start_server(AISC_MAGIC_NUMBER, servername)) { 
    101101        ali_message ("Cannot contact Probe bank server"); 
    102102        return -1; 
     
    152152 
    153153        ali_message("Connecting to PT server"); 
    154         if (open(context->servername, context->gb_main) != 0) { 
     154        if (open(context->servername) != 0) { 
    155155            ali_fatal_error("Can't connect to PT server"); 
    156156        } 
  • branches/dev_elmar/NALIGNER/ali_pt.hxx

    r7945 r8224  
    7878    char *get_family_member(char *specified_family, unsigned long number); 
    7979    char *get_extension_member(char *specified_family, unsigned long number); 
    80     int open(char *servername, GBDATA *gb_main); 
     80    int open(char *servername); 
    8181    void close(); 
    8282 
  • branches/dev_elmar/NAMES/Makefile

    r7945 r8224  
    3636names.o: $(ARBHOME)/INCLUDE/arb_core.h 
    3737names.o: $(ARBHOME)/INCLUDE/arb_error.h 
     38names.o: $(ARBHOME)/INCLUDE/arb_file.h 
    3839names.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    3940names.o: $(ARBHOME)/INCLUDE/arb_string.h 
  • branches/dev_elmar/NAMES/names.cxx

    r7945 r8224  
    1414 
    1515#include <arbdb.h> 
     16#include <arb_file.h> 
    1617#include <names_prototypes.h> 
    1718#include <server.h> 
  • branches/dev_elmar/NAMES_COM/names_extern.c

    r7415 r8224  
    44 
    55struct sigcontext; 
     6#include <attributes.h> 
    67#include "C/server.h" 
    78 
  • branches/dev_elmar/NTREE/ColumnStat_2_gnuplot.cxx

    r7945 r8224  
    2020#include <aw_root.hxx> 
    2121#include <arbdbt.h> 
     22#include <arb_file.h> 
    2223 
    2324#include <unistd.h> 
  • branches/dev_elmar/NTREE/Makefile

    r7945 r8224  
    203203ad_trees.o: $(ARBHOME)/INCLUDE/arb_core.h 
    204204ad_trees.o: $(ARBHOME)/INCLUDE/arb_error.h 
     205ad_trees.o: $(ARBHOME)/INCLUDE/arb_file.h 
    205206ad_trees.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    206207ad_trees.o: $(ARBHOME)/INCLUDE/arb_strbuf.h 
     
    348349ColumnStat_2_gnuplot.o: $(ARBHOME)/INCLUDE/arb_core.h 
    349350ColumnStat_2_gnuplot.o: $(ARBHOME)/INCLUDE/arb_error.h 
     351ColumnStat_2_gnuplot.o: $(ARBHOME)/INCLUDE/arb_file.h 
    350352ColumnStat_2_gnuplot.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    351353ColumnStat_2_gnuplot.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    511513NT_extern.o: $(ARBHOME)/INCLUDE/arb_core.h 
    512514NT_extern.o: $(ARBHOME)/INCLUDE/arb_error.h 
     515NT_extern.o: $(ARBHOME)/INCLUDE/arb_file.h 
    513516NT_extern.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    514517NT_extern.o: $(ARBHOME)/INCLUDE/arb_progress.h 
     
    667670NT_main.o: $(ARBHOME)/INCLUDE/arb_core.h 
    668671NT_main.o: $(ARBHOME)/INCLUDE/arb_error.h 
     672NT_main.o: $(ARBHOME)/INCLUDE/arb_file.h 
    669673NT_main.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    670674NT_main.o: $(ARBHOME)/INCLUDE/arb_progress.h 
  • branches/dev_elmar/NTREE/NT_cb.cxx

    r7945 r8224  
    119119 
    120120void NT_system_cb(AW_window *aww, AW_CL cl_command, AW_CL cl_auto_help_file) { 
    121     AW_system(aww, GLOBAL_gb_main, (const char *)cl_command, (const char *)cl_auto_help_file); 
     121    AW_system(aww, (const char *)cl_command, (const char *)cl_auto_help_file); 
    122122} 
    123123 
  • branches/dev_elmar/NTREE/NT_edconf.cxx

    r7945 r8224  
    642642#define CONFNAME "default_configuration" 
    643643 
    644 void nt_start_editor_on_configuration(AW_window *aww) { 
     644static void nt_start_editor_on_configuration(AW_window *aww) { 
    645645    aww->hide(); 
    646     char *cn = aww->get_root()->awar(AWAR_CONFIGURATION)->read_string(); 
    647     char *com = (char *)GBS_global_string("arb_edit4 -c '%s' &", cn); 
    648     GBCMC_system(GLOBAL_gb_main, com); 
    649     delete cn; 
     646 
     647    const char *cn  = aww->get_root()->awar(AWAR_CONFIGURATION)->read_char_pntr(); 
     648    const char *com = GBS_global_string("arb_edit4 -c '%s' &", cn); 
     649 
     650    aw_message_if(GBK_system(com)); 
    650651} 
    651652 
     
    673674void NT_start_editor_on_tree(AW_window *, AW_CL cl_use_species_aside, AW_CL) { 
    674675    GB_ERROR error = nt_create_configuration(0, nt_get_current_tree_root(), CONFNAME, (int)cl_use_species_aside); 
    675     if (!error) { 
    676         int res = GBCMC_system(GLOBAL_gb_main, "arb_edit4 -c "CONFNAME" &"); 
    677         if (res != 0) error = GB_await_error(); 
    678     } 
     676    if (!error) error = GBK_system("arb_edit4 -c " CONFNAME " &"); 
    679677    aw_message_if(error); 
    680678} 
  • branches/dev_elmar/NTREE/NT_extern.cxx

    r7945 r8224  
    5252#include <arb_strbuf.h> 
    5353#include <arb_strarray.h> 
     54#include <arb_file.h> 
    5455 
    5556#include <arb_version.h> 
     
    677678        nt_assert(GB_is_privatefile(mail_file, false)); 
    678679 
    679         error = GB_system(command); 
     680        error = GBK_system(command); 
    680681        GB_unlink_or_warn(mail_file, &error); 
    681682 
     
    15711572            AWMIMT("!toggle_focus",  "Toggle focus follows mouse", "f", 0,            AWM_ALL, NT_toggle_focus_policy,             0, 0); 
    15721573            SEP________________________SEP(); 
    1573             AWMIMT("save_props", "Save properties (in ~/.arb_prop/ntree.arb)", "S", "savedef.hlp", AWM_ALL, (AW_CB) AW_save_properties, 0, 0); 
     1574            AWMIMT("save_props", "Save properties (ntree.arb)", "S", "savedef.hlp", AWM_ALL, (AW_CB) AW_save_properties, 0, 0); 
    15741575        } 
    15751576    } 
  • branches/dev_elmar/NTREE/NT_main.cxx

    r7945 r8224  
    2525#include <aw_file.hxx> 
    2626#include <aw_msg.hxx> 
    27 #include <arb_progress.h> 
    2827#include <aw_root.hxx> 
    2928 
    3029#include <arbdbt.h> 
    3130#include <adGene.h> 
     31 
    3232#include <arb_version.h> 
     33#include <arb_progress.h> 
     34#include <arb_file.h> 
    3335 
    3436using namespace std; 
     
    203205static ARB_ERROR load_and_startup_main_window(AW_root *aw_root, const char *autorun_macro) { 
    204206    char *db_server = aw_root->awar(AWAR_DB_PATH)->read_string(); 
    205     GLOBAL_gb_main  = GBT_open(db_server, "rw", "$(ARBHOME)/lib/pts/*"); 
     207    GLOBAL_gb_main  = GBT_open(db_server, "rw"); 
    206208 
    207209    ARB_ERROR error; 
     
    514516 
    515517int main(int argc, char **argv) { 
    516     unsigned long mtime = GB_time_of_file("$(ARBHOME)/lib/message"); 
    517     unsigned long rtime = GB_time_of_file("$(HOME)/.arb_prop/msgtime"); 
    518     if (mtime > rtime) { 
    519         AW_edit("${ARBHOME}/lib/message"); 
    520         system("touch ${HOME}/.arb_prop/msgtime"); 
    521     } 
    522518    aw_initstatus(); 
    523519    GB_set_verbose(); 
    524520 
    525521    GB_shell shell; 
    526     AW_root *aw_root = AWT_create_root(".arb_prop/ntree.arb", "ARB_NT"); 
     522    AW_root *aw_root = AWT_create_root("ntree.arb", "ARB_NT"); 
    527523 
    528524    GLOBAL_NT.awr = aw_root; 
     525 
     526    { 
     527        char *message = strdup(GB_path_in_ARBLIB("message")); 
     528        char *stamp   = strdup(GB_path_in_arbprop("msgtime")); 
     529        if (GB_time_of_file(message)>GB_time_of_file(stamp)) { 
     530            AW_edit(message); 
     531            system(GBS_global_string("touch %s", stamp)); 
     532        } 
     533        free(stamp); 
     534        free(message); 
     535    } 
    529536 
    530537    // create some early awars 
     
    559566            if (mode == EXPORT) { 
    560567                MG_create_all_awars(aw_root, AW_ROOT_DEFAULT, ":", "noname.arb"); 
    561                 GLOBAL_gb_merge = GBT_open(":", "rw", 0); 
     568                GLOBAL_gb_merge = GBT_open(":", "rw"); 
    562569                if (!GLOBAL_gb_merge) { 
    563570                    error = GB_await_error(); 
     
    568575#endif // DEBUG 
    569576 
    570                     GLOBAL_gb_dest = GBT_open("noname.arb", "cw", 0); 
     577                    GLOBAL_gb_dest = GBT_open("noname.arb", "cw"); 
    571578#if defined(DEBUG) 
    572579                    AWT_announce_db_to_browser(GLOBAL_gb_dest, "New database (noname.arb)"); 
  • branches/dev_elmar/NTREE/ad_ext.cxx

    r7945 r8224  
    176176                else { 
    177177                    GB_clear_error(); 
    178                     type             = GBT_read_string(gb_ali, "_TYPE"); 
    179                     if (!type) error = GB_await_error(); 
     178                    type = GBT_read_string(gb_ali, "_TYPE"); 
     179                    if (!type) { 
     180                        if (GB_have_error()) { 
     181                            error = GB_await_error(); 
     182                        } 
     183                        else { 
     184                            type = strdup(""); 
     185                        } 
     186                    } 
    180187                } 
    181188            } 
  • branches/dev_elmar/NTREE/ad_trees.cxx

    r7945 r8224  
    2323#include <arbdbt.h> 
    2424#include <arb_strbuf.h> 
     25#include <arb_file.h> 
    2526 
    2627#define nt_assert(bed) arb_assert(bed) 
  • branches/dev_elmar/PARSIMONY/PARS_main.cxx

    r7945 r8224  
    13891389    awm->create_menu("Properties", "r", AWM_ALL); 
    13901390    { 
    1391         awm->insert_menu_topic("props_menu",  "Menu: Colors and Fonts ...",              "M", "props_frame.hlp",      AWM_ALL, AW_POPUP, (AW_CL)AW_preset_window,       0); 
    1392         awm->insert_menu_topic("props_tree",  "Tree: Colors and Fonts ...",              "C", "pars_props_data.hlp",  AWM_ALL, AW_POPUP, (AW_CL)AW_create_gc_window,    (AW_CL)aw_gc_manager); 
    1393         awm->insert_menu_topic("props_tree2", "Tree: Settings ...",                      "T", "nt_tree_settings.hlp", AWM_ALL, AW_POPUP, (AW_CL)NT_create_tree_setting, (AW_CL)ntw); 
    1394         awm->insert_menu_topic("props_kl",    "KERN. LIN ...",                           "K", "kernlin.hlp",          AWM_ALL, AW_POPUP, (AW_CL)create_kernighan_window, 0); 
    1395         awm->insert_menu_topic("save_props",  "Save Defaults (in ~/.arb_prop/pars.arb)", "D", "savedef.hlp",          AWM_ALL, (AW_CB)AW_save_properties, 0, 0); 
     1391        awm->insert_menu_topic("props_menu",  "Menu: Colors and Fonts ...", "M", "props_frame.hlp",      AWM_ALL, AW_POPUP,(AW_CL)AW_preset_window,        0); 
     1392        awm->insert_menu_topic("props_tree",  "Tree: Colors and Fonts ...", "C", "pars_props_data.hlp",  AWM_ALL, AW_POPUP,(AW_CL)AW_create_gc_window,     (AW_CL)aw_gc_manager); 
     1393        awm->insert_menu_topic("props_tree2", "Tree: Settings ...",         "T", "nt_tree_settings.hlp", AWM_ALL, AW_POPUP,(AW_CL)NT_create_tree_setting, (AW_CL)ntw); 
     1394        awm->insert_menu_topic("props_kl",    "KERN. LIN ...",              "K", "kernlin.hlp",          AWM_ALL, AW_POPUP,(AW_CL)create_kernighan_window, 0); 
     1395        awm->insert_menu_topic("save_props",  "Save Defaults (pars.arb)",   "D", "savedef.hlp",          AWM_ALL,          (AW_CB)AW_save_properties,      0, 0); 
    13961396    } 
    13971397    awm->button_length(5); 
     
    16651665 
    16661666    GB_shell shell; 
    1667     AW_root *aw_root      = AWT_create_root(".arb_prop/pars.arb", "ARB_PARS"); 
     1667    AW_root *aw_root      = AWT_create_root("pars.arb", "ARB_PARS"); 
    16681668    AD_map_viewer_aw_root = aw_root; 
    16691669 
     
    17061706    } 
    17071707 
    1708     GLOBAL_gb_main = GBT_open(db_server, "rw", 0); 
     1708    GLOBAL_gb_main = GBT_open(db_server, "rw"); 
    17091709    if (!GLOBAL_gb_main) aw_popup_exit(GB_await_error()); // exits 
    17101710 
  • branches/dev_elmar/PGT/arb_interface.cxx

    r7190 r8224  
    7676 
    7777/**************************************************************************** 
    78 *  ESTABLISH A CONNECTION TO THE ARB CONFIGURATION 
    79 ****************************************************************************/ 
    80 int CONFIG_connect() 
    81 { 
    82     global_gbConfig= NULL; // ABFRAGE !!! 
    83     global_CONFIG_available= false; 
    84  
    85     // GET ARB HOME 
    86     const char *home= GB_getenvHOME(); 
    87     char *buffer= (char *)malloc(1025 * sizeof(char)); 
    88     sprintf(buffer,"%s/%s", home, PGT_CONFIG_FILE); 
    89  
    90     // OPEN CONFIG FILE 
    91     global_gbConfig= GB_open(buffer, "rwc"); 
    92     if(!global_gbConfig) 
    93     { 
    94         free(buffer); 
    95         return 0; 
    96     } 
    97  
    98     // DISABLE TRANSACTIONS 
    99     GB_no_transaction(global_gbConfig); 
    100  
    101     global_CONFIG_available= true; 
    102  
    103     free(buffer); 
    104     return 1; 
     78 *  ESTABLISH A CONNECTION TO THE ARB CONFIGURATION 
     79 ****************************************************************************/ 
     80void CONFIG_connect() { 
     81    char *config    = strdup(GB_path_in_arbprop(PGT_CONFIG_NAME)); 
     82    global_gbConfig = GB_open(config, "rwc");                // OPEN CONFIG FILE 
     83    free(config); 
     84 
     85    if (global_gbConfig) GB_no_transaction(global_gbConfig); // DISABLE TRANSACTIONS 
     86    global_CONFIG_available = global_gbConfig; 
    10587} 
    10688 
     
    10991*  CLOSE THE ARB CONFIGURATION 
    11092****************************************************************************/ 
    111 int CONFIG_disconnect() 
    112 { 
    113     if(global_gbConfig) 
    114     { 
    115         // GET ARB HOME 
    116         const char *home= GB_getenvHOME(); 
    117         char *buffer= (char *)malloc(1025 * sizeof(char)); 
    118         sprintf(buffer,"%s/%s", home, PGT_CONFIG_FILE); 
    119  
    120         GB_save(global_gbConfig, buffer, "a"); 
    121  
     93void CONFIG_disconnect() { 
     94    if (global_gbConfig) { 
     95        GB_save_in_arbprop(global_gbConfig, PGT_CONFIG_NAME, "a"); 
    12296        GB_close(global_gbConfig); 
    123  
    124         free(buffer); 
    125     } 
    126  
    127     global_CONFIG_available= false; 
    128     global_gbConfig= NULL; 
    129  
    130     return 1; 
     97    } 
     98    global_CONFIG_available = false; 
     99    global_gbConfig         = NULL; 
    131100} 
    132101 
  • branches/dev_elmar/PGT/arb_interface.hxx

    r7190 r8224  
    2828#define AWAR_ORGANISM_NAME   "tmp/focus/organism_name" 
    2929 
    30 // PATH TO THE PGT CONFIG FILE 
    31 #define PGT_CONFIG_FILE            ".arb_prop/pgt.arb" 
     30// NAME OF THE PGT CONFIG FILE 
     31#define PGT_CONFIG_NAME            "pgt.arb" 
    3232 
    3333// CONFIG DATABASE ENTRIES 
     
    5656int ARB_disconnect(); 
    5757 
    58 int CONFIG_connect(); 
    59 int CONFIG_disconnect(); 
     58void CONFIG_connect(); 
     59void CONFIG_disconnect(); 
    6060 
    6161bool ARB_begin_transaction(); 
  • branches/dev_elmar/PHYLO/PH_display.cxx

    r7661 r8224  
    209209 
    210210    if (!device) return; 
    211     if (!markerline) return; 
    212211     
    213212    GB_transaction dummy(PHDATA::ROOT->gb_main); 
  • branches/dev_elmar/PHYLO/PH_main.cxx

    r7945 r8224  
    474474    // Properties menu 
    475475    awm->create_menu("Properties", "P"); 
    476     awm->insert_menu_topic("props_menu", "Menu: Colors and Fonts ...",                 "M", "props_frame.hlp",   AWM_ALL, AW_POPUP, (AW_CL)AW_preset_window,   0); 
    477     awm->insert_menu_topic("props_data", "Data: Colors and Fonts ...",                 "D", "ph_props_data.hlp", AWM_ALL, AW_POPUP, (AW_CL)AW_create_gc_window, (AW_CL)gcmiddle); 
    478     awm->insert_menu_topic("save_props", "Save Properties (in ~/.arb_prop/phylo.arb)", "S", "savedef.hlp",       AWM_ALL,          (AW_CB)AW_save_properties,    0, 0); 
     476    awm->insert_menu_topic("props_menu", "Menu: Colors and Fonts ...",  "M", "props_frame.hlp",   AWM_ALL, AW_POPUP,(AW_CL)AW_preset_window,    0); 
     477    awm->insert_menu_topic("props_data", "Data: Colors and Fonts ...",  "D", "ph_props_data.hlp", AWM_ALL, AW_POPUP,(AW_CL)AW_create_gc_window, (AW_CL)gcmiddle); 
     478    awm->insert_menu_topic("save_props", "Save Properties (phylo.arb)", "S", "savedef.hlp",       AWM_ALL,          (AW_CB)AW_save_properties,  0, 0); 
    479479 
    480480 
     
    549549 
    550550    GB_shell shell; 
    551     AW_root  *aw_root = AWT_create_root(".arb_prop/phylo.arb", "ARB_PHYLO"); 
     551    AW_root  *aw_root = AWT_create_root("phylo.arb", "ARB_PHYLO"); 
    552552    PH_root  *ph_root = new PH_root; 
    553553    GB_ERROR  error   = ph_root->open(db_server); 
  • branches/dev_elmar/PROBE/Makefile

    r7945 r8224  
    2727 
    2828proto: 
    29         ../AISC_MKPTPS/aisc_mkpt -G -E -z -A -w pt_prototypes.h $(OBJECTS:.o=.cxx) probe_tree.h >pt_prototypes.h.tmp 
     29        ../AISC_MKPTPS/aisc_mkpt -P -G -E -z -A -w pt_prototypes.h $(OBJECTS:.o=.cxx) probe_tree.h >pt_prototypes.h.tmp 
    3030        ../SOURCE_TOOLS/mv_if_diff pt_prototypes.h.tmp pt_prototypes.h 
    3131 
     
    5757PT_buildtree.o: $(ARBHOME)/INCLUDE/arb_assert.h 
    5858PT_buildtree.o: $(ARBHOME)/INCLUDE/arb_core.h 
     59PT_buildtree.o: $(ARBHOME)/INCLUDE/arb_defs.h 
    5960PT_buildtree.o: $(ARBHOME)/INCLUDE/arb_error.h 
     61PT_buildtree.o: $(ARBHOME)/INCLUDE/arb_file.h 
    6062PT_buildtree.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    6163PT_buildtree.o: $(ARBHOME)/INCLUDE/arb_progress.h 
     
    7375PT_buildtree.o: $(ARBHOME)/INCLUDE/static_assert.h 
    7476PT_buildtree.o: $(ARBHOME)/INCLUDE/test_global.h 
     77PT_buildtree.o: $(ARBHOME)/INCLUDE/test_unit.h 
    7578 
    7679PT_debug.o: probe.h 
     
    202205PT_main.o: $(ARBHOME)/INCLUDE/arb_assert.h 
    203206PT_main.o: $(ARBHOME)/INCLUDE/arb_core.h 
     207PT_main.o: $(ARBHOME)/INCLUDE/arb_defs.h 
    204208PT_main.o: $(ARBHOME)/INCLUDE/arb_error.h 
     209PT_main.o: $(ARBHOME)/INCLUDE/arb_file.h 
    205210PT_main.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    206211PT_main.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    218223PT_main.o: $(ARBHOME)/INCLUDE/PT_server.h 
    219224PT_main.o: $(ARBHOME)/INCLUDE/PT_server_prototypes.h 
     225PT_main.o: $(ARBHOME)/INCLUDE/ptclean.h 
    220226PT_main.o: $(ARBHOME)/INCLUDE/server.h 
    221227PT_main.o: $(ARBHOME)/INCLUDE/servercntrl.h 
     
    287293PT_prefixtree.o: $(ARBHOME)/INCLUDE/arb_core.h 
    288294PT_prefixtree.o: $(ARBHOME)/INCLUDE/arb_error.h 
     295PT_prefixtree.o: $(ARBHOME)/INCLUDE/arb_file.h 
    289296PT_prefixtree.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    290297PT_prefixtree.o: $(ARBHOME)/INCLUDE/arb_string.h 
  • branches/dev_elmar/PROBE/PT_buildtree.cxx

    r7945 r8224  
    1313#include "probe_tree.h" 
    1414#include "pt_prototypes.h" 
     15#include <arb_defs.h> 
     16#include <arb_file.h> 
    1517 
    1618#include <arb_progress.h> 
     
    1820#include <unistd.h> 
    1921 
    20 POS_TREE *build_pos_tree (POS_TREE *pt, int anfangs_pos, int apos, int RNS_nr, unsigned int end) 
    21 { 
    22     static POS_TREE       *pthelp, *pt_next; 
    23     unsigned int i, j; 
    24     int          height = 0, anfangs_apos_ref, anfangs_rpos_ref, RNS_nr_ref; 
    25     pthelp = pt; 
    26     i = anfangs_pos; 
    27     while (PT_read_type(pthelp) == PT_NT_NODE) {    // now we got an inner node 
    28         if ((pt_next = PT_read_son_stage_1(psg.ptmain, pthelp, (PT_BASES)psg.data[RNS_nr].data[i])) == NULL) { 
    29                             // there is no son of that type -> simply add the new son to that path // 
    30             if (pthelp == pt) { // now we create a new root structure (size will change) 
    31                 PT_create_leaf(psg.ptmain, &pthelp, (PT_BASES)psg.data[RNS_nr].data[i], anfangs_pos, apos, RNS_nr); 
    32                 return pthelp;  // return the new root 
    33             } 
    34             else { 
    35                 PT_create_leaf(psg.ptmain, &pthelp, (PT_BASES)psg.data[RNS_nr].data[i], anfangs_pos, apos, RNS_nr); 
    36                 return pt;  // return the old root 
    37             } 
     22// AISC_MKPT_PROMOTE: class DataLoc; 
     23 
     24static POS_TREE *build_pos_tree(POS_TREE *const root, const DataLoc& loc) { 
     25    POS_TREE *at = root; 
     26    int       height = 0; 
     27 
     28    while (PT_read_type(at) == PT_NT_NODE) {    // now we got an inner node 
     29        POS_TREE *pt_next = PT_read_son_stage_1(at, loc[height]); 
     30        if (!pt_next) { // there is no son of that type -> simply add the new son to that path // 
     31            bool atRoot = (at == root); 
     32            PT_create_leaf(&at, loc[height], loc); 
     33            return atRoot ? at : root; // inside tree return old root, otherwise new root has been created 
    3834        } 
    3935        else {            // go down the tree 
    40             pthelp = pt_next; 
     36            at = pt_next; 
    4137            height++; 
    42             i++; 
    43             if (i >= end) {     // end of sequence reached -> change node to chain and add 
    44                         // should never be reached, because of the terminal symbol 
    45                         // of each sequence 
    46                 if (PT_read_type(pthelp) == PT_NT_CHAIN) 
    47                     pthelp = PT_add_to_chain(psg.ptmain, pthelp, RNS_nr, apos, anfangs_pos); 
     38 
     39            if (loc.is_shorther_than(height)) { 
     40                // end of sequence reached -> change node to chain and add 
     41                // should never be reached, because of the terminal symbol of each sequence (@@@ this IS reached - even with unittestdb) 
     42                if (PT_read_type(at) == PT_NT_CHAIN) { 
     43                    PT_add_to_chain(at, loc); 
     44                } 
    4845                // if type == node then forget it 
    49                 return pt; 
    50             } 
    51         } 
    52     } 
    53             // type == leaf or chain 
    54     if (PT_read_type(pthelp) == PT_NT_CHAIN) {      // old chain reached 
    55         pthelp = PT_add_to_chain(psg.ptmain, pthelp, RNS_nr, apos, anfangs_pos); 
    56         return pt; 
    57     } 
    58     anfangs_rpos_ref = PT_read_rpos(psg.ptmain, pthelp); // change leave to node and create two sons 
    59     anfangs_apos_ref = PT_read_apos(psg.ptmain, pthelp); 
    60     RNS_nr_ref = PT_read_name(psg.ptmain, pthelp); 
    61     j = anfangs_rpos_ref + height; 
    62  
    63     while (psg.data[RNS_nr].data[i] == psg.data[RNS_nr_ref].data[j]) {  // creates nodes until sequences are different 
    64                                         // type != nt_node 
    65         if (PT_read_type(pthelp) == PT_NT_CHAIN) {          // break 
    66             pthelp = PT_add_to_chain(psg.ptmain, pthelp, RNS_nr, apos, anfangs_pos); 
    67             return pt; 
     46                return root; 
     47            } 
     48        } 
     49    } 
     50 
     51    // type == leaf or chain 
     52    if (PT_read_type(at) == PT_NT_CHAIN) {      // old chain reached 
     53        PT_add_to_chain(at, loc); 
     54        return root; 
     55    } 
     56 
     57    // change leave to node and create two sons 
     58 
     59    const DataLoc loc_ref(at); 
     60 
     61    while (loc[height] == loc_ref[height]) {  // creates nodes until sequences are different 
     62        // type != nt_node 
     63        if (PT_read_type(at) == PT_NT_CHAIN) {  
     64            PT_add_to_chain(at, loc); 
     65            return root; 
    6866        } 
    6967        if (height >= PT_POS_TREE_HEIGHT) { 
    70             if (PT_read_type(pthelp) == PT_NT_LEAF) { 
    71                 pthelp = PT_leaf_to_chain(psg.ptmain, pthelp); 
    72             } 
    73             pthelp = PT_add_to_chain(psg.ptmain, pthelp, RNS_nr, apos, anfangs_pos); 
    74             return pt; 
    75         } 
    76         if (((i + 1) >= end) && (j + 1 >= (unsigned)(psg.data[RNS_nr_ref].size))) { // end of both sequences 
    77             return pt; 
    78         } 
    79         pthelp = PT_change_leaf_to_node(psg.ptmain, pthelp); // change tip to node and append two new leafs 
    80         if (i + 1 >= end) {                 // end of source sequence reached 
    81             pthelp = PT_create_leaf(psg.ptmain, &pthelp, (PT_BASES)psg.data[RNS_nr_ref].data[j], 
    82                     anfangs_rpos_ref, anfangs_apos_ref, RNS_nr_ref); 
    83             return pt; 
    84         } 
    85         if (j + 1 >= (unsigned)(psg.data[RNS_nr_ref].size)) {       // end of reference sequence 
    86             pthelp = PT_create_leaf(psg.ptmain, &pthelp, (PT_BASES)psg.data[RNS_nr].data[i], anfangs_pos, apos, RNS_nr); 
    87             return pt; 
    88         } 
    89         pthelp = PT_create_leaf(psg.ptmain, &pthelp, (PT_BASES)psg.data[RNS_nr].data[i], anfangs_rpos_ref, anfangs_apos_ref, RNS_nr_ref); 
    90                     // dummy leaf just to create a new node; may become a chain 
    91         i++; 
    92         j++; 
     68            if (PT_read_type(at) == PT_NT_LEAF) { 
     69                at = PT_leaf_to_chain(at); 
     70            } 
     71            PT_add_to_chain(at, loc); 
     72            return root; 
     73        } 
     74 
     75        bool loc_done = loc.is_shorther_than(height+1); 
     76        bool ref_done = loc_ref.is_shorther_than(height+1); 
     77 
     78        if (ref_done && loc_done) return root; // end of both sequences 
     79 
     80        at = PT_change_leaf_to_node(at); // change tip to node and append two new leafs 
     81        if (loc_done) { // end of source sequence reached 
     82            PT_create_leaf(&at, loc_ref[height], loc_ref); 
     83            return root; 
     84        } 
     85        if (ref_done) { // end of reference sequence 
     86            PT_create_leaf(&at, loc[height], loc); 
     87            return root; 
     88        } 
     89        at = PT_create_leaf(&at, loc[height], loc_ref); // dummy leaf just to create a new node; may become a chain 
    9390        height++; 
    9491    } 
     92 
     93     
     94     
    9595    if (height >= PT_POS_TREE_HEIGHT) { 
    96         if (PT_read_type(pthelp) == PT_NT_LEAF) 
    97             pthelp = PT_leaf_to_chain(psg.ptmain, pthelp); 
    98         pthelp = PT_add_to_chain(psg.ptmain, pthelp, RNS_nr, apos, anfangs_pos); 
    99         return pt; 
    100     } 
    101     if (PT_read_type(pthelp) == PT_NT_CHAIN) { 
    102         pthelp = PT_add_to_chain(psg.ptmain, pthelp, RNS_nr, apos, anfangs_pos); 
     96        if (PT_read_type(at) == PT_NT_LEAF) at = PT_leaf_to_chain(at); 
     97        PT_add_to_chain(at, loc); 
     98        return root; 
     99    } 
     100    if (PT_read_type(at) == PT_NT_CHAIN) { 
     101        // not covered by test - but looks similar to case in top-loop 
     102        PT_add_to_chain(at, loc); 
    103103    } 
    104104    else { 
    105         pthelp = PT_change_leaf_to_node(psg.ptmain, pthelp); // Blatt loeschen 
    106         PT_create_leaf(psg.ptmain, &pthelp, (PT_BASES)psg.data[RNS_nr].data[i], anfangs_pos, apos, RNS_nr); // zwei neue Blaetter 
    107         PT_create_leaf(psg.ptmain, &pthelp, (PT_BASES)psg.data[RNS_nr_ref].data[j], anfangs_rpos_ref, anfangs_apos_ref, RNS_nr_ref); 
    108     } 
    109     return pt; 
    110 } 
     105        at = PT_change_leaf_to_node(at);             // delete leaf 
     106        PT_create_leaf(&at, loc[height], loc); // two new leafs 
     107        PT_create_leaf(&at, loc_ref[height], loc_ref); 
     108    } 
     109    return root; 
     110} 
     111 
    111112 
    112113inline void get_abs_align_pos(char *seq, int &pos) 
     
    147148} 
    148149 
    149 long PTD_save_partial_tree(FILE *out, PTM2 *ptmain, POS_TREE * node, char *partstring, int partsize, long pos, long *ppos, ARB_ERROR& error) { 
     150long PTD_save_partial_tree(FILE *out, POS_TREE * node, char *partstring, int partsize, long pos, long *ppos, ARB_ERROR& error) { 
    150151    if (partsize) { 
    151         POS_TREE *son = PT_read_son(ptmain, node, (PT_BASES)partstring[0]); 
     152        POS_TREE *son = PT_read_son(node, (PT_BASES)partstring[0]); 
    152153        if (son) { 
    153             pos = PTD_save_partial_tree(out, ptmain, son, partstring+1, partsize-1, pos, ppos, error); 
     154            pos = PTD_save_partial_tree(out, son, partstring+1, partsize-1, pos, ppos, error); 
    154155        } 
    155156    } 
    156157    else { 
    157         PTD_clear_fathers(ptmain, node); 
     158        PTD_clear_fathers(node); 
    158159        long r_pos; 
    159160        int blocked; 
     
    165166            fflush(stdout); 
    166167#endif 
    167             r_pos = PTD_write_leafs_to_disk(out, ptmain, node, pos, ppos, &blocked, error); 
     168            r_pos = PTD_write_leafs_to_disk(out, node, pos, ppos, &blocked, error); 
    168169            if (r_pos > pos) pos = r_pos; 
    169170        } 
     
    221222            psg.ptmain->stage1 = 1;             // enter stage 1 
    222223 
    223             pt = PT_create_leaf(psg.ptmain, NULL, PT_N, 0, 0, 0);  // create main node 
    224             pt = PT_change_leaf_to_node(psg.ptmain, pt); 
     224            pt = PT_create_leaf(NULL, PT_N, DataLoc(0, 0, 0));  // create main node 
     225            pt = PT_change_leaf_to_node(pt); 
    225226            psg.stat.cut_offs = 0;                  // statistic information 
    226227            GB_begin_transaction(psg.gb_main); 
     
    267268 
    268269                    int abs_align_pos = psize-1; 
    269                     for (int j = psg.data[i].size - 1; j >= 0; j--, abs_align_pos--) { 
     270                    for (int j = psg.data[i].get_size() - 1; j >= 0; j--, abs_align_pos--) { 
    270271                        get_abs_align_pos(align_abs, abs_align_pos); // may result in neg. abs_align_pos (seems to happen if sequences are short < 214bp ) 
    271272                        if (abs_align_pos < 0) break; // -> in this case abort 
    272273 
    273                         if (partsize && (*partstring != psg.data[i].data[j] || strncmp(partstring, psg.data[i].data+j, partsize))) continue; 
    274                         if (ptd_string_shorter_than(psg.data[i].data+j, 9)) continue; 
    275  
    276                         pt = build_pos_tree(pt, j, abs_align_pos, i, psg.data[i].size); 
     274                        if (partsize && (*partstring != psg.data[i].get_data()[j] || strncmp(partstring, psg.data[i].get_data()+j, partsize))) continue; 
     275                        if (ptd_string_shorter_than(psg.data[i].get_data()+j, 9)) continue; 
     276 
     277                        pt = build_pos_tree(pt, DataLoc(i, abs_align_pos, j)); 
    277278                    } 
    278279                    free(align_abs); 
     
    280281                    ++data_progress; 
    281282                } 
    282                 pos = PTD_save_partial_tree(out, psg.ptmain, pt, partstring, partsize, pos, &last_obj, error); 
     283                pos = PTD_save_partial_tree(out, pt, partstring, partsize, pos, &last_obj, error); 
    283284                if (error) break; 
    284285 
     
    292293            if (!error) { 
    293294                if (partsize) { 
    294                     pos = PTD_save_partial_tree(out, psg.ptmain, pt, NULL, 0, pos, &last_obj, error); 
     295                    pos = PTD_save_partial_tree(out, pt, NULL, 0, pos, &last_obj, error); 
    295296#ifdef PTM_DEBUG 
    296297                    PTM_debug_mem(); 
     
    377378        } 
    378379        else { 
    379             error = PTD_read_leafs_from_disk(tname, psg.ptmain, &psg.pt); 
     380            error = PTD_read_leafs_from_disk(tname, &psg.pt); 
    380381            fclose(in); 
    381382        } 
     
    385386} 
    386387 
     388// -------------------------------------------------------------------------------- 
     389 
     390#ifdef UNIT_TESTS 
     391#ifndef TEST_UNIT_H 
     392#include <test_unit.h> 
     393#endif 
     394 
     395int main(int argc, const char*argv[]); 
     396void NOTEST_SLOW_maybe_build_tree() { 
     397    // does only test sth if DB is present. 
     398 
     399    const char *dbarg      = "-D" "extra_pt_src.arb"; 
     400    const char *testDB     = dbarg+2; 
     401    const char *resultPT   = "extra_pt_src.arb.pt"; 
     402    const char *expectedPT = "extra_pt_src.arb_expected.pt"; 
     403    bool        exists     = GB_is_regularfile(testDB); 
     404 
     405    if (exists) { 
     406        const char *argv[] = { 
     407            "fake_pt_server", 
     408            "-build", 
     409            dbarg, 
     410        }; 
     411 
     412#if 1 
     413        // build 
     414        int res = main(ARRAY_ELEMS(argv), argv); 
     415        TEST_ASSERT_EQUAL(res, EXIT_SUCCESS); 
     416#endif 
     417 
     418// #define TEST_AUTO_UPDATE 
     419#if defined(TEST_AUTO_UPDATE) 
     420        TEST_COPY_FILE(resultPT, expectedPT); 
     421#else // !defined(TEST_AUTO_UPDATE) 
     422        TEST_ASSERT_FILES_EQUAL(resultPT, expectedPT); 
     423#endif 
     424    } 
     425} 
     426 
     427#endif // UNIT_TESTS 
     428 
     429// -------------------------------------------------------------------------------- 
  • branches/dev_elmar/PROBE/PT_debug.cxx

    r7945 r8224  
    4747            basecnt = 0; 
    4848            for (i=PT_QU; i<PT_B_MAX; i++) { 
    49                 if ((pt_help = PT_read_son(psg.ptmain, pt, (PT_BASES)i))) 
     49                if ((pt_help = PT_read_son(pt, (PT_BASES)i))) 
    5050                { 
    5151                    basecnt++; 
     
    6161            ptds->chains[height]++; 
    6262            psg.height = 0; 
    63             PT_forwhole_chain(psg.ptmain, pt, PT_chain_count()); 
     63            PT_forwhole_chain(pt, PT_chain_count()); 
    6464            if (psg.height >= DEBUG_MAX_CHAIN_SIZE) psg.height = DEBUG_MAX_CHAIN_SIZE; 
    6565            ptds->chainsizes[psg.height][height]++; 
     
    6868            if (ptds->chaincount<20) { 
    6969                printf("\n\n\n\n"); 
    70                 PT_forwhole_chain(psg.ptmain, pt, PTD_chain_print()); 
     70                PT_forwhole_chain(pt, PTD_chain_print()); 
    7171            } 
    7272            break; 
     
    140140        struct probe_input_data& data = psg.data[leaf.name]; 
    141141 
    142         PT_BASES b = (PT_BASES)data.data[leaf.rpos]; 
    143  
    144         printf("%s[%c] %s apos=%i rpos=%i\n", prefix, PT_BASES_2_char(b), data.name, leaf.apos, leaf.rpos); 
     142        PT_BASES b = (PT_BASES)data.get_data()[leaf.rpos]; 
     143 
     144        printf("%s[%c] %s apos=%i rpos=%i\n", prefix, PT_BASES_2_char(b), data.get_name(), leaf.apos, leaf.rpos); 
    145145        return 0; 
    146146    } 
     
    152152    switch (PT_read_type(pt)) { 
    153153        case PT_NT_NODE: 
    154             for (int i = PT_N; i<PT_B_MAX; i++) { 
     154            for (int i = PT_QU; i<PT_B_MAX; i++) { 
    155155                PT_BASES  b   = PT_BASES(i); 
    156                 POS_TREE *son = PT_read_son(psg.ptmain, pt, b); 
     156                POS_TREE *son = PT_read_son(pt, b); 
    157157                if (son) { 
    158                     char *subPrefix = GBS_global_string_copy("%s%c", prefix, PT_BASES_2_char(b)); 
     158                    char *subPrefix = GBS_global_string_copy("%s%c", prefix, b == PT_QU ? '.' : PT_BASES_2_char(b)); 
    159159                    PT_dump_POS_TREE_recursive(son, subPrefix); 
    160160                    free(subPrefix); 
     
    163163            break; 
    164164        case PT_NT_LEAF: { 
    165             PT_dump_leaf dump_leaf(prefix); 
    166             dump_leaf(DataLoc(psg.ptmain, pt)); 
    167             break; 
    168         } 
    169         case PT_NT_CHAIN: 
    170             PT_forwhole_chain(psg.ptmain, pt, PT_dump_leaf(prefix)); 
    171             break; 
     165            char         *subPrefix = GBS_global_string_copy("{l} %s", prefix); 
     166            PT_dump_leaf  dump_leaf(subPrefix); 
     167            dump_leaf(DataLoc(pt)); 
     168            free(subPrefix); 
     169            break; 
     170        } 
     171        case PT_NT_CHAIN: { 
     172            char *subPrefix = GBS_global_string_copy("{c} %s", prefix); 
     173            PT_forwhole_chain(pt, PT_dump_leaf(subPrefix)); 
     174            free(subPrefix); 
     175            break; 
     176        } 
    172177        default: 
    173178            printf("%s [unhandled]\n", prefix); 
     
    183188    // Debug function for all stages 
    184189#if defined(DEBUG) 
    185     long             i; 
    186     PTM2        *ptmain = psg.ptmain; 
    187190    if (!node) printf("Zero node\n"); 
    188     PT_READ_PNTR(&node->data, i); 
    189     printf("node father 0x%lx\n", i); 
     191 
     192    { 
     193        long i; 
     194        PT_READ_PNTR(&node->data, i); 
     195        printf("node father 0x%lx\n", i); 
     196    } 
     197 
    190198    switch (PT_read_type(node)) { 
    191         case PT_NT_LEAF: 
    192             printf("leaf %i:%i,%i\n", PT_read_name(ptmain, node), 
    193                    PT_read_rpos(ptmain, node), PT_read_apos(ptmain, node)); 
    194             break; 
     199        case PT_NT_LEAF: { 
     200            DataLoc loc(node); 
     201            printf("leaf %i:%i,%i\n", loc.name, loc.rpos, loc.apos); 
     202            break; 
     203        } 
    195204        case PT_NT_NODE: 
    196             for (i = 0; i < PT_B_MAX; i++) { 
    197                 printf("%6li:0x%p\n", i, PT_read_son(ptmain, node, (PT_BASES)i)); 
     205            for (long i = 0; i < PT_B_MAX; i++) { 
     206                printf("%6li:0x%p\n", i, PT_read_son(node, (PT_BASES)i)); 
    198207            } 
    199208            break; 
    200209        case PT_NT_CHAIN: 
    201210            printf("chain:\n"); 
    202             PT_forwhole_chain(ptmain, node, PTD_chain_print()); 
     211            PT_forwhole_chain(node, PTD_chain_print()); 
    203212            break; 
    204213        case PT_NT_SAVED: 
  • branches/dev_elmar/PROBE/PT_etc.cxx

    r7999 r8224  
    7272} 
    7373 
    74 const char *virt_name(PT_probematch *ml) 
     74const char *virt_name(PT_probematch *ml)  
    7575{ 
    7676    // get the name with a virtual function 
    7777    if (gene_flag) { 
    78         const gene_struct *gs = get_gene_struct_by_internal_gene_name(psg.data[ml->name].name); 
     78        const gene_struct *gs = get_gene_struct_by_internal_gene_name(psg.data[ml->name].get_name()); 
    7979        return gs ? gs->get_arb_species_name() : "<cantResolveName>"; 
    8080    } 
    8181    else { 
    82         pt_assert(psg.data[ml->name].name); 
    83         return psg.data[ml->name].name; 
    84     } 
    85 } 
    86  
    87 const char *virt_fullname(PT_probematch * ml) 
     82        pt_assert(psg.data[ml->name].get_name()); 
     83        return psg.data[ml->name].get_name(); 
     84    } 
     85} 
     86 
     87const char *virt_fullname(PT_probematch * ml)  
    8888{ 
    8989    if (gene_flag) { 
    90         const gene_struct *gs = get_gene_struct_by_internal_gene_name(psg.data[ml->name].name); 
     90        const gene_struct *gs = get_gene_struct_by_internal_gene_name(psg.data[ml->name].get_name()); 
    9191        return gs ? gs->get_arb_gene_name() : "<cantResolveGeneFullname>"; 
    9292    } 
    9393    else { 
    94         return psg.data[ml->name].fullname ?  psg.data[ml->name].fullname : "<undefinedFullname>"; 
     94        return psg.data[ml->name].get_fullname() ?  psg.data[ml->name].get_fullname() : "<undefinedFullname>"; 
    9595    } 
    9696} 
     
    163163    // clear 'is_group' 
    164164    for (int i = 0; i < psg.data_count; i++) { 
    165         psg.data[i].is_group = 0; // Note: probes are designed for species with is_group == 1 
     165        psg.data[i].set_group_state(0); // Note: probes are designed for species with is_group == 1 
    166166    } 
    167167    locs->group_count = 0; 
     
    212212                const char *checksum = get_list_part(checksums, coff); 
    213213                // if sequence checksum changed since pt server was updated -> not found 
    214                 found                = atol(checksum) == psg.data[idx].checksum; 
     214                found                = atol(checksum) == psg.data[idx].get_checksum(); 
    215215            } 
    216216            else { 
     
    219219 
    220220            if (found) { 
    221                 psg.data[idx].is_group = 1; // mark 
     221                psg.data[idx].set_group_state(1); // mark 
    222222                locs->group_count++; 
    223223            } 
  • branches/dev_elmar/PROBE/PT_family.cxx

    r7945 r8224  
    2222inline void aisc_link(dll_public *dll, PT_family_list *family)   { aisc_link(reinterpret_cast<dllpublic_ext*>(dll), reinterpret_cast<dllheader_ext*>(family)); } 
    2323 
     24 
     25class HitCounter { 
     26    int    count;     // Counter for matches 
     27    double rel_count; // match_count / (seq_len - probe_len + 1) 
     28 
     29public: 
     30    HitCounter() : count(0), rel_count(0.0) {} 
     31 
     32    void inc() { count++; } 
     33    void calc_rel_match(int max_poss_matches) { 
     34        rel_count = max_poss_matches>0 ? double(count)/max_poss_matches : 0; 
     35    } 
     36 
     37    bool less_abs(const HitCounter& other) const { return count < other.count; } 
     38    bool less_rel(const HitCounter& other) const { return rel_count < other.rel_count; } 
     39 
     40    int get_match_count() const { return count; } 
     41    const double& get_rel_match_count() const { return rel_count; } 
     42}; 
     43 
     44class FamilyStat : virtual Noncopyable { 
     45    size_t      size; 
     46    HitCounter *famstat; 
     47 
     48public: 
     49    FamilyStat(size_t size_) : size(size_), famstat(new HitCounter[size]) { } 
     50    ~FamilyStat() { delete [] famstat; } 
     51 
     52    void calc_rel_matches(int probe_len, int sequence_length)  { 
     53        for (size_t i = 0; i < size; i++) { 
     54            int max_poss_matches = std::min(psg.data[i].get_size(), sequence_length) - probe_len + 1; 
     55            famstat[i].calc_rel_match(max_poss_matches); 
     56        } 
     57    } 
     58 
     59    const HitCounter& hits(size_t idx) const { pt_assert(idx<size); return famstat[idx]; } 
     60 
     61    void count_match(size_t idx) { famstat[idx].inc(); } 
     62 
     63    bool less_abs(int a, int b) const { return famstat[a].less_abs(famstat[b]); } 
     64    bool less_rel(int a, int b) const { return famstat[a].less_rel(famstat[b]); } 
     65}; 
     66 
    2467class ProbeTraversal { 
    2568    static Range range; 
    2669 
    27     static void count_match(const DataLoc& match) { 
    28         if (range.contains(match)) { 
    29             ++psg.data[match.name].stat.match_count; 
    30         } 
    31     } 
    32  
    33     // ---------------------------------------- 
    34      
    3570    const char *probe; 
    3671    int         height; 
    3772    int         needed_positions; 
    3873    int         accept_mismatches; 
     74     
     75    FamilyStat& fam_stat; 
     76 
     77    void count_match(const DataLoc& match) const { 
     78        if (range.contains(match)) { 
     79            fam_stat.count_match(match.name); 
     80        } 
     81    } 
    3982 
    4083    bool at_end() const { return *probe == PT_QU; } 
     
    5598 
    5699    void match_rest_and_mark(const DataLoc& loc) { 
    57         do match_one_char(psg.data[loc.name].data[loc.rpos+height]); while (match_possible()); 
     100        do match_one_char(psg.data[loc.name].get_data()[loc.rpos+height]); while (match_possible()); 
    58101        if (did_match()) count_match(loc); 
    59102    } 
     
    69112        range  = Range(-1, -1, -1); 
    70113    } 
    71      
    72     ProbeTraversal(const char *probe_, int needed_positions_, int accept_mismatches_) 
     114 
     115    ProbeTraversal(const char *probe_, int needed_positions_, int accept_mismatches_, FamilyStat& fam_stat_) 
    73116        : probe(probe_), 
    74117          height(0), 
    75118          needed_positions(needed_positions_), 
    76           accept_mismatches(accept_mismatches_) 
     119          accept_mismatches(accept_mismatches_), 
     120          fam_stat(fam_stat_) 
    77121    { } 
    78122 
     
    100144    if (PT_read_type(pt) == PT_NT_NODE) { 
    101145        for (int base = PT_N; base < PT_B_MAX; base++) { 
    102             POS_TREE *pt_son = PT_read_son(psg.ptmain, pt, (PT_BASES)base); 
     146            POS_TREE *pt_son = PT_read_son(pt, (PT_BASES)base); 
    103147            if (pt_son && !at_end()) { 
    104148                ProbeTraversal sub(*this); 
     
    112156    } 
    113157    else { 
    114         PT_withall_tips(psg.ptmain, pt, *this); // calls operator()  
     158        PT_withall_tips(pt, *this); // calls operator()  
    115159    } 
    116160} 
     
    123167    if (PT_read_type(pt) == PT_NT_NODE) { 
    124168        for (int base = PT_N; base < PT_B_MAX; base++) { 
    125             POS_TREE *pt_son = PT_read_son(psg.ptmain, pt, (PT_BASES)base); 
     169            POS_TREE *pt_son = PT_read_son(pt, (PT_BASES)base); 
    126170            if (pt_son) mark_all(pt_son); 
    127171        } 
    128172    } 
    129173    else { 
    130         PT_withall_tips(psg.ptmain, pt, *this); // calls operator()  
    131     } 
    132 } 
    133  
    134  
    135 static void clear_statistic() { 
    136     //! Clear all information in psg.data[i].stat 
    137  
    138     for (int i = 0; i < psg.data_count; i++) { 
    139         memset((char *) &psg.data[i].stat, 0, sizeof(probe_statistic)); 
    140     } 
    141 } 
    142  
    143  
    144  
    145 static void make_match_statistic(int probe_len, int sequence_length) { 
    146     //! Calculate the statistic information for the family 
    147  
    148     // compute statistic for all species in family 
    149     for (int i = 0; i < psg.data_count; i++) { 
    150         int all_len = std::min(psg.data[i].size, sequence_length) - probe_len + 1; 
    151         if (all_len <= 0) { 
    152             psg.data[i].stat.rel_match_count = 0; 
    153         } 
    154         else { 
    155             psg.data[i].stat.rel_match_count = psg.data[i].stat.match_count / (double) (all_len); 
    156         } 
     174        PT_withall_tips(pt, *this); // calls operator()  
    157175    } 
    158176} 
    159177 
    160178struct cmp_probe_abs { 
    161     bool operator()(const struct probe_input_data* a, const struct probe_input_data* b) { 
    162         return b->stat.match_count < a->stat.match_count; 
    163     } 
     179    const FamilyStat& fam_stat; 
     180    cmp_probe_abs(const FamilyStat& fam_stat_) : fam_stat(fam_stat_) {} 
     181    bool operator()(int a, int b) { return fam_stat.less_abs(b, a); } 
    164182}; 
    165183 
    166184struct cmp_probe_rel { 
    167     bool operator()(const struct probe_input_data* a, const struct probe_input_data* b) { 
    168         return b->stat.rel_match_count < a->stat.rel_match_count; 
    169     } 
    170 }; 
    171  
    172 static int make_PT_family_list(PT_family *ffinder) { 
     185    const FamilyStat& fam_stat; 
     186    cmp_probe_rel(const FamilyStat& fam_stat_) : fam_stat(fam_stat_) {} 
     187    bool operator()(int a, int b) { return fam_stat.less_rel(b, a); } 
     188}; 
     189 
     190static int make_PT_family_list(PT_family *ffinder, const FamilyStat& famStat) { 
    173191    //!  Make sorted list of family members 
    174192 
     193    // destroy old list 
     194    while (ffinder->fl) destroy_PT_family_list(ffinder->fl); 
     195 
    175196    // Sort the data 
    176     std::vector<struct probe_input_data*> my_list; 
    177     my_list.resize(psg.data_count); 
    178  
    179     for (int i = 0; i < psg.data_count; i++) { 
    180         my_list[i] = &psg.data[i]; 
    181     } 
     197    std::vector<int> sorted; 
     198    sorted.resize(psg.data_count); 
     199 
     200    for (int i = 0; i < psg.data_count; i++) sorted[i] = i; 
    182201 
    183202    bool sort_all = ffinder->sort_max == 0 || ffinder->sort_max >= psg.data_count; 
     
    185204    if (ffinder->sort_type == 0) { 
    186205        if (sort_all) { 
    187             std::sort(my_list.begin(), my_list.end(), cmp_probe_abs()); 
     206            std::sort(sorted.begin(), sorted.end(), cmp_probe_abs(famStat)); 
    188207        } 
    189208        else { 
    190             std::partial_sort(my_list.begin(), my_list.begin() + ffinder->sort_max, my_list.begin() + psg.data_count, cmp_probe_abs()); 
     209            std::partial_sort(sorted.begin(), sorted.begin() + ffinder->sort_max, sorted.begin() + psg.data_count, cmp_probe_abs(famStat)); 
    191210        } 
    192211    } 
    193212    else { 
    194213        if (sort_all) { 
    195             std::sort(my_list.begin(), my_list.begin() + psg.data_count, cmp_probe_rel()); 
     214            std::sort(sorted.begin(), sorted.begin() + psg.data_count, cmp_probe_rel(famStat)); 
    196215        } 
    197216        else { 
    198             std::partial_sort(my_list.begin(), my_list.begin() + ffinder->sort_max, my_list.begin() + psg.data_count, cmp_probe_rel()); 
    199         } 
    200     } 
    201  
    202     // destroy old list 
    203     while (ffinder->fl) destroy_PT_family_list(ffinder->fl); 
     217            std::partial_sort(sorted.begin(), sorted.begin() + ffinder->sort_max, sorted.begin() + psg.data_count, cmp_probe_rel(famStat)); 
     218        } 
     219    } 
    204220 
    205221    // build new list 
     
    208224    int end = (sort_all) ? psg.data_count : ffinder->sort_max; 
    209225    for (int i = 0; i < end; i++) { 
    210         if (my_list[i]->stat.match_count != 0) { 
     226        probe_input_data& pid = psg.data[sorted[i]]; 
     227        const HitCounter& ps  = famStat.hits(sorted[i]); 
     228 
     229        if (ps.get_match_count() != 0) { 
    211230            PT_family_list *fl = create_PT_family_list(); 
    212231 
    213             fl->name        = strdup(my_list[i]->name); 
    214             fl->matches     = my_list[i]->stat.match_count; 
    215             fl->rel_matches = my_list[i]->stat.rel_match_count; 
     232            fl->name        = strdup(pid.get_name()); 
     233            fl->matches     = ps.get_match_count(); 
     234            fl->rel_matches = ps.get_rel_match_count(); 
    216235 
    217236            aisc_link(&ffinder->pfl, fl); 
     
    263282    int   sequence_len = probe_compress_sequence(sequence, species->size); 
    264283 
    265     clear_statistic(); 
    266  
    267284    // if find_type > 0 -> search only probes starting with 'A' (quick but less accurate) 
    268285    char last_first_c = ffinder->find_type ? PT_A : PT_T; 
     
    270287    ProbeTraversal::restrictMatchesToRegion(ffinder->range_start, ffinder->range_end, probe_len); 
    271288 
     289    FamilyStat famStat(psg.data_count); 
     290     
    272291    // Note: code depends on order of ../AWTC/awtc_next_neighbours.hxx@FF_complement_dep 
    273292    for (int cmode = 1; cmode <= 8; cmode *= 2) { 
     
    290309                    for (char *probe = sequence; probe < last_probe; ++probe) { 
    291310                        if (probe_is_ok(probe, probe_len, first_c, second_c)) { 
    292                             ProbeTraversal(probe, probe_len, mismatch_nr).mark_matching(psg.pt); 
     311                            ProbeTraversal(probe, probe_len, mismatch_nr, famStat).mark_matching(psg.pt); 
    293312                        } 
    294313                    } 
     
    298317    } 
    299318 
    300     make_match_statistic(ffinder->pr_len, sequence_len); 
    301     make_PT_family_list(ffinder); 
     319    famStat.calc_rel_matches(ffinder->pr_len, sequence_len); 
     320    make_PT_family_list(ffinder, famStat); 
    302321 
    303322    ProbeTraversal::unrestrictMatchesToRegion(); 
  • branches/dev_elmar/PROBE/PT_findEx.cxx

    r7415 r8224  
    2121        case PT_NT_NODE: { 
    2222            for (int i=PT_A; i<PT_B_MAX; ++i) { 
    23                 POS_TREE *son = PT_read_son(psg.ptmain, node, PT_BASES(i)); 
     23                POS_TREE *son = PT_read_son(node, PT_BASES(i)); 
    2424                if (son) { 
    2525                    probe[0] = PT_BASES(i); // write leftmost probe into result 
     
    3737        case PT_NT_LEAF: { 
    3838            // here the probe-tree is cut off, because only one species matches 
    39             int pos  = PT_read_rpos(psg.ptmain, node) + height; 
    40             int name = PT_read_name(psg.ptmain, node); 
    41             if (pos + restlen >= psg.data[name].size) 
     39            DataLoc loc(node); 
     40            int     pos  = loc.rpos + height; 
     41            int     name = loc.name; 
     42 
     43            if (pos + restlen >= psg.data[name].get_size()) 
    4244                break;          // at end-of-sequence -> no probe with wanted length here 
    4345 
    4446            pt_assert(probe[restlen] == 0); 
    45             const char *seq_data = psg.data[name].data; 
     47            const char *seq_data = psg.data[name].get_data(); 
    4648            for (int r = 0; r<restlen; ++r) { 
    4749                int data = seq_data[pos+r]; 
     
    7072    switch (PT_read_type(node)) { 
    7173        case PT_NT_NODE: { 
    72             POS_TREE *son   = PT_read_son(psg.ptmain, node, PT_BASES(probe[0])); 
     74            POS_TREE *son   = PT_read_son(node, PT_BASES(probe[0])); 
    7375            bool      found = (son != 0) && findNextProbe(son, probe+1, restlen-1, height+1); 
    7476 
     
    7779            if (!found) { 
    7880                for (int i=probe[0]+1; !found && i<PT_B_MAX; ++i) { 
    79                     son = PT_read_son(psg.ptmain, node, PT_BASES(i)); 
     81                    son = PT_read_son(node, PT_BASES(i)); 
    8082                    if (son) { 
    8183                        probe[0] = PT_BASES(i); // change probe 
  • branches/dev_elmar/PROBE/PT_io.cxx

    r7946 r8224  
    1616#include <BI_basepos.hxx> 
    1717#include <arb_progress.h> 
    18  
    19 #include <sys/stat.h> 
    2018 
    2119int compress_data(char *probestring) { 
     
    7371} 
    7472 
    75 ARB_ERROR probe_read_data_base(const char *name) { // goes to header: __ATTR__USERESULT 
     73ARB_ERROR probe_read_data_base(const char *name, bool readOnly) { // goes to header: __ATTR__USERESULT 
    7674    ARB_ERROR error; 
    7775    GB_set_verbose(); 
     
    7977    psg.gb_shell = new GB_shell; 
    8078 
    81     GBDATA *gb_main     = GB_open(name, "r"); 
     79    GBDATA *gb_main     = GB_open(name, readOnly ? "r" : "rw"); 
    8280    if (!gb_main) error = GB_await_error(); 
    8381    else { 
     
    197195} 
    198196 
    199 char *probe_read_alignment(int j, int *psize) { 
     197char *probe_input_data::read_alignment(int *psize) const { 
    200198    char           *buffer     = 0; 
    201     GBDATA         *gb_species = psg.data[j].gbd; 
     199    GBDATA         *gb_species = get_gbdata(); 
    202200    GB_transaction  ta(gb_species); 
    203201    GBDATA         *gb_ali     = GB_entry(gb_species, psg.alignment_name); 
     
    210208} 
    211209 
    212 /** Cache: 
    213  * Instead of extracting the pure sequence data and checksum from the arb 
    214  * database each time the pt server loads, cache this data in a separate 
    215  * file to regain near instant pt server startup time. 
    216  * 
    217  * The format of the file is as follows: 
    218  * uint32: magic 
    219  * uint32: version 
    220  * uint32: number of sequences c 
    221  * uint32[c]: lengths of sequences 
    222  * uint32[c]: checksums 
    223  * char[]: sequences 
    224  */ 
    225 static const uint cache_magic = 0x97CAC11E; 
    226 static const uint cache_version = 1; 
    227  
    228 static char* cache_mkfilename(const char *arbfile) { 
    229     const char*  const suffix = ".ptc"; 
    230     char *cname = (char*)calloc(sizeof(char),strlen(arbfile)+strlen(suffix)+1); 
    231     sprintf(cname, "%s%s", arbfile, suffix); 
    232     return cname; 
    233 } 
    234  
    235 static int cache_load(const char* filename, const uint count) { 
    236     char *cname = cache_mkfilename(filename); 
    237  
    238     // get stats for arb-file 
    239     struct stat s_arb, s_ptc; 
    240     if (stat(filename,&s_arb)) { 
    241         perror("Unable to stat arb file! Utterly weird, I just opened it..."); 
    242         exit(1); 
    243     } 
    244  
    245     // get stats for cache-file 
    246     if (stat(cname, &s_ptc)) { 
    247         printf("Couldn't find cache file.\n"); 
    248         return 1; 
    249     } 
    250  
    251     // check that cache file is newer than arb file 
    252     if (s_arb.st_mtime > s_ptc.st_mtime) { 
    253         printf("Cachefile older than ARB file.\n"); 
    254         return 1; 
    255     } 
    256  
    257     printf("Loading data from cache:\n"); 
    258  
    259     FILE *fp = fopen(cname, "r"); 
    260     if (!fp) { 
    261         perror("Unable to open cache file."); 
    262         return 1; 
    263     } 
    264     free(cname); 
    265  
    266     uint rval; 
    267     fread(&rval, sizeof(int), 1, fp); 
    268     if (rval != cache_magic) { 
    269         printf("Cache file not a cache file!?!\n"); 
    270         return 1; 
    271     } 
    272  
    273     fread(&rval, sizeof(int), 1, fp); 
    274     if (rval != cache_version) { 
    275         printf("Cache file has wrong version"); 
    276         return 1; 
    277     } 
    278  
    279     fread(&rval, sizeof(int), 1, fp); 
    280     if (rval != count) { 
    281         printf("Unable to load cache: wrong number of sequences!\n"); 
    282         return 1; 
    283     } 
    284  
    285     int *sizes = (int*)calloc(sizeof(int), count); 
    286     if (fread(sizes, sizeof(int), count, fp) != count) { 
    287         printf("Cache file too short!"); 
    288         return 1; 
    289     } 
    290  
    291     uint *checksums = (uint*)calloc(sizeof(uint), count); 
    292     if (fread(checksums, sizeof(uint), count, fp) != count) { 
    293         printf("Cache file too short!"); 
    294         return 1; 
    295     } 
    296  
    297     ulong datasize = 0; 
    298     for (uint i=0; i<count; i++) { 
    299         psg.data[i].size = sizes[i]; 
    300         datasize += sizes[i]; 
    301         psg.data[i].checksum = checksums[i]; 
    302     } 
    303  
    304     free(sizes); 
    305     free(checksums); 
    306  
    307     char *data = (char*)calloc(sizeof(char), datasize); 
    308     if (fread(data, sizeof(char), datasize, fp) != datasize) { 
    309         printf("Cache file too short!"); 
    310         return 1; 
    311     } 
    312  
    313     for (uint i=0; i<count; i++) { 
    314         psg.data[i].data = data; 
    315         data += psg.data[i].size; 
    316     } 
    317  
    318     printf("done\n"); 
    319  
    320     return 0; 
    321 } 
    322  
    323 void cache_save(const char *filename, int count) { 
    324     char *cname = cache_mkfilename(filename); 
    325     FILE *fp = fopen(cname, "w+"); 
    326     if (!fp) { 
    327         perror("Unable to open cache file! Not saving cache."); 
    328         return; 
    329     } 
    330     free(cname); 
    331  
    332     printf("PT-cache: writing cache file...\n"); 
    333  
    334     fwrite(&cache_magic, sizeof(uint), 1, fp); 
    335     fwrite(&cache_version, sizeof(uint), 1, fp); 
    336     fwrite(&count, sizeof(count), 1, fp); 
    337  
    338  
    339     int *sizes = (int*)calloc(sizeof(int), count); 
    340     uint *checksums = (uint*)calloc(sizeof(uint), count); 
    341     for (int i=0; i<count; i++) { 
    342         sizes[i]=psg.data[i].size; 
    343         checksums[i]=psg.data[i].checksum; 
    344     } 
    345     fwrite(sizes, sizeof(int), count, fp); 
    346     fwrite(checksums, sizeof(uint), count, fp); 
    347     free(sizes); 
    348     free(checksums); 
    349  
    350     for (int i=0; i<count; i++) { 
    351         fwrite(psg.data[i].data, sizeof(char), psg.data[i].size, fp); 
    352     } 
    353  
    354     fclose(fp); 
    355  
    356     printf("done\n"); 
    357 } 
    358  
    359 void probe_read_alignments(const char* filename) { 
     210char *probe_read_alignment(int j, int *psize) {  
     211    return psg.data[j].read_alignment(psize); 
     212} 
     213 
     214GB_ERROR probe_input_data::init(GBDATA *gb_species) { 
     215    GB_ERROR  error   = NULL; 
     216    GBDATA   *gb_ali  = GB_entry(gb_species, psg.alignment_name); 
     217    GBDATA   *gb_data = gb_ali ? GB_entry(gb_ali, "data") : NULL; 
     218 
     219    if (!gb_data) { 
     220        error = GBS_global_string("Species '%s' has no data in '%s'\n", GBT_read_name(gb_species), psg.alignment_name); 
     221    } 
     222    else { 
     223        int   hsize; 
     224        char *sdata = probe_read_string_append_point(gb_data, &hsize); 
     225 
     226        if (!sdata) { 
     227            error = GBS_global_string("Could not read data in '%s' for species '%s'\n(Reason: %s)\n", 
     228                                      psg.alignment_name, GBT_read_name(gb_species), GB_await_error()); 
     229        } 
     230        else { 
     231            name = strdup(GBT_read_name(gb_species)); 
     232 
     233            fullname                = GBT_read_string(gb_species, "full_name"); 
     234            if (!fullname) fullname = strdup(""); 
     235 
     236            gbd   = gb_species; 
     237 
     238            set_checksum(GB_checksum(sdata, hsize, 1, ".-")); 
     239            int csize = probe_compress_sequence(sdata, hsize); 
     240 
     241            set_data(GB_memdup(sdata, csize), csize); 
     242            free(sdata); 
     243        } 
     244    } 
     245 
     246    return error; 
     247} 
     248 
     249void probe_read_alignments(const char* /*filename*/) { 
    360250    // reads sequence data into psg.data 
    361251 
     
    379269    int icount = GB_number_of_subentries(psg.gb_species_data); 
    380270     
    381     psg.data       = (probe_input_data *)calloc(sizeof(probe_input_data), icount); 
     271    psg.data       = new probe_input_data[icount]; 
    382272    psg.data_count = 0; 
    383273 
     
    388278        arb_progress progress("Preparing sequence data", icount); 
    389279        int count = 0; 
    390         int recache = cache_load(filename, icount); 
    391280 
    392281        for (GBDATA *gb_species = GBT_first_species_rel_species_data(psg.gb_species_data); 
     
    396285            probe_input_data& pid = psg.data[count]; 
    397286 
    398             pid.name     = strdup(GBT_read_name(gb_species)); 
    399             pid.fullname = GBT_read_string(gb_species, "full_name"); 
    400  
    401             if (!pid.fullname) pid.fullname = strdup(""); 
    402  
    403             pid.is_group = 1; 
    404             pid.gbd      = gb_species; 
    405  
    406             GBDATA *gb_ali  = GB_entry(gb_species, psg.alignment_name); 
    407             GBDATA *gb_data = gb_ali ? GB_entry(gb_ali, "data") : NULL; 
    408             if (!gb_data) { 
    409                 fprintf(stderr, "Species '%s' has no data in '%s'\n", pid.name, psg.alignment_name); 
     287            GB_ERROR error = pid.init(gb_species); 
     288            if (error) { 
     289                fputs(error, stderr); 
     290                fputc('\n', stderr); 
    410291                data_missing++; 
    411292            } 
    412             else if (recache) { 
    413                 int   hsize; 
    414                 char *data = probe_read_string_append_point(gb_data, &hsize); 
    415  
    416                 if (!data) { 
    417                     GB_ERROR error = GB_await_error(); 
    418                     fprintf(stderr, "Could not read data in '%s' for species '%s'\n(Reason: %s)\n", 
    419                             psg.alignment_name, pid.name, error); 
    420                     data_missing++; 
    421                 } 
    422                 else { 
    423                     if (recache) { 
    424                     pid.checksum = GB_checksum(data, hsize, 1, ".-"); 
    425                     int   size = probe_compress_sequence(data, hsize); 
    426  
    427                     pid.data = GB_memdup(data, size); 
    428                     pid.size = size; 
    429  
    430                     free(data); 
    431                     count++; 
    432                 } 
    433                 } 
    434                      
    435             } else { 
     293            else { 
    436294                count++; 
    437295            } 
     
    443301        psg.data_count = count; 
    444302        GB_commit_transaction(psg.gb_main); 
    445         if (recache && data_missing == 0) 
    446             cache_save(filename, count); 
    447303    } 
    448304 
     
    456312    } 
    457313    fflush(stdout); 
    458  
    459314} 
    460315 
     
    463318    psg.namehash = GBS_create_hash(psg.data_count, GB_MIND_CASE); 
    464319    for (i=0; i<psg.data_count; i++) { 
    465         GBS_write_hash(psg.namehash, psg.data[i].name, i+1); 
     320        GBS_write_hash(psg.namehash, psg.data[i].get_name(), i+1); 
    466321    } 
    467322    unsigned int    max_size; 
    468323    max_size = 0; 
    469324    for (i = 0; i < psg.data_count; i++) {  // get max sequence len 
    470         max_size = std::max(max_size, (unsigned)(psg.data[i].size)); 
    471         psg.char_count += psg.data[i].size; 
     325        max_size = std::max(max_size, (unsigned)(psg.data[i].get_size())); 
     326        psg.char_count += psg.data[i].get_size(); 
    472327    } 
    473328    psg.max_size = max_size; 
  • branches/dev_elmar/PROBE/PT_main.cxx

    r7946 r8224  
    1616 
    1717#include <arbdbt.h> 
     18#include <arb_file.h> 
     19#include <arb_defs.h> 
    1820#include <servercntrl.h> 
    1921#include <server.h> 
     
    2123#include <struct_man.h> 
    2224#include <ut_valgrinded.h> 
     25#include <ptclean.h> 
    2326 
    2427#include <unistd.h> 
     
    4245 
    4346ARB_ERROR pt_init_main_struct(PT_main *, const char *filename) { // __ATTR__USERESULT 
    44     ARB_ERROR error = probe_read_data_base(filename); 
     47    ARB_ERROR error = probe_read_data_base(filename, true); 
    4548    if (!error) { 
    4649        GB_begin_transaction(psg.gb_main); 
     
    6770    // shutdown server 
    6871    aisc_server_shutdown(psg.com_so); 
    69     PT_exit(EXIT_SUCCESS); // never returns 
    70     return 0; 
     72    PT_exit(); 
     73    exit(EXIT_SUCCESS); 
    7174} 
    7275 
     
    98101    if (psg_initialized) { 
    99102        if (psg.gb_main) { 
    100             int count = GB_number_of_subentries(psg.gb_species_data); 
    101             for (int i = 0; i < count; ++i) { 
    102                 free(psg.data[i].data); 
    103                 free(psg.data[i].name); 
    104                 free(psg.data[i].fullname); 
    105             } 
    106             free(psg.data); 
     103            delete [] psg.data; 
    107104 
    108105            GB_close(psg.gb_main); 
     
    131128} 
    132129 
    133 void PT_exit(int exitcode) { // goes to header: __ATTR__NORETURN 
     130void PT_exit() {  
    134131    // unique exit point to ensure cleanup 
    135132    if (aisc_main) destroy_PT_main(aisc_main); 
    136133    if (psg_initialized) PT_exit_psg(); 
    137134    PTM_finally_free_all_mem(); 
    138     exit(exitcode); 
    139135} 
    140136 
     
    220216            const char *map_str     = GB_read_char_pntr(map_ptr_str); 
    221217 
    222             parse_names_into_gene_struct(map_str, all_gene_structs); 
     218            error = parse_names_into_gene_struct(map_str, all_gene_structs).deliver(); 
    223219 
    224220            // build indices : 
     
    309305            if (update_reason) { 
    310306                printf("- updating postree (Reason: %s)", update_reason); 
    311                 char *build_cmd  = GBS_global_string_copy("%s -build -D%s", exename, arbdb_name); 
    312                 make_valgrinded_call(build_cmd); 
    313                 error            = GB_system(build_cmd); 
    314                 free(build_cmd); 
     307 
     308                const char *build_step[] = { 
     309                    "build_clean", 
     310                    "build_map", 
     311                    "build", 
     312                }; 
     313 
     314                for (size_t s = 0; !error && s<ARRAY_ELEMS(build_step); s++) { 
     315                    if (s == 1 && !GB_supports_mapfile()) continue; // skip useless step  
     316                     
     317                    char *build_cmd = GBS_global_string_copy("%s -%s -D%s", exename, build_step[s], arbdb_name); 
     318                    make_valgrinded_call(build_cmd); 
     319                    error           = GBK_system(build_cmd); 
     320                    free(build_cmd); 
     321                } 
     322 
    315323                if (error) error = GBS_global_string("Failed to update postree (Reason: %s)", error.deliver()); 
    316324            } 
     
    364372        char *pt_name = GBS_global_string_copy("%s.pt", params->db_server); 
    365373 
    366         if (strcmp(command, "-build") == 0) {  // build command 
     374        if (strcmp(command, "-build_clean") == 0) {  // cleanup source DB 
     375            error = probe_read_data_base(params->db_server, false); 
     376            if (!error) { 
     377                pt_assert(psg.gb_main); 
     378                error = prepare_ptserver_database(psg.gb_main, PTSERVER); 
     379                if (!error) { 
     380                    const char *mode = "bf"; // save PT-server database withOUT! Fastload file 
     381                    error            = GB_save_as(psg.gb_main, params->db_server, mode); 
     382                } 
     383            } 
     384        } 
     385        else if (strcmp(command, "-build_map") == 0) {  // create a clean mapfile for source DB 
     386            if (GB_supports_mapfile()) { 
     387                error = probe_read_data_base(params->db_server, false); 
     388                if (!error) { 
     389                    pt_assert(psg.gb_main); 
     390                    const char *mode = "bfm"; // save PT-server database with Fastload file 
     391                    error            = GB_save_as(psg.gb_main, params->db_server, mode); 
     392                } 
     393            } 
     394            else { 
     395                error = "Invalid invocation of -build_map (your ARB version does not support mapfiles)"; 
     396            } 
     397        } 
     398        else if (strcmp(command, "-build") == 0) {  // build command 
    367399            error = pt_init_main_struct(aisc_main, params->db_server); 
    368400            if (error) error = GBS_global_string("Gave up (Reason: %s)", error.deliver()); 
     
    477509 
    478510    free_arb_params(params); 
    479     PT_exit(exitcode); 
    480 } 
     511    PT_exit(); 
     512    return exitcode; 
     513} 
  • branches/dev_elmar/PROBE/PT_match.cxx

    r7999 r8224  
    6767            pos = matchLoc.rpos+psg.height; 
    6868            height = psg.height; 
    69             while ((base=probe[height]) && (ref = psg.data[matchLoc.name].data[pos])) { 
     69            while ((base=probe[height]) && (ref = psg.data[matchLoc.name].get_data()[pos])) { 
    7070                if (ref == PT_N || base == PT_N) { 
    7171                    // @@@ Warning: dupped code also counts PT_QU as mismatch! 
     
    124124    int            base; 
    125125    int            error; 
    126     int            name, pos, rpos; 
    127126    PT_probematch *ml; 
    128127 
     
    135134    } 
    136135    if (PT_read_type(pt) == PT_NT_LEAF) { 
    137         name = PT_read_name(psg.ptmain, pt); 
    138         pos  = PT_read_apos(psg.ptmain, pt); 
    139         rpos = PT_read_rpos(psg.ptmain, pt); 
     136        DataLoc loc(pt); 
    140137 
    141138        // @@@ dupped code from PT_store_match_in::operator() 
    142139        ml = create_PT_probematch(); 
    143140 
    144         ml->name         = name; 
    145         ml->b_pos        = pos; 
     141        ml->name         = loc.name; 
     142        ml->b_pos        = loc.apos; 
    146143        ml->g_pos        = -1; 
    147         ml->rpos         = rpos; 
     144        ml->rpos         = loc.rpos; 
    148145        ml->mismatches   = psg.mismatches; 
    149146        ml->wmismatches  = psg.wmismatches; 
     
    158155        if (PT_read_type(pt) == PT_NT_CHAIN) { 
    159156            psg.probe = 0; 
    160             if (PT_forwhole_chain(psg.ptmain, pt, PT_store_match_in(locs))) { 
     157            if (PT_forwhole_chain(pt, PT_store_match_in(locs))) { 
    161158                error = 1; 
    162159                return 1; 
     
    165162        else { 
    166163            for (base = PT_QU; base< PT_B_MAX; base++) { 
    167                 error = read_names_and_pos(locs, PT_read_son(psg.ptmain, pt, (PT_BASES)base)); 
     164                error = read_names_and_pos(locs, PT_read_son(pt, (PT_BASES)base)); 
    168165                if (error) return error; 
    169166            } 
     
    197194    if (PT_read_type(pt) == PT_NT_NODE && probe[height]) { 
    198195        for (i=PT_N; i<PT_B_MAX; i++) { 
    199             if ((pthelp = PT_read_son(psg.ptmain, pt, (PT_BASES)i))) { 
     196            if ((pthelp = PT_read_son(pt, (PT_BASES)i))) { 
    200197                new_N_mis = N_mismatches; 
    201198                base = probe[height]; 
     
    232229            // @@@ code here is duplicate of code in PT_store_match_in::operator() 
    233230 
    234             pos  = PT_read_rpos(psg.ptmain, pt) + height; 
    235             name = PT_read_name(psg.ptmain, pt); 
     231            DataLoc loc(pt); 
     232            pos  = loc.rpos + height; 
     233            name = loc.name; 
    236234 
    237235            // @@@ recursive use of strlen with constant result (argh!) 
    238             if (pos + (int)(strlen(probe+height)) >= psg.data[name].size)       // end of sequence 
     236            if (pos + (int)(strlen(probe+height)) >= psg.data[name].get_size())       // end of sequence 
    239237                return 0; 
    240238 
    241239            while ((base = probe[height])) { 
    242                 i = psg.data[name].data[pos]; 
     240                i = psg.data[name].get_data()[pos]; 
    243241                if (i == PT_N || base == PT_N || i == PT_QU || base == PT_QU) { 
    244242                    psg.N_mismatches = psg.N_mismatches + 1; 
     
    260258            psg.probe = probe; 
    261259            psg.height = height; 
    262             PT_forwhole_chain(psg.ptmain, pt, PT_store_match_in(locs)); // @@@ why ignore result 
     260            PT_forwhole_chain(pt, PT_store_match_in(locs)); // @@@ why ignore result 
    263261            return 0; 
    264262        } 
     
    444442    pt_build_pos_to_weight((PT_MATCH_TYPE)locs->sort_by, probestring); 
    445443 
    446     if (psg.deep >= 0) { 
    447         get_info_about_probe(locs, probestring, psg.pt, 0, 0.0, 0, 0); 
    448     } 
    449     else { 
    450         ptnd_new_match(locs,    probestring); 
    451     } 
     444    pt_assert(psg.deep >= 0); // deep < 0 was used till [8011] to trigger "new match" (feature unused) 
     445    get_info_about_probe(locs, probestring, psg.pt, 0, 0.0, 0, 0); 
     446 
    452447    if (locs->pm_reversed) { 
    453448        psg.reversed = 1; 
    454         rev_pro = reverse_probe(probestring, 0); 
     449        rev_pro      = reverse_probe(probestring, 0); 
    455450        complement_probe(rev_pro, 0); 
    456451        freeset(locs->pm_csequence, psg.main_probe = strdup(rev_pro)); 
    457         if (psg.deep >= 0) { 
    458             get_info_about_probe(locs, rev_pro, psg.pt, 0, 0.0, 0, 0); 
    459         } 
    460         else { 
    461             ptnd_new_match(locs,        rev_pro); 
    462         } 
     452         
     453        get_info_about_probe(locs, rev_pro, psg.pt, 0, 0.0, 0, 0); 
    463454        free(rev_pro); 
    464455    } 
     
    564555         pr_pos--, al_pos--) 
    565556    { 
    566         if (!psg.data[ml->name].data[al_pos]) break; 
    567         ref[pr_pos] = psg.data[ml->name].data[al_pos]; 
     557        if (!psg.data[ml->name].get_data()[al_pos]) break; 
     558        ref[pr_pos] = psg.data[ml->name].get_data()[al_pos]; 
    568559    } 
    569560    ref[9] = '-'; 
     
    572563 
    573564    for (int pr_pos = 0, al_pos = ml->rpos; 
    574          pr_pos < pr_len && al_pos < psg.data[ml->name].size; 
     565         pr_pos < pr_len && al_pos < psg.data[ml->name].get_size(); 
    575566         pr_pos++, al_pos++) 
    576567    { 
    577568        int a = ml->sequence[pr_pos]; 
    578         int b = psg.data[ml->name].data[al_pos]; 
     569        int b = psg.data[ml->name].get_data()[al_pos]; 
    579570        if (a == b) { 
    580571            ref[pr_pos+10] = '='; 
     
    593584 
    594585    for (int pr_pos = 0, al_pos = ml->rpos+pr_len; 
    595          pr_pos < 9 && al_pos < psg.data[ml->name].size; 
     586         pr_pos < 9 && al_pos < psg.data[ml->name].get_size(); 
    596587         pr_pos++, al_pos++) 
    597588    { 
    598         ref[pr_pos+11+pr_len] = psg.data[ml->name].data[al_pos]; 
     589        ref[pr_pos+11+pr_len] = psg.data[ml->name].get_data()[al_pos]; 
    599590    } 
    600591    ref[10+pr_len] = '-'; 
     
    605596 
    606597const char* get_match_acc(PT_probematch *ml) { 
     598/* 
    607599    GB_transaction trans(psg.gb_main); 
    608600    GBDATA *gbd = GB_entry(psg.data[ml->name].gbd, "acc"); 
     
    610602        return GB_read_char_pntr(gbd); 
    611603    } 
     604*/ 
    612605    return 0; 
    613606} 
    614607int get_match_start(PT_probematch *ml) { 
     608/* 
    615609    GB_transaction trans(psg.gb_main); 
    616610    GBDATA *gbd = GB_entry(psg.data[ml->name].gbd, "start"); 
     
    618612        return GB_read_int(gbd); 
    619613    } 
     614*/ 
    620615    return 0; 
    621616} 
    622617int get_match_stop(PT_probematch *ml) { 
     618/* 
    623619    GB_transaction trans(psg.gb_main); 
    624620    GBDATA *gbd = GB_entry(psg.data[ml->name].gbd, "stop"); 
     
    626622        return GB_read_int(gbd); 
    627623    } 
     624*/ 
    628625    return 0; 
    629626} 
     
    709706 
    710707    for (; ml; ml = ml->next) { 
    711         probe_input_data&  pid    = psg.data[ml->name]; 
    712         GBDATA            *gb_pos = GB_entry(pid.gbd, "abspos"); 
    713  
    714         if (gb_pos) { 
    715             long gene_pos  = GB_read_int(gb_pos); 
    716             ml->g_pos      = ml->b_pos; 
    717             ml->b_pos     += gene_pos; 
     708        long gene_pos = psg.data[ml->name].get_abspos(); 
     709        if (gene_pos >= 0) { 
     710            ml->g_pos  = ml->b_pos; 
     711            ml->b_pos += gene_pos; 
    718712        } 
    719713        else { 
    720714            fprintf(stderr, "Error in gene-pt-server: gene w/o position info\n"); 
    721             pt_assert(gb_pos); 
     715            pt_assert(0); 
    722716        } 
    723717    } 
     
    821815    for (i = 0; i < psg.data_count; i++) 
    822816    { 
    823         GBS_strcat(memfile, psg.data[i].name); 
     817        GBS_strcat(memfile, psg.data[i].get_name()); 
    824818        GBS_chrcat(memfile, (char)1); 
    825819    } 
  • branches/dev_elmar/PROBE/PT_new_design.cxx

    r7945 r8224  
    5454    } 
    5555} 
    56 struct ptnd_loop_com { 
     56 
     57static struct ptnd_loop_com { 
    5758    PT_pdc        *pdc; 
    5859    PT_local      *locs; 
    5960    PT_probeparts *parts; 
    6061    int            mishits; 
    61     int            new_match; // match or design the probe: 1 match   0 design 
    6262    double         sum_bonds; // sum of bond of longest non mismatch string 
    6363    double         dt;     // sum of mismatches 
     
    193193        // count all mishits for a probe 
    194194 
    195         // @@@ dupped code is in ptnd_count_mishits and ptnd_count_mishits2 
    196195        char *probe = psg.probe; 
    197196        psg.abs_pos.announce(probeLoc.apos); 
     
    199198        const probe_input_data& pid = psg.data[probeLoc.name]; 
    200199 
    201         if (pid.is_group) return 0;              // don't count group or neverminds 
    202         if (probe) { 
    203             int rpos = probeLoc.rpos + psg.height; 
    204             while (*probe && pid.data[rpos]) { 
    205                 if (pid.data[rpos] != *(probe)) return 0; 
    206                 probe++; 
    207                 rpos++; 
    208             } 
    209         } 
    210         ptnd.mishits++; 
     200        if (pid.outside_group()) { 
     201            if (probe) { 
     202                int rpos = probeLoc.rpos + psg.height; 
     203                while (*probe && pid.get_data()[rpos]) { 
     204                    if (pid.get_data()[rpos] != *(probe)) return 0; 
     205                    probe++; 
     206                    rpos++; 
     207                } 
     208            } 
     209            ptnd.mishits++; 
     210        } 
    211211        return 0; 
    212212    } 
     
    215215static int ptnd_count_mishits2(POS_TREE *pt) { 
    216216    //! go down the tree to chains and leafs; count the species that are in the non member group 
    217     int base; 
    218     int name; 
    219     int mishits = 0; 
    220  
    221217    if (pt == NULL) 
    222218        return 0; 
     219     
    223220    if (PT_read_type(pt) == PT_NT_LEAF) { 
    224         name     = PT_read_name(psg.ptmain, pt); 
    225         int apos = PT_read_apos(psg.ptmain, pt); 
    226  
    227         // @@@ dupped code from ptnd_chain_count_mishits::operator(): 
    228         psg.abs_pos.announce(apos); 
    229         if (!psg.data[name].is_group)   return 1; 
    230         return 0; 
    231     } 
    232     else if (PT_read_type(pt) == PT_NT_CHAIN) { 
     221        DataLoc loc(pt); 
     222        psg.abs_pos.announce(loc.apos); 
     223        return psg.data[loc.name].outside_group(); 
     224    } 
     225     
     226    if (PT_read_type(pt) == PT_NT_CHAIN) { 
    233227        psg.probe = 0; 
    234228        ptnd.mishits = 0; 
    235         PT_forwhole_chain(psg.ptmain, pt, ptnd_chain_count_mishits()); 
     229        PT_forwhole_chain(pt, ptnd_chain_count_mishits()); 
    236230        return ptnd.mishits; 
    237231    } 
    238     else { 
    239         for (base = PT_QU; base< PT_B_MAX; base++) { 
    240             mishits += ptnd_count_mishits2(PT_read_son(psg.ptmain, pt, (PT_BASES)base)); 
    241         } 
    242         return mishits; 
    243     } 
     232     
     233    int mishits = 0; 
     234    for (int base = PT_QU; base< PT_B_MAX; base++) { 
     235        mishits += ptnd_count_mishits2(PT_read_son(pt, (PT_BASES)base)); 
     236    } 
     237    return mishits; 
    244238} 
    245239 
     
    409403static int ptnd_count_mishits(char *probe, POS_TREE *pt, int height) { 
    410404    //! search down the tree to find matching species for the given probe 
    411     int       name; 
    412405    int       i; 
    413406    POS_TREE *pthelp; 
    414     int       pos; 
    415407    int       mishits; 
    416408 
     
    420412        for (i=PT_A; i<PT_B_MAX; i++) { 
    421413            if (i != *probe) continue; 
    422             if ((pthelp = PT_read_son(psg.ptmain, pt, (PT_BASES)i))) 
     414            if ((pthelp = PT_read_son(pt, (PT_BASES)i))) 
    423415                mishits += ptnd_count_mishits(probe+1, pthelp, height+1); 
    424416        } 
     
    427419    if (*probe) { 
    428420        if (PT_read_type(pt) == PT_NT_LEAF) { 
    429             pos  = PT_read_rpos(psg.ptmain, pt) + height; 
    430             name = PT_read_name(psg.ptmain, pt); 
    431  
    432             // @@@ dupped code from ptnd_chain_count_mishits::operator() 
    433             if (pos + (int)(strlen(probe)) >= psg.data[name].size)              // after end 
     421            const DataLoc loc(pt); 
     422            int           pos = loc.rpos+height; 
     423 
     424            if (pos + (int)(strlen(probe)) >= psg.data[loc.name].get_size())              // after end 
    434425                return 0; 
    435426 
    436427            while (*probe) { 
    437                 if (psg.data[name].data[pos++] != *(probe++)) 
     428                if (psg.data[loc.name].get_data()[pos++] != *(probe++)) 
    438429                    return 0; 
    439430            } 
     
    443434            psg.height = height; 
    444435            ptnd.mishits = 0; 
    445             PT_forwhole_chain(psg.ptmain, pt, ptnd_chain_count_mishits()); 
     436            PT_forwhole_chain(pt, ptnd_chain_count_mishits()); 
    446437            return ptnd.mishits; 
    447438        } 
     
    482473} 
    483474 
    484 static void ptnd_check_bonds(PT_pdc *pdc, int match) { 
     475static void ptnd_check_bonds(PT_pdc *pdc) { 
    485476    /*! check the average bond size. 
    486477     * 
     
    501492        tprobe->sum_bonds = sbond; 
    502493    } 
    503     match = match; 
    504494} 
    505495 
     
    628618} 
    629619 
    630 static void ptnd_check_part_inc_dt(PT_pdc *pdc, PT_probeparts *parts, 
    631                                    const DataLoc& matchLoc, 
    632                                    double dt, double sum_bonds) 
    633 { 
     620static void ptnd_check_part_inc_dt(PT_pdc *pdc, PT_probeparts *parts, const DataLoc& matchLoc, double dt, double sum_bonds) { 
    634621    //! test the probe parts, search the longest non mismatch string 
    635622 
     
    649636        while (start>=0) { 
    650637            if (pos<0) break;   // out of sight 
    651             h = ptnd_check_split(ptnd.pdc, probe, start, psg.data[matchLoc.name].data[pos]); 
     638            h = ptnd_check_split(ptnd.pdc, probe, start, psg.data[matchLoc.name].get_data()[pos]); 
    652639            if (h>0.0 && !split)        return; // there is a longer part matching this 
    653640            dt -= h; 
     
    664651    if (pos >= PERC_SIZE) return; // out of observation 
    665652    tprobe->perc[pos] ++; 
    666     if (ptnd.new_match) {                       // save the result in probematch 
    667         PT_probematch *match; 
    668         if (psg.data[matchLoc.name].match) { 
    669             if (psg.data[matchLoc.name].match->dt < ndt) return; 
    670             // there is a better hit for that sequence 
    671             match = psg.data[matchLoc.name].match; 
    672         } 
    673         else { 
    674             match = create_PT_probematch(); 
    675             aisc_link(&ptnd.locs->ppm, match); 
    676             psg.data[matchLoc.name].match = match; 
    677         } 
    678         match->name = matchLoc.name; 
    679         match->b_pos = matchLoc.apos - parts->start;     // that's not correct !!! 
    680         match->rpos = matchLoc.rpos-parts->start; 
    681         match->N_mismatches = -1;       // there are no mismatches in this mode 
    682         match->mismatches = -1; 
    683         match->wmismatches = dt;        // only weighted mismatches (maybe) 
    684         match->dt = ndt; 
    685         match->sequence = psg.main_probe; 
    686         match->reversed = psg.reversed; 
    687     } 
    688653} 
    689654static int ptnd_check_inc_mode(PT_pdc *pdc, PT_probeparts *parts, double dt, double sum_bonds) 
     
    705670     
    706671    int operator() (const DataLoc& partLoc) { 
    707         char   *probe  = psg.probe; 
    708         int     height = psg.height; 
    709         double  sbond  = ptnd.sum_bonds; 
    710         double  dt     = ptnd.dt; 
    711         double  h      = 1.0; 
    712         int     pos; 
    713         int     base; 
    714  
    715         if (!ptnd.new_match && psg.data[partLoc.name].is_group) return 0;           // don't count group or neverminds 
    716         if (probe) { 
    717             pos = partLoc.rpos+psg.height; 
    718             while (probe[height] && (base = psg.data[partLoc.name].data[pos])) { 
    719                 if (!split && (h = ptnd_check_split(ptnd.pdc, probe, height, base) < 0.0)) { 
    720                     dt -= h; 
    721                     split = 1; 
     672        if (psg.data[partLoc.name].outside_group()) { 
     673            char   *probe  = psg.probe; 
     674            int     height = psg.height; 
     675            double  sbond  = ptnd.sum_bonds; 
     676            double  dt     = ptnd.dt; 
     677            double  h      = 1.0; 
     678            int     pos; 
     679            int     base; 
     680 
     681            if (probe) { 
     682                pos = partLoc.rpos+psg.height; 
     683                while (probe[height] && (base = psg.data[partLoc.name].get_data()[pos])) { 
     684                    if (!split && (h = ptnd_check_split(ptnd.pdc, probe, height, base) < 0.0)) { 
     685                        dt -= h; 
     686                        split = 1; 
     687                    } 
     688                    else { 
     689                        dt += h; 
     690                        sbond += ptnd_check_max_bond(ptnd.pdc, probe[height]) - h; 
     691                    } 
     692                    height++; pos++; 
    722693                } 
    723                 else { 
    724                     dt += h; 
    725                     sbond += ptnd_check_max_bond(ptnd.pdc, probe[height]) - h; 
    726                 } 
    727                 height++; pos++; 
    728             } 
    729         } 
    730         ptnd_check_part_inc_dt(ptnd.pdc, ptnd.parts, partLoc, dt, sbond); 
     694            } 
     695            ptnd_check_part_inc_dt(ptnd.pdc, ptnd.parts, partLoc, dt, sbond); 
     696        } 
    731697        return 0; 
    732698    } 
     
    739705 
    740706    int base; 
    741     int name, apos, rpos; 
    742  
    743707    if (pt == NULL) 
    744708        return; 
    745709    if (PT_read_type(pt) == PT_NT_LEAF) { 
    746710        // @@@ dupped code is in ptnd_chain_check_part::operator() 
    747         name = PT_read_name(psg.ptmain, pt); 
    748         if (!ptnd.new_match && psg.data[name].is_group) return; 
    749         rpos = PT_read_rpos(psg.ptmain, pt); 
    750         apos = PT_read_apos(psg.ptmain, pt); 
    751         ptnd_check_part_inc_dt(ptnd.pdc, ptnd.parts, DataLoc(name, apos, rpos), dt, sum_bonds); 
     711        DataLoc loc(pt); 
     712        if (psg.data[loc.name].outside_group()) { 
     713            ptnd_check_part_inc_dt(ptnd.pdc, ptnd.parts, loc, dt, sum_bonds); 
     714        } 
    752715    } 
    753716    else if (PT_read_type(pt) == PT_NT_CHAIN) { 
     
    755718        ptnd.dt = dt; 
    756719        ptnd.sum_bonds = sum_bonds; 
    757         PT_forwhole_chain(psg.ptmain, pt, ptnd_chain_check_part(0)); 
     720        PT_forwhole_chain(pt, ptnd_chain_check_part(0)); 
    758721    } 
    759722    else { 
    760723        for (base = PT_QU; base< PT_B_MAX; base++) { 
    761             ptnd_check_part_all(PT_read_son(psg.ptmain, pt, (PT_BASES)base), dt, sum_bonds); 
     724            ptnd_check_part_all(PT_read_son(pt, (PT_BASES)base), dt, sum_bonds); 
    762725        } 
    763726    } 
     
    765728static void ptnd_check_part(char *probe, POS_TREE *pt, int  height, double dt, double sum_bonds, int split) { 
    766729    //! search down the tree to find matching species for the given probe 
    767     int       name; 
     730    int       pos; 
    768731    int       i; 
    769732    POS_TREE *pthelp; 
    770     int       rpos, apos, pos; 
    771733    double    ndt, nsum_bonds, h; 
    772734    int       nsplit; 
     
    778740        if (split && ptnd_check_inc_mode(ptnd.pdc, ptnd.parts, dt, sum_bonds)) return; 
    779741        for (i=PT_A; i<PT_B_MAX; i++) { 
    780             if ((pthelp = PT_read_son(psg.ptmain, pt, (PT_BASES)i))) 
     742            if ((pthelp = PT_read_son(pt, (PT_BASES)i))) 
    781743            { 
    782744                nsplit = split; 
     
    810772        if (PT_read_type(pt) == PT_NT_LEAF) { 
    811773            // @@@ dupped code is in ptnd_chain_check_part::operator() 
    812             name = PT_read_name(psg.ptmain, pt); 
    813             if (!ptnd.new_match && psg.data[name].is_group)     return; 
    814             rpos = PT_read_rpos(psg.ptmain, pt); 
    815             apos = PT_read_apos(psg.ptmain, pt); 
    816             pos = rpos + height; 
    817             if (pos + (int)(strlen(probe+height)) >= psg.data[name].size)               // after end 
    818                 return; 
    819             while (probe[height] && (ref = psg.data[name].data[pos])) { 
    820                 if (split) { 
    821                     h = ptnd_check_split(ptnd.pdc, probe, height, ref); 
    822                     if (h<0.0) dt -= h; else dt += h; 
    823                 } else if ((h = ptnd_check_split(ptnd.pdc, probe, height, 
    824                                                  ref)) < 0.0) { 
    825                     dt -= h; 
    826                     split = 1; 
     774            const DataLoc loc(pt); 
     775            if (psg.data[loc.name].outside_group()) { 
     776                pos = loc.rpos + height; 
     777                if (pos + (int)(strlen(probe+height)) >= psg.data[loc.name].get_size())               // after end 
     778                    return; 
     779                while (probe[height] && (ref = psg.data[loc.name].get_data()[pos])) { 
     780                    if (split) { 
     781                        h = ptnd_check_split(ptnd.pdc, probe, height, ref); 
     782                        if (h<0.0) dt -= h; else dt += h; 
     783                    } 
     784                    else if ((h = ptnd_check_split(ptnd.pdc, probe, height, ref)) < 0.0) { 
     785                        dt -= h; 
     786                        split = 1; 
     787                    } 
     788                    else { 
     789                        dt += h; 
     790                        sum_bonds += ptnd_check_max_bond(ptnd.pdc, probe[height]) - h; 
     791                    } 
     792                    height++; pos++; 
    827793                } 
    828                 else { 
    829                     dt += h; 
    830                     sum_bonds += ptnd_check_max_bond(ptnd.pdc, probe[height]) - h; 
    831                 } 
    832                 height++; pos++; 
    833             } 
    834             ptnd_check_part_inc_dt(ptnd.pdc, ptnd.parts, DataLoc(name, apos, rpos), dt, sum_bonds); 
     794                ptnd_check_part_inc_dt(ptnd.pdc, ptnd.parts, loc, dt, sum_bonds); 
     795            } 
    835796            return; 
    836797        } 
     
    840801            ptnd.dt = dt; 
    841802            ptnd.sum_bonds = sum_bonds; 
    842             PT_forwhole_chain(psg.ptmain, pt, ptnd_chain_check_part(split)); 
     803            PT_forwhole_chain(pt, ptnd_chain_check_part(split)); 
    843804            return; 
    844805        } 
     
    895856} 
    896857 
    897 inline void PT_incr_hash(GB_HASH *hash, char *sequence, int len) { 
     858inline void PT_incr_hash(GB_HASH *hash, const char *sequence, int len) { 
    898859    char c        = sequence[len]; 
    899     sequence[len] = 0; 
     860    const_cast<char*>(sequence)[len] = 0; 
    900861 
    901862    pt_assert(strlen(sequence) == (size_t)len); 
     
    903864    GBS_incr_hash(hash, sequence); 
    904865 
    905     sequence[len] = c; 
    906 } 
    907  
    908 static void ptnd_add_sequence_to_hash(PT_pdc *pdc, GB_HASH *hash, char *sequence, int seq_len, int probe_len, char *prefix, int prefix_len) { 
     866    const_cast<char*>(sequence)[len] = c; 
     867} 
     868 
     869static void ptnd_add_sequence_to_hash(PT_pdc *pdc, GB_HASH *hash, const char *sequence, int seq_len, int probe_len, char *prefix, int prefix_len) { 
    909870    int pos; 
    910871    if (*prefix) { // partition search, else very large hash tables (>60 mbytes) 
     
    946907        int used_idx = 0; 
    947908        for (int name = 0; name < psg.data_count; name++) { 
    948             if (psg.data[name].is_group == 1) { 
     909            if (psg.data[name].inside_group()) { 
    949910                group_idx[used_idx++]                  = name; // store marked group indices 
    950                 unsigned long size                     = psg.data[name].size; 
     911                unsigned long size                     = psg.data[name].get_size(); 
    951912                datasize                              += size; 
    952913                if (datasize<size) datasize            = ULONG_MAX; // avoid overflow! 
     
    1002963        for (int g = 0; g<group_count; ++g) { 
    1003964            int      name             = group_idx[g]; 
    1004             long     possible_tprobes = psg.data[name].size-pdc->probelen+1; 
     965            long     possible_tprobes = psg.data[name].get_size()-pdc->probelen+1; 
    1005966            GB_HASH *hash_one         = GBS_create_hash(possible_tprobes*hash_multiply, GB_MIND_CASE); // count tprobe occurrences for one group/sequence 
    1006             ptnd_add_sequence_to_hash(pdc, hash_one, psg.data[name].data, psg.data[name].size, pdc->probelen, partstring, partsize); 
     967            ptnd_add_sequence_to_hash(pdc, hash_one, psg.data[name].get_data(), psg.data[name].get_size(), pdc->probelen, partstring, partsize); 
    1007968            GBS_hash_do_loop(hash_one, ptnd_collect_hash, hash_outer); // merge hash_one into hash 
    1008969#if defined(DEBUG) 
     
    10491010    //  IDP probe design 
    10501011 
    1051     PT_local *locs   = (PT_local*)pdc->mh.parent->parent; 
    1052     ptnd.new_match   = 0; 
    1053     ptnd.locs        = locs; 
    1054     ptnd.pdc         = pdc; 
     1012    PT_local *locs = (PT_local*)pdc->mh.parent->parent; 
     1013 
     1014    ptnd.locs = locs; 
     1015    ptnd.pdc  = pdc; 
    10551016 
    10561017    const char *error; 
     
    10831044    ptnd_first_check(pdc); 
    10841045    ptnd_check_position(pdc); 
    1085     ptnd_check_bonds(pdc, ptnd.new_match); 
     1046    ptnd_check_bonds(pdc); 
    10861047    ptnd_cp_tprobe_2_probepart(pdc); 
    10871048    ptnd_duplicate_probepart(pdc); 
     
    10971058} 
    10981059 
    1099 void ptnd_new_match(PT_local * locs, char *probestring) 
    1100 { 
    1101     PT_pdc     *pdc = locs->pdc; 
    1102     PT_tprobes *tprobe; 
    1103  
    1104     ptnd.locs      = locs; 
    1105     ptnd.pdc       = pdc; 
    1106     ptnd.new_match = 1; 
    1107  
    1108     if (!pdc) return; // no config 
    1109  
    1110     tprobe           = create_PT_tprobes(); 
    1111     tprobe->sequence = strdup(probestring); 
    1112  
    1113     aisc_link(&pdc->ptprobes, tprobe); 
    1114     ptnd_check_bonds(pdc, ptnd.new_match); 
    1115     ptnd_cp_tprobe_2_probepart(pdc); 
    1116     ptnd_duplicate_probepart(pdc); 
    1117     ptnd_sort_parts(pdc); 
    1118     ptnd_remove_duplicated_probepart(pdc); 
    1119     ptnd_check_probepart(pdc); 
    1120  
    1121     while (pdc->parts)                  destroy_PT_probeparts(pdc->parts); 
    1122     while ((tprobe = pdc->tprobes))     destroy_PT_tprobes(tprobe); 
    1123 } 
  • branches/dev_elmar/PROBE/PT_prefixtree.cxx

    r7945 r8224  
    1212#include "probe_tree.h" 
    1313#include "pt_prototypes.h" 
     14 
     15#include <arb_file.h> 
    1416 
    1517#include <sys/types.h> 
     
    204206} 
    205207 
    206 POS_TREE *PT_add_to_chain(PTM2 *ptmain, POS_TREE *node, int name, int apos, int rpos)   // stage1 
    207 {                                           // insert at the beginning of list 
    208     static char buffer[100]; 
     208POS_TREE *PT_add_to_chain(POS_TREE *node, const DataLoc& loc) { // stage1 
     209    // insert at the beginning of list 
     210 
     211    char *data  = (&node->data) + psg.ptmain->mode; 
     212    data       += (node->flags&1) ? 4 : 2; 
     213 
    209214    unsigned long old_first; 
    210     char *data; 
    211     int mainapos;                           // TODO: mainapos isn't used 
    212     data = (&node->data) + ptmain->mode; 
    213     if (node->flags&1) { 
    214         PT_READ_INT(data, mainapos); 
    215         data += 4; 
    216     } 
    217     else { 
    218         PT_READ_SHORT(data, mainapos); 
    219         data += 2; 
    220     } 
    221215    PT_READ_PNTR(data, old_first);  // create a new list element 
    222     char *p; 
    223     p = buffer; 
     216 
     217    static char  buffer[100]; 
     218    char        *p = buffer; 
     219 
    224220    PT_WRITE_PNTR(p, old_first); 
    225221    p += sizeof(PT_PNTR); 
    226     PT_WRITE_NAT(p, name); 
    227     PT_WRITE_NAT(p, rpos); 
    228     PT_WRITE_NAT(p, apos); 
     222 
     223    PT_WRITE_NAT(p, loc.name); 
     224    PT_WRITE_NAT(p, loc.rpos); 
     225    PT_WRITE_NAT(p, loc.apos); 
     226     
    229227    int size = p - buffer; 
    230     p = (char *)PTM_get_mem(size); 
     228    p        = (char *)PTM_get_mem(size); 
    231229    memcpy(p, buffer, size); 
    232230    PT_WRITE_PNTR(data, p); 
     
    235233} 
    236234 
    237  
    238 POS_TREE *PT_change_leaf_to_node(PTM2 * /* ptmain */, POS_TREE *node) // stage 1 
    239 { 
     235POS_TREE *PT_change_leaf_to_node(POS_TREE *node) { // stage 1 
     236    if (PT_GET_TYPE(node) != PT_NT_LEAF) PT_CORE; 
     237     
    240238    long i; 
    241     POS_TREE *father, *new_elem; 
    242     if (PT_GET_TYPE(node) != PT_NT_LEAF) PT_CORE; 
    243239    PT_READ_PNTR((&node->data), i); 
    244     father=(POS_TREE *)i; 
    245     new_elem = (POS_TREE *)PTM_get_mem(PT_EMPTY_NODE_SIZE); 
     240 
     241    POS_TREE *father   = (POS_TREE *)i; 
     242    POS_TREE *new_elem = (POS_TREE *)PTM_get_mem(PT_EMPTY_NODE_SIZE); 
    246243    if (father) PT_change_father(father, node, new_elem); 
    247244    PTM_free_mem((char *)node, PT_LEAF_SIZE(node)); 
    248245    PT_SET_TYPE(new_elem, PT_NT_NODE, 0); 
    249246    PT_WRITE_PNTR((&(new_elem->data)), (long)father); 
     247 
    250248    return new_elem; 
    251249} 
    252250 
    253 POS_TREE *PT_leaf_to_chain(PTM2 *ptmain, POS_TREE *node)        // stage 1 
    254 { 
     251POS_TREE *PT_leaf_to_chain(POS_TREE *node) { // stage 1 
     252    if (PT_GET_TYPE(node) != PT_NT_LEAF) PT_CORE; 
     253 
    255254    long i; 
    256     int apos, rpos, name; 
    257     POS_TREE *father, *new_elem; 
    258     int chain_size; 
    259     char    *data; 
    260     if (PT_GET_TYPE(node) != PT_NT_LEAF) PT_CORE; 
    261255    PT_READ_PNTR((&node->data), i); 
    262     father=(POS_TREE *)i; 
    263     name = PT_read_name(ptmain, node);                          // backup name, 
    264     apos = PT_read_apos(ptmain, node);                          //        apos, 
    265     rpos = PT_read_rpos(ptmain, node);                          //        rpos 
    266     chain_size = PT_EMPTY_CHAIN_SIZE; 
    267     if (apos>PT_SHORT_SIZE) chain_size+=2; 
    268  
    269     new_elem = (POS_TREE *)PTM_get_mem(chain_size); 
     256 
     257    POS_TREE      *father = (POS_TREE *)i; 
     258    const DataLoc  loc(node); 
     259 
     260    int chain_size                          = PT_EMPTY_CHAIN_SIZE; 
     261    if (loc.apos>PT_SHORT_SIZE) chain_size += 2; 
     262 
     263    POS_TREE *new_elem = (POS_TREE *)PTM_get_mem(chain_size); 
    270264    PT_change_father(father, node, new_elem); 
    271265    PTM_free_mem((char *)node, PT_LEAF_SIZE(node)); 
    272266    PT_SET_TYPE(new_elem, PT_NT_CHAIN, 0); 
    273     PT_WRITE_PNTR((&new_elem->data), (long)father);             // father 
    274     data = (&new_elem->data)+sizeof(PT_PNTR); 
    275     if (apos>PT_SHORT_SIZE) {                                   // mainapos 
    276         PT_WRITE_INT(data, apos);                               // . 
    277         data+=4; new_elem->flags|=1;                            // . 
    278     } 
    279     else {                                                      // . 
    280         PT_WRITE_SHORT(data, apos);                             // . 
    281         data+=2;                                                // . 
    282     } 
    283     PT_WRITE_PNTR(data, NULL);                                  // first element 
    284     PT_add_to_chain(ptmain, new_elem, name, apos, rpos); 
     267    PT_WRITE_PNTR((&new_elem->data), (long)father); 
     268     
     269    char *data = (&new_elem->data)+sizeof(PT_PNTR); 
     270    if (loc.apos>PT_SHORT_SIZE) {                                    
     271        PT_WRITE_INT(data, loc.apos);                                
     272        data+=4; 
     273        new_elem->flags|=1; 
     274    } 
     275    else {                                                       
     276        PT_WRITE_SHORT(data, loc.apos); 
     277        data+=2; 
     278    } 
     279    PT_WRITE_PNTR(data, NULL); 
     280    PT_add_to_chain(new_elem, loc); 
     281 
    285282    return new_elem; 
    286283} 
    287284 
    288 POS_TREE       * 
    289 PT_create_leaf(PTM2 *ptmain, POS_TREE ** pfather, PT_BASES base, int rpos, int apos, int name)  // stage 1 
    290 { 
    291     POS_TREE       *father, *node, *new_elemfather; 
    292     int             base2; 
    293     int     leafsize; 
    294     char        *dest; 
     285POS_TREE *PT_create_leaf(POS_TREE ** pfather, PT_BASES base, const DataLoc& loc) { // stage 1 
     286    POS_TREE *father, *node, *new_elemfather; 
     287    int       base2; 
     288    int       leafsize; 
     289    char     *dest; 
    295290    leafsize = PT_EMPTY_LEAF_SIZE; 
    296     if (rpos>PT_SHORT_SIZE) leafsize+=2; 
    297     if (apos>PT_SHORT_SIZE) leafsize+=2; 
    298     if (name>PT_SHORT_SIZE) leafsize+=2; 
    299     node = (POS_TREE *) PTM_get_mem(leafsize); 
     291 
     292    if (loc.rpos>PT_SHORT_SIZE) leafsize += 2; 
     293    if (loc.apos>PT_SHORT_SIZE) leafsize += 2; 
     294    if (loc.name>PT_SHORT_SIZE) leafsize += 2; 
     295    node                              = (POS_TREE *) PTM_get_mem(leafsize); 
    300296    if (base >= PT_B_MAX) 
    301         *(int *) 0 = 0; 
     297        *(int *) 0                    = 0; 
    302298    if (pfather) { 
    303299        int             oldfathersize; 
     
    341337    PT_SET_TYPE(node, PT_NT_LEAF, 0); 
    342338    dest = (&node->data) + sizeof(PT_PNTR); 
    343     if (name>PT_SHORT_SIZE) { 
    344         PT_WRITE_INT(dest, name); 
     339    if (loc.name>PT_SHORT_SIZE) { 
     340        PT_WRITE_INT(dest, loc.name); 
    345341        node->flags |= 1; 
    346342        dest += 4; 
    347343    } 
    348344    else { 
    349         PT_WRITE_SHORT(dest, name); 
     345        PT_WRITE_SHORT(dest, loc.name); 
    350346        dest += 2; 
    351347    } 
    352     if (rpos>PT_SHORT_SIZE) { 
    353         PT_WRITE_INT(dest, rpos); 
     348    if (loc.rpos>PT_SHORT_SIZE) { 
     349        PT_WRITE_INT(dest, loc.rpos); 
    354350        node->flags |= 2; 
    355351        dest += 4; 
    356352    } 
    357353    else { 
    358         PT_WRITE_SHORT(dest, rpos); 
     354        PT_WRITE_SHORT(dest, loc.rpos); 
    359355        dest += 2; 
    360356    } 
    361     if (apos>PT_SHORT_SIZE) { 
    362         PT_WRITE_INT(dest, apos); 
     357    if (loc.apos>PT_SHORT_SIZE) { 
     358        PT_WRITE_INT(dest, loc.apos); 
    363359        node->flags |= 4; 
    364360        dest += 4; 
    365361    } 
    366362    else { 
    367         PT_WRITE_SHORT(dest, apos); 
     363        PT_WRITE_SHORT(dest, loc.apos); 
    368364        dest += 2; 
    369365    } 
    370366    if (base == PT_QU) 
    371         return PT_leaf_to_chain(ptmain, node); 
     367        return PT_leaf_to_chain(node); 
    372368    return node; 
    373369} 
    374  
    375370 
    376371// ------------------------------------ 
    377372//      functions for stage 1: save 
    378373 
    379 void PTD_clear_fathers(PTM2 *ptmain, POS_TREE * node)       // stage 1 
    380 { 
    381     POS_TREE       *sons; 
    382     int i; 
    383     PT_NODE_TYPE    type = PT_read_type(node); 
    384     if (type == PT_NT_SAVED) return; 
    385     PT_WRITE_PNTR((&node->data), NULL); 
    386     if (type == PT_NT_NODE) { 
    387         for (i = PT_QU; i < PT_B_MAX; i++) { 
    388             sons = PT_read_son(ptmain, node, (PT_BASES)i); 
    389             if (sons) 
    390                 PTD_clear_fathers(ptmain, sons); 
     374void PTD_clear_fathers(POS_TREE * node) { // stage 1 
     375    PT_NODE_TYPE type = PT_read_type(node); 
     376    if (type != PT_NT_SAVED) { 
     377        PT_WRITE_PNTR((&node->data), NULL); 
     378        if (type == PT_NT_NODE) { 
     379            for (int i = PT_QU; i < PT_B_MAX; i++) { 
     380                POS_TREE *sons = PT_read_son(node, (PT_BASES)i); 
     381                if (sons) PTD_clear_fathers(sons); 
     382            } 
    391383        } 
    392384    } 
     
    445437} 
    446438 
    447 long PTD_write_tip_to_disk(FILE * out, PTM2 * /* ptmain */, POS_TREE * node, long pos) 
     439long PTD_write_tip_to_disk(FILE * out, POS_TREE * node, long pos) 
    448440{ 
    449441    int size, cnt; 
     
    490482} 
    491483 
    492 ARB_ERROR ptd_write_chain_entries(FILE * out, long *ppos, PTM2 * /* ptmain */, char ** entry_tab,  int n_entries, int mainapos) { // __ATTR__USERESULT 
     484ARB_ERROR ptd_write_chain_entries(FILE * out, long *ppos, char ** entry_tab,  int n_entries, int mainapos) { // __ATTR__USERESULT 
    493485    ARB_ERROR   error; 
    494486    int         lastname = 0; 
     
    530522 
    531523 
    532 long PTD_write_chain_to_disk(FILE * out, PTM2 *ptmain, POS_TREE * node, long pos, ARB_ERROR& error) { 
     524long PTD_write_chain_to_disk(FILE * out, POS_TREE * node, long pos, ARB_ERROR& error) { 
    533525    char *data; 
    534526    long oldpos = pos; 
     
    536528    pos++; 
    537529    int mainapos; 
    538     data = (&node->data) + ptmain->mode; 
     530    data = (&node->data) + psg.ptmain->mode; 
    539531 
    540532    if (node->flags&1) { 
     
    556548        char **entry_tab = (char **)GB_calloc(sizeof(char *), n_entries); 
    557549        ptd_set_chain_references((char *)first_entry, entry_tab); 
    558         error = ptd_write_chain_entries(out, &pos, ptmain, entry_tab, n_entries, mainapos); 
     550        error = ptd_write_chain_entries(out, &pos, entry_tab, n_entries, mainapos); 
    559551        free(entry_tab); 
    560552    } 
     
    593585} 
    594586 
    595 long PTD_write_node_to_disk(FILE * out, PTM2 *ptmain, POS_TREE * node, long *r_poss, long pos) { 
     587long PTD_write_node_to_disk(FILE * out, POS_TREE * node, long *r_poss, long pos) { 
    596588    int i, size;   // Save node after all descendends are already saved 
    597589    POS_TREE *sons; 
     
    606598 
    607599    for (i = PT_QU; i < PT_B_MAX; i++) {    // free all sons 
    608         sons = PT_read_son(ptmain, node, (PT_BASES)i); 
     600        sons = PT_read_son(node, (PT_BASES)i); 
    609601        if (sons) { 
    610602            int memsize; 
     
    759751} 
    760752 
    761 long PTD_write_leafs_to_disk(FILE * out, PTM2 *ptmain, POS_TREE * node, long pos, long *pnodepos, int *pblock, ARB_ERROR& error) { 
     753long PTD_write_leafs_to_disk(FILE * out, POS_TREE * node, long pos, long *pnodepos, int *pblock, ARB_ERROR& error) { 
    762754    // returns new pos when son is written 0 otherwise 
    763755    // pnodepos is set to last object 
     
    778770    else if (type == PT_NT_LEAF) { 
    779771        *pnodepos = pos; 
    780         pos = PTD_write_tip_to_disk(out, ptmain, node, pos); 
     772        pos = PTD_write_tip_to_disk(out, node, pos); 
    781773    } 
    782774    else if (type == PT_NT_CHAIN) { 
    783775        *pnodepos = pos; 
    784         pos = PTD_write_chain_to_disk(out, ptmain, node, pos, error); 
     776        pos = PTD_write_chain_to_disk(out, node, pos, error); 
    785777    } 
    786778    else if (type == PT_NT_NODE) { 
     
    788780        o_pos = pos; 
    789781        for (i = PT_QU; i < PT_B_MAX && !error; i++) {    // save all sons 
    790             sons = PT_read_son(ptmain, node, (PT_BASES)i); 
     782            sons = PT_read_son(node, (PT_BASES)i); 
    791783            r_poss[i] = 0; 
    792784            if (sons) { 
    793                 r_pos = PTD_write_leafs_to_disk(out, ptmain, sons, pos, &(r_poss[i]), &(block[0]), error); 
     785                r_pos = PTD_write_leafs_to_disk(out, sons, pos, &(r_poss[i]), &(block[0]), error); 
    794786                if (r_pos>pos) {        // really saved ???? 
    795787                    son_size[i] = r_pos-pos; 
     
    813805        else {          // now i can write my data 
    814806            *pnodepos = pos; 
    815             if (!error) pos = PTD_write_node_to_disk(out, ptmain, node, r_poss, pos); 
     807            if (!error) pos = PTD_write_node_to_disk(out, node, r_poss, pos); 
    816808        } 
    817809    } 
     
    824816 
    825817 
    826 ARB_ERROR PTD_read_leafs_from_disk(const char *fname, PTM2 *ptmain, POS_TREE **pnode) { // __ATTR__USERESULT 
     818ARB_ERROR PTD_read_leafs_from_disk(const char *fname, POS_TREE **pnode) { // __ATTR__USERESULT 
    827819    GB_ERROR  error  = NULL; 
    828820    char     *buffer = GB_map_file(fname, 0); 
     
    892884            pt_assert(i >= 0); 
    893885 
    894             *pnode             = (POS_TREE *)(i+buffer); 
    895             ptmain->mode       = 0; 
    896             ptmain->data_start = buffer; 
     886            *pnode = (POS_TREE *)(i+buffer); 
     887 
     888            psg.ptmain->mode       = 0; 
     889            psg.ptmain->data_start = buffer; 
    897890        } 
    898891    } 
  • branches/dev_elmar/PROBE/needs_libs

    r6865 r8224  
    44SERVERCNTRL/SERVERCNTRL.a 
    55SL/HELIX/HELIX.a 
     6SL/PTCLEAN/PTCLEAN.a 
    67 
  • branches/dev_elmar/PROBE/probe.h

    r7999 r8224  
    5050#define FINDANSWER   52                             // private msg type: find result answer 
    5151 
     52extern int gene_flag;           // if 'gene_flag' == 1 -> we are a gene pt server 
    5253extern ULONG physical_memory; 
    5354struct Hs_struct; 
     
    100101//      Probe search 
    101102 
    102 struct probe_statistic { 
    103     int    match_count;                             // Counter for matches 
    104     double rel_match_count;                         // match_count / (seq_len - probe_len + 1) 
    105 }; 
    106  
    107 struct probe_input_data {                           // every taxa's own data 
    108     char   *data;                                   // sequence 
    109     long    checksum; 
    110     int     size; 
     103class probe_input_data : virtual Noncopyable {      // every taxa's own data 
     104 
     105    char *data;       // sequence 
     106    long  checksum;   // checksum of sequence 
     107    int   size; 
     108 
    111109    char   *name; 
    112110    char   *fullname; 
    113111    GBDATA *gbd; 
    114112 
    115     // probe design 
    116     int is_group;                                   // -1: nevermind, 0: no group, 1: group 
    117  
    118     // probe design (match) 
    119     PT_probematch *match;                           // best hit for PT_new_design 
    120  
    121     // find family 
    122     probe_statistic stat; 
    123  
    124     int next; 
     113    bool group;           // probe_design: whether species is in group 
     114 
     115    // obsolete methods below @@@ remove them 
     116    GBDATA *get_gbdata() const { return gbd; } 
     117    void set_data(char *assign, int size_) { pt_assert(!data); data = assign; size = size_; } 
     118    void set_checksum(long cs) { checksum = cs; } 
     119     
     120public: 
     121 
     122    probe_input_data() 
     123        : data(0), 
     124          checksum(0),  
     125          size(0),  
     126          name(0),  
     127          fullname(0),  
     128          gbd(0),  
     129          group(false)  
     130    {} 
     131    ~probe_input_data() { 
     132        free(data); 
     133        free(name); 
     134        free(fullname); 
     135    } 
     136 
     137    GB_ERROR init(GBDATA *gbd_); 
     138 
     139    const char *get_data() const { return data; } 
     140    char *read_alignment(int *psize) const; 
     141 
     142    const char *get_name() const { return name; } 
     143    const char *get_fullname() const { return fullname; } 
     144    long get_checksum() const { return checksum; } 
     145    int get_size() const { return size; } 
     146 
     147    bool inside_group() const { return group; } 
     148    bool outside_group() const { return !group; } 
     149 
     150    void set_group_state(bool isGroupMember) { group = isGroupMember; } 
     151 
     152    long get_abspos() const { 
     153        pt_assert(gene_flag); // only legal in gene-ptserver 
     154        GBDATA *gb_pos = GB_entry(get_gbdata(), "abspos"); 
     155        if (gb_pos) return GB_read_int(gb_pos); 
     156        return -1; 
     157    } 
     158 
     159private: 
    125160}; 
    126161 
     
    198233    GB_HASH  *namehash;                             // name to int 
    199234 
     235    int                      data_count; 
    200236    struct probe_input_data *data;                  // the internal database 
    201237 
     
    203239    BI_ecoli_ref *bi_ecoli; 
    204240 
    205     int  data_count; 
    206241    int  max_size;                                  // maximum sequence len 
    207242    long char_count;                                // number of all 'acgtuACGTU' 
     
    284319}; 
    285320 
    286 extern int gene_flag;           // if 'gene_flag' == 1 -> we are a gene pt server 
    287  
    288321struct ltByArbName { 
    289322    bool operator()(const gene_struct *gs1, const gene_struct *gs2) const { 
     
    313346#error probe.h included twice 
    314347#endif 
     348 
     349 
  • branches/dev_elmar/PROBE/probe_tree.h

    r7945 r8224  
    411411// calculate the index of the pointer in a node 
    412412 
    413 inline POS_TREE *PT_read_son(PTM2 *ptmain, POS_TREE *node, PT_BASES base) 
     413inline POS_TREE *PT_read_son(POS_TREE *node, PT_BASES base) 
    414414{ 
    415     long i; 
    416     UINT sec; 
    417     UINT offset; 
     415    long  i; 
     416    UINT  sec; 
     417    UINT  offset; 
     418    PTM2 *ptmain = psg.ptmain; 
    418419    if (ptmain->stage3) {       // stage 3  no father 
    419420        if (node->flags & IS_SINGLE_BRANCH_NODE) { 
     
    503504} 
    504505 
    505 inline POS_TREE *PT_read_son_stage_1(PTM2 *ptmain, POS_TREE *node, PT_BASES base) 
    506 { 
    507     long i; 
     506inline POS_TREE *PT_read_son_stage_1(POS_TREE *node, PT_BASES base) { 
    508507    if (!((1<<base) & node->flags)) return NULL;   // bit not set 
    509508    base = (PT_BASES)PT_count_bits[base][node->flags]; 
    510     PT_READ_PNTR((&node->data)+sizeof(PT_PNTR)*base+ptmain->mode, i); 
    511     return (POS_TREE *)(i+ptmain->data_start); // ptmain->data_start == 0x00 in stage 1 
     509    long i; 
     510    PT_READ_PNTR((&node->data)+sizeof(PT_PNTR)*base+psg.ptmain->mode, i); 
     511    return (POS_TREE *)(i+psg.ptmain->data_start); // psg.ptmain->data_start == 0x00 in stage 1 
    512512} 
    513513 
     
    517517} 
    518518 
    519 inline int PT_read_name(PTM2 *ptmain, POS_TREE *node) 
    520 { 
    521     int i; 
    522     if (node->flags&1) { 
    523         PT_READ_INT((&node->data)+ptmain->mode, i); 
    524     } 
    525     else { 
    526         PT_READ_SHORT((&node->data)+ptmain->mode, i); 
    527     } 
    528     pt_assert(i >= 0); 
    529     return i; 
    530 } 
    531  
    532 inline int PT_read_rpos(PTM2 *ptmain, POS_TREE *node) 
    533 { 
    534     int i; 
    535     char *data = (&node->data)+2+ptmain->mode; 
    536     if (node->flags&1) data+=2; 
    537     if (node->flags&2) { 
    538         PT_READ_INT(data, i); 
    539     } 
    540     else { 
    541         PT_READ_SHORT(data, i); 
    542     } 
    543     pt_assert(i >= 0); 
    544     return i; 
    545 } 
    546  
    547 inline int PT_read_apos(PTM2 *ptmain, POS_TREE *node) 
    548 { 
    549     int i; 
    550     char *data = (&node->data)+ptmain->mode+4;  // father 4 name 2 rpos 2 
    551     if (node->flags&1) data+=2; 
    552     if (node->flags&2) data+=2; 
    553     if (node->flags&4) { 
    554         PT_READ_INT(data, i); 
    555     } 
    556     else { 
    557         PT_READ_SHORT(data, i); 
    558     } 
    559     pt_assert(i >= 0); 
    560     return i; 
    561 } 
    562  
    563519struct DataLoc { 
    564     int name; 
     520    int name; // index into psg.data[], aka as species id 
    565521    int apos; 
    566     int rpos; 
     522    int rpos; // position in data 
    567523 
    568524    void init(const char ** data, int pos) { 
    569525        *data = PT_READ_CHAIN_ENTRY(*data, pos, &name, &apos, &rpos); 
    570526    } 
    571     void init(PTM2 *ptmain, POS_TREE *pt) { 
    572         pt_assert(PT_read_type(pt) == PT_NT_LEAF); 
    573  
    574         name = PT_read_name(ptmain, pt); 
    575         apos = PT_read_apos(ptmain, pt); 
    576         rpos = PT_read_rpos(ptmain, pt); 
     527    void init(POS_TREE *node) { 
     528        pt_assert(PT_read_type(node) == PT_NT_LEAF); 
     529        char *data = (&node->data)+psg.ptmain->mode; 
     530        if (node->flags&1) { PT_READ_INT(data, name); data += 4; } else { PT_READ_SHORT(data, name); data += 2; } 
     531        if (node->flags&2) { PT_READ_INT(data, rpos); data += 4; } else { PT_READ_SHORT(data, rpos); data += 2; } 
     532        if (node->flags&4) { PT_READ_INT(data, apos); data += 4; } else { PT_READ_SHORT(data, apos); data += 2; } 
     533 
     534        pt_assert(name >= 0); 
     535        pt_assert(apos >= 0); 
     536        pt_assert(rpos >= 0); 
    577537    } 
    578538 
    579539    DataLoc(int name_, int apos_, int rpos_) : name(name_), apos(apos_), rpos(rpos_) {} 
    580     DataLoc(const char ** data, int pos) { 
    581         name = 0; 
    582         init(data, pos); 
    583     } 
    584     DataLoc(PTM2 *ptmain, POS_TREE *pt) { 
    585         init(ptmain, pt); 
    586     } 
     540    DataLoc(POS_TREE *pt) { init(pt); } 
     541    DataLoc(const char ** data, int pos) { name = 0; init(data, pos); } 
     542 
     543    const probe_input_data& get_pid() const { pt_assert(name >= 0 && name<psg.data_count); return psg.data[name]; } 
     544    const char *get_data() const { return get_pid().get_data(); } 
     545    PT_BASES operator[](int offset) const { return PT_BASES(get_data()[rpos+offset]); } 
     546 
     547    int restlength() const { return get_pid().get_size()-rpos; } 
     548    bool is_shorther_than(int offset) const { return offset >= restlength(); } 
    587549 
    588550#if defined(DEBUG) 
    589551    void dump(FILE *fp) const { 
    590         fprintf(fp, "          apos=%6i  rpos=%6i  name=%6i='%s'\n", apos, rpos, name, psg.data[name].name); 
     552        fprintf(fp, "          apos=%6i  rpos=%6i  name=%6i='%s'\n", apos, rpos, name, psg.data[name].get_name()); 
    591553        fflush(fp); 
    592554    } 
     
    595557 
    596558template<typename T> 
    597 int PT_forwhole_chain(PTM2 *ptmain, POS_TREE *node, T func) { 
     559int PT_forwhole_chain(POS_TREE *node, T func) { 
    598560    pt_assert(PT_read_type(node) == PT_NT_CHAIN); 
    599561 
    600     const char *data = (&node->data) + ptmain->mode; 
     562    const char *data = (&node->data) + psg.ptmain->mode; 
    601563    int         pos; 
    602564 
     
    621583 
    622584template<typename T> 
    623 int PT_withall_tips(PTM2 *ptmain, POS_TREE *node, T func) { 
     585int PT_withall_tips(POS_TREE *node, T func) { 
    624586    // like PT_forwhole_chain, but also can handle leafs 
    625587    PT_NODE_TYPE type = PT_read_type(node); 
    626588    if (type == PT_NT_LEAF) { 
    627         return func(DataLoc(ptmain, node)); 
     589        return func(DataLoc(node)); 
    628590    } 
    629591 
    630592    pt_assert(type == PT_NT_CHAIN); 
    631     return PT_forwhole_chain(ptmain, node, func); 
     593    return PT_forwhole_chain(node, func); 
    632594} 
    633595 
  • branches/dev_elmar/PROBE/pt_prototypes.h

    r7999 r8224  
    1313 
    1414/* PT_buildtree.cxx */ 
    15 POS_TREE *build_pos_tree(POS_TREE *pt, int anfangs_pos, int apos, int RNS_nr, unsigned int end); 
    16 long PTD_save_partial_tree(FILE *out, PTM2 *ptmain, POS_TREE *node, char *partstring, int partsize, long pos, long *ppos, ARB_ERROR &error); 
     15 
     16 class DataLoc; 
     17 
     18long PTD_save_partial_tree(FILE *out, POS_TREE *node, char *partstring, int partsize, long pos, long *ppos, ARB_ERROR &error); 
    1719ARB_ERROR enter_stage_1_build_tree(PT_main *, char *tname) __ATTR__USERESULT; 
    1820ARB_ERROR enter_stage_3_load_tree(PT_main *, const char *tname) __ATTR__USERESULT; 
     
    4042int compress_data(char *probestring); 
    4143void PT_base_2_string(char *id_string, long len); 
    42 ARB_ERROR probe_read_data_base(const char *name) __ATTR__USERESULT; 
     44ARB_ERROR probe_read_data_base(const char *name, bool readOnly) __ATTR__USERESULT; 
    4345int probe_compress_sequence(char *seq, int seqsize); 
    4446char *probe_read_alignment(int j, int *psize); 
     
    5456void PT_init_psg(void); 
    5557void PT_exit_psg(void); 
    56 void PT_exit(int exitcode) __ATTR__NORETURN; 
     58void PT_exit(void); 
    5759GB_ERROR PT_init_map(void) __ATTR__USERESULT; 
    5860 
     
    7779char *get_design_hinfo(PT_tprobes *tprobe); 
    7880int PT_start_design(PT_pdc *pdc, int dummy_1x); 
    79 void ptnd_new_match(PT_local *locs, char *probestring); 
    8081 
    8182/* PT_prefixtree.cxx */ 
     
    8990PTM2 *PT_init(void); 
    9091void PT_change_father(POS_TREE *father, POS_TREE *source, POS_TREE *dest); 
    91 POS_TREE *PT_add_to_chain(PTM2 *ptmain, POS_TREE *node, int name, int apos, int rpos); 
    92 POS_TREE *PT_change_leaf_to_node(PTM2 *, POS_TREE *node); 
    93 POS_TREE *PT_leaf_to_chain(PTM2 *ptmain, POS_TREE *node); 
    94 POS_TREE *PT_create_leaf(PTM2 *ptmain, POS_TREE **pfather, PT_BASES base, int rpos, int apos, int name); 
    95 void PTD_clear_fathers(PTM2 *ptmain, POS_TREE *node); 
     92POS_TREE *PT_add_to_chain(POS_TREE *node, const DataLoc &loc); 
     93POS_TREE *PT_change_leaf_to_node(POS_TREE *node); 
     94POS_TREE *PT_leaf_to_chain(POS_TREE *node); 
     95POS_TREE *PT_create_leaf(POS_TREE **pfather, PT_BASES base, const DataLoc &loc); 
     96void PTD_clear_fathers(POS_TREE *node); 
    9697void PTD_put_longlong(FILE *out, ULONG i); 
    9798void PTD_put_int(FILE *out, ULONG i); 
    9899void PTD_put_short(FILE *out, ULONG i); 
    99100void PTD_set_object_to_saved_status(POS_TREE *node, long pos, int size); 
    100 long PTD_write_tip_to_disk(FILE *out, PTM2 *, POS_TREE *node, long pos); 
     101long PTD_write_tip_to_disk(FILE *out, POS_TREE *node, long pos); 
    101102int ptd_count_chain_entries(char *entry); 
    102103void ptd_set_chain_references(char *entry, char **entry_tab); 
    103 ARB_ERROR ptd_write_chain_entries(FILE *out, long *ppos, PTM2 *, char **entry_tab, int n_entries, int mainapos) __ATTR__USERESULT; 
    104 long PTD_write_chain_to_disk(FILE *out, PTM2 *ptmain, POS_TREE *node, long pos, ARB_ERROR &error); 
     104ARB_ERROR ptd_write_chain_entries(FILE *out, long *ppos, char **entry_tab, int n_entries, int mainapos) __ATTR__USERESULT; 
     105long PTD_write_chain_to_disk(FILE *out, POS_TREE *node, long pos, ARB_ERROR &error); 
    105106void PTD_debug_nodes(void); 
    106 long PTD_write_node_to_disk(FILE *out, PTM2 *ptmain, POS_TREE *node, long *r_poss, long pos); 
    107 long PTD_write_leafs_to_disk(FILE *out, PTM2 *ptmain, POS_TREE *node, long pos, long *pnodepos, int *pblock, ARB_ERROR &error); 
    108 ARB_ERROR PTD_read_leafs_from_disk(const char *fname, PTM2 *ptmain, POS_TREE **pnode) __ATTR__USERESULT; 
     107long PTD_write_node_to_disk(FILE *out, POS_TREE *node, long *r_poss, long pos); 
     108long PTD_write_leafs_to_disk(FILE *out, POS_TREE *node, long pos, long *pnodepos, int *pblock, ARB_ERROR &error); 
     109ARB_ERROR PTD_read_leafs_from_disk(const char *fname, POS_TREE **pnode) __ATTR__USERESULT; 
    109110 
    110111/* PT_debug.cxx */ 
     
    114115 
    115116/* probe_tree.h */ 
    116 template <typename T >int PT_forwhole_chain(PTM2 *ptmain, POS_TREE *node, T func); 
    117 template <typename T >int PT_withall_tips(PTM2 *ptmain, POS_TREE *node, T func); 
     117template <typename T >int PT_forwhole_chain(POS_TREE *node, T func); 
     118template <typename T >int PT_withall_tips(POS_TREE *node, T func); 
    118119 
    119120#else 
  • branches/dev_elmar/PROBE_COM/PT_extern.c

    r7415 r8224  
    33#include <cstring> 
    44#include "PT_server.h" 
     5#include <attributes.h> 
    56#include "C/server.h" 
    67#include <aisc_server_proto.h> 
  • branches/dev_elmar/PROBE_DESIGN/Makefile

    r7945 r8224  
    4040probe_design.o: $(ARBHOME)/INCLUDE/arb_core.h 
    4141probe_design.o: $(ARBHOME)/INCLUDE/arb_error.h 
     42probe_design.o: $(ARBHOME)/INCLUDE/arb_file.h 
    4243probe_design.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    4344probe_design.o: $(ARBHOME)/INCLUDE/arb_progress.h 
     
    5657probe_design.o: $(ARBHOME)/INCLUDE/aw_color_groups.hxx 
    5758probe_design.o: $(ARBHOME)/INCLUDE/aw_device.hxx 
    58 probe_design.o: $(ARBHOME)/INCLUDE/aw_edit.hxx 
    5959probe_design.o: $(ARBHOME)/INCLUDE/aw_keysym.hxx 
    6060probe_design.o: $(ARBHOME)/INCLUDE/aw_msg.hxx 
  • branches/dev_elmar/PROBE_DESIGN/probe_design.cxx

    r7999 r8224  
    2626#include <aw_awars.hxx> 
    2727#include <aw_preset.hxx> 
    28 #include <aw_edit.hxx> 
    2928#include <aw_select.hxx> 
    3029#include <aw_msg.hxx> 
     
    3332#include <adGene.h> 
    3433#include <arb_strbuf.h> 
     34#include <arb_file.h> 
    3535 
    3636// general awars 
     
    237237} 
    238238 
    239 static const char *PD_probe_pt_look_for_server(AW_root *root, GBDATA *gb_main, GB_ERROR& error) { 
     239static const char *PD_probe_pt_look_for_server(AW_root *root, GB_ERROR& error) {  
    240240    // return PT server info string (see GBS_read_arb_tcp for details) 
    241241    // or NULL (in this case 'error' is set) 
     
    244244    const char *server_tag = GBS_ptserver_tag(root->awar(AWAR_PT_SERVER)->read_int()); 
    245245 
    246     error = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag, gb_main); 
     246    error = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag); 
    247247    if (!error) { 
    248248        result             = GBS_read_arb_tcp(server_tag); 
     
    419419 
    420420    { 
    421         const char *servername = PD_probe_pt_look_for_server(root, gb_main, error); 
     421        const char *servername = PD_probe_pt_look_for_server(root, error); 
    422422        if (servername) { 
    423423            pd_gl.link = aisc_open(servername, &pd_gl.com, AISC_MAGIC_NUMBER); 
     
    683683         
    684684        if (!error) { 
    685             const char *servername = PD_probe_pt_look_for_server(root, gb_main, error); 
     685            const char *servername = PD_probe_pt_look_for_server(root, error); 
    686686 
    687687            if (!error) { 
     
    16561656} 
    16571657 
    1658 static void pd_start_pt_server(AW_window *aww, AW_CL cl_gb_main) { 
     1658static void pd_start_pt_server(AW_window *aww) { 
    16591659    const char *server_tag = GBS_ptserver_tag(aww->get_root()->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int()); 
    16601660    arb_progress progress("Connecting PT-server"); 
    1661     GB_ERROR error = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag, (GBDATA*)cl_gb_main); 
     1661    GB_ERROR error = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag); 
    16621662    if (error) aw_message(error); 
    16631663} 
     
    18161816        if (!error) { 
    18171817            progress.subtitle("Start PT-server (builds in background)"); 
    1818             error = arb_start_server(server_tag, gb_main, 1); 
     1818            error = arb_start_server(server_tag, 1); 
    18191819        } 
    18201820    } 
    18211821    if (error) aw_message(error); 
    1822 } 
    1823  
    1824 static void arb_tcp_dat_changed_cb(const char * /* path */, bool fileChanged, bool /* editorTerminated */) { 
    1825 #if defined(DEBUG) && 0 
    1826     printf("File '%s': changed=%i editorTerminated=%i\n", path, int(fileChanged), int(editorTerminated)); 
    1827 #endif // DEBUG 
    1828     if (fileChanged) { 
    1829         awt_refresh_all_pt_server_selection_lists(); 
    1830     } 
    1831 } 
    1832  
    1833 static void pd_edit_arb_tcp(AW_window *aww, AW_CL cl_gb_main) { 
    1834     GBDATA *gb_main  = (GBDATA*)cl_gb_main; 
    1835     char   *filename = GBS_find_lib_file("arb_tcp.dat", "", true); 
    1836  
    1837     AW_edit(filename, arb_tcp_dat_changed_cb, aww, gb_main); 
    1838     free(filename); 
    18391822} 
    18401823 
     
    18681851 
    18691852    aws->at("start"); 
    1870     aws->callback(pd_start_pt_server, (AW_CL)gb_main); 
     1853    aws->callback(pd_start_pt_server); 
    18711854    aws->create_button("START_SERVER", "Start server"); 
    18721855 
     
    18841867 
    18851868    aws->at("edit"); 
    1886     aws->callback(pd_edit_arb_tcp, (AW_CL)gb_main); 
     1869    aws->callback(awt_edit_arbtcpdat_cb, (AW_CL)gb_main); 
    18871870    aws->create_button("CREATE_TEMPLATE", "Configure"); 
    18881871 
  • branches/dev_elmar/RNA3D/RNA3D_StructureData.cxx

    r7272 r8224  
    3636 
    3737static char *find_data_file(const char *name) { 
    38     char *fname = GBS_find_lib_file(name, "rna3d/", false); 
     38    char *fname = GB_lib_file(false, "rna3d/", name); 
    3939    if (!fname) throw string("file not found: ")+name; 
    4040    return fname; 
  • branches/dev_elmar/RNA3D/RNA3D_Textures.cxx

    r6678 r8224  
    4646    } 
    4747 
    48     char *fname = GBS_find_lib_file(imageName, "rna3d/images/", false); 
     48    char *fname = GB_lib_file(false, "rna3d/images/", imageName); 
    4949    if (!fname) { 
    5050        throw string("File not found: ")+imageName; 
  • branches/dev_elmar/SECEDIT/Makefile

    r7945 r8224  
    252252SEC_main.o: $(ARBHOME)/INCLUDE/arb_core.h 
    253253SEC_main.o: $(ARBHOME)/INCLUDE/arb_error.h 
     254SEC_main.o: $(ARBHOME)/INCLUDE/arb_file.h 
    254255SEC_main.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    255256SEC_main.o: $(ARBHOME)/INCLUDE/arb_string.h 
  • branches/dev_elmar/SECEDIT/SEC_db.cxx

    r7337 r8224  
    372372 
    373373    { 
    374         char *dir = GBS_global_string_copy("%s/.arb_prop/secondary_structure", GB_getenvHOME()); 
     374        char *dir = strdup(GB_path_in_arbprop("secondary_structure")); 
    375375        AW_create_fileselection_awars(aw_root, AWAR_SECEDIT_SAVEDIR, dir, ".ass", "noname.ass"); 
    376376        free(dir); 
  • branches/dev_elmar/SECEDIT/SEC_main.cxx

    r7945 r8224  
    2222#include <aw_msg.hxx> 
    2323#include <aw_root.hxx> 
     24 
     25#include <arb_file.h> 
    2426 
    2527#ifndef sec_assert // happens in NDEBUG mode 
  • branches/dev_elmar/SERVERCNTRL/Makefile

    r7945 r8224  
    3939servercntrl.o: $(ARBHOME)/INCLUDE/arb_core.h 
    4040servercntrl.o: $(ARBHOME)/INCLUDE/arb_error.h 
     41servercntrl.o: $(ARBHOME)/INCLUDE/arb_file.h 
    4142servercntrl.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    4243servercntrl.o: $(ARBHOME)/INCLUDE/arb_string.h 
  • branches/dev_elmar/SERVERCNTRL/servercntrl.cxx

    r7945 r8224  
    1313#include <client_privat.h> 
    1414#include <client.h> 
     15 
    1516#include <arbdb.h> 
     17#include <arb_file.h> 
    1618#include <ut_valgrinded.h> 
    1719 
     
    8486} 
    8587 
    86 GB_ERROR arb_start_server(const char *arb_tcp_env, GBDATA *gbmain, int do_sleep) 
     88GB_ERROR arb_start_server(const char *arb_tcp_env, int do_sleep) 
    8789{ 
    8890    const char *tcp_id; 
     
    153155 
    154156            if (!error) { 
    155 #if defined(DEBUG) 
    156                 printf("Starting server (cmd='%s')\n", command); 
    157 #endif // DEBUG 
    158                 if (!gbmain || GBCMC_system(gbmain, command)) system(command); 
     157                error = GBK_system(command); 
    159158                if (do_sleep) sleep(delay); 
    160159            } 
     
    166165} 
    167166 
    168 static GB_ERROR arb_wait_for_server(const char *arb_tcp_env, GBDATA *gbmain, const char *tcp_id, int magic_number, struct gl_struct *serverctrl, int wait) { 
     167static GB_ERROR arb_wait_for_server(const char *arb_tcp_env, const char *tcp_id, int magic_number, struct gl_struct *serverctrl, int wait) { 
    169168    serverctrl->link = aisc_open(tcp_id, &(serverctrl->com), magic_number); 
    170169    if (!serverctrl->link) { // no server running -> start one 
    171         GB_ERROR error = arb_start_server(arb_tcp_env, gbmain, 0); 
     170        GB_ERROR error = arb_start_server(arb_tcp_env, 0); 
    172171        if (error) return error; 
    173172 
     
    185184} 
    186185 
    187 GB_ERROR arb_look_and_start_server(long magic_number, const char *arb_tcp_env, GBDATA *gbmain) { 
     186GB_ERROR arb_look_and_start_server(long magic_number, const char *arb_tcp_env) { 
    188187    GB_ERROR    error       = 0; 
    189188    const char *tcp_id      = GBS_read_arb_tcp(arb_tcp_env); 
     
    244243 
    245244        if (!error) { 
    246             error = arb_wait_for_server(arb_tcp_env, gbmain, tcp_id, magic_number, &glservercntrl, 20); 
     245            error = arb_wait_for_server(arb_tcp_env, tcp_id, magic_number, &glservercntrl, 20); 
    247246 
    248247            if (!error) { 
  • branches/dev_elmar/SERVERCNTRL/servercntrl.h

    r6656 r8224  
    3232 
    3333char *prefixSSH(const char *host, const char *command, int async); 
    34 GB_ERROR arb_start_server(const char *arb_tcp_env, GBDATA *gbmain, int do_sleep); 
    35 GB_ERROR arb_look_and_start_server(long magic_number, const char *arb_tcp_env, GBDATA *gbmain); 
     34GB_ERROR arb_start_server(const char *arb_tcp_env, int do_sleep); 
     35GB_ERROR arb_look_and_start_server(long magic_number, const char *arb_tcp_env); 
    3636GB_ERROR arb_look_and_kill_server(int magic_number, const char *arb_tcp_env); 
    3737void arb_print_server_params(void); 
  • branches/dev_elmar/SH/README

    r7488 r8224  
    2929        arb_phyml                               wrapper for phyml 
    3030        arb_proml                               wrapper for proml 
    31         arb_protml                              wrapper for protml 
    3231        arb_protpars                            wrapper for protpars 
    3332        arb_raxml                               wrapper for raxml 
  • branches/dev_elmar/SH/arb_installubuntu4arb.sh

    r7489 r8224  
    44# 
    55# Tested with: 
    6 #       * Ubuntu 8.10 (Intrepid Ibex) 
     6#       * Ubuntu 10.04 (Lucid Lynx) 
    77# 
    88# [ May as well work with other ubuntu flavors or debian. 
  • branches/dev_elmar/SL/AW_NAME/AW_names_admin.cxx

    r7945 r8224  
    1717#include <aw_msg.hxx> 
    1818#include <aw_root.hxx> 
     19#include <awt_sel_boxes.hxx> 
     20 
     21#include <arb_file.h> 
    1922 
    2023static char *namesFilename(AW_CL cl_gb_main) { 
     
    5053                                           " %s", 
    5154                                           path, newpath, path); 
    52     GB_ERROR error = GB_system(command); 
     55    GB_ERROR error = GBK_system(command); 
    5356    if (error) aw_message(error); 
    5457 
     
    6568    else AW_advice("Calling 'Species/Generate New Names' is highly recommended", AW_ADVICE_TOGGLE|AW_ADVICE_HELP, 0, "namesadmin.hlp"); 
    6669} 
    67  
    68 static void edit_arb_tcp(AW_window *aww, AW_CL cl_gb_main) { 
    69     GBDATA *gb_main  = (GBDATA*)cl_gb_main; 
    70     char   *filename = GBS_find_lib_file("arb_tcp.dat", "", true); 
    71  
    72     AW_edit(filename, NULL, aww, gb_main); 
    73     free(filename); 
    74 } 
    75  
    7670 
    7771void AW_create_namesadmin_awars(AW_root *awr, GBDATA *gb_main) { 
     
    115109 
    116110    aws->at("config"); 
    117     aws->callback(edit_arb_tcp, cl_gb_main); 
     111    aws->callback(awt_edit_arbtcpdat_cb, cl_gb_main); 
    118112    aws->create_button("CREATE_TEMPLATE", "Configure arb_tcp.dat"); 
    119113 
  • branches/dev_elmar/SL/AW_NAME/AW_rename.cxx

    r7945 r8224  
    208208            const char *server_id = GBS_nameserver_tag(add_field); 
    209209 
    210             err = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_id, gb_main); 
     210            err = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_id); 
    211211 
    212212            if (!err) { 
  • branches/dev_elmar/SL/AW_NAME/Makefile

    r7945 r8224  
    4545AW_names_admin.o: $(ARBHOME)/INCLUDE/arb_core.h 
    4646AW_names_admin.o: $(ARBHOME)/INCLUDE/arb_error.h 
     47AW_names_admin.o: $(ARBHOME)/INCLUDE/arb_file.h 
    4748AW_names_admin.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    4849AW_names_admin.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    6061AW_names_admin.o: $(ARBHOME)/INCLUDE/aw_root.hxx 
    6162AW_names_admin.o: $(ARBHOME)/INCLUDE/aw_window.hxx 
     63AW_names_admin.o: $(ARBHOME)/INCLUDE/awt_sel_boxes.hxx 
    6264AW_names_admin.o: $(ARBHOME)/INCLUDE/cb.h 
    6365AW_names_admin.o: $(ARBHOME)/INCLUDE/dupstr.h 
  • branches/dev_elmar/SL/DB_QUERY/db_query.cxx

    • Property svn:mergeinfo changed from /trunk/SL/DB_QUERY/db_query.cxx:7771-7998 to /trunk/SL/DB_QUERY/db_query.cxx:7771-8223
  • branches/dev_elmar/SL/DB_QUERY/db_query.h

    • Property svn:mergeinfo changed from /trunk/SL/DB_QUERY/db_query.h:7771-7998 to /trunk/SL/DB_QUERY/db_query.h:7771-8223
  • branches/dev_elmar/SL/DB_QUERY/db_query_local.h

    • Property svn:mergeinfo changed from /trunk/SL/DB_QUERY/db_query_local.h:7771-7998 to /trunk/SL/DB_QUERY/db_query_local.h:7771-8223
  • branches/dev_elmar/SL/DB_UI/ui_species.cxx

    • Property svn:mergeinfo changed from /trunk/SL/DB_UI/ui_species.cxx:7771-7998 to /trunk/SL/DB_UI/ui_species.cxx:7771-8223
  • branches/dev_elmar/SL/ITEMS/changekey.cxx

    • Property svn:mergeinfo changed from /trunk/SL/ITEMS/changekey.cxx:7771-7998 to /trunk/SL/ITEMS/changekey.cxx:7771-8223
  • branches/dev_elmar/SL/ITEMS/item_sel_list.cxx

    • Property svn:mergeinfo changed from /trunk/SL/ITEMS/item_sel_list.cxx:7771-7998 to /trunk/SL/ITEMS/item_sel_list.cxx:7771-8223
  • branches/dev_elmar/SL/ITEMS/item_sel_list.h

    • Property svn:mergeinfo changed from /trunk/SL/ITEMS/item_sel_list.h:7771-7998 to /trunk/SL/ITEMS/item_sel_list.h:7771-8223
  • branches/dev_elmar/SL/ITEMS/items.h

    • Property svn:mergeinfo changed from /trunk/SL/ITEMS/items.h:7771-7998 to /trunk/SL/ITEMS/items.h:7771-8223
  • branches/dev_elmar/SL/ITEMS/species.cxx

    • Property svn:mergeinfo changed from /trunk/SL/ITEMS/species.cxx:7771-7998 to /trunk/SL/ITEMS/species.cxx:7771-8223
  • branches/dev_elmar/SL/Makefile

    r7945 r8224  
    11 
    22ARCHS_ALL = \ 
     3        PTCLEAN/PTCLEAN.dummy  \ 
    34        ALIVIEW/ALIVIEW.dummy  \ 
    45        AP_TREE/AP_TREE.dummy  \ 
  • branches/dev_elmar/SL/NDS/nds.cxx

    • Property svn:mergeinfo changed from /trunk/SL/NDS/nds.cxx:7771-7998 to /trunk/SL/NDS/nds.cxx:7771-8223
  • branches/dev_elmar/SL/NDS/nds.h

    • Property svn:mergeinfo changed from /trunk/SL/NDS/nds.h:7771-7998 to /trunk/SL/NDS/nds.h:7771-8223
  • branches/dev_elmar/SL/PRONUC/Makefile

    r7423 r8224  
    7979iupac.o: $(ARBHOME)/INCLUDE/arb_core.h 
    8080iupac.o: $(ARBHOME)/INCLUDE/arbdb_base.h 
     81iupac.o: $(ARBHOME)/INCLUDE/arbtools.h 
    8182iupac.o: $(ARBHOME)/INCLUDE/dupstr.h 
    8283iupac.o: $(ARBHOME)/INCLUDE/test_global.h 
  • branches/dev_elmar/SL/REFENTRIES/refentries.cxx

    • Property svn:mergeinfo changed from /trunk/SL/REFENTRIES/refentries.cxx:7771-7998 to /trunk/SL/REFENTRIES/refentries.cxx:7771-8223
  • branches/dev_elmar/SL/REFENTRIES/refentries.h

    • Property svn:mergeinfo changed from /trunk/SL/REFENTRIES/refentries.h:7771-7998 to /trunk/SL/REFENTRIES/refentries.h:7771-8223
  • branches/dev_elmar/SL/SEQIO/Makefile

    r7945 r8224  
    4646seq_export.o: $(ARBHOME)/INCLUDE/arb_core.h 
    4747seq_export.o: $(ARBHOME)/INCLUDE/arb_error.h 
     48seq_export.o: $(ARBHOME)/INCLUDE/arb_file.h 
    4849seq_export.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    4950seq_export.o: $(ARBHOME)/INCLUDE/arb_progress.h 
  • branches/dev_elmar/SL/SEQIO/seq_export.cxx

    r7945 r8224  
    1414#include <arbdbt.h> 
    1515#include <arb_strarray.h> 
     16#include <arb_file.h> 
    1617#include <xml.hxx> 
    1718#include <arb_progress.h> 
     
    560561 
    561562                GB_informationf("exec '%s'", efo.system); 
    562                 error = GB_system(sys); 
     563                error = GBK_system(sys); 
    563564 
    564565                GB_unlink_or_warn(intermediate_export, &error); 
  • branches/dev_elmar/SOURCE_TOOLS/arb_valgrind

    r7945 r8224  
    1818    echo '    -q             quiet' 
    1919    echo '    -L <file>      log stdout to <file> (does not work with -D)' 
     20    echo '    -E <file>      log stderr to <file> (does not work with -D)' 
     21    echo '                   Default is to collect output and print in after valgrind terminates' 
    2022    echo '    -D             run gdb on error' 
    2123    echo '    -e             return exitcode 1 on valgrind-errors' 
     
    6365    QUIET='' 
    6466    LOG_STDOUT='' 
     67    LOG_STDERR='' 
    6568    ERROR_EXITCODE='' 
    6669 
     
    120123            if [ "$1" = "-L" ] ; then 
    121124                LOG_STDOUT=$2 
     125                shift 2 
     126                SCAN_ARGS=1 
     127            fi 
     128            if [ "$1" = "-E" ] ; then 
     129                LOG_STDERR=$2 
    122130                shift 2 
    123131                SCAN_ARGS=1 
     
    162170        echo "VG_CMD='$VG_CMD $@'" 
    163171        if [ "$ATTACH" = "" ]; then 
     172            POSTDUMP_STDOUT=0 
     173            POSTDUMP_STDERR=0 
    164174            if [ -z "$LOG_STDOUT" ]; then 
    165175                LOG_STDOUT=/tmp/arb_valgrind_$USER_$$.stdout 
    166             fi 
    167             $VG_CMD --log-fd=3 "$@" 3>&1 >$LOG_STDOUT 2>&1 | $DIR/valgrind2grep $CALLERS "$FILTER" $SUPPX  
     176                POSTDUMP_STDOUT=1 
     177            fi 
     178            if [ -z "$LOG_STDERR" ]; then 
     179                LOG_STDERR=/tmp/arb_valgrind_$USER_$$.stderr 
     180                POSTDUMP_STDERR=1 
     181            fi 
     182            $VG_CMD --log-fd=3 "$@" 3>&1 >$LOG_STDOUT 2>$LOG_STDERR | $DIR/valgrind2grep $CALLERS "$FILTER" $SUPPX 
    168183            EXITCODE=${PIPESTATUS[0]} 
     184 
     185            if [ "$POSTDUMP_STDOUT" = "1" ]; then 
     186                echo "-------------------- [stdout of '$@' ]" 
     187                cat $LOG_STDOUT 
     188                rm $LOG_STDOUT 
     189            fi 
     190            if [ "$POSTDUMP_STDERR" = "1" ]; then 
     191                echo "-------------------- [stderr of '$@' ]" 
     192                cat $LOG_STDERR 
     193                rm $LOG_STDERR 
     194            fi 
     195            if [ "$POSTDUMP_STDOUT" = "1" -o "$POSTDUMP_STDERR" = "1" ]; then 
     196                echo "-------------------- [end of output]" 
     197            fi 
    169198        else 
    170199            $VG_CMD "$@" 
  • branches/dev_elmar/SOURCE_TOOLS/dep.4dummy

    r7945 r8224  
    2424PHYLO/PHYLO.dummy: AWT/AWT.dummy SL/MATRIX/MATRIX.dummy 
    2525PRIMER_DESIGN/PRIMER_DESIGN.dummy: AWT/AWT.dummy 
    26 PROBE/PROBE.dummy: PROBE_COM/PROBE_COM.dummy SERVERCNTRL/SERVERCNTRL.dummy SL/HELIX/HELIX.dummy 
     26PROBE/PROBE.dummy: PROBE_COM/PROBE_COM.dummy SERVERCNTRL/SERVERCNTRL.dummy SL/HELIX/HELIX.dummy SL/PTCLEAN/PTCLEAN.dummy 
    2727PROBE_DESIGN/PROBE_DESIGN.dummy: SERVERCNTRL/SERVERCNTRL.dummy SL/TREEDISP/TREEDISP.dummy 
    2828RNA3D/RNA3D.dummy: AWT/AWT.dummy GL/glAW/glAW.dummy GL/glpng/glpng.dummy SL/HELIX/HELIX.dummy 
     
    4848SL/NEIGHBOURJOIN/NEIGHBOURJOIN.dummy: ARBDB/ARBDB.dummy 
    4949SL/PRONUC/PRONUC.dummy: ARBDB/ARBDB.dummy 
     50SL/PTCLEAN/PTCLEAN.dummy: ARBDB/ARBDB.dummy 
    5051SL/REFENTRIES/REFENTRIES.dummy: WINDOW/WINDOW.dummy 
    5152SL/REGEXPR/REGEXPR.dummy: ARBDB/ARBDB.dummy 
  • branches/dev_elmar/SOURCE_TOOLS/dep.alltargets

    r7945 r8224  
    4848SL/NEIGHBOURJOIN/NEIGHBOURJOIN.a 
    4949SL/PRONUC/PRONUC.a 
     50SL/PTCLEAN/PTCLEAN.a 
    5051SL/REFENTRIES/REFENTRIES.a 
    5152SL/REGEXPR/REGEXPR.a 
  • branches/dev_elmar/SOURCE_TOOLS/dep.libtargets

    r7945 r8224  
    4848SL/NEIGHBOURJOIN/NEIGHBOURJOIN.a 
    4949SL/PRONUC/PRONUC.a 
     50SL/PTCLEAN/PTCLEAN.a 
    5051SL/REFENTRIES/REFENTRIES.a 
    5152SL/REGEXPR/REGEXPR.a 
  • branches/dev_elmar/SOURCE_TOOLS/generate_all_links.sh

    r7945 r8224  
    229229symlink_file ../CORE/arb_core.h INCLUDE/arb_core.h && 
    230230symlink_file ../CORE/arb_cs.h INCLUDE/arb_cs.h && 
     231symlink_file ../CORE/arb_file.h INCLUDE/arb_file.h && 
    231232symlink_file ../CORE/arb_msg.h INCLUDE/arb_msg.h && 
    232233symlink_file ../CORE/arb_signal.h INCLUDE/arb_signal.h && 
     
    278279symlink_file ../SL/PRONUC/AP_pro_a_nucs.hxx INCLUDE/AP_pro_a_nucs.hxx && 
    279280symlink_file ../SL/PRONUC/iupac.h INCLUDE/iupac.h && 
     281symlink_file ../SL/PTCLEAN/ptclean.h INCLUDE/ptclean.h && 
    280282symlink_file ../SL/REFENTRIES/refentries.h INCLUDE/refentries.h && 
    281283symlink_file ../SL/REGEXPR/RegExpr.hxx INCLUDE/RegExpr.hxx && 
  • branches/dev_elmar/SOURCE_TOOLS/postcompile.pl

    r7945 r8224  
    4141                  qr/^base\sclass\s.*has\sa\snon-virtual\sdestructor/, 
    4242                  qr/\sshould\sbe\sinitialized\sin\sthe\smember\sinitialization\slist/, 
    43  
     43                  qr/boost::icl::(insert|add)_iterator<ContainerT>.*should\sreturn/, # filter boost-iterator postfix operators warnings 
    4444                  qr/^\s\sbut\sdoes\snot\soverride/, # belongs to reg_Weffpp_copyable 
    4545                  qr/^\s\sor\s'operator=/, # belongs to reg_Weffpp_copyable 
     
    5050 
    5151# regexps for files: 
    52 my $reg_user_include = qr/^\/usr\/include\//; 
     52my $reg_user_include       = qr/^\/usr\/include\//; 
     53my $reg_HEADERLIBS_include = qr/\/HEADERLIBS\//; 
    5354 
    5455my $stop_after_first_error = 0; 
     
    217218} 
    218219 
     220sub is_system_or_builtin($) { 
     221  my ($file) = @_; 
     222  return (($file =~ $reg_user_include) or ($file eq '<built-in>') or ($file =~ $reg_HEADERLIBS_include)); 
     223} 
     224 
     225sub suppress_shadow_warning_for($) { 
     226  my ($file) = @_; 
     227  return is_system_or_builtin($file); 
     228} 
     229 
    219230sub parse_input(\@) { 
    220231  my ($out_r) = @_; 
     
    243254            $_ = suppress($_,@warnout); 
    244255          } 
     256          elsif (suppress_shadow_warning_for($file)) { 
     257            $_ = suppress($_,@warnout); 
     258            # $location_info = undef; 
     259          } 
    245260        } 
    246261        elsif ($warn_text =~ $reg_shadow_location) { 
    247262          if (not defined $shadow_warning) { warning('no shadow_warning seen',@warnout); } 
    248263          else { 
    249             if ($file =~ $reg_user_include or $file eq '<built-in>') { 
     264            if (suppress_shadow_warning_for($file)) { 
    250265              # don't warn about /usr/include or <built-in> shadowing 
    251266              $_ = suppress($_,@warnout); 
  • branches/dev_elmar/SOURCE_TOOLS/tabBrake.pl

    r7945 r8224  
    6767                                        'GDE/PHYML', 
    6868                                        'GDE/RAxML', 
    69                                         'GDE/MOLPHY', 
    7069                                        'GDE/SUPPORT', 
    7170                                        'GDE/PHYLIP', 
  • branches/dev_elmar/SOURCE_TOOLS/valgrind2grep

    r7408 r8224  
    108108  chomp; 
    109109  addFileIndex($_,$_); 
    110   # $fileIndex{$_} = $_; 
    111110  if (/\/([^\/]+)\/([^\/]+)$/) { 
    112111    my $last_dir = $1; 
     
    115114    addFileIndex($fname,$_); 
    116115    addFileIndex($last_dir.'/'.$fname,$_); 
    117     # $fileIndex{$fname} = $_; 
    118     # $fileIndex{$last_dir.'/'.$fname} = $_; 
    119116  } 
    120117  elsif (/\/([^\/]+)$/) { 
    121118    my $fname = $1; 
    122119    addFileIndex($fname,$_); 
    123     # $fileIndex{$fname} = $_; 
    124120  } 
    125121  else { 
     
    130126close(SOURCELIST); 
    131127 
     128sub parentDir($) { 
     129  my ($dirOrFile) = @_; 
     130  if ($dirOrFile =~ /\/[^\/]+$/o) { return $`; } 
     131  return undef; 
     132} 
     133 
    132134sub makeTargetAbsolute($$) { 
    133135  my ($abslink,$reltarget) = @_; 
    134   if ($abslink =~ /\/[^\/]+$/o) { 
    135     my $absdir = $`; 
    136     while ($reltarget =~ /^..\//o) { 
     136  my $absdir = parentDir($abslink); 
     137  if (defined $absdir) { 
     138    while ($reltarget =~ /^\.\.\//o) { 
    137139      $reltarget = $'; 
    138       if ($absdir =~ /\/[^\/]+$/o) { 
    139         $absdir = $`; 
     140      my $absparent = parentDir($absdir); 
     141      if (defined $absparent) { 
     142        $absdir = $absparent; 
    140143      } 
    141144      else { 
     
    143146      } 
    144147    } 
    145     # print "absdir='$absdir' reltarget='$reltarget'\n"; 
    146     return $absdir.'/'.$reltarget; 
     148 
     149    my $result = $absdir.'/'.$reltarget; 
     150    return $result; 
    147151  } 
    148152  else { 
  • branches/dev_elmar/STAT/ST_quality.cxx

    r7945 r8224  
    220220                            free(blownUp_report); 
    221221                        } 
    222                         if (report == ST_QUALITY_REPORT_TEMP) GB_set_temporary(gb_report); 
     222                        if (report == ST_QUALITY_REPORT_TEMP) error = GB_set_temporary(gb_report); 
    223223 
    224224                        delete [] report_str; 
  • branches/dev_elmar/TEMPLATES/attributes.h

    r7945 r8224  
    101101 
    102102// ------------------------------------------------------------ 
     103// casting result to void does not help when a function is 
     104// declared with __ATTR__USERESULT. Use 
     105 
     106#ifdef __cplusplus 
     107template <typename T> void IGNORE_RESULT(const T&) {} 
     108#endif 
     109 
     110// ------------------------------------------------------------ 
    103111// helper macros to declare attributed function prototype and 
    104112// start function definition in one line (static or inline functions only) 
  • branches/dev_elmar/TEMPLATES/ut_valgrinded.h

    r7945 r8224  
    2323#endif 
    2424 
    25  
    26 #define UTVG_ANY_SYSCALL "any.syscall" 
     25#define UTVG_CALL_SEEN "flag.valgrind.callseen" 
    2726 
    2827namespace utvg { 
     
    4241        const char  *path = flag_name(name); 
    4342        struct stat  stt; 
    44          
     43 
    4544        return stat(path, &stt) == 0 && S_ISREG(stt.st_mode); 
     45    } 
     46    inline void raise_flag(const char *name) { 
     47        const char *path = flag_name(name); 
     48        FILE       *fp   = fopen(path, "w"); 
     49        arb_assert(fp); 
     50        fclose(fp); 
    4651    } 
    4752 
     
    6065    }; 
    6166 
    62     inline void touch(const char *file) { 
    63         FILE *out = fopen(file, "w"); 
    64         fclose(out); 
     67    inline const valgrind_info& get_valgrind_info() { 
     68        static valgrind_info vinfo; 
     69        return vinfo; 
    6570    } 
    6671}; 
     
    6873inline void make_valgrinded_call(char *&command) { 
    6974    using namespace utvg; 
    70     static valgrind_info valgrind; 
     75    const valgrind_info& valgrind = get_valgrind_info(); 
    7176    if (valgrind.wanted) { 
    7277// #define VALGRIND_ONLY_SOME 
     
    8489        freeset(command, valgrinded_command); 
    8590 
    86         touch(flag_name(UTVG_ANY_SYSCALL)); 
     91        utvg::raise_flag(UTVG_CALL_SEEN); 
    8792    } 
    8893} 
     94 
     95inline bool will_valgrind_calls() { return utvg::get_valgrind_info().wanted; } 
     96inline bool seen_valgrinded_call() { return utvg::flag_exists(UTVG_CALL_SEEN); } 
    8997 
    9098#else 
    9199 
    92100#define make_valgrinded_call(command) 
     101inline bool will_valgrind_calls() { return false; } 
     102inline bool seen_valgrinded_call() { return false; } 
    93103 
    94104#endif 
  • branches/dev_elmar/TOOLS/Makefile

    r7945 r8224  
    295295arb_replace.o: $(ARBHOME)/INCLUDE/arb_core.h 
    296296arb_replace.o: $(ARBHOME)/INCLUDE/arb_error.h 
     297arb_replace.o: $(ARBHOME)/INCLUDE/arb_file.h 
    297298arb_replace.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    298299arb_replace.o: $(ARBHOME)/INCLUDE/arb_strbuf.h 
     
    312313arb_test.o: $(ARBHOME)/INCLUDE/arb_defs.h 
    313314arb_test.o: $(ARBHOME)/INCLUDE/arb_error.h 
     315arb_test.o: $(ARBHOME)/INCLUDE/arb_file.h 
    314316arb_test.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    315317arb_test.o: $(ARBHOME)/INCLUDE/arb_string.h 
  • branches/dev_elmar/TOOLS/arb_2_ascii.cxx

    r7945 r8224  
    5959        else { 
    6060            error = GB_save(gb_main, out, saveflags); 
     61            GB_close(gb_main); 
    6162        } 
    62  
    63         GB_close(gb_main); 
    6463    } 
    6564 
  • branches/dev_elmar/TOOLS/arb_2_bin.cxx

    r7190 r8224  
    6666        printf("Reading database...\n"); 
    6767        GB_shell  shell; 
    68         GBDATA   *gb_main = GBT_open(in, rtype, 0); 
     68        GBDATA   *gb_main = GBT_open(in, rtype); 
    6969        if (!gb_main) { 
    7070            error = GB_await_error(); 
  • branches/dev_elmar/TOOLS/arb_export_rates.cxx

    r7945 r8224  
    7777    if (!error) { 
    7878        GB_shell  shell; 
    79         GBDATA   *gb_main = GBT_open(dbname, "r", 0); 
     79        GBDATA   *gb_main = GBT_open(dbname, "r"); 
    8080        if (!gb_main) { 
    8181            error = GB_await_error(); 
  • branches/dev_elmar/TOOLS/arb_export_tree.cxx

    r7945 r8224  
    5959 
    6060            GB_shell  shell; 
    61             GBDATA   *gb_main = GBT_open(db_name, "r", 0); 
     61            GBDATA   *gb_main = GBT_open(db_name, "r"); 
    6262 
    6363            if (!gb_main) error = GB_await_error(); 
  • branches/dev_elmar/TOOLS/arb_notify.cxx

    r6381 r8224  
    2323    if (!progname || progname[0] == 0) progname = "arb_notify"; 
    2424 
     25    GB_shell shell; 
    2526    GBDATA *gb_main = GB_open(":", "r"); 
    2627    if (!gb_main) { 
  • branches/dev_elmar/TOOLS/arb_perf_test.cxx

    r7945 r8224  
    148148    else { 
    149149        char *in = argv[1]; 
    150         gb_main  = GBT_open(in, "rw", 0); 
     150        gb_main  = GBT_open(in, "rw"); 
    151151 
    152152        if (!gb_main) { 
  • branches/dev_elmar/TOOLS/arb_probe.cxx

    r7999 r8224  
    7979    const char *server_tag = GBS_ptserver_tag(P.SERVERID); 
    8080 
    81     error = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag, 0); 
     81    error = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag); 
    8282    if (error) return NULL; 
    8383     
     
    319319 
    320320#ifdef UNIT_TESTS 
    321     const int minServerID   = TEST_SERVER_ID; 
     321    const int minServerID   = TEST_GENESERVER_ID; 
    322322#else // !UNIT_TESTS 
    323323    const int minServerID   = 0; 
     
    326326    P.SERVERID = getInt("serverid", 0, minServerID, 100, "Server Id, look into $ARBHOME/lib/arb_tcp.dat"); 
    327327#ifdef UNIT_TESTS 
    328     if (P.SERVERID<0) { arb_assert(P.SERVERID == TEST_SERVER_ID); } 
     328    if (P.SERVERID<0) { arb_assert(P.SERVERID == TEST_SERVER_ID || P.SERVERID == TEST_GENESERVER_ID); } 
    329329#endif 
    330330 
     
    455455#endif 
    456456 
    457 static void test_setup() { 
    458     static bool setup = false; 
    459     if (!setup) { 
    460         TEST_SETUP_GLOBAL_ENVIRONMENT("ptserver"); // first call will recreate the test pt-server 
    461         setup = true; 
    462     } 
     457static int test_setup(bool use_gene_ptserver) { 
     458    static bool setup[2] = { false, false }; 
     459    if (!setup[use_gene_ptserver]) { 
     460        TEST_SETUP_GLOBAL_ENVIRONMENT(use_gene_ptserver ? "ptserver_gene" : "ptserver"); // first call will recreate the test pt-server 
     461        setup[use_gene_ptserver] = true; 
     462    } 
     463    return use_gene_ptserver ? TEST_GENESERVER_ID : TEST_SERVER_ID; 
     464} 
     465 
     466// ---------------------------------- 
     467//      test probe design / match 
     468 
     469#define TEST_PART1(fake_argc,fake_argv)                                                 \ 
     470    int       serverid = test_setup(use_gene_ptserver);                                 \ 
     471    TEST_ASSERT_EQUAL(true, parseCommandLine(fake_argc, fake_argv));                    \ 
     472    TEST_ASSERT((serverid == TEST_SERVER_ID)||(serverid == TEST_GENESERVER_ID));        \ 
     473    P.SERVERID         = serverid;                                                      \ 
     474    ARB_ERROR error;                                                                    \ 
     475    char      *answer   = execute(error);                                               \ 
     476    TEST_ASSERT_NO_ERROR(error.deliver()) 
     477 
     478 
     479#define TEST_ARB_PROBE(fake_argc,fake_argv,expected) do {               \ 
     480        TEST_PART1(fake_argc,fake_argv);                                \ 
     481        TEST_ASSERT_EQUAL(answer, expected);                            \ 
     482        free(answer);                                                   \ 
     483    } while(0) 
     484 
     485#define TEST_ARB_PROBE__BROKEN(fake_argc,fake_argv,expected) do {       \ 
     486        TEST_PART1(fake_argc,fake_argv);                                \ 
     487        TEST_ASSERT_EQUAL__BROKEN(answer, expected);                    \ 
     488        free(answer);                                                   \ 
     489    } while(0) 
     490 
     491#define TEST_ARB_PROBE_FILT(fake_argc,fake_argv,filter,expected) do {   \ 
     492        TEST_PART1(fake_argc,fake_argv);                                \ 
     493        char  *filtered   = filter(answer);                             \ 
     494        TEST_ASSERT_EQUAL(filtered, expected);                          \ 
     495        free(filtered);                                                 \ 
     496        free(answer);                                                   \ 
     497    } while(0) 
     498 
     499typedef const char *CCP; 
     500 
     501void TEST_SLOW_match_geneprobe() { 
     502    bool use_gene_ptserver = true; 
     503    { 
     504        const char *arguments[] = { 
     505            "prgnamefake", 
     506            "matchsequence=NNUCNN", 
     507            "matchacceptN=4",  
     508            "matchlimitN=5",  
     509        }; 
     510        CCP expectd = "    organism genename------- mis N_mis wmis pos gpos rev          'NNUCNN'\1" 
     511            "genome2\1" "  genome2  gene3             0     4  0.0   2    1 0   .........-UU==GG-UUGAUC\1" 
     512            "genome2\1" "  genome2  joined1           0     4  0.0   2    1 0   .........-UU==GG-UUGAUCCUG\1" 
     513            "genome2\1" "  genome2  gene2             0     4  0.0  10    4 0   ......GUU-GA==CU-GCCA\1" 
     514            "genome2\1" "  genome2  intergene_19_65   0     4  0.0  31   12 0   GGUUACUGC-AU==GG-UGUUCGCCU\1" 
     515            "genome1\1" "  genome1  intergene_17_65   0     4  0.0  31   14 0   GGUUACUGC-UA==GG-UGUUCGCCU\1" 
     516            "genome2\1" "  genome2  intergene_19_65   0     4  0.0  38   19 0   GCAUUCGGU-GU==GC-CUAAGCACU\1" 
     517            "genome1\1" "  genome1  intergene_17_65   0     4  0.0  38   21 0   GCUAUCGGU-GU==GC-CUAAGCCAU\1" 
     518            "genome1\1" "  genome1  intergene_17_65   0     4  0.0  56   39 0   AGCCAUGCG-AG==AU-AUGUA\1" ""; 
     519         
     520        TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd); 
     521    } 
     522    { 
     523        const char *arguments[] = { 
     524            "prgnamefake", 
     525            "matchsequence=NGGUUN", 
     526            "matchacceptN=2",  
     527            "matchlimitN=3",  
     528        }; 
     529        CCP expectd = "    organism genename------- mis N_mis wmis pos gpos rev          'NGGUUN'\1" 
     530            "genome1\1" "  genome1  joined1           0     2  0.0   5    2 0   ........C-U====G-AUCCUGC\1" 
     531            "genome2\1" "  genome2  intergene_19_65   0     2  0.0  21    2 0   ........G-A====A-CUGCAUUCG\1" 
     532            "genome1\1" "  genome1  intergene_17_65   0     2  0.0  21    4 0   ......CAG-A====A-CUGCUAUCG\1" 
     533            "genome2\1" "  genome2  gene3             0     2  0.0   5    4 0   ......UUU-C====G-AUC\1" 
     534            "genome2\1" "  genome2  joined1           0     2  0.0   5    4 0   ......UUU-C====G-AUCCUGCCA\1" ""; 
     535 
     536        TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd); 
     537    } 
     538 
     539    { 
     540        const char *arguments[] = { 
     541            "prgnamefake", 
     542            "matchsequence=UGAUCCU", // exists in data 
     543        }; 
     544        CCP expectd = "    organism genename mis N_mis wmis pos gpos rev          'UGAUCCU'\1" 
     545            "genome1\1" "  genome1  gene2      0     0  0.0   9    1 0   .........-=======-GC\1" 
     546            "genome2\1" "  genome2  gene2      0     0  0.0   9    3 0   .......GU-=======-GCCA\1" ""; 
     547 
     548        TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd); // @@@ defect: probe exists as well in 'joined1' (of both genomes) 
     549    } 
     550    { 
     551        const char *arguments[] = { 
     552            "prgnamefake", 
     553            "matchsequence=GAUCCU", 
     554        }; 
     555        CCP expectd = "    organism genename mis N_mis wmis pos gpos rev          'GAUCCU'\1" 
     556            "genome2\1" "  genome2  gene2      0     0  0.0  10    4 0   ......GUU-======-GCCA\1" ""; 
     557 
     558        TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd); // @@@ defect: probe is part of above probe, but reports less hits 
     559    } 
     560    { 
     561        const char *arguments[] = { 
     562            "prgnamefake", 
     563            "matchsequence=UUUCGG", // exists only in genome2  
     564        }; 
     565        CCP expectd = "    organism genename mis N_mis wmis pos gpos rev          'UUUCGG'\1" 
     566            "genome2\1" "  genome2  gene3      0     0  0.0   2    1 0   .........-======-UUGAUC\1" 
     567            "genome2\1" "  genome2  joined1    0     0  0.0   2    1 0   .........-======-UUGAUCCUG\1" ""; 
     568 
     569        TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd); // @@@ defect: also exists in genome2/gene1 
     570    } 
     571    { 
     572        const char *arguments[] = { 
     573            "prgnamefake", 
     574            "matchsequence=AUCCUG",  
     575        }; 
     576        CCP expectd = "    organism genename mis N_mis wmis pos gpos rev          'AUCCUG'\1" 
     577            "genome2\1" "  genome2  gene2      0     0  0.0  11    5 0   .....GUUG-======-CCA\1" ""; 
     578 
     579        TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd); // @@@ defect: exists in 'gene2' and 'joined1' of both genomes 
     580    } 
     581    { 
     582        const char *arguments[] = { 
     583            "prgnamefake", 
     584            "matchsequence=UUGAUCCUGC", 
     585        }; 
     586        CCP expectd = "    organism genename mis N_mis wmis pos gpos rev          'UUGAUCCUGC'\1" 
     587            "genome2\1" "  genome2  gene2      0     0  0.0   8    2 0   ........G-==========-CA\1" 
     588            "genome1\1" "  genome1  joined1    0     0  0.0   8    5 0   .....CUGG-==========-\1" ""; 
     589 
     590        TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd); // @@@ defect: also exists in 'genome2/joined1' 
     591    } 
     592} 
     593 
     594void TEST_SLOW_match_probe() { 
     595    bool use_gene_ptserver = false; 
     596    { 
     597        const char *arguments[] = { 
     598            "prgnamefake", 
     599            "matchsequence=UAUCGGAGAGUUUGA", 
     600        }; 
     601        CCP expected = "    name---- fullname mis N_mis wmis pos ecoli rev          'UAUCGGAGAGUUUGA'\1" 
     602            "BcSSSS00\1" "  BcSSSS00            0     0  0.0   3     2 0   .......UU-===============-UCAAGUCGA\1"; 
     603 
     604        TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expected); 
     605    } 
     606 
     607    // ---------------------------------------------------------------------------- 
     608    //      match with old(=default) N-mismatch-behavior (accepting 1 N-match) 
     609 
     610    { 
     611        const char *arguments[] = { 
     612            "prgnamefake", 
     613            "matchsequence=CANCUCCUUUC", // contains 1 N 
     614            NULL // matchmismatches 
     615        }; 
     616 
     617        CCP expectd0 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCUCCUUUC'\1" 
     618            "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176   162 0   CGGCUGGAU-==C========-U\1" ""; // only N-mismatch accepted 
     619 
     620        CCP expectd1 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCUCCUUUC'\1" 
     621            "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176   162 0   CGGCUGGAU-==C========-U\1" 
     622            "PbcAcet2\1" "  PbcAcet2            0     2  0.0 176   162 0   CGGCUGGAU-==C=======N-N\1" 
     623            "ClfPerfr\1" "  ClfPerfr            1     1  0.0 176   162 0   AGAUUAAUA-=CC========-U\1"; 
     624 
     625        CCP expectd2 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCUCCUUUC'\1" 
     626            "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176   162 0   CGGCUGGAU-==C========-U\1" 
     627            "PbcAcet2\1" "  PbcAcet2            0     2  0.0 176   162 0   CGGCUGGAU-==C=======N-N\1" 
     628            "DlcTolu2\1" "  DlcTolu2            0     3  0.0 176   162 0   CGGCUGGAU-==C======NN-N\1" 
     629            "ClfPerfr\1" "  ClfPerfr            1     1  0.0 176   162 0   AGAUUAAUA-=CC========-U\1"; 
     630 
     631        arguments[2] = "matchmismatches=0";  TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
     632        arguments[2] = "matchmismatches=1";  TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
     633        arguments[2] = "matchmismatches=2";  TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
     634    } 
     635    { 
     636        const char *arguments[] = { 
     637            "prgnamefake", 
     638            "matchsequence=UCACCUCCUUUC", // contains no N 
     639            NULL // matchmismatches 
     640        }; 
     641 
     642        CCP expectd0 = "    name---- fullname mis N_mis wmis pos ecoli rev          'UCACCUCCUUUC'\1" 
     643            "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175   161 0   GCGGCUGGA-============-U\1" 
     644            "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175   161 0   GCGGCUGGA-===========N-N\1"; 
     645 
     646        CCP expectd1 = "    name---- fullname mis N_mis wmis pos ecoli rev          'UCACCUCCUUUC'\1" 
     647            "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175   161 0   GCGGCUGGA-============-U\1" 
     648            "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175   161 0   GCGGCUGGA-===========N-N\1" 
     649            "DlcTolu2\1" "  DlcTolu2            0     2  0.0 175   161 0   GCGGCUGGA-==========NN-N\1" ""; 
     650 
     651        CCP expectd2 = "    name---- fullname mis N_mis wmis pos ecoli rev          'UCACCUCCUUUC'\1" 
     652            "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175   161 0   GCGGCUGGA-============-U\1" 
     653            "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175   161 0   GCGGCUGGA-===========N-N\1" 
     654            "DlcTolu2\1" "  DlcTolu2            0     2  0.0 175   161 0   GCGGCUGGA-==========NN-N\1" 
     655            "ClfPerfr\1" "  ClfPerfr            2     0  0.0 175   161 0   AAGAUUAAU-A=C=========-U\1" ""; 
     656 
     657        arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
     658        arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
     659        arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
     660    } 
     661 
     662    // ---------------------------------------------- 
     663    //      do not accept any N-matches as match 
     664 
     665    { 
     666        const char *arguments[] = { 
     667            "prgnamefake", 
     668            "matchsequence=CANCUCCUUUC", // contains 1 N 
     669            NULL, // matchmismatches 
     670            "matchacceptN=0", 
     671        }; 
     672 
     673        CCP expectd0 = ""; // nothing matches 
     674 
     675        CCP expectd1 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCUCCUUUC'\1" 
     676            "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176   162 0   CGGCUGGAU-==C========-U\1" ""; 
     677  
     678        CCP expectd2 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCUCCUUUC'\1" 
     679            "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176   162 0   CGGCUGGAU-==C========-U\1" 
     680            "PbcAcet2\1" "  PbcAcet2            0     2  0.0 176   162 0   CGGCUGGAU-==C=======N-N\1" 
     681            "ClfPerfr\1" "  ClfPerfr            1     1  0.0 176   162 0   AGAUUAAUA-=CC========-U\1" ""; 
     682 
     683        arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
     684        arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
     685        arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
     686    } 
     687    { 
     688        const char *arguments[] = { 
     689            "prgnamefake", 
     690            "matchsequence=UCACCUCCUUUC", // contains no N 
     691            NULL, // matchmismatches 
     692            "matchacceptN=0", 
     693        }; 
     694 
     695        CCP expectd0 = "    name---- fullname mis N_mis wmis pos ecoli rev          'UCACCUCCUUUC'\1" 
     696            "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175   161 0   GCGGCUGGA-============-U\1" ""; 
     697 
     698        CCP expectd1 = "    name---- fullname mis N_mis wmis pos ecoli rev          'UCACCUCCUUUC'\1" 
     699            "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175   161 0   GCGGCUGGA-============-U\1" 
     700            "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175   161 0   GCGGCUGGA-===========N-N\1" ""; 
     701 
     702        CCP expectd2 = "    name---- fullname mis N_mis wmis pos ecoli rev          'UCACCUCCUUUC'\1" 
     703            "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175   161 0   GCGGCUGGA-============-U\1" 
     704            "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175   161 0   GCGGCUGGA-===========N-N\1" 
     705            "DlcTolu2\1" "  DlcTolu2            0     2  0.0 175   161 0   GCGGCUGGA-==========NN-N\1" 
     706            "ClfPerfr\1" "  ClfPerfr            2     0  0.0 175   161 0   AAGAUUAAU-A=C=========-U\1" ""; 
     707         
     708        arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
     709        arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
     710        arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
     711    } 
     712 
     713    // ---------------------------------- 
     714    //      accept several N-matches 
     715 
     716    { 
     717        const char *arguments[] = { 
     718            "prgnamefake", 
     719            "matchsequence=CANCUCCUUNC", // contains 2 N 
     720            NULL, // matchmismatches 
     721            "matchacceptN=2", 
     722            "matchlimitN=4", 
     723        }; 
     724 
     725        CCP expectd0 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCUCCUUNC'\1" 
     726            "BcSSSS00\1" "  BcSSSS00            0     2  0.0 176   162 0   CGGCUGGAU-==C======U=-U\1" ""; 
     727 
     728        CCP expectd1 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCUCCUUNC'\1" 
     729            "BcSSSS00\1" "  BcSSSS00            0     2  0.0 176   162 0   CGGCUGGAU-==C======U=-U\1" 
     730            "DlcTolu2\1" "  DlcTolu2            0     3  0.0 176   162 0   CGGCUGGAU-==C=======N-N\1" 
     731            "PbcAcet2\1" "  PbcAcet2            0     3  0.0 176   162 0   CGGCUGGAU-==C======UN-N\1" 
     732            "ClfPerfr\1" "  ClfPerfr            1     2  0.0 176   162 0   AGAUUAAUA-=CC======U=-U\1" ""; 
     733         
     734        CCP expectd2 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCUCCUUNC'\1" 
     735            "BcSSSS00\1" "  BcSSSS00            0     2  0.0 176   162 0   CGGCUGGAU-==C======U=-U\1" 
     736            "DlcTolu2\1" "  DlcTolu2            0     3  0.0 176   162 0   CGGCUGGAU-==C=======N-N\1" 
     737            "PbcAcet2\1" "  PbcAcet2            0     3  0.0 176   162 0   CGGCUGGAU-==C======UN-N\1" 
     738            "ClfPerfr\1" "  ClfPerfr            1     2  0.0 176   162 0   AGAUUAAUA-=CC======U=-U\1" ""; 
     739         
     740        arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
     741        arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
     742        arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
     743    } 
     744 
     745    // -------------------------- 
     746    //      truncate results 
     747 
     748    { 
     749        const char *arguments[] = { 
     750            "prgnamefake", 
     751            "matchsequence=CANCNCNNUNC", // contains 5N 
     752            NULL, // matchmismatches 
     753            "matchacceptN=5", 
     754            "matchlimitN=7", 
     755            "matchmaxresults=5", 
     756        }; 
     757 
     758        CCP expectd0 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCNCNNUNC'\1" 
     759            "BcSSSS00\1" "  BcSSSS00            0     5  0.0 176   162 0   CGGCUGGAU-==C=U=CU=U=-U\1" ""; 
     760 
     761        CCP expectd1 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCNCNNUNC'\1" 
     762            "BcSSSS00\1" "  BcSSSS00            0     5  0.0 176   162 0   CGGCUGGAU-==C=U=CU=U=-U\1" 
     763            "DlcTolu2\1" "  DlcTolu2            0     6  0.0 176   162 0   CGGCUGGAU-==C=U=CU==N-N\1" 
     764            "PbcAcet2\1" "  PbcAcet2            0     6  0.0 176   162 0   CGGCUGGAU-==C=U=CU=UN-N\1" 
     765            "LgtLytic\1" "  LgtLytic            1     5  0.0  31    26 0   GUCGAACGG-==G=A=AG=CU-AGCUUGCUA\1" 
     766            "ClfPerfr\1" "  ClfPerfr            1     5  0.0 111    99 0   CGGCUGGAU-==U=AUAA=G=-AGCGAUUGG\1"; // one hit is truncated here 
     767         
     768        CCP expectd2 = "    name---- fullname mis N_mis wmis pos ecoli rev          'CANCNCNNUNC'\1" 
     769            "VbrFurni\1" "  VbrFurni            2     5  0.0  40    35 0   CGGCAGCGA-==A=AUUGAA=-CUUCGGGGG\1" 
     770            "HllHalod\1" "  HllHalod            2     5  0.0  45    40 0   AAACGAUGG-A=G=UUGC=U=-CAGGCGUCG\1" 
     771            "VblVulni\1" "  VblVulni            2     5  0.0  49    44 0   AGCACAGAG-A=A=UUGU=U=-UCGGGUGGC\1" 
     772            "LgtLytic\1" "  LgtLytic            2     5  0.0 101    89 0   GGGGAAACU-==AGCUAA=A=-CGCAUAAUC\1" 
     773            "ClfPerfr\1" "  ClfPerfr            2     5  0.0 172   158 0   AGGAAGAUU-A=UAC=CC=C=-UUUCU\1"; // many hits are truncated here 
     774 
     775        arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
     776        arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
     777        arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
     778    } 
     779} 
     780 
     781static char *extract_locations(const char *probe_design_result) { 
     782    const char *Target = strstr(probe_design_result, "\nTarget"); 
     783    if (Target) { 
     784        const char *designed = strchr(Target+7, '\n'); 
     785        if (designed) { 
     786            ++designed; 
     787            char *result = strdup(""); 
     788 
     789            while (designed) { 
     790                const char *eol       = strchr(designed, '\n'); 
     791                const char *space1    = strchr(designed, ' ');          if (!space1) break; // 1st space between probe and len 
     792                const char *nonspace  = space1+strspn(space1, " ");     if (!nonspace) break; 
     793                const char *space2    = strchr(nonspace, ' ');          if (!space2) break; // 1st space between len and "X=" 
     794                const char *nonspace2 = space2+strspn(space2, " ");     if (!nonspace2) break; 
     795                const char *space3    = strchr(nonspace2, ' ');         if (!space3) break; // 1st space between "X=" and abs 
     796                const char *nonspace3 = space3+strspn(space3, " ");     if (!nonspace3) break; 
     797                const char *space4    = strchr(nonspace3, ' ');         if (!space4) break; // 1st space between abs and rest 
     798 
     799                char *abs = GB_strpartdup(nonspace3, space4-1); 
     800 
     801                freeset(result, GBS_global_string_copy("%s%c%c%s", result, space2[1], space2[2], abs)); 
     802                free(abs); 
     803 
     804                designed = eol ? eol+1 : NULL; 
     805            } 
     806 
     807            return result; 
     808        } 
     809    } 
     810    return strdup("can't extract"); 
     811} 
     812 
     813void TEST_SLOW_design_probe() { 
     814    bool use_gene_ptserver = false; 
     815    const char *arguments[] = { 
     816        "prgnamefake", 
     817        "designnames=ClnCorin#CltBotul#CPPParap#ClfPerfr", 
     818        "designmintargets=100", 
     819    }; 
     820    const char *expected =  
     821        "Probe design Parameters:\n" 
     822        "Length of probe      18\n" 
     823        "Temperature        [ 0.0 -400.0]\n" 
     824        "GC-Content         [30.0 -80.0]\n" 
     825        "E.Coli Position    [any]\n" 
     826        "Max Non Group Hits     0\n" 
     827        "Min Group Hits       100%\n" 
     828        "Target             le     apos ecol grps  G+C 4GC+2AT Probe sequence     | Decrease T by n*.3C -> probe matches n non group species\n" 
     829        "CGAAAGGAAGAUUAAUAC 18 A=    94   82    4 33.3 48.0    GUAUUAAUCUUCCUUUCG |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
     830        "GAAAGGAAGAUUAAUACC 18 A+     1   83    4 33.3 48.0    GGUAUUAAUCUUCCUUUC |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
     831        "UCAAGUCGAGCGAUGAAG 18 B=    18   17    4 50.0 54.0    CUUCAUCGCUCGACUUGA |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
     832        "AUCAAGUCGAGCGAUGAA 18 B-     1   16    4 44.4 52.0    UUCAUCGCUCGACUUGAU |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  2,  3,\n"; 
     833 
     834    TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expected); 
     835 
     836    // ------------------------------------------------------ 
     837    //      design MANY probes to test location specifier 
     838 
     839    { 
     840        char *positions = extract_locations(expected); 
     841        TEST_ASSERT_EQUAL(positions, "A=94A+1B=18B-1"); 
     842        free(positions); 
     843    } 
     844 
     845    const char *arguments_loc[] = { 
     846        "prgnamefake", 
     847        // "designnames=Stsssola#Stsssola", // @@@ crashes the ptserver 
     848        "designnames=CPPParap#PsAAAA00", 
     849        "designmintargets=50", // hit at least 1 of the 2 targets 
     850        "designmingc=0", "designmaxgc=100", // allow all GCs 
     851        "designmishit=99999",  // allow enough outgroup hits 
     852        "designmaxhits=99999", // do not limit results 
     853        "designprobelength=3", 
     854    }; 
     855 
     856    const char *expected_loc =  
     857        "A=96B=141C=20D=107B+1E=110F=84G=9H=150I=145C+1D+1J=17K=122L=72C-1M=33N=114E+1O=163" 
     858        "P=24E+2F+1Q=138R=54O+1S=49A-1T=87G+1J-1N-1U=79F+2U-1V=129I+2H-2C+2W=12D-1D+2C-2R+1" 
     859        "P-1J-2O+2V-2X=92W+2W+1Y=125Z=176D-2H+1a=104H-1L+1"; 
     860 
     861    TEST_ARB_PROBE_FILT(ARRAY_ELEMS(arguments_loc), arguments_loc, extract_locations, expected_loc); 
     862} 
     863 
     864void TEST_SLOW_match_designed_probe() { 
     865    bool use_gene_ptserver = false; 
     866    const char *arguments[] = { 
     867        "prgnamefake",  
     868        "matchsequence=UCAAGUCGAGCGAUGAAG",  
     869    }; 
     870    CCP expected = "    name---- fullname mis N_mis wmis pos ecoli rev          'UCAAGUCGAGCGAUGAAG'\1" 
     871        "ClnCorin\1" "  ClnCorin            0     0  0.0  18    17 0   .GAGUUUGA-==================-UUCCUUCGG\1" 
     872        "CltBotul\1" "  CltBotul            0     0  0.0  18    17 0   ........A-==================-CUUCUUCGG\1" 
     873        "CPPParap\1" "  CPPParap            0     0  0.0  18    17 0   AGAGUUUGA-==================-UUCCUUCGG\1" 
     874        "ClfPerfr\1" "  ClfPerfr            0     0  0.0  18    17 0   AGAGUUUGA-==================-UUUCCUUCG\1"; 
     875 
     876    TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expected); 
    463877} 
    464878 
    465879void TEST_SLOW_variable_defaults_in_server() { 
    466     test_setup(); 
     880    test_setup(false); 
    467881 
    468882    const char *server_tag = GBS_ptserver_tag(TEST_SERVER_ID); 
    469     TEST_ASSERT_NO_ERROR(arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag, 0)); 
     883    TEST_ASSERT_NO_ERROR(arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag)); 
    470884 
    471885    const char *servername = GBS_read_arb_tcp(server_tag);; 
     
    521935} 
    522936 
    523 // ---------------------------------- 
    524 //      test probe design / match 
    525  
    526 #define TEST_PART1(fake_argc,fake_argv)                                 \ 
    527     test_setup();                                                       \ 
    528     TEST_ASSERT_EQUAL(true, parseCommandLine(fake_argc, fake_argv));    \ 
    529     P.SERVERID = TEST_SERVER_ID;                                        \ 
    530     ARB_ERROR  error;                                                   \ 
    531     char      *answer = execute(error);                                 \ 
    532     TEST_ASSERT_NO_ERROR(error.deliver());                              \ 
    533  
    534  
    535 #define TEST_ARB_PROBE(fake_argc,fake_argv,expected) do {               \ 
    536         TEST_PART1(fake_argc,fake_argv);                                \ 
    537         TEST_ASSERT_EQUAL(answer, expected);                            \ 
    538         free(answer);                                                   \ 
    539     } while(0) 
    540  
    541 #define TEST_ARB_PROBE__BROKEN(fake_argc,fake_argv,expected) do {       \ 
    542         TEST_PART1(fake_argc,fake_argv);                                \ 
    543         TEST_ASSERT_EQUAL__BROKEN(answer, expected);                    \ 
    544         free(answer);                                                   \ 
    545     } while(0) 
    546  
    547 #define TEST_ARB_PROBE_FILT(fake_argc,fake_argv,filter,expected) do {   \ 
    548         TEST_PART1(fake_argc,fake_argv);                                \ 
    549         char  *filtered   = filter(answer);                             \ 
    550         TEST_ASSERT_EQUAL(filtered, expected);                          \ 
    551         free(filtered);                                                 \ 
    552         free(answer);                                                   \ 
    553     } while(0) 
    554  
    555 void TEST_SLOW_match_probe() { 
    556     typedef const char *CCP; 
    557     { 
    558         const char *arguments[] = { 
    559             "fake", // "program"-name 
    560             "matchsequence=UAUCGGAGAGUUUGA", 
    561         }; 
    562         CCP expected = "    name---- fullname mis N_mis wmis pos rev          'UAUCGGAGAGUUUGA'\1" 
    563             "BcSSSS00\1" "  BcSSSS00            0     0  0.0   3 0   .......UU-===============-UCAAGUCGA\1"; 
    564  
    565         TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expected); 
    566     } 
    567  
    568     // ---------------------------------------------------------------------------- 
    569     //      match with old(=default) N-mismatch-behavior (accepting 1 N-match) 
    570  
    571     { 
    572         const char *arguments[] = { 
    573             "fake", // "program"-name 
    574             "matchsequence=CANCUCCUUUC", // contains 1 N 
    575             NULL // matchmismatches 
    576         }; 
    577  
    578         CCP expectd0 = "    name---- fullname mis N_mis wmis pos rev          'CANCUCCUUUC'\1" 
    579             "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176 0   CGGCUGGAU-==C========-U\1"; // only N-mismatch accepted 
    580  
    581         CCP expectd1 = "    name---- fullname mis N_mis wmis pos rev          'CANCUCCUUUC'\1" 
    582             "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176 0   CGGCUGGAU-==C========-U\1"  
    583             "PbcAcet2\1" "  PbcAcet2            0     2  0.0 176 0   CGGCUGGAU-==C=======N-N\1"  
    584             "ClfPerfr\1" "  ClfPerfr            1     1  0.0 176 0   AGAUUAAUA-=CC========-U\1"; 
    585  
    586         CCP expectd2 = "    name---- fullname mis N_mis wmis pos rev          'CANCUCCUUUC'\1" 
    587             "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176 0   CGGCUGGAU-==C========-U\1" 
    588             "PbcAcet2\1" "  PbcAcet2            0     2  0.0 176 0   CGGCUGGAU-==C=======N-N\1" 
    589             "DlcTolu2\1" "  DlcTolu2            0     3  0.0 176 0   CGGCUGGAU-==C======NN-N\1" 
    590             "ClfPerfr\1" "  ClfPerfr            1     1  0.0 176 0   AGAUUAAUA-=CC========-U\1"; 
    591  
    592         arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
    593         arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
    594         arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
    595     } 
    596     { 
    597         const char *arguments[] = { 
    598             "fake", // "program"-name 
    599             "matchsequence=UCACCUCCUUUC", // contains no N 
    600             NULL // matchmismatches 
    601         }; 
    602  
    603         CCP expectd0 = "    name---- fullname mis N_mis wmis pos rev          'UCACCUCCUUUC'\1" 
    604             "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175 0   GCGGCUGGA-============-U\1" 
    605             "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175 0   GCGGCUGGA-===========N-N\1" ""; 
    606  
    607         CCP expectd1 = "    name---- fullname mis N_mis wmis pos rev          'UCACCUCCUUUC'\1" 
    608             "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175 0   GCGGCUGGA-============-U\1" 
    609             "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175 0   GCGGCUGGA-===========N-N\1" 
    610             "DlcTolu2\1" "  DlcTolu2            0     2  0.0 175 0   GCGGCUGGA-==========NN-N\1" ""; 
    611  
    612         CCP expectd2 = "    name---- fullname mis N_mis wmis pos rev          'UCACCUCCUUUC'\1" 
    613             "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175 0   GCGGCUGGA-============-U\1" 
    614             "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175 0   GCGGCUGGA-===========N-N\1" 
    615             "DlcTolu2\1" "  DlcTolu2            0     2  0.0 175 0   GCGGCUGGA-==========NN-N\1" 
    616             "ClfPerfr\1" "  ClfPerfr            2     0  0.0 175 0   AAGAUUAAU-A=C=========-U\1" ""; 
    617  
    618         arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
    619         arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
    620         arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
    621     } 
    622  
    623     // ---------------------------------------------- 
    624     //      do not accept any N-matches as match 
    625  
    626     { 
    627         const char *arguments[] = { 
    628             "fake", // "program"-name 
    629             "matchsequence=CANCUCCUUUC", // contains 1 N 
    630             NULL, // matchmismatches 
    631             "matchacceptN=0", 
    632         }; 
    633  
    634         CCP expectd0 = ""; // nothing matches 
    635  
    636         CCP expectd1 = "    name---- fullname mis N_mis wmis pos rev          'CANCUCCUUUC'\1" 
    637             "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176 0   CGGCUGGAU-==C========-U\1" ""; 
    638  
    639         CCP expectd2 = "    name---- fullname mis N_mis wmis pos rev          'CANCUCCUUUC'\1" 
    640             "BcSSSS00\1" "  BcSSSS00            0     1  0.0 176 0   CGGCUGGAU-==C========-U\1" 
    641             "PbcAcet2\1" "  PbcAcet2            0     2  0.0 176 0   CGGCUGGAU-==C=======N-N\1" 
    642             "ClfPerfr\1" "  ClfPerfr            1     1  0.0 176 0   AGAUUAAUA-=CC========-U\1" ""; 
    643  
    644         arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
    645         arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
    646         arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
    647     } 
    648     { 
    649         const char *arguments[] = { 
    650             "fake", // "program"-name 
    651             "matchsequence=UCACCUCCUUUC", // contains no N 
    652             NULL, // matchmismatches 
    653             "matchacceptN=0", 
    654         }; 
    655  
    656         CCP expectd0 = "    name---- fullname mis N_mis wmis pos rev          'UCACCUCCUUUC'\1" 
    657             "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175 0   GCGGCUGGA-============-U\1" ""; 
    658  
    659         CCP expectd1 = "    name---- fullname mis N_mis wmis pos rev          'UCACCUCCUUUC'\1" 
    660             "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175 0   GCGGCUGGA-============-U\1" 
    661             "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175 0   GCGGCUGGA-===========N-N\1" ""; 
    662  
    663         CCP expectd2 = "    name---- fullname mis N_mis wmis pos rev          'UCACCUCCUUUC'\1" 
    664             "BcSSSS00\1" "  BcSSSS00            0     0  0.0 175 0   GCGGCUGGA-============-U\1" 
    665             "PbcAcet2\1" "  PbcAcet2            0     1  0.0 175 0   GCGGCUGGA-===========N-N\1" 
    666             "DlcTolu2\1" "  DlcTolu2            0     2  0.0 175 0   GCGGCUGGA-==========NN-N\1" 
    667             "ClfPerfr\1" "  ClfPerfr            2     0  0.0 175 0   AAGAUUAAU-A=C=========-U\1" ""; 
    668          
    669         arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
    670         arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
    671         arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
    672     } 
    673  
    674     // ---------------------------------- 
    675     //      accept several N-matches 
    676  
    677     { 
    678         const char *arguments[] = { 
    679             "fake", // "program"-name 
    680             "matchsequence=CANCUCCUUNC", // contains 2 N 
    681             NULL, // matchmismatches 
    682             "matchacceptN=2", 
    683             "matchlimitN=4", 
    684         }; 
    685  
    686         CCP expectd0 = "    name---- fullname mis N_mis wmis pos rev          'CANCUCCUUNC'\1" 
    687             "BcSSSS00\1" "  BcSSSS00            0     2  0.0 176 0   CGGCUGGAU-==C======U=-U\1" ""; 
    688          
    689         CCP expectd1 = "    name---- fullname mis N_mis wmis pos rev          'CANCUCCUUNC'\1" 
    690             "BcSSSS00\1" "  BcSSSS00            0     2  0.0 176 0   CGGCUGGAU-==C======U=-U\1" 
    691             "DlcTolu2\1" "  DlcTolu2            0     3  0.0 176 0   CGGCUGGAU-==C=======N-N\1" 
    692             "PbcAcet2\1" "  PbcAcet2            0     3  0.0 176 0   CGGCUGGAU-==C======UN-N\1" 
    693             "ClfPerfr\1" "  ClfPerfr            1     2  0.0 176 0   AGAUUAAUA-=CC======U=-U\1" ""; 
    694          
    695         CCP expectd2 = "    name---- fullname mis N_mis wmis pos rev          'CANCUCCUUNC'\1" 
    696             "BcSSSS00\1" "  BcSSSS00            0     2  0.0 176 0   CGGCUGGAU-==C======U=-U\1" 
    697             "DlcTolu2\1" "  DlcTolu2            0     3  0.0 176 0   CGGCUGGAU-==C=======N-N\1" 
    698             "PbcAcet2\1" "  PbcAcet2            0     3  0.0 176 0   CGGCUGGAU-==C======UN-N\1" 
    699             "ClfPerfr\1" "  ClfPerfr            1     2  0.0 176 0   AGAUUAAUA-=CC======U=-U\1" ""; 
    700          
    701         arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
    702         arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
    703         arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
    704     } 
    705  
    706     // -------------------------- 
    707     //      truncate results 
    708  
    709     { 
    710         const char *arguments[] = { 
    711             "fake", // "program"-name 
    712             "matchsequence=CANCNCNNUNC", // contains 5N 
    713             NULL, // matchmismatches 
    714             "matchacceptN=5", 
    715             "matchlimitN=7", 
    716             "matchmaxresults=5", 
    717         }; 
    718  
    719         CCP expectd0 = "    name---- fullname mis N_mis wmis pos rev          'CANCNCNNUNC'\1" 
    720             "BcSSSS00\1" "  BcSSSS00            0     5  0.0 176 0   CGGCUGGAU-==C=U=CU=U=-U\1" ""; 
    721              
    722         CCP expectd1 = "    name---- fullname mis N_mis wmis pos rev          'CANCNCNNUNC'\1"  
    723             "BcSSSS00\1" "  BcSSSS00            0     5  0.0 176 0   CGGCUGGAU-==C=U=CU=U=-U\1" 
    724             "DlcTolu2\1" "  DlcTolu2            0     6  0.0 176 0   CGGCUGGAU-==C=U=CU==N-N\1" 
    725             "PbcAcet2\1" "  PbcAcet2            0     6  0.0 176 0   CGGCUGGAU-==C=U=CU=UN-N\1" 
    726             "LgtLytic\1" "  LgtLytic            1     5  0.0  31 0   GUCGAACGG-==G=A=AG=CU-AGCUUGCUA\1" 
    727             "ClfPerfr\1" "  ClfPerfr            1     5  0.0 111 0   CGGCUGGAU-==U=AUAA=G=-AGCGAUUGG\1"; // one hit is truncated here 
    728          
    729         CCP expectd2 = "    name---- fullname mis N_mis wmis pos rev          'CANCNCNNUNC'\1" 
    730             "VbrFurni\1" "  VbrFurni            2     5  0.0  40 0   CGGCAGCGA-==A=AUUGAA=-CUUCGGGGG\1" 
    731             "HllHalod\1" "  HllHalod            2     5  0.0  45 0   AAACGAUGG-A=G=UUGC=U=-CAGGCGUCG\1" 
    732             "VblVulni\1" "  VblVulni            2     5  0.0  49 0   AGCACAGAG-A=A=UUGU=U=-UCGGGUGGC\1" 
    733             "LgtLytic\1" "  LgtLytic            2     5  0.0 101 0   GGGGAAACU-==AGCUAA=A=-CGCAUAAUC\1" 
    734             "ClfPerfr\1" "  ClfPerfr            2     5  0.0 172 0   AGGAAGAUU-A=UAC=CC=C=-UUUCU\1" ""; // many hits are truncated here 
    735  
    736         arguments[2] = "matchmismatches=0"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd0); 
    737         arguments[2] = "matchmismatches=1"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd1); 
    738         arguments[2] = "matchmismatches=2"; TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expectd2); 
    739     } 
    740 } 
    741  
    742 static char *extract_locations(const char *probe_design_result) { 
    743     const char *Target = strstr(probe_design_result, "\nTarget"); 
    744     if (Target) { 
    745         const char *designed = strchr(Target+7, '\n'); 
    746         if (designed) { 
    747             ++designed; 
    748             char *result = strdup(""); 
    749  
    750             while (designed) { 
    751                 const char *eol       = strchr(designed, '\n'); 
    752                 const char *space1    = strchr(designed, ' ');          if (!space1) break; // 1st space between probe and len 
    753                 const char *nonspace  = space1+strspn(space1, " ");     if (!nonspace) break; 
    754                 const char *space2    = strchr(nonspace, ' ');          if (!space2) break; // 1st space between len and "X=" 
    755                 const char *nonspace2 = space2+strspn(space2, " ");     if (!nonspace2) break; 
    756                 const char *space3    = strchr(nonspace2, ' ');         if (!space3) break; // 1st space between "X=" and abs 
    757                 const char *nonspace3 = space3+strspn(space3, " ");     if (!nonspace3) break; 
    758                 const char *space4    = strchr(nonspace3, ' ');         if (!space4) break; // 1st space between abs and rest 
    759  
    760                 char *abs = GB_strpartdup(nonspace3, space4-1); 
    761  
    762                 freeset(result, GBS_global_string_copy("%s%c%c%s", result, space2[1], space2[2], abs)); 
    763                 free(abs); 
    764  
    765                 designed = eol ? eol+1 : NULL; 
    766             } 
    767  
    768             return result; 
    769         } 
    770     } 
    771     return strdup("can't extract"); 
    772 } 
    773  
    774 void TEST_SLOW_design_probe() { 
    775     const char *arguments[] = { 
    776         "fake", // "program"-name 
    777         "designnames=ClnCorin#CltBotul#CPPParap#ClfPerfr", 
    778         "designmintargets=100", 
    779     }; 
    780     const char *expected =  
    781         "Probe design Parameters:\n" 
    782         "Length of probe      18\n" 
    783         "Temperature        [ 0.0 -400.0]\n" 
    784         "GC-Content         [30.0 -80.0]\n" 
    785         "E.Coli Position    [any]\n" 
    786         "Max Non Group Hits     0\n" 
    787         "Min Group Hits       100%\n" 
    788         "Target             le     apos ecol grps  G+C 4GC+2AT Probe sequence     | Decrease T by n*.3C -> probe matches n non group species\n" 
    789         "CGAAAGGAAGAUUAAUAC 18 A=    94   94    4 33.3 48.0    GUAUUAAUCUUCCUUUCG |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
    790         "GAAAGGAAGAUUAAUACC 18 A+     1   95    4 33.3 48.0    GGUAUUAAUCUUCCUUUC |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
    791         "UCAAGUCGAGCGAUGAAG 18 B=    18   18    4 50.0 54.0    CUUCAUCGCUCGACUUGA |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
    792         "AUCAAGUCGAGCGAUGAA 18 B-     1   17    4 44.4 52.0    UUCAUCGCUCGACUUGAU |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  2,  3,\n"; 
    793  
    794     TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expected); 
    795  
    796     // ------------------------------------------------------ 
    797     //      design MANY probes to test location specifier 
    798  
    799     { 
    800         char *positions = extract_locations(expected); 
    801         TEST_ASSERT_EQUAL(positions, "A=94A+1B=18B-1"); 
    802         free(positions); 
    803     } 
    804  
    805     const char *arguments_loc[] = { 
    806         "fake", // "program"-name 
    807         // "designnames=Stsssola#Stsssola", // @@@ crashes the ptserver 
    808         "designnames=CPPParap#PsAAAA00", 
    809         "designmintargets=50", // hit at least 1 of the 2 targets 
    810         "designmingc=0", "designmaxgc=100", // allow all GCs 
    811         "designmishit=99999",  // allow enough outgroup hits 
    812         "designmaxhits=99999", // do not limit results 
    813         "designprobelength=3", 
    814     }; 
    815  
    816     const char *expected_loc =  
    817         "A=96B=141C=20D=107B+1E=110F=84G=9H=150I=145C+1D+1J=17K=122L=72C-1M=33N=114E+1O=163" 
    818         "P=24E+2F+1Q=138R=54O+1S=49A-1T=87G+1J-1N-1U=79F+2U-1V=129I+2H-2C+2W=12D-1D+2C-2R+1" 
    819         "P-1J-2O+2V-2X=92W+2W+1Y=125Z=176D-2H+1a=104H-1L+1"; 
    820  
    821     TEST_ARB_PROBE_FILT(ARRAY_ELEMS(arguments_loc), arguments_loc, extract_locations, expected_loc); 
    822 } 
    823  
    824 void TEST_SLOW_match_designed_probe() { 
    825     const char *arguments[] = { 
    826         "fake", // "program"-name  
    827         "matchsequence=UCAAGUCGAGCGAUGAAG",  
    828     }; 
    829     const char *expected = 
    830     "    name---- fullname mis N_mis wmis pos rev          'UCAAGUCGAGCGAUGAAG'\1" 
    831     "ClnCorin\1" "  ClnCorin            0     0  0.0  18 0   .GAGUUUGA-==================-UUCCUUCGG\1" 
    832     "CltBotul\1" "  CltBotul            0     0  0.0  18 0   ........A-==================-CUUCUUCGG\1" 
    833     "CPPParap\1" "  CPPParap            0     0  0.0  18 0   AGAGUUUGA-==================-UUCCUUCGG\1" 
    834     "ClfPerfr\1" "  ClfPerfr            0     0  0.0  18 0   AGAGUUUGA-==================-UUUCCUUCG\1"; 
    835  
    836     TEST_ARB_PROBE(ARRAY_ELEMS(arguments), arguments, expected); 
    837 } 
    838  
    839  
    840937#endif 
  • branches/dev_elmar/TOOLS/arb_replace.cxx

    r7314 r8224  
    1010 
    1111#include <arb_strbuf.h> 
     12#include <arb_file.h> 
    1213#include <arbdb.h> 
    1314 
  • branches/dev_elmar/TOOLS/arb_test.cxx

    r7945 r8224  
    1212#include <arbdbt.h> 
    1313#include <arb_defs.h> 
     14#include <unistd.h> 
    1415 
    1516int main(int, char **) { 
     
    2122 
    2223#ifdef UNIT_TESTS 
     24#include <arb_file.h> 
    2325#include <test_unit.h> 
    2426#include <ut_valgrinded.h> 
     
    2729 
    2830 
     31inline void make_valgrinded_call_from_pipe(char *&command) { 
     32    using namespace utvg; 
     33    static valgrind_info valgrind; 
     34    if (valgrind.wanted) { 
     35        char *pipeSym = strchr(command, '|'); 
     36        if (pipeSym) { 
     37            char *left  = GB_strpartdup(command, pipeSym-1); 
     38            char *right = strdup(pipeSym+1); 
     39 
     40            make_valgrinded_call(left); 
     41            make_valgrinded_call_from_pipe(right); 
     42 
     43            freeset(command, GBS_global_string_copy("%s | %s", left, right)); 
     44 
     45            free(right); 
     46            free(left); 
     47        } 
     48        else { 
     49            make_valgrinded_call(command); 
     50        } 
     51    } 
     52} 
     53 
    2954inline GB_ERROR valgrinded_system(const char *cmdline) { 
    30     char     *cmddup = strdup(cmdline); 
    31     make_valgrinded_call(cmddup); 
    32     GB_ERROR  error  = GB_system(cmddup); 
     55    char *cmddup = strdup(cmdline); 
     56    make_valgrinded_call_from_pipe(cmddup); 
     57 
     58    GB_ERROR error = GBK_system(cmddup); 
    3359    free(cmddup); 
    3460    return error; 
     
    3662 
    3763#define RUN_TOOL(cmdline)                valgrinded_system(cmdline) 
    38 #define RUN_TOOL_NEVER_VALGRIND(cmdline) GB_system(cmdline) 
     64#define RUN_TOOL_NEVER_VALGRIND(cmdline) GBK_system(cmdline) 
    3965 
    4066#define TEST_RUN_TOOL(cmdline)                TEST_ASSERT_NO_ERROR(RUN_TOOL(cmdline)) 
     
    5581    // test conversion (bin->ascii->bin) via stream (this tests 'arb_repair') 
    5682    TEST_RUN_TOOL(GBS_global_string("arb_2_ascii %s - | arb_2_bin - %s", binary, binary_2ND)); 
     83 
    5784    // TEST_ASSERT_FILES_EQUAL(binary, binary_2ND); // can't compare binary files (they contain undefined bytes) 
     85 
     86    // instead convert back to ascii and compare result with original 
    5887    TEST_ASSERT_ZERO_OR_SHOW_ERRNO(GB_unlink(ascii)); 
    5988    TEST_RUN_TOOL(GBS_global_string("arb_2_ascii %s %s", binary_2ND, ascii)); 
    6089    TEST_ASSERT_FILES_EQUAL(ascii, ascii_ORG); 
    61      
     90 
    6291    TEST_ASSERT_ZERO_OR_SHOW_ERRNO(GB_unlink(ascii)); 
    6392    TEST_ASSERT_ZERO_OR_SHOW_ERRNO(GB_unlink(binary)); 
     
    6594    TEST_ASSERT_ZERO_OR_SHOW_ERRNO(GB_unlink("ascii2bin.ARF")); 
    6695    TEST_ASSERT_ZERO_OR_SHOW_ERRNO(GB_unlink("ascii2bin2.ARF")); 
    67 } 
    68  
    69 void TEST_SLOW_arb_gene_probe() { 
    70     const char *genome   = "tools/gene_probe.arb"; 
    71     const char *out      = "tools/gene_probe_out.arb"; 
    72     const char *expected = "tools/gene_probe_expected.arb"; 
    73  
    74     TEST_RUN_TOOL(GBS_global_string("arb_gene_probe %s %s", genome, out)); 
    75     TEST_ASSERT_FILES_EQUAL(out, expected); 
    76     TEST_ASSERT_ZERO_OR_SHOW_ERRNO(GB_unlink(out)); 
    77     TEST_ASSERT_ZERO_OR_SHOW_ERRNO(GB_unlink("tools/gene_probe_out.ARM")); 
    7896} 
    7997 
     
    180198 
    181199void TEST_arb_replace() { 
    182     const char *infile = "tools/gene_probe.arb"; 
     200    const char *infile = "tools/arb_replace.in"; 
    183201    const char *file1  = "tools/arb_replace_1.out"; 
    184202    const char *file2  = "tools/arb_replace_2.out"; 
     
    221239            char *cmd = GBS_global_string_copy("bash -c '%s >stdout.log 2>stderr.log'", escaped); 
    222240 
    223             appendError(GB_system(cmd)); 
     241            appendError(GBK_system(cmd)); 
    224242            free(cmd); 
    225243            free(escaped); 
     
    298316                       " matchsequence=UAUCGGAGAGUUUGA", 
    299317 
    300                        "    name---- fullname mis N_mis wmis pos rev          'UAUCGGAGAGUUUGA'" 
    301                        "BcSSSS00" 
    302                        "  BcSSSS00            0     0  0.0   3 0   .......UU-===============-UCAAGUCGA" 
    303                        ); 
     318                       /* ---- */ "    name---- fullname mis N_mis wmis pos ecoli rev          'UAUCGGAGAGUUUGA'\1" 
     319                       "BcSSSS00\1" "  BcSSSS00            0     0  0.0   3     2 0   .......UU-===============-UCAAGUCGA\1" 
     320        ); 
    304321 
    305322    TEST_STDOUT_EQUALS("arb_probe" 
     
    316333                       "Min Group Hits       100%\n" 
    317334                       "Target             le     apos ecol grps  G+C 4GC+2AT Probe sequence     | Decrease T by n*.3C -> probe matches n non group species\n" 
    318                        "CGAAAGGAAGAUUAAUAC 18 A=    94   94    4 33.3 48.0    GUAUUAAUCUUCCUUUCG |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
    319                        "GAAAGGAAGAUUAAUACC 18 A+     1   95    4 33.3 48.0    GGUAUUAAUCUUCCUUUC |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
    320                        "UCAAGUCGAGCGAUGAAG 18 B=    18   18    4 50.0 54.0    CUUCAUCGCUCGACUUGA |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
    321                        "AUCAAGUCGAGCGAUGAA 18 B-     1   17    4 44.4 52.0    UUCAUCGCUCGACUUGAU |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  2,  3,\n" 
     335                       "CGAAAGGAAGAUUAAUAC 18 A=    94   82    4 33.3 48.0    GUAUUAAUCUUCCUUUCG |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
     336                       "GAAAGGAAGAUUAAUACC 18 A+     1   83    4 33.3 48.0    GGUAUUAAUCUUCCUUUC |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
     337                       "UCAAGUCGAGCGAUGAAG 18 B=    18   17    4 50.0 54.0    CUUCAUCGCUCGACUUGA |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,\n" 
     338                       "AUCAAGUCGAGCGAUGAA 18 B-     1   16    4 44.4 52.0    UUCAUCGCUCGACUUGAU |  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  2,  3,\n" 
    322339                       ); 
    323340} 
     
    371388} 
    372389 
     390static char *notification_result = NULL; 
     391static void test_notification_cb(const char *message, void *cd) { 
     392    const char *cds     = (const char *)cd; 
     393    notification_result = GBS_global_string_copy("message='%s' cd='%s'", message, cds); 
     394} 
     395 
     396#define INIT_NOTIFICATION                                                                       \ 
     397    GB_shell shell;                                                                             \ 
     398    GBDATA *gb_main = GBT_open("nosuch.arb", "crw");                                            \ 
     399    const char *cd  = "some argument";                                                          \ 
     400    char *cmd = GB_generate_notification(gb_main, test_notification_cb, "the note", (void*)cd) 
     401 
     402#define EXIT_NOTIFICATION       \ 
     403    GB_close(gb_main);          \ 
     404    free(cmd) 
     405     
     406#define TEST_DBSERVER_OPEN(gbmain) TEST_ASSERT_NO_ERROR(GBCMS_open(":", 0, gbmain)) 
     407#define TEST_DBSERVER_SERVE_UNTIL(gbmain, cond) do {                    \ 
     408        bool success            = GBCMS_accept_calls(gb_main, false);   \ 
     409        while (success) success = GBCMS_accept_calls(gb_main, true);    \ 
     410        GB_usleep(10000);                                               \ 
     411    } while(!(cond)) 
     412 
     413#define TEST_DBSERVER_CLOSE(gbmain) GBCMS_shutdown(gb_main) 
     414 
     415void TEST_close_with_pending_notification() { 
     416    INIT_NOTIFICATION; 
     417    EXIT_NOTIFICATION; 
     418} 
     419void TEST_close_after_pending_notification_removed() { 
     420    INIT_NOTIFICATION; 
     421    TEST_ASSERT_NO_ERROR(GB_remove_last_notification(gb_main)); 
     422    EXIT_NOTIFICATION; 
     423} 
     424void TEST_arb_notify() { 
     425    INIT_NOTIFICATION; 
     426 
     427    TEST_DBSERVER_OPEN(gb_main); 
     428 
     429    TEST_ASSERT_NULL(notification_result); 
     430    TEST_ASSERT_NO_ERROR(GBK_system(GBS_global_string("%s &", cmd))); // async call to arb_notify 
     431 
     432    TEST_DBSERVER_SERVE_UNTIL(gb_main, notification_result); 
     433    TEST_DBSERVER_CLOSE(gb_main); 
     434 
     435    TEST_ASSERT_EQUAL(notification_result, "message='the note' cd='some argument'"); 
     436    freenull(notification_result); 
     437 
     438    EXIT_NOTIFICATION; 
     439} 
     440 
    373441#endif // UNIT_TESTS 
    374442 
  • branches/dev_elmar/UNIT_TESTER/Makefile

    r7945 r8224  
    6464TestEnvironment.o: $(ARBHOME)/INCLUDE/arb_defs.h 
    6565TestEnvironment.o: $(ARBHOME)/INCLUDE/arb_error.h 
     66TestEnvironment.o: $(ARBHOME)/INCLUDE/arb_file.h 
    6667TestEnvironment.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    6768TestEnvironment.o: $(ARBHOME)/INCLUDE/arb_str.h 
  • branches/dev_elmar/UNIT_TESTER/Makefile.suite

    r7945 r8224  
    1212PATCHNAMESUFFIX:= 
    1313 
     14VALGRIND_INTERNAL=$(findstring B,$(VALGRIND))$(findstring A,$(VALGRIND)) 
     15VALGRIND_EXTERNAL=$(findstring E,$(VALGRIND)) 
     16VALGRIND_ANY=$(VALGRIND_INTERNAL)$(VALGRIND_EXTERNAL) 
     17 
    1418# -------------------- build patch name 
    1519 
     
    1721PATCHNAMESUFFIX:=$(PATCHNAMESUFFIX)__only_$(RESTRICT_LIB) 
    1822endif 
     23 
    1924ifneq ($(RESTRICT_MODULE),'.') 
    2025PATCHNAMESUFFIX:=$(PATCHNAMESUFFIX)__notAllFiles 
    2126endif 
     27 
    2228SKIPPED_SLOW:=$(shell (test -f skipslow.stamp && ls -1 skipslow.stamp)) 
    2329ifneq ('$(SKIPPED_SLOW)','') 
    2430PATCHNAMESUFFIX:=$(PATCHNAMESUFFIX)__SLOW_skipped 
    2531endif 
     32 
     33ifneq ('$(VALGRIND_ANY)','') 
     34PATCHNAMESUFFIX:=$(PATCHNAMESUFFIX)__valgrinded_$(VALGRIND_ANY) 
     35endif 
     36 
    2637PATCHNAMESUFFIX:=$(subst :,_,$(PATCHNAMESUFFIX)) 
    2738 
    2839# -------------------- targets 
    2940 
    30 VALGRIND_EXTERNAL=$(findstring E,$(VALGRIND)) 
    31  
    3241cleanup_environment: 
    33         ./test_environment clean 
     42        ./test_environment clean || echo "Failed to clean environment (maybe some setup/cleanup crashed?)" 
    3443ifeq ($(VALGRIND_EXTERNAL),E) 
    3544        ./valgrind/arb_valgrind_logged WAIT 
  • branches/dev_elmar/UNIT_TESTER/README.txt

    r7945 r8224  
    157157   stored inside $ARBHOME/patches.arb/ 
    158158 
    159    After DELETE_PATCHES_AFTER seconds the patch will be deleted automatically 
    160    (see Makefile.setup.local). 
     159   After PATCHES_KEEP_HOURS seconds the patch will be deleted automatically 
     160   (see Makefile.setup.local), considering at least PATCHES_MIN_KEPT patches remain. 
    161161 
    1621628. Building tests 
  • branches/dev_elmar/UNIT_TESTER/TestEnvironment.cxx

    r7945 r8224  
    1414#include <arb_defs.h> 
    1515#include <arb_str.h> 
     16#include <arb_file.h> 
    1617#include <arbdb.h> 
    1718#include <PT_com.h> 
     
    2728 
    2829#include <sys/stat.h> 
     30#include <sys/time.h> 
    2931 
    3032 
     
    3941enum Mode { UNKNOWN, SETUP, CLEAN }; 
    4042static const char *mode_command[] = { NULL, "setup", "clean" }; // same order as in enum Mode 
    41  
    42 typedef GB_ERROR Error; 
     43static Mode other_mode[] = { UNKNOWN, CLEAN, SETUP };  
     44 
     45typedef SmartCharPtr Error; 
    4346 
    4447static const char *upcase(const char *str) { 
     
    6366} 
    6467 
     68#if defined(DEBUG) 
     69// #define DUMP_MUTEX_ACCESS 
     70#endif 
     71 
     72 
    6573class Mutex : virtual Noncopyable { 
    6674    string name; 
     
    6876 
    6977    bool mutexdir_exists() const { return GB_is_directory(mutexdir.c_str()); } 
     78 
     79    static const char *now() { 
     80        static char buf[100]; 
     81        timeval t; 
     82        gettimeofday(&t, NULL); 
     83        sprintf(buf, "%li.%li", t.tv_sec, t.tv_usec); 
     84        return buf; 
     85    } 
    7086 
    7187    static set<string> known_mutexes; 
     
    8399        arb_assert(maxwait>0); 
    84100 
     101        test_data().entered_mutex_loop = true; // avoid race-condition 
    85102        while (!gotMutex) { 
    86103            if (mutexdir_exists()) { 
    87104                if (wait>maxwait && mutexdir_exists()) { 
    88                     GBK_terminatef("Failed to get mutex for more than %i seconds", maxwait); 
    89                 } 
    90                 printf("mutex '%s' exists.. sleeping\n", name.c_str()); 
     105                    GBK_terminatef("[%s] Failed to get mutex for more than %i seconds", now(), maxwait); 
     106                } 
     107                printf("[%s] mutex '%s' exists.. sleeping\n", now(), name.c_str()); 
    91108                sleep(1); 
    92109                wait++; 
     
    95112                int res = mkdir(mutexdir.c_str(), S_IRWXU); 
    96113                if (res == 0) { 
    97                     printf("allocated mutex '%s'\n", name.c_str()); 
     114#if defined(DUMP_MUTEX_ACCESS) 
     115                    printf("[%s] allocated mutex '%s'\n", now(), name.c_str()); 
     116#endif 
    98117                    gotMutex = true; 
    99118                } 
    100119                else { 
    101120                    wait = 0; // reset timeout 
    102                     printf("lost race for mutex '%s'\n", name.c_str()); 
     121                    printf("[%s] lost race for mutex '%s'\n", now(), name.c_str()); 
    103122                } 
    104123            } 
     
    108127    ~Mutex() { 
    109128        if (!mutexdir_exists()) { 
    110             printf("Strange - mutex '%s' has vanished\n", name.c_str()); 
     129            printf("[%s] Strange - mutex '%s' has vanished\n", now(), name.c_str()); 
    111130        } 
    112131        else { 
    113132            if (rmdir(mutexdir.c_str()) != 0) { 
    114133                const char *error = GB_IO_error("remove", mutexdir.c_str()); 
    115                 GBK_terminatef("Failed to release mutex dir (%s)", error); 
     134                GBK_terminatef("[%s] Failed to release mutex dir (%s)", now(), error); 
    116135            } 
    117136            else { 
    118                 printf("released mutex '%s'\n", mutexdir.c_str()); 
     137#if defined(DUMP_MUTEX_ACCESS) 
     138                printf("[%s] released mutex '%s'\n", now(), mutexdir.c_str()); 
     139#endif 
    119140            } 
    120141        } 
     
    162183        if (!fp) { 
    163184            GB_ERROR error = GB_IO_error("creating flag", flagfile); 
    164             StaticCode::errorf(__FILE__, __LINE__, "%s\n", error); 
     185            HERE.errorf(true, "%s\n", error); 
    165186        } 
    166187        fclose(fp); 
     
    176197        if (res != 0) { 
    177198            GB_ERROR error = GB_IO_error("unlinking", flagfile); 
    178             StaticCode::errorf(__FILE__, __LINE__, "%s\n", error); 
     199            HERE.errorf(true, "%s\n", error); 
    179200        } 
    180201        env_assert(!flagFileExists()); 
     
    209230    PersistantFlag& operator = (bool b) { 
    210231        if (b != bool(*this)) { 
     232            StaticCode::printf("Changing flag '%s' to %i\n", name.c_str(), int(b)); 
    211233            value = b; 
    212234            updateFlagFile(); 
     
    270292//      ptserver 
    271293 
    272 static void test_ptserver_activate(bool start) { 
    273     const char *server_tag = GBS_ptserver_tag(TEST_SERVER_ID); 
     294static void test_ptserver_activate(bool start, int serverid) { 
     295    const char *server_tag = GBS_ptserver_tag(serverid); 
    274296    if (start) { 
    275         TEST_ASSERT_NO_ERROR(arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag, 0)); 
     297        TEST_ASSERT_NO_ERROR(arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag)); 
    276298    } 
    277299    else { // stop 
     
    288310    // TEST_SETUP_GLOBAL_ENVIRONMENT("ptserver"); 
    289311 
     312    Error error; 
    290313    switch (mode) { 
    291314        case SETUP: { 
    292             test_ptserver_activate(false);                        // first kill pt-server (otherwise we may test an outdated pt-server) 
    293             TEST_ASSERT_NO_ERROR(GB_system("touch TEST_pt.arb")); // force rebuild 
    294             test_ptserver_activate(true); 
     315            test_ptserver_activate(false, TEST_SERVER_ID);                     // first kill pt-server (otherwise we may test an outdated pt-server) 
     316            TEST_ASSERT_NO_ERROR(GBK_system("cp TEST_pt_src.arb TEST_pt.arb")); // force rebuild 
     317            test_ptserver_activate(true, TEST_SERVER_ID); 
    295318            TEST_ASSERT_FILES_EQUAL("TEST_pt.arb.pt.expected", "TEST_pt.arb.pt"); 
    296319            TEST_ASSERT(GB_time_of_file("TEST_pt.arb.pt") >= GB_time_of_file("TEST_pt.arb")); 
     
    298321        } 
    299322        case CLEAN: { 
    300             test_ptserver_activate(false); 
     323            test_ptserver_activate(false, TEST_SERVER_ID); 
    301324            TEST_ASSERT_ZERO_OR_SHOW_ERRNO(unlink("TEST_pt.arb.pt")); 
    302325            break; 
     
    307330    } 
    308331 
    309     return NULL; 
     332    return error; 
     333} 
     334 
     335static Error ptserver_gene(Mode mode) { 
     336    // test-gene-ptserver is restarted and rebuild. 
     337    // This is done only once in the complete test suite. 
     338    //  
     339    // every unit-test using the test-gene-ptserver should simply call 
     340    // TEST_SETUP_GLOBAL_ENVIRONMENT("ptserver_gene"); 
     341 
     342// #define TEST_AUTO_UPDATE 
     343 
     344    Error error; 
     345    switch (mode) { 
     346        case SETUP: { 
     347            test_ptserver_activate(false, TEST_GENESERVER_ID);                     // first kill pt-server (otherwise we may test an outdated pt-server) 
     348            TEST_ASSERT_NO_ERROR(GBK_system("arb_gene_probe TEST_gpt_src.arb TEST_gpt.arb")); // prepare gene-ptserver-db (forcing rebuild) 
     349 
     350#if defined(TEST_AUTO_UPDATE) 
     351            TEST_COPY_FILE("TEST_gpt.arb", "TEST_gpt.arb.expected"); 
     352#else // !defined(TEST_AUTO_UPDATE) 
     353            TEST_ASSERT_FILES_EQUAL("TEST_gpt.arb.expected", "TEST_gpt.arb"); 
     354#endif 
     355 
     356            test_ptserver_activate(true, TEST_GENESERVER_ID); 
     357 
     358#if defined(TEST_AUTO_UPDATE) 
     359            TEST_COPY_FILE("TEST_gpt.arb.pt", "TEST_gpt.arb.pt.expected"); 
     360#else // !defined(TEST_AUTO_UPDATE) 
     361            TEST_ASSERT_FILES_EQUAL("TEST_gpt.arb.pt.expected", "TEST_gpt.arb.pt"); 
     362#endif 
     363 
     364            TEST_ASSERT(GB_time_of_file("TEST_gpt.arb.pt") >= GB_time_of_file("TEST_gpt.arb")); 
     365            break; 
     366        } 
     367        case CLEAN: { 
     368            test_ptserver_activate(false, TEST_GENESERVER_ID); 
     369            TEST_ASSERT_ZERO_OR_SHOW_ERRNO(unlink("TEST_gpt.arb.pt")); 
     370            break; 
     371        } 
     372        case UNKNOWN: 
     373            env_assert(0); 
     374            break; 
     375    } 
     376 
     377#undef TEST_AUTO_UPDATE 
     378     
     379    return error; 
    310380} 
    311381 
     
    314384typedef Error (*Environment_cb)(Mode mode); 
    315385 
    316 static Environment_cb  wrapped_cb    = NULL; 
    317 static Mode            wrapped_mode  = UNKNOWN; 
    318 static const char     *wrapped_error = NULL; 
     386static Environment_cb wrapped_cb   = NULL; 
     387static Mode           wrapped_mode = UNKNOWN; 
     388static SmartCharPtr   wrapped_error; 
     389 
    319390void wrapped() { wrapped_error = wrapped_cb(wrapped_mode); } 
    320  
    321 static LazyPersistantFlag any_setup(ANY_SETUP, true); 
    322391 
    323392class FunInfo { 
     
    325394    string             name; 
    326395    LazyPersistantFlag is_setup; 
     396    LazyPersistantFlag changing; // some process is currently setting up/cleaning the environment 
     397 
     398    void all_get_lazy_again() { 
     399        changing.get_lazy_again(); 
     400        is_setup.get_lazy_again(); 
     401    } 
    327402 
    328403    Error set_to(Mode mode) { 
    329404        StaticCode::printf("[%s environment '%s' START]\n", mode_command[mode], get_name()); 
    330405 
    331         any_setup = true; 
    332  
    333         wrapped_cb    = cb; 
    334         wrapped_mode  = mode; 
    335         wrapped_error = NULL; 
     406        wrapped_cb   = cb; 
     407        wrapped_mode = mode; 
     408        wrapped_error.SetNull(); 
    336409 
    337410        chdir(runDir()); 
    338411 
    339         long            duration; 
    340         UnitTestResult  guard_says = execute_guarded(wrapped, &duration, MAX_EXEC_MS_ENV, false); 
    341         const char     *error      = NULL; 
     412        long           duration; 
     413        UnitTestResult guard_says = execute_guarded(wrapped, &duration, MAX_EXEC_MS_ENV, false); 
     414        Error          error; 
    342415 
    343416        switch (guard_says) { 
    344417            case TEST_OK: 
    345                 if (wrapped_error) { 
    346                     error = GBS_global_string("returns error: %s", wrapped_error); 
     418                if (wrapped_error.isSet()) { 
     419                    error = GBS_global_string_copy("returns error: %s", &*wrapped_error); 
    347420                } 
    348421                break; 
     
    354427                    : "has been interrupted (might be a deaklock)"; 
    355428 
    356                 error = GBS_global_string("%s%s", 
    357                                           what_happened, 
    358                                           wrapped_error ? GBS_global_string(" (wrapped_error='%s')", wrapped_error) : ""); 
     429                error = GBS_global_string_copy("%s%s", 
     430                                               what_happened, 
     431                                               wrapped_error.isSet() ? GBS_global_string(" (wrapped_error='%s')", &*wrapped_error) : ""); 
    359432                break; 
    360433            } 
    361434        } 
    362         if (error) { 
    363             error = GBS_global_string("%s(%s) %s", name.c_str(), upcase(mode_command[mode]), error); 
     435        if (error.isSet()) { 
     436            error = GBS_global_string_copy("%s(%s) %s", name.c_str(), upcase(mode_command[mode]), &*error); 
    364437        } 
    365438        else { 
     439            Mutex m(FLAG_MUTEX); 
     440 
     441            env_assert(changing); 
    366442            is_setup = (mode == SETUP); 
    367443#if defined(SIMULATE_ENVSETUP_TIMEOUT) 
     
    377453            } 
    378454#endif 
     455            changing = false; 
     456            all_get_lazy_again(); 
    379457        } 
    380458 
     
    388466        : cb(cb_), 
    389467          name(name_), 
    390           is_setup(name_) 
     468          is_setup(name_), 
     469          changing(GBS_global_string("changing_%s", name_)) 
    391470    {} 
    392471 
    393     Error switch_to(Mode mode) { 
    394         Error error      = NULL; 
     472    Error switch_to(Mode mode) { // @@@ need to return allocated msg (it gets overwritten) 
     473        Error error; 
    395474        bool  want_setup = (mode == SETUP); 
    396         if (is_setup == want_setup) { 
    397             StaticCode::printf("[environment '%s' already was %s]\n", get_name(), mode_command[mode]); 
    398         } 
    399         else { 
    400             error = set_to(mode); 
    401         } 
    402  
    403         is_setup.get_lazy_again(); 
     475 
     476        bool perform_change  = false; 
     477        bool wait_for_change = false; 
     478        { 
     479            Mutex m(FLAG_MUTEX); 
     480 
     481            if (changing) { // somebody is changing the environment state 
     482                if (is_setup == want_setup) { // wanted state was reached, but somebody is altering it 
     483                    error = GBS_global_string_copy("[environment '%s' was %s, but somebody is changing it to %s]", 
     484                                                   get_name(), mode_command[mode], mode_command[other_mode[mode]]); 
     485                } 
     486                else { // the somebody is changing to my wanted state 
     487                    wait_for_change = true; 
     488                } 
     489            } 
     490            else { 
     491                if (is_setup == want_setup) { 
     492                    StaticCode::printf("[environment '%s' already was %s]\n", get_name(), mode_command[mode]); 
     493                } 
     494                else { 
     495                    changing = perform_change = true; 
     496                } 
     497            } 
     498 
     499            all_get_lazy_again(); 
     500        } 
     501 
     502        env_assert(!(perform_change && wait_for_change)); 
     503 
     504        if (perform_change) set_to(mode); 
     505 
     506        if (wait_for_change) { 
     507            bool reached = false; 
     508            while (!reached) { 
     509                StaticCode::printf("[waiting until environment '%s' reaches '%s']\n", get_name(), mode_command[mode]); 
     510                sleep(1); 
     511                { 
     512                    Mutex m(FLAG_MUTEX); 
     513                    if (!changing && is_setup == want_setup) reached = true; 
     514                    all_get_lazy_again(); 
     515                } 
     516            } 
     517            StaticCode::printf("[environment '%s' has reached '%s']\n", get_name(), mode_command[mode]); 
     518        } 
    404519 
    405520        return error; 
     
    414529static FunInfo modules[] = { 
    415530    FUNINFO(ptserver), 
     531    FUNINFO(ptserver_gene), 
    416532}; 
    417533 
     
    428544 
    429545static Error set_all_modules_to(Mode mode) { 
    430     Error error = NULL; 
    431  
    432     for (size_t e = 0; !error && e<MODULES; ++e) error = modules[e].switch_to(mode); 
    433  
    434      
    435  
     546    Error error; 
     547    for (size_t e = 0; error.isNull() && e<MODULES; ++e) { 
     548        error = modules[e].switch_to(mode); 
     549    } 
    436550    return error; 
    437551} 
     
    460574 
    461575int main(int argc, char* argv[]) { 
    462     Error error = NULL; 
    463     if (argc<2 || argc>3) error = "Wrong number of arguments"; 
     576    Error error; 
     577    bool  showUsage = true; 
     578 
     579    if (argc<2 || argc>3) error = strdup("Wrong number of arguments"); 
    464580    else { 
    465581        const char *modearg = argv[1]; 
     
    471587 
    472588        if (mode == UNKNOWN) { 
    473             error = GBS_global_string("unknown argument '%s' (known modes are: %s)", modearg, known_modes(' ')); 
     589            error = GBS_global_string_copy("unknown argument '%s' (known modes are: %s)", modearg, known_modes(' ')); 
    474590        } 
    475591        else { 
    476592            if (argc == 2) { 
    477                 Mutex m(FLAG_MUTEX); 
    478  
    479                 error                        = set_all_modules_to(mode); 
    480                 if (mode == CLEAN) any_setup = false;    // reset during final environment cleanup 
    481                 any_setup.get_lazy_again(); 
     593                error     = set_all_modules_to(mode); 
     594                showUsage = false; 
    482595            } 
    483596            else { 
     
    486599 
    487600                if (!module) { 
    488                     error = GBS_global_string("unknown argument '%s' (known modules are: %s)", modulearg, known_modules(' ')); 
     601                    error = GBS_global_string_copy("unknown argument '%s' (known modules are: %s)", modulearg, known_modules(' ')); 
    489602                } 
    490603                else { 
    491                     Mutex m(FLAG_MUTEX); 
    492                     error = module->switch_to(mode); 
    493                     any_setup.get_lazy_again(); 
    494                 } 
    495             } 
    496         } 
    497     } 
    498  
    499     if (error) { 
     604                    error     = module->switch_to(mode); 
     605                    showUsage = false; 
     606                } 
     607            } 
     608        } 
     609    } 
     610 
     611    if (error.isSet()) { 
    500612        const char *exename = argv[0]; 
    501         StaticCode::printf("%s: %s\n", exename, error); 
    502         StaticCode::printf("Usage: %s [%s] [%s]\n", exename, known_modes('|'), known_modules('|')); 
     613        StaticCode::printf("Error in %s: %s\n", exename, &*error); 
     614        if (showUsage) StaticCode::printf("Usage: %s [%s] [%s]\n", exename, known_modes('|'), known_modules('|')); 
    503615        return EXIT_FAILURE; 
    504616    } 
  • branches/dev_elmar/UNIT_TESTER/UnitTester.cxx

    r7623 r8224  
    3838 
    3939struct Globals : virtual Noncopyable { 
    40     bool   inside_test; 
    41     bool   running_on_valgrind; 
    42     char  *runDir; 
    43     pid_t  pid; 
     40    bool        inside_test; 
     41    bool        running_on_valgrind; 
     42    char       *runDir; 
     43    pid_t       pid; 
     44    const char *libname; 
    4445 
    4546    Globals() 
     
    212213} 
    213214 
    214 // set by TestEnvironment.cxx@ANY_SETUP 
    215 static const char * const any_setup_flag = "../" FLAGS_DIR "/" ANY_SETUP "." FLAGS_EXT; 
    216  
    217 static bool been_inside_environment() { 
    218     struct stat stt; 
    219     return stat(any_setup_flag, &stt) == 0 && S_ISREG(stt.st_mode); 
    220     // dups GB_is_regularfile("any_setup") 
    221 } 
    222 static void reset_been_inside_environment() { 
    223     if (been_inside_environment()) { 
    224         TEST_ASSERT_ZERO_OR_SHOW_ERRNO(unlink(any_setup_flag)); 
    225     } 
    226 } 
    227  
    228 static bool did_valgrinded_syscall() { 
    229     return utvg::flag_exists(UTVG_ANY_SYSCALL); 
    230 } 
    231 static void reset_did_valgrinded_syscall() { 
    232     if (did_valgrinded_syscall()) { 
    233         TEST_ASSERT_ZERO_OR_SHOW_ERRNO(unlink(utvg::flag_name(UTVG_ANY_SYSCALL))); 
    234     } 
    235 } 
    236  
    237 void sleepms(long ms) { 
     215class Flag { 
     216    string flagname; 
     217 
     218public: 
     219    Flag(const string& flagname_) : flagname(flagname_) {} 
     220 
     221    bool is_up() const { struct stat stt; return stat(flagname.c_str(), &stt) == 0 && S_ISREG(stt.st_mode); } 
     222    void raise() { 
     223        fprintf(stderr, "Raising flag '%s'\n", flagname.c_str()); fflush(stderr); 
     224        ut_assert(!is_up()); 
     225        FILE *fp = fopen(flagname.c_str(), "w"); 
     226        fclose(fp); 
     227    } 
     228    void lower() { 
     229        fprintf(stderr, "Lowering flag '%s'\n", flagname.c_str()); fflush(stderr); 
     230        ut_assert(is_up()); 
     231        TEST_ASSERT_ZERO_OR_SHOW_ERRNO(unlink(flagname.c_str())); 
     232    } 
     233 
     234    void lower_if_up() { if (is_up()) lower(); } 
     235}; 
     236 
     237inline Flag getLocalFlag(const char *flagname) { 
     238    string localname  = string(GLOBAL.runDir)+"/../flags/"+flagname+'.'+GLOBAL.libname; 
     239    return Flag(localname.c_str()); 
     240} 
     241 
     242static bool flag_callback(arb_test::FlagAction action, const char *name) { 
     243    using namespace arb_test; 
     244 
     245    Flag flag   = getLocalFlag(name); 
     246    bool result = true; 
     247 
     248    switch (action) { 
     249        case FLAG_RAISE: 
     250            flag.raise(); 
     251            break; 
     252        case FLAG_IS_RAISED: 
     253            result = flag.is_up(); 
     254            break; 
     255    } 
     256 
     257    return result; 
     258} 
     259 
     260inline bool been_inside_environment() { 
     261    return getLocalFlag(ANY_SETUP).is_up() || arb_test::test_data().entered_mutex_loop; 
     262} 
     263inline bool did_valgrinded_syscall() {  
     264    return seen_valgrinded_call(); 
     265} 
     266inline void reset_test_local_flags() { 
     267    getLocalFlag(ANY_SETUP).lower_if_up(); 
     268} 
     269 
     270inline void sleepms(long ms) { 
    238271    int  seconds = ms/1000; 
    239272    long rest_ms = ms - seconds*1000; 
     
    256289 
    257290    if (did_valgrinded_syscall()) { 
    258         fprintf(stderr, "[valgrinded system call detected. Added %li ms tolerance]\n", MAX_EXEC_MS_VGSYS); 
     291        const long additional    = max_allowed_duration_ms*3 + MAX_EXEC_MS_VGSYS; 
     292        fprintf(stderr, "[external calls are running valgrinded. Added %li ms tolerance]\n", additional); 
    259293        fflush(stderr); 
    260         sleepms(MAX_EXEC_MS_VGSYS); 
    261         max_allowed_duration_ms += MAX_EXEC_MS_VGSYS; 
    262     } 
    263      
     294        sleepms(additional); 
     295        max_allowed_duration_ms += additional; 
     296    } 
     297 
    264298    const long aBIT = 50*1000; // µs 
    265299 
     
    353387    UnitTest_function      fun  = test.fun; 
    354388 
    355     reset_been_inside_environment(); 
    356     reset_did_valgrinded_syscall(); 
    357  
     389    reset_test_local_flags(); 
     390     
    358391    bool           marked_as_slow   = strlen(test.name) >= 10 && memcmp(test.name, "TEST_SLOW_", 10) == 0; 
    359392    long           duration_usec; 
     
    431464 
    432465    TEST_ASSERT_ZERO_OR_SHOW_ERRNO(chdir("run")); 
    433     GLOBAL.runDir = getcwd(0, PATH_MAX); 
     466    GLOBAL.runDir  = getcwd(0, PATH_MAX); 
     467    GLOBAL.libname = libname; 
    434468 
    435469    size_t tests  = 0; 
     
    438472    { 
    439473        arb_test::GlobalTestData& global = arb_test::test_data(); 
    440      
     474 
     475        global.init(flag_callback); 
    441476        global.show_warnings = (warn_level != 0); 
    442477 
  • branches/dev_elmar/UNIT_TESTER/UnitTester.hxx

    r7945 r8224  
    4545const long MAX_EXEC_MS_SLOW   = 20 * SECONDS;       // same for slow tests 
    4646const long MAX_EXEC_MS_ENV    = 30 * SECONDS;       // same for environment setup/cleanup 
    47 const long MAX_EXEC_MS_VGSYS  = 40 * SECONDS;       // same for valgrinded system calls (especially pt_server) 
     47const long MAX_EXEC_MS_VGSYS  = 60 * SECONDS;       // same for valgrinded system calls (especially pt_server) 
    4848 
    4949const long WARN_SLOW_ABOVE_MS = 1 * SECONDS;        // when too warn about slow test 
     
    5252#define FLAGS_EXT "flag" 
    5353 
    54 #define ANY_SETUP "any_setup" 
    55  
    5654#else 
    5755#error UnitTester.hxx included twice 
  • branches/dev_elmar/UNIT_TESTER/reporter.pl

    r7945 r8224  
    9999    if (/^UnitTester:/) { 
    100100      if (/tests=([0-9]+)/)   { $tests_this += $1; $seenSummary=1; } 
    101       if (/skipped=([0-9]+)/) { $skipped_this += $1; } 
     101      if (/skipped=([0-9]+)/) { $skipped_this += $1; $dump_log = 1; } 
    102102 
    103103      if (/passed=([0-9]+)/)  { $passed += $1; } 
  • branches/dev_elmar/UNIT_TESTER/run

    • Property svn:ignore set to
      TEST_gpt.ARM
      TEST_gpt.arb
      TEST_pt.arb
      *.ARF
      TEST_pt.ARM
  • branches/dev_elmar/UNIT_TESTER/test_global.h

    r7623 r8224  
    7272    }; 
    7373 
     74    enum FlagAction { 
     75        FLAG_RAISE, 
     76        FLAG_IS_RAISED, 
     77    }; 
     78 
    7479    class GlobalTestData { 
     80        typedef bool (*FlagCallback)(FlagAction action, const char *name); 
     81 
     82        FlagCallback flag_cb; 
     83 
    7584        GlobalTestData() 
    76             : annotation(NULL), 
     85            : flag_cb(NULL), 
     86              annotation(NULL), 
    7787              show_warnings(true), 
    7888              assertion_failed(false), 
     
    8595        GlobalTestData(const GlobalTestData&); // do not synthesize 
    8696        GlobalTestData& operator=(const GlobalTestData&); // do not synthesize 
    87          
     97 
    8898        static GlobalTestData *instance(bool erase) { 
    8999            static GlobalTestData *data = 0;             // singleton 
     
    113123        bool assertion_failed; 
    114124        bool running_test; 
     125        bool entered_mutex_loop; // helper to avoid race-condition 
    115126 
    116127        // counters 
    117128        size_t warnings; 
     129 
     130        void raiseLocalFlag(const char *name) const { 
     131            if (flag_cb) { 
     132                flag_cb(FLAG_RAISE, name); 
     133            } 
     134            else { 
     135                fputs("cannot raise local flag (called from outside test-code?)\n", stderr); 
     136            } 
     137        } 
     138        void init(FlagCallback fc) { flag_cb = fc; } 
    118139 
    119140        bool not_covered_by_test() const { return !running_test; } 
  • branches/dev_elmar/UNIT_TESTER/test_unit.h

    r7945 r8224  
    1616#include <arb_assert.h> 
    1717#endif 
     18#ifndef ARBTOOLS_H 
     19#include <arbtools.h> 
     20#endif 
    1821#ifndef _GLIBCXX_CSTDARG 
    1922#include <cstdarg> 
     
    2528#include <errno.h> 
    2629#endif 
     30#ifndef DUPSTR_H 
     31#include <dupstr.h> 
     32#endif 
     33 
     34#if defined(_GLIBCXX_STRING) 
     35#define TESTS_KNOW_STRING 
     36#endif 
     37 
    2738 
    2839#define ENABLE_CRASH_TESTS // comment out this line to get rid of provoked SEGVs (e.g. while debugging test-code) 
    29 // #define TRACE_IS_EQUAL // print calls to numerical is_equal() 
    3040 
    3141/* Note: 
     
    3646 * test is known to fail, but cannot be fixed atm for some reason 
    3747 * 
     48 * Recommended test-assertion is TEST_EXPECT(that(..).xxx()) 
     49 * see examples in test-unit-tests in ../CORE/arb_string.cxx@UNIT_TESTS 
    3850 */ 
    3951 
    4052#define TEST_ASSERT(cond) test_assert(cond, false) 
    4153 
     54#define ANY_SETUP "any_env_setup" 
     55 
    4256namespace arb_test { 
    4357 
    44     class StaticCode { 
    45         static void vcompiler_msg(const char *filename, int lineno, const char *message_type, const char *format, va_list parg) __attribute__((format(__printf__, 4, 0))) { 
    46             fprintf(stderr, "%s:%i: ", filename, lineno); 
     58    // ------------- 
     59    //      str 
     60 
     61    class str { 
     62        char *s; 
     63    public: 
     64        str() : s(0) {} 
     65        str(const str& other) : s(nulldup(other.s)) {} 
     66        explicit str(char *S) : s(S) {} 
     67        str& operator = (const str& other) { 
     68            freedup(s, other.s); 
     69            return *this; 
     70        } 
     71        str& operator = (char *S) { 
     72            freeset(s, S); 
     73            return *this; 
     74        } 
     75        ~str() { free(s); } 
     76 
     77        bool exists() const { return s; } 
     78        void assign(char *S) { s = S; } 
     79        const char *value() const { return s; } 
     80    }; 
     81 
     82    // ----------------------- 
     83    //      location info 
     84 
     85#define WITHVALISTFROM(format,CODE)  do { va_list parg; va_start(parg, format); CODE; va_end(parg); } while(0) 
     86#define VPRINTFORMAT(format)         WITHVALISTFROM(format, vfprintf(stderr, format, parg)) 
     87#define VCOMPILERMSG(msgtype,format) WITHVALISTFROM(format, vcompiler_msg(msgtype, format, parg)) 
     88 
     89    class locinfo //! stores source code location 
     90    { 
     91        const char *file; 
     92        int         line; 
     93 
     94        __attribute__((format(__printf__, 2, 0))) void vcompiler_msg(const char *message_type, const char *format, va_list parg) const { 
     95            fprintf(stderr, "%s:%i: ", file, line); 
    4796            if (message_type) fprintf(stderr, "%s: ", message_type); 
    4897            vfprintf(stderr, format, parg); 
    4998        } 
    50  
    51 #define WITHVALISTFROM(format,CODE)             do { va_list parg; va_start(parg, format); CODE; va_end(parg); } while(0) 
    52 #define VPRINTFORMAT(format)                    WITHVALISTFROM(format, vfprintf(stderr, format, parg)) 
    53 #define VCOMPILERMSG(file,line,msgtype,format)  WITHVALISTFROM(format, vcompiler_msg(file, line, msgtype, format, parg)) 
    5499         
    55100    public: 
    56  
     101        locinfo() : file(0), line(0) {} 
     102        locinfo(const char *file_, int line_) : file(file_), line(line_) {} 
     103 
     104        bool exists() const { return file; } 
     105 
     106        const char *get_file() const { return file; } 
     107        int get_line() const { return line; } 
     108 
     109        __attribute__((format(printf, 2, 3))) void warningf(const char *format, ...) const { 
     110            GlobalTestData& global = test_data(); 
     111            if (global.show_warnings) { 
     112                FlushedOutput yes; 
     113                VCOMPILERMSG("Warning", format); 
     114                GlobalTestData::print_annotation(); 
     115                global.warnings++; 
     116            } 
     117        } 
     118 
     119        __attribute__((format(printf, 3, 4))) void errorf(bool fail, const char *format, ...) const { 
     120            { 
     121                FlushedOutput yes; 
     122                VCOMPILERMSG("Error", format); 
     123                GlobalTestData::print_annotation(); 
     124            } 
     125            if (fail) TRIGGER_ASSERTION(false); // fake an assertion failure 
     126        } 
     127        __attribute__((format(printf, 3, 4))) void ioerrorf(bool fail, const char *format, ...) const { 
     128            { 
     129                FlushedOutput yes; 
     130                VCOMPILERMSG("Error", format); 
     131                fprintf(stderr, " (errno=%i='%s')", errno, strerror(errno)); 
     132                GlobalTestData::print_annotation(); 
     133            } 
     134            if (fail) TRIGGER_ASSERTION(false); // fake an assertion failure 
     135        } 
     136    }; 
     137 
     138    // -------------------- 
     139    //      StaticCode 
     140 
     141    struct StaticCode { 
    57142        static void printf(const char *format, ...) __attribute__((format(printf, 1, 2))) { 
    58143            FlushedOutputNoLF yes; 
    59144            VPRINTFORMAT(format); 
    60145        } 
    61         static void warningf(const char *filename, int lineno, const char *format, ...) __attribute__((format(printf, 3, 4))) { 
    62             GlobalTestData& global = test_data(); 
    63             if (global.show_warnings) { 
    64                 FlushedOutput yes; 
    65                 VCOMPILERMSG(filename, lineno, "Warning", format); 
    66                 GlobalTestData::print_annotation(); 
    67                 global.warnings++; 
    68             } 
    69         } 
    70         static void errorf(const char *filename, int lineno, const char *format, ...) __attribute__((format(printf, 3, 4))) { 
    71             { 
    72                 FlushedOutput yes; 
    73                 VCOMPILERMSG(filename, lineno, "Error", format); 
    74                 GlobalTestData::print_annotation(); 
    75             } 
    76             TRIGGER_ASSERTION(false); // fake an assertion failure 
    77         } 
    78         static void ioerrorf(const char *filename, int lineno, const char *format, ...) __attribute__((format(printf, 3, 4))) { 
    79             { 
    80                 FlushedOutput yes; 
    81                 VCOMPILERMSG(filename, lineno, "Error", format); 
    82                 fprintf(stderr, " (errno=%i='%s')", errno, strerror(errno)); 
    83                 GlobalTestData::print_annotation(); 
    84             } 
    85             TRIGGER_ASSERTION(false); // fake an assertion failure 
    86         } 
    87146#undef VPRINTFORMAT 
    88147#undef VCOMPILERMSG 
    89148#undef WITHVALISTFROM 
    90149 
    91         static void print_readable_string(const char *s, FILE *out) { 
     150        static char *readable_string(const char *s) { 
    92151            // quote like C does! 
    93152            if (s) { 
    94                 fputc('\"', out); 
    95                 for (int i_ = 0; s[i_]; ++i_) { 
    96                     switch (s[i_]) { 
    97                         case '\n': fputs("\\n", out); break; 
    98                         case '\t': fputs("\\t", out); break; 
    99                         case '\"': fputs("\\\"", out); break; 
    100                         case '\\': fputs("\\\\", out); break; 
    101                         default: fputc(s[i_], out); break; 
     153                size_t  len    = strlen(s)*4; 
     154                char   *res = (char*)malloc(len+2+1); 
     155 
     156                int j     = 0; 
     157                res[j++] = '\"'; 
     158                for (int i = 0; s[i]; ++i) { 
     159                    unsigned char c = static_cast<unsigned char>(s[i]); 
     160                    char esc = 0; 
     161                    switch (c) { 
     162                        case '\n': esc = 'n'; break; 
     163                        case '\t': esc = 't'; break; 
     164                        case '\"': esc = '\"'; break; 
     165                        case '\\': esc = '\\'; break; 
     166                        default: if (c<10) esc = c-1+'1'; break; 
     167                    } 
     168                    if (esc) { 
     169                        res[j++] = '\\'; 
     170                        res[j++] = esc; 
     171                    } 
     172                    else { 
     173                        if (c >= 32 && c<127) { 
     174                            res[j++] = c; 
     175                        } 
     176                        else { 
     177                            j += sprintf(res+j, "\\x%02x", int(c)); 
     178                        } 
    102179                    } 
    103180                } 
    104                 fputc('\"', out); 
     181                res[j++] = '\"'; 
     182                res[j++] = 0; 
     183                return res; 
    105184            } 
    106185            else { 
    107                 fputs("(null)", out); 
    108             } 
    109         } 
    110     }; 
    111  
    112     inline void print(int i)                 { fprintf(stderr, "%i", i); } 
    113     inline void print_hex(int i)             { fprintf(stderr, "0x%x", i); } 
    114  
    115     inline void print(long L)                { fprintf(stderr, "%li", L); } 
    116     inline void print_hex(long L)            { fprintf(stderr, "0x%lx", L); } 
    117  
    118     inline void print(const char *s)         { StaticCode::print_readable_string(s, stderr); } 
    119     // no print_hex for strings 
    120  
    121     inline void print(size_t z)              { fprintf(stderr, "%zu", z); } 
    122     inline void print_hex(size_t z)          { fprintf(stderr, "0x%zx", z); } 
    123  
    124     inline void print(unsigned char c)       { fprintf(stderr, "'%c'", c); } 
    125     inline void print_hex(unsigned char c)   { print_hex(size_t(c)); } 
    126  
    127     inline void print(char c)                { print((unsigned char)c); } 
    128     inline void print_hex(char c)            { print_hex((unsigned char)c); } 
     186                return strdup("(null)"); 
     187            } 
     188        } 
     189        static void print_readable_string(const char *s, FILE *out) { 
     190            fputs(str(readable_string(s)).value(), out); 
     191        } 
     192 
     193        static char *vstrf(const char *format, va_list& parg) __attribute__((format(__printf__, 1, 0))) { 
     194            static const size_t max_vstrf_size = 10000; 
     195            static char         vstrf_buf[max_vstrf_size]; 
     196 
     197            int printed = vsnprintf(vstrf_buf, max_vstrf_size, format, parg); 
     198            arb_assert(printed >= 0 && size_t(printed)<max_vstrf_size); 
     199 
     200            char *result    = (char*)malloc(printed+1); 
     201            memcpy(result, vstrf_buf, printed); 
     202            result[printed] = 0; 
     203            return result; 
     204        } 
     205 
     206        static char *strf(const char *format, ...) __attribute__((format(__printf__, 1, 2))) { 
     207            va_list  parg; 
     208            va_start(parg, format); 
     209            char *result = vstrf(format, parg); 
     210            va_end(parg); 
     211            return result; 
     212        } 
     213 
     214    }; 
     215 
     216    inline char *val2readable(bool b) { return strdup(b ? "true" : "false"); } 
     217     
     218    inline char *val2readable(int i) { return StaticCode::strf("%i", i); } 
     219    inline char *val2hex(int i) { return StaticCode::strf("0x%x", i); } 
     220 
     221    inline char *val2readable(long L) { return StaticCode::strf("%li", L); } 
     222    inline char *val2hex(long L) { return StaticCode::strf("0x%lx", L); } 
     223 
     224    inline char *val2readable(size_t z) { return StaticCode::strf("%zu", z); } 
     225    inline char *val2hex(size_t z) { return StaticCode::strf("0x%zx", z); } 
    129226 
    130227    // dont dup size_t: 
    131228#ifdef ARB_64 
    132     inline void print(unsigned u)            { fprintf(stderr, "%u", u); } 
    133     inline void print_hex(unsigned u)        { fprintf(stderr, "0x%x", u); } 
     229    inline char *val2readable(unsigned u) { return StaticCode::strf("%u", u); } 
     230    inline char *val2hex(unsigned u) { return StaticCode::strf("0x%x", u); } 
    134231#else 
    135     inline void print(long unsigned u)       { fprintf(stderr, "%lu", u); } 
    136     inline void print_hex(long unsigned u)   { fprintf(stderr, "0x%lx", u); } 
     232    inline char *val2readable(long unsigned u) { return StaticCode::strf("%lu", u); } 
     233    inline char *val2hex(long unsigned u) { return StaticCode::strf("0x%lx", u); } 
    137234#endif 
     235 
     236    inline char *val2readable(double d) { return StaticCode::strf("%f", d); } 
     237 
     238    inline char *val2readable(unsigned char c) { arb_assert(c); return StaticCode::strf("'%c'", c); } 
     239    inline char *val2readable(const char *s) { return StaticCode::readable_string(s); } 
     240 
     241#ifdef TESTS_KNOW_STRING 
     242    inline char *val2readable(const std::string& s) { return StaticCode::readable_string(s.c_str()); } 
     243#endif 
     244 
     245    template <typename T> inline void print(const T& t) { fputs(val2readable(make_copy(t)), stderr); } 
     246    template <typename T> inline void print_hex(const T& t) { fputs(val2hex(make_copy(t)), stderr); } 
    138247 
    139248    template <typename T1, typename T2> inline void print_pair(T1 t1, T2 t2) { 
    140249        print(t1); 
    141         fputs(", ", stderr); 
     250        fputs(",", stderr); 
    142251        print(t2); 
    143252    } 
     
    148257    } 
    149258 
    150     template <typename T> inline const char *nameoftype(T unspecialized) { 
    151         return specialized_nameoftype(unspecialized);  // define instanciating type below! 
    152     } 
    153  
    154 #define NAMEOFTYPE(type) template <> inline const char * nameoftype<>(type) { return #type; } 
    155     NAMEOFTYPE(bool); 
    156     NAMEOFTYPE(char); 
    157     NAMEOFTYPE(unsigned char); 
    158     NAMEOFTYPE(const char*); 
    159     NAMEOFTYPE(int); 
    160     NAMEOFTYPE(unsigned int); 
    161     NAMEOFTYPE(long int); 
    162     NAMEOFTYPE(long unsigned int); 
    163 #undef NAMEOFTYPE 
    164  
    165  
    166  
    167 #ifdef TRACE_IS_EQUAL 
    168     template <typename T1, typename T2> inline bool bool_traced(const char *name, bool equal, T1 t1, T2 t2) { 
    169         fprintf(stderr, "%-5s = %s(%s ", (equal ? "true" : "false"), name, nameoftype(t1)); 
    170         print(t1); 
    171         fprintf(stderr, ",%s ", nameoftype(t2)); 
    172         print(t2); 
    173         fprintf(stderr, ")\n"); 
    174         return equal; 
    175     } 
    176 #else 
    177     template <typename T1, typename T2> inline bool bool_traced(const char *, bool equal, T1 , T2 ) { 
    178         return equal; 
    179     } 
     259    class epsilon_similar { 
     260        double epsilon; 
     261    public: 
     262        epsilon_similar(double epsilon_) : epsilon(epsilon_) {} 
     263        bool operator()(const double& d1, const double& d2) const { 
     264            double diff = d1-d2; 
     265            if (diff<0.0) diff = -diff; // do not use fabs() here 
     266            return diff <= epsilon; 
     267        } 
     268    }; 
     269 
     270    struct containing { 
     271        bool operator()(const char *str, const char *part) const { return strstr(str, part); } 
     272#if defined(TESTS_KNOW_STRING) 
     273        bool operator()(const std::string& str, const std::string& part) const { return strstr(str.c_str(), part.c_str()); } 
    180274#endif 
    181  
    182     template <typename T1, typename T2> inline bool is_equal(T1 t1, T2 t2) { 
    183         return bool_traced("is_equal", t1 == t2, t1, t2); 
    184     } 
    185     template<> inline bool is_equal<>(const char *s1, const char *s2) { 
    186         return bool_traced("is_equal", (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0), s1, s2); 
    187     } 
    188     template <typename T1, typename T2> inline bool is_less(T1 t1, T2 t2) { 
    189         return bool_traced("is_less", t1 < t2, t1, t2); 
    190     } 
    191  
    192  
    193     template <typename T1, typename T2> inline void print_failed_compare(T1 t1, T2 t2, const char *prefix, const char *infix, const char *suffix) { 
    194         FlushedOutput yes; 
    195         fputs(prefix, stderr); 
    196         print_pair(t1, t2); 
    197         fputs(infix, stderr); 
    198         print_hex_pair(t1, t2); 
    199         fputs(suffix, stderr); 
    200     } 
    201     template <typename T1, typename T2> inline void print_failed_equal(T1 t1, T2 t2) { 
    202         print_failed_compare(t1, t2, "test_equal(", ") (", ") returns false"); 
    203     } 
    204     template <typename T1, typename T2> inline void print_failed_less_equal(T1 t1, T2 t2) { 
    205         print_failed_compare(t1, t2, "test_less_equal(", ") (", ") returns false"); 
    206     } 
    207     template <typename T1, typename T2> inline void print_failed_different(T1 t1, T2 t2) { 
    208         print_failed_compare(t1, t2, "test_different(", ") (", ") returns false"); 
    209     } 
    210  
    211     template<> inline void print_failed_equal<>(const char *s1, const char *s2) { 
    212         FlushedOutput yes; 
    213         fputs("test_equal(", stderr); 
    214         print(s1); 
    215         fputs(",\n           ", stderr); 
    216         print(s2); 
    217         fputs(") returns false", stderr); 
    218     } 
    219     template<> inline void print_failed_different<>(const char *s1, const char *) { 
    220         FlushedOutput yes; 
    221         fputs("test_different(", stderr); 
    222         print(s1); 
    223         fputs(", <same>", stderr); 
    224         fputs(") returns false", stderr); 
    225     } 
    226  
    227     template <typename T1, typename T2> inline bool test_equal(T1 t1, T2 t2) { 
    228         bool equal = is_equal(t1, t2); 
    229         if (!equal) print_failed_equal(t1, t2); 
    230         return equal; 
    231     } 
    232     template <typename T1, typename T2> inline bool test_less_equal(T1 lower, T2 upper) { 
    233         bool less_equal = is_equal(lower, upper) || is_less(lower, upper); 
    234         if (!less_equal) print_failed_less_equal(lower, upper); 
    235         return less_equal; 
    236     } 
    237     template <typename T1, typename T2> inline bool test_different(T1 t1, T2 t2) { 
    238         bool different = !is_equal(t1, t2); 
    239         if (!different) print_failed_different(t1, t2); 
    240         return different; 
    241     } 
    242  
    243 #define ACCEPT_NON_CONST_ARGUMENTS(FUN,TYPE) \ 
    244     template<> inline bool FUN<>(TYPE p1, TYPE p2) { return FUN((const TYPE)p1, (const TYPE)p2); } \ 
    245         template<> inline bool FUN<>(TYPE p1, const TYPE p2) { return FUN((const TYPE)p1, p2); } \ 
    246         template<> inline bool FUN<>(const TYPE p1, TYPE p2) { return FUN(p1, (const TYPE)p2); } 
    247  
    248     ACCEPT_NON_CONST_ARGUMENTS(test_equal, char*); 
    249     ACCEPT_NON_CONST_ARGUMENTS(test_different, char*); 
    250  
    251 #ifdef ARB_64 
    252     typedef long int NULLPTR; 
    253 #else 
    254     typedef int      NULLPTR; 
    255 #endif 
    256      
    257 #define ACCEPT_NULLPTR_ARGUMENTS(FUN,TYPE)         \ 
    258     template<> inline bool FUN<>(TYPE p1, NULLPTR p2) { TEST_ASSERT(!p2); return FUN((const TYPE)p1, (const TYPE)p2); } \ 
    259         template<> inline bool FUN<>(const TYPE p1, NULLPTR p2) { TEST_ASSERT(!p2); return FUN((const TYPE)p1, (const TYPE)p2); } \ 
    260         template<> inline bool FUN<>(NULLPTR p1, TYPE p2) { TEST_ASSERT(!p1); return FUN((const TYPE)p1, (const TYPE)p2); } \ 
    261         template<> inline bool FUN<>(NULLPTR p1, const TYPE p2) { TEST_ASSERT(!p1); return FUN((const TYPE)p1, (const TYPE)p2); } 
    262  
    263     ACCEPT_NULLPTR_ARGUMENTS(test_equal, char*); 
    264     ACCEPT_NULLPTR_ARGUMENTS(test_different, char*); 
    265  
    266     inline bool test_similar(double d1, double d2, double epsilon) { 
    267         double diff = d1-d2; 
    268         if (diff<0.0) diff = -diff; // do not use fabs() here 
    269  
    270         bool in_epsilon_range = diff < epsilon; 
    271         if (!in_epsilon_range) { 
    272             StaticCode::printf("test_similar(%f,%f,%f) returns false\n", d1, d2, epsilon); 
    273         } 
    274         return in_epsilon_range; 
    275     } 
    276  
    277     inline bool test_equal(double d1, double d2) { return test_similar(d1, d2, 0.000001); } 
    278  
    279     inline bool test_strcontains(const char *str, const char *part)  { 
    280         const char *found = strstr(str, part); 
    281         if (!found) StaticCode::printf("string '%s'\ndoes not contain '%s'\n", str, part); 
    282         return found; 
    283     } 
    284      
    285     // inline bool is_equal(double d1, double d2) { 
    286         // return is_similar(d1, d2, 0.000001); 
    287     // } 
     275    }; 
    288276 
    289277    inline bool files_are_equal(const char *file1, const char *file2) { 
     
    362350        return !error; 
    363351    } 
     352 
     353 
     354    // ------------------ 
     355    //      copy 
     356 
     357 
     358    template <typename T> 
     359    class copy //! makes char* copyable, so it can be handled like most other types 
     360    { 
     361        T t; 
     362    public: 
     363        copy(const T& t_) : t(t_) {} 
     364        operator const T&() const { return t; } 
     365    }; 
     366 
     367    template <> 
     368    class copy<const char *> { 
     369        str t; 
     370    public: 
     371        copy(const char *t_) : t(str(t_ ? strdup(t_) : NULL)) {} 
     372        operator const char *() const { return t.value(); } 
     373    }; 
     374 
     375    template <typename T> class copy< copy<T> > { copy(const copy<T>& t_); }; // avoid copies of copies 
     376 
     377    template <typename T> inline copy<T> make_copy(const T& t) { return copy<T>(t); } 
     378 
     379    inline copy<const char *> make_copy(const char *p) { return copy<const char *>(p); } 
     380    inline copy<const char *> make_copy(char *p) { return copy<const char *>(p); } 
     381    inline copy<const char *> make_copy(const unsigned char *p) { return copy<const char *>(reinterpret_cast<const char *>(p)); } 
     382    inline copy<const char *> make_copy(unsigned char *p) { return copy<const char *>(reinterpret_cast<const char *>(p)); } 
     383    inline copy<const char *> make_copy(const signed char *p) { return copy<const char *>(reinterpret_cast<const char *>(p)); } 
     384    inline copy<const char *> make_copy(signed char *p) { return copy<const char *>(reinterpret_cast<const char *>(p)); } 
     385 
     386    inline copy<unsigned char> make_copy(char p) { return copy<unsigned char>(p); } 
     387    inline copy<unsigned char> make_copy(unsigned char p) { return copy<unsigned char>(p); } 
     388    inline copy<unsigned char> make_copy(signed char p) { return copy<unsigned char>(p); } 
     389 
     390    template <typename T> str readable(const copy<T>& v) { return str(val2readable(v)); } 
     391    template <typename T> str readableHex(const copy<T>& v) { return str(val2readableHex(v)); } 
     392 
     393    template <typename T> bool operator == (const copy<T>& v1, const copy<T>& v2) { return static_cast<const T&>(v1) == static_cast<const T&>(v2); } 
     394    template <typename T> bool operator != (const copy<T>& v1, const copy<T>& v2) { return !(v1 == v2); } 
     395 
     396    template <> inline bool operator == <const char *>(const copy<const char *>& v1, const copy<const char *>& v2) { 
     397        const char *val1 = v1; 
     398        const char *val2 = v2; 
     399 
     400        return (val1 == val2) || (val1 && val2 && (strcmp(val1, val2) == 0)); 
     401    } 
     402 
     403 
     404 
     405    // ------------------------------- 
     406    //      some output functions 
     407 
     408    inline void print(const char *s) { fputs(s, stderr); } 
     409    inline void print(char c) { fputc(c, stderr); } 
     410    inline void print(int i) { fprintf(stderr, "%i", i); } 
     411 
     412    inline void space() { print(' '); } 
     413    inline void nl() { print('\n'); } 
     414     
     415    inline void print_indent(int indent) { while (indent--) space(); } 
     416 
     417    inline void spaced(const char *word) { space(); print(word); space(); } 
     418    inline void select_spaced(bool first, const char *singular, const char *plural) { spaced(first ? singular : plural); } 
     419     
     420 
     421#define HASTOBE_CLONABLE(type) virtual type *clone() const = 0 
     422#define MAKE_CLONABLE(type)    type *clone() const { return new type(*this); } 
     423 
     424    // ------------------------------ 
     425    //      abstract expectation 
     426 
     427    struct expectation //! something expected. can be fulfilled or not (and can explain why/not) 
     428    { 
     429        virtual ~expectation() {} 
     430        HASTOBE_CLONABLE(expectation); 
     431 
     432        virtual bool fulfilled() const              = 0; 
     433        virtual void explain(int indent) const      = 0; 
     434        virtual void dump_brief_description() const = 0; 
     435    }; 
     436 
     437    // ------------------- 
     438    //      asserters 
     439 
     440    class asserter : virtual Noncopyable { 
     441        expectation *expected; 
     442        locinfo      loc; 
     443        const char  *code; 
     444 
     445        virtual void announce_failure() const { TRIGGER_ASSERTION(false); } 
     446 
     447        void err(const char *format) const { loc.errorf(false, format, code); } 
     448        void warn(const char *format) const { loc.warningf(format, code); } 
     449         
     450    public: 
     451        asserter(const expectation& e, const char *nontmp_code, const char *file, int line) 
     452            : expected(e.clone()), 
     453              loc(file, line), 
     454              code(nontmp_code) 
     455        {} 
     456        virtual ~asserter() { delete expected; } 
     457 
     458        const char *get_code() const { return code; } 
     459 
     460        void expect_that() const { 
     461            if (!expected->fulfilled()) { 
     462                err("Failed expectation '%s'"); 
     463                print("expectation fails because\n"); 
     464                expected->explain(2); print('\n'); 
     465                announce_failure(); 
     466            } 
     467        } 
     468        void expect_broken() const { 
     469            if (expected->fulfilled()) { 
     470                err("Previously broken expectation '%s' succeeds"); 
     471                announce_failure(); 
     472            } 
     473            else { 
     474                warn("Expectation '%s' known as broken (accepted until fixed)"); 
     475                print("Broken because\n"); 
     476                expected->explain(2); print('\n'); 
     477            } 
     478        } 
     479        void expect_wanted_behavior() const { 
     480            if (expected->fulfilled()) { 
     481                err("Wanted behavior '%s' reached"); 
     482                announce_failure(); 
     483            } 
     484            else { 
     485                warn("Wanted behavior: '%s'"); 
     486                print("Unsatisfied because\n"); 
     487                expected->explain(2); print('\n'); 
     488            } 
     489        } 
     490 
     491    }; 
     492 
     493    class debug_asserter : public asserter { 
     494        virtual void announce_failure() const { 
     495            print("<<< would trigger assertion now! >>>\n"); 
     496        } 
     497    public: 
     498        debug_asserter(const expectation& e, const char *code_, const char *file, int line) 
     499            : asserter(e, code_, file, line) 
     500        {} 
     501 
     502        void debug_expectations() { 
     503            fprintf(stderr, "-------------------- [Debugging expectations for '%s']\n", get_code()); 
     504            expect_that(); 
     505            expect_broken(); 
     506            expect_wanted_behavior(); 
     507        } 
     508    }; 
     509 
     510    // ---------------------------------------- 
     511    //      matchable + matcher (abstract) 
     512 
     513    struct matchable //! can be matched with corresponding matcher. 
     514    { 
     515        virtual ~matchable() {} 
     516        HASTOBE_CLONABLE(matchable); 
     517 
     518        virtual const char *name() const           = 0; 
     519        virtual const char *readable_value() const = 0; 
     520    }; 
     521 
     522    struct matcher //! can match things. 
     523    { 
     524        virtual ~matcher() {} 
     525        HASTOBE_CLONABLE(matcher); 
     526 
     527        virtual bool matches(const matchable& thing) const                      = 0; 
     528        virtual void dump_expectation(const matchable& thing, int indent) const = 0; 
     529        virtual void dump_brief_description(const matchable& thing) const       = 0; 
     530    }; 
     531 
     532    // ---------------------------------------------- 
     533    //      expectation from matchable + matcher 
     534 
     535 
     536    class match_expectation : public expectation //! expectation composed from matcher and corresponding matchable. 
     537    { 
     538        matchable *thing; 
     539        matcher   *condition; 
     540    public: 
     541        match_expectation(const matchable& thing_, const matcher& condition_) 
     542            : thing(thing_.clone()), 
     543              condition(condition_.clone()) 
     544        {} 
     545        match_expectation(const match_expectation& other) 
     546            : thing(other.thing->clone()), 
     547              condition(other.condition->clone()) 
     548        {} 
     549        DECLARE_ASSIGNMENT_OPERATOR(match_expectation); 
     550        MAKE_CLONABLE(match_expectation); 
     551        ~match_expectation() { 
     552            delete thing; 
     553            delete condition; 
     554        } 
     555 
     556        bool fulfilled() const { return condition->matches(*thing); } 
     557        void explain(int indent) const { condition->dump_expectation(*thing, indent); } 
     558        void dump_brief_description() const { condition->dump_brief_description(*thing); } 
     559    }; 
     560 
     561    // ------------------- 
     562    //      predicate 
     563 
     564 
     565    class predicate_description { 
     566        const char  *primary; 
     567        const char  *inverse; 
     568        mutable str  tmp; 
     569 
     570        void erase_last_from_tmp() const { 
     571            char *t   = const_cast<char*>(tmp.value()); 
     572            int   len = strlen(t); 
     573            t[len-1]  = 0; 
     574        } 
     575 
     576        static bool ends_with_s(const char *s) { 
     577            int len          = strlen(s); 
     578            return s[len-1] == 's'; 
     579        } 
     580 
     581        const char *make(const char *desc, bool got) const { 
     582            if (ends_with_s(desc)) { 
     583                if (got) return desc; 
     584                tmp = StaticCode::strf("doesnt %s", desc); 
     585                erase_last_from_tmp(); 
     586            } 
     587            else { 
     588                tmp = StaticCode::strf("%s %s", got ? "is" : "isnt", desc); 
     589            } 
     590            return tmp.value(); 
     591        } 
     592 
     593    public: 
     594        predicate_description(const char *primary_) : primary(primary_), inverse(NULL) {} 
     595        predicate_description(const char *primary_, const char *inverse_) : primary(primary_), inverse(inverse_) {} 
     596        predicate_description(const predicate_description& other) : primary(other.primary), inverse(other.inverse) {} 
     597        DECLARE_ASSIGNMENT_OPERATOR(predicate_description); 
     598 
     599        const char *make(bool expected, bool got) const { 
     600            if (expected) return make(primary, got); 
     601            if (inverse) return make(inverse, !got); 
     602            return make(primary, !got); 
     603        } 
     604    }; 
     605 
     606    template <typename FUNC> 
     607    class predicate { 
     608        FUNC                  pred; 
     609        predicate_description description; 
     610    public: 
     611        predicate(FUNC pred_, const char *name) : pred(pred_), description(name) {} 
     612        predicate(FUNC pred_, const char *name, const char *inverse) : pred(pred_), description(name, inverse) {} 
     613 
     614        template <typename T> bool matches(const copy<T>& v1, const copy<T>& v2) const { return pred(v1, v2); } 
     615        const char *describe(bool expected, bool got) const { return description.make(expected, got); } 
     616    }; 
     617 
     618    template <typename FUNC> predicate<FUNC> make_predicate(FUNC func, const char *primary, const char *inverse) { 
     619        return predicate<FUNC>(func, primary, inverse); 
     620    } 
     621 
     622    // ------------------------------------------ 
     623    //      matchable + matcher (for values) 
     624 
     625    template <typename T> inline bool equals(const copy<T>& t1, const copy<T>& t2) { return t1 == t2; } 
     626    template <typename T> inline bool less(const copy<T>& t1, const copy<T>& t2) { return t1 < t2; } 
     627    template <typename T> inline bool more(const copy<T>& t1, const copy<T>& t2) { return t1 > t2; } 
     628 
     629    template <typename T> 
     630    class matchable_value : public matchable //! matchable for values 
     631    { 
     632        copy<T>      val; 
     633        mutable str  readable; 
     634        const char * code; 
     635    public: 
     636        matchable_value(copy<T> val_, const char *nontemp_code) : val(val_), code(nontemp_code) {} 
     637        matchable_value(const matchable_value<T>& other) : val(other.val), readable(other.readable), code(other.code) {} 
     638        DECLARE_ASSIGNMENT_OPERATOR(matchable_value); 
     639        MAKE_CLONABLE(matchable_value<T>); 
     640 
     641        const copy<T>& value() const { return val; } 
     642        char *gen_description() const { return StaticCode::strf("%s (=%s)", code, val.readable()); } 
     643 
     644        const char *name() const { return code; } 
     645        const char *readable_value() const { 
     646            if (!readable.exists()) readable = arb_test::readable(val); 
     647            return readable.value(); 
     648        } 
     649 
     650        template <typename U> inline match_expectation equals_expectation(bool invert, const U& other, const char *code) const; 
     651        template <typename U> inline match_expectation lessThan_expectation(bool invert, const U& other, const char *code) const; 
     652        template <typename U> inline match_expectation moreThan_expectation(bool invert, const U& other, const char *code) const; 
     653         
     654        template <typename FUNC> inline match_expectation predicate_expectation(bool wanted, predicate<FUNC> pred, matchable_value<T> arg) const; 
     655        template <typename U, typename FUNC> inline match_expectation predicate_expectation(bool wanted, FUNC pred, const char *pred_code, const U& arg, const char *arg_code) const; 
     656    }; 
     657 
     658    template <typename T, typename U> 
     659    inline const matchable_value<T> make_matchable_value(const U& other, const char *code_) { 
     660        return matchable_value<T>(T(other), code_); 
     661    } 
     662#if defined(TESTS_KNOW_STRING) 
     663    template<> 
     664    inline const matchable_value<const char*> make_matchable_value<const char *, std::string>(const std::string& other, const char *code_) { 
     665        return matchable_value<const char *>(other.c_str(), code_); 
     666    } 
     667#endif 
     668     
     669    template <typename T> template <typename U> 
     670    inline match_expectation matchable_value<T>::equals_expectation(bool wanted, const U& other, const char *code_) const { 
     671        return predicate_expectation(wanted, make_predicate(equals<T>, "equals", "differs"), make_matchable_value<T,U>(other, code_)); 
     672    } 
     673    template <typename T> template <typename U> 
     674    inline match_expectation matchable_value<T>::lessThan_expectation(bool wanted, const U& other, const char *code_) const { 
     675        return predicate_expectation(wanted, make_predicate(less<T>, "less than", "more or equal"), make_matchable_value<T,U>(other, code_)); 
     676    } 
     677    template <typename T> template <typename U> 
     678    inline match_expectation matchable_value<T>::moreThan_expectation(bool wanted, const U& other, const char *code_) const { 
     679        return predicate_expectation(wanted, make_predicate(more<T>, "more than", "less or equal"), make_matchable_value<T,U>(other, code_)); 
     680    } 
     681     
     682    template <typename T> 
     683    class value_matcher : public matcher //! matcher for values 
     684    { 
     685        matchable_value<T> expected; 
     686    public: 
     687        value_matcher(const matchable_value<T>& expected_) : expected(expected_) {} 
     688        virtual ~value_matcher() {} 
     689 
     690        virtual bool matches(const copy<T>& v1, const copy<T>& v2) const       = 0; 
     691        virtual const char *relation(bool isMatch) const                       = 0; 
     692 
     693        const matchable_value<T>& get_expected() const { return expected; } 
     694 
     695        bool matches(const matchable& thing) const { 
     696            const matchable_value<T>& value_thing = dynamic_cast<const matchable_value<T>&>(thing); 
     697            return matches(value_thing.value(), expected.value()); 
     698        } 
     699 
     700        void dump_expectation(const matchable& thing, int indent) const { 
     701            bool isMatch = matches(thing); 
     702            print_indent(indent); 
     703            fprintf(stderr, "'%s' %s '%s'", thing.name(), relation(isMatch), expected.name()); 
     704 
     705            const matchable_value<T>& value_thing = dynamic_cast<const matchable_value<T>&>(thing); 
     706            if (equals<T>(value_thing.value(), expected.value())) { 
     707                fprintf(stderr, " (both are %s)", value_thing.readable_value()); 
     708            } 
     709            else { 
     710                int diff = strlen(thing.name())-strlen(expected.name()); 
     711 
     712                print(", where\n"); 
     713                indent += 2;; 
     714                print_indent(indent); fprintf(stderr, "'%s'%*s is %s, and\n", thing.name(),    (diff>0 ? 0 : -diff), "", thing.readable_value()); 
     715                print_indent(indent); fprintf(stderr, "'%s'%*s is %s",        expected.name(), (diff<0 ? 0 : diff),  "", expected.readable_value()); 
     716            } 
     717        } 
     718        void dump_brief_description(const matchable& thing) const { 
     719            print(thing.name()); 
     720            print('.'); 
     721            print(relation(true)); 
     722            print('('); print(expected.name()); print(')'); 
     723        } 
     724 
     725    }; 
     726 
     727    // --------------------------- 
     728    //      predicate_matcher 
     729 
     730 
     731    template <typename T, typename FUNC> 
     732    class predicate_matcher : public value_matcher<T> { 
     733        predicate<FUNC> pred; 
     734        bool            expected_result; 
     735 
     736    public: 
     737        predicate_matcher(bool wanted, predicate<FUNC> pred_, const matchable_value<T>& arg) 
     738            : value_matcher<T>(arg), 
     739              pred(pred_), 
     740              expected_result(wanted) 
     741        {} 
     742        MAKE_CLONABLE(predicate_matcher); 
     743 
     744        bool matches(const copy<T>& v1, const copy<T>& v2) const { return correlated(pred.matches(v1, v2), expected_result); } 
     745        const char *relation(bool isMatch) const { return pred.describe(expected_result, correlated(isMatch, expected_result)); } 
     746    }; 
     747 
     748    template <typename T> template <typename FUNC> 
     749    inline match_expectation matchable_value<T>::predicate_expectation(bool wanted, predicate<FUNC> pred, matchable_value<T> arg) const { 
     750        return match_expectation(*this, predicate_matcher<T,FUNC>(wanted, pred, arg)); 
     751    } 
     752    template <typename T> template <typename U, typename FUNC> 
     753    inline match_expectation matchable_value<T>::predicate_expectation(bool wanted, FUNC pred, const char *pred_code, const U& arg, const char *arg_code) const { 
     754        return match_expectation(*this, predicate_matcher<T,FUNC>(wanted, predicate<FUNC>(pred, pred_code), make_matchable_value<T,U>(arg, arg_code))); 
     755    } 
     756 
     757    // ------------------------------------------------ 
     758    //      matchable + matcher (for expectations) 
     759 
     760    const int MAX_GROUP_SIZE = 3; 
     761    class expectation_group : public matchable //! group of expectation. matchable with group_matcher 
     762    { 
     763        int          count; 
     764        expectation *depend_on[MAX_GROUP_SIZE]; 
     765 
     766        expectation_group& operator = (const expectation_group&); // forbidden 
     767    protected: 
     768 
     769    public: 
     770        expectation_group(const expectation& e) : count(1) { 
     771            depend_on[0] = e.clone(); 
     772        } 
     773        expectation_group(const expectation& e1, const expectation& e2) : count(2) { 
     774            depend_on[0] = e1.clone(); 
     775            depend_on[1] = e2.clone(); 
     776        } 
     777        expectation_group(const expectation_group& other) : count(other.count) { 
     778            for (int i = 0; i<count; ++i) { 
     779                depend_on[i] = other.depend_on[i]->clone(); 
     780            } 
     781        } 
     782        virtual ~expectation_group() { 
     783            for (int i = 0; i<count; ++i) { 
     784                delete depend_on[i]; 
     785            } 
     786        } 
     787        MAKE_CLONABLE(expectation_group); 
     788 
     789        expectation_group& add(const expectation& e) { depend_on[count++] = e.clone(); return *this; } 
     790 
     791        const char *name() const { 
     792            return "<expectation_group>"; 
     793        } 
     794        const char *readable_value() const { 
     795            return "<value of expectation_group>"; 
     796        } 
     797 
     798        const expectation& dependent(int i) const { arb_assert(i<count); return *depend_on[i]; } 
     799        int size() const { return count; } 
     800        int count_fulfilled() const { 
     801            int ff = 0; 
     802            for (int i = 0; i<count; ++i) { 
     803                ff += dependent(i).fulfilled(); 
     804            } 
     805            return ff; 
     806        } 
     807        void dump_some_expectations(int indent, bool fulfilled, bool unfulfilled) const { 
     808            if (fulfilled||unfulfilled) { 
     809                bool all    = fulfilled && unfulfilled; 
     810                bool wanted = fulfilled; 
     811 
     812                bool printed = false; 
     813                for (int i = 0; i<size(); ++i) { 
     814                    const expectation& e = dependent(i); 
     815 
     816                    bool is_fulfilled = e.fulfilled(); 
     817                    if (all || is_fulfilled == wanted) { 
     818                        if (printed) print('\n'); 
     819                        e.explain(indent); 
     820                        printed = true; 
     821                    } 
     822                } 
     823            } 
     824        } 
     825        void dump_brief_description() const { 
     826            print("of("); 
     827            bool printed = false; 
     828            for (int i = 0; i<size(); ++i) { 
     829                if (printed) print(", "); 
     830                const expectation& e = dependent(i); 
     831                e.dump_brief_description(); 
     832                printed = true; 
     833            } 
     834            print(')'); 
     835        } 
     836    }; 
     837 
     838    struct group_match //! result of matching an expectation_group with a group_matcher 
     839    { 
     840        const int count; 
     841        const int fulfilled; 
     842        const int min_req; 
     843        const int max_req; 
     844        const int diff; 
     845 
     846        int required(int what) const { return what == -1 ? count : what; } 
     847        group_match(const expectation_group& group, int min, int max) 
     848            : count(group.size()), 
     849              fulfilled(group.count_fulfilled()), 
     850              min_req(required(min)), 
     851              max_req(required(max)), 
     852              diff(fulfilled<min_req 
     853                   ? fulfilled-min_req 
     854                   : (fulfilled>max_req ? fulfilled-max_req : 0)) 
     855        {} 
     856 
     857 
     858        inline static void is(int a) { select_spaced(a == 1, "is", "are"); } 
     859        inline static void was(int a) { select_spaced(a < 2, "was", "were"); } 
     860        inline static void amountzero(int a, const char *zero) { a ? print(a) : print(zero); } 
     861 
     862        void dump_num_of(int amount, const char *thing) const { 
     863            amountzero(amount, "no"); 
     864            space(); 
     865            print(thing); 
     866            if (amount != 1) print('s'); 
     867        } 
     868 
     869        void dump(const expectation_group& group, int indent) const { 
     870            print_indent(indent); 
     871            if (count == 1) { 
     872                print("expectation "); 
     873                print("'"); 
     874                group.dependent(0).dump_brief_description(); 
     875                print("' "); 
     876                print(fulfilled ? "fulfilled" : "fails"); 
     877                print(diff ? " unexpectedly" : " as expected"); 
     878            } 
     879            else { 
     880                print("expected "); 
     881                int that_many; 
     882                if (min_req == max_req) { 
     883                    if (diff>0 && min_req>0) print("only "); 
     884                    that_many = min_req; 
     885                } 
     886                else { 
     887                    if (diff) { 
     888                        print("at"); select_spaced(diff<0, "least", "most"); 
     889                        that_many = diff<0 ? min_req : max_req; 
     890                    } 
     891                    else { 
     892                        fprintf(stderr, "%i-", min_req); 
     893                        that_many = max_req; 
     894                    } 
     895                } 
     896                dump_num_of(that_many, "fulfilled expectation"); 
     897                space(); 
     898                group.dump_brief_description(); 
     899                nl(); 
     900 
     901                indent += 2; 
     902                print_indent(indent); 
     903                if (diff == 0) print("and "); else print("but "); 
     904 
     905                if (diff<0 && fulfilled>0) print("only "); 
     906                amountzero(fulfilled, "none"); is(fulfilled); print("fulfilled"); 
     907            } 
     908 
     909            print(", because\n"); 
     910            bool show_fulfilled   = diff >= 0; 
     911            bool show_unfulfilled = diff <= 0; 
     912            group.dump_some_expectations(indent+2, show_fulfilled, show_unfulfilled); 
     913        } 
     914    }; 
     915 
     916    class group_matcher : public matcher //! matches expectation_group for degree of fulfilledness 
     917    { 
     918        int min, max; 
     919        group_matcher(int min_, int max_) : min(min_), max(max_) {} 
     920    public: 
     921        MAKE_CLONABLE(group_matcher); 
     922 
     923        bool matches(const matchable& thing) const { 
     924            return group_match(dynamic_cast<const expectation_group&>(thing), min, max).diff == 0; 
     925        } 
     926 
     927        void dump_expectation(const matchable& thing, int indent) const { 
     928            const expectation_group& group = dynamic_cast<const expectation_group&>(thing); 
     929            group_match matching(group, min, max); 
     930            matching.dump(group, indent); 
     931        } 
     932 
     933        // factories 
     934        static group_matcher all() { return group_matcher(-1, -1); } 
     935        static group_matcher none() { return group_matcher(0, 0); } 
     936        static group_matcher atleast(int min_) { return group_matcher(min_, -1); } 
     937        static group_matcher atmost(int max_) { return group_matcher(0, max_); } 
     938        static group_matcher exacly(int amount) { return group_matcher(amount, amount); } 
     939 
     940        // match_expectation factories 
     941        match_expectation of(const expectation& e) const { 
     942            return match_expectation(expectation_group(e), *this); 
     943        } 
     944        match_expectation of(const expectation& e1, const expectation& e2) const { 
     945            return match_expectation(expectation_group(e1, e2), *this); 
     946        } 
     947        match_expectation of(const expectation& e1, const expectation& e2, const expectation& e3) const { 
     948            return match_expectation(expectation_group(e1, e2).add(e3), *this); 
     949        } 
     950 
     951        void dump_brief_description(const matchable& thing) const { 
     952            if (max == -1) { 
     953                if (min == -1) { 
     954                    print("all"); 
     955                } 
     956                else { 
     957                    fprintf(stderr, "atleast(%i)", min); 
     958                } 
     959            } 
     960            else if (max == 0) { 
     961                print("none"); 
     962            } 
     963            else if (min == max) { 
     964                fprintf(stderr, "exactly(%i)", min); 
     965            } 
     966            else { 
     967                fprintf(stderr, "[%i-%i]", min, max); 
     968            } 
     969 
     970            print('.'); 
     971 
     972            const expectation_group& group = dynamic_cast<const expectation_group&>(thing); 
     973            group.dump_brief_description(); 
     974        } 
     975    }; 
     976 
     977    // -------------------------- 
     978    //      helper functions 
     979 
     980     
     981    template <typename T> const matchable_value<T> CREATE_matchable(const copy<T>& val, const char *code) { return matchable_value<T>(val, code); } 
     982 
     983    inline group_matcher all() { return group_matcher::all(); } 
     984    inline group_matcher none() { return group_matcher::none(); } 
     985    inline group_matcher atleast(int min) { return group_matcher::atleast(min); } 
     986    inline group_matcher atmost(int max) { return group_matcher::atmost(max); } 
     987    inline group_matcher exacly(int amount) { return group_matcher::exacly(amount); } 
     988 
     989    inline match_expectation wrong(const expectation& e) { return none().of(e); } 
    364990}; 
    365991 
    366992// -------------------------------------------------------------------------------- 
    367993 
    368 #define TEST_WARNING(format,strarg)           arb_test::StaticCode::warningf(__FILE__, __LINE__, format, (strarg)) 
    369 #define TEST_WARNING2(format,strarg1,strarg2) arb_test::StaticCode::warningf(__FILE__, __LINE__, format, (strarg1), (strarg2)) 
    370  
    371 #define TEST_ERROR(format,strarg)           arb_test::StaticCode::errorf(__FILE__, __LINE__, format, (strarg)) 
    372 #define TEST_ERROR2(format,strarg1,strarg2) arb_test::StaticCode::errorf(__FILE__, __LINE__, format, (strarg1), (strarg2)) 
    373 #define TEST_IOERROR(format,strarg)         arb_test::StaticCode::ioerrorf(__FILE__, __LINE__, format, (strarg)) 
     994#define MATCHABLE_ARGS_UNTYPED(val) val, #val 
     995#define MATCHABLE_ARGS_TYPED(val)   make_copy(val), #val 
     996 
     997#define equals(val)  equals_expectation(true, MATCHABLE_ARGS_UNTYPED(val)) 
     998#define differs(val) equals_expectation(false, MATCHABLE_ARGS_UNTYPED(val)) 
     999 
     1000#define less_than(val) lessThan_expectation(true, MATCHABLE_ARGS_UNTYPED(val)) 
     1001#define more_than(val) moreThan_expectation(true, MATCHABLE_ARGS_UNTYPED(val)) 
     1002 
     1003#define less_or_equal(val) moreThan_expectation(false, MATCHABLE_ARGS_UNTYPED(val)) 
     1004#define more_or_equal(val) lessThan_expectation(false, MATCHABLE_ARGS_UNTYPED(val)) 
     1005 
     1006#define is(pred,arg)     predicate_expectation(true, MATCHABLE_ARGS_UNTYPED(pred), MATCHABLE_ARGS_UNTYPED(arg)) 
     1007#define is_not(pred,arg) predicate_expectation(false, MATCHABLE_ARGS_UNTYPED(pred), MATCHABLE_ARGS_UNTYPED(arg)) 
     1008 
     1009#define that(thing) CREATE_matchable(MATCHABLE_ARGS_TYPED(thing)) 
     1010 
     1011#define TEST_EXPECT(EXPCTN) do { using namespace arb_test; asserter(EXPCTN, #EXPCTN, __FILE__, __LINE__).expect_that(); } while(0) 
     1012#define TEST_EXPECT__BROKEN(EXPCTN) do { using namespace arb_test; asserter(EXPCTN, #EXPCTN, __FILE__, __LINE__).expect_broken(); } while(0) 
     1013#define TEST_EXPECT__WANTED(EXPCTN) do { using namespace arb_test; asserter(EXPCTN, #EXPCTN, __FILE__, __LINE__).expect_wanted_behavior(); } while(0) 
     1014 
     1015#define DEBUG_TEST_EXPECT(EXPCTN) do {                                                  \ 
     1016        using namespace arb_test;                                                       \ 
     1017        debug_asserter(EXPCTN, #EXPCTN, __FILE__, __LINE__).                            \ 
     1018            debug_expectations();                                                       \ 
     1019        debug_asserter(wrong(EXPCTN), "wrong(" #EXPCTN ")", __FILE__, __LINE__).        \ 
     1020            debug_expectations();                                                       \ 
     1021    } while(0) 
     1022 
     1023// -------------------------------------------------------------------------------- 
     1024 
     1025#define HERE arb_test::locinfo(__FILE__, __LINE__) 
     1026 
     1027#define TEST_WARNING(format,strarg)           HERE.warningf(format, (strarg)) 
     1028#define TEST_WARNING2(format,strarg1,strarg2) HERE.warningf(format, (strarg1), (strarg2)) 
     1029#define TEST_ERROR(format,strarg)             HERE.errorf(true, format, (strarg)) 
     1030#define TEST_ERROR2(format,strarg1,strarg2)   HERE.errorf(true, format, (strarg1), (strarg2)) 
     1031#define TEST_IOERROR(format,strarg)           HERE.ioerrorf(true, format, (strarg)) 
    3741032 
    3751033// -------------------------------------------------------------------------------- 
     
    3921050    } while (0) 
    3931051 
    394  
    395 #define TEST_ASSERT_ZERO(cond)         TEST_ASSERT((cond)         == 0) 
    396 #define TEST_ASSERT_ZERO__BROKEN(cond) TEST_ASSERT__BROKEN((cond) == 0) 
     1052#define TEST_ASSERT_ZERO(cond)         TEST_EXPECT(that(cond).equals(0)) 
     1053#define TEST_ASSERT_ZERO__BROKEN(cond) TEST_EXPECT__BROKEN(that(cond).equals(0)) 
    3971054 
    3981055#define TEST_ASSERT_ZERO_OR_SHOW_ERRNO(iocond)                  \ 
     
    4261083 
    4271084 
    428 #define TEST_ASSERT_NO_ERROR__BROKEN(error_cond)                        \ 
     1085#define TEST_ASSERT_NO_ERROR__BROKEN(error_cond)                                \ 
     1086    do {                                                                        \ 
     1087        const char *error_ = (error_cond);                                      \ 
     1088        if (error_) {                                                           \ 
     1089            TEST_WARNING2("Known broken behavior ('%s' reports error '%s')",    \ 
     1090                          #error_cond, error_);                                 \ 
     1091        }                                                                       \ 
     1092        else {                                                                  \ 
     1093            TEST_ERROR("Formerly broken test '%s' succeeds (reports no error)", \ 
     1094                       #error_cond);                                            \ 
     1095        }                                                                       \ 
     1096    } while (0) 
     1097 
     1098#define TEST_ASSERT_ERROR__BROKEN(error_cond)                                           \ 
     1099    do {                                                                                \ 
     1100        const char *error_ = (error_cond);                                              \ 
     1101        if (!error_) {                                                                  \ 
     1102            TEST_WARNING("Known broken behavior ('%s' fails to report error)",          \ 
     1103                         #error_cond);                                                  \ 
     1104        }                                                                               \ 
     1105        else {                                                                          \ 
     1106            TEST_ERROR2("Former broken test '%s' succeeds (reports error '%s')",        \ 
     1107                        #error_cond, error_);                                           \ 
     1108        }                                                                               \ 
     1109    } while (0) 
     1110 
     1111 
     1112// -------------------------------------------------------------------------------- 
     1113 
     1114#define TEST_EXPORTED_ERROR() (GB_have_error() ? GB_await_error() : NULL) 
     1115 
     1116#define TEST_CLEAR_EXPORTED_ERROR()                                     \ 
    4291117    do {                                                                \ 
    430         const char *error = (error_cond);                               \ 
    431         if (error) {                                                    \ 
    432             TEST_WARNING2("Known broken behavior ('%s' reports error '%s')", \ 
    433                          #error_cond, error);                           \ 
    434         }                                                               \ 
    435         else {                                                          \ 
    436             TEST_ERROR("Formerly broken test '%s' succeeds (reports no error)", \ 
    437                        #error_cond);                                    \ 
     1118        const char *error_ = TEST_EXPORTED_ERROR();                     \ 
     1119        if (error_) {                                                   \ 
     1120            TEST_WARNING("detected and cleared exported error '%s'",    \ 
     1121                         error_);                                       \ 
    4381122        }                                                               \ 
    4391123    } while (0) 
    4401124 
    441 #define TEST_ASSERT_ERROR__BROKEN(error_cond)                           \ 
    442     do {                                                                \ 
    443         const char *error = (error_cond);                               \ 
    444         if (!error) {                                                    \ 
    445             TEST_WARNING("Known broken behavior ('%s' fails to report error)", \ 
    446                          #error_cond);                                  \ 
    447         }                                                               \ 
    448         else {                                                          \ 
    449             TEST_ERROR2("Former broken test '%s' succeeds (reports error '%s')", \ 
    450                        #error_cond, error);                             \ 
    451         }                                                               \ 
    452     } while (0) 
    453  
    454  
    455 // -------------------------------------------------------------------------------- 
    456  
    457 #define TEST_EXPORTED_ERROR() (GB_have_error() ? GB_await_error() : NULL) 
    458  
    459 #define TEST_CLEAR_EXPORTED_ERROR()                                     \ 
    460     do {                                                                \ 
    461         const char *error = TEST_EXPORTED_ERROR();                      \ 
    462         if (error) {                                                    \ 
    463             TEST_WARNING("detected and cleared exported error '%s'",    \ 
    464                          error);                                        \ 
    465         }                                                               \ 
    466     } while (0) 
    467  
    468 #define TEST_ASSERT_NORESULT__ERROREXPORTED_CHECKERROR(create_result,equal,contains) \ 
    469     do {                                                                \ 
    470         TEST_CLEAR_EXPORTED_ERROR();                                    \ 
    471         bool have_result = (create_result);                             \ 
    472         const char *error = TEST_EXPORTED_ERROR();                      \ 
    473         if (have_result) {                                              \ 
    474             if (error) {                                                \ 
    475                 TEST_WARNING("Error '%s' exported (when result returned)", \ 
    476                              error);                                    \ 
    477             }                                                           \ 
    478             TEST_ERROR("Expected '%s' to return NULL", #create_result); \ 
    479         }                                                               \ 
    480         else if (!error) {                                              \ 
    481             TEST_ERROR("'%s' (w/o result) should always export error",  \ 
    482                        #create_result);                                 \ 
    483         }                                                               \ 
    484         if (equal) TEST_ASSERT_EQUAL(error, equal);                     \ 
    485         if (contains) TEST_ASSERT_CONTAINS(error, contains);            \ 
     1125#define TEST_ASSERT_NORESULT__ERROREXPORTED_CHECKERROR(create_result,equal,contains)    \ 
     1126    do {                                                                                \ 
     1127        TEST_CLEAR_EXPORTED_ERROR();                                                    \ 
     1128        bool have_result = (create_result);                                             \ 
     1129        const char *error_ = TEST_EXPORTED_ERROR();                                     \ 
     1130        if (have_result) {                                                              \ 
     1131            if (error_) {                                                               \ 
     1132                TEST_WARNING("Error '%s' exported (when result returned)",              \ 
     1133                             error_);                                                   \ 
     1134            }                                                                           \ 
     1135            TEST_ERROR("Expected '%s' to return NULL", #create_result);                 \ 
     1136        }                                                                               \ 
     1137        else if (!error_) {                                                             \ 
     1138            TEST_ERROR("'%s' (w/o result) should always export error",                  \ 
     1139                       #create_result);                                                 \ 
     1140        }                                                                               \ 
     1141        if (equal) TEST_ASSERT_EQUAL(error_, equal);                                    \ 
     1142        if (contains) TEST_ASSERT_CONTAINS(error_, contains);                           \ 
    4861143    } while (0) 
    4871144 
     
    4901147     
    4911148 
    492 #define TEST_ASSERT_RESULT__NOERROREXPORTED(create_result)              \ 
    493     do {                                                                \ 
    494         TEST_CLEAR_EXPORTED_ERROR();                                    \ 
    495         bool have_result = (create_result);                             \ 
    496         const char *error = TEST_EXPORTED_ERROR();                      \ 
    497         if (have_result) {                                              \ 
    498             if (error) {                                                \ 
    499                 TEST_ERROR("Error '%s' exported (when result returned)", \ 
    500                            error);                                      \ 
    501             }                                                           \ 
    502         }                                                               \ 
    503         else {                                                          \ 
    504             if (!error) {                                               \ 
    505                 TEST_WARNING("'%s' (w/o result) should always export error", \ 
    506                              #create_result);                           \ 
    507             }                                                           \ 
    508             else {                                                      \ 
    509                 TEST_WARNING("exported error is '%s'", error);          \ 
    510             }                                                           \ 
    511             TEST_ERROR2("Expected '%s' to return sth (exported=%s)", #create_result, error); \ 
    512         }                                                               \ 
     1149#define TEST_ASSERT_RESULT__NOERROREXPORTED(create_result)                                      \ 
     1150    do {                                                                                        \ 
     1151        TEST_CLEAR_EXPORTED_ERROR();                                                            \ 
     1152        bool have_result = (create_result);                                                     \ 
     1153        const char *error_ = TEST_EXPORTED_ERROR();                                             \ 
     1154        if (have_result) {                                                                      \ 
     1155            if (error_) {                                                                       \ 
     1156                TEST_ERROR("Error '%s' exported (when result returned)",                        \ 
     1157                           error_);                                                             \ 
     1158            }                                                                                   \ 
     1159        }                                                                                       \ 
     1160        else {                                                                                  \ 
     1161            if (!error_) {                                                                      \ 
     1162                TEST_WARNING("'%s' (w/o result) should always export error",                    \ 
     1163                             #create_result);                                                   \ 
     1164            }                                                                                   \ 
     1165            else {                                                                              \ 
     1166                TEST_WARNING("exported error is '%s'", error_);                                 \ 
     1167            }                                                                                   \ 
     1168            TEST_ERROR2("Expected '%s' to return sth (exported=%s)", #create_result, error_);  \ 
     1169        }                                                                                       \ 
    5131170    } while (0) 
    5141171 
     
    5441201// -------------------------------------------------------------------------------- 
    5451202 
    546 #define TEST_ASSERT_NULL(n)         TEST_ASSERT(arb_test::test_equal(n, (typeof(n))NULL)) 
    547 #define TEST_ASSERT_NULL__BROKEN(n) TEST_ASSERT__BROKEN(arb_test::test_equal(n, (typeof(n))NULL)) 
    548  
    549 #define TEST_ASSERT_EQUAL(e1,t2)         TEST_ASSERT(arb_test::test_equal(e1, t2)) 
    550 #define TEST_ASSERT_EQUAL__BROKEN(e1,t2) TEST_ASSERT__BROKEN(arb_test::test_equal(e1, t2)) 
    551  
    552 #define TEST_ASSERT_SIMILAR(e1,t2,epsilon)         TEST_ASSERT(arb_test::test_similar(e1, t2, epsilon)) 
    553 #define TEST_ASSERT_SIMILAR__BROKEN(e1,t2,epsilon) TEST_ASSERT__BROKEN(arb_test::test_similar(e1, t2, epsilon)) 
    554  
    555 #define TEST_ASSERT_DIFFERENT(e1,t2)         TEST_ASSERT(arb_test::test_different(e1, t2)) 
    556 #define TEST_ASSERT_DIFFERENT__BROKEN(e1,t2) TEST_ASSERT__BROKEN(arb_test::test_different(e1, t2)) 
    557  
    558 #define TEST_ASSERT_LOWER_EQUAL(lower,upper)  TEST_ASSERT(arb_test::test_less_equal(lower, upper)) 
    559 #define TEST_ASSERT_LOWER(lower,upper) do { TEST_ASSERT_LOWER_EQUAL(lower, upper); TEST_ASSERT_DIFFERENT(lower, upper); } while(0) 
    560 #define TEST_ASSERT_IN_RANGE(val,lower,upper) do { TEST_ASSERT_LOWER_EQUAL(lower, val); TEST_ASSERT_LOWER_EQUAL(val, upper); } while(0) 
    561  
    562  
    563 #define TEST_ASSERT_CONTAINS(str, part) TEST_ASSERT(arb_test::test_strcontains(str, part)) 
     1203#define TEST_ASSERT_EQUAL(e1,t2)         TEST_EXPECT(that(e1).equals(t2)) 
     1204#define TEST_ASSERT_EQUAL__BROKEN(e1,t2) TEST_EXPECT__BROKEN(that(e1).equals(t2)) 
     1205 
     1206#define TEST_ASSERT_NULL(n)         TEST_ASSERT_EQUAL(n, NULL) 
     1207#define TEST_ASSERT_NULL__BROKEN(n) TEST_ASSERT_EQUAL__BROKEN(n, NULL) 
     1208 
     1209#define TEST_ASSERT_SIMILAR(e1,t2,epsilon)         TEST_EXPECT(that(e1).is(epsilon_similar(epsilon), t2)) 
     1210#define TEST_ASSERT_SIMILAR__BROKEN(e1,t2,epsilon) TEST_EXPECT__BROKEN(that(e1).is(epsilon_similar(epsilon), t2)) 
     1211 
     1212#define TEST_ASSERT_DIFFERENT(e1,t2)         TEST_EXPECT(that(e1).differs(t2)); 
     1213#define TEST_ASSERT_DIFFERENT__BROKEN(e1,t2) TEST_EXPECT__BROKEN(that(e1).differs(t2)); 
     1214 
     1215#define TEST_ASSERT_LOWER_EQUAL(lower,upper)  TEST_EXPECT(that(lower).less_or_equal(upper)) 
     1216#define TEST_ASSERT_LOWER(lower,upper)        TEST_EXPECT(that(lower).less_than(upper)) 
     1217#define TEST_ASSERT_IN_RANGE(val,lower,upper) TEST_EXPECT(all().of(that(val).more_or_equal(lower), that(val).less_or_equal(upper))) 
     1218 
     1219#define TEST_ASSERT_CONTAINS(str, part) TEST_EXPECT(that(str).is(containing(), part)) 
    5641220 
    5651221// -------------------------------------------------------------------------------- 
     
    5741230 
    5751231namespace arb_test { 
     1232    inline bool test_mem_equal(const void *mem1, const void *mem2, size_t size) { 
     1233        FlushedOutputNoLF yes; 
     1234        return GB_test_mem_equal(reinterpret_cast<const unsigned char *>(mem1), 
     1235                                 reinterpret_cast<const unsigned char *>(mem2), size) == size; 
     1236    } 
    5761237    inline bool test_files_equal(const char *file1, const char *file2) { 
    5771238        FlushedOutputNoLF yes; 
     
    5881249}; 
    5891250 
     1251#define TEST_COPY_FILE(src, dst) TEST_ASSERT(system(GBS_global_string("cp '%s' '%s'", src, dst)) == 0) 
     1252 
    5901253#define TEST_ASSERT_TEXTFILE_DIFFLINES(f1,f2,diff)         TEST_ASSERT(arb_test::test_textfile_difflines(f1,f2, diff)) 
    5911254#define TEST_ASSERT_TEXTFILE_DIFFLINES__BROKEN(f1,f2,diff) TEST_ASSERT__BROKEN(arb_test::test_textfile_difflines(f1,f2, diff)) 
     
    5961259#define TEST_ASSERT_FILES_EQUAL(f1,f2)         TEST_ASSERT(arb_test::test_files_equal(f1,f2)) 
    5971260#define TEST_ASSERT_FILES_EQUAL__BROKEN(f1,f2) TEST_ASSERT__BROKEN(arb_test::test_files_equal(f1,f2)) 
     1261 
     1262#define TEST_ASSERT_MEM_EQUAL(m1,m2,size)         TEST_ASSERT(arb_test::test_mem_equal(m1,m2,size)) 
     1263#define TEST_ASSERT_MEM_EQUAL__BROKEN(m1,m2,size) TEST_ASSERT__BROKEN(arb_test::test_mem_equal(m1,m2,size)) 
    5981264 
    5991265#define TEST_ASSERT_TEXTFILES_EQUAL(f1,f2)         TEST_ASSERT_TEXTFILE_DIFFLINES(f1,f2,0) 
     
    6171283// -------------------------------------------------------------------------------- 
    6181284 
    619 #define TEST_SETUP_GLOBAL_ENVIRONMENT(modulename) TEST_ASSERT_NO_ERROR(GB_system("../test_environment setup " modulename)) 
     1285#define TEST_SETUP_GLOBAL_ENVIRONMENT(modulename) do {                                                          \ 
     1286        arb_test::test_data().raiseLocalFlag(ANY_SETUP);                                                        \ 
     1287        TEST_ASSERT_NO_ERROR(GBK_system(GBS_global_string("../test_environment setup %s",  (modulename))));      \ 
     1288    } while(0) 
    6201289// cleanup is done (by Makefile.suite) after all unit tests have been run 
    6211290 
  • branches/dev_elmar/UNIT_TESTER/valgrind/arb_valgrind_logged

    r7209 r8224  
    1010    local EXE=$1 
    1111    shift 
    12     arb_valgrind -L $LOGGED.stdout $EXE "$@" > $LOGGING 
     12    arb_valgrind -L $LOGGED.stdout -E $LOGGED.stderr $EXE "$@" > $LOGGING 
     13    local EXITCODE=$? 
    1314    sleep 2 
    1415    cp $LOGGING $LOGGED 
     
    1617    cat $LOGGED.stdout 
    1718    rm $LOGGED.stdout 
     19    cat $LOGGED.stderr 1>&2 
     20    rm $LOGGED.stderr 
     21    return $EXITCODE 
    1822} 
    1923 
     
    5862    rm_if $BASEDIR/flag.valgrind.leaks 
    5963    rm_if $BASEDIR/flag.valgrind.reachable 
     64    rm_if $BASEDIR/flag.valgrind.callseen 
    6065} 
    6166 
  • branches/dev_elmar/WETC/WETC_main.cxx

    r7945 r8224  
    3131        } 
    3232        else { 
    33             AW_root *aw_root = AWT_create_root(".arb_prop/ntree.arb", "ARB_WETC"); 
     33            GB_shell shell; 
     34            AW_root *aw_root = AWT_create_root("ntree.arb", "ARB_WETC"); 
    3435 
    3536            AWT_show_file(aw_root, file); 
     
    3738            AWT_install_cb_guards(); 
    3839            aw_root->main_loop(); 
    39  
    4040        } 
    4141    } 
  • branches/dev_elmar/WINDOW/AW_edit.cxx

    r7945 r8224  
    111111    if (command) { 
    112112        aw_assert(!error); 
    113         error = GB_system(command); 
     113        error = GBK_system(command); 
    114114        if (error) { 
    115115            aw_message(error); error = NULL; 
     
    135135} 
    136136 
    137 void AW_system(AW_window *aww, GBDATA *gb_main, const char *command, const char *auto_help_file) { 
     137void AW_system(AW_window *aww, const char *command, const char *auto_help_file) { 
    138138    if (auto_help_file) AW_POPUP_HELP(aww, (AW_CL)auto_help_file); 
    139     if (GBCMC_system(gb_main, command) != 0) { 
    140         const char *error = GBS_global_string("Failed to execute '%s'\n(Reason: %s)", command, GB_await_error()); 
    141         aw_message(error); 
    142     } 
     139    aw_message_if(GBK_system(command)); 
    143140} 
  • branches/dev_elmar/WINDOW/AW_file_selection.cxx

    r7945 r8224  
    1717#include <arbdbt.h> 
    1818#include <arb_strbuf.h> 
     19#include <arb_file.h> 
    1920 
    2021#include <dirent.h> 
  • branches/dev_elmar/WINDOW/AW_help.cxx

    r7945 r8224  
    1616#include "aw_msg.hxx" 
    1717 
    18 #include <arbdbt.h> 
     18#include <arbdb.h> 
     19#include <arb_file.h> 
    1920 
    2021#include <sys/stat.h> 
     
    283284    } 
    284285 
    285     if (sys[0] && !error) error = GB_system(sys); 
     286    if (sys[0] && !error) error = GBK_system(sys); 
    286287 
    287288    return error; 
     
    414415                char       *gen_help_cmd  = GBS_global_string_copy(gen_help_tmpl, GB_getenvDOCPATH(), searchtext, helpfilename); 
    415416 
    416                 error = GB_system(gen_help_cmd); 
     417                error = GBK_system(gen_help_cmd); 
    417418 
    418419                free(gen_help_cmd); 
  • branches/dev_elmar/WINDOW/AW_nawar.cxx

    r7669 r8224  
    1414#include "aw_msg.hxx" 
    1515#include <arbdb.h> 
     16#include <arb_file.h> 
    1617#include <sys/stat.h> 
    1718 
     
    584585} 
    585586 
    586 const char *AW_root::property_DB_fullname(const char *default_name) { 
    587     const char *home = GB_getenvHOME(); 
    588     return GBS_global_string("%s/%s", home, default_name); 
    589 } 
    590  
    591 bool AW_root::property_DB_exists(const char *default_name) { 
    592     return GB_is_regularfile(property_DB_fullname(default_name)); 
    593 } 
    594  
    595587AW_default AW_root::load_properties(const char *default_name) { 
    596     GBDATA *gb_default = GB_open(default_name, "rwcD"); 
     588    GBDATA   *gb_default = GB_open(default_name, "rwcD"); 
     589    GB_ERROR  error      = NULL; 
    597590 
    598591    if (gb_default) { 
     
    600593 
    601594        GBDATA *gb_tmp = GB_search(gb_default, "tmp", GB_CREATE_CONTAINER); 
    602         GB_set_temporary(gb_tmp); 
     595        error          = GB_set_temporary(gb_tmp); 
    603596    } 
    604597    else { 
    605         GB_ERROR    error           = GB_await_error(); 
     598        error = GB_await_error(); 
     599    } 
     600 
     601    if (error) { 
    606602        const char *shown_name      = strrchr(default_name, '/'); 
    607603        if (!shown_name) shown_name = default_name; 
     
    609605        GBK_terminatef("Error loading properties '%s': %s", shown_name, error); 
    610606    } 
     607     
    611608    return (AW_default) gb_default; 
    612609} 
     
    624621            aw_update_awar_window_geometry(this); 
    625622            error = GB_pop_transaction(gb_main); 
    626             if (!error) error = GB_save_in_home(gb_main, filename, "a"); 
     623            if (!error) error = GB_save_in_arbprop(gb_main, filename, "a"); 
    627624        } 
    628625    } 
  • branches/dev_elmar/WINDOW/AW_status.cxx

    r7945 r8224  
    806806 
    807807        GB_shell shell; 
    808         AW_root *aw_root = new AW_root(".arb_prop/status.arb", "ARB_STATUS", true); 
     808        AW_root *aw_root = new AW_root("status.arb", "ARB_STATUS", true); 
    809809        create_status_awars(aw_root); 
    810810 
  • branches/dev_elmar/WINDOW/AW_window.cxx

    r7945 r8224  
    2424#include <arbdbt.h> 
    2525#include <arb_handlers.h> 
     26#include <arb_file.h> 
    2627 
    2728#include <X11/keysym.h> 
     
    33823383} 
    33833384 
    3384 GB_ERROR AW_root::start_macro_recording(const char *file, 
    3385         const char *application_id, const char *stop_action_name) { 
     3385GB_ERROR AW_root::start_macro_recording(const char *file, const char *application_id, const char *stop_action_name) { 
     3386    GB_ERROR error = NULL; 
    33863387    if (prvt->recording_macro_file) { 
    3387         return GB_export_error("Already Recording Macro"); 
    3388     } 
    3389     char *path = 0; 
    3390     if (file[0] == '/') { 
    3391         path = strdup(file); 
     3388        error = "Already recording macro"; 
    33923389    } 
    33933390    else { 
    3394         path = GBS_global_string_copy("%s/%s", GB_getenvARBMACROHOME(), file); 
    3395     } 
    3396     char *macro_header = GB_read_file("$(ARBHOME)/lib/macro.head"); 
    3397     if (!macro_header) { 
    3398         return GB_export_errorf("Cannot open file '%s'", "$(ARBHOME)/lib/macro.head"); 
    3399     } 
    3400  
    3401     prvt->recording_macro_file = fopen(path, "w"); 
    3402     prvt->recording_macro_path = path; 
    3403     if (!prvt->recording_macro_file) { 
    3404         delete macro_header; 
    3405         return GB_export_errorf("Cannot open file '%s' for writing", file); 
    3406     } 
    3407     prvt->stop_action_name = strdup(stop_action_name); 
    3408     prvt->application_name_for_macros = strdup(application_id); 
    3409  
    3410     fprintf(prvt->recording_macro_file, "%s", macro_header); 
    3411     free(macro_header); 
    3412     return 0; 
     3391        char *path               = NULL; 
     3392        if (file[0] == '/') path = strdup(file); 
     3393        else  path               = GBS_global_string_copy("%s/%s", GB_getenvARBMACROHOME(), file); 
     3394 
     3395        char *macro_header       = GB_read_file(GB_path_in_ARBLIB("macro.head")); 
     3396        if (!macro_header) error = GB_await_error(); 
     3397        else { 
     3398            prvt->recording_macro_file = fopen(path, "w"); 
     3399 
     3400            if (prvt->recording_macro_file) { 
     3401                prvt->stop_action_name            = strdup(stop_action_name); 
     3402                prvt->application_name_for_macros = strdup(application_id); 
     3403 
     3404                fprintf(prvt->recording_macro_file, "%s", macro_header); 
     3405                reassign(prvt->recording_macro_path, path); 
     3406            } 
     3407            else error = GB_IO_error("recording to", file); 
     3408            free(macro_header); 
     3409        } 
     3410        free(path); 
     3411    } 
     3412    return error; 
    34133413} 
    34143414 
  • branches/dev_elmar/WINDOW/Makefile

    r7945 r8224  
    242242AW_file_selection.o: $(ARBHOME)/INCLUDE/arb_core.h 
    243243AW_file_selection.o: $(ARBHOME)/INCLUDE/arb_error.h 
     244AW_file_selection.o: $(ARBHOME)/INCLUDE/arb_file.h 
    244245AW_file_selection.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    245246AW_file_selection.o: $(ARBHOME)/INCLUDE/arb_strbuf.h 
     
    302303AW_help.o: aw_window.hxx 
    303304AW_help.o: $(ARBHOME)/INCLUDE/ad_prot.h 
    304 AW_help.o: $(ARBHOME)/INCLUDE/ad_t_prot.h 
    305305AW_help.o: $(ARBHOME)/INCLUDE/arb_assert.h 
    306306AW_help.o: $(ARBHOME)/INCLUDE/arb_core.h 
    307307AW_help.o: $(ARBHOME)/INCLUDE/arb_error.h 
     308AW_help.o: $(ARBHOME)/INCLUDE/arb_file.h 
    308309AW_help.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    309310AW_help.o: $(ARBHOME)/INCLUDE/arb_string.h 
    310311AW_help.o: $(ARBHOME)/INCLUDE/arbdb.h 
    311312AW_help.o: $(ARBHOME)/INCLUDE/arbdb_base.h 
    312 AW_help.o: $(ARBHOME)/INCLUDE/arbdbt.h 
    313313AW_help.o: $(ARBHOME)/INCLUDE/arbtools.h 
    314314AW_help.o: $(ARBHOME)/INCLUDE/attributes.h 
     
    353353AW_nawar.o: $(ARBHOME)/INCLUDE/arb_core.h 
    354354AW_nawar.o: $(ARBHOME)/INCLUDE/arb_error.h 
     355AW_nawar.o: $(ARBHOME)/INCLUDE/arb_file.h 
    355356AW_nawar.o: $(ARBHOME)/INCLUDE/arb_msg.h 
    356357AW_nawar.o: $(ARBHOME)/INCLUDE/arb_string.h 
     
    542543AW_window.o: $(ARBHOME)/INCLUDE/arb_defs.h 
    543544AW_window.o: $(ARBHOME)/INCLUDE/arb_error.h 
     545AW_window.o: $(ARBHOME)/INCLUDE/arb_file.h 
    544546AW_window.o: $(ARBHOME)/INCLUDE/arb_handlers.h 
    545547AW_window.o: $(ARBHOME)/INCLUDE/arb_msg.h 
  • branches/dev_elmar/WINDOW/aw_position.hxx

    r7669 r8224  
    3232 
    3333#if defined(DEBUG) 
     34 
    3435#define ISVALID(a) aw_assert((a).valid()) 
     36 
     37inline const double& NONAN(const double& d) { 
     38    aw_assert(d == d); 
     39    return d; 
     40} 
     41 
    3542#else 
    3643#define ISVALID(a) 
     44#define NONAN(d)   (d) 
    3745#endif // DEBUG 
    3846 
     
    7886 
    7987        Position(double X, double Y) : x(X), y(Y) { ISVALID(*this); } 
     88        // Position(const Position& other) : x(other.x), y(other.y) { ISVALID(*this); } 
    8089        Position() : x(NAN), y(NAN) {} // default is no position 
    8190        ~Position() {} 
     
    8796        const double& ypos() const { return y; } 
    8897 
    89         void setx(const double& X) { x = X; } 
    90         void sety(const double& Y) { y = Y; } 
    91  
    92         void movex(const double& X) { x += X; } 
    93         void movey(const double& Y) { y += Y; } 
     98        void setx(const double& X) { x = NONAN(X); } 
     99        void sety(const double& Y) { y = NONAN(Y); } 
     100 
     101        void movex(const double& X) { x += NONAN(X); } 
     102        void movey(const double& Y) { y += NONAN(Y); } 
    94103 
    95104        void move(const Vector& movement) { *this += movement; } 
     
    103112    extern const Position Origin; 
    104113 
     114    inline bool nearlyEqual(const Position& p1, const Position& p2) { 
     115        return 
     116            nearlyEqual(p1.xpos(), p2.xpos()) &&  
     117            nearlyEqual(p1.ypos(), p2.ypos());  
     118    } 
     119     
    105120    // ------------------------------- 
    106121    //      a 2D vector 
     
    176191    extern const Vector ZeroVector; 
    177192 
     193    inline bool nearlyEqual(const Vector& v1, const Vector& v2) { return nearlyEqual(v1.endpoint(), v2.endpoint()); } 
     194     
    178195    // ----------------------------------------- 
    179196    //      inline Position members 
     
    273290    inline bool is_vertical(const LineVector& line) { return is_vertical(line.line_vector()); } 
    274291    inline bool is_horizontal(const LineVector& line) { return is_horizontal(line.line_vector()); } 
    275  
     292    inline bool nearlyEqual(const LineVector& L1, const LineVector& L2) { 
     293        return 
     294            nearlyEqual(L1.line_vector(), L2.line_vector()) && 
     295            nearlyEqual(L1.start(), L2.start()); 
     296    } 
     297     
    276298    // --------------------- 
    277299    //      a rectangle 
     
    468490    } 
    469491 
    470     inline bool are_orthographic(const Vector& v1, const Vector& v2) { 
     492    inline bool are_orthographic(const Vector& v1, const Vector& v2) { // orthogonal (dt.) 
    471493        return are_equal(scalarProduct(v1, v2), 0); 
    472494    } 
     495 
    473496#endif // DEBUG 
    474497 
  • branches/dev_elmar/WINDOW/aw_root.hxx

    r7945 r8224  
    147147    void unlink_awars_from_DB(GBDATA *gb_main);     // use before calling GB_close for 'gb_main', if you have AWARs in DB 
    148148 
    149     static const char *property_DB_fullname(const char *default_name); 
    150     static bool        property_DB_exists(const char *default_name); 
    151  
    152149    AW_default check_properties(AW_default aw_props) { 
    153150        return aw_props ? aw_props : application_database; 
     
    189186inline AW_default get_AW_ROOT_DEFAULT() { return AW_root::SINGLETON->check_properties(NULL); } 
    190187 
    191 void AW_system(AW_window *aww, GBDATA *gb_main, const char *command, const char *auto_help_file); 
     188void AW_system(AW_window *aww, const char *command, const char *auto_help_file); 
    192189 
    193190#else 
  • branches/dev_elmar/arb_LICENSE.txt

    r7945 r8224  
    236236        which is provided in 'lib/GPL.txt'. 
    237237 
    238     molphy 
    239  
    240         MOLPHY: A Computer Program Package for Molecular Phylogenetics 
    241          
    242         Readme 
    243                This is the MOLPHY (ProtML) distribution,  version 2.3. 
    244                 Copyright (c) 1992-1996, Jun Adachi & Masami Hasegawa. 
    245                                  All rights reserved. 
    246          
    247                 MOLPHY is a program package for MOLecular PHYlogenetics. 
    248          
    249         ProtML is a main program in MOLPHY for inferring evolutionary trees from 
    250         PROTein (amino acid) sequences by using the Maximum Likelihood method. 
    251          
    252         Programs (C language) 
    253           ProtML: Maximum Likelihood Inference of Protein Phylogeny 
    254           NucML:  Maximum Likelihood Inference of Nucleic Acid Phylogeny 
    255           ProtST: Basic Statistics of Protein Sequences 
    256           NucST:  Basic Statistics of Nucleic Acid Sequences 
    257           NJdist: Neighbor Joining Phylogeny from Distance Matrix 
    258         Utilities (Perl) 
    259           mollist:  get identifiers list        molrev:   reverse DNA sequences 
    260           molcat:   concatenate sequences       molcut:   get partial sequences 
    261           molmerge: merge sequences             nuc2ptn:  DNA -> Amino acid 
    262           rminsdel: remove INS/DEL sites        molcodon: get specified codon sites 
    263           molinfo:  get varied sites            mol2mol:  MOLPHY format beautifer 
    264           inl2mol:  Interleaved -> MOLPHY       mol2inl:  MOLPHY -> Interleaved 
    265           mol2phy:  MOLPHY -> Sequential        phy2mol:  Sequential -> MOLPHY 
    266           must2mol: MUST -> MOLPHY              etc. 
    267          
    268         MOLPHY is a free software, and you can use and redistribute it. 
    269         The programs are written in a standard subset of C with UNIX-like OS. 
    270         The utilities are written in the "Perl" (Ver.4.036) with UNIX-like OS. 
    271         MOLPHY has been tested on SUN4's (cc & gcc with SUN-OS 4.1.3) and 
    272         HP9000/700 (cc, c89 & gcc with HP-UX 9.05). 
    273         However, MOLPHY has NOT been tested on VAX, IBM-PC, and Macintosh. 
    274          
    275         NETWORK DISTRIBUTION ONLY: The latest version of MOLPHY is always available 
    276         by anonymous ftp in ftp.ism.ac.jp: /pub/ISMLIB/MOLPHY/. 
    277  
    278238    readseq 
    279239 
  • branches/dev_elmar/arb_README.txt

    r6211 r8224  
    99        ARB is currently developed on Linux PCs only. 
    1010 
    11         Compiling ARB using the gcc compiler (versions 2.95.3, 3.x and 4.x series) 
     11        Compiling ARB using the gcc compiler (4.x series) 
    1212        as well works on Mac OSX and Sun OS - but we do not publish or support 
    1313        these versions. 
     
    3939        'arb.64.*.tgz'          // 64 bit versions 
    4040 
    41         'arb.*.SuSE*.tgz        // SuSE version 
    42         'arb.*.Ubuntu*.tgz      // Ubuntu version (recommended) 
    43  
    4441        'arb.*.OPENGL.tgz'      // OPENGL version (contains RNA3D, a 3D-molecule-viewer) 
    4542 
     
    4845        choose a 64-bit-version, if your system is 64-bit. 
    4946 
    50         Normally one of the Ubuntu versions should work for you, only 
    51         use one of the SuSE versions, if the Ubuntu version has problems 
    52         (e.g. does not display group names in ARB_EDIT4). 
     47        You need only ONE of the available 'arb.*.tgz'! 
    5348 
    5449 
     
    6661                'arb_install.sh'                // install script 
    6762                'arb_README.txt'                // this file 
    68                 'arb.*.tgz'                     // ARB binaries 
     63                'arb.*.tgz'                     // your chosen ARB version 
     64 
    6965 
    7066        are located and type 
  • branches/dev_elmar/arb_UBUNTU.txt

    r7489 r8224  
    11 
    2 ARB requirements on Ubuntu 8.10 
    3 ------------------------------- 
     2ARB requirements on Ubuntu 10.04 
     3-------------------------------- 
    44 
    55[Note:] 
  • branches/dev_elmar/lib/arb_tcp_org.dat

    r6708 r8224  
    3232 
    3333ARB_TEST_PT_SERVER          localhost:3200          arb_pt_server   -D$(ARBHOME)/UNIT_TESTER/run/TEST_pt.arb 
    34  
     34ARB_TEST_PT_SERVER_GENE     localhost:3201          arb_pt_server   -D$(ARBHOME)/UNIT_TESTER/run/TEST_gpt.arb 
    3535 
    3636#***********    Private Servers (for each user) ****************** 
  • branches/dev_elmar/lib/pictures/ad_gen_create.fig

    • Property svn:mergeinfo changed from /trunk/lib/pictures/ad_gen_create.fig:7771-7998 to /trunk/lib/pictures/ad_gen_create.fig:7771-8223
  • branches/dev_elmar/lib/pictures/awt/export.fig

    r4087 r8224  
    1 #FIG 2.1 
    2 80 2 
    3 6 84 169 474 539 
    4 2 1 0 1 -1 0 0 0 0.000 -1 0 0 
    5          239 204 84 204 84 574 474 574 474 204 319 204 9999 9999 
     1#FIG 3.2  Produced by xfig version 3.2.5b 
     2Landscape 
     3Center 
     4Metric 
     5A4       
     6100.00 
     7Single 
     8-2 
     91200 2 
     106 1275 2550 7125 8100 
     112 1 0 1 -1 -1 0 0 -1 0.000 0 0 -1 0 0 6 
     12         3600 3075 1275 3075 1275 8625 7125 8625 7125 3075 4800 3075 
    613-6 
    7 6 89 159 469 229 
    8 4 0 18 12 0 -1 0 0.00000 4 15 28 89 264 $box 
    9 4 2 18 12 0 -1 0 0.00000 4 15 33 469 233 $filter 
    10 4 2 18 12 0 -1 0 0.00000 4 15 33 409 229 Suffix 
    11 4 0 18 12 0 -1 0 0.00000 4 15 153 94 229 Directories (D) and Files (f) 
    12 4 1 18 12 0 -1 0 0.00000 4 15 52 279 209 Filename 
     146 1350 2400 7050 3450 
     154 0 -1 0 0 18 12 0.0000 4 210 495 1350 3975 $box\001 
     164 2 -1 0 0 18 12 0.0000 4 210 585 7050 3510 $filter\001 
     174 2 -1 0 0 18 12 0.0000 4 165 570 6150 3450 Suffix\001 
     184 0 -1 0 0 18 12 0.0000 4 210 2805 1425 3450 Directories (D) and Files (f)\001 
     194 1 -1 0 0 18 12 0.0000 4 165 930 4200 3150 Filename\001 
    1320-6 
    14 2 2 0 1 -1 0 0 0 0.000 0 0 0 
    15          479 624 479 34 74 34 74 624 479 624 9999 9999 
    16 4 0 18 12 0 -1 0 0.00000 4 15 38 89 64 $close 
    17 4 2 18 12 0 -1 0 0.00000 4 15 31 469 64 $help 
    18 4 2 18 12 0 -1 0 0.00000 4 15 78 469 564 $to:file_name 
    19 4 0 18 12 0 -1 0 0.00000 4 15 63 89 564 $file_name 
    20 4 2 18 12 0 -1 0 0.00000 4 15 43 469 514 $to:box 
    21 4 0 18 12 0 -1 0 0.00000 4 15 57 89 534 File Name 
    22 4 0 18 12 0 -1 0 0.00000 4 15 34 89 99 $what 
    23 4 0 18 12 0 -1 0 0.00000 4 15 81 89 134 $remove_root 
    24 4 0 18 12 0 -1 0 0.00000 4 15 81 89 179 $color 
    25 4 0 18 12 0 -1 0 0.00000 4 15 28 89 609 $xfig 
    26 4 2 18 12 0 -1 0 0.00000 4 15 43 184 609 $to:xfig 
    27 4 0 18 12 0 -1 0 0.00000 4 15 45 339 609 $cancel 
    28 4 2 18 12 0 -1 0 0.00000 4 15 60 454 609 $to:cancel 
     212 2 0 1 -1 -1 0 0 -1 0.000 0 0 0 0 0 5 
     22         7200 9375 7200 525 1125 525 1125 9375 7200 9375 
     234 0 -1 0 0 18 12 0.0000 4 210 675 1350 975 $close\001 
     244 2 -1 0 0 18 12 0.0000 4 225 570 7050 975 $help\001 
     254 2 -1 0 0 18 12 0.0000 4 225 1380 7050 8475 $to:file_name\001 
     264 0 -1 0 0 18 12 0.0000 4 225 1095 1350 8475 $file_name\001 
     274 2 -1 0 0 18 12 0.0000 4 210 780 7050 7725 $to:box\001 
     284 0 -1 0 0 18 12 0.0000 4 165 1020 1350 8025 File Name\001 
     294 0 -1 0 0 18 12 0.0000 4 210 600 1350 1500 $what\001 
     304 0 -1 0 0 18 12 0.0000 4 225 1440 1350 2025 $remove_root\001 
     314 0 -1 0 0 18 12 0.0000 4 210 660 1350 2700 $color\001 
     324 0 -1 0 0 18 12 0.0000 4 225 480 1350 9150 $xfig\001 
  • branches/dev_elmar/lib/pictures/awt/secExport.fig

    r4750 r8224  
    1 #FIG 3.2 
     1#FIG 3.2  Produced by xfig version 3.2.5b 
    22Landscape 
    33Center 
     
    12122 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 1 
    1313         7155 8865 
    14 4 0 -1 0 0 18 12 0.0000 4 165 450 1440 8595 $xfig\001 
    15 4 0 -1 0 0 18 12 0.0000 4 150 900 1305 7155 $file_name\001 
    16 4 2 -1 0 0 2 12 0.0000 4 150 720 5895 2250 X:Suffix\001 
    17 4 0 -1 0 0 18 12 0.0000 4 135 360 1350 2745 $box\001 
    18 4 0 -1 0 0 2 14 0.0000 4 135 810 1350 6750 File Name\001 
    19 4 2 -1 0 0 18 12 0.0000 4 165 720 3375 8595 $to:xfig\001 
    20 4 0 -1 0 0 18 12 0.0000 4 135 540 1710 8100 $color\001 
    21 4 2 -1 0 0 18 12 0.0000 4 150 1350 7065 7290 $to:X:file_name\001 
    22 4 0 -1 0 0 18 12 0.0000 4 135 450 1710 7695 $what\001 
    23 4 0 -1 0 0 2 14 0.0000 4 165 3150 1350 1935 Select Path to export the STRUCTURE\001 
    24 4 0 -1 0 0 2 13 0.0000 4 165 2610 1350 2295 Directories (D) and Files (f)\001 
    25 4 2 -1 0 0 18 12 0.0000 4 150 810 7065 6390 $to:X:box\001 
    26 4 2 -1 0 0 18 12 0.0000 4 150 810 7065 2340 $X:filter\001 
    27 4 2 -1 0 0 18 12 0.0000 4 150 810 7065 8595 $X:cancel\001 
    28 4 0 -1 0 0 18 12 0.0000 4 135 540 1350 1575 $close\001 
    29 4 2 -1 0 0 18 12 0.0000 4 165 630 7065 1620 $X:help\001 
     144 0 -1 0 0 18 12 0.0000 4 225 480 1440 8595 $xfig\001 
     154 0 -1 0 0 18 12 0.0000 4 225 1095 1305 7155 $file_name\001 
     164 2 -1 0 0 2 12 0.0000 4 150 750 5895 2250 X:Suffix\001 
     174 0 -1 0 0 18 12 0.0000 4 210 495 1350 2745 $box\001 
     184 0 -1 0 0 2 14 0.0000 4 165 1080 1350 6750 File Name\001 
     194 0 -1 0 0 18 12 0.0000 4 210 660 1710 8100 $color\001 
     204 2 -1 0 0 18 12 0.0000 4 225 1590 7065 7290 $to:X:file_name\001 
     214 0 -1 0 0 18 12 0.0000 4 210 600 1710 7695 $what\001 
     224 0 -1 0 0 2 14 0.0000 4 225 4200 1350 1935 Select Path to export the STRUCTURE\001 
     234 0 -1 0 0 2 13 0.0000 4 195 2445 1350 2295 Directories (D) and Files (f)\001 
     244 2 -1 0 0 18 12 0.0000 4 210 990 7065 6390 $to:X:box\001 
     254 2 -1 0 0 18 12 0.0000 4 210 795 7065 2340 $X:filter\001 
     264 0 -1 0 0 18 12 0.0000 4 210 675 1350 1575 $close\001 
     274 2 -1 0 0 18 12 0.0000 4 225 780 7065 1620 $X:help\001 
  • branches/dev_elmar/lib/pictures/dbbrowser.fig

    r2753 r8224  
    1 #FIG 3.2 
     1#FIG 3.2  Produced by xfig version 3.2.5b 
    22Landscape 
    33Center 
     
    88-2 
    991200 2 
    10 2 1 0 1 -1 -1 0 0 -1 0.000 0 0 -1 0 0 1 
    11          600 825 
    12 2 1 0 1 -1 -1 0 0 -1 0.000 0 0 -1 0 0 2 
    13          8865 10200 8865 10275 
    14 4 0 -1 0 0 18 13 0.0000 4 180 600 750 1200 $close\001 
    15 4 2 -1 0 0 18 12 0.0000 4 180 645 8700 1200 $X:help\001 
    16 4 2 -1 0 0 18 13 0.0000 4 195 945 8700 2385 $to:X:path\001 
    17 4 0 -1 0 0 18 13 0.0000 4 135 420 855 2250 Path\001 
    18 4 0 -1 0 0 18 13 0.0000 4 135 840 855 1755 Database\001 
    19 4 0 -1 0 0 18 13 0.0000 4 135 1335 855 7695 Y:Information:\001 
    20 4 2 -1 0 0 18 13 0.0000 4 180 1350 8700 7380 $to:XY:browse\001 
    21 4 2 -1 0 0 18 13 0.0000 4 180 1035 8700 10170 $to:XY:info\001 
    22 4 0 -1 0 0 18 13 0.0000 4 135 750 855 2790 Browse:\001 
    23 4 0 -1 0 0 18 13 0.0000 4 180 780 855 3150 $browse\001 
    24 4 0 -1 0 0 18 13 0.0000 4 180 660 855 8190 $Y:info\001 
    25 4 0 -1 0 0 18 13 0.0000 4 195 510 2115 2250 $path\001 
    26 4 0 -1 0 0 18 13 0.0000 4 180 345 2115 1755 $db\001 
    27 4 0 -1 0 0 18 13 0.0000 4 195 1080 4050 2745 $navigation\001 
    28 4 0 -1 0 0 18 13 0.0000 4 180 600 2115 2745 $order\001 
     102 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 1 
     11         675 990 
     122 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 1 
     13         19440 13770 
     144 0 -1 0 0 18 13 0.0000 4 210 675 750 1200 $close\001 
     154 0 -1 0 0 18 13 0.0000 4 165 975 2475 1260 Database\001 
     164 0 -1 0 0 18 13 0.0000 4 210 390 3735 1260 $db\001 
     174 0 -1 0 0 18 13 0.0000 4 165 480 2475 1845 Path\001 
     184 0 -1 0 0 18 13 0.0000 4 225 585 3735 1845 $path\001 
     194 0 -1 0 0 18 13 0.0000 4 210 690 2115 2385 $order\001 
     204 0 -1 0 0 18 13 0.0000 4 225 1215 4815 2385 $navigation\001 
     214 0 -1 0 0 18 13 0.0000 4 165 840 855 2430 Browse:\001 
     224 0 -1 0 0 18 13 0.0000 4 210 870 855 2790 $browse\001 
     234 2 -1 0 0 18 12 0.0000 4 225 780 19365 1350 $X:help\001 
     244 2 -1 0 0 18 13 0.0000 4 225 1080 19365 1980 $to:X:path\001 
     254 2 -1 0 0 18 13 0.0000 4 210 1155 19365 13725 $to:XY:info\001 
     264 0 -1 0 0 18 13 0.0000 4 165 1260 9540 2745 Information:\001 
     274 0 -1 0 0 18 13 0.0000 4 210 510 9540 3105 $info\001 
     284 2 -1 0 0 18 13 0.0000 4 210 1380 9495 13725 $to:Y:browse\001 
     294 0 -1 0 0 18 13 0.0000 4 225 855 11835 2700 $infoopt\001 
  • branches/dev_elmar/util/arb_srclst.pl

    r7999 r8224  
    168168                             qr/\/UNIT_TESTER\/run\/.*\.tree$/o, 
    169169                             qr/\/UNIT_TESTER\/run\/impexp\/.*\.exported$/o, 
    170                              qr/\/UNIT_TESTER\/run\/TEST_.*\.pt$/o, # has to move to skipped_when_matchesFull (when merging test env) 
    171170                             qr/\/UNIT_TESTER\/valgrind\/arb_valgrind_logged$/o, 
    172171                             qr/^\.\/etc\//o, 
     
    211210                                qr/^\.\/SOURCE_TOOLS\/valgrind2grep\.lst$/o, 
    212211                                qr/^\.\/TEMPLATES\/arb_build\.h$/o, 
     212                                qr/^\.\/UNIT_TESTER\/run\/TEST_g?pt\.arb$/o, 
     213                                qr/^\.\/UNIT_TESTER\/run\/.*\.ARM$/o, 
     214                                qr/^\.\/UNIT_TESTER\/run\/.*\.ARF$/o, 
    213215                                qr/date\.xsl$/o, 
    214216                               );