Coverage Report

Created: 2023-01-19 06:30

/src/wpantund/src/util/args.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *
3
 * Copyright (c) 2016 Nest Labs, Inc.
4
 * All rights reserved.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 *
18
 */
19
20
#ifndef UTIL_ARGS_HEADER_INCLUDED
21
#define UTIL_ARGS_HEADER_INCLUDED 1
22
23
#include <stdio.h>
24
#include <string.h>
25
#include <stdbool.h>
26
27
typedef struct {
28
  char shortarg;
29
  const char* longarg;
30
  const char* param;
31
  const char* desc;
32
} arg_list_item_t;
33
34
static inline void
35
print_arg_list_help(
36
    const arg_list_item_t arg_list[],
37
    const char*                             command_name,
38
    const char*                             syntax
39
    )
40
0
{
41
0
  int i;
42
43
0
  printf("Syntax:\n");
44
0
  printf("   %s %s\n", command_name, syntax);
45
0
  printf("Options:\n");
46
0
  for (i = 0; arg_list[i].desc; ++i) {
47
0
    if (arg_list[i].shortarg)
48
0
      printf("   -%c", arg_list[i].shortarg);
49
0
    else
50
0
      printf("     ");
51
52
0
    if (arg_list[i].longarg) {
53
0
      if (arg_list[i].shortarg)
54
0
        printf("/");
55
0
      else
56
0
        printf(" ");
57
58
0
      printf("--%s%s",
59
0
             arg_list[i].longarg,
60
0
             &"                    "[strlen(arg_list[i].longarg)]);
61
0
    } else {
62
0
      printf("                       ");
63
0
    }
64
65
0
    if (arg_list[i].param != NULL) {
66
0
      printf(" %s [%s]\n", arg_list[i].desc, arg_list[i].param);
67
0
    } else {
68
0
      printf(" %s\n", arg_list[i].desc);
69
0
    }
70
71
0
  }
72
0
}
73
74
#endif // UTIL_ARGS_HEADER_INCLUDED