]> mj.ucw.cz Git - paperjam.git/blob - jam.h
f5d2ca1d5e5a9c122cf86b44bd734dd593ddc280
[paperjam.git] / jam.h
1 #include <vector>
2 #include <list>
3
4 using namespace std;
5
6 #include "pdf-tools.h"
7
8 typedef unsigned int uint;
9
10 #define NONRET __attribute__((noreturn))
11 #define UNUSED __attribute__((unused))
12
13 struct pipeline;
14 struct cmd;
15
16 enum arg_type {
17   AT_STRING,
18   AT_DOUBLE,
19   AT_DIMEN,
20   AT_TYPE_MASK = 0xffff,
21   AT_MANDATORY = 0x10000,
22   AT_POSITIONAL = 0x20000,
23 };
24
25 struct arg_def {
26   const char *name;
27   uint type;
28 };
29
30 class arg_val {
31 public:
32   virtual bool given() { return false; }
33   explicit virtual operator double() { abort(); }
34   explicit virtual operator string() { abort(); }
35   double double_default(double def) { return given() ? (double) *this : def; }
36   const string string_default(const string def) { return given() ? (string) *this : def; }
37   virtual string dump() { return "<undef>"; }
38 };
39
40 struct page_out {
41 };
42
43 struct page {
44   double width;
45   double height;
46   virtual void render(page_out *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
47   page(double _w, double _h) : width(_w), height(_h) { }
48 };
49
50 struct cmd_exec {
51   virtual vector<page *> process(vector <page *> pages UNUSED) { abort(); }
52 };
53
54 struct cmd_def {
55   const char *name;
56   const arg_def *arg_defs;
57   bool has_pipeline;
58   cmd_exec *(*constructor)(cmd *cmd);
59 };
60
61 struct cmd {
62   const cmd_def *def;
63   vector<arg_val *> args;
64   pipeline *pipe;
65   cmd_exec *exec;
66 };
67
68 struct pipeline_selector {
69   int from;
70   int to;
71 };
72
73 struct pipeline_branch {
74   vector<pipeline_selector> selectors;
75   list<cmd *> commands;
76 };
77
78 struct pipeline {
79   vector<pipeline_branch *> branches;
80 };
81
82 // parse.cc
83
84 void parse(const char *in, list<cmd *> *cmds);
85
86 // cmds.cc
87
88 extern const cmd_def cmd_table[];