Skip to content

Commit

Permalink
fix indentation (4 -> 2 spaces)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalyazin authored and Nikita Kalyazin committed Apr 23, 2014
1 parent 13c6591 commit f36a8ef
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions src/cscope.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,81 +18,81 @@ findAssignCmd = "9"
symbolToSearch = process.argv[2]
dbPath = process.argv[3]
if !symbolToSearch || !dbPath
console.log "Usage: coffee cscope.coffee <symbol> <db>"
process.exit 1
console.log "Usage: coffee cscope.coffee <symbol> <db>"
process.exit 1

genericFind = (cmd, symbol, db, callback) ->
cscopeRegex = /cscope: (\d+) lines/
outputRegex = /([\w.\/]+)\s+([a-zA-Z_$][\w$]+|<unknown>)\s+(\d+)\s+(.+)/
prompt = ">> "
quitCmd = "q"

nexpect.spawn "cscope"
, ["-d", "-k", "-l", "-f" + db]
.expect prompt
.sendline cmd + symbolToSearch
.expect cscopeRegex
.sendline quitCmd
.run (err, stdout, exitcode) ->
if err
console.log "could not invoke cscope (#{err})"
process.exit 1
header = stdout[1].match(cscopeRegex)
lines = parseInt(header[1])
if lines == 0 # no such symbol
return null

startIdx = 2
res = []
drop_next = null
# for line in [startIdx..startIdx + lines - 1]
padding = 3 # 2 x ">>" and lines count
# FIXME: ugly hack
for line in [startIdx..startIdx + (stdout.length - padding) - 1]
if drop_next
drop_next = null
continue
m = stdout[line].match(outputRegex)
if !m # broken line
m = (stdout[line] + stdout[line + 1]).match(outputRegex)
drop_next = 1
res.push
file: m[1]
sym: m[2]
line: m[3]
ctx: m[4]
callback res
cscopeRegex = /cscope: (\d+) lines/
outputRegex = /([\w.\/]+)\s+([a-zA-Z_$][\w$]+|<unknown>)\s+(\d+)\s+(.+)/
prompt = ">> "
quitCmd = "q"

nexpect.spawn "cscope"
, ["-d", "-k", "-l", "-f" + db]
.expect prompt
.sendline cmd + symbolToSearch
.wait cscopeRegex
.sendline quitCmd
.run (err, stdout, exitcode) ->
if err
console.log "could not invoke cscope (#{err})"
process.exit 1
header = stdout[1].match(cscopeRegex)
lines = parseInt(header[1])
if lines == 0 # no such symbol
return null

startIdx = 2
res = []
drop_next = null
# for line in [startIdx..startIdx + lines - 1]
padding = 3 # 2 x ">>" and lines count
# FIXME: ugly hack
for line in [startIdx..startIdx + (stdout.length - padding) - 1]
if drop_next
drop_next = null
continue
m = stdout[line].match(outputRegex)
if !m # broken line
m = (stdout[line] + stdout[line + 1]).match(outputRegex)
drop_next = 1
res.push
file: m[1]
sym: m[2]
line: m[3]
ctx: m[4]
callback res

findSymbol = (symbol, db, callback) ->
genericFind findSymbolCmd, symbol, db, callback
genericFind findSymbolCmd, symbol, db, callback

funcsCalledBy = (symbol, db, callback) ->
genericFind funcsCalledByCmd, symbol, db, callback
genericFind funcsCalledByCmd, symbol, db, callback

funcsCalling = (symbol, db, callback) ->
genericFind funcsCallingCmd, symbol, db, callback
genericFind funcsCallingCmd, symbol, db, callback

findTextString = (symbol, db, callback) ->
genericFind findTextStringCmd, symbol, db, callback
genericFind findTextStringCmd, symbol, db, callback

# changeTextString = (symbol, db, callback) ->
# genericFind changeTextStringCmd, symbol, db, callback
# genericFind changeTextStringCmd, symbol, db, callback

findEgrepPattern = (symbol, db, callback) ->
genericFind findEgrepPatternCmd, symbol, db, callback
genericFind findEgrepPatternCmd, symbol, db, callback

findFile = (symbol, db, callback) ->
genericFind findFileCmd, symbol, db, callback
genericFind findFileCmd, symbol, db, callback

findFilesIncluding = (symbol, db, callback) ->
genericFind findFilesIncludingCmd, symbol, db, callback
genericFind findFilesIncludingCmd, symbol, db, callback

findAssign = (symbol, db, callback) ->
genericFind findAssignCmd, 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}"
for r in results
console.log "file: #{r.file}, sym: #{r.sym}, line: #{r.line}"

# findSymbol symbolToSearch, dbPath, printResult
# funcsCalledBy symbolToSearch, dbPath, printResult
Expand Down

0 comments on commit f36a8ef

Please sign in to comment.