English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
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  
Old 19 June 2021, 22:25   #2
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
Quote:
Originally Posted by guy lateur View Post
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.

Typically, it is up to your code to initialize library bases, i.e.
Code:
RegexBase = OpenLibrary("regexp.library",version);
followed by a check whether the library open actually worked, and at the end of the program, a matching


Code:
CloseLibrary(RegexBase);

The library name you find in the documentation, and the name of the library base you find in the "proto" file.


For most standard system libraries, some compilers will create automatically code that opens the corresponding libraries if you don't do it yourself. Thus, you will typically get away by *not* having opened "dos.library" because the compiler startup code will do that for you.


As said, this is compiler specific, and it is certainly good practise to open the libraries you need yourself.
Thomas Richter is offline  
Old 20 June 2021, 14:50   #3
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Some additional comments:

You will never include a compiler-specific pragmas/ or inline/ file.
proto/regex.h
will include all you need and keeps your source easily portable between different compilers. Also the prototypes in
clib/regex_protos.h
are not needed, as
proto/regex.h
takes care of that as well.

The FD file is only needed if you want to build header files for a currently unsupported compiler.
phx is offline  
Old 20 June 2021, 21:16   #4
guy lateur
Registered User
 
guy lateur's Avatar
 
Join Date: May 2017
Location: Belgium
Age: 50
Posts: 334
Quote:
Originally Posted by Thomas Richter View Post
..
Quote:
Originally Posted by phx View Post
..
Thank you both for your input, this has certainly cleared up a few things!
guy lateur is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
New a500 56pin header xraynorm support.Hardware 7 31 December 2018 11:41
Amiga 500 internal floppy header rfancella support.Hardware 3 30 October 2015 00:48
A500 keyboard 8 pin header Connector xArtx support.Hardware 5 31 January 2015 15:46
where are header files located in GCC ? Morbane Coders. General 0 05 January 2012 11:42

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:03.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.06810 seconds with 15 queries