]>
Dogcows Code - chaz/tar/blob - tests/genfile.c
1 /* Generate a file containing some preset patterns.
3 Copyright (C) 1995, 1996, 1997, 2001, 2003 Free Software
6 François Pinard <pinard@iro.umontreal.ca>, 1995.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software Foundation,
20 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 # define EXIT_SUCCESS 0
32 # define EXIT_FAILURE 1
41 /* The name this program was run with. */
42 const char *program_name
;
44 /* If nonzero, display usage information and exit. */
45 static int show_help
= 0;
47 /* If nonzero, print the version on standard output and exit. */
48 static int show_version
= 0;
50 /* Length of file to generate. */
51 static int file_length
= 0;
53 /* Pattern to generate. */
54 static enum pattern pattern
= DEFAULT_PATTERN
;
56 /* Explain how to use the program, then get out. */
60 if (status
!= EXIT_SUCCESS
)
61 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
65 printf (_("Generate data files for GNU tar test suite.\n"));
68 Usage: %s [OPTION]...\n"), program_name
);
70 If a long option shows an argument as mandatory, then it is mandatory\n\
71 for the equivalent short option also.\n\
73 -l, --file-length=LENGTH LENGTH of generated file\n\
74 -p, --pattern=PATTERN PATTERN is `default' or `zeros'\n\
75 --help display this help and exit\n\
76 --version output version information and exit\n"),
82 /* Main program. Decode ARGC arguments passed through the ARGV array
83 of strings, then launch execution. */
85 /* Long options equivalences. */
86 static const struct option long_options
[] =
88 {"help", no_argument
, &show_help
, 1},
89 {"length", required_argument
, NULL
, 'l'},
90 {"pattern", required_argument
, NULL
, 'p'},
91 {"version", no_argument
, &show_version
, 1},
95 static char const * const pattern_args
[] = { "default", "zeros", 0 };
96 static enum pattern
const pattern_types
[] = {DEFAULT_PATTERN
, ZEROS_PATTERN
};
99 main (int argc
, char *const *argv
)
101 int option_char
; /* option character */
102 int counter
; /* general purpose counter */
104 /* Decode command options. */
106 program_name
= argv
[0];
107 setlocale (LC_ALL
, "");
109 while (option_char
= getopt_long (argc
, argv
, "l:p:", long_options
, NULL
),
114 usage (EXIT_FAILURE
);
120 file_length
= atoi (optarg
);
124 pattern
= XARGMATCH ("--pattern", optarg
,
125 pattern_args
, pattern_types
);
129 /* Process trivial options. */
133 printf ("genfile (GNU %s) %s\n", PACKAGE
, VERSION
);
134 printf (_("Copyright (C) %d Free Software Foundation, Inc.\n"), 2003);
136 This program comes with NO WARRANTY, to the extent permitted by law.\n\
137 You may redistribute it under the terms of the GNU General Public License;\n\
138 see the file named COPYING for details."));
140 /* Note to translator: Please translate "F. Pinard" to "François
141 Pinard" if "ç" (c-with-cedilla) is available in the
142 translation's character set and encoding. */
143 puts (_("Written by F. Pinard."));
149 usage (EXIT_SUCCESS
);
152 usage (EXIT_FAILURE
);
158 case DEFAULT_PATTERN
:
159 for (counter
= 0; counter
< file_length
; counter
++)
160 putchar (counter
& 255);
164 for (counter
= 0; counter
< file_length
; counter
++)
This page took 0.040578 seconds and 4 git commands to generate.