static void dump_menu (FILE *f, int menu) { struct keymap_t *map; const struct binding_t *b; char buf[SHORT_STRING]; /* browse through the keymap table */ for (map = Keymaps[menu]; map; map = map->next) { if (map->op != OP_NULL) { km_expand_key (buf, sizeof (buf), map); if (map->op == OP_MACRO) { if (map->descr == NULL) format_line (f, -1, buf, "macro", map->macro); else format_line (f, 1, buf, map->macro, map->descr); } else { b = help_lookupFunction (map->op, menu); format_line (f, 0, buf, b ? b->name : "UNKNOWN", b ? _(HelpStrings[b->op]) : _("ERROR: please report this bug")); } } } }
string Timevault::text(bool detailed) { stringstream header, details, summary; time_t elapsed_total = 0; size_t samples_total = 0; header << endl; header << " Identifier" << setw(width-11) << "|"; header << " Samples " << "|"; header << " Elapsed " << "|"; header << " Average " << endl; header << format_line('=', '+'); // // Iterate over identifiers for(multimap<string, time_t>::iterator it=_elapsed.begin(); it!=_elapsed.end(); it=_elapsed.upper_bound(it->first)) { pair<multimap<string, time_t>::iterator, multimap<string, time_t>::iterator> ret; ret = _elapsed.equal_range((*it).first); // // Accumulate elapsed time for each identifier and count amount of samples time_t acc = 0; size_t samples = 0; for(multimap<string, time_t>::iterator inner=ret.first; inner!=ret.second; ++inner) { samples++; acc += (*inner).second; details << format_row((*inner).first, (*inner).second, 1) << endl; } elapsed_total += acc; samples_total += samples; // // Create textual representation details << format_line('-', '+'); details << format_row("Subtotal", acc, samples) << endl << endl; summary << format_row((*it).first, acc, samples) << endl; } summary << format_line('=', '+'); summary << format_row("Total", elapsed_total, samples_total) << endl; if (detailed) { return header.str() + details.str() + header.str() + summary.str(); } else { return header.str() + summary.str(); } }
int list_column_dir(char *dir, t_opt *t) { DIR *d; struct dirent *e; struct stat s; char *file; if (!(d = get_dir_ptr(dir))) return (1); my_printf("Total : %d\n", get_total_blocks(dir)); while ((e = readdir(d))) { file = format_dir(dir, e->d_name); if (e->d_name[0] != '.') { if (stat(file, &s) == -1) { closedir(d); return (1); } format_line(e->d_name, &s, t); } free(file); } closedir(d); my_printf("\n\n"); return (0); }
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, char *line, int line_size, int *print_prefix) { char part[3][LINE_SZ]; format_line(ptr, level, fmt, vl, part, sizeof(part[0]), print_prefix, NULL); snprintf(line, line_size, "%s%s%s", part[0], part[1], part[2]); }
static char *vbackends_show_json(char *raw) { char *out1 = NULL, *out2 = NULL, *out3 = NULL ; struct vsb *final= VSB_new_auto(); char *tokens = NULL, *ptr = NULL; char tmp[1000]; int raw_len = 0; int state = 0; int cont = 0; int sum = 0; raw_len = strlen(raw); tokens = strtok(raw, "\n"); sum = sum + strlen(tokens); while(tokens != NULL){ strcpy(tmp, (tokens)); tokens = strtok(NULL, "\n"); sum = sum + strlen(tmp); if(cont > 0){ ptr = format_line(tmp); VSB_cat(final, ptr); if(sum < raw_len) VSB_cat(final, ",\n"); free(ptr); } cont++; }
static void vbackends_show_json(struct vsb *json, char *raw) { char *tokens = NULL, *ptr = NULL; char tmp[1000]; int raw_len = 0; int cont = 0; int sum = 0; raw_len = strlen(raw); tokens = strtok(raw, "\n"); sum = sum + strlen(tokens); VSB_cat(json, "{\n \"backends\" : [\n"); while(tokens != NULL){ strcpy(tmp, (tokens)); tokens = strtok(NULL, "\n"); sum = sum + strlen(tmp); if(cont > 0){ ptr = format_line(tmp); VSB_cat(json, ptr); if(sum < raw_len) VSB_cat(json, ",\n"); free(ptr); } cont++; } VSB_cat(json, "\n]\n}\n"); }
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, char *line, int line_size, int *print_prefix) { AVBPrint part[3]; format_line(ptr, level, fmt, vl, part, print_prefix, NULL); snprintf(line, line_size, "%s%s%s", part[0].str, part[1].str, part[2].str); av_bprint_finalize(part+2, NULL); }
void logger_c::log_line(std::string const &message) { try { mm_text_io_c out(new mm_file_io_c(m_file_name.string(), bfs::exists(m_file_name) ? MODE_WRITE : MODE_CREATE)); out.setFilePointer(0, seek_end); out.puts(format_line(message)); } catch (mtx::mm_io::exception &ex) { } }
void main(int argc) { get_bin_cluster_id(); format_line(); while (1) { add_key_input(); send_display(buffer); /* give pointer to assembly function */ } }
int main(void) { int c; char sentence[MAX_LINE_SIZE]; while((c = format_line(sentence, MAX_LINE_SIZE)) != EOF) if(c != '\n') printf("Inverted sentence: %s\n",sentence); return 0; }
static void dump_unbound (FILE *f, const struct binding_t *funcs, struct keymap_t *map, struct keymap_t *aux) { int i; for (i = 0; funcs[i].name; i++) { if (! is_bound (map, funcs[i].op) && (!aux || ! is_bound (aux, funcs[i].op))) format_line (f, 0, funcs[i].name, "", _(HelpStrings[funcs[i].op])); } }
static const char* playlist_callback_name(int selected_item, void *data, char *buffer, size_t buffer_len) { struct playlist_viewer *local_viewer = (struct playlist_viewer *)data; int track_num = get_track_num(local_viewer, selected_item); struct playlist_entry *track = playlist_buffer_get_track(&(local_viewer->buffer), track_num); format_line(track, buffer, buffer_len); return(buffer); }
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix = 1; static int count; static char prev[LINE_SZ]; AVBPrint part[3]; char line[LINE_SZ]; static int is_atty; int type[2]; if (level > av_log_level) return; #if HAVE_PTHREADS pthread_mutex_lock(&mutex); #endif format_line(ptr, level, fmt, vl, part, &print_prefix, type); snprintf(line, sizeof(line), "%s%s%s", part[0].str, part[1].str, part[2].str); #if HAVE_ISATTY if (!is_atty) is_atty = isatty(2) ? 1 : -1; #endif if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev) && *line && line[strlen(line) - 1] != '\r'){ count++; if (is_atty == 1) fprintf(stderr, " Last message repeated %d times\r", count); goto end; } if (count > 0) { fprintf(stderr, " Last message repeated %d times\n", count); count = 0; } strcpy(prev, line); sanitize(part[0].str); colored_fputs(type[0], part[0].str); sanitize(part[1].str); colored_fputs(type[1], part[1].str); sanitize(part[2].str); colored_fputs(av_clip(level >> 3, 0, 6), part[2].str); end: av_bprint_finalize(part+2, NULL); #if HAVE_PTHREADS pthread_mutex_unlock(&mutex); #endif }
void add_key_input() { char input = 0; input = read_key(); /* blocking */ if (input == '\n') { process_command(); next_line(); format_line(); } else if (input == 0x7f) {// backspace if (current_column > 2) { current_column -= 1; buffer[C(current_line, current_column)] = 0; } } else if (input != 0) { put_char(input); } }
/* * updateline() - like s_refresh() but only for cursor line * * This determines whether or not we need to call s_refresh() to examine * the entire screen for changes. This occurs if the size of the cursor line * (in rows) has changed. */ static void updateline(void) { char *ptr; int col; int size; int j; if (RedrawingDisabled) /* Is this the correct action ? */ return; ptr = format_line(Curschar->linep->s, &col); size = 1 + ((col - 1) / Columns); if (Cline_size == size) { s_cursor_off(); windgoto(Cline_row, 0); if (P(P_NU)) { /* * This should be done more efficiently. */ outstr(mkline(cntllines(Filemem, Curschar))); } outstr(ptr); j = col; col %= Columns; if ((col != 0) || (j == 0)) { #ifdef T_END_L windgoto(Cline_row + size - 1, col); toutstr(T_END_L); #else for (; col < Columns; col++) outchar(' '); #endif } s_cursor_on(); } else { s_refresh(VALID_TO_CURSCHAR); } }
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix = 1; static int count; static char prev[1024]; char part[3][512]; char line[1024]; static int is_atty; int type[2]; if (level > av_log_level) return; format_line(ptr, level, fmt, vl, part, sizeof(part[0]), &print_prefix, type); snprintf(line, sizeof(line), "%s%s%s", part[0], part[1], part[2]); #if HAVE_ISATTY if (!is_atty) is_atty = isatty(2) ? 1 : -1; #endif #undef fprintf if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ count++; if (is_atty == 1) fprintf(stderr, " Last message repeated %d times\r", count); return; } if (count > 0) { fprintf(stderr, " Last message repeated %d times\n", count); count = 0; } strcpy(prev, line); sanitize(part[0]); colored_fputs(type[0], part[0]); sanitize(part[1]); colored_fputs(type[1], part[1]); sanitize(part[2]); colored_fputs(av_clip(level >> 3, 0, 6), part[2]); }
void run_test(int NUM_TESTS, std::vector<int> NUM_POINTS, std::vector<int> NUM_RUNS) { for (int i = 0; i < NUM_TESTS; ++i) { kdtree::KDTree<Point> tr(2); for(int k=0; k<NUM_POINTS[i]; k++) { double x = ((float)rand() / RAND_MAX) * 200.0 - 100.0; double y = ((float)rand() / RAND_MAX) * 200.0 - 100.0; Point p(x,y); tr.insert( p ); } timer.restart(); for (int j = 0; j < NUM_RUNS[i]; ++j) { double x = ((float)rand() / RAND_MAX) * 200.0 - 100.0; double y = ((float)rand() / RAND_MAX) * 200.0 - 100.0; Point ps(x,y); std::pair<Point,double> pt = tr.nearest( ps ); } double total_time = timer.elapsed(); double time_per_test = total_time / NUM_RUNS[i]; format_line(NUM_POINTS[i], NUM_RUNS[i], total_time, time_per_test); } }
void print_list(My402List *list) { print_title(); My402ListElem * elem = NULL; int balance_value = 0, amount_value = 0; for (elem = My402ListFirst(list); elem != NULL; elem = My402ListNext(list, elem)) { My402TransData * data = (My402TransData *)(elem -> obj); char line[LINE_LENGTH + 1], buffer[26]; time_t timestamp; timestamp = data -> timestamp; strncpy(buffer, ctime(×tamp), sizeof(buffer)); format_line(line); format_time(line, buffer, 2); format_description(line, data -> description, 19); amount_value = cal_amount(data -> amount, data -> type); format_money(line, amount_value, 46, 61); balance_value = cal_balance(balance_value, data -> amount, data -> type); format_money(line, balance_value, 63, 78); fprintf(stdout, "%s\n", line); } print_line(); }
StringPtr WebInterface::generate_main_page() { StringPtr page(new std::string); ctemplate::TemplateDictionary dict("main"); LOG_DBG("Generating main page!"); ConsoleLinePtrDequePtr lines = application_interface_->get_output_message(); dict[KW_TITLE] = page_title_ + " - Console interface"; dict[KW_HEAD] = (format_head(lines->front()->get_time(), lines->back()->get_time(), URI_PAGE_CL)->str()); dict[KW_CONTENT] = (format_line(lines)->str()); dict[KW_MENU] = (format_menu(URI_PAGE_MAIN)->str()); dict.ShowSection(KW_SECTION_INPUT); LOG_DBG("Expanding template: %s", get_home_folder_path(template_name_).c_str()); ctemplate::ExpandTemplate(get_home_folder_path(template_name_), ctemplate::DO_NOT_STRIP, &dict, page.get()); LOG_DBG("Main page size: %lu", page->size()); return page; }
void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) { static const unsigned short spaces_total = 19; if (*buf) { free(*buf); *buf = NULL; } // Report on total logging, current and for all time android::String8 output("size/num"); size_t oldLength; short spaces = 1; log_id_for_each(id) { if (!(logMask & (1 << id))) { continue; } oldLength = output.length(); if (spaces < 0) { spaces = 0; } output.appendFormat("%*s%s", spaces, "", android_log_id_to_name(id)); spaces += spaces_total + oldLength - output.length(); } spaces = 4; output.appendFormat("\nTotal"); log_id_for_each(id) { if (!(logMask & (1 << id))) { continue; } oldLength = output.length(); if (spaces < 0) { spaces = 0; } output.appendFormat("%*s%zu/%zu", spaces, "", sizesTotal(id), elementsTotal(id)); spaces += spaces_total + oldLength - output.length(); } spaces = 6; output.appendFormat("\nNow"); log_id_for_each(id) { if (!(logMask & (1 << id))) { continue; } size_t els = elements(id); if (els) { oldLength = output.length(); if (spaces < 0) { spaces = 0; } output.appendFormat("%*s%zu/%zu", spaces, "", sizes(id), els); spaces -= output.length() - oldLength; } spaces += spaces_total; } // Report on Chattiest // Chattiest by application (UID) static const size_t maximum_sorted_entries = 32; log_id_for_each(id) { if (!(logMask & (1 << id))) { continue; } bool headerPrinted = false; std::unique_ptr<const UidEntry *[]> sorted = sort(maximum_sorted_entries, id); ssize_t index = -1; while ((index = uidTable_t::next(index, sorted, maximum_sorted_entries)) >= 0) { const UidEntry *entry = sorted[index]; uid_t u = entry->getKey(); if ((uid != AID_ROOT) && (u != uid)) { continue; } if (!headerPrinted) { if (uid == AID_ROOT) { output.appendFormat( "\n\nChattiest UIDs in %s:\n", android_log_id_to_name(id)); } else { output.appendFormat( "\n\nLogging for your UID in %s:\n", android_log_id_to_name(id)); } android::String8 name("UID"); android::String8 size("Size"); android::String8 pruned("Pruned"); if (!worstUidEnabledForLogid(id)) { pruned.setTo(""); } format_line(output, name, size, pruned); headerPrinted = true; } android::String8 name(""); name.appendFormat("%u", u); char *n = uidToName(u); if (n) { name.appendFormat("%*s%s", (int)std::max(6 - name.length(), (size_t)1), "", n); free(n); } android::String8 size(""); size.appendFormat("%zu", entry->getSizes()); android::String8 pruned(""); size_t dropped = entry->getDropped(); if (dropped) { pruned.appendFormat("%zu", dropped); } format_line(output, name, size, pruned); } } if (enable) { bool headerPrinted = false; std::unique_ptr<const PidEntry *[]> sorted = pidTable.sort(maximum_sorted_entries); ssize_t index = -1; while ((index = pidTable.next(index, sorted, maximum_sorted_entries)) >= 0) { const PidEntry *entry = sorted[index]; uid_t u = entry->getUid(); if ((uid != AID_ROOT) && (u != uid)) { continue; } if (!headerPrinted) { if (uid == AID_ROOT) { output.appendFormat("\n\nChattiest PIDs:\n"); } else { output.appendFormat("\n\nLogging for this PID:\n"); } android::String8 name(" PID/UID"); android::String8 size("Size"); android::String8 pruned("Pruned"); format_line(output, name, size, pruned); headerPrinted = true; } android::String8 name(""); name.appendFormat("%5u/%u", entry->getKey(), u); const char *n = entry->getName(); if (n) { name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", n); } else { char *un = uidToName(u); if (un) { name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", un); free(un); } } android::String8 size(""); size.appendFormat("%zu", entry->getSizes()); android::String8 pruned(""); size_t dropped = entry->getDropped(); if (dropped) { pruned.appendFormat("%zu", dropped); } format_line(output, name, size, pruned); } } *buf = strdup(output.string()); }
void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) { static const unsigned short spaces_total = 19; if (*buf) { free(*buf); *buf = NULL; } // Report on total logging, current and for all time android::String8 output("size/num"); size_t oldLength; short spaces = 1; log_id_for_each(id) { if (!(logMask & (1 << id))) { continue; } oldLength = output.length(); if (spaces < 0) { spaces = 0; } output.appendFormat("%*s%s", spaces, "", android_log_id_to_name(id)); spaces += spaces_total + oldLength - output.length(); } spaces = 4; output.appendFormat("\nTotal"); log_id_for_each(id) { if (!(logMask & (1 << id))) { continue; } oldLength = output.length(); if (spaces < 0) { spaces = 0; } output.appendFormat("%*s%zu/%zu", spaces, "", sizesTotal(id), elementsTotal(id)); spaces += spaces_total + oldLength - output.length(); } spaces = 6; output.appendFormat("\nNow"); log_id_for_each(id) { if (!(logMask & (1 << id))) { continue; } size_t els = elements(id); if (els) { oldLength = output.length(); if (spaces < 0) { spaces = 0; } output.appendFormat("%*s%zu/%zu", spaces, "", sizes(id), els); spaces -= output.length() - oldLength; } spaces += spaces_total; } // Report on Chattiest // Chattiest by application (UID) static const size_t maximum_sorted_entries = 32; log_id_for_each(id) { if (!(logMask & (1 << id))) { continue; } bool headerPrinted = false; std::unique_ptr<const UidEntry *[]> sorted = sort(maximum_sorted_entries, id); ssize_t index = -1; while ((index = uidTable_t::next(index, sorted, maximum_sorted_entries)) >= 0) { const UidEntry *entry = sorted[index]; uid_t u = entry->getKey(); if ((uid != AID_ROOT) && (u != uid)) { continue; } if (!headerPrinted) { output.appendFormat("\n\n"); android::String8 name(""); if (uid == AID_ROOT) { name.appendFormat( "Chattiest UIDs in %s log buffer:", android_log_id_to_name(id)); } else { name.appendFormat( "Logging for your UID in %s log buffer:", android_log_id_to_name(id)); } android::String8 size("Size"); android::String8 pruned("Pruned"); if (!worstUidEnabledForLogid(id)) { pruned.setTo(""); } format_line(output, name, size, pruned); name.setTo("UID PACKAGE"); size.setTo("BYTES"); pruned.setTo("LINES"); if (!worstUidEnabledForLogid(id)) { pruned.setTo(""); } format_line(output, name, size, pruned); headerPrinted = true; } android::String8 name(""); name.appendFormat("%u", u); char *n = uidToName(u); if (n) { name.appendFormat("%*s%s", (int)std::max(6 - name.length(), (size_t)1), "", n); free(n); } android::String8 size(""); size.appendFormat("%zu", entry->getSizes()); android::String8 pruned(""); size_t dropped = entry->getDropped(); if (dropped) { pruned.appendFormat("%zu", dropped); } format_line(output, name, size, pruned); } } if (enable) { // Pid table bool headerPrinted = false; std::unique_ptr<const PidEntry *[]> sorted = pidTable.sort(maximum_sorted_entries); ssize_t index = -1; while ((index = pidTable.next(index, sorted, maximum_sorted_entries)) >= 0) { const PidEntry *entry = sorted[index]; uid_t u = entry->getUid(); if ((uid != AID_ROOT) && (u != uid)) { continue; } if (!headerPrinted) { output.appendFormat("\n\n"); android::String8 name(""); if (uid == AID_ROOT) { name.appendFormat("Chattiest PIDs:"); } else { name.appendFormat("Logging for this PID:"); } android::String8 size("Size"); android::String8 pruned("Pruned"); format_line(output, name, size, pruned); name.setTo(" PID/UID COMMAND LINE"); size.setTo("BYTES"); pruned.setTo("LINES"); format_line(output, name, size, pruned); headerPrinted = true; } android::String8 name(""); name.appendFormat("%5u/%u", entry->getKey(), u); const char *n = entry->getName(); if (n) { name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", n); } else { char *un = uidToName(u); if (un) { name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", un); free(un); } } android::String8 size(""); size.appendFormat("%zu", entry->getSizes()); android::String8 pruned(""); size_t dropped = entry->getDropped(); if (dropped) { pruned.appendFormat("%zu", dropped); } format_line(output, name, size, pruned); } } if (enable) { // Tid table bool headerPrinted = false; // sort() returns list of references, unique_ptr makes sure self-delete std::unique_ptr<const TidEntry *[]> sorted = tidTable.sort(maximum_sorted_entries); ssize_t index = -1; while ((index = tidTable.next(index, sorted, maximum_sorted_entries)) >= 0) { const TidEntry *entry = sorted[index]; uid_t u = entry->getUid(); if ((uid != AID_ROOT) && (u != uid)) { continue; } if (!headerPrinted) { // Only print header if we have table to print output.appendFormat("\n\n"); android::String8 name("Chattiest TIDs:"); android::String8 size("Size"); android::String8 pruned("Pruned"); format_line(output, name, size, pruned); name.setTo(" TID/UID COMM"); size.setTo("BYTES"); pruned.setTo("LINES"); format_line(output, name, size, pruned); headerPrinted = true; } android::String8 name(""); name.appendFormat("%5u/%u", entry->getKey(), u); const char *n = entry->getName(); if (n) { name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", n); } else { // if we do not have a PID name, lets punt to try UID name? char *un = uidToName(u); if (un) { name.appendFormat("%*s%s", (int)std::max(12 - name.length(), (size_t)1), "", un); free(un); } // We tried, better to not have a name at all, we still // have TID/UID by number to report in any case. } android::String8 size(""); size.appendFormat("%zu", entry->getSizes()); android::String8 pruned(""); size_t dropped = entry->getDropped(); if (dropped) { pruned.appendFormat("%zu", dropped); } format_line(output, name, size, pruned); } } if (enable && (logMask & (1 << LOG_ID_EVENTS))) { // Tag table bool headerPrinted = false; std::unique_ptr<const TagEntry *[]> sorted = tagTable.sort(maximum_sorted_entries); ssize_t index = -1; while ((index = tagTable.next(index, sorted, maximum_sorted_entries)) >= 0) { const TagEntry *entry = sorted[index]; uid_t u = entry->getUid(); if ((uid != AID_ROOT) && (u != uid)) { continue; } android::String8 pruned(""); if (!headerPrinted) { output.appendFormat("\n\n"); android::String8 name("Chattiest events log buffer TAGs:"); android::String8 size("Size"); format_line(output, name, size, pruned); name.setTo(" TAG/UID TAGNAME"); size.setTo("BYTES"); format_line(output, name, size, pruned); headerPrinted = true; } android::String8 name(""); if (u == (uid_t)-1) { name.appendFormat("%7u", entry->getKey()); } else { name.appendFormat("%7u/%u", entry->getKey(), u); } const char *n = entry->getName(); if (n) { name.appendFormat("%*s%s", (int)std::max(14 - name.length(), (size_t)1), "", n); } android::String8 size(""); size.appendFormat("%zu", entry->getSizes()); format_line(output, name, size, pruned); } } *buf = strdup(output.string()); }
/** * Search the pattern from the buffer as a specified encoding `t`. If matching string was found, * results will be added to `match_lines` list. This method do also scanning new lines, and count * up it. */ int search_buffer(const char *buf, size_t search_len, const char *pattern, int pattern_len, enum file_type t, char eol, size_t *line_count, char **last_new_line_scan_pos, match_line_list *match_lines, int thread_no) { match m; const char *p = buf; int after_count = 0; int match_count = 0; // Search the first pattern in the buffer. while (search_by(p, search_len, pattern, pattern_len, t, &m, thread_no)) { // Search head/end of the line, then calculate line length from them. int plen = m.end - m.start; size_t rest_len = search_len - m.start - plen + 1; const char *line_head = reverse_char(p, eol, m.start); char *line_end = memchr(p + m.start + plen, eol, rest_len); line_head = line_head == NULL ? p : line_head + 1; // Collect after context. const char *last_line_end_by_after = p; if (match_count > 0 && (op.after_context > 0 || op.context > 0)) { last_line_end_by_after = after_context(line_head, p, search_len, *line_count, match_lines, eol, &after_count); } // Count lines. if (op.show_line_number) { *last_new_line_scan_pos = scan_newline(*last_new_line_scan_pos, line_end, line_count, eol); } // Collect before context. if (op.before_context > 0 || op.context > 0) { before_context(buf, line_head, last_line_end_by_after, *line_count, match_lines, eol); } // Search next pattern in the current line and format them in order to print. m.start -= line_head - p; m.end = m.start + plen; match_count += format_line(line_head, line_end - line_head, pattern, plen, t, *line_count, &m, match_lines, thread_no); size_t diff = line_end - p + 1; if (search_len < diff) { break; } search_len -= diff; p = line_end + 1; } // Collect last after context. And calculate max line number in this file in order to do // padding line number on printing result. if (match_count > 0 && search_len > 0 && (op.after_context > 0 || op.context > 0)) { after_context(NULL, p, search_len, *line_count, match_lines, eol, &after_count); } match_lines->max_line_no = *line_count + after_count; return match_count; }
static void paint_dayview_appts(Calendar *c, Paint_cache *cache, int a_total, void *rect) { int w = c->view->boxw; int h = c->view->boxh; int begin_time, end_time; int x, x2, y, y2, num_hrs, i, last_hr, hr, x_off; Cal_Font *pf = c->fonts->boldfont; Cal_Font *pf2 = c->fonts->viewfont; XFontSetExtents fontextents; XFontSetExtents fontextents2; Props *p = (Props*)c->properties; Boolean am = True; char buf[5], *appt_str; int pfy, curr_line, maxlines; Lines *lines = NULL, *headlines = NULL; DisplayType disp_t; Colormap cmap; Pixel fg; Tick start_tick, end_tick; int nop, hrbox_margin; CalFontExtents(pf, &fontextents); CalFontExtents(pf2, &fontextents2); XtVaGetValues(c->canvas, XmNcolormap, &cmap, XmNforeground, &fg, NULL); /* draw horizontal lines */ begin_time = get_int_prop(p, CP_DAYBEGIN); end_time = get_int_prop(p, CP_DAYEND); disp_t = get_int_prop(p, CP_DEFAULTDISP); num_hrs = end_time - begin_time + 1; if (disp_t == HOUR12) CalTextExtents(pf, "12pm", 4, &nop, &nop, &hrbox_margin, &nop); else CalTextExtents(pf, "24 ", 3, &nop, &nop, &hrbox_margin, &nop); x = MOBOX_AREA_WIDTH+2; x2 = x + w; y = c->view->topoffset; for (i = 0; i <= num_hrs; i++) { gr_draw_line(c->xcontext, x, y, x2, y, gr_solid, rect); y += h; } /* draw vertical line */ y = c->view->topoffset; y2 = y + num_hrs * h; x += hrbox_margin; gr_draw_line(c->xcontext, x, y, x, y2, gr_solid, rect); x = MOBOX_AREA_WIDTH+3; y += h/2+4; /* draw in hours */ for (i = begin_time - 1; i < end_time; i++) { hr = i; if (i < begin_time) (void) sprintf(buf, ""); else if (disp_t == HOUR12) { am = adjust_hour(&hr); (void) sprintf(buf, "%d%s", hr, am ? "a" : "p"); } else (void) sprintf(buf, "%02d", hr); x_off = gr_center(hrbox_margin, buf, pf); /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x+x_off, y, pf, buf, fg, cmap, rect); else */ gr_text(c->xcontext, x+x_off, y, pf, buf, rect); y += h; } /* draw in appointments */ x = MOBOX_AREA_WIDTH + hrbox_margin + 6; pfy = fontextents2.max_logical_extent.height; maxlines = (h - 6) / pfy; curr_line = last_hr = 0; /* loop thru, getting out the "no time" appointments */ for (i = 0; i < a_total; i++) { if (i != a_total) last_hr = hr; hr = begin_time; if (cache[i].show_time == 0) { if (last_hr != hr) curr_line = 0; y = c->view->topoffset + 2 + pfy; if (curr_line < maxlines) { y += (curr_line * pfy) + h * (hr - begin_time); headlines = lines = text_to_lines(cache[i].summary, 4); start_tick = cache[i].start_time; end_tick = cache[i].end_time; if (lines != NULL && lines->s != NULL) { appt_str = ckalloc(cm_strlen(lines->s)+18); format_line(start_tick, lines->s, appt_str, end_tick, cache[i].show_time, disp_t); lines = lines->next; } else { appt_str = ckalloc(15); format_line(start_tick, (char*)NULL, appt_str, end_tick, cache[i].show_time, disp_t); } appt_str[cm_strlen(appt_str)]=NULL; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); free(appt_str); appt_str = NULL; curr_line++; if (curr_line < maxlines && lines != NULL) { appt_str = ckalloc(324); cm_strcpy(appt_str, " "); while (lines != NULL) { if (lines->s != NULL) cm_strcat(appt_str, lines->s); lines = lines->next; if (lines != NULL && lines->s != NULL) cm_strcat(appt_str, " - "); } y += pfy; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); curr_line++; free(appt_str); appt_str = NULL; } destroy_lines(headlines); lines=NULL; } } } for (i = 0; i < a_total; i++) { if (i != a_total) last_hr = hr; start_tick = cache[i].start_time; end_tick = cache[i].end_time; hr = hour(start_tick); if (hr >= begin_time && hr < end_time && (cache[i].show_time && !magic_time(start_tick))) { if (last_hr != hr) curr_line = 0; y = c->view->topoffset + 2 + pfy; if (curr_line < maxlines) { y += (curr_line * pfy) + h * (hr - begin_time + 1); headlines = lines = text_to_lines(cache[i].summary, 4); if (lines != NULL && lines->s != NULL) { appt_str = ckalloc(cm_strlen(lines->s)+18); format_line(start_tick, lines->s, appt_str, end_tick, cache[i].show_time, disp_t); lines = lines->next; } else { appt_str = ckalloc(15); format_line(start_tick, (char*)NULL, appt_str, end_tick, cache[i].show_time, disp_t); } appt_str[cm_strlen(appt_str)]=NULL; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); free(appt_str); appt_str = NULL; curr_line++; if (curr_line < maxlines && lines != NULL) { appt_str = ckalloc(324); cm_strcpy(appt_str, " "); while (lines != NULL) { if (lines->s != NULL) cm_strcat(appt_str, lines->s); lines = lines->next; if (lines != NULL && lines->s != NULL) cm_strcat(appt_str, " - "); } y += pfy; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); curr_line++; free(appt_str); appt_str = NULL; } destroy_lines(headlines); lines=NULL; } } } }
void CScriptEdit::CheckScript(int messages) { CString tmpstr; CString linestr; CString line; trigger trigger; action action; int i; int triggeroraction; int startline, endline; int num_or; bool tr_override; int commentpos; if(m_bcs) { tmpstr.Format("Edit script: %s%s",itemname, the_script.m_changed?"*":""); } else { tmpstr.Format("Edit script source: %s%s",itemname, the_script.m_changed?"*":""); } SetWindowText(tmpstr); if(!(messages&FORCED_CHECK) ) { if(editflg&NOCHECK) return; if(!m_text_control.GetModify()) return; } m_text_control.SetModify(false); m_count=m_text_control.GetLineCount(); if(m_errors) delete [] m_errors; triggeroraction=TA_IF; if(m_count<0) { m_errors=new int[1]; m_errors[0]=m_count; m_firsterror=0; endline=m_count=1; } else { m_firsterror=-1; m_errors=new int[m_count]; if(messages&WHOLE_CHECK) { startline=0; endline=m_count; } else { startline=m_text_control.GetFirstVisibleLine(); endline=min(m_count,startline+LINES); while(startline>0) { if(GetLine(startline)=="IF") break; startline--; } } num_or=0; tr_override=false; for(i=startline;i<endline;i++) { line=GetLine(i); commentpos=line.Find("//"); if(commentpos>=0) { tmpstr=line.Left(commentpos); } else tmpstr=line; tmpstr.TrimRight(); tmpstr.TrimLeft(); if(!tmpstr.IsEmpty()) { switch(triggeroraction) { case TA_ACTION: m_errors[i]=match_string(tmpstr, "END",0,-130); if(!m_errors[i]) { triggeroraction=TA_IF; break; } m_errors[i]=match_string(tmpstr, "RESPONSE #%d",m_indent,-110); if(!m_errors[i]) { triggeroraction=TA_ACTION; break; } m_errors[i]=compile_action(tmpstr, action, 0); format_line(tmpstr,m_indent*2); break; case TA_TRIGGER: m_errors[i]=match_string(tmpstr, "THEN",0,-120); if(!m_errors[i]) { if(num_or) { m_errors[i]=CE_INCOMPLETE_OR; } if(tr_override) { m_errors[i]=CE_INCOMPLETE_TROVERRIDE; } triggeroraction=TA_RESPONSE; break; } m_errors[i]=compile_trigger(tmpstr, trigger); format_line(tmpstr, num_or?m_indent+2:m_indent); if((trigger.opcode&0x1fff)==TR_OR) { if(num_or) m_errors[i]=CE_INCOMPLETE_OR; num_or=trigger.bytes[0]; } else { if(num_or) num_or--; } if((trigger.opcode==TR_OVERRIDE) && is_this_bgee()) { if(tr_override) m_errors[i]=CE_INCOMPLETE_TROVERRIDE; else tr_override=true; } else { //override object??? tr_override=false; } break; case TA_IF: m_errors[i]=match_string(tmpstr, "IF",0,-100); triggeroraction=TA_TRIGGER; num_or=0; tr_override=false; break; case TA_RESPONSE: m_errors[i]=match_string(tmpstr, "RESPONSE #%d",m_indent,-110); triggeroraction=TA_ACTION; break; } if(m_errors[i]) { if(m_firsterror==-1) m_firsterror=i; } } else m_errors[i]=0; if(commentpos>=0) line=tmpstr+line.Mid(commentpos); else line=tmpstr; } } if(messages&SHOW_MESSAGES) { if(m_firsterror>=0) { for(i=m_firsterror;i<endline;i++) { if(m_errors[i]) { tmpstr.Format("Error in script line #%d: %s",i+1,get_compile_error(m_errors[i]) ); if(MessageBox(tmpstr,"Dialog editor",MB_ICONEXCLAMATION|MB_OKCANCEL)==IDCANCEL) { m_firsterror=i; //positioning to the cancelled line break; } } } } } }