1 #ifndef CGATS_H
2 
3 /*
4  * Committee for Graphics Arts Technologies Standards
5  * CGATS.5 and IT8.7 family file I/O class
6  * Version 2.05
7  */
8 
9 /*
10  * Author: Graeme W. Gill
11  * Date:   20/12/95
12  *
13  * Copyright 1995, 1996, 2002, Graeme W. Gill
14  * All rights reserved.
15  *
16  * This material is licensed with an "MIT" free use license:-
17  * see the License4.txt file in this directory for licensing details.
18  */
19 
20 /* Version of cgatslib release */
21 
22 #define CGATSLIB_VERSION 0x020005
23 #define CGATSLIB_VERSION_STR "2.05"
24 
25 #define CGATS_ERRM_LENGTH 2000
26 
27 #ifdef __cplusplus
28 	extern "C" {
29 #endif
30 
31 #include "pars.h"		/* We use the ASCII parsing class */
32 
33 /* Possible table types */
34 typedef enum { it8_7_1, it8_7_2, it8_7_3, it8_7_4, cgats_5, cgats_X, tt_other, tt_none } table_type;
35 
36 /* Possible data types - real, integer, char string, non-quoted char string, no value */
37 typedef enum { r_t, i_t, cs_t, nqcs_t, none_t } data_type;
38 
39 union _cgats_set_elem {
40 	int i;
41 	double d;
42 	char *c;
43 }; typedef union _cgats_set_elem cgats_set_elem;
44 
45 struct _cgats_table {
46 	cgatsAlloc *al;		/* Copy of parent memory allocator */
47 	table_type tt;		/* Table type */
48 	int oi;				/* other type index */
49 
50 	/* Read only */
51 	int nkwords;		/* Number of keywords */
52 	int nfields;		/* Number of fields of data */
53 	int nsets;			/* Number of data sets */
54 
55 	char **ksym;		/* Pointer to [nkwords] array of pointers to keyword symbols */
56 	char **kdata;		/* Pointer to [nkwords] array of pointers to keyword values */
57 
58 	char **fsym;		/* Pointer to [nfields] array of pointers to field symbols */
59 	data_type *ftype;	/* Pointer to [nfields] array of field types */
60 	char ***rfdata;		/* Pointer to [nsets] array of pointers */
61 						/*         to [nfields] array of pointers to read file field text values */
62 	void ***fdata;		/* Pointer to [nsets] array of pointers */
63 						/*         to [nfields] array of pointers to field set values of ftype */
64 	/* Private */
65 	int nkwordsa;		/* Number of keywords allocated */
66 	int nfieldsa;		/* Number of fields allocated */
67 	int nsetsa;			/* Number of sets allocated */
68 	char **kcom;		/* Pointer to [nkwords] array of pointers to keyword comments */
69 	int ndf;			/* Next data field - used by add_data_item() */
70 	int sup_id;			/* Set to non-zero if table ID output is to be suppressed */
71 	int sup_kwords;		/* Set to non-zero if table default keyword output is to be suppressed */
72 	int sup_fields;		/* Set to non-zero if table field output is to be suppressed */
73 }; typedef struct _cgats_table cgats_table;
74 
75 struct _cgats {
76 	/* Private */
77 	cgatsAlloc *al;		/* Memory allocator */
78 	int del_al;			/* Flag to indicate we al->del() */
79 
80 	/* Read only Variables */
81 	int ntables;		/* Number of tables */
82 
83 	cgats_table *t;		/* Pointer to an array of ntable table structures */
84 
85 	/* Undefined CGATS table type */
86 	char *cgats_type;
87 
88 	/* User defined table types */
89 	int nothers;		/* Number of other identifiers */
90 	char **others;		/* Other file type identifiers */
91 
92 	/* Options */
93 	int emit_keywords;	/* NZ to emit "KEYWORD" for non-standard keywords (default no) */
94 
95 	/* Public Methods */
96 	int (*set_cgats_type)(struct _cgats *p, const char *osym);
97 											/* Define the (one) variable CGATS type */
98 											/* Return -2, set errc & err on system error */
99 
100 	int (*add_other)(struct _cgats *p, const char *osym);
101 											/* Add a user defined file identifier string. */
102 											/* Use a zero length string for wildcard. */
103 											/* Return the oi */
104 											/* Return -2, set errc & err on system error */
105 
106 	int (*get_oi)(struct _cgats *p, const char *osym);
107 											/* Return the oi of the given other type */
108 											/* return -ve and errc and err set on error */
109 
110 	int (*read)(struct _cgats *p, cgatsFile *fp);	/* Read a cgats file into structure */
111 												/* return -ve and errc and err set on error */
112 
113 	/* NULL if SEPARATE_STD is defined: */
114 	int (*read_name)(struct _cgats *p, const char *filename);	/* Standard file I/O */
115 												/* return -ve and errc and err set on error */
116 
117 	int (*find_kword)(struct _cgats *p, int table, const char *ksym);
118 												/* Return index of the keyword, -1 on fail */
119 												/* -2 on illegal table index, errc & err */
120 	int (*find_field)(struct _cgats *p, int table, const char *fsym);
121 												/* Return index of the field, -1 on fail */
122 												/* -2 on illegal table index, errc & err */
123 
124 	int (*add_table)(struct _cgats *p, table_type tt, int oi);
125 	                                        /* Add a new (empty) table to the structure */
126 											/* Return the index of the table */
127 											/* Return -2, set errc & err on system error */
128 											/* if tt is tt_other, io sets the other index */
129 	int (*set_table_flags)(struct _cgats *p, int table, int sup_id,int sup_kwords,int sup_fields);
130 						/* Set or reset table output suppresion flags */
131 						/* Return -ve, set errc & err on error */
132 	int (*add_kword)(struct _cgats *p, int table, const char *ksym, const char *kdata, const char *kcom);
133 						/* Add a new keyword/value pair + optional comment to the table */
134 						/* Return index of new keyword, or -1, errc & err on error */
135 	int (*add_field)(struct _cgats *p, int table, const char *fsym, data_type ftype);
136 						/* Add a new field to the table */
137 						/* Return index of new field, or -1, -2, errc and err on error */
138 	int (*add_set)(struct _cgats *p, int table, ...);	/* Add a set of data */
139 						/* Return 0 normally, -1, -2, errc & err if error */
140 	int (*add_setarr)(struct _cgats *p, int table, cgats_set_elem *ary); /* Add data from array */
141 						/* Return 0 normally, -1, -2, errc & err if error */
142 	int (*write)(struct _cgats *p, cgatsFile *fp);	/* Write structure into cgats file */
143 										/* return -ve and errc and err set on error */
144 
145 	int (*get_setarr)(struct _cgats *p, int table, int set_index, cgats_set_elem *ary);
146 						/* Fill a suitable set_element with a line of data */
147 						/* Return 0 normally, -1, -2, errc & err if error */
148 	/* NULL if SEPARATE_STD is defined: */
149 	int (*write_name)(struct _cgats *p, const char *filename);	/* Standard file I/O */
150 										/* return -ve and errc and err set on error */
151 
152 
153 	int (*error)(struct _cgats *p, char **mes);		/* Return error code and message */
154 													/* for the first error, if any error */
155 													/* has occured since object creation. */
156 	void (*del)(struct _cgats *p);					/* Delete the object */
157 
158 	char err[CGATS_ERRM_LENGTH];		/* Error message */
159 	int errc;			/* Error code */
160 	char ferr[CGATS_ERRM_LENGTH];		/* First error message */
161 	int ferrc;			/* First error code */
162 }; typedef struct _cgats cgats;
163 
164 /* Creator */
165 extern cgats *new_cgats_al(cgatsAlloc *al);	/* with allocator object */
166 
167 #ifdef COMBINED_STD
168 #define CGATS_STATIC static
169 #else
170 #define CGATS_STATIC
171 #endif
172 
173 /* Available if SEPARATE_STD is not defined */
174 extern cgats *new_cgats(void);							/* Standard allocator */
175 
176 /* Available from cgatsstd.obj SEPARATE_STD is defined: */
177 CGATS_STATIC int cgats_read_name(cgats *p, const char *filename);
178 CGATS_STATIC int cgats_write_name(cgats *p, const char *filename);
179 
180 #ifdef __cplusplus
181 	}
182 #endif
183 
184 #define CGATS_H
185 #endif /* CGATS_H */
186