Blame tests/parse_flags.c
|
Packit Service |
def718 |
#include "config.h"
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#include <stdio.h>
|
|
Packit Service |
def718 |
#include <string.h>
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#include "json.h"
|
|
Packit Service |
def718 |
#include "parse_flags.h"
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#if !defined(HAVE_STRCASECMP) && defined(_MSC_VER)
|
|
Packit Service |
def718 |
# define strcasecmp _stricmp
|
|
Packit Service |
def718 |
#elif !defined(HAVE_STRCASECMP)
|
|
Packit Service |
def718 |
# error You do not have strcasecmp on your system.
|
|
Packit Service |
def718 |
#endif /* HAVE_STRNCASECMP */
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
static struct {
|
|
Packit Service |
def718 |
const char *arg;
|
|
Packit Service |
def718 |
int flag;
|
|
Packit Service |
def718 |
} format_args[] = {
|
|
Packit Service |
def718 |
{ "plain", JSON_C_TO_STRING_PLAIN },
|
|
Packit Service |
def718 |
{ "spaced", JSON_C_TO_STRING_SPACED },
|
|
Packit Service |
def718 |
{ "pretty", JSON_C_TO_STRING_PRETTY },
|
|
Packit Service |
def718 |
};
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
#ifndef NELEM
|
|
Packit Service |
def718 |
#define NELEM(x) (sizeof(x) / sizeof(x[0]))
|
|
Packit Service |
def718 |
#endif
|
|
Packit Service |
def718 |
|
|
Packit Service |
def718 |
int parse_flags(int argc, char **argv)
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
int arg_idx;
|
|
Packit Service |
def718 |
int sflags = 0;
|
|
Packit Service |
def718 |
for (arg_idx = 1; arg_idx < argc ; arg_idx++)
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
int jj;
|
|
Packit Service |
def718 |
for (jj = 0; jj < (int)NELEM(format_args); jj++)
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
if (strcasecmp(argv[arg_idx], format_args[jj].arg) == 0)
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
sflags |= format_args[jj].flag;
|
|
Packit Service |
def718 |
break;
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
if (jj == NELEM(format_args))
|
|
Packit Service |
def718 |
{
|
|
Packit Service |
def718 |
printf("Unknown arg: %s\n", argv[arg_idx]);
|
|
Packit Service |
def718 |
exit(1);
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
}
|
|
Packit Service |
def718 |
return sflags;
|
|
Packit Service |
def718 |
}
|