summaryrefslogtreecommitdiff
path: root/gpdl/psitop.c
blob: 12c4ace53ec75bba1b2b66c119f5c8f5bebb6edc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/* Copyright (C) 2001-2023 Artifex Software, Inc.
   All Rights Reserved.

   This software is provided AS-IS with no warranty, either express or
   implied.

   This software is distributed under license and may not be copied,
   modified or distributed except as expressly authorized under the terms
   of the license contained in the file LICENSE in this distribution.

   Refer to licensing information at http://www.artifex.com or contact
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
   CA 94129, USA, for further information.
*/

/* psitop.c */
/* Top-level API implementation of PS Language Interface */

#include "stdio_.h"
#include "ghost.h"
#include "imain.h"
#include "imainarg.h"
#include "iapi.h"
#include "psapi.h"
#include "string_.h"
#include "gdebug.h"
#include "gp.h"
#include "gserrors.h"
#include "gstypes.h"
#include "gsmemory.h"
#include "gsmalloc.h"
#include "gsstate.h"		/* must precede gsdevice.h */
#include "gxdevice.h"		/* must precede gsdevice.h */
#include "gsdevice.h"
#include "icstate.h"		/* for i_ctx_t */
#include "iminst.h"
#include "gsstruct.h"		/* for gxalloc.h */
#include "gspaint.h"
#include "gxalloc.h"
#include "gxstate.h"
#include "plparse.h"
#include "pltop.h"
#include "plmain.h"
#include "gzstate.h"
#include "gsicc_manage.h"

/* Forward decls */

/************************************************************/
/******** Language wrapper implementation (see pltop.h) *****/
/************************************************************/

/* Import operator procedures */
extern int zflush(i_ctx_t *);

/*
 * PS interpreter instance: derived from pl_interp_implementation_t
 */
typedef struct ps_interp_instance_s {
    gs_memory_t  *memory;
    uint          bytes_fed;
    gs_lib_ctx_t *psapi_instance;
} ps_interp_instance_t;

static int
check_token(int token_type, const char *s, const char *e, int *score)
{
    /* Empty tokens are always OK */
    if (s == e)
        return 0;

    switch (token_type) {
        case 'a':
            /* Angle bracket - mainly to catch << */
            break;
        case 'n':
            /* Name */
            /* FIXME: Check it's a valid name */
            break;
        case 'd':
            /* Dictionary */
            break;
        case 'i':
            /* int - ok by construction. */
            return 0;
        case 'f':
            /* float - ok by construction. */
            return 0;
    }

#define TOKEN_CHECK(n) else if (e-s == strlen(n) && memcmp(s, n, e-s) == 0) { score[0] += e-s; score[1]++; }

    if (0) { /* Initial block of checking chain */ }
    TOKEN_CHECK("dup")
    TOKEN_CHECK("exch")
    TOKEN_CHECK("grestore")
    TOKEN_CHECK("gsave")
    TOKEN_CHECK("idiv")
    TOKEN_CHECK("lineto")
    TOKEN_CHECK("mod")
    TOKEN_CHECK("mul")
    TOKEN_CHECK("moveto")
    TOKEN_CHECK("setflat")
    TOKEN_CHECK("setlinecap")
    TOKEN_CHECK("setlinejoin")
    TOKEN_CHECK("showpage")
    TOKEN_CHECK("stroke")
    TOKEN_CHECK("translate")
    TOKEN_CHECK("systemdict")

    if (score[0] > 1024 && score[1] >= 3)
        return 1;
    if (score[0] < -1024)
        return 1;

    return 0;
}

static int
score_comment(const char *s, const char *e, int *score)
{
#define COMMENT_CHECK(n) else if (e-s >= strlen(n) && memcmp(s, n, strlen(n)) == 0) { score[0] += 100; score[1]++; }

    if (0) { /* Initial block of checking chain */ }
    COMMENT_CHECK("!PS")
    COMMENT_CHECK("%Title:")
    COMMENT_CHECK("%Version:")
    COMMENT_CHECK("%Creator:")
    COMMENT_CHECK("%CreationDate:")
    COMMENT_CHECK("%Document")
    COMMENT_CHECK("%BoundingBox:")
    COMMENT_CHECK("%HiResBoundingBox:")
    COMMENT_CHECK("%Pages:")
    COMMENT_CHECK("%+ procset")
    COMMENT_CHECK("%End")
    COMMENT_CHECK("%Begin")
    COMMENT_CHECK("%Copyright")
    else {
        score[0]++; score[1]++;
    }

    if (score[0] > 1024 && score[1] >= 3)
        return 1;

    return 0;
}

