merlyn@iwarp.intel.com (Randal Schwartz) (12/13/89)
In article <128978@sun.Eng.Sun.COM>, henry%angel (Henry McGilton -- Software Products) writes: | This requirement occurs all the time. If you have access | to any UNIX system running the 4.x BSD (Berkeley) flavor of | UNIX, you should find a program called `soelim'. While | soelim was originally written for another purpose, it turns | out that it does just what you want, namely, to do the | source'ing of included files before the troff preprocessors | do their work. Then you run the pipeline of commands in the form: | | soelim sourcefiles . . . | pic | tbl | eqn | troff . . . | | I don't know if soelim is available on System V at this | point. If you have access to a BSD system, grab the source | from such a system. soelim was written by Bill Joy in | 1977, and, as far as I know, is not copyrighted. Well, a simple soelim in Perl (of course) is: #!/usr/bin/perl -p next unless /^\.so\s+(.*)/; if (open(SO,$1)) { $_ = join("",<SO>); close(SO); } else { warn "Cannot open $1 at $ARGV (line $.): $!"; } This only works one level deep (no nested .so's), and requires Perl 3.0, although the only 3-ism is the "warn". Usage is like 'cat'... one or more files are concatenated, no files means use stdin. Just another Perl hacker, -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/
chip@ateng.com (Chip Salzenberg) (12/14/89)
According to merlyn@iwarp.intel.com (Randal Schwartz): >#!/usr/bin/perl -p >next unless /^\.so\s+(.*)/; >if (open(SO,$1)) { > $_ = join("",<SO>); > close(SO); >} else { > warn "Cannot open $1 at $ARGV (line $.): $!"; >} I should really hope that people would prefer NOT to read in the entire file and assign it to $_. Rather, I'd do this: #!/usr/bin/perl -p next unless /^\.so\s+(\S+)/; # A better regexp $SO = $1; if (open(SO)) { while (<SO>) { print; } close(SO); } else { warn "Cannot open $SO at $ARGV (line $.): $!"; } $_ = ""; # You forgot this, Randal >This only works one level deep (no nested .so's), and requires Perl >3.0, although the only 3-ism is the "warn". Ditto. -- You may redistribute this article only to those who may freely do likewise. Chip Salzenberg at A T Engineering; <chip@ateng.com> or <uunet!ateng!chip> "The Usenet, in a very real sense, does not exist."
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (12/15/89)
In article <2586A576.9028@ateng.com> chip@ateng.com (Chip Salzenberg) writes:
: According to merlyn@iwarp.intel.com (Randal Schwartz):
: >#!/usr/bin/perl -p
: >next unless /^\.so\s+(.*)/;
: >if (open(SO,$1)) {
: > $_ = join("",<SO>);
: > close(SO);
: >} else {
: > warn "Cannot open $1 at $ARGV (line $.): $!";
: >}
:
: I should really hope that people would prefer NOT to read in the entire
: file and assign it to $_. Rather, I'd do this:
:
: #!/usr/bin/perl -p
: next unless /^\.so\s+(\S+)/; # A better regexp
: $SO = $1;
: if (open(SO)) {
: while (<SO>) {
: print;
: }
: close(SO);
: } else {
: warn "Cannot open $SO at $ARGV (line $.): $!";
: }
: $_ = ""; # You forgot this, Randal
:
: >This only works one level deep (no nested .so's), and requires Perl
: >3.0, although the only 3-ism is the "warn".
:
: Ditto.
There's an example of nested include file processing (thought not
specifically .so files) in the perl manual. Look under "open".
Larry Wall
lwall@jpl-devvax.jpl.nasa.gov