⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dscutil.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 2 页
字号:
		    p = "Unknown";	}	sprintf(buf, "page orientation %s\n", p);	(*dfn)(ptr, buf);    }    if (dsc->page_bbox) {	sprintf(buf, "default page boundingbox %d %d %d %d\n",	    dsc->page_bbox->llx, dsc->page_bbox->lly, 	    dsc->page_bbox->urx, dsc->page_bbox->ury);        (*dfn)(ptr, buf);    }    for (i=0; dsc->media && (i<dsc->media_count); i++) {	if (dsc->media[i]) {	    sprintf(buf, "media %d   (%.50s) %g %g %g (%.50s) (%.50s)\n", i,		dsc->media[i]->name ? dsc->media[i]->name : "", 		dsc->media[i]->width, dsc->media[i]->height, 		dsc->media[i]->weight, 		dsc->media[i]->colour ? dsc->media[i]->colour : "", 		dsc->media[i]->type ? dsc->media[i]->type : "");	    (*dfn)(ptr, buf);	    if (dsc->media[i]->mediabox) {	        sprintf(buf, "  mediabox %d %d %d %d\n",		    dsc->media[i]->mediabox->llx,		    dsc->media[i]->mediabox->llx,		    dsc->media[i]->mediabox->llx,		    dsc->media[i]->mediabox->llx);		    (*dfn)(ptr, buf);		}	}    }    if (dsc->page_media) {	sprintf(buf, "default page media %.50s\n", dsc->page_media->name);        (*dfn)(ptr, buf);    }    if (dsc->viewing_orientation) {	sprintf(buf, "default viewing orientation %f %f %f %f\n",	    dsc->viewing_orientation->xx,	    dsc->viewing_orientation->xy,	    dsc->viewing_orientation->yx,	    dsc->viewing_orientation->yy);        (*dfn)(ptr, buf);    }    sprintf(fmtbuf, "comments %%%s %%%s\n", offset_fmt, offset_fmt);    sprintf(buf, fmtbuf, dsc->begincomments, dsc->endcomments);    (*dfn)(ptr, buf);    sprintf(fmtbuf, "preview %%%s %%%s\n", offset_fmt, offset_fmt);    sprintf(buf, fmtbuf, dsc->beginpreview, dsc->endpreview);    (*dfn)(ptr, buf);    sprintf(fmtbuf, "defaults %%%s %%%s\n", offset_fmt, offset_fmt);    sprintf(buf, fmtbuf, dsc->begindefaults, dsc->enddefaults);    (*dfn)(ptr, buf);    sprintf(fmtbuf, "prolog %%%s %%%s\n", offset_fmt, offset_fmt);    sprintf(buf, fmtbuf, dsc->beginprolog, dsc->endprolog);    (*dfn)(ptr, buf);    sprintf(fmtbuf, "setup %%%s %%%s\n", offset_fmt, offset_fmt);    sprintf(buf, fmtbuf, dsc->beginsetup, dsc->endsetup);    (*dfn)(ptr, buf);    sprintf(buf, "pages %d\n", dsc->page_pages);    (*dfn)(ptr, buf);    for (i=0; i<dsc->page_count; i++) {        sprintf(fmtbuf, "page %%.20s %%d  %%%s %%%s\n", offset_fmt, offset_fmt);	sprintf(buf, fmtbuf,	    dsc->page[i].label, dsc->page[i].ordinal, 	    dsc->page[i].begin, dsc->page[i].end);        (*dfn)(ptr, buf);	if (dsc->page[i].media) {	    sprintf(buf, "  page media %s\n", dsc->page[i].media->name);            (*dfn)(ptr, buf);	}	if (dsc->page[i].orientation != CDSC_ORIENT_UNKNOWN) {	    switch (dsc->page[i].orientation) {		case CDSC_PORTRAIT:			p = "Portrait";			break;		case CDSC_LANDSCAPE:			p = "Landscape";			break;		default:			p = "Unknown";	    }	    sprintf(buf, "  page orientation %s\n", p);	    (*dfn)(ptr, buf);	}	if (dsc->page[i].viewing_orientation) {	    sprintf(buf, "  viewing orientation %f %f %f %f\n",		dsc->page[i].viewing_orientation->xx,		dsc->page[i].viewing_orientation->xy,		dsc->page[i].viewing_orientation->yx,		dsc->page[i].viewing_orientation->yy);	    (*dfn)(ptr, buf);	}	if (dsc->page[i].crop_box) {	    sprintf(buf, "pagecropbox %f %f %f %f\n",		dsc->page[i].crop_box->fllx, dsc->page[i].crop_box->flly, 		dsc->page[i].crop_box->furx, dsc->page[i].crop_box->fury);	    (*dfn)(ptr, buf);	}    }    sprintf(fmtbuf, "trailer %%%s %%%s\n", offset_fmt, offset_fmt);    sprintf(buf, fmtbuf, dsc->begintrailer, dsc->endtrailer);    (*dfn)(ptr, buf);    if (pdcs) {	sprintf(buf, "DCS 2.0 separations\n");	(*dfn)(ptr, buf);    }    while (pdcs) {	if (pdcs->location && (dsc_stricmp(pdcs->location, "Local") == 0))	    sprintf(buf, " %s %s\n", pdcs->colourname, pdcs->filename);	else {            sprintf(fmtbuf, " %%s #%%%s %%%s\n", offset_fmt, offset_fmt);	    sprintf(buf, fmtbuf, pdcs->colourname, pdcs->begin, pdcs->end);	}        (*dfn)(ptr, buf);	pdcs = pdcs->next;    }    if (colour) {	sprintf(buf, "colours\n");	(*dfn)(ptr, buf);    }    while (colour) {	const char *type;	switch (colour->type) {	    case CDSC_COLOUR_PROCESS:		type = "Process";		break;	    case CDSC_COLOUR_CUSTOM:		type = "Custom";		break;	    default:		type = "Unknown";	}	sprintf(buf, " %s %s", colour->name, type);        (*dfn)(ptr, buf);	switch (colour->custom) {	    case CDSC_CUSTOM_COLOUR_CMYK:		sprintf(buf, " CMYK %g %g %g %g\n", colour->cyan, 		    colour->magenta, colour->yellow, colour->black);		break;	    case CDSC_CUSTOM_COLOUR_RGB:		sprintf(buf, " RGB %g %g %g\n", 		    colour->red, colour->green, colour->blue);		break;	    default:		sprintf(buf, "\n");	}        (*dfn)(ptr, buf);	colour = colour->next;    }    for (i=0; dsc->media && (i<dsc->media_count); i++) {	if (dsc->media[i]) {	    sprintf(buf, "media %d   (%.50s) %g %g %g (%.50s) (%.50s)\n", i,		dsc->media[i]->name ? dsc->media[i]->name : "", 		dsc->media[i]->width, dsc->media[i]->height, 		dsc->media[i]->weight, 		dsc->media[i]->colour ? dsc->media[i]->colour : "", 		dsc->media[i]->type ? dsc->media[i]->type : "");	    (*dfn)(ptr, buf);	    if (dsc->media[i]->mediabox) {	        sprintf(buf, "  mediabox %d %d %d %d\n",		    dsc->media[i]->mediabox->llx,		    dsc->media[i]->mediabox->llx,		    dsc->media[i]->mediabox->llx,		    dsc->media[i]->mediabox->llx);		    (*dfn)(ptr, buf);		}	}    }    (*dfn)(ptr, "== END DSC dump ==\n");}#ifdef STANDALONE/****************************************************************//* TESTING CODE *//****************************************************************/#include <fcntl.h>void dump_fn(void *caller_data, const char *str){    fputs(str, stdout);}#define COPY_BUF_SIZE 4096void ps_copy(FILE *outfile, FILE *infile, long begin, long end){    char *buf;    int count;    buf = (char *)malloc(COPY_BUF_SIZE);    if (buf == (char *)NULL)	return;    if (begin >= 0)	fseek(infile, begin, SEEK_SET);    begin = ftell(infile);    while (begin < end) {        count = min(end-begin, COPY_BUF_SIZE);	if ((count = fread(buf, 1, count, infile)) > 0) {	    fwrite(buf, 1, count, outfile);	    begin += count;	}	else	    begin = end;	/* EOF or error */    }    free(buf);}long mem_allocated = 0;long mem_signature = 0x5aa5f00f;FILE *mem_file = NULL;#define MEM_FILE "c:/gsview.txt"void *debug_memalloc(size_t size, void *closure_data){    void *p = malloc(size + 3 * sizeof(long));    long *pl = (long *)p;    if (pl) {	pl[0] = mem_signature;	pl[1] = (long)closure_data;	pl[2] = size;	mem_allocated += size;	p = (void *)(pl + 3);    }    if (mem_file == (FILE *)NULL)	mem_file = fopen(MEM_FILE, "w");    if (mem_file != (FILE *)NULL) {	fprintf(mem_file, "memalloc(%d) allocated=%ld ptr=0x%lx\n", 	    size, mem_allocated, (long)p);	fflush(mem_file);    }    return p;}void debug_memfree(void *ptr, void *closure_data){    long *pl = (long *)ptr;    long oldsize = 0;    int corrupted = 0;    int closure_mismatch = 0;    if (pl) {	pl -= 3;	oldsize = pl[2];	mem_allocated -= oldsize;	if (pl[1] != (long)closure_data)	    closure_mismatch = 1;	if (pl[0] != mem_signature)	    corrupted = 1;	else	    free((void *)pl);    }    if (mem_file == (FILE *)NULL)	mem_file = fopen(MEM_FILE, "w");    if (mem_file != (FILE *)NULL) {	fprintf(mem_file, "memfree(%ld) allocated=%ld ptr=0x%lx\n", 	    oldsize, mem_allocated, (long)ptr);	if (closure_mismatch)	    fprintf(mem_file, "memsfree closure_data MISMATCH\n");	if (corrupted)	    fprintf(mem_file, "memfree HEAP IS CORRUPTED\n");	fflush(mem_file);    }}int main(int argc, char *argv[]){    CDSC *dsc;    FILE *infile;    char buf[256];    char bigbuf[4096];    int count;    int code;    unsigned int i;    const char *filename = NULL;	    if (argc >= 2)	filename = argv[1];    if (filename == NULL)	filename = "t.ps";    /* file must be opened in BINARY mode */    infile = fopen(filename, "rb");    if (infile == NULL)	return 1;    /* test 1 - write single byte at a time */    fprintf(stdout, "TEST 1 - SINGLE BYTE\n");    fseek(infile, 0, SEEK_SET);    dsc = dsc_init(NULL);    dsc_set_debug_function(dsc, dump_fn);    dsc_set_error_function(dsc, dsc_error_fn);    while ((count = fread(buf, 1, 1, infile))!=0) {	dsc_scan_data(dsc, buf, count);    }    dsc_fixup(dsc);    dsc_display(dsc, dump_fn);    dsc_free(dsc);    /* test 2 - write multiple bytes at a time */    fprintf(stdout, "TEST 2 - %d BYTES\n", sizeof(buf));    fseek(infile, 0, SEEK_SET);    dsc = dsc_init(NULL);    dsc_set_debug_function(dsc, dump_fn);    dsc_set_error_function(dsc, dsc_error_fn);    while ((count = fread(buf, 1, sizeof(buf), infile))!=0) {	dsc_scan_data(dsc, buf, count);    }    dsc_fixup(dsc);    dsc_display(dsc, dump_fn);    dsc_free(dsc);    /* test 3 - write one line at a time a time */    /* Only works if the file does not contain null characters */    fprintf(stdout, "TEST 3 - LINE\n");    fseek(infile, 0, SEEK_SET);    dsc = dsc_init(NULL);    dsc_set_debug_function(dsc, dump_fn);    dsc_set_error_function(dsc, dsc_error_fn);    memset(buf, 0, sizeof(buf));    while (fgets(buf, sizeof(buf)-1, infile) != NULL) {	code  = dsc_scan_data(dsc, buf, strlen(buf));	if (code != CDSC_OK)	    fprintf(stdout, "Line %d, DSC %d\n", dsc->line_count, code);    }    dsc_fixup(dsc);    dsc_display(dsc, dump_fn);    fflush(stdout);#ifndef UNIX    setmode(fileno(stdout), O_BINARY);#endif    fputs("==== COMMENTS ====\r\n", stdout);    ps_copy(stdout, infile, dsc->begincomments, dsc->endcomments);    fputs("==== PREVIEW ====\r\n", stdout);    ps_copy(stdout, infile, dsc->beginpreview, dsc->endpreview);    fputs("==== DEFAULTS ====\r\n", stdout);    ps_copy(stdout, infile, dsc->begindefaults, dsc->enddefaults);    fputs("==== PROLOG ====\r\n", stdout);    ps_copy(stdout, infile, dsc->beginprolog, dsc->endprolog);    fputs("==== SETUP ====\r\n", stdout);    ps_copy(stdout, infile, dsc->beginsetup, dsc->endsetup);    for (i=0; i<dsc->page_count; i++) {	fprintf(stdout, "==== PAGE %d ====\r\n", i+1);	ps_copy(stdout, infile, dsc->page[i].begin, dsc->page[i].end);    }    fputs("==== TRAILER ====\r\n", stdout);    ps_copy(stdout, infile, dsc->begintrailer, dsc->endtrailer);    fputs("==== EOF ====\r\n", stdout);    dsc_free(dsc);    /* test 4 - write multiple bytes at a time, debug memalloc */    fprintf(stdout, "TEST 4 - %d BYTES, DEBUG MALLOC\n", sizeof(buf));    fseek(infile, 0, SEEK_SET);    dsc = dsc_init_with_alloc(NULL, debug_memalloc, debug_memfree, NULL);    dsc_set_debug_function(dsc, dump_fn);    dsc_set_error_function(dsc, dsc_error_fn);    while ((count = fread(buf, 1, sizeof(buf), infile))!=0) {	dsc_scan_data(dsc, buf, count);    }    dsc_fixup(dsc);    dsc_display(dsc, dump_fn);    dsc_free(dsc);    if (mem_file)	fclose(mem_file);    /* test 5 - write multiple bytes at a time */    fprintf(stdout, "TEST 5 - %d BYTES\n", sizeof(bigbuf));    fseek(infile, 0, SEEK_SET);    dsc = dsc_init(NULL);    dsc_set_debug_function(dsc, dump_fn);    dsc_set_error_function(dsc, dsc_error_fn);    while ((count = fread(bigbuf, 1, sizeof(bigbuf), infile))!=0) {	dsc_scan_data(dsc, bigbuf, count);    }    dsc_fixup(dsc);    dsc_display(dsc, dump_fn);    dsc_free(dsc);    dsc = NULL;    return 0;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -