#!/usr/bin/perl -w use strict; use diagnostics; # Beautify code for pasting to DB forum. # Bugs: Slow, ugly code. Shouldn't loop through all commands: that's what hashes are for! # Bugfix: the forum won't give
tags to lines ending in or , # so these tags are always followed by   # Create an array of valid command strings. chomp(my @commands=); my $skipped; my $workString; my $resultString; my $char; my %complex=('"' => 1, "'" => 2, 'REM' => 3, 'RENSTART' => 4, 'REMEND' => 5); my $inComplex=0; # Parse the input. while (<>) { $resultString=''; ($workString=$_) =~ s/\s*$//; # Remove trailing whitespace so can detect last character. if ($workString eq '') {print; next;} #Ignore blank lines. # Ensure & and < are escaped. Maybe also escape : to prevent smileys. Has to be first s/// $workString =~ s/\&/&/g; $workString =~ s/\$&<\/i> /i; # The  \; is kludge for forum's
bug. $workString =~ s/\`.*/$&<\/i> /; $workString =~ s/REMSTART/$&/ig; $workString =~ s/REMEND/$&<\/i> /ig; # Keywords. CHAR: while (1) { $char=0; CMD: foreach my $cmd (@commands) { if (!$inComplex) { # Using word boundaries for speed, but must find commands with nonword chars on their boundary.02:17 22/06/01 if ((substr $cmd,-1,1)eq '$') { (my $var=$cmd)=~s,\$,\\\$,; if ($workString =~ s/^($var)/$1<\/b>/i) { $char=(length $1)+7; last CMD; } } if (((uc $cmd eq "#INCLUDE")&&((substr $resultString,-1,1)eq'#')&&($workString=~s/^(INCLUDE)\b/$1<\b>/i)) ||($workString =~ s/^($cmd)\b/$1<\/b>/i)) { $char=(length $1)+7; $char-- if uc $cmd eq "#INCLUDE"; last CMD; } if ($workString =~ s/^(REMSTART)\b/$1<\/b>/i) { $inComplex=$complex{'REM'}; $char=15; last CMD; } if ($workString =~ s/^(REM)\b/$1<\/b>/i) { # The rest of the line can be ignored. $resultString.=$workString; last CHAR; } } elsif (($inComplex==$complex{'REM'})&&($workString =~ s/^(REMEND)\b/$1<\/b>/i)) { $inComplex=0; $char=13; last CMD; } } # Kludge for the forum's
bug. if ($char >= length $workString) { $resultString.=$workString.' '; last CHAR; } # Move on to the next word boundary, counting quotes as we go. $workString =~ m/(.+?)\b/; if (defined $1) { $skipped=$1 } else {$skipped=$workString; $char=length $workString} $char+=(length $skipped); # Point Char at next word boundary. # Check for string beginnings/ends if not in a comment. if ($inComplex != $complex{'REM'}) { foreach (split //, $skipped) { if (($_ eq '"')||($_ eq "'")) { $inComplex=$complex{$_} if !$inComplex; $inComplex=0 if $inComplex eq $complex{$_}; } } } if ($char < length $workString) { $resultString.=substr($workString, 0, $char); $workString=substr($workString, $char); } else { $resultString.=$workString; last CHAR; } } # Indent. Treats tabs as just one space wide. Done last for speed. $resultString =~ s/^\s*/'  ' x length($&)/e; #Display the modified line. print "$resultString\n"; } # Deal with unmatched REMSTARTs by closing italics just in case. Bit of a kludge. print "
\n"; # Longest commands MUST be first below, for the highlighting algorithm to work. # If more commands are added and the data area gets messed up, then either # move the first line here up to just after the @commands= line, or # use both lines to sort a file containing the new command set, and use that. #@commands=sort { (length $b <=> length $a) or (lc($b) cmp lc($a)) } @commands; #foreach (@commands) {print "$_\n"} __END__ PERFORM CHECKLIST FOR CONTROL DEVICES PERFORM CHECKLIST FOR GRAPHICS CARDS PERFORM CHECKLIST FOR DISPLAY MODES PERFORM CHECKLIST FOR OBJECT LIMBS SET STATIC OBJECTS WIREFRAME OFF SET OBJECT TO OBJECT ORIENTATION SET OBJECT TO CAMERA ORIENTATION SET OBJECT COLLISION TO POLYGONS SET CAMERA TO OBJECT ORIENTATION SET STATIC OBJECTS WIREFRAME ON SET OBJECT COLLISION TO SPHERES SET LIGHT TO OBJECT ORIENTATION SET OBJECT COLLISION TO BOXES SET LIGHT TO OBJECT POSITION PERFORM CHECKLIST FOR DRIVES PERFORM CHECKLIST FOR FONTS PERFORM CHECKLIST FOR FILES DELETE OBJECT COLLISION BOX SET STATIC OBJECTS TEXTURE CLEAR ALL OBJECT KEYFRAMES OBJECT COLLISION CENTER Z OBJECT COLLISION CENTER Y OBJECT COLLISION CENTER X MAKE STATIC COLLISION BOX MAKE OBJECT COLLISION BOX DETACH OBJECT FROM STATIC SET OBJECT INTERPOLATION SET OBJECT COLLISION OFF SET MATRIX WIREFRAME OFF SET GLOBAL COLLISION OFF GET STATIC COLLISION HIT DISABLE STATIC OCCLUSION SET OBJECT ROTATION ZYX SET OBJECT ROTATION XYZ SET OBJECT COLLISION ON SET MATRIX WIREFRAME ON SET GLOBAL COLLISION ON SET CAMERA ROTATION ZYX SET CAMERA ROTATION XYZ OBJECT COLLISION RADIUS ENABLE STATIC OCCLUSION ATTACH OBJECT TO STATIC APPEND OBJECT ANIMATION ALPHABLENDING AVAILABLE SET TEXT TO BOLDITALIC PREPARE MATRIX TEXTURE MATRIX WIREFRAME STATE GET STATIC COLLISION Z GET STATIC COLLISION Y GET STATIC COLLISION X GET OBJECT COLLISION Z GET OBJECT COLLISION Y GET OBJECT COLLISION X CURRENT GRAPHICS CARD$ SYSTEM TMEM AVAILABLE SYSTEM SMEM AVAILABLE SYSTEM DMEM AVAILABLE SET NORMALIZATION OFF SET DIRECTIONAL LIGHT SCROLL OBJECT TEXTURE SAVE OBJECT ANIMATION MAKE MESH FROM OBJECT FORCE AUTO CENTER OFF DISABLE OBJECT ZDEPTH DELETE STATIC OBJECTS CLEAR OBJECT KEYFRAME TEXT BACKGROUND TYPE STOP RECORDING SOUND SET TEXT TRANSPARENT SET NORMALIZATION ON SET CAMERA TO FOLLOW SCALE OBJECT TEXTURE OBJECT INTERPOLATION MAKE OBJECT TRIANGLE MAKE OBJECT CYLINDER FORCE AUTO CENTER ON ENABLE OBJECT ZDEPTH CONTROL DEVICE NAME$ ANIMATION POSITION Y ANIMATION POSITION X TOTAL OBJECT FRAMES SET WINDOW POSITION SET OBJECT KEYFRAME SCROLL LIMB TEXTURE SAVE STATIC OBJECTS READ BYTE FROM FILE LOAD STATIC OBJECTS LISTENER POSITION Z LISTENER POSITION Y LISTENER POSITION X GLUE OBJECT TO LIMB FILTERING AVAILABLE COLOR AMBIENT LIGHT WRITE TO CLIPBOARD WRITE BYTE TO FILE SHIFT MATRIX RIGHT SET TEXT TO NORMAL SET TEXT TO ITALIC SET OBJECT TEXTURE SET CURRENT BITMAP SET CONTROL DEVICE SCALE LIMB TEXTURE MATRIX TILES EXIST MAKE STATIC OBJECT MAKE OBJECT SPHERE LIMB TEXTURE NAME$ JOYSTICK HAT ANGLE GET FTP FILE NAME$ FORCE WATER EFFECT FLUSH VIDEO MEMORY DISABLE SYSTEMKEYS CHECKLIST QUANTITY CHECK DISPLAY MODE TURN OBJECT RIGHT TURN CAMERA RIGHT SUSPEND FOR MOUSE SHIFT MATRIX LEFT SHIFT MATRIX DOWN SET WINDOW LAYOUT SET MATRIX NORMAL SET MATRIX HEIGHT SET GRAPHICS CARD SET EMULATION OFF SET AMBIENT LIGHT ROLL OBJECT RIGHT ROLL CAMERA RIGHT POSITION LISTENER PITCH OBJECT DOWN PITCH CAMERA DOWN OBJECT POSITION Z OBJECT POSITION Y OBJECT POSITION X MATRIX TILE COUNT MATRIX POSITION Z MATRIX POSITION Y MATRIX POSITION X MAKE OBJECT PLAIN LIGHT DIRECTION Z LIGHT DIRECTION Y LIGHT DIRECTION X JOYSTICK SLIDER D JOYSTICK SLIDER C JOYSTICK SLIDER B JOYSTICK SLIDER A GET MATRIX HEIGHT GET GROUND HEIGHT GET FTP FILE TYPE GET FTP FILE SIZE ENABLE SYSTEMKEYS DISABLE ESCAPEKEY CLEAR CAMERA VIEW CHRISTOPHERBAMBER CHECKLIST VALUE D CHECKLIST VALUE C CHECKLIST VALUE B CHECKLIST VALUE A CHECKLIST STRING$ CAMERA POSITION Z CAMERA POSITION Y CAMERA POSITION X ANIMATION PLAYING ANIMATION LOOPING TURN OBJECT LEFT TURN CAMERA LEFT TEXTURE BACKDROP SPRITE COLLISION SOUND POSITION Z SOUND POSITION Y SOUND POSITION X SHOW ALL SPRITES SET WINDOW TITLE SET TEXT TO BOLD SET SOUND VOLUME SET OBJECT SPEED SET OBJECT FRAME SET MUSIC VOLUME SET EMULATION ON SET DISPLAY MODE SET CAMERA RANGE ROLL OBJECT LEFT ROLL CAMERA LEFT RESUME ANIMATION RANDOMIZE MATRIX OBJECT IN SCREEN OBJECT COLLISION MAKE OBJECT CUBE MAKE OBJECT CONE LISTENER ANGLE Z LISTENER ANGLE Y LISTENER ANGLE X LIMB DIRECTION Z LIMB DIRECTION Y LIMB DIRECTION X LIGHT POSITION Z LIGHT POSITION Y LIGHT POSITION X JOYSTICK TWIST Z JOYSTICK TWIST Y JOYSTICK TWIST X HIDE ALL SPRITES GHOST OBJECT OFF GHOST MATRIX OFF GET SOUND VOLUME GET MUSIC VOLUME GET FTP PROGRESS FIX OBJECT PIVOT ENABLE ESCAPEKEY DELETE DIRECTORY DELETE ANIMATION CONTROL DEVICE Z CONTROL DEVICE Y CONTROL DEVICE X ANIMATION PAUSED ANIMATION HEIGHT 3DBLIT AVAILABLE WRITE FILEBLOCK SUSPEND FOR KEY SPRITE OFFSET Y SPRITE OFFSET X SPRITE MIRRORED SHIFT MATRIX UP SET WINDOW SIZE SET TEXT OPAQUE SET SOUND SPEED SET POINT LIGHT SET MUSIC SPEED SET MIPMAP MODE SET MATRIX TILE SET LIGHT RANGE SET CAMERA VIEW SCROLL BACKDROP ROTATE LISTENER POSITION OBJECT POSITION MATRIX POSITION CAMERA PLACE ANIMATION PITCH OBJECT UP PITCH CAMERA UP PAUSE ANIMATION OBJECT SCREEN Y OBJECT SCREEN X MINIMIZE WINDOW MAXIMIZE WINDOW MAKE OBJECT BOX LOCK OBJECT OFF LIMB POSITION Z LIMB POSITION Y LIMB POSITION X JOYSTICK FIRE X JOYSTICK FIRE D JOYSTICK FIRE C JOYSTICK FIRE B JOYSTICK FIRE A GHOST OBJECT ON GHOST MATRIX ON GET SOUND SPEED GET MUSIC SPEED FTP DELETE FILE FORCE NO EFFECT EMPTY CHECKLIST CHECK LIMB LINK BITMAP MIRRORED ANIMATION WIDTH ANIMATION EXIST ZROTATE OBJECT ZROTATE CAMERA YROTATE OBJECT YROTATE CAMERA XROTATE OBJECT XROTATE CAMERA WRITE DIRBLOCK TEXTURE OBJECT STRETCH SPRITE STOP ANIMATION SPRITE SCALE Y SPRITE SCALE X SPRITE FLIPPED SET WINDOW OFF SET SPOT LIGHT SET CAMERA FOV SCREEN INVALID SCALE LISTENER RESTORE WINDOW READ FILEBLOCK POSITION SOUND POSITION MOUSE POSITION LIGHT PLAY ANIMATION OBJECT VISIBLE OBJECT PLAYING OBJECT LOOPING OBJECT ANGLE Z OBJECT ANGLE Y OBJECT ANGLE X MAKE DIRECTORY LOOP ANIMATION LOCK OBJECT ON LOAD ANIMATION JOYSTICK RIGHT GET FTP STATUS GET FILE NAME$ GET FILE DATE$ GET CLIPBOARD$ FTP FIND FIRST FTP DISCONNECT FORCE CHAINSAW EMULATION MODE CURRENT BITMAP COLOR BACKDROP CAMERA ANGLE Z CAMERA ANGLE Y CAMERA ANGLE X BITMAP FLIPPED UPDATE MATRIX UNLOCK EDITOR UNGLUE OBJECT TNL AVAILABLE SPRITE HEIGHT SOUND PLAYING SOUND LOOPING SET WINDOW ON SET TEXT SIZE SET TEXT FONT SET SOUND PAN SCREEN HEIGHT ROTATE OBJECT ROTATE CAMERA READ DIRBLOCK OPEN TO WRITE OFFSET SPRITE OBJECT SIZE Z OBJECT SIZE Y OBJECT SIZE X MUSIC PLAYING MUSIC LOOPING MIRROR SPRITE MIRROR BITMAP MALCOLMBAMBER LIMB OFFSET Z LIMB OFFSET Y LIMB OFFSET X LIGHT VISIBLE JOYSTICK LEFT JOYSTICK DOWN GET SOUND PAN GET FILE TYPE FTP TERMINATE FTP FIND NEXT FOG AVAILABLE DRAW TO FRONT DELETE SPRITE DELETE OBJECT DELETE MATRIX DELETE BITMAP CREATE BITMAP BOB COLLISION BITMAP HEIGHT APPEND OBJECT WRITE STRING TEXTURE LIMB SPRITE WIDTH SPRITE IMAGE SPRITE EXIST SPEECH EXIST SOUND PAUSED SCREEN WIDTH SCREEN DEPTH SCALE SPRITE SCALE OBJECT SAY TO SOUND ROTATE LIGHT RESUME SOUND RESUME MUSIC RECORD SOUND POINT OBJECT POINT CAMERA PASTE SPRITE OPEN TO READ OBJECT SPEED OBJECT FRAME OBJECT EXIST MUSIC PAUSED MATRIX EXIST LOAD CDMUSIC LOAD 3DSOUND LIMB VISIBLE LIMB TEXTURE LIMB ANGLE Z LIMB ANGLE Y LIMB ANGLE X GET FTP DIR$ FTP PUT FILE FTP GET FILE FORCE IMPACT FOG DISTANCE EXITFUNCTION EXECUTE FILE DRAW TO BACK DELETE SOUND DELETE MUSIC DELETE LIGHT DELETE IMAGE COLOR OBJECT CLONE OBJECT BOB OFFSET Y BOB OFFSET X BOB MIRRORED BITMAP WIDTH BITMAP EXIST BITMAP DEPTH BACKDROP OFF WRITE FLOAT TEXT HEIGHT STRETCH BOB STOP OBJECT SOUND EXIST SIZE SPRITE SHOW WINDOW SHOW SPRITE SHOW OBJECT SCREEN TYPE SAY TO FILE SAVE BITMAP ROTATE LIMB RENAME FILE READ STRING POINT LIGHT PLAY OBJECT PAUSE SOUND PAUSE MUSIC PASTE IMAGE OFFSET LIMB OBJECT SIZE MUSIC EXIST MOVE OBJECT MOVE CAMERA MAKE OBJECT MAKE MATRIX LOOP OBJECT LOCK EDITOR LOAD OBJECT LOAD BITMAP LIGHT RANGE LIGHT EXIST JOYSTICK UP IMAGE EXIST HIDE WINDOW HIDE SPRITE HIDE OBJECT FTP SET DIR FTP PROCEED FTP CONNECT FORCE SHOOT FORCE RIGHT FORCE ANGLE FLIP SPRITE FLIP BITMAP FILL MATRIX FADE OBJECT FADE BITMAP ENDFUNCTION DISABLE TNL DELETE MESH DELETE FILE COPY BITMAP COLOR LIGHT CLONE SOUND CHANGE MESH CENTER TEXT BOB SCALE Y BOB SCALE X BOB FLIPPED BLUR BITMAP BACKDROP ON AUTOCAM OFF WRITE WORD WRITE LONG WRITE FILE WRITE BYTE UNLOCK CLI TEXT WIDTH TEXT STYLE TEXT FONT$ STOP SOUND STOP MUSIC SPRITE HIT SOUND TYPE SKIP BYTES SHOW MOUSE SHOW LIGHT SET SPRITE SET OBJECT SET MATRIX SET CURSOR SCREEN FPS SCALE LIMB SAVE SOUND SAVE IMAGE SAVE ARRAY READ FLOAT PLAY SOUND PLAY MUSIC PATH EXIST OFFSET BOB OBJECT HIT MOUSEMOVEZ MOUSEMOVEY MOUSEMOVEX MOUSECLICK MIRROR BOB MESH EXIST MAKE LIGHT LOOP SOUND LOOP MUSIC LOAD SOUND LOAD MUSIC LOAD IMAGE LOAD ARRAY LIMB EXIST LIGHT TYPE JOYSTICK Z JOYSTICK Y JOYSTICK X HIDE MOUSE HIDE LIGHT FORCE LEFT FORCE DOWN FIND FIRST FILE EXIST ENABLE TNL DELETE BOB CURVEVALUE CURVEANGLE CONTROLKEY COLOR LIMB CLOSE FILE BOB HEIGHT AUTOCAM ON WRAPVALUE TEXT SIZE SYNC RATE STATISTIC SHOW LIMB SET GAMMA SCALE BOB RETURNKEY READ WORD READ LONG READ FILE READ BYTE RANDOMIZE PASTE BOB NEWZVALUE NEWYVALUE NEWXVALUE MOVE FILE MAKE FILE LOAD MESH LINK LIMB LEEBAMBER HIDE LIMB GET TIME$ GET IMAGE GET DATE$ FOG COLOR FIND NEXT FILE SIZE FILE OPEN ESCAPEKEY DRIVELIST COPY FILE BOB WIDTH BOB IMAGE BOB EXIST WAIT KEY SYNC OFF SPRITE Y SPRITE X SPACEKEY SHIFTKEY SCANCODE RIGHTKEY REMSTART LOCK CLI KEYSTATE GET DIR$ FUNCTION FORCE UP FLIP BOB FILE END ENDWHILE ATANFULL APPNAME$ ADD LIMB #INCLUDE WINDIR$ SYNC ON SET DIR SET BOB RESTORE LEFTKEY FOG OFF ELLIPSE DOWNKEY BOB HIT UPPER$ SPRITE SPACE$ RIGHT$ RETURN REPEAT REMEND PRINTC MOUSEZ MOUSEY MOUSEX LOWER$ INKEY$ FOG ON CIRCLE WHILE UPKEY UNTIL UNDIM TIMER SLEEP PRINT POINT LEFT$ INPUT GOSUB ENDIF BREAK BOB Y BOB X 3DS2X WAIT THEN TEXT SYNC STR$ STOP SQRT RGBR RGBG RGBB READ NEXT MID$ LOOP LINE HTAN HSIN HEX$ HCOS GOTO EXIT ELSE DATA CHR$ BIN$ ATAN ASIN ACOS VAL TAN SIN SAY RND RGB REM NOT LEN INT INK INC FOR EXP END DOT DIR DIM DEC COS CLS CL$ BOX BOB ASC AND ABS TO OR IF DO CD