commit 185be9c20d3f205f3e609d6155a7d34a99357775
parent ea1ff22cec6490b8ca2eea56dc38999b73735735
Author: xplshn <anto@xplshn.com.ar>
Date: Tue, 10 Nov 2026 21:51:49 -0300
mkman fixes and define GNU_SOURCE in libutil/passwd.c
Signed-off-by: xplshn <anto@xplshn.com.ar>
Diffstat:
5 files changed, 73 insertions(+), 11 deletions(-)
diff --git a/cmd/extra/fdisk.c b/cmd/extra/fdisk.c
@@ -862,9 +862,8 @@ do_fdisk(const char *path)
}
// ?man fdisk: partition table manipulator
-// ?man arguments: [-l] [-p] [-g] [-m] [-s] [-a] [-d] [-n index] [-b start] [-e
-// end] [-t type] [-c name] [device] ?man fdisk performs partition table
-// operations for MBR, GPT and BSD disklabels
+// ?man arguments: [-l] [-p] [-g] [-m] [-s] [-a] [-d] [-n index] [-b start] [-e end] [-t type] [-c name] [device]
+// ?man fdisk performs partition table operations for MBR, GPT and BSD disklabels
int
main(int argc, char *argv[])
{
diff --git a/cmd/linux/rmmod.c b/cmd/linux/rmmod.c
@@ -35,11 +35,9 @@ main(int argc, char *argv[])
ARGBEGIN
{
- // ?man -f: specify f option
case 'f':
flags |= O_TRUNC;
break;
- // ?man -w: specify w option
case 'w':
flags &= ~O_NONBLOCK;
break;
diff --git a/scripts/mkman/mkman_test.go b/scripts/mkman/mkman_test.go
@@ -155,6 +155,28 @@ func TestParsePageRejectionClasses(t *testing.T) {
}
}
+func TestParseDirectiveComments(t *testing.T) {
+ content := "// ?man cmd: summary\n" +
+ "#ifndef O_SEARCH /* not present on some bsds */\n" +
+ "// ?man -a: use a\n" +
+ "#endif /* O_SEARCH */\n" +
+ "#ifdef FEATURE_A /* gated\n" +
+ " feature\n" +
+ " still */\n" +
+ "// ?man -b: use b\n" +
+ "#endif\n" +
+ "#if defined(FEATURE_A) /* a // b */\n" +
+ "// ?man -c: use c\n" +
+ "#endif\n"
+ page, err := parseSource(t, content, Config{"FEATURE_A": "1"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(page.Options) != 3 {
+ t.Fatalf("got %d options, want 3", len(page.Options))
+ }
+}
+
func TestParseOptionCompatibility(t *testing.T) {
for _, line := range []string{
"-a: use a",
diff --git a/scripts/mkman/parse.go b/scripts/mkman/parse.go
@@ -116,6 +116,31 @@ func parseConditional(directive string, cfg Config, stack *ifStack, lineNo int)
return nil
}
+// stripDirectiveComments removes c comments from a preprocessor line. open
+// reports a block comment that carries on past the end of the line
+func stripDirectiveComments(s string) (string, bool) {
+ var b strings.Builder
+ for {
+ block := strings.Index(s, "/*")
+ line := strings.Index(s, "//")
+ if line >= 0 && (block < 0 || line < block) {
+ b.WriteString(s[:line])
+ return strings.TrimSpace(b.String()), false
+ }
+ if block < 0 {
+ b.WriteString(s)
+ return strings.TrimSpace(b.String()), false
+ }
+ b.WriteString(s[:block])
+ end := strings.Index(s[block+2:], "*/")
+ if end < 0 {
+ return strings.TrimSpace(b.String()), true
+ }
+ b.WriteByte(' ')
+ s = s[block+2+end+2:]
+ }
+}
+
func extractManLines(path string, cfg Config) ([]string, error) {
contentBytes, err := os.ReadFile(path)
if err != nil {
@@ -127,6 +152,8 @@ func extractManLines(path string, cfg Config) ([]string, error) {
sc := bufio.NewScanner(strings.NewReader(string(contentBytes)))
sc.Buffer(make([]byte, 1<<20), 1<<20)
inBlockComment := false
+ inDirectiveComment := false
+ pendingDirective := ""
lineNo := 0
for sc.Scan() {
@@ -160,14 +187,27 @@ func extractManLines(path string, cfg Config) ([]string, error) {
continue
}
- if strings.HasPrefix(trimmed, "#") {
- directive := trimmed[1:]
- if ci := strings.Index(directive, "// "); ci >= 0 {
- directive = directive[:ci]
+ if inDirectiveComment || strings.HasPrefix(trimmed, "#") {
+ text := pendingDirective
+ if inDirectiveComment {
+ idx := strings.Index(trimmed, "*/")
+ if idx < 0 {
+ continue
+ }
+ text += " " + trimmed[idx+2:]
+ pendingDirective = ""
+ inDirectiveComment = false
+ } else {
+ text = trimmed[1:]
+ }
+ text, open := stripDirectiveComments(text)
+ if open {
+ inDirectiveComment = true
+ pendingDirective = text
+ continue
}
- directive = strings.TrimSpace(directive)
- if err := parseConditional(directive, cfg, stack, lineNo); err != nil {
+ if err := parseConditional(text, cfg, stack, lineNo); err != nil {
return nil, err
}
continue
diff --git a/shared/libutil/passwd.c b/shared/libutil/passwd.c
@@ -1,5 +1,8 @@
/* see LICENSE file for copyright and license details */
#if FEATURE_PASSWD_EXT
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE /* musl declares fgetpwent/putpwent only under it */
+#endif
#ifndef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#endif