void startline(PdfFile * file,ByteArray * bytearray) { char * line = ByteArray_readLine(bytearray); if(strstr(line," obj")) { PdfObj_read(file,line); line = NULL; }else if(strncmp(line,"xref",4)==0){ printf("xref!\n"); PdfXref_read(bytearray); }else if(strncmp(line,"trailer",7)==0){ printf("trailer!\n"); PdfTrailer_read(file,bytearray); }else if(strncmp(line,"startxref",7)==0){ printf("startxref!\n"); free(line); line = ByteArray_readLine(bytearray); printf("%d,",atoi(line)); }else if(strncmp(line,"%%EOF",5)==0){ printf("\nfile end!\n"); //free(line); line = NULL; } if(line){ free(line); } if(bytearray->position < bytearray->length) startline(file,bytearray); }
static void oput(int ch) /* int ch; / * next output character */ { /* * * Responsible for adding all printing characters from the input file to the * open string on top of the stack. The only other characters that end up in * that string are the quotes required for special characters. Reverse printing * mode hasn't been tested but it should be close. hpos and lastx should disagree * each time (except after startline() does something), and that should force a * call to endstring() for every character. * */ if ( stringcount > 100 ) /* don't put too much on the stack */ endline(); if ( vpos != lasty ) endline(); if ( advance == -1 ) /* for reverse printing - move first */ hmot(hmi); startline(); if ( lastc != ch || hpos != prevx ) { if ( lastx != hpos ) endstring(); if ( isascii(ch) && isprint(ch) ) { if ( ch == '\\' || ch == '(' || ch == ')' ) putc('\\', fp_out); putc(ch, fp_out); } else fprintf(fp_out, "\\%.3o", ch & 0377); lastc = ch; prevx = hpos; lastx += lasthmi; } /* End if */ if ( advance != -1 ) hmot(hmi); markedpage = TRUE; } /* End of oput */
PdfFile * PdfFile_parse(ByteArray * bytearray,char * out) { PdfFile * file = malloc(sizeof(PdfFile)); memset(file,0,sizeof(PdfFile)); file->bytearray = bytearray; file->header = PdfHeader_read(bytearray); if(file->header==NULL) { PdfFile_free(file); return 0; } startline(file,bytearray); return file; }
/* Print a string */ static void prstr( const char *string) { size_t len = strlen(string) + 1; /* * If this string overflows this line, and there's other stuff * on the line, create a new one. */ if (linelen > 0 && linelen + len >= RMARGIN - LMARGIN) { endline(); startline(""); } g_printf(" %s", string); linelen += len; }
/*** inc - translate a mailbox into a set of documents * * We read each message from the mailbox, copying it into * a 'presentation file', which contains the message in * the DH presentation format. We need to translate the * "From " line into presentation header format, but * fortunately the rest of a standard mail message is * conformant with the DH presentation format. * * When we have copied the entire message to this file, * we rewind the stream to the start of that file, and * create a document, setting the text (header and body) * of the document to the message, by a call to puttext(); * * This operation is repeated until the end of the mailbox * is reached. */ static VOID inc(PSTR mboxname, PSTR foldername) { static CHAR lbuf[MAXLEN]; /* line buffer */ FILE *mailbox; /* mailbox file */ FILE *pf; /* presentation format file */ Dhandle dh; /* handle to document being created */ Fhandle fh; /* target folder */ PSTR tmpnam; /* pointer to name of temp. file */ PSTR p; /* open mailbox for reading */ if ( (mailbox = fopen(mboxname, "r")) == NULL ) { fprintf(stderr, "Can't open mailbox '%s'\n", mboxname); exit(1); } /* open up the inbox folder */ if ( (fh = getfolder(foldername, FLD_SPEC)) == ERROR ) { fprintf(stderr, "can't open folder '%s'\n", foldername); fclose(mailbox); exit(1); } /* skip to start of first message */ do { fgets(lbuf, MAXLEN, mailbox); } while ( feof(mailbox) == 0 && !startline(lbuf) ); /* ** at the start of this loop, the stream 'mailbox' ** is either pointing to the end of the mailbox, or ** to the beginning of a message */ while ( feof(mailbox) == 0 ) { /* open presentation format file */ tmpnam = mktmpnam(); pf = fopen(tmpnam, "w+"); #if defined (XENIX) unlink("dhtmp"); #endif fputs ("Mail-Flags: 0001\n", pf); /* copy message into presentation file */ /* if from line contains only "From ", don't output it */ p = lbuf + 4; while ( *p == ' ' ) p++; if ( *p == '\n' ) fgets(lbuf, MAXLEN, mailbox); do { if ( strncmp(lbuf, "Mail-Flags: ", 12) ) fputs(lbuf, pf); fgets(lbuf, MAXLEN, mailbox); } while ( feof(mailbox) == 0 && !startline(lbuf)); fseek(pf, 0L, 0); fflush(pf); /* ** message is now in presentation file, with stream ** positioned at the start of the message */ if ( (dh = getdoc(fh, DOC_CREATE, NULL)) == ERROR ) { fprintf(stderr, "Can't create document\n"); exit(1); } puttext(dh, _fileno(pf)); adddl(fh, getid(dh)); putdoc(dh); fclose(pf); #if defined (MSDOS) _unlink(tmpnam); #endif free(tmpnam); } putfolder(fh); putdl(); fclose(mailbox); }
int main( int argc, char ** argv) { const char *v; char *verstr; size_t v_len; (void)argc; /* Quiet unused parameter warning */ (void)argv; /* Quiet unused parameter warning */ /* * Configure program for internationalization: * 1) Only set the message locale for now. * 2) Set textdomain for all amanda related programs to "amanda" * We don't want to be forced to support dozens of message catalogs. */ setlocale(LC_MESSAGES, "C"); textdomain("amanda"); g_printf(_("/* version.c - generated by genversion.c - DO NOT EDIT! */\n")); g_printf("const char * const version_info[] = {\n"); startline("build:"); v = VERSION; v_len = sizeof("Amanda-") + strlen(v) + 1; verstr = malloc(v_len); if (!verstr) { g_fprintf(stderr, _("genversion: Not enough memory")); abort(); /*NOTREACHED*/ } g_snprintf(verstr, v_len, "Amanda-%s", v); /* safe */ prvar("VERSION", verstr); free(verstr); #ifdef BUILT_DATE prvar("BUILT_DATE", BUILT_DATE); #else prundefvar("BUILT_DATE"); #endif #ifdef BUILT_MACH prvar("BUILT_MACH", BUILT_MACH); #else prundefvar("BUILT_MACH"); #endif #ifdef BUILT_REV prvar("BUILT_REV", BUILT_REV); #else prundefvar("BUILT_REV"); #endif #ifdef BUILT_BRANCH prvar("BUILT_BRANCH", BUILT_BRANCH); #else prundefvar("BUILT_BRANCH"); #endif #ifdef CC prvar("CC", CC); #else prundefvar("CC"); #endif endline(); startline("paths:"); prvar("bindir", bindir); prvar("sbindir", sbindir); prvar("libexecdir", libexecdir); prvar("amlibexecdir", amlibexecdir); prvar("mandir", mandir); prvar("AMANDA_TMPDIR", AMANDA_TMPDIR); #ifdef AMANDA_DBGDIR prvar("AMANDA_DBGDIR", AMANDA_DBGDIR); #else prundefvar("AMANDA_DBGDIR"); #endif prvar("CONFIG_DIR", CONFIG_DIR); #ifdef DEV_PREFIX prvar("DEV_PREFIX", DEV_PREFIX); #else prundefvar("DEV_PREFIX"); #endif #ifdef RDEV_PREFIX prvar("RDEV_PREFIX", RDEV_PREFIX); #else prundefvar("RDEV_PREFIX"); #endif #ifdef DUMP prvar("DUMP", DUMP); prvar("RESTORE", RESTORE); #else prundefvar("DUMP"); prundefvar("RESTORE"); #endif #ifdef VDUMP prvar("VDUMP", VDUMP); prvar("VRESTORE", VRESTORE); #else prundefvar("VDUMP"); prundefvar("VRESTORE"); #endif #ifdef XFSDUMP prvar("XFSDUMP", XFSDUMP); prvar("XFSRESTORE", XFSRESTORE); #else prundefvar("XFSDUMP"); prundefvar("XFSRESTORE"); #endif #ifdef VXDUMP prvar("VXDUMP", VXDUMP); prvar("VXRESTORE", VXRESTORE); #else prundefvar("VXDUMP"); prundefvar("VXRESTORE"); #endif #ifdef SAMBA_CLIENT prvar("SAMBA_CLIENT", SAMBA_CLIENT); #else prundefvar("SAMBA_CLIENT"); #endif #ifdef GNUTAR prvar("GNUTAR", GNUTAR); #else prundefvar("GNUTAR"); #endif #ifdef COMPRESS_PATH prvar("COMPRESS_PATH", COMPRESS_PATH); #else prundefvar("COMPRESS_PATH"); #endif #ifdef UNCOMPRESS_PATH prvar("UNCOMPRESS_PATH", UNCOMPRESS_PATH); #else prundefvar("UNCOMPRESS_PATH"); #endif #ifdef LPRCMD prvar("LPRCMD", LPRCMD); #else prundefvar(" LPRCMD"); #endif #ifdef MAILER prvar("MAILER", MAILER); #else prundefvar(" MAILER"); #endif #ifdef GNUTAR_LISTED_INCREMENTAL_DIR prvar("listed_incr_dir", GNUTAR_LISTED_INCREMENTAL_DIR); #else prundefvar("GNUTAR_LISTED_INCREMENTAL_DIR"); #endif endline(); startline("defs:"); prvar("DEFAULT_SERVER", DEFAULT_SERVER); prvar("DEFAULT_CONFIG", DEFAULT_CONFIG); prvar("DEFAULT_TAPE_SERVER", DEFAULT_TAPE_SERVER); #ifdef DEFAULT_TAPE_DEVICE prvar("DEFAULT_TAPE_DEVICE", DEFAULT_TAPE_DEVICE); #endif #ifdef AIX_BACKUP prstr("AIX_BACKUP"); #endif #ifdef BROKEN_VOID prstr("BROKEN_VOID"); #endif #ifdef DUMP_RETURNS_1 prstr("DUMP_RETURNS_1"); #endif #ifdef HAVE_MMAP prstr("HAVE_MMAP"); #endif #ifndef HAVE_STRERROR prstr("NEED_STRERROR"); #endif #ifndef HAVE_STRSTR prstr("NEED_STRSTR"); #endif #ifdef HAVE_SYSVSHM prstr("HAVE_SYSVSHM"); #endif #ifdef WANT_AMFLOCK_POSIX prstr("AMFLOCK_POSIX"); #endif #ifdef WANT_AMFLOCK_FLOCK prstr("AMFLOCK_FLOCK"); #endif #ifdef WANT_AMFLOCK_LOCKF prstr("AMFLOCK_LOCKF"); #endif #ifdef WANT_AMFLOCK_LNLOCK prstr("AMFLOCK_LNLOCK"); #endif #ifdef STATFS_BSD prstr("STATFS_BSD"); #endif #ifdef STATFS_OSF1 prstr("STATFS_OSF1"); #endif #ifdef STATFS_ULTRIX prstr("STATFS_ULTRIX"); #endif #ifdef SETPGRP_VOID prstr("SETPGRP_VOID"); #endif #ifdef ASSERTIONS prstr("ASSERTIONS"); #endif #ifdef AMANDA_DEBUG_DAYS prnum("AMANDA_DEBUG_DAYS", AMANDA_DEBUG_DAYS); #endif #ifdef BSD_SECURITY prstr("BSD_SECURITY"); #endif #ifdef KRB5_SECURITY prstr("KRB5_SECURITY"); #endif #ifdef RSH_SECURITY prstr("RSH_SECURITY"); #endif #ifdef USE_AMANDAHOSTS prstr("USE_AMANDAHOSTS"); #endif #ifdef USE_RUNDUMP prstr("USE_RUNDUMP"); #endif prvar("CLIENT_LOGIN", CLIENT_LOGIN); #ifdef CHECK_USERID prstr("CHECK_USERID"); #endif #ifdef HAVE_GZIP prstr("HAVE_GZIP"); #endif #ifdef COMPRESS_SUFFIX prvar("COMPRESS_SUFFIX", COMPRESS_SUFFIX); #endif #ifdef COMPRESS_FAST_OPT prvar("COMPRESS_FAST_OPT", COMPRESS_FAST_OPT); #endif #ifdef COMPRESS_BEST_OPT prvar("COMPRESS_BEST_OPT", COMPRESS_BEST_OPT); #endif #ifdef UNCOMPRESS_OPT prvar("UNCOMPRESS_OPT", UNCOMPRESS_OPT); #endif endline(); g_printf(" 0\n};\n"); return (0); /* exit */ }