/** ** @brief Prints all echo arguments. ** @param opt Echo options structure. ** @param argv Input arguments values. ** @param optind Input options. ** @param builtin_fd IOs streams. ** @return Returns the return value of printing, 0 if success. */ static inline int print_all(struct s_echo_opt *opt, char **argv, int optind, s_builtin_fd *builtin_fd) { int i; int argc; argc = get_argc(argv); if (opt->eflag == false) { for (i = optind; i < argc - 1; i++) fprintf(builtin_fd->fout, "%s ", argv[i]); if (argv[i]) fprintf(builtin_fd->fout, "%s", argv[i]); } else { for (i = optind; i < argc - 1; i++) { if (print_escaped(argv[i], builtin_fd) == -1) return (-1); fprintf(builtin_fd->fout, " "); } if (argv[i]) if (print_escaped(argv[i], builtin_fd) == -1) return (-1); } return (0); }
static inline void _nl_log_untranslated_locked (const char *logfilename, const char *domainname, const char *msgid1, const char *msgid2, int plural) { FILE *logfile; const char *separator; /* Can we reuse the last opened logfile? */ if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0) { /* Close the last used logfile. */ if (last_logfilename != NULL) { if (last_logfile != NULL) { fclose (last_logfile); last_logfile = NULL; } free (last_logfilename); last_logfilename = NULL; } /* Open the logfile. */ last_logfilename = (char *) malloc (strlen (logfilename) + 1); if (last_logfilename == NULL) return; strcpy (last_logfilename, logfilename); last_logfile = fopen (logfilename, "a"); if (last_logfile == NULL) return; } logfile = last_logfile; fprintf (logfile, "domain "); print_escaped (logfile, domainname, domainname + strlen (domainname)); separator = strchr (msgid1, MSGCTXT_SEPARATOR); if (separator != NULL) { /* The part before the MSGCTXT_SEPARATOR is the msgctxt. */ fprintf (logfile, "\nmsgctxt "); print_escaped (logfile, msgid1, separator); msgid1 = separator + 1; } fprintf (logfile, "\nmsgid "); print_escaped (logfile, msgid1, msgid1 + strlen (msgid1)); if (plural) { fprintf (logfile, "\nmsgid_plural "); print_escaped (logfile, msgid2, msgid2 + strlen (msgid2)); fprintf (logfile, "\nmsgstr[0] \"\"\n"); } else fprintf (logfile, "\nmsgstr \"\"\n"); putc ('\n', logfile); }
static void debug_each_source_column() { do_indent (); fprintf (ipf->output_fp, "<s_col %d cindex=%d text=\"%s\" ", iterate_source_column->index, iterate_source_column->cindex, iterate_source_column->filler_flag ? (Uchar*)"<filler>" : iterate_source_column->text); if (!iterate_source_column->index && *iterate_line->altsig) fprintf (ipf->output_fp, "(aka `%s') ", iterate_line->altsig); fprintf (ipf->output_fp, "cols=%d viswidth=%d zero=%s space=%s phant=%s", iterate_source_column->columns_occupied, iterate_source_column->visible_width, t_or_f(iterate_composite_column->zero_flag), t_or_f(iterate_composite_column->space_flag), t_or_f(iterate_source_column->needs_phantom)); fprintf (ipf->output_fp, "\n"); do_indent (); fprintf (ipf->output_fp, "\tcomposite = %p; composite_end = %p\n", iterate_source_column->composite, iterate_source_column->composite_end); do_indent (); fprintf (ipf->output_fp, " complex = %p ", iterate_source_column->complex); if (iterate_source_column->complex_text) { fprintf (ipf->output_fp, "complex_has_variant=%s complex_text = `%s'>\n", t_or_f(iterate_source_column->complex_has_variant), print_escaped(iterate_source_column->complex_text)); } else fprintf (ipf->output_fp, ">\n"); }
inline std::ostream& operator<<( custom_printer<pcdata> const& p, const_string value ) { print_escaped( *p, value ); return *p; }
void kty_object_to_string(kty_item_t *item, int depth) { int count = 0; htbl_t *table; entry_t *entry; fdprintf(STDOUT, "{"); table = item->item.i_object; if (table) { fdprintf(STDOUT, "\n"); for (entry = table->head; entry != NULL ; entry = entry->next) { if (count > 0) fdprintf(STDOUT, ",\n"); count++; print_indent(depth + 1); fdprintf(STDOUT, "\""); print_escaped(entry->key, cgc_strlen(entry->key)); fdprintf(STDOUT, "\": "); kty_print_item(entry->val, depth + 1); } } if (count > 0) { fdprintf(STDOUT, "\n"); print_indent(depth); } fdprintf(STDOUT, "}"); }
static int print_list(alpm_list_t *list, extractfn fn) { alpm_list_t *i; int out = 0; if (!list) { if (opt_verbose) { out += printf("None"); } return out; } i = list; while (1) { char *item = (char*)(fn ? fn(i->data) : i->data); if (item == NULL) { continue; } out += printf("%s", item); if ((i = alpm_list_next(i))) { out += print_escaped(opt_listdelim); } else { break; } } return out; }
static void debug_each_composite_column() { List *vlist; do_indent (); fprintf (ipf->output_fp, "<comp_col %d text=\"%s\" delim=\"%s\" viswidth=%d maxwidth=%d zero=%s space=%s\n", iterate_composite_column->index, iterate_composite_column->text, print_escaped(iterate_composite_column->delim), iterate_composite_column->visible_width, iterate_composite_column->maxwidth, t_or_f(iterate_composite_column->zero_flag), t_or_f(iterate_composite_column->space_flag)); do_indent (); fprintf (ipf->output_fp, "\tcomplex_index=%d complex_columns=%d complex_has_variant=%s s_l_d=%s phant=%s>\n", iterate_composite_column->complex_index, iterate_composite_column->complex_columns, t_or_f(iterate_composite_column->complex->complex_has_variant), t_or_f(iterate_composite_column->short_line_divider), t_or_f(iterate_composite_column->needs_phantom)); do_indent (); fprintf (ipf->output_fp, "\tcomplex = %p\n", iterate_composite_column); vlist = vars_lookup2(iterate_line->name, iterate_composite_column->index); if (list_len(vlist)) { indent += 2; vars_normalize_length(vlist); list_exec (vlist, debug_print_variant); indent -= 2; } }
/* Add to the log file an entry denoting a failed translation. */ void _nl_log_untranslated (const char *logfilename, const char *domainname, const char *msgid1, const char *msgid2, int plural) { static char *last_logfilename = NULL; static FILE *last_logfile = NULL; FILE *logfile; /* Can we reuse the last opened logfile? */ if (last_logfilename == NULL || strcmp (logfilename, last_logfilename) != 0) { /* Close the last used logfile. */ if (last_logfilename != NULL) { if (last_logfile != NULL) { fclose (last_logfile); last_logfile = NULL; } free (last_logfilename); last_logfilename = NULL; } /* Open the logfile. */ last_logfilename = (char *) malloc (strlen (logfilename) + 1); if (last_logfilename == NULL) return; strcpy (last_logfilename, logfilename); last_logfile = fopen (logfilename, "a"); if (last_logfile == NULL) return; } logfile = last_logfile; fprintf (logfile, "domain "); print_escaped (logfile, domainname); fprintf (logfile, "\nmsgid "); print_escaped (logfile, msgid1); if (plural) { fprintf (logfile, "\nmsgid_plural "); print_escaped (logfile, msgid2); fprintf (logfile, "\nmsgstr[0] \"\"\n"); } else fprintf (logfile, "\nmsgstr \"\"\n"); putc ('\n', logfile); }
inline std::ostream& operator<<( custom_printer<attr_value> const& p, T const& value ) { *p << "=\""; print_escaped( *p, value ); *p << '"'; return *p; }
/** * Prints a row or column style to a file. * \param style Pointer to the style to print * \param f The stream to print to */ static void print_rc_style(struct spreadconv_rc_style *style, FILE *f) { fprintf(f, "<style:style style:name=\""); print_escaped(f, style->name); fprintf(f, "\" "); if (style->type == LSC_STYLE_ROW) { fprintf(f, "style:family=\"table-row\">\n"); fprintf(f, "<style:table-row-properties style:row-height=\""); } else { /* assuming LSC_STYLE_COLUMN */ fprintf(f, "style:family=\"table-column\">\n"); fprintf(f, "<style:table-column-properties style:column-width=\""); } print_escaped(f, style->size); fprintf(f, "\" />\n"); fprintf(f, "</style:style>\n"); }
/** * Prints a cell style to a file. * \param style Pointer to the style to print * \param f The stream to print to */ static void print_cell_style(struct spreadconv_cell_style *style, FILE *f) { /* * TODO * if only row_span || col_span are != NULL then * we have nothing to print */ fprintf(f, "<style:style style:name=\""); print_escaped(f, style->name); fprintf(f, "\" "); fprintf(f, "style:family=\"table-cell\">\n"); fprintf(f, "<style:table-cell-properties "); if (style->valign != 0) { fprintf(f, "style:vertical-align=\""); print_escaped(f, style->valign); fprintf(f, "\" "); } if (style->border != 0) { fprintf(f, "fo:border=\""); print_escaped(f, style->border); fprintf(f, "\" "); } if (style->border_top != 0) { fprintf(f, "fo:border-top=\""); print_escaped(f, style->border_top); fprintf(f, "\" "); } if (style->border_bottom != 0) { fprintf(f, "fo:border-bottom=\""); print_escaped(f, style->border_bottom); fprintf(f, "\" "); } if (style->border_left != 0) { fprintf(f, "fo:border-left=\""); print_escaped(f, style->border_left); fprintf(f, "\" "); } if (style->border_right != 0) { fprintf(f, "fo:border-right=\""); print_escaped(f, style->border_right); fprintf(f, "\" "); } fprintf(f, "/>\n"); if (style->halign != 0) { fprintf(f, "<style:paragraph-properties "); fprintf(f, "fo:text-align=\""); print_escaped(f, style->halign); fprintf(f, "\""); fprintf(f, "/>\n"); } fprintf(f, "</style:style>\n"); }
static int print_filelist(alpm_filelist_t *filelist) { int out = 0; size_t i; for (i = 0; i < filelist->count; i++) { out += printf("%s", (filelist->files + i)->name); out += print_escaped(opt_listdelim); } return out; }
void page(void) { char *mess = get_message(); printf("Content-Type: text/html\n\n"); printf("<HTML><HEAD>\n"); printf("<TITLE>Disseny d'aplicacions WEB: Exemple CGI interactiu</TITLE></TITLE>\n"); printf("</HEAD><BODY BGCOLOR=\"lightblue\">\n"); printf("<center><H1>Exemple de CGI interactiu</H1></center><HR>\n"); printf("<H2>Últim missatge:</H2>\n"); if (strlen(mess) == 0) { printf("<EM>(no hi missatge)</EM>\n"); } else { printf("<PRE>\n"); print_escaped(mess); printf("</PRE>\n"); } printf("<H2>Missatge:</H2>\n"); //*** printf("<FORM METHOD=\"POST\" ACTION=\"%s\"><CENTER>\n", getenv("SCRIPT_NAME")); printf("<FORM METHOD=\"POST\" ACTION=\"#\"><CENTER>\n"); printf("<TEXTAREA NAME=\"message\" ROWS=\"15\" COLS=\"100\">"); print_escaped(mess); printf("</TEXTAREA>\n"); printf("<BR><INPUT TYPE=\"submit\" NAME=\"change\" VALUE=\"Canvia\">\n"); printf("</CENTER></FORM><HR>\n"); printf("</BODY></HTML>\n"); }
static void debug_each_reconstructed_column() { do_indent (); fprintf (ipf->output_fp, "<recons_col %d text=\"%s\" delim=\"%s\" maxwidth=%d\n", iterate_reconstructed_column->index, iterate_reconstructed_column->text, print_escaped(iterate_reconstructed_column->delim), iterate_reconstructed_column->maxwidth); do_indent (); fprintf (ipf->output_fp, "\tcomplex_index=%d complex_columns=%d zero=%s space=%s phant=%s>\n", iterate_reconstructed_column->complex_index, iterate_reconstructed_column->complex_columns, t_or_f(iterate_reconstructed_column->zero_flag), t_or_f(iterate_reconstructed_column->space_flag), t_or_f(iterate_reconstructed_column->needs_phantom)); }
/** print domain name */ static void print_dname(uint8_t* d, size_t len) { uint8_t lablen; size_t i = 0; if(len == 1 && d[0] == 0) { printf("."); return; } while(i < len) { lablen = d[i++]; if(lablen == 0) continue; if(lablen+i > len) { printf(" malformed!"); return; } print_escaped(&d[i], lablen); i += lablen; printf("."); } }
static inline std::ostream& print_attr_value( std::ostream& where_to, const_string value ) { where_to << "=\""; return print_escaped( where_to, value ) << '"'; }
static int print_pkg(alpm_pkg_t *pkg, const char *format) { const char *f, *end; char fmt[64], buf[64]; int len, out = 0; end = format + strlen(format); for (f = format; f < end; f++) { len = 0; if (*f == '%') { len = strspn(f + 1 + len, printf_flags); len += strspn(f + 1 + len, digits); snprintf(fmt, len + 3, "%ss", f); fmt[len + 1] = 's'; f += len + 1; switch (*f) { /* simple attributes */ case 'f': /* filename */ out += printf(fmt, alpm_pkg_get_filename(pkg)); break; case 'n': /* package name */ out += printf(fmt, alpm_pkg_get_name(pkg)); break; case 'v': /* version */ out += printf(fmt, alpm_pkg_get_version(pkg)); break; case 'd': /* description */ out += printf(fmt, alpm_pkg_get_desc(pkg)); break; case 'u': /* project url */ out += printf(fmt, alpm_pkg_get_url(pkg)); break; case 'p': /* packager name */ out += printf(fmt, alpm_pkg_get_packager(pkg)); break; case 's': /* md5sum */ out += printf(fmt, alpm_pkg_get_md5sum(pkg)); break; case 'a': /* architecutre */ out += printf(fmt, alpm_pkg_get_arch(pkg)); break; case 'i': /* has install scriptlet? */ out += printf(fmt, alpm_pkg_has_scriptlet(pkg) ? "yes" : "no"); break; case 'r': /* repo */ out += printf(fmt, alpm_db_get_name(alpm_pkg_get_db(pkg))); break; case 'w': /* install reason */ out += printf(fmt, alpm_pkg_get_reason(pkg) ? "dependency" : "explicit"); break; case '!': /* result number */ snprintf(buf, sizeof(buf), "%d", opt_pkgcounter++); out += printf(fmt, buf); break; case 'g': /* base64 gpg sig */ out += printf(fmt, alpm_pkg_get_base64_sig(pkg)); break; case 'h': /* sha256sum */ out += printf(fmt, alpm_pkg_get_sha256sum(pkg)); break; /* times */ case 'b': /* build date */ out += print_time(alpm_pkg_get_builddate(pkg)); break; case 'l': /* install date */ out += print_time(alpm_pkg_get_installdate(pkg)); break; /* sizes */ case 'k': /* download size */ out += printf(fmt, size_to_string(alpm_pkg_get_size(pkg))); break; case 'm': /* install size */ out += printf(fmt, size_to_string(alpm_pkg_get_isize(pkg))); break; /* lists */ case 'F': /* files */ out += print_filelist(alpm_pkg_get_files(pkg)); break; case 'N': /* requiredby */ out += print_list(alpm_pkg_compute_requiredby(pkg), NULL); break; case 'L': /* licenses */ out += print_list(alpm_pkg_get_licenses(pkg), NULL); break; case 'G': /* groups */ out += print_list(alpm_pkg_get_groups(pkg), NULL); break; case 'E': /* depends (shortdeps) */ out += print_list(alpm_pkg_get_depends(pkg), (extractfn)alpm_dep_get_name); break; case 'D': /* depends */ out += print_list(alpm_pkg_get_depends(pkg), (extractfn)alpm_dep_compute_string); break; case 'O': /* optdepends */ out += print_list(alpm_pkg_get_optdepends(pkg), (extractfn)format_optdep); break; case 'o': /* optdepends (shortdeps) */ out += print_list(alpm_pkg_get_optdepends(pkg), (extractfn)alpm_dep_get_name); break; case 'C': /* conflicts */ out += print_list(alpm_pkg_get_conflicts(pkg), (extractfn)alpm_dep_get_name); break; case 'S': /* provides (shortdeps) */ out += print_list(alpm_pkg_get_provides(pkg), (extractfn)alpm_dep_get_name); break; case 'P': /* provides */ out += print_list(alpm_pkg_get_provides(pkg), (extractfn)alpm_dep_compute_string); break; case 'R': /* replaces */ out += print_list(alpm_pkg_get_replaces(pkg), (extractfn)alpm_dep_get_name); break; case 'B': /* backup */ out += print_list(alpm_pkg_get_backup(pkg), alpm_backup_get_name); break; case 'V': /* package validation */ out += print_allocated_list(get_validation_method(pkg), NULL); break; case 'M': /* modified */ out += print_allocated_list(get_modified_files(pkg), NULL); break; case '%': fputc('%', stdout); out++; break; default: fputc('?', stdout); out++; break; } } else if (*f == '\\') { char esc[3] = { f[0], f[1], '\0' }; out += print_escaped(esc); ++f; } else { fputc(*f, stdout); out++; } } /* only print a delimeter if any package data was outputted */ if (out > 0) { print_escaped(opt_delim); } return !out; }
/** inspect a chunk in the file */ static void* inspect_chunk(void* base, void* cv, struct inspect_totals* t) { udb_chunk_d* cp = (udb_chunk_d*)cv; udb_void c = (udb_void)(cv - base); udb_void data; uint8_t exp = cp->exp; uint8_t tp = cp->type; uint8_t flags = cp->flags; uint64_t sz = 0; if(exp == UDB_EXP_XL) { sz = ((udb_xl_chunk_d*)cp)->size; data = c + sizeof(udb_xl_chunk_d); } else { sz = (uint64_t)1<<exp; data = c + sizeof(udb_chunk_d); } if(v) { /* print chunk details */ printf("chunk at %llu exp=%d type=%d (%s) flags=0x%x " "size=%llu\n", ULL c, exp, tp, chunk_type2str(tp), flags, ULL sz); if(tp == udb_chunk_type_free) { udb_free_chunk_d* fp = (udb_free_chunk_d*)cp; printf("prev: %llu\n", ULL fp->prev); printf("next: %llu\n", ULL fp->next); } else { printf("ptrlist: %llu\n", ULL cp->ptrlist); } } if(v>=2 && tp != udb_chunk_type_free && cp->ptrlist) { /* follow the pointer list */ udb_rel_ptr* pl = UDB_REL_PTR(cp->ptrlist); while(pl->next) { printf("relptr %llu\n", ULL UDB_SYSTOREL(base, pl)); printf(" prev-ptrlist: %llu\n", ULL pl->prev); printf(" data: %llu\n", ULL pl->data); printf(" next-ptrlist: %llu\n", ULL pl->next); pl = UDB_REL_PTR(pl->next); } } /* print data details */ if(v>=2) { if(cp->type == udb_chunk_type_radtree) { struct udb_radtree_d* d = (struct udb_radtree_d*)UDB_REL(base, data); printf(" radtree count=%llu root=%llu\n", ULL d->count, ULL d->root.data); } else if(cp->type == udb_chunk_type_radnode) { struct udb_radnode_d* d = (struct udb_radnode_d*)UDB_REL(base, data); printf(" radnode pidx=%d offset=%d elem=%llu " "parent=%llu lookup=%llu\n", (int)d->pidx, (int)d->offset, ULL d->elem.data, ULL d->parent.data, ULL d->lookup.data); } else if(cp->type == udb_chunk_type_radarray) { struct udb_radarray_d* d = (struct udb_radarray_d*)UDB_REL( base, data); unsigned i; printf(" radarray len=%d capacity=%d str_cap=%d\n", (int)d->len, (int)d->capacity, (int)d->str_cap); for(i=0; i<d->len; i++) if(d->array[i].node.data) { printf(" [%u] node=%llu len=%d ", i, ULL d->array[i].node.data, (int)d->array[i].len); print_escaped( ((uint8_t*)&d->array[d->capacity])+ i*d->str_cap, (size_t)d->array[i].len); printf("\n"); } } else if(cp->type == udb_chunk_type_zone) { struct zone_d* d = (struct zone_d*)UDB_REL(base, data); printf(" zone "); print_dname(d->name, d->namelen); printf(" rr_count=%llu rrset_count=%llu expired=%d " "node=%llu domains=%llu\n", ULL d->rr_count, ULL d->rrset_count, (int)d->expired, ULL d->node.data, ULL d->domains.data); } else if(cp->type == udb_chunk_type_domain) { struct domain_d* d = (struct domain_d*)UDB_REL(base, data); printf(" domain "); print_dname(d->name, d->namelen); printf(" node=%llu rrsets=%llu\n", ULL d->node.data, ULL d->rrsets.data); } else if(cp->type == udb_chunk_type_rrset) { struct rrset_d* d = (struct rrset_d*)UDB_REL(base, data); printf(" rrset type=%d next=%llu rrs=%llu\n", (int)d->type, ULL d->next.data, ULL d->rrs.data); } else if(cp->type == udb_chunk_type_rr) { struct rr_d* d = (struct rr_d*)UDB_REL(base, data); printf(" rr type=%d class=%d ttl=%u next=%llu len=%d ", (int)d->type, (int)d->klass, (unsigned)d->ttl, ULL d->next.data, (int)d->len); print_hex(d->wire, d->len); printf("\n"); } else if(cp->type == udb_chunk_type_task) { struct task_list_d* d = (struct task_list_d*)UDB_REL(base, data); printf(" task type=%d next=%llu yesno=%d oldserial=%u newserial=%u zone=%s\n", (int)d->task_type, ULL d->next.data, (int)d->yesno, (unsigned)d->oldserial, (unsigned)d->newserial, d->size > sizeof(*d)? dname_to_string(d->zname, NULL):"\"\""); } } /* end verbosity 2 */ /* update stats */ t->exp_num[exp]++; if(tp == udb_chunk_type_free) { t->exp_free[exp]++; } else { t->type_num[tp]++; t->type_exp_num[tp][exp]++; } /* check end marker */ if(exp == UDB_EXP_XL) { if(sz != *(uint64_t*)(cv+sz-2*sizeof(uint64_t))) { printf(" end xl size is wrong: %llu\n", ULL *(uint64_t*)(cv+sz-2*sizeof(uint64_t))); } } if(exp != *(uint8_t*)(cv+sz-1)) { printf(" end exp is wrong: %d\n", *(uint8_t*)(cv+sz-1)); } return cv+sz; }
int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Expected usage: %s <sd-leak-file>\n" " sd-leak-file: Output of --shutdown-leaks=<file> option.\n", argv[0]); return 1; } NS_InitXPCOM2(NULL, NULL, NULL); ADLog log; if (!log.Read(argv[1])) { fprintf(stderr, "%s: Error reading input file %s.\n", argv[0], argv[1]); } const size_t count = log.count(); PLHashTable *memory_map = PL_NewHashTable(count * 8, hash_pointer, PL_CompareValues, PL_CompareValues, 0, 0); if (!memory_map) { fprintf(stderr, "%s: Out of memory.\n", argv[0]); return 1; } // Create one |AllocationNode| object for each log entry, and create // entries in the hashtable pointing to it for each byte it occupies. AllocationNode *nodes = new AllocationNode[count]; if (!nodes) { fprintf(stderr, "%s: Out of memory.\n", argv[0]); return 1; } { AllocationNode *cur_node = nodes; for (ADLog::const_iterator entry = log.begin(), entry_end = log.end(); entry != entry_end; ++entry, ++cur_node) { const ADLog::Entry *e = cur_node->entry = *entry; cur_node->reached = false; for (ADLog::Pointer p = e->address, p_end = e->address + e->datasize; p != p_end; ++p) { PLHashEntry *e = PL_HashTableAdd(memory_map, p, cur_node); if (!e) { fprintf(stderr, "%s: Out of memory.\n", argv[0]); return 1; } } } } // Construct graph based on pointers. for (AllocationNode *node = nodes, *node_end = nodes + count; node != node_end; ++node) { const ADLog::Entry *e = node->entry; for (const char *d = e->data, *d_end = e->data + e->datasize - e->datasize % sizeof(ADLog::Pointer); d != d_end; d += sizeof(ADLog::Pointer)) { AllocationNode *target = (AllocationNode*) PL_HashTableLookup(memory_map, *(void**)d); if (target) { target->pointers_from.AppendElement(node); node->pointers_to.AppendElement(target); } } } // Do a depth-first search on the graph (i.e., by following // |pointers_to|) and assign the post-order index to |index|. { PRUint32 dfs_index = 0; nsVoidArray stack; for (AllocationNode *n = nodes, *n_end = nodes+count; n != n_end; ++n) { if (n->reached) { continue; } stack.AppendElement(n); do { PRUint32 pos = stack.Count() - 1; AllocationNode *n = static_cast<AllocationNode*>(stack[pos]); if (n->reached) { n->index = dfs_index++; stack.RemoveElementAt(pos); } else { n->reached = true; // When doing post-order processing, we have to be // careful not to put reached nodes into the stack. nsVoidArray &pt = n->pointers_to; for (PRInt32 i = pt.Count() - 1; i >= 0; --i) { if (!static_cast<AllocationNode*>(pt[i])->reached) { stack.AppendElement(pt[i]); } } } } while (stack.Count() > 0); } } // Sort the nodes by their DFS index, in reverse, so that the first // node is guaranteed to be in a root SCC. AllocationNode **sorted_nodes = new AllocationNode*[count]; if (!sorted_nodes) { fprintf(stderr, "%s: Out of memory.\n", argv[0]); return 1; } { for (size_t i = 0; i < count; ++i) { sorted_nodes[i] = nodes + i; } NS_QuickSort(sorted_nodes, count, sizeof(AllocationNode*), sort_by_reverse_index, 0); } // Put the nodes into their strongly-connected components. PRUint32 num_sccs = 0; { for (size_t i = 0; i < count; ++i) { nodes[i].reached = false; } nsVoidArray stack; for (AllocationNode **sn = sorted_nodes, **sn_end = sorted_nodes + count; sn != sn_end; ++sn) { if ((*sn)->reached) { continue; } // We found a new strongly connected index. stack.AppendElement(*sn); do { PRUint32 pos = stack.Count() - 1; AllocationNode *n = static_cast<AllocationNode*>(stack[pos]); stack.RemoveElementAt(pos); if (!n->reached) { n->reached = true; n->index = num_sccs; stack.AppendElements(n->pointers_from); } } while (stack.Count() > 0); ++num_sccs; } } // Identify which nodes are leak roots by using DFS, and watching // for component transitions. PRUint32 num_root_nodes = count; { for (size_t i = 0; i < count; ++i) { nodes[i].is_root = true; } nsVoidArray stack; for (AllocationNode *n = nodes, *n_end = nodes+count; n != n_end; ++n) { if (!n->is_root) { continue; } // Loop through pointers_to, and add any that are in a // different SCC to stack: for (int i = n->pointers_to.Count() - 1; i >= 0; --i) { AllocationNode *target = static_cast<AllocationNode*>(n->pointers_to[i]); if (n->index != target->index) { stack.AppendElement(target); } } while (stack.Count() > 0) { PRUint32 pos = stack.Count() - 1; AllocationNode *n = static_cast<AllocationNode*>(stack[pos]); stack.RemoveElementAt(pos); if (n->is_root) { n->is_root = false; --num_root_nodes; stack.AppendElements(n->pointers_to); } } } } // Sort the nodes by their SCC index. NS_QuickSort(sorted_nodes, count, sizeof(AllocationNode*), sort_by_index, 0); // Print output. { printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n" "<html>\n" "<head>\n" "<title>Leak analysis</title>\n" "<style type=\"text/css\">\n" " .root { background: white; color: black; }\n" " .nonroot { background: #ccc; color: black; }\n" "</style>\n" "</head>\n"); printf("<body>\n\n" "<p>Generated %d entries (%d in root SCCs) and %d SCCs.</p>\n\n", count, num_root_nodes, num_sccs); for (size_t i = 0; i < count; ++i) { nodes[i].reached = false; } // Loop over the sorted nodes twice, first printing the roots // and then the non-roots. for (PRInt32 root_type = true; root_type == true || root_type == false; --root_type) { if (root_type) { printf("\n\n" "<div class=\"root\">\n" "<h1 id=\"root\">Root components</h1>\n"); } else { printf("\n\n" "<div class=\"nonroot\">\n" "<h1 id=\"nonroot\">Non-root components</h1>\n"); } PRUint32 component = (PRUint32)-1; bool one_object_component; for (const AllocationNode *const* sn = sorted_nodes, *const* sn_end = sorted_nodes + count; sn != sn_end; ++sn) { const AllocationNode *n = *sn; if (n->is_root != root_type) continue; const ADLog::Entry *e = n->entry; if (n->index != component) { component = n->index; one_object_component = sn + 1 == sn_end || (*(sn+1))->index != component; if (!one_object_component) printf("\n\n<h2 id=\"c%d\">Component %d</h2>\n", component, component); } if (one_object_component) { printf("\n\n<div id=\"c%d\">\n", component); printf("<h2 id=\"o%d\">Object %d " "(single-object component %d)</h2>\n", n-nodes, n-nodes, component); } else { printf("\n\n<h3 id=\"o%d\">Object %d</h3>\n", n-nodes, n-nodes); } printf("<pre>\n"); printf("%p <%s> (%d)\n", e->address, e->type, e->datasize); for (size_t d = 0; d < e->datasize; d += sizeof(ADLog::Pointer)) { AllocationNode *target = (AllocationNode*) PL_HashTableLookup(memory_map, *(void**)(e->data + d)); if (target) { printf(" <a href=\"#o%d\">0x%08X</a> <%s>", target - nodes, *(unsigned int*)(e->data + d), target->entry->type); if (target->index != n->index) { printf(", component %d", target->index); } printf("\n"); } else { printf(" 0x%08X\n", *(unsigned int*)(e->data + d)); } } if (n->pointers_from.Count()) { printf("\nPointers from:\n"); for (PRUint32 i = 0, i_end = n->pointers_from.Count(); i != i_end; ++i) { AllocationNode *t = static_cast<AllocationNode*> (n->pointers_from[i]); const ADLog::Entry *te = t->entry; printf(" <a href=\"#o%d\">%s</a> (Object %d, ", t - nodes, te->type, t - nodes); if (t->index != n->index) { printf("component %d, ", t->index); } if (t == n) { printf("self)\n"); } else { printf("%p)\n", te->address); } } } print_escaped(stdout, e->allocation_stack); printf("</pre>\n"); if (one_object_component) { printf("</div>\n"); } } printf("</div>\n"); } printf("</body>\n" "</html>\n"); } delete [] sorted_nodes; delete [] nodes; NS_ShutdownXPCOM(NULL); return 0; }
/** * Prints a table cell to a file. * \remarks Currently only float, string and formula are supported. * \param cell Pointer to the cell to print * \param f The spream to print to */ static void print_table_cell(struct spreadconv_cell *cell, FILE *f) { /* avoid printing rubbish if text is NULL */ if (cell->text == 0) cell->text = strdup(""); fprintf(f, "<table:table-cell "); if (cell->style != 0) { fprintf(f, "table:style-name=\""); print_escaped(f, cell->style->name); fprintf(f, "\" "); } if ((cell->value_type == NULL) || (strncmp(cell->value_type, "string", strlen("string")) == 0)) { if (cell->style) if (cell->style->row_span || cell->style->col_span) { if (!cell->style->row_span) { cell->style->row_span = strdup("1"); } else { if (!cell->style->col_span) { cell->style->col_span = strdup("1"); } } fprintf(f, "table:number-columns-spanned=\"%s\" ", cell->style->col_span); fprintf(f, "table:number-rows-spanned=\"%s\"", cell->style->row_span); } fprintf(f, ">\n"); fprintf(f, "<text:p>"); print_escaped(f, cell->text); fprintf(f, "</text:p>\n"); fprintf(f, "</table:table-cell>\n"); return; } if (strncmp(cell->value_type, "formula", strlen("formula")) == 0) { fprintf(f, "table:formula=\""); print_escaped(f, cell->text); fprintf(f, "\" />\n"); return; } if (strncmp(cell->value_type, "float", strlen("float")) == 0) { fprintf(f, "office:value-type=\"float\" "); fprintf(f, "office:value=\"%s\">\n", cell->text); fprintf(f, "office:value=\""); print_escaped(f, cell->text); fprintf(f, "\" "); /* redundant code*/ if (cell->style) if (cell->style->row_span || cell->style->col_span) { if (!cell->style->row_span) { cell->style->row_span = strdup("1"); } else { if (!cell->style->col_span) { cell->style->col_span = strdup("1"); } } fprintf(f, "table:number-columns-spanned=\"%s\" ", cell->style->col_span); fprintf(f, "table:number-rows-spanned=\"%s\"", cell->style->row_span); } fprintf(f, ">\n<text:p>"); print_escaped(f, cell->text); fprintf(f, "</text:p>\n</table:table-cell>\n"); return; } /* If we got here, then the value_type is not supported */ fprintf(stderr, "Cell value type not supported: %s\n", cell->value_type); assert(0); }
static void interpret(char *name, char *val, int comma, int rtype) { int type; while (*name == ' '||*name == '(') name++; /* Do some fixups */ if (rtype == AUDIT_EXECVE && name[0] == 'a') type = T_ESCAPED; else if (rtype == AUDIT_AVC && strcmp(name, "saddr") == 0) type = -1; else if (strcmp(name, "acct") == 0) { // Remove trailing punctuation int len = strlen(val); if (val[len-1] == ':') val[len-1] = 0; if (val[0] == '"') type = T_ESCAPED; else if (is_hex_string(val)) type = T_ESCAPED; else type = -1; } else type = audit_lookup_type(name); switch(type) { case T_UID: print_uid(val); break; case T_GID: print_gid(val); break; case T_SYSCALL: print_syscall(val); break; case T_ARCH: print_arch(val); break; case T_EXIT: print_exit(val); break; case T_ESCAPED: print_escaped(val); break; case T_PERM: print_perm(val); break; case T_MODE: print_mode(val); break; case T_SOCKADDR: print_sockaddr(val); break; case T_FLAGS: print_flags(val); break; case T_PROMISC: print_promiscuous(val); break; case T_CAPABILITY: print_capabilities(val); break; case T_SIGNAL: print_signals(val); break; case T_KEY: print_key(val); break; case T_LIST: print_list(val); break; case T_TTY_DATA: print_tty_data(val); break; default: printf("%s%c", val, comma ? ',' : ' '); } }
static gboolean query_module (const char *dir, const char *name, GString *contents) { void (*list) (const GtkIMContextInfo ***contexts, guint *n_contexts); gpointer list_ptr; gpointer init_ptr; gpointer exit_ptr; gpointer create_ptr; GModule *module; gchar *path; gboolean error = FALSE; if (g_path_is_absolute (name)) path = g_strdup (name); else path = g_build_filename (dir, name, NULL); module = g_module_open (path, 0); if (!module) { g_fprintf (stderr, "Cannot load module %s: %s\n", path, g_module_error()); error = TRUE; } if (module && g_module_symbol (module, "im_module_list", &list_ptr) && g_module_symbol (module, "im_module_init", &init_ptr) && g_module_symbol (module, "im_module_exit", &exit_ptr) && g_module_symbol (module, "im_module_create", &create_ptr)) { const GtkIMContextInfo **contexts; guint n_contexts; int i; list = list_ptr; print_escaped (contents, path); g_string_append_c (contents, '\n'); (*list) (&contexts, &n_contexts); for (i = 0; i < n_contexts; i++) { print_escaped (contents, contexts[i]->context_id); print_escaped (contents, contexts[i]->context_name); print_escaped (contents, contexts[i]->domain); print_escaped (contents, contexts[i]->domain_dirname); print_escaped (contents, contexts[i]->default_locales); g_string_append_c (contents, '\n'); } g_string_append_c (contents, '\n'); } else { g_fprintf (stderr, "%s does not export GTK+ IM module API: %s\n", path, g_module_error ()); error = TRUE; } g_free (path); if (module) g_module_close (module); return error; }
/** * Creates the content file. This is where most of the text (and the * code) actually resides. It is also the only file creation routine so * far that actually uses the data it is supplied with. * \param data A \a spreadconv_data structure from which to draw * information * \return 0 on success, -1 on error */ static int create_content_file(struct spreadconv_data *data) { FILE *f; int i, j; f = fopen("content.xml", "w"); if (f == 0) return -1; fprintf(f, "<?xml version=\"1.0\"?>\n"); fprintf(f, "<office:document-content "); print_namespaces(f); fprintf(f, ">\n"); /* print style information */ fprintf(f, "<office:automatic-styles>\n"); for (i=0; i<data->n_unique_rc_styles; i++) print_rc_style(&data->unique_rc_styles[i], f); for (i=0; i<data->n_unique_cell_styles; i++) print_cell_style(&data->unique_cell_styles[i], f); fprintf(f, "</office:automatic-styles>\n"); /* print the actual spreadsheet */ fprintf(f, "<office:body>\n"); fprintf(f, "<office:spreadsheet>\n"); /* avoid printing garbage if data->name is NULL */ if (data->name == 0) data->name = strdup("Sheet 1"); fprintf(f, "<table:table table:name=\"%s\">\n", data->name); /* print the columns */ for (i=0; i<data->n_cols; i++) { fprintf(f, "<table:table-column "); if (data->col_styles[i] != 0) { fprintf(f, "table:style-name=\""); print_escaped(f, data->col_styles[i]->name); fprintf(f, "\" "); } fprintf(f, "/>\n"); } /* print the rows, each with the associated cells */ for (i=0; i<data->n_rows; i++) { fprintf(f, "<table:table-row "); if (data->row_styles[i] != 0) { fprintf(f, "table:style-name=\""); print_escaped(f, data->row_styles[i]->name); fprintf(f, "\" "); } fprintf(f, ">\n"); for (j=0; j<data->n_cols; j++) print_table_cell(&data->cells[i][j], f); fprintf(f, "</table:table-row>\n"); } fprintf(f, "</table:table>\n"); fprintf(f, "</office:spreadsheet>\n"); fprintf(f, "</office:body>\n"); fprintf(f, "</office:document-content>\n"); fclose(f); return 0; }
void kty_string_to_string(kty_item_t *item) { fdprintf(STDOUT, "\""); print_escaped(item->item.i_string.s, item->item.i_string.len); fdprintf(STDOUT, "\""); }
static inline std::ostream& print_pcdata( std::ostream& where_to, const_string value ) { return print_escaped( where_to, value ); }
static void print_string(const char *name,const char *str) { print_name(name); print_escaped((unsigned char *)str,strlen(str)); putchar('\n'); }