[Nut-upsdev] newhidups: regular expressions

Peter Selinger selinger at mathstat.dal.ca
Tue Sep 13 05:46:44 UTC 2005


I have created a branch "regex_branch" in the CVS tree. In it, I have
implemented UPS selection via extended regular expressions that are
matched against various data obtained from the UPS (Vendor, Product,
Serial number, VendorID, ProductID). These are implemented via new
driver options

-x vendor=<regex>
-x product=<regex>
-x serial=<regex>
-x vendorid=<regex>
-x productid=<regex>

This mechanism should give more flexibility in selecting devices than
most people will ever need.

Notes:

* the regular expressions are "extended", see regex(7). This means
that operators such as "|", "+", "?" etc can be used. 

* the regular expressions must match the *entire* string supplied by
the UPS (not just an initial portion). Thus, to match any BackUPS
model, try something like -x product=".*Back-?UPS.*". 

* Most people will of course just give a plain string, such as -x
product="APC Back-UPS Pro 650". Just keep in mind that certain
characters (*.+|?()^$[] and so forth) have special meanings in regular
expressions and must be escaped.

* matching is case-insensitive

* Vendor ID and Product ID are matched as if they were 4-digit
hexadecimal strings (e.g. 050D). 

* any surrounding whitespace is removed from the UPS string before the
matching.

* when *re*-opening a device, we ignore the regular expressions, and
just try to connect (as best as possible) to the same device that had
already been opened before. This is the same behavior as before.

The version I checked into CVS (cvs update -r regex_branch) works for
me; however, somebody might want to test and critique this before
moving the changes to the main branch.

Best, -- Peter




More information about the Nut-upsdev mailing list