| 1 | #include <unistd.h> |
| 2 | #include <getopt.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
| 5 | #include <fcntl.h> |
| 6 | |
| 7 | #include "ustcomm.h" |
| 8 | |
| 9 | void parse_opts(int argc, char **argv) |
| 10 | { |
| 11 | int flags, opt; |
| 12 | int nsecs, tfnd; |
| 13 | |
| 14 | nsecs = 0; |
| 15 | tfnd = 0; |
| 16 | flags = 0; |
| 17 | while ((opt = getopt(argc, argv, "nt:")) != -1) { |
| 18 | switch (opt) { |
| 19 | case 'n': |
| 20 | flags = 1; |
| 21 | break; |
| 22 | case 't': |
| 23 | nsecs = atoi(optarg); |
| 24 | tfnd = 1; |
| 25 | break; |
| 26 | default: /* '?' */ |
| 27 | fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", |
| 28 | argv[0]); |
| 29 | exit(EXIT_FAILURE); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind); |
| 34 | |
| 35 | if (optind >= argc) { |
| 36 | fprintf(stderr, "Expected argument after options\n"); |
| 37 | exit(EXIT_FAILURE); |
| 38 | } |
| 39 | |
| 40 | printf("name argument = %s\n", argv[optind]); |
| 41 | |
| 42 | /* Other code omitted */ |
| 43 | |
| 44 | exit(EXIT_SUCCESS); |
| 45 | |
| 46 | } |
| 47 | |
| 48 | int main(int argc, char *argv[]) |
| 49 | { |
| 50 | pid_t pid = atoi(argv[1]); |
| 51 | |
| 52 | char *msg = argv[2]; |
| 53 | |
| 54 | send_message(pid, msg, NULL); |
| 55 | |
| 56 | return 0; |
| 57 | } |