diff --git a/src/cscope.coffee b/src/cscope.coffee index bba2c8a..305306a 100644 --- a/src/cscope.coffee +++ b/src/cscope.coffee @@ -1,36 +1,25 @@ -# TODO: rename methods in a consistent way -# TODO: Gruntfile.coffee (refer to github.com/atom/node-ctags) -# TODO: add tests -# TODO: move all this to github issues - nexpect = require 'nexpect' -findSymbolCmd = "1" -funcsCalledByCmd = "2" -funcsCallingCmd = "3" -# findTextStringCmd = "4" # FIXME: only same dir -# changeTextStringCmd = "5" # TODO: do i need this at all? -# findEgrepPatternCmd = "6" # FIXME: only same dir -findFileCmd = "7" -findFilesIncludingCmd = "8" -findAssignCmd = "9" - -symbolToSearch = process.argv[2] -dbPath = process.argv[3] -if !symbolToSearch || !dbPath - console.log "Usage: coffee cscope.coffee " - process.exit 1 +cmd = + findSymbol: '1' + findCallees: '2' + findCallers: '3' + findFile: '7' + findIncluders: '8' + findAssignments: '9' -genericFind = (cmd, symbol, db, callback) -> +genericFind = (cmd, symbol, options, callback) -> cscopeRegex = /cscope: (\d+) lines/ outputRegex = /([\w.\/]+)\s+([a-zA-Z_$][\w$]+|)\s+(\d+)\s+(.+)/ prompt = ">> " quitCmd = "q" - nexpect.spawn "cscope" - , ["-d", "-k", "-l", "-f" + db] + opts = ['-l', '-k', '-d'] + opts.push '-f' + options.refFile if options.refFile + + nexpect.spawn "cscope", opts .expect prompt - .sendline cmd + symbolToSearch + .sendline cmd + symbol .wait cscopeRegex .sendline quitCmd .run (err, stdout, exitcode) -> @@ -63,43 +52,16 @@ genericFind = (cmd, symbol, db, callback) -> ctx: m[4] callback res -findSymbol = (symbol, db, callback) -> - genericFind findSymbolCmd, symbol, db, callback - -funcsCalledBy = (symbol, db, callback) -> - genericFind funcsCalledByCmd, symbol, db, callback - -funcsCalling = (symbol, db, callback) -> - genericFind funcsCallingCmd, symbol, db, callback - -# findTextString = (symbol, db, callback) -> -# genericFind findTextStringCmd, symbol, db, callback - -# changeTextString = (symbol, db, callback) -> -# genericFind changeTextStringCmd, symbol, db, callback - -# findEgrepPattern = (symbol, db, callback) -> -# genericFind findEgrepPatternCmd, symbol, db, callback - -findFile = (symbol, db, callback) -> - genericFind findFileCmd, symbol, db, callback - -findFilesIncluding = (symbol, db, callback) -> - genericFind findFilesIncludingCmd, symbol, db, callback - -findAssign = (symbol, db, callback) -> - genericFind findAssignCmd, symbol, db, callback - -printResult = (results) -> - for r in results - console.log "file: #{r.file}, sym: #{r.sym}, line: #{r.line}" - -# findSymbol symbolToSearch, dbPath, printResult -funcsCalledBy symbolToSearch, dbPath, printResult -# funcsCalling symbolToSearch, dbPath, printResult -# findTextString symbolToSearch, dbPath, printResult -# changeTextString symbolToSearch, dbPath, printResult -# findEgrepPattern symbolToSearch, dbPath, printResult -# findFile symbolToSearch, dbPath, printResult -# findFilesIncluding symbolToSearch, dbPath, printResult -# findAssign symbolToSearch, dbPath, printResult +module.exports = + findSymbol: (symbol, options, callback) -> + genericFind cmd.findSymbolCmd, symbol, options, callback + findCallees: (symbol, options, callback) -> + genericFind cmd.findCallees, symbol, options, callback + findCallers: (symbol, options, callback) -> + genericFind cmd.findCallers, symbol, options, callback + findFile: (symbol, options, callback) -> + genericFind cmd.findFile, symbol, options, callback + findIncluders: (symbol, options, callback) -> + genericFind cmd.findIncluders, symbol, options, callback + findAssignments: (symbol, options, callback) -> + genericFind cmd.findAssignments, symbol, options, callback