static void print_status(std::map<std::string, git_wd::file_status> const & fs, bool untracked) { for (auto && kv : fs) { char const * stati = untracked? "?DM": "ADM"; uint8_t const colors[] = { untracked? 0xe: 0xa, 0xa, 0xc }; console_color_guard concolor(colors[static_cast<int>(kv.second)]); std::cout << stati[static_cast<int>(kv.second)] << " " << kv.first << "\n"; } }
void move1(chess *q, int *prloc, int *locinput, char *str) { int *killedpiece; int a, i; if((((locinput[3] == NOKILL) && (strcmp(str, "undo") != 0 && strcmp(str, "undowithoutredo") != 0))) || (((prloc[3] == NOKILL) && (strcmp(str, "undo") == 0 || strcmp(str, "undowithoutredo") == 0)))){ if(locinput[0] != PAWN) { update(q, prloc, locinput);/* Because it will change its position */ } /* For normal case we are putting the piece on new location */ /* For undo case we are putting the piece on old location */ q->p[locinput[1]][locinput[2]].name[1] = rconvertp(locinput[0]); q->p[locinput[1]][locinput[2]].name[0] = concolor(q->state); q->p[locinput[1]][locinput[2]].status = ALIVE; q->p[locinput[1]][locinput[2]].color = q->state; /* For normal case we are making the old location as empty */ /* For undo case we are making the new location empty */ q->p[prloc[1]][prloc[2]].name[0] = q->p[prloc[1]][prloc[2]].name[1] = '_'; q->p[prloc[1]][prloc[2]].status = NOSTATUS; q->p[prloc[1]][prloc[2]].color = NOCOLOR; if(strcmp(str, "undo") == 0 || strcmp(str, "undowithoutredo") == 0) { q->p[locinput[1]][locinput[2]].name[0] = concolor(q->prevstate); q->p[locinput[1]][locinput[2]].color = q->prevstate; /* Done with prloc not for undo */ } else if(strcmp(str, "redo") == 0) { q->p[locinput[1]][locinput[2]].name[0] = concolor(q->state); q->p[locinput[1]][locinput[2]].color = q->state; } else { /* free redo */ if(empty(&q->r) == 0 && strcmp(str, "exp") != 0) { freeredo(q, &q->r); } } } else {/* KILL */ /* For the piece being killed */ a = convertp(q->p[locinput[1]][locinput[2]].name[1]); /* Converts char into int */ if(a != PAWN) { killedpiece = (int *)malloc(sizeof(int) * 4); killedpiece[0] = a; killedpiece[1] = locinput[1]; killedpiece[2] = locinput[2]; killedpiece[3] = NOKILL; remov(q, killedpiece);/* The piece will be removed from the list */ free(killedpiece); } if(locinput[0] != PAWN) { update(q, prloc, locinput);/* Because it is changing its position */ } /* Everything about killedpiece is done and now about moving */ if((strcmp(str, "undo") == 0) || (strcmp(str, "redo") == 0) || (strcmp(str, "undowithoutredo") == 0)) { q->p[locinput[1]][locinput[2]].name[1] = rconvertp(locinput[0]); q->p[locinput[1]][locinput[2]].status = ALIVE; if(strcmp(str, "undo") == 0 || strcmp(str, "undowithoutredo") == 0) { q->p[locinput[1]][locinput[2]].name[0] = concolor(q->prevstate); q->p[locinput[1]][locinput[2]].color = q->prevstate; } else { q->p[locinput[1]][locinput[2]].name[0] = concolor(q->state); q->p[locinput[1]][locinput[2]].color = q->state; } /* Done with prloc not for undo */ /* Restoring the killed piece */ if(strcmp(str, "undo") == 0 || strcmp(str, "undowithoutredo") == 0) { q->p[prloc[1]][prloc[2]].name[0] = concolor(q->state); q->p[prloc[1]][prloc[2]].name[1] = rconvertp(prloc[4]); } else { q->p[prloc[1]][prloc[2]].name[0] = '_'; q->p[prloc[1]][prloc[2]].name[1] = '_'; } q->p[prloc[1]][prloc[2]].status = ALIVE; q->p[prloc[1]][prloc[2]].color = prloc[8]; } else { /* free redo */ if(empty(&q->r) == 0 && strcmp(str, "exp") != 0) { freeredo(q, &q->r); } update(q, prloc, locinput); q->p[prloc[1]][prloc[2]].name[0] = q->p[prloc[1]][prloc[2]].name[1] = '_'; q->p[prloc[1]][prloc[2]].status = NOSTATUS; q->p[prloc[1]][prloc[2]].color = NOCOLOR; q->p[locinput[1]][locinput[2]].name[1] = rconvertp(locinput[0]);/* Converts int to char */ q->p[locinput[1]][locinput[2]].name[0] = concolor(q->state); q->p[locinput[1]][locinput[2]].status = ALIVE; q->p[locinput[1]][locinput[2]].color = q->state; if(locinput[0] != PAWN) { update(q, prloc, locinput); } } } }