mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-01 22:58:40 -04:00
scanner: Generalize desc_dump() to handle hanging indents
This commit is contained in:
parent
5b0d8f09af
commit
375cb418f4
1 changed files with 65 additions and 34 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
@ -155,26 +156,59 @@ static const char *indent(int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
desc_dump(char *src, int startcol)
|
desc_dump(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
int i, j, col = startcol;
|
va_list ap;
|
||||||
|
char buf[128], *desc, hang;
|
||||||
|
int col, i, j, k, startcol;
|
||||||
|
|
||||||
for (i = 0; src[i]; i++) {
|
va_start(ap, fmt);
|
||||||
if (isspace(src[i]))
|
vsnprintf(buf, sizeof buf, fmt, ap);
|
||||||
continue;
|
desc = va_arg(ap, char *);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
for (i = 0, col = 0; buf[i] != '*'; i++) {
|
||||||
|
if (buf[i] == '\t')
|
||||||
|
col = (col + 8) & ~7;
|
||||||
|
else
|
||||||
|
col++;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s", buf);
|
||||||
|
|
||||||
|
if (!desc) {
|
||||||
|
printf("(none)\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
startcol = col;
|
||||||
|
col += strlen(&buf[i]);
|
||||||
|
if (col - startcol > 2)
|
||||||
|
hang = '\t';
|
||||||
|
else
|
||||||
|
hang = ' ';
|
||||||
|
|
||||||
|
for (i = 0; desc[i]; ) {
|
||||||
|
k = i;
|
||||||
|
while (desc[i] && isspace(desc[i]))
|
||||||
|
i++;
|
||||||
|
if (!desc[i])
|
||||||
|
break;
|
||||||
|
|
||||||
j = i;
|
j = i;
|
||||||
while (src[i] && !isspace(src[i]))
|
while (desc[i] && !isspace(desc[i]))
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (col + i - j > 72) {
|
if (col + i - j > 72) {
|
||||||
printf("\n%s * ", indent(startcol));
|
printf("\n%s*%c", indent(startcol), hang);
|
||||||
col = startcol;
|
col = startcol;
|
||||||
}
|
}
|
||||||
|
|
||||||
col += printf("%s%.*s",
|
if (col > startcol && k > 0)
|
||||||
col > startcol ? " " : "", i - j, &src[j]);
|
col += printf(" ");
|
||||||
|
col += printf("%.*s", i - j, &desc[j]);
|
||||||
}
|
}
|
||||||
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -638,20 +672,19 @@ emit_enumerations(struct interface *interface)
|
||||||
interface->uppercase_name, e->uppercase_name);
|
interface->uppercase_name, e->uppercase_name);
|
||||||
|
|
||||||
if (desc) {
|
if (desc) {
|
||||||
printf("/**\n"
|
printf("/**\n");
|
||||||
" * %s_%s - %s\n", interface->name,
|
desc_dump(" * %s_%s - ",
|
||||||
e->name, desc->summary);
|
interface->name, e->name, desc->summary);
|
||||||
wl_list_for_each(entry, &e->entry_list, link) {
|
wl_list_for_each(entry, &e->entry_list, link) {
|
||||||
printf(" * @%s_%s_%s: %s\n",
|
desc_dump(" * @%s_%s_%s: ",
|
||||||
interface->uppercase_name,
|
interface->uppercase_name,
|
||||||
e->uppercase_name,
|
e->uppercase_name,
|
||||||
entry->uppercase_name,
|
entry->uppercase_name,
|
||||||
entry->summary);
|
entry->summary);
|
||||||
}
|
}
|
||||||
if (desc->text) {
|
if (desc->text) {
|
||||||
printf(" *\n"
|
printf(" *\n");
|
||||||
" * ");
|
desc_dump(" * ", desc->text);
|
||||||
desc_dump(desc->text, 0);
|
|
||||||
}
|
}
|
||||||
printf(" */\n");
|
printf(" */\n");
|
||||||
}
|
}
|
||||||
|
|
@ -680,16 +713,15 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
|
||||||
is_interface = message_list == &interface->request_list;
|
is_interface = message_list == &interface->request_list;
|
||||||
if (interface->description) {
|
if (interface->description) {
|
||||||
struct description *desc = interface->description;
|
struct description *desc = interface->description;
|
||||||
printf("/**\n"
|
printf("/**\n");
|
||||||
" * %s - %s\n", interface->name, desc->summary);
|
desc_dump(" * %s - ", interface->name, desc->summary);
|
||||||
wl_list_for_each(m, message_list, link) {
|
wl_list_for_each(m, message_list, link) {
|
||||||
struct description *mdesc = m->description;
|
struct description *mdesc = m->description;
|
||||||
printf(" * @%s: %s\n", m->name, mdesc ? mdesc->summary :
|
desc_dump(" * @%s: ",
|
||||||
"(none)");
|
m->name, mdesc ? mdesc->summary : "(none)");
|
||||||
}
|
}
|
||||||
printf(" *\n"
|
printf(" *\n");
|
||||||
" * ");
|
desc_dump(" * ", desc->text);
|
||||||
desc_dump(desc->text, 0);
|
|
||||||
printf(" */\n");
|
printf(" */\n");
|
||||||
}
|
}
|
||||||
printf("struct %s_%s {\n", interface->name,
|
printf("struct %s_%s {\n", interface->name,
|
||||||
|
|
@ -699,16 +731,15 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
|
||||||
struct description *mdesc = m->description;
|
struct description *mdesc = m->description;
|
||||||
|
|
||||||
printf("\t/**\n");
|
printf("\t/**\n");
|
||||||
printf("\t * %s - %s\n", m->name, mdesc ? mdesc->summary :
|
desc_dump("\t * %s - ",
|
||||||
"(none)");
|
m->name, mdesc ? mdesc->summary : "(none)");
|
||||||
wl_list_for_each(a, &m->arg_list, link) {
|
wl_list_for_each(a, &m->arg_list, link) {
|
||||||
printf("\t * @%s: %s\n", a->name, a->summary ?
|
desc_dump("\t * @%s: ",
|
||||||
a->summary : "(none)");
|
a->name, a->summary ? a->summary : "(none)");
|
||||||
}
|
}
|
||||||
if (mdesc) {
|
if (mdesc) {
|
||||||
printf("\t * ");
|
printf("\t *\n");
|
||||||
desc_dump(mdesc->text, 8);
|
desc_dump("\t * ", mdesc->text, 8, 0);
|
||||||
printf("\n");
|
|
||||||
}
|
}
|
||||||
if (m->since > 1) {
|
if (m->since > 1) {
|
||||||
printf("\t * @since: %d\n", m->since);
|
printf("\t * @since: %d\n", m->since);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue