提交 eb70ceba 编写于 作者: E Eric Blake

docs: fix layout of code snippets

Similar to commit 52dbeac8, we should indent code snippets in
other places to ensure they appear correctly in html.  See
http://libvirt.org/html/libvirt-libvirt.html#virNodeGetCPUStats
for an example improved by this patch.  Also fix some missing
semicolons in the examples.

* src/libvirt.c: Indent code samples in comments.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 9d30e078
...@@ -1150,9 +1150,9 @@ do_open(const char *name, ...@@ -1150,9 +1150,9 @@ do_open(const char *name,
} }
/* /*
* If no URI is passed, then check for an environment string if not * If no URI is passed, then check for an environment string if not
* available probe the compiled in drivers to find a default hypervisor * available probe the compiled in drivers to find a default hypervisor
* if detectable. * if detectable.
*/ */
if (!name && if (!name &&
virConnectGetDefaultURI(conf, &name) < 0) virConnectGetDefaultURI(conf, &name) < 0)
...@@ -7629,14 +7629,14 @@ error: ...@@ -7629,14 +7629,14 @@ error:
* *
* Here is a sample code snippet: * Here is a sample code snippet:
* *
* if ((virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, 0) == 0) && * if (virNodeGetCPUStats(conn, cpuNum, NULL, &nparams, 0) == 0 &&
* (nparams != 0)) { * nparams != 0) {
* if ((params = malloc(sizeof(virNodeCPUStats) * nparams)) == NULL) * if ((params = malloc(sizeof(virNodeCPUStats) * nparams)) == NULL)
* goto error; * goto error;
* memset(params, 0, sizeof(virNodeCPUStats) * nparams); * memset(params, 0, sizeof(virNodeCPUStats) * nparams);
* if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, 0)) * if (virNodeGetCPUStats(conn, cpuNum, params, &nparams, 0))
* goto error; * goto error;
* } * }
* *
* This function doesn't require privileged access to the hypervisor. * This function doesn't require privileged access to the hypervisor.
* This function expects the caller to allocate the @params. * This function expects the caller to allocate the @params.
...@@ -7722,14 +7722,14 @@ error: ...@@ -7722,14 +7722,14 @@ error:
* *
* Here is the sample code snippet: * Here is the sample code snippet:
* *
* if ((virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, 0) == 0) && * if (virNodeGetMemoryStats(conn, cellNum, NULL, &nparams, 0) == 0 &&
* (nparams != 0)) { * nparams != 0) {
* if ((params = malloc(sizeof(virNodeMemoryStats) * nparams)) == NULL) * if ((params = malloc(sizeof(virNodeMemoryStats) * nparams)) == NULL)
* goto error; * goto error;
* memset(params, cellNum, 0, sizeof(virNodeMemoryStats) * nparams); * memset(params, cellNum, 0, sizeof(virNodeMemoryStats) * nparams);
* if (virNodeGetMemoryStats(conn, params, &nparams, 0)) * if (virNodeGetMemoryStats(conn, params, &nparams, 0))
* goto error; * goto error;
* } * }
* *
* This function doesn't require privileged access to the hypervisor. * This function doesn't require privileged access to the hypervisor.
* This function expects the caller to allocate the @params. * This function expects the caller to allocate the @params.
...@@ -8134,14 +8134,14 @@ error: ...@@ -8134,14 +8134,14 @@ error:
* *
* Here is a sample code snippet: * Here is a sample code snippet:
* *
* char *ret = virDomainGetSchedulerType(dom, &nparams); * char *ret = virDomainGetSchedulerType(dom, &nparams);
* if (ret && nparams != 0) { * if (ret && nparams != 0) {
* if ((params = malloc(sizeof(*params) * nparams)) == NULL) * if ((params = malloc(sizeof(*params) * nparams)) == NULL)
* goto error; * goto error;
* memset(params, 0, sizeof(*params) * nparams); * memset(params, 0, sizeof(*params) * nparams);
* if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, 0)) * if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, 0))
* goto error; * goto error;
* } * }
* *
* Returns -1 in case of error, 0 in case of success. * Returns -1 in case of error, 0 in case of success.
*/ */
...@@ -9381,24 +9381,21 @@ error: ...@@ -9381,24 +9381,21 @@ error:
* on each array element, then calling free() on @domains. * on each array element, then calling free() on @domains.
* *
* Example of usage: * Example of usage:
* virDomainPtr *domains;
* size_t i;
* int ret;
* unsigned int flags = VIR_CONNECT_LIST_DOMAINS_RUNNING |
* VIR_CONNECT_LIST_DOMAINS_PERSISTENT;
*
* ret = virConnectListAllDomains(conn, &domains, flags);
* if (ret < 0)
* error();
* *
* for (i = 0; i < ret; i++) { * virDomainPtr *domains;
* do_something_with_domain(domains[i]); * size_t i;
* * int ret;
* //here or in a separate loop if needed * unsigned int flags = VIR_CONNECT_LIST_DOMAINS_RUNNING |
* virDomainFree(domains[i]); * VIR_CONNECT_LIST_DOMAINS_PERSISTENT;
* } * ret = virConnectListAllDomains(conn, &domains, flags);
* * if (ret < 0)
* free(domains); * error();
* for (i = 0; i < ret; i++) {
* do_something_with_domain(domains[i]);
* //here or in a separate loop if needed
* virDomainFree(domains[i]);
* }
* free(domains);
*/ */
int int
virConnectListAllDomains(virConnectPtr conn, virConnectListAllDomains(virConnectPtr conn,
...@@ -17023,7 +17020,7 @@ virStreamRef(virStreamPtr stream) ...@@ -17023,7 +17020,7 @@ virStreamRef(virStreamPtr stream)
* API looks like * API looks like
* *
* virStreamPtr st = virStreamNew(conn, 0); * virStreamPtr st = virStreamNew(conn, 0);
* int fd = open("demo.iso", O_RDONLY) * int fd = open("demo.iso", O_RDONLY);
* *
* virConnectUploadFile(conn, "demo.iso", st); * virConnectUploadFile(conn, "demo.iso", st);
* *
...@@ -17040,7 +17037,7 @@ virStreamRef(virStreamPtr stream) ...@@ -17040,7 +17037,7 @@ virStreamRef(virStreamPtr stream)
* } * }
* int offset = 0; * int offset = 0;
* while (offset < got) { * while (offset < got) {
* int sent = virStreamSend(st, buf+offset, got-offset) * int sent = virStreamSend(st, buf+offset, got-offset);
* if (sent < 0) { * if (sent < 0) {
* virStreamAbort(st); * virStreamAbort(st);
* goto done; * goto done;
...@@ -17117,7 +17114,7 @@ error: ...@@ -17117,7 +17114,7 @@ error:
* API looks like * API looks like
* *
* virStreamPtr st = virStreamNew(conn, 0); * virStreamPtr st = virStreamNew(conn, 0);
* int fd = open("demo.iso", O_WRONLY, 0600) * int fd = open("demo.iso", O_WRONLY, 0600);
* *
* virConnectDownloadFile(conn, "demo.iso", st); * virConnectDownloadFile(conn, "demo.iso", st);
* *
...@@ -17132,7 +17129,7 @@ error: ...@@ -17132,7 +17129,7 @@ error:
* } * }
* int offset = 0; * int offset = 0;
* while (offset < got) { * while (offset < got) {
* int sent = write(fd, buf+offset, got-offset) * int sent = write(fd, buf + offset, got - offset);
* if (sent < 0) { * if (sent < 0) {
* virStreamAbort(st); * virStreamAbort(st);
* goto done; * goto done;
...@@ -17216,7 +17213,7 @@ error: ...@@ -17216,7 +17213,7 @@ error:
* } * }
* *
* virStreamPtr st = virStreamNew(conn, 0); * virStreamPtr st = virStreamNew(conn, 0);
* int fd = open("demo.iso", O_RDONLY) * int fd = open("demo.iso", O_RDONLY);
* *
* virConnectUploadFile(conn, st); * virConnectUploadFile(conn, st);
* if (virStreamSendAll(st, mysource, &fd) < 0) { * if (virStreamSendAll(st, mysource, &fd) < 0) {
...@@ -17313,7 +17310,7 @@ cleanup: ...@@ -17313,7 +17310,7 @@ cleanup:
* } * }
* *
* virStreamPtr st = virStreamNew(conn, 0); * virStreamPtr st = virStreamNew(conn, 0);
* int fd = open("demo.iso", O_WRONLY) * int fd = open("demo.iso", O_WRONLY);
* *
* virConnectUploadFile(conn, st); * virConnectUploadFile(conn, st);
* if (virStreamRecvAll(st, mysink, &fd) < 0) { * if (virStreamRecvAll(st, mysink, &fd) < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册