25#if HAVE_DECL___ENVIRON
27#elif HAVE_DECL__NSGETENVIRON
28#include <crt_externs.h>
39# ifdef HAVE_SYS_TYPES_H
40# include <sys/types.h>
90#if defined (HAVE_OPENDIR) && (defined (HAVE_DIRENT_H) || defined (_MSC_VER))
91static bool recurseUsingOpendir (
const char *
const dirName)
94 DIR *
const dir = opendir (dirName);
102 if (strcmp (
entry->d_name,
".") != 0 &&
103 strcmp (
entry->d_name,
"..") != 0)
107 if (strcmp (dirName,
".") == 0)
108 filePath =
entry->d_name;
124#elif defined (HAVE__FINDFIRST)
126static bool createTagsForWildcardEntry (
127 const char *
const pattern,
const size_t dirLength,
128 const char *
const entryName)
132 if (strcmp (entryName,
".") != 0 && strcmp (entryName,
"..") != 0)
143static bool createTagsForWildcardUsingFindfirst (
const char *
const pattern)
146 const size_t dirLength =
baseFilename (pattern) - pattern;
147#if defined (HAVE__FINDFIRST)
148 struct _finddata_t fileInfo;
149 findfirst_t hFile = _findfirst (pattern, &fileInfo);
154 const char *
const entry = (
const char *) fileInfo.name;
155 resize |= createTagsForWildcardEntry (pattern, dirLength,
entry);
156 }
while (_findnext (hFile, &fileInfo) == 0);
168 static unsigned int recursionDepth = 0;
174 verbose (
"ignoring \"%s\" (recursive link)\n", dirName);
176 verbose (
"ignoring \"%s\" (directory)\n", dirName);
178 verbose (
"not descending in directory \"%s\" (depth %u > %u)\n",
182 verbose (
"RECURSING into directory \"%s\"\n", dirName);
183#if defined (HAVE_OPENDIR) && (defined (HAVE_DIRENT_H) || defined (_MSC_VER))
184 resize = recurseUsingOpendir (dirName);
185#elif defined (HAVE__FINDFIRST)
191 resize = createTagsForWildcardUsingFindfirst (
vStringValue (pattern));
209 verbose (
"excluding \"%s\" (the early stage)\n", entryName);
211 verbose (
"ignoring \"%s\" (symbolic link)\n", entryName);
212 else if (! status->
exists)
217 verbose (
"ignoring \"%s\" (special file)\n", entryName);
219 verbose (
"excluding \"%s\"\n", entryName);
227#ifdef MANUAL_GLOBBING
229static bool createTagsForWildcardArg (
const char *
const arg)
235#if defined (HAVE__FINDFIRST)
240 (strcmp (patternS,
".") == 0 || strcmp (patternS,
"..") == 0))
245 resize |= createTagsForWildcardUsingFindfirst (patternS);
261 const char *
const arg =
cArgItem (args);
263#ifdef MANUAL_GLOBBING
264 resize |= createTagsForWildcardArg (arg);
306 if (strcmp (fileName,
"-") == 0)
310 FILE *
const fp = fopen (fileName,
"r");
337 clock_t timeStamps [3];
345 error (
FATAL,
"No files specified. Try \"%s --help\".",
351#define timeStamp(n) timeStamps[(n)]=(Option.printTotals ? clock():(clock_t)0)
359 verbose (
"Reading command line arguments\n");
364 verbose (
"Reading list file\n");
369 verbose (
"Reading filter input\n");
403 json_t * tmp = json_object ();
407 error (
FATAL,
"install_syscall_filter failed");
421 while (fgets (buffer,
sizeof(buffer), stdin))
423 if (buffer[0] ==
'\n')
426 request = json_loads (buffer, JSON_DISABLE_EOF_CHECK,
NULL);
433 json_t *
command = json_object_get (request,
"command");
440 if (!strcmp (
"generate-tags", json_string_value (
command)))
442 json_int_t size = -1;
445 if (json_unpack (request,
"{ss}",
"filename", &
filename) == -1)
447 error (
FATAL,
"invalid generate-tags request");
451 json_unpack (request,
"{sI}",
"size", &size);
458 "invalid request in sandbox submode: reading file contents from a file is limited");
467 unsigned char *data =
eMalloc (size);
468 size = fread (data, 1, size, stdin);
475 fputs (
"{\"_type\": \"completed\", \"command\": \"generate-tags\"}\n", stdout);
485 json_decref (request);
492 const char *safe_vars[] = {
493 "BASH_FUNC_module()=",
499 for (sv = safe_vars[0]; sv !=
NULL; sv++)
500 if (strncmp(var, sv, strlen (sv)) == 0)
511#if HAVE_DECL___ENVIRON
513#elif HAVE_DECL__NSGETENVIRON
515 char ***ep = _NSGetEnviron();
528 for (i = 0; e [i]; i++)
532 value = strchr (e [i],
'=');
537 if (!strncmp (value,
"() {", 4))
555#if defined(WIN32) && defined(HAVE_MKSTEMP)
557 srand ((
unsigned int) clock ());
581 verbose (
"Reading initial options from command line\n");
598 freeEncodingResources ();
static bool isSafeVar(const char *var)
static bool etagsInclude(void)
static void runMainLoop(cookedArgs *args)
int ctags_cli_main(int argc, char **argv)
static bool createTagsForEntry(const char *const entryName)
static bool recurseIntoDirectory(const char *const dirName)
static void batchMakeTags(cookedArgs *args, void *user)
static bool createTagsFromListFile(const char *const fileName)
static mainLoopFunc mainLoop
static bool createTagsFromFileInput(FILE *const fp, const bool filter)
static void sanitizeEnviron(void)
void setMainLoop(mainLoopFunc func, void *data)
static bool createTagsForArgs(cookedArgs *const args)
void freeTagFileResources(void)
void closeTagFile(const bool resize)
void error(const errorSelection selection, const char *const format,...)
void setErrorPrinter(errorPrintFunc printer, void *data)
bool stderrDefaultErrorPrinter(const errorSelection selection, const char *const format, va_list ap, void *data)
void initFieldObjects(void)
#define CTAGS_ATTR_UNUSED
void interactiveLoop(cookedArgs *args, void *user)
int installSyscallFilter(void)
void freeKeywordTable(void)
void freeRegexResources(void)
MIO * mio_new_memory(unsigned char *data, size_t size, MIOReallocFunc realloc_func, MIODestroyNotify free_func)
mio_new_memory: @data: Initial data (may be NULL) @size: Length of @data in bytes @realloc_func: A fu...
int mio_unref(MIO *mio)
mio_unref: @mio: A MIO object
cookedArgs * cArgNewFromArgv(char *const *const argv)
const char * cArgItem(cookedArgs *const current)
bool cArgOff(cookedArgs *const current)
void parseCmdlineOptions(cookedArgs *const args)
void testEtagsInvocation(void)
void previewFirstOption(cookedArgs *const args)
cookedArgs * cArgNewFromLineFile(FILE *const fp)
void verbose(const char *const format,...)
void cArgDelete(cookedArgs *const current)
void cArgForth(cookedArgs *const current)
void readOptionConfiguration(void)
bool isExcludedFile(const char *const name, bool falseIfExceptionsAreDefeind)
void freeOptionResources(void)
void(* mainLoopFunc)(cookedArgs *args, void *data)
void printParserStatisticsIfUsed(langType language)
unsigned int countParsers(void)
void initializeParsing(void)
bool parseFile(const char *const fileName)
bool parseFileWithMio(const char *const fileName, MIO *mio, void *clientData)
void freeParserResources(void)
void freeInputFileResources(void)
char * combinePathAndFile(const char *const path, const char *const file)
void setExecutableName(const char *const path)
void * eMalloc(const size_t size)
void eFreeNoNullCheck(void *const ptr)
bool isRecursiveLink(const char *const dirName)
const char * getExecutableName(void)
void * eRealloc(void *const ptr, const size_t size)
void setCurrentDirectory(void)
void eFree(void *const ptr)
fileStatus * eStat(const char *const fileName)
void eStatFree(fileStatus *status)
const char * baseFilename(const char *const filePath)
void freeRoutineResources(void)
#define OUTPUT_PATH_SEPARATOR
void printTotals(const clock_t *const timeStamps, bool append, sortType sorted)
stringList * etagsInclude
unsigned int maxRecursionDepth
void finiDefaultTrashBox(void)
void initDefaultTrashBox(void)
void vStringCopyS(vString *const string, const char *const s)
vString * vStringNew(void)
void vStringDelete(vString *const string)
void vStringNCopyS(vString *const string, const char *const s, const size_t length)
void vStringCatS(vString *const string, const char *const s)
vString * vStringNewInit(const char *const s)
static void vStringPut(vString *const string, const int c)
void setTagWriter(writerType wtype, tagWriter *customWriter)
void initXtagObjects(void)