/* Copyright (C) 2001 Ghostgum Software Pty Ltd. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307. */ /* $Id: dxmainc.c,v 1.4.2.2.2.1 2003/01/17 00:49:00 giles Exp $ */ /* dxmainc.c */ /* * Ghostscript frontend which provides a console to the Ghostscript * shared library. Load time linking to libgs.so * This does not support the display device. Use dxmain.c/gsx for that, * or modify this program to use bare Xlib calls. * Compile using * gcc -o gsc dxmainc.c -lgs * * The ghostscript library needs to be compiled with * gcc -fPIC -g -c -Wall file.c * gcc -shared -Wl,-soname,libgs.so.7 -o libgs.so.7.00 file.o -lc */ #include #include #include #include #include #include #define __PROTOTYPES__ #include "errors.h" #include "iapi.h" const char start_string[] = "systemdict /start get exec\n"; static int gsdll_stdin(void *instance, char *buf, int len); static int gsdll_stdout(void *instance, const char *str, int len); static int gsdll_stdout(void *instance, const char *str, int len); /*********************************************************************/ /* stdio functions */ /* callback for reading stdin */ /* Use async input */ static int gsdll_stdin(void *instance, char *buf, int len) { return read(fileno(stdin), buf, len); } static int gsdll_stdout(void *instance, const char *str, int len) { fwrite(str, 1, len, stdout); fflush(stdout); return len; } static int gsdll_stderr(void *instance, const char *str, int len) { fwrite(str, 1, len, stderr); fflush(stderr); return len; } /*********************************************************************/ int main(int argc, char *argv[]) { int exit_status; int code = 1; gs_main_instance *instance; int exit_code; /* run Ghostscript */ if ((code = gsapi_new_instance(&instance, NULL)) == 0) { gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr); code = gsapi_init_with_args(instance, argc, argv); if (code == 0) code = gsapi_run_string(instance, start_string, 0, &exit_code); gsapi_exit(instance); if (code == e_Quit) code = 0; /* user executed 'quit' */ gsapi_delete_instance(instance); } exit_status = 0; switch (code) { case 0: case e_Info: case e_Quit: break; case e_Fatal: exit_status = 1; break; default: exit_status = 255; } return exit_status; }