static struct xmllog_entry * parse_logentry(struct xml_tree *node) { struct xmllog_entry *pe = (struct xmllog_entry*) node; struct xml_attn *pa; struct xml_tree *p; int v, n; if (!is_empty_text(node)) return 0; pe->revision = -1; for (pa = pe->b.first; pa; pa = pa->next) { if (pa->tag == A_REVISION) { if (sscanf(pa->text, "%d%n", &v, &n) != 1 || pa->text[n]) return attr_err(pa, "cannot parse attribute value"); if (v < 0) return attr_err(pa, "invalid attribute value"); pe->revision = v; } else { return attr_err(pa, "unexpected attribute"); } } if (pe->revision < 0) return elem_err(node, "attribute revision is undefined"); for (p = pe->b.first_down; p; p = p->right) { switch (p->tag) { case T_AUTHOR: if (p->first) return elem_err(p, "attributes are not allowed"); if (p->first_down) return elem_err(p, "nested elements are not allowed"); if (pe->author) return elem_err(p, "author already defined"); pe->author = p->text; p->text = 0; break; case T_DATE: if (p->first) return elem_err(p, "attributes are not allowed"); if (p->first_down) return elem_err(p, "nested elements are not allowed"); if (pe->date.year) return elem_err(p, "date already defined"); if (parse_date(p, p->text, &pe->date) < 0) return 0; break; case T_PATHS: if (!parse_paths(p, pe)) return 0; break; case T_MSG: if (p->first) return elem_err(p, "attributes are not allowed"); if (p->first_down) return elem_err(p, "nested elements are not allowed"); if (pe->msg) return elem_err(p, "msg already defined"); pe->msg = p->text; p->text = 0; break; default: return elem_err(p, "unexpected element"); } } if (!pe->author) return elem_err(node, "author is not defined"); return pe; }
void insert_line( text_t *txt, int index, char *new_line ) { if ( is_empty_text( txt ) ) { insert_into_empty_text( txt, index, new_line ); } }
static void * parse_paths(struct xml_tree *node, struct xmllog_entry *pe) { struct xml_tree *p; struct xmllog_path *pp; struct xml_attn *a; int x, n; if (!node) return NULL; if (node->tag != T_PATHS) abort(); if (node->first) return elem_err(node, "attributes are not allowed"); if (!is_empty_text(node)) return 0; for (p = node->first_down; p; p = p->right) { if (p->tag != T_PATH) return elem_err(p, "unexpected element"); pp = (struct xmllog_path*) p; for (a = p->first; a; a = a->next) { switch (a->tag) { case A_ACTION: if (!a->text || strlen(a->text) != 1) return attr_err(a, "invalid attribute value"); switch (a->text[0]) { case 'D': case 'A': case 'M': break; default: return attr_err(a, "invalid attribute value"); } pp->action = a->text[0]; break; case A_COPYFROM_PATH: pp->copyfrom_path = a->text; a->text = 0; break; case A_COPYFROM_REV: if (sscanf(a->text, "%d%n", &x, &n) != 1 || a->text[n]) return attr_err(a, "invalid attribute value"); if (x < 1) return attr_err(a, "invalid attribute value"); pp->copyfrom_rev = x; break; case A_KIND: break; default: return attr_err(a, "unexpected attribute"); } } if (!pp->action) elem_err(p, "action attribute expected"); pp->path = p->text; p->text = 0; XEXPAND2(pe->paths); pe->paths.v[pe->paths.u] = pp; pe->paths.u++; } return node; }
/** * User press Enter key on search entry */ void on_search_entry_activate(GtkEntry *entry, gpointer data) { const gchar *text; if (gtk_entry_get_text_length(entry) == 0) return ; text = gtk_entry_get_text(entry); if (is_empty_text(text)) return ; weather_window_hide_result_tv(WEATHER_WINDOW(main_window)); weather_window_search(WEATHER_WINDOW(main_window), text); }
static struct xmllog_root * parse_xmllog(struct xml_tree *root) { struct xmllog_root *xmlroot; struct xml_tree *p; struct xmllog_entry *xmle; if (root->tag != T_LOG) return elem_err(root, "<log> element expected"); if (!is_empty_text(root)) return 0; if (root->first) elem_err(root, "attributes not allowed for <log>"); xmlroot = (struct xmllog_root*) root; for (p = root->first_down; p; p = p->right) { if (p->tag != T_LOGENTRY) return elem_err(p, "<logentry> element expected"); if (!(xmle = parse_logentry(p))) return 0; XEXPAND2(xmlroot->e); xmlroot->e.v[xmlroot->e.u++] = xmle; } return xmlroot; }
/* Main program. */ void main(int argc, const char* argv[]) { FILE* sdfile = NULL; FILE* outfile = NULL; char* buffer = NULL; long index=0, nerr=0, nboom_rtrip=0, nmismatch_rtrip=0; IXA_BOOL key; IXA_BOOL generate_auxinfo = IXA_TRUE; IXA_BOOL verbose = IXA_FALSE; const char* inchi; const char* auxinfo; const char* inchikey; IXA_BOOL round_trip; char options[256]; char* saved_inchi = NULL; IXA_STATUS_HANDLE status = NULL; IXA_MOL_HANDLE molecule = NULL; IXA_INCHIBUILDER_HANDLE inchi_builder = NULL; IXA_INCHIKEYBUILDER_HANDLE key_builder = NULL; #if defined(_WIN32) const char *platform="Windows"; #else const char *platform="Linux"; #endif char banner[255]; sprintf( banner, "%s\n%-s Build of %-s %-s%s", APP_DESCRIPTION, platform, __DATE__, __TIME__, RELEASE_IS_FINAL?"":" *** pre-release, for evaluation only ***"); fprintf( stderr, "%-s\n", banner); #ifdef IXA_USES_NON_EX_CORE_API fprintf( stderr, "Note: IXA API in current build uses non-extended core API calls\n"); #else fprintf( stderr, "Note: IXA API in current build uses extended core API calls\n"); #endif if (argc < 3) { /* Not enough command line arguments have been provided. Output some help information, then exit. */ print_help(); return; } /* Open input and output files. */ sdfile = fopen(argv[1],"rb"); /* fopen_s(&sdfile, argv[1], "r"); */ if (!sdfile) { fprintf(stderr, "Failed to open \"%s\" for reading\n", argv[1]); goto cleanup; } outfile = fopen( argv[2], "w"); /* fopen_s(&outfile, argv[2], "w"); */ if (!outfile) { fprintf(stderr, "Failed to open \"%s\" for writing\n", argv[2]); goto cleanup; } /* Create status, molecule and InChI builder objects. */ status = IXA_STATUS_Create(); molecule = IXA_MOL_Create(status); if (!CheckStatus(status, index)) goto cleanup; inchi_builder = IXA_INCHIBUILDER_Create(status); if (!CheckStatus(status, index)) goto cleanup; /* Read any command line options that may have been given and set up the InChI builder accordingly. */ if (!ReadOptions(argc, argv, &key, &round_trip, &generate_auxinfo, &verbose, options, status, inchi_builder)) goto cleanup; /* If InChI keys have been requested, create an InChI key builder object. */ if (key) { key_builder = IXA_INCHIKEYBUILDER_Create(status); if (!CheckStatus(status, index)) goto cleanup; } /* Warning: in this demo, we just assume that molfile's size does not */ /* exceed some (large) MOLBUFSIZE; no further checks are performed. */ buffer = (char *) calloc( MOLBUFSIZE, sizeof(char) ); if ( !buffer ) { fprintf(stderr, "Out of memory\n"); goto cleanup; } /* Iterate the molecules in the input SD file and create an InChI for each one. */ index = 0; while ( get_next_molfile_as_text( sdfile, buffer, MOLBUFSIZE ) > 0 && !is_empty_text( buffer ) ) { /* Set up the molecule object with atoms and bonds to represent the data that has just been read from the input file. */ IXA_MOL_ReadMolfile(status, molecule, buffer); if (!CheckStatus(status,index+1)) { nerr++; goto endloop; } fprintf(outfile, "%-ld\t", index+1); /* Bind the molecule object to the InChI builder object. */ IXA_INCHIBUILDER_SetMolecule(status, inchi_builder, molecule); if (!CheckStatus(status,index+1)) { nerr++; goto endloop; } /* Retrieve the molecule's InChI and write it to the output file. */ inchi = IXA_INCHIBUILDER_GetInChI(status, inchi_builder); if (!CheckStatus(status,index+1)) { nerr++; goto endloop; } fprintf(outfile, "%s\t", inchi); if (generate_auxinfo) { /* AuxInfo has been requested. Retrieve the molecule's AuxInfo and write it to the output file. */ auxinfo = IXA_INCHIBUILDER_GetAuxInfo(status, inchi_builder); if (!CheckStatus(status,index+1)) { nerr++; goto endloop; } fprintf(outfile, "%s\t", auxinfo); } if (key_builder) { /* InChI keys have been requested. Retrieve the molecule's InChI key and write it to the output file. */ IXA_INCHIKEYBUILDER_SetInChI(status, key_builder, inchi); if (!CheckStatus(status,index+1)) { nerr++; goto endloop; } inchikey = IXA_INCHIKEYBUILDER_GetInChIKey(status, key_builder); if (!CheckStatus(status,index+1)) { nerr++; goto endloop; } fprintf(outfile, "InChIKey=%s\t", inchikey); } if (round_trip) { /* Round trip tests have been requested. Turn the InChI that has just been generated into a molecule and use that molecule as the basis for a new InChI. The two InChIs should be identical. */ saved_inchi = (char *) realloc(saved_inchi, strlen(inchi) + 1); strcpy(saved_inchi, inchi); IXA_MOL_ReadInChI(status, molecule, saved_inchi); if (!CheckStatus(status,index+1)) { fprintf(stderr, "\n!!! Round trip failed: could not read InChI : structure %-ld\n", index+1); { nboom_rtrip++; goto endloop; } } IXA_INCHIBUILDER_SetMolecule(status, inchi_builder, molecule); if (!CheckStatus(status,index+1)) { fprintf(stderr, "\n!!! Round trip failed: could not set IXA mol from read InChI string : structure %-ld\n", index+1); { nboom_rtrip++; goto endloop; } } /* strcpy(inchi,"NOTHING"); */ inchi = IXA_INCHIBUILDER_GetInChI(status, inchi_builder); if (!CheckStatus(status,index+1)) { fprintf(stderr, "\n!!! Round trip failed: could not generate InChI from IXA mol obtained from read InChI : structure %-ld\n", index+1); { nboom_rtrip++; goto endloop; } } if (strcmp(inchi, saved_inchi) != 0) { fprintf(stderr, "\n!!! Round trip failed : structure %-ld\n", index+1); fprintf(stderr, " OLD: %s\n", saved_inchi); fprintf(stderr, " NEW: %s", inchi); nmismatch_rtrip++; } else if ( verbose ) { fprintf(stderr, "\nRound trip OK : structure %-ld\n", index+1); fprintf(stderr, " OLD: %s\n", saved_inchi); fprintf(stderr, " NEW: %s", inchi); } } endloop: /* Every so often write a dot to stdout so the user knows that this program has not frozen. */ fprintf( outfile, "\n" ); if (index % 100 == 0) { fprintf(stderr, "."); } index++; fflush(NULL); } /* Main loop */ fprintf(stderr, "\n"); cleanup: fprintf(stderr, "\nFinished processing %-ld molecules.\nGeneration (struct->InChI) errors: %-ld", index, nerr); if (round_trip) { fprintf( stderr, "\nRound trip (struct->InChI->struct->InChI) problems: %-ld (%-ld failures, %-ld mismatches)", nboom_rtrip + nmismatch_rtrip, nboom_rtrip, nmismatch_rtrip); } fprintf(stderr, ".\n"); /* Release resources prior to program exit. */ if ( saved_inchi ) free(saved_inchi); if ( buffer ) free(buffer); if (sdfile) fclose(sdfile); if (outfile) fclose(outfile); IXA_INCHIKEYBUILDER_Destroy(NULL, key_builder); IXA_INCHIBUILDER_Destroy(NULL, inchi_builder); IXA_MOL_Destroy(NULL, molecule); IXA_STATUS_Destroy(status); }