"Fossies" - the Fresh Open Source Software Archive

Member "ghostpdl-9.27/psi/dxmainc.c" (4 Apr 2019, 3079 Bytes) of package /linux/misc/ghostpdl-9.27.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "dxmainc.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes reports: 9.27rc1_vs_9.27 or 9.26_vs_9.27.

    1 /* Copyright (C) 2001-2019 Artifex Software, Inc.
    2    All Rights Reserved.
    3 
    4    This software is provided AS-IS with no warranty, either express or
    5    implied.
    6 
    7    This software is distributed under license and may not be copied,
    8    modified or distributed except as expressly authorized under the terms
    9    of the license contained in the file LICENSE in this distribution.
   10 
   11    Refer to licensing information at http://www.artifex.com or contact
   12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
   13    CA 94945, U.S.A., +1(415)492-9861, for further information.
   14 */
   15 
   16 
   17 /* dxmainc.c */
   18 /*
   19  * Ghostscript frontend which provides a console to the Ghostscript
   20  * shared library.  Load time linking to libgs.so
   21  * This does not support the display device.  Use dxmain.c/gsx for that,
   22  * or modify this program to use bare Xlib calls.
   23  * Compile using
   24  *    gcc -o gsc dxmainc.c -lgs
   25  *
   26  * The ghostscript library needs to be compiled with
   27  *  gcc -fPIC -g -c -Wall file.c
   28  *  gcc -shared -Wl,-soname,libgs.so.7 -o libgs.so.7.00 file.o -lc
   29  */
   30 
   31 #include <stdio.h>
   32 #include <stdlib.h>
   33 #include <string.h>
   34 #include <unistd.h>
   35 #include <fcntl.h>
   36 #include <errno.h>
   37 #define __PROTOTYPES__
   38 #include "ierrors.h"
   39 #include "iapi.h"
   40 
   41 const char start_string[] = "systemdict /start get exec\n";
   42 
   43 static int gsdll_stdin(void *instance, char *buf, int len);
   44 static int gsdll_stdout(void *instance, const char *str, int len);
   45 static int gsdll_stdout(void *instance, const char *str, int len);
   46 
   47 /*********************************************************************/
   48 /* stdio functions */
   49 
   50 /* callback for reading stdin */
   51 /* Use async input */
   52 static int
   53 gsdll_stdin(void *instance, char *buf, int len)
   54 {
   55     return read(fileno(stdin), buf, len);
   56 }
   57 
   58 static int
   59 gsdll_stdout(void *instance, const char *str, int len)
   60 {
   61     fwrite(str, 1, len, stdout);
   62     fflush(stdout);
   63     return len;
   64 }
   65 
   66 static int
   67 gsdll_stderr(void *instance, const char *str, int len)
   68 {
   69     fwrite(str, 1, len, stderr);
   70     fflush(stderr);
   71     return len;
   72 }
   73 
   74 /*********************************************************************/
   75 
   76 int main(int argc, char *argv[])
   77 {
   78     int exit_status;
   79     int code = 1, code1;
   80     void *instance = NULL;
   81     int exit_code;
   82 
   83     /* run Ghostscript */
   84     if ((code = gsapi_new_instance(&instance, NULL)) == 0) {
   85         gsapi_set_stdio(instance, gsdll_stdin, gsdll_stdout, gsdll_stderr);
   86         code = gsapi_init_with_args(instance, argc, argv);
   87 
   88         if (code == 0)
   89             code = gsapi_run_string(instance, start_string, 0, &exit_code);
   90         code1 = gsapi_exit(instance);
   91         if (code == 0 || code == gs_error_Quit)
   92             code = code1;
   93         if (code == gs_error_Quit)
   94             code = 0;   /* user executed 'quit' */
   95 
   96         gsapi_delete_instance(instance);
   97     }
   98 
   99     exit_status = 0;
  100     switch (code) {
  101         case 0:
  102         case gs_error_Info:
  103         case gs_error_Quit:
  104             break;
  105         case gs_error_Fatal:
  106             exit_status = 1;
  107             break;
  108         default:
  109             exit_status = 255;
  110     }
  111 
  112     return exit_status;
  113 }