]>
Dogcows Code - chaz/tar/blob - genfile.c
b5c79c30962a480a0339424f0092e1259df13e63
1 /* Generate a file containing some preset patterns.
3 Copyright (C) 1995, 1996, 1997, 2001, 2003, 2004 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. */
57 static void usage (int) __attribute__ ((noreturn
));
61 if (status
!= EXIT_SUCCESS
)
62 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
66 printf (_("Generate data files for GNU tar test suite.\n"));
69 Usage: %s [OPTION]...\n"), program_name
);
71 If a long option shows an argument as mandatory, then it is mandatory\n\
72 for the equivalent short option also.\n\
74 -l, --file-length=LENGTH LENGTH of generated file\n\
75 -p, --pattern=PATTERN PATTERN is `default' or `zeros'\n\
76 --help display this help and exit\n\
77 --version output version information and exit\n"),
83 /* Main program. Decode ARGC arguments passed through the ARGV array
84 of strings, then launch execution. */
86 /* Long options equivalences. */
87 static const struct option long_options
[] =
89 {"help", no_argument
, &show_help
, 1},
90 {"length", required_argument
, NULL
, 'l'},
91 {"pattern", required_argument
, NULL
, 'p'},
92 {"version", no_argument
, &show_version
, 1},
96 static char const * const pattern_args
[] = { "default", "zeros", 0 };
97 static enum pattern
const pattern_types
[] = {DEFAULT_PATTERN
, ZEROS_PATTERN
};
100 main (int argc
, char *const *argv
)
102 int option_char
; /* option character */
103 int counter
; /* general purpose counter */
105 /* Decode command options. */
107 program_name
= argv
[0];
108 setlocale (LC_ALL
, "");
110 while (option_char
= getopt_long (argc
, argv
, "l:p:", long_options
, NULL
),
115 usage (EXIT_FAILURE
);
121 file_length
= atoi (optarg
);
125 pattern
= XARGMATCH ("--pattern", optarg
,
126 pattern_args
, pattern_types
);
130 /* Process trivial options. */
134 printf ("genfile (GNU %s) %s\n", PACKAGE
, VERSION
);
135 printf (_("Copyright (C) %d Free Software Foundation, Inc.\n"), 2003);
137 This program comes with NO WARRANTY, to the extent permitted by law.\n\
138 You may redistribute it under the terms of the GNU General Public License;\n\
139 see the file named COPYING for details."));
141 /* Note to translator: Please translate "F. Pinard" to "François
142 Pinard" if "ç" (c-with-cedilla) is available in the
143 translation's character set and encoding. */
144 puts (_("Written by F. Pinard."));
150 usage (EXIT_SUCCESS
);
153 usage (EXIT_FAILURE
);
159 case DEFAULT_PATTERN
:
160 for (counter
= 0; counter
< file_length
; counter
++)
161 putchar (counter
& 255);
165 for (counter
= 0; counter
< file_length
; counter
++)
This page took 0.043035 seconds and 3 git commands to generate.