Toolkit Tutorial: Advanced Programming


#include <stdio.h>
#define DX_API_PUBLIC
#include "dt_smiles.h"
#include "dt_progob.h"

int main ( int argc , char ** argv ) {
 
dt_Handle program , object , container ;
 
dt_Integer length ;
 
dt_String string ;
 
char * ptr , input [ 8192 ];

 
/* check for program */
 
if ( 1 == argc ) {
   
printf ( "Usage: %s <program talker>\n"
       
"Examples:\n"
       
"  printf \"O\\nOc1ccc(O)cc1\\n\" | %s fingertalk\n"
       
"  printf \"O\\nOc1ccc(O)cc1\\n\" | %s clogptalk\n"
       
"  printf \"Qwerty: Set PROPERTY POLAR_SURFACE_AREA \\n \\\n"
       
"          O\\nOc1ccc(O)cc1\\n\" | %s dayproptalk\n" ,
       
argv [ 0 ], argv [ 0 ], argv [ 0 ], argv [ 0 ]);
   
return 1 ;
 
}

 
/* create program object with a string object.  Use a
    sequence of string objects to pass arguments. */

 
object = dt_alloc_string ( strlen ( argv [ 1 ]), argv [ 1 ]);
 
program = dt_alloc_program ( object );
 
dt_dealloc ( object );

 
/* loop over input and truncate at new line */
 
while ( NULL != ( fgets ( input , 8192 , stdin ))) {
   
if ( NULL != ( ptr = strchr ( input , '\n' )))
     
* ptr = '\0' ;

   
/* put program input as a string or a sequence of strings */
   
object = dt_alloc_string ( strlen ( input ), input );
   
container = dt_converse ( program , object );
   
dt_dealloc ( object );

   
/* get program output as a sequence of strings */
   
object = dt_next ( container );
   
if ( NULL_OB != ( string = dt_stringvalue ( & length , object )))
     
printf ( "%.*s\n" , length , string );
   
dt_dealloc ( object );
   
dt_dealloc ( container );
 
}

 
return 0 ;
}