Code Review requested: Postscript Interpreter

L

luser- -droog

A productive 3-day weekend! Counting everything in systemdict,
it's got 181 operators.

http://code.google.com/p/xpost/downloads/list

The one I'd been dreading turned out pretty well, I think.
After I wrote it, I just kind of stared at it for a while.
But when I dared to try it, it worked!

/*
(15, 2)
(7, 2) 1
(3, 2) 1 1
(1, 2) 1 1 1
1 1 1 1
*/

int conv_rad (int num, int rad, char *s, int n) {
char *vec =
"0123456789"
"ABCDEFGHIJKLM"
"NOPQRSTUVWXYZ";
int off;
if (n == 0) return 0;
if (num < rad) {
*s = vec[num];
return 1;
}
off = conv_rad(num/rad, rad, s, n);
if ((off == n) || (off == -1)) return -1;
s[off] = vec[num%rad];
return off+1;
}

/* num radix string cvrs substring
convert to string with radix
*/
void Ocvrs (Object *o) {
int rad, n;
char *s;

if (type(o[0]) == realtype) o[0] = makeinteger(o[0].r);
if (!typearg3(integer,integer,string)) error(typecheck, OP_cvrs);
rad = o[1].i;
if ( (rad < 2) || (rad > 36)) error(rangecheck, OP_cvrs);
s = (char *)VM(o[2].s);
n = o[2].n;
n = conv_rad(o[0].i, rad, s, n);
if (n == -1) error(rangecheck, OP_cvrs);
o[0] = substring(o[2], 0, n);
}
 
K

Keith Thompson

Authoritative Answer: "It depends." <grin>

Even more authoritative answer: Do whatever the library's documentation
recommends, so your code will be compatible with other code that uses
the same library.

In this particular case, <http://cairographics.org/FAQ/> says:

You will need to instruct the compiler where to find the cairo.h
file, (generally something like -I /usr/include/cairo), and tell
the linker where to find the cairo library and to link with it,
(often something like -L /usr/lib -lcairo).

which implies that you should use "-I/usr/include/cairo" and
"#include <cairo.h>".

[...]
 

Members online

No members online now.

Forum statistics

Threads
474,083
Messages
2,570,590
Members
47,211
Latest member
JaydenBail

Latest Threads

Top