1 | /* datain.h |
---|
2 | * Header file for code that... |
---|
3 | * Reads in survey files, dealing with special characters, keywords & data |
---|
4 | * Copyright (C) 1994-2024 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 | #ifndef DATAIN_H |
---|
22 | #define DATAIN_H |
---|
23 | |
---|
24 | #include <setjmp.h> |
---|
25 | #include <stdio.h> /* for FILE */ |
---|
26 | |
---|
27 | #include "message.h" /* for DIAG_WARN, etc */ |
---|
28 | |
---|
29 | // We rely on implicit initialisation of this struct, so members will be |
---|
30 | // initialised to NULL, 0, false, etc. |
---|
31 | typedef struct parse { |
---|
32 | FILE *fh; |
---|
33 | const char *filename; |
---|
34 | // ftell() at start of the current line. |
---|
35 | long lpos; |
---|
36 | unsigned int line; |
---|
37 | bool reported_where : 1; |
---|
38 | unsigned prev_line_len : 31; |
---|
39 | struct parse *parent; |
---|
40 | } parse; |
---|
41 | |
---|
42 | extern int ch; |
---|
43 | extern parse file; |
---|
44 | extern jmp_buf jbSkipLine; |
---|
45 | extern bool f_export_ok; |
---|
46 | |
---|
47 | #define nextch() (ch = GETC(file.fh)) |
---|
48 | |
---|
49 | typedef struct { |
---|
50 | long offset; |
---|
51 | int ch; |
---|
52 | } filepos; |
---|
53 | |
---|
54 | void get_pos(filepos *fp); |
---|
55 | void set_pos(const filepos *fp); |
---|
56 | |
---|
57 | void set_declination_location(real x, real y, real z, const char *proj_str, |
---|
58 | filepos *fp); |
---|
59 | |
---|
60 | void skipblanks(void); |
---|
61 | |
---|
62 | /* reads complete data file */ |
---|
63 | void data_file(const char *pth, const char *fnm); |
---|
64 | |
---|
65 | real calculate_convergence_xy(const char *proj_str, |
---|
66 | double x, double y, double z); |
---|
67 | |
---|
68 | void skipline(void); |
---|
69 | |
---|
70 | /* Read the current line into a string, converting each tab to a space. |
---|
71 | * |
---|
72 | * The string is allocated with malloc() the caller is responsible for calling |
---|
73 | * free(). |
---|
74 | */ |
---|
75 | char* grab_line(void); |
---|
76 | |
---|
77 | /* The severity values are defined in message.h. */ |
---|
78 | #define DIAG_SEVERITY_MASK 0x03 |
---|
79 | |
---|
80 | // Call skipline() after reporting the diagnostic: |
---|
81 | #define DIAG_SKIP 0x04 |
---|
82 | |
---|
83 | // Context type values: |
---|
84 | |
---|
85 | #define DIAG_CONTEXT_MASK 0x78 |
---|
86 | // Report column number based of the current file position. |
---|
87 | #define DIAG_COL 0x08 |
---|
88 | // Set caret_width to s_len(&token): |
---|
89 | #define DIAG_TOKEN 0x10 |
---|
90 | // The following codes say to parse and discard a value from the current file |
---|
91 | // position - caret_width is set to its length: |
---|
92 | #define DIAG_WORD 0x18 // Span of non-blanks and non-comments. |
---|
93 | #define DIAG_UINT 0x20 // Span of digits. |
---|
94 | #define DIAG_DATE 0x28 // Span of digits and full stops. |
---|
95 | #define DIAG_NUM 0x30 // Real number. |
---|
96 | #define DIAG_STRING 0x38 // Possibly quoted string value. |
---|
97 | #define DIAG_TAIL 0x40 // Rest of the line (not including |
---|
98 | // trailing blanks or comment). |
---|
99 | |
---|
100 | // A non-zero caret_width value can be encoded in the upper bits. |
---|
101 | #define DIAG_FROM_SHIFT 7 |
---|
102 | // Mask to detect embedded caret_width value. |
---|
103 | #define DIAG_FROM_MASK (~((1U << DIAG_FROM_SHIFT) - 1)) |
---|
104 | // Specify the caret_width explicitly. |
---|
105 | #define DIAG_WIDTH(W) ((W) << DIAG_FROM_SHIFT) |
---|
106 | // Specify caret_width to be from filepos POS to the current position. |
---|
107 | #define DIAG_FROM(POS) DIAG_WIDTH(ftell(file.fh) - (POS).offset) |
---|
108 | |
---|
109 | void compile_diagnostic(int flags, int en, ...); |
---|
110 | |
---|
111 | void compile_diagnostic_at(int flags, const char * file, unsigned line, int en, ...); |
---|
112 | void compile_diagnostic_pfx(int flags, const prefix * pfx, int en, ...); |
---|
113 | |
---|
114 | void compile_diagnostic_token_show(int flags, int en); |
---|
115 | void compile_diagnostic_buffer(int flags, int en, ...); |
---|
116 | |
---|
117 | #endif |
---|