Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use perl instead of sed #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions iocAdmin/Db/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,4 @@ $(COMMON_DIR)/iocAdminVxWorks.db: $(COMMON_DIR)/iocAdminScanMon.db $(COMMON_DIR)

$(COMMON_DIR)/siteEnvVars.substitutions: $(EPICS_BASE)/configure/CONFIG_SITE_ENV
@echo Expanding siteEnvVars.substitutions from CONFIG_SITE_ENV....
@echo "file iocEnvVar.template" > $@
@echo "{" >> $@
@echo "pattern" >> $@
@echo "{ ENVNAME, ENVVAR, ENVTYPE }" >> $@
@sed -n 's/^EPICS_\([A-Z_]*\).*/{\1, EPICS_\1, epics}/p' $< >> $@
@echo "}" >> $@
@perl ../genSiteEnvVars.pl < $< > $@
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to use $(PERL) here instead of directly calling perl

This I leave up to you, but I think I would prefer a perl script that does not read from stdin but takes a file as an argument; looking at most of the perl scripts in use in various EPICS modules that seems to be more the more consistent standard.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on using $(PERL).

Most Base build rules that run generator scripts start with @$(RM) $@ to explicitly delete the target file first, so any errors which result in the script not actually regenerating the output file will trigger an error from GNUmake instead of it just continuing without recreating the file. I guess that's an enhancement request since the original rule didn't do that, but I recommend adding it anyway.

Switching from stdin to a filename argument might not need any changes to your Perl code at all, since using while (<>) { ... } in Perl inline code automatically opens and parses the files listed in @ARGV anyway (improve on that, Python!).

9 changes: 9 additions & 0 deletions iocAdmin/Db/genSiteEnvVars.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
print("file iocEnvVar.template\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a shebang, usage, and copyright notice?

print("{\n");
print("pattern\n");
print("{ ENVNAME, ENVVAR, ENVTYPE }\n");
Comment on lines +1 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a here-doc could reduce the number of quotes and escaped newlines, and I recommend always quoting the argument to file (again, not in the original). My personal preference for formatting substitution files would have fewer newlines:

print << __END__;
file "iocEnvVar.template" {
  pattern { ENVNAME, ENVVAR, ENVTYPE }
__END__

while(<>) {
$m = s/^EPICS_([A-Z_]*).*/{${1}, EPICS_${1}, epics}/;
print $_ if $m;
}
print("}\n");
Loading