diff --git a/pdf.c b/pdf.c index 390686abc4e02a8fb2585bbfc3013a4fe618386d..fb4fc4c3583014a9a3bbbb94351d85d7f2967144 100644 --- a/pdf.c +++ b/pdf.c @@ -511,7 +511,7 @@ act_ahexeod(const HParseResult *p, void *u) // uint8_t b = H_CAST_UINT(p->ast); //XXX DEBUG - fprintf(stdout, "acthexeod:: Here\n"); + //fprintf(stdout, "acthexeod:: Here\n"); return NULL; } @@ -625,7 +625,7 @@ act_a85group(const HParseResult *p, void *u) bytes[1] = (fourbytes & 0x00FF0000) >> 16; bytes[2] = (fourbytes & 0x0000FF00) >> 8; bytes[3] = (fourbytes & 0x000000FF); - fprintf(stdout, "%6x ==> %2x %2x %2x %2x\n", fourbytes, bytes[0], bytes[1], bytes[2], bytes[3]); // XXX debug + //fprintf(stdout, "%6x ==> %2x %2x %2x %2x\n", fourbytes, bytes[0], bytes[1], bytes[2], bytes[3]); // XXX debug } return H_MAKE_BYTES(bytes, 4); } @@ -645,8 +645,8 @@ act_a85partial2group(const HParseResult *p, void *u) for (int i=0; i<2; i++) { assert(digits[i]->token_type == TT_SEQUENCE); fourbytes = fourbytes * 85 + H_CAST_UINT(digits[i]->seq->elements[0]); - fprintf(stdout, "act_a85partial2group: i = %d, digit = %2lx, fourbytes = %4x (%d)\n", i, H_CAST_UINT(digits[i]->seq->elements[0]), - fourbytes, fourbytes); // XXX DEBUG + //fprintf(stdout, "act_a85partial2group: i = %d, digit = %2lx, fourbytes = %4x (%d)\n", i, H_CAST_UINT(digits[i]->seq->elements[0]), + // fourbytes, fourbytes); // XXX DEBUG } // fill the other bytes with 0 @@ -656,7 +656,7 @@ act_a85partial2group(const HParseResult *p, void *u) // truncate and return only the high order byte bytes[0] = (fourbytes & 0xFF000000) >> 24; - fprintf(stdout, "act_a85partial2group: %4x (%d) ==> %2x \n", fourbytes, fourbytes, bytes[0]); // XXX DEBUG + //fprintf(stdout, "act_a85partial2group: %4x (%d) ==> %2x \n", fourbytes, fourbytes, bytes[0]); // XXX DEBUG return H_MAKE_BYTES(bytes, 1); } @@ -695,8 +695,8 @@ act_a85partial3group(const HParseResult *p, void *u) bytes[1] = (fourbytes & 0x00FF0000) >> 16; //bytes[2] = (fourbytes & 0x0000FF00) >> 8; - fprintf(stdout, "act_a85partial3group: %4x (%d) ==> %2x %2x\n", fourbytes, fourbytes, bytes[0], - bytes[1]); // XXX DEBUG + //fprintf(stdout, "act_a85partial3group: %4x (%d) ==> %2x %2x\n", fourbytes, fourbytes, bytes[0], + // bytes[1]); // XXX DEBUG return H_MAKE_BYTES(bytes, 2); } @@ -732,7 +732,7 @@ act_a85partial4group(const HParseResult *p, void *u) bytes[1] = (fourbytes & 0x00FF0000) >> 16; bytes[2] = (fourbytes & 0x0000FF00) >> 8; - fprintf(stdout, "act_a85partial4group: %4x (%d) ==> %2x %2x %2x\n", fourbytes, fourbytes, bytes[0], bytes[1], bytes[2]); // XXX debug + //fprintf(stdout, "act_a85partial4group: %4x (%d) ==> %2x %2x %2x\n", fourbytes, fourbytes, bytes[0], bytes[1], bytes[2]); // XXX debug return H_MAKE_BYTES(bytes, 3); } @@ -798,8 +798,8 @@ act_a85string(const HParseResult *p, void *u) assert(chunks->elements[i]->token_type == TT_BYTES && chunks->elements[i]->bytes.len == 4); memcpy(result_bytes + out_pos, chunks->elements[i]->bytes.token, 4); - fprintf(stdout, "%2x%2x%2x%2x - %8x\n", result_bytes[out_pos], result_bytes[out_pos+1], - result_bytes[out_pos+2], result_bytes[out_pos+3], *((unsigned int *)(chunks->elements[i]->bytes.token))); // XXX DEBUG + //fprintf(stdout, "%2x%2x%2x%2x - %8x\n", result_bytes[out_pos], result_bytes[out_pos+1], + // result_bytes[out_pos+2], result_bytes[out_pos+3], *((unsigned int *)(chunks->elements[i]->bytes.token))); // XXX DEBUG out_pos += 4; } @@ -1359,7 +1359,7 @@ act_Tc_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_Tc_op:: %3.3f\n", txte->value); + //fprintf(stdout, "act_Tc_op:: %3.3f\n", txte->value); return H_MAKE(TextEntry, txte); } @@ -1383,7 +1383,7 @@ act_Tw_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_Tw_op:: %3.3f\n", txte->value); + //fprintf(stdout, "act_Tw_op:: %3.3f\n", txte->value); return H_MAKE(TextEntry, txte); } @@ -1408,7 +1408,7 @@ act_Tz_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_Tz_op:: %3.3f\n", txte->value); + //fprintf(stdout, "act_Tz_op:: %3.3f\n", txte->value); return H_MAKE(TextEntry, txte); } @@ -1433,7 +1433,7 @@ act_TL_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_TL_op:: %3.3f\n", txte->value); + //fprintf(stdout, "act_TL_op:: %3.3f\n", txte->value); return H_MAKE(TextEntry, txte); } @@ -1464,9 +1464,9 @@ act_Tf_op(const HParseResult *p, void *u) txte->fref.fontsize = (double) H_FIELD_UINT(1); else if (tokenType == TT_DOUBLE) txte->fref.fontsize = (double) H_FIELD_DOUBLE(1); - else - fprintf(stderr, "act_Tf_op: Unexpected token type for fontsize - token_type=%u\n", - tokenType); + //else + // fprintf(stderr, "act_Tf_op: Unexpected token type for fontsize - token_type=%u\n", + // tokenType); // save this foont as the current state to be used by subsequent text @@ -1478,11 +1478,11 @@ act_Tf_op(const HParseResult *p, void *u) txte->ts.font = aux->tstate.font; // recursive :-) defn // DEBUG - fprintf(stdout, "act_Tf_op: fn=%.*s, fontsize=%3.3f, fontstate=%p, page=", - txte->fref.namelen, txte->fref.fontname, txte->fref.fontsize, (void*)txte); - if (aux->tstate.page->type==PG_NODE) - pp_ref(stdout, aux->tstate.page->me, 0, 0); - fprintf(stdout, "\n"); + //fprintf(stdout, "act_Tf_op: fn=%.*s, fontsize=%3.3f, fontstate=%p, page=", + // txte->fref.namelen, txte->fref.fontname, txte->fref.fontsize, (void*)txte); + //if (aux->tstate.page->type==PG_NODE) + // pp_ref(stdout, aux->tstate.page->me, 0, 0); + //fprintf(stdout, "\n"); return ((HParsedToken *)restok); } @@ -1519,7 +1519,7 @@ act_Tr_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_Tr_op:: %d\n", txte->mode); + //fprintf(stdout, "act_Tr_op:: %d\n", txte->mode); return H_MAKE(TextEntry, txte); } @@ -1543,7 +1543,7 @@ act_Ts_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_Ts_op:: %3.3f\n", txte->value); + //fprintf(stdout, "act_Ts_op:: %3.3f\n", txte->value); return H_MAKE(TextEntry, txte); } @@ -1576,8 +1576,8 @@ act_Td_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_Td_op: text position ::tx=%.3f:ty=%.3f\n", - txte->pos.tx, txte->pos.ty); + //fprintf(stdout, "act_Td_op: text position ::tx=%.3f:ty=%.3f\n", + // txte->pos.tx, txte->pos.ty); return H_MAKE(TextEntry, txte); } @@ -1605,8 +1605,8 @@ act_TD_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_TD_op: text position ::tx=%3.3f:ty=%3.3f\n", txte->pos.tx, txte->pos.ty); - pp_fontstate(stdout, &txte->ts); + //fprintf(stdout, "act_TD_op: text position ::tx=%3.3f:ty=%3.3f\n", txte->pos.tx, txte->pos.ty); + //pp_fontstate(stdout, &txte->ts); return H_MAKE(TextEntry, txte); } @@ -1632,9 +1632,9 @@ act_Tm_op(const HParseResult *p, void *u) txte->fm.cell[i] = p->ast->seq->elements[0]->seq->elements[i]->seq->elements[0]->dbl; - fprintf(stdout, "act_Tm_op: text matrix ::\n"); - for (int i=0; i<3; i++) - fprintf(stdout, "%3.3f : %3.3f\n", txte->fm.cell[i*2], txte->fm.cell[i*2+1]); + //fprintf(stdout, "act_Tm_op: text matrix ::\n"); + //for (int i=0; i<3; i++) + // fprintf(stdout, "%3.3f : %3.3f\n", txte->fm.cell[i*2], txte->fm.cell[i*2+1]); return H_MAKE(TextEntry, txte); } @@ -1658,8 +1658,8 @@ act_Tstar_op(const HParseResult *p, void *u) txte->ts.page = aux->tstate.page; txte->ts.font = aux->tstate.font; - fprintf(stdout, "act_Tstar_op: position pointer\n"); - pp_fontstate(stdout, &txte->ts); + //fprintf(stdout, "act_Tstar_op: position pointer\n"); + //pp_fontstate(stdout, &txte->ts); return H_MAKE(TextEntry, txte); } @@ -1695,9 +1695,9 @@ act_Tj_op(const HParseResult *p, void *u) txte->ts.font = aux->tstate.font; - fprintf(stdout, "\nact_Tj_op:: nchars=%u, txt=%.*s\n", txte->tstr.nchars, - txte->tstr.nchars, txte->tstr.text); - pp_fontstate(stdout, &txte->ts); + //fprintf(stdout, "\nact_Tj_op:: nchars=%u, txt=%.*s\n", txte->tstr.nchars, + // txte->tstr.nchars, txte->tstr.text); + //pp_fontstate(stdout, &txte->ts); return H_MAKE(TextEntry, txte); } @@ -1726,9 +1726,9 @@ act_TsingleQ_op(const HParseResult *p, void *u) txte->ts.font = aux->tstate.font; - fprintf(stdout, "\nact_TsingleQ_op:: nchars=%u, txt=%.*s\n", txte->tstr.nchars, - txte->tstr.nchars, txte->tstr.text); - pp_fontstate(stdout, &txte->ts); + //fprintf(stdout, "\nact_TsingleQ_op:: nchars=%u, txt=%.*s\n", txte->tstr.nchars, + // txte->tstr.nchars, txte->tstr.text); + //pp_fontstate(stdout, &txte->ts); return H_MAKE(TextEntry, txte); } @@ -1763,10 +1763,10 @@ act_TdoubleQ_op(const HParseResult *p, void *u) - fprintf(stdout, "act_TdoubleQ_op:: aw=%3.3f, ac=%3.3f\n", txte->twfmt.aw, txte->twfmt.ac); - fprintf(stdout, "\nact_TdoubleQ_op:: nchars=%u, txt=%.*s\n", txte->tstr.nchars, - txte->tstr.nchars, txte->tstr.text); - pp_fontstate(stdout, &txte->ts); + //fprintf(stdout, "act_TdoubleQ_op:: aw=%3.3f, ac=%3.3f\n", txte->twfmt.aw, txte->twfmt.ac); + //fprintf(stdout, "\nact_TdoubleQ_op:: nchars=%u, txt=%.*s\n", txte->tstr.nchars, + // txte->tstr.nchars, txte->tstr.text); + //pp_fontstate(stdout, &txte->ts); return H_MAKE(TextEntry, txte); } @@ -1820,10 +1820,10 @@ act_TJ_op(const HParseResult *p, void *u) // Debug // fprintf(stdout, "act_TJ_op:Cumulative=%d/0x%x bytes, Additional:%d bytes\n", // txte->tarray.flattened.nchars, txte->tarray.flattened.nchars, txte->tarray.elts[i].tstr.nchars); - fprintf(stdout, "act_TJ_op::: Using font= %p - page=", txte->ts.font); - pp_ref(stdout, txte->ts.page->me, 0, 0); - fprintf(stdout, "\nact_TJ_op:: nchars=%u, txt=%.*s\n", txte->tarray.elts[i].tstr.nchars, - txte->tarray.elts[i].tstr.nchars, txte->tarray.elts[i].tstr.text); + //fprintf(stdout, "act_TJ_op::: Using font= %p - page=", txte->ts.font); + //pp_ref(stdout, txte->ts.page->me, 0, 0); + //fprintf(stdout, "\nact_TJ_op:: nchars=%u, txt=%.*s\n", txte->tarray.elts[i].tstr.nchars, + // txte->tarray.elts[i].tstr.nchars, txte->tarray.elts[i].tstr.text); break; default: fprintf(stderr, "act_TJ_op:: Unexpected element type :: %d\n", elt->seq->elements[0]->token_type); @@ -1847,9 +1847,9 @@ act_TJ_op(const HParseResult *p, void *u) } } - fprintf(stdout, "\nact_TJ_op:: nchars=%u, txt=%.*s\n", txte->tarray.flattened.nchars, - txte->tarray.flattened.nchars, txte->tarray.flattened.text); - pp_fontstate(stdout, &txte->ts); + //fprintf(stdout, "\nact_TJ_op:: nchars=%u, txt=%.*s\n", txte->tarray.flattened.nchars, + // txte->tarray.flattened.nchars, txte->tarray.flattened.text); + //pp_fontstate(stdout, &txte->ts); return H_MAKE(TextEntry, txte); } @@ -1863,7 +1863,7 @@ HParsedToken * act_txtobj(const HParseResult *p, void *u) { - fprintf(stdout, "act_txtobj:: Here\n"); + //fprintf(stdout, "act_txtobj:: Here\n"); assert(p->ast->token_type == TT_SEQUENCE); @@ -1875,7 +1875,7 @@ act_txtobj(const HParseResult *p, void *u) int textlen=0; - fprintf(stdout, "act_txtobj:: numtokens = %lu\n", opstream->seq->used); + //fprintf(stdout, "act_txtobj:: numtokens = %lu\n", opstream->seq->used); // Walk through the tokens to determine how much space to allocate // Count the number of characters in the stream @@ -1926,9 +1926,9 @@ act_txtobj(const HParseResult *p, void *u) case TW_TJ: memcpy(&tstr[idx], txte->tarray.flattened.text, txte->tarray.flattened.nchars); idx += txte->tarray.flattened.nchars; - fprintf(stdout, "act_txtobj - array:: len=%u, str=", txte->tarray.flattened.nchars); - fwrite((const void *)txte->tarray.flattened.text, (int) txte->tarray.flattened.nchars, 1, stdout); - pp_fontstate(stdout, ts); + //fprintf(stdout, "act_txtobj - array:: len=%u, str=", txte->tarray.flattened.nchars); + //fwrite((const void *)txte->tarray.flattened.text, (int) txte->tarray.flattened.nchars, 1, stdout); + //pp_fontstate(stdout, ts); break; case TW_Tq: @@ -1939,9 +1939,9 @@ act_txtobj(const HParseResult *p, void *u) case TW_Tj: memcpy(&tstr[idx], txte->tstr.text, txte->tstr.nchars); idx += txte->tstr.nchars; - fprintf(stdout, "act_txtobj:: len=%u, str=", txte->tstr.nchars); - fwrite((const void *)txte->tstr.text, (int) txte->tstr.nchars, 1, stdout); - pp_fontstate(stdout, ts); + //fprintf(stdout, "act_txtobj:: len=%u, str=", txte->tstr.nchars); + //fwrite((const void *)txte->tstr.text, (int) txte->tstr.nchars, 1, stdout); + //pp_fontstate(stdout, ts); break; default: ; // ignore @@ -1967,12 +1967,14 @@ act_txtobj(const HParseResult *p, void *u) tt_text = H_MAKE(TextEntry, txtobj); // DEBUG + /* if (textlen) { fprintf(stdout, "act_txtobj:: "); pp_textentry(stdout, tt_text, 0, 0); if (&txtobj->ts.page) pp_fontstate(stdout, &txtobj->ts); } + */ return (HParsedToken *)tt_text; } @@ -1996,14 +1998,14 @@ ktxtstream(HAllocator *mm__, const HParsedToken *x, void *env) assert (x->token_type == TT_SEQUENCE); int n_tobjs = x->seq->used; - fprintf(stdout, "\n\nktxtstream: Num txtobjs = %d\n", n_tobjs); + //fprintf(stdout, "\n\nktxtstream: Num txtobjs = %d\n", n_tobjs); for (int n=0; n<n_tobjs; n++) { assert(x->seq->elements[n]->token_type == TT_TextEntry); TextEntry *tste = H_CAST(TextEntry, x->seq->elements[n]); assert(tste->type == TW_Tj); - fprintf(stdout, "ktxtstream: Value = %.*s\n", tste->tstr.nchars, tste->tstr.text); + //fprintf(stdout, "ktxtstream: Value = %.*s\n", tste->tstr.nchars, tste->tstr.text); // store the string in the environment @@ -2084,7 +2086,7 @@ text_extract(struct Env *aux) char *outfn = (char *) malloc(sizeof(char) * namelen+1); if (outfn == NULL) { - fprintf(stderr, "text_extract:: malloc() failed"); + //fprintf(stderr, "text_extract:: malloc() failed"); return errno; } memcpy(outfn, outdir, outdlen); @@ -2095,15 +2097,15 @@ text_extract(struct Env *aux) // open the file for writing FILE *stream; if (!(stream = fopen(outfn, "w"))) { - fprintf(stderr, - "text_extract:: Failed to open file '%s' for writing\n", outfn); + //fprintf(stderr, + // "text_extract:: Failed to open file '%s' for writing\n", outfn); return errno; } // DEBUG char *outfn2 = (char *) malloc(sizeof(char) * namelen+1); if (outfn2 == NULL) { - fprintf(stderr, "text_extract:: malloc() failed"); + //fprintf(stderr, "text_extract:: malloc() failed"); return errno; } sfxlen = strlen(".strtxt"); @@ -2116,8 +2118,8 @@ text_extract(struct Env *aux) // open the file for writing FILE *stream2; if (!(stream2 = fopen(outfn2, "w"))) { - fprintf(stderr, - "text_extract:: Failed to open file '%s' for writing\n", outfn); + //fprintf(stderr, + // "text_extract:: Failed to open file '%s' for writing\n", outfn); return errno; } // DEBUG @@ -2146,21 +2148,22 @@ text_extract(struct Env *aux) tstr = &txte->tarray.flattened; break; default: - fprintf(stderr, "text_extract:: Text token type '%u' ignored\n", - txte->type); + //fprintf(stderr, "text_extract:: Text token type '%u' ignored\n", + // txte->type); + break; } if (tstr) { ft = lookup_font(&txte->ts, aux); if (ft) { - pp_fontinfo(stdout, &txte->ts, ft); + //pp_fontinfo(stdout, &txte->ts, ft); pp_fontinfo(stream, &txte->ts, ft); } else { char *estr = "\nMissing Font Info!!\n"; - fwrite((const void *)estr, strlen(estr), 1, stdout); + //fwrite((const void *)estr, strlen(estr), 1, stdout); fwrite((const void *)estr, strlen(estr), 1, stream); } - fwrite((const void *)tstr->text, (int) tstr->nchars, 1, stdout); + //fwrite((const void *)tstr->text, (int) tstr->nchars, 1, stdout); fwrite((const void *)tstr->text, (int) tstr->nchars, 1, stream); } } @@ -2194,13 +2197,13 @@ char convert2char(unsigned int b1) } else if ( (b1 < 20) || ( b1 > 127 ) ) { - fprintf(stdout, " 0X%02X ", b1); + //fprintf(stdout, " 0X%02X ", b1); val = '?'; } else { val = b1; - fprintf(stdout, "%c", val); + //fprintf(stdout, "%c", val); } return val; } @@ -2211,7 +2214,7 @@ act_txtbegin_(const HParseResult *p, void *u) { const HParsedToken *tok=p->ast; - fprintf(stdout, "act_txtbegin:: Here %lx\n", (long unsigned int)tok); + //fprintf(stdout, "act_txtbegin:: Here %lx\n", (long unsigned int)tok); return (HParsedToken *)tok; } @@ -2219,7 +2222,7 @@ HParsedToken * act_txtend(const HParseResult *p, void *u) { - fprintf(stdout, "act_txtend:: Here\n"); + //fprintf(stdout, "act_txtend:: Here\n"); return (HParsedToken *)p->ast; } @@ -2230,7 +2233,7 @@ HParsedToken * act_bytestream(const HParseResult *p, void *u) { size_t n = p->ast->seq->used; - fprintf(stdout, "\nact_bytestream: token_type: %u, size: %lu\n", p->ast->token_type, n); + //fprintf(stdout, "\nact_bytestream: token_type: %u, size: %lu\n", p->ast->token_type, n); uint8_t *bytebuf = h_arena_malloc(p->arena, sizeof(uint8_t) * n); for (int i=0; i<n; i++) { @@ -2238,7 +2241,7 @@ act_bytestream(const HParseResult *p, void *u) bytebuf[i] = p->ast->seq->elements[i]->uint; } - fprintf(stdout, "act_bytestream: the string: %.*s\n", (int)n, (char *)bytebuf); + //fprintf(stdout, "act_bytestream: the string: %.*s\n", (int)n, (char *)bytebuf); #if 0 char *buf = malloc(sizeof(char) * n); @@ -2246,7 +2249,7 @@ act_bytestream(const HParseResult *p, void *u) for (int i=0; i<n; i++) { buf[i] = convert2char(p->ast->seq->elements[i]->uint); } - fprintf(stdout, "act_bytestream: the string: %.*s\n", (int)n, buf); + //fprintf(stdout, "act_bytestream: the string: %.*s\n", (int)n, buf); free (buf); } #endif @@ -2808,10 +2811,10 @@ parse_obj(struct Env *aux, size_t nr, size_t gen, size_t offset) // DEBUG - fprintf(stdout, "\nparse_obj: Parsed Result:\n"); - h_pprintln(stdout, res->ast); // XXX debug - fprintf(stdout, "\nparse_obj: Returning:\n"); - h_pprintln(stdout, H_INDEX_TOKEN(res->ast, 1)); // XXX debug + //fprintf(stdout, "\nparse_obj: Parsed Result:\n"); + //h_pprintln(stdout, res->ast); // XXX debug + //fprintf(stdout, "\nparse_obj: Returning:\n"); + //h_pprintln(stdout, H_INDEX_TOKEN(res->ast, 1)); // XXX debug // DEBUG return H_INDEX_TOKEN(res->ast, 1); @@ -2839,8 +2842,8 @@ parse_objstm_obj(struct Env *aux, size_t nr, size_t stm_nr, size_t idx) if (ent->n.gen != 0) return NULL; /* stream replaced */ if (ent->obj == NULL) { - fprintf(stdout, "\nparse_objstm_obj:: Parsing object stream id = %lu, %d, at offset = %zu (%#zx)\n", - stm_nr, 0, ent->n.offs, ent->n.offs); // XXX DEBUG + //fprintf(stdout, "\nparse_objstm_obj:: Parsing object stream id = %lu, %d, at offset = %zu (%#zx)\n", + // stm_nr, 0, ent->n.offs, ent->n.offs); // XXX DEBUG ent->obj = parse_obj(aux, stm_nr, 0, ent->n.offs); } break; @@ -2858,8 +2861,8 @@ parse_objstm_obj(struct Env *aux, size_t nr, size_t stm_nr, size_t idx) * decode the stream and find the target object in it */ // XXX debug - fprintf(stdout, "\nparse_objstm_obj:: token type = %u, \n", ent->obj->token_type); - h_pprintln(stdout, stm); // XXX debug + //fprintf(stdout, "\nparse_objstm_obj:: token type = %u, \n", ent->obj->token_type); + //h_pprintln(stdout, stm); // XXX debug // XXX debug // get the object at index @@ -2876,8 +2879,8 @@ parse_objstm_obj(struct Env *aux, size_t nr, size_t stm_nr, size_t idx) return NULL; } } - fprintf(stdout, "\npparse_objstm_obj:: Returning token of type = %u, \n", stm->token_type); - h_pprintln(stdout, stm); // XXX debug + //fprintf(stdout, "\npparse_objstm_obj:: Returning token of type = %u, \n", stm->token_type); + //h_pprintln(stdout, stm); // XXX debug return stm; } @@ -2895,12 +2898,12 @@ resolve(struct Env *aux, const HParsedToken *v) r = v->user; /* find the xref entry for this reference */ - fprintf(stdout, "\nresolve:: Looking up xref = %lu, %lu\n", r->nr, r->gen); // XXX DEBUG + //fprintf(stdout, "\nresolve:: Looking up xref = %lu, %lu\n", r->nr, r->gen); // XXX DEBUG ent = lookup_xref(aux, r->nr, r->gen); if (ent == NULL) return NULL; /* obj not found */ if (ent->obj != NULL) { - fprintf(stdout, "\nresolve:: ent->obj->token_type = %u\n", ent->obj->token_type); // XXX DEBUG + //fprintf(stdout, "\nresolve:: ent->obj->token_type = %u\n", ent->obj->token_type); // XXX DEBUG return resolve(aux, ent->obj); } @@ -2913,19 +2916,19 @@ resolve(struct Env *aux, const HParsedToken *v) case XR_INUSE: if (ent->n.gen != r->gen) return NULL; /* obj nr reused */ - fprintf(stdout, "resolve:: parse object at offset = %zu (%#zx)\n", ent->n.offs, ent->n.offs); + //fprintf(stdout, "resolve:: parse object at offset = %zu (%#zx)\n", ent->n.offs, ent->n.offs); ent->obj = parse_obj(aux, r->nr, r->gen, ent->n.offs); break; case XR_OBJSTM: if (r->gen != 0) return NULL; /* invalid entry! */ - fprintf(stdout, "resolve:: parse object stream - oid = %lu, stm_oid = %lu, stm_idx = %lu\n", - r->nr, ent->o.stm, ent->o.idx); // XXX DEBUG + //fprintf(stdout, "resolve:: parse object stream - oid = %lu, stm_oid = %lu, stm_idx = %lu\n", + // r->nr, ent->o.stm, ent->o.idx); // XXX DEBUG ent->obj = parse_objstm_obj(aux, r->nr, ent->o.stm, ent->o.idx); break; } - fprintf (stdout, "resolve: Recursive call to resolve - token_type = %u\n", ent->obj->token_type); // XXX DEBUG + //fprintf (stdout, "resolve: Recursive call to resolve - token_type = %u\n", ent->obj->token_type); // XXX DEBUG return resolve(aux, ent->obj); } @@ -3181,7 +3184,7 @@ FlateDecode(const Dict *parms, HBytes b, HParser *p) // decoded stream in pred.out // FILE *decodef = fopen ("flatecode.out", "w"); // fprintf (decodef, "FlateDecode:: Inflated string (%lu)\n:%.*s\n", pred.nout, (int)pred.nout, pred.out); - fprintf (stdout, "FlateDecode:: Inflated string (%lu)\n:%.*s\n", pred.nout, (int)pred.nout, pred.out); + //fprintf (stdout, "FlateDecode:: Inflated string (%lu)\n:%.*s\n", pred.nout, (int)pred.nout, pred.out); unsigned char *fdec = pred.out; // char _l; int i; @@ -3433,7 +3436,7 @@ ASCIIHexDecode(const Dict *parms, HBytes b, HParser *p) HParseResult *f_res, *res; // XXX debug - fprintf(stdout, "ASCIIHexDecode:: bytes=[%.*s]\n", (int)b.len, b.token); + //fprintf(stdout, "ASCIIHexDecode:: bytes=[%.*s]\n", (int)b.len, b.token); f_res = h_parse(p_ahexstream, b.token, b.len); if(!f_res) @@ -3443,8 +3446,8 @@ ASCIIHexDecode(const Dict *parms, HBytes b, HParser *p) } assert(f_res->ast && f_res->ast->token_type == TT_BYTES); - fprintf(stdout, "ASCIIHexDecode::string = [%.*s]\n", - (int)f_res->ast->bytes.len, (char*)f_res->ast->bytes.token); + //fprintf(stdout, "ASCIIHexDecode::string = [%.*s]\n", + // (int)f_res->ast->bytes.len, (char*)f_res->ast->bytes.token); // SR::TODO:: Do a H_MAKE rather than a parse and let the caller do the parse res = h_parse(p, f_res->ast->bytes.token, f_res->ast->bytes.len); @@ -3464,7 +3467,7 @@ ASCII85Decode(const Dict *parms, HBytes b, HParser *p) HParseResult *f_res, *res; // XXX debug - fprintf(stdout, "ASCII85Decode:: bytes=[%.*s]\n", (int)b.len, b.token); + //fprintf(stdout, "ASCII85Decode:: bytes=[%.*s]\n", (int)b.len, b.token); f_res = h_parse(p_a85string, b.token, b.len); if(!f_res) @@ -3511,8 +3514,8 @@ act_take_bytes(const HParseResult *p, void *env) * below. */ // DEBUG - fprintf (stdout, "act_take_bytes: Current position (bytes)= %p, len=%ld\n", - (void *)bs->token + offset, bs->len); + //fprintf (stdout, "act_take_bytes: Current position (bytes)= %p, len=%ld\n", + // (void *)bs->token + offset, bs->len); return H_MAKE_BYTES(bs->token + offset, bs->len); } @@ -3607,9 +3610,11 @@ decode_contentstream(const Dict *d, HBytes b, HParser *p) res = filter(parms, b, p); /* Debug */ + /* if (res){ fprintf(stdout, "decode_contentstream: parsed token type is = %u\n", res->ast->token_type); } + */ } /* The dictionary provided direction for processing the stream */ /* @@ -3618,9 +3623,11 @@ decode_contentstream(const Dict *d, HBytes b, HParser *p) */ else { // content stream is not encoded res = h_parse(p, b.token, b.len); + /* if (res == NULL) { // Probably does not need to be flagged fprintf(stderr, "decode_contentstream::Text String parse failed!!\n"); } + */ } /* @@ -3674,8 +3681,8 @@ parse_item(struct Env *aux, size_t nr, size_t gen, size_t offset, HParser *p) fprintf(stderr, "parse_item: Attempt to use a NULL parser!\n"); return NULL; } - fprintf(stdout, "\nparse_item:: Parsing reference = %lu, %lu, at offset = %zu (%#zx)\n", - nr, gen, offset, offset); + //fprintf(stdout, "\nparse_item:: Parsing reference = %lu, %lu, at offset = %zu (%#zx)\n", + // nr, gen, offset, offset); HParser *pItem = h_right(h_seek(offset * 8, SEEK_SET), p); res = h_parse(pItem, aux->input, aux->sz); if (res == NULL) { @@ -3728,8 +3735,8 @@ parse_objstm_item(struct Env *aux, size_t nr, size_t stm_nr, size_t idx, size_t /* * decode the stream and find the target object in it */ - fprintf(stdout, "\nparse_objstm_item:: Parsing object stream id = %lu, %d, at offset = %zu (%#zx)\n", - stm_nr, 0, ent->n.offs, ent->n.offs); + //fprintf(stdout, "\nparse_objstm_item:: Parsing object stream id = %lu, %d, at offset = %zu (%#zx)\n", + // stm_nr, 0, ent->n.offs, ent->n.offs); ent->obj = parse_item(aux, stm_nr, 0, ent->n.offs, p); *offset = ent->n.offs; } @@ -3748,9 +3755,11 @@ parse_objstm_item(struct Env *aux, size_t nr, size_t stm_nr, size_t idx, size_t * decode the stream and find the target object in it */ // XXX debug + /* fprintf(stdout, "\nparse_objstm_item:: Type of object looked up = %u at offset = %zu (%#zx)\n", stm->token_type, ent->n.offs, ent->n.offs); h_pprintln(stdout, ent->obj); + */ // XXX debug // get the object at index @@ -3772,8 +3781,8 @@ parse_objstm_item(struct Env *aux, size_t nr, size_t stm_nr, size_t idx, size_t } } - fprintf(stdout, "\nparse_objstm_item:: Returning token of type = %u, \n", stm->token_type); - h_pprintln(stdout, stm); // XXX debug + //fprintf(stdout, "\nparse_objstm_item:: Returning token of type = %u, \n", stm->token_type); + //h_pprintln(stdout, stm); // XXX debug return stm; } @@ -3794,12 +3803,12 @@ resolve_item(struct Env *aux, const HParsedToken *v, size_t *offset, HParser *p) r = v->user; /* find the xref entry for this reference */ - fprintf(stdout, "\nresolve_item:: Looking up xref = %lu, %lu\n", r->nr, r->gen); + //fprintf(stdout, "\nresolve_item:: Looking up xref = %lu, %lu\n", r->nr, r->gen); ent = lookup_xref(aux, r->nr, r->gen); if (ent == NULL) return NULL; /* obj not found -- xref error */ if (ent->obj != NULL) { - fprintf(stdout, "\nresolve_item:: ent->obj->token_type = %u\n", ent->obj->token_type); + //fprintf(stdout, "\nresolve_item:: ent->obj->token_type = %u\n", ent->obj->token_type); return resolve_item(aux, ent->obj, offset, p); } @@ -3812,23 +3821,25 @@ resolve_item(struct Env *aux, const HParsedToken *v, size_t *offset, HParser *p) case XR_INUSE: if (ent->n.gen != r->gen) return NULL; /* obj nr reused */ - fprintf(stdout, "resolve_item:: parse object at offset = %lu\n", ent->n.offs); + //fprintf(stdout, "resolve_item:: parse object at offset = %lu\n", ent->n.offs); ent->obj = parse_item(aux, r->nr, r->gen, ent->n.offs, p); *offset = ent->n.offs; break; case XR_OBJSTM: if (r->gen != 0) return NULL; /* invalid entry! */ - fprintf(stdout, "resolve_item:: parse object stream - oid = %lu, stm_oid = %lu, stm_idx = %lu\n", - r->nr, ent->o.stm, ent->o.idx); + //fprintf(stdout, "resolve_item:: parse object stream - oid = %lu, stm_oid = %lu, stm_idx = %lu\n", + // r->nr, ent->o.stm, ent->o.idx); ent->obj = parse_objstm_item(aux, r->nr, ent->o.stm, ent->o.idx, offset, p); break; } // DEBUG + /* if (ent->obj) fprintf (stdout, "resolve_item: Recursive call to resolve - token_type = %u at offset = %zu (%#zx)\n", ent->obj->token_type, *offset, *offset); + */ return resolve_item(aux, ent->obj, offset, p); } @@ -3848,8 +3859,9 @@ is_parent(Dict *dict, const HParsedToken *expected) else if (item->token_type == TT_Ref) { ref = H_CAST(Ref, item); if (expected == NULL) { - fprintf(stderr, "is_parent: Inconsistent parent field=<%zu, %zu>, expected = NULL!\n", - ref->nr, ref->gen); + //fprintf(stderr, "is_parent: Inconsistent parent field=<%zu, %zu>, expected = NULL!\n", + // ref->nr, ref->gen); + return res; } else { assert(expected->token_type == TT_Ref); @@ -3857,9 +3869,11 @@ is_parent(Dict *dict, const HParsedToken *expected) res = (ref->nr == pRef->nr) && (ref->gen == pRef->gen); } } + /* else { fprintf(stderr, "is_parent: Unexpected token type = %u!\n", item->token_type); } + */ return res; } @@ -3877,6 +3891,7 @@ has_value(Dict *dict, char *fn, char *value) } + /* // DEBUG if (item == NULL) { fprintf(stderr, "has_value: No such field (%s) in dictionary!\n", fn); @@ -3885,6 +3900,7 @@ has_value(Dict *dict, char *fn, char *value) fprintf(stderr, "has_value: Field:%s has token type %u for value!\n", fn, item->token_type); } + */ // DEBUG @@ -3904,7 +3920,7 @@ get_fontdict(const HParsedToken *obj, struct Env* aux) assert(obj->token_type == TT_Ref); ref = H_CAST(Ref, obj); - fprintf(stdout, "\n\nget_fontdict: Ref = [%lu, %lu]\n\n", ref->nr, ref->gen); + //fprintf(stdout, "\n\nget_fontdict: Ref = [%lu, %lu]\n\n", ref->nr, ref->gen); item = resolve(aux, obj); if ( (item) && (item->token_type == TT_Dict) ) { dict = H_CAST(Dict, item); @@ -3917,8 +3933,8 @@ get_fontdict(const HParsedToken *obj, struct Env* aux) if ( (stm->tok[i].oid.nr == ref->nr) && (stm->tok[i].oid.gen == ref->gen) ) { if (stm->tok[i].obj->token_type != TT_Dict) { - fprintf(stdout, "\nget_fontdict:Expected Dictionary, Got a token of type=%u\n", - stm->tok[i].obj->token_type); + //fprintf(stdout, "\nget_fontdict:Expected Dictionary, Got a token of type=%u\n", + // stm->tok[i].obj->token_type); dict = NULL; } else { @@ -3956,7 +3972,7 @@ get_dictoftype( else if (obj->token_type == TT_Objstm) { stm = H_CAST(Objstm, obj); for (int i=0; i<stm->numObjs; i++) { - h_pprintln(stdout, stm->tok[i].obj); + //h_pprintln(stdout, stm->tok[i].obj); size_t ioff = 0; const HParsedToken *sitem = resolve_item(aux, stm->tok[i].obj, &ioff, p_objdef); if ((sitem) && (sitem->token_type == TT_Dict)) { @@ -3970,17 +3986,20 @@ get_dictoftype( } } } + /* else { fprintf(stdout, "get_dictoftype: token type not yet handled: %u\n", obj->token_type); fprintf(stdout, "get_dictoftype: Possibly needed for CMAPS\n"); h_pprintln(stdout, obj); } + */ if (dict == NULL) tok = NULL; // DEBUG + /* if (pRefT) { fprintf(stdout, "\nget_dictoftype: Parent = "); pp_ref(stdout, pRefT, 0, 0); @@ -3994,6 +4013,7 @@ get_dictoftype( else { fprintf(stdout, "\nget_dictoftype: Null dictionary of Type = %s\n", value); } + */ return tok; } @@ -4015,8 +4035,8 @@ kbyteostream(HAllocator *mm__, const HParsedToken *x, void *env) struct streamspec *spec; size_t sz=0, nOffset=0; - fprintf(stdout, "kbyteostream: dictionary\n"); - pp_dict(stdout, dict_t, 5, 0); + //fprintf(stdout, "kbyteostream: dictionary\n"); + //pp_dict(stdout, dict_t, 5, 0); /* look for the Length entry -- could be a reference */ v = dictentry(dict, "Length"); @@ -4072,8 +4092,8 @@ kcontentstream(HAllocator *mm__, const HParsedToken *x, void *env) struct streamspec *spec; size_t sz=0, nOffset=0; - fprintf(stdout, "kcontentstream: dictionary\n"); - pp_dict(stdout, dict_t, 5, 0); + //fprintf(stdout, "kcontentstream: dictionary\n"); + //pp_dict(stdout, dict_t, 5, 0); /* look for the Length entry -- could be a reference */ v = dictentry(dict, "Length"); @@ -4153,7 +4173,7 @@ getFontinfo(const Dict *fontdict, char *name, struct Env *aux) fontinfo->name = h_arena_malloc(fontdict->arena, sizeof(char)*(item->bytes.len+1)); memcpy(fontinfo->name, (char *)item->bytes.token, item->bytes.len); fontinfo->name[item->bytes.len] = '\0'; - fprintf(stdout, "getFontinfo: Subtype = %s\n", fontinfo->type); + //fprintf(stdout, "getFontinfo: Subtype = %s\n", fontinfo->type); } } item = dictentry(fontdict, "Subtype"); @@ -4162,7 +4182,7 @@ getFontinfo(const Dict *fontdict, char *name, struct Env *aux) fontinfo->type = h_arena_malloc(fontdict->arena, sizeof(char)*(item->bytes.len+1)); memcpy(fontinfo->type, (char *)item->bytes.token, item->bytes.len); fontinfo->type[item->bytes.len] = '\0'; - fprintf(stdout, "getFontinfo: Subtype = %s\n", fontinfo->type); + //fprintf(stdout, "getFontinfo: Subtype = %s\n", fontinfo->type); } item = dictentry(fontdict, "BaseFont"); if (item) { @@ -4170,7 +4190,7 @@ getFontinfo(const Dict *fontdict, char *name, struct Env *aux) fontinfo->basefont = h_arena_malloc(fontdict->arena, sizeof(char)*(item->bytes.len+1)); memcpy(fontinfo->basefont, (char *)item->bytes.token, item->bytes.len); fontinfo->basefont[item->bytes.len] = '\0'; - fprintf(stdout, "getFontinfo: Basefont = %s\n", fontinfo->basefont); + //fprintf(stdout, "getFontinfo: Basefont = %s\n", fontinfo->basefont); } size_t offset; // This is available if needed item = dictentry(fontdict, "Encoding"); @@ -4183,12 +4203,12 @@ getFontinfo(const Dict *fontdict, char *name, struct Env *aux) fontinfo->encoding = h_arena_malloc(fontdict->arena, sizeof(char)*(item->bytes.len+1)); memcpy(fontinfo->encoding, (char *)item->bytes.token, item->bytes.len); fontinfo->encoding[item->bytes.len] = '\0'; - fprintf(stdout, "getFontinfo: encoding = %s at offset %zu (%#zx)\n", - fontinfo->encoding, offset, offset); + //fprintf(stdout, "getFontinfo: encoding = %s at offset %zu (%#zx)\n", + // fontinfo->encoding, offset, offset); } else if (item->token_type == TT_Dict) { - pp_dict(stdout, item, 0, 0); + //pp_dict(stdout, item, 0, 0); const Dict *encodingDict = H_CAST(Dict, item); item = dictentry(encodingDict, "BaseEncoding"); @@ -4196,12 +4216,12 @@ getFontinfo(const Dict *fontdict, char *name, struct Env *aux) fontinfo->encoding = h_arena_malloc(fontdict->arena, sizeof(char)*(item->bytes.len+1)); memcpy(fontinfo->encoding, (char *)item->bytes.token, item->bytes.len); fontinfo->encoding[item->bytes.len] = '\0'; - fprintf(stdout, "getFontinfo: encoding = %s\n", fontinfo->encoding); + //fprintf(stdout, "getFontinfo: encoding = %s\n", fontinfo->encoding); } } else { - fprintf(stdout, "\nUnexpected token type in parsing font -Encoding- attribute -" - "token_type = %u\n", item->token_type); + //fprintf(stdout, "\nUnexpected token type in parsing font -Encoding- attribute -" + // "token_type = %u\n", item->token_type); } } } @@ -4212,14 +4232,14 @@ getFontinfo(const Dict *fontdict, char *name, struct Env *aux) offset = 0; item = resolve_item(aux, item, &offset, p_objdef); if (item) { // TODO: Failure ==> xref error -- Figure out how to handle - fprintf(stdout, "getFontinfo: FontDescriptor item description:\n"); - h_pprintln(stdout, item); + //fprintf(stdout, "getFontinfo: FontDescriptor item description:\n"); + //h_pprintln(stdout, item); item = get_dictoftype(item, NULL, "FontDescriptor", aux); if (item) { fontinfo->descriptor = item; - fprintf(stdout, "getFontinfo: FontDescriptor at offset %zu (%#zx):\n", - offset, offset); - pp_dict(stdout, item, 0, 0); + //fprintf(stdout, "getFontinfo: FontDescriptor at offset %zu (%#zx):\n", + // offset, offset); + //pp_dict(stdout, item, 0, 0); } } } @@ -4230,14 +4250,14 @@ getFontinfo(const Dict *fontdict, char *name, struct Env *aux) offset = 0; item = resolve_item(aux, item, &offset, p_objdef); if (item) { // TODO: Failure ==> xref error -- Figure out how to handle - fprintf(stdout, "getFontinfo: toUnicode item description:\n"); - h_pprintln(stdout, item); + //fprintf(stdout, "getFontinfo: toUnicode item description:\n"); + //h_pprintln(stdout, item); item = get_dictoftype(item, NULL, "ToUnicode", aux); if (item) { fontinfo->toUnicode = item; - fprintf(stdout, "getFontinfo: toUnicode at offset %zu (%#zx):\n", - offset, offset); - pp_dict(stdout, item, 0, 0); + //fprintf(stdout, "getFontinfo: toUnicode at offset %zu (%#zx):\n", + // offset, offset); + //pp_dict(stdout, item, 0, 0); } } } @@ -4248,14 +4268,14 @@ getFontinfo(const Dict *fontdict, char *name, struct Env *aux) offset = 0; item = resolve_item(aux, item, &offset, p_objdef); if (item) { // TODO: Failure ==> xref error -- Figure out how to handle - fprintf(stdout, "getFontinfo: descendantFonts item description:\n"); - h_pprintln(stdout, item); + //fprintf(stdout, "getFontinfo: descendantFonts item description:\n"); + //h_pprintln(stdout, item); item = get_dictoftype(item, NULL, "DescendantFonts", aux); if (item) { fontinfo->descendantFonts = item; - fprintf(stdout, "getFontinfo: descendantFonts at offset %zu (%#zx):\n", - offset, offset); - pp_dict(stdout, item, 0, 0); + //fprintf(stdout, "getFontinfo: descendantFonts at offset %zu (%#zx):\n", + // offset, offset); + //pp_dict(stdout, item, 0, 0); } } else { // xref error @@ -4291,18 +4311,20 @@ lookup_font(TextState_T *state, struct Env *aux) dict = get_fontdict(item, aux); if (dict) { fontinfo = getFontinfo(dict, fr->fn, aux); - fprintf(stdout, "\n\nlookup_font: fontinfo = %p\n\n", (void*)fontinfo); + //fprintf(stdout, "\n\nlookup_font: fontinfo = %p\n\n", (void*)fontinfo); } } } } + /* else { // inherit // DEBUG fprintf(stdout, "\n\nlookup_font: Font Resource not found for FontState:\n"); pp_fontstate(stdout, state); fprintf(stdout, "\n\nlookup_font: Inheritance not yet supported!\n\n"); } + */ } return (fontinfo); } @@ -4318,15 +4340,16 @@ void parse_fonts(const HParsedToken *dict_t, RsrcDict_T *pgRsrc, struct Env *aux if (item) { // TODO: Failure ==> xref error -- Figure out how to handle assert(item->token_type == TT_Dict); Dict *fontlist = H_CAST(Dict, item); - fprintf(stdout, "parse_fonts: Num fonts used in page = %lu \n", fontlist->used); - pp_dict(stdout, item, 0, 0); + //fprintf(stdout, "parse_fonts: Num fonts used in page = %lu \n", fontlist->used); + //pp_dict(stdout, item, 0, 0); if (pgRsrc->fonts) { - fprintf(stderr, "\n\nparse_fonts: Attempt to add fonts -- Supported??\n\n"); + //fprintf(stderr, "\n\nparse_fonts: Attempt to add fonts -- Supported??\n\n"); + return; } else { pgRsrc->fonts = item; pgRsrc->numFonts = fontlist->used; - fprintf(stdout, "\n\nparse_fonts: Number of fonts used = %lu\n\n", pgRsrc->numFonts); + //fprintf(stdout, "\n\nparse_fonts: Number of fonts used = %lu\n\n", pgRsrc->numFonts); } } } @@ -4378,11 +4401,13 @@ void parse_xobject( Dict *xolist = H_CAST(Dict, item); // DEBUG + /* fprintf(stdout, "\nparse_xobject: Node for Parent = "); if (parent->me) pp_ref(stdout, parent->me, 0, 0); fprintf(stdout, "\nOld XO Count = %lu, Num xobjects used in page = %lu \n", aux->catalog.xoCount, xolist->used); pp_dict(stdout, item, 0, 0); + */ // DEBUG aux->catalog.xoCount += xolist->used; @@ -4407,10 +4432,12 @@ void parse_xobject( if (tok == NULL) continue; // DEBUG + /* fprintf(stdout, "\nparse_xobject: XObject Reference = : "); pp_ref(stdout, ref, 0, 0); fprintf(stdout, "\n"); h_pprintln(stdout, tok); + */ // DEBUG // tok can be an image dictionary -- which we are ignoring @@ -4431,18 +4458,18 @@ void parse_xobject( * We are only handling forms at the moment */ if (bytes_eq(item->bytes, "Form")) { - fprintf(stdout, "\n\nparse_xobject:: Parsing Form XObject\n"); + //fprintf(stdout, "\n\nparse_xobject:: Parsing Form XObject\n"); const HParsedToken *xoRsrc_t; const HParsedToken *rsrcdict_t; size_t offset = 0; xoRsrc_t = dictentry(xobj_d, "Resources"); if (xoRsrc_t) { - fprintf(stdout, "\n\nparse_xobject: Found resources in node\n"); + //fprintf(stdout, "\n\nparse_xobject: Found resources in node\n"); rsrcdict_t = resolve_item(aux, xoRsrc_t, &offset, p_objdef); // DEBUG - fprintf(stdout, "\nparse_xobject: Resource token type = %u\n",rsrcdict_t->token_type); - h_pprintln(stdout, rsrcdict_t); + //fprintf(stdout, "\nparse_xobject: Resource token type = %u\n",rsrcdict_t->token_type); + //h_pprintln(stdout, rsrcdict_t); parse_rsrcdict(xodict->arena, rsrcdict_t, xobj_r->node, aux); @@ -4452,16 +4479,16 @@ void parse_xobject( xobj_t = H_INDEX_TOKEN(tok, 1); // expecting an HParseResult token const HParseResult *res = H_CAST(HParseResult, xobj_t); // DEBUG - fprintf(stdout, "\nparse_xobject: Byte Stream = : "); - h_pprintln(stdout, res->ast); + //fprintf(stdout, "\nparse_xobject: Byte Stream = : "); + //h_pprintln(stdout, res->ast); HBytes stm = H_CAST_BYTES(res->ast); res = h_parse(p_textstream, stm.token, stm.len); if (res) { // text found in stream // DEBUG - fprintf(stdout, "\nparse_xobject: Parsing text : "); - h_pprintln(stdout, res->ast); + //fprintf(stdout, "\nparse_xobject: Parsing text : "); + //h_pprintln(stdout, res->ast); // xobj_r->node->xn.dict = 0; xobj_r->node->xn.textStream = res->ast; @@ -4486,28 +4513,30 @@ void parse_rsrcdict(HArena *arena, const HParsedToken *dict_t, PtNode_T *pgNode, // rsrc->seenCmaps = NULL; // rsrc->numCmapsSeen = 0; } + /* else { fprintf (stderr, "\nparse_rsrcdict: What token type is this? - %u\n", dict_t->token_type); } + */ // Resource is a simple dictionary if (dict_t->token_type == TT_Dict) { // DEBUG - fprintf(stdout, "\nparse_rsrcdict: Simple dictionary:\n"); - h_pprintln(stdout, dict_t); + //fprintf(stdout, "\nparse_rsrcdict: Simple dictionary:\n"); + //h_pprintln(stdout, dict_t); parse_fonts(dict_t, rsrc, aux); parse_xobject(dict_t, pgNode, rsrc, aux); } else if (dict_t->token_type == TT_Objstm) { const Objstm *strmc = H_CAST(Objstm, dict_t); - fprintf(stdout, "\nparse_rsrcdict: stream object -numObjs = %lu\n", strmc->numObjs); - h_pprintln(stdout, dict_t); + //fprintf(stdout, "\nparse_rsrcdict: stream object -numObjs = %lu\n", strmc->numObjs); + //h_pprintln(stdout, dict_t); for (int i=0; i<strmc->numObjs; i++) { - fprintf(stdout, "\nparse_rsrcdict: oid = [%zu, %zu]\n", - strmc->tok[i].oid.nr, strmc->tok[i].oid.gen); + //fprintf(stdout, "\nparse_rsrcdict: oid = [%zu, %zu]\n", + // strmc->tok[i].oid.nr, strmc->tok[i].oid.gen); if (strmc->tok[i].obj->token_type == TT_Dict) { parse_fonts(strmc->tok[i].obj, rsrc, aux); parse_xobject(strmc->tok[i].obj, pgNode, rsrc, aux); @@ -4555,15 +4584,15 @@ void parse_pagenode ( const HParsedToken *item = NULL; const HParsedToken *contents_t = NULL; // dictionary token - Ref *contents_r = NULL; + //Ref *contents_r = NULL; const HParsedToken *contents = NULL; // resolved token const HParsedToken *entry = NULL; const HParsedToken *rsrcdict_t = NULL; size_t nOffset = 0; // DEBUG - fprintf(stdout, "\nparse_pagenode: parsing Page Node = "); - pp_ref(stdout, myRef, 0, 0); + //fprintf(stdout, "\nparse_pagenode: parsing Page Node = "); + //pp_ref(stdout, myRef, 0, 0); // set some global state variables @@ -4578,8 +4607,8 @@ void parse_pagenode ( assert(item->token_type == TT_Ref); if ( !( ( ((Ref*)item->user)->nr == ((Ref*)parent->user)->nr ) && ( ((Ref*)item->user)->gen == ((Ref*)parent->user)->gen ) ) ) { - fprintf(stderr, "parse_pagenode: Inconsistent parent pointer [p = %p]!\n", - (void *)item); + //fprintf(stderr, "parse_pagenode: Inconsistent parent pointer [p = %p]!\n", + // (void *)item); // should this just be a warning? goto end; } @@ -4591,23 +4620,23 @@ void parse_pagenode ( myNode->pgRsrc = NULL; item = dictentry(myDict, "Resources"); if (item) { - fprintf(stdout, "\n\nparse_pagenode: Found resources in node\n"); + //fprintf(stdout, "\n\nparse_pagenode: Found resources in node\n"); rsrcdict_t = resolve(aux, item); - fprintf(stdout, "\nparse_pagenode: Resource token type = %u\n",rsrcdict_t->token_type); + //fprintf(stdout, "\nparse_pagenode: Resource token type = %u\n",rsrcdict_t->token_type); parse_rsrcdict(arena, rsrcdict_t, myNode, aux); - pp_ptnode(stdout, myNode); + //pp_ptnode(stdout, myNode); } // Process the contents stream or array contents_t = dictentry(myDict, "Contents"); if (contents_t == NULL) { - fprintf(stderr, "parse_pagenode: Page node without contents!\n"); + //fprintf(stderr, "parse_pagenode: Page node without contents!\n"); goto end; } else if (contents_t->token_type == TT_Ref) { - contents_r = H_CAST(Ref, contents_t); - fprintf(stdout, "parse_pagenode: ref.nr = %ld, ref.gen=%ld\n", contents_r->nr, contents_r->gen); + //contents_r = H_CAST(Ref, contents_t); + //fprintf(stdout, "parse_pagenode: ref.nr = %ld, ref.gen=%ld\n", contents_r->nr, contents_r->gen); contents = resolve_item(aux, contents_t, &myNode->offset, p_cstream); if (!contents) { // TODO: Failure ==> xref error -- Figure out how to handle @@ -4615,11 +4644,11 @@ void parse_pagenode ( } if (contents->token_type == TT_Objstm) { // Resources for the page node parse_rsrcdict(arena, contents, myNode, aux); - pp_ptnode(stdout, myNode); + //pp_ptnode(stdout, myNode); } else { // DEBUG - fprintf(stdout, "\n\nparse_pagenode: What is token 0 anyway?\n"); + //fprintf(stdout, "\n\nparse_pagenode: What is token 0 anyway?\n"); HParsedToken *tok0 = H_INDEX_TOKEN(contents, 0); h_pprintln(stdout, tok0); @@ -4627,7 +4656,7 @@ void parse_pagenode ( if (res_strm->token_type == TT_SEQUENCE) { // this seems like a big assumption myNode->pn.textStream = res_strm; - fprintf(stdout, "parse_pagenode: Page node contents = %p\n", (void *)contents); + //fprintf(stdout, "parse_pagenode: Page node contents = %p\n", (void *)contents); } else myNode->pn.textStream = NULL; @@ -4640,24 +4669,24 @@ void parse_pagenode ( const HParsedToken **pieces = h_arena_malloc(arena, sizeof(HBytes*) * numelts); for (int i=0; i<numelts; i++) { entry = H_INDEX_TOKEN(contents_t, i); - contents_r = H_CAST(Ref, entry); - fprintf(stdout, "\n\nparse_pagenode: objstream contents: strm obj#:%d, oid=<%zu, %zu>\n", - i+1, contents_r->nr, contents_r->gen); + //contents_r = H_CAST(Ref, entry); + //fprintf(stdout, "\n\nparse_pagenode: objstream contents: strm obj#:%d, oid=<%zu, %zu>\n", + // i+1, contents_r->nr, contents_r->gen); contents = resolve_item(aux, entry, &nOffset, p_byteostm); if (!contents) { // TODO: Failure ==> xref error -- Figure out how to handle goto end; } HParsedToken *res_strm = H_INDEX_TOKEN(contents, 1); - fprintf(stdout, "\nparse_pagenode: Field 2 type = %u\n", res_strm->token_type); + //fprintf(stdout, "\nparse_pagenode: Field 2 type = %u\n", res_strm->token_type); HParseResult *bstrm_r = H_CAST(HParseResult, res_strm); if ( (bstrm_r) && (bstrm_r->ast) ) { pieces[i] = bstrm_r->ast; bstrm = H_CAST_BYTES(bstrm_r->ast); bufsz += bstrm.len; - fprintf(stdout, "\n\nparse_pagenode: the extracted byte stream:\n%.*s, lensofar = %lu\n", - (int)bstrm.len, (char*)bstrm.token, bufsz); + //fprintf(stdout, "\n\nparse_pagenode: the extracted byte stream:\n%.*s, lensofar = %lu\n", + // (int)bstrm.len, (char*)bstrm.token, bufsz); - fprintf(stdout, "\n\nparse_pagenode: Done parsing strm obj# = %d\n\n", i+1); + //fprintf(stdout, "\n\nparse_pagenode: Done parsing strm obj# = %d\n\n", i+1); } else { const HParsedToken *nullbyte = h_make_bytes(arena, NULL, 0); @@ -4673,20 +4702,20 @@ void parse_pagenode ( if (bstrm.len) { memcpy(&whole[offset], bstrm.token, bstrm.len); offset+=bstrm.len; - fprintf(stdout, "\n**** index=%d, offset=%lu\n", i, offset); + //fprintf(stdout, "\n**** index=%d, offset=%lu\n", i, offset); } } assert(offset == bufsz); - fprintf(stdout, "\n\nparse_pagenode: the extracted byte stream array:\n%.*s, bufsz = %lu\n", - (int)bufsz, (char*)whole, bufsz); + //fprintf(stdout, "\n\nparse_pagenode: the extracted byte stream array:\n%.*s, bufsz = %lu\n", + // (int)bufsz, (char*)whole, bufsz); HParseResult *tstrm=h_parse(p_textstream, whole, bufsz); if (tstrm) { - fprintf(stdout, "\n\nparse_pagenode: textstream token_type = %u\n\n", tstrm->ast->token_type); + //fprintf(stdout, "\n\nparse_pagenode: textstream token_type = %u\n\n", tstrm->ast->token_type); myNode->pn.textStream = tstrm->ast; } } else { - fprintf(stdout, "parse_pagenode: Unexpected page node contents token type = %u\n", contents_t->token_type); + //fprintf(stdout, "parse_pagenode: Unexpected page node contents token type = %u\n", contents_t->token_type); goto end; } @@ -4736,8 +4765,8 @@ parse_pagetree( const HParsedToken *rsrcdict_t = NULL; - fprintf(stdout, "\nparse_pagetree: parsing Page Tree Node = "); - pp_ref(stdout, myRef, 0, 0); + //fprintf(stdout, "\nparse_pagetree: parsing Page Tree Node = "); + //pp_ref(stdout, myRef, 0, 0); myNode->type = PG_TREE; @@ -4748,7 +4777,7 @@ parse_pagetree( // Count is a required field except for the root item = dictentry(myDict, "Count"); if ( (item == NULL) || (item->token_type != TT_SINT) ) { - fprintf(stderr, "parse_pagetree: Required page node count missing!\n"); + //fprintf(stderr, "parse_pagetree: Required page node count missing!\n"); goto end; // This should just be a warning } else { @@ -4764,7 +4793,7 @@ parse_pagetree( // Kids is a required field kids = dictentry(myDict, "Kids"); // array of references to page or page tree nodes if ( (kids == NULL) || (kids->token_type != TT_SEQUENCE) ) { - fprintf(stderr, "parse_pagetree: This tree node has no pages!\n"); + //fprintf(stderr, "parse_pagetree: This tree node has no pages!\n"); goto end; // Nothing more to do here } @@ -4797,7 +4826,7 @@ parse_pagetree( if (pageDict_t) { kidDict = H_CAST(Dict, pageDict_t); if (++curr > aux->catalog.pgCount) { - fprintf(stderr, "parse_pagetree: More kids then specified leaves!\n"); + //fprintf(stderr, "parse_pagetree: More kids then specified leaves!\n"); // TODO:: probably just a warning is enough here -- run the VIOL parser? } parse_pagenode(aux, kid, kidRef, kidDict, myRef, pgTable->arena); @@ -4807,23 +4836,25 @@ parse_pagetree( myNode->pgRsrc = NULL; item = dictentry(myDict, "Resources"); if (item) { - fprintf(stdout, "\n\nparse_pagetree: Found resources in node\n"); + //fprintf(stdout, "\n\nparse_pagetree: Found resources in node\n"); size_t offset = 0; rsrcdict_t = resolve_item(aux, item, &offset, p_objdef); if (!rsrcdict_t) { // TODO: Failure ==> xref error -- Figure out how to handle goto end; } - fprintf(stdout, "\nparse_pagetree: Resource token type = %u\n",rsrcdict_t->token_type); + //fprintf(stdout, "\nparse_pagetree: Resource token type = %u\n",rsrcdict_t->token_type); parse_rsrcdict(pgTable->arena, rsrcdict_t, myNode, aux); - pp_ptnode(stdout, myNode); + //pp_ptnode(stdout, myNode); } } + /* else { Ref *ref = (Ref *)kidRef->user; fprintf(stderr, "parse_pagetree: Reference <%zu, %zu> not found -- Deleted?!\n", ref->nr, ref->gen); } + */ } // end loop @@ -4862,12 +4893,13 @@ parse_catalog(struct Env *aux, const HParsedToken *root) aux->catalog.xoCount = 0; // DEBUG + /* fprintf(stdout, "\nparse_catalog: parsing Catalog = "); if (root->token_type == TT_Ref) pp_ref(stdout, root, 0, 0); else if (root->token_type == TT_Dict) pp_dict(stdout, root, 0, 0); - + */ // Ensure the reference is to the catalog dictionary @@ -4885,7 +4917,7 @@ parse_catalog(struct Env *aux, const HParsedToken *root) // Catalog found -- Now get the root of the page tree associated with the catalog ptRef = dictentry(catalog, "Pages"); // indirect reference to a dictionary if ( (ptRef == NULL) || (ptRef->token_type != TT_Ref) ) { - fprintf(stderr, "parse_catalog: Page Tree not found!\n"); + //fprintf(stderr, "parse_catalog: Page Tree not found!\n"); goto end; } aux->catalog.pRoot = ptRef; // indirect reference to the page tree @@ -4898,7 +4930,7 @@ parse_catalog(struct Env *aux, const HParsedToken *root) } dict_t = get_dictoftype(dict_t, NULL, "Pages", aux); // page tree root dictionary (parent is NULL) if (!dict_t) { - fprintf(stderr, "parse_catalog: No page table!\n"); + //fprintf(stderr, "parse_catalog: No page table!\n"); goto end; // Nothing more to do here } ptRoot = H_CAST(Dict, dict_t); @@ -4907,7 +4939,7 @@ parse_catalog(struct Env *aux, const HParsedToken *root) parse_pagetree(aux, &aux->catalog.pgTree, ptRef, ptRoot, NULL, 0); } else { // looks like the field "Type:Catalog" is a hint, not a requirement for a valid pdf - fprintf (stdout, "\n\nThe Catalog is missing!!"); + //fprintf (stdout, "\n\nThe Catalog is missing!!"); goto end; } @@ -5002,7 +5034,7 @@ p_stream_data__m(HAllocator *mm__, const Dict *dict, struct Env *aux) return p_xrefdata__m(mm__, dict); if (bytes_eq(v->bytes, "ObjStm")) { - fprintf(stdout, "\np_stream_data__m:: Parsing object stream\n"); + //fprintf(stdout, "\np_stream_data__m:: Parsing object stream\n"); return p_objstm__m(mm__, dict); } @@ -5015,13 +5047,13 @@ p_stream_data__m(HAllocator *mm__, const Dict *dict, struct Env *aux) */ v = dictentry(dict, "Subtype"); if (bytes_eq(v->bytes, "Form")) { - fprintf(stdout, "\n\np_stream_data_m:: Found Form XObject\n"); - fprintf(stdout, "p_stream_data_m:: Current XObject count = %lu\n", aux->catalog.xoCount); + //fprintf(stdout, "\n\np_stream_data_m:: Found Form XObject\n"); + //fprintf(stdout, "p_stream_data_m:: Current XObject count = %lu\n", aux->catalog.xoCount); // parse_xobject(mm__, dict, aux); return p_bytestream; #if 0 if (bytes_eq(v->bytes, "Image")) { - fprintf(stdout, "\n\np_stream_data_m:: Found XObject - Image\n"); + //fprintf(stdout, "\n\np_stream_data_m:: Found XObject - Image\n"); return p_fail; } #endif @@ -5052,7 +5084,7 @@ act_ks_value(const HParseResult *p, void *u) (int)b.len, b.token); // XXX return the undecoded stream (p->ast)? } - fprintf(stdout, "\n\nact_ks_value\n\n"); + //fprintf(stdout, "\n\nact_ks_value\n\n"); return H_MAKE(HParseResult, res); } @@ -5067,8 +5099,8 @@ HParser * kstream(HAllocator *mm__, const HParsedToken *x, void *env) { // DEBUG - fprintf (stdout, "\n\nkstream:"); - h_pprintln(stdout, x); + //fprintf (stdout, "\n\nkstream:"); + //h_pprintln(stdout, x); // DEBUG