Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #3548 > unrolled thread
| Started by | news@zzo38computer.org.invalid |
|---|---|
| First post | 2020-06-08 12:03 -0700 |
| Last post | 2020-06-09 11:42 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.postscript
C macros for reading PostScript binary object format news@zzo38computer.org.invalid - 2020-06-08 12:03 -0700
Re: C macros for reading PostScript binary object format luser droog <luser.droog@gmail.com> - 2020-06-09 11:42 -0700
| From | news@zzo38computer.org.invalid |
|---|---|
| Date | 2020-06-08 12:03 -0700 |
| Subject | C macros for reading PostScript binary object format |
| Message-ID | <1591642301.bystand@zzo38computer.org> |
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?)
[toc] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2020-06-09 11:42 -0700 |
| Message-ID | <7b9561ce-1c65-48f7-a90b-5b0e3cebcc22o@googlegroups.com> |
| In reply to | #3548 |
On Monday, June 8, 2020 at 2:03:16 PM UTC-5, ne...@zzo38computer.org.invalid wrote:
> 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.
>
I rewrote these macros as K&R style functions. Modest increase in size but
I find it easier to read this way. I think I got all the types in that
look like they're not int.
#include <stdint.h>
enum { TY_NULL, TY_INT, TY_REAL, TY_NAME, TY_BOOL, TY_STRING, TY_ARRAY = 9, TY_MARK };
float obj_float(object,x)unsigned char *object;{
int t = obj_type(object,x);
return t==TY_INT ? (float)x
: t==TY_REAL ? obj_ufloat(object,x)
: 0;
}
obj_index(object,x,y)unsigned char *object;{
return obj_rawvalue(object,x) + y*8;
}
obj_int(object,x)unsigned char *object;{
int t = obj_type(x);
return t==TY_INT ||
t==TY_BOOL ? obj_rawvalue(object,x)
: t==TY_REAL ? (int)obj_ufloat(x)
: 0;
}
int_64_t obj_int64(object,x)unsigned char *object;{
int t = obj_type(x);
return t==TY_INT ||
t==TY_BOOL ? obj_rawvalue(object,x)
: t==TY_REAL ? (int64_t)obj_ufloat(x)
: 0;
}
obj_isnum(object,x)unsigned char *object;{
return obj_type(x)==TY_INT || obj_type(x)==TY_REAL;
}
obj_length(object,x)unsigned char *object;{
return object[x+2]<<8 | object[x+3];
}
obj_ptr(object,x)unsigned char *object;{
return object + obj_rawvalue(x);
}
obj_rawvalue(object,x)unsigned char *object;{
return object[x+4]<<24 | object[x+5]<<16 | object[x+6]<<8 | object[x+7];
}
obj_tag(object)unsigned char *object;{
return object[1];
}
obj_type(object,x)unsigned char *object;{
return object[x]&127;
}
float obj_ufloat(object,x)unsigned char *object;{
union{ int i; float f; } f;
f.i = obj_rawvalue(object,x);
return f.f;
}
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web