Example #1
0
Value Interpreter::eval(const String& data, const String& name)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::HandleScope scope(isolate);

    v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, mData->context);
    v8::Context::Scope contextScope(context);

    v8::Handle<v8::String> fileName = v8::String::NewFromUtf8(isolate, name.constData());
    v8::Handle<v8::String> source = v8::String::NewFromUtf8(isolate, data.constData());

    v8::TryCatch try_catch;
    v8::Handle<v8::Script> script = v8::Script::Compile(source, fileName);
    if (script.IsEmpty()) {
        error() << "script" << name << "didn't compile";
        return Value();
    }

    const v8::Handle<v8::Value> result = script->Run();
    if (try_catch.HasCaught()) {
        const v8::Handle<v8::Message> msg = try_catch.Message();
        {
            const v8::String::Utf8Value str(msg->Get());
            error() << ToCString(str);
        }
        {
            const v8::String::Utf8Value str(msg->GetScriptResourceName());
            error() << String::format<64>("At %s:%d", ToCString(str), msg->GetLineNumber());
        }
        return Value();
    }

    return mData->v8ValueToValue(result);
}
Example #2
0
    void processStdin()
    {
        assert(!data.contains('\n'));
        while (true) {
            const int ch = getc(stdin);
            if (ch == EOF)
                return;
            if (ch == '\n')
                break;
            data.append(static_cast<char>(ch));
        }
        const int colon = data.indexOf(':');
        if (colon == -1) {
            error() << "Failed to match completion header" << data;
            EventLoop::eventLoop()->unregisterSocket(STDIN_FILENO);
            EventLoop::eventLoop()->quit();
            return;
        }

        int line, column, contentsSize, pos;
        const int ret = sscanf(data.constData() + colon + 1, "%d:%d:%d:%d", &line, &column, &pos, &contentsSize);
        if (ret != 4) {
            error() << "Failed to match completion header" << ret << "\n" << data;
            EventLoop::eventLoop()->unregisterSocket(STDIN_FILENO);
            EventLoop::eventLoop()->quit();
            return;
        }
        String contents(contentsSize, ' ');
        int read = 0;
        char *c = contents.data();
        while (read < contentsSize) {
            const int r = fread(c + read, sizeof(char), contentsSize - read, stdin);
            if (r < 0) {
                EventLoop::eventLoop()->unregisterSocket(STDIN_FILENO);
                EventLoop::eventLoop()->quit();
                return;
            }
            read += r;
        }
        Path path(data.constData(), colon);
        data.clear();
        if (!path.resolve(Path::MakeAbsolute)) {
            error() << "Can't resolve" << path;
            return;
        }
        // error() << path << line << column << contentsSize << pos << "\n" << contents.left(100)
        //         << contents.right(100);

        CompletionMessage msg(CompletionMessage::None, path, line, column, pos);
        const String args = String::format<64>("%s:%d:%d:%d:%d", path.constData(), line, column, pos, contentsSize);
        const char *argv[] = { "completionStream", args.constData() };
        msg.init(2, argv);
        msg.setContents(contents);
        connection->send(msg);
    }
