]> git.ozlabs.org Git - ccan-lca-2011.git/blobdiff - ccan/oserver/_info
lca2011: add option parsing using ccan/opt.
[ccan-lca-2011.git] / ccan / oserver / _info
index 85ed0bf7881684c93ee5178d6af0a2366303cb04..6879f42903aa2bcab42523c330ccb3a1ae9bae03 100644 (file)
  *     #include <sys/types.h>
  *     #include <sys/socket.h>
  *     #include <ccan/oserver/oserver.h>
+ *     #include <ccan/opt/opt.h>
  *     #include <err.h>
  *     #include <stdlib.h>
  *
- *     int main(void)
+ *     int main(int argc, char *argv[])
  *     {
  *             int fd, sockfd;
+ *             unsigned int port = OSERVER_PORT;
  *
- *             sockfd = oserver_setup();
+ *             opt_register_noarg("--help|--usage|-h", opt_usage_and_exit,
+ *                                "\nA oserver program", "Usage information");
+ *             opt_register_arg("--port", opt_set_uintval, opt_show_uintval,
+ *                              &port, "Server port number");
+ *
+ *             opt_parse(&argc, argv, opt_log_stderr_exit);
+ *             if (argc != 1)
+ *                     opt_log_stderr_exit("Unknown extra arguments");
+ *
+ *             sockfd = oserver_setup(port);
  *             if (sockfd < 0)
  *                     err(1, "Failed to set up server socket");
  *
@@ -44,6 +55,7 @@ int main(int argc, char *argv[])
                printf("ccan/foreach\n");
                printf("ccan/noerr\n");
                printf("ccan/failtest\n");
+               printf("ccan/opt\n");
                return 0;
        }