1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 21:08:08 +01:00

Change to the linux kernel coding style

for arq in `git ls-files *.c`; do
    echo $arq;
    indent -linux -l115 $arq;
    done

The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
Carlos R. Mafra
2009-08-20 00:59:40 +02:00
parent 59fc927dc9
commit 688a56e8ab
209 changed files with 87034 additions and 98138 deletions

View File

@@ -32,54 +32,52 @@
#include "generic.h"
RImage *bilinear (int argc, char **argv, int width, int height,
int relief) {
RImage *bilinear(int argc, char **argv, int width, int height, int relief)
{
int color[4][3];
RImage *image;
unsigned char *cptr;
int i, j, k;
argc--; argv++;
argc--;
argv++;
if (!start_image ("bilinear", argc, 4, 5, width, height, &image)) {
return (RImage *)0;
if (!start_image("bilinear", argc, 4, 5, width, height, &image)) {
return (RImage *) 0;
}
for (i=0; i<4; i++) {
if (!parse_color (argv[i], color[i])) {
error ("can't parse color: \"%s\"\n", argv[i]);
for (i = 0; i < 4; i++) {
if (!parse_color(argv[i], color[i])) {
error("can't parse color: \"%s\"\n", argv[i]);
return 0;
}
}
cptr = image->data;
for (i=0; i<height; i++) {
for (i = 0; i < height; i++) {
int b = 0xff * i / height;
int t = 0xff - b;
for (j=0; j<width; j++) {
for (j = 0; j < width; j++) {
int r = 0xff * j / width;
int l = 0xff - r;
int f[4];
f[0] = (l*t) >> 8;
f[1] = (r*t) >> 8;
f[2] = (l*b) >> 8;
f[3] = (r*b) >> 8;
f[0] = (l * t) >> 8;
f[1] = (r * t) >> 8;
f[2] = (l * b) >> 8;
f[3] = (r * b) >> 8;
for (k=0; k<3; k++) {
for (k = 0; k < 3; k++) {
*cptr++ =
( f[0] * color[0][k] +
f[1] * color[1][k] +
f[2] * color[2][k] +
f[3] * color[3][k] ) >> 8;
(f[0] * color[0][k] +
f[1] * color[1][k] + f[2] * color[2][k] + f[3] * color[3][k]) >> 8;
}
if (RRGBAFormat==image->format)
if (RRGBAFormat == image->format)
cptr++;
}
}
return image;
}

View File

@@ -25,7 +25,8 @@
#include "generic.h"
RImage *fade (int argc, char **argv, int width, int height, int relief) {
RImage *fade(int argc, char **argv, int width, int height, int relief)
{
int from[3] = { 0x00, 0x00, 0x00 };
int to[3] = { 0xff, 0xff, 0xff };
@@ -38,29 +39,28 @@ RImage *fade (int argc, char **argv, int width, int height, int relief) {
int c, done, option_index = 0;
optind = 1;
for (done=0; !done; ) {
for (done = 0; !done;) {
static struct option long_options[] = {
{"from", 1, 0, 'f'},
{"to", 1, 0, 't'},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "f:t:",
long_options, &option_index);
c = getopt_long(argc, argv, "f:t:", long_options, &option_index);
if (c == -1) {
break;
}
switch (c) {
case 'f':
if (!parse_color (optarg, from)) {
error ("invalid color: %s\n", optarg);
if (!parse_color(optarg, from)) {
error("invalid color: %s\n", optarg);
return 0;
}
break;
case 't':
if (!parse_color (optarg, to)) {
error ("invalid color: %s\n", optarg);
if (!parse_color(optarg, to)) {
error("invalid color: %s\n", optarg);
return 0;
}
break;
@@ -73,35 +73,35 @@ RImage *fade (int argc, char **argv, int width, int height, int relief) {
argc -= optind;
argv += optind;
if (!start_image ("fade", argc, 0, 1, width, height, &image)) {
return (RImage *)0;
if (!start_image("fade", argc, 0, 1, width, height, &image)) {
return (RImage *) 0;
}
this = (int *) malloc (width * sizeof (int));
last = (int *) malloc (width * sizeof (int));
this = (int *)malloc(width * sizeof(int));
last = (int *)malloc(width * sizeof(int));
if (!this || !last) {
RReleaseImage (image);
free (this);
free (last);
return (RImage *)0;
RReleaseImage(image);
free(this);
free(last);
return (RImage *) 0;
}
for (i=0; i<width; i++) {
for (i = 0; i < width; i++) {
this[i] = 255;
}
factor = pow (0.2, 1.0 / height);
factor = pow(0.2, 1.0 / height);
delta = (factor < 0.5) ? 2.0 * factor : 2.0 * (1.0 - factor);
srand (time (0));
srand(time(0));
cptr = image->data;
for (j=0; j<height; j++) {
memcpy (last, this, width * sizeof (int));
for (i=0; i<width; i++) {
for (j = 0; j < height; j++) {
memcpy(last, this, width * sizeof(int));
for (i = 0; i < width; i++) {
int output[3];
int k = i + random_int (3) - 1;
double f = factor + random_double (delta) - delta/2.0;
int k = i + random_int(3) - 1;
double f = factor + random_double(delta) - delta / 2.0;
if (k < 0) {
k = 0;
@@ -110,19 +110,18 @@ RImage *fade (int argc, char **argv, int width, int height, int relief) {
k = width - 1;
}
this[i] = (int) (f * last[k]);
interpolate_color (output, from, to, this[i]);
this[i] = (int)(f * last[k]);
interpolate_color(output, from, to, this[i]);
*cptr++ = output[0];
*cptr++ = output[1];
*cptr++ = output[2];
if (RRGBAFormat==image->format)
if (RRGBAFormat == image->format)
cptr++;
}
}
free (this);
free (last);
free(this);
free(last);
return image;
}

View File

@@ -39,7 +39,8 @@
static Display *dpy = 0;
static Colormap cmap;
void initWindowMaker (Display *d, Colormap c) {
void initWindowMaker(Display * d, Colormap c)
{
if (!d) {
return;
}
@@ -47,17 +48,19 @@ void initWindowMaker (Display *d, Colormap c) {
cmap = c;
}
void error (const char *format, ...) {
void error(const char *format, ...)
{
va_list args;
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
int parse_color (const char *string, int *result) {
int parse_color(const char *string, int *result)
{
XColor color;
if (!XParseColor (dpy, cmap, string, &color)) {
if (!XParseColor(dpy, cmap, string, &color)) {
return 0;
}
result[0] = color.red >> 8;
@@ -67,50 +70,52 @@ int parse_color (const char *string, int *result) {
return 1;
}
int parse_xcolor (const char *string, XColor *xcolor) {
if (!XParseColor (dpy, cmap, string, xcolor)) {
return 0;
int parse_xcolor(const char *string, XColor * xcolor)
{
if (!XParseColor(dpy, cmap, string, xcolor)) {
return 0;
}
if (!XAllocColor(dpy, cmap, xcolor)) {
return 0;
}
if (!XAllocColor (dpy, cmap, xcolor)) {
return 0;
}
return 1;
}
void interpolate_color (int *t, const int *s0, const int *s1, int mix) {
void interpolate_color(int *t, const int *s0, const int *s1, int mix)
{
t[0] = (mix * s0[0] + (255 - mix) * s1[0]) >> 8;
t[1] = (mix * s0[1] + (255 - mix) * s1[1]) >> 8;
t[2] = (mix * s0[2] + (255 - mix) * s1[2]) >> 8;
}
int random_int (int range) {
int random_int(int range)
{
return rand() / (RAND_MAX / range + 1);
}
double random_double (double range) {
double random_double(double range)
{
return ((double)rand()) / (((double)RAND_MAX) / range);
}
int start_image (const char *name,
int argc, int argc_min, int argc_max,
int width, int height, RImage **image) {
int start_image(const char *name, int argc, int argc_min, int argc_max, int width, int height, RImage ** image)
{
if (!dpy) {
error ("%s: library not initialized\n", name);
error("%s: library not initialized\n", name);
return 0;
}
if ((argc < argc_min) || (argc >= argc_max)) {
error ("%s: invalid number of parameters: \n", name, argc);
error("%s: invalid number of parameters: \n", name, argc);
return 0;
}
*image = RCreateImage (width, height, 0);
*image = RCreateImage(width, height, 0);
if (!*image) {
error ("%s: can't create image\n", name);
error("%s: can't create image\n", name);
return 0;
}
return 1;
}

View File

@@ -46,14 +46,13 @@
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
/* Don't include stdlib.h for non-GNU C libraries because some of them
contain conflicting prototypes for getopt. */
#include <stdlib.h>
#endif /* GNU C library. */
#endif /* GNU C library. */
/* This version of `getopt' appears to the caller like standard Unix `getopt'
but it behaves differently for the user, since it allows the user
@@ -143,9 +142,8 @@ int optopt = '?';
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return EOF with `optind' != ARGC. */
static enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
static enum {
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} ordering;
/* Value of POSIXLY_CORRECT environment variable. */
@@ -163,20 +161,18 @@ static char *posixly_correct;
/* Avoid depending on library functions or files
whose names are inconsistent. */
char *getenv ();
char *getenv();
static char *
my_index (str, chr)
const char *str;
int chr;
static char *my_index(str, chr)
const char *str;
int chr;
{
while (*str)
{
if (*str == chr)
return (char *) str;
str++;
}
return 0;
while (*str) {
if (*str == chr)
return (char *)str;
str++;
}
return 0;
}
/* If using GCC, we can safely declare strlen this way.
@@ -187,11 +183,11 @@ my_index (str, chr)
#ifndef __STDC__
/* gcc with -traditional declares the built-in strlen to return int,
and has done so at least since version 2.4.5. -- rms. */
extern int strlen (const char *);
#endif /* not __STDC__ */
#endif /* __GNUC__ */
extern int strlen(const char *);
#endif /* not __STDC__ */
#endif /* __GNUC__ */
#endif /* not __GNU_LIBRARY__ */
#endif /* not __GNU_LIBRARY__ */
/* Handle permutation of arguments. */
@@ -211,96 +207,84 @@ static int last_nonopt;
`first_nonopt' and `last_nonopt' are relocated so that they describe
the new indices of the non-options in ARGV after they are moved. */
static void
exchange (argv)
char **argv;
static void exchange(argv)
char **argv;
{
int bottom = first_nonopt;
int middle = last_nonopt;
int top = optind;
char *tem;
int bottom = first_nonopt;
int middle = last_nonopt;
int top = optind;
char *tem;
/* Exchange the shorter segment with the far end of the longer segment.
That puts the shorter segment into the right place.
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
/* Exchange the shorter segment with the far end of the longer segment.
That puts the shorter segment into the right place.
It leaves the longer segment in the right place overall,
but it consists of two parts that need to be swapped next. */
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
{
/* Bottom segment is the short one. */
int len = middle - bottom;
register int i;
while (top > middle && middle > bottom) {
if (top - middle > middle - bottom) {
/* Bottom segment is the short one. */
int len = middle - bottom;
register int i;
/* Swap it with the top part of the top segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
/* Swap it with the top part of the top segment. */
for (i = 0; i < len; i++) {
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
}
/* Exclude the moved bottom segment from further swapping. */
top -= len;
} else {
/* Top segment is the short one. */
int len = top - middle;
register int i;
/* Swap it with the bottom part of the bottom segment. */
for (i = 0; i < len; i++) {
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
}
}
else
{
/* Top segment is the short one. */
int len = top - middle;
register int i;
/* Swap it with the bottom part of the bottom segment. */
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
}
/* Exclude the moved top segment from further swapping. */
bottom += len;
}
}
/* Update records for the slots the non-options now occupy. */
/* Update records for the slots the non-options now occupy. */
first_nonopt += (optind - last_nonopt);
last_nonopt = optind;
first_nonopt += (optind - last_nonopt);
last_nonopt = optind;
}
/* Initialize the internal data when the first call is made. */
static const char *
_getopt_initialize (optstring)
const char *optstring;
static const char *_getopt_initialize(optstring)
const char *optstring;
{
/* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
/* Start processing options with ARGV-element 1 (since ARGV-element 0
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
first_nonopt = last_nonopt = optind = 1;
first_nonopt = last_nonopt = optind = 1;
nextchar = NULL;
nextchar = NULL;
posixly_correct = getenv ("POSIXLY_CORRECT");
posixly_correct = getenv("POSIXLY_CORRECT");
/* Determine how to handle the ordering of options and nonoptions. */
/* Determine how to handle the ordering of options and nonoptions. */
if (optstring[0] == '-')
{
ordering = RETURN_IN_ORDER;
++optstring;
}
else if (optstring[0] == '+')
{
ordering = REQUIRE_ORDER;
++optstring;
}
else if (posixly_correct != NULL)
ordering = REQUIRE_ORDER;
else
ordering = PERMUTE;
if (optstring[0] == '-') {
ordering = RETURN_IN_ORDER;
++optstring;
} else if (optstring[0] == '+') {
ordering = REQUIRE_ORDER;
++optstring;
} else if (posixly_correct != NULL)
ordering = REQUIRE_ORDER;
else
ordering = PERMUTE;
return optstring;
return optstring;
}
/* Scan elements of ARGV (whose length is ARGC) for option characters
@@ -359,386 +343,337 @@ _getopt_initialize (optstring)
If LONG_ONLY is nonzero, '-' as well as '--' can introduce
long-named options. */
int
_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
int argc;
char *const *argv;
const char *optstring;
const struct option *longopts;
int *longind;
int long_only;
int _getopt_internal(argc, argv, optstring, longopts, longind, long_only)
int argc;
char *const *argv;
const char *optstring;
const struct option *longopts;
int *longind;
int long_only;
{
optarg = NULL;
optarg = NULL;
if (optind == 0)
optstring = _getopt_initialize (optstring);
if (optind == 0)
optstring = _getopt_initialize(optstring);
if (nextchar == NULL || *nextchar == '\0')
{
/* Advance to the next ARGV-element. */
if (nextchar == NULL || *nextchar == '\0') {
/* Advance to the next ARGV-element. */
if (ordering == PERMUTE)
{
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
if (ordering == PERMUTE) {
/* If we have just processed some options following some non-options,
exchange them so that the options come first. */
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange ((char **) argv);
else if (last_nonopt != optind)
first_nonopt = optind;
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange((char **)argv);
else if (last_nonopt != optind)
first_nonopt = optind;
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
/* Skip any additional non-options
and extend the range of non-options previously skipped. */
while (optind < argc
&& (argv[optind][0] != '-' || argv[optind][1] == '\0'))
optind++;
last_nonopt = optind;
}
/* The special ARGV-element `--' means premature end of options.
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
if (optind != argc && !strcmp (argv[optind], "--"))
{
optind++;
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange ((char **) argv);
else if (first_nonopt == last_nonopt)
first_nonopt = optind;
last_nonopt = argc;
optind = argc;
}
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
if (optind == argc)
{
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
optind = first_nonopt;
return EOF;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
{
if (ordering == REQUIRE_ORDER)
return EOF;
optarg = argv[optind++];
return 1;
}
/* We have found another option-ARGV-element.
Skip the initial punctuation. */
nextchar = (argv[optind] + 1
+ (longopts != NULL && argv[optind][1] == '-'));
}
/* Decode the current option-ARGV-element. */
/* Check whether the ARGV-element is a long option.
If long_only and the ARGV-element has the form "-f", where f is
a valid short option, don't consider it an abbreviated form of
a long option that starts with f. Otherwise there would be no
way to give the -f short option.
On the other hand, if there's a long option "fubar" and
the ARGV-element is "-fu", do consider that an abbreviation of
the long option, just like "--fu", and not "-f" with arg "u".
This distinction seems to be the most useful approach. */
if (longopts != NULL
&& (argv[optind][1] == '-'
|| (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
{
char *nameend;
const struct option *p;
const struct option *pfound = NULL;
int exact = 0;
int ambig = 0;
int indfound;
int option_index;
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
/* Do nothing. */ ;
/* Test all long options for either exact match
or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp (p->name, nextchar, nameend - nextchar))
{
if (nameend - nextchar == (int) strlen (p->name))
{
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
}
else if (pfound == NULL)
{
/* First nonexact match found. */
pfound = p;
indfound = option_index;
}
else
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact)
{
if (opterr)
fprintf (stderr, "%s: option `%s' is ambiguous\n",
argv[0], argv[optind]);
nextchar += strlen (nextchar);
optind++;
return '?';
}
if (pfound != NULL)
{
option_index = indfound;
optind++;
if (*nameend)
{
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
optarg = nameend + 1;
else
{
if (opterr)
{
if (argv[optind - 1][1] == '-')
/* --option */
fprintf (stderr,
"%s: option `--%s' doesn't allow an argument\n",
argv[0], pfound->name);
else
/* +option or -option */
fprintf (stderr,
"%s: option `%c%s' doesn't allow an argument\n",
argv[0], argv[optind - 1][0], pfound->name);
}
nextchar += strlen (nextchar);
return '?';
while (optind < argc && (argv[optind][0] != '-' || argv[optind][1] == '\0'))
optind++;
last_nonopt = optind;
}
}
else if (pfound->has_arg == 1)
{
if (optind < argc)
optarg = argv[optind++];
else
{
if (opterr)
fprintf (stderr, "%s: option `%s' requires an argument\n",
argv[0], argv[optind - 1]);
nextchar += strlen (nextchar);
return optstring[0] == ':' ? ':' : '?';
/* The special ARGV-element `--' means premature end of options.
Skip it like a null option,
then exchange with previous non-options as if it were an option,
then skip everything else like a non-option. */
if (optind != argc && !strcmp(argv[optind], "--")) {
optind++;
if (first_nonopt != last_nonopt && last_nonopt != optind)
exchange((char **)argv);
else if (first_nonopt == last_nonopt)
first_nonopt = optind;
last_nonopt = argc;
optind = argc;
}
}
nextchar += strlen (nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag)
{
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
/* If we have done all the ARGV-elements, stop the scan
and back over any non-options that we skipped and permuted. */
if (optind == argc) {
/* Set the next-arg-index to point at the non-options
that we previously skipped, so the caller will digest them. */
if (first_nonopt != last_nonopt)
optind = first_nonopt;
return EOF;
}
/* If we have come to a non-option and did not permute it,
either stop the scan or describe it to the caller and pass it by. */
if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) {
if (ordering == REQUIRE_ORDER)
return EOF;
optarg = argv[optind++];
return 1;
}
/* We have found another option-ARGV-element.
Skip the initial punctuation. */
nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-'));
}
/* Can't find it as a long option. If this is not getopt_long_only,
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-'
|| my_index (optstring, *nextchar) == NULL)
/* Decode the current option-ARGV-element. */
/* Check whether the ARGV-element is a long option.
If long_only and the ARGV-element has the form "-f", where f is
a valid short option, don't consider it an abbreviated form of
a long option that starts with f. Otherwise there would be no
way to give the -f short option.
On the other hand, if there's a long option "fubar" and
the ARGV-element is "-fu", do consider that an abbreviation of
the long option, just like "--fu", and not "-f" with arg "u".
This distinction seems to be the most useful approach. */
if (longopts != NULL
&& (argv[optind][1] == '-'
|| (long_only && (argv[optind][2] || !my_index(optstring, argv[optind][1]))))) {
char *nameend;
const struct option *p;
const struct option *pfound = NULL;
int exact = 0;
int ambig = 0;
int indfound;
int option_index;
for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
/* Do nothing. */ ;
/* Test all long options for either exact match
or abbreviated matches. */
for (p = longopts, option_index = 0; p->name; p++, option_index++)
if (!strncmp(p->name, nextchar, nameend - nextchar)) {
if (nameend - nextchar == (int)strlen(p->name)) {
/* Exact match found. */
pfound = p;
indfound = option_index;
exact = 1;
break;
} else if (pfound == NULL) {
/* First nonexact match found. */
pfound = p;
indfound = option_index;
} else
/* Second or later nonexact match found. */
ambig = 1;
}
if (ambig && !exact) {
if (opterr)
fprintf(stderr, "%s: option `%s' is ambiguous\n", argv[0], argv[optind]);
nextchar += strlen(nextchar);
optind++;
return '?';
}
if (pfound != NULL) {
option_index = indfound;
optind++;
if (*nameend) {
/* Don't test has_arg with >, because some C compilers don't
allow it to be used on enums. */
if (pfound->has_arg)
optarg = nameend + 1;
else {
if (opterr) {
if (argv[optind - 1][1] == '-')
/* --option */
fprintf(stderr,
"%s: option `--%s' doesn't allow an argument\n",
argv[0], pfound->name);
else
/* +option or -option */
fprintf(stderr,
"%s: option `%c%s' doesn't allow an argument\n",
argv[0], argv[optind - 1][0], pfound->name);
}
nextchar += strlen(nextchar);
return '?';
}
} else if (pfound->has_arg == 1) {
if (optind < argc)
optarg = argv[optind++];
else {
if (opterr)
fprintf(stderr, "%s: option `%s' requires an argument\n",
argv[0], argv[optind - 1]);
nextchar += strlen(nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
nextchar += strlen(nextchar);
if (longind != NULL)
*longind = option_index;
if (pfound->flag) {
*(pfound->flag) = pfound->val;
return 0;
}
return pfound->val;
}
/* Can't find it as a long option. If this is not getopt_long_only,
or the option starts with '--' or is not a valid short
option, then it's an error.
Otherwise interpret it as a short option. */
if (!long_only || argv[optind][1] == '-' || my_index(optstring, *nextchar) == NULL) {
if (opterr) {
if (argv[optind][1] == '-')
/* --option */
fprintf(stderr, "%s: unrecognized option `--%s'\n", argv[0], nextchar);
else
/* +option or -option */
fprintf(stderr, "%s: unrecognized option `%c%s'\n",
argv[0], argv[optind][0], nextchar);
}
nextchar = (char *)"";
optind++;
return '?';
}
}
/* Look at and handle the next short option-character. */
{
if (opterr)
{
if (argv[optind][1] == '-')
/* --option */
fprintf (stderr, "%s: unrecognized option `--%s'\n",
argv[0], nextchar);
else
/* +option or -option */
fprintf (stderr, "%s: unrecognized option `%c%s'\n",
argv[0], argv[optind][0], nextchar);
}
nextchar = (char *) "";
optind++;
return '?';
char c = *nextchar++;
char *temp = my_index(optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
++optind;
if (temp == NULL || c == ':') {
if (opterr) {
if (posixly_correct)
/* 1003.2 specifies the format of this message. */
fprintf(stderr, "%s: illegal option -- %c\n", argv[0], c);
else
fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
}
optopt = c;
return '?';
}
if (temp[1] == ':') {
if (temp[2] == ':') {
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0') {
optarg = nextchar;
optind++;
} else
optarg = NULL;
nextchar = NULL;
} else {
/* This is an option that requires an argument. */
if (*nextchar != '\0') {
optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
optind++;
} else if (optind == argc) {
if (opterr) {
/* 1003.2 specifies the format of this message. */
fprintf(stderr, "%s: option requires an argument -- %c\n",
argv[0], c);
}
optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
} else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
optarg = argv[optind++];
nextchar = NULL;
}
}
return c;
}
}
/* Look at and handle the next short option-character. */
{
char c = *nextchar++;
char *temp = my_index (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*nextchar == '\0')
++optind;
if (temp == NULL || c == ':')
{
if (opterr)
{
if (posixly_correct)
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
else
fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c);
}
optopt = c;
return '?';
}
if (temp[1] == ':')
{
if (temp[2] == ':')
{
/* This is an option that accepts an argument optionally. */
if (*nextchar != '\0')
{
optarg = nextchar;
optind++;
}
else
optarg = NULL;
nextchar = NULL;
}
else
{
/* This is an option that requires an argument. */
if (*nextchar != '\0')
{
optarg = nextchar;
/* If we end this ARGV-element by taking the rest as an arg,
we must advance to the next element now. */
optind++;
}
else if (optind == argc)
{
if (opterr)
{
/* 1003.2 specifies the format of this message. */
fprintf (stderr, "%s: option requires an argument -- %c\n",
argv[0], c);
}
optopt = c;
if (optstring[0] == ':')
c = ':';
else
c = '?';
}
else
/* We already incremented `optind' once;
increment it again when taking next ARGV-elt as argument. */
optarg = argv[optind++];
nextchar = NULL;
}
}
return c;
}
}
int
getopt (argc, argv, optstring)
int argc;
char *const *argv;
const char *optstring;
int getopt(argc, argv, optstring)
int argc;
char *const *argv;
const char *optstring;
{
return _getopt_internal (argc, argv, optstring,
(const struct option *) 0,
(int *) 0,
0);
return _getopt_internal(argc, argv, optstring, (const struct option *)0, (int *)0, 0);
}
#endif /* _LIBC or not __GNU_LIBRARY__. */
#endif /* _LIBC or not __GNU_LIBRARY__. */
#ifdef TEST
/* Compile with -DTEST to make an executable for use in testing
the above definition of `getopt'. */
int
main (argc, argv)
int argc;
char **argv;
int main(argc, argv)
int argc;
char **argv;
{
int c;
int digit_optind = 0;
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
while (1) {
int this_option_optind = optind ? optind : 1;
c = getopt (argc, argv, "abc:d:0123456789");
if (c == EOF)
break;
c = getopt(argc, argv, "abc:d:0123456789");
if (c == EOF)
break;
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
switch (c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'a':
printf("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'b':
printf("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case 'c':
printf("option c with value `%s'\n", optarg);
break;
case '?':
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
default:
printf("?? getopt returned character code 0%o ??\n", c);
}
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
if (optind < argc) {
printf("non-option ARGV-elements: ");
while (optind < argc)
printf("%s ", argv[optind++]);
printf("\n");
}
exit (0);
exit(0);
}
#endif /* TEST */
#endif /* TEST */

View File

@@ -12,7 +12,6 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. */
#include "getopt.h"
#ifndef __STDC__
@@ -35,28 +34,26 @@
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#include <stdlib.h>
#else
char *getenv ();
char *getenv();
#endif
#ifndef NULL
#define NULL 0
#endif
int
getopt_long (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
int getopt_long(argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
return _getopt_internal(argc, argv, options, long_options, opt_index, 0);
}
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
@@ -64,110 +61,102 @@ getopt_long (argc, argv, options, long_options, opt_index)
but does match a short option, it is parsed as a short option
instead. */
int
getopt_long_only (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
int getopt_long_only(argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
return _getopt_internal(argc, argv, options, long_options, opt_index, 1);
}
#endif /* _LIBC or not __GNU_LIBRARY__. */
#endif /* _LIBC or not __GNU_LIBRARY__. */
#ifdef TEST
#include <stdio.h>
int
main (argc, argv)
int argc;
char **argv;
int main(argc, argv)
int argc;
char **argv;
{
int c;
int digit_optind = 0;
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] =
{
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
};
while (1) {
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] = {
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
if (c == EOF)
break;
c = getopt_long(argc, argv, "abc:d:0123456789", long_options, &option_index);
if (c == EOF)
break;
switch (c)
{
case 0:
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
switch (c) {
case 0:
printf("option %s", long_options[option_index].name);
if (optarg)
printf(" with arg %s", optarg);
printf("\n");
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'a':
printf("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'b':
printf("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case 'c':
printf("option c with value `%s'\n", optarg);
break;
case 'd':
printf ("option d with value `%s'\n", optarg);
break;
case 'd':
printf("option d with value `%s'\n", optarg);
break;
case '?':
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
default:
printf("?? getopt returned character code 0%o ??\n", c);
}
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
if (optind < argc) {
printf("non-option ARGV-elements: ");
while (optind < argc)
printf("%s ", argv[optind++]);
printf("\n");
}
exit (0);
exit(0);
}
#endif /* TEST */
#endif /* TEST */

View File

@@ -36,9 +36,10 @@
#include <time.h>
#include "generic.h"
RImage *waves (int argc, char **argv, int width, int height, int relief) {
RImage *waves(int argc, char **argv, int width, int height, int relief)
{
int i, j, k, done, sine [256];
int i, j, k, done, sine[256];
int from[3] = { 0x00, 0x00, 0x00 };
int to[3] = { 0xff, 0xff, 0xff };
int layers, range, dx[1000], dy[1000];
@@ -49,29 +50,28 @@ RImage *waves (int argc, char **argv, int width, int height, int relief) {
int c;
optind = 1;
for (done=0; !done; ) {
for (done = 0; !done;) {
static struct option long_options[] = {
{"from", 1, 0, 'f'},
{"to", 1, 0, 't'},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "f:t:",
long_options, &option_index);
c = getopt_long(argc, argv, "f:t:", long_options, &option_index);
if (c == -1) {
break;
}
switch (c) {
case 'f':
if (!parse_color (optarg, from)) {
error ("invalid color: %s\n", optarg);
if (!parse_color(optarg, from)) {
error("invalid color: %s\n", optarg);
return 0;
}
break;
case 't':
if (!parse_color (optarg, to)) {
error ("invalid color: %s\n", optarg);
if (!parse_color(optarg, to)) {
error("invalid color: %s\n", optarg);
return 0;
}
break;
@@ -84,12 +84,12 @@ RImage *waves (int argc, char **argv, int width, int height, int relief) {
argc -= optind;
argv += optind;
if (!start_image ("waves", argc, 2, 3, width, height, &image)) {
return (RImage *)0;
if (!start_image("waves", argc, 2, 3, width, height, &image)) {
return (RImage *) 0;
}
layers = atoi (argv[0]);
range = atoi (argv[1]);
layers = atoi(argv[0]);
range = atoi(argv[1]);
if (layers <= 0) {
layers = 1;
@@ -102,33 +102,32 @@ RImage *waves (int argc, char **argv, int width, int height, int relief) {
range = 1;
}
for (i=0; i<256; i++) {
sine[i] = (int) (127.0 * sin (2.0 * M_PI * i / 256)) + 128;
for (i = 0; i < 256; i++) {
sine[i] = (int)(127.0 * sin(2.0 * M_PI * i / 256)) + 128;
}
srand (time (0));
srand(time(0));
for (i=0; i<layers; i++) {
dx[i] = random_int (range) - range / 2;
dy[i] = random_int (range) - range / 2;
for (i = 0; i < layers; i++) {
dx[i] = random_int(range) - range / 2;
dy[i] = random_int(range) - range / 2;
}
cptr = image->data;
for (i=0; i<height; i++) {
for (j=0; j<width; j++) {
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int output[3], value = 0;
for (k=0; k<layers; k++) {
value += sine[(j*dx[k]+i*dy[k]) & 255];
for (k = 0; k < layers; k++) {
value += sine[(j * dx[k] + i * dy[k]) & 255];
}
interpolate_color (output, from, to, value / layers);
interpolate_color(output, from, to, value / layers);
*cptr++ = output[0];
*cptr++ = output[1];
*cptr++ = output[2];
if ( RRGBAFormat==image->format )
if (RRGBAFormat == image->format)
cptr++;
}
}
return image;
}