Skip to content

Instantly share code, notes, and snippets.

@h2oota
Created November 18, 2012 23:00
Show Gist options
  • Save h2oota/4107985 to your computer and use it in GitHub Desktop.
Save h2oota/4107985 to your computer and use it in GitHub Desktop.
cscope-indexer for cscope-win32
@if (0==1) never execute
@echo off & setlocal enableextensions
REM bat + CScript
REM for JSCript, '@ if' is a conditional compile statement. then JScript discards @ if/ ~~ @ end.
REM for cmd.exe, '@ if' is a IF-STATEMENT. @ means no echo. the condition is never satisfied, because "(0" is not equal "1)". 'never execute' is dummy command for syntax checking.
REM http://emacswiki.org/emacs/CScopeAndEmacs
REM ******************************************************************
REM Not responsible for any loss resulting from the use of this script
REM ******************************************************************
REM sed and grep should be installed and in PATH
REM those windows version can be installed via MSYS package (http://www.mingw.org/wiki/MSYS)
set script=%~f0
set n=0
set recursive=0
set listonly=0
set verbose=0
set LIST_FILE=cscope.files
set DATABASE_FILE=cscope.out
set param="%*%"
:LOOP
if "%~1" == "" goto PROCESS
if "%~1" == "-r" goto RECURSE
if "%~1" == "-i" goto LISTFILE
if "%~1" == "-f" goto CSCOPEOUT
if "%~1" == "-l" goto LISTONLY
if "%~1" == "-v" goto VERBOSE
shift
goto LOOP
:RECURSE
set recursive=1
shift
goto LOOP
:LISTFILE
shift
set LIST_FILE=%~1
shift
goto LOOP
:CSCOPEOUT
shift
set DATABASE_FILE=%~1
shift
goto LOOP
:LISTONLY
set listonly=1
shift
goto LOOP
:VERBOSE
set verbose=1
shift
goto LOOP
:PROCESS
IF %verbose%==1 echo cscope-indexer args: %param%
IF %recursive%==1 goto GET_RECURSE_SRC
dir /B > "%LIST_FILE%.tmp"
goto CSCOPE
:GET_RECURSE_SRC
dir /S /B > "%LIST_FILE%.tmp"
goto CSCOPE
:CSCOPE
IF %listonly%==1 goto ALMOST_DONE
CScript //Nologo //E:JScript "%script%" <"%LIST_FILE%.tmp" >"%LIST_FILE%"
cscope -b -i "%LIST_FILE%" -f "%DATABASE_FILE%"
goto DONE
:ALMOST_DONE
CScript //Nologo //E:JScript "%script%" <"%LIST_FILE%.tmp" >"%LIST_FILE%"
goto DONE
:DONE
del "%LIST_FILE%.tmp"
echo Done
goto :EOF
@end
/*
* escape each line
*/
var re = new RegExp("\\.(?:[chly](xx|pp)?|cc|hh)$", "i")
while (! WScript.StdIn.AtEndOfLine) {
var txt = WScript.StdIn.ReadLine();
if (txt.match(re))
WScript.StdOut.WriteLine("\"" + txt + "\"");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment