Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
the stuff is now in a library which comes with Parrot
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Nov 5, 2009
1 parent 700ef97 commit c035be3
Showing 1 changed file with 2 additions and 119 deletions.
121 changes: 2 additions & 119 deletions Configure.pir
Expand Up @@ -5,6 +5,8 @@
.include 'iglobals.pasm'

.sub 'main' :main
load_bytecode 'Configure.pbc'

# Wave to the friendly users
print "Hello, I'm Configure. My job is to poke and prod\n"
print "your system to figure out how to build Markdown.\n"
Expand Down Expand Up @@ -56,125 +58,6 @@
end
.end


.sub 'genfile'
.param string tmpl
.param string outfile
.param pmc config
$S0 = slurp(tmpl)
$S0 = subst_config($S0, config)
$S0 = subst_slash($S0)
output(outfile, $S0)
printerr "\n\tGenerating '"
printerr outfile
printerr "'\n\n"
.end

.sub 'slurp'
.param string filename
$P0 = new 'FileHandle'
push_eh _handler
$S0 = $P0.'readall'(filename)
pop_eh
.return ($S0)
_handler:
.local pmc e
.get_results (e)
$S0 = "Can't open '"
$S0 .= filename
$S0 .= "' ("
$S1 = err
$S0 .= $S1
$S0 .= ")\n"
e = $S0
rethrow e
.end

.sub 'output'
.param string filename
.param string content
$P0 = new 'FileHandle'
push_eh _handler
$P0.'open'(filename, 'w')
pop_eh
$P0.'puts'(content)
$P0.'close'()
.return ()
_handler:
.local pmc e
.get_results (e)
$S0 = "Can't open '"
$S0 .= filename
$S0 .= "' ("
$S1 = err
$S0 .= $S1
$S0 .= ")\n"
e = $S0
rethrow e
.end

.sub 'subst_config'
.param string content
.param pmc config
$P0 = split "\n", content
.local string result, line
result = ''
L1:
unless $P0 goto L2
line = shift $P0
$I0 = 0
$S0 = ''
L3:
$I1 = index line, '@', $I0
if $I1 < 0 goto L4
$I2 = $I1 - $I0
inc $I1
$I3 = index line, '@', $I1
if $I3 < 0 goto L4
$S1 = substr line, $I0, $I2
$S0 .= $S1
$I4 = $I3 - $I1
$S1 = substr line, $I1, $I4
$I7 = exists config[$S1]
unless $I7 goto L5
$S2 = config[$S1]
$S0 .= $S2
goto L6
L5:
printerr "\tunknown config: "
printerr $S1
printerr "\n"
L6:
$I0 = $I3 + 1
goto L3
L4:
$S1 = substr line, $I0
$S0 .= $S1
result .= $S0
result .= "\n"
goto L1
L2:
.return (result)
.end

.sub 'subst_slash'
.param string str
$S1 = sysinfo .SYSINFO_PARROT_OS
unless $S1 == 'MSWin32' goto L1
$P0 = split "/", str
str = join "\\", $P0
$P0 = split "\\\\", str
str = join "/", $P0
$P0 = split "\\*", str
str = join "\\\\*", $P0
.return (str)
L1:
$P0 = split "//", str
str = join "/", $P0
.return (str)
.end


# Local Variables:
# mode: pir
# fill-column: 100
Expand Down

0 comments on commit c035be3

Please sign in to comment.