reorder

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

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

commit ec9f66541b06122a3ca1134749d6ff815adcaad8
parent 7031d02379354a4bf4265e7482bc95cffd14ee9b
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Mon, 20 Jan 2025 11:34:34 +0100

On construit la commande à exec

Diffstat:
Mreorder.c | 28+++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/reorder.c b/reorder.c @@ -7,7 +7,7 @@ #define LIST_SIZE 1000 /* Le chiffre c'est des octets. Les caractères sont encodés sur un octet chacun ? * Donc si on met 5 la taille max serait 4 caractères ? */ -#define CARD_NAME_SIZE 10 +#define CARD_NAME_SIZE 20 struct pile { @@ -48,6 +48,15 @@ void moveselection(struct pile* p, char* direction, bool selection) { } } +void updatecmd(char* cmd, const struct pile p) { + if (p.cardCount == 0 ) { return; } + strcat(cmd,p.cards[0]); + for (int i=1;i<p.cardCount;i++) { + strcat(cmd," | \n"); + strcat(cmd,p.cards[i]); + } +} + struct pile file2pile(FILE *fp) { struct pile pi; struct pile *p=&pi; @@ -56,15 +65,18 @@ struct pile file2pile(FILE *fp) { p->cards = malloc(LIST_SIZE); char line[CARD_NAME_SIZE]; while (fgets(line, sizeof(line), fp)) { + /* Retire le retour à la ligne à la fin de line */ + line[strcspn(line, "\n")] = '\0'; addcardtopile(line, p); } return pi; } -void display(struct pile* h, struct pile* p, int handcurline, int playedcurline, char* curmenu,bool selection) { +void display(struct pile* h, struct pile* p, int handcurline, int playedcurline, char* curmenu,bool selection, char* cmd) { tb_clear(); - int i; int j; + int i; int j; int w; + int biggestpile=max(p->cardCount,h->cardCount); for (i=0;i<h->cardCount;i++) { if (i==handcurline && curmenu=="hand") { if (selection) { @@ -75,7 +87,7 @@ void display(struct pile* h, struct pile* p, int handcurline, int playedcurline, } else { tb_printf(0, i, TB_DEFAULT, TB_BLACK, h->cards[i]); } } - for (int w=0;w<max(p->cardCount,h->cardCount);w++) { + for (int w=0;w<biggestpile;w++) { tb_printf(CARD_NAME_SIZE,w,TB_DEFAULT, TB_BLACK, "|"); } for (j=0;j<p->cardCount;j++) { @@ -88,6 +100,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_present(); } @@ -96,6 +109,9 @@ int main(int argc, char **argv) { FILE *fp = fopen("deck", "r"); + char cmd[2000]; + cmd[0]='\0'; + struct pile hand = file2pile(fp); struct pile *h = &hand; struct pile played; @@ -111,7 +127,9 @@ int main(int argc, char **argv) { char* curmenu="hand"; while(!quit) { - display(h,p,hand.curline,played.curline,curmenu,selection); + cmd[0]='\0'; + updatecmd(cmd, played); + display(h,p,hand.curline,played.curline,curmenu,selection,cmd); tb_poll_event(&ev); switch(ev.key) { /* up */