我正在寻找一种通过API查询linux手册页的方法,我发现最接近的是http://linux.die.net/man,但是命令分为8个部分,例如gcc是第1部分:http://linux.die.net/man/1/gcc,因为它实际上不是一个API,所以你得到一个完整的html页面(包括侧边栏和广告)作为回报.
在我开始尝试制作之前,这样的事情是否已经存在?
snprintf(3)的Linux手册页给出了以下示例:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
char *
make_message(const char *fmt, ...)
{
int n;
int size = 100; /* Guess we need no more than 100 bytes */
char *p, *np;
va_list ap;
if ((p = malloc(size)) == NULL)
return NULL;
while (1) {
/* Try to print in the allocated space */
va_start(ap, fmt);
n = vsnprintf(p, size, fmt, ap);
va_end(ap);
/* Check error code */
if (n < 0)
return NULL;
/* If that worked, return …Run Code Online (Sandbox Code Playgroud) 我正在编写一些自定义man页面,我希望包含可能经常更改的内容,例如man页面编写的日期.
例如,一个是在git 回购中,我想更新man页面的日期,无需手动更改.
是否有可能#include在*roff文件中调用shell变量,或者可能是markdown文件,然后使用pandoc" 编译 " man页面?
我知道这是一个奇怪的问题,但我没有遇到过类似的问题.
请注意,这与简单地包含$MANPATH要调用的手册页不同man.
IE,我想使用类似的东西:
.TH foo 10 "$(git log -n1 | grep Date | tail -c 31)" "$(git branch | grep "*")"
而不是每次都必须手动更改日期和分支/头名称.无论是降价还是给予pandoc或其他内容,还是roff文件本身,我都可以.
我有scandir()的问题:联机帮助页包含这个原型:
int scandir(const char *dir, struct dirent ***namelist,
int (*filter)(const struct dirent *),
int (*compar)(const struct dirent **, const struct dirent **));
Run Code Online (Sandbox Code Playgroud)
所以我有这个:
static inline int
RubyCompare(const struct dirent **a,
const struct dirent **b)
{
return(strcmp((*a)->d_name, (*b)->d_name));
}
Run Code Online (Sandbox Code Playgroud)
这是电话:
num = scandir(buf, &entries, NULL, RubyCompare);
Run Code Online (Sandbox Code Playgroud)
最后,编译器说:
warning: passing argument 4 of ‘scandir’ from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)
编译器是gcc-4.3.2,我的CFLAGS如下:
-Wall -Wpointer-arith -Wstrict-prototypes -Wunused -Wshadow -std=gnu99
Run Code Online (Sandbox Code Playgroud)
这个警告是什么意思?RubyCompare的声明看起来对我来说是正确的,除了警告代码完全可行.
我安装了debian lenny,但我很惊讶我无法获取系统调用的手册页(man 2 read等等)
我该如何安装它们?
我有一个关于基本 bash 脚本的计算机科学测试。我们在仅离线的 Linux 机器(几乎都是 Fedora)上工作,这些机器安装了所有典型的手册/信息页面。话虽这么说,记住 bashif语句测试之类的东西是相当单调的,是否有一个 man/info 页面涵盖简单的主题,如if语法、bash 脚本语法等?
我正在使用x86_64 GNU/Linux与gcc.
大纲部分man -s2 open说:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试编译以下代码片段时,gcc不会抛出警告/错误.
#include <stdio.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
int fd;
fd = open("foo.txt", O_RDWR, 0777);
if(fd == -1)
perror("open");
fd = creat("foo.txt", 0777);
if(fd == -1)
perror("creat");
close(fd);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
那么,types.h和stat.h可选的?他们在manpage中的目的是什么open()?
在Ubuntu中,安装libstdc ++ 6-xx-doc后,docs可以通过man获得,例如libstdc ++ - 4.8-doc:
man std::list
man std::weak_ptr
man std::ios_base
Run Code Online (Sandbox Code Playgroud)
是否可以在OSX上安装c ++手册页(使用brew或任何其他方法)?特别需要手册页的原因是我可以使用vim访问它们SHIFT-K.
注意:我正在使用g ++的XCode版本:
snowch$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 OS X(El Capitan,v10.11.3)终端(bash shell)中做一个简单的输出重定向,并在输出中得到一堆不需要的字符。这不会发生在 Linux 上。
例如,如果我输入man open > open.txt,我会得到以下信息:
OPEN(1) BSD General Commands Manual OPEN(1)
NNAAMMEE
ooppeenn -- open files and directories
SSYYNNOOPPSSIISS
ooppeenn [--ee] [--tt] [--ff] [--FF] [--WW] [--RR] [--nn] [--gg] [--hh] [--bb _b_u_n_d_l_e___i_d_e_n_t_i_f_i_e_r]
[--aa _a_p_p_l_i_c_a_t_i_o_n] _f_i_l_e _._._. [----aarrggss _a_r_g_1 _._._.]
DDEESSCCRRIIPPTTIIOONN
The ooppeenn command opens a file (or a directory or URL), just as if you had
double-clicked the file's icon. If no application name is specified, the
default application as determined via LaunchServices …Run Code Online (Sandbox Code Playgroud) 我读过man test并发现:
注意:二进制 -a 和 -o 本质上是不明确的。使用“测试 EXPR1 && 测试 EXPR2”或“测试 EXPR1 ||” 改为测试 EXPR2'。
有人可以解释一下-aand中的含糊之处-o吗?
英语不是我的母语。据我了解,Kevin Braunsdorf 和 Matthew Bradburn(本手册页的作者)建议我们使用&&而不是仅仅-a因为-a可以用作另一个二进制文件中的密钥,因为-a可能有不同的可能含义。
所以,与我们使用时-a没有关联。对于某些人来说并不清楚,所以人们会这样想:“嗯,那把钥匙是什么?我不知道,不确定它是什么,我必须访问......”logical ANDtestlogical ANDman
我能找到的唯一原因是,使用 的代码&&比使用 的代码更容易阅读-a(仅是一个示例):
与-a:
if [ -f "${my_var_with_filename}" -a -n "${my_another_array_var_with_filename[2]}" -o -r /just/path/to/file ]
then
...
fi
Run Code Online (Sandbox Code Playgroud)
与 && 相同:
if [ -f "${my_var_with_filename}" ] && [ -n "${my_another_array_var_with_filename[2]}" ] || …Run Code Online (Sandbox Code Playgroud)