Hi Tracy,
Nice script. Below I offer a few ideas, not really necessary
to add, just more for your info...
<plug> I will be doing another CI programming talk at both the
east and west coast Solution Symposiums. I'd be happy to take
pre-submitted questions. Also my paper will be on the Interex
site and on Jazz. And, anticipating the question, I think a lot
of the talk will be the same or similar to the talk I did last
year, but I will try to add new examples, and emphasize different
areas of CI programming. </plug>
> parm ldevno="6"
# You may want to verify user input for the LDEVNO parm, e.g.
if not numeric("!ldevno") then
echo Expected a single printer LDEV number
return
endif
# You could test that the script is really run with STDIN redirected
# in a couple of ways: 1) testing HPINTERACTIVE or HPDUPLICATIVE or 2)
# testing the value of the HPSTDIN variable, e.g.
if hpstdin = "$STDIN" then
echo This script must be run with $Stdin redirected to the
echo output of :SHOWDEV
return
endif
> setvar _sp_eof finfo(HPSTDIN,'eof')
# May want to ensure that there are at least a few records in
# the input file, otherwise the user may have issued the SHOWDEV
# incorrectly. IMO, it is better to have the script do the SHOWDEV
# itself, so you have more control.
if _sp_eof <= 2 then
echo Wrong input file, or the SHOWDEV command may have been
echo entered incorrectly.
print hpstdin
return
endif
> setvar if_printer false
> while setvar(_sp_eof,_sp_eof-1) >= 0
> input _sp_rec
> if pos('spooled',dwns(_sp_rec)) > 0 and
> numeric(word(_sp_rec)) and not pos('down',dwns(_sp_rec)) > 0 then
# totally in the FWIW department ...
# You can combine the two statements above, maybe making it less
# readable (to many) but a tad more efficient. It's actually more
# readable to me, but that's another story... [note: only one dwns()
# needed too]
if pos('spooled',setvar(_sp_rec,dwns(input()))) > 0 and &
numeric(word(_sp_rec)) and not pos('down',_sp_rec) > 0 then
> setvar finddev str(_sp_rec,2,4)
# I think it is much safer to not use output columns. Then if somehow
# the SHOWDEV output changed (suppose larger LDEV numbers) then your
# script still runs correctly. I prefer to use word(), e.g.:
setvar finddev word(_sp_rec)
# word() returns a string, but if you want it to be stored as an
# integer you can do:
setvar finddev ![word(_sp_rec)]
> if !ldevno = !finddev then
# Note: you NEED the ! in front of the ldevno parm since it is a
# parameter, but you do not need the ! in front of the finddev var.
# Note: the CI lets you compare an integer (ldevno) and a string
# (finddev -- see the str() statement above) since explicit
# references (!name) removes all typing. I prefer to try to keep
# the types consistent for easier maintenance down the road.
# You also might want to stop the WHILE loop now, since you don't
# care about any other LDEVs.
setvar _sp_eof -1
> echo Printer found number: !ldevno
> setvar if_printer true
> endif
> endif
> endwhile
# last comment, I believe the body of the WHILE loop can be
# reduced, as:
setvar if_printer false
while not if_printer and &
setvar(_sp_eof,_sp_eof-1) >= 0 &
"!ldevno" <> word(setvar(_sp_rec,dwns(input()))) do
if pos('spooled',_sp_rec) > 0 and pos('down',_sp_rec) = 0 then
echo Printer found number: !ldevno
setvar if_printer true
endif
endwhile
# Note tested but it should work.
HTH,
Jeff Vance, vCSY
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|