[Info-vax] OpenVMS - DCL - Data entry filtering
Paul Sture
nospam at sture.ch
Wed Mar 25 06:47:05 EDT 2015
On 2015-03-25, IanD <iloveopenvms at gmail.com> wrote:
>
> I am wanting to write a small bit of DCL that will filter a users
> input to ensure that the following characters are voided in any input
>
> ban_these_characters = "~`!@#$%^&*()-+={}[]\|;:',.<>/?"""
>
> The OS version is 7.3-2 if that helps
>
> I tried things like the following:
>
> ban_these_characters = "~`!@#$%^&*()-+={}[]\|;:',.<>/?"""
> data_entry = "~~test~~"
> data_entry = data_entry - ban_these_characters
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>> Question: Is there a smarter / easier way of doing this in DCL? <<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
The code below employs a loop to catch multiple occurrences of unwanted
characters.
$ ! FILTER.COM
$ ! ----------
$ !
$ data = P1
$ write sys$output "input string : ", "''data'"
$ s_quote = "'"
$ d_quote = """"
$! ban_these_characters = "~`!@#$%^&*()-+={}[]\|;:,.<>/?"
$l1:
$ saved_length = f$length(data)
$ data = data - "~" - "`" - "!" - "@" - "#" - "$" -"%" - "^" - "&"
$ data = data - "*" - "(" - ")" - "-" - "+" - "=" - "{" - "}" - "["
$ data = data - "]" - "\" - "|" - ";" -":" - "," - "." - "<" - ">"
$ data = data - "/" - "?" - s_quote - d_quote
$ if f$length(data) .ne. saved_length then goto l1
$ write sys$output "output string: ", "''data'"
The logic here says that if the before and after string lengths are
the same, then nothing was subtracted on the last pass and we've
nailed all occurrences of unwanted characters.
P.S. On my first attempt I tried that little lot with continuation
characters to form one line for the "data = data - " command, but
that threw a
%DCL-W-COMPLX, expression too complex - simplify
Splitting it into multiple lines as above allowed me to hone
straight in on a typo that was present.
--
Real Daleks don't climb the stairs - real Daleks level the building.
More information about the Info-vax
mailing list