Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!tut.cis.ohio-state.edu!ucbvax!ulysses!cjc From: cjc@ulysses.homer.nj.att.com (Chris Calabrese[mav]) Newsgroups: comp.windows.news Subject: Re: stringtype => dicttype Summary: passing postscript directly to the server from C Message-ID: <11413@ulysses.homer.nj.att.com> Date: 6 Apr 89 19:07:02 GMT References: <3230.8904051131@prsun5f.prl.philips.co.uk> Organization: AT&T Bell Laboratories, Murray Hill Lines: 102 In article <3230.8904051131@prsun5f.prl.philips.co.uk>, davidw@prlhp1.UUCP (David Walker) writes: > > In a cps application it does not see, possible to pass a dicttype > from the c code to postscript. You can only pass strings or ints and > there is no postscript command to convert a string into a dict name. > Does anyone know how to do this, if it is possible. Well, I already answered the original posting to this thread by email, but I guess it's a problem of general interest. While it is true that you can not pass types other than string and int, it is possible to pass raw postscript to be executed on the server. The first is to use pprintf(), which is how CPS sends information to the server (the cps routines become preprocessor macros which call pprintf()). My favorite method, however, is to make use of some postscript operators to change a string into an executable array and execute it. I do something like this: in foo.cps: cps raw_postscript(string mystring) mystring cvx exec in foo.c: int array[SIZE]; int maxarray; int i; char buffer[BufferSize]; raw_postscript("/foo [ "); for(i=0; i - { READ_TAG tagprint typedprint uniquecid dup typedprint [exch cidinterest] forkeventmgr waitprocess pop } def cdef read_file(string data, int id) => READ_TAG (data, id) cdef end_cid(int id) id {exit} sendcidevent cdef cid_exec(string data, int id) id {data cvx exec} sendcidevent in foo.c: ... else if (read_file(data, &intdata)) { if(debug) fprintf(stderr, "read request %s %d\n", data, intdata); do_read(data, intdata); end_cid(intdata); } ... /* * Read a file and send it to the postscript server * as if it had been done with '{ run } stopped' */ do_read(name, id) char *name; int id; { FILE *fileptr; char data[STRING_SIZE]; /* start the block to execute */ cid_exec("{", id); /* open the file */ if((fileptr = fopen(name, "r")) == NULL) { cid_exec("} stopped pop\n", id); return; } /* go through the file and dump it */ while(fgets(data, STRING_SIZE, fileptr) != NULL) { cid_exec(data, id); } /* now we're done! */ cid_exec(" } stopped pop\n", id); } -- Name: Christopher J. Calabrese Brain loaned to: AT&T Bell Laboratories, Murray Hill, NJ att!ulysses!cjc cjc@ulysses.att.com Obligatory Quote: ``Now, where DID I put that bagel?''