linux下的wc命令的源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/* wc - print the number of lines, words, and bytes in files

Copyright (C) 1985, 1991, 1995-2010 Free Software Foundation, Inc.

This program is free software: you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program. If not, see . */ /* Written by Paul Rubin, phr@

and David MacKenzie, djm@. */

#include

#include

#include

#include

#include

#include

#include

#include "system.h"

#include "argv-iter.h"

#include "error.h"

#include "mbchar.h"

#include "physmem.h"

#include "quote.h"

#include "quotearg.h"

#include "readtokens0.h"

#include "safe-read.h"

#include "xfreopen.h"

#if !defined iswspace && !HAVE_ISWSPACE

# define iswspace(wc) \

((wc) == to_uchar (wc) && isspace (to_uchar (wc)))

#endif

/* The official name of this program (e.g., no `g' prefix). */

#define PROGRAM_NAME "wc"

#define AUTHORS \

proper_name ("Paul Rubin"), \

proper_name ("David MacKenzie")

/* Size of atomic reads. */

#define BUFFER_SIZE (16 * 1024)

/* Cumulative number of lines, words, chars and bytes in all files so far.

max_line_length is the maximum over all files processed so far. */ static uintmax_t total_lines;

static uintmax_t total_words;

static uintmax_t total_chars;

static uintmax_t total_bytes;

static uintmax_t max_line_length;

/* Which counts to print. */

static bool print_lines, print_words, print_chars, print_bytes;

static bool print_linelength;

/* The print width of each count. */

static int number_width;

/* True if we have ever read the standard input. */

static bool have_read_stdin;

/* The result of calling fstat or stat on a file descriptor or file. */

struct fstatus

{

/* If positive, fstat or stat has not been called yet. Otherwise, this is the value returned from fstat or stat. */

int failed;

/* If FAILED is zero, this is the file's status. */

struct stat st;

};

/* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum

{

FILES0_FROM_OPTION = CHAR_MAX + 1

};

static struct option const longopts[] =

{

{"bytes", no_argument, NULL, 'c'},

{"chars", no_argument, NULL, 'm'},

{"lines", no_argument, NULL, 'l'},

{"words", no_argument, NULL, 'w'},

{"files0-from", required_argument, NULL, FILES0_FROM_OPTION}, {"max-line-length", no_argument, NULL, 'L'},

{GETOPT_HELP_OPTION_DECL},

{GETOPT_VERSION_OPTION_DECL},

{NULL, 0, NULL, 0}

};

void

usage (int status)

{

if (status != EXIT_SUCCESS)

相关文档
最新文档