"; $prefix2='olink targetptr="start">'; $prefix3='olink targetptr="end">'; $prefix4='label="['; $prefix5='label="'; $prefix6='COMM.IOVBK~CH.'; $lookup="[30.,[29. [32.,[30. [33.,[31. [34.,[32. [35.,[33. [36.,[34. [37.,[35. [38.,[36. [39.,[37. [40.,[38. [41.,[39. [42.,[40. [43.,[41. [46.,[42. [47.,[43. [48.,[44. [49.,[45. [50.,[46. [50A.,[47. [52.,[48. [53.,[49. [54.,[50. [55.,[51. [56.,[52. [59.,[53. [60.,[54. [61.,[55."; $ourlookup=$lookup; if (isset($argv[0])) { // PHP command line specific interactive input code below ... $ourlookup=""; print " Chapter Renumbering ------------------- "; $filespec = "COM_.IOVBK/*.xml"; print "Type file specification [COM_.IOVBK/*.xml].\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first) { if ($things[0] == "" || strlen($line) == 0) { $filespec="COM_.IOVBK/*.xml"; } else { $filespec=$things[0]; } } $first=false; } $bits=explode(".",$filespec); $thisext=$bits[sizeof($bits) - 1]; $bckext=strrev($thisext); if ($bckext == $thisext) $bckext .= "_bck"; $things=explode("\n", $line); print "Type comma separated chapter mapping data [[30.,[29. [32.,[30. [33.,[31. [34.,[32. [35.,[33. [36.,[34. [37.,[35. [38.,[36. [39.,[37. [40.,[38. [41.,[39. [42.,[40. [43.,[41. [46.,[42. [47.,[43. [48.,[44. [49.,[45. [50.,[46. [50A.,[47. [52.,[48. [53.,[49. [54.,[50. [55.,[51. [56.,[52. [59.,[53. [60.,[54. [61.,[55.]\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first || 1 == 1) { if ($first && ($things[0] == "" || strlen($line) == 0)) { $ourlookup=$lookup; } else { $ourlookup.=$things[0] . "\n"; } } $first=false; } print "Type the string that causes no internal clashes [#@!@#] by being temporarily placed before '.'.\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first) { if ($things[0] == "" || strlen($line) == 0) { $ynftt="#@!@#"; } else { $ynftt=$things[0]; } } $first=false; } print "Type the prefix identifier 1 of 6 [olink>] (before what is in your lookup).\n Type dot to not do this substitution idea.\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first) { if ($things[0] == "" || strlen($line) == 0) { $prefix1="olink>"; } else if ($things[0] == '.') { $prefix1=""; } else { $prefix1=trim($things[0]); } } $first=false; } print "Type the prefix identifier 2 of 6 [olink targetptr=" . '"' . "start" . '"' . ">] (before what is in your lookup).\n Type dot to not do this substitution idea.\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first) { if ($things[0] == "" || strlen($line) == 0) { $prefix2='olink targetptr="start">'; } else if ($things[0] == '.') { $prefix2=""; } else { $prefix2=trim($things[0]); } } $first=false; } print "Type the prefix identifier 3 of 6 [olink targetptr=" . '"' . "end" . '"' . ">] (before what is in your lookup).\n Type dot to not do this substitution idea.\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first) { if ($things[0] == "" || strlen($line) == 0) { $prefix3='olink targetptr="end">'; } else if ($things[0] == '.') { $prefix3=""; } else { $prefix3=trim($things[0]); } } $first=false; } print "Type the prefix identifier 4 of 6 [label=" . '"' . "[] (before just the chapter number and " . '.' . ").\n Type dot to not do this substitution idea.\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first) { if ($things[0] == "" || strlen($line) == 0) { $prefix4='label="['; } else if ($things[0] == '.') { $prefix4=""; } else { $prefix4=trim($things[0]); } } $first=false; } print "Type the prefix identifier 5 of 6 [label=" . '"' . "] (before just the chapter number and " . '"' . ").\n Type dot to not do this substitution idea.\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first) { if ($things[0] == "" || strlen($line) == 0) { $prefix5='label="'; } else if ($things[0] == '.') { $prefix5=""; } else { $prefix5=trim($things[0]); } } $first=false; } print "Type the prefix identifier 6 of 6 [COMM.IOVBK~CH.] (before just the chapter number and " . '"' . ").\n Type dot to not do this substitution idea.\n Type nothing on a line by itself when you're done.\n"; $line = " "; $first=true; while (strlen($line) != 0) { $line = trim(fgets(STDIN)); // reads one line from STDIN //fscanf(STDIN, "%s\n%s", $filespec, $other); // reads number from STDIN $things=explode("\n", $line); if ($first) { if ($things[0] == "" || strlen($line) == 0) { $prefix6="COMM.IOVBK~CH."; } else if ($things[0] == '.') { $prefix6=""; } else { $prefix6=trim($things[0]); } } $first=false; } } // ... end of PHP command line specific interactive input code //echo $ourlookup; $from=[]; $to=[]; $flist=""; $num = 0; foreach (glob($filespec) as $filename) { if (!file_exists(str_replace("." . $thisext, "." . $bckext, $filename))) { file_put_contents(str_replace("." . $thisext, "." . $bckext, $filename), file_get_contents($filename)); } $flist.=$filename."\n"; $num++; } $lbits=explode("\n", $ourlookup); //$lookup); for ($i=0; $i