1 /*
2  * $Id: util.h,v 1.50 2016/08/19 16:13:59 sfeam Exp $
3  */
4 
5 /* GNUPLOT - util.h */
6 
7 /*[
8  * Copyright 1986 - 1993, 1998, 2004   Thomas Williams, Colin Kelley
9  *
10  * Permission to use, copy, and distribute this software and its
11  * documentation for any purpose with or without fee is hereby granted,
12  * provided that the above copyright notice appear in all copies and
13  * that both that copyright notice and this permission notice appear
14  * in supporting documentation.
15  *
16  * Permission to modify the software is granted, but not the right to
17  * distribute the complete modified source code.  Modifications are to
18  * be distributed as patches to the released version.  Permission to
19  * distribute binaries produced by compiling modified sources is granted,
20  * provided you
21  *   1. distribute the corresponding source modifications from the
22  *    released version in the form of a patch file along with the binaries,
23  *   2. add special version identification to distinguish your version
24  *    in addition to the base release version number,
25  *   3. provide your name and address as the primary contact for the
26  *    support of your modified version, and
27  *   4. retain our contact information in regard to use of the base
28  *    software.
29  * Permission to distribute the released version of the source code along
30  * with corresponding source modifications in the form of a patch file is
31  * granted with same provisions 2 through 4 for binary distributions.
32  *
33  * This software is provided "as is" without express or implied warranty
34  * to the extent permitted by applicable law.
35 ]*/
36 
37 #ifndef GNUPLOT_UTIL_H
38 # define GNUPLOT_UTIL_H
39 
40 #include "gp_types.h"
41 #include "stdfn.h"		/* for size_t */
42 
43 /* special token number meaning 'do not draw the "caret"', for
44  * int_error and friends: */
45 #define NO_CARET (-1)
46 
47 /* token number meaning 'the error was in the datafile, not the
48    command line' */
49 #define DATAFILE (-2)
50 
51 /* TRUE if command just typed; becomes FALSE whenever we
52  * send some other output to screen.  If FALSE, the command line
53  * will be echoed to the screen before the ^ error message.
54  */
55 extern TBOOLEAN screen_ok;
56 
57 /* decimal sign */
58 extern char *decimalsign;
59 extern char *numeric_locale;	/* LC_NUMERIC */
60 extern char *current_locale;	/* LC_TIME */
61 
62 /* degree sign */
63 extern char degree_sign[8];
64 
65 /* special characters used by gprintf() */
66 extern const char *micro;
67 extern const char *minus_sign;
68 extern TBOOLEAN use_micro;
69 extern TBOOLEAN use_minus_sign;
70 
71 extern const char *current_prompt; /* needed by is_error() and friends */
72 
73 /* Functions exported by util.c: */
74 
75 /* Command parsing helpers: */
76 int equals __PROTO((int, const char *));
77 int almost_equals __PROTO((int, const char *));
78 int isstring __PROTO((int));
79 int isanumber __PROTO((int));
80 int isletter __PROTO((int));
81 int is_definition __PROTO((int));
82 TBOOLEAN might_be_numeric __PROTO((int));
83 void copy_str __PROTO((char *, int, int));
84 size_t token_len __PROTO((int));
85 void capture __PROTO((char *, int, int, int));
86 void m_capture __PROTO((char **, int, int));
87 void m_quote_capture __PROTO((char **, int, int));
88 char *try_to_get_string __PROTO((void));
89 void parse_esc __PROTO((char *));
90 int type_udv __PROTO((int));
91 
92 char *gp_stradd __PROTO((const char *, const char *));
93 #define isstringvalue(c_token) (isstring(c_token) || type_udv(c_token)==STRING)
94 
95 /* HBB 20010726: IMHO this one belongs into alloc.c: */
96 char *gp_strdup __PROTO((const char *));
97 
98 /* HBB 20020405: moved this here, from axis.[ch] */
99 void gprintf __PROTO((char *, size_t, char *, double, double));
100 
101 /* Error message handling */
102 #if defined(VA_START) && defined(STDC_HEADERS)
103 #  if defined(__GNUC__)
104     void os_error __PROTO((int, const char *, ...)) __attribute__((noreturn));
105     void int_error __PROTO((int, const char *, ...)) __attribute__((noreturn));
106     void common_error_exit __PROTO((void)) __attribute__((noreturn));
107 #  elif defined(_MSC_VER)
108     __declspec(noreturn) void os_error(int, const char *, ...);
109     __declspec(noreturn) void int_error(int, const char *, ...);
110     __declspec(noreturn) void common_error_exit();
111 #  else
112     void os_error __PROTO((int, const char *, ...));
113     void int_error __PROTO((int, const char *, ...));
114     void common_error_exit __PROTO((void));
115 #  endif
116 void int_warn __PROTO((int, const char *, ...));
117 #else
118 void os_error __PROTO(());
119 void int_error __PROTO(());
120 void int_warn __PROTO(());
121 void common_error_exit __PROTO(());
122 #endif
123 
124 void squash_spaces __PROTO((char *s, int remain));
125 
126 TBOOLEAN existdir __PROTO((const char *));
127 TBOOLEAN existfile(const char *);
128 
129 char *getusername __PROTO((void));
130 
131 TBOOLEAN contains8bit __PROTO((const char *s));
132 TBOOLEAN utf8toulong __PROTO((unsigned long * wch, const char ** str));
133 TBOOLEAN is_sjis_lead_byte(char c);
134 size_t strlen_utf8 __PROTO((const char *s));
135 size_t strlen_sjis(const char *s);
136 size_t gp_strlen __PROTO((const char *s));
137 char * gp_strchrn __PROTO((const char *s, int N));
138 TBOOLEAN streq __PROTO((const char *a, const char *b));
139 size_t strappend(char **dest, size_t *size, size_t len, const char *src);
140 
141 char *num_to_str(double r);
142 char *value_to_str(struct value *val, TBOOLEAN need_quotes);
143 
144 /* To disallow 8-bit characters in variable names, set this to */
145 /* #define ALLOWED_8BITVAR(c) FALSE */
146 #define ALLOWED_8BITVAR(c) ((c)&0x80)
147 
148 #endif /* GNUPLOT_UTIL_H */
149