Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5af75ed1 authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "logcat: switch to <regex>."

parents 4b8e6b67 addd8521
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ cc_defaults {
    ],
    shared_libs: [
        "libbase",
        "libpcrecpp",
        "libprocessgroup",
    ],
    static_libs: ["liblog"],
+5 −9
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@

#include <atomic>
#include <memory>
#include <regex>
#include <string>
#include <utility>
#include <vector>
@@ -56,8 +57,6 @@
#include <processgroup/sched_policy.h>
#include <system/thread_defs.h>

#include <pcrecpp.h>

#define DEFAULT_MAX_ROTATED_LOGS 4

struct log_device_t {
@@ -113,7 +112,7 @@ struct android_logcat_context_internal {
    size_t outByteCount;
    int printBinary;
    int devCount;  // >1 means multiple
    pcrecpp::RE* regex;
    std::unique_ptr<std::regex> regex;
    log_device_t* devices;
    EventTagMap* eventTagMap;
    // 0 means "infinite"
@@ -307,9 +306,7 @@ static bool regexOk(android_logcat_context_internal* context,
                    const AndroidLogEntry& entry) {
    if (!context->regex) return true;

    std::string messageString(entry.message, entry.messageLen);

    return context->regex->PartialMatch(messageString);
    return std::regex_search(entry.message, entry.message + entry.messageLen, *context->regex);
}

static void processBuffer(android_logcat_context_internal* context,
@@ -460,7 +457,7 @@ static void show_help(android_logcat_context_internal* context) {
                    "  -d              Dump the log and then exit (don't block)\n"
                    "  -e <expr>, --regex=<expr>\n"
                    "                  Only print lines where the log message matches <expr>\n"
                    "                  where <expr> is a Perl-compatible regular expression\n"
                    "                  where <expr> is a regular expression\n"
                    // Leave --head undocumented as alias for -m
                    "  -m <count>, --max-count=<count>\n"
                    "                  Quit after printing <count> lines. This is meant to be\n"
@@ -1000,7 +997,7 @@ static int __logcat(android_logcat_context_internal* context) {
                break;

            case 'e':
                context->regex = new pcrecpp::RE(optarg);
                context->regex.reset(new std::regex(optarg));
                break;

            case 'm': {
@@ -1701,7 +1698,6 @@ int android_logcat_destroy(android_logcat_context* ctx) {
        sched_yield();
    }

    delete context->regex;
    context->argv_hold.clear();
    context->args.clear();
    context->envp_hold.clear();