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