Created
March 13, 2010 23:42
-
-
Save ybakos/331632 to your computer and use it in GitHub Desktop.
Excerpt from translator.rb, showing students filename handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Begin driver script. | |
| # | |
| # Expects only one argument, the .vm filename or directory | |
| def args_valid? | |
| if ARGV.size == 1 && (File.extname(ARGV[0]) == '.vm' || File.directory?(ARGV[0])) | |
| true | |
| else | |
| false | |
| end | |
| end | |
| def parse_filenames(path) | |
| if File.directory?(path) | |
| dirname = path.chomp('/') | |
| vm_filenames = [] | |
| Dir.foreach(dirname) do |f| | |
| vm_filenames << "#{dirname}/#{f}" if File.extname(f) == '.vm' | |
| end | |
| else | |
| vm_filenames = path | |
| end | |
| return vm_filenames | |
| end | |
| if args_valid? then Translator.translate!(parse_filenames(ARGV[0])) | |
| else abort('Usage: ./translator.rb <Prog.vm> | <directory>') end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment