source: git/src/datain.h @ a17dce1c

stereo-2025
Last change on this file since a17dce1c was a17dce1c, checked in by Olly Betts <olly@…>, 7 months ago

Assume we have setjmp.h/setjmp()/longjmp()

They're provided by all platforms we realistically support (and
probably all platforms we've ever actually supported).

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/* datain.h
2 * Header file for code that...
3 * Reads in survey files, dealing with special characters, keywords & data
4 * Copyright (C) 1994-2022 Olly Betts
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20
21#include <setjmp.h>
22
23#include <stdio.h> /* for FILE */
24
25#include "message.h" /* for DIAG_WARN, etc */
26
27typedef struct parse {
28   FILE *fh;
29   const char *filename;
30   long lpos;
31   unsigned int line;
32   bool reported_where : 1;
33   unsigned prev_line_len : 31;
34   struct parse *parent;
35   jmp_buf jbSkipLine;
36} parse;
37
38extern int ch;
39extern parse file;
40extern bool f_export_ok;
41
42#define nextch() (ch = GETC(file.fh))
43
44typedef struct {
45   long offset;
46   int ch;
47} filepos;
48
49void get_pos(filepos *fp);
50void set_pos(const filepos *fp);
51
52void skipblanks(void);
53
54/* reads complete data file */
55void data_file(const char *pth, const char *fnm);
56
57void skipline(void);
58
59/* Read the current line into a string, converting each tab to a space.
60 *
61 * The string is allocated with malloc() the caller is responsible for calling
62 * free().
63 */
64char* grab_line(void);
65
66/* The severity values are defined in message.h. */
67#define DIAG_SEVERITY_MASK      0x03
68
69// Call skipline() after reporting the diagnostic:
70#define DIAG_SKIP               0x04
71
72// Context type values:
73
74#define DIAG_CONTEXT_MASK       0x78
75// Report column number based of the current file position.
76#define DIAG_COL                0x08
77// Set caret_width to s_len(&token):
78#define DIAG_TOKEN              0x10
79// The following codes say to parse and discard a value from the current file
80// position - caret_width is set to its length:
81#define DIAG_WORD               0x18    // Span of non-blanks and non-comments.
82#define DIAG_UINT               0x20    // Span of digits.
83#define DIAG_DATE               0x28    // Span of digits and full stops.
84#define DIAG_NUM                0x30    // Real number.
85#define DIAG_STRING             0x38    // Possibly quoted string value.
86#define DIAG_TAIL               0x40    // Rest of the line (not including
87                                        // trailing blanks or comment).
88
89// A non-zero caret_width value can be encoded in the upper bits.
90#define DIAG_FROM_SHIFT 7
91// Mask to detect embedded caret_width value.
92#define DIAG_FROM_MASK  (~((1U << DIAG_FROM_SHIFT) - 1))
93// Specify the caret_width explicitly.
94#define DIAG_WIDTH(W)   ((W) << DIAG_FROM_SHIFT)
95// Specify caret_width to be from filepos POS to the current position.
96#define DIAG_FROM(POS)  DIAG_WIDTH(ftell(file.fh) - (POS).offset)
97
98void compile_diagnostic(int flags, int en, ...);
99
100void compile_diagnostic_at(int flags, const char * file, unsigned line, int en, ...);
101void compile_diagnostic_pfx(int flags, const prefix * pfx, int en, ...);
102
103void compile_diagnostic_token_show(int flags, int en);
104void compile_diagnostic_buffer(int flags, int en, ...);
Note: See TracBrowser for help on using the repository browser.