summaryrefslogtreecommitdiff
path: root/buttress.h
blob: afb38ae4132ebdb0b80cf0f370b7399cf18ada5e (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
#ifndef BUTTRESS_BUTTRESS_H
#define BUTTRESS_BUTTRESS_H

#ifdef __GNUC__
#define NORETURN __attribute__((__noreturn__))
#endif

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

/*
 * Structure tags
 */
typedef struct input_Tag input;
typedef struct paragraph_Tag paragraph;
typedef struct word_Tag word;

/*
 * Data structure to hold all the file names etc for input
 */
#define INPUT_PUSHBACK_MAX 16
struct input_Tag {
    char **filenames;		       /* complete list of input files */
    int nfiles;			       /* how many in the list */
    FILE *currfp;		       /* the currently open one */
    int currindex;		       /* which one is that in the list */
    char pushback[INPUT_PUSHBACK_MAX]; /* pushed-back input characters */
    int npushback;
};

/*
 * Data structure to hold the input form of the source, ie a linked
 * list of paragraphs
 */
struct paragraph_Tag {
    paragraph *next;
    int type;
    char *keyword;		       /* for IR, IA, and heading paras */
    word *words;		       /* list of words in paragraph */
} paragraph;
enum {
    para_IA,			       /* index alias */
    para_IR,			       /* index rewrite */
    para_Chapter,
    para_Appendix,
    para_Heading,
    para_Subsect,
    para_Normal,
    para_Bullet,
    para_Code
};

/*
 * Data structure to hold an individual word
 */
struct word_Tag {
    word *next;
    int type;
    char *text;
}
enum {
    word_Normal,
    word_Emph,
    word_Code,
    word_IndexRef		       /* always invisible */
}

/*
 * error.c
 */
void fatal(int code, ...) NORETURN;
void error(int code, ...);
enum {
    err_nomemory,		       /* out of memory */
    err_optnoarg,		       /* option `-%s' requires an argument */
    err_nosuchopt,		       /* unrecognised option `-%s' */
    err_noinput,		       /* no input files */
};

/*
 * malloc.c
 */
void *smalloc(int size);
void *srealloc(void *p, int size);
void sfree(void *p);

/*
 * help.c
 */
void help(void);
void usage(void);
void showversion(void);

/*
 * licence.c
 */
void licence(void);

/*
 * version.c
 */
const char *const version;

/*
 * input.c
 */
paragraph *read_input(input *in);

#endif