Mail Archives: djgpp/1998/02/17/16:24:35
From: | Shaun Jackman <sjackman AT rogers DOT wave DOT ca>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Modify global variables from within a program
|
Date: | Sun, 15 Feb 1998 19:44:02 -0800
|
Organization: | ARC Technologies
|
Lines: | 48
|
Message-ID: | <34E7B601.DAE03C63@rogers.wave.ca>
|
NNTP-Posting-Host: | pc-15794.bc.rogers.wave.ca
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
I want to be able to modify global variables from within the program I
am writing, through a console interface.
To implement this I wrote a little script:
nm *.o|sort|uniq|grep 00000004|tail -n +2|tr \040 \t|cut -f 3>out1
paste -d \"\" NUL out1 NUL>out2
paste -d (&,); register NUL out1 out2 NUL NUL|uniq>globals
echo void register_globals() {>globals.c
cat globals>>globals.c
echo }>>globals.c
(note: the file "register" is simply a file containing 100 lines of
"register_global")
This scans all the *.o files in the current directory, extracts the
global variables, and writes a c file called globals.c
For example, if there were a bunch of some source files that declared
int globalvar1;
int globalvar2;
int globalvar3;
Then my script would write a c file:
void register_globals() {
register_global(&globalvar1, "globalvar1");
register_global(&globalvar2, "globalvar2");
register_global(&globalvar3, "globalvar3");
}
which I could then compile and link into the program.
(assuming there is a function called register_global that hashes the
string and links it to the variable, to make it available for the
console)
Unfortuneately, I haven't been using the unix textutils very long, and
I'm not quite sure how to use them properly.
What this script actually gives is:
void register_globals() {
register_global(&_globalvar1, "_globalvar1");
register_global(&_globalvar2, "_globalvar2");
register_global(&_globalvar3, "_globalvar3");
register_global(&,);
}
How can I fix my script?
Or, is there a better way to do what I'm doing?
Thanks for your help,
Please reply by e-mail as well if possible,
Shaun Jackman
- Raw text -