Example #3
0
int JobMessage::execute() const
{
    Process process;
    process.setCwd(mCwd);
    process.exec(mCompiler, mArgs);
    const String out = process.readAllStdOut();
    if (!out.isEmpty())
        fprintf(stdout, "%s", out.constData());
    const String err = process.readAllStdErr();
    if (!err.isEmpty())
        fprintf(stderr, "%s", err.constData());
    return process.returnCode();
}
Example #4
0
File: Log.cpp Project: jmataraz/rct
void logDirect(int level, const String &out)
{
    std::lock_guard<std::mutex> lock(sOutputsMutex);
    if (sOutputs.isEmpty()) {
        printf("%s\n", out.constData());
    } else {
        for (Set<LogOutput*>::const_iterator it = sOutputs.begin(); it != sOutputs.end(); ++it) {
            LogOutput *output = *it;
            if (output->testLog(level)) {
                output->log(out.constData(), out.size());
            }
        }
    }
}
Example #5
0
bool JSONParser::parse(const String& json)
{
    v8::Isolate* isolate = v8::Isolate::New();
    const v8::Isolate::Scope isolateScope(isolate);
    v8::HandleScope handleScope;

    v8::Handle<v8::ObjectTemplate> globalTemplate = v8::ObjectTemplate::New();
#ifdef V8_NEW_CONTEXT_TAKES_ISOLATE
    v8::Handle<v8::Context> context = v8::Context::New(isolate, 0, globalTemplate);
#else
    v8::Handle<v8::Context> context = v8::Context::New(0, globalTemplate);
#endif
    v8::Context::Scope contextScope(context);

    v8::Handle<v8::Object> global = context->Global();

    v8::Handle<v8::Object> JSON = global->Get(v8::String::New("JSON"))->ToObject();
    v8::Handle<v8::Function> JSON_parse = v8::Handle<v8::Function>::Cast(JSON->Get(v8::String::New("parse")));

    v8::Handle<v8::Value> data = v8::String::New(json.constData(), json.size());
    v8::Handle<v8::Value> value = JSON_parse->Call(JSON, 1, &data);

    mRoot = v8ValueToValue(value);
    //isolate->Dispose();
    return isValid();
}
Example #6
0
bool Connection::send(int id, const String &message)
{
    if (message.isEmpty())
        return true;

    if (!mClient->isConnected()) {
        ::error("Trying to send message to unconnected client (%d)", id);
        return false;
    }

    if (mSilent)
        return true;

    String header, data;
    {
        if (message.size()) {
            Serializer strm(data);
            strm << id;
            strm.write(message.constData(), message.size());
        }
        Serializer strm(header);
        strm << data.size();
    }
    mPendingWrite += (header.size() + data.size());
    return mClient->write(header) && mClient->write(data);
}
Example #7
0
File: Rct.cpp Project: farva/rct
String colorize(const String &string, AnsiColor color, int from, int len)
{
    assert(from <= string.size());
    assert(from >= 0);
    if (len == -1) {
        len = string.size() - from;
    }
    assert(from + len <= string.size());
    if (!len)
        return string;

    String ret;
    ret.reserve(string.size() + 20);
    const char *str = string.constData();
    if (from > 0) {
        ret.append(str, from);
        str += from;
    }
    ret.append(colors[color]);
    ret.append(str, len);
    str += len;
    ret.append(colors[AnsiColor_Default]);
    if (from + len != string.size())
        ret.append(str, string.size() - from - len);

    return ret;
}
Example #8
0
String Location::toString(Flags<ToStringFlag> flags, Hash<Path, String> *contextCache) const
{
    if (isNull())
        return String();
    const unsigned int l = line();
    const unsigned int c = column();
    int extra = RTags::digits(l) + RTags::digits(c) + 3;
    String ctx;
    if (flags & Location::ShowContext) {
        ctx += '\t';
        ctx += context(flags, contextCache);
        extra += ctx.size();
    }

    Path p = path();
    if (flags & ConvertToRelative) {
        Sandbox::encode(p);
    } else if (!(flags & AbsolutePath) && Server::instance()) {
        Server *server = Server::instance();
        if (std::shared_ptr<Project> pp = server->currentProject()) {
            const Path projectPath = pp->path();
            if (!projectPath.isEmpty() && p.startsWith(projectPath))
                p.remove(0, projectPath.size());
        }
    }

    String ret(p.size() + extra, ' ');

    const int w = snprintf(ret.data(), ret.size() + extra + 1, "%s:%d:%d:", p.constData(), l, c);
    if (!ctx.isEmpty()) {
        memcpy(ret.data() + w, ctx.constData(), ctx.size());
    }
    return ret;
}
Example #9
0
Client *Client::create(const Rect& rect, int screenNumber, const String &clazz, const String &instance, bool movable)
{
    WindowManager *wm = WindowManager::instance();
    xcb_connection_t* conn = wm->connection();
    xcb_screen_t* scr = wm->screens().at(screenNumber);

    xcb_window_t window = xcb_generate_id(conn);
    const uint32_t values[] = {
        scr->black_pixel,
        XCB_GRAVITY_NORTH_WEST,
        XCB_GRAVITY_NORTH_WEST,
        1,
        (XCB_EVENT_MASK_STRUCTURE_NOTIFY
         | XCB_EVENT_MASK_ENTER_WINDOW
         | XCB_EVENT_MASK_LEAVE_WINDOW
         | XCB_EVENT_MASK_EXPOSURE
         | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
         | XCB_EVENT_MASK_POINTER_MOTION
         | XCB_EVENT_MASK_BUTTON_PRESS
         | XCB_EVENT_MASK_BUTTON_RELEASE)
    };
    warning() << "creating client window" << rect;
    xcb_create_window(conn, XCB_COPY_FROM_PARENT, window, scr->root,
                      rect.x, rect.y, rect.width, rect.height, 0,
                      XCB_COPY_FROM_PARENT, XCB_COPY_FROM_PARENT,
                      XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY | XCB_CW_WIN_GRAVITY
                      | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK, values);

    xcb_icccm_wm_hints_t wmHints;
    xcb_icccm_wm_hints_set_none(&wmHints);
    xcb_icccm_wm_hints_set_input(&wmHints, 0);
    xcb_icccm_set_wm_hints(conn, window, &wmHints);

    xcb_size_hints_t wmNormalHints;
    memset(&wmNormalHints, 0, sizeof(wmNormalHints));
    xcb_icccm_size_hints_set_position(&wmNormalHints, 1, rect.x, rect.y);
    xcb_icccm_size_hints_set_size(&wmNormalHints, 1, rect.width, rect.height);
    xcb_icccm_set_wm_normal_hints(conn, window, &wmNormalHints);

    String className = clazz + ' ' + instance;
    className[clazz.size()] = '\0';
    xcb_icccm_set_wm_class(conn, window, className.size(), className.constData());
    Client *ptr = new Client(window);
    ptr->mMovable = movable;
    ptr->mRect = rect;
    ptr->mOwned = true;
    ptr->mScreenNumber = screenNumber;
    ptr->init();
    ptr->mNoFocus = true;
    Workspace *ws = wm->activeWorkspace(screenNumber);
    assert(ws);
    ptr->mWorkspace = ws;
    ws->addClient(ptr);

    wm->js().onClient(ptr);
    ptr->complete();

    sClients[window] = ptr;
    return ptr;
}
Example #10
0
void DumpThread::run()
{
    const auto key = mConnection->disconnected().connect([this](const std::shared_ptr<Connection> &) { abort(); });

    CXIndex index = clang_createIndex(0, 0);
    CXTranslationUnit translationUnit = 0;
    String clangLine;
    RTags::parseTranslationUnit(mSource.sourceFile(), mSource.toCommandLine(Source::Default), translationUnit,
                                index, 0, 0, CXTranslationUnit_DetailedPreprocessingRecord, &clangLine);
    if (!(mQueryFlags & QueryMessage::DumpCheckIncludes))
        writeToConnetion(String::format<128>("Indexed: %s => %s", clangLine.constData(), translationUnit ? "success" : "failure"));
    if (translationUnit) {
        clang_visitChildren(clang_getTranslationUnitCursor(translationUnit), DumpThread::visitor, this);
        clang_disposeTranslationUnit(translationUnit);
    }

    clang_disposeIndex(index);
    mConnection->disconnected().disconnect(key);
    std::weak_ptr<Connection> conn = mConnection;
    if (mQueryFlags & QueryMessage::DumpCheckIncludes) {
        checkIncludes();
    }
    EventLoop::mainEventLoop()->callLater([conn]() {
            if (auto c = conn.lock())
                c->finish();
        });
}
Example #11
0
bool QueryJob::writeRaw(const String &out, Flags<WriteFlag> flags)
{
    assert(mConnection);
    if (!(flags & IgnoreMax) && mQueryMessage) {
        const int max = mQueryMessage->max();
        if (max != -1 && mLinesWritten == max) {
            return false;
        }
        assert(mLinesWritten < max || max == -1);
        ++mLinesWritten;
    }

    if (!(mJobFlags & QuietJob))
        warning("=> %s", out.constData());

    if (mConnection) {
        if (!mConnection->write(out)) {
            abort();
            return false;
        }
        return true;
    }

    return true;
}
Example #12
0
static inline String xmlEscape(const String& xml)
{
    if (xml.isEmpty())
        return xml;

    std::ostringstream strm;
    const char* ch = xml.constData();
    bool done = false;
    while (true) {
        switch (*ch) {
        case '\0':
            done = true;
            break;
        case '"':
            strm << "\\\"";
            break;
        case '<':
            strm << "&lt;";
            break;
        case '>':
            strm << "&gt;";
            break;
        case '&':
            strm << "&amp;";
            break;
        default:
            strm << *ch;
            break;
        }
        if (done)
            break;
        ++ch;
    }
    return strm.str();
}
Example #13
0
bool QueryJob::filter(const String &value) const
{
    if (mFilters.isEmpty() && !(queryFlags() & QueryMessage::FilterSystemIncludes))
        return true;

    const char *val = value.constData();
    while (*val && isspace(*val))
        ++val;
    const char *space = strchr(val, ' ');
    Path path;
    uint32_t fileId = 0;
    if (space) {
        path.assign(val, space - val);
    } else {
        path = val;
    }

    if (!path.isFile())
        return true; // non-file things go unfiltered

    if (queryFlags() & QueryMessage::FilterSystemIncludes && Path::isSystem(val))
        return false;
    fileId = Location::fileId(path);

    if (mFilters.isEmpty())
        return true;

    for (const std::shared_ptr<Filter> &filter : mFilters) {
        if (filter->match(fileId, path))
            return true;
    }
    return false;
}
Example #14
0
 void send(const String &string)
 {
     if (connection) {
         connection->write(string);
         connection->finish();
     } else {
         output->log(string.constData(), string.size());
     }
 }
