View Single Post
Old 19 June 2021, 19:24   #1
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Using libraries and header files

Lately I've been taking my first steps in some C development for classic Amiga systems. I was looking for support for regular expressions, and I found this library on Aminet: https://aminet.net/package/util/libs/regex_ranieri I'm using SAS/C for now, so I'll focus on that (might switch to vbcc later, though). The archive has an include folder specifically for SAS/C, containing 4 header files. It's not 100% clear to me what every file does or represents, so I'll present here what I think is going on. It's been more than 20 years since I did any development in C, so please bear with me..

The first file is
proto/regex.h
. This file (in)directly includes all other files, so I'm assuming this is the file I should include in my code. This file declares this:
extern struct Library *RegexBase
. I've seen similar declarations in other libraries, so I guess this must be a standard way of doing things. However, I've never found where this struct actually gets initialised. Is there some code added by the compiler/linker that does this? I feel like there's a bit of black magic going on here.

The file
proto/regex.h
includes the second file,
pragmas/regex-pragmas.h
. This file contains several directives like this one:
#pragma libcall RegexBase regcomp 24 09803
. I'm assuming these connect the C versions of the functions (eg, regcomp) to an entry point/offset in the library. It needs the aforementioned RegexBase for that, which would make sense.

The file
proto/regex.h
also includes the third file,
clib/regex-protos.h
. This contains the regular C function prototypes, like
int regcomp(regex_t *, const char *, int)
. Just like any other prototypes, these are needed for compilation, so it makes sense they have to be in there somewhere.

The third file includes the fourth and last header file,
libraries/regex.h
, which contains some struct definitions like
regex_t
and
regmatch_t
. It also defines some flags for compiling and executing the regular expressions, and some error codes. Makes sense.

Finally, there's a file named
fd/regex_lib.fd
. It contains stuff like
##base _RegexBase
and
##bias 30
. It also contains lines like this:
regcomp(preg,pattern,cflags)(a0/a1,d0)
, which tells which C arguments correspond to which registers. I understand this is needed to be able to call the routines in the library, but I'm not sure how this info is used or when this gets invoked.

So I guess my main question is how this RegexBase thing works. And this fd thing. Also, if anything I said above is wrong or incomplete, please let me know. Like I said earlier, most of what I find in this library, I also come across in other contexts, so it would be helpful if I could get a clear picture of what exactly is going on and why. If you know of any places where I can read up on this subject, please let me know. TIA for any input!
guy lateur is offline  
 
Page generated in 0.07802 seconds with 11 queries