static void show_result_list(struct merge_list *entry) { printf("%s\n", explanation(entry)); do { struct merge_list *link = entry->link; static const char *desc[4] = { "result", "base", "our", "their" }; printf(" %-6s %o %s %s\n", desc[entry->stage], entry->mode, sha1_to_hex(entry->blob->object.sha1), entry->path); entry = link; } while (entry); }
message::cli_arg to_cli_arg(bool use_caf_prefix) override { std::string argname; if (use_caf_prefix) argname = "caf#"; if (strcmp(category(), "global") != 0) { argname += category(); argname += "."; } argname += name(); if (short_name() != '\0') { argname += ','; argname += short_name(); } return {std::move(argname), explanation(), ref_}; }
void CSMesBackgroundComputation::run() { for(;;) { CSMesBackgroundComputations::data_t data; data.type=CSMesBackgroundComputations::data_t::NOP; while ( pool_p->dequeueRequest(data) ) { switch (data.type) { case CSMesBackgroundComputations::data_t::NOP: break; case CSMesBackgroundComputations::data_t::END_THREAD: return ; case CSMesBackgroundComputations::data_t::STATISTIC_MEASUREMENTS: { int nb_tested=-1; int nb_untested=-1; { QMutexLocker locker(&csmes_mutex); if (csmes_p && !abort_operation) csmes_p->statisticExecution(data.measurements, data.comparaisons, data.test_count_mode, data.coverage_level, data.method, data.comparaison_mode, nb_tested,nb_untested,abort_operation); } bool emit_data = data.type!=CSMesBackgroundComputations::data_t::NOP; if (abort_operation) { pool_p->enqueueRequest(data); emit_data=false; } if (emit_data) emit statisticExecution(data.measurements, data.comparaisons, data.test_count_mode, data.coverage_level, data.method, data.comparaison_mode, nb_tested,nb_untested); else msleep(250); } break; case CSMesBackgroundComputations::data_t::EXPLANATION: { QString expl; { QMutexLocker locker(&csmes_mutex); if (csmes_p && !abort_operation) expl = csmes_p->explanation (data.module,data.source,data.lines_indexes,data.source_type,data.coverage_level,data.method,data.executed_by_limit) ; } bool emit_data = data.type!=CSMesBackgroundComputations::data_t::NOP; if (abort_operation) { pool_p->enqueueRequest(data); emit_data=false; } if (emit_data) emit explanation(data.module,data.source,data.lines_indexes,data.source_type,data.coverage_level,data.method,data.executed_by_limit,expl); else msleep(250); } break; } } pool_p->waitForRequest(); } }
/* Main function */ int main() { /* CREATE GIVEN TEXT FILES */ FILE* pPets; if ((pPets = fopen("//Users//Jamesie//Xcode//16.5.15a//16.5.15a//pets.txt", "w")) == NULL) { printf("Unable to create pets.txt\n"); exit(EXIT_FAILURE); } else { fprintf(pPets, "dog Dalmation 3 100 EQP3\n" /* pet 1 */ "mouse Black 4 10 EQP1\n" /* pet 2 */ "dog Retriever 9 50 EQP2\n" /* pet 3 */ "dog Wolf 7 300 EQP2\n" /* pet 4 */ "cat Persian 3 100 EQP3\n" /* pet 5 */ "cat Munchkin 8 150 EQP4\n" /* pet 6 */ "cat Manx 3 100 EQP3\n" /* pet 7 */ "rabbit Angora 2 50 EQP7\n" /* pet 8 */ "rabbit Alaska 2 30 EQP7\n" /* pet 9 */ "dog Terrier 9 300 EQP3\n" /* pet 10 */ "fish Gold 4 50 EQP5\n"); /* pet 11 */ #ifdef MY_DEBUG printf("Pet database successfully loaded.\n"); #endif } fclose(pPets); FILE *pEquipment; if ((pEquipment = fopen("//Users//Jamesie//Xcode//16.5.15a//16.5.15a//equip.txt", "w")) == NULL) { printf("Unable to create equip.txt\n"); exit(EXIT_FAILURE); } else { fprintf(pEquipment, "EQP1 MouseCage 50\n" "EQP2 DogBed 30\n" "EQP3 TravelCage 50\n" "EQP4 CatCage 40\n" "EQP5 FishBowl 20\n" "EQP6 FishTank 100\n" "EQP7 RabbitCage 100\n"); #ifdef MY_DEBUG printf("Equipment database successfully loaded.\n\n"); #endif } fclose(pEquipment); /* GIVEN TEXT FILES CREATED */ /* READ FILES INTO TWO ARRAYS OF STRUCTURES */ int i; PET pet_list[NUM_PETS]; /* FIRST ARRAY OF STRUCTS */ if ((pPets = fopen("//Users//Jamesie//Xcode//16.5.15a//16.5.15a//pets.txt", "r")) == NULL) { printf("Unable to open pets.txt\n"); exit(EXIT_FAILURE); } else { for(i = 0; i < NUM_PETS; i++) { fscanf(pPets, "%s %s %d %d %s", pet_list[i].petcategory, pet_list[i].breed, &pet_list[i].age, &pet_list[i].petprice, pet_list[i].petsequip.equipcode); #ifdef MY_DEBUG printf("%s %s %d %d %s\n", pet_list[i].petcategory, pet_list[i].breed, pet_list[i].age, pet_list[i].petprice, pet_list[i].petsequip.equipcode); #endif } #ifdef MY_DEBUG printf("Pet data successfully read into array.\n\n"); #endif } fclose(pPets); EQUIP equip_list[NUM_EQUIP]; /* SECOND ARRAY OF STRUCTS */ if ((pEquipment = fopen("//Users//Jamesie//Xcode//16.5.15a//16.5.15a//equip.txt", "r")) == NULL) { printf("Unable to open equip.txt\n"); exit(EXIT_FAILURE); } else { for(i = 0; i < NUM_EQUIP; i++) { fscanf(pEquipment, "%s %s %d", equip_list[i].equipcode, equip_list[i].equipname, &equip_list[i].equipprice); #ifdef MY_DEBUG printf("%s %s %d\n", equip_list[i].equipcode, equip_list[i].equipname, equip_list[i].equipprice); #endif } #ifdef MY_DEBUG printf("Equipment data successfully read into array.\n\n"); #endif } fclose(pEquipment); /* ARRAYS OF STRUCTS CONSTRUCTED */ /* TRANSFER RELEVANT EQUIP DATA INTO PET STRUCTS */ int j; for(i = 0; i < NUM_PETS; i++) { for(j = 0; j < NUM_EQUIP; j++) { if((strcmp(pet_list[i].petsequip.equipcode, equip_list[j].equipcode)) == 0) { strcpy(pet_list[i].petsequip.equipname, equip_list[j].equipname); pet_list[i].petsequip.equipprice = equip_list[j].equipprice; } } } #ifdef MY_DEBUG for(i = 0; i < NUM_PETS; i++) { printf("Pet %d's equipment is %s with price €%d\n", i+1, pet_list[i].petsequip.equipname, pet_list[i].petsequip.equipprice); } #endif /* pet_list NOW CONTAINS ALL RELEVANT DATA */ /* APPLY PRICE REDUCTIONS BASED ON AGE */ for(i = 0; i < NUM_PETS; i++) { if((strcmp(pet_list[i].petcategory, "fish")) == 0 || (strcmp(pet_list[i].petcategory, "mouse")) == 0) { if(pet_list[i].age > 3) { pet_list[i].petprice -= 0.2 * pet_list[i].petprice; } #ifdef MY_DEBUG printf("New pet price for (old) pet %d is €%d\n", i+1, pet_list[i].petprice); #endif } else if((strcmp(pet_list[i].petcategory, "rabbit")) == 0) { pet_list[i].petprice -= 0.1 * pet_list[i].petprice; #ifdef MY_DEBUG printf("New price for (rabbit) pet %d is €%d\n", i+1, pet_list[i].petprice); #endif } else if((strcmp(pet_list[i].petcategory, "dog")) == 0 || (strcmp(pet_list[i].petcategory, "cat")) == 0) { if(pet_list[i].age > 6) { pet_list[i].petprice -= 0.5 * pet_list[i].petprice; #ifdef MY_DEBUG printf("New price for (old) pet %d is €%d\n", i+1, pet_list[i].petprice); #endif } } } /* PET PRICES ARE NOW COMPLETELY ACCURATE */ /* CALCULATE TOTAL PRICES FOR EACH PET */ for(i = 0; i < NUM_PETS; i++) { pet_list[i].totalprice = pet_list[i].petprice + pet_list[i].petsequip.equipprice; #ifdef MY_DEBUG printf("Total price for pet %d is €%d\n", i+1, pet_list[i].totalprice); #endif } /* TOTAL PRICES FOUND */ /* WRITE ALL DATA INTO NEW FILE */ FILE* pAllData; if((pAllData = fopen("//Users//Jamesie//Xcode//16.5.15a//16.5.15a//finaldata.txt", "w")) == NULL) { printf("Unable to create records file\n"); exit(EXIT_FAILURE); } else { for(i = 0; i < NUM_PETS; i++) { fprintf(pAllData, "%s %s %d %s %d\n", pet_list[i].petcategory, pet_list[i].breed, pet_list[i].age, pet_list[i].petsequip.equipname, pet_list[i].totalprice); } #ifdef MY_DEBUG printf("Records file successfully written\n"); #endif } fclose(pAllData); /* MUST HAVE AT LEAST THREE FUNCTIONS: menu, buy_pet, view_category */ void explanation(void); /* Function 1 */ int menu(void); /* Function 2 */ int menu_choice; void buy_pet(PET pet_array[]); /* Function 3 */ void view_category(PET pet_array[]); /* Function 4 */ /* EXECUTION OF INTERACTIVE PROGRAM */ explanation(); do { menu_choice = menu(); switch(menu_choice) { case 1: buy_pet(pet_list); break; case 2: view_category(pet_list); } } while (menu_choice != 0); printf("Program ends\n"); exit(EXIT_SUCCESS); }