]>
Dogcows Code - chaz/tar/blob - tests/genfile.c
1 /* Generate a file containing some preset patterns.
2 Copyright © 1995, 1996, 1997 Free Software Foundation, Inc.
3 François Pinard <pinard@iro.umontreal.ca>, 1995.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 # define EXIT_SUCCESS 0
28 # define EXIT_FAILURE 1
37 /* The name this program was run with. */
38 const char *program_name
;
40 /* If nonzero, display usage information and exit. */
41 static int show_help
= 0;
43 /* If nonzero, print the version on standard output and exit. */
44 static int show_version
= 0;
46 /* Length of file to generate. */
47 static int file_length
= 0;
49 /* Pattern to generate. */
50 static enum pattern pattern
= DEFAULT
;
52 /*-----------------------------------------------.
53 | Explain how to use the program, then get out. |
54 `-----------------------------------------------*/
59 if (status
!= EXIT_SUCCESS
)
60 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
64 printf (_("Generate data files for GNU tar test suite.\n"));
67 Usage: %s [OPTION]...\n"), program_name
);
69 If a long option shows an argument as mandatory, then it is mandatory\n\
70 for the equivalent short option also.\n\
72 -l, --file-length=LENGTH LENGTH of generated file\n\
73 -p, --pattern=PATTERN PATTERN is `default' or `zeros'\n\
74 --help display this help and exit\n\
75 --version output version information and exit\n"),
81 /*----------------------------------------------------------------------.
82 | Main program. Decode ARGC arguments passed through the ARGV array of |
83 | strings, then launch execution. |
84 `----------------------------------------------------------------------*/
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},
97 const char *pattern_strings
[] =
105 main (int argc
, char *const *argv
)
107 int option_char
; /* option character */
108 int counter
; /* general purpose counter */
110 /* Decode command options. */
112 program_name
= argv
[0];
113 setlocale (LC_ALL
, "");
115 while (option_char
= getopt_long (argc
, argv
, "l:p:", long_options
, NULL
),
120 usage (EXIT_FAILURE
);
126 file_length
= atoi (optarg
);
130 switch (argmatch (optarg
, pattern_strings
))
134 error (0, 0, _("Ambiguous pattern `%s'"), optarg
);
135 usage (EXIT_FAILURE
);
138 error (0, 0, _("Unknown pattern `%s'"), optarg
);
139 usage (EXIT_FAILURE
);
152 /* Process trivial options. */
156 printf ("genfile (GNU %s) %s\n", PACKAGE
, VERSION
);
159 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.\n"),
162 This is free software; see the source for copying conditions. There is NO\n\
163 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
167 Written by François Pinard <pinard@iro.umontreal.ca>.\n"),
173 usage (EXIT_SUCCESS
);
176 usage (EXIT_FAILURE
);
183 for (counter
= 0; counter
< file_length
; counter
++)
184 putchar (counter
& 255);
188 for (counter
= 0; counter
< file_length
; counter
++)
This page took 0.044139 seconds and 4 git commands to generate.