I figured someone would ask for that one. <grin>

But I also figured on a pretty finite number of "infinite" scores in
one vbs file, so I really didn't know if it was worth the time.  If
problems in finding these persist, I should be able to modify the
report, yes.

In case anyone else wants this and/or knows Perl though, here's the
report generator itself.  Pardon the lack of documentation within the
code; as I said yesterday, I didn't spend a lot of time doing this.
It currently expects to be run from a directory under which each
project is its own directory, the directories being the respective
package names of the script sets.  To test your own code, just run
this from a level above its directory.  I'm something of a command
guy, so apologies to the GUI fans out there for the quaint interface
and instructions.

This is exactly the code I ran yesterday to produce the list I sent
out.  I ran this on a FreeBSD machine, not a Windows machine; but I
think it would work in either place.

---begin oernscore.pl---
#! /usr/bin/env perl -w

# "on error resume next" danger score calculator.
#
# Rules:
#       - A score of N means a set of N code lines between "on error resume 
next" and "on error goto 0" (not inclusive) was found.
#       - Comments and blank lines in code don't count.
#       - A file's score is the highest count found in it.
#       - A sub, function, or file with an "on error resume next" that is not 
turned back off gets an infinite score.
#       - Infinite scores will be suffixed with "function," "sub," or "file" to 
indicate which type of infinity was found.
#
# Author:  Doug Lee of SSB BART Group

