| 1 | #include <stdio.h> | 
|---|
| 2 | #include <stdlib.h> | 
|---|
| 3 | #include <string.h> | 
|---|
| 4 | #include <malloc.h> | 
|---|
| 5 | #include <names_client.h> | 
|---|
| 6 | #include <arbdb.h> | 
|---|
| 7 | #include <arbdbt.h> | 
|---|
| 8 | #include <servercntrl.h> | 
|---|
| 9 | #include <client.h> | 
|---|
| 10 |  | 
|---|
| 11 | struct ang_struct { | 
|---|
| 12 | aisc_com *link; | 
|---|
| 13 | T_AN_LOCAL locs; | 
|---|
| 14 | T_AN_MAIN com; | 
|---|
| 15 | } ang = { 0,0,0} ; | 
|---|
| 16 |  | 
|---|
| 17 | int init_local_com_names() | 
|---|
| 18 | { | 
|---|
| 19 | /*** create and init local com structure ***/ | 
|---|
| 20 | if( aisc_create(ang.link, AN_MAIN, ang.com, | 
|---|
| 21 | MAIN_LOCAL, AN_LOCAL, &ang.locs, | 
|---|
| 22 | LOCAL_WHOAMI, "i bin der arb_tree", | 
|---|
| 23 | NULL)){ | 
|---|
| 24 | return 1; | 
|---|
| 25 | } | 
|---|
| 26 | return 0; | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | GB_ERROR connect_2_an(GBDATA *gb_main) | 
|---|
| 30 | { | 
|---|
| 31 | char *servername; | 
|---|
| 32 | char *name_server = "ARB_NAME_SERVER"; | 
|---|
| 33 |  | 
|---|
| 34 | if (arb_look_and_start_server(AISC_MAGIC_NUMBER,name_server,gb_main)){ | 
|---|
| 35 | return "Sorry I can't start the NAME SERVER"; | 
|---|
| 36 | } | 
|---|
| 37 | servername = (char *)GBS_read_arb_tcp(name_server); | 
|---|
| 38 | if (!servername) exit (-1); | 
|---|
| 39 |  | 
|---|
| 40 | ang.link = (aisc_com *)aisc_open(servername, &ang.com,AISC_MAGIC_NUMBER); | 
|---|
| 41 | if (init_local_com_names()){ | 
|---|
| 42 | free(servername); | 
|---|
| 43 | return "Sorry I can't start the NAME SERVER"; | 
|---|
| 44 | } | 
|---|
| 45 | free(servername); | 
|---|
| 46 | return 0; | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | void disconnect_an(void) | 
|---|
| 50 | { | 
|---|
| 51 | if (ang.link) aisc_close(&ang.link); | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 | GB_ERROR pars_names(GBDATA *gb_main, int use_advice, int save_data) | 
|---|
| 56 | { | 
|---|
| 57 | GBDATA *gb_species_data; | 
|---|
| 58 | GBDATA *gb_species; | 
|---|
| 59 | GBDATA *gb_full_name; | 
|---|
| 60 | GBDATA *gb_name; | 
|---|
| 61 | GBDATA *gb_acc; | 
|---|
| 62 | long        hash; | 
|---|
| 63 | static      char *shrt; | 
|---|
| 64 |  | 
|---|
| 65 | char        *full_name; | 
|---|
| 66 | char        *name; | 
|---|
| 67 | char        *advice; | 
|---|
| 68 | char        *acc; | 
|---|
| 69 |  | 
|---|
| 70 | GB_ERROR err; | 
|---|
| 71 | GB_ERROR err2; | 
|---|
| 72 | char        buffer[256]; | 
|---|
| 73 |  | 
|---|
| 74 | err = connect_2_an(gb_main); | 
|---|
| 75 | if (err) return err; | 
|---|
| 76 |  | 
|---|
| 77 | err = GBT_begin_rename_session(gb_main,1); | 
|---|
| 78 | if (err) return err; | 
|---|
| 79 |  | 
|---|
| 80 |  | 
|---|
| 81 | gb_species_data = GB_search(gb_main,"species_data",GB_CREATE_CONTAINER); | 
|---|
| 82 |  | 
|---|
| 83 | hash = GBS_create_hash(1024); | 
|---|
| 84 | err2 = 0; | 
|---|
| 85 |  | 
|---|
| 86 | if (aisc_nput(ang.link, AN_LOCAL, ang.locs, | 
|---|
| 87 | LOCAL_USEADVICE,              use_advice, | 
|---|
| 88 | 0)){ | 
|---|
| 89 | err = "Connection Problems with the NAME_SERVER"; | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | for (       gb_species = GBT_first_species_rel_species_data(gb_species_data); | 
|---|
| 93 | gb_species&&!err; | 
|---|
| 94 | gb_species = GBT_next_species(gb_species)){ | 
|---|
| 95 | gb_full_name = GB_find(gb_species,"full_name",0,down_level); | 
|---|
| 96 | gb_name = GB_find(gb_species,"name",0,down_level); | 
|---|
| 97 | gb_acc = GB_find(gb_species,"acc",0,down_level); | 
|---|
| 98 |  | 
|---|
| 99 | if (gb_acc)     acc = GB_read_string(gb_acc); | 
|---|
| 100 | else            acc = strdup(""); | 
|---|
| 101 | if (gb_full_name) full_name = GB_read_string(gb_full_name); | 
|---|
| 102 | else              full_name = strdup(""); | 
|---|
| 103 | name = GB_read_string(gb_name); | 
|---|
| 104 | if (strlen(acc) + strlen(full_name) ) { | 
|---|
| 105 | if (aisc_nput(ang.link, AN_LOCAL, ang.locs, | 
|---|
| 106 | LOCAL_FULL_NAME,      full_name, | 
|---|
| 107 | LOCAL_ACCESSION,      acc, | 
|---|
| 108 | LOCAL_ADVICE,         name, | 
|---|
| 109 | 0)){ | 
|---|
| 110 | err = "Connection Problems with the NAME_SERVER"; | 
|---|
| 111 | } | 
|---|
| 112 | if (aisc_get(ang.link, AN_LOCAL, ang.locs, | 
|---|
| 113 | LOCAL_GET_SHORT,       &shrt, | 
|---|
| 114 | 0)){ | 
|---|
| 115 | err = "Connection Problems with the NAME_SERVER"; | 
|---|
| 116 | } | 
|---|
| 117 | }else{ | 
|---|
| 118 | shrt = strdup(name); | 
|---|
| 119 | } | 
|---|
| 120 | if (!err) { | 
|---|
| 121 | if (GBS_read_hash(hash,shrt)) { | 
|---|
| 122 | char *newshrt; | 
|---|
| 123 | int i; | 
|---|
| 124 | newshrt = (char *)calloc(sizeof(char),strlen(shrt)+10); | 
|---|
| 125 | for (i= 1 ; ; i++) { | 
|---|
| 126 | sprintf(newshrt,"%s.%i",shrt,i); | 
|---|
| 127 | if (!GBS_read_hash(hash,newshrt))break; | 
|---|
| 128 | } | 
|---|
| 129 | err2 = "There are duplicated entries!!.\nThe duplicated entries contain a '.' character !!!"; | 
|---|
| 130 | free(shrt); shrt = newshrt; | 
|---|
| 131 | } | 
|---|
| 132 | GBS_incr_hash(hash,shrt); | 
|---|
| 133 | err = GBT_rename_species(name,shrt); | 
|---|
| 134 | } | 
|---|
| 135 | if (name)       free(name);     name = 0; | 
|---|
| 136 | if (acc)        free(acc);      acc = 0; | 
|---|
| 137 | if (full_name)  free(full_name);full_name = 0; | 
|---|
| 138 | if (shrt)       free(shrt);     shrt = 0; | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 |  | 
|---|
| 142 | GBS_free_hash(hash); | 
|---|
| 143 | hash = 0; | 
|---|
| 144 | if (err) { | 
|---|
| 145 | GBT_abort_rename_session(); | 
|---|
| 146 | return err; | 
|---|
| 147 | }else{ | 
|---|
| 148 | //              if (save_data) { | 
|---|
| 149 | //                      if (aisc_put(ang.link, AN_MAIN, ang.com, | 
|---|
| 150 | //                              MAIN_SAVEALL,   0,0)){ | 
|---|
| 151 | //                              err = "Nameserver cannot save the data"; | 
|---|
| 152 | //                      } | 
|---|
| 153 | //              } | 
|---|
| 154 | GBT_commit_rename_session(0); | 
|---|
| 155 | } | 
|---|
| 156 | disconnect_an(); | 
|---|
| 157 | return err2; | 
|---|
| 158 | } | 
|---|