;Script Debugger file creator ;Written by Stuart Pearson ;This script carries out the following: ;1) Ask user to input an existing script filename (sInputfile) ;2) Copies the input file to a backup file (sSafetyfile) ;3) Copies the input file to a temporary file (sDebugfile) ;4) Reads the input file on a line by line basis. For the majority of lines the input line is written to the temporary file. ;5) If the input line contains either an fgets or fputs statement, Prior to the line being written to the temporary file a ; formatted line stating the debugcount value is written to the file. i.e. debugcount=1 ;6) Each time an fgets or fputs is encountered the debugcount variable is incremented and the corresponding value written to ; temporary file. ;7) Once the input file has been read in its entirety the input file is deleted and the temporary file is copied to the ; input filename. ;8) The input filename is then re-compiled. ;In order to make use of this script the sInputfile should contain the following statement: ; 'when $errornum call error_handling_procedure' ;The error handling procedure should record the value of the debugcount (i.e. debugcount:%d) in an error file. ;To prevent incorrect debugcount values being registered for debugcount statements in the error procedure, prior to the error ;handling procedure there should be a line containing the text "no more debug" ;As the script uses strfind statements to find fgets or fgets it is easy to amend to look for other statements string sInputfile ;Input script file to be examined by program string sDebugfile ;output file to be created string sSafetyfile ;copy of the sInputfile (created as safety backup) string sLne ;String that contains the content of each line read string sDebuglne ;Formatted string with debug count information string sDebugmessage ;String variable storing formatted string displayed in dialogbox 0 integer iCounter ;Debug counter integer iNo_more_debug ;Check for error writing procedure proc main ask_filename: sSafetyfile="safety.was" sDebugfile="temp.was" sdlginput "Input Required" "Enter Filename" sInputfile if nullstr sInputfile exit endif if not strfind sInputfile ".was" strcat sInputfile ".was" endif if not isfile sInputfile usermsg "Invalid Filename!" goto ask_filename endif if isfile sSafetyfile delfile sSafetyfile endif if isfile sDebugfile delfile sDebugfile endif copyfile sInputfile sSafetyfile copyfile sInputfile sDebugfile iNo_more_debug=0 fopen 0 sInputfile READ TEXT fopen 1 sDebugfile WRITE TEXT iCounter=0 strfmt sDebugmessage "DEBUG MESSAGES ADDED:%d" iCounter dialogbox 0 98 89 264 62 3 "Script Progress" text 1 46 23 172 20 sDebugmessage center enddialog while not feof 0 nextline: fgets 0 sLne if strfind sLne "no_more_debug" iNo_more_debug=1 endif if strfind sLne "debugcount=" ;check for existing debug message goto nextline ;don't copy line endif if iNo_more_debug==1 goto bypass_check endif if strfind sLne "fputs" ;check for fputs command iCounter ++ strfmt sDebuglne "debugcount=%d" iCounter ;format debug string strfmt sDebugmessage "DEBUG MESSAGES ADDED:%d" iCounter dlgupdate 0 1 fputs 1 sDebuglne ;write debug string endif if strfind sLne "fgets" ;check for fgets command iCounter ++ strfmt sDebuglne "debugcount=%d" iCounter ;format debug string strfmt sDebugmessage "DEBUG MESSAGES ADDED:%d" iCounter dlgupdate 0 1 fputs 1 sDebuglne ;write debug string endif bypass_check: fputs 1 sLne ;copy line to debug file endwhile fclose 0 fclose 1 delfile sInputfile copyfile sDebugfile sInputfile strfmt sDebugmessage "COMPILING %s" sInputfile dlgupdate 0 1 if compile sInputfile usermsg "File Compile successful" else usermsg "Compile Error" endif dlgdestroy 0 cancel endproc