Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / bin / tttar / tttar_utils.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: tttar_utils.h /main/3 1995/10/20 17:01:53 rswiston $                                                         */
28 /*
29  * tttar_utils.h - Utilities for the ToolTalk archive tool.
30  *
31  * Copyright (c) 1990 by Sun Microsystems, Inc.
32  */
33
34 #ifndef _LSTAR_UTILS_H
35 #define _LSTAR_UTILS_H
36
37 #include <api/c/tt_c.h>
38 #include <util/tt_string.h>
39
40
41 /*
42  * External Variables
43  */
44
45 extern Tt_status        err_noted;              // Used by note_err() macro.
46 extern char            *ptr_returned;           // Used by note_ptr_err() macro.
47 extern void            *voidptr_returned;       // Used by note_voidptr_err() macro.
48 extern Tt_message       msg_returned;           // Used by note_msg_err() macro.
49 extern int              int_returned;           // Used by note_int_err() macro.
50 extern char             our_process_name[];
51
52 /*
53  * Constants
54  */
55
56 /*
57  * STRING_EQUAL() - Check 2 strings for equality.
58  */
59 #define STRING_EQUAL(s1,s2) ( strcmp( s1, s2 ) == 0 )
60
61 /*
62  * NULL_OR_EMPTY() - Is this string ptr NULL or empty?
63  */
64 #define NULL_OR_EMPTY(p) (( (char *)p == NULL ) || ( *(char *)p == '\0' ))
65
66 /*
67  * IS_TT_ERR() - Is this Tt_status neither TT_OK nor a TT_WARN?
68  */
69 #define IS_TT_ERR(err)  ( err > TT_WRN_LAST )
70
71 /*
72  * stringify() - Turn a macro argument into a string.
73  *      gross Reiserism, use # in ANSI C
74  */
75 #if defined(__STDC__)
76 #define stringify(s) #s
77 #else
78 /* gross Reiserism, use # in ANSI C */
79 #define stringify(s) "s"
80 #endif
81
82 /*
83  * note_err() - Note any error corresponding to this Tt_status
84  *      expression, returning the error code
85  */
86 #define note_err(expression)                                    \
87         (   ( TT_OK == ( err_noted = expression))               \
88           ? TT_OK                                               \
89           : note_error( err_noted, stringify(expression),       \
90                         __FILE__, __LINE__ ))
91
92
93 /*
94  * note_ptr_err() - Assign the (char *) expression to ptr_returned,
95  *      noting any error on stderr if error isn't TT_OK, and
96  *      return the error code
97  */
98 #define note_ptr_err(expression)                                        \
99         (   (    TT_OK                                                  \
100               == ( err_noted =                                          \
101                    tt_pointer_error(ptr_returned = expression)))        \
102           ? TT_OK                                                       \
103           : note_error( err_noted, stringify(expression),               \
104                         __FILE__, __LINE__ ))
105
106 /*
107  * note_int_err() - Assign the (int) expression to int_returned,
108  *      noting any error on stderr if error isn't TT_OK, and
109  *      return the error code
110  */
111 #define note_int_err(expression)                                        \
112         (   (    TT_OK                                                  \
113               == ( err_noted =                                          \
114                    tt_int_error(int_returned = expression)))            \
115           ? TT_OK                                                       \
116           : note_error( err_noted, stringify(expression),               \
117                         __FILE__, __LINE__ ))
118
119 /*
120  * note_msg_err() - Assign the expression to msg_returned,
121  *      noting any error on stderr if error isn't TT_OK, and
122  *      return the error code
123  */
124 #define note_msg_err(expression)                                        \
125         (   (    TT_OK                                                  \
126               == ( err_noted =                                          \
127                    tt_pointer_error(msg_returned = expression)))        \
128           ? TT_OK                                                       \
129           : note_error( err_noted, stringify(expression),               \
130                         __FILE__, __LINE__ ))
131
132 /*
133  * note_voidptr_err() - Assign the expression to voidptr_returned,
134  *      noting any error on stderr if error isn't TT_OK, and
135  *      return the error code
136  */
137 #define note_voidptr_err(expression)                                    \
138         (   (    TT_OK                                                  \
139               == ( err_noted =                                          \
140                    tt_pointer_error(voidptr_returned = expression)))    \
141           ? TT_OK                                                       \
142           : note_error( err_noted, stringify(expression),               \
143                         __FILE__, __LINE__ ))
144
145 /*
146  * Procedure declarations
147  */
148
149 Tt_status       note_error( Tt_status error, char *expression, 
150                             char *file, int line );
151 void            my_tt_free( caddr_t p );
152 void            my_tt_release( int mark );
153 bool_t          in_list( _Tt_string s, _Tt_string_list_ptr list );
154
155 #endif /* _LSTAR_UTILS_H */