From 5f3c2ba6f78eacf129a6e12e1de9c65e350ab7eb Mon Sep 17 00:00:00 2001 From: hackbard Date: Fri, 12 Sep 2008 14:58:04 +0200 Subject: [PATCH] first simple atom match code --- atom_match.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 atom_match.c diff --git a/atom_match.c b/atom_match.c new file mode 100644 index 0000000..7eb5556 --- /dev/null +++ b/atom_match.c @@ -0,0 +1,228 @@ +/* + * atom_match.c - match atoms and process + * + * author: frank.zirkelbach@physik.uni-augsburg.de + * + */ + +#define _GNU_SOURCE +#include + +#include "moldyn.h" + +#define PSE_NAME +#define PSE_COL +#include "pse.h" +#undef PSE_NAME +#undef PSE_COL + +#define ME "[atom match]" + +#define LAND 0 +#define LOR 1 + +#define SELECT 1 +#define UNSELECT 0 + +#define S_COL_NO_OVERRIDE 0 +#define S_COL_NONE 1 +#define S_COL_BLUE 2 +#define S_COL_RED 3 +#define S_COL_BLACK 4 + +/* rule types */ +#define RT_ELEMENT 0 + +typedef int t_element; + +typedef struct s_rule { + u8 type; + u8 logic_op; + void *params; +} t_rule; + +typedef struct s_am { + int count; + t_rule rule[32]; + char infile[128]; +} t_am; + +int parse_rule(t_am *am,char *line) { + + int wcnt; + char *wptr; + char word[16][64]; + + t_element *element; + + wcnt=0; + while(1) { + if(wcnt) + wptr=strtok(NULL," "); + else + wptr=strtok(line," "); + if(wptr==NULL) + break; + strncpy(word[wcnt],wptr,64); + wcnt+=1; + } + + switch(word[0][0]) { + case 'e': + am->rule[am->count].params=malloc(sizeof(t_element)); + element=am->rule[am->count].params; + if(element==NULL) { + printf("%s malloc (element).\n",ME); + return -1; + } + *element=atoi(word[1]); + break; + /* + case '': + break; + case '': + break; + */ + default: + return -1; + } + + return 0; +} + +int parse_argv(int argc,char **argv,t_am *am) { + + int i; + int ret; + + memset(am,0,sizeof(t_am)); + ret=0; + + for(i=1;iinfile,argv[++i],128); + break; + case 'a': + // and rule + am->rule[am->count].logic_op=LAND; + ret=parse_rule(am,argv[++i]); + am->count+=1; + break; + case 'o': + // or rule + am->rule[am->count].logic_op=LOR; + ret=parse_rule(am,argv[++i]); + am->count+=1; + break; + case 'p': + // how to process data + break; + default: + printf("%s unknown switch: %s\n", + ME,argv[i]); + return -1; + + } + } + else { + printf("%s unknown argument: %s\n",ME,argv[i]); + return -1; + } + } + + return ret; +} + +int main(int argc,char **argv) { + + t_am am; + t_moldyn moldyn; + u8 *sel_atom; + u8 *sel_color; + int i,j,acnt; + t_atom *atom; + + t_element *e; + + memset(&moldyn,0,sizeof(t_moldyn)); + + if(parse_argv(argc,argv,&am)<0) { + printf("%s aborted (bad args).\n",ME); + return -1; + } + + if(moldyn_read_save_file(&moldyn,am.infile)<0) { + printf("%s aborted (bad infile).\n",ME); + return -1; + } + + acnt=moldyn.count; + atom=moldyn.atom; + + link_cell_init(&moldyn,VERBOSE); + + /* alloc select status and color memory */ + sel_atom=malloc(acnt*sizeof(u8)); + if(sel_atom==NULL) { + printf("%s aborted (malloc failed).\n",ME); + return -1; + } + sel_color=malloc(acnt*sizeof(u8)); + if(sel_color==NULL) { + printf("%s aborted (malloc failed).\n",ME); + return -1; + } + + /* apply rules */ + for(i=0;i skipped.\n", + ME,am.rule[i].type); + break; + } + } + + /* process data */ + for(i=0;i