/[webpac]/trunk/openisis/luti.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/openisis/luti.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 239 - (show annotations)
Mon Mar 8 17:49:13 2004 UTC (20 years ago) by dpavlin
File MIME type: text/plain
File size: 4903 byte(s)
including openisis 0.9.0 into webpac tree

1 /*
2 openisis - an open implementation of the CDS/ISIS database
3 Version 0.8.x (patchlevel see file Version)
4 Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library 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 GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 see README for more information
21 EOH */
22 #ifndef LUTI_H
23
24 /*
25 $Id: luti.h,v 1.30 2003/04/17 13:14:41 mawag Exp $
26 common utilities for openisis lib implementation.
27 */
28
29 #include <assert.h>
30
31
32 #include "loi.h"
33
34
35 extern LogLevel log_lev;
36 #define LOG_DO( lev ) ((lev) <= log_lev)
37 #define LOG_DONT( lev ) ((lev) > log_lev)
38
39 /**
40 NOTE: unlike sMsg, this directly and immediatly lio_writes to file 2.
41 So this is more expensive, but threadsafe.
42
43 print some log message to stderr or some configured logdevice.
44 for errors, use one of the LERR_xxx codes or
45 a loglevel of SYSERR or IOERR to determine the error from errno.
46 loglevels FATAL and ERROR, when used w/o error code,
47 assum IDIOT and INVAL, resp.
48 other logging levels do not assume an error (i.e. 0 == -LERR_OK).
49 any error or loglevel code implies stream 2.
50 @param code errorcode (-LERR_xxx) or loglevel as described above
51 @return a non-positive code as described above
52 */
53 extern int log_msg ( int code, const char *fmt, ... );
54 #ifndef NDEBUG
55 # define LOG_DBG log_msg
56 #else
57 # ifdef __GNUC__
58 # define LOG_DBG( args... )
59 # else
60 # define LOG_DBG (void) /* compiler should dispose statement off */
61 # endif
62 #endif
63
64 #define LOG_OTO( to, args ) do { ret = log_msg args; goto to; } while (0)
65
66 /* content logging is usually on level LOG_TRACE */
67 #define LOG_STR( rec, desc ) log_str( LOG_TRACE, rec, desc )
68 #define LOG_HEX( mem, len ) log_hex( LOG_TRACE, mem, len )
69
70 /**
71 dump a record
72 @param level loglevel necessary for output to occurr.
73 */
74 extern void log_str ( LogLevel level, int *rec, const char **desc );
75
76 /*
77 * print fields of record to stderr
78 * @param level if negative, print msg to stdout
79 * @param delim field delimiter (default '; ')
80 */
81 extern void log_rec (int level,
82 Rec *rec, const char *msg, const char *delim);
83
84 /**
85 hexdump memory
86 @param level loglevel necessary for output to occurr.
87 */
88 extern void log_hex ( LogLevel level, const void *mem, int len );
89
90 /**
91 do a malloc and print error if out of memory.
92 */
93 extern void *lmalloc ( int size );
94
95 /* more specific log functions in log.h */
96
97 /* printint: optional sign, up to 10 digits, 0 byte.
98 buf must be at least 12 bytes long.
99 return length w/o the 0 byte.
100 */
101 extern int lprint ( void *buf, int i );
102
103
104 /* Lookup of id from name */
105 typedef struct OpenIsisLT *LutiLT;
106
107 /* create lookup table */
108 extern LutiLT luti_ltnew ();
109 /* destroy lookup table */
110 extern void luti_ltdel (LutiLT lt);
111 /* add entry */
112 extern void luti_ltadd (LutiLT lt, const char *name, int id);
113 /* get id for name */
114 extern int luti_ltget (LutiLT lt, const char *name);
115 /* remove entry */
116 extern void luti_ltrmv (LutiLT lt, const char *name);
117
118 /* get fdt from rec */
119 extern Fdt* luti_fdt_from_rec (Rec *rec);
120
121 /* get fd, tag, occurence from path */
122 extern const char* luti_parse_path (
123 const char *path, const Fdt *fdt, Fd **fd, int *tag, int *occ);
124
125 /* extract embedded record from envelope */
126 extern Rec* luti_unwrap (Rec *env, int *pos, int tag, int dbid);
127
128 /* extract embedded record from envelope */
129 extern Rec* luti_getembed (
130 Rec *env, const char *path, const Fdt *fdt);
131
132 /* embed record in envelope */
133 extern Rec* luti_wrap (Rec *env, Rec *rec, int tag);
134
135 /* append src fields to tgt */
136 extern Rec* luti_append (Rec *tgt, Rec *src);
137
138 /** incr base ptr by incr*siz, if 0 < maxnum && *num < maxnum
139 new allocated range is memsetted 0
140 NOTE: base is address of base for reallocation (whatever_type**)
141 @return index of first new allocated address in array or -1 if out of mem
142 */
143 extern int luti_ptrincr (
144 void *base, int *num, int incr, int siz, int maxnum);
145
146 /** free pointer array
147 */
148 extern void luti_free (void **arr, int num);
149
150 /** check whether string represents a boolean value
151 @return 0 str is false,
152 1 str is true,
153 -1 str is something else
154 */
155 extern int luti_true (const char *str, int len);
156
157 /**
158 s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
159 forced to non-negative
160 */
161 extern int lhash ( const char *str, int len );
162
163 extern const char luti_hex[16]; /* '0'..'9','a'..'f' */
164
165 #define LUTI_H
166 #endif /* LUTI_H */

  ViewVC Help
Powered by ViewVC 1.1.26