亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? cut.c

?? linux 應(yīng)用開發(fā)技術(shù)詳解中的附錄源碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* cut - remove parts of lines of files
   Copyright (C) 1984, 1997, 1998, 1999, 2000, 2001, 2002 by David M. Ihnat

   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 2, 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, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

/* Written by David Ihnat.  */

/* POSIX changes, bug fixes, long-named options, and cleanup
   by David MacKenzie <djm@gnu.ai.mit.edu>.

   Rewrite cut_fields and cut_bytes -- Jim Meyering.  */

#include <config.h>

#include <stdio.h>
#include <assert.h>
#include <getopt.h>
#include <sys/types.h>

/* Get mbstate_t, mbrtowc().  */
#if HAVE_WCHAR_H
# include <wchar.h>
#endif

#include "system.h"
#include "getstr.h"
#include "closeout.h"
#include "error.h"

/* MB_LEN_MAX is incorrectly defined to be 1 in at least one GCC
   installation; work around this configuration error.	*/
#if !defined MB_LEN_MAX || MB_LEN_MAX < 2
# undef MB_LEN_MAX
# define MB_LEN_MAX 16
#endif

/* Some systems, like BeOS, have multibyte encodings but lack mbstate_t.  */
#if HAVE_MBRTOWC && defined mbstate_t
# define mbrtowc(pwc, s, n, ps) (mbrtowc) (pwc, s, n, 0)
#endif

/* The official name of this program (e.g., no `g' prefix).  */
#define PROGRAM_NAME "cut"

#define AUTHORS N_ ("David Ihnat, David MacKenzie, and Jim Meyering")

#define FATAL_ERROR(Message)						\
  do									\
    {									\
      error (0, 0, (Message));						\
      usage (2);							\
    }									\
  while (0)

/* Append LOW, HIGH to the list RP of range pairs, allocating additional
   space if necessary.  Update local variable N_RP.  When allocating,
   update global variable N_RP_ALLOCATED.  */

#define ADD_RANGE_PAIR(rp, low, high)					\
  do									\
    {									\
      if (n_rp >= n_rp_allocated)					\
	{								\
	  n_rp_allocated *= 2;						\
	  (rp) = (struct range_pair *) xrealloc ((char *) (rp),		\
				   n_rp_allocated * sizeof (*(rp)));	\
	}								\
      rp[n_rp].lo = (low);						\
      rp[n_rp].hi = (high);						\
      ++n_rp;								\
    }									\
  while (0)

/* Refill the buffer BUF to get a multibyte character. */
#define REFILL_BUFFER(BUF, BUFPOS, BUFLEN, STREAM)			\
  do									\
    {									\
      if (BUFLEN < MB_LEN_MAX && !feof (STREAM) && !ferror (STREAM))	\
	{								\
	  memmove (BUF, BUFPOS, BUFLEN);				\
	  BUFLEN += fread (BUF + BUFLEN, sizeof(char), BUFSIZ, STREAM); \
	  BUFPOS = BUF;							\
	}								\
    }									\
  while (0)

/* Get wide character on BUFPOS. BUFPOS is not included after that.
   If byte sequence is not valid as a character, CONVFAIL is 1. Otherwise 0. */ 
#define GET_NEXT_WC_FROM_BUFFER(WC, BUFPOS, BUFLEN, MBLENGTH, STATE, CONVFAIL) \
  do									\
    {									\
      mbstate_t state_bak;						\
									\
      if (BUFLEN < 1)							\
	{								\
	  WC = WEOF;							\
	  break;							\
	}								\
									\
      /* Get a wide character. */					\
      CONVFAIL = 0;							\
      state_bak = STATE;						\
      MBLENGTH = mbrtowc ((wchar_t *)&WC, BUFPOS, BUFLEN, &STATE);	\
									\
      switch (MBLENGTH)							\
	{								\
	case (size_t)-1:						\
	case (size_t)-2:						\
	  CONVFAIL++;							\
	  STATE = state_bak;						\
	  /* Fall througn. */						\
									\
	case 0:								\
	  MBLENGTH = 1;							\
	  break;							\
	}								\
    }									\
  while (0)

