/* * Format the seqset `seq' as a string. Returns a newly allocated * string which must be free()d by the caller. */ EXPORTED char *seqset_cstring(const struct seqset *seq) { struct buf buf = BUF_INITIALIZER; unsigned i; if (!seq) return NULL; if (!seq->len) return NULL; for (i = 0; i < seq->len; i++) { /* join with comma if not the first item */ if (i) buf_putc(&buf, ','); /* single value only */ if (seq->set[i].low == seq->set[i].high) format_num(&buf, seq->set[i].low); /* value range */ else { format_num(&buf, seq->set[i].low); buf_putc(&buf, ':'); format_num(&buf, seq->set[i].high); } } return buf_release(&buf); }
void MainWidget::update_time() { int days = 0, hours = 0, mins = 0, secs = 0, tc = 0; tc = to.toTime_t() - QDateTime::currentDateTime().toTime_t(); // 剩余秒数 days = (int)(tc/60/60/24); // 计算天数 tc -= days*60*60*24; hours = (int)(tc/60/60); // 计算时数 tc -= hours*60*60; mins = (int)(tc/60); // 计算分数 tc -= mins*60; secs = tc%60; // 计算秒数 ui->ldays->setText( format_num(days) ); ui->lhours->setText( format_num(hours) ); ui->lmins->setText( format_num(mins) ); ui->lsecs->setText( format_num(secs) ); }
void childhandler(int sig) { int status, ret; int i; char buf[100]; static const char entered[] = "Entered childhandler\n"; static const char exited[] = "Exited childhandler\n"; write(1, entered, strlen(entered)); for (i = 0; i < nkids; i++) { if (kids[i] == NOT_USED) continue; retry: if ((ret = waitpid(kids[i], & status, WNOHANG)) == kids[i]) { strcpy(buf, "\treaped process "); strcat(buf, format_num(ret)); strcat(buf, "\n"); write(1, buf, strlen(buf)); kids[i] = NOT_USED; } else if (ret == 0) { strcpy(buf, "\tpid "); strcat(buf, format_num(kids[i])); strcat(buf, " not available yet\n"); write(1, buf, strlen(buf)); } else if (ret == -1 && errno == EINTR) { write(1, "\tretrying\n", 10); goto retry; } else { strcpy(buf, "\twaitpid() failed: "); strcat(buf, strerror(errno)); strcat(buf, "\n"); write(1, buf, strlen(buf)); } } write(1, exited, strlen(exited)); }
static void update_headnumx( int lvl, char *hnumstr, size_t hnsize ) { size_t pos; char *pn; int rc; *hnumstr = 0; pos = 0; if( layout_work.hx[lvl].number_form == num_none ) { return; // no number output } if( lvl > 0 ) { // reuse formatted number from previous lvl if( (layout_work.hx[lvl].number_form == num_prop) && (layout_work.hx[lvl - 1].headnsub != NULL) ) { strcpy( hnumstr, layout_work.hx[lvl - 1].headnsub->value ); pos = strlen( hnumstr ); } } if( pos > 0 ) { // we have a formatted number from parent lvl *(hnumstr + pos) = layout_work.heading.delim; pos++; *(hnumstr + pos) = 0; } pn = format_num( layout_work.hx[lvl].headn, hnumstr + pos, hnsize - pos, layout_work.hx[lvl].number_style ); if( pn != NULL ) { pos += strlen( pn ); // all ok } else { pn = hnumstr + pos; *pn = '?'; // create dummy number *(pn + 1) = 0; pos++; } if( layout_work.hx[lvl].headnsub == NULL ) {// first time here rc = add_symvar_addr( &global_dict, hnumx, hnumstr, no_subscript, 0, &layout_work.hx[lvl].headnsub ); } else { if( strlen( layout_work.hx[lvl].headnsub->value ) < strlen( hnumstr ) ) { // need more room layout_work.hx[lvl].headnsub->value = mem_realloc( layout_work.hx[lvl].headnsub->value, strlen( hnumstr ) + 1 ); } strcpy( layout_work.hx[lvl].headnsub->value, hnumstr ); } }
static void update_oops (BITui* ui, int which, int32_t val) { assert (which >= 0 || which <= 3); if (ui->stats[which] == val) { return; } if (ui->stats[which] > 0 && val == 0) { float col[4]; get_color_from_theme(0, col); robtk_lbl_set_color (ui->lbl_data[which], col[0], col[1], col[2], col[3]); } else if (ui->stats[which] == 0 && val > 0) { robtk_lbl_set_color (ui->lbl_data[which], 1.0, .2, .2, 1.0); } ui->stats[which] = val; char buf[32]; format_num (buf, val); robtk_lbl_set_text (ui->lbl_data[which], buf); }
/* * print formated number */ void fmt_printN(var_num_t x, int output, int handle) { fmt_node_t *node; char buf[64]; if (fmt_count == 0) { rt_raise(ERR_FORMAT_INVALID_FORMAT); } else { fmt_printL(output, handle); node = &fmt_stack[fmt_cur]; fmt_cur++; if (fmt_cur >= fmt_count) fmt_cur = 0; if (node->type == 1) { format_num(buf, node->fmt, x); pv_write(buf, output, handle); if (fmt_cur != 0) { fmt_printL(output, handle); } } else { rt_raise(ERR_FORMAT_INVALID_FORMAT); } } }
static void gml_li_ol( const gmltag * entry ) { char charnumber[MAX_L_AS_STR]; char * p; char * pn; int32_t t_align = 0; int32_t t_left_indent_1 = 0; int32_t t_left_indent_2 = 0; int32_t t_right_indent = 0; uint32_t num_len; scan_err = false; p = scan_start; if( nest_cb == NULL ) { xx_nest_err( err_li_lp_no_list ); // tag must be in a list scan_start = scan_stop + 1; return; } t_align = conv_hor_unit( &((ol_lay_level *)(nest_cb->lay_tag))->align, g_curr_font ); nest_cb->li_number++; pn = format_num( nest_cb->li_number, charnumber, MAX_L_AS_STR, ((ol_lay_level *)(nest_cb->lay_tag))->number_style ); if( pn != NULL ) { num_len = strlen( pn ); *(pn + num_len) = ' '; // trailing space like wgml4 does *(pn + num_len + 1) = '\0'; num_len++; } else { pn = charnumber; *pn = '?'; *(pn + 1) = 0; num_len = 1; } scr_process_break(); g_curr_font = ((ol_lay_level *)(nest_cb->lay_tag))->number_font; if( ProcFlags.need_li_lp ) { // first :li for this list set_skip_vars( &nest_cb->xl_pre_skip, NULL, NULL, 1, g_curr_font ); } else if( !nest_cb->compact ) { set_skip_vars( &((ol_lay_level *)(nest_cb->lay_tag))->skip, NULL, NULL, 1, g_curr_font ); } else { // compact set_skip_vars( NULL, NULL, NULL, 1, g_curr_font ); } post_space = 0; /* Use original indents, not values possibly modified by IN */ if( g_indent > 0 ) { t_left_indent_1 = conv_hor_unit( &((ol_lay_level *)(nest_cb->lay_tag))->left_indent, g_curr_font ) + nest_cb->prev->left_indent + nest_cb->prev->align; } else { t_left_indent_1 = conv_hor_unit( &((ol_lay_level *)(nest_cb->lay_tag))->left_indent, g_curr_font ) + nest_cb->prev->left_indent; } t_left_indent_2 = conv_hor_unit( &((ol_lay_level *)(nest_cb->lay_tag))->left_indent, g_curr_font ); t_right_indent = -1 * conv_hor_unit( &((ol_lay_level *)(nest_cb->lay_tag))->right_indent, g_curr_font ) + nest_cb->prev->right_indent; g_cur_left = nest_cb->lm + t_left_indent_2; g_page_right = nest_cb->rm + t_right_indent; g_cur_h_start = g_cur_left; ProcFlags.keep_left_margin = true; // keep special Note indent start_line_with_string( charnumber, g_curr_font, true ); g_cur_h_start = g_cur_left + t_align; if( t_line != NULL ) { if( t_line->last != NULL ) { g_cur_left += t_line->last->width + post_space; } } post_space = 0; if( g_cur_h_start > g_cur_left ) { g_cur_left = g_cur_h_start; } g_cur_h_start = g_cur_left; ju_x_start = g_cur_h_start; g_curr_font = ((ol_lay_level *)(nest_cb->lay_tag))->font; if( *p == '.' ) p++; // over '.' while( *p == ' ' ) p++; // skip initial spaces ProcFlags.need_li_lp = false; // 1. item in list processed if( *p ) { process_text( p, g_curr_font ); // if text follows } nest_cb->align = t_align; /* Set indents to their original values for the next LI */ if( g_indent > 0 ) { nest_cb->left_indent = t_left_indent_1; } else { nest_cb->left_indent = t_left_indent_1 + nest_cb->prev->align; } nest_cb->right_indent = t_right_indent; scan_start = scan_stop + 1; return; }
static void gen_toc( void ) { bool levels[7]; // track levels char buffer[11]; char postfix[12]; ffh_entry * curr; int i; int j; uint32_t cur_level; uint32_t indent[7]; uint32_t size; if( hd_list == NULL ) return; // no hd_list, no TOC /* Insert TOC into current section */ last_page_out(); // ensure are on new page g_skip = 0; // ignore remaining skip value set_section_banners( doc_sect_toc ); reset_t_page(); /* Set TOC margins and other values */ g_page_left = g_page_left_org + 2 * conv_hor_unit( &layout_work.toc.left_adjust, g_curr_font ); // matches wgml 4.0 g_page_right = g_page_right_org - conv_hor_unit( &layout_work.toc.right_adjust, g_curr_font ); size = conv_hor_unit( &layout_work.tocpgnum.size, g_curr_font ); // space from fill to right edge figlist_toc_tabs( layout_work.toc.fill_string, size ); /* Initialize levels and indent values */ for( i = 0; i < 7; i++ ) { levels[i] = false; indent[i] = 0; } /* Get converted indent values, which are cumulative */ for( i = 0; i < 7; i++ ) { for( j = i; j < 7; j++ ) { indent[j] += conv_hor_unit( &layout_work.tochx[i].indent, g_curr_font ); } } /* Output TOC */ concat_save = ProcFlags.concat; ProcFlags.concat = true; justify_save = ProcFlags.justify; ProcFlags.justify = ju_off; ProcFlags.keep_left_margin = true; // keep all indents while outputting text curr = hd_list; while( curr != NULL ) { cur_level = curr->number; for( i = 0; i < 7; i++ ) { if( i > cur_level ) { // all lower levels are inactive levels[i] = false; } } if( cur_level < layout_work.toc.toc_levels ) { g_curr_font = layout_work.tochx[cur_level].font; if( levels[cur_level] ) { spacing = layout_work.toc.spacing; set_skip_vars( &layout_work.tochx[cur_level].skip, NULL, NULL, spacing, g_curr_font ); } else { spacing = 1; set_skip_vars( &layout_work.tochx[cur_level].pre_skip, NULL, &layout_work.tochx[cur_level].post_skip, spacing, g_curr_font ); } g_cur_left = g_page_left + indent[cur_level]; g_cur_h_start = g_cur_left; if( curr->prefix != NULL ) { process_text( curr->prefix, g_curr_font ); g_cur_left = t_line->last->x_address + t_line->last->width + wgml_fonts[g_curr_font].spc_width; g_cur_h_start = g_cur_left; ProcFlags.ct = true; // emulate CT post_space = 0; } else { t_line = alloc_text_line(); // capture spacing if no prefix } if( !levels[cur_level] ) { spacing = layout_work.toc.spacing; set_skip_vars( NULL, NULL, NULL, spacing, g_curr_font ); } if( curr->text != NULL ) { g_page_right -= size; if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right -= tab_col; } else { g_page_right -= 3 * tab_col; } ProcFlags.stop_xspc = true; // suppress 2nd space after stop process_text( curr->text, g_curr_font ); if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right += tab_col; } else { g_page_right += 3 * tab_col; } g_page_right += size; } ProcFlags.ct = true; // emulate CT g_curr_font = FONT0; process_text( "$", g_curr_font ); format_num( curr->pageno, &buffer, sizeof( buffer ), curr->style ); strcpy_s( postfix, 12, "$" ); // insert tab characters strcat_s( postfix, 12, buffer ); // append page number g_curr_font = layout_work.tocpgnum.font; process_text( postfix, g_curr_font ); } scr_process_break(); // ensure line break levels[cur_level] = true; // first entry of level done curr = curr->next; } ProcFlags.concat = concat_save; ProcFlags.justify = justify_save; /* Re-establish current section */ last_page_out(); // ensure all pages output set_section_banners( ProcFlags.doc_sect ); reset_t_page(); return; }
static void gen_figlist( void ) { char buffer[11]; char postfix[12]; ffh_entry * curr; uint32_t size; if( fig_list == NULL ) return; // no fig_list, no FIGLIST /* Insert FIGLIST into current section */ last_page_out(); // ensure are on new page g_skip = 0; // ignore remaining skip value set_section_banners( doc_sect_figlist ); reset_t_page(); /* Set FIGLIST margins and other values */ g_page_left = g_page_left_org + 2 * conv_hor_unit( &layout_work.figlist.left_adjust, g_curr_font ); // matches wgml 4.0 g_page_right = g_page_right_org - conv_hor_unit( &layout_work.figlist.right_adjust, g_curr_font ); size = conv_hor_unit( &layout_work.flpgnum.size, g_curr_font ); // space from fill to right edge figlist_toc_tabs( layout_work.figlist.fill_string, size ); /* Output FIGLIST */ concat_save = ProcFlags.concat; ProcFlags.concat = true; justify_save = ProcFlags.justify; ProcFlags.justify = ju_off; ProcFlags.keep_left_margin = true; // keep all indents while outputting text curr = fig_list; while( curr != NULL ) { if( curr->flags & ffh_figcap ) { // no FIGCAP used, no FIGLIST output g_curr_font = FONT0; // wgml 4.0 uses font 0 if( ProcFlags.page_started ) { // not on first entry spacing = layout_work.figlist.spacing; set_skip_vars( NULL, NULL, NULL, spacing, g_curr_font ); } g_cur_left = g_page_left; g_cur_h_start = g_cur_left; process_text( curr->prefix, g_curr_font ); // caption prefix if( curr->text != NULL ) { g_cur_left = t_line->last->x_address + t_line->last->width + wgml_fonts[g_curr_font].spc_width; g_cur_h_start = g_cur_left; ProcFlags.ct = true; // emulate CT ProcFlags.stop_xspc = true; // suppress 2nd space after stops post_space = 0; g_page_right -= size; if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right -= tab_col; } else { g_page_right -= 3 * tab_col; } if( !ProcFlags.page_started ) { // first entry wrapping spacing = layout_work.figlist.spacing; } set_skip_vars( &layout_work.figlist.skip, NULL, NULL, spacing, g_curr_font ); process_text( curr->text, g_curr_font );// caption text if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right += tab_col; } else { g_page_right += 3 * tab_col; } g_page_right += size; } ProcFlags.ct = true; // emulate CT g_curr_font = FONT0; process_text( "$", g_curr_font ); format_num( curr->pageno, &buffer, sizeof( buffer ), curr->style ); strcpy_s( postfix, 12, "$" ); // insert tab characters strcat_s( postfix, 12, buffer ); // append page number g_curr_font = layout_work.flpgnum.font; process_text( postfix, g_curr_font ); } scr_process_break(); // ensure line break curr = curr->next; } ProcFlags.concat = concat_save; ProcFlags.justify = justify_save; /* Re-establish current section */ last_page_out(); // ensure all pages output set_section_banners( ProcFlags.doc_sect ); reset_t_page(); return; }