Path: csiph.com!aioe.org!.POSTED.iSqskUzK2KPWtZfZ6bkvfw.user.gioia.aioe.org!not-for-mail From: news@zzo38computer.org.invalid Newsgroups: comp.lang.postscript Subject: C macros for reading PostScript binary object format Date: Mon, 08 Jun 2020 12:03:12 -0700 Organization: Aioe.org NNTP Server Lines: 35 Message-ID: <1591642301.bystand@zzo38computer.org> NNTP-Posting-Host: iSqskUzK2KPWtZfZ6bkvfw.user.gioia.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: bystand/1.1.2pre1 X-Notice: Filtered by postfilter v. 0.9.2 Xref: csiph.com comp.lang.postscript:3548 As part of TeXnicard, I wrote a set of C macros to read the PostScript binary object format. I am also including a copy of them here. TeXnicard is in the public domain, so you can use this for whatever you want to do. #define TY_NULL 0 #define TY_INT 1 #define TY_REAL 2 #define TY_NAME 3 #define TY_BOOL 4 #define TY_STRING 5 #define TY_ARRAY 9 #define TY_MARK 10 #define obj_float(x) ({ int x__=(x); int t_=obj_type(x__); t_==TY_INT?(float)obj_rawvalue(x__):t_==TY_REAL?obj_ufloat(x__):0; }) #define obj_index(x,y) (obj_rawvalue(x)+(y)*8) #define obj_int(x) ({ int x__=(x); int t_=obj_type(x__); t_==TY_INT||t_==TY_BOOL?obj_rawvalue(x__):t_==TY_REAL?(int)obj_ufloat(x__):0; }) #define obj_int64(x) ({ int x__=(x); int t_=obj_type(x__); t_==TY_INT||t_==TY_BOOL?obj_rawvalue(x__):t_==TY_REAL?(sqlite3_int64)obj_ufloat(x__):0; }) #define obj_isnum(x) ({ int x__=(x); obj_type(x__)==TY_INT || obj_type(x__)==TY_REAL; }) #define obj_length(x) ({ int x__=(x); (object[x__+2]<<8)|object[x__+3]; }) #define obj_ptr(x) (object+obj_rawvalue(x)) #define obj_rawvalue(x) ({ int y__=(x); (int)((object[y__+4]<<24)|(object[y__+5]<<16)|(object[y__+6]<<8)|object[y__+7]); }) #define obj_tag() (object[1]) #define obj_type(x) (object[x]&127) #define obj_ufloat(x) ({ union { int i; float f; } f__; f__.i=obj_rawvalue(x); f__.f; }) // see psi/ibnum.h in Ghostscript for an explanation of this bug You can read the header of the PostScript binary object data to find the total size of the data; the pointer "object" is of type "unsigned char*" and points to just after the header. Note that the above uses "sqlite3_int64" as the 64-bit integer type. If your program does not use SQLite, then you must change this. -- This signature intentionally left blank. (But if it has these words, then actually it isn't blank, isn't it?)