1 /*
2  *      atclib.h
3  *	An excerpt of the header for Atclib
4  */
5 
6 
7 /*
8 This file is part of Atclib.
9 
10 Atclib is Copyright � 1995-1999 Andr� Majorel.
11 
12 This library is free software; you can redistribute it and/or
13 modify it under the terms of the GNU Library General Public
14 License as published by the Free Software Foundation; either
15 version 2 of the License, or (at your option) any later version.
16 
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 Library General Public License for more details.
21 
22 You should have received a copy of the GNU Library General Public
23 License along with this library; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 02111-1307, USA.
26 */
27 
28 
29 #if !defined(AL_AATCLIB_H)  /* To be immune from double inclusion */
30 #define AL_AATCLIB_H        /* To be immune from double inclusion */
31 
32 /* WARNING
33 You should never ever define AL_AILLEGAL_ACCESS. This macro is used
34 to restrict access to information that is considered private,
35 undocumented and that can be changed without notice. Only Atclib
36 modules can define it, not application programs.
37 */
38 
39 #ifndef FILE
40 #include <stdio.h>
41 #endif
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /*
48  *	al_a*
49  *	General
50  */
51 /* This is meant to be an even more invalid pointer than NULL */
52 #define AL_AINVALIDPOINTER ((void *)-1)
53 
54 /* To size_t what INT_MAX is to int. ANSI should have provided it! */
55 #define AL_ASIZE_T_MAX ((size_t)(((size_t)0)-1))
56 
57 /* min and max are not available everywhere */
58 #define	al_amin(a,b) ((a) < (b) ? (a) : (b))
59 #define	al_amax(a,b) ((a) > (b) ? (a) : (b))
60 
61 /* Common flags */
62 #define AL_AICASE  0x0001  /* Ignore case when matching strings */
63 
64 typedef       char *al_as_t;   /* String */
65 typedef const char *al_acs_t;  /* Constant string */
66 
67 /* Useful when you need a specific number of bits/bytes */
68 typedef unsigned char  al_au1_t;
69 typedef   signed char  al_as1_t;
70 typedef unsigned short al_au2_t;
71 typedef   signed short al_as2_t;
72 typedef unsigned long  al_au4_t;
73 typedef   signed long  al_as4_t;
74 
75 extern int al_aerrno;
76 #define AL_ABADL      1  /* Not a valid list pointer */
77 #define AL_AEOL       2  /* Attempt to read at end of list or step past it */
78 #define AL_AINVAL     3  /* Invalid argument */
79 #define AL_ANOFIX     4  /* Not a fixed element length list */
80 #define AL_ANOMEM     5  /* Not enough memory */
81 #define AL_ANOVAR     6  /* Not a variable element length list */
82 #define AL_AOVERFLOW  7  /* Buffer overflow */
83 al_acs_t al_astrerror (int e);
84 
85 extern const char al_adigits[36];  /* Contains 0-9A-Z */
86 
87 
88 /*
89  *	al_f*
90  *	Filesystem and disks
91  */
92 /* FIXME how do you port this to UNIX ? */
93 #define AL_FDRV 2                       /* "<d>:" */
94 #define AL_FPATH 65                     /* <64_characters>"\" */
95 #define AL_FBASE 8                      /* "ABCDEFGH" */
96 #define AL_FEXT 4                       /* ".IJK" + 3 characters */
97 #define AL_FBE (AL_FBASE+AL_FEXT)
98                                         /* complete spec (by definition) */
99 #define AL_FSPEC (AL_FDRV+AL_FPATH+AL_FBASE+AL_FEXT)
100 #define AL_FPCSD '\\'                   /* Path component separator for DOS */
101 #define AL_FPCSU '/'                    /* Path component separator for Unix */
102 #define al_fispcsd(c) ((c)=='\\'||(c)=='/') /* Is a path component separator? */
103 #define al_fispcsu(c) ((c)=='/')            /* Is a path component separator? */
104 #define AL_FPS '/'
105 #define al_fisps(c) ((c)=='/')
106 typedef char al_fdrv_t [AL_FDRV+1 ];
107 typedef char al_fpath_t[AL_FPATH+1];
108 typedef char al_fbase_t[AL_FBASE+1];
109 typedef char al_fext_t [AL_FEXT+1 ];
110 typedef char al_fbe_t  [AL_FBE+1  ];
111 typedef char al_fspec_t[AL_FSPEC+1];
112 void al_fana     (al_acs_t ispec, al_as_t odrv, al_as_t opath, al_as_t obase, al_as_t oext);
113 int al_fcanon    (al_acs_t strin, al_as_t strout);
114 int al_fchdir    (al_acs_t path);
115 int al_fnature   (al_acs_t spec);
116 int al_fmakepath (al_acs_t path);
117 
118 
119 /*
120  *	al_l*
121  *	Linked lists
122  */
123 #ifdef AL_AILLEGAL_ACCESS
124 enum { AL_LLIST_MAGIC = 0x18a3 };  /* Magic number for al_llist_t */
125 #define al_lcheckmagic(list) \
126 do\
127   if (list == NULL || list->magic != AL_LLIST_MAGIC)\
128     { al_aerrno = AL_ABADL; return AL_ABADL; }\
129 while (0)
130 /* FIXME: this code assumes that (union *) and (void *) have the same
131    size. I don't see why they wouldn't but I don't think this is
132    warranted by the standard. */
133 typedef struct             /* One element of a fixed-length list */
134   {
135   void   *next;            /* Never used (overlaid by al_lelt_t.next) */
136   char data[1];          /* First char of data buffer */
137   } al_leltfix_t;
138 
139 typedef struct             /* One element of a variable-length list */
140   {
141   void   *next;            /* Never used (overlaid by al_lelt_t.next) */
142   size_t length;           /* Length of the element */
143   char data[1];          /* First char of data buffer */
144   } al_leltvar_t;
145 
146 typedef union al_lelt_u    /* One element of any list */
147   {
148   union al_lelt_u *next;   /* Pointer to next element in the list or NULL */
149   al_leltfix_t     f;      /* The fixed-length flavour */
150   al_leltvar_t     v;      /* The variable-length flavour */
151   } al_lelt_t;
152 
153 struct al_llist_s          /* One instance of this per list */
154   {
155   unsigned   magic;        /* Magic number to validate the structure */
156   size_t     length;       /* Size of an element in bytes or 0 */
157   al_lelt_t *first;        /* First element of the list (or NULL) */
158   al_lelt_t *current;      /* Current element */
159   int        ateol;        /* Current is not current but previous */
160   long       curno;        /* No. of current element */
161   al_lelt_t *prev;         /* Previous element (or NULL) */
162   long       total;        /* Total number of elements */
163   };
164 
165 struct al_lpos_s           /* Type used by al_lgetpos and al_lsetpos to store pointer position */
166   {
167   al_lelt_t *current;
168   int        ateol;
169   long       curno;
170   al_lelt_t *prev;
171   };
172 #endif
173 
174 typedef struct al_llist_s al_llist_t;
175 typedef struct al_lpos_s  al_lpos_t;
176 
177 int    al_leol   (al_llist_t *l);
178 long   al_lcount   (al_llist_t *l);
179 al_llist_t *al_lcreate (size_t eltsz);
180 int    al_ldelete  (al_llist_t *l);
181 int    al_ldiscard (al_llist_t *l);
182 int    al_lgetpos  (al_llist_t *l, al_lpos_t *pos);
183 int    al_linsert  (al_llist_t *l, const void *buf);
184 int    al_linsertl (al_llist_t *l, const void *buf, size_t length);
185 size_t al_llength  (al_llist_t *l);
186 int    al_lpeek    (al_llist_t *l, void *buf);
187 int    al_lpeekl   (al_llist_t *l, void *buf, size_t *length);
188 int    al_lpoke    (al_llist_t *l, const void *buf);
189 int    al_lpokel   (al_llist_t *l, const void *buf, size_t length);
190 void  *al_lptr     (al_llist_t *l);
191 int    al_lread    (al_llist_t *l, void *buf);
192 int    al_lreadl   (al_llist_t *l, void *buf, size_t *length);
193 int    al_lrewind  (al_llist_t *l);
194 int    al_lseek    (al_llist_t *l, long offset, int origin);
195 int    al_lsetpos  (al_llist_t *l, const al_lpos_t *pos);
196 int    al_lstep    (al_llist_t *l);
197 long   al_ltell    (al_llist_t *l);
198 int    al_lwrite   (al_llist_t *l, const void *buf);
199 int    al_lwritel  (al_llist_t *l, const void *buf, size_t length);
200 
201 
202 /*
203  *	al_s*
204  *	Strings
205  */
206 int    al_sapc      (al_as_t dest, char   source, size_t maxlen);
207 int    al_saps      (al_as_t dest, al_acs_t source, size_t maxlen);
208 int    al_sapslower (al_as_t dest, al_acs_t source, size_t maxlen);
209 int    al_sapsupper (al_as_t dest, al_acs_t source, size_t maxlen);
210 int    al_scpc      (al_as_t dest, char   source, size_t maxlen);
211 int    al_scps      (al_as_t dest, al_acs_t source, size_t maxlen);
212 int    al_scpslower (al_as_t dest, al_acs_t source, size_t maxlen);
213 int    al_scpsupper (al_as_t dest, al_acs_t source, size_t maxlen);
214 int    al_sbegins   (al_acs_t mainstr, al_acs_t substr);
215 char  *al_sdup      (al_acs_t str);
216 int    al_sends     (al_acs_t mainstr, al_acs_t substr);
217 size_t al_sfirsts   (al_acs_t s1, al_acs_t s2, int flags);
218 size_t al_sfirstw   (al_acs_t s1, al_acs_t s2, int flags);
219 int    al_sisnum    (al_acs_t str);
220 int    al_strOLC    (al_acs_t str, char chr);
221 #define AL_SICASE 0x01  /* Ignore case when matching */
222 #define AL_SDOS   0x02  /* Dot is special and "\" is same as "/" */
223 #define AL_SLDOT  0x04  /* A leading dot "." is a special character */
224 #define AL_SSLASH 0x08  /* The slash "/" is a special character */
225 #define AL_SESC   0x10  /* The backslash "\" escapes "*" "?" and "[" */
226 int al_swcmatch (al_acs_t pattern, al_acs_t string, int flags);
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 #endif  /* To be immune from double inclusion */
232 
233