static int
ps_detect_language(const char *s, int len)
{
    /* For postscript, we look for %! */
    if (len >= 2) {
        if (s[0] != '%' || s[1] != '!') {
            /* Not what we were looking for */
        } else if (len >= 12 && memcmp(s+2, "Postscript", 10) == 0) {
            return 100;
        } else if (len >= 4 && memcmp(s+2, "PS", 2) == 0) {
            return 100;
        } else if (len >= 3 && s[2] == '/') {
            /* Looks like a shell script. Don't want that. */
            return 0;
        } else {
            /* If it begins %!, then it's PROBABLY postscript */
            return 80;
        }
    }
    /* For PDF, we allow for leading crap, then a postscript version marker */
    {
        const char *t = s;
        int left = len-22;
        /* Search within just the first 4K, plus a bit for the marker length. */
        if (left > 4096+22)
            left = 4096+22;
        while (left > 22) {
            if (memcmp(t, "%PDF-", 5) == 0 &&
                t[5] >= '1' && t[5] <= '9' &&
                t[6] == '.' &&
                t[7] >= '0' && t[7] <= '9') {
                return 100;
            }
            if (memcmp(t, "%!PS-Adobe-", 11) == 0 &&
                t[11] >= '0' && t[11] <= '9' &&
                t[12] == '.' &&
                t[13] >= '0' && t[13] <= '9' &&
                memcmp(t+14, " PDF-", 5) == 0 &&
                t[19] >= '0' && t[19] <= '9' &&
                t[20] == '.' &&
                t[21] >= '0' && t[21] <= '9') {
                return 100;
            }
            t++;
            left--;
        }
    }

    /* Now we do some seriously hairy stuff */
    {
        const char *t = s;
        const char *token = t;
        int left = len;
        int token_type = 0;
        int score[2] = { 0, 0 };

        while (left--) {
            if (*t == '%') {
                if (check_token(token_type, token, t, score))
                    break;
                /* Skip to end of line */
                left--;
                token = ++t;
                while (left && *t != '\r' && *t != '\n') {
                    left--; t++;
                }
                if (score_comment(token, t, score))
                    break;
                /* Skip any combination of newlines */
                while (left && (*t == '\r' || *t == '\n')) {
                    left--; t++;
                }
                token_type = 0;
                continue;
            } else if (*t == 27) {
                /* Give up if we meet an ESC. It could be a UEL. */
                break;
            } else if (*t <= 32 || *(unsigned char *)t > 127) {
                if (check_token(token_type, token, t, score))
                    break;
                if (*t != 9 && *t != 10 && *t != 12 && *t != 13 && *t != 32)
                    score[0]--;
                token = t+1;
                token_type = 0;
            } else if (*t == '/') {
                if (check_token(token_type, token, t, score))
                    break;
                token = t+1;
                token_type = 'n';
            } else if (*t == '[' || *t == ']' || *t == '{' || *t == '}') {
                if (check_token(token_type, token, t, score))
                    break;
                token = t+1;
                token_type = 0;
            } else if (*t == '<') {
                if (token_type == 'a') {
                    /* << */
                    token = t+1;
                    token_type = 'd';
                } else if (token_type == 'd') {
                    /* <<< ???!? */
                    score[0] -= 10;
                } else {
                    if (check_token(token_type, token, t, score))
                        break;
                    token = t+1;
                    token_type = 'a';
                }
            } else if (*t == '>') {
                if (check_token(token_type, token, t, score))
                    break;
                token = t+1;
                token_type = 0;
            } else if (*t >= '0' && *t <= '9') {
                if (token_type == 'i') {
                    /* Keep going */
                } else if (token_type == 'f') {
                    /* Keep going */
                } else {
                    if (check_token(token_type, token, t, score))
                        break;
                    token = t;
                    token_type = 'i';
                }
            } else if (*t == '.') {
                if (token_type == 'f') {
                    /* seems unlikely */
                    score[0]--;
                    break;
                } else if (token_type == 'i') {
                    token = t;
                    token_type = 'f';
                } else {
                    if (check_token(token_type, token, t, score))
                        break;
                    token = t;
                    token_type = 'f';
                }
            } else {
                /* Assume anything else goes into the token */
            }
            t++;
        }
        if (score[0] < 0 || score[1] < 3)
            return 0; /* Unlikely to be PS */
        else if (score[0] > 0)
            return 75; /* Could be PS */
    }

    return 0;
}

