示例#1
0
文件: cordprnt.c 项目: sebgod/bdwgc
int CORD_vsprintf(CORD * out, CORD format, va_list args)
{
    CORD_ec result;
    register int count;
    register char current;
    CORD_pos pos;
    char conv_spec[CONV_SPEC_LEN + 1];

    CORD_ec_init(result);
    for (CORD_set_pos(pos, format, 0); CORD_pos_valid(pos); CORD_next(pos)) {
        current = CORD_pos_fetch(pos);
        if (current == '%') {
            CORD_next(pos);
            if (!CORD_pos_valid(pos)) return(-1);
            current = CORD_pos_fetch(pos);
            if (current == '%') {
                CORD_ec_append(result, current);
            } else {
                int width, prec;
                int left_adj = 0;
                int long_arg = 0;
                CORD arg;
                size_t len;

                if (extract_conv_spec(pos, conv_spec,
                                      &width, &prec,
                                      &left_adj, &long_arg) < 0) {
                    return(-1);
                }
                current = CORD_pos_fetch(pos);
                switch(current) {
                case 'n':
                    /* Assign length to next arg */
                    if (long_arg == 0) {
                        int * pos_ptr;
                        pos_ptr = va_arg(args, int *);
                        *pos_ptr = ec_len(result);
                    } else if (long_arg > 0) {
                        long * pos_ptr;
                        pos_ptr = va_arg(args, long *);
                        *pos_ptr = ec_len(result);
                    } else {
示例#2
0
CORD CORD_from_file_eager(FILE * f)
{
    register int c;
    CORD_ec ecord;

    CORD_ec_init(ecord);
    for(;;) {
        c = getc(f);
        if (c == 0) {
          /* Append the right number of NULs    */
          /* Note that any string of NULs is rpresented in 4 words, */
          /* independent of its length.                 */
            register size_t count = 1;

            CORD_ec_flush_buf(ecord);
            while ((c = getc(f)) == 0) count++;
            ecord[0].ec_cord = CORD_cat(ecord[0].ec_cord, CORD_nul(count));
        }
        if (c == EOF) break;
        CORD_ec_append(ecord, c);
    }
    (void) fclose(f);
    return(CORD_balance(CORD_ec_to_cord(ecord)));
}