openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

main.c (1750B)


      1 /* 
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        main.c
      8  * Purpose:     API mode test driver
      9  */
     10 
     11 #include <stdio.h>
     12 #include <stdlib.h>
     13 #include <string.h>
     14 #include <unistd.h>
     15 #include "api_mode_yy.h"
     16 #include "api_grammar.tab.h"
     17 
     18 #if defined(APIMODE_INCLUDE_MAIN)
     19 
     20 static void
     21 usage(void)
     22 {
     23     fprintf(stderr, "apimode [-h] [-d] [-v]\n");
     24     fprintf(stderr, "    -h     Print this message\n");
     25     fprintf(stderr, "    -d     Grammar debug\n");
     26     fprintf(stderr, "    -v     Verbose messages\n");
     27 }
     28 
     29 #define BUF_SIZE 128
     30 static char buf[BUF_SIZE];
     31 
     32 static int
     33 parse_callback(api_mode_arg_t *arg, void *user_data)
     34 {
     35     (void)user_data;
     36     api_mode_show(0,arg);
     37 
     38     return 0;
     39 }
     40 
     41 int
     42 main(int argc, char *argv[])
     43 {
     44     int c;
     45     int flags = 0;
     46 
     47     while ((c = getopt(argc, argv, "sdhv")) != EOF) {
     48         switch (c) {
     49         case 's':
     50             flags |= SCAN_DEBUG;
     51             break;
     52         case 'd':
     53             flags |= PARSE_DEBUG;
     54             break;
     55         case 'v':
     56             flags |= PARSE_VERBOSE;
     57             break;
     58         case 'h':
     59         default:
     60             usage();
     61             exit(0);
     62             break;
     63         }
     64     }
     65 
     66     for (;;) {
     67         if (flags & PARSE_VERBOSE) {
     68             puts("Reading...\n");
     69         }
     70         memset(buf, 0, sizeof(buf));
     71         if ((fgets(buf, sizeof(buf), stdin)) == NULL) {
     72             break;
     73         }
     74         if (flags & PARSE_VERBOSE) {
     75             puts("Parsing...\n");
     76         }
     77         api_mode_parse_string(buf, flags, parse_callback, NULL);
     78     }
     79     return 0;
     80 }
     81 
     82 #endif /* APIMODE_INCLUDE_MAIN */