[mac-gs] API help needed

Darryl Snover dsnover@fast.net
Wed, 2 Jul 2003 16:53:57 -0400


Hi All

I'm trying to write a _very_ simple interface into the GhostscriptLib 
PPC on Mac OS 8.6 thru 9.2, with the only purpose to take a ps file 
and convert to PDF.  I am not having too much luck, but I'm hoping 
someone here can point me in the right direction.  I'm working with 
CodeWarrior 5 professional, and in a simple project, here is my code:

Whenever I try to use the 'code = gsapi_init_with_args()', I get an 
'illegal exception' error.  Any help anyone might me able to lend 
would be very much appreciated.  For what its worth, I do get the 
proper product and revision, so at least I know the shared library is 
in the correct place....

Best Regards,

Darryl Snover

  Here is my code (based on the api example):


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "iapi.h"
#include "errors.h"

/*
typedef struct gsapi_revisions {
	const char *product;
	const char *copyright;
	long revision;
	long revisiondate;
};
*/
extern int gsapi_revision (gsapi_revision_t *pr, int len);
extern int gsapi_new_instance (gs_main_instance **pinstance, void 
*caller_handle);
extern int gsapi_init_with_args (gs_main_instance *instance, int 
argc, char **argv);
extern void gsapi_delete_instance (gs_main_instance *instance);
extern int gsapi_exit (gs_main_instance *instance);


gs_main_instance * minst;
int main(void)
{
	int i, code, gsargc;
	char * gsargv[10];
	gsapi_revision_t r;
	i = gsapi_revision(&r, sizeof(r));

	printf ("%s %i\n\n",r.product, r.revision);
	gsargv[0] = "ps2pdf";       /* actual value doesn't matter */
     gsargv[1] = "-dNOPAUSE";
     gsargv[2] = "-dBATCH";
     gsargv[3] = "-dSAFER";
     gsargv[4] = "-sDEVICE=pdfwrite";
     gsargv[5] = "-sOutputFile=out.pdf";
     gsargv[6] = "-c";
     gsargv[7] = ".setpdfwrite";
     gsargv[8] = "-f";
     gsargv[9] = "input.ps";
     gsargc=10;

     code = gsapi_new_instance(&minst, NULL);
     if (code < 0)
         return 1;
     code = gsapi_init_with_args(minst, gsargc, gsargv);
     gsapi_exit(minst);

     gsapi_delete_instance(minst);

     if ((code == 0) )
         return 0;
     return 1;
}