#include #include #include "dt_smiles.h" #define TRUE 1 #define FALSE 0 #define MX_SMILES 1000 /*============================================================================ * sayerrors() -- dump errors in message queue to stderr */ static void sayerrors(void) { dt_Handle sob, sos = dt_errors(DX_ERR_ERROR); dt_String str; dt_Integer lens; while (NULL_OB != (sob = dt_next(sos))) { str = dt_stringvalue(&lens, sob); if (str) fprintf(stderr, "%.*s\n", lens, str); dt_dealloc(sob); } dt_dealloc(sos); dt_errorclear(); } /*============================================================================ * main.c -- test du_chiralify(), get SMILES, show chiral isomers */ main(int ac, char *av[]) { dt_Handle mol, sos, sob; char *str, smi[MX_SMILES]; int lens, n; /*** Get SMILES from user. ***/ if (1 < ac) { fprintf(stderr, "%s -- exhaustive isomeric SMILES generation\n" "This program demonstrates the function du_chiralify().\n" "Enter a SMILES, see unspecified chiralities enumerated.\n" "No program options or arguments are used.\n" "Contributed by Dave Weininger, Daylight CIS, Mar 1997\n", *av); exit(1); } /*** Get SMILES from user. ***/ while (fgets(smi,1000,stdin)) { smi[strlen(smi)-1]='\0'; if (NULL_OB != (mol = dt_smilin(strlen(smi), smi))) { /*** Get sequence of SMILES of chiral isomers. ***/ sos = du_chiralify(mol); /*** Print isomers as numbered sequence of strings. ***/ if (NULL_OB == sos) { printf("No (additional) chiral isomers detected.\n"); } else { dt_reset(sos); for (n = 0; NULL_OB != (sob = dt_next(sos)); n++) { str = dt_stringvalue(&lens, sob); printf("%3d %.*s\n", n + 1, lens, str); dt_dealloc(sob); } dt_dealloc(sos); } } /*** Show error queue each time through. ***/ sayerrors(); } printf("\n%s exits.\n", *av); }