LCOV - code coverage report
Current view: top level - src - gensvm_cmdarg.c (source / functions) Hit Total Coverage
Test: coverage.all Lines: 14 14 100.0 %
Date: 2017-02-21 18:44:20 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file gensvm_cmdarg.c
       3             :  * @author G.J.J. van den Burg
       4             :  * @date 2016-05-01
       5             :  * @brief Functions for dealing with command line arguments
       6             :  *
       7             :  * @details
       8             :  * This file contains several utility functions for coordinating input and
       9             :  * output of data and model files.
      10             :  *
      11             :  * @copyright
      12             :  Copyright 2016, G.J.J. van den Burg.
      13             : 
      14             :  This file is part of GenSVM.
      15             : 
      16             :  GenSVM is free software: you can redistribute it and/or modify
      17             :  it under the terms of the GNU General Public License as published by
      18             :  the Free Software Foundation, either version 3 of the License, or
      19             :  (at your option) any later version.
      20             : 
      21             :  GenSVM is distributed in the hope that it will be useful,
      22             :  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      24             :  GNU General Public License for more details.
      25             : 
      26             :  You should have received a copy of the GNU General Public License
      27             :  along with GenSVM. If not, see <http://www.gnu.org/licenses/>.
      28             : 
      29             :  */
      30             : 
      31             : #include "gensvm_cmdarg.h"
      32             : 
      33             : /**
      34             :  * @brief Check if any command line arguments contain string
      35             :  *
      36             :  * @details
      37             :  * Check if any of a given array of command line arguments contains a given
      38             :  * string. If the string is found, the index of the string in argv is
      39             :  * returned. If the string is not found, 0 is returned.
      40             :  *
      41             :  * This function is copied from MSVMpack/libMSVM.c.
      42             :  *
      43             :  * @param[in]   argc    number of command line arguments
      44             :  * @param[in]   argv    command line arguments
      45             :  * @param[in]   str     string to find in the arguments
      46             :  * @returns             index of the string in the arguments if found, 0
      47             :  *                      otherwise
      48             :  */
      49           3 : int gensvm_check_argv(int argc, char **argv, char *str)
      50             : {
      51             :         int i;
      52           3 :         int arg_str = 0;
      53           6 :         for (i=1; i<argc; i++)
      54           5 :                 if (strstr(argv[i], str) != NULL) {
      55           2 :                         arg_str = i;
      56           2 :                         break;
      57             :                 }
      58             : 
      59           3 :         return arg_str;
      60             : }
      61             : 
      62             : /**
      63             :  * @brief Check if a command line argument equals a string
      64             :  *
      65             :  * @details
      66             :  * Check if any of the command line arguments is exactly equal to a given
      67             :  * string. If so, return the index of the corresponding command line argument.
      68             :  * If not, return 0.
      69             :  *
      70             :  * This function is copied from MSVMpack/libMSVM.c
      71             :  *
      72             :  * @param[in]   argc    number of command line arguments
      73             :  * @param[in]   argv    command line arguments
      74             :  * @param[in]   str     string to find in the arguments
      75             :  * @returns             index of the command line argument that corresponds to
      76             :  *                      the string, 0 if none matches.
      77             :  */
      78           3 : int gensvm_check_argv_eq(int argc, char **argv, char *str)
      79             : {
      80             :         int i;
      81           3 :         int arg_str = 0;
      82           7 :         for (i=1; i<argc; i++)
      83           5 :                 if (strcmp(argv[i], str) == 0) {
      84           1 :                         arg_str = i;
      85           1 :                         break;
      86             :                 }
      87             : 
      88           3 :         return arg_str;
      89             : }

Generated by: LCOV version 1.12