 # Top-level objects shared by all the functions.
 opts         = {}
 sources      = []
-contents     = []
+sourceCode   = []
 optionParser = null
 
 # Run `coffee` by parsing passed options and determining what action to take.

# compile them. If a directory is passed, recursively compile all
# '.coffee' extension source files in it and all subdirectories.
compileScripts = ->
  unprocessed = []
  remainingFiles = ->
    total = 0
    total += x for x in unprocessed
    total
  trackUnprocessedFiles = (sourceIndex, fileCount) ->
    unprocessed[sourceIndex] ?= 0
    unprocessed[sourceIndex] += fileCount
  trackCompleteFiles = (sourceIndex, fileCount) ->
    unprocessed[sourceIndex] -= fileCount
    if opts.join
      if helpers.compact(contents).length > 0 and remainingFiles() is 0
        compileJoin()
  for source in sources
    trackUnprocessedFiles sources.indexOf(source), 1
  for source in sources
    base = path.join(source)
    compile = (source, sourceIndex, topLevel) ->
      path.exists source, (exists) ->
        if topLevel and not exists and source[-7..] isnt '.coffee'
          return compile "#{source}.coffee", sourceIndex, topLevel
        if topLevel and not exists 
          console.error "File not found: #{source}"
          process.exit 1

          if stats.isDirectory()
            fs.readdir source, (err, files) ->
              throw err if err
              files = files.map (file) -> path.join source, file
              index = sources.indexOf source
              sources[index..index] = files
              sourceCode[index..index] = files.map -> null
              compile file for file in files
          else if topLevel or path.extname(source) is '.coffee'
            fs.readFile source, (err, code) ->
              throw err if err
              compileScript(source, code.toString(), base)
            watch source, base if opts.watch
          else
            index = sources.indexOf source
            sources.splice index, 1
            sourceCode.splice index, 1
            
    compile source, true

# Compile a single source script, containing the given code, according to the
# requested options. If evaluating the script directly sets `__filename`,
