| |
| /pliant/sample/typo.pli |
| |
| 1 |
abstract | |
| 2 |
[This program is expected to automaticaly apply some typo changes in order to correct my poor english.] ; eol | |
| 3 |
highlight "make a backup before running this" | |
| 4 |
| |
| 5 |
| |
| 6 |
module "/pliant/language/stream.pli" | |
| 7 |
module "/pliant/language/unsafe.pli" | |
| 8 |
module "/pliant/admin/file.pli" | |
| 9 |
module "/pliant/admin/asciifile.pli" | |
| 10 |
| |
| 11 |
| |
| 12 |
function oneup s -> s2 | |
| 13 |
arg Str s s2 | |
| 14 |
s2 := upper:(s 0 1)+(s 1 s:len) | |
| 15 |
| |
| 16 |
function sameup replace with -> result | |
| 17 |
arg Str replace with result | |
| 18 |
if replace=lower:replace | |
| 19 |
result := lower with | |
| 20 |
eif replace=upper:replace | |
| 21 |
result := upper with | |
| 22 |
eif replace=oneup:replace | |
| 23 |
result := oneup with | |
| 24 |
else | |
| 25 |
console "!!! " replace eol | |
| 26 |
result := replace | |
| 27 |
| |
| 28 |
| |
| 29 |
gvar Dictionary changes | |
| 30 |
| |
| 31 |
function change replace with | |
| 32 |
arg Str replace with | |
| 33 |
changes insert replace true addressof:(new Str with) | |
| 34 |
| |
| 35 |
| |
| 36 |
change "peaces" "pieces" | |
| 37 |
change "flushy" "flashy" | |
| 38 |
change "durty" "dirty" | |
| 39 |
| |
| 40 |
| |
| 41 |
function typo filename apply_changes | |
| 42 |
arg Str filename ; arg CBool apply_changes | |
| 43 |
var CBool some := false | |
| 44 |
(var AsciiFile ft) load filename | |
| 45 |
for (var Int l) 0 ft:size-1 | |
| 46 |
var Int i := 0 | |
| 47 |
while i<ft:l:len | |
| 48 |
var Char ch := ft:l:i | |
| 49 |
if ch>="a" and ch<="z" or ch>="A" and ch<="Z" | |
| 50 |
var Int j := i+1 | |
| 51 |
part find_word | |
| 52 |
if j<ft:l:len | |
| 53 |
var Char ch := ft:l:j | |
| 54 |
if ch>="a" and ch<="z" or ch>="A" and ch<="Z" | |
| 55 |
j+= 1 | |
| 56 |
restart find_word | |
| 57 |
var Str word := lower (ft:l i j-i) | |
| 58 |
if (changes first word)<>null | |
| 59 |
console (left word 30 " ") " " filename " " l eol | |
| 60 |
var Str with := (changes first word) map Str | |
| 61 |
ft l := (ft:l 0 i)+(sameup word with)+(ft:l j ft:l:len) | |
| 62 |
i += with:len | |
| 63 |
some := true | |
| 64 |
else | |
| 65 |
i := j | |
| 66 |
eif ch>="0" and ch<="9" | |
| 67 |
part skip_number | |
| 68 |
i += 1 | |
| 69 |
var Char ch := ft:l:i | |
| 70 |
if ch>="0" and ch<="9" or ch>="a" and ch<="z" or ch>="A" and ch<="Z" | |
| 71 |
i+= 1 | |
| 72 |
restart skip_number | |
| 73 |
else | |
| 74 |
i += 1 | |
| 75 |
if apply_changes and some | |
| 76 |
ft store | |
| 77 |
| |
| 78 |
| |
| 79 |
function typo apply_changes | |
| 80 |
arg CBool apply_changes | |
| 81 |
var Array:FileInfo files := file_list "/pliant/" standard+recursive | |
| 82 |
for (var Int i) 0 files:size-1 | |
| 83 |
var Str f := files:i:name | |
| 84 |
var Str e := files:i extension | |
| 85 |
if f="/pliant/sample/typo.pli" | |
| 86 |
void | |
| 87 |
eif (" .c .pli .style .page .html " search " "+e+" " -1)<>(-1) | |
| 88 |
typo files:i:name apply_changes | |
| 89 |
eif (" .s .lst .o .jpeg .png .fig .exe .dump .dll .so .bat .zip .tgz " search " "+e+" " -1)<>(-1) | |
| 90 |
void | |
| 91 |
eif e="" | |
| 92 |
void | |
| 93 |
else | |
| 94 |
console "unexpected extension for file " files:i:name eol | |
| 95 |
| |
| 96 |
export typo | |
| 97 |
| |
| |