/* NT ooREXX: rename all upper case 8+3 file names to lower case. */ /* Usage: dirty [directory] */ /* If a directory is specified the script fixes 8+3 names in */ /* and below this directory. A typical use case is `dirty .` */ /* to fix the actual directory and its subdirectories. */ /* "Content Management System" (own your roll): */ /* If no directory is specified the script fixes a predefined */ /* directory tree (see variable ROOT below) and calls DIR2HTML */ /* to update index.html files. DIR2HTML then calls SITEMAP to */ /* update sitemap.xml + sitenew.xml + siteold.xml. */ /* Installation */ /* 1: Copy DIRTY.REX, DIR2HTML.CMD, and SITEMAP.CMD to your tools */ /* or REXX directory. For NT ooREXX rename two copied *.CMD */ /* to *.REX. For OS/2 REXX rename one copied *.REX to *.CMD. */ /* 2: Edit the ROOT and BASE variables in SITEMAP. ROOT is the */ /* local directory of your site including all subdirectories. */ /* BASE is the "canonical" URL of your site. Test SITEMAP, it */ /* should create files sitemap.xml + sitenew.xml + siteold.xml */ /* in the ROOT directory. */ /* 3: While you are at it update the robots.txt file in the ROOT */ /* directory. A minimal robots.txt for BASE http:\\www.xxx.yy */ /* consists of three lines: */ /* Sitemap: http://www.xxx.yy/sitemap.xml */ /* User-agent: * */ /* Disallow: */ /* 4: Edit some variables in DIR2HTML. Variable DIR.. should be */ /* the same as ROOT in SITEMAP. Variable H.. can be the same */ /* as BASE, but it can be also a user friendly "short URL" of */ /* your site. Technically: H.. can be a redirecting URL, but */ /* the BASE for web crawlers should be the final URL. */ /* 5: Test DIR2HTML, it should create simple index.html files in */ /* the listed subdirectories DIR.1, DIR.2, DIR.3, etc., of the */ /* root DIR.. Open one of these local index.html files with */ /* your browser to check the mandatory W3C validator icon, an */ /* optional site banner image, and an optional style sheet. */ /* ! It makes no sense to have an index.html and an index.htm in */ /* ! the same directory. List only subdirectories without index */ /* ! as DIR.1, DIR.2, etc. in DIR2HTML. The subdirectories can */ /* ! be at any level below the root DIR.. (DIR2HTML adjusts all */ /* ! relative paths). */ /* DIR2HTML calls SITEMAP to update sitenew.xml (there are new */ /* index.htm files) and sitemap.xml (sitenew.xml is new). */ /* If siteold.xml is also updated some old index.html files */ /* were replaced by DIR2HTML - make sure that you wanted this. */ /* 7: Edit variable ROOT in DIRTY. This should be the same ROOT */ /* as in SITEMAP. Test DIRTY, it will call DIR2HTML. */ /* Maintenance: */ /* 1: When you add, update, or delete local files in or below the */ /* ROOT directory use DIRTY to refresh index.html and sitemap */ /* files. */ /* 2: Whenever the sitemap was changed upload all changed files */ /* to your site. FTPSYNCH.REX (NT) or FTPSYNCH.CMD (OS/2) can */ /* do this. FTPSYNCH also deletes "unknown" remote files, if */ /* you deleted the corresponding local files. */ /* 3: When you add (or remove) local subdirectories below ROOT */ /* update DIR2HTML if necessary. FTPSYNCH automatically adds */ /* missing remote subdirectories. FTPSYNCH ignores "unknown" */ /* remote subdirectories. In other words, you have to remove */ /* obsolete remote subdirectories manually; this is a feature. */ /* 4: If you move your site to another hoster update the BASE (in */ /* SITEMAP) and the corresponding robots.txt line. Update H.. */ /* in DIR2HTML if necessary, otherwise redirect H.. to the new */ /* BASE. In both cases use DIRTY to update the index.html and */ /* sitemap files. */ /* References: (Frank Ellermann, 2010) */ /* (= this script) */ /* SITEMAP (REXX) */ /* DIR2HTML (REXX) */ /* FTPSYNCH OS/2 REXX */ /* FTPSYNCH NT ooREXX */ /* manual for scripts */ ROOT = 'd:\inetpub\ftproot' signal on novalue name TRAP ; signal on syntax name TRAP signal on failure name TRAP ; signal on halt name TRAP call UTIL 'SysFileTree' ; signal on error name TRAP LOWER = xrange( 'a', 'z' ) ; UPPER = translate( LOWER ) FIXED = 0 ; TOTAL = 0 SUB = strip( strip( strip( arg( 1 )),, '"' )) if SUB = '' then DIR = ROOT ; else do DIR = stream( SUB, 'c', 'q exists' ) if DIR <> '' then exit TRAP( 'no directory:' DIR ) DIR = directory( SUB ) if DIR = '' then exit TRAP( 'not found:' SUB ) end if right( DIR, 2 ) = ':\' then DIR = left( DIR, 2 ) SHY = '**-*-' /* AD-R- (not H and not S) */ call SysFileTree DIR || '\', 'D.', 'DOS', SHY if result <> 0 then exit TRAP( 'SysFileTree' DIR result ) SUB = D.0 + 1 ; D.SUB = DIR ; D.0 = SUB do SUB = 1 to D.0 DIR = D.SUB || '\*' call SysFileTree DIR, 'F.', 'FO', SHY if result <> 0 then exit TRAP( 'SysFileTree' DIR result ) DIR = length( DIR ) ; TOTAL = TOTAL + F.0 do FILE = 1 to F.0 PATH = F.FILE ; NAME = substr( PATH, DIR ) if NAME <> translate( NAME ) then iterate FILE NAME = translate( NAME, LOWER, UPPER ) address CMD '@ren "' || PATH || '" "' || NAME || '"' FIXED = FIXED + 1 ; say PATH end FILE end SUB if FIXED <> 0 | TOTAL = 0 /* if something happened: */ then say FIXED 'of' TOTAL 'file names fixed to lower case' if arg( 1 ) = '' then exit dir2html() ; else exit 0 /* see , (c) F. Ellermann */ UTIL: procedure /* load necessary RexxUtil entry */ if RxFuncQuery( arg( 1 )) then if RxFuncAdd( arg( 1 ), 'RexxUtil', arg( 1 )) then exit TRAP( "can't add RexxUtil" arg( 1 )) return 0 TRAP: /* select REXX exception handler */ call trace 'O' ; trace N /* don't trace interactive */ parse source TRAP /* source on separate line */ TRAP = x2c( 0D ) || right( '+++', 10 ) TRAP || x2c( 0D0A ) TRAP = TRAP || right( '+++', 10 ) /* = standard trace prefix */ TRAP = TRAP strip( condition( 'c' ) 'trap:' condition( 'd' )) select when wordpos( condition( 'c' ), 'ERROR FAILURE' ) > 0 then do if condition( 'd' ) > '' /* need an additional line */ then TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 ) TRAP = TRAP '(RC' rc || ')' /* any system error codes */ if condition( 'c' ) = 'FAILURE' then rc = -3 end when wordpos( condition( 'c' ), 'HALT SYNTAX' ) > 0 then do if condition( 'c' ) = 'HALT' then rc = 4 if condition( 'd' ) > '' & condition( 'd' ) <> rc then do if condition( 'd' ) <> errortext( rc ) then do TRAP = TRAP || x2c( 0D0A ) || right( '+++', 10 ) TRAP = TRAP errortext( rc ) end /* future condition( 'd' ) */ end /* may use errortext( rc ) */ else TRAP = TRAP errortext( rc ) rc = -rc /* rc < 0: REXX error code */ end when condition( 'c' ) = 'NOVALUE' then rc = -2 /* dubious */ when condition( 'c' ) = 'NOTREADY' then rc = -1 /* dubious */ otherwise /* force non-zero whole rc */ if datatype( value( 'RC' ), 'W' ) = 0 then rc = 1 if rc = 0 then rc = 1 if condition() = '' then TRAP = TRAP arg( 1 ) end /* direct: TRAP( message ) */ TRAP = TRAP || x2c( 0D0A ) || format( sigl, 6 ) signal on syntax name TRAP.SIGL /* throw syntax error 3... */ if 0 < sigl & sigl <= sourceline() /* if no handle for source */ then TRAP = TRAP '*-*' strip( sourceline( sigl )) else TRAP = TRAP '+++ (source line unavailable)' TRAP.SIGL: /* ...catch syntax error 3 */ if abbrev( right( TRAP, 2 + 6 ), x2c( 0D0A )) then do TRAP = TRAP '+++ (source line unreadable)' ; rc = -rc end select when 0 then do /* in pipes STDERR: output */ parse version TRAP.REXX /* REXX/Personal: \dev\con */ if abbrev( TRAP.REXX, 'REXXSAA ' ) | /**/ , 6 <= word( TRAP.REXX, 2 ) then TRAP.REXX = 'STDERR' else TRAP.REXX = '\dev\con' signal on syntax name TRAP.FAIL call lineout TRAP.REXX , TRAP /* fails if no more handle */ end when 0 then do /* OS/2 PM or ooREXX on NT */ signal on syntax name TRAP.FAIL call RxMessageBox translate( TRAP, ' ', x2c( 0D )), /**/ , 'Trap' time(),, 'ERROR' end otherwise say TRAP ; trace ?L /* interactive Label trace */ end if condition() = 'SIGNAL' then signal TRAP.EXIT TRAP.CALL: return rc /* continue after CALL ON */ TRAP.FAIL: say TRAP ; rc = 0 - rc /* force TRAP error output */ TRAP.EXIT: exit rc /* exit for any SIGNAL ON */