Ticket #1436: fix_longopt.patch
File fix_longopt.patch, 5.9 KB (added by fperrad, 12 years ago) |
---|
-
src/longopt.c
25 25 /* HEADERIZER BEGIN: static */ 26 26 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 27 27 28 static int longopt_get_longopt(PARROT_INTERP, 29 int argc, 28 static int longopt_get_longopt(int argc, 30 29 ARGIN(const char* argv[]), 31 30 ARGIN(const struct longopt_opt_decl options[]), 32 31 ARGMOD(struct longopt_opt_info* info_buf)) 33 __attribute__nonnull__( 1)32 __attribute__nonnull__(2) 34 33 __attribute__nonnull__(3) 35 34 __attribute__nonnull__(4) 36 __attribute__nonnull__(5)37 35 FUNC_MODIFIES(* info_buf); 38 36 39 static int longopt_get_shortopt(PARROT_INTERP, 40 int argc, 37 static int longopt_get_shortopt(int argc, 41 38 ARGIN(const char* argv[]), 42 39 ARGIN(const struct longopt_opt_decl options[]), 43 40 ARGMOD(struct longopt_opt_info* info_buf)) 44 __attribute__nonnull__( 1)41 __attribute__nonnull__(2) 45 42 __attribute__nonnull__(3) 46 43 __attribute__nonnull__(4) 47 __attribute__nonnull__(5)48 44 FUNC_MODIFIES(* info_buf); 49 45 50 46 #define ASSERT_ARGS_longopt_get_longopt __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 51 PARROT_ASSERT_ARG(interp) \ 52 , PARROT_ASSERT_ARG(argv) \ 47 PARROT_ASSERT_ARG(argv) \ 53 48 , PARROT_ASSERT_ARG(options) \ 54 49 , PARROT_ASSERT_ARG(info_buf)) 55 50 #define ASSERT_ARGS_longopt_get_shortopt __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 56 PARROT_ASSERT_ARG(interp) \ 57 , PARROT_ASSERT_ARG(argv) \ 51 PARROT_ASSERT_ARG(argv) \ 58 52 , PARROT_ASSERT_ARG(options) \ 59 53 , PARROT_ASSERT_ARG(info_buf)) 60 54 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ … … 101 95 return 0; 102 96 103 97 if (info_buf->_shortopt_pos) 104 return longopt_get_shortopt( interp,argc, argv, options, info_buf);98 return longopt_get_shortopt(argc, argv, options, info_buf); 105 99 106 100 if (argv[dex][1] == '-') { /* Long option or -- */ 107 101 if (argv[dex][2] == '\0') { … … 109 103 return 0; 110 104 } 111 105 else { /* Long option */ 112 return longopt_get_longopt( interp,argc, argv, options, info_buf);106 return longopt_get_longopt(argc, argv, options, info_buf); 113 107 } 114 108 } 115 109 else { /* Short option */ 116 return longopt_get_shortopt( interp,argc, argv, options, info_buf);110 return longopt_get_shortopt(argc, argv, options, info_buf); 117 111 } 118 112 } 119 113 120 114 /* 121 115 122 =item C<static int longopt_get_longopt( PARROT_INTERP, int argc, const char*123 argv[],const struct longopt_opt_decl options[], struct longopt_opt_info*116 =item C<static int longopt_get_longopt(int argc, const char* argv[], 117 const struct longopt_opt_decl options[], struct longopt_opt_info* 124 118 info_buf)> 125 119 126 120 Find the option identifier of a long option. … … 135 129 */ 136 130 137 131 static int 138 longopt_get_longopt( PARROT_INTERP,int argc, ARGIN(const char* argv[]),132 longopt_get_longopt(int argc, ARGIN(const char* argv[]), 139 133 ARGIN(const struct longopt_opt_decl options[]), 140 134 ARGMOD(struct longopt_opt_info* info_buf)) 141 135 { … … 167 161 info_buf->opt_arg = &argv[dex][optlen+1]; 168 162 } 169 163 else { 170 Parrot_snprintf(interp,longopt_error_buffer,164 snprintf(longopt_error_buffer, 171 165 sizeof (longopt_error_buffer), 172 166 "Option %s does not expect an argument", 173 167 dptr->opt_long[sptr]); … … 182 176 ++info_buf->opt_index; 183 177 } 184 178 else { 185 Parrot_snprintf(interp,longopt_error_buffer,179 snprintf(longopt_error_buffer, 186 180 sizeof (longopt_error_buffer), 187 181 "Option %s needs an argument", 188 182 dptr->opt_long[sptr]); … … 206 200 207 201 /* Couldn't find it. */ 208 202 info_buf->opt_id = -1; 209 Parrot_snprintf(interp,longopt_error_buffer,203 snprintf(longopt_error_buffer, 210 204 sizeof (longopt_error_buffer), 211 205 "Option %s not known", argv[dex]); 212 206 info_buf->opt_error = longopt_error_buffer; … … 215 209 216 210 /* 217 211 218 =item C<static int longopt_get_shortopt( PARROT_INTERP, int argc, const char*219 argv[],const struct longopt_opt_decl options[], struct longopt_opt_info*212 =item C<static int longopt_get_shortopt(int argc, const char* argv[], 213 const struct longopt_opt_decl options[], struct longopt_opt_info* 220 214 info_buf)> 221 215 222 216 Find the option identifier of the next short option. … … 232 226 */ 233 227 234 228 static int 235 longopt_get_shortopt( PARROT_INTERP,int argc, ARGIN(const char* argv[]),229 longopt_get_shortopt(int argc, ARGIN(const char* argv[]), 236 230 ARGIN(const struct longopt_opt_decl options[]), 237 231 ARGMOD(struct longopt_opt_info* info_buf)) 238 232 { … … 261 255 ++info_buf->opt_index; 262 256 } 263 257 else { 264 Parrot_snprintf(interp,longopt_error_buffer,258 snprintf(longopt_error_buffer, 265 259 sizeof (longopt_error_buffer), 266 260 "Option -%c expects an argument", *pos); 267 261 info_buf->opt_error = longopt_error_buffer; … … 299 293 300 294 /* Couldn't find it in the table */ 301 295 info_buf->opt_id = -1; 302 Parrot_snprintf(interp,longopt_error_buffer,296 snprintf(longopt_error_buffer, 303 297 sizeof (longopt_error_buffer), 304 298 "Option -%c not known", *pos); 305 299 info_buf->opt_error = longopt_error_buffer;