Re: [hackers] [farbfeld] arg.h: Refactor ARGF_() || Laslo Hunhold

From: Michael Forney <mforney_AT_mforney.org>
Date: Fri, 4 Aug 2017 08:37:14 -0700

On 8/4/17, git_AT_suckless.org <git_AT_suckless.org> wrote:
> commit 959b70ab5a7f7801f7047b9d513671cd95500488
> Author: Laslo Hunhold <dev_AT_frign.de>
> AuthorDate: Fri Aug 4 16:11:12 2017 +0200
> Commit: Laslo Hunhold <dev_AT_frign.de>
> CommitDate: Fri Aug 4 16:11:12 2017 +0200
>
> arg.h: Refactor ARGF_()
>
> diff --git a/arg.h b/arg.h
> index 81127a2..042f5c1 100644
> --- a/arg.h
> +++ b/arg.h
> _AT_@ -24,15 +24,15 @@ extern char *argv0;
> /* int main(int argc, char *argv[]) */
> #define ARGBEGIN for (argv0 = *argv, *argv ? (argc--, argv++) : ((void
> *)0); \
> *argv && (*argv)[0] == '-' && (*argv)[1]; argc--,
> argv++) { \
> - int i, argused;
> \
> + int _i, _argused;

You can't use identifiers that begin with '_', they are reserved for
the C implementation:

"All identifiers that begin with an underscore are always reserved for
use as identifiers with file scope in both the ordinary and tag name
spaces."

(from C99 section 7.1.3)

> \
> if ((*argv)[1] == '-' && !(*argv)[2]) {
> \
> argc--, argv++; \
> break; \
> }
> \
> - for (i = 1, argused = 0; (*argv)[i]; i++) {
> \
> - switch((*argv)[i])
> -#define ARGEND if (argused) { \
> - if ((*argv)[i + 1]) { \
> + for (_i = 1, _argused = 0; (*argv)[_i]; _i++) {
> \
> + switch((*argv)[_i])
> +#define ARGEND if (_argused) { \
> + if ((*argv)[_i + 1]) { \
> break; \
> } else { \
> argc--, argv++; \
> _AT_@ -41,13 +41,9 @@ extern char *argv0;
> } \
> }
> \
> }
> -#define ARGC() (*argv)[i]
> -#define ARGF_(x) ((!(*argv)[i + 1] && !*(argv + 1)) ? \
> - (x) : \
> - (argused = 1, ((*argv)[i + 1]) ? \
> - (&(*argv)[i + 1]) : \
> - (*(argv + 1)) \
> - ) \
> +#define ARGC() (*argv)[_i]
> +#define ARGF_(x) (((*argv)[_i + 1]) ? (_argused = 1, &((*argv)[_i + 1])) :
> \
> + (*(argv + 1)) ? (_argused = 1, *(argv + 1)) :
> (x) \
> )
> #define EARGF(x) ARGF_(((x), exit(1), (char *)0))
> #define ARGF() ARGF_((char *)0)
>
>
Received on Fri Aug 04 2017 - 17:37:14 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 04 2017 - 17:49:11 CEST