void print_file_info(HANDLE hOut, BY_HANDLE_FILE_INFORMATION & bhfi, const wchar_t * filename) { char output[2048]; BprintBuffer<char> bp(output, NUMELMS(output), hOut); //char * pout = output; //if (label_output) bp.append("LINKS: "); //bp.append_num(bhfi.nNumberOfLinks); //if (label_output) bp.append(" INDEX:"); char numbuf[64], *p = numbuf; if (hex_filenumber) p = append(p, "0x", &numbuf[64]); if (quad_filenumber) { if (hex_filenumber) { append_hex(p, _qword(bhfi.nFileIndexLow, bhfi.nFileIndexHigh)); } else { append_num(p, _qword(bhfi.nFileIndexLow, bhfi.nFileIndexHigh)); } } else if (wide_filenumber) { if (hex_filenumber) { p = append_hex(p, bhfi.nFileIndexHigh, 2); p = append(p, ".", &numbuf[64]); p = append_hex(p, bhfi.nFileIndexLow, 8); } else { p = append_num(p, bhfi.nFileIndexHigh, false, 2, '0'); p = append(p, ".", &numbuf[64]); p = append_num(p, bhfi.nFileIndexLow, false, 9, '0'); } } else { unsigned __int64 id = _qword(bhfi.nFileIndexLow, bhfi.nFileIndexHigh); unsigned int sect = bhfi.nFileIndexHigh >> 16; id &= 0xFFFFFFFFFFFFull; if (hex_filenumber) { p = append_hex(p, sect, 2); p = append(p, ".", &numbuf[64]); p = append_hex(p, id, 6); } else { p = append_num(p, sect, false, 2, '0'); p = append(p, ".", &numbuf[64]); p = append_num(p, id, false, 7, '0'); } } //if (label_output) bp.append(" NAME:"); //*pout++ = ' '; ULONG_PTR vargs[] = { bhfi.nNumberOfLinks, (ULONG_PTR)(char*)numbuf, (ULONG_PTR)filename }; bp.vformatl(label_output ? "LINKS: {0:d} INDEX: {1} NAME: {2:w}" : " {0:d} {1} {2:w}", NUMELMS(vargs), vargs); //char * pend = output+sizeof(output)-6; //while (pout < pend && *filename) { *pout++ = (char)*filename++; } //if (*filename) bp.append("..."); //bp.EndLine(false); if ( ! bp.Write()) ExitProcess(GetLastError()); }
static gboolean gsf_export(GwyContainer *container, const gchar *filename, G_GNUC_UNUSED GwyRunType mode, GError **error) { static const gchar zeroes[4] = { 0, 0, 0, 0 }; GString *header = NULL; gfloat *dfl = NULL; guint i, xres, yres, padding; gint id; GwyDataField *dfield; const gdouble *d; gdouble v; gchar *s; GwySIUnit *unit, *emptyunit; FILE *fh; gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, &dfield, GWY_APP_DATA_FIELD_ID, &id, 0); if (!dfield) { err_NO_CHANNEL_EXPORT(error); return FALSE; } if (!(fh = g_fopen(filename, "wb"))) { err_OPEN_WRITE(error); return FALSE; } xres = gwy_data_field_get_xres(dfield); yres = gwy_data_field_get_yres(dfield); header = g_string_new(MAGIC); g_string_append_printf(header, "XRes = %u\n", xres); g_string_append_printf(header, "YRes = %u\n", yres); append_num(header, "XReal", gwy_data_field_get_xreal(dfield)); append_num(header, "YReal", gwy_data_field_get_yreal(dfield)); if ((v = gwy_data_field_get_xoffset(dfield))) append_num(header, "XOffset", v); if ((v = gwy_data_field_get_yoffset(dfield))) append_num(header, "YOffset", v); emptyunit = gwy_si_unit_new(NULL); unit = gwy_data_field_get_si_unit_xy(dfield); if (!gwy_si_unit_equal(unit, emptyunit)) { s = gwy_si_unit_get_string(unit, GWY_SI_UNIT_FORMAT_PLAIN); g_string_append_printf(header, "XYUnits = %s\n", s); g_free(s); } unit = gwy_data_field_get_si_unit_z(dfield); if (!gwy_si_unit_equal(unit, emptyunit)) { s = gwy_si_unit_get_string(unit, GWY_SI_UNIT_FORMAT_PLAIN); g_string_append_printf(header, "ZUnits = %s\n", s); g_free(s); } g_object_unref(emptyunit); s = gwy_app_get_data_field_title(container, id); g_string_append_printf(header, "Title = %s\n", s); g_free(s); if (fwrite(header->str, 1, header->len, fh) != header->len) { err_WRITE(error); goto fail; } padding = 4 - (header->len % 4); if (fwrite(zeroes, 1, padding, fh) != padding) { err_WRITE(error); goto fail; } g_string_free(header, TRUE); header = NULL; dfl = g_new(gfloat, xres*yres); d = gwy_data_field_get_data_const(dfield); for (i = 0; i < xres*yres; i++) { union { guchar pp[4]; float f; } z; z.f = d[i]; #if (G_BYTE_ORDER == G_BIG_ENDIAN) GWY_SWAP(guchar, z.pp[0], z.pp[3]); GWY_SWAP(guchar, z.pp[1], z.pp[2]); #endif dfl[i] = z.f; } if (fwrite(dfl, sizeof(gfloat), xres*yres, fh) != xres*yres) { err_WRITE(error); goto fail; } g_free(dfl); fclose(fh); return TRUE; fail: if (fh) fclose(fh); g_unlink(filename); if (header) g_string_free(header, TRUE); g_free(dfl); return FALSE; }