hi Gawk Team!
some months ago i was sending here some of the @include directive
helpfull features - and i want to pay your attention again about one
small feature that i was suggesting:
all files that was @included as the part of the gawk's script source, including main file are present in the predefined global array PROCINFO[ "include" ] for
each file included:
@include "abc.gwk"
# PROCINFO[ "include" ][ "abc" ] = "filepath/" abc.gwk
this feature is able to know at the user level the exact filepath of
itself code.
at this moment i may provide at least two examples because of why this feature is really needfull:
1) as i said previously: an library may needs some files during i's initialization. and this file should be placed near with the file
@included. and there is no possibility to read that kind of files
because we don't know WHERE required file is located.
as example of such kind files i was reporting exact mylife-cases:
- library for generating graphic files was needs the default.bmp and
default palette files
- an text-macro service library was requring to load auto macro definition file
2) now there is another case why this feature will be really helpful:
- one of my gawk library have self-modification feature: it's reading
ITSELF FILE and compares it with the stored copy of itself file that
is placed NEAR ITSELF FILE. if files are not equal to each other then
copy of the file is refreshed and self-modification process performed generating new version of itself file.
after rewriting library-itself file by generated new itself-version
gawk's execution will be aborted because of requiring gawk script
restart.
the self-modification feature is allows to quckly operates with the
library's constant values.
in fact without this feature an multiple hardcoded filepaths are
using. this leads to fact that gawk script by default never can be
portable or have multiplatform support (the cases that i having in my
job)
the suggested feature is small, safe and strong.
may its have a chance just to be discussed by the Gawk Team? =)
note: possibly Dynamic Extensions may also needs in such like feature
with Respect
Denis
hi Gawk Team!
some months ago i was sending here some of the @include directive
helpfull features - and i want to pay your attention again about one
small feature that i was suggesting:
[...]
me gawk expirience is more than ten years.
the offer is extremely simple and specific, etc
me gawk expirience is more than ten years.needed for various parts of the code to work. where do I load them from?
the offer is extremely simple and specific. external files may be
PROCINFO[ "include" ][ filename(no ext) ] == full filepath to file included
I guess AWKPATH is the answer to all your questions.
In article <6235A9EC.6060003@users.sourceforge.net>,
Manuel Collado <m-collado@users.sourceforge.net> wrote:
I guess AWKPATH is the answer to all your questions.
No, it isn't. Certainly not the answer to the question as posed (which is
"I want to know from whence any/all of my include files came").
Although, as I hint in my previous response, a sensible setting of AWKPATH and some cleanup/re-organization of OP's software envrionment (aka, ecosystem) may, in fact, be part of the long term solution to OP's issues.
But, the fact is, we still really don't know (and probably never will) what OP's real, underlying problem is.
In article<6235A9EC.6060003@users.sourceforge.net>,As I understand it, @include only takes strings (not variables) so the 'basename' of the file to be included is always known. And AWKPATH is
Manuel Collado<m-collado@users.sourceforge.net> wrote:
I guess AWKPATH is the answer to all your questions.No, it isn't. Certainly not the answer to the question as posed (which is
"I want to know from whence any/all of my include files came"
On 19/03/2022 11:39, Kenny McCormack wrote:
In article<6235A9EC.6060003@users.sourceforge.net>,
Manuel Collado<m-collado@users.sourceforge.net> wrote:
I guess AWKPATH is the answer to all your questions.No, it isn't. Certainly not the answer to the question as posed (which is >> "I want to know from whence any/all of my include files came"
As I understand it, @include only takes strings (not variables) so the >'basename' of the file to be included is always known.
And AWKPATH is
the only environment variable (plus the current directory) which tells
the @include mechanism where to look.
Since the value of AWKPATH is available to the running AWK program, it
would seem to be simple enough to write a function that takes the
include file name and does an equivalent search through AWKPATH,
stopping at the first match which will be the file that was included.
Nested @includes (are they allowed?)
could do the same thing themselves
so that a results array equivalent to PROCINFO[ "include" ][ filename(no >ext) ] is built-up.
Am I missing something here?
On 19/03/2022 11:39, Kenny McCormack wrote:
In article<6235A9EC.6060003@users.sourceforge.net>,As I understand it, @include only takes strings (not variables) so the 'basename' of the file to be included is always known. And AWKPATH is
Manuel Collado<m-collado@users.sourceforge.net> wrote:
I guess AWKPATH is the answer to all your questions.No, it isn't. Certainly not the answer to the question as posed
(which is
"I want to know from whence any/all of my include files came"
the only environment variable (plus the current directory) which tells
the @include mechanism where to look.
Since the value of AWKPATH is available to the running AWK program, it
would seem to be simple enough to write a function that takes the
include file name and does an equivalent search through AWKPATH,
stopping at the first match which will be the file that was included.
El 20/03/2022 a las 0:09, Bruce Horrocks escribió:--- Synchronet 3.19c-Linux NewsLink 1.113
On 19/03/2022 11:39, Kenny McCormack wrote:
In article<6235A9EC.6060003@users.sourceforge.net>,As I understand it, @include only takes strings (not variables) so the
Manuel Collado<m-collado@users.sourceforge.net> wrote:
I guess AWKPATH is the answer to all your questions.No, it isn't. Certainly not the answer to the question as posed
(which is
"I want to know from whence any/all of my include files came"
'basename' of the file to be included is always known. And AWKPATH is
the only environment variable (plus the current directory) which tells
the @include mechanism where to look.
Since the value of AWKPATH is available to the running AWK program, it
would seem to be simple enough to write a function that takes the
include file name and does an equivalent search through AWKPATH,
stopping at the first match which will be the file that was included.
Yes. What about the next code?
# Check if a file exists
function file_exists(file, rc, line) {
rc = getline line < file
if (rc >= 0) {
close(file)
return 1
} else {
return 0
}
}
# Return the effective path of an @include file
function which(script, awkpath, k) {
split(ENVIRON["AWKPATH"], awkpath, ":")
for (k=1; k in awkpath; k++) {
if (file_exists(awkpath[k] "/" script)) {
return awkpath[k] "/" script
} else if (file_exists(awkpath[k] "/" script ".awk")) {
return awkpath[k] "/" script ".awk"
}
}
}
The OP could test it and tell us if it solves the problem.
--
Manuel Collado - http://mcollado.z15.es
This is similar to the code in the igawk.sh script which comes
with the gawk distribution. That program could easily be modified
to set up an array with the information that the OP desired.
As such, it is rather unlikely that his requested feature would
be added to gawk itself.
If anyone here ... could explain to me what they think OP's actually
problem is, I'd be most grateful.
On 20/03/2022 16:04, Kenny McCormack wrote:
If anyone here ... could explain to me what they think OP's actually
problem is, I'd be most grateful.
I think Digi's scenario is that he is using AWK as a code generator to create a dynamic piece of AWK code. The dynamic code is, I'm assuming, mostly a framework with a bunch of @includes that are inserted by the
code generator. When the dynamic code is run the @includes pull in the actual code and, hey presto, it all works.
To complicate things further, some of those @included libraries need to
read in a data file that is specific to the library in some way, and
held in the same source directory as the @include file itself.
Hence the request: if he could easily obtain the location of the
@included file then he could easily know where to read the data file.
If that is indeed the requirement then Manuel Collado's sample code that checks for a file and get its path would do the job.
On 2022-03-21, Mack The Knife <mack@the-knife.org> wrote:
This is similar to the code in the igawk.sh script which comes
with the gawk distribution. That program could easily be modified
to set up an array with the information that the OP desired.
As such, it is rather unlikely that his requested feature would
be added to gawk itself.
The new Awk with C Preprocessor (cppawk) solves the problem
like this:
In article <20220321072908.947@kylheku.com>,
Kaz Kylheku <480-992-1380@kylheku.com> wrote:
On 2022-03-21, Mack The Knife <mack@the-knife.org> wrote:
This is similar to the code in the igawk.sh script which comes
with the gawk distribution. That program could easily be modified
to set up an array with the information that the OP desired.
As such, it is rather unlikely that his requested feature would
be added to gawk itself.
The new Awk with C Preprocessor (cppawk) solves the problem
like this:
No, it doesn't, since the OP wanted access to the information from
within the running awk program.
hello
sorry i have a lot of job last week.
i see in gawk manual 2.7 - there is a some recent changes about it...
and it describes exactly my case: many libraries, with a separate folder for each. and all these folders are located in one global folder. suppose I point the AWKPATH to this global folder. but i cannot performing @include by the filepath that is RELATIVE to AWKPATH:
- library's global folder (AWKPATH) is located at:
Directory of D:/a/ab/abc/mod/
02-Apr-22 03:04 <DIR> arr
27-Mar-22 20:20 <DIR> audio
27-Mar-22 20:20 <DIR> class
27-Mar-22 20:20 <DIR> core
27-Mar-22 20:20 <DIR> env
27-Mar-22 20:20 <DIR> gmatch
27-Mar-22 20:20 <DIR> grp
27-Mar-22 20:20 <DIR> io
27-Mar-22 20:20 <DIR> list
27-Mar-22 20:20 <DIR> mac
27-Mar-22 20:20 <DIR> mpu
27-Mar-22 20:20 <DIR> op
27-Mar-22 20:20 <DIR> other
27-Mar-22 20:20 <DIR> rexp
27-Mar-22 20:20 <DIR> rexp2
27-Mar-22 20:20 <DIR> smatch
27-Mar-22 20:20 <DIR> str
27-Mar-22 20:20 <DIR> term
27-Mar-22 20:20 <DIR> uid
27-Mar-22 20:20 <DIR> wav
14-Dec-21 03:24 13,369 _env.inc
27-Mar-22 20:20 <DIR> _grp
each folder is the library's folder that is typically contains library's source file for including:
Directory of D:/a/ab/abc/mod/arr/
30-Mar-22 16:35 117,290 _arr.mod
30-Mar-22 16:35 117,290 _arr.inc
30-Mar-22 16:35 117,290 _arr.mod.prev
- executing gawk script:
@include "arr/_arr.mod"
and FAILs because of the '/'-character is exist in the RELATIVE (by the actual) filepath.
situation. this leads that filepath for @include directive must be ALWAYS absolute. feature of the AWKPATH is completely isn't useful for me.
my current solution(windows) is making some network file share (env) that is using like AWKPATH do. all include directives then allows to be looks like:
@include "//env/mod/arr/_arr.mod"
ok. but this is not the all.
sometimes, included library contains nested includes. and these filepaths are also needs to be hardcoded. everwhere - there are only hardcoded filepaths:
@include "//env/mod/arr/_arr.inc"
this leads to many problems including such kind of questions like: portability ? multiplatforming? changing version of the librarys?
I was offering several solutions:
- environment variables are able to read in filepaths for @include:
like: %ENVIRON%
@include "%env%arr/_arr.mod"
- current folder for a subincludings located in a file - is the folder where this file is located:
...
@include "//env/mod/arr/_arr.mod"
...
_arr.mod:
...
@include "_arr.inc" # the path is the original's file (_arr.mod) folder: "%env%arr/"
...
as for the requested feature, I look even further than the described problems with include. it's about similar problems at the user level.--
I think there is no need to describe all the cases why and when any library needs some kind of it's internal file. there are quite a lot of such cases. I am sure that this question is clear to everyone. so as the result, we have the same hardcoded filepaths - but now also at the gawk user level.
that's the reason of requesting feature.
thnx)
D
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 793 |
Nodes: | 10 (1 / 9) |
Uptime: | 38:26:06 |
Calls: | 11,106 |
Calls today: | 3 |
Files: | 186,086 |
Messages: | 1,751,447 |