#include #include #include #include #include "xconf.h" #include "components.h" PUBLIC COMPONENT::COMPONENT( const char *manuf_id, const char *model_id, XCONFIG *_xconfig, NOTICE *_notice, ACTION *_action) : PAIRES (manuf_id,model_id) { xconfig = _xconfig; notice = _notice; action = _action; } PUBLIC COMPONENTS::COMPONENTS() { max_component = 0; nb_component = 0; tb_component = NULL; max_xconfig = 0; nb_xconfig = 0; tb_xconfig = NULL; max_notice = 0; nb_notice = 0; tb_notice = NULL; } PUBLIC VIRTUAL COMPONENTS::~COMPONENTS() { for (int i=0; iparse (buf,fname,noline); }else if (doing_notice){ notice->add (pt); }else if (doing_action){ action->add (pt); }else{ // This is a model ID add (new COMPONENT (manuf,pt,xconfig,notice,action)); } } } fclose (fin); } return ret; } static int cmp (const void **pp1, const char **pp2) { COMPONENT *p1 = (COMPONENT *)(*pp1); COMPONENT *p2 = (COMPONENT *)(*pp2); int ret = strcmp(p1->keyw,p2->keyw); if (ret == 0) ret = strcmp(p1->arg,p2->arg); return ret; } /* Sort all COMPONENT by manuf_id and model_id. */ PUBLIC void COMPONENTS::sort () { qsort (tb_component,nb_component,sizeof(COMPONENT*),cmp); } /* Print all COMPONENTS with the same format as input, mostly to debug */ PUBLIC void COMPONENTS::print (FILE *fout) { XCONFIG *xconfig=NULL; NOTICE *notice=NULL; ACTION *action=NULL; char manuf[100]; manuf[0] = '\0'; for (int i=0; ikeyw,manuf)!=0){ strcpy (manuf,comp->keyw); fprintf (fout,"-%s\n",manuf); } if (comp->xconfig != xconfig){ xconfig = comp->xconfig; fprintf (fout,"\t@\n"); xconfig->print (fout,2); fprintf (fout,"\t@\n"); } if (comp->notice != notice){ notice = comp->notice; fprintf (fout,"\t!\n"); notice->print (fout,2); fprintf (fout,"\t!\n"); } if (comp->action != action){ action = comp->action; fprintf (fout,"\t$\n"); action->print (fout,2); fprintf (fout,"\t$\n"); } fprintf (fout,"\t%s\n",comp->arg); } } /* Encode de component ids in a string table so it fit the dialog system. tb[optnum*2] = manuf_id; tb[optnum*2+1] = model_id; Return the number of components placed in tbopt2, not the number of strings. */ PUBLIC int COMPONENTS::setmenu ( char *tbopt2[]) { int nb = 0; char *manuf = NULL; for (int i=0; ikeyw,manuf)!=0){ manuf = comp->keyw; tbopt2[nb++] = manuf; }else{ tbopt2[nb++] = " "; } tbopt2[nb++] = comp->arg; } tbopt2[nb] = NULL; return nb_component; } PUBLIC COMPONENT *COMPONENTS::item(int no) { COMPONENT *ret = NULL; if (no >= 0 && no < nb_component) ret = tb_component[no]; return ret; } #ifdef TEST int main (int argc, char *argv[]) { COMPONENTS comp; comp.read ("adaptors.xconf"); comp.sort (); comp.print (stdout); return 0; } #endif