/* Get implementation's characteristics */
static const pl_interp_characteristics_t * /* always returns a descriptor */
ps_impl_characteristics(const pl_interp_implementation_t *impl)     /* implementation of interpreter to alloc */
{
    /* version and build date are not currently used */
  static const pl_interp_characteristics_t ps_characteristics = {
    "POSTSCRIPT",
    ps_detect_language,
  };

  return &ps_characteristics;
}

/* Do per-instance interpreter allocation/init. */
static int
ps_impl_allocate_interp_instance(pl_interp_implementation_t *impl, gs_memory_t *mem)
{
    ps_interp_instance_t *psi
        = (ps_interp_instance_t *)gs_alloc_bytes( mem,
                                                  sizeof(ps_interp_instance_t),
                                                  "ps_impl_allocate_interp_instance");

    int code;
#define GS_MAX_NUM_ARGS 10
    const char *gsargs[GS_MAX_NUM_ARGS] = {0};
    int nargs = 0;

    if (!psi)
        return gs_error_VMerror;

    gsargs[nargs++] = "gpdl";
    /* We start gs with the nullpage device, and replace the device with the
     * set_device call from the language independent code.
     */
    gsargs[nargs++] = "-sDEVICE=nullpage";
    /* As we're "printer targetted, use a jobserver */
    gsargs[nargs++] = "-dJOBSERVER";

    psi->memory = mem;
    psi->bytes_fed = 0;
    psi->psapi_instance = gs_lib_ctx_get_interp_instance(mem);
    code = psapi_new_instance(&psi->psapi_instance, NULL);
    if (code < 0) {
        gs_free_object(mem, psi, "ps_impl_allocate_interp_instance");
        return code;
    }

    /* The above call to psapi_new_instance will have set the ps interpreter
     * to expect 'local' encoding. When running under PL, this means we'll
     * end up decoding the input stuff to utf8, and then feed that into the
     * gs instance, where it will decode it again! Avoid this, by setting
     * gs to expect UTF8 input. */
    psapi_set_arg_encoding(psi->psapi_instance, PS_ARG_ENCODING_UTF8);

    impl->interp_client_data = psi;

    /* Tell gs not to ignore a UEL, but do an interpreter exit */
    psapi_act_on_uel(psi->psapi_instance);

    code = psapi_init_with_args01(psi->psapi_instance, nargs, (char **)gsargs);
    if (code < 0) {
        (void)psapi_exit(psi->psapi_instance);
        psapi_delete_instance(psi->psapi_instance);
        gs_free_object(mem, psi, "ps_impl_allocate_interp_instance");
    }
    return code;
}

/*
 * Get the allocator with which to allocate a device
 */
static gs_memory_t *
ps_impl_get_device_memory(pl_interp_implementation_t *impl)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;

    return psapi_get_device_memory(psi->psapi_instance);
}

static int
ps_impl_set_param(pl_interp_implementation_t *impl,
                  gs_param_list *plist)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;

    return psapi_set_param(psi->psapi_instance, plist);
}

static int
ps_impl_add_path(pl_interp_implementation_t *impl,
                 const char                 *path)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;

    return psapi_add_path(psi->psapi_instance, path);
}

static int
ps_impl_post_args_init(pl_interp_implementation_t *impl)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;
    const float *resolutions;
    const long *page_sizes;

    pl_main_get_forced_geometry(psi->memory, &resolutions, &page_sizes);
    psapi_force_geometry(psi->psapi_instance, resolutions, page_sizes);

    return psapi_init_with_args2(psi->psapi_instance);
}

