A
aekalman
I'm really having difficulty with regular expressions -- perhaps
someone can help?
BACKGROUND: The strings:
sfiaravrt-7s-ec-sf-64.r90
sliaravrt-7s-ec-sf-64-i.r90
sfiaravra-6s-ec-sf.r90
sliaravrd-5l-sf-64.r90
sliaravrt-1s.r90
....
are various file names in a group of files.
Within a complex makefile system for generating libraries, I use the
following shell commands and reg exp to extract information from the
file names and pass that onto the compiler (via recursive make) as
command-line arguments, using:
*****
INDEX=$(shell expr '$(1)' : '$(2)')
PAIR=$(filter $(1)@%,$(2))
VAL=$(patsubst $(1)@%,%,$(2))
GETVAL = $(call VAL,$(call INDEX,$(1),$(2)),$(call PAIR,$(call
INDEX,$(1),$(2)),$(3)))
*****
TYPE_VALS = sf@OSF sl@OSL
FAMILY_VALS = iaravr@iaravr
CONFIG_VALS = a@OSA d@OSD e@OSE m@OSM t@OST
CPU_VALS = 0@0 1@1 2@2 3@3 4@4 5@5 6@6 7@7
MODEL_VALS = l@OSL s@OSS t@OST
CORE_VALS = -ec@OSE
FLASH_VALS = -sf@OSS
DOUBLES_VALS = -64@OSD
OPTION_VALS = -i@OSI
$(LIBRARIES):
$(MAKE) -f Makefile2 $@ \
T=$(call GETVAL,$@,\(..\), $(TYPE_VALS)) \
F=$(call GETVAL,$@,..\(......\).*\.r90, $(FAMILY_VALS)) \
C=$(call GETVAL,$@,........\(.\).*\.r90, $(CONFIG_VALS)) \
CPU=$(call GETVAL,$@,..........\(.\).*\.r90,$(CPU_VALS)) \
MODEL=$(call GETVAL,$@,...........\(.\).*\.r90,$(MODEL_VALS)) \
CORE=$(call GETVAL,$@,............\(.*\).r90,$(CORE_VALS)) \
FLASH=$(call GETVAL,$@,............\(.*\).r90, $(FLASH_VALS)) \
DOUBLES=$(call GETVAL,$@,............\(.*\).r90,$(DOUBLES_VALS)) \
O=$(call GETVAL,$@,............\(.*\).r90, $(OPTION_VALS))
*****
When you run make, you get something out like this:
make -f Makefile2 sfiaravrt-7s-ec-sf-64.r90 T=OSF F=iaravr C=OST CPU=7
....
The reg exp patterns are in the calls to GETVAL. This systems works
GREAT for filenames of constant length and format, and was suggest by
Jonathan Kamens to me back in '01.
PROBLEM: Using regular expressions, I am able to find patterns at the
start of the strings (like the (f,l) pair in the second position, or
the (a,d,t) trio in the ninth position) just fine because their
positions are fixed -- easy. The GETVAL macro returns a string (e.g.
OSF) that is passed onto the compiler via MAKE as T=OSF. Note that a
match must occur, and so the variable (in this case, T) is always
defined.
It's starting with the 13th position that I'm having trouble. I can't
seem to build a reg exp that excludes the first 12 characters, and
only searches from the 13th character onwards, up to the .r90 at the
end. I want to search only the 13th through last positions of the
filenames for the patterns:
-ec
-sf
-64
-i
and, if found, set the associated variable (e.g. CORE) to the value in
its key/value pairs list (e.g. CORE=OSE for "-ec is present"), o/wise
leave it undefined or defined to OSNONE (e.g. CORE=OSNONE for "-ec was
not found in the filename").
How do I do that?
Can anyone help? Please?
Thanks,
--Andrew Kalman
aek at pumpkin inc dot com
someone can help?
BACKGROUND: The strings:
sfiaravrt-7s-ec-sf-64.r90
sliaravrt-7s-ec-sf-64-i.r90
sfiaravra-6s-ec-sf.r90
sliaravrd-5l-sf-64.r90
sliaravrt-1s.r90
....
are various file names in a group of files.
Within a complex makefile system for generating libraries, I use the
following shell commands and reg exp to extract information from the
file names and pass that onto the compiler (via recursive make) as
command-line arguments, using:
*****
INDEX=$(shell expr '$(1)' : '$(2)')
PAIR=$(filter $(1)@%,$(2))
VAL=$(patsubst $(1)@%,%,$(2))
GETVAL = $(call VAL,$(call INDEX,$(1),$(2)),$(call PAIR,$(call
INDEX,$(1),$(2)),$(3)))
*****
TYPE_VALS = sf@OSF sl@OSL
FAMILY_VALS = iaravr@iaravr
CONFIG_VALS = a@OSA d@OSD e@OSE m@OSM t@OST
CPU_VALS = 0@0 1@1 2@2 3@3 4@4 5@5 6@6 7@7
MODEL_VALS = l@OSL s@OSS t@OST
CORE_VALS = -ec@OSE
FLASH_VALS = -sf@OSS
DOUBLES_VALS = -64@OSD
OPTION_VALS = -i@OSI
$(LIBRARIES):
$(MAKE) -f Makefile2 $@ \
T=$(call GETVAL,$@,\(..\), $(TYPE_VALS)) \
F=$(call GETVAL,$@,..\(......\).*\.r90, $(FAMILY_VALS)) \
C=$(call GETVAL,$@,........\(.\).*\.r90, $(CONFIG_VALS)) \
CPU=$(call GETVAL,$@,..........\(.\).*\.r90,$(CPU_VALS)) \
MODEL=$(call GETVAL,$@,...........\(.\).*\.r90,$(MODEL_VALS)) \
CORE=$(call GETVAL,$@,............\(.*\).r90,$(CORE_VALS)) \
FLASH=$(call GETVAL,$@,............\(.*\).r90, $(FLASH_VALS)) \
DOUBLES=$(call GETVAL,$@,............\(.*\).r90,$(DOUBLES_VALS)) \
O=$(call GETVAL,$@,............\(.*\).r90, $(OPTION_VALS))
*****
When you run make, you get something out like this:
make -f Makefile2 sfiaravrt-7s-ec-sf-64.r90 T=OSF F=iaravr C=OST CPU=7
....
The reg exp patterns are in the calls to GETVAL. This systems works
GREAT for filenames of constant length and format, and was suggest by
Jonathan Kamens to me back in '01.
PROBLEM: Using regular expressions, I am able to find patterns at the
start of the strings (like the (f,l) pair in the second position, or
the (a,d,t) trio in the ninth position) just fine because their
positions are fixed -- easy. The GETVAL macro returns a string (e.g.
OSF) that is passed onto the compiler via MAKE as T=OSF. Note that a
match must occur, and so the variable (in this case, T) is always
defined.
It's starting with the 13th position that I'm having trouble. I can't
seem to build a reg exp that excludes the first 12 characters, and
only searches from the 13th character onwards, up to the .r90 at the
end. I want to search only the 13th through last positions of the
filenames for the patterns:
-ec
-sf
-64
-i
and, if found, set the associated variable (e.g. CORE) to the value in
its key/value pairs list (e.g. CORE=OSE for "-ec is present"), o/wise
leave it undefined or defined to OSNONE (e.g. CORE=OSNONE for "-ec was
not found in the filename").
How do I do that?
Can anyone help? Please?
Thanks,
--Andrew Kalman
aek at pumpkin inc dot com