关于one-true-awk和gawk对RS处理的差异的源代码…

2009-05-13 05:04:38来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

在下面这贴的讨论中发现了FreeBSD的awk和gawk在对RS的处理上的不同之处,即对于RS,FreeBSD的awk只接受其第一个字符,而gawk则可接受一个正则表达式。原因已在原贴内给出,此处单列一贴,以便检索。
http://bbs.chinaunix.net/viewthread.php?tid=846353&extra=page%3D1&page=1
FreeBSD的awk是传统的awk,见代码中的版权声明:
CODE:
[Copy to clipboard]
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name Lucent Technologies or any of
its entities not be used in advertising or publicity pertaining
to distribution of the software without specific, written prior
permission.
LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.
****************************************************************/以及README文件中的片段:
QUOTE:
This is the version of awk described in "The AWK Programming Language",
by Al Aho, Brian Kernighan, and Peter Weinberger
(Addison-Wesley, 1988, ISBN 0-201-07981-X).而gawk则对此进行了扩展,见【GAWK: Effective AWK Programming】:
QUOTE:
When using gawk, the value of RS is not limited to a one-character string. It can be any regular expression.
The use of RS as a regular expression and the RT variable are gawk extensions; they are
not available in compatibility mode. In compatibility mode, only the first character of the value of RS is used to determine the end of the record.对这种差异的源代码定位如下:
FreeBSD6.1
/usr/src/contrib/one-true-awk/lib.c:
CODE:
[Copy to clipboard]
int readrec(char **pbuf, int *pbufsize, FILE *inf)        /* read one record into buf */
{
        int sep, c;
        char *rr, *buf = *pbuf;
        int bufsize = *pbufsize;
        if (strlen(*FS) >= sizeof(inputFS))
                FATAL("field separator %.10s... is too long", *FS);
        strcpy(inputFS, *FS);        /* for subsequent field splitting */

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:尝试 文泉驿 字体替代 tahoma + cjk

下一篇:js注册检测