reorder

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

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

commit a7a7bf3bba0e256797d7373768c830733f17d7cb
parent e85880ae68aaeb83fb636ac1c9eb97d66a6a308f
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Wed, 15 Jan 2025 20:53:34 +0100

Je sais pas faire du CCCCC

Faut factoriser
Voir des histoires de struct aussi

Diffstat:
Mreorder.c | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 86 insertions(+), 24 deletions(-)

diff --git a/reorder.c b/reorder.c @@ -33,12 +33,13 @@ int main(int argc, char **argv) { tb_init(); bool selection=false; bool quit=true; + char* curmenu="hand"; while(quit) { tb_clear(); - int i; + int i; int j; for (i=0;i<handLineCount;i++) { - if (i==curline) { + if (i==curline && curmenu=="hand") { if (selection) { tb_printf(0, i, TB_BLACK, TB_BLUE, hand[i]); } else { @@ -48,43 +49,104 @@ int main(int argc, char **argv) { else { tb_printf(0, i, TB_DEFAULT, TB_BLACK, hand[i]); } } tb_printf(0, i, TB_DEFAULT, TB_BLACK, "------"); - for (i++;i<playedLineCount;i++) { - tb_printf(0, i, TB_DEFAULT, TB_BLACK, played[i]); + for (j=0;j<playedLineCount;j++) { + if (j==curline && curmenu=="played") { + if (selection) { + tb_printf(0, i+j+1, TB_BLACK, TB_BLUE, played[j]); + } else { + tb_printf(0, i+j+1, TB_BLACK, TB_WHITE, played[j]); + } + } } tb_present(); tb_poll_event(&ev); switch(ev.key) { + /* up */ case 65517: - if (curline>0) { - if (selection) { - char* tmp; - tmp=hand[curline]; - hand[curline]=hand[curline-1]; - hand[curline-1]=tmp; + if (curmenu=="hand") { + if (curline>0) { + if (selection) { + char* tmp; + tmp=hand[curline]; + hand[curline]=hand[curline-1]; + hand[curline-1]=tmp; + } + curline--; + } + } else if (curmenu=="played") { + if (curline>0) { + if (selection) { + char* tmp; + tmp=played[curline]; + played[curline]=played[curline-1]; + played[curline-1]=tmp; + } + curline--; } - curline--; } break; + /* down */ case 65516: - if (curline<handLineCount-1) { + if (curmenu=="hand") { + if (curline<handLineCount-1) { + if (selection) { + char* tmp; + tmp=hand[curline]; + hand[curline]=hand[curline+1]; + hand[curline+1]=tmp; + } + curline++; + } + } else if (curmenu=="played") { + if (curline<playedLineCount-1) { + if (selection) { + char* tmp; + tmp=played[curline]; + played[curline]=played[curline+1]; + played[curline+1]=tmp; + } + curline++; + } + } + break; + /* <- */ + case 65515: + if (curmenu=="played") { if (selection) { - char* tmp; - tmp=hand[curline]; - hand[curline]=hand[curline+1]; - hand[curline+1]=tmp; + hand[handLineCount] = malloc(256); + strcpy(hand[handLineCount], played[curline]); + handLineCount++; + if(handLineCount > sizeof(hand)){ + listSize *= 2; + hand = realloc(hand, listSize); + } + playedLineCount--; + for(int w=curline;w<playedLineCount;w++) { + played[w]=played[w+1]; + } } - curline++; + curmenu="hand"; + curline=handLineCount-1; } break; + /* -> */ case 65514: - if (selection) { - played[playedLineCount] = malloc(256); - strcpy(played[playedLineCount], hand[curline]); - playedLineCount++; - if(playedLineCount > sizeof(played)){ - listSize *= 2; - played = realloc(played, listSize); + if (curmenu=="hand") { + if (selection) { + played[playedLineCount] = malloc(256); + strcpy(played[playedLineCount], hand[curline]); + playedLineCount++; + if(playedLineCount > sizeof(played)){ + listSize *= 2; + played = realloc(played, listSize); + } + handLineCount--; + for(int w=curline;w<handLineCount;w++) { + hand[w]=hand[w+1]; + } } + curmenu="played"; + curline=playedLineCount-1; } break; case 13: