static int l2_proto2text(char **pos,char **end,int *length, const struct atm_blli *blli) { if (!blli->l2_proto) return 0; PUT("l2="); switch (blli->l2_proto) { #define X(u,l) case ATM_L2_##u: PUT(#l); MAYBE(","); return 0 X(ISO1745,iso1745); X(Q291,q291); X(LAPB,lapb); X(ISO8802,iso8802); X(X75,x75); #undef X #define X(u,l) case ATM_L2_##u: PUT(#l); break X(X25_LL,x25_ll); X(X25_ML,x25_ml); X(HDLC_ARM,hdlc_arm); X(HDLC_NRM,hdlc_nrm); X(HDLC_ABM,hdlc_abm); X(Q922,q992); X(ISO7776,iso7776); #undef X case ATM_L2_USER: PUT("user,info=%d",blli->l2.user); MAYBE(","); return 0; default: return -1; } MAYBE(","); if (blli->l2.itu.mode) { PUT("mode="); switch (blli->l2.itu.mode) { case ATM_IMD_NORMAL: PUT("norm"); break; case ATM_IMD_EXTENDED: PUT("ext"); break; default: return -1; } MAYBE(","); } if (blli->l2.itu.window) { PUT("window=%d",blli->l2.itu.window); MAYBE(","); } return 0; }
static int bhli2text(char **pos,char **end,int *length, const struct atm_bhli *bhli) { if (!bhli->hl_type) return 0; PUT("bhli:"); switch (bhli->hl_type) { case ATM_HL_ISO: PUT("iso="); DUMP(bhli->hl_info,bhli->hl_length); break; case ATM_HL_USER: PUT("user="******"hlp="); DUMP(bhli->hl_info,bhli->hl_length); break; #endif case ATM_HL_VENDOR: if (bhli->hl_length != 7) return -1; PUT("oui="); DUMP(bhli->hl_info,3); PUT(",id="); DUMP(bhli->hl_info+3,4); break; default: return -1; } MAYBE(","); return 0; }
static int blli2text(char **pos,char **end,int *length, const struct atm_blli *blli) { MAYBE("blli:"); if (l2_proto2text(pos,end,length,blli)) return -1; return l3_proto2text(pos,end,length,blli); }
static int mpx_cap(char **pos,char **end,int *length,const char *label, int cap) { if (!cap) return 0; PUT("%s=",label); switch (cap) { case ATM_MC_TS: PUT("ts"); break; case ATM_MC_TS_FEC: PUT("ts_fec"); break; case ATM_MC_PS: PUT("ps"); break; case ATM_MC_PS_FEC: PUT("ps_fec"); break; case ATM_MC_H221: PUT("h221"); break; default: return -1; } MAYBE(","); return 0; }
PandaNextSeq panda_args_hang_opener( PandaArgsHang data, PandaLogProxy logger, PandaFailAlign *fail, void **fail_data, PandaDestroy *fail_destroy, void **next_data, PandaDestroy *next_destroy) { MANAGED_STACK(PandaNextSeq, inner); inner = data->opener(data->user_data, logger, fail, fail_data, fail_destroy, &inner_data, &inner_destroy); if (inner == NULL) { MAYBE(next_data) = NULL; MAYBE(next_destroy) = NULL; return NULL; } return panda_trim_overhangs(inner, inner_data, inner_destroy, logger, data->forward, data->forward_length, data->reverse, data->reverse_length, data->skip, data->threshold, next_data, next_destroy); }
static int l3_proto2text(char **pos,char **end,int *length, const struct atm_blli *blli) { if (!blli->l3_proto) return 0; PUT("l3="); switch (blli->l3_proto) { #define X(u,l) case ATM_L3_##u: PUT(#l); break X(X25,x25); X(ISO8208,iso8208); X(X223,x223); #undef X case ATM_L3_TR9577: PUT("tr9577,ipi="); if (blli->l3.tr9577.ipi != NLPID_IEEE802_1_SNAP) { PUT("0x%x",blli->l3.tr9577.ipi); } else { PUT("snap,oui="); DUMP(blli->l3.tr9577.snap,3); PUT(",pid="); DUMP(blli->l3.tr9577.snap+3,2); } MAYBE(","); return 0; case ATM_L3_USER: PUT("user,info=%d",blli->l3.user); MAYBE(","); return 0; #define X(u,l) case ATM_L3_##u: PUT(#l); MAYBE(","); return 0 X(ISO8473,iso8473); X(T70,t70); X(H321,h321); #undef X case ATM_L3_H310: PUT("h310"); MAYBE(","); switch (blli->l3.h310.term_type) { case ATM_TT_NONE: return 0; case ATM_TT_RX: PUT("term=rx"); break; case ATM_TT_TX: PUT("term=tx"); break; case ATM_TT_RXTX: PUT("term=rxtx"); break; default: return -1; } MAYBE(","); mpx_cap(pos,end,length,"fw_mpx",blli->l3.h310.fw_mpx_cap); mpx_cap(pos,end,length,"bw_mpx",blli->l3.h310.bw_mpx_cap); return 0; default: return -1; } MAYBE(","); if (blli->l3.itu.mode) { PUT("mode="); switch (blli->l3.itu.mode) { case ATM_IMD_NORMAL: PUT("norm"); break; case ATM_IMD_EXTENDED: PUT("ext"); break; default: return -1; } MAYBE(","); } if (blli->l3.itu.def_size) { PUT("size=%d",blli->l3.itu.def_size); MAYBE(","); } if (blli->l3.itu.window) { PUT("window=%d",blli->l3.itu.window); MAYBE(","); } return 0; }
int solveMineSweeper(Board boardh, Board boardv) { // Initialize groups groupListArrayNumber = 0; for (int x = 0; x < boardv.width; x++) { for (int y = 0; y < boardv.height; y++) { char cell = get(boardv, x,y); if (cell == MINE || cell == UNKNOWN) { // Not a number! continue; } Group newGroup = buildGroup(boardv, x, y); if (newGroup.size != 0) { addToList(newGroup); } } } while (1) { MAYBE(printf("creation of groups complete\n")); for (int i = 0; i < groupListArrayNumber; i++) { for (int j = i + 1; j < groupListArrayNumber; j++) { MAYBE(printf("G%d[%d/%d]; G%d[%d/%d]; GLAN: %d)\n", i, groupList[i].mines, groupList[i].size, j, groupList[j].mines, groupList[j].size, groupListArrayNumber)); if (groupList[i].size == groupList[j].size // Groups are && containedIn(groupList[i], groupList[j])) { // the same removeFromList(j); MAYBE(printf("remove\n")); } else if (containedIn(groupList[i], groupList[j])) { //remove elements of i from j MAYBE(printf("SUB: G%d - G%d\n", j, i)); MAYBE(printGroup(groupList[j])); MAYBE(printGroup(groupList[i])); groupList[j] = subtract(groupList[j],groupList[i]); MAYBE(printGroup(groupList[j])); } else if (containedIn(groupList[j], groupList[i])) { //remove elements of j from i MAYBE(printf("SUB: G%d - G%d\n", i, j)); MAYBE(printGroup(groupList[i])); MAYBE(printGroup(groupList[j])); groupList[i] = subtract(groupList[i],groupList[j]); MAYBE(printGroup(groupList[i])); } else if (intersectSolver(groupList[i], groupList[j])>=0) { int x = intersectSolver(groupList[i], groupList[j]); MAYBE(printf("FIRST: %d, SECOND: %d\n", groupList[i].mines - (groupList[i].size - x), groupList[j].mines - (groupList[j].size - x))); MAYBE(printf("\nINTERCEPTION: mine:%d\n", x)); MAYBE(printGroup(groupList[i])); MAYBE(printGroup(groupList[j])); Group a, b; a = subtract(groupList[i], groupList[j]); // LEFT b = subtract(groupList[i], a); //isto vai dar merda!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! b.mines = x; addToList(b); groupList[i] = subtract(groupList[i], b); groupList[j] = subtract(groupList[j], b); } else { continue; } i = -1; // Reset outer for break; } } MAYBE(printf("cleaning of groups complete\n")); bool stallAlert = 0; int forMax = groupListArrayNumber; for (int i = 0; i < forMax; i++){ MAYBE(printf("for i:%d forMax:%d\n",i,forMax)); int result = NEUTRAL; if (groupList[i].mines == 0) { for (int j =0; j < groupList[i].size; j++) { makePlay(boardh, boardv, groupList[i].positions[j][0], groupList[i].positions[j][1], CLEAR); MAYBE(printf("Marking Clear (%d,%d)\n", groupList[i].positions[j][0], groupList[i].positions[j][1])); } } else if (groupList[i].mines == groupList[i].size) { for (int j = 0; j < groupList[i].size; j++) { makePlay(boardh, boardv, groupList[i].positions[j][0], groupList[i].positions[j][1], MINE); MAYBE(printf("Marking Mine (%d,%d)\n", groupList[i].positions[j][0], groupList[i].positions[j][1])); } removeFromList(i); i--; forMax--; } else { continue; } // Delete group stallAlert = 1; // maybe break; } for (int i = 0; i < forMax; i++){ int result = NEUTRAL; if (groupList[i].mines == 0) { for (int j =0; j < groupList[i].size; j++) { Group newGroup = buildGroup(boardv, groupList[i].positions[j][0], groupList[i].positions[j][1]); if (newGroup.size > 0) { addToList(newGroup); } } // Delete group removeFromList(i); i--; forMax--; } } printBoard(boardv); if (stallAlert == 0) { printBoard(boardv); printBoard(boardh); printf("Stalled!\n glan: %d \n", groupListArrayNumber); for (int i = 0; i < groupListArrayNumber; i++) { printGroup(groupList[i]); } return NEUTRAL; } } }
bool panda_dispatch_args( char *const *args, int args_length, const panda_tweak_assembler *const *const assembler_args, size_t assembler_args_length, const panda_tweak_general *const *const general_args, size_t general_args_length, PandaTweakGeneral tweak, void *user_data, panda_tweak_assembler_opt * options, size_t options_length, size_t *options_used, int *args_unused) { int c; size_t it; char optlist[MAX_OPT_LIST + 1]; char seen_options[MAX_OPT_LIST + 1]; size_t seen_options_length = 0; const panda_tweak_general **general_tweak; const panda_tweak_assembler **assembler_tweak; size_t opt_it; #ifdef __GLIBC__ optind = 0; #else optind = 1; #endif opt_it = 0; *options_used = 0; MAYBE(args_unused) = 0; c = '\0'; for (it = 0; it < general_args_length; it++) { if (general_args[it]->flag <= c) { fprintf(stderr, "Internal error: general arguments in a bad order.\n"); abort(); } c = optlist[opt_it++] = general_args[it]->flag; if (general_args[it]->takes_argument != NULL) optlist[opt_it++] = ':'; if (opt_it >= MAX_OPT_LIST) { fprintf(stderr, "Internal error: too many options.\n"); abort(); } } c = '\0'; for (it = 0; it < assembler_args_length; it++) { if (assembler_args[it]->flag <= c) { fprintf(stderr, "Internal error: assembler arguments in a bad order.\n"); abort(); } c = optlist[opt_it++] = assembler_args[it]->flag; if (assembler_args[it]->takes_argument != NULL) optlist[opt_it++] = ':'; if (opt_it >= MAX_OPT_LIST) { fprintf(stderr, "Internal error: too many options.\n"); abort(); } } optlist[opt_it] = '\0'; /* Process command line arguments. */ while ((c = getopt(args_length, args, optlist)) != -1) { if (c == '?') { if (strchr(optlist, optopt) != NULL) { if ((general_tweak = BSEARCH(&optopt, general)) != NULL) { fprintf(stderr, "Option -%c requires an argument %s.\n", optopt, (*general_tweak)->takes_argument); } else if ((assembler_tweak = BSEARCH(&optopt, assembler)) != NULL) { fprintf(stderr, "Option -%c requires an argument %s.\n", optopt, (*assembler_tweak)->takes_argument); } else { fprintf(stderr, "Unhandled command line argument -%c requires an argument. This is a bug.\n", (int) optopt); } } else if (isprint(optopt)) { fprintf(stderr, "Unknown option `-%c'.\n", optopt); } else { fprintf(stderr, "Unknown option character `\\x%x'.\n", (unsigned int) optopt); } CLEANUP(); return false; } else { if ((general_tweak = BSEARCH(&c, general)) != NULL) { if ((*general_tweak)->takes_argument != NULL || !(*general_tweak)->repeatable) { if (memchr(seen_options, c, seen_options_length) != NULL) { fprintf(stderr, "Command line argument -%c may not be repeated.\n", (int) c); CLEANUP(); return false; } if (seen_options_length == MAX_OPT_LIST) { fprintf(stderr, "Too many command line arguments.\n"); CLEANUP(); return false; } seen_options[seen_options_length++] = c; } if (!tweak(user_data, c, (*general_tweak)->takes_argument != NULL ? optarg : NULL)) { CLEANUP(); return false; } } else if ((assembler_tweak = BSEARCH(&c, assembler)) != NULL) { if ((*assembler_tweak)->takes_argument == NULL || !(*assembler_tweak)->repeatable) { if (memchr(seen_options, c, seen_options_length) != NULL) { fprintf(stderr, "Command line argument -%c may not be repeated.\n", (int) c); CLEANUP(); return false; } if (seen_options_length == MAX_OPT_LIST) { fprintf(stderr, "Too many command line arguments.\n"); CLEANUP(); return false; } seen_options[seen_options_length++] = c; } it = (*options_used)++; if (it >= options_length) { fprintf(stderr, "Too many command line arguments.\n"); CLEANUP(); return false; } options[it].tweak = *assembler_tweak; if ((*assembler_tweak)->takes_argument != NULL) { options[it].arg = malloc(strlen(optarg) + 1); memcpy(options[it].arg, optarg, strlen(optarg) + 1); } else { options[it].arg = NULL; } } else { fprintf(stderr, "Unhandled command line argument -%c. This is a bug.\n", (int) c); CLEANUP(); return false; } } } MAYBE(args_unused) = optind; if (optind < args_length && (((int) args[optind][0]) & 0x80) != 0) { fprintf(stderr, "You pasted stuff from the man page. Replace the dashes with hyphens.\n"); CLEANUP(); return false; } return true; }