struct range_pair
  {
    unsigned int lo;
    unsigned int hi;
  };

/* This buffer is used to support the semantics of the -s option
   (or lack of same) when the specified field list includes (does
   not include) the first field.  In both of those cases, the entire
   first field must be read into this buffer to determine whether it
   is followed by a delimiter or a newline before any of it may be
   output.  Otherwise, cut_fields can do the job without using this
   buffer.  */
static char *field_1_buffer;

/* The number of bytes allocated for FIELD_1_BUFFER.  */
static size_t field_1_bufsize;

/* The largest byte, character or field index used as an endpoint of a closed
   or degenerate range specification;  this doesn't include the starting
   index of right-open-ended ranges.  For example, with either range spec
   `2-5,9-', `2-3,5,9-' this variable would be set to 5.  */
static unsigned int max_range_endpoint;

/* If nonzero, this is the index of the first field in a range that goes
   to end of line. */
static unsigned int eol_range_start;

/* In byte mode, which bytes to output.
   In character mode, which characters to output.
   In field mode, which DELIM-separated fields to output.
   Bytes, characters and fields are numbered starting with 1,
   so the zeroth element of this array is unused.
   A byte, character or field K has been selected if
   (K <= MAX_RANGE_ENDPOINT and PRINTABLE_FIELD[K])
    || (EOL_RANGE_START > 0 && K >= EOL_RANGE_START).  */
static int *printable_field;

enum operating_mode
  {
    undefined_mode,

    /* Output bytes that are at the given positions. */
    byte_mode,

    /* Output characters that are at the given positions. */
    character_mode,

    /* Output the given delimeter-separated fields. */
    field_mode
  };

/* The name this program was run with. */
char *program_name;

static enum operating_mode operating_mode;

/* If nonzero, when in byte mode, don't split multibyte characters.  */
static int byte_mode_character_aware;

/* If nonzero, the function for single byte locale is work
   if this program runs on multibyte locale. */
static int force_singlebyte_mode;

/* If nonzero do not output lines containing no delimeter characters.
   Otherwise, all such lines are printed.  This option is valid only
   with field mode.  */
static int suppress_non_delimited;

/* The delimeter character for field mode. */
static int delim;
#if HAVE_WCHAR_H
static wchar_t wcdelim;
#endif

/* The length of output_delimiter_string.  */
static size_t output_delimiter_length;

/* The output field separator string.  Defaults to the 1-character
   string consisting of the input delimiter.  */
static char *output_delimiter_string;

/* Nonzero if we have ever read standard input. */
static int have_read_stdin;

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

static struct option const longopts[] =
{
  {"bytes", required_argument, 0, 'b'},
  {"characters", required_argument, 0, 'c'},
  {"fields", required_argument, 0, 'f'},
  {"delimiter", required_argument, 0, 'd'},
  {"only-delimited", no_argument, 0, 's'},
  {"output-delimiter", required_argument, 0, OUTPUT_DELIMITER_OPTION},
  {GETOPT_HELP_OPTION_DECL},
  {GETOPT_VERSION_OPTION_DECL},
  {0, 0, 0, 0}
};