Example #15
0
bool Path::write(const Path& path, const String& data, WriteMode mode)
{
    FILE* f = fopen(path.constData(), mode == Overwrite ? "w" : "a");
    if (!f)
        return false;
    const int ret = fwrite(data.constData(), sizeof(char), data.size(), f);
    fclose(f);
    return ret == data.size();
}
Example #16
0
void sigSegvHandler(int signal)
{
    fprintf(stderr, "Caught signal %d\n", signal);
    String trace = RTags::backtrace();
    if (!trace.isEmpty()) {
        fprintf(stderr, "%s", trace.constData());
    }
    fflush(stderr);
    _exit(1);
}
Example #17
0
static void sigSegvHandler(int signal)
{
    if (Server *server = Server::instance())
        server->stopServers();
    fprintf(stderr, "Caught signal %d\n", signal);
    const String trace = Rct::backtrace();
    fprintf(stderr, "%s\n", trace.constData());
    fflush(stderr);
    _exit(1);
}
Example #18
0
List<String> AST::evaluate(const String &script)
{
    assert(mReturnValues.isEmpty());
    try {
        mState->operator()(script.constData());
    } catch (...) {
        error() << "Got exception";
    }
    return std::move(mReturnValues);
}
Example #19
0
File: Log.cpp Project: emdeesee/rct
static inline void writeLog(FILE *f, const char *msg, int len, Flags<LogOutput::LogFlag> flags)
{
    if (sTimedLogs) {
        const String time = String::formatTime(::time(0), String::Time);
        fwrite(time.constData(), time.size(), 1, f);
    }
    fwrite(msg, len, 1, f);
    if (flags & LogOutput::TrailingNewLine)
        fwrite("\n", 1, 1, f);
}
Example #20
0
static inline String sha1(const String& input)
{
    unsigned char digest[SHA_DIGEST_LENGTH];

    SHA_CTX ctx;
    SHA1_Init(&ctx);
    SHA1_Update(&ctx, input.constData(), input.size());
    SHA1_Final(digest, &ctx);

    return String(reinterpret_cast<char*>(&digest[0]), SHA_DIGEST_LENGTH);
}
Example #21
0
static void sigHandler(int signal)
{
    // this is not really allowed in signal handlers but will mostly work
    const String trace = Rct::backtrace();
    if (ClangIndexer::serverOpts() & Server::SuspendRPOnCrash) {
        int seconds = 2;
        printf("@CRASH@Caught signal %d\n%s@CRASH@", signal, trace.constData());
        while (true) {
            printf("@CRASH@rp crashed, waiting for debugger pid: %d@CRASH@", getpid());
            fflush(stdout);
            sleep(seconds);
            if (seconds < 32)
                seconds *= 2;
        }
    }
    fprintf(stderr, "Caught signal %d\n%s\n", signal, trace.constData());
    fflush(stderr);
    ::closelog();
    _exit(1);
}
Example #22
0
static inline String base64(const String& input)
{
#ifdef OS_Darwin
    String result;
    SecTransformRef transform = SecEncodeTransformCreate(kSecBase64Encoding, 0);
    CFDataRef sourceData = CFDataCreate(kCFAllocatorDefault,
                                        reinterpret_cast<const UInt8*>(input.constData()),
                                        input.size());
    SecTransformSetAttribute(transform, kSecTransformInputAttributeName, sourceData, 0);
    CFDataRef encodedData = static_cast<CFDataRef>(SecTransformExecute(transform, 0));
    const long len = CFDataGetLength(encodedData);
    if (len > 0) {
        result.resize(len);
        CFDataGetBytes(encodedData, CFRangeMake(0, len), reinterpret_cast<UInt8*>(result.data()));
    }
    CFRelease(encodedData);
    CFRelease(transform);
    CFRelease(sourceData);
#else
    BIO *base64_filter = BIO_new(BIO_f_base64());
    BIO_set_flags(base64_filter, BIO_FLAGS_BASE64_NO_NL);

    BIO *bio = BIO_new(BIO_s_mem());
    BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);

    bio = BIO_push(base64_filter, bio);

    BIO_write(bio, input.constData(), input.size());

    BIO_flush(bio);

    char *new_data;

    const long bytes_written = BIO_get_mem_data(bio, &new_data);

    String result(new_data, bytes_written);
    BIO_free_all(bio);
