Tracer des diagrammes dans un terminal - retour accueil
git clone git://bebou.netlib.re/boxes
Log | Files | Refs | README |
commit 6d70bb451a6f8b07d3075e4d833e5f9eb4d7692a parent 038a595870938bd8be2728651bba74b4f1825756 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Mon, 16 Jun 2025 22:38:04 +0200 On peut donner des coords en entrée boxe x y h w arrow startx starty endx endy simple efficace, encore plus de facto je pense que ça crash de ouf si le format est pas correct et aussi si y'a rien dans stderr ça attend, alors que c'est pas ce qu'on veut Diffstat:
M | boxes.c | | | 34 | +++++++++++++++++++++++++++++++--- |
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/boxes.c b/boxes.c @@ -78,13 +78,41 @@ void deletebox(struct boxpile *boxes, int index) { } int main(int argc, char **argv) { + + int toparsecount=0; + char line[1000]; + char **toparse; + + while (fgets(line, sizeof(line), stdin)) { + if(strlen(line)==1) continue; + toparse=realloc(toparse,(toparsecount+1)*sizeof(void*)); + toparse[toparsecount] = malloc(1000); + strcpy(toparse[toparsecount], line); + toparsecount++; + } + + struct boxpile boxes; boxes.list=malloc(MAX_BOX_NB*sizeof(struct box)); boxes.count=0; + struct arrowpile arrows; arrows.list=malloc(MAX_BOX_NB*sizeof(struct arrow)); arrows.count=0; + + char *delimiter=" "; + char* token; + for (int i=0;i<toparsecount;i++) { + token = strtok(toparse[i], delimiter); + char *type=token; + int args[4]; int j=0; + while (token) { + token = strtok(NULL, delimiter); + if(token!=NULL) args[j++]=(int)strtol(token, NULL, 10); + } + if(strcmp(type,"arrow")==0) addarrow(&arrows,createarrow(args[0],args[1],args[2],args[3])); + else if (strcmp(type,"box")==0) addbox(&boxes,createbox(args[0],args[1],args[2],args[3])); + } + tb_init(); tb_hide_cursor(); tb_set_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE); int mode=0; struct tb_event ev; - struct boxpile boxes; boxes.list=malloc(MAX_BOX_NB*sizeof(struct box)); boxes.count=0; - struct arrowpile arrows; arrows.list=malloc(MAX_BOX_NB*sizeof(struct arrow)); arrows.count=0; int curx; int cury; while(1) { tb_clear(); @@ -107,7 +135,7 @@ int main(int argc, char **argv) { for (int i=0;i<arrows.count;i++) printf("arrow %d %d %d %d\n",arrows.list[i].startx,arrows.list[i].starty,arrows.list[i].endx,arrows.list[i].endy); for (int i=0;i<boxes.count;i++) - printf("boxe %d %d %d %d\n",boxes.list[i].x,boxes.list[i].y,boxes.list[i].w,boxes.list[i].h); + printf("box %d %d %d %d\n",boxes.list[i].x,boxes.list[i].y,boxes.list[i].w,boxes.list[i].h); free(boxes.list); return 0; case 65512: /*MouseLeft*/