void
usage (int status)
{
  if (status != 0)
    fprintf (stderr, _("Try `%s --help' for more information.\n"),
	     program_name);
  else
    {
      printf (_("\
Usage: %s [OPTION]... [FILE]...\n\
"),
	      program_name);
      fputs (_("\
Print selected parts of lines from each FILE to standard output.\n\
\n\
"), stdout);
      fputs (_("\
Mandatory arguments to long options are mandatory for short options too.\n\
"), stdout);
      fputs (_("\
  -b, --bytes=LIST        output only these bytes\n\
  -c, --characters=LIST   output only these characters\n\
  -d, --delimiter=DELIM   use DELIM instead of TAB for field delimiter\n\
"), stdout);
      fputs (_("\
  -f, --fields=LIST       output only these fields;  also print any line\n\
                            that contains no delimiter character, unless\n\
                            the -s option is specified\n\
  -n                      with -b: don't split multibyte characters\n\
"), stdout);
      fputs (_("\
  -s, --only-delimited    do not print lines not containing delimiters\n\
      --output-delimiter=STRING  use STRING as the output delimiter\n\
                            the default is to use the input delimiter\n\
"), stdout);
      fputs (HELP_OPTION_DESCRIPTION, stdout);
      fputs (VERSION_OPTION_DESCRIPTION, stdout);
      fputs (_("\
\n\
Use one, and only one of -b, -c or -f.  Each LIST is made up of one\n\
range, or many ranges separated by commas.  Each range is one of:\n\
\n\
  N     N'th byte, character or field, counted from 1\n\
  N-    from N'th byte, character or field, to end of line\n\
  N-M   from N'th to M'th (included) byte, character or field\n\
  -M    from first to M'th (included) byte, character or field\n\
\n\
With no FILE, or when FILE is -, read standard input.\n\
"), stdout);
      printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
    }
  exit (status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

static int
print_kth (unsigned int k)
{
  return ((0 < eol_range_start && eol_range_start <= k)
	  || (k <= max_range_endpoint && printable_field[k]));
}

/* Given the list of field or byte range specifications FIELDSTR, set
   MAX_RANGE_ENDPOINT and allocate and initialize the PRINTABLE_FIELD
   array.  If there is a right-open-ended range, set EOL_RANGE_START
   to its starting index.  FIELDSTR should be composed of one or more
   numbers or ranges of numbers, separated by blanks or commas.
   Incomplete ranges may be given: `-m' means `1-m'; `n-' means `n'
   through end of line.  Return nonzero if FIELDSTR contains at least
   one field specification, zero otherwise.  */

/* FIXME-someday:  What if the user wants to cut out the 1,000,000-th field
   of some huge input file?  This function shouldn't have to alloate a table
   of a million ints just so we can test every field < 10^6 with an array
   dereference.  Instead, consider using a dynamic hash table.  It would be
   simpler and nearly as good a solution to use a 32K x 4-byte table with
   one bit per field index instead of a whole `int' per index.  */

static int
set_fields (const char *fieldstr)
{
  unsigned int initial = 1;	/* Value of first number in a range.  */
  unsigned int value = 0;	/* If nonzero, a number being accumulated.  */
  int dash_found = 0;		/* Nonzero if a '-' is found in this field.  */
  int field_found = 0;		/* Non-zero if at least one field spec
				   has been processed.  */

  struct range_pair *rp;
  unsigned int n_rp;
  unsigned int n_rp_allocated;
  unsigned int i;

  n_rp = 0;
  n_rp_allocated = 16;
  rp = (struct range_pair *) xmalloc (n_rp_allocated * sizeof (*rp));

  /* Collect and store in RP the range end points.
     It also sets EOL_RANGE_START if appropriate.  */

  for (;;)
    {
      if (*fieldstr == '-')
	{
	  /* Starting a range. */
	  if (dash_found)
	    FATAL_ERROR (_("invalid byte, character or field list"));
	  dash_found++;
	  fieldstr++;

	  if (value)
	    {
	      initial = value;
	      value = 0;
	    }
	  else
	    initial = 1;
	}
      else if (*fieldstr == ',' || ISBLANK (*fieldstr) || *fieldstr == '\0')
	{
	  /* Ending the string, or this field/byte sublist. */
	  if (dash_found)
	    {
	      dash_found = 0;

	      /* A range.  Possibilites: -n, m-n, n-.
		 In any case, `initial' contains the start of the range. */
	      if (value == 0)
		{
		  /* `n-'.  From `initial' to end of line. */
		  if(eol_range_start == 0 ||
		     (eol_range_start != 0 && eol_range_start > initial))
		    eol_range_start = initial;
		  field_found = 1;
		}
	      else
		{
		  /* `m-n' or `-n' (1-n). */
		  if (value < initial)
		    FATAL_ERROR (_("invalid byte, character or field list"));

		  /* Is there already a range going to end of line? */
		  if (eol_range_start != 0)
		    {
		      /* Yes.  Is the new sequence already contained
			 in the old one?  If so, no processing is
			 necessary. */
		      if (initial < eol_range_start)
			{
			  /* No, the new sequence starts before the
			     old.  Does the old range going to end of line
			     extend into the new range?  */
			  if (value + 1 >= eol_range_start)
			    {
			      /* Yes.  Simply move the end of line marker. */
			      eol_range_start = initial;
			    }
			  else
			    {
			      /* No.  A simple range, before and disjoint from
				 the range going to end of line.  Fill it. */
			      ADD_RANGE_PAIR (rp, initial, value);
			    }

			  /* In any case, some fields were selected. */
			  field_found = 1;
			}
		    }
		  else
		    {
		      /* There is no range going to end of line. */
		      ADD_RANGE_PAIR (rp, initial, value);
		      field_found = 1;
		    }
		  value = 0;
		}
	    }
	  else if (value != 0)
	    {
	      /* A simple field number, not a range. */
	      ADD_RANGE_PAIR (rp, value, value);
	      value = 0;
	      field_found = 1;
	    }

	  if (*fieldstr == '\0')
	    {
	      break;
	    }

	  fieldstr++;
	}
      else if (ISDIGIT (*fieldstr))
	{
	  /* detect overflow. */
	  {
	    double check_overflow;

	   check_overflow = value + (*fieldstr - '0') / 10.0;
	   if(check_overflow > UINT_MAX / 10.0)
	      FATAL_ERROR (_("too large number"));
	  }
	  value = 10 * value + *fieldstr - '0';
	  fieldstr++;
	}
      else
	FATAL_ERROR (_("invalid byte, character or field list"));
    }

  max_range_endpoint = 0;
  for (i = 0; i < n_rp; i++)
    {
      if (rp[i].hi > max_range_endpoint)
	max_range_endpoint = rp[i].hi;
    }

  /* Allocate an array large enough so that it may be indexed by
     the field numbers corresponding to all finite ranges
     (i.e. `2-6' or `-4', but not `5-') in FIELDSTR.  */

  printable_field = (int *) xmalloc ((max_range_endpoint + 1) * sizeof (int));
  memset (printable_field, 0, (max_range_endpoint + 1) * sizeof (int));

  /* Set the array entries corresponding to integers in the ranges of RP.  */
  for (i = 0; i < n_rp; i++)
    {
      unsigned int j;
      for (j = rp[i].lo; j <= rp[i].hi; j++)
	{
	  printable_field[j] = 1;
	}
    }

  free (rp);

  return field_found;
}

/* Read from stream STREAM, printing to standard output any selected bytes.  */
static void
cut_bytes (FILE *stream)
{
  int byte_idx;			/* number of bytes in the line so far. */

  byte_idx = 0;
  while (1)
    {
      int c;			/* each byte from the file. */

      c = getc (stream);

      if (c == '\n')
	{
	  putchar ('\n');
	  byte_idx = 0;
	}
      else if (c == EOF)
	{
	  if (byte_idx > 0)
	    putchar ('\n');
	  break;
	}
      else
	{
	  ++byte_idx;
	  if (print_kth (byte_idx))
	    {
	      putchar (c);
	    }
	}
    }
}

#if HAVE_MBRTOWC
/* This function is in use for the following case.

   1. Read from the stream STREAM, printing to standard output any selected
   characters. 

   2. Read from stream STREAM, printing to standard output any selected bytes,
   without splitting multibyte characters.  */
 
static void
cut_characters_or_cut_bytes_no_split (FILE *stream)
{
  int idx;		/* number of bytes or characters in the line so far. */
  char buf[MB_LEN_MAX + BUFSIZ];  /* For spooling a read byte sequence. */
  char *bufpos;		/* Next read position of BUF. */
  size_t buflen;	/* The length of the byte sequence in buf. */
  wint_t wc;		/* A gotten wide character. */
  size_t mblength;	/* The byte size of a multibyte character which shows
			   as same character as WC. */
  mbstate_t state;	/* State of the stream. */
  int convfail;		/* 1, when conversion is failed. Otherwise 0. */

  idx = 0;
  buflen = 0;
  bufpos = buf;
  memset (&state, '\0', sizeof(mbstate_t));

  while (1)
    {
      REFILL_BUFFER (buf, bufpos, buflen, stream);

      GET_NEXT_WC_FROM_BUFFER (wc, bufpos, buflen, mblength, state, convfail);

      if (wc == WEOF)
	{
	  if (idx > 0)
	    putchar ('\n');

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲人成小说网站色在线| 91精品国产欧美日韩| 国产亚洲成aⅴ人片在线观看| 日韩精品色哟哟| 欧美日韩精品一区二区三区蜜桃| 亚洲欧美怡红院| 在线观看亚洲a| 五月开心婷婷久久| 欧美一级二级三级蜜桃| 久久精工是国产品牌吗| 精品久久国产97色综合| 国产成人精品aa毛片| 中文字幕乱码久久午夜不卡 | 欧美日韩成人综合天天影院 | 免费在线看一区| 欧美精品一区二区久久婷婷 | 天天综合天天做天天综合| 91精品国产色综合久久不卡蜜臀| 日本 国产 欧美色综合| 精品电影一区二区| 成人av在线影院| 亚洲高清不卡在线观看| 欧美一区二区三级| 国产寡妇亲子伦一区二区| 亚洲品质自拍视频| 这里是久久伊人| 国产成人在线影院| 一区二区三区免费在线观看| 经典三级视频一区| 国产精品国产三级国产普通话蜜臀 | 91精品国产免费| 国产精品一区二区视频| 亚洲视频香蕉人妖| 欧美电影免费提供在线观看| 大尺度一区二区| 亚洲观看高清完整版在线观看 | 欧美在线观看一二区| 日日欢夜夜爽一区| 国产精品久久久久久亚洲毛片 | 91蜜桃婷婷狠狠久久综合9色| 五月天一区二区三区| 欧美午夜宅男影院| 国产精品一二三四五| 午夜亚洲福利老司机| 中文字幕av一区二区三区高| 欧美日韩精品系列| 成人听书哪个软件好| 蜜臀av在线播放一区二区三区| 99久久国产综合精品女不卡| 亚洲免费观看在线观看| 欧美精品一区二区蜜臀亚洲| 欧美三级视频在线| a亚洲天堂av| 国产自产视频一区二区三区| 午夜国产精品影院在线观看| 国产精品激情偷乱一区二区∴| 日韩视频一区在线观看| 在线观看国产91| 福利一区二区在线观看| 免费看日韩a级影片| 亚洲欧美日韩精品久久久久| 久久青草国产手机看片福利盒子 | 日韩视频在线观看一区二区| 色噜噜狠狠色综合欧洲selulu| 国产一本一道久久香蕉| 青青青爽久久午夜综合久久午夜| 亚洲欧美aⅴ...| 中文字幕亚洲区| 日本一区二区三区高清不卡| 精品国产制服丝袜高跟| 91麻豆精品国产91久久久久久久久| 91亚洲国产成人精品一区二区三 | 成人激情文学综合网| 国产主播一区二区| 久久精品国产精品亚洲红杏| 午夜在线成人av| 亚洲丰满少妇videoshd| 亚洲乱码日产精品bd| 亚洲人精品午夜| 亚洲男同1069视频| 亚洲精品ww久久久久久p站| 国产精品视频免费| 国产精品免费久久| 国产精品无人区| 亚洲欧洲精品成人久久奇米网| 久久精品夜色噜噜亚洲a∨| 欧美精品一区二区三区高清aⅴ| 日韩欧美高清一区| 精品国产乱码久久久久久浪潮| 日韩欧美国产不卡| 久久蜜桃av一区二区天堂| www一区二区| 国产精品久99| 一区二区三区四区中文字幕| 夜夜嗨av一区二区三区四季av| 亚洲一区免费观看| 强制捆绑调教一区二区| 激情都市一区二区| 成人黄色片在线观看| 91色porny在线视频| 欧美色图激情小说| 欧美哺乳videos| 国产精品视频一二三| 亚洲香肠在线观看| 看片网站欧美日韩| 成人黄色小视频在线观看| 欧洲激情一区二区| 精品裸体舞一区二区三区| 中文字幕欧美国产| 偷拍日韩校园综合在线| 精久久久久久久久久久| eeuss鲁一区二区三区| 欧美体内she精高潮| 337p粉嫩大胆噜噜噜噜噜91av| 中文字幕一区二区三区在线不卡 | 欧美日韩国产片| 精品毛片乱码1区2区3区 | 日韩欧美高清一区| 国产精品乱子久久久久| 亚洲www啪成人一区二区麻豆| 久久99精品久久久久久动态图| 成人avav在线| 91精品国产色综合久久不卡蜜臀| 国产欧美日本一区视频| 亚洲成人自拍一区| 国产盗摄一区二区三区| 欧美三区在线观看| 亚洲国产电影在线观看| 秋霞影院一区二区| 一本色道亚洲精品aⅴ| 精品区一区二区| 亚洲线精品一区二区三区| 国产suv精品一区二区三区| 欧美日韩国产高清一区二区三区 | 欧美va亚洲va| 夜夜爽夜夜爽精品视频| 国产一区二区福利| 欧美精品九九99久久| 综合久久国产九一剧情麻豆| 美女精品自拍一二三四| 欧美在线观看一区| 亚洲欧洲精品一区二区精品久久久| 久久国产精品99精品国产| 色视频成人在线观看免| 欧美国产欧美综合| 精品在线一区二区三区| 欧美欧美欧美欧美| 一区二区三区日本| 成人免费毛片片v| 久久久噜噜噜久噜久久综合| 视频一区二区三区中文字幕| 91免费版pro下载短视频| 中文字幕精品一区| 高清免费成人av| 久久先锋影音av鲁色资源网| 日韩av中文字幕一区二区| 欧美中文字幕一区| 亚洲男人的天堂在线观看| 国产成人在线电影| 久久久久99精品国产片| 韩国一区二区三区| 26uuu亚洲综合色| 久久99精品国产.久久久久| 欧美一级精品大片| 免费不卡在线视频| 欧美一级久久久久久久大片| 日韩经典中文字幕一区| 欧美裸体一区二区三区| 亚洲激情五月婷婷| 日本黄色一区二区| 亚洲一区在线电影| 欧美三级视频在线观看| 日韩中文字幕一区二区三区| 欧美军同video69gay| 日韩激情视频网站| 日韩欧美亚洲国产另类 | 精品国产乱码久久久久久图片| 日韩中文字幕不卡| 日韩你懂的电影在线观看| 日本中文字幕一区二区有限公司| 在线成人免费视频| 美女视频黄a大片欧美| 精品88久久久久88久久久| 国产专区欧美精品| 中文字幕五月欧美| 色狠狠综合天天综合综合| 亚洲综合激情另类小说区| 欧美日韩美女一区二区| 免费在线观看精品| 久久精品夜色噜噜亚洲a∨| 99综合影院在线| 亚洲国产欧美日韩另类综合| 在线不卡中文字幕播放| 国产一区欧美二区| 1区2区3区欧美| 欧美图区在线视频| 久久成人免费网| 国产精品国产精品国产专区不片 | 在线精品视频免费播放| 偷拍与自拍一区|