Changes in uspace/srv/net/app/parse.c [3be62bc:21580dd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/app/parse.c
r3be62bc r21580dd 38 38 #include <string.h> 39 39 40 #include "../include/socket.h"41 42 40 #include "../err.h" 43 41 44 42 #include "parse.h" 45 43 46 int parse_address_family(const char * name){ 47 if(str_lcmp(name, "AF_INET", 7) == 0){ 48 return AF_INET; 49 }else if(str_lcmp(name, "AF_INET6", 8) == 0){ 50 return AF_INET6; 51 } 52 return EAFNOSUPPORT; 53 } 44 int parse_parameter_int( int argc, char ** argv, int * index, int * value, const char * name, int offset ){ 45 char * rest; 54 46 55 int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset){ 56 char * rest; 57 58 if(offset){ 59 *value = strtol(argv[*index] + offset, &rest, 10); 60 }else if((*index) + 1 < argc){ 61 ++ (*index); 62 *value = strtol(argv[*index], &rest, 10); 47 if( offset ){ 48 * value = strtol( argv[ * index ] + offset, & rest, 10 ); 49 }else if(( * index ) + 1 < argc ){ 50 ++ ( * index ); 51 * value = strtol( argv[ * index ], & rest, 10 ); 63 52 }else{ 64 fprintf( stderr, "Command line error: missing %s\n", name);53 fprintf( stderr, "Command line error: missing %s\n", name ); 65 54 return EINVAL; 66 55 } 67 if( rest && (*rest)){68 fprintf( stderr, "Command line error: %s unrecognized (%d: %s)\n", name, * index, argv[*index]);56 if( rest && ( * rest )){ 57 fprintf( stderr, "Command line error: %s unrecognized (%d: %s)\n", name, * index, argv[ * index ] ); 69 58 return EINVAL; 70 59 } … … 72 61 } 73 62 74 int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value)){ 63 int parse_parameter_string( int argc, char ** argv, int * index, char ** value, const char * name, int offset ){ 64 if( offset ){ 65 * value = argv[ * index ] + offset; 66 }else if(( * index ) + 1 < argc ){ 67 ++ ( * index ); 68 * value = argv[ * index ]; 69 }else{ 70 fprintf( stderr, "Command line error: missing %s\n", name ); 71 return EINVAL; 72 } 73 return EOK; 74 } 75 76 int parse_parameter_name_int( int argc, char ** argv, int * index, int * value, const char * name, int offset, int ( * parse_value )( const char * value )){ 75 77 ERROR_DECLARE; 76 78 77 char * 79 char * parameter; 78 80 79 ERROR_PROPAGATE( parse_parameter_string(argc, argv, index, ¶meter, name, offset));80 * value = (*parse_value)(parameter);81 if(( *value) == ENOENT){82 fprintf( stderr, "Command line error: unrecognized %s value (%d: %s)\n", name, * index, parameter);81 ERROR_PROPAGATE( parse_parameter_string( argc, argv, index, & parameter, name, offset )); 82 * value = ( * parse_value )( parameter ); 83 if(( * value ) == ENOENT ){ 84 fprintf( stderr, "Command line error: unrecognized %s value (%d: %s)\n", name, * index, parameter ); 83 85 return ENOENT; 84 86 } … … 86 88 } 87 89 88 int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset){ 89 if(offset){ 90 *value = argv[*index] + offset; 91 }else if((*index) + 1 < argc){ 92 ++ (*index); 93 *value = argv[*index]; 94 }else{ 95 fprintf(stderr, "Command line error: missing %s\n", name); 96 return EINVAL; 97 } 98 return EOK; 99 } 100 101 int parse_protocol_family(const char * name){ 102 if(str_lcmp(name, "PF_INET", 7) == 0){ 103 return PF_INET; 104 }else if(str_lcmp(name, "PF_INET6", 8) == 0){ 105 return PF_INET6; 106 } 107 return EPFNOSUPPORT; 108 } 109 110 int parse_socket_type(const char * name){ 111 if(str_lcmp(name, "SOCK_DGRAM", 11) == 0){ 112 return SOCK_DGRAM; 113 }else if(str_lcmp(name, "SOCK_STREAM", 12) == 0){ 114 return SOCK_STREAM; 115 } 116 return ESOCKTNOSUPPORT; 117 } 118 119 void print_unrecognized(int index, const char * parameter){ 120 fprintf(stderr, "Command line error: unrecognized argument (%d: %s)\n", index, parameter); 90 void print_unrecognized( int index, const char * parameter ){ 91 fprintf( stderr, "Command line error - unrecognized parameter (%d: %s)\n", index, parameter ); 121 92 } 122 93
Note:
See TracChangeset
for help on using the changeset viewer.