check transfer  0.1
Check data transfer for SDAccell OpenCL application
parse_cmd.cpp
Go to the documentation of this file.
1 /*
2  * parse_cmd.cpp
3  *
4  * Created on: Sep 4, 2017
5  *
6  * Functions for parse command line
7  *
8  */
9 
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include "parse_cmd.h"
14 
15 
16 /**
17  * \brief Get integer value from command line
18  *
19  * format command line:
20  * <name1> <value1> <name2> <value2>
21  *
22  * \param argc number of argument
23  * \param argv pointers to arguments
24  * \param name key of argument
25  * \param defValue default value for arguments
26  *
27  * \return value of argument or default value of argument
28  */
29 int GetFromCommnadLine(int argc, char **argv, const char* name, int defValue)
30 {
31  int ret=defValue;
32  for( int ii=1; ii<argc-1; ii++ )
33  {
34  if( 0==strcmp( argv[ii], name) )
35  {
36  ret=atoi( argv[ii+1] );
37  }
38  }
39  return ret;
40 }
41 
42 
43 /**
44  * \brief Get string value from command line
45  *
46  * format command line:
47  * <name1> <text1> <name2> <text2>
48  *
49  * \param argc number of argument
50  * \param argv pointers to arguments
51  * \param name key of argument
52  * \param defValue default value for arguments
53  * \param dst pointer to destination string, NULL - do not copy
54  * \param dstLen max number of chars in the dst
55  *
56  * \return 0 - name not found, 1 - found only name, 2 - found name and text
57  */
58  int GetStrFromCommnadLine(int argc, char **argv, const char* name, char* defValue, char* dst, int dstLen )
59 {
60  int ret=0;
61  int index=0;
62  for( int ii=1; ii<argc; ii++ )
63  {
64  if( 0==strcmp( argv[ii], name) )
65  {
66  if( ii==(argc-1) )
67  ret=1;
68  else
69  {
70  ret=2; index=ii;
71  }
72 
73  break;
74  }
75  }
76  if( NULL!=dst )
77  {
78  if( 2==ret )
79  strncpy( dst, argv[index+1], dstLen );
80  else
81  strncpy( dst, defValue, dstLen );
82  dst[dstLen-1]=0;
83  }
84  return ret;
85 }
int GetStrFromCommnadLine(int argc, char **argv, const char *name, char *defValue, char *dst, int dstLen)
Get string value from command line.
Definition: parse_cmd.cpp:58
int GetFromCommnadLine(int argc, char **argv, const char *name, int defValue)
Get integer value from command line.
Definition: parse_cmd.cpp:29