bes  Updated for version 3.20.6
menuindx.h
1 /*
2  * FILENAME: menuindx.h
3  *
4  * CAVEAT:
5  * No claims are made as to the suitability of the accompanying
6  * source code for any purpose. Although this source code has been
7  * used by the NOAA, no warranty, expressed or implied, is made by
8  * NOAA or the United States Government as to the accuracy and
9  * functioning of this source code, nor shall the fact of distribution
10  * constitute any such endorsement, and no responsibility is assumed
11  * by NOAA in connection therewith. The source code contained
12  * within was developed by an agency of the U.S. Government.
13  * NOAA's National Geophysical Data Center has no objection to the
14  * use of this source code for any purpose since it is not subject to
15  * copyright protection in the U.S. If this source code is incorporated
16  * into other software, a statement identifying this source code may be
17  * required under 17 U.S.C. 403 to appear with any copyright notice.
18  */
19 
20 #ifndef MENU_INDEX_FILE
21 /* Restrictions placed on menu files by all mn_ functions:
22  *
23  * Maximum line length: 490 bytes
24  * Maximum length of section titles: 200 bytes
25  * EOL characters: unix, mac, or PC,
26  * but must be uniform throughout the file.
27  * Maximum number of sections: 32,700
28  * Maximum menu file size: 2,000,000,000 bytes
29  * Maximum section size: 64000 bytes
30  *
31  * Restrictions inside mn_ functions:
32  *
33  * Minimum max_buffer_size: 1000 bytes
34  * Maximum size of buffers created: MENU_INDEX_PTR->max_buffer_size
35  *
36  */
37 
38 #if 0 && !(defined(FREEFORM) && defined(XVT))
39 #include <assert.h>
40 #endif
41 
42 #ifdef MEN2HTML
43 #include <m2herror.h>
44 #endif
45 
46 /* Define the ROW_SIZES structure, if it has not already been defined */
47 /**********************************************************************/
49 /**********************************************************************/
50 #ifndef ROWSIZE_STRUCT_DEFINED
51 #define ROWSIZE_STRUCT_DEFINED
52 typedef struct {
53  long start;
54  long num_bytes;
56 #endif
57 
58 #define ulong unsigned long
59 
60 /* menu related structures: */
61 typedef struct menu_index_struct {
62  void *check_address;
63  char *menu_file; /* path and file name */
64  char *file_eol_str; /* EOL sequence for the menu file */
65  char index_origion; /* boolean for memory/file index */
66  char correct_eol_len; /* boolean for correction of EOL length */
67  char index_eol_len; /* end-of-line length for index */
68  char menu_in_mem; /* boolean for file/memory created menu */
69  char binary_menu; /* boolean for binary menu
70  (if BINARY_MENU section exists) */
71  ulong lines_in_index; /* (file index) number of lines in index */
72  ulong bytes_in_index; /* (file index) number of bytes in index */
73  ulong lines_in_menu; /* number of lines in menu, total */
74  ulong bytes_in_menu; /* number of bytes in menu, total */
75  ulong max_buffer_size; /* maximum buffer size */
76  short file_eollen; /* length of EOL sequence for the menu file */
77  char index_corrupt; /* file index exists, but is corrupt */
78  char file_index_exists;/* boolean (TRUE if file index exists) */
79  char **index_buffer; /* array of buffer pointers */
80  ulong *buffer_length; /* actual length of buffers array */
81  short num_buffers; /* the number of buffers required */
82  short num_sections; /* the number of sections in the menu */
83  char *menu_name; /* the name of the menu
84  (as in a MENU_NAME section) */
85  char *text_content; /* the text content of the menu
86  (as in the TEXT_CONTENT section) */
87  char *data_path_one; /* the path to prepend to
88  documentation files 1st */
89  char *data_path_two; /* the path to prepend to
90  documentation files 2nd */
92 
93 /* Please note that this struct, while designed as a DLL, IS NOT COMPATIBLE
94  * WITH THE FREEFORM DLLs defined in adtlib. DO NOT USE THE DLL_ MACROS with
95  * these structures. This is a non-circular DLL, and various reasons exist
96  * which justify not using the DLL functions on this structure. */
97 typedef struct menu_selection_dll_struct {
98  void *check_address;
99  struct menu_selection_dll_struct *next_selection;
100  struct menu_selection_dll_struct *previous_selection;
101  char *user_display; /* The element to display on the user interface */
102  char *next_event; /* file name or new section name */
103  char *additional_info; /* additional information for a file (HDF+...) */
104  char help_exists; /* boolean; true if help exists for selection */
105  char *help_title; /* the title of the help section (if exists) */
106  ROW_SIZES_PTR help_sec;/* rowsize struct for help section (or NULL) */
107  char selection_type; /* The type of the selection */
108  char ascii_data_file; /* true if $ was encountered */
109  short selection_num; /* The number of the selection (i.e. 3rd of 5) */
110  void *extra_info; /* An extra information pointer
111  (In GeoVu, a MENU_OPEN struct */
113 
114 typedef struct menu_section_struct {
115  void *check_address;
116  MENU_INDEX_PTR mindex; /* a pointer to the menu index */
117  char *title; /* the title of the section (may not occur in menu file) */
118  char *section; /* the section title as recorded in the menu file */
119  char *parent; /* the parent section (NULL if none) */
120  char *next; /* if section_type=help, section to display next */
121  char section_type; /* the type of the section (help or selection) */
122  char help_exists; /* boolean; true if help for section exists */
123  char dynamic_section; /* boolean; true if section was dynamically made */
124  char *help_title; /* the title of the help section (NULL if none) */
125  ROW_SIZES_PTR help_sec; /* rowsize struct for the help section (or NULL)*/
126  char *display; /* the buffer to display (if section_type==help)*/
127  int num_choices; /* The number of MENU_SELECTION dll members */
128  MENU_SELECTION_PTR selection; /* Ptr to the first MENU_SELECTION dll
129  member (if section_type==selection)*/
130  void *extra_info; /* For use by whatever function calls us, for anything
131  (In GeoVu, a MENU_PLACEHOLDER struct) */
133 
134 /* If we are inside GeoVu, define the MENU_OPEN struct here */
135 #ifdef XVT
136 
137 /* Define the menu_open struct */
138 typedef struct menu_open_struct {
139  MENU_INDEX_PTR mindex; /* A pointer to the menu index
140  (if it exists, NULL if not) */
141  int menu_navigation_count; /* The number of sections of this menu
142  open under navigation (This is used
143  internally only in GETMENU.C and has
144  no significance outside of that module */
145  int usage_count; /* The number of data bins open with this
146  menu (might need help) */
147  char *path_to_data; /* The path to data (if it exists) */
148  char *menu_file_name; /* The menu file (with path)*/
149 } MENU_OPEN, *MENU_OPEN_PTR;
150 
151 #endif
152 
153 /* Section type defines */
154 #define MENU_SECTION_TYPE_SELECTION 0
155 #define MENU_SECTION_TYPE_HELP 1
156 
157 /* Directive type defines */
158 #define MENU_DIRECTIVE_NEW_SECTION 0
159 #define MENU_DIRECTIVE_TERM_SECTION 1
160 #define MENU_DIRECTIVE_NEW_MENU_FILE 2
161 #define MENU_DIRECTIVE_DATA_FILE 3
162 
163 /* Menu index origion defines */
164 #define MENU_INDEX_FILE 0
165 #define MENU_INDEX_MEM 1
166 
167 /* Menu origion defines */
168 #define MENU_IN_FILE 0
169 #define MENU_IN_MEM 1
170 
171 /* the menu directory seperator is a backslash by standard */
172 #define MENU_DIR_SEP '\\'
173 
174 /* Define the default menu name */
175 #define MENU_UNTITLED "Untitled"
176 
177 /* Define the default text content */
178 #define MENU_TEXT_CONTENT "ASCII"
179 
180 /* Define menu data section title extension */
181 #define MENU_DATA_SECTION "_DATASEC"
182 
183 /* Define menu index section title and length */
184 #define MENU_INDEX_SECTION "*MENU INDEX"
185 #define MENU_INDEX_SECTION_LEN 11
186 
187 /* Define menu text content section */
188 #define MENU_TEXT_CONTENT_SEC "TEXT_CONTENT"
189 
190 #define MENU_FOPEN_R "rb"
191 #define MENU_FOPEN_W "wb"
192 #define MENU_FOPEN_U "r+b"
193 
194 #ifdef SUNCC
195 #include <unistd.h>
196 #endif
197 
198 /* The MENU_ERR_PUSH define is for greater flexibility in error handling;
199  * these lines make sure that MENU_ERR_PUSH defaults to err_push.
200  *
201  * Because MEN2HTML uses the menu functions, and must send errors to
202  * stdout (instead of stderr) and in HTML format, this macro is necessary.
203  */
204 #ifndef MENU_ERR_PUSH
205 #define MENU_ERR_PUSH(a, b, c) err_push(b, c)
206 #endif
207 
208 /* Function declarations for mn_index functions: */
209 MENU_INDEX_PTR mn_index_make (char *filename, ulong max_buf_size, char *outfilename);
210 int mn_index_remove(char *filename, char *outfilename);
211 int mn_index_get_offset(MENU_INDEX_PTR mindex, char *section, ROW_SIZES_PTR rowsize);
212 int mn_index_free(MENU_INDEX_PTR mindex);
213 int mn_index_find_title(MENU_INDEX_PTR mindex, char *postfix, ROW_SIZES_PTR rowsize, char **buffer);
214 int mn_index_set_paths(MENU_INDEX_PTR mindex, char *pathone, char *pathtwo);
215 char *mn_binary_fgets(char *string, int n, FILE *stream, char *file_eol_str);
216 char *mn_get_file_eol_str(char *filename);
217 
218 /* Function declarations for other mn_ functions: */
219 int mn_sec_titles_to_buf(MENU_INDEX_PTR mindex, char *buf_to_use, int *num_sections, char **buf_filled);
220 int mn_section_get(MENU_INDEX_PTR mindex, char *buf_to_use, ROW_SIZES_PTR rowsize, char **buf_filled);
221 int mn_help_sec_find(MENU_INDEX_PTR mindex, char *lookup, ROW_SIZES_PTR rowsize, char *section_name);
222 int mn_sec_process(MENU_INDEX_PTR mindex, char *section_title, ROW_SIZES_PTR rowsize, char *parent_menu, MENU_SECTION_PTR *menu_sec);
223 int mn_help_sec_get(MENU_INDEX_PTR mindex, char *lookup, ROW_SIZES_PTR rowsize, char **buf_filled);
224 int mn_proc_section_free(MENU_SECTION_PTR menu_sec);
225 int mn_selection_free(MENU_SELECTION_PTR selection);
226 int mn_datasec_len_get(MENU_INDEX_PTR mindex, ROW_SIZES_PTR rowsize, long *length);
227 int mn_section_rebuild(MENU_SECTION_PTR msection, char **buffer);
228 MENU_SELECTION_PTR mn_selection_copy(MENU_SELECTION_PTR selection);
229 
230 
231 
232 
233 /* Macros for navigating the MENU_SELECTION dll */
234 #define MENU_NEXT_SELECTION(a) ((a)->next_selection)
235 #define MENU_PREV_SELECTION(a) ((a)->previous_selection)
236 #define MENU_REWIND_SELECTION_DLL(a) {while((a)->previous_selection) (a)=(a)->previous_selection;}
237 
238 /* This macro removes and frees the MENU_SELECTION_PTR 'rmv' */
239 #define MENU_REMOVE_SELECTION(rmv, newptr) { \
240  newptr = NULL; \
241  if(rmv->previous_selection){ \
242  rmv->previous_selection->next_selection = rmv->next_selection; \
243  newptr = rmv->previous_selection; \
244  } \
245  if(rmv->next_selection){ \
246  rmv->next_selection->previous_selection = rmv->previous_selection; \
247  newptr = rmv->next_selection; \
248  } \
249  mn_selection_free(rmv); \
250  rmv = NULL; }
251 
252 /* This macro inserts the MENU_SELECTION_PTR 'ins' into 'list' */
253 #define MENU_INSERT_SELECTION(ins, list) { \
254  if(list){ \
255  ins->previous_selection = list; \
256  ins->next_selection = list->next_selection; \
257  list->next_selection = ins; \
258  if(ins->next_selection) \
259  ins->next_selection->previous_selection = ins; \
260  } \
261  else \
262  list = ins;}
263 
264 #endif
265 
266 #ifdef MEMTRAP
267 /* Macros for memory testing */
268 #define mAlloc(sz) mn_malloc(sz, __LINE__, ROUTINE_NAME)
269 #define reAlloc(mptr, sz) mn_realloc(mptr, sz, __LINE__, ROUTINE_NAME)
270 #define fRee(sz) mn_free(sz, __LINE__, ROUTINE_NAME)
271 
272 void *mn_malloc(size_t memsize, int linenum, char *routine);
273 void *mn_realloc(void *memblk, size_t memsize, int linenum, char *routine);
274 void mn_free(void *memblk, int linenum, char *routine);
275 
276 #define MEMTRAPFILE "c:\\memtrap"
277 
278 #else
279 
280 #define mAlloc(sz) memMalloc(sz, "menu")
281 #define reAlloc(mptr, sz) memRealloc(mptr, sz, "menu")
282 #define fRee(sz) memFree(sz, "menu")
283 #endif
284 
285 #ifdef NO_FF
286 
287 /* We are NOT including freeform, so we need to define our very own
288  * strnstr function */
289 char *mn_strnstr(char *pcPattern, char *pcText, size_t uTextLen);
290 #define MN_STRNSTR(strpattern, strtext, textsize) mn_strnstr(strpattern, strtext, textsize)
291 
292 #else
293 
294 /* We are including freeform, use ff_strnstr */
295 #define MN_STRNSTR(strpattern, strtext, textsize) ff_strnstr(strpattern, strtext, textsize)
296 
297 #endif
ROW_SIZES
Definition: menuindx.h:52
menu_index_struct
Definition: menuindx.h:61
menu_section_struct
Definition: menuindx.h:114
menu_selection_dll_struct
Definition: menuindx.h:97