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;
}
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)