本文整理汇总了C++中write_header函数的典型用法代码示例。如果您正苦于以下问题:C++ write_header函数的具体用法?C++ write_header怎么用?C++ write_header使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_header函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
{
case 0:
if (!strcmp("mo", long_options[option_index].name))
{
opt_multi_out = 1;
mo_prefix = optarg;
}
if (!strcmp("interp", long_options[option_index].name))
{
opt_interp_proj = 1;
}
else if (!strcmp("scale", long_options[option_index].name))
{
if (!strcmp("mult", optarg))
opt_scale = SCALE_MULT;
else if (!strcmp("diag", optarg))
opt_scale = SCALE_DIAG;
else if (!strcmp("none", optarg))
opt_scale = SCALE_NONE;
else
error("Unrecognized scale type.");
}
else if (!strcmp("sort", long_options[option_index].name))
{
if (!strcmp("ev", optarg))
opt_sort = SORT_EV;
else if (!strcmp("lc", optarg))
opt_sort = SORT_LC;
else
error("Unrecognized sort type.");
}
else if (!strcmp("header", long_options[option_index].name))
{
write_header(err);
exit(0);
}
else if (!strcmp("add-back-mean", long_options[option_index].name))
{
opt_add_back_mean = 1;
}
else if (!strcmp("format", long_options[option_index].name))
{
fprintf(err,
"\n"
"#BEGIN INPUT\n"
"<PixeLens input text line 0>\n"
"<PixeLens input text line 1>\n"
" ...\n"
"<PixeLens input text line n>\n"
"#END INPUT\n"
"#BEGIN ENSEM \n"
"#BEGIN MODEL\n"
"<point 0>\n"
"<point 1>\n"
" ...\n"
"<point m>\n"
"#END MODEL\n"
" ...\n"
"#END ENSEM\n"
"\n"
"Blank lines are allowed and any line beginning with a '#' that is\n"
"not mentioned above is interpretted as a comment. It may be the case\n"
"that there are no models. \n"
"\n"
);
exit(0);
示例2: write_header
const char * Nes_File_Writer::write_block_header( nes_tag_t tag, long size )
{
write_remain = size;
return write_header( tag, size );
}
示例3: begin_comment
std::ostream& CPPCodeGenerator::operator ()(std::ostream &os) const
{
begin_comment(os);
write_header(os);
end_comment(os);
os << std::endl <<std::endl;
std::set< shared_ptr<model::Class> > class_dependencies;
m_Class->visit(bind(&CPPCodeGenerator::collect_class_dependencies, this, _1, ref(class_dependencies)));
os << "#ifndef J2CPP_INCLUDE_IMPLEMENTATION" << std::endl << std::endl;
std::string strIFNDEF=m_Class->get_cxx_include_path();
algorithm::to_upper(strIFNDEF);
algorithm::replace_all(strIFNDEF,"/","_");
os << "#ifndef J2CPP_" << strIFNDEF << "_HPP_DECL" << std::endl;
os << "#define J2CPP_" << strIFNDEF << "_HPP_DECL" << std::endl;
os << std::endl << std::endl;
BOOST_FOREACH(shared_ptr<model::Class> dependend_class, class_dependencies)
{
if(dependend_class==m_Class) continue;
std::vector< shared_ptr<model::Entity> > parentEntities;
if(shared_ptr<model::Entity> parentEntity=dependend_class->get_parent())
{
do
{
parentEntities.push_back(parentEntity);
parentEntity=parentEntity->get_parent();
}
while(parentEntity && parentEntity!=m_RootNS);
}
os << "namespace j2cpp { ";
for(std::size_t ns=0;ns<parentEntities.size();++ns)
{
if(shared_ptr<model::Namespace> enclosingNamespace=shared_ptr<model::Namespace>(parentEntities[parentEntities.size()-ns-1],detail::dynamic_cast_tag()))
{
os << "namespace " << enclosingNamespace->get_name() << " { ";
}
else
if(shared_ptr<model::Class> enclosingClass=shared_ptr<model::Class>(parentEntities[parentEntities.size()-ns-1],detail::dynamic_cast_tag()))
{
os << "namespace " << enclosingClass->get_name() << "_ { ";
}
}
os << "class " << dependend_class->get_name() << ";";
for(std::size_t ns=0;ns<parentEntities.size();++ns)
os << " }";
os << " }" << std::endl;
}
os << std::endl << std::endl;
std::set<std::string> dependenciesIncludes;
BOOST_FOREACH(shared_ptr<model::Class> dependend_class, class_dependencies)
{
if(dependend_class==m_Class) continue;
dependenciesIncludes.insert(dependend_class->get_cxx_include_path());
}
BOOST_FOREACH(std::string incPath, dependenciesIncludes)
{
os << "#include <" << incPath << ".hpp>" << std::endl;
}
示例4: ordered_map_file_open
int ordered_map_file_open(const char *path, OrderedMapFile **out_omf) {
*out_omf = nullptr;
OrderedMapFile *omf = create_zero<OrderedMapFile>();
if (!omf) {
ordered_map_file_close(omf);
return GenesisErrorNoMem;
}
if (omf->queue.error() || omf->cond.error() || omf->mutex.error()) {
ordered_map_file_close(omf);
return omf->queue.error() || omf->cond.error() || omf->mutex.error();
}
omf->list = create_zero<List<OrderedMapFileEntry *>>();
if (!omf->list) {
ordered_map_file_close(omf);
return GenesisErrorNoMem;
}
omf->map = create_zero<HashMap<ByteBuffer, OrderedMapFileEntry *, ByteBuffer::hash>>();
if (!omf->map) {
ordered_map_file_close(omf);
return GenesisErrorNoMem;
}
omf->running = true;
int err = omf->write_thread.start(run_write, omf);
if (err) {
ordered_map_file_close(omf);
return err;
}
bool open_for_writing = false;
omf->file = fopen(path, "rb+");
if (omf->file) {
int err = read_header(omf);
if (err == GenesisErrorEmptyFile) {
open_for_writing = true;
} else if (err) {
ordered_map_file_close(omf);
return err;
}
} else {
open_for_writing = true;
}
if (open_for_writing) {
omf->file = fopen(path, "wb+");
if (!omf->file) {
ordered_map_file_close(omf);
return GenesisErrorFileAccess;
}
int err = write_header(omf);
if (err) {
ordered_map_file_close(omf);
return err;
}
}
// read everything into list
omf->write_buffer.resize(TRANSACTION_METADATA_SIZE);
omf->transaction_offset = UUID_SIZE;
for (;;) {
size_t amt_read = fread(omf->write_buffer.raw(), 1, TRANSACTION_METADATA_SIZE, omf->file);
if (amt_read != TRANSACTION_METADATA_SIZE) {
// partial transaction. ignore it and we're done.
break;
}
uint8_t *transaction_ptr = (uint8_t*)omf->write_buffer.raw();
int transaction_size = read_uint32be(&transaction_ptr[4]);
omf->write_buffer.resize(transaction_size);
transaction_ptr = (uint8_t*)omf->write_buffer.raw();
size_t amt_to_read = transaction_size - TRANSACTION_METADATA_SIZE;
amt_read = fread(&transaction_ptr[TRANSACTION_METADATA_SIZE], 1, amt_to_read, omf->file);
if (amt_read != amt_to_read) {
// partial transaction. ignore it and we're done.
break;
}
uint32_t computed_crc = crc32(0, &transaction_ptr[4], transaction_size - 4);
uint32_t crc_from_file = read_uint32be(&transaction_ptr[0]);
if (computed_crc != crc_from_file) {
// crc check failed. ignore this transaction and we're done.
break;
}
int put_count = read_uint32be(&transaction_ptr[8]);
int del_count = read_uint32be(&transaction_ptr[12]);
int offset = TRANSACTION_METADATA_SIZE;
for (int i = 0; i < put_count; i += 1) {
int key_size = read_uint32be(&transaction_ptr[offset]); offset += 4;
int val_size = read_uint32be(&transaction_ptr[offset]); offset += 4;
OrderedMapFileEntry *entry = create_zero<OrderedMapFileEntry>();
if (!entry) {
ordered_map_file_close(omf);
return GenesisErrorNoMem;
}
entry->key = ByteBuffer((char*)&transaction_ptr[offset], key_size); offset += key_size;
entry->offset = omf->transaction_offset + offset;
//.........这里部分代码省略.........
示例5: main
int main(int argc, char *argv[])
/**********************************************************************
vicNl.c Dag Lohmann January 1996
This program controls file I/O and variable initialization as well as
being the primary driver for the model.
For details about variables, input files and subroutines check:
http://ce.washington.edu/~hydro/Lettenmaier/Models/VIC/VIC_home.html
UNITS: unless otherwise marked:
all water balance components are in mm
all energy balance components are in mks
depths, and lengths are in m
modifications:
1997-98 Model was updated from simple 2 layer water balance to
an extension of the full energy and water balance 3 layer
model. KAC
02-27-01 added controls for lake model KAC
11-18-02 Updated storage of lake water for water balance
calculations. LCB
03-12-03 Modifed to add AboveTreeLine to soil_con_struct so that
the model can make use of the computed treeline. KAC
04-10-03 Modified to initialize storm parameters using the state
file. KAC
04-10-03 Modified to start the model by skipping records until the
state file date is found. This replaces the previous method
of modifying the global file start date, which can change
the interpolation of atmospheric forcing data. KAC
04-15-03 Modified to store wet and dry fractions when intializing
water balance storage. This accounts for changes in model
state initialization, which now stores wet and dry fractions
rather than just averagedvalues. KAC
29-Oct-03 Modified the version display banner to print the version
string defined in global.h. TJB
01-Nov-04 Updated arglist for make_dist_prcp(), as part of fix for
QUICK_FLUX state file compatibility. TJB
02-Nov-04 Updated arglist for read_lakeparam(), as part of fix for
lake fraction readjustment. TJB
2005-Apr-13 OUTPUT_FORCE option now calls close_files(). TJB
2006-Sep-23 Implemented flexible output configuration; uses the new
out_data, out_data_files, and save_data structures. TJB
2006-Oct-16 Merged infiles and outfiles structs into filep_struct;
This included merging builtnames into filenames. TJB
2006-Nov-07 Removed LAKE_MODEL option. TJB
2006-Nov-07 Changed statefile to init_state in call to
check_state_file(). TJB
2007-Jan-15 Added PRT_HEADER option; added call to
write_header(). TJB
2007-Apr-04 Added option to continue run after a cell fails. GCT/KAC
2007-Apr-21 Added calls to free_dmy(), free_out_data_files(),
free_out_data(), and free_veglib(). Added closing of
all parameter files. TJB
2007-Aug-21 Return ErrorFlag from initialize_model_state. JCA
2007-Sep-14 Excluded calls to free_veglib() and closing of parameter
files other than the soil param file for the case
when OUTPUT_FORCE=TRUE. TJB
2007-Nov-06 Moved computation of cell_area from read_lakeparam() to
read_soilparam() and read_soilparam_arc(). TJB
2008-May-05 Added prcp fraction (mu) to initial water storage
computation. This solves water balance errors for the
case where DIST_PRCP is TRUE. TJB
2009-Jan-16 Added soil_con.avgJulyAirTemp to argument list of
initialize_atmos(). TJB
2009-Jun-09 Modified to use extension of veg_lib structure to contain
bare soil information. TJB
2009-Jul-07 Added soil_con.BandElev[] to read_snowband() arg list. TJB
2009-Jul-31 Replaced references to N+1st veg tile with references
to index of lake/wetland tile. TJB
2009-Sep-28 Replaced initial water/energy storage computations and
calls to calc_water_balance_error/calc_energy_balance_error
with an initial call to put_data. Modified the call to
read_snowband(). TJB
2009-Dec-11 Removed save_data structure from argument list of
initialize_model_state(). TJB
2010-Mar-31 Added cell_area to initialize_atmos(). TJB
2010-Apr-28 Removed individual soil_con variables from argument list
of initialize_atmos() and replaced with *soil_con. TJB
2010-Nov-10 Added closing of state files. TJB
2011-Jan-04 Made read_soilparam_arc() a sub-function of
read_soilparam(). TJB
2012-Jan-16 Removed LINK_DEBUG code BN
**********************************************************************/
{
extern veg_lib_struct *veg_lib;
extern option_struct options;
extern Error_struct Error;
extern global_param_struct global_param;
/** Variable Declarations **/
char NEWCELL;
char LASTREC;
char MODEL_DONE;
char RUN_MODEL;
char *init_STILL_STORM;
char ErrStr[MAXSTRING];
int rec, i, j;
//.........这里部分代码省略.........
示例6: write_data
void write_data( t_uint8 id, t_uint16 data )
{
write_header( id, XTYPE_DATA, data );
}
示例7: write_header
void VrmlExporter::begin() {
file_.open(file_name_, std::ios::out);
write_header();
}
示例8: main
//.........这里部分代码省略.........
/**********************************************
* BUILDING THE HMM
**********************************************/
/* Build the motif-based HMM. */
if (hmm_type == LINEAR_HMM) {
if (order_spacing != NULL) {
reorder_motifs(order_spacing, &num_motifs, motifs);
}
else {
die("No order specified for the motifs.\n"
"For the linear model the motif file must contain motif occurence\n"
"data or the motif order must be specified using "
"the --order option.");
}
build_linear_hmm(
background,
order_spacing,
spacer_states,
motifs,
num_motifs,
fim,
&the_hmm
);
} else if (hmm_type == COMPLETE_HMM) {
build_complete_hmm(
background,
spacer_states,
motifs,
num_motifs,
transp_freq,
spacer_ave,
fim,
&the_hmm
);
} else if (hmm_type == STAR_HMM) {
build_star_hmm(
background,
spacer_states,
motifs,
num_motifs,
fim,
&the_hmm
);
}
// Add some global information.
copy_string(&(the_hmm->motif_file), meme_filename);
/**********************************************
* WRITING THE HMM
**********************************************/
/* Print the header. */
if (print_header)
write_header(
program,
"",
description,
meme_filename,
NULL,
NULL,
stdout
);
/* Write the HMM. */
write_mhmm(verbosity, the_hmm, stdout);
/* Print the program parameters. */
if (print_params) {
printf("Program parameters for mhmm\n");
printf(" MEME file: %s\n", meme_filename);
printf(" Motifs:");
write_string_list(" ", requested_motifs, stdout);
printf("\n");
printf(" Model topology: %s\n",
convert_enum_type(hmm_type, HMM_STRS, NUM_HMM_T));
printf(" States per spacer: %d\n", spacer_states);
printf(" Spacers are free-insertion modules: %s\n",
boolean_to_string(fim));
printf("\n");
}
free_array(background);
free_string_list(requested_motifs);
free_order(order_spacing);
free_matrix(transp_freq);
free_matrix(spacer_ave);
for (i_motif = 0; i_motif < num_motifs; i_motif++)
free_motif(&(motifs[i_motif]));
free_mhmm(the_hmm);
return(0);
}
示例9: write_type_header
/*=== write_type_header ===================================================
* <Description Text>
*
* Assumes: ?
*
* Returns: nothing
*
* Modifies: ?
*
* Calls: nothing
*
* Called By: ?
*
* History: MM/DD/YY MRH Created initial version based on function
* 'func()' in motif/csr/file.c
*/
void
write_type_header(FILE *header)
{
char description[512];
FIELD *field;
char define_name[80];
/*
* Write header comment
*/
sprintf(description, "\
Public interface to the '%s' Abstract Datatype. \
This file was automatically generated.",
gAPIType);
write_header(header, gTypeHeaderName, description);
fprintf(header, "#ifndef _%s_\n", gTypeHeaderNameUC);
fprintf(header, "#define _%s_\n", gTypeHeaderNameUC);
/*
* extern "C" if a C++ compiler.
*/
fprintf(header, "\n#ifdef %s\n", CPLUSPLUS);
fprintf(header, "extern \"C\"\n{\n");
fprintf(header, "#endif\n");
/*
* #Defines for string lengths of objects.
*/
sprintf(description, "\n\n\
The following are '#define's of the string lengths of each of the %s \
field objects.",
gAPIType);
write_comment(header, 0, description);
for (field = gFields; field; field = field->next)
{
if (field->exclude ||
(field->join && ! field->is_master_join))
continue;
if (field->field_type == FIELD_STRING_TYPE)
{
sprintf(define_name, "GAL_%s_%s_LEN", gAPINameUC, ((field->has_alias)
? field->alias_uc
: field->name_uc));
write_define(header, define_name, field->field_length + 1);
}
}
/*
* Insert type prototype. The key is public knowledge.
*/
sprintf(description, "\n\n\
%s provides a unique key interface to the %s abstract datatype.",
gAPIKeyType, gAPIType);
write_comment(header, 0, description);
fprintf(header, "typedef struct _gal_%s_key_data_\n{\n", gAPIName);
for (field = gFields; field; field = field->next)
if (field->is_key)
write_object_field(header, field);
fprintf(header, "\n}");
fprintf(header, " %s,\n", gAPIKeyTypeData);
fprintf(header, " *%s;\n", gAPIKeyType);
/*
* extern "C" if a C++ compiler.
*/
fprintf(header, "\n#ifdef %s\n", CPLUSPLUS);
fprintf(header, "}\n");
fprintf(header, "#endif\n\n");
fprintf(header, "#endif /* #ifndef _%s_ */\n", gTypeHeaderNameUC);
}
示例10: cipher_filter_cfb
/*
* This filter is used to en/de-cipher data with a symmetric algorithm
*/
int
cipher_filter_cfb (void *opaque, int control,
iobuf_t a, byte *buf, size_t *ret_len)
{
cipher_filter_context_t *cfx = opaque;
size_t size = *ret_len;
int rc = 0;
if (control == IOBUFCTRL_UNDERFLOW) /* decrypt */
{
rc = -1; /* not yet used */
}
else if (control == IOBUFCTRL_FLUSH) /* encrypt */
{
log_assert (a);
if (!cfx->wrote_header)
write_header (cfx, a);
if (cfx->mdc_hash)
gcry_md_write (cfx->mdc_hash, buf, size);
gcry_cipher_encrypt (cfx->cipher_hd, buf, size, NULL, 0);
if (cfx->short_blklen_warn)
{
cfx->short_blklen_count += size;
if (cfx->short_blklen_count > (150 * 1024 * 1024))
{
log_info ("WARNING: encrypting more than %d MiB with algorithm "
"%s should be avoided\n", 150,
openpgp_cipher_algo_name (cfx->dek->algo));
cfx->short_blklen_warn = 0; /* Don't show again. */
}
}
rc = iobuf_write (a, buf, size);
}
else if (control == IOBUFCTRL_FREE)
{
if (cfx->mdc_hash)
{
byte *hash;
int hashlen = gcry_md_get_algo_dlen (gcry_md_get_algo(cfx->mdc_hash));
byte temp[22];
log_assert (hashlen == 20);
/* We must hash the prefix of the MDC packet here. */
temp[0] = 0xd3;
temp[1] = 0x14;
gcry_md_putc (cfx->mdc_hash, temp[0]);
gcry_md_putc (cfx->mdc_hash, temp[1]);
gcry_md_final (cfx->mdc_hash);
hash = gcry_md_read (cfx->mdc_hash, 0);
memcpy(temp+2, hash, 20);
gcry_cipher_encrypt (cfx->cipher_hd, temp, 22, NULL, 0);
gcry_md_close (cfx->mdc_hash); cfx->mdc_hash = NULL;
if (iobuf_write( a, temp, 22))
log_error ("writing MDC packet failed\n");
}
gcry_cipher_close (cfx->cipher_hd);
}
else if (control == IOBUFCTRL_DESC)
{
mem2str (buf, "cipher_filter_cfb", *ret_len);
}
return rc;
}
示例11: write_arduino_code_verbose
/* Same as write_arduino_code(), but uses the verbose versions of functions */
void write_arduino_code_verbose(FILE *output_file, MuxPipe *pipes, size_t total_pipes)
{
write_header(output_file);
write_setup_verbose(output_file, pipes, total_pipes);
write_loop_verbose(output_file);
}
示例12: gzip
/* ===========================================================================
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb"). The file is given either by file descriptor
or path name (if fd == -1).
az_open returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR).
*/
int az_open (azio_stream *s, const char *path, int Flags, File fd)
{
int err;
int level = Z_DEFAULT_COMPRESSION; /* compression level */
int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
s->stream.zalloc = (alloc_func)0;
s->stream.zfree = (free_func)0;
s->stream.opaque = (voidpf)0;
memset(s->inbuf, 0, AZ_BUFSIZE_READ);
memset(s->outbuf, 0, AZ_BUFSIZE_WRITE);
s->stream.next_in = s->inbuf;
s->stream.next_out = s->outbuf;
s->stream.avail_in = s->stream.avail_out = 0;
s->z_err = Z_OK;
s->z_eof = 0;
s->in = 0;
s->out = 0;
s->back = EOF;
s->crc = crc32(0L, Z_NULL, 0);
s->transparent = 0;
s->mode = 'r';
s->version = (unsigned char)az_magic[1]; /* this needs to be a define to version */
s->minor_version= (unsigned char) az_magic[2]; /* minor version */
s->dirty= AZ_STATE_CLEAN;
/*
We do our own version of append by nature.
We must always have write access to take card of the header.
*/
DBUG_ASSERT(Flags | O_APPEND);
DBUG_ASSERT(Flags | O_WRONLY);
if (Flags & O_RDWR)
s->mode = 'w';
if (s->mode == 'w')
{
err = deflateInit2(&(s->stream), level,
Z_DEFLATED, -MAX_WBITS, 8, strategy);
/* windowBits is passed < 0 to suppress zlib header */
s->stream.next_out = s->outbuf;
if (err != Z_OK)
{
destroy(s);
return Z_NULL;
}
} else {
s->stream.next_in = s->inbuf;
err = inflateInit2(&(s->stream), -MAX_WBITS);
/* windowBits is passed < 0 to tell that there is no zlib header.
* Note that in this case inflate *requires* an extra "dummy" byte
* after the compressed stream in order to complete decompression and
* return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
* present after the compressed stream.
*/
if (err != Z_OK)
{
destroy(s);
return Z_NULL;
}
}
s->stream.avail_out = AZ_BUFSIZE_WRITE;
errno = 0;
s->file = fd < 0 ? my_open(path, Flags, MYF(0)) : fd;
if (s->file < 0 )
{
destroy(s);
return Z_NULL;
}
if (Flags & O_CREAT || Flags & O_TRUNC)
{
s->rows= 0;
s->forced_flushes= 0;
s->shortest_row= 0;
s->longest_row= 0;
s->auto_increment= 0;
s->check_point= 0;
s->comment_start_pos= 0;
s->comment_length= 0;
s->frm_start_pos= 0;
s->frm_length= 0;
s->dirty= 1; /* We create the file dirty */
s->start = AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
write_header(s);
my_seek(s->file, 0, MY_SEEK_END, MYF(0));
//.........这里部分代码省略.........
示例13: print_data_button
/*######################### print_data_button() #########################*/
void
print_data_button(Widget w, XtPointer client_data, XtPointer call_data)
{
char message[MAX_MESSAGE_LENGTH],
sum_sep_line[MAX_OUTPUT_LINE_LENGTH + SHOW_LONG_FORMAT + 1];
/* Prepare separator line. */
(void)memset(sum_sep_line, '=', sum_line_length);
sum_sep_line[sum_line_length] = '\0';
if (range_type == SELECTION_TOGGLE)
{
int no_selected,
*select_list;
if (XmListGetSelectedPos(listbox_w, &select_list, &no_selected) == False)
{
show_message(statusbox_w, "No data selected for printing!");
XtPopdown(printshell);
return;
}
else
{
int fd,
prepare_status;
char *line,
line_buffer[256];
XmStringTable all_items;
if (device_type == PRINTER_TOGGLE)
{
prepare_status = prepare_printer(&fd);
}
else
{
prepare_status = prepare_file(&fd, (device_type == MAIL_TOGGLE) ? 0 : 1);
if ((prepare_status != SUCCESS) && (device_type == MAIL_TOGGLE))
{
prepare_tmp_name();
prepare_status = prepare_file(&fd, 1);
}
}
if (prepare_status == SUCCESS)
{
register int i,
length;
write_header(fd, sum_sep_line);
XtVaGetValues(listbox_w, XmNitems, &all_items, NULL);
for (i = 0; i < no_selected; i++)
{
XmStringGetLtoR(all_items[select_list[i] - 1], XmFONTLIST_DEFAULT_TAG, &line);
length = sprintf(line_buffer, "%s\n", line);
if (write(fd, line_buffer, length) != length)
{
(void)fprintf(stderr, "write() error : %s (%s %d)\n",
strerror(errno), __FILE__, __LINE__);
XtFree(line);
exit(INCORRECT);
}
XtFree(line);
XmListDeselectPos(listbox_w, select_list[i]);
}
write_summary(fd, sum_sep_line);
/*
* Remember to insert the correct summary, since all files
* have now been deselected.
*/
(void)strcpy(summary_str, total_summary_str);
SHOW_SUMMARY_DATA();
if (device_type == PRINTER_TOGGLE)
{
int status;
char buf;
/* Send Control-D to printer queue. */
buf = CONTROL_D;
if (write(fd, &buf, 1) != 1)
{
(void)fprintf(stderr, "write() error : %s (%s %d)\n",
strerror(errno), __FILE__, __LINE__);
XtFree(line);
exit(INCORRECT);
}
if ((status = pclose(fp)) < 0)
{
(void)sprintf(message,
"Failed to send printer command (%d) : %s",
status, strerror(errno));
}
else
{
(void)sprintf(message, "Send job to printer (%d)", status);
}
//.........这里部分代码省略.........
示例14: BX_DEBUG
/* This could be done much better, I'm sure. In fact, the whole header doesn't
* need to be re-written each time a new tlb is allocated nor does the whole
* slb need to be re-written (most of the time) but that can be changed whenever
* it becomes an issue... image I/O is not a bottleneck.
*/
bool vmware3_image_t::sync()
{
if(current->synced)
return true;
unsigned relative_offset = (unsigned)(current->offset - current->min_offset);
unsigned i = relative_offset >> FL_SHIFT;
unsigned j = (relative_offset & ~FL_MASK) / tlb_size;
if (current->slb[i][j] == 0)
{
if (current->flb[i] == 0)
{
unsigned slb_size = slb_count * 4;
/* Re-write the FLB */
current->flb[i] = current->header.next_sector_to_allocate;
if(::lseek(current->fd, current->header.flb_offset_sectors * 512, SEEK_SET) < 0)
{
BX_DEBUG(("could not seek vmware3 COW image to flb on sync"));
return false;
}
if(write_ints(current->fd, current->flb, current->header.flb_count) < 0)
{
BX_DEBUG(("could not re-write flb to vmware3 COW image on sync"));
return false;
}
current->header.next_sector_to_allocate += (slb_size / 512) + ((slb_size % 512) ? 1 : 0);
}
/* Re-write the SLB */
current->slb[i][j] = current->header.next_sector_to_allocate;
if(::lseek(current->fd, current->flb[i] * 512, SEEK_SET) < 0)
{
BX_DEBUG(("could not seek vmware3 COW image to slb on sync"));
return false;
}
if(write_ints(current->fd, current->slb[i], slb_count) < 0)
{
BX_DEBUG(("could not re-write slb to vmware3 COW image on sync"));
return false;
}
current->header.next_sector_to_allocate += current->header.tlb_size_sectors;
/* Update the header */
if(::lseek(current->fd, 0, SEEK_SET) < 0)
{
BX_DEBUG(("could not seek to vmware3 COW image to offset 0 on sync"));
return false;
}
if(write_header(current->fd, current->header) < 0)
{
BX_DEBUG(("could not re-write header to vmware3 COW image on sync"));
return false;
}
}
if(::lseek(current->fd, current->slb[i][j] * 512, SEEK_SET) < 0)
{
BX_DEBUG(("could not seek vmware3 COW image to offset %d on sync", current->slb[i][j] * 512));
return false;
}
if(::write(current->fd, current->tlb, tlb_size) < 0)
{
BX_DEBUG(("could not write tlb to vmware3 COW image on sync"));
return false;
}
current->synced = true;
return true;
}
示例15: csa_new_from_bwt
//.........这里部分代码省略.........
if (csa.D >= csa.n) {
printf("D=%d >= n=%ld\n",csa.D,csa.n);
exit(0);
}
if (csa.D2 >= csa.n) {
printf("D2=%d >= n=%ld\n",csa.D2,csa.n);
exit(0);
}
if (idx_id >= 0) {
n = csa.n;
k = csa.k;
//// compute SA and ISA
if (csa.D > 0) csa.SA = (uchar *) mymalloc(((n-1)/csa.D+1+1)*k);
if (csa.D2 > 0) csa.ISA = (uchar *) mymalloc(((n-1)/csa.D2+1+1)*k);
if (csa.D == 0 && csa.D2 == 0) goto brk;
switch (psi_id & 0x3f) {
case ID_DIFF_GAMMA:
case ID_DIFF_GAMMA_RL:
case ID_DIFF_GAMMA_SPARSE:
case ID_DIFF_GAMMA_RL_SPARSE:
case ID_SPARSE4:
case ID_DIFF_GAMMA_RR:
j = 0;
for (i=0; i<=n; i++) {
display_progressbar("making sa ",i,n);
j = csa.psi(&csa,j);
// sa[j] = i;
if (csa.D > 0 && j % csa.D == 0) {
putuint(csa.SA,j / csa.D,i,k);
}
if (csa.D2 > 0 && i % csa.D2 == 0) {
putuint(csa.ISA,i / csa.D2,j,k);
}
}
// putuint(csa.SA,0,n,k);
break;
case ID_BWT_DNA:
case ID_BWT_BIT:
case ID_BWT_WT:
case ID_BWT_WT_HUF:
case ID_BWT_WT_DENSE:
case ID_BWT_WT_SPARSE4:
case ID_BWT_WT_RR:
case ID_BWT_HUF:
j = 0;
for (i=n-1; i>=0; i--) {
display_progressbar("making sa ",i,n);
v = csa.LF(&csa,j);
// printf("LF[%ld] = %ld\n",j,v);
j = v;
if (csa.D > 0 && j % csa.D == 0) putuint(csa.SA, j/csa.D , i, k);
if (csa.D2 > 0 && i % csa.D2 == 0) putuint(csa.ISA, i/csa.D2, j, k);
}
putuint(csa.SA,0,n,k);
break;
default:
break;
}
brk:
//// write idx
f2 = fopen(fidx,"wb"); /* directory */
if (f2 == NULL) {
perror("csa2_new1: ");
exit(1);
}
isize = 0;
writeint(4,VERSION,f2); /* version */
isize += 4;
writeint(1,ID_HEADER,f2); // header ID
isize += 1;
isize = write_header(&csa, f2, isize);
if (csa.D > 0) {
writeint(1,ID_SA,f2);
isize += 1;
isize = write_sa(&csa, f2, isize);
}
if (csa.D2 > 0) {
writeint(1,ID_ISA,f2);
isize += 1;
isize = write_isa(&csa, f2, isize);
}
fclose(f2);
if (csa.D > 0) free(csa.SA);
if (csa.D2 > 0) free(csa.ISA);
printf("Total %ld bytes (%1.3f bpc)\n",(psize+isize),
(double)(psize+isize)*8/csa.n);
}
free(fidx);
}