/* Prepare interp instance for the next "job" */
static int
ps_impl_init_job(pl_interp_implementation_t *impl,
                 gx_device                  *device)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;
    int exit_code;
    int code;

    /* Any error after here *must* reset the device to null */
    code = psapi_set_device(psi->psapi_instance, device);

    if (code >= 0)
        code = psapi_run_string(psi->psapi_instance, "erasepage", 0, &exit_code);

    if (code < 0) {
        int code1 = psapi_set_device(psi->psapi_instance, NULL);
        (void)code1;
    }

    /* Make sure the PageSpotColors is set to -1 for PS */
    {
        gs_c_param_list* params;
        int page_spot_colors = -1;
        int code2;

        params = gs_c_param_list_alloc(psi->memory, "ps_impl_init_job");
        if (params == NULL)
            return_error(gs_error_VMerror);

        gs_c_param_list_write(params, psi->memory);
        gs_param_list_set_persistent_keys((gs_param_list*)params, false);

        code2 = param_write_int((gs_param_list*)params, "PageSpotColors", &(page_spot_colors));
        if (code2 < 0) {
            gs_c_param_list_free(psi->memory, params, "ps_impl_init_job");
            return code2;
        }

        gs_c_param_list_read(params);

        code2 = psapi_set_device_param(psi->psapi_instance, (gs_param_list*)params);
        gs_c_param_list_free(psi->memory, params, "ps_impl_init_job");
        if (code2 < 0)
            return code2;
    }
    return code;
}

static int
ps_impl_run_prefix_commands(pl_interp_implementation_t *impl,
                            const char                 *prefix)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;
    int exit_code;
    int code = 0;

    if (prefix == NULL)
        return 0;

    /* Any error after here *must* reset the device to null */
    code = psapi_run_string(psi->psapi_instance, prefix, 0, &exit_code);

    if (code < 0) {
        int code1 = psapi_set_device(psi->psapi_instance, NULL);
        (void)code1;
    }

    return code;
}

static int
ps_impl_process_file(pl_interp_implementation_t *impl, const char *filename)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;
    int exit_code;

    return psapi_run_file(psi->psapi_instance, filename, 0, &exit_code);
}

/* Do any setup for parser per-cursor */
static int                      /* ret 0 or +ve if ok, else -ve error code */
ps_impl_process_begin(pl_interp_implementation_t * impl)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;
    int exit_code;

    psi->bytes_fed = 0;
    return psapi_run_string_begin(psi->psapi_instance, 0, &exit_code);
}

/* TODO: in some fashion have gs pass back how far into the input buffer it
 * had read, so we don't need to explicitly search the buffer for the UEL
 */
static int
ps_impl_process(pl_interp_implementation_t * impl, stream_cursor_read * pr)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;
    unsigned int len;
    int code, exit_code = 0;

    if (psi->bytes_fed == 0)
    {
        /* Skip over whitespace/comments looking for a PDF marker. */
        while (pr->ptr < pr->limit)
        {
            int i;

            /* Skip over whitespace (as defined in PLRM) */
            if (pr->ptr[1] == 0 ||
                pr->ptr[1] == 9 ||
                pr->ptr[1] == 10 ||
                pr->ptr[1] == 12 ||
                pr->ptr[1] == 13 ||
                pr->ptr[1] == 32) {
                pr->ptr++;
                continue;
            }

            /* If we're not starting a comment, exit. */
            if (pr->ptr[1] != '%')
                break;

            /* If we're starting with a PDF header, swap to file mode. */
            if (pr->limit - pr->ptr >= 8 &&
                strncmp((const char *)&pr->ptr[2], "PDF-", 4) == 0 &&
                (pr->ptr[6] >= '1' && pr->ptr[6] <= '9') &&
                pr->ptr[7] == '.' &&
                (pr->ptr[8] >= '0' && pr->ptr[8] <= '9'))
                return_error(gs_error_NeedFile);

            /* Check for a historical PDF header. */
            if (pr->limit - pr->ptr >= 22 &&
                strncmp((const char *)&pr->ptr[2], "!PS-Adobe-", 10) == 0 &&
                (pr->ptr[12] >= '0' && pr->ptr[12] <= '9') &&
                pr->ptr[13] == '.' &&
                (pr->ptr[14] >= '0' && pr->ptr[14] <= '9') &&
                strncmp((const char *)&pr->ptr[15], " PDF-", 5) == 0 &&
                (pr->ptr[20] >= '0' && pr->ptr[20] <= '9') &&
                pr->ptr[21] == '.' &&
                (pr->ptr[22] >= '0' && pr->ptr[22] <= '9'))
                return_error(gs_error_NeedFile);

            /* Do we have a complete comment that we can skip? */
            for (i = 1; pr->ptr + i < pr->limit; i++)
                if (pr->ptr[i+1] == 10 || pr->ptr[i+1] == 13) {
                    pr->ptr += i;
                    i = 0; /* Loop again in case there are more comments. */
                    break;
                }
            /* If we fall out of the loop naturally, then we hit the end
             * of the buffer without terminating our comment. We need to
             * abort the loop and return. */
            if (i != 0)
                return_error(gs_error_NeedInput);
        }
    }

    len = pr->limit - pr->ptr;
    code = psapi_run_string_continue(psi->psapi_instance, (const char *)pr->ptr + 1, len, 0, &exit_code);
    if (exit_code == gs_error_InterpreterExit) {
        int64_t offset;

        offset = psapi_get_uel_offset(psi->psapi_instance) - psi->bytes_fed;
        pr->ptr += offset;
        psi->bytes_fed += offset + 1;

#ifdef SEND_CTRLD_AFTER_UEL
        {
            const char eot[1] = {4};
            code = psapi_run_string_continue(psi->psapi_instance, eot, 1, 0, &exit_code);
            (void)code; /* Ignoring code here */
        }
#endif
        return gs_error_InterpreterExit;
    }
    else {
        pr->ptr = pr->limit;
        psi->bytes_fed += len;
    }
    return code;
}

