static void test_file (const gchar *filename, GString *string) { gchar *contents; gchar *markup; gsize length; GError *error = NULL; PangoLayout *layout; gchar *p; gint width = 0; gint ellipsize_at = 0; PangoEllipsizeMode ellipsize = PANGO_ELLIPSIZE_NONE; PangoWrapMode wrap = PANGO_WRAP_WORD; PangoFontDescription *desc; if (!g_file_get_contents (filename, &contents, &length, &error)) { fprintf (stderr, "%s\n", error->message); g_error_free (error); return; } p = strchr (contents, '\n'); g_assert (p); markup = p + 1; *p = '\0'; parse_params (contents, &width, &ellipsize_at, &ellipsize, &wrap); layout = pango_layout_new (context); desc = pango_font_description_from_string ("Cantarell 11"); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); pango_layout_set_markup (layout, markup, length); g_free (contents); if (width != 0) pango_layout_set_width (layout, width * PANGO_SCALE); pango_layout_set_ellipsize (layout, ellipsize); pango_layout_set_wrap (layout, wrap); g_string_append (string, pango_layout_get_text (layout)); g_string_append (string, "\n---\n\n"); g_string_append_printf (string, "wrapped: %d\n", pango_layout_is_wrapped (layout)); g_string_append_printf (string, "ellipsized: %d\n", pango_layout_is_ellipsized (layout)); g_string_append_printf (string, "lines: %d\n", pango_layout_get_line_count (layout)); if (width != 0) g_string_append_printf (string, "width: %d\n", pango_layout_get_width (layout)); g_string_append (string, "\n---\n\n"); dump_attrs (pango_layout_get_attributes (layout), string); g_string_append (string, "\n---\n\n"); dump_lines (layout, string); g_string_append (string, "\n---\n\n"); dump_runs (layout, string); g_object_unref (layout); }
std::string dump_property(const Class::Property& prop) { std::string out; out.append(".property ["); out.append(dump_attrs(prop.attr)); out.append(" ] "); out.append(prop.name); out.append(" = \n "); out.append(prop.initializer); out.append(";\n"); return out; }
static void ileaf_dump(struct btree *btree, vleaf *vleaf) { struct sb *sb = btree->sb; struct ileaf *leaf = vleaf; inum_t inum = ibase(leaf); be_u16 *dict = vleaf + sb->blocksize; unsigned offset = 0; printf("inode table block 0x%Lx/%i (%x bytes free)\n", (L)ibase(leaf), icount(leaf), ileaf_free(btree, leaf)); //hexdump(dict - icount(leaf), icount(leaf) * 2); for (int i = -1; -i <= icount(leaf); i--, inum++) { int limit = from_be_u16(dict[i]), size = limit - offset; if (!size) continue; printf(" 0x%Lx: ", (L)inum); //printf("[%x] ", offset); if (size < 0) printf("<corrupt>\n"); else if (!size) printf("<empty>\n"); else { /* FIXME: this doesn't work in kernel */ struct inode inode = { .i_sb = vfs_sb(btree->sb) }; unsigned xsize = decode_xsize(&inode, leaf->table + offset, size); tux_inode(&inode)->xcache = xsize ? new_xcache(xsize) : NULL; decode_attrs(&inode, leaf->table + offset, size); dump_attrs(&inode); xcache_dump(&inode); free(tux_inode(&inode)->xcache); } offset = limit; } } void *ileaf_lookup(struct btree *btree, inum_t inum, struct ileaf *leaf, unsigned *result) { assert(inum >= ibase(leaf)); assert(inum < ibase(leaf) + btree->entries_per_leaf); unsigned at = inum - ibase(leaf), size = 0; void *attrs = NULL; printf("lookup inode 0x%Lx, %Lx + %x\n", (L)inum, (L)ibase(leaf), at); if (at < icount(leaf)) { be_u16 *dict = (void *)leaf + btree->sb->blocksize; unsigned offset = atdict(dict, at); if ((size = from_be_u16(*(dict - at - 1)) - offset)) attrs = leaf->table + offset; } *result = size; return attrs; }
std::string dump_method(const Function& func) { std::string out; out.append(".method ["); out.append(dump_attrs(func.attr)); out.append(" ] "); out.append(dump_lineno(func)); out.append(func.name); out.append("("); for (const auto& param : func.params) { folly::format(&out, " {}${},", param.byRef ? "&" : "", param.name); } out.append(") {\n"); out.append(dump_function_body(func)); out.append("}\n\n"); return out; }
int main(int argc, char *argv[]) { unsigned abits = DATA_BTREE_BIT|CTIME_SIZE_BIT|MODE_OWNER_BIT|LINK_COUNT_BIT|MTIME_BIT; struct sb *sb = &(struct sb){ .version = 0, .blocksize = 1 << 9, }; struct inode *inode = &(struct inode){ INIT_INODE(sb, 0x666), .present = abits, .i_uid = 0x12121212, .i_gid = 0x34343434, .btree = { .root = { .block = 0xcaba1f00dULL, .depth = 3 } }, .i_size = 0x123456789ULL, .i_ctime = spectime(0xdec0debeadULL), .i_mtime = spectime(0xbadfaced00dULL) }; char attrs[1000] = { }; printf("%i attributes starting from %i\n", MAX_ATTRS - MIN_ATTR, MIN_ATTR); printf("need %i attr bytes\n", encode_asize(abits)); printf("decode %ti attr bytes\n", sizeof(attrs)); decode_attrs(inode, attrs, sizeof(attrs)); dump_attrs(inode); exit(0); }
std::string dump_class(const Class& cls) { std::string out; out.append(".class "); if (cls.attr != 0) { out.append("["); out.append(dump_attrs(cls.attr)); out.append(" ] "); } out.append(cls.name); if (cls.parentName) { folly::format(&out, " extends {}", *cls.parentName); } if (!cls.implements.empty()) { out.append(" implements ("); for (const auto& name : cls.implements) { out.append(" "); out.append(name); } out.append(" )"); } out.append(" {\n"); if (!cls.traits.empty()) { out.append(" .use"); for (const auto& trait : cls.traits) { out.append(" "); out.append(trait); } out.append(";\n"); } for (const auto& property : cls.properties) { out.append(dump_property(property)); } for (const auto& method : cls.methods) { out.append(dump_method(*method)); } out.append("}\n\n"); return out; }
main (int argc, char *argv[]) { double x, y, z; int i, j, k, s1; int32 file_id; int32 vhead_id, vprof_id; int hnrec, hnfield, hnattr; int pnrec, pnfield, pnattr; struct rtp_head head1, head2; struct rtp_prof prof1[4], prof2[4]; struct FLIST (*hflist)[], (*pflist)[]; struct ALIST (*halist)[], (*palist)[]; struct ALIST halist1[8], palist1[8]; int npro = 2; /* initialize header and profile structures */ headinit(&head1); headinit(&head2); for (i = 0; i < npro; i++) { profinit(&prof1[i]); profinit(&prof2[i]); } /* fill in profile structures with some plausible data */ head1.ptype = 0; /* level profile */ head1.pfields = 3; /* profile with calculated radiances */ head1.pmin = 10; head1.pmax = 1000; head1.ngas = MAXGAS; for (i=0; i<MAXGAS; i++) head1.glist[i] = i + 1; head1.nchan = MAXCHAN; for (i=0; i<MAXCHAN; i++) { head1.vchan[i] = i + 600; head1.ichan[i] = i; } for (k=0; k < npro; k++) { prof1[k].plat = 32; prof1[k].plon = 55; prof1[k].ptime = 30000; prof1[k].stemp = 290; prof1[k].salti = 10; prof1[k].spres = 1000; for (i=0; i<MAXEMIS; i++) { prof1[k].efreq[i] = i*200 + 600; prof1[k].emis[i] = 1.0 - i / 1.0; prof1[k].rho[i] = i / 1.0; } prof1[k].nlevs = MAXLEV; for (j=0; j < MAXLEV; j++) { prof1[k].plevs[j] = j * 10; prof1[k].ptemp[j] = 200 + j; } for (i=0; i<MAXGAS; i++) for (j=0; j < MAXLEV; j++) prof1[k].gamnt[i][j] = (i+1) * 1000 + j + 1; prof1[k].scanang = 42; prof1[k].satzen = 45; for (i=0; i<MAXCHAN; i++) prof1[k].rcalc[i] = i / 10.0; strcpy((char *) prof1[k].pnote, "test comment string"); prof1[k].udef[10] = 997; } halist1[0].fname = "header"; halist1[0].aname = "title"; halist1[0].atext = "attribute test file"; halist1[1].fname = "ngas"; halist1[1].aname = "units"; halist1[1].atext = "(count)"; halist1[2].fname = "\0"; palist1[0].fname = "profiles"; palist1[0].aname = "title"; palist1[0].atext = "profile attribute test"; palist1[1].fname = "gamnt"; palist1[1].aname = "units"; palist1[1].atext = "PPMV"; palist1[2].fname = "\0"; fprintf(stdout, "============ write test ===========\n"); file_id = pvopen("pvtest.hdf", "c"); pvwrite1("header", file_id, &hfield, NHFIELD, &halist1, 2, &vhead_id); pvwrite1("profiles", file_id, &pfield, NPFIELD, &palist1, 2, &vprof_id); pvwrite2(vhead_id, 1, (char *) &head1); /* pvwrite2(vprof_id, 1, (char *) &prof1[0]); pvwrite2(vprof_id, 1, (char *) &prof1[1]); */ pvwrite2(vprof_id, 2, (char *) &prof1[0]); pvwrite3(vhead_id); pvwrite3(vprof_id); pvclose(file_id); fprintf(stdout, "============ read test ============\n"); file_id = pvopen("pvtest.hdf", "r"); pvread1("header", file_id, &hflist, &hnfield, &halist, &hnattr, &hnrec, &vhead_id); dump_flist(hflist, hnfield, "pvtest() header flist dump"); dump_attrs(halist, hnattr, "pvtest() header alist dump"); pvread1("profiles", file_id, &pflist, &pnfield, &palist, &pnattr, &pnrec, &vprof_id); dump_flist(pflist, pnfield, "pvtest() profile flist dump"); dump_attrs(palist, pnattr, "pvtest() profile alist dump"); pvread2(vhead_id, 1, (char *) &head2); /* pvread2(vprof_id, 1, (char *) &prof2[0]); pvread2(vprof_id, 1, (char *) &prof2[1]); */ pvread2(vprof_id, 2, (char *) &prof2[0]); dump_pstr(&head2, &prof2); pvread3(vprof_id); pvread3(vhead_id); pvclose(file_id); return(0); }
static int check_and_fix_dimensions(const PyArrayObject* arr,const int rank,npy_intp *dims) { /* This function fills in blanks (that are -1\'s) in dims list using the dimensions from arr. It also checks that non-blank dims will match with the corresponding values in arr dimensions. */ const npy_intp arr_size = (PyArray_NDIM(arr))?PyArray_Size((PyObject *)arr):1; #ifdef DEBUG_COPY_ND_ARRAY dump_attrs(arr); printf("check_and_fix_dimensions:init: dims="); dump_dims(rank,dims); #endif if (rank > PyArray_NDIM(arr)) { /* [1,2] -> [[1],[2]]; 1 -> [[1]] */ npy_intp new_size = 1; int free_axe = -1; int i; npy_intp d; /* Fill dims where -1 or 0; check dimensions; calc new_size; */ for(i=0;i<PyArray_NDIM(arr);++i) { d = PyArray_DIM(arr,i); if (dims[i] >= 0) { if (d>1 && dims[i]!=d) { fprintf(stderr,"%d-th dimension must be fixed to %" NPY_INTP_FMT " but got %" NPY_INTP_FMT "\n", i,dims[i], d); return 1; } if (!dims[i]) dims[i] = 1; } else { dims[i] = d ? d : 1; } new_size *= dims[i]; } for(i=PyArray_NDIM(arr);i<rank;++i) if (dims[i]>1) { fprintf(stderr,"%d-th dimension must be %" NPY_INTP_FMT " but got 0 (not defined).\n", i,dims[i]); return 1; } else if (free_axe<0) free_axe = i; else dims[i] = 1; if (free_axe>=0) { dims[free_axe] = arr_size/new_size; new_size *= dims[free_axe]; } if (new_size != arr_size) { fprintf(stderr,"unexpected array size: new_size=%" NPY_INTP_FMT ", got array with arr_size=%" NPY_INTP_FMT " (maybe too many free" " indices)\n", new_size,arr_size); return 1; } } else if (rank==PyArray_NDIM(arr)) { npy_intp new_size = 1; int i; npy_intp d; for (i=0; i<rank; ++i) { d = PyArray_DIM(arr,i); if (dims[i]>=0) { if (d > 1 && d!=dims[i]) { fprintf(stderr,"%d-th dimension must be fixed to %" NPY_INTP_FMT " but got %" NPY_INTP_FMT "\n", i,dims[i],d); return 1; } if (!dims[i]) dims[i] = 1; } else dims[i] = d; new_size *= dims[i]; } if (new_size != arr_size) { fprintf(stderr,"unexpected array size: new_size=%" NPY_INTP_FMT ", got array with arr_size=%" NPY_INTP_FMT "\n", new_size,arr_size); return 1; } } else { /* [[1,2]] -> [[1],[2]] */ int i,j; npy_intp d; int effrank; npy_intp size; for (i=0,effrank=0;i<PyArray_NDIM(arr);++i) if (PyArray_DIM(arr,i)>1) ++effrank; if (dims[rank-1]>=0) if (effrank>rank) { fprintf(stderr,"too many axes: %d (effrank=%d), expected rank=%d\n", PyArray_NDIM(arr),effrank,rank); return 1; } for (i=0,j=0;i<rank;++i) { while (j<PyArray_NDIM(arr) && PyArray_DIM(arr,j)<2) ++j; if (j>=PyArray_NDIM(arr)) d = 1; else d = PyArray_DIM(arr,j++); if (dims[i]>=0) { if (d>1 && d!=dims[i]) { fprintf(stderr,"%d-th dimension must be fixed to %" NPY_INTP_FMT " but got %" NPY_INTP_FMT " (real index=%d)\n", i,dims[i],d,j-1); return 1; } if (!dims[i]) dims[i] = 1; } else dims[i] = d; } for (i=rank;i<PyArray_NDIM(arr);++i) { /* [[1,2],[3,4]] -> [1,2,3,4] */ while (j<PyArray_NDIM(arr) && PyArray_DIM(arr,j)<2) ++j; if (j>=PyArray_NDIM(arr)) d = 1; else d = PyArray_DIM(arr,j++); dims[rank-1] *= d; } for (i=0,size=1;i<rank;++i) size *= dims[i]; if (size != arr_size) { fprintf(stderr,"unexpected array size: size=%" NPY_INTP_FMT ", arr_size=%" NPY_INTP_FMT ", rank=%d, effrank=%d, arr.nd=%d, dims=[", size,arr_size,rank,effrank,PyArray_NDIM(arr)); for (i=0;i<rank;++i) fprintf(stderr," %" NPY_INTP_FMT,dims[i]); fprintf(stderr," ], arr.dims=["); for (i=0;i<PyArray_NDIM(arr);++i) fprintf(stderr," %" NPY_INTP_FMT,PyArray_DIM(arr,i)); fprintf(stderr," ]\n"); return 1; } } #ifdef DEBUG_COPY_ND_ARRAY printf("check_and_fix_dimensions:end: dims="); dump_dims(rank,dims); #endif return 0; }