#endif

    return result;
}
Example #23
0
void RClient::onNewMessage(const Message *message, Connection *)
{
    if (message->messageId() == ResponseMessage::MessageId) {
        const String response = static_cast<const ResponseMessage*>(message)->data();
        if (!response.isEmpty()) {
            fprintf(stdout, "%s\n", response.constData());
            fflush(stdout);
        }
    } else {
        error("Unexpected message: %d", message->messageId());
    }
}
Example #24
0
String Location::context(Flags<ToStringFlag> flags, Hash<Path, String> *cache) const
{
    String copy;
    String *code = 0;
    const Path p = path();
    if (cache) {
        String &ref = (*cache)[p];
        if (ref.isEmpty()) {
            ref = p.readAll();
        }
        code = &ref;
    } else {
        copy = p.readAll();
        code = &copy;
    }

    String ret;
    if (!code->isEmpty()) {
        unsigned int l = line();
        if (!l)
            return String();
        const char *ch = code->constData();
        while (--l) {
            ch = strchr(ch, '\n');
            if (!ch)
                return String();
            ++ch;
        }
        const char *end = strchr(ch, '\n');
        if (!end)
            return String();

        ret.assign(ch, end - ch);
        // error() << "foobar" << ret << bool(flags & NoColor);
        if (!(flags & NoColor)) {
            const size_t col = column() - 1;
            if (col + 1 < ret.size()) {
                size_t last = col;
                if (ret.at(last) == '~')
                    ++last;
                while (ret.size() > last && (isalnum(ret.at(last)) || ret.at(last) == '_'))
                    ++last;
                static const char *color = "\x1b[32;1m"; // dark yellow
                static const char *resetColor = "\x1b[0;0m";
                // error() << "foobar"<< end << col << ret.size();
                ret.insert(last, resetColor);
                ret.insert(col, color);
            }
            // printf("[%s]\n", ret.constData());
        }
    }
    return ret;
}
Example #25
0
void RClient::onNewMessage(const std::shared_ptr<Message> &message, const std::shared_ptr<Connection> &)
{
    if (message->messageId() == ResponseMessage::MessageId) {
        const String response = std::static_pointer_cast<ResponseMessage>(message)->data();
        if (!response.isEmpty() && mLogLevel >= LogLevel::Error) {
            fprintf(stdout, "%s\n", response.constData());
            fflush(stdout);
        }
    } else {
        error("Unexpected message: %d", message->messageId());
    }
}
Example #26
0
bool JSONParser::parse(const String& json)
{
    char errbuf[128];
    yajl_val value = yajl_tree_parse(json.constData(), errbuf, sizeof(errbuf));
    if (!value) {
        mRoot = Value(); // just in case
        return false;
    }
    mRoot = yajlValueToValue(value);
    yajl_tree_free(value);
    return isValid();
}
Example #27
0
File: Rct.cpp Project: farva/rct
String addrLookup(const String& addr, LookupMode mode, bool *ok)
{
    sockaddr_storage sockaddr;
    memset(&sockaddr, 0, sizeof(sockaddr_storage));
    size_t sz;
    if (mode == Auto)
        mode = addr.contains(':') ? IPv6 : IPv4;
    if (mode == IPv6) {
        sockaddr_in6* sockaddr6 = reinterpret_cast<sockaddr_in6*>(&sockaddr);
        if (inet_pton(AF_INET6, addr.constData(), &sockaddr6->sin6_addr) != 1) {
            if (ok)
                *ok = false;
            return addr;
        }
        sockaddr.ss_family = AF_INET6;
        sz = sizeof(sockaddr_in6);
    } else {
        sockaddr_in* sockaddr4 = reinterpret_cast<sockaddr_in*>(&sockaddr);
        if (inet_pton(AF_INET, addr.constData(), &sockaddr4->sin_addr) != 1) {
            if (ok)
                *ok = false;
            return addr;
        }
        sockaddr.ss_family = AF_INET;
        sz = sizeof(sockaddr_in);
    }
    String out(NI_MAXHOST, '\0');
    const struct sockaddr* sa = reinterpret_cast<struct sockaddr*>(&sockaddr);
    if (getnameinfo(sa, sz, out.data(), NI_MAXHOST, 0, 0, 0) != 0) {
        if (ok)
            *ok = false;
        // bad
        return addr;
    }
    out.resize(strlen(out.constData()));
    if (ok)
        *ok = true;

    return out;
}
Example #28
0
String Location::key(unsigned flags) const
{
    if (isNull())
        return String();
    int extra = 0;
    const int off = offset();
    int line = 0, col = 0;
    if (flags & Location::Padded) {
        extra = 7;
    } else if (flags & Location::ShowLineNumbers && convertOffset(line, col)) {
        extra = RTags::digits(line) + RTags::digits(col) + 3;
    } else {
        flags &= ~Location::ShowLineNumbers;
        extra = RTags::digits(off) + 1;
    }
    String ctx;
    if (flags & Location::ShowContext) {
        ctx += '\t';
        ctx += context();
        extra += ctx.size();
    }

    const Path p = path();

    String ret(p.size() + extra, '0');

    if (flags & Location::Padded) {
        snprintf(ret.data(), ret.size() + extra + 1, "%s,%06d%s", p.constData(),
                 off, ctx.constData());
    } else if (flags & Location::ShowLineNumbers) {
        snprintf(ret.data(), ret.size() + extra + 1, "%s:%d:%d:%s", p.constData(),
                 line, col, ctx.constData());
    } else {
        snprintf(ret.data(), ret.size() + extra + 1, "%s,%d%s", p.constData(),
                 off, ctx.constData());
    }
    return ret;
}
Example #29
0
static void man()
{
    String out =
        "<!DOCTYPE manpage SYSTEM \"http://masqmail.cx/xmltoman/xmltoman.dtd\">\n"
        "<?xml-stylesheet type=\"text/xsl\" href=\"http://masqmail.cx/xmltoman/xmltoman.xsl\"?>\n"
        "\n"
        "<manpage name=\"rc\" section=\"1\" desc=\"command line client for RTags\">\n"
        "\n"
        "<synopsis>\n"
        "  <cmd>rc <arg>file.1.xml</arg> > file.1</cmd>\n"
        "</synopsis>\n"
        "\n"
        "<description>\n"
        "\n"
        "<p>rc is a command line client used to control RTags.</p>\n"
        "\n"
        "</description>\n";
    for (int i=0; opts[i].description; ++i) {
        if (*opts[i].description) {
            if (!opts[i].longOpt && !opts[i].shortOpt) {
                if (i)
                    out.append("</section>\n");
                out.append(String::format<128>("<section name=\"%s\">\n", opts[i].description));
            } else {
                out.append(String::format<64>("  <option>%s%s%s%s<optdesc>%s</optdesc></option>\n",
                                              opts[i].longOpt ? String::format<4>("--%s", opts[i].longOpt).constData() : "",
                                              opts[i].longOpt && opts[i].shortOpt ? "|" : "",
                                              opts[i].shortOpt ? String::format<2>("-%c", opts[i].shortOpt).constData() : "",
                                              opts[i].argument == required_argument ? " [arg] "
                                              : opts[i].argument == optional_argument ? " [optional] " : "",
                                              opts[i].description));
            }
        }
    }
    out.append("</section>\n"
               "<section name=\"Authors\">\n"
               "  <p>RTags was written by Jan Erik Hanssen &lt;jhanssen@gmail.com&gt; and Anders Bakken &lt;abakken@gmail.com&gt;</p>\n"
               "</section>\n"
               "<section name=\"See also\">\n"
               "  <p><manref name=\"rdm\" section=\"1\"/></p>\n"
               "</section>\n"
               "<section name=\"Comments\">\n"
               "  <p>This man page was written using <manref name=\"xmltoman\" section=\"1\" href=\"http://masqmail.cx/xmltoman/\"/>.</p>\n"
               "</section>\n"
               "</manpage>\n");
    printf("%s", out.constData());
}
Example #30
0
static inline Path checkEntry(const Entry *entries, const Path &path, const Path &home)
{
    for (int i=0; entries[i].name; ++i) {
        Path p = findAncestor(path, entries[i].name, entries[i].flags);
        if ((p.isEmpty() || p == home) && (entries[i].flags & Wildcard)) {
            const int len = strlen(entries[i].name);
            if (entries[i].name[len - 1] == '*') {
                const String name(entries[i].name, len - 1);
                p = findAncestor(path, name.constData(), entries[i].flags & ~Wildcard);
            }
        }
        if (!p.isEmpty() && p != home) {
            return p;
        }
    }
    return Path();
}