static int                      /* ret 0 or +ve if ok, else -ve error code */
ps_impl_process_end(pl_interp_implementation_t * impl)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;
    int exit_code, code;

    code = psapi_run_string_end(psi->psapi_instance, 0, &exit_code);

    if (exit_code == gs_error_InterpreterExit || code == gs_error_NeedInput)
        code = 0;

    return code;
}

/* Not implemented */
static int
ps_impl_flush_to_eoj(pl_interp_implementation_t *impl, stream_cursor_read *cursor)
{
    const byte *p = cursor->ptr;
    const byte *rlimit = cursor->limit;

    /* Skip to, but leave UEL in buffer for PJL to find later */
    for (; p < rlimit; ++p)
        if (p[1] == '\033') {
            uint avail = rlimit - p;

            if (memcmp(p + 1, "\033%-12345X", min(avail, 9)))
                continue;
            if (avail < 9)
                break;
            cursor->ptr = p;
            return 1;           /* found eoj */
        }
    cursor->ptr = p;
    return 0;                   /* need more */
}

/* Parser action for end-of-file */
static int
ps_impl_process_eof(pl_interp_implementation_t *impl)
{
    return 0;
}

/* Report any errors after running a job */
static int
ps_impl_report_errors(pl_interp_implementation_t *impl,      /* interp instance to wrap up job in */
                      int                  code,           /* prev termination status */
                      long                 file_position,  /* file position of error, -1 if unknown */
                      bool                 force_to_cout    /* force errors to cout */
)
{
    return 0;
}

/* Wrap up interp instance after a "job" */
static int
ps_impl_dnit_job(pl_interp_implementation_t *impl)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;

    return psapi_set_device(psi->psapi_instance, NULL);
}

/* Deallocate a interpreter instance */
static int
ps_impl_deallocate_interp_instance(pl_interp_implementation_t *impl)
{
    ps_interp_instance_t *psi = (ps_interp_instance_t *)impl->interp_client_data;
    int                   code;

    if (psi == NULL)
        return 0;
    code = psapi_exit(psi->psapi_instance);
    psapi_delete_instance(psi->psapi_instance);
    gs_free_object(psi->memory, psi, "ps_impl_allocate_interp_instance");
    impl->interp_client_data = NULL;
    return code;
}

/* Parser implementation descriptor */
const pl_interp_implementation_t ps_implementation = {
  ps_impl_characteristics,
  ps_impl_allocate_interp_instance,
  ps_impl_get_device_memory,
  ps_impl_set_param,
  ps_impl_add_path,
  ps_impl_post_args_init,
  ps_impl_init_job,
  ps_impl_run_prefix_commands,
  ps_impl_process_file,
  ps_impl_process_begin,
  ps_impl_process,
  ps_impl_process_end,
  ps_impl_flush_to_eoj,
  ps_impl_process_eof,
  ps_impl_report_errors,
  ps_impl_dnit_job,
  ps_impl_deallocate_interp_instance,
  NULL, /* ps_impl_reset */
  NULL  /* interp_client_data */
};