Example #1
0
void
exToHt(char *filename)
{
    char line[MaxLineLength], *line2;
    char *title, *pagename;
    FILE *inFile = fopen(filename, "r");
    FILE *outFile;
    int len, i;
    struct timeval  tvp;
    struct stat buf;

    if (inFile == NULL) {
        fprintf(stderr, "couldn't open %s for reading.\n", filename);
        return;
    }
    strcpy(line, "Menu");
    strcat(line, filename);
    len = strlen(line);
    for (i = 0; i < len; i++)
        if (line[i] == '.') {
            line[i] = '\0';
            break;
        }
    outFile = fopen(line, "w");
    if (outFile == NULL) {
        fprintf(stderr, "couldn't open %s for writing.\n", line);
        return;
    }
    pagename = allocString(line);
    title = getExTitle(inFile, line);
    if (title == NULL) {
        return;
    }
    files[numFiles++] = pagename;
    emitCoverLink(pagename, title);
    emitHeader(outFile, pagename, title);
    while (fgets(line, MaxLineLength, inFile) != NULL) {
        if ((line2 = strPrefix("\\begin{page}{", line)))
            emitMenuEntry(line2, outFile);
        else if ((line2 = strPrefix("\\spadcommand{", line)))
            emitSpadCommand(line2, "\\spadcommand{", outFile);
        else if ((line2 = strPrefix("\\spadpaste{", line)))
            emitSpadCommand(line2, "\\spadpaste{", outFile);
        else if ((line2 = strPrefix("\\example{", line)))
            emitSpadCommand(line2, "\\example{", outFile);
        else if ((line2 = strPrefix("\\graphpaste{", line)))
            emitSpadCommand(line2, "\\graphpaste{", outFile);
    }
    emitFooter(outFile);
    fclose(inFile);
    fclose(outFile);
    stat(filename,&buf);
    tvp.tv_sec =buf.st_mtime;
    tvp.tv_usec =0;
    if timercmp(&tvp,&latest_date[1],>){
        latest_date[1].tv_sec=buf.st_mtime;
        }
}
Example #2
0
void CGModule::emitModule(){
	
	CGSymFinder vis(this);
	
	size_t k;
	for( k=0;k<frames.size();++k ){
		CGFrame *f=frames[k];
		CGSym *sym=f->fun->sym;
		if( sym->linkage==CG_EXPORT ) exportSyms.insert( sym->value );
		CGAsm *as;
		for( as=f->assem.begin;as!=f->assem.end;as=as->succ ){
			CGStm *t=as->stm;
			if( !t ) continue;
			t->visit( vis );
		}
	}
	
	set<string>::iterator sym_it;
	
	//header
	emitHeader();
	
	//imports
	for( sym_it=importSyms.begin();sym_it!=importSyms.end();++sym_it ){
		emitImport( *sym_it );
	}
	
	//exports
	for( sym_it=exportSyms.begin();sym_it!=exportSyms.end();++sym_it ){
		emitExport( *sym_it );
	}
	
	//frames
	for( k=0;k<frames.size();++k ){
		emitFrame( frames[k] );
	}
	
	//datas
	for( k=0;k<datas.size();++k ){
		emitData( datas[k] );
	}
	
	//footer
	emitFooter();
	
	out.flush();
}
Example #3
0
bool SkPDFDocument::emitPDF(SkWStream* stream) {
    if (fPages.isEmpty()) {
        return false;
    }
    for (int i = 0; i < fPages.count(); i++) {
        if (fPages[i] == NULL) {
            return false;
        }
    }

    // We haven't emitted the document before if fPageTree is empty.
    if (fPageTree.isEmpty()) {
        SkPDFDict* pageTreeRoot;
        SkPDFPage::GeneratePageTree(fPages, fCatalog.get(), &fPageTree,
                                    &pageTreeRoot);
        fDocCatalog->insert("Pages", new SkPDFObjRef(pageTreeRoot))->unref();

        /* TODO(vandebo): output intent
        SkRefPtr<SkPDFDict> outputIntent = new SkPDFDict("OutputIntent");
        outputIntent->unref();  // SkRefPtr and new both took a reference.
        outputIntent->insert("S", new SkPDFName("GTS_PDFA1"))->unref();
        outputIntent->insert("OutputConditionIdentifier",
                             new SkPDFString("sRGB"))->unref();
        SkRefPtr<SkPDFArray> intentArray = new SkPDFArray;
        intentArray->unref();  // SkRefPtr and new both took a reference.
        intentArray->append(outputIntent.get());
        fDocCatalog->insert("OutputIntent", intentArray.get());
        */

        bool firstPage = true;
        for (int i = 0; i < fPages.count(); i++) {
            int resourceCount = fPageResources.count();
            fPages[i]->finalizePage(fCatalog.get(), firstPage, &fPageResources);
            addResourcesToCatalog(resourceCount, firstPage, &fPageResources,
                                  fCatalog.get());
            if (i == 0) {
                firstPage = false;
                fSecondPageFirstResourceIndex = fPageResources.count();
            }
        }

        // Build font subsetting info before proceeding.
        perform_font_subsetting(fCatalog.get(), fPages, &fSubstitutes);

        // Figure out the size of things and inform the catalog of file offsets.
        off_t fileOffset = headerSize();
        fileOffset += fCatalog->setFileOffset(fDocCatalog.get(),
                (size_t) fileOffset);
        fileOffset += fCatalog->setFileOffset(fPages[0], (size_t) fileOffset);
        fileOffset += fPages[0]->getPageSize(fCatalog.get(),
                (size_t) fileOffset);
        for (int i = 0; i < fSecondPageFirstResourceIndex; i++) {
            fileOffset += fCatalog->setFileOffset(fPageResources[i],
                                                  (size_t) fileOffset);
        }
        // Add the size of resources of substitute objects used on page 1.
        fileOffset += fCatalog->setSubstituteResourcesOffsets(fileOffset, true);
        if (fPages.count() > 1) {
            // TODO(vandebo): For linearized format, save the start of the
            // first page xref table and calculate the size.
        }

        for (int i = 0; i < fPageTree.count(); i++) {
            fileOffset += fCatalog->setFileOffset(fPageTree[i],
                    (size_t) fileOffset);
        }

        for (int i = 1; i < fPages.count(); i++) {
            fileOffset += fPages[i]->getPageSize(fCatalog.get(),
                    (size_t) fileOffset);
        }

        for (int i = fSecondPageFirstResourceIndex;
                 i < fPageResources.count();
                 i++) {
            fileOffset += fCatalog->setFileOffset(fPageResources[i],
                                                  (size_t) fileOffset);
        }

        fileOffset += fCatalog->setSubstituteResourcesOffsets(fileOffset,
                                                              false);
        fXRefFileOffset = fileOffset;
    }

    emitHeader(stream);
    fDocCatalog->emitObject(stream, fCatalog.get(), true);
    fPages[0]->emitObject(stream, fCatalog.get(), true);
    fPages[0]->emitPage(stream, fCatalog.get());
    for (int i = 0; i < fSecondPageFirstResourceIndex; i++) {
        fPageResources[i]->emit(stream, fCatalog.get(), true);
    }
    fCatalog->emitSubstituteResources(stream, true);
    // TODO(vandebo): Support linearized format
    // if (fPages.size() > 1) {
    //     // TODO(vandebo): Save the file offset for the first page xref table.
    //     fCatalog->emitXrefTable(stream, true);
    // }

    for (int i = 0; i < fPageTree.count(); i++) {
        fPageTree[i]->emitObject(stream, fCatalog.get(), true);
    }

    for (int i = 1; i < fPages.count(); i++) {
        fPages[i]->emitPage(stream, fCatalog.get());
    }

    for (int i = fSecondPageFirstResourceIndex;
            i < fPageResources.count();
            i++) {
        fPageResources[i]->emit(stream, fCatalog.get(), true);
    }

    fCatalog->emitSubstituteResources(stream, false);
    int64_t objCount = fCatalog->emitXrefTable(stream, fPages.count() > 1);
    emitFooter(stream, objCount);
    return true;
}
Example #4
0
size_t SkPDFDocument::headerSize() {
    SkDynamicMemoryWStream buffer;
    emitHeader(&buffer);
    return buffer.getOffset();
}