Vidir: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 107: Line 107:
{ „mypath” }
{ „mypath” }
{ „filtered” }
{ „filtered” }
{ „pidstring” }
{ „myfilename” }
{ „mycommand” }
{ „editedlist” }
{ „foundflag” }
{ „aktfilename” }
{ „neworiginalname” }

</syntaxhighlight>

=={{header|Peri}}==
<syntaxhighlight lang="peri">
###sysinclude standard.uh
###sysinclude args.uh
###sysinclude list.uh
###sysinclude str.uh
###sysinclude io.uh
###define SEPARATOR 9
#g argc 3 < { "." }{ 2 argv } sto mypath
@mypath 'd inv istrue { ."The given directory doesn't exist! Exited.\n" end }
6 '- pidstr sto pidstring
@mypath getdir { ."Cannot load the dir! Aborted.\n" end } sto mydir
mypath per // Ha nem per-jelre végződik, kiegészíti vele.
10 mem sto aktstr
10 mem sto aktfilename
10 mem sto neworiginalname
"dr" sto types
1 mem !maximize sto szep
@szep 0 SEPARATOR inv []
@mydir ~r @mydir ~d + sto elemszám
//@elemszám 300 [[mem]] sto tömb
@elemszám 1 [[mem]] sto tömb
zero index
types {~ @mydir {~?~} <-~ {{ #g
1 sto() aktstr~
@aktstr 0 {~?~} #k uppercase inv []
#s @szep sum aktstr
{{}} #g !(#s) !trim dup sum aktstr inv mem
@szep sum aktstr
@mydir {~?~} {{}} getfilename sum aktstr
@aktstr @index [[tömb]]=
#g ++() index
}}
~}
"/tmp/peridiredit_tempfile-" sto myfilename
#s
@pidstring sum myfilename
".txt" sum myfilename
@tömb @myfilename listtofile! // print the list into a temporary file
"EDITOR" env sto mycommand
" " sum mycommand
@myfilename sum mycommand

@mycommand shell // execute the command

@myfilename filetolist sto editedlist
//@editedlist [[print]]! end

tömb~ externalloop: {{ // Loop for the original list
#g {{}} @[[tömb]] ~ inv { {{<}} } // If empty lines occured...
zero foundflag
editedlist~ {{ // loop for the edited list
// searching for the originaltype and originalnumber:
#g
{{}} [[editedlist]][0] {{}}§externalloop [[tömb]][0] != { {{<}} }
SEPARATOR {{}} 1 [[editedlist]][_] sto uj
SEPARATOR {{}}§externalloop 1 [[tömb]][_] sto er
#s @er @uj != { @er inv mem @uj inv mem {{<}} }

SEPARATOR {{}} 2 [[editedlist]][_] -- sto uj // trim the NL char at the end of the string
SEPARATOR {{}}§externalloop 2 [[tömb]][_] sto er
#s @er @uj != {
aktfilename @mypath = @er sum aktfilename
neworiginalname @mypath = @uj sum neworiginalname
@aktfilename @neworiginalname rename
."Renamed : " @aktfilename printnl
." ==> " @neworiginalname printnl
}
@er inv mem @uj inv mem
one foundflag
}} // editedlist~
@foundflag inv { // Nincs meg a file vagy dir. Ekkor le kell törölni:
{{}} [[tömb]][0] 'D #g == { // directory
SEPARATOR {{}} 2 [[tömb]][_] sto er
aktfilename @mypath #s = @er sum aktfilename @er inv mem
@aktfilename rmdir
."Deleted : " @aktfilename sprintnl
{{<}}
}
{{}} [[tömb]][0] 'R #g == { // Regular file
SEPARATOR {{}} 2 [[tömb]][_] sto er
aktfilename @mypath #s = @er sum aktfilename @er inv mem
@aktfilename removefile
."Deleted : " @aktfilename sprintnl
{{<}}
}
}
}} // tömb~
@myfilename removefile
end

{ „er” }
{ „uj” }
{ „szep” }
{ „types” }
{ „index” }
{ „mydir” }
{ „tömb” }
{ „mypath” }
{ „aktstr” }
{ „elemszám” }
{ „pidstring” }
{ „pidstring” }
{ „myfilename” }
{ „myfilename” }