develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35061 - trunk/languages/befunge

From:
jquelin
Date:
January 6, 2009 10:26
Subject:
[svn:parrot] r35061 - trunk/languages/befunge
Message ID:
20090106182601.21956CB9F9@x12.develooper.com
Author: jquelin
Date: Tue Jan  6 10:26:00 2009
New Revision: 35061

Modified:
   trunk/languages/befunge/befunge.pir

Log:
moved argv parsing in a sub


Modified: trunk/languages/befunge/befunge.pir
==============================================================================
--- trunk/languages/befunge/befunge.pir	(original)
+++ trunk/languages/befunge/befunge.pir	Tue Jan  6 10:26:00 2009
@@ -15,35 +15,16 @@
 .sub "befunge" :main
     .param pmc argv
 
-    .local int    i, debug
-    .local string arg, char, file
-    .local pmc    playfield
-
     print "befunge being ported to a working state...\n"
 
     # disable buffering on stdout
     #getstdout stdout
     #pioctl I10, P10, 3, 0
 
+    .local int debug
+    .local pmc playfield
+    (debug, playfield) = _parse_argv(argv)
 
-    i     = 0
-    debug = 0
-
-ARGV_NEXT:
-    inc i
-    arg  = argv[i]
-    char = substr arg, 0, 1
-    ne char, "-",  ARGV_DONE
-    eq arg,  "-d", ARGV_DEBUG
-    goto ARGV_NEXT
-
-ARGV_DEBUG:
-    debug_initialize()
-    goto ARGV_NEXT
-
-ARGV_DONE:
-    file      = argv[i]
-    playfield = load(file)
 
 =pod
 
@@ -146,3 +127,40 @@
         end
 .end
 
+
+#
+# (playfield, debug) = _parse_argv(argv)
+#
+# parse argv and return the playfield loaded from the file passed as argument,
+# and a boolean telling whether we're in debug mode or not.
+#
+.sub "_parse_argv"
+    .param pmc argv
+    
+    .local int    i, debug
+    .local string arg, char, file
+    .local pmc    playfield
+    
+    i     = 0
+    debug = 0
+  _PARSE_ARGS__ARGV_NEXT:
+    inc i
+    arg  = argv[i]
+    char = substr arg, 0, 1
+    if char != "-"   goto _PARSE_ARGV__DONE
+    if arg  ==  "-d" goto _PARSE_ARGV__DEBUG
+    goto _PARSE_ARGS__ARGV_NEXT
+
+  _PARSE_ARGV__DEBUG:
+    debug_initialize()
+    debug = 1
+    goto _PARSE_ARGS__ARGV_NEXT
+
+  _PARSE_ARGV__DONE:
+    file      = argv[i]
+    playfield = load(file)
+    
+    .return(playfield, debug)
+.end
+
+



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About