1 /*
2  * Grace - GRaphing, Advanced Computation and Exploration of data
3  *
4  * Home page: http://plasma-gate.weizmann.ac.il/Grace/
5  *
6  * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7  * Copyright (c) 1996-2001 Grace Development Team
8  *
9  * Maintained by Evgeny Stambulchik
10  *
11  *
12  *                           All Rights Reserved
13  *
14  *    This program is free software; you can redistribute it and/or modify
15  *    it under the terms of the GNU General Public License as published by
16  *    the Free Software Foundation; either version 2 of the License, or
17  *    (at your option) any later version.
18  *
19  *    This program is distributed in the hope that it will be useful,
20  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *    GNU General Public License for more details.
23  *
24  *    You should have received a copy of the GNU General Public License
25  *    along with this program; if not, write to the Free Software
26  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  */
28 
29 #ifndef __UTILS_H_
30 #define __UTILS_H_
31 
32 /* for size_t */
33 #include <sys/types.h>
34 
35 #define  PAD(bits, pad)  (((bits)+(pad)-1)&-(pad))
36 
37 #define MIN2(a, b) (((a) < (b)) ? a : b)
38 #define MAX2(a, b) (((a) > (b)) ? a : b)
39 #define MIN3(a, b, c) (((a) < (b)) ? MIN2(a, c) : MIN2(b, c))
40 #define MAX3(a, b, c) (((a) > (b)) ? MAX2(a, c) : MAX2(b, c))
41 
42 #define yes_or_no(x) ((x)?"yes":"no")
43 #define on_or_off(x) ((x)?"on":"off")
44 #define true_or_false(x) ((x)?"true":"false")
45 #define w_or_v(x) ((x == COORD_WORLD)?"world":"view")
46 
47 #define LFORMAT_TYPE_PLAIN      0
48 #define LFORMAT_TYPE_EXTENDED   1
49 
50 #define XCFREE(ptr) xfree(ptr); ptr = NULL
51 
52 #define PSTRING(s) ((s == NULL) ? "" : escapequotes(s))
53 
54 void *xmalloc(size_t size);
55 void *xcalloc(size_t nmemb, size_t size);
56 void *xrealloc(void *ptr, size_t size);
57 void xfree(void *ptr);
58 
59 void fswap(double *x, double *y);
60 void iswap(int *x, int *y);
61 int isoneof(int c, char *s);
62 int argmatch(char *s1, char *s2, int atleast);
63 void lowtoupper(char *s);
64 void convertchar(char *s);
65 int ilog2(int n);
66 double comp_area(int n, double *x, double *y);
67 double comp_perimeter(int n, double *x, double *y);
68 
69 char *create_fstring(int form, int prec, double loc, int type);
70 char *escapequotes (char *s);
71 
72 int sign(double a);
73 double mytrunc(double a);
74 
75 void bailout(void);
76 
77 void installSignal(void);
78 
79 int bin_dump(char *value, int i, int pad);
80 unsigned char reversebits(unsigned char inword);
81 
82 char *copy_string(char *dest, const char *src);
83 char *concat_strings(char *dest, const char *src);
84 int compare_strings(const char *s1, const char *s2);
85 
86 char *get_grace_home(void);
87 void set_grace_home(const char *dir);
88 
89 char *get_help_viewer(void);
90 void set_help_viewer(const char *dir);
91 
92 char *get_print_cmd(void);
93 void set_print_cmd(const char *cmd);
94 
95 char *get_editor(void);
96 void set_editor(const char *cmd);
97 
98 void set_docname(const char *s);
99 char *get_docname(void);
100 char *get_docbname(void);
101 
102 void errmsg(const char *msg);
103 void echomsg(char *msg);
104 void stufftext(char *msg);
105 
106 int yesnoterm(char *msg);
107 int yesno(char *msg, char *s1, char *s2, char *help_anchor);
108 
109 char *mybasename(const char *s);
110 
111 void expand_tilde(char *buf);
112 int set_workingdir(const char *wd);
113 char *get_workingdir(void);
114 
115 void init_username(void);
116 char *get_username(void);
117 
118 void init_userhome(void);
119 char *get_userhome(void);
120 
121 void update_app_title(void);
122 
123 void set_dirtystate(void);
124 void clear_dirtystate(void);
125 void lock_dirtystate(int flag);
126 int is_dirtystate(void);
127 
128 int system_wrap(const char *string);
129 void msleep_wrap(unsigned int msec);
130 
131 int init_locale(void);
132 void set_locale_num(int flag);
133 
134 long bi_version_id(void);
135 char *bi_version_string(void);
136 char *bi_system(void);
137 char *bi_date(void);
138 char *bi_gui(void);
139 #ifdef MOTIF_GUI
140 char *bi_gui_xbae(void);
141 #endif
142 char *bi_ccompiler(void);
143 char *bi_t1lib(void);
144 #ifdef HAVE_LIBPNG
145 char *bi_pnglib(void);
146 #endif
147 #ifdef HAVE_LIBJPEG
148 char *bi_libjpeg(void);
149 #endif
150 #ifdef HAVE_LIBPDF
151 char *bi_libpdf(void);
152 #endif
153 
154 
155 #ifdef DEBUG
156 void set_debuglevel(int level);
157 int get_debuglevel(void);
158 #endif
159 
160 #endif /* __UTILS_H_*/
161