/* Outils pour tester keycontrol */ #include #include #include #include #include #include #include using namespace std; int main (int argc, char *argv[]) { glocal int ret = -1; glocal const char *host = "localhost"; glocal const char *port = "8190"; glocal bool lines = false; glocal SSTRINGS args; glocal const char *resfile = NULL; glocal.ret = (argc,argv); setproginfo ("keytest",VERSION,"Envoie des commandes pour tester keycontrol"); setarg ('d',"lines","Envoie du text",glocal.lines,false); setarg ('a',"args","Envoie des parametres",glocal.args,false); setarg ('h',"host","Serveur keycontrol",glocal.host,false); setarg ('p',"port","Port TCP du serveur keycontrol",glocal.port,false); setarg ('r',"resultat","Place le resultat dans un fichier",glocal.resfile,false); glocal FILE *fres = stdout; glocal string line; glocal int ret = 0; if (glocal.resfile != NULL){ glocal.fres = fopen (glocal.resfile,"w"); if (glocal.fres == NULL){ tlmp_error ("Ne peut ouvrir le fichie resultat %s (%s)\n" ,glocal.resfile,strerror(errno)); exit (-1); } } glocal.line = argv[0]; for (int i=1; i(glocal.host,glocal.port,5); bool sendend = false; sendf ("cmd %s\n",glocal.line.c_str()); for (int i=0; ic_str(); const char *pt = strchr(line,'='); if (pt != NULL){ string tmp(line,pt-line); sendf ("prm %s %s\n",tmp.c_str(),pt+1); sendend = true; }else{ tlmp_error ("Pas de =: %s\n",line); exit (-1); } } if (glocal.lines){ printf ("Attend des ligne\n"); char buf[100]; while (fgets(buf,sizeof(buf),stdin)!=NULL){ sendf ("dat %s",buf); } sendend = true; } if (sendend){ send ("end\n"); } printf ("Attend le resultat\n"); if (strcmp(line,"end")==0){ end = true; }else if (strncmp(line,"dat ",4)==0){ fprintf (glocal.fres,"%s\n",line+4); }else if (strncmp(line,"err ",4)==0){ printf ("Erreur: %s\n",line+4); glocal.ret = -1; } if (glocal.fres != stdout) fclose (glocal.fres); return glocal.ret; return glocal.ret; }