reorder

Un outil pour réarranger les lignes de stdin - retour accueil

git clone git://bebou.netlib.re/reorder
Log | Files | Refs | README |

commit be1bf26acbbb1d137b996a51970b5eecd588e7cc
parent ec9f66541b06122a3ca1134749d6ff815adcaad8
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Mon, 20 Jan 2025 14:24:15 +0100

On execute la pile played

Y'a pas les scripts qui vont bien dans ce dépôt, en faite reorder est en
train de devenir l'interface du jeu en entier donc faudrait que je le
bouge dans le dépôt cardgame ?

Diffstat:
Mreorder.c | 22++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/reorder.c b/reorder.c @@ -50,11 +50,21 @@ void moveselection(struct pile* p, char* direction, bool selection) { void updatecmd(char* cmd, const struct pile p) { if (p.cardCount == 0 ) { return; } + strcat(cmd,"( cat ./"); strcat(cmd,p.cards[0]); for (int i=1;i<p.cardCount;i++) { - strcat(cmd," | \n"); + strcat(cmd," | \n./"); strcat(cmd,p.cards[i]); } + strcat(cmd," ) 2> /dev/null"); +} + +void updateres(char *res, const char *cmd, FILE *fp) { + fp = popen(cmd,"r"); + char line[1000]; + while(fgets(line, sizeof(line), fp)) { + strcat(res, line); + } } struct pile file2pile(FILE *fp) { @@ -73,7 +83,7 @@ struct pile file2pile(FILE *fp) { } -void display(struct pile* h, struct pile* p, int handcurline, int playedcurline, char* curmenu,bool selection, char* cmd) { +void display(struct pile* h, struct pile* p, int handcurline, int playedcurline, char* curmenu,bool selection, char* cmd, char* res) { tb_clear(); int i; int j; int w; int biggestpile=max(p->cardCount,h->cardCount); @@ -101,6 +111,7 @@ void display(struct pile* h, struct pile* p, int handcurline, int playedcurline, else { tb_printf(CARD_NAME_SIZE+2, j, TB_DEFAULT, TB_BLACK, p->cards[j]); } } tb_printf(0, biggestpile+1, TB_DEFAULT, TB_BLACK, cmd); + tb_printf(0, biggestpile+10, TB_DEFAULT, TB_BLACK, res); tb_present(); } @@ -108,6 +119,8 @@ int main(int argc, char **argv) { struct tb_event ev; FILE *fp = fopen("deck", "r"); + char res[2000]; + FILE *fp2; char cmd[2000]; cmd[0]='\0'; @@ -127,9 +140,10 @@ int main(int argc, char **argv) { char* curmenu="hand"; while(!quit) { - cmd[0]='\0'; + cmd[0]='\0';res[0]='\0'; updatecmd(cmd, played); - display(h,p,hand.curline,played.curline,curmenu,selection,cmd); + updateres(res, cmd, fp2); + display(h,p,hand.curline,played.curline,curmenu,selection,cmd,res); tb_poll_event(&ev); switch(ev.key) { /* up */