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

📄 dscparse.cpp

📁 okular
💻 CPP
📖 第 1 页 / 共 5 页
字号:
dsc_private int dsc_scan_comments(CDSC *dsc){    /* Comments section ends at */    /*  %%EndComments */    /*  another section */    /*  line that does not start with %% */    /* Save a few important lines */    char *line = dsc->line;    GSBOOL continued = FALSE;    dsc->id = CDSC_OK;    if (IS_DSC(line, "%%EndComments")) {	dsc->id = CDSC_ENDCOMMENTS;	dsc->endcomments = DSC_END(dsc);	dsc->scan_section = scan_pre_preview;	return CDSC_OK;    }    else if (IS_DSC(line, "%%BeginComments")) {	/* ignore because we are in this section */	dsc->id = CDSC_BEGINCOMMENTS;    }    else if (dsc_is_section(line)) {	dsc->endcomments = DSC_START(dsc);	dsc->scan_section = scan_pre_preview;	return CDSC_PROPAGATE;    }    else if (line[0] == '%' && IS_WHITE_OR_EOL(line[1])) {	dsc->endcomments = DSC_START(dsc);	dsc->scan_section = scan_pre_preview;	return CDSC_PROPAGATE;    }    else if (line[0] != '%') {	dsc->id = CDSC_OK;	dsc->endcomments = DSC_START(dsc);	dsc->scan_section = scan_pre_preview;	return CDSC_PROPAGATE;    }    else if (IS_DSC(line, "%%Begin")) {	dsc->endcomments = DSC_START(dsc);	dsc->scan_section = scan_pre_preview;	return CDSC_PROPAGATE;    }    /* Handle continuation lines.     * To simply processing, we assume that contination lines      * will only occur if repeat parameters are allowed and that      * a complete set of these parameters appears on each line.       * This is more restrictive than the DSC specification, but     * is valid for the DSC comments understood by this parser     * for all documents that we have seen.     */    if (IS_DSC(line, "%%+")) {	line = dsc->last_line;	continued = TRUE;    }    else	dsc_save_line(dsc);    if (IS_DSC(line, "%%Pages:")) {	dsc->id = CDSC_PAGES;	if (dsc_parse_pages(dsc) != 0)	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%Creator:")) {	dsc->id = CDSC_CREATOR;	dsc->dsc_creator = dsc_add_line(dsc, dsc->line+10, dsc->line_length-10);	if (dsc->dsc_creator==NULL)	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%CreationDate:")) {	dsc->id = CDSC_CREATIONDATE;	dsc->dsc_date = dsc_add_line(dsc, dsc->line+15, dsc->line_length-15);	if (dsc->dsc_date==NULL)	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%Title:")) {	dsc->id = CDSC_TITLE;	dsc->dsc_title = dsc_add_line(dsc, dsc->line+8, dsc->line_length-8);	if (dsc->dsc_title==NULL)	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%Copyright:")) {	dsc->id = CDSC_COPYRIGHT;	dsc->dsc_copyright = dsc_add_line(dsc, dsc->line+12, dsc->line_length-12);	if (dsc->dsc_copyright == NULL)	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%For:")) {	dsc->id = CDSC_FOR;	dsc->dsc_for = dsc_add_line(dsc, dsc->line+6, dsc->line_length-6);	if (dsc->dsc_for==NULL)	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%LanguageLevel:")) {	unsigned int n = continued ? 3 : 16;	unsigned int i;	int ll;	dsc->id = CDSC_LANGUAGELEVEL;	ll = dsc_get_int(dsc->line+n, dsc->line_length-n, &i);	if (i) {	    if ( (ll==1) || (ll==2) || (ll==3) )		dsc->language_level = ll;	    else {		dsc_unknown(dsc);	    }	}	else 	    dsc_unknown(dsc);    }    else if (IS_DSC(line, "%%BoundingBox:")) {	dsc->id = CDSC_BOUNDINGBOX;	if (dsc_parse_bounding_box(dsc, &(dsc->bbox), continued ? 3 : 14))	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%HiResBoundingBox:")) {	dsc->id = CDSC_HIRESBOUNDINGBOX;	if (dsc_parse_float_bounding_box(dsc, &(dsc->hires_bbox), 	    continued ? 3 : 19))	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%CropBox:")) {	dsc->id = CDSC_CROPBOX;	if (dsc_parse_float_bounding_box(dsc, &(dsc->crop_box), 	    continued ? 3 : 10))	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%Orientation:")) {	dsc->id = CDSC_ORIENTATION;	if (dsc_parse_orientation(dsc, &(dsc->page_orientation), 		continued ? 3 : 14))	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%PageOrder:")) {	dsc->id = CDSC_PAGEORDER;	if (dsc_parse_order(dsc))	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%DocumentMedia:")) {	dsc->id = CDSC_DOCUMENTMEDIA;	if (dsc_parse_document_media(dsc))	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%DocumentPaperSizes:")) {	/* DSC 2.1 */	unsigned int n = continued ? 3 : 21;	unsigned int count = 0;	unsigned int i = 1;	char name[MAXSTR];	char *p;	dsc->id = CDSC_DOCUMENTPAPERSIZES;	while (i && (dsc->line[n]!='\r') && (dsc->line[n]!='\n')) {	    p = dsc_copy_string(name, sizeof(name)-1,		    dsc->line+n, dsc->line_length-n, &i);	    if (i && p) {		const CDSCMEDIA *m = dsc_known_media;		if (count >= dsc->media_count) {		    /* set some default values */		    CDSCMEDIA lmedia;		    lmedia.name = p;		    lmedia.width = 595.0;		    lmedia.height = 842.0;		    lmedia.weight = 80.0;		    lmedia.colour = NULL;		    lmedia.type = NULL;		    lmedia.mediabox = NULL;		    if (dsc_add_media(dsc, &lmedia))			return CDSC_ERROR;		}		else		    dsc->media[count]->name = 			dsc_alloc_string(dsc, p, strlen(p));		/* find in list of known media */		while (m && m->name) {		    if (dsc_stricmp(p, m->name)==0) {			dsc->media[count]->width = m->width;			dsc->media[count]->height = m->height;			break;		    }		    m++;		}	    }	    n+=i;	    count++;	}    }    else if (IS_DSC(line, "%%DocumentPaperForms:")) {	/* DSC 2.1 */	unsigned int n = continued ? 3 : 21;	unsigned int count = 0;	unsigned int i = 1;	char type[MAXSTR];	char *p;	dsc->id = CDSC_DOCUMENTPAPERFORMS;	while (i && (dsc->line[n]!='\r') && (dsc->line[n]!='\n')) {	    p = dsc_copy_string(type, sizeof(type)-1,		    dsc->line+n, dsc->line_length-n, &i);	    if (i && p) {		if (count >= dsc->media_count) {		    /* set some default values */		    CDSCMEDIA lmedia;		    lmedia.name = NULL;		    lmedia.width = 595.0;		    lmedia.height = 842.0;		    lmedia.weight = 80.0;		    lmedia.colour = NULL;		    lmedia.type = p;		    lmedia.mediabox = NULL;		    if (dsc_add_media(dsc, &lmedia))			return CDSC_ERROR;		}		else		    dsc->media[count]->type = 			dsc_alloc_string(dsc, p, strlen(p));	    }	    n+=i;	    count++;	}    }    else if (IS_DSC(line, "%%DocumentPaperColors:")) {	/* DSC 2.1 */	unsigned int n = continued ? 3 : 22;	unsigned int count = 0;	unsigned int i = 1;	char colour[MAXSTR];	char *p;	dsc->id = CDSC_DOCUMENTPAPERCOLORS;	while (i && (dsc->line[n]!='\r') && (dsc->line[n]!='\n')) {	    p = dsc_copy_string(colour, sizeof(colour)-1, 		    dsc->line+n, dsc->line_length-n, &i);	    if (i && p) {		if (count >= dsc->media_count) {		    /* set some default values */		    CDSCMEDIA lmedia;		    lmedia.name = NULL;		    lmedia.width = 595.0;		    lmedia.height = 842.0;		    lmedia.weight = 80.0;		    lmedia.colour = p;		    lmedia.type = NULL;		    lmedia.mediabox = NULL;		    if (dsc_add_media(dsc, &lmedia))			return CDSC_ERROR;		}		else		    dsc->media[count]->colour = 			dsc_alloc_string(dsc, p, strlen(p));	    }	    n+=i;	    count++;	}    }    else if (IS_DSC(line, "%%DocumentPaperWeights:")) {	/* DSC 2.1 */	unsigned int n = continued ? 3 : 23;	unsigned int count = 0;	unsigned int i = 1;	float w;	dsc->id = CDSC_DOCUMENTPAPERWEIGHTS;	while (i && (dsc->line[n]!='\r') && (dsc->line[n]!='\n')) {	    w = dsc_get_real(dsc->line+n, dsc->line_length-n, &i);	    if (i) {		if (count >= dsc->media_count) {		    /* set some default values */		    CDSCMEDIA lmedia;		    lmedia.name = NULL;		    lmedia.width = 595.0;		    lmedia.height = 842.0;		    lmedia.weight = w;		    lmedia.colour = NULL;		    lmedia.type = NULL;		    lmedia.mediabox = NULL;		    if (dsc_add_media(dsc, &lmedia))			return CDSC_ERROR;		}		else		    dsc->media[count]->weight = w;	    }	    n+=i;	    count++;	}    }    else if (IS_DSC(line, "%%DocumentData:")) {	unsigned int n = continued ? 3 : 15;	char *p = dsc->line + n;        while (IS_WHITE(*p))	    p++;	dsc->id = CDSC_DOCUMENTDATA;	if (COMPARE(p, "Clean7Bit"))	    dsc->document_data = CDSC_CLEAN7BIT;	else if (COMPARE(p, "Clean8Bit"))	    dsc->document_data = CDSC_CLEAN8BIT;	else if (COMPARE(p, "Binary"))	    dsc->document_data = CDSC_BINARY;	else	    dsc_unknown(dsc);    }    else if (IS_DSC(line, "%%Requirements:")) {	dsc->id = CDSC_REQUIREMENTS;	/* ignore */    }    else if (IS_DSC(line, "%%DocumentNeededFonts:")) {	dsc->id = CDSC_DOCUMENTNEEDEDFONTS;	/* ignore */    }    else if (IS_DSC(line, "%%DocumentSuppliedFonts:")) {	dsc->id = CDSC_DOCUMENTSUPPLIEDFONTS;	/* ignore */    }    else if (dsc->line[0] == '%' && IS_WHITE_OR_EOL(dsc->line[1])) {	dsc->id = CDSC_OK;	/* ignore */    }    else {	dsc->id = CDSC_UNKNOWNDSC;	dsc_unknown(dsc);    }    dsc->endcomments = DSC_END(dsc);    return CDSC_OK;}dsc_private int dsc_scan_preview(CDSC *dsc){    /* Preview section ends at */    /*  %%EndPreview */    /*  another section */    /* Preview section must start with %%BeginPreview */    char *line = dsc->line;    dsc->id = CDSC_OK;    if (dsc->scan_section == scan_pre_preview) {	if (IS_BLANK(line))	    return CDSC_OK;	/* ignore blank lines before preview */	else if (IS_DSC(line, "%%BeginPreview")) {	    dsc->id = CDSC_BEGINPREVIEW;	    dsc->beginpreview = DSC_START(dsc);	    dsc->endpreview = DSC_END(dsc);	    dsc->scan_section = scan_preview;	    /* Don't mark the preview as EPSI if a DOS EPS header is present */	    if (dsc->preview == CDSC_NOPREVIEW)		dsc->preview = CDSC_EPSI;	    return CDSC_OK;	}	else {	    dsc->scan_section = scan_pre_defaults;	    return CDSC_PROPAGATE;	}    }    if (IS_DSC(line, "%%BeginPreview")) {	/* ignore because we are in this section */    }    else if (dsc_is_section(line)) {	dsc->endpreview = DSC_START(dsc);	dsc->scan_section = scan_pre_defaults;	return CDSC_PROPAGATE;    }    else if (IS_DSC(line, "%%EndPreview")) {	dsc->id = CDSC_ENDPREVIEW;	dsc->endpreview = DSC_END(dsc);	dsc->scan_section = scan_pre_defaults;	return CDSC_OK;    }    else if (line[0] == '%' && line[1] != '%') {	/* Ordinary comments are OK */    }    else {	dsc->id = CDSC_UNKNOWNDSC;	/* DSC comments should not occur in preview */	dsc_unknown(dsc);    }    dsc->endpreview = DSC_END(dsc);    return CDSC_OK;}dsc_private intdsc_scan_defaults(CDSC *dsc){    /* Defaults section ends at */    /*  %%EndDefaults */    /*  another section */    /* Defaults section must start with %%BeginDefaults */    char *line = dsc->line;    dsc->id = CDSC_OK;    if (dsc->scan_section == scan_pre_defaults) {	if (IS_BLANK(line))	    return CDSC_OK;	/* ignore blank lines before defaults */	else if (IS_DSC(line, "%%BeginDefaults")) {	    dsc->id = CDSC_BEGINDEFAULTS;	    dsc->begindefaults = DSC_START(dsc);	    dsc->enddefaults = DSC_END(dsc);	    dsc->scan_section = scan_defaults;	    return CDSC_OK;	}	else {	    dsc->scan_section = scan_pre_prolog;	    return CDSC_PROPAGATE;	}    }    if (NOT_DSC_LINE(line)) {	/* ignore */    }    else if (IS_DSC(line, "%%BeginPreview")) {	/* ignore because we have already processed this section */    }    else if (IS_DSC(line, "%%BeginDefaults")) {	/* ignore because we are in this section */    }    else if (dsc_is_section(line)) {	dsc->enddefaults = DSC_START(dsc);	dsc->scan_section = scan_pre_prolog;	return CDSC_PROPAGATE;    }    else if (IS_DSC(line, "%%EndDefaults")) {	dsc->id = CDSC_ENDDEFAULTS;	dsc->enddefaults = DSC_END(dsc);	dsc->scan_section = scan_pre_prolog;	return CDSC_OK;    }    else if (IS_DSC(line, "%%PageMedia:")) {	dsc->id = CDSC_PAGEMEDIA;	dsc_parse_media(dsc, &dsc->page_media);    }    else if (IS_DSC(line, "%%PageOrientation:")) {	dsc->id = CDSC_PAGEORIENTATION;	/* This can override %%Orientation:  */	if (dsc_parse_orientation(dsc, &(dsc->page_orientation), 18))	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%PageBoundingBox:")) {	dsc->id = CDSC_PAGEBOUNDINGBOX;	if (dsc_parse_bounding_box(dsc, &(dsc->page_bbox), 18))	    return CDSC_ERROR;    }    else if (IS_DSC(line, "%%ViewingOrientation:")) {	dsc->id = CDSC_VIEWINGORIENTATION;	if (dsc_parse_viewing_orientation(dsc, &dsc->viewing_orientation))	    return CDSC_ERROR;    }    else {	dsc->id = CDSC_UNKNOWNDSC;	/* All other DSC comments are unknown, but not an error */	dsc_unknown(dsc);    }    dsc->enddefaults = DSC_END(dsc);    return CDSC_OK;}/* CDSC_RESPONSE_OK and CDSC_RESPONSE_CANCEL mean ignore the  * mismatch (default) */dsc_private intdsc_check_match_prompt(CDSC *dsc, const char *str, int count){    if (count != 0) {	char buf[MAXSTR+MAXSTR] = "";	if (dsc->line_length < (unsigned int)(sizeof(buf)/2-1))  {	    strncpy(buf, dsc->line, dsc->line_length);	    buf[dsc->line_length] = '\0';	}	sprintf(buf+strlen(buf), "\n%%%%Begin%.40s: / %%%%End%.40s\n", str, str);	return dsc_error(dsc, CDSC_MESSAGE_BEGIN_END, buf, strlen(buf));    }    return CDSC_RESPONSE_CANCEL;}dsc_private intdsc_check_match_type(C

⌨️ 快捷键说明

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