static uint16_t common_rsp(const struct l2cap_frame *frame, struct tid_data *tid) { uint16_t bytes; if (frame->size < 2) { print_text(COLOR_ERROR, "invalid size"); packet_hexdump(frame->data, frame->size); return 0; } bytes = get_be16(frame->data); print_field("Attribute bytes: %d", bytes); if (bytes > frame->size - 2) { print_text(COLOR_ERROR, "invalid attribute size"); packet_hexdump(frame->data + 2, frame->size - 2); return 0; } return bytes; }
/* summary_len == 0 means "no summary */ static gboolean view_msg_plain (MuMsg *msg, MuConfig *opts) { gchar *attachs; time_t date; const GSList *lst; gboolean color; color = !opts->nocolor; print_field ("From", mu_msg_get_from (msg), color); print_field ("To", mu_msg_get_to (msg), color); print_field ("Cc", mu_msg_get_cc (msg), color); print_field ("Bcc", mu_msg_get_bcc (msg), color); print_field ("Subject", mu_msg_get_subject (msg), color); if ((date = mu_msg_get_date (msg))) print_field ("Date", mu_date_str_s ("%c", date), color); if ((lst = mu_msg_get_tags (msg))) { gchar *tags; tags = mu_str_from_list (lst,','); print_field ("Tags", tags, color); g_free (tags); } if ((attachs = get_attach_str (msg, opts))) { print_field ("Attachments", attachs, color); g_free (attachs); } body_or_summary (msg, opts); return TRUE; }
static bool bnep_control(struct bnep_frame *bnep_frame, uint8_t indent, int hdr_len) { uint8_t ctype; struct l2cap_frame *frame = &bnep_frame->l2cap_frame; const struct bnep_control_data *bnep_control_data = NULL; const char *type_str; int i; if (!l2cap_frame_get_u8(frame, &ctype)) return false; for (i = 0; bnep_control_table[i].str; i++) { if (bnep_control_table[i].type == ctype) { bnep_control_data = &bnep_control_table[i]; break; } } if (bnep_control_data) type_str = bnep_control_data->str; else type_str = "Unknown control type"; print_field("%*c%s (0x%02x) ", indent, ' ', type_str, ctype); if (!bnep_control_data || !bnep_control_data->func) { packet_hexdump(frame->data, hdr_len - 1); l2cap_frame_pull(frame, frame, hdr_len - 1); goto done; } if (!bnep_control_data->func(bnep_frame, indent+2)) return false; done: return true; }
/* a summary_len of 0 mean 'don't show summary, show body */ static void body_or_summary (MuMsg *msg, MuConfig *opts) { const char *body; gboolean color; color = !opts->nocolor; body = mu_msg_get_body_text (msg, mu_config_get_msg_options(opts)); if (!body) return; if (opts->summary_len != 0) { gchar *summ; summ = mu_str_summarize (body, opts->summary_len); print_field ("Summary", summ, color); g_free (summ); } else { color_maybe (MU_COLOR_YELLOW); mu_util_print_encoded ("\n%s\n", body); color_maybe (MU_COLOR_DEFAULT); } }
static bool bnep_general(struct bnep_frame *bnep_frame, uint8_t indent, int hdr_len) { struct l2cap_frame *frame; char src_addr[20], dest_addr[20]; if (!get_macaddr(bnep_frame, dest_addr)) return false; if (!get_macaddr(bnep_frame, src_addr)) return false; frame = &bnep_frame->l2cap_frame; if (!l2cap_frame_get_be16(frame, &proto)) return false; print_field("%*cdst %s src %s [proto 0x%04x] ", indent, ' ', dest_addr, src_addr, proto); return true; }
static void print_sco_routing(uint8_t routing) { const char *str; switch (routing) { case 0x00: str = "PCM"; break; case 0x01: str = "Transport"; break; case 0x02: str = "Codec"; break; case 0x03: str = "I2S"; break; default: str = "Reserved"; break; } print_field("SCO routing: %s (0x%2.2x)", str, routing); }
static void launch_ram_cmd(const void *data, uint8_t size) { uint32_t addr = get_le32(data); print_field("Address: 0x%8.8x", addr); }
bool AI::run() { engine->click(Game::a_open, 5, 5); size_t size_x = engine->get_size_x(); size_t size_y = engine->get_size_y(); bool changed = false; bool won = false; do { changed = false; auto field = get_field(); if(verbose){ print_field(field, ostr); (*ostr) << std::endl; } for(size_t x = 0; x < size_x; x++) { for(size_t y = 0; y < size_y; y++) { if((field[x][y] >= '1') && (field[x][y] <= '8')) { size_t count = 0; engine->cycle_cells(x, y, [&field, &count](size_t x_, size_t y_) { if((field[x_][y_] == '#') || (field[x_][y_] == 'f')) { count++; } }); if(count == (field[x][y] - '0')) { engine->cycle_cells(x, y, [&field, this, &changed](size_t x_, size_t y_) { if(field[x_][y_] == '#') { this->engine->click(Game::a_flag, x_, y_); field[x_][y_] = 'f'; changed = true; } }); } } } } field = get_field(); if(verbose){ print_field(field, ostr); (*ostr) << std::endl; } for(size_t x = 0; x < size_x; x++) { for(size_t y = 0; y < size_y; y++) { if((field[x][y] >= '1') && (field[x][y] <= '8')) { size_t count = 0; engine->cycle_cells(x, y, [&field, &count](size_t x_, size_t y_) { if(field[x_][y_] == 'f') { count++; } }); if(count == (field[x][y] - '0')) { engine->cycle_cells(x, y, [&field, this, &changed, &won](size_t x_, size_t y_) { if(field[x_][y_] == '#') { auto code = this->engine->click(Game::a_open, x_, y_); if(code == 1) { if(verbose){ print_lose(); (*ostr) << "I lost!" << std::endl; } changed = false; } else if (code == 2) { changed = false; won = true; if(verbose) { print(); (*ostr) << "I won!" << std::endl; } } field = get_field(); } }); } } } } } while (changed); if(!won) { if(verbose) { (*ostr) << "Not sure what to do here..." << std::endl; } else { print(); } } return won; }
/** * Lists all installed MIDlet suites. This is an example of how to use * the public MIDP API. * * @param argc The total number of arguments * @param argv An array of 'C' strings containing the arguments * * @return <tt>0</tt> for success, otherwise <tt>-1</tt> * * IMPL_NOTE: determine if it is desirable for user targeted output * messages to be sent via the log/trace service, or if * they should remain as printf calls */ int listMidlets(int argc, char* argv[]) { int status = -1; int i; long size; char* midpHome = NULL; (void)argv; /* Avoid compiler warnings */ if (argc > 1) { REPORT_ERROR(LC_AMS, "Too many arguments given"); fprintf(stderr, "Too many arguments given\n"); return -1; } /* get midp home directory, set it */ midpHome = midpFixMidpHome(argv[0]); if (midpHome == NULL) { return -1; } /* set up midpHome before calling initialize */ midpSetHomeDir(midpHome); if (midpInitialize() != 0) { REPORT_ERROR(LC_AMS, "Not enough memory"); fprintf(stderr, "Not enough memory\n"); return -1; } do { SuiteIdType* pSuites = NULL; int numberOfSuites = 0; MIDPError err; err = midp_get_suite_ids(&pSuites, &numberOfSuites); if (err != ALL_OK) { REPORT_ERROR1(LC_AMS, "Error in midp_get_suite_ids(), code %d", err); fprintf(stderr, "Error in midp_get_suite_ids(), code %d.\n", err); break; } if (numberOfSuites == 0) { REPORT_ERROR(LC_AMS, "No MIDlet Suites installed on phone"); printf("** No MIDlet Suites installed on phone\n"); status = 0; break; } for (i = 0; i < numberOfSuites; i++) { MidpInstallInfo info; MidpProperties properties; info = midp_get_suite_install_info(pSuites[i]); if (BAD_ID_INFO_STATUS(info)) { REPORT_ERROR(LC_AMS, "Suite list is corrupt"); fprintf(stderr, "Suite list is corrupt\n"); break; } if (OUT_OF_MEM_INFO_STATUS(info)) { REPORT_ERROR(LC_AMS, "Out Of Memory for Info"); fprintf(stderr, "Out Of Memory for Info\n"); break; } if (SUITE_CORRUPTED_ERR_STATUS(info)) { /* * Installinfo is not initialsed in case of an error * so no need to free it */ REPORT_ERROR1(LC_AMS, "Error : Suite %d is corrupted", (i+1)); fprintf(stderr, "Error : Suite %d is corrupted\n", (i+1)); continue; } if (READ_ERROR_INFO_STATUS(info)) { REPORT_ERROR(LC_AMS, "Corrupt install info"); fprintf(stderr, "Corrupt install info\n"); break; } properties = midp_get_suite_properties(pSuites[i]); if (OUT_OF_MEM_PROPERTY_STATUS(properties)) { midp_free_install_info(&info); midp_free_properties(&properties); REPORT_ERROR(LC_AMS, "Out Of Memory for properties"); fprintf(stderr, "Out Of Memory for properties\n"); break; } if (CORRUPTED_PROPERTY_STATUS(properties)) { midp_free_install_info(&info); midp_free_properties(&properties); REPORT_ERROR1(LC_AMS, "Error : Suite %d is corrupted", (i+1)); fprintf(stderr, "Error : Suite %d is corrupted\n", (i+1)); continue; } if (READ_ERROR_PROPERTY_STATUS(properties)) { midp_free_install_info(&info); midp_free_properties(&properties); REPORT_ERROR(LC_AMS, "Corrupt properties"); fprintf(stderr, "Corrupt properties\n"); break; } printf("[%d]\n", (i + 1)); printProperty(" Name: ", &SUITE_NAME_PROP, properties); printProperty(" Vendor: ", &SUITE_VENDOR_PROP, properties); printProperty(" Version: ", &SUITE_VERSION_PROP, properties); printProperty(" Description: ", &SUITE_DESC_PROP, properties); if (info.authPathLen > 0) { int j; puts(" Authorized by: "); for (j = 0; j < info.authPathLen; j++) { print_field(" ", &info.authPath_as[j]); } } print_field(" SecurityDomain: ", &info.domain_s); printf(" Verified: %s\n", (info.pVerifyHash != NULL ? "true" : "false")); printf(" Suite ID: %ld\n", (long)pSuites[i]); print_field(" JAD URL: ", &info.jadUrl_s); print_field(" JAR URL: ", &info.jarUrl_s); size = midp_get_suite_storage_size(pSuites[i]); if (size < 0) { fprintf(stderr, "Ran out of memory getting the size\n"); } else { printf(" Size: %ldK\n", (size + 1023) / 1024); } midp_free_install_info(&info); midp_free_properties(&properties); } midp_free_suite_ids(pSuites, numberOfSuites); status = 0; } while (0); midpFinalize(); return status; }
/** * Prints a property value to <tt>stdout</tt>. * * @param pszLabel A 'C' string label to be printed before the * property value * @param key The property key of the value to print * @param props The properties to search for <tt>key</tt> */ static void printProperty(char* pszLabel, const pcsl_string * key, MidpProperties props) { print_field(pszLabel, midp_find_property(&props, key)); }
void uiprintfield( a_dialog *dialog, VFIELD *field ) { print_field( dialog->vs, field, field == dialog->curr ); }
static void handle_continuation(struct tid_data *tid, bool nested, uint16_t bytes, const uint8_t *data, uint16_t size) { uint8_t *newdata; int i, n = -1; if (bytes + 1 > size) { print_text(COLOR_ERROR, "missing continuation state"); return; } if (tid->cont[0] == 0x00 && data[bytes] == 0x00) { decode_data_elements(0, 2, data, bytes, nested ? print_attr_lists : print_attr_list); print_continuation(data + bytes, size - bytes); return; } for (i = 0; i < MAX_CONT; i++) { if (cont_list[i].cont[0] == 0x00) { if (n < 0) n = i; continue; } if (cont_list[i].channel != tid->channel) continue; if (cont_list[i].cont[0] != tid->cont[0]) continue; if (!memcmp(cont_list[i].cont + 1, tid->cont + 1, tid->cont[0])) { n = i; break; } } print_continuation(data + bytes, size - bytes); if (n < 0) return; newdata = realloc(cont_list[n].data, cont_list[n].size + bytes); if (!newdata) { print_text(COLOR_ERROR, "failed buffer allocation"); free(cont_list[n].data); cont_list[n].data = NULL; cont_list[n].size = 0; return; } cont_list[n].channel = tid->channel; cont_list[n].data = newdata; if (bytes > 0) { memcpy(cont_list[n].data + cont_list[n].size, data, bytes); cont_list[n].size += bytes; } if (data[bytes] == 0x00) { print_field("Combined attribute bytes: %d", cont_list[n].size); decode_data_elements(0, 2, cont_list[n].data, cont_list[n].size, nested ? print_attr_lists : print_attr_list); free(cont_list[n].data); cont_list[n].data = NULL; cont_list[n].size = 0; } else memcpy(cont_list[i].cont, data + bytes, data[bytes] + 1); }
int main (int argc, char ** argv) { int i; /* * this is set to either euler or runge_kutta_4 */ enum solver_t solver; /* * bc (boundary condition) can be either periodic or no_slip */ enum bc_t bc; /* * these specify the geometry of the area to be simulated * tdim ist the total number of points, i.e. tdim = xdim *ydim */ int xdim, ydim, tdim; double dx, dy; /* * this holds the neighbors */ int **neighbors; /* * this holds latitude and longitude values of each point */ unsigned int *lat, *lon; /* * this holds order of the data to be printed out */ unsigned int *print_out_order; /* * these control temporal aspects of the simulation */ long int ncycle; double dt = 5.1; long int n_iter = 25800; int write_out_interval = 5000; /* * these hold the physical parameters * * f0: coriolis parameter (1/1sec) * beta: linear beta for coriolis force (1/(meter sec)) * forcingTerm: Wind stress amplitude "tau_0"(N/meter^2) * dissipationTerm: "A" viscosity coefficient (meters^2/sec) * RayleighFriction: Rayleigh friction parameter (1/sec) */ double f0 = 5.0e-5; double beta =2e-11; double forcingTerm = 0.0005; double dissipationTerm = 0.00005; double RayleighFriction = 5e-8; /* * upper layer equilibrium depth (meters) */ double EquilibriumDepth = 50000.0; double A; /* * this holds the physical parameters and the forcing */ double *parameters; double *x_forcing, *y_forcing, *z_forcing; /* * "fields" holds the values of the u, v and P fields */ double *fields; double *u, *v, *P; /* * "fields_prev" holds the u, v and P values of the previous time step */ //double *fields_prev; //double *u_prev, *v_prev, *P_prev; /* * these are temporary storage locations * for the Runge-Kutta scheme */ double *temp_dots_rk; double *temp_fields_rk; /* * read parameters from command line */ if(argc == 2){ get_parameters(argv[1], &xdim, &ydim, &dx, &dy, &n_iter, &dt, &write_out_interval, &bc, &solver, &f0, &beta, &forcingTerm, &dissipationTerm, &RayleighFriction, &EquilibriumDepth, &A); } else{ fprintf(stderr, "ERROR: You need to give a file containing the parameters as an argument!\n"); exit(1); } print_parameters(xdim, ydim, dx, dy, n_iter, dt, write_out_interval, bc, solver, f0, beta, forcingTerm, dissipationTerm, RayleighFriction, EquilibriumDepth, A); tdim = xdim*ydim; /* * allocate arrays containing geometrical information and fill these */ lat = calloc(tdim, sizeof(unsigned int)); lon = calloc(tdim, sizeof(unsigned int)); print_out_order = calloc(tdim, sizeof(unsigned int)); neighbors = calloc(tdim, sizeof(int*)); for(i=0; i< tdim; i++){ neighbors[i] = calloc(4, sizeof(int)); } initialize_geometry(xdim, ydim, neighbors, lat, lon, print_out_order); /* * allocate memory for physical parameters and forcing */ parameters = calloc(5+3*tdim, sizeof(double)); parameters[0] = f0; parameters[1] = beta; parameters[2] = forcingTerm; parameters[3] = dissipationTerm; parameters[4] = RayleighFriction; x_forcing = parameters + 5; y_forcing = parameters + 5 + tdim; z_forcing = parameters + 5 + 2*tdim; /* * allocate "fields" and set addresses for u, v, and P */ fields = calloc(3*tdim, sizeof(double)); u = fields; v = fields + tdim; P = fields + 2 * tdim; /* * allocate "fields_prev" and set addresses for u_prev, v_prev, and P_prev */ //fields_prev = calloc(3*tdim, sizeof(double)); //u_prev = fields_prev; //v_prev = fields_prev + tdim; //P_prev = fields_prev + 2 * tdim; double *fields_dot; fields_dot = calloc(3*tdim, sizeof(double)); /* * allocate memory for temporary Runge-Kutta storage locations */ temp_dots_rk = calloc(3*tdim, sizeof(double)); temp_fields_rk = calloc(3*tdim, sizeof(double)); /* * initialize fields */ initialize_fields (u, v, P, x_forcing, y_forcing, z_forcing, xdim, ydim, dx, dy, EquilibriumDepth, A, neighbors, lat, lon, bc); /* * loop through time steps to do the actual simulation */ for (ncycle=0; ncycle<n_iter; ncycle++) { //printf("step #%li\n", ncycle); /* * print result */ if(ncycle % write_out_interval == 0){ print_field(u, "u", ncycle, xdim, ydim, print_out_order); print_field(v, "v", ncycle, xdim, ydim, print_out_order); print_field(P, "P", ncycle, xdim, ydim, print_out_order); printf("%li ", ncycle); fflush(stdout); } Fcalc(fields_dot, fields, parameters, xdim, ydim, dx, dy, neighbors, lat, bc, print_out_order, ncycle); //for (i=0;i<3*tdim;i++) { // fields_prev[i] = fields[i]; //} if(solver == runge_kutta_4){ /* * Runge-Kutta 4th order * * dt * y_1 = y_0 + ---- (y'_0 + 2 * y'_A + 2 * y'_B +y'_C) * 6 */ /* dt * first step: y_A = y_0 + ---- y'_0 * 2 */ for (i=0; i < 3*tdim; i++) { temp_fields_rk[i] = fields[i]+0.5*dt*fields_dot[i]; } Fcalc(temp_dots_rk, temp_fields_rk, parameters, xdim, ydim, dx, dy, neighbors, lat, bc, print_out_order, ncycle); for (i=0; i < 3*tdim; i++) { fields_dot[i] += 2*temp_dots_rk[i]; } /* dt * second step: y_B = y_0 + ---- y'_A * 2 */ for (i=0; i < 3*tdim; i++) { temp_fields_rk[i] = fields[i]+0.5*dt*temp_dots_rk[i]; } Fcalc(temp_dots_rk, temp_fields_rk, parameters, xdim, ydim, dx, dy, neighbors, lat, bc, print_out_order, ncycle); for (i=0; i < 3*tdim; i++) { fields_dot[i] += 2*temp_dots_rk[i]; } /* * third step: y_C = y_0 + dt * y'_B */ for (i=0; i < 3*tdim; i++){ temp_fields_rk[i] = fields[i]+dt*temp_dots_rk[i]; } Fcalc(temp_dots_rk, temp_fields_rk, parameters, xdim, ydim, dx, dy, neighbors, lat, bc, print_out_order, ncycle); for (i=0; i < 3*tdim; i++) { fields_dot[i] += temp_dots_rk[i]; } /* dt * final step: y_1 = y_0 + ---- (y'_0 + 2 * y'_A + 2 * y'_B +y'_C) * 6 */ for (i=0; i < 3*tdim; i++) { fields_dot[i] /= 6.0; fields[i] += dt*fields_dot[i]; } } else{ if(solver == euler){ /* * the Euler scheme */ for (i=0; i < 3*tdim; i++) { fields[i] += dt*fields_dot[i]; } } else{ fprintf(stderr, "ERROR: No valid solver was found\n"); exit(2); } } } printf("\n"); return(0); }
void InstructionPrinter::do_LoadField(LoadField* x) { print_field(x); }
static inline bool mcc_frame(struct rfcomm_frame *rfcomm_frame, uint8_t indent) { uint8_t length, ex_length, type; const char *type_str; int i; struct l2cap_frame *frame = &rfcomm_frame->l2cap_frame; struct rfcomm_lmcc mcc; const struct mcc_data *mcc_data = NULL; if (!l2cap_frame_get_u8(frame, &mcc.type) || !l2cap_frame_get_u8(frame, &length)) return false; if (RFCOMM_TEST_EA(length)) mcc.length = (uint16_t) GET_LEN8(length); else { if (!l2cap_frame_get_u8(frame, &ex_length)) return false; mcc.length = ((uint16_t) length << 8) | ex_length; mcc.length = GET_LEN16(mcc.length); } type = RFCOMM_GET_MCC_TYPE(mcc.type); for (i = 0; mcc_table[i].str; i++) { if (mcc_table[i].type == type) { mcc_data = &mcc_table[i]; break; } } if (mcc_data) type_str = mcc_data->str; else type_str = "Unknown"; print_field("%*cMCC Message type: %s %s (0x%2.2x)", indent, ' ', type_str, CR_STR(mcc.type), type); print_field("%*cLength: %d", indent+2, ' ', mcc.length); rfcomm_frame->mcc = mcc; switch (type) { case RFCOMM_TEST: return mcc_test(rfcomm_frame, indent+10); case RFCOMM_MSC: return mcc_msc(rfcomm_frame, indent+2); case RFCOMM_RPN: return mcc_rpn(rfcomm_frame, indent+2); case RFCOMM_RLS: return mcc_rls(rfcomm_frame, indent+2); case RFCOMM_PN: return mcc_pn(rfcomm_frame, indent+2); case RFCOMM_NSC: return mcc_nsc(rfcomm_frame, indent+2); default: packet_hexdump(frame->data, frame->size); } return true; }
/** * Reentrant formatted print. * * Supported '%' format characters: * - 's' const char * null terminated string as text or "(null)" * - 'x' int/long hexadecimal '0xnn' * - 'X' int/long hexadecimal '0XNN' * - 'u' int/long unsigned decimal * - 'd' int/long signed decimal * - 'i' int/long signed decimal * - 'p' pointer pointer value is printed as "0xnnnn" (IF CONFIGURED) * - 'c' char single character * - 'o' int/long octal numbers (IF CONFIGURED) * * Supported flags: * - '#' use alternate form (IF CONFIGURED) * - 'l' use long instead of int for numbers (IF CONFIGURED) * - 'll' use long long for numbers (IF CONFIGURED) * - '-' align left * - ' ' prefix non-negative numbers with single space * - '+' prefix non-negative numbers with plus * - '0' pad with '0' instead of ' ' * - '*' fetch width from the argument list (unsigned int) * * The field width (e.g. "%10s") can also be specified. * The field precision (e.g. "%10.3s" can also be specified (IF CONFIGURED) * * Unsupported are: * - float numbers (format char: e E f F g G a A) * - write-back character count ("%n") * * @param write_char [in] function used to write characters * @param format [in] format string * @param args [in] variable argument list * @return the number of characters that were written */ int embtextf_vuprintf (embtextf_putchar_fn write_char, const char *format, va_list args) { int character_count = 0; enum { DIRECT, FORMATING } mode = DIRECT; unsigned int wp_value = 0; unsigned int width = 0; flags_t flags; const char* specifier = format; char *char_p; char character; int radix; char have_wp_value = 0; #if EMBTEXTF_ENABLE_VUPRINTF_PRECISION - 0 char have_precision = 0; #endif /* EMBTEXTF_ENABLE_VUPRINTF_PRECISION */ char is_zero = 0; char is_negative = 0; union { int i; #if EMBTEXTF_ENABLE_VUPRINTF_INTPTR - 0 intptr_t ptr; #endif /* EMBTEXTF_ENABLE_VUPRINTF_INTPTR */ #if EMBTEXTF_ENABLE_VUPRINTF_LONG - 0 long int li; #if EMBTEXTF_ENABLE_VUPRINTF_LONGLONG - 0 long long int lli; #endif /* EMBTEXTF_ENABLE_VUPRINTF_LONGLONG */ #endif /* EMBTEXTF_ENABLE_VUPRINTF_LONG */ } number; char buffer[MAX_FORMAT_LENGTH]; /* used to print numbers */ while ((character = *format++)) { /* test and save character */ if (mode == DIRECT) { /* output characters from the format string directly, except the */ /* '%' sign which changes the mode */ if (character == '%') { width = wp_value = 0; memset(&flags, 0, sizeof(flags)); have_wp_value = is_zero = is_negative = 0; #if EMBTEXTF_ENABLE_VUPRINTF_PRECISION - 0 have_precision = 0; #endif /* EMBTEXTF_ENABLE_VUPRINTF_PRECISION */ specifier = format - 1; mode = FORMATING; } else { write_character: write_char(character); character_count++; mode = DIRECT; } } else { /* FORMATING */ /* process format characters */ switch (character) { /* output '%' itself */ case '%': goto write_character; /* character is already the % */ #if EMBTEXTF_ENABLE_VUPRINTF_ALTERNATE_FORM - 0 /* alternate form flag */ case '#': flags.is_alternate_form = 1; break; #endif /* EMBTEXTF_ENABLE_VUPRINTF_ALTERNATE_FORM */ #if EMBTEXTF_ENABLE_VUPRINTF_LONG - 0 /* interpret next number as long integer */ case 'l': #if EMBTEXTF_ENABLE_VUPRINTF_LONGLONG - 0 if (flags.is_longlong) { goto bad_format; } else if (flags.is_long) { flags.is_long = 0; flags.is_longlong = 1; } else #endif /* EMBTEXTF_ENABLE_VUPRINTF_LONGLONG */ { if (flags.is_long) { goto bad_format; } flags.is_long = 1; } break; #endif /* EMBTEXTF_ENABLE_VUPRINTF_LONG */ /* left align instead of right align */ case '-': flags.left_align = 1; break; /* emit a + before a positive number */ case '+': flags.sign_char = '+'; break; /* emit a space before a positive number */ case ' ': /* + overrides space as a flag character */ if ('+' != flags.sign_char) { flags.sign_char = ' '; } break; #if EMBTEXTF_ENABLE_VUPRINTF_PRECISION - 0 case '.': /* explicit precision is present */ if (have_wp_value) { width = wp_value; wp_value = 0; have_wp_value = 0; } have_precision = 1; break; #endif /* EMBTEXTF_ENABLE_VUPRINTF_PRECISION */ /* fetch length from argument list instead of the format */ /* string itself */ case '*': { int val = va_arg(args, int); if (val >= 0) { wp_value = val; #if EMBTEXTF_ENABLE_VUPRINTF_PRECISION - 0 } else if (have_precision) { wp_value = 0; #endif /* EMBTEXTF_ENABLE_VUPRINTF_PRECISION */ } else { flags.left_align = 1; wp_value = -val; } have_wp_value = 1; break; } /* format field width. zero needs special treatment */ /* as when it occurs as first number it is the */ /* flag to pad with zeroes instead of spaces */ case '0': /* a leading zero means filling with zeros */ /* it must be a leading zero if 'width' is zero */ /* otherwise it is in a number as in "10" */ if (wp_value == 0 #if EMBTEXTF_ENABLE_VUPRINTF_PRECISION - 0 && !have_precision #endif /* EMBTEXTF_ENABLE_VUPRINTF_PRECISION */ ) { flags.fill_zero = !flags.left_align; break; } /*@fallthrough@ */ case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': wp_value *= 10; wp_value += character - '0'; have_wp_value = 1; break; /* placeholder for one character */ case 'c': character = va_arg(args, int); if (! have_wp_value #if EMBTEXTF_ENABLE_VUPRINTF_PRECISION - 0 && ! have_precision #endif /* EMBTEXTF_ENABLE_VUPRINTF_PRECISION */ ) { goto write_character; } char_p = buffer; buffer[0] = character; buffer[1] = 0; goto emit_string; /* placeholder for arbitrary length null terminated */ /* string */ case 's': char_p = va_arg(args, char *); emit_string: /* Note: Zero-padding on strings is undefined; it * is legitimate to zero-pad */ #if EMBTEXTF_ENABLE_VUPRINTF_PRECISION - 0 if (have_precision) { flags.truncate_precision = 1; flags.precision = wp_value; } else #endif /* EMBTEXTF_ENABLE_VUPRINTF_PRECISION */ if (have_wp_value) { width = wp_value; } character_count += print_field(write_char, (char_p != NULL) ? char_p : "(null)", width, flags); mode = DIRECT; break; #if EMBTEXTF_ENABLE_VUPRINTF_INTPTR - 0 /* placeholder for an address */ /* addresses are automatically in alternate form and */ /* hexadecimal. */ case 'p': number.ptr = (intptr_t) va_arg(args, void *); number.ptr &= UINTPTR_MAX; radix = 16; #if EMBTEXTF_ENABLE_VUPRINTF_ALTERNATE_FORM - 0 flags.is_alternate_form = (0 != number.ptr); #endif /* EMBTEXTF_ENABLE_VUPRINTF_ALTERNATE_FORM */ goto emit_number; #endif /* EMBTEXTF_ENABLE_VUPRINTF_INTPTR */ /* hexadecimal output */ case 'X': flags.uppercase = 1; /*@fallthrough@ */ case 'x': radix = 16; goto fetch_number; #if EMBTEXTF_ENABLE_VUPRINTF_OCTAL - 0 /* octal output */ case 'o': radix = 8; goto fetch_number; #endif /* EMBTEXTF_ENABLE_VUPRINTF_OCTAL */ /* decimal signed numbers */ case 'd': case 'i': flags.is_signed = 1; /*@fallthrough@ */ /* decimal unsigned numbers */ case 'u': radix = 10; /* label for number outputs including argument fetching */ fetch_number: #if EMBTEXTF_ENABLE_VUPRINTF_LONG - 0 #if EMBTEXTF_ENABLE_VUPRINTF_LONGLONG - 0 if (flags.is_longlong) { number.lli = va_arg(args, long long int); is_zero = (number.lli == 0); is_negative = (number.lli < 0); } else #endif /* EMBTEXTF_ENABLE_VUPRINTF_LONGLONG */ if (flags.is_long) { number.li = va_arg(args, long int); is_zero = (number.li == 0); is_negative = (number.li < 0); } else #endif /* EMBTEXTF_ENABLE_VUPRINTF_LONG */ {
void InstructionPrinter::do_StoreField(StoreField* x) { print_field(x); output()->print(" := "); print_value(x->value()); output()->print(" (%c)", type2char(x->field()->type()->basic_type())); }
void InstructionPrinter::do_LoadField(LoadField* x) { print_field(x); output()->print(" (%c)", type2char(x->field()->type()->basic_type())); }
static void print_boolean(uint8_t indent, const uint8_t *data, uint32_t size) { print_field("%*c%s", indent, ' ', data[0] ? "true" : "false"); }
void uiprintfield( a_dialog *ui_dlg_info, VFIELD *field ) { print_field( ui_dlg_info->vs, field, field == ui_dlg_info->curr ); }
void broadcom_lm_diag(const void *data, uint8_t size) { uint8_t type; uint32_t clock; const uint8_t *addr; const char *str; if (size != 63) { packet_hexdump(data, size); return; } type = *((uint8_t *) data); clock = get_be32(data + 1); switch (type) { case 0x00: str = "LMP sent"; break; case 0x01: str = "LMP receive"; break; case 0x80: str = "LL sent"; break; case 0x81: str = "LL receive"; break; default: str = "Unknown"; break; } print_field("Type: %s (%u)", str, type); print_field("Clock: 0x%8.8x", clock); switch (type) { case 0x00: addr = data + 5; print_field("Address: --:--:%2.2X:%2.2X:%2.2X:%2.2X", addr[0], addr[1], addr[2], addr[3]); packet_hexdump(data + 9, 1); lmp_packet(data + 10, size - 10, true); break; case 0x01: addr = data + 5; print_field("Address: --:--:%2.2X:%2.2X:%2.2X:%2.2X", addr[0], addr[1], addr[2], addr[3]); packet_hexdump(data + 9, 4); lmp_packet(data + 13, size - 13, true); break; case 0x80: case 0x81: packet_hexdump(data + 5, 7); llcp_packet(data + 12, size - 12, true); break; default: packet_hexdump(data + 9, size - 9); break; } }
static void decode_data_elements(uint32_t position, uint8_t indent, const uint8_t *data, uint32_t size, void (*print_func) (uint32_t, uint8_t, uint8_t, const uint8_t *, uint32_t)) { uint32_t datalen, elemlen, extrabits; int i; if (!size) return; extrabits = get_bits(data, size); if (size < 1 + (extrabits / 8)) { print_text(COLOR_ERROR, "data element descriptor too short"); packet_hexdump(data, size); return; } datalen = get_size(data, size); if (size < 1 + (extrabits / 8) + datalen) { print_text(COLOR_ERROR, "data element size too short"); packet_hexdump(data, size); return; } elemlen = 1 + (extrabits / 8) + datalen; for (i = 0; type_table[i].str; i++) { uint8_t type = (data[0] & 0xf8) >> 3; if (type_table[i].value != type) continue; if (print_func) { print_func(position, indent, type, data + 1 + (extrabits / 8), datalen); break; } print_field("%*c%s (%d) with %u byte%s [%u extra bits] len %u", indent, ' ', type_table[i].str, type, datalen, datalen == 1 ? "" : "s", extrabits, elemlen); if (!valid_size(data[0] & 0x07, type_table[i].sizes)) { print_text(COLOR_ERROR, "invalid data element size"); packet_hexdump(data + 1 + (extrabits / 8), datalen); break; } if (type_table[i].recurse) decode_data_elements(0, indent + 2, data + 1 + (extrabits / 8), datalen, print_func); else if (type_table[i].print) type_table[i].print(indent + 2, data + 1 + (extrabits / 8), datalen); break; } if (elemlen > size) { print_text(COLOR_ERROR, "invalid data element size"); return; } data += elemlen; size -= elemlen; decode_data_elements(position + 1, indent, data, size, print_func); }
void InstructionPrinter::do_StoreField(StoreField* x) { print_field(x); tty->print(" := "); print_value(x->value()); }
static void print_full_information(void) { static const WCHAR newlineW[] = {'\n',0}; static const WCHAR emptyW[] = {0}; FIXED_INFO *info; IP_ADAPTER_ADDRESSES *adapters; ULONG out = 0; if (GetNetworkParams(NULL, &out) == ERROR_BUFFER_OVERFLOW) { info = HeapAlloc(GetProcessHeap(), 0, out); if (!info) exit(1); if (GetNetworkParams(info, &out) == ERROR_SUCCESS) { WCHAR hostnameW[MAX_HOSTNAME_LEN + 4]; MultiByteToWideChar(CP_ACP, 0, info->HostName, -1, hostnameW, sizeof(hostnameW)/sizeof(hostnameW[0])); print_field(STRING_HOSTNAME, hostnameW); /* FIXME: Output primary DNS suffix. */ print_field(STRING_NODE_TYPE, nodetype_to_string(info->NodeType)); print_field(STRING_IP_ROUTING, boolean_to_string(info->EnableRouting)); /* FIXME: Output WINS proxy status and DNS suffix search list. */ ipconfig_printfW(newlineW); } HeapFree(GetProcessHeap(), 0, info); } if (GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, NULL, &out) == ERROR_BUFFER_OVERFLOW) { adapters = HeapAlloc(GetProcessHeap(), 0, out); if (!adapters) exit(1); if (GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, adapters, &out) == ERROR_SUCCESS) { IP_ADAPTER_ADDRESSES *p; for (p = adapters; p; p = p->Next) { IP_ADAPTER_UNICAST_ADDRESS *addr; WCHAR physaddr_buf[3 * MAX_ADAPTER_ADDRESS_LENGTH]; IP_ADAPTER_GATEWAY_ADDRESS_LH *gateway; WCHAR addr_buf[54]; ipconfig_message_printfW(STRING_ADAPTER_FRIENDLY, iftype_to_string(p->IfType), p->FriendlyName); ipconfig_printfW(newlineW); print_field(STRING_CONN_DNS_SUFFIX, p->DnsSuffix); print_field(STRING_DESCRIPTION, p->Description); print_field(STRING_PHYS_ADDR, physaddr_to_string(physaddr_buf, p->PhysicalAddress, p->PhysicalAddressLength)); print_field(STRING_DHCP_ENABLED, boolean_to_string(p->Flags & IP_ADAPTER_DHCP_ENABLED)); /* FIXME: Output autoconfiguration status. */ for (addr = p->FirstUnicastAddress; addr; addr = addr->Next) { if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &addr->Address)) print_field(STRING_IP_ADDRESS, addr_buf); /* FIXME: Output corresponding subnet mask. */ } if (p->FirstGatewayAddress) { if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &p->FirstGatewayAddress->Address)) print_field(STRING_DEFAULT_GATEWAY, addr_buf); for (gateway = p->FirstGatewayAddress->Next; gateway; gateway = gateway->Next) { if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &gateway->Address)) print_value(addr_buf); } } else print_field(STRING_DEFAULT_GATEWAY, emptyW); ipconfig_printfW(newlineW); } } HeapFree(GetProcessHeap(), 0, adapters); } }
static void advertising_packet(const void *data, uint8_t size) { const uint8_t *ptr = data; uint8_t pdu_type, length, win_size, hop, sca; bool tx_add, rx_add; uint32_t access_addr, crc_init; uint16_t win_offset, interval, latency, timeout; const char *str; if (size < 2) { print_text(COLOR_ERROR, "packet too short"); packet_hexdump(data, size); return; } pdu_type = ptr[0] & 0x0f; tx_add = !!(ptr[0] & 0x40); rx_add = !!(ptr[0] & 0x80); length = ptr[1] & 0x3f; switch (pdu_type) { case 0x00: str = "ADV_IND"; break; case 0x01: str = "ADV_DIRECT_IND"; break; case 0x02: str = "ADV_NONCONN_IND"; break; case 0x03: str = "SCAN_REQ"; break; case 0x04: str = "SCAN_RSP"; break; case 0x05: str = "CONNECT_REQ"; break; case 0x06: str = "ADV_SCAN_IND"; break; default: str = "Reserved"; break; } print_field("Type: %s (0x%2.2x)", str, pdu_type); print_field("TxAdd: %u", tx_add); print_field("RxAdd: %u", rx_add); print_field("Length: %u", length); if (length != size - 2) { print_text(COLOR_ERROR, "packet size mismatch"); packet_hexdump(data + 2, size - 2); return; } switch (pdu_type) { case 0x00: /* ADV_IND */ case 0x02: /* AVD_NONCONN_IND */ case 0x06: /* ADV_SCAN_IND */ case 0x04: /* SCAN_RSP */ if (length < 6) { print_text(COLOR_ERROR, "payload too short"); packet_hexdump(data + 2, length); return; } packet_print_addr("Advertiser address", data + 2, tx_add); packet_print_ad(data + 8, length - 6); break; case 0x01: /* ADV_DIRECT_IND */ if (length < 12) { print_text(COLOR_ERROR, "payload too short"); packet_hexdump(data + 2, length); return; } packet_print_addr("Advertiser address", data + 2, tx_add); packet_print_addr("Inititator address", data + 8, rx_add); break; case 0x03: /* SCAN_REQ */ if (length < 12) { print_text(COLOR_ERROR, "payload too short"); packet_hexdump(data + 2, length); return; } packet_print_addr("Scanner address", data + 2, tx_add); packet_print_addr("Advertiser address", data + 8, rx_add); break; case 0x05: /* CONNECT_REQ */ if (length < 34) { print_text(COLOR_ERROR, "payload too short"); packet_hexdump(data + 2, length); return; } packet_print_addr("Inititator address", data + 2, tx_add); packet_print_addr("Advertiser address", data + 8, rx_add); access_addr = ptr[14] | ptr[15] << 8 | ptr[16] << 16 | ptr[17] << 24; crc_init = ptr[18] | ptr[19] << 8 | ptr[20] << 16; print_field("Access address: 0x%8.8x", access_addr); print_field("CRC init: 0x%6.6x", crc_init); set_crc_init(access_addr, crc24_bit_reverse(crc_init)); win_size = ptr[21]; win_offset = ptr[22] | ptr[23] << 8; interval = ptr[24] | ptr[25] << 8; latency = ptr[26] | ptr[27] << 8; timeout = ptr[28] | ptr[29] << 8; print_field("Transmit window size: %u", win_size); print_field("Transmit window offset: %u", win_offset); print_field("Connection interval: %u", interval); print_field("Connection slave latency: %u", latency); print_field("Connection supervision timeout: %u", timeout); packet_print_channel_map_ll(ptr + 30); hop = ptr[35] & 0x1f; sca = (ptr[35] & 0xe0) >> 5; switch (sca) { case 0: str = "251 ppm to 500 ppm"; break; case 1: str = "151 ppm to 250 ppm"; break; case 2: str = "101 ppm to 150ppm"; break; case 3: str = "76 ppm to 100 ppm"; break; case 4: str = "51 ppm to 75 ppm"; break; case 5: str = "31 ppm to 50 ppm"; break; case 6: str = "21 ppm to 30 ppm"; break; case 7: str = "0 ppm to 20 ppm"; break; default: str = "Invalid"; break; } print_field("Hop increment: %u", hop); print_field("Sleep clock accuracy: %s (%u)", str, sca); break; default: packet_hexdump(data + 2, length); break; } }
ui_event uiprocessdialogevent( ui_event ui_ev, a_dialog *ui_dlg_info ) { VFIELD *field; a_check *check; an_edit_control *edit; unsigned choice; a_combo_box *combo; a_list *list; ui_ev = uicheckmove( ui_ev, ui_dlg_info ); ui_ev = uitabkey( ui_ev, ui_dlg_info ); field = ui_dlg_info->curr; if( field != NULL ) { switch( field->typ ) { case FLD_CHECK: case FLD_RADIO: switch( ui_ev ) { case EV_MOUSE_DCLICK: case EV_MOUSE_PRESS: case ' ' : ui_ev = EV_CHECK_BOX_CLICK; if( field->typ == FLD_RADIO ) { do_radio( ui_dlg_info, field ); break; } if( field->typ == FLD_CHECK ) { ui_dlg_info->dirty = true; check = field->u.check; check->val = !check->val; print_field( ui_dlg_info->vs, field, true ); break; } } break; case FLD_EDIT: case FLD_INVISIBLE_EDIT: ui_ev = uiledit( ui_ev ); edit = field->u.edit; if( ui_dlg_info->edit_data != NULL ) { edit->buffer = ui_dlg_info->edit_data->edit_buffer; edit->length = ui_dlg_info->edit_data->edit_eline.length; } break; case FLD_LISTBOX: case FLD_EDIT_MLE: list = field->u.list; ui_ev = uilistbox( ui_ev, list, true ); break; case FLD_PULLDOWN: list = field->u.list; if( list->box == NULL ) { ui_ev = pulldownfilter( ui_ev, ui_dlg_info ); } else { choice = list->choice; ui_ev = uilistbox( ui_ev, list, false ); if( choice != list->choice ) { ui_dlg_info->dirty = true; print_field( ui_dlg_info->vs, field, true ); } } break; case FLD_COMBOBOX: combo = field->u.combo; list = &combo->list; edit = &combo->edit; if( list->box == NULL ) { ui_ev = pulldownfilter( ui_ev, ui_dlg_info ); } else { choice = list->choice; ui_ev = uilistbox( ui_ev, list, combo->perm ); if( choice != list->choice ) { ui_dlg_info->dirty = true; setcombobuffer( ui_dlg_info, field ); print_field( ui_dlg_info->vs, field, true ); } } ui_ev = uiledit( ui_ev ); if( ui_dlg_info->edit_data != NULL ) { edit->buffer = ui_dlg_info->edit_data->edit_buffer; edit->length = ui_dlg_info->edit_data->edit_eline.length; } break; } } ui_ev = uihotkeyfilter( ui_dlg_info, ui_ev ); ui_ev = uihotspotfilter( ui_dlg_info->vs, ui_dlg_info->fields, ui_ev ); return( ui_ev ); }
EVENT uiprocessdialogevent( EVENT ev, a_dialog *info ) { VFIELD *field; a_check *check; an_edit_control *edit; unsigned choice; a_combo_box *combo; a_list *list; ev = uicheckmove( ev, info ); ev = uitabkey( ev, info ); field = info->curr; if( field != NULL ) { switch( field->typ ) { case FLD_CHECK: case FLD_RADIO: switch( ev ) { case EV_MOUSE_DCLICK: case EV_MOUSE_PRESS: case ' ' : ev = EV_CHECK_BOX_CLICK; if( field->typ == FLD_RADIO ) { do_radio( info, field ); break; } if( field->typ == FLD_CHECK ) { info->dirty = TRUE; check = field->ptr; check->val = !check->val; print_field( info->vs, field, TRUE ); break; } } break; case FLD_EDIT: case FLD_INVISIBLE_EDIT: ev = uiledit( ev ); edit = field->ptr; if( info->edit_data != NULL ) { edit->buffer = info->edit_data->edit_buffer; edit->length = info->edit_data->edit_eline.length; } break; case FLD_LISTBOX: case FLD_EDIT_MLE: list = field->ptr; ev = uilistbox( ev, list, TRUE ); break; case FLD_PULLDOWN: list = field->ptr; if( list->box == NULL ) { ev = pulldownfilter( ev, info ); } else { choice = list->choice; ev = uilistbox( ev, list, FALSE ); if( choice != list->choice ) { info->dirty = TRUE; print_field( info->vs, field, TRUE ); } } break; case FLD_COMBOBOX: combo = field->ptr; list = &combo->list; edit = &combo->edit; if( list->box == NULL ) { ev = pulldownfilter( ev, info ); } else { choice = list->choice; ev = uilistbox( ev, list, combo->perm ); if( choice != list->choice ) { info->dirty = TRUE; setcombobuffer( info, field ); print_field( info->vs, field, TRUE ); } } ev = uiledit( ev ); if( info->edit_data != NULL ) { edit->buffer = info->edit_data->edit_buffer; edit->length = info->edit_data->edit_eline.length; } break; } } ev = uihotkeyfilter( info, ev ); ev = uihotspotfilter( info->vs, info->fields, ev ); return( ev ); }
static ui_event pulldownfilter( ui_event ui_ev, a_dialog *ui_dlg_info ) { a_list *list = NULL; a_combo_box *combo; VSCREEN *vs; SAREA area; VFIELD *fld; fld = ui_dlg_info->curr; if( fld->typ == FLD_PULLDOWN ) { list = fld->u.list; } else if( fld->typ == FLD_COMBOBOX ) { combo = fld->u.combo; list = &combo->list; } switch( ui_ev ) { case EV_MOUSE_DCLICK: case EV_MOUSE_PRESS: { ORD row, col; uivmousepos( ui_dlg_info->vs, &row, &col ); area = fld->area; area.width += 1; /* extra column for button */ if( fld->typ == FLD_COMBOBOX ) { /* mouse press must be on little button at right */ area.col += area.width; area.width = 1; } if( fld->typ == FLD_COMBOBOX || fld->typ == FLD_PULLDOWN ) { /* mouse press must be on top line */ area.height = 1; } if( row < area.row || row >= area.row + area.height ) break; if( col < area.col || col >= area.col + area.width ) { break; } /* FALLS into next case */ } case EV_CURSOR_DOWN: case EV_ALT_CURSOR_DOWN: /* list->box must be null */ area = fld->area; vs = ui_dlg_info->vs; area.row += ( vs->area.row + 2 ); area.col += vs->area.col; if( fld->typ == FLD_COMBOBOX ) { area.col++; } if( area.row + area.height >= UIData->height ) { area.row -= area.height + 3; } vs = uiopen( &area, NULL, V_DIALOGUE | V_LISTBOX ); area.row = 0; area.col = 0; list->box = uibeglistbox( vs, &area, list ); if( ui_ev != EV_MOUSE_PRESS && ui_ev != EV_MOUSE_DCLICK && fld->typ == FLD_COMBOBOX ) { ui_dlg_info->dirty = true; setcombobuffer( ui_dlg_info, fld ); print_field( ui_dlg_info->vs, fld, true ); } break; } return( ui_ev ); }
EVENT pulldownfilter( EVENT ev, a_dialog *info ) { a_list *list = NULL; a_combo_box *combo; VSCREEN *vs; SAREA area; VFIELD *fld; fld = info->curr; if( fld->typ == FLD_PULLDOWN ) { list = fld->ptr; } else if( fld->typ == FLD_COMBOBOX ) { combo = fld->ptr; list = &combo->list; } if( list->get == NULL ) { list->get = ( bool (*) ( void *, unsigned, char *, unsigned ) ) uigetlistelement; // set get_element function } switch( ev ) { case EV_MOUSE_DCLICK: case EV_MOUSE_PRESS: { ORD row, col; uivmousepos( info->vs, &row, &col ); area = fld->area; area.width += 1; /* extra column for button */ if( fld->typ == FLD_COMBOBOX ) { /* mouse press must be on little button at right */ area.col += area.width; area.width = 1; } if( fld->typ == FLD_COMBOBOX || fld->typ == FLD_PULLDOWN ) { /* mouse press must be on top line */ area.height = 1; } if( row < area.row || row >= area.row + area.height ) break; if( col < area.col || col >= area.col + area.width ) break; /* FALLS into next case */ } case EV_CURSOR_DOWN: case EV_ALT_CURSOR_DOWN: /* list->box must be null */ area = fld->area; vs = info->vs; area.row += ( vs->area.row + 2 ); area.col += vs->area.col; if( fld->typ == FLD_COMBOBOX ) { area.col++; } if( area.row + area.height >= UIData->height ) { area.row -= area.height + 3; } vs = uiopen( &area, NULL, V_DIALOGUE | V_LISTBOX ); area.row = 0; area.col = 0; list->box = uibeglistbox( vs, &area, list ); if( ev != EV_MOUSE_PRESS && ev != EV_MOUSE_DCLICK && fld->typ == FLD_COMBOBOX ) { info->dirty = TRUE; setcombobuffer( info, fld ); print_field( info->vs, fld, TRUE ); } break; } return( ev ); }
error_code_t print_mem(lnf_mem_t *mem, size_t limit) { lnf_rec_t *rec; //record = line size_t rec_cntr = 0; //aka lines counter lnf_mem_cursor_t *cursor; //current record (line) cursor size_t fld_max_size = 0; //maximum data size length in bytes size_t data_max_strlen[LNF_FLD_TERM_] = {0}; //maximum data string len if (output_params.print_records != OUTPUT_ITEM_YES) { return E_OK; } first_item = first_item ? false : (putchar('\n'), false); secondary_errno = lnf_rec_init(&rec); if (secondary_errno != LNF_OK) { print_err(E_LNF, secondary_errno, "lnf_rec_init()"); return E_LNF; } /* * Find out maximum data type size of present fields, length of headers * and last present field ID. */ for (size_t i = 0; i < fields_cnt; ++i) { size_t header_str_len = strlen(field_get_name(fields[i].id)); MAX_ASSIGN(fld_max_size, fields[i].size); MAX_ASSIGN(data_max_strlen[fields[i].id], header_str_len); } /* Find out max data length, converted to string. */ lnf_mem_first_c(mem, &cursor); while (cursor != NULL) { //row loop char buff[fld_max_size]; lnf_mem_read_c(mem, cursor, rec); for (size_t i = 0; i < fields_cnt; ++i) { //column loop size_t data_str_len; //XXX: lnf_rec_fget() may return LNF_ERR_UNKFLD even if //field is present (e.g. if duration is zero). lnf_rec_fget(rec, fields[i].id, buff); data_str_len = strlen(field_to_str(fields[i].id, buff)); MAX_ASSIGN(data_max_strlen[fields[i].id], data_str_len); } if (++rec_cntr == limit) { break; } lnf_mem_next_c(mem, &cursor); } rec_cntr = 0; /* Actual printing: header. */ for (size_t i = 0; i < fields_cnt; ++i) { //column loop print_field(field_get_name(fields[i].id), data_max_strlen[fields[i].id], PRETTY_PRINT_COL_WIDTH, i == (fields_cnt - 1)); } /* Actual printing: field data converted to string. */ lnf_mem_first_c(mem, &cursor); while (cursor != NULL) { //row loop char buff[fld_max_size]; lnf_mem_read_c(mem, cursor, rec); for (size_t i = 0; i < fields_cnt; ++i) { //column loop //XXX: see above lnf_rec_fget() lnf_rec_fget(rec, fields[i].id, buff); print_field(field_to_str(fields[i].id, buff), data_max_strlen[fields[i].id], PRETTY_PRINT_COL_WIDTH, i == (fields_cnt - 1)); } if (++rec_cntr == limit) { break; } lnf_mem_next_c(mem, &cursor); } lnf_rec_free(rec); return E_OK; }