| 1 | package manpagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 5 | "path/filepathscip-go gomod github.com/golang/go/src go1.13 `path/filepath`/" |
| 6 | "regexpscip-go gomod github.com/golang/go/src go1.13 regexp/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.13 strings/" |
| 8 | |
| 9 | "github.com/Debian/debiman/internal/tagscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/tag`/" |
| 10 | "golang.org/x/text/languagescip-go gomod golang.org/x/text v0.3.2 `golang.org/x/text/language`/" |
| 11 | "pault.ag/go/debian/versionscip-go gomod pault.ag/go/debian b831f604d664 `pault.ag/go/debian/version`/" |
| 12 | ) |
| 13 | |
| 14 | type PkgMetascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta# struct { |
| 15 | Componentscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Component. string |
| 16 | Filenamescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Filename. string |
| 17 | Sourcepkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Sourcepkg. string |
| 18 | Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg. string |
| 19 | Replacesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Replaces. []string |
| 20 | |
| 21 | // Version is used by the templates when rendering. |
| 22 | Versionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Version. versionscip-go gomod pault.ag/go/debian b831f604d664 `pault.ag/go/debian/version`/.Versionscip-go gomod pault.ag/go/debian b831f604d664 `pault.ag/go/debian/version`/Version# |
| 23 | |
| 24 | // Suite is the Debian suite in which this binary package was |
| 25 | // found. |
| 26 | Suitescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Suite. string |
| 27 | } |
| 28 | |
| 29 | func (p *PkgMetascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#) SameBinaryscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#SameBinary().(o *PkgMetascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#) bool { |
| 30 | if p.Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg. == o.Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg. { |
| 31 | return true |
| 32 | } |
| 33 | for _, r := range p.Replacesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Replaces. { |
| 34 | if r == o.Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg. { |
| 35 | return true |
| 36 | } |
| 37 | } |
| 38 | for _, r := range o.Replacesscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Replaces. { |
| 39 | if r == p.Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg. { |
| 40 | return true |
| 41 | } |
| 42 | } |
| 43 | return false |
| 44 | } |
| 45 | |
| 46 | type Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta# struct { |
| 47 | // Name is e.g. “w3m”, or “systemd.service”. |
| 48 | Namescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Name. string |
| 49 | |
| 50 | // Package is the Debian binary package from which this manpage |
| 51 | // was extracted. |
| 52 | Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package. *PkgMetascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta# |
| 53 | |
| 54 | // Section is the man section to which this manpage belongs, |
| 55 | // e.g. 1, 3pm, … |
| 56 | Sectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Section. string |
| 57 | |
| 58 | // Language is the locale-like language directory |
| 59 | // (i.e. language[_territory][.codeset][@modifier], with language coming |
| 60 | // from ISO639 and territory coming from ISO3166) in which this |
| 61 | // manpage was found. |
| 62 | Languagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Language. string |
| 63 | LanguageTagscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#LanguageTag. languagescip-go gomod golang.org/x/text v0.3.2 `golang.org/x/text/language`/.Tagscip-go gomod golang.org/x/text v0.3.2 `golang.org/x/text/language`/Tag# |
| 64 | } |
| 65 | |
| 66 | // FromManPath constructs a manpage, gathering details from path (relative underneath /usr/share/man). |
| 67 | func FromManPathscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/FromManPath().(path string, p *PkgMetascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#) (*Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#, error) { |
| 68 | // man pages are in /usr/share/man/(<lang>/|)man<section>/<name>.<section>.gz |
| 69 | |
| 70 | lang := "C" |
| 71 | |
| 72 | parts := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Splitscip-go gomod github.com/golang/go/src go1.13 strings/Split().(path, "/") |
| 73 | if len(parts) == 3 { |
| 74 | // Language-specific subdirectory |
| 75 | lang = parts[0] |
| 76 | // Strip the codeset, if any |
| 77 | if idx := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Indexscip-go gomod github.com/golang/go/src go1.13 strings/Index().(lang, "."); idx > -1 { |
| 78 | lidx := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.LastIndexscip-go gomod github.com/golang/go/src go1.13 strings/LastIndex().(lang, "@") |
| 79 | if lidx == -1 { |
| 80 | lidx = len(lang) |
| 81 | } |
| 82 | lang = lang[:idx] + lang[lidx:len(lang)] |
| 83 | } |
| 84 | parts = parts[1:] |
| 85 | } |
| 86 | |
| 87 | // Both C and POSIX are to be treated as english, see |
| 88 | // https://sources.debian.net/src/man-db/2.7.6.1-2/lib/encodings.c/#L83 |
| 89 | if lang == "C" || lang == "POSIX" { |
| 90 | lang = "en" |
| 91 | } |
| 92 | |
| 93 | tag, err := tagscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/tag`/.FromLocalescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/tag`/FromLocale().(lang) |
| 94 | if err != nil { |
| 95 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Cannot parse language %q: %v", lang, err) |
| 96 | } |
| 97 | |
| 98 | if len(parts) != 2 { |
| 99 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Unexpected path format %q", path) |
| 100 | } |
| 101 | |
| 102 | if !stringsscip-go gomod github.com/golang/go/src go1.13 strings/.HasSuffixscip-go gomod github.com/golang/go/src go1.13 strings/HasSuffix().(parts[1], ".gz") { |
| 103 | parts[1] = parts[1] + ".gz" |
| 104 | } |
| 105 | |
| 106 | section := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.13 strings/TrimPrefix().(parts[0], "man") |
| 107 | re := regexpscip-go gomod github.com/golang/go/src go1.13 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.13 regexp/MustCompile().(fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().(`\.%s([^.]*)\.gz$`, section)) |
| 108 | matches := re.FindStringSubmatchscip-go gomod github.com/golang/go/src go1.13 regexp/Regexp#FindStringSubmatch().(parts[1]) |
| 109 | if matches == nil { |
| 110 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("file name (%q) does not match regexp %v", parts[1], re) |
| 111 | } |
| 112 | if len(matches) > 1 { |
| 113 | section = section + matches[1] |
| 114 | } |
| 115 | |
| 116 | return &Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#{ |
| 117 | Namescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Name.: stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.13 strings/TrimSuffix().(parts[1], "."+section+".gz"), |
| 118 | Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package.: p, |
| 119 | Sectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Section.: stringsscip-go gomod github.com/golang/go/src go1.13 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.13 strings/ToLower().(section), |
| 120 | Languagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Language.: lang, |
| 121 | LanguageTagscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#LanguageTag.: tag, |
| 122 | }, nil |
| 123 | } |
| 124 | |
| 125 | // FromServingPath constructs a manpage, gathering details from path |
| 126 | func FromServingPathscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/FromServingPath().(servingDir, path string) (*Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#, error) { |
| 127 | // *servingDir/<suite>/<binarypkg>/<name>.<section>.<lang> |
| 128 | relpath := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.13 strings/TrimPrefix().(path, filepathscip-go gomod github.com/golang/go/src go1.13 `path/filepath`/.Cleanscip-go gomod github.com/golang/go/src go1.13 `path/filepath`/Clean().(servingDir)+"/") |
| 129 | pparts := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Splitscip-go gomod github.com/golang/go/src go1.13 strings/Split().(relpath, "/") |
| 130 | if len(pparts) != 3 { |
| 131 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Unexpected path format %q", relpath) |
| 132 | } |
| 133 | |
| 134 | base := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.TrimSuffixscip-go gomod github.com/golang/go/src go1.13 strings/TrimSuffix().(filepathscip-go gomod github.com/golang/go/src go1.13 `path/filepath`/.Basescip-go gomod github.com/golang/go/src go1.13 `path/filepath`/Base().(path), ".gz") |
| 135 | // the first part can contain dots, so we need to “split from the right” |
| 136 | // TODO: this can be implemented more efficiently |
| 137 | allbparts := stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Splitscip-go gomod github.com/golang/go/src go1.13 strings/Split().(base, ".") |
| 138 | if len(allbparts) < 3 { |
| 139 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Unexpected file name format %q", base) |
| 140 | } |
| 141 | bparts := []string{ |
| 142 | stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Joinscip-go gomod github.com/golang/go/src go1.13 strings/Join().(allbparts[:len(allbparts)-2], "."), |
| 143 | allbparts[len(allbparts)-2], |
| 144 | allbparts[len(allbparts)-1], |
| 145 | } |
| 146 | |
| 147 | tag, err := tagscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/tag`/.FromLocalescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/tag`/FromLocale().(bparts[2]) |
| 148 | if err != nil { |
| 149 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Cannot parse language %q (in path %q): %v", bparts[2], path, err) |
| 150 | } |
| 151 | |
| 152 | if len(bparts) != 3 { |
| 153 | return nil, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Unexpected file name format %q", base) |
| 154 | } |
| 155 | |
| 156 | return &Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#{ |
| 157 | Namescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Name.: bparts[0], |
| 158 | Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package.: &PkgMetascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#{ |
| 159 | Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg.: pparts[1], |
| 160 | Suitescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Suite.: pparts[0], |
| 161 | }, |
| 162 | Sectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Section.: bparts[1], |
| 163 | Languagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Language.: bparts[2], |
| 164 | LanguageTagscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#LanguageTag.: tag, |
| 165 | }, nil |
| 166 | } |
| 167 | |
| 168 | func (m *Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#) Stringscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#String().() string { |
| 169 | return m.ServingPathscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#ServingPath().() |
| 170 | } |
| 171 | |
| 172 | func (m *Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#) ServingPathscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#ServingPath().() string { |
| 173 | return m.Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package..Suitescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Suite. + "/" + m.Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package..Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg. + "/" + m.Namescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Name. + "." + m.Sectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Section. + "." + m.Languagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Language. |
| 174 | } |
| 175 | |
| 176 | // RawPath returns the path to access the raw manpage equivalent of |
| 177 | // what is currently being served, i.e. locked to the current |
| 178 | // language. |
| 179 | func (m *Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#) RawPathscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#RawPath().() string { |
| 180 | return m.Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package..Suitescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Suite. + "/" + m.Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package..Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg. + "/" + m.Namescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Name. + "." + m.Sectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Section. + "." + m.Languagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Language. + ".gz" |
| 181 | } |
| 182 | |
| 183 | func (m *Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#) PermaLinkscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#PermaLink().() string { |
| 184 | return m.Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package..Suitescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Suite. + "/" + m.Packagescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Package..Binarypkgscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/PkgMeta#Binarypkg. + "/" + m.Namescip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Name. + "." + m.Sectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Section. |
| 185 | } |
| 186 | |
| 187 | func (m *Metascip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#) MainSectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#MainSection().() string { |
| 188 | return m.Sectionscip-go gomod github.com/Debian/debiman . `github.com/Debian/debiman/internal/manpage`/Meta#Section.[:1] |
| 189 | } |