1

As mentioned in the title I want to invoke the preprocessor from a shell.

Let me clarify: Suppose I have to invoke Preprocessor for command patch in Linux say:

patch -p1 -D `"{what and how should i write here }"` < patch.patch

Patch command has an option -D where I can define a preprocessor (to my understanding). I tried searching on Google I got only one link I couldn't understand it properly. Please guide me with an example (or proper reference).

  1. What all can be written in -D option of any command?
  2. Are constructs same for all command are different for different commands?
  3. What can be the input variables?
4

1 回答 1

2

-D选项意味着对修补文件所做的patch更改将被#ifndef X/ #else/#endif如果X是您指定为-D选项的参数的内容。

例如:

$ cat file-1.c
#include <stdio.h>

int main(void)
{
    printf("Hello world\n");
    return 0;
}
$ cat file-2.c
#include <stdio.h>

int main(void)
{
    puts("Hello world");
    return 0;
}
$ diff -u file-1.c file-2.c > patch
$ patch -DPRINTF_TO_PUTS -i patch --verbose
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- file-1.c   2013-02-01 00:33:01.000000000 -0800
|+++ file-2.c   2013-02-01 00:33:17.000000000 -0800
--------------------------
Patching file file-1.c using Plan A...
Hunk #1 succeeded at 2.
done
$ file-1.c
#include <stdio.h>

int main(void)
{
#ifndef PRINTF_TO_PUTS
    printf("Hello world\n");
#else
    puts("Hello world");
#endif
    return 0;
}
$

所以,回答你的问题:

  1. 您应该-Dpatch命令行后面加上一个有效的 C 标识符。
  2. 不同的命令对任何给定的选项字母应用不同的含义。您可以在The Art of Unix Programming中找到有关选项常见解释的信息,但只有 52 个字母(单字母)选项,并且不同命令的参数有更多不同的含义。
  3. 我不确定你的意思。

这些都不会从命令行调用 C 预处理器。cpp如果您需要这样做,请在您的系统上查找程序。如果你在任何地方都找不到cpp,你可能最终会调用gcc -E

于 2013-02-01T08:37:51.367 回答