Exemple #1
0
 mapped_files_t(int nb_files, char *argv[], bool sequential) {
   for(int j = 0; j < nb_files; j++) {
     push_back(mapped_file(argv[j]));
     if(sequential)
       end()->sequential();
   }
 }
Exemple #2
0
int main()
{
    ACE_INET_Addr server_addr;
    ACE_SOCK_Acceptor acceptor;
    ACE_SOCK_Stream peer;

    if (-1 == server_addr.set(22334))
    {
        log("server_addr.set faild\n");
        return 1;
    }

    if (-1 == acceptor.open(server_addr))
    {
        log("acceptor.open failed\n");
        return 1;
    }

    while(1)
    {
        if (-1 == acceptor.accept(peer))
        {
            log("acceptor.accept failed\n");
            return 1;
        }

        peer.disable(ACE_NONBLOCK);

        auto_ptr<char> pathname(get_url_pathname(&peer));
        ACE_Mem_Map mapped_file(pathname.get());

        if (-1 == (peer.send_n(mapped_file.addr(), mapped_file.size())))
        {
            log("peer.send_n failed\n");
            return 1;
        }
        
        peer.close();
    }

    return acceptor.close() == -1 ? 1 : 0;
}
Exemple #3
0
 mapped_files_t(int nb_files, char *argv[]) {
   for(int j = 0; j < nb_files; j++)
     push_back(mapped_file(argv[j]));
 }
Exemple #4
0
int builtin_help(Environment &env, const std::vector<std::string> &tokens, const fdmask &fds) {

	bool error = false;
	filesystem::path _f;

	// todo -- -f to specify help file.
	auto argv = getopt(tokens, [&](char c){
		switch(tolower(c))
		{

			default:
				fdprintf(stderr, "### Help - \"-%c\" is not an option.\n", c);
				error = true;
				break;
		}
	});

	if (error) {
		fdputs("# Usage - Help [-f helpfile] command...\n", stderr);
		return 1;
	}


	const filesystem::path sd(ToolBox::MacToUnix(env.get("shelldirectory")));
	const filesystem::path hd = sd / "Help";

	filesystem::path mono;
	mapped_file mono_file;
	std::error_code ec;

	if (_f.empty()) {
		mono = sd / "MPW.Help";
		mono_file = mapped_file(mono, mapped_file::priv, ec);
	} else {

		mono = _f;
		mono_file = mapped_file(mono, mapped_file::priv, ec);
		if (!mono_file && !_f.is_absolute()) {
			mono = sd / _f;
			mono_file = mapped_file(mono, mapped_file::priv, ec);
		}

		if (!mono_file) {
			fdprintf(stderr, "### Help: Unable to open %s\n", _f.c_str());
			fdprintf(stderr, "# %s\n", ec.message().c_str());
			return 3;
		}

	}

	if (mono_file) {
		std::replace(mono_file.begin(), mono_file.end(), '\r', '\n');
	}

	if (argv.empty()) {
		help_helper(mono_file, fds, "");
		return 0;
	}

	int rv = 0;
	for (const auto &cmd : argv) {


		// 1. check for $MPW:Help:command
		filesystem::path p(hd);
		p /= cmd;

		mapped_file f(p, mapped_file::priv, ec);
		if (!ec) {
			std::replace(f.begin(), f.end(), '\r', '\n');
			write(stdout, f.data(), f.size());
			fdputs("\n", stdout);
			continue;
		}


		if (mono_file) {
			bool ok = help_helper(mono_file, fds, cmd);
			if (ok) break;
		}

		fdprintf(stderr, "### Help - \"%s\" was not found.\n", cmd.c_str());
		rv = 2;
	}

	return rv;
}