| 249 | static int |
| 250 | usage(const char* program) { |
| 251 | // Issue usage message |
| 252 | fprintf(stderr, "usage: %s [-P] [--raw|-r] <attribute-name> <file1> " |
| 253 | "[<file2>...]\n" |
| 254 | "\t-P : Don't resolve links\n" |
| 255 | "\t--raw|-r : Get the raw data of attributes\n", program); |
| 256 | // Be's original version -only- returned 1 if the |
| 257 | // amount of parameters was wrong, not if the file |
| 258 | // or attribute couldn't be found (!) |
| 259 | // In all other cases it returned 0 |
| 260 | return 1; |
| 261 | } |
| 262 | |
| 263 | |
261 | | if (!strcmp(argv[attrNameIndex], "-P")) { |
262 | | resolveLinks = false; |
263 | | attrNameIndex++; |
| 276 | const char* short_options = "rP"; |
| 277 | const struct option long_options[] = { |
| 278 | {"raw", no_argument, NULL, 'r'}, |
| 279 | {NULL, 0, NULL, 0} |
| 280 | }; |
| 281 | |
| 282 | int rez, option_index; |
| 283 | while ((rez = getopt_long(argc, argv, short_options, long_options, |
| 284 | &option_index)) != -1) { |
| 285 | switch (rez) { |
| 286 | case 'r': |
| 287 | keepRaw = true; |
| 288 | break; |
| 289 | case 'P': |
| 290 | resolveLinks = false; |
| 291 | break; |
| 292 | default: |
| 293 | return usage(program); |
273 | | // Cat the attribute for every file given |
274 | | for (int32 i = attrNameIndex + 1; i < argc; i++) { |
275 | | status_t status = catAttr(argv[attrNameIndex], argv[i], keepRaw, |
| 297 | if (optind + 2 > argc) |
| 298 | return usage(program); |
| 299 | |
| 300 | const char* attr_name = argv[optind++]; |
| 301 | while (optind < argc) { |
| 302 | const char* file_name = argv[optind++]; |
| 303 | status_t status = catAttr(attr_name, file_name, keepRaw, |
277 | | if (status != B_OK) { |
278 | | fprintf(stderr, "%s: \"%s\", attribute \"%s\": %s\n", |
279 | | program, argv[i], argv[attrNameIndex], strerror(status)); |
280 | | } |
| 305 | if (status != B_OK) { |
| 306 | fprintf(stderr, "%s: \"%s\", attribute \"%s\": %s\n", |
| 307 | program, file_name, attr_name, strerror(status)); |
282 | | } else { |
283 | | // Issue usage message |
284 | | fprintf(stderr, "usage: %s [-P] [--raw|-r] <attribute-name> <file1> " |
285 | | "[<file2>...]\n" |
286 | | "\t-P : Don't resolve links\n" |
287 | | "\t--raw|-r : Get the raw data of attributes\n", program); |
288 | | // Be's original version -only- returned 1 if the |
289 | | // amount of parameters was wrong, not if the file |
290 | | // or attribute couldn't be found (!) |
291 | | // In all other cases it returned 0 |
292 | | return 1; |