[b0d908e] | 1 | /* datain.h |
---|
[d1b1380] | 2 | * Header file for code that... |
---|
| 3 | * Reads in survey files, dealing with special characters, keywords & data |
---|
[37d6b84] | 4 | * Copyright (C) 1994-2022 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 | |
---|
[7d5f3c0] | 21 | #ifdef HAVE_SETJMP_H |
---|
[647407d] | 22 | # include <setjmp.h> |
---|
[d1b1380] | 23 | #endif |
---|
| 24 | |
---|
[a420b49] | 25 | #include <stdio.h> /* for FILE */ |
---|
| 26 | |
---|
[37d6b84] | 27 | #include "message.h" /* for DIAG_WARN, etc */ |
---|
| 28 | |
---|
[a420b49] | 29 | typedef struct parse { |
---|
[58cc1fb] | 30 | FILE *fh; |
---|
[a63fb408] | 31 | const char *filename; |
---|
[a420b49] | 32 | unsigned int line; |
---|
[da96015] | 33 | long lpos; |
---|
[b0d908e] | 34 | bool reported_where; |
---|
[421b7d2] | 35 | struct parse *parent; |
---|
[7d5f3c0] | 36 | #ifdef HAVE_SETJMP_H |
---|
[58cc1fb] | 37 | jmp_buf jbSkipLine; |
---|
[d1b1380] | 38 | #endif |
---|
| 39 | } parse; |
---|
[58cc1fb] | 40 | |
---|
| 41 | extern int ch; |
---|
[d1b1380] | 42 | extern parse file; |
---|
[932f7e9] | 43 | extern bool f_export_ok; |
---|
[d1b1380] | 44 | |
---|
[e02a6a6] | 45 | #define nextch() (ch = GETC(file.fh)) |
---|
[c80bd34] | 46 | |
---|
| 47 | typedef struct { |
---|
| 48 | long offset; |
---|
| 49 | int ch; |
---|
| 50 | } filepos; |
---|
| 51 | |
---|
| 52 | void get_pos(filepos *fp); |
---|
| 53 | void set_pos(const filepos *fp); |
---|
[d1b1380] | 54 | |
---|
[a9f5117] | 55 | void skipblanks(void); |
---|
[d1b1380] | 56 | |
---|
[3a54fd29] | 57 | /* reads complete data file */ |
---|
[a9f5117] | 58 | void data_file(const char *pth, const char *fnm); |
---|
[3a54fd29] | 59 | |
---|
[a9f5117] | 60 | void skipline(void); |
---|
[d1b1380] | 61 | |
---|
[37d6b84] | 62 | /* Read the current line into a string. |
---|
| 63 | * |
---|
| 64 | * The string is allocated with malloc() the caller is responsible for calling |
---|
| 65 | * free(). |
---|
| 66 | */ |
---|
| 67 | char* grab_line(void); |
---|
| 68 | |
---|
| 69 | /* The severity values are defined in message.h. */ |
---|
[cab0f26] | 70 | #define DIAG_SEVERITY_MASK 0x03 |
---|
[f0e31b0] | 71 | // Report column number based of the current file position. |
---|
[cab0f26] | 72 | #define DIAG_COL 0x04 |
---|
[f0e31b0] | 73 | // Call skipline() after reporting the diagnostic: |
---|
[cab0f26] | 74 | #define DIAG_SKIP 0x08 |
---|
[f0e31b0] | 75 | // Set caret_width to s_len(&token): |
---|
[caae6cd] | 76 | #define DIAG_TOKEN 0x10 |
---|
[f0e31b0] | 77 | // The following codes say to parse and discard a value from the current file |
---|
| 78 | // position - caret_width is set to its length: |
---|
| 79 | #define DIAG_WORD 0x20 // Span of non-blanks. |
---|
| 80 | #define DIAG_UINT 0x40 // Span of digits. |
---|
| 81 | #define DIAG_DATE 0x80 // Span of digits and full stops. |
---|
| 82 | #define DIAG_NUM 0x100 // Real number. |
---|
| 83 | #define DIAG_STRING 0x200 // Possibly quoted string value. |
---|
[498ed7b] | 84 | #define DIAG_TAIL 0x400 // Rest of the line (not including trailing blanks or comment). |
---|
[d3fa693] | 85 | #define DIAG_FROM_ 0x800 // Width is from filepos in bits above this one |
---|
| 86 | #define DIAG_FROM_SHIFT 12 |
---|
| 87 | #define DIAG_FROM(POS) (DIAG_FROM_ | ((ftell(file.fh) - (POS).offset) << DIAG_FROM_SHIFT)) |
---|
[39fba51] | 88 | |
---|
[cab0f26] | 89 | void compile_diagnostic(int flags, int en, ...); |
---|
| 90 | |
---|
| 91 | void compile_diagnostic_at(int flags, const char * file, unsigned line, int en, ...); |
---|
| 92 | void compile_diagnostic_pfx(int flags, const prefix * pfx, int en, ...); |
---|
| 93 | |
---|
| 94 | void compile_diagnostic_token_show(int flags, int en); |
---|
| 95 | void compile_diagnostic_buffer(int flags, int en, ...); |
---|