void print_trace(state_t *st) { fprintf(stderr, "DEBUG:\nStack:\n"); print_stack(st); fprintf(stderr, "Global vars:\n"); print_vars(st->vars, 1); fprintf(stderr, "Local vars:\n"); print_vars(st->frame->vars, 0); fprintf(stderr, "\n"); }
static int run(struct fi_info *hints, char *node, char *port) { struct fi_info *info; int ret; uint64_t flags; flags = list_providers ? FI_PROV_ATTR_ONLY : 0; ret = fi_getinfo(FI_VERSION(FI_MAJOR_VERSION, FI_MINOR_VERSION), node, port, flags, hints, &info); if (ret) { fprintf(stderr, "fi_getinfo: %d\n", ret); return ret; } if (env) ret = print_vars(); else if (verbose) ret = print_long_info(info); else if (list_providers) ret = print_providers(info); else ret = print_short_info(info); fi_freeinfo(info); return ret; }
bool_t vars_action(cmdline_t* options) { varmap_t* vm = NULL; assert(options != NULL); vm = fetchdeps_varmap_new(); if (!vm) goto failure; if (!fetchdeps_environ_init_all_vars(vm, options->argv + 1)) goto failure; print_vars(vm); fetchdeps_varmap_free(vm); return 1; failure: fetchdeps_errors_trap_system_error(); if (vm) fetchdeps_varmap_free(vm); return 0; }
int main (int argc, char const *argv[]) { int *reg_base = malloc(REGISTRE_LIMIT_INITIAL * sizeof(int)); print_zone_contenu(reg_base,REGISTRE_LIMIT_INITIAL,0,REGISTRE_LIMIT_INITIAL); struct var v = {"variable", {12,13}}; struct var *vars[2]; vars[0] = &v; vars[1]=NULL; //sert pour localiser la fin du tableau print_vars(vars); print_zone_contenu(reg_base,REGISTRE_LIMIT_INITIAL,v.tableau.pos,v.tableau.taille); print_erreur(HORS_SEG); print_erreur(MEM_INSUFFISANTE); print_erreur(NO_VAR); print_limit(REGISTRE_LIMIT_INITIAL); print_prompt(); return 0; }
void generate_code(struct tac * tac_mapped, FILE * f_out) { // gather data to be declared in the end unsigned n_strings = count_string_literals(tac_mapped); unsigned n_vars = count_vars(tac_mapped); char ** p_lit_strings = malloc(sizeof(char*) * n_strings); unsigned i_string = 0; int * func_params; count_func_params(tac_mapped, &func_params); int n_pushes = 0; // create mappings between variables and registers int * var_mapping; int * reg_mapping; unsigned res_reg, op1_reg, op2_reg; create_variable_mapping(n_vars, &var_mapping); create_register_mapping(®_mapping); // id counter for auxiliary labels generic_label_id = 0; // initial settings fprintf(f_out,".text\n"); fprintf(f_out,".org 0\n"); fprintf(f_out,"li $sp,0x00800000\n"); fprintf(f_out,"la $28,heap\n"); // call main and break after it's finished fprintf(f_out,"jal label1\n"); fprintf(f_out,"break\n"); for (unsigned i = 0; i < tac_mapped->instructions_cnt; i++) { struct tac_instruction inst = tac_mapped->instructions[i]; switch (inst.operator) { case OPERATOR_LABEL: clear_mappings(var_mapping, n_vars, reg_mapping, f_out); fprintf(f_out, "\nlabel%d:\n",inst.op1.value.num); break; case OPERATOR_ASSIGN: if ((inst.data_type == DATA_TYPE_STRING) && (inst.op1.type == OPERAND_TYPE_LITERAL)) { //string literal p_lit_strings[i_string] = inst.op1.value.string_val; res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); fprintf(f_out, "\tla $%d,str%d\n", res_reg, i_string); i_string++; } else if (inst.data_type == DATA_TYPE_STRING) { //string // not doing deep copy, because we cannot change the string anyway res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out, "\taddi $%d,$%d,0\n", res_reg, op1_reg); } else if (inst.op1.type == OPERAND_TYPE_LITERAL) { // int or char literal res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); fprintf(f_out, "\tli $%d,%d\n", res_reg, get_op_val(inst, 1)); } else { // int or char res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out, "\taddi $%d,$%d,0\n", res_reg, op1_reg); } break; case OPERATOR_SLT: if (inst.data_type == DATA_TYPE_STRING) { compare_strings(inst, var_mapping, reg_mapping, f_out, OPERATOR_SLT); break; } res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tslt $%d,$%d,$%d\n", res_reg, op1_reg, op2_reg); break; case OPERATOR_SLET: if (inst.data_type == DATA_TYPE_STRING) { compare_strings(inst, var_mapping, reg_mapping, f_out, OPERATOR_SLET); break; } res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tslt $%d,$%d,$%d\n", res_reg, op2_reg, op1_reg); fprintf(f_out, "\tlui $25,0xFFFF\n"); fprintf(f_out, "\tori $25,$25,0xFFFE\n"); fprintf(f_out, "\tnor $%d,$%d,$25\n", res_reg, res_reg); break; case OPERATOR_SGET: if (inst.data_type == DATA_TYPE_STRING) { compare_strings(inst, var_mapping, reg_mapping, f_out, OPERATOR_SGET); break; } res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tslt $%d,$%d,$%d\n", res_reg, op1_reg, op2_reg); fprintf(f_out, "\tlui $25,0xFFFF\n"); fprintf(f_out, "\tori $25,$25,0xFFFE\n"); fprintf(f_out, "\tnor $%d,$%d,$25\n", res_reg, res_reg); break; case OPERATOR_SGT: if (inst.data_type == DATA_TYPE_STRING) { compare_strings(inst, var_mapping, reg_mapping, f_out, OPERATOR_SGT); break; } res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tslt $%d,$%d,$%d\n", res_reg, op2_reg, op1_reg); break; case OPERATOR_SE: if (inst.data_type == DATA_TYPE_STRING) { compare_strings(inst, var_mapping, reg_mapping, f_out, OPERATOR_SE); break; } res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tsub $%d,$%d,$%d\n", res_reg, op1_reg, op2_reg); fprintf(f_out, "\tsltu $%d,$zero,$%d\n", res_reg, res_reg); fprintf(f_out, "\tlui $25,0xFFFF\n"); fprintf(f_out, "\tori $25,$25,0xFFFE\n"); fprintf(f_out, "\tnor $%d,$%d,$25\n", res_reg, res_reg); break; case OPERATOR_SNE: if (inst.data_type == DATA_TYPE_STRING) { compare_strings(inst, var_mapping, reg_mapping, f_out, OPERATOR_SNE); break; } res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tsub $%d,$%d,$%d\n", res_reg, op1_reg, op2_reg); fprintf(f_out, "\tsltu $%d,$zero,$%d\n", res_reg, res_reg); break; case OPERATOR_BZERO: clear_mappings(var_mapping, n_vars, reg_mapping, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out, "\tbeq $%d, $0, label%d\n", op1_reg, inst.op2.value.num); break; case OPERATOR_NEG: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out, "\tsltu $%d,$zero,$%d\n", res_reg, op1_reg); fprintf(f_out, "\tlui $25,0xFFFF\n"); fprintf(f_out, "\tori $25,$25,0xFFFE\n"); fprintf(f_out, "\tnor $%d,$%d,$25\n", res_reg, res_reg); break; case OPERATOR_AND: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\taddi $%d,$zero,0\n", res_reg); fprintf(f_out, "\tbeq $%d, $0, labelgen%d\n", op1_reg, generic_label_id); fprintf(f_out, "\tbeq $%d, $0, labelgen%d\n", op2_reg, generic_label_id); fprintf(f_out, "\taddi $%d,$zero,1\n", res_reg); fprintf(f_out, "\nlabelgen%d:\n",generic_label_id); generic_label_id++; break; case OPERATOR_OR: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\taddi $%d,$zero,1\n", res_reg); fprintf(f_out, "\tbne $%d, $0, labelgen%d\n", op1_reg, generic_label_id); fprintf(f_out, "\tbne $%d, $0, labelgen%d\n", op2_reg, generic_label_id); fprintf(f_out, "\taddi $%d,$zero,0\n", res_reg); fprintf(f_out, "\nlabelgen%d:\n",generic_label_id); generic_label_id++; break; case OPERATOR_JUMP: clear_mappings(var_mapping, n_vars, reg_mapping, f_out); fprintf(f_out, "\tj label%d\n",inst.op1.value.num); break; case OPERATOR_SUB: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tsub $%d,$%d,$%d\n", res_reg, op1_reg, op2_reg); break; case OPERATOR_ADD: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tadd $%d,$%d,$%d\n", res_reg, op1_reg, op2_reg); break; case OPERATOR_DIV: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tdiv $%d,$%d\n", op1_reg, op2_reg); fprintf(f_out, "\tmflo $%d\n", res_reg); break; case OPERATOR_MOD: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tdiv $%d,$%d\n", op1_reg, op2_reg); fprintf(f_out, "\tmfhi $%d\n", res_reg); break; case OPERATOR_MUL: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); op2_reg = get_register(var_mapping, reg_mapping, inst.op2.value.num, inst, f_out); fprintf(f_out, "\tmul $%d,$%d,$%d\n", res_reg, op1_reg, op2_reg); break; case OPERATOR_POP: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); fprintf(f_out, "\tlw $%d,0($fp)\n", res_reg); fprintf(f_out,"\taddi $fp,$fp,4\n"); break; case OPERATOR_PUSH: // push param on stack op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out,"\taddi $sp,$sp,-4\n"); fprintf(f_out,"\tsw $%d,0($sp)\n",op1_reg); n_pushes++; break; case OPERATOR_CALL: n_pushes -= func_params[inst.op1.value.num]; if ((inst.op1.value.num >=2) && inst.op1.value.num <= 8) { // built in function generate_built_in(inst.op1.value.num, n_pushes, tac_mapped, i, func_params, f_out, reg_mapping, var_mapping); if (inst.op1.value.num == 2) n_pushes = 0; break; } // push old FP fprintf(f_out,"\taddi $sp,$sp,-4\n"); fprintf(f_out,"\tsw $fp,0($sp)\n"); // set new FP fprintf(f_out,"\taddi $fp,$sp,4\n"); // push old RA fprintf(f_out,"\taddi $sp,$sp,-4\n"); fprintf(f_out,"\tsw $ra,0($sp)\n"); // push vars clear_mappings(var_mapping, n_vars, reg_mapping, f_out); fprintf(f_out,"\tjal push_registers\n"); // call fprintf(f_out,"\tjal label%d\n",inst.op1.value.num); // pop vars clear_mappings(var_mapping, n_vars, reg_mapping, f_out); fprintf(f_out,"\tjal pop_registers\n"); // pop ra fprintf(f_out,"\tlw $ra,0($sp)\n"); fprintf(f_out,"\taddi $sp,$sp,4\n"); // pop fp + params fprintf(f_out,"\taddi $25,$fp,0\n"); fprintf(f_out,"\tlw $fp,0($sp)\n"); fprintf(f_out,"\taddi $sp,$25,0\n"); // save return value res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); fprintf(f_out,"\taddi $%d,$2,0\n",res_reg); break; case OPERATOR_RETURN: if (inst.op1.type == OPERAND_TYPE_LITERAL) { if (inst.data_type == DATA_TYPE_STRING) { p_lit_strings[i_string] = inst.op1.value.string_val; fprintf(f_out, "\tla $2,str%d\n", i_string); i_string++; } else { fprintf(f_out,"\tli $2,%d\n",get_op_val(inst,1)); fprintf(f_out, "\tjr $ra\n"); } } else { op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out,"\taddi $2,$%d,0\n",op1_reg); fprintf(f_out, "\tjr $ra\n"); } break; case OPERATOR_CAST_INT_TO_CHAR: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out, "\tli $%d,0\n",res_reg); fprintf(f_out, "\taddi $%d,$%d,0\n",res_reg,op1_reg); fprintf(f_out, "\tli $25,0x00FF\n"); fprintf(f_out, "\tand $%d,$%d,$25\n",res_reg,res_reg); break; case OPERATOR_CAST_CHAR_TO_INT: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out, "\tli $%d,0\n",res_reg); fprintf(f_out, "\taddi $%d,$%d,0\n",res_reg,op1_reg); //fprintf(f_out, "\tli $25,0x000F\n"); //fprintf(f_out, "\tand $%d,$%d,$25\n",res_reg,res_reg); break; case OPERATOR_CAST_CHAR_TO_STRING: res_reg = get_register(var_mapping, reg_mapping, inst.res_num, inst, f_out); op1_reg = get_register(var_mapping, reg_mapping, inst.op1.value.num, inst, f_out); fprintf(f_out, "\taddi $%d,$28,0\n",res_reg); fprintf(f_out, "\tsb $%d,0($%d)\n",op1_reg,res_reg); fprintf(f_out, "\tsb $0,1($%d)\n",res_reg); fprintf(f_out, "\taddi $28,$28,2\n"); break; default: fprintf(f_out, "\tMISSING INSTR\n"); break; } } // generate push_registers function fprintf(f_out,"\npush_registers:\n"); for (unsigned i_reg = 0; i_reg < n_vars; i_reg++) { fprintf(f_out,"\taddi $sp,$sp,-4\n"); fprintf(f_out,"\tla $25,var%d\n",i_reg); fprintf(f_out,"\tlw $8,0($25)\n"); fprintf(f_out,"\tsw $8,0($sp)\n"); } fprintf(f_out,"\tjr $ra\n"); // generate pop_registers function fprintf(f_out,"\npop_registers:\n"); for (int i_reg = n_vars-1; i_reg >= 0; i_reg--) { fprintf(f_out,"\tla $25,var%d\n",i_reg); fprintf(f_out,"\tlw $8,0($sp)\n"); fprintf(f_out,"\tsw $8,0($25)\n"); fprintf(f_out,"\taddi $sp,$sp,4\n"); } fprintf(f_out,"\tjr $ra\n"); // print data - strings + variables fprintf(f_out,"\n.data\n"); print_string_literals(f_out, p_lit_strings, n_strings); print_vars(f_out, n_vars); fprintf(f_out,"\n.align 4\n"); fprintf(f_out,"\nheap:\n"); free(func_params); // dealocate register and variable mappings destroy_mappings(reg_mapping, var_mapping); }
int main(int argc, char **argv) { int i; int num; int rank, size; /*#define STR_SZ (15)*/ #define STR_SZ (50) int name_len = STR_SZ; char name[STR_SZ] = ""; int desc_len = STR_SZ; char desc[STR_SZ] = ""; int verb; MPI_Datatype dtype; int count; int bind; int varclass; int readonly, continuous, atomic; int provided; MPIX_T_enum enumtype; int pq_idx = -1, uq_idx = -1, pqm_idx = -1, uqm_idx = -1; int pqm_writable = -1, uqm_writable = -1; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); provided = 0xdeadbeef; MPIX_T_init_thread(MPI_THREAD_SINGLE, &provided); assert(provided != 0xdeadbeef); num = 0xdeadbeef; MPIX_T_pvar_get_num(&num); printf("get_num=%d\n", num); assert(num != 0xdeadbeef); for (i = 0; i < num; ++i) { name_len = desc_len = STR_SZ; MPIX_T_pvar_get_info(i, name, &name_len, &verb, &varclass, &dtype, &enumtype, desc, &desc_len, &bind, &readonly, &continuous, &atomic); printf("index=%d\n", i); printf("--> name='%s' name_len=%d desc='%s' desc_len=%d\n", name, name_len, desc, desc_len); printf("--> verb=%d varclass=%d dtype=%#x bind=%d readonly=%d continuous=%d atomic=%d\n", verb, varclass, dtype, bind, readonly, continuous, atomic); if (0 == strcmp(name, "posted_recvq_length")) { pq_idx = i; } else if (0 == strcmp(name, "unexpected_recvq_length")) { uq_idx = i; } else if (0 == strcmp(name, "posted_recvq_match_attempts")) { pqm_idx = i; pqm_writable = !readonly; } else if (0 == strcmp(name, "unexpected_recvq_match_attempts")) { uqm_idx = i; uqm_writable = !readonly; } } printf("pq_idx=%d uq_idx=%d pqm_idx=%d uqm_idx=%d\n", pq_idx, uq_idx, pqm_idx, uqm_idx); /* setup a session and handles for the PQ and UQ length variables */ session = MPIX_T_PVAR_SESSION_NULL; MPIX_T_pvar_session_create(&session); assert(session != MPIX_T_PVAR_SESSION_NULL); pq_handle = MPIX_T_PVAR_HANDLE_NULL; MPIX_T_pvar_handle_alloc(session, pq_idx, NULL, &pq_handle, &count); assert(count = 1); assert(pq_handle != MPIX_T_PVAR_HANDLE_NULL); uq_handle = MPIX_T_PVAR_HANDLE_NULL; MPIX_T_pvar_handle_alloc(session, uq_idx, NULL, &uq_handle, &count); assert(count = 1); assert(uq_handle != MPIX_T_PVAR_HANDLE_NULL); pqm_handle = MPIX_T_PVAR_HANDLE_NULL; MPIX_T_pvar_handle_alloc(session, pqm_idx, NULL, &pqm_handle, &count); assert(count = 1); assert(pqm_handle != MPIX_T_PVAR_HANDLE_NULL); uqm_handle = MPIX_T_PVAR_HANDLE_NULL; MPIX_T_pvar_handle_alloc(session, uqm_idx, NULL, &uqm_handle, &count); assert(count = 1); assert(uqm_handle != MPIX_T_PVAR_HANDLE_NULL); /* now send/recv some messages and track the lengths of the queues */ { int buf1, buf2, buf3, buf4; MPI_Request r1, r2, r3, r4; buf1 = buf2 = buf3 = buf4 = 0xfeedface; r1 = r2 = r3 = r4 = MPI_REQUEST_NULL; posted_qlen = 0x0123abcd; unexpected_qlen = 0x0123abcd; posted_queue_match_attempts = 0x0123abcd; unexpected_queue_match_attempts = 0x0123abcd; print_vars(1); MPI_Isend(&buf1, 1, MPI_INT, 0, /*tag=*/11, MPI_COMM_SELF, &r1); print_vars(2); printf("expected (posted_qlen,unexpected_qlen) = (0,1)\n"); MPI_Isend(&buf1, 1, MPI_INT, 0, /*tag=*/22, MPI_COMM_SELF, &r2); print_vars(3); printf("expected (posted_qlen,unexpected_qlen) = (0,2)\n"); MPI_Irecv(&buf2, 1, MPI_INT, 0, /*tag=*/33, MPI_COMM_SELF, &r3); print_vars(4); printf("expected (posted_qlen,unexpected_qlen) = (1,2)\n"); MPI_Recv(&buf3, 1, MPI_INT, 0, /*tag=*/22, MPI_COMM_SELF, MPI_STATUS_IGNORE); MPI_Wait(&r2, MPI_STATUS_IGNORE); print_vars(5); printf("expected (posted_qlen,unexpected_qlen) = (1,1)\n"); MPI_Recv(&buf3, 1, MPI_INT, 0, /*tag=*/11, MPI_COMM_SELF, MPI_STATUS_IGNORE); MPI_Wait(&r1, MPI_STATUS_IGNORE); print_vars(6); printf("expected (posted_qlen,unexpected_qlen) = (1,0)\n"); MPI_Send(&buf3, 1, MPI_INT, 0, /*tag=*/33, MPI_COMM_SELF); MPI_Wait(&r3, MPI_STATUS_IGNORE); print_vars(7); printf("expected (posted_qlen,unexpected_qlen) = (0,0)\n"); } if (pqm_writable) { posted_queue_match_attempts = 0; MPIX_T_pvar_write(session, pqm_handle, &posted_queue_match_attempts); } if (uqm_writable) { unexpected_queue_match_attempts = 0; MPIX_T_pvar_write(session, uqm_handle, &unexpected_queue_match_attempts); } print_vars(8); /* cleanup */ MPIX_T_pvar_handle_free(session, &uqm_handle); MPIX_T_pvar_handle_free(session, &pqm_handle); MPIX_T_pvar_handle_free(session, &uq_handle); MPIX_T_pvar_handle_free(session, &pq_handle); MPIX_T_pvar_session_free(&session); MPIX_T_finalize(); MPI_Finalize(); return 0; }
int main(int argc, char** argv) { #ifdef HAVE_LIBMESH libMesh::LibMeshInit init(argc,argv); #else FemusInit init(argc,argv); #endif // ======= Files ======================== Files files; files.ConfigureRestart(); files.CheckIODirectories(); files.CopyInputFiles(); files.RedirectCout(); // ======= Physics Input Parser ======================== FemusInputParser<double> physics_map("Physics",files.GetOutputPath()); const double rhof = physics_map.get("rho0"); const double Uref = physics_map.get("Uref"); const double Lref = physics_map.get("Lref"); const double muf = physics_map.get("mu0"); const double _pref = rhof*Uref*Uref; physics_map.set("pref",_pref); const double _Re = (rhof*Uref*Lref)/muf; physics_map.set("Re",_Re); const double _Fr = (Uref*Uref)/(9.81*Lref); physics_map.set("Fr",_Fr); const double _Pr = muf/rhof; physics_map.set("Pr",_Pr); // ======= Mesh ===== const unsigned NoLevels = 3; const unsigned dim = 2; const GeomElType geomel_type = QUAD; GenCase mesh(NoLevels,dim,geomel_type,"inclQ2D2x2.gam"); mesh.SetLref(1.); // ======= MyDomainShape (optional, implemented as child of Domain) ==================== FemusInputParser<double> box_map("Box",files.GetOutputPath()); Box mybox(mesh.get_dim(),box_map); mybox.InitAndNondimensionalize(mesh.get_Lref()); mesh.SetDomain(&mybox); mesh.GenerateCase(files.GetOutputPath()); mesh.SetLref(Lref); mybox.InitAndNondimensionalize(mesh.get_Lref()); XDMFWriter::ReadMeshAndNondimensionalizeBiquadraticHDF5(files.GetOutputPath(),mesh); XDMFWriter::PrintMeshXDMF(files.GetOutputPath(),mesh,BIQUADR_FE); XDMFWriter::PrintMeshLinear(files.GetOutputPath(),mesh); //gencase is dimensionalized, meshtwo is nondimensionalized //since the meshtwo is nondimensionalized, all the BC and IC are gonna be implemented on a nondimensionalized mesh //now, a mesh may or may not have an associated domain //moreover, a mesh may or may not be read from file //the generation is dimensional, the nondimensionalization occurs later //Both the Mesh and the optional domain must be nondimensionalized //first, we have to say if the mesh has a shape or not //that depends on the application, it must be put at the main level //then, after you know the shape, you may or may not generate the mesh with that shape //the two things are totally independent, and related to the application, not to the library // ===== QuantityMap : this is like the MultilevelSolution ========================================= QuantityMap qty_map; qty_map.SetMeshTwo(&mesh); qty_map.SetInputParser(&physics_map); Pressure pressure("Qty_Pressure",qty_map,1,LL); qty_map.AddQuantity(&pressure); VelocityX velocityX("Qty_Velocity0",qty_map,1,QQ); qty_map.AddQuantity(&velocityX); VelocityY velocityY("Qty_Velocity1",qty_map,1,QQ); qty_map.AddQuantity(&velocityY); Temperature temperature("Qty_Temperature",qty_map,1,QQ); qty_map.AddQuantity(&temperature); TempLift templift("Qty_TempLift",qty_map,1,QQ); qty_map.AddQuantity(&templift); TempAdj tempadj("Qty_TempAdj",qty_map,1,QQ); qty_map.AddQuantity(&tempadj); // ===== end QuantityMap ========================================= // ====== Start new main ================================= MultiLevelMesh ml_msh; ml_msh.GenerateCoarseBoxMesh(8,8,0,0,1,0,2,0,0,QUAD9,"fifth"); // ml_msh.GenerateCoarseBoxMesh(numelemx,numelemy,numelemz,xa,xb,ya,yb,za,zb,elemtype,"fifth"); ml_msh.RefineMesh(NoLevels,NoLevels,NULL); ml_msh.PrintInfo(); ml_msh.SetWriter(XDMF); //ml_msh.GetWriter()->write(files.GetOutputPath(),"biquadratic"); ml_msh.SetDomain(&mybox); MultiLevelSolution ml_sol(&ml_msh); ml_sol.AddSolution("Qty_Temperature",LAGRANGE,SECOND,0); ml_sol.AddSolution("Qty_TempLift",LAGRANGE,SECOND,0); ml_sol.AddSolution("Qty_TempAdj",LAGRANGE,SECOND,0); ml_sol.AddSolutionVector(ml_msh.GetDimension(),"Qty_Velocity",LAGRANGE,SECOND,0); ml_sol.AddSolution("Qty_Pressure",LAGRANGE,FIRST,0); ml_sol.AddSolution("Qty_TempDes",LAGRANGE,SECOND,0,false); //this is not going to be an Unknown! //moreover, this is not going to need any BC (i think they are excluded with "false") // I would like to have a Solution that is NOT EVEN related to the mesh at all... just like a function "on-the-fly" // ******* Set problem ******* MultiLevelProblem ml_prob(&ml_sol); ml_prob.SetMeshTwo(&mesh); ml_prob.SetQruleAndElemType("fifth"); ml_prob.SetInputParser(&physics_map); ml_prob.SetQtyMap(&qty_map); // ******* Initial condition ******* ml_sol.InitializeMLProb(&ml_prob,"Qty_Temperature",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_TempLift",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_TempAdj",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_Velocity0",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_Velocity1",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_Pressure",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_TempDes",SetInitialCondition); /// @todo you have to call this before you can print /// @todo I can also call it after instantiation MLProblem /// @todo I cannot call it with "All" and with a FUNCTION, because I need the string for "All" as a variable /// @todo Have to say that you have to call this initialize BEFORE the generation of the boundary conditions; /// if you called this after, it would superimpose the BOUNDARY VALUES /// @todo you have to initialize also those variables which are NOT unknowns! // ******* Set boundary function function ******* ml_sol.AttachSetBoundaryConditionFunctionMLProb(SetBoundaryCondition); // ******* Generate boundary conditions ******* ml_sol.GenerateBdc("Qty_Temperature","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_TempLift","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_TempAdj","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_Velocity0","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_Velocity1","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_Pressure","Steady",&ml_prob); // ******* Debug ******* ml_sol.SetWriter(VTK); std::vector<std::string> print_vars(1); print_vars[0] = "All"; // we should find a way to make this easier ml_sol.GetWriter()->write(files.GetOutputPath(),"biquadratic",print_vars); //=============================================== //================== Add EQUATIONS AND ====================== //========= associate an EQUATION to QUANTITIES ======== //======================================================== // not all the Quantities need to be unknowns of an equation SystemTwo & eqnNS = ml_prob.add_system<SystemTwo>("Eqn_NS"); eqnNS.AddSolutionToSystemPDEVector(ml_msh.GetDimension(),"Qty_Velocity"); eqnNS.AddSolutionToSystemPDE("Qty_Pressure"); eqnNS.AddUnknownToSystemPDE(&velocityX); eqnNS.AddUnknownToSystemPDE(&velocityY); eqnNS.AddUnknownToSystemPDE(&pressure); eqnNS.SetAssembleFunction(GenMatRhsNS); SystemTwo & eqnT = ml_prob.add_system<SystemTwo>("Eqn_T"); eqnT.AddSolutionToSystemPDE("Qty_Temperature"); eqnT.AddSolutionToSystemPDE("Qty_TempLift"); eqnT.AddSolutionToSystemPDE("Qty_TempAdj"); eqnT.AddUnknownToSystemPDE(&temperature); eqnT.AddUnknownToSystemPDE(&templift); eqnT.AddUnknownToSystemPDE(&tempadj); //the order in which you add defines the order in the matrix as well, so it is in tune with the assemble function eqnT.SetAssembleFunction(GenMatRhsT); //================================ //========= End add EQUATIONS and ======== //========= associate an EQUATION to QUANTITIES ======== //================================ //Ok now that the mesh file is there i want to COMPUTE the MG OPERATORS... but I want to compute them ONCE and FOR ALL, //not for every equation... but the functions belong to the single equation... I need to make them EXTERNAL // then I'll have A from the equation, PRL and REST from a MG object. //So somehow i'll have to put these objects at a higher level... but so far let us see if we can COMPUTE and PRINT from HERE and not from the gencase //once you have the list of the equations, you loop over them to initialize everything for (MultiLevelProblem::const_system_iterator eqn = ml_prob.begin(); eqn != ml_prob.end(); eqn++) { SystemTwo* sys = static_cast<SystemTwo*>(eqn->second); // ******* set MG-Solver ******* sys->SetMgType(F_CYCLE); sys->SetLinearConvergenceTolerance(1.e-10); sys->SetNonLinearConvergenceTolerance(1.e-10);//1.e-5 sys->SetNumberPreSmoothingStep(1); sys->SetNumberPostSmoothingStep(1); sys->SetMaxNumberOfLinearIterations(8); //2 sys->SetMaxNumberOfNonLinearIterations(15); //10 // ******* Set Preconditioner ******* sys->SetMgSmoother(GMRES_SMOOTHER);//ASM_SMOOTHER,VANKA_SMOOTHER // ******* init ******* sys->init(); // ******* Set Smoother ******* sys->SetSolverFineGrids(GMRES); sys->SetPreconditionerFineGrids(ILU_PRECOND); sys->SetTolerances(1.e-12,1.e-20,1.e+50,20); /// what the heck do these parameters mean? // ******* Add variables to be solved ******* /// do we always need this? sys->ClearVariablesToBeSolved(); sys->AddVariableToBeSolved("All"); // ******* For Gmres Preconditioner only ******* sys->SetDirichletBCsHandling(ELIMINATION); // ******* For Gmres Preconditioner only ******* // sys->solve(); //===================== sys -> init_two(); //the dof map is built here based on all the solutions associated with that system sys -> _LinSolver[0]->set_solver_type(GMRES); //if I keep PREONLY it doesn't run //===================== sys -> init_unknown_vars(); //===================== sys -> _dofmap.ComputeMeshToDof(); //===================== sys -> initVectors(); //===================== sys -> Initialize(); ///===================== sys -> _bcond.GenerateBdc(); //===================== GenCase::ReadMGOps(files.GetOutputPath(),sys); } // ======== Loop =================================== FemusInputParser<double> loop_map("TimeLoop",files.GetOutputPath()); OptLoop opt_loop(files, loop_map); opt_loop.TransientSetup(ml_prob); // reset the initial state (if restart) and print the Case opt_loop.optimization_loop(ml_prob); // at this point, the run has been completed files.PrintRunForRestart(DEFAULT_LAST_RUN); files.log_petsc(); // ============ clean ================================ ml_prob.clear(); mesh.clear(); return 0; }
int main(int argc, char *argv[]) { int opt; char *config_file = NULL; int i = 0; unsigned rnd_seed = 0; int seed_set = 0; program_name = argv[0]; while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) { switch (opt) { case 'a': AIRPORT_MARKER = 1; break; case 'e': config_file = optarg; break; case 'i': DISTINCT_ISLANDS = 0; break; case 'o': ORE = 0; break; case 'q': quiet = 1; break; case 'R': rnd_seed = strtoul(optarg, NULL, 10); seed_set = 1; break; case 's': outfile = optarg; break; case 'h': usage(); exit(0); case 'v': printf("%s\n\n%s", version, legal); exit(0); default: help(NULL); exit(1); } } parse_args(argc - optind, argv + optind); if (!seed_set) rnd_seed = pick_seed(); seed_prng(rnd_seed); empfile_init(); if (emp_config(config_file) < 0) exit(1); empfile_fixup(); allocate_memory(); print_vars(); qprint("\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n"); qprint("seed is %u\n", rnd_seed); do { init(); if (i) qprint("\ntry #%d (out of %d)...\n", i + 1, NUMTRIES); qprint("placing capitals...\n"); if (!drift()) qprint("fairland: unstable drift -- try increasisg DRIFT_MAX\n"); qprint("growing continents...\n"); grow_continents(); } while (fl_status && ++i < NUMTRIES); if (fl_status) { fputs("ERROR: World not large enough to hold continents\n", stderr); exit(1); } qprint("growing islands:"); grow_islands(); qprint("\nelevating land...\n"); create_elevations(); qprint("designating sectors...\n"); if (ORE) qprint("adding resources...\n"); write_newcap_script(); if (chdir(gamedir)) { fprintf(stderr, "Can't chdir to %s (%s)\n", gamedir, strerror(errno)); exit(EXIT_FAILURE); } if (!ef_open(EF_SECTOR, EFF_MEM | EFF_NOTIME)) exit(1); write_sects(); qprint("writing to sectors file...\n"); if (!ef_close(EF_SECTOR)) exit(1); output(); qprint("\n\nA script for adding all the countries can be found in \"%s\".\n", outfile); if (!ORE) qprint("\t*** Resources have not been added ***\n"); exit(0); }
int main(int argc, char *argv[]) { char *configuration = NULL; char *infile = NULL; char *outfile = NULL; char *verbose = NULL; int version_opt = 0; char *logdir = NULL; char *logfile = NULL; char *home = NULL; int help_opt = 0; int c; static struct option long_options[] = { {"configuration", required_argument, 0, 'c'}, {"silent", no_argument, 0, 1}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"logdir", required_argument, 0, 'l'}, {"logfile", required_argument, 0, 'L'}, {"home", required_argument, 0, 2}, {"infile", required_argument, 0, 'i'}, {"outfile", required_argument, 0, 'o'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; #ifdef XCP int is_bash_exist = system("command -v bash"); if ( is_bash_exist != 0 ) { fprintf(stderr, "Cannot find bash. Please ensure that bash is " "installed and available in the PATH\n"); exit(2); } #endif strcpy(progname, argv[0]); init_var_hash(); while(1) { int option_index = 0; c = getopt_long(argc, argv, "i:o:c:vVl:L:h", long_options, &option_index); if (c == -1) break; switch(c) { case 1: verbose = "n"; break; case 2: if (home) free (home); home = strdup(optarg); break; case 'i': if (infile) free(infile); infile = strdup(optarg); break; case 'o': if (outfile) free(outfile); outfile = strdup(optarg); break; case 'v': verbose = "y"; break; case 'V': version_opt = 1; break; case 'l': if (logdir) free(logdir); logdir = strdup(optarg); break; case 'L': if (logfile) free(logfile); logfile = strdup(optarg); break; case 'c': if (configuration) free(configuration); configuration = strdup(optarg); break; case 'h': help_opt = 1; break; default: fprintf(stderr, "Invalid optin value, received code 0%o\n", c); exit(1); } } if (version_opt || help_opt) { if (version_opt) print_version(); if (help_opt) print_help(); exit(0); } setup_my_env(); /* Read $HOME/.pgxc_ctl */ build_pgxc_ctl_home(home); if (infile) reset_var_val(VAR_configFile, infile); if (logdir) reset_var_val(VAR_logDir, logdir); if (logfile) reset_var_val(VAR_logFile, logfile); startLog(sval(VAR_logDir), sval(VAR_logFile)); prepare_pgxc_ctl_bash(pgxc_ctl_bash_path); build_configuration_path(configuration); read_configuration(); check_configuration(); /* * Setop output */ if (outfile) { elog(INFO, "Output file: %s\n", outfile); if ((outF = fopen(outfile, "w"))) dup2(fileno(outF),2); else elog(ERROR, "ERROR: Cannot open output file %s, %s\n", outfile, strerror(errno)); } else outF = stdout; /* * Startup Message */ elog(NOTICE, " ******** PGXC_CTL START ***************\n\n"); elog(NOTICE, "Current directory: %s\n", pgxc_ctl_home); /* * Setup input */ if (infile) { elog(INFO, "Input file: %s\n", infile); inF = fopen(infile, "r"); if(inF == NULL) { elog(ERROR, "ERROR: Cannot open input file %s, %s\n", infile, strerror(errno)); exit(1); } } else inF = stdin; /* * If we have remaing arguments, they will be treated as a command to do. Do this * first, then handle the input from input file specified by -i option. * If it is not found, then exit. */ #if 0 print_vars(); #endif if (optind < argc) { char orgBuf[MAXLINE + 1]; char wkBuf[MAXLINE + 1]; orgBuf[0] = 0; while (optind < argc) { strncat(orgBuf, argv[optind++], MAXLINE); strncat(orgBuf, " ", MAXLINE); } strncpy(wkBuf, orgBuf, MAXLINE); do_singleLine(orgBuf, wkBuf); if (infile) do_command(inF, outF); } else do_command(inF, outF); exit(0); }
/* * interactively select a kernel image and options. * The kernel can be an actual filename or a label in the config file * Return: * -1: if unsucessful * 0: otherwise */ static INTN select_kernel(CHAR16 *buffer, INTN size) { #define CHAR_CTRL_C L'\003' /* Unicode CTRL-C */ #define CHAR_CTRL_D L'\004' /* Unicode CTRL-D */ #define CHAR_CTRL_U L'\025' /* Unicode CTRL-U */ //#define CHAR_TAB L'\t' SIMPLE_INPUT_INTERFACE *ip = systab->ConIn; EFI_INPUT_KEY key; EFI_STATUS status; INTN pos = 0, ret; INT8 first_time = 1; /* * let's give some help first */ print_help(0); print_infos(0); reprint: buffer[pos] = CHAR_NULL; Print(L"\nELILO boot: %s", buffer); /* * autoboot with default choice after timeout expires */ if (first_time && (ret=wait_timeout(elilo_opt.timeout)) != 1) { return ret == -1 ? -1: 0; } first_time = 0; for (;;) { while ((status = uefi_call_wrapper(ip->ReadKeyStroke, 2, ip, &key)) == EFI_NOT_READY); if (EFI_ERROR(status)) { ERR_PRT((L"select_kernel readkey: %r", status)); return -1; } switch (key.UnicodeChar) { case CHAR_TAB: Print(L"\n"); if (pos == 0) { print_label_list(); Print(L"(or a kernel file name: [[dev_name:/]path/]kernel_image cmdline options)\n"); } else { buffer[pos] = CHAR_NULL; display_label_info(buffer); } goto reprint; case L'%': if (pos>0) goto normal_char; Print(L"\n"); print_vars(); goto reprint; case L'?': if (pos>0) goto normal_char; Print(L"\n"); print_help(1); goto reprint; case L'&': if (pos>0) goto normal_char; Print(L"\n"); print_infos(1); goto reprint; case L'=': if (pos>0) goto normal_char; Print(L"\n"); print_devices(); goto reprint; case CHAR_BACKSPACE: if (pos == 0) break; pos--; Print(L"\b \b"); break; case CHAR_CTRL_U: /* clear line */ while (pos) { Print(L"\b \b"); pos--; } break; case CHAR_CTRL_C: /* kill line */ pos = 0; goto reprint; case CHAR_LINEFEED: case CHAR_CARRIAGE_RETURN: buffer[pos] = CHAR_NULL; Print(L"\n"); return 0; default: normal_char: if (key.UnicodeChar == CHAR_CTRL_D || key.ScanCode == 0x17 ) { Print(L"\nGiving up then...\n"); return -1; } if (key.UnicodeChar == CHAR_NULL) break; if (pos > size-1) break; buffer[pos++] = key.UnicodeChar; /* Write the character out */ Print(L"%c", key.UnicodeChar); } } return 0; }
void fence_insertert::solve() { #ifdef HAVE_GLPK ilpt ilp; instrumenter.message.statistics() << "po^+ edges considered:" << unique << " cycles:" << instrumenter.set_of_cycles.size() << messaget::eom; /* sets the variables and coefficients */ //nb of po+ considered * types of fences (_e) unsigned i=1; mip_set_var(ilp, i); /* sets the constraints */ mip_set_cst(ilp, i); instrumenter.message.debug() << "3: " << i << messaget::eom; assert(i-1==constraints_number); const unsigned const_constraints_number=constraints_number; const unsigned const_unique=unique; const unsigned mat_size=const_unique*fence_options*const_constraints_number; instrumenter.message.statistics() << "size of the system: " << mat_size << messaget::eom; instrumenter.message.statistics() << "# of constraints: " << const_constraints_number << messaget::eom; instrumenter.message.statistics() << "# of variables: " << const_unique*fence_options << messaget::eom; ilp.set_size(mat_size); #ifdef DEBUG print_vars(); #endif /* fills the constraints coeff */ /* tables read from 1 in glpk -- first row/column ignored */ mip_fill_matrix(ilp, i, const_constraints_number, const_unique); instrumenter.message.statistics() << "i: " << i << " mat_size: " << mat_size << messaget::eom; //assert(i-1==mat_size); #ifdef DEBUG for(i=1; i<=mat_size; ++i) instrumenter.message.debug() << i << "[" << ilp.imat[i] << "," << ilp.jmat[i] << "]=" << ilp.vmat[i] << messaget::eom; #endif /* solves MIP by branch-and-cut */ ilp.solve(); #ifdef DEBUG print_vars(); #endif /* checks optimality */ switch(glp_mip_status(ilp.lp)) { case GLP_OPT: instrumenter.message.result() << "Optimal solution found" << messaget::eom; break; case GLP_UNDEF: instrumenter.message.result() << "Solution undefined" << messaget::eom; assert(0); case GLP_FEAS: instrumenter.message.result() << "Solution feasible, yet not proven \ optimal, due to early termination" << messaget::eom; break; case GLP_NOFEAS: instrumenter.message.result() << "No feasible solution, the system is UNSAT" << messaget::eom; assert(0); } event_grapht& egraph=instrumenter.egraph; /* loads results (x_i) */ instrumenter.message.statistics() << "minimal cost: " << glp_mip_obj_val(ilp.lp) << messaget::eom; for(unsigned j=1; j<=const_unique*fence_options; ++j) { if(glp_mip_col_val(ilp.lp, j)>=1) { /* insert that fence */ assert(map_to_e.find(col_to_var(j))!=map_to_e.end()); const edget& delay = map_to_e.find(col_to_var(j))->second; instrumenter.message.statistics() << delay.first << " -> " << delay.second << " : " << to_string(col_to_fence(j)) << messaget::eom; instrumenter.message.statistics() << "(between " << egraph[delay.first].source_location << " and " << egraph[delay.second].source_location << messaget::eom; fenced_edges.insert(std::pair<edget,fence_typet>(delay, col_to_fence(j))); } } #else throw "Sorry, musketeer requires glpk; please recompile\ musketeer with glpk."; #endif }
//---------------------------------------------------------------------- const char* parse_args(int argc, const char** argv, int parseonly, struct log2mem_handle * handle) { int i = 1; const char* filename = 0; int defaultshow = 1; enum showbits { eSummary = 0x01, eCounters = 0x02, eRows = 0x04, eVars = 0x08 }; int toshow = 0; for (;i < argc; i++) { if ( strcmp(argv[i], "-h")==0 || strcmp(argv[i],"--help")==0 ) help(); else if (strcmp(argv[i], "-s")==0) { toshow |= eSummary; } else if (strcmp(argv[i], "-c")==0) { toshow |= eCounters; } else if (strcmp(argv[i], "-r")==0) { toshow |= eRows; } else if (strcmp(argv[i], "-v")==0) { toshow |= eVars; } else if (strcmp(argv[i], "-a")==0) { toshow |= ~eSummary; } else if (strcmp(argv[i], "-F")==0) { if (++i >= argc) die("missing argument to -F", NULL); g_delim = argv[i]; g_showdelim = 1; } else if (strcmp(argv[i], "-z")==0) { g_showdelim = 0; } else if (strcmp(argv[i], "-t")==0) { g_terse = 1; } else if (strcmp(argv[i], "--version")==0) { printf("log2mem version: " PACKAGE_VERSION "\n"); exit(1); } else if (strncmp(argv[i], OPT_DOUBLE, strlen(OPT_DOUBLE))==0) { set_var_double(argc, argv, &i, handle); defaultshow = 0; } else if (strncmp(argv[i], OPT_INT, strlen(OPT_INT))==0) { set_var_int(argc, argv, &i, handle); defaultshow = 0; } else if (strncmp(argv[i], OPT_STRING, strlen(OPT_STRING))==0) { set_var_string(argc, argv, &i, handle); defaultshow = 0; } else if ((strncmp(argv[i], "--",2)==0) && strlen(argv[i])>2 ) { set_var_by_name(argc, argv, &i, handle); defaultshow = 0; } else { if (filename == 0) filename = argv[i]; else { die("unexpected argument: ", argv[i]); } } } if (defaultshow && !toshow) toshow = 0xFFFF; if (!parseonly) { //if (toshow & eSummary) print_summary(handle); if (toshow & eRows) print_rows(handle); if (toshow & eCounters) print_counters(handle); if (toshow & eVars) print_vars(handle); } return filename; }
int main(int argc, char **argv) { int c; int updates = 0; char *usage = "Usage: %s [-v] [-f prom-device]" " [variable[=value] ...]"; eplist_t *elist; benv_des_t *bd; char *file = NULL; setpname(argv[0]); while ((c = getopt(argc, argv, "f:Itv")) != -1) switch (c) { case 'v': verbose++; break; case 'f': file = optarg; break; case 't': test++; break; default: exit(_error(NO_PERROR, usage, argv[0])); } (void) uname(&uts_buf); bd = new_bd(); init_benv(bd, file); map_benv(bd); if (bd->len) { parse_benv(bd); unmap_benv(bd); } elist = bd->elist; if (optind >= argc) { print_vars(elist); return (0); } else while (optind < argc) { /* * If "-" specified, read variables from stdin; * otherwise, process each argument as a variable * print or set request. */ if (strcmp(argv[optind], "-") == 0) { char *line; while ((line = get_line()) != NULL) updates += proc_var(line, elist); clearerr(stdin); } else updates += proc_var(argv[optind], elist); optind++; } /* * don't write benv if we are processing delayed writes since * it is likely that the delayed writes changes bootenv.rc anyway... */ if (updates) write_benv(bd); close_kbenv(); return (0); }