| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <memory.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include <arbdb.h> |
|---|
| 6 | #include <arbdbt.h> |
|---|
| 7 | #include <aw_root.hxx> |
|---|
| 8 | #include <aw_device.hxx> |
|---|
| 9 | #include <aw_window.hxx> |
|---|
| 10 | #include <aw_awars.hxx> |
|---|
| 11 | #include <awt.hxx> |
|---|
| 12 | |
|---|
| 13 | #ifndef ARB_ASSERT_H |
|---|
| 14 | #include <arb_assert.h> |
|---|
| 15 | #endif |
|---|
| 16 | #define awtc_assert(bed) arb_assert(bed) |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #define AWAR_PARSER "tmp/submission/parser" |
|---|
| 20 | #define AWAR_PARSED "tmp/submission/parsed" |
|---|
| 21 | |
|---|
| 22 | void AWTC_create_submission_variables(AW_root *root,AW_default db1) |
|---|
| 23 | { |
|---|
| 24 | root->awar_string( "submission/source", "" , db1); |
|---|
| 25 | root->awar_string( AWAR_PARSER, "press READ INFO" , db1); |
|---|
| 26 | root->awar_string( AWAR_PARSED, "" , db1); |
|---|
| 27 | root->awar_string( "submission/file", "" , db1); |
|---|
| 28 | root->awar_string( "submission/privat", "$(ADDRESS, db1)=TUM Munich:\n" ); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | static void ed_calltexe_event(AW_window *aww,char *varname) |
|---|
| 32 | { |
|---|
| 33 | AW_root *aw_root = aww->get_root(); |
|---|
| 34 | char *file; |
|---|
| 35 | file = aw_root->awar(varname)->read_string(); |
|---|
| 36 | AWT_edit(file); |
|---|
| 37 | free(file); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | static AW_window *create_calltexe_window(AW_root *root, char *varname) |
|---|
| 41 | { |
|---|
| 42 | AWUSE(root); |
|---|
| 43 | |
|---|
| 44 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 45 | { |
|---|
| 46 | char *var_id = GBS_string_2_key(varname); |
|---|
| 47 | char *window_id = GBS_global_string_copy("SUBM_TEXTEDIT_%s", var_id); |
|---|
| 48 | aws->init( root, window_id, "START TEXT EDITOR"); |
|---|
| 49 | free(window_id); |
|---|
| 50 | free(var_id); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | aws->load_xfig("calltexe.fig"); |
|---|
| 54 | aws->label_length( 18 ); |
|---|
| 55 | aws->button_length( 8 ); |
|---|
| 56 | |
|---|
| 57 | aws->at( "close" ); |
|---|
| 58 | aws->callback ( (AW_CB0)AW_POPDOWN ); |
|---|
| 59 | aws->create_button( "CLOSE", "CLOSE", "O" ); |
|---|
| 60 | |
|---|
| 61 | aws->at("file"); |
|---|
| 62 | aws->create_input_field(varname,34); |
|---|
| 63 | |
|---|
| 64 | aws->at("edit"); |
|---|
| 65 | aws->callback( (AW_CB1)ed_calltexe_event,(AW_CL)varname); |
|---|
| 66 | aws->create_button( "EDIT", "EDIT", "E" ); |
|---|
| 67 | |
|---|
| 68 | return (AW_window *)aws; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | #if 0 |
|---|
| 72 | static long ed_submit_info_event_sequence(void *strstruct,char *alignment,long modu) |
|---|
| 73 | { |
|---|
| 74 | int i; |
|---|
| 75 | char buffer[256]; |
|---|
| 76 | int size = strlen(alignment); |
|---|
| 77 | int c; |
|---|
| 78 | long seq_len = 0; |
|---|
| 79 | for (seq_len=i=0;i<size;i++) { |
|---|
| 80 | c = alignment[i]; |
|---|
| 81 | if (c == '.') continue; |
|---|
| 82 | if (c == '-') continue; |
|---|
| 83 | |
|---|
| 84 | if (c==':') c = ';'; |
|---|
| 85 | if (c=='=') c = '-'; |
|---|
| 86 | if ( !(seq_len%modu) ) { |
|---|
| 87 | sprintf(buffer,"\n%8li ",seq_len+1); |
|---|
| 88 | GBS_strcat(strstruct,buffer); |
|---|
| 89 | } |
|---|
| 90 | if ( !(seq_len%10) ) GBS_strcat(strstruct," "); |
|---|
| 91 | seq_len++; |
|---|
| 92 | GBS_chrcat(strstruct,c); |
|---|
| 93 | } |
|---|
| 94 | return seq_len; |
|---|
| 95 | } |
|---|
| 96 | #endif |
|---|
| 97 | |
|---|
| 98 | static void ed_submit_info_event_rm(char *string) |
|---|
| 99 | { |
|---|
| 100 | char *p = string; |
|---|
| 101 | int c; |
|---|
| 102 | while ((c=*p)!= 0 ) { |
|---|
| 103 | if (c==':') *p = ';'; |
|---|
| 104 | if (c=='=') *p = '-'; |
|---|
| 105 | p++; |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | extern GBDATA *GLOBAL_gb_main; |
|---|
| 110 | |
|---|
| 111 | static void ed_submit_info_event(AW_window *aww) { |
|---|
| 112 | AW_root *aw_root = aww->get_root(); |
|---|
| 113 | GB_transaction dummy(GLOBAL_gb_main); |
|---|
| 114 | char *species_name = aw_root->awar(AWAR_SPECIES_NAME)->read_string(); |
|---|
| 115 | GBDATA *gb_species = GBT_find_species(GLOBAL_gb_main,species_name); |
|---|
| 116 | GBS_strstruct *strstruct = GBS_stropen(1000); |
|---|
| 117 | |
|---|
| 118 | if (gb_species) { |
|---|
| 119 | for (GBDATA *gb_entry = GB_child(gb_species); gb_entry; gb_entry = GB_nextChild(gb_entry)) { |
|---|
| 120 | int type = GB_read_type(gb_entry); |
|---|
| 121 | switch (type) { |
|---|
| 122 | case GB_STRING: |
|---|
| 123 | case GB_INT: |
|---|
| 124 | case GB_BITS: |
|---|
| 125 | case GB_FLOAT: { |
|---|
| 126 | char *key = GB_read_key(gb_entry); |
|---|
| 127 | |
|---|
| 128 | GBS_strcat(strstruct,"$("); |
|---|
| 129 | GBS_strcat(strstruct,key); |
|---|
| 130 | GBS_strcat(strstruct,")="); |
|---|
| 131 | free(key); |
|---|
| 132 | |
|---|
| 133 | key = GB_read_as_string(gb_entry); |
|---|
| 134 | ed_submit_info_event_rm(key); |
|---|
| 135 | GBS_strcat(strstruct,key); |
|---|
| 136 | free(key); |
|---|
| 137 | |
|---|
| 138 | GBS_strcat(strstruct,":\n"); |
|---|
| 139 | break; |
|---|
| 140 | } |
|---|
| 141 | default: |
|---|
| 142 | break; |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | char *seq_info = GBS_string_eval(" ","*=" |
|---|
| 146 | "$(SEQ_LEN)\\=*(|sequence|len(.-))\\:\n" |
|---|
| 147 | "$(SEQ_A)\\=*(|sequence|count(aA))\\:\n" |
|---|
| 148 | "$(SEQ_C)\\=*(|sequence|count(cC))\\:\n" |
|---|
| 149 | "$(SEQ_G)\\=*(|sequence|count(gG))\\:\n" |
|---|
| 150 | "$(SEQ_T)\\=*(|sequence|count(tT))\\:\n" |
|---|
| 151 | "$(SEQ_U)\\=*(|sequence|count(uU))\\:\n" |
|---|
| 152 | "$(SEQUENCE)\\=*(|sequence|remove(.-)|format_sequence(firsttab\\=12;tab\\=12;width\\=60;numleft;gap\\=10))\\:\n" |
|---|
| 153 | ,gb_species); |
|---|
| 154 | if (seq_info) { |
|---|
| 155 | GBS_strcat(strstruct, seq_info); |
|---|
| 156 | free(seq_info); |
|---|
| 157 | } |
|---|
| 158 | else { |
|---|
| 159 | aw_message(GB_await_error()); |
|---|
| 160 | } |
|---|
| 161 | }else{ |
|---|
| 162 | GBS_strcat(strstruct,"Species not found"); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | char *parser = GBS_strclose(strstruct); |
|---|
| 166 | aw_root->awar(AWAR_PARSER)->write_string(parser); |
|---|
| 167 | |
|---|
| 168 | free(parser); |
|---|
| 169 | free(species_name); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | static void ed_save_var_to_file(AW_window *aww,char *data_var, char *file_var) |
|---|
| 173 | { |
|---|
| 174 | AW_root *aw_root = aww->get_root(); |
|---|
| 175 | char * data = aw_root->awar(data_var)->read_string(); |
|---|
| 176 | char *file_name = aw_root->awar(file_var)->read_string(); |
|---|
| 177 | FILE *out = fopen(file_name,"w"); |
|---|
| 178 | if (out) fprintf(out,"%s",data); |
|---|
| 179 | fclose(out); |
|---|
| 180 | free(file_name); |
|---|
| 181 | free(data); |
|---|
| 182 | } |
|---|
| 183 | static void ed_submit_parse_event(AW_window *aww) |
|---|
| 184 | { |
|---|
| 185 | AW_root *aw_root = aww->get_root(); |
|---|
| 186 | char *parser = aw_root->awar(AWAR_PARSER)->read_string(); |
|---|
| 187 | char *dest; |
|---|
| 188 | char *dest2; |
|---|
| 189 | char *privat; |
|---|
| 190 | char *p,*d; |
|---|
| 191 | int c; |
|---|
| 192 | |
|---|
| 193 | for (d = p = parser; *p; p++) { |
|---|
| 194 | if ((c=*p)==':') { |
|---|
| 195 | if (p[1] == '\n') p++; // skip newline |
|---|
| 196 | } |
|---|
| 197 | *(d++) = c; |
|---|
| 198 | } |
|---|
| 199 | *d = 0; |
|---|
| 200 | char *sub_file = aw_root->awar("submission/source")->read_string(); |
|---|
| 201 | char *source = GB_read_file(sub_file); |
|---|
| 202 | if (source) { |
|---|
| 203 | dest = GBS_string_eval(source,parser,0); |
|---|
| 204 | if (!dest) dest = strdup(GB_await_error()); |
|---|
| 205 | } |
|---|
| 206 | else { |
|---|
| 207 | dest = strdup("submission form not found"); |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | awtc_assert(dest); // should contain partly filled form or error message |
|---|
| 211 | |
|---|
| 212 | privat = aw_root->awar("submission/privat")->read_string(); |
|---|
| 213 | for (d = p = privat; *p; p++) { |
|---|
| 214 | if ((c=*p)==':') { |
|---|
| 215 | if (p[1] == '\n') p++; // skip newline |
|---|
| 216 | } |
|---|
| 217 | *(d++) = c; |
|---|
| 218 | } |
|---|
| 219 | *d = 0; |
|---|
| 220 | |
|---|
| 221 | dest2 = GBS_string_eval(dest,privat,0); |
|---|
| 222 | if (!dest2) dest2 = strdup(GB_await_error()); |
|---|
| 223 | |
|---|
| 224 | aw_root->awar(AWAR_PARSED)->write_string(dest2); |
|---|
| 225 | |
|---|
| 226 | free(dest); |
|---|
| 227 | free(dest2); |
|---|
| 228 | free(privat); |
|---|
| 229 | free(source); |
|---|
| 230 | free (sub_file); |
|---|
| 231 | free(parser); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | static void ed_submit_gen_event(AW_window *aww) |
|---|
| 235 | { |
|---|
| 236 | AW_root *aw_root = aww->get_root(); |
|---|
| 237 | char buffer[256]; |
|---|
| 238 | char *name = aw_root->awar(AWAR_SPECIES_NAME)->read_string(); |
|---|
| 239 | sprintf(buffer,"%s.submit",name); |
|---|
| 240 | free(name); |
|---|
| 241 | aw_root->awar("submission/file")->write_string(buffer); |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | AW_window *AWTC_create_submission_window(AW_root *root) |
|---|
| 246 | { |
|---|
| 247 | AWUSE(root); |
|---|
| 248 | |
|---|
| 249 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 250 | aws->init( root, "SUBMISSION", "SUBMISSION"); |
|---|
| 251 | |
|---|
| 252 | aws->load_xfig("submiss.fig"); |
|---|
| 253 | aws->label_length( 18 ); |
|---|
| 254 | aws->button_length( 8 ); |
|---|
| 255 | |
|---|
| 256 | aws->at( "close" ); |
|---|
| 257 | aws->callback ( (AW_CB0)AW_POPDOWN ); |
|---|
| 258 | aws->create_button( "CLOSE", "CLOSE", "O" ); |
|---|
| 259 | |
|---|
| 260 | aws->callback( AW_POPUP_HELP,(AW_CL)"submission.hlp"); |
|---|
| 261 | aws->at("help"); |
|---|
| 262 | aws->create_button("HELP", "HELP","H"); |
|---|
| 263 | |
|---|
| 264 | aws->button_length( 15 ); |
|---|
| 265 | |
|---|
| 266 | aws->at("privat"); |
|---|
| 267 | aws->create_text_field("submission/privat",80,5); |
|---|
| 268 | |
|---|
| 269 | aws->at( "parsed_info" ); |
|---|
| 270 | aws->create_text_field( AWAR_PARSER, 80,6 ); |
|---|
| 271 | |
|---|
| 272 | aws->at( "parsed" ); |
|---|
| 273 | aws->create_text_field( AWAR_PARSED, 80,13 ); |
|---|
| 274 | |
|---|
| 275 | aws->at( "species" ); |
|---|
| 276 | aws->label( "Species Name:"); |
|---|
| 277 | aws->create_input_field( AWAR_SPECIES_NAME, 12 ); |
|---|
| 278 | |
|---|
| 279 | aws->at( "submission" ); |
|---|
| 280 | char **submits = GBS_read_dir(GB_path_in_ARBLIB("submit", NULL), NULL); |
|---|
| 281 | if (submits) { |
|---|
| 282 | aws->create_option_menu( "submission/source", "Select a Form", "s" ); |
|---|
| 283 | for (char **submit = submits; *submit; submit++){ |
|---|
| 284 | aws->insert_option(*submit,"",*submit); |
|---|
| 285 | } |
|---|
| 286 | aws->insert_default_option("default","d","default"); |
|---|
| 287 | aws->update_option_menu(); |
|---|
| 288 | |
|---|
| 289 | GBT_free_names(submits); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | aws->at("gen"); |
|---|
| 293 | aws->label("Gen File Name"); |
|---|
| 294 | aws->callback(ed_submit_gen_event); |
|---|
| 295 | aws->create_button("GEN_FILE_NAME", "CREATE NAME","C"); |
|---|
| 296 | |
|---|
| 297 | aws->at( "file" ); |
|---|
| 298 | aws->label( "or enter"); |
|---|
| 299 | aws->create_input_field( "submission/file", 30 ); |
|---|
| 300 | |
|---|
| 301 | aws->at( "info" ); |
|---|
| 302 | aws->callback( ed_submit_info_event); |
|---|
| 303 | aws->create_button("READ_INFO", "READ INFO","R"); |
|---|
| 304 | |
|---|
| 305 | aws->at( "parse" ); |
|---|
| 306 | aws->callback((AW_CB0)ed_submit_parse_event); |
|---|
| 307 | aws->create_button("FILL_OUT_FORM", "FILL THE FORM","F"); |
|---|
| 308 | |
|---|
| 309 | aws->at( "write" ); |
|---|
| 310 | aws->callback( (AW_CB)ed_save_var_to_file,(AW_CL)AWAR_PARSED,(AW_CL)"submission/file"); |
|---|
| 311 | aws->create_button("SAVE", "SAVE TO FILE","S"); |
|---|
| 312 | |
|---|
| 313 | aws->button_length( 20 ); |
|---|
| 314 | aws->at( "edit" ); |
|---|
| 315 | aws->callback(AW_POPUP,(AW_CL)create_calltexe_window,(AW_CL)"submission/source"); |
|---|
| 316 | aws->create_button("EDIT_FORM", "EDIT FORM","R"); |
|---|
| 317 | |
|---|
| 318 | aws->at( "editresult" ); |
|---|
| 319 | aws->callback(AW_POPUP,(AW_CL)create_calltexe_window,(AW_CL)"submission/file"); |
|---|
| 320 | aws->create_button("EDIT_SAVED", "EDIT SAVED","S"); |
|---|
| 321 | |
|---|
| 322 | aws->at("privatlabel"); |
|---|
| 323 | aws->create_button(0,"Your private data"); |
|---|
| 324 | |
|---|
| 325 | return (AW_window *)aws; |
|---|
| 326 | } |
|---|