GNU/Linux - 宏处理工具M4

GNU M4
M4 = "Macro Processor, Version 4".
1, Introduction to GNU M4
GNU M4 是传统 Unix 宏处理器的实现。它主要与 SVR4 兼容,但也有一些扩展功能(例如,处理超过 9 个位置参数的宏命令)。GNU M4 还内置了包含文件、运行 shell 命令、运算等功能。
GNU M4 is an implementation of the traditional Unix macro processor. It is mostly SVR4 compatible although it has some extensions (for example, handling more than 9 positional parameters to macros). GNU M4 also has built-in functions for including files, running shell commands, doing arithmetic, etc.
GNU M4 是一个宏处理器,它可以将输入复制到输出,并不断扩展宏。宏可以是内置的,也可以是用户自定义的,并且可以接受任意数量的参数。除了进行宏扩展外,m4 还具有内置函数,可用于包含已命名文件、运行 UNIX 命令、进行整数运算、以各种方式处理文本、递归等......m4 既可用作编译器的前端,也可单独用作宏处理器。
GNU M4 is a macro processor in the sense that it copies its input to the output expanding macros as it goes. Macros are either builtin or user-defined and can take any number of arguments. Besides just doing macro expansion, m4 has builtin functions for including named files, running UNIX commands, doing integer arithmetic, manipulating text in various ways, recursion etc... m4 can be used either as a front-end to a compiler or as a macro processor in its own right.
GNU M4 的最大用户之一是 GNU Autoconf 项目。
One of the biggest users of GNU M4 is the GNU Autoconf project.
2, Downloading M4
最新的稳定版本是 1.4.19,可在 Index of /gnu/m4 [通过 http] 和 ftp://ftp.gnu.org/gnu/m4/ [通过 FTP]上找到。也可以在我们的 FTP 镜像 ( GNU Mirror List- GNU Project - Free Software Foundation) 中找到。稳定版开发分支也可以通过以下任一方式从 git 签出:
The latest stable version is 1.4.19, and can be found on Index of /gnu/m4 [via http] and ftp://ftp.gnu.org/gnu/m4/ [via FTP]. It can also be found on one of our FTP mirrors ( GNU Mirror List- GNU Project - Free Software Foundation). The stable development branch can also be checked out from git, using either of:
git clone git://git.sv.gnu.org/m4
git clone http://git.savannah.gnu.org/r/m4.git
followed by:
git checkout -b branch-1.4 origin/branch-1.4
3, Documentation
GNU M4 文档有多种格式,请访问 GNU M4 - GNU macro processor - GNU Project - Free Software Foundation。您也可以通过查看本地文档找到更多有关 GNU M4 的信息。例如,您可以尝试查看 /usr/share/doc/m4/,或在 shell 提示下使用 info m4。
GNU M4 documentation can be found in several formats at GNU M4 - GNU macro processor - GNU Project - Free Software Foundation. You may also find more information about GNU M4 by looking at your local documentation. For example, you might try looking in /usr/share/doc/m4/, or use info m4 at the shell prompt.
GNU M4 - GNU macro processor - GNU Project - Free Software Foundation
GNU M4 1.4.19 macro processor
4, Mailing Lists
GNU M4 有多个邮件列表: < bug-m4@gnu.org>、< m4-discuss@gnu.org>、< m4-patches@gnu.org> 和 < m4-announce@gnu.org>。这些邮件列表都有存档;请参阅每个邮件列表的详细信息以获取存档链接。
GNU M4 has several mailing lists: < bug-m4@gnu.org >, < m4-discuss@gnu.org >, < m4-patches@gnu.org >, and < m4-announce@gnu.org >. Archives of these lists are available; see the details of each list for a link to the archives.
您可以如下所述通过网络订阅任何 GNU 邮件列表。或者,您也可以向相关请求列表发送一封空邮件,在邮件标题行注明 "订阅"。例如,要订阅 bug-m4 列表,您可以向 < bug-m4-request@gnu.org> 发送一封没有正文、标题行仅为 "订阅 "的邮件。
You can subscribe to any GNU mailing list via the web as described below. Or you can send an empty mail with a Subject: header line of just "subscribe" to the relevant request list. For example, to subscribe yourself to the bug-m4 list, you would send mail to < bug-m4-request@gnu.org > with no body and a Subject: header line of just "subscribe".
为防止垃圾邮件泛滥,有必要对 GNU M4 邮件列表进行管理。向邮件列表发布的内容由列表版主负责发布。有时,版主会在短时间内无法工作。请耐心等待。如果您在列表存档中没有看到该邮件,则说明该邮件没有被发布。
It has been necessary to moderate the GNU M4 mailing lists to prevent the flood of spam. Postings to the lists are held for release by the list moderator. Sometimes the moderators are unavailable for brief periods of time. Please be patient when posting. If you don't see the message in the list archive then it did not get posted.
5, Announcements
低容量邮件列表 m4-announce 包含有关 GNU M4 的所有公告。有关 M4 和大多数其他 GNU 软件的重要公告也在 < info-gnu@gnu.org> 上发布。
The low-volume mailing list m4-announce contains all announcements about GNU M4. Important announcements about M4 and most other GNU Software are also made on < info-gnu@gnu.org >.
6, Tracking Development
中型邮件列表 bug-m4 跟踪所有错误报告。有关提交错误报告的更多信息,请参阅下面的 "报告错误 "部分。
The moderate-volume mailing list bug-m4 tracks all bug reports. For more information on submitting bugs, please see the section Report a Bug below.
中型邮件列表 m4-patches 用于提出和跟踪所有重要补丁。GNU M4 正在积极开发中,2.0 版本将有许多新功能,如更好的输入控制、多精度运算和可加载模块。有关 GNU M4 未来发展的更多信息,请访问 GNU M4 - Summary [Savannah]。您可以使用 git 跟踪开发进程:
The moderate-volume mailing list m4-patches is used to propose and track all significant patches. GNU M4 is being actively developed, and version 2.0 will have many new features, such as better input control, multiple precision arithmetic and loadable modules. More information about the future of GNU M4 is at GNU M4 - Summary [Savannah]. You can track development in git, using:
git clone git://git.sv.gnu.org/m4
git clone http://git.savannah.gnu.org/r/m4.git
You can also view the git tree on the web. ( http://git.sv.gnu.org/gitweb/?p=m4.git)
另外,这里还有一个只读的 CVS 镜像:
Alternatively, there is a read-only CVS mirror here:
cvs -d :pserver:anonymous@pserver.git.sv.gnu.org:/m4.git \
co -d m4 HEAD


M4的使用和学习
Here's a simple usage guide for GNU M4 with basic examples:
Step-by-Step: Example 1 Simple Usage of GNU M4

  1. Install GNU M4
    Make sure M4 is installed. You can check by typing:
    m4 --version
    If not installed, install it via your package manager (as described earlier).
  2. Creating a Simple M4 Script
    Let's create a basic file `example.m4` with simple macros.
    define(`PI', `3.14159')
    define(`greeting', `Hello, World!')
    PI is the value of pi.
    greeting
    This file contains two macros:
  • `PI` with the value `3.14159`
  • `greeting` with the value `Hello, World!`
  1. Running the M4 Script
    To process the file using M4, open a terminal and run:
    m4 example.m4
    The output will be:
    3.14159 is the value of pi.
    Hello, World!
    Example 2: Using Arguments in Macros
    You can pass arguments to macros. In this example, let's define a macro that takes a name as an argument.
  2. Create a file `greet.m4`:
    define(`greet', `Hello, $1!')
    greet(`Alice')
    greet(`Bob')
  3. Run the M4 script:
    m4 greet.m4
    The output will be:
    Hello, Alice!
    Hello, Bob!
    Example 3: Simple Conditional with `ifelse`
    You can use simple conditionals with `ifelse`.
  4. Create a file `condition.m4`:
    ifelse(`yes', `yes', `The answer is yes.', `The answer is no.')
  5. Run the M4 script:
    m4 condition.m4
    Output:
    The answer is yes.
    这些是如何使用 GNU M4 定义宏、使用参数和条件的简单示例。它是一个非常通用的文本处理工具!
    These are simple examples of how to define macros, use arguments, and conditionals with GNU M4. It's a very versatile tool for text processing!
    参考:
    GNU M4 - GNU Project - Free Software Foundation
相关推荐
云边有个稻草人3 小时前
【优选算法】—复写零(双指针算法)
笔记·算法·双指针算法
冷眼看人间恩怨11 小时前
【Qt笔记】QDockWidget控件详解
c++·笔记·qt·qdockwidget
Hejjon16 小时前
SpringBoot 整合 SQLite 数据库
笔记
西洼工作室19 小时前
【java 正则表达式 笔记】
java·笔记·正则表达式
初学者7.19 小时前
Webpack学习笔记(2)
笔记·学习·webpack
新手上路狂踩坑20 小时前
Android Studio的笔记--BusyBox相关
android·linux·笔记·android studio·busybox
stm 学习ing21 小时前
HDLBits训练3
c语言·经验分享·笔记·算法·fpga·eda·verilog hdl
尘觉1 天前
算法的学习笔记—扑克牌顺子(牛客JZ61)
数据结构·笔记·学习·算法
bohu831 天前
sentinel学习笔记1-为什么需要服务降级
笔记·学习·sentinel·滑动窗口
初学者7.1 天前
Webpack学习笔记(3)
笔记·学习·webpack