ppd_emit_to_file(3)

πŸ“¦ version 0.10, in debian bookworm, ubuntu jammy

πŸ’– ppd_emit_to_file β€” the ppd_emit_to_file(3) page, but make it cute πŸ’–

okay bestie, so this one lives in the Library Functions Manual, and it's all about outputting device specific code. yes we're getting into printer brain territory, it's giving very niche, it's giving very powerful. let's go 🫢


✨ NAME ✨

ppd_emit_to_file, ppd_emit_to_fd β€” output device specific code, fr fr.


🌸 SYNOPSIS 🌸

#include <ppd/ppd.h>

gboolean ppd_emit( PpdFile * ppd,FILE *fp,PpdSectionOrder section );
gboolean ppd_emitfd( PpdFile * ppd, int fd,PpdSectionOrder section );

πŸ¦‹ DESCRIPTION πŸ¦‹

so the ppd_emit_* functions? they output the device specific code that matches the section you asked for β€” but only the code that hasn't already been emitted. the way it just... knows what's been done already. obsessed. πŸ’…

you get that PpdFile pointer by opening a PPD file through the ppd_load(3) family of functions. iykyk.

and the section can be literally any one of these:

  • PPD_ORDER_ANY β€” option code can be anywhere in the file. no rules, main character energy, she goes wherever. ✨
  • PPD_ORDER_DOCUMENT β€” option code must be in the DocumentSetup section.
  • PPD_ORDER_EXIT β€” option code must be sent prior to the document.
  • PPD_ORDER_JCL β€” option code must be sent as a JCL command.
  • PPD_ORDER_PAGE β€” option code must be in the PageSetup section.
  • PPD_ORDER_PROLOG β€” option code must be in the Prolog section.
also important bestie: the sections PPD_ORDER_DOCUMENT and PPD_ORDER_PAGE will also output code from the PPD_ORDER_ANY section. so ANY is basically everywhere at once. she contains multitudes. πŸ’€

and once a code section has been emitted, it gets marked as such β€” and it will not be emitted again unless it's re-marked. so like... remember that, or you'll be staring at your output wondering where the code went. not that i've done that. πŸ™ˆ


πŸŽ€ EXAMPLE πŸŽ€

okay here's the whole flow, look at it, it's a journey:

     /* Setup code to emitted */
        ppd_mark_defaults(ppd);
        ppd_mark_option(ppd,"Duplex","DuplexNoTumble");
        ppd_mark_option(ppd,"PageSize","A4");

     /* Emit initial code (including any reset and JCL code) */
        ppd_emit_to_file(ppd,stdout,PPD_ORDER_EXIT);
        fputs(ppd->jcl_begin->str,stdout);
        ppd_emit_to_file(ppd, stdout, PPD_ORDER_JCL);
        fputs(ppd->jcl_ps->str, stdout);

     /* Any header comments go here */
     ...

     /* Prolog section */
        printf("%%%%BeginProlog0);
        ppd_emit_to_file(ppd, stdout, PPD_ORDER_PROLOG);
        printf("%%%%EndProlog0);

     /* Setup section */
        printf("%%%%BeginSetup0);
        ppd_emit_to_file(ppd, stdout, PPD_ORDER_DOCUMENT);
        printf("%%%%EndSetup0);

     /* Main document begins */
     for (...) {
          printf("%%%%Page: 1 10);

          /* Re-mark so that this is emitted on each page */
             ppd_mark_option(ppd,"PageSize","A4");
             printf("%%%%PageSetup0);
             ppd_emit_to_file(ppd, stdout, PPD_ORDER_PAGE);
             printf("%%%%EndPageSetup0);

          /* Page info goes here */
          ...
     }

     /* Send ending JCL code */
        fputs(ppd->jcl_end->str,stdout);

see how she re-marks PageSize so it gets emitted on every single page? that's the trick. that's the whole trick. 🧚


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the page bestie!! 🫢 it's ppd_emit_to_file(3) from the Library Functions Manual, so if you ever need to cite her, that's the vibe. go emit some code, you're gonna slay. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from