source: git/src/datain.h @ 94aeeaf

stereo-2025
Last change on this file since 94aeeaf was d5a206ec, checked in by Olly Betts <olly@…>, 11 months ago

Fix handling of unsupported datum in Walls WPJ

The context started two columns too far right.

Also change tab to space in context shown for declination used "info"
message so the context matches that shown in other diagnostics.

  • 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#ifdef HAVE_SETJMP_H
22# include <setjmp.h>
23#endif
24
25#include <stdio.h> /* for FILE */
26
27#include "message.h" /* for DIAG_WARN, etc */
28
29typedef struct parse {
30   FILE *fh;
31   const char *filename;
32   long lpos;
33   unsigned int line;
34   bool reported_where : 1;
35   unsigned prev_line_len;
36   struct parse *parent;
37#ifdef HAVE_SETJMP_H
38   jmp_buf jbSkipLine;
39#endif
40} parse;
41
42extern int ch;
43extern parse file;
44extern bool f_export_ok;
45
46#define nextch() (ch = GETC(file.fh))
47
48typedef struct {
49   long offset;
50   int ch;
51} filepos;
52
53void get_pos(filepos *fp);
54void set_pos(const filepos *fp);
55
56void skipblanks(void);
57
58/* reads complete data file */
59void data_file(const char *pth, const char *fnm);
60
61void skipline(void);
62
63/* Read the current line into a string, converting each tab to a space.
64 *
65 * The string is allocated with malloc() the caller is responsible for calling
66 * free().
67 */
68char* grab_line(void);
69
70/* The severity values are defined in message.h. */
71#define DIAG_SEVERITY_MASK 0x03
72// Report column number based of the current file position.
73#define DIAG_COL        0x04
74// Call skipline() after reporting the diagnostic:
75#define DIAG_SKIP       0x08
76// Set caret_width to s_len(&token):
77#define DIAG_TOKEN      0x10
78// The following codes say to parse and discard a value from the current file
79// position - caret_width is set to its length:
80#define DIAG_WORD       0x20    // Span of non-blanks (and non-comments).
81#define DIAG_UINT       0x40    // Span of digits.
82#define DIAG_DATE       0x80    // Span of digits and full stops.
83#define DIAG_NUM        0x100   // Real number.
84#define DIAG_STRING     0x200   // Possibly quoted string value.
85#define DIAG_TAIL       0x400   // Rest of the line (not including trailing blanks or comment).
86#define DIAG_FROM_      0x800   // The caret_width value is in bits above this one.
87#define DIAG_FROM_SHIFT 12
88// Specify the caret_width explicitly.
89#define DIAG_WIDTH(W)   (DIAG_FROM_ | ((W) << DIAG_FROM_SHIFT))
90// Specify caret_width to be from filepos POS to the current position.
91#define DIAG_FROM(POS)  DIAG_WIDTH(ftell(file.fh) - (POS).offset)
92
93void compile_diagnostic(int flags, int en, ...);
94
95void compile_diagnostic_at(int flags, const char * file, unsigned line, int en, ...);
96void compile_diagnostic_pfx(int flags, const prefix * pfx, int en, ...);
97
98void compile_diagnostic_token_show(int flags, int en);
99void compile_diagnostic_buffer(int flags, int en, ...);
Note: See TracBrowser for help on using the repository browser.