Пример #1
0
void ListSymbolsJob::execute()
{
    Set<String> out;
    std::shared_ptr<Project> proj = project();
    if (proj) {
        if (queryFlags() & QueryMessage::IMenu) {
            out = imenu(proj);
        } else {
            out = listSymbols(proj);
        }
    }

    const bool elispList = queryFlags() & QueryMessage::ElispList;

    if (elispList) {
        write("(list", IgnoreMax|DontQuote);
        for (Set<String>::const_iterator it = out.begin(); it != out.end(); ++it) {
            write(*it);
        }
        write(")", IgnoreMax|DontQuote);
    } else {
        List<String> sorted = out.toList();
        if (queryFlags() & QueryMessage::ReverseSort) {
            std::sort(sorted.begin(), sorted.end(), std::greater<String>());
        } else {
            std::sort(sorted.begin(), sorted.end());
        }
        const int count = sorted.size();
        for (int i=0; i<count; ++i) {
            write(sorted.at(i));
        }
    }
}
Пример #2
0
int ListSymbolsJob::execute()
{
    Set<String> out;
    std::shared_ptr<Project> proj = project();
    if (proj) {
        if (queryFlags() & QueryMessage::WildcardSymbolNames
                && (string.contains('*') || string.contains('?')) && !string.endsWith('*')) {
            string += '*';
        }
        List<QueryMessage::PathFilter> filters = pathFilters();
        List<Path> paths;
        for (const auto &filter : filters) {
            if (filter.mode == QueryMessage::PathFilter::Self) {
                paths.append(filter.pattern);
                if (!paths.last().isFile()) {
                    paths.clear();
                    break;
                }
            } else {
                paths.clear();
                break;
            }
        }
        if (!paths.isEmpty()) {
            out = listSymbolsWithPathFilter(proj, paths);
        } else {
            out = listSymbols(proj);
        }
    }

    if (queryFlags() & QueryMessage::Elisp) {
        write("(list", IgnoreMax | DontQuote);
        for (Set<String>::const_iterator it = out.begin(); it != out.end(); ++it) {
            write(*it);
        }
        write(")", IgnoreMax | DontQuote);
    } else {
        List<String> sorted = out.toList();
        if (queryFlags() & QueryMessage::ReverseSort) {
            std::sort(sorted.begin(), sorted.end(), std::greater<String>());
        } else {
            std::sort(sorted.begin(), sorted.end());
        }
        const int count = sorted.size();
        for (int i = 0; i < count; ++i) {
            write(sorted.at(i));
        }
    }
    return out.isEmpty() ? 1 : 0;
}
Пример #3
0
int main(int argc,char **argv)
{
  char cmd[256];

  if (argc<2)
  {
    printf("Usage: %s [source_file | source_dir]\n",argv[0]);
    exit(1);
  }

  // initialize data structures 
  initDoxygen();

  // setup the non-default configuration options

  // we need a place to put intermediate files
  Config_getString("OUTPUT_DIRECTORY")="/tmp/doxygen"; 
  // disable html output
  Config_getBool("GENERATE_HTML")=FALSE;
  // disable latex output
  Config_getBool("GENERATE_LATEX")=FALSE;
  // be quiet
  Config_getBool("QUIET")=TRUE;
  // turn off warnings
  Config_getBool("WARNINGS")=FALSE;
  Config_getBool("WARN_IF_UNDOCUMENTED")=FALSE;
  Config_getBool("WARN_IF_DOC_ERROR")=FALSE;
  // Extract as much as possible
  Config_getBool("EXTRACT_ALL")=TRUE;
  Config_getBool("EXTRACT_STATIC")=TRUE;
  Config_getBool("EXTRACT_PRIVATE")=TRUE;
  Config_getBool("EXTRACT_LOCAL_METHODS")=TRUE;
  // Extract source browse information, needed 
  // to make doxygen gather the cross reference info
  Config_getBool("SOURCE_BROWSER")=TRUE;

  // set the input
  Config_getList("INPUT").append(argv[1]);

  // check and finialize the configuration
  checkConfiguration();
  adjustConfiguration();

  // parse the files
  parseInput();

  // iterate over the input files
  FileNameListIterator fnli(*Doxygen::inputNameList); 
  FileName *fn;
  // foreach file with a certain name
  for (fnli.toFirst();(fn=fnli.current());++fnli)
  {
    FileNameIterator fni(*fn);
    FileDef *fd;
    // for each file definition
    for (;(fd=fni.current());++fni)
    {
      // get the references (linked and unlinked) found in this file
      findXRefSymbols(fd);
    }
  }

  // remove temporary files
  if (!Doxygen::objDBFileName.isEmpty()) unlink(Doxygen::objDBFileName);
  if (!Doxygen::entryDBFileName.isEmpty()) unlink(Doxygen::entryDBFileName);
  // clean up after us
  rmdir("/tmp/doxygen");

  while (1)
  {
    printf("> Type a symbol name or\n> .list for a list of symbols or\n> .quit to exit\n> ");
    fgets(cmd,256,stdin);
    QCString s(cmd);
    if (s.at(s.length()-1)=='\n') s=s.left(s.length()-1); // strip trailing \n
    if (s==".list") 
      listSymbols();
    else if (s==".quit") 
      exit(0);
    else 
      lookupSymbols(s);
  }
}
Пример #4
0
bool GRTags::exec(int argc, char **argv)
{
    option options[] = {
        { "help", no_argument, 0, 'h' },
        { "version", no_argument, 0, 'V' },
        { "verbose", no_argument, 0, 'v' },
        { "exclude", required_argument, 0, 'e' },
        { "references", required_argument, 0, 'R' },
        { "list-symbols", optional_argument, 0, 'S' },
        { "find-symbols", required_argument, 0, 'F' },
        { "all-symbols", required_argument, 0, 'l' },
        { "show-context", no_argument, 0, 'C' },
        { "find-file", optional_argument, 0, 'P' },
        { "dir", required_argument, 0, 'd' },
        { "dump", no_argument, 0, 's' },
        { "create", no_argument, 0, 'c' },
        { "silent", no_argument, 0, 'i' },
        { "update", no_argument, 0, 'u' },
        { "match-icase", no_argument, 0, 'I' },
        { "find-file-prefer-exact", no_argument, 0, 'A' },
        { "absolute-path", no_argument, 0, 'K' },
        { 0, 0, 0, 0 }
    };

    int logLevel = 0;
    Path dir;
    int c;
    const ByteArray shortOptions = RTags::shortOptions(options);
    ByteArray pattern;
    while ((c = getopt_long(argc, argv, shortOptions.constData(), options, 0)) != -1) {
        switch (c) {
        case '?':
            return false;
        case 'h':
            printf("grtags [...options]\n"
                   "  --help|-h                    Display this help\n"
                   "  --version|-V                 Display version information\n"
                   "  --verbose|-v                 Increase verbosity\n"
                   "  --silent|-i                  Be silent\n"
                   "  --exclude|-e [filter]        Exclude this pattern (e.g. .git, *.cpp)\n"
                   "  --references|-R [arg]        Show references to arg\n"
                   "  --list-symbols|-S [arg]      List symbols matching arg\n"
                   "  --all-symbols|-l [arg]       List symbols and references matching arg\n"
                   "  --find-symbols|-F [arg]      Find symbols matching arg\n"
                   "  --context|-C                 Show context\n"
                   "  --dump|-s                    Dump db contents\n"
                   "  --create|-c                  Force creation of new DB\n"
                   "  --update|-u                  Update existing DB (noop with no DB)\n"
                   "  --find-file|-P [arg]         List files matching optional arg\n"
                   "  --match-icase|-I             Match paths case insensitively\n"
                   "  --find-file-prefer-exact|-A  Use to make --find-file prefer exact matches over partial\n"
                   "  --absolute-path|-K           Print files with absolute path.\n"
                   "  --dir|-d [arg]               Parse this directory (default .)\n");

            return true;
        case 'V':
            printf("GRTags version 0.2\n");
            return true;
        case 'C':
            mKeyFlags |= Location::ShowContext;
            break;
        case 'A':
            mFlags |= PreferExact;
            break;
        case 'I':
            mFlags |= MatchCaseInsensitive;
            break;
        case 'K':
            mFlags |= AbsolutePath;
            break;
        case 'P':
            mMode = Paths;
            if (optarg) {
                pattern = optarg;
            } else if (optind < argc && *argv[optind] != '-') {
                pattern = argv[optind++];
            }
            break;
        case 'R':
            mMode = FindReferences;
            pattern = optarg;
            break;
        case 'F':
            mMode = FindSymbols;
            pattern = optarg;
            break;
        case 'l':
            mMode = FindAll;
            pattern = optarg;
            break;
        case 'S':
            mMode = ListSymbols;
            if (optarg) {
                pattern = optarg;
            } else if (optind < argc && *argv[optind] != '-') {
                pattern = argv[optind++];
            }
            break;
        case 'c':
            mMode = Create;
            break;
        case 'u':
            mMode = Update;
            break;
        case 'e':
            mFilters.append(optarg);
            break;
        case 'v':
            if (logLevel >= 0)
                ++logLevel;
            break;
        case 'i':
            logLevel = -1;
            break;
        case 's':
            mMode = Dump;
            break;
        case 'd':
            dir = optarg;
            if (!dir.isDir()) {
                fprintf(stderr, "%s is not a valid directory\n", optarg);
                return false;
            }
            break;
        }
    }
    if (dir.isEmpty()) {
        Path p = Path::pwd();
        while (!p.isEmpty()) {
            const Path db = p + "/.gr";
            if (db.isDir()) {
                dir = p;
                break;
            }
            p = p.parentDir();
        }
        if (dir.isEmpty()) {
            if (mMode == Detect)
                mMode = Create;
            if (mMode == Create)
                dir = Path::pwd();
        }
    }
    if (dir.isEmpty()) {
        warning() << "Can't find database";
        return false;
    }

    initLogging(logLevel, Path(), 0);
    if (!load(dir + "/.gr"))
        return false;
    switch (mMode) {
    case Dump:
        dump();
        return true;
    case Update:
    case Create:
        dir.visit(&GRTags::visit, this);
        if (parseFiles())
            return save();
        return true;
    case Paths:
        paths(pattern);
        break;
    case FindReferences:
    case FindAll:
    case FindSymbols:
        findSymbols(pattern);
        break;
    case ListSymbols:
        listSymbols(pattern);
        break;
    case Detect:
        break;
    }
    return false;
}