my @files = <*/*.[vV][bB][sS]>;
my @counts = ();
foreach my $file (@files) {
        $lines = getUnprotectedLineCount($file);
        next if $lines =~ /^\s*0/;
        push(@counts, ("$lines:  $file"));
}
foreach my $count (sort {$b cmp $a} @counts) {
        $count =~ s/^9999999/Infinite/;
        print "$count\n";
}
exit 0;

sub getUnprotectedLineCount
{
        my $file = shift;
        open(FH, "<$file") ||die "Can't open/read from $file; $!\n";
        my $cnt = 0;
        my $maxcnt = 0;
        my $state = 0;
        while ($_ = <FH>) {
                chomp;
                next if /^\s*$/ || /^\s*'/;
                if (/^\s*on\s+error\s+resume\s+next/i) {
                        $state = 1;
                } elsif (/^\s*on\s+error\s+goto\s+0/i) {
                        $state = 0;
                        $maxcnt = $cnt if $maxcnt < $cnt;
                        $cnt = 0;
                } elsif ($state == 1 && /^\s*end\s+(sub|function)/i) {
                        # Infinite; runs off end of routine.
                        close(FH);
                        return "9999999 ($1)";
                } else {
                        # Nicely adds 0 outside of and 1 inside of "on error 
resume next" blocks.
                        $cnt += $state;
                }
        }
        close(FH);
        $maxcnt = sprintf("%7d", $maxcnt);
        $maxcnt = "9999999 (file)" if $state == 1;
        return $maxcnt;
}
---end oernscore.pl---

On Thu, Sep 11, 2008 at 04:12:22PM -0400, Jamal Mazrui wrote:
Thanks for that info, Doug.  If you get a chance, can you include the
name of the function in the report?

Jamal
On Wed, 10 Sep 2008, Doug Lee wrote:

> Date: Wed, 10 Sep 2008 16:17:14 -0400
> From: Doug Lee <[EMAIL PROTECTED]>
> Reply-To: [email protected]
> To: [email protected]
> Subject: An urging regarding error handling in Window-Eyes scripts
>
> I was prompted to put this message together by today's chain of
> messages about various scripts that produce no output and/or seem to
> stall forever.
>
> I've probably said this before, but I'm not sure if I said it here on
> this list.
>
> I would like to urge Window-Eyes scripters that use VBScript to avoid
> using "on error resume next" except where there is very good reason to
> do so.  Here are a few major problems that little command can cause:
>
> 1.  If an error occurs in an If statement while an "on error resume
> next" is in effect, it will always act True, because "resume next"
> means resume execution inside the If part.  This is usually exactly
> what you do not want.
>
> 2.  If an error occurs in a While or other loop condition, it can
> cause an infinite loop, because "resume next" means resume execution
> inside the loop.
>
> 3.  You may put an "on error resume next" line in your code to catch
> one type of error, but it will quietly absorb (and mask) any
> unexpected type of error imaginable.  For example, if you try
> protecting yourself from division by 0 when calculating an average,
> but you happen to misspell a variable name, you will get the wrong
> answer without seeing why.
>
> When you do use "on error resume next," I recommend the following
> precautions:
>
> 1.  Run without that line first and make sure to figure out what kinds
> of errors might occur there.  This is the time to make sure nothing is
> misspelled etc.
>
> 2.  When you put the "on error resume next" line in, put a corresponding
> "on error goto 0" line below it, and as close to the "on error
> resume next" as possible.  Avoid control flow commands like If,
> While, sub and function calls, etc. within that little space between
> the two lines.  Think of the gap between "on error resume next" and
> "on error goto 0" as a 500-foot deep crack in the ground:  If you
> don't want someone to fall in, keep that thing skinny!
>
> In case it's useful, I am pasting below the output of a
> hastily-written Perl program that attempts to score vbs files on their
> use of "on error resume next."  Here are the rules it uses first:
>
>       - A score of N means a set of N code lines between "on error resume 
> next" and "on error goto 0" (not inclusive) was found.
>       - Comments and blank lines in code don't count.
>       - A file's score is the highest count found in it.
>       - A sub, function, or file with an "on error resume next" that is not 
> turned back off gets an infinite score.
>       - Infinite scores will be suffixed with "function," "sub," or "file" to 
> indicate which type of infinity was found.
>
> I wrote this rather quickly, so pardon any errors in its results.  I
> did spot-check it though.
>
> And here's the output, most unprotected lines first, infinite scores
> at the top, files scoring 0 omitted entirely.  The file names are the
> package name, a slash, and the actual file name.
>
>       Infinite (Function):  weatherornot/weatherornot.vbs
>       Infinite (Function):  LookupTerm/LookupTerm.vbs
>       Infinite (Function):  HomerSharedObject/HomerSharedObject.vbs
>       Infinite (Function):  ExamineSystem/ExamineSystem.vbs
>       Infinite (Function):  ActivateWindow/ActivateWindow.vbs
>            81:  progressindicator/ProgressIndicator.vbs
>            59:  HarvestWindow/HarvestWindow.vbs
>            47:  CaptureScreen/CaptureScreen.vbs
>            46:  weevent/weevent.vbs
>            38:  OperateServices/OperateServices.vbs
>            34:  CalculateDate/CalculateDate.vbs
>            26:  IEMax/IEMax.vbs
>            20:  winamp/winamp.vbs
>            19:  TerminateProcesses/TerminateProcesses.vbs
>            18:  RelaunchWindow-eyes/RelaunchWindow-eyes.vbs
>            18:  CheckLanguage/CheckLanguage.vbs
>            16:  TrackTime/TrackTime.vbs
>            16:  SetCheckbox/SetCheckbox.vbs
>            16:  SelectText/SelectText.vbs
>            16:  RunAtCursor/RunAtCursor.vbs
>            16:  RecentPaths/RecentPaths.vbs
>            16:  PasteSpecialCharacter/PasteSpecialCharacter.vbs
>            16:  JumpToItem/JumpToItem.vbs
>            16:  InteractiveJScript/InteractiveJScript.vbs
>            16:  InstallPackages/InstallPackages.vbs
>            16:  GoToSpecialFolder/GoToSpecialFolder.vbs
>            16:  GoToFolder/GoToFolder.vbs
>            16:  FocusControl/FocusControl.vbs
>            16:  EvaluateJScript/EvaluateJScript.vbs
>            16:  DetectShortcutKeys/DetectShortcutKeys.vbs
>            16:  AppendToClipboard/AppendToClipboard.vbs
>            15:  gwtoolkit/gwtoolkit.vbs
>            15:  MicrosoftWordCount/WinwordCount.vbs
>            14:  autocomplete/autocomplete.vbs
>            11:  HomerLayout/HomerLayout.vbs
>             9:  ScriptTemplate/ScriptTemplate.vbs
>             9:  ReplyToSender/ReplyToSender.vbs
>             9:  RemapCapsLock/RemapCapsLock.vbs
>             9:  EdSharp/EdSharp.vbs
>             8:  WEActions/WEActions.vbs
>             8:  TogglePunctuation/TogglePunctuation.vbs
>             8:  SpellIt/SpellIt.vbs
>             8:  ScriptMenu/ScriptMenu.vbs
>             8:  ScriptManager/ScriptManager.vbs
>             8:  RestoreDefaultSets/RestoreDefaultSets.vbs
>             8:  LearnScripting/LearnScripting.vbs
>             8:  KillWineyes/KillWineyes.vbs
>             8:  FileDir/FileDir.vbs
>             8:  DeleteStrokes/DeleteStrokes.vbs
>             8:  BeautifyVBScript/BeautifyVBScript.vbs
>             6:  easycddaextractor/easycddaextractor.vbs
>             5:  ShutdownNow/ShutdownNow.vbs
>             5:  RestartNow/RestartNow.vbs
>             5:  QuerySettings/QuerySettings.vbs
>             5:  LoadedScripts/LoadedScripts.vbs
>             5:  ConvertUnits/ConvertUnits.vbs
>             4:  AlternateMenu/AlternateMenu.vbs
>             3:  RelaunchWindow-eyes/BootStrap.vbs
>
> --
> Doug Lee, Senior Accessibility Programmer
> SSB BART Group - Accessibility-on-Demand
> mailto:[EMAIL PROTECTED]  http://www.ssbbartgroup.com
> "While they were saying among themselves it cannot be done,
> it was done." --Helen Keller
>

-- 
Doug Lee, Senior Accessibility Programmer
SSB BART Group - Accessibility-on-Demand
mailto:[EMAIL PROTECTED]  http://www.ssbbartgroup.com
"While they were saying among themselves it cannot be done,
it was done." --Helen Keller

Reply via email to