src/tools/bpluginfo.c
void parse_args(progdata * pdata, int argc, char *argv[])
{

   int i;
   char *dirtmp;
   char *progdir;
   int api;
   int s;

   if (argc < 2) {
      /* TODO - add a real help screen */
      printf("\nNot enough parameters!\n");
      print_help(argc, argv);
      exit(1);
   }

   if (argc > 5) {
      /* TODO - add a real help screen */
      printf("\nToo many parameters!\n");
      print_help(argc, argv);
      exit(1);
   }

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-h") == 0) {
         /* help screen */
         print_help(argc, argv);
         exit(0);
      }
      if (strcmp(argv[i], "-v") == 0) {
          /* verbose option */
          pdata->verbose = 1;
          continue;
      }
      if (strcmp(argv[i], "-f") == 0) {
         /* functions list */
         pdata->listfunc = 1;
         continue;
      }
      if (strcmp(argv[i], "-i") == 0) {
         /* header list */
         pdata->listinfo = 1;
         continue;
      }
      if (strcmp(argv[i], "-a") == 0) {
         /* bacula api version */
         if (i < argc - 1) {
            s = sscanf(argv[i + 1], "%d", &api);
            if (s == 1) {
               pdata->bapiversion = api;
               i++;
               continue;
            }
         }
         printf("\nAPI version number required!\n");
         print_help(argc, argv);
         exit(1);
      }
      if (!pdata->pluginfile) {
          if (argv[i][0] != '/') {
             dirtmp = MALLOC(PATH_MAX);
             ASSERT_MEMORY(dirtmp);
             progdir = MALLOC(PATH_MAX);
             ASSERT_MEMORY(progdir);
             dirtmp = getcwd(dirtmp, PATH_MAX);

             strcat(dirtmp, "/");
             strcat(dirtmp, argv[i]);

             if (realpath(dirtmp, progdir) == NULL) {
                /* error in resolving path */
                FREE(progdir);
                progdir = bstrdup(argv[i]);
             }
             pdata->pluginfile = bstrdup(progdir);
             FREE(dirtmp);
             FREE(progdir);
          } else {
             pdata->pluginfile = bstrdup(argv[i]);
          }
    continue;
      }
   }
}
/*
 * parse execution arguments and fills required pdata structure fields
 *
 * input:
 *    pdata - pointer to program data structure
 *    argc, argv - execution envinroment variables
 * output:
 *    pdata - required structure fields
 *
 * supported options:
 * -v    verbose flag
 * -i    list plugin header info only (default)
 * -f    list implemented functions only
 * -a    bacula api version (default 1)
 * -h    help screen
 */
parse execution arguments and fills required pdata structure fields
input:
pdata - pointer to program data structure
argc, argv - execution envinroment variables
output:
pdata - required structure fields


parse execution arguments and fills required pdata structure fields input : pdata - pointer to program data structure argc argv - execution envinroment variables output : pdata - required structure fields
void parse_args(progdata * pdata, int argc, char *argv[])
{
   int i;
   char *dirtmp;
   char *progdir;
   int api;
   int s;
   if (argc < 2) {
      printf("\nNot enough parameters!\n");
      print_help(argc, argv);
      exit(1);
   }
   if (argc > 5) {
      printf("\nToo many parameters!\n");
      print_help(argc, argv);
      exit(1);
   }
   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-h") == 0) {
         print_help(argc, argv);
         exit(0);
      }
      if (strcmp(argv[i], "-v") == 0) {
          pdata->verbose = 1;
          continue;
      }
      if (strcmp(argv[i], "-f") == 0) {
         pdata->listfunc = 1;
         continue;
      }
      if (strcmp(argv[i], "-i") == 0) {
         pdata->listinfo = 1;
         continue;
      }
      if (strcmp(argv[i], "-a") == 0) {
         if (i < argc - 1) {
            s = sscanf(argv[i + 1], "%d", &api);
            if (s == 1) {
               pdata->bapiversion = api;
               i++;
               continue;
            }
         }
         printf("\nAPI version number required!\n");
         print_help(argc, argv);
         exit(1);
      }
      if (!pdata->pluginfile) {
          if (argv[i][0] != '/') {
             dirtmp = MALLOC(PATH_MAX);
             ASSERT_MEMORY(dirtmp);
             progdir = MALLOC(PATH_MAX);
             ASSERT_MEMORY(progdir);
             dirtmp = getcwd(dirtmp, PATH_MAX);
             strcat(dirtmp, "/");
             strcat(dirtmp, argv[i]);
             if (realpath(dirtmp, progdir) == NULL) {
                FREE(progdir);
                progdir = bstrdup(argv[i]);
             }
             pdata->pluginfile = bstrdup(progdir);
             FREE(dirtmp);
             FREE(progdir);
          } else {
             pdata->pluginfile = bstrdup(argv[i]);
          }
    continue;
      }
   }
}
void parse_args ( progdata * pdata , int argc , char * argv [ ] ) { int i ; char * dirtmp ; char * progdir ; int api ; int s ; if ( argc < 2 ) { printf ( " \n \n " ) ; print_help ( argc , argv ) ; exit ( 1 ) ; } if ( argc > 5 ) { printf ( " \n \n " ) ; print_help ( argc , argv ) ; exit ( 1 ) ; } for ( i = 1 ; i < argc ; i ++ ) { if ( strcmp ( argv [ i ] , " " ) == 0 ) { print_help ( argc , argv ) ; exit ( 0 ) ; } if ( strcmp ( argv [ i ] , " " ) == 0 ) { pdata -> verbose = 1 ; continue ; } if ( strcmp ( argv [ i ] , " " ) == 0 ) { pdata -> listfunc = 1 ; continue ; } if ( strcmp ( argv [ i ] , " " ) == 0 ) { pdata -> listinfo = 1 ; continue ; } if ( strcmp ( argv [ i ] , " " ) == 0 ) { if ( i < argc - 1 ) { s = sscanf ( argv [ i + 1 ] , " " , & api ) ; if ( s == 1 ) { pdata -> bapiversion = api ; i ++ ; continue ; } } printf ( " \n \n " ) ; print_help ( argc , argv ) ; exit ( 1 ) ; } if ( ! pdata -> pluginfile ) { if ( argv [ i ] [ 0 ] != ' ' ) { dirtmp = MALLOC ( PATH_MAX ) ; ASSERT_MEMORY ( dirtmp ) ; progdir = MALLOC ( PATH_MAX ) ; ASSERT_MEMORY ( progdir ) ; dirtmp = getcwd ( dirtmp , PATH_MAX ) ; strcat ( dirtmp , " " ) ; strcat ( dirtmp , argv [ i ] ) ; if ( realpath ( dirtmp , progdir ) == NULL ) { FREE ( progdir ) ; progdir = bstrdup ( argv [ i ] ) ; } pdata -> pluginfile = bstrdup ( progdir ) ; FREE ( dirtmp ) ; FREE ( progdir ) ; } else { pdata -> pluginfile = bstrdup ( argv [ i ] ) ; } continue ; } } }
parse execution arguments and fills required pdata structure fields
 input:
    pdata - pointer to program data structure
    argc, argv - execution envinroment variables
 output:
    pdata - required structure fields
parse execution arguments and fills required pdata structure fields input : pdata - pointer to program data structure argc argv - execution envinroment variables output : pdata - required structure fields
/* TODO - add a real help screen */ /* TODO - add a real help screen */ /* help screen */ /* verbose option */ /* functions list */ /* header list */ /* bacula api version */ /* error in resolving path */