Includes ?? 
Author Message
 Includes ??

Hi,
    I think I knew how to do that with awk before :
    I have a large and complex program that I need to slice in multiple
files that I gather in a main one just like in C with the "include"
pre-processing command.
    Any idea please ?

--
 Cordialement,

Ghislain Benrais
Tel : 01 41 86 22 00
Fax : 01 41 86 22 39
CSA TMO



Fri, 08 Nov 2002 03:00:00 GMT  
 Includes ??


Quote:
>Hi,
>    I think I knew how to do that with awk before :
>    I have a large and complex program that I need to slice in multiple
>files that I gather in a main one just like in C with the "include"
>pre-processing command.
>    Any idea please ?

use multiple -f scripts

e.g.

awk -f awkscript1 -f awkscript2 -f awkscript3 infile > outfile

man awk

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Fri, 08 Nov 2002 03:00:00 GMT  
 Includes ??

Quote:



>>Hi,
>>    I think I knew how to do that with awk before :
>>    I have a large and complex program that I need to slice in multiple
>>files that I gather in a main one just like in C with the "include"
>>pre-processing command.
>>    Any idea please ?

>use multiple -f scripts

>e.g.

>awk -f awkscript1 -f awkscript2 -f awkscript3 infile > outfile

Note that this doesn't work under Solaris (where awk is oawk).

This method does work in (Solaris) nawk, and in most enhanced AWK's
(gawk,mawk,tawk).

In addition:

        1) In gawk, you can use "igawk"
        2) In Thompson AWK, you can put them in separate files and compile
           them together into an executable.

To be honest, the lack of a good include capability in T-AWK is a little
annoying.  They expect you to get around it by using a Makefile.

You could probably hack something up in m4 if you cared to.



Fri, 08 Nov 2002 03:00:00 GMT  
 Includes ??


Quote:
>Hi,
>    I think I knew how to do that with awk before :
>    I have a large and complex program that I need to slice in multiple
>files that I gather in a main one just like in C with the "include"
>pre-processing command.
>    Any idea please ?

Perhaps I am being too simplistic, but if all you are trying to
do is to concatinate many (small) component awk programs into one
why not do it with
    cat prog1 prog2 prog3 prog4 ... > temp.awk
    awk -f temp.awk
 You can use the * facility to save you listing individual programs

Mark
---
Mark Katz
Mark-it, London. Delivering MR-IT/Internet solutions
Tel: (44) 20-8731 7516, Fax: (44) 20-8458 9554
For latest information about ISPC/ITE - see http://www.e-tabs.com



Fri, 08 Nov 2002 03:00:00 GMT  
 Includes ??

Quote:



>> I have a large and complex program that I need to slice
>> in multiple files that I gather in a main one just like
>> in C with the "include" pre-processing command.
>> Any idea please ?
>Perhaps I am being too simplistic, but if all you are
>trying to do is to concatinate many (small) component
>awk programs into one why not do it with
>    cat prog1 prog2 prog3 prog4 ... > temp.awk
>    awk -f temp.awk

If the components just contain function declarations
it's probably Ok, but I doubt if that would merge
BEGIN {}, patternbody, and END {} sections correctly ?

--
  (  Kees Nuyt; Rotterdam; Netherlands

c[_] Disclaimer: Any opinions etc. are mine, not necessarily my employer's.



Mon, 11 Nov 2002 03:00:00 GMT  
 Includes ??




[...]

% >Perhaps I am being too simplistic, but if all you are
% >trying to do is to concatinate many (small) component
% >awk programs into one why not do it with
% >    cat prog1 prog2 prog3 prog4 ... > temp.awk
% >    awk -f temp.awk
%
% If the components just contain function declarations
% it's probably Ok, but I doubt if that would merge
% BEGIN {}, patternbody, and END {} sections correctly ?

But, you don't have to merge them. You can nave as many as you like
of each, and they can come in any order.

The easiest thing is probably to use more than one -f argument, as in
 #!/usr/bin/awk -f /usr/local/lib/awk/lib1.awk -f /usr/local/lib/awk/lib2.awk -f
 BEGIN { function1("init string") }
 function2() { function3() }

Granted, on Solaris, you have to type

 #!/usr/bin/nawk -f ...

or

 #!/usr/xpg4/bin/awk -f ...

I don't think that invalidates the approach.
--

Patrick TJ McPhee
East York  Canada



Mon, 11 Nov 2002 03:00:00 GMT  
 Includes ??


Quote:




> [...]

> % >Perhaps I am being too simplistic, but if all you are
> % >trying to do is to concatinate many (small) component
> % >awk programs into one why not do it with
> % >    cat prog1 prog2 prog3 prog4 ... > temp.awk
> % >    awk -f temp.awk
> %
> % If the components just contain function declarations
> % it's probably Ok, but I doubt if that would merge
> % BEGIN {}, patternbody, and END {} sections correctly ?

> But, you don't have to merge them. You can nave as many as you like
> of each, and they can come in any order.

> The easiest thing is probably to use more than one -f argument, as in
>  #!/usr/bin/awk -f /usr/local/lib/awk/lib1.awk -f /usr/local/lib/awk/lib2.awk -f

That won't work.  argv[1] will be -f.  argv[2] will be everything
else on the line.  Also,  in most cases the #! line is limited to
32 chars.  You can use the igawk script that comes with the gawk
distro,  or on unix boxes use my awkfe awk front end.  Write if
you're interested or check deja,  I posted it not too long ago.

--
Dan Mercer

- Show quoted text -

Quote:
>  BEGIN { function1("init string") }
>  function2() { function3() }

> Granted, on Solaris, you have to type

>  #!/usr/bin/nawk -f ...

> or

>  #!/usr/xpg4/bin/awk -f ...

> I don't think that invalidates the approach.
> --

> Patrick TJ McPhee
> East York  Canada


Opinions expressed herein are my own and may not represent those of my employer.


Mon, 11 Nov 2002 03:00:00 GMT  
 Includes ??

% > The easiest thing is probably to use more than one -f argument, as in
% >  #!/usr/bin/awk -f /usr/local/lib/awk/lib1.awk -f
% /usr/local/lib/awk/lib2.awk -f
%
% That won't work.  argv[1] will be -f.  argv[2] will be everything

I can't say I've done this on every system going, but this definitely
works on some systems. I mean, I use a few different systems, I use multiple
-f with some regularity, and I haven't had it fail yet.

% else on the line.  Also,  in most cases the #! line is limited to
% 32 chars.

I guess it depends on what you mean by most. I can say with certainty
that I run scripts pretty much every day on AIX, Solaris, HP-UX,
FreeBSD, and TRU64 (sic) Unix where the path to the script processor is
longer than 32 chars. I'm fairly sure that I've done the same thing on
Linux and Dynix.

Granted, if it doesn't work on your machine, you can't use it, but
I maintain that it's easier than using scripts that concatenate files
together, and it's probably faster and better all around.
--

Patrick TJ McPhee
East York  Canada



Tue, 12 Nov 2002 03:00:00 GMT  
 Includes ??


Quote:


> % > The easiest thing is probably to use more than one -f argument, as in
> % >  #!/usr/bin/awk -f /usr/local/lib/awk/lib1.awk -f
> % /usr/local/lib/awk/lib2.awk -f
> %
> % That won't work.  argv[1] will be -f.  argv[2] will be everything

> I can't say I've done this on every system going, but this definitely
> works on some systems. I mean, I use a few different systems, I use multiple
> -f with some regularity, and I haven't had it fail yet.

Well, -f does work on the command line.  It just doesn't work
in a shebang:

      $ uname -a
      HP-UX limswks7 B.10.20 A 9000/780 2010966112 two-user license
      $ head -1 tb
      #!/usr/bin/awk -f ./fun1 -f ./fun2 -f
      $ tb
      $ tb
      awk: Cannot find or open file  ./fun1 -f ./fun2 -f.
       The source line number is 1.
       The error context is
                       >>>  <<<

Quote:
> % else on the line.  Also,  in most cases the #! line is limited to
> % 32 chars.

Sorry,  last time I checked was on HP-UX 9.

--
Dan Mercer

Quote:
> I guess it depends on what you mean by most. I can say with certainty
> that I run scripts pretty much every day on AIX, Solaris, HP-UX,
> FreeBSD, and TRU64 (sic) Unix where the path to the script processor is
> longer than 32 chars. I'm fairly sure that I've done the same thing on
> Linux and Dynix.

> Granted, if it doesn't work on your machine, you can't use it, but
> I maintain that it's easier than using scripts that concatenate files
> together, and it's probably faster and better all around.
> --

> Patrick TJ McPhee
> East York  Canada


Opinions expressed herein are my own and may not represent those of my employer.


Sat, 16 Nov 2002 03:00:00 GMT  
 Includes ??

% Well, -f does work on the command line.  It just doesn't work
% in a shebang:

[meaning using multiple -fs to get the effect of included files]

As I said, I can't say it works on every system going, but it definitely works
on some systems. If it doesn't work on your system, you have to do something
else, but if it _does_ work on your system, then it's a good way to get
the effect of file inclusion in a script.

--

Patrick TJ McPhee
East York  Canada



Sun, 17 Nov 2002 03:00:00 GMT  
 Includes ??
The advantage of multiple "-f"s over cating the files is that,
if there is an error, you get the proper file name and line number.


Tue, 18 Feb 2003 12:56:09 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Program to convert C include to ASM include

2. Program to convert C include to ASM include

3. Req: Program to convert C include to ASM include

4. including preprocessor directives in included file

5. Including Extra Variables In An Include Statement

6. Include or not include ?

7. pre-processor include vs. F77-MIL-STD include

8. Bug in Enumerable#include? (Range#include?, actually) ???

9. Why module methods are NOT included by 'include' statement?

10. Difference between #include "" and #include <>?

11. PHP can't 'global' vars when including from an included file

12. INCLUDE statement: what if INCLUDE'd file changed?

 

 
Powered by phpBB® Forum Software