├── Dictionary Preferences.png ├── Dictionary.css ├── Dictionary.png ├── Info.plist ├── LICENSE ├── Makefile ├── ManDictionary.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── usrsse2.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── ManDictionary └── main.swift ├── README.md └── Terminal.png /Dictionary Preferences.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/usr-sse2/ManToDictionary/2dff509acee4196fb49e7e1340d0e972ccba3bfd/Dictionary Preferences.png -------------------------------------------------------------------------------- /Dictionary.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | @namespace d url(http://www.apple.com/DTDs/DictionaryService-1.0.rng); 3 | 4 | d|entry { 5 | } 6 | 7 | pre { 8 | white-space: pre-wrap; 9 | word-break: keep-all; 10 | word-wrap: break-word; 11 | } 12 | 13 | h1 { 14 | font-size: 150%; 15 | } 16 | 17 | h3 { 18 | font-size: 100%; 19 | } 20 | 21 | span.column { 22 | display: block; 23 | border: solid 2px #c0c0c0; 24 | margin-left: 2em; 25 | margin-right: 2em; 26 | margin-top: 0.5em; 27 | margin-bottom: 0.5em; 28 | padding: 0.5em; 29 | } 30 | 31 | @media (prefers-dark-interface) 32 | { 33 | body { 34 | color: white; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Dictionary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/usr-sse2/ManToDictionary/2dff509acee4196fb49e7e1340d0e972ccba3bfd/Dictionary.png -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleIdentifier 8 | ru.usrsse2.ManDictionary 9 | CFBundleName 10 | MAN_SECTION_PLACEHOLDER 11 | CFBundleShortVersionString 12 | 1.0 13 | DCSDictionaryCopyright 14 | This dictionary was created from man pages using ManToDictionary by usrsse2 (https://github.com/usr-sse2/ManToDictionary). All contents belong to creators of the original man pages. 15 | DCSDictionaryManufacturerName 16 | usrsse2 17 | DCSDictionaryFrontMatterReferenceID 18 | front_back_matter 19 | DCSDictionaryUseSystemAppearance 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Michael Belyaev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile 3 | # 4 | # 5 | # 6 | 7 | ########################### 8 | 9 | # You need to edit these values. 10 | 11 | DICT_SRC_PATH = dictionary.xml 12 | CSS_PATH = Dictionary.css 13 | PLIST_PATH = Info.plist 14 | 15 | DICT_BUILD_OPTS = 16 | # Suppress adding supplementary key. 17 | # DICT_BUILD_OPTS = -s 0 # Suppress adding supplementary key. 18 | 19 | ########################### 20 | 21 | # The DICT_BUILD_TOOL_DIR value is used also in "build_dict.sh" script. 22 | # You need to set it when you invoke the script directly. 23 | 24 | DICT_BUILD_TOOL_DIR = "/DevTools/Utilities/Dictionary Development Kit" 25 | DICT_BUILD_TOOL_BIN = "$(DICT_BUILD_TOOL_DIR)/bin" 26 | 27 | ########################### 28 | 29 | DICT_DEV_KIT_OBJ_DIR = ./objects 30 | export DICT_DEV_KIT_OBJ_DIR 31 | 32 | DESTINATION_FOLDER = ~/Library/Dictionaries 33 | RM = /bin/rm 34 | 35 | ########################### 36 | 37 | all: 38 | "$(DICT_BUILD_TOOL_BIN)/build_dict.sh" $(DICT_BUILD_OPTS) $(DICT_NAME) $(DICT_SRC_PATH) $(CSS_PATH) $(PLIST_PATH) 39 | echo "Done." 40 | 41 | 42 | install: 43 | echo "Installing into $(DESTINATION_FOLDER)". 44 | mkdir -p $(DESTINATION_FOLDER) 45 | ditto --noextattr --norsrc $(DICT_DEV_KIT_OBJ_DIR)/$(DICT_NAME).dictionary $(DESTINATION_FOLDER)/$(DICT_NAME).dictionary 46 | touch $(DESTINATION_FOLDER) 47 | echo "Done." 48 | echo "To test the new dictionary, try Dictionary.app." 49 | 50 | clean: 51 | $(RM) -rf $(DICT_DEV_KIT_OBJ_DIR) 52 | -------------------------------------------------------------------------------- /ManDictionary.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 355AA76322704D0500392DC6 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 355AA76222704D0500392DC6 /* main.swift */; }; 11 | 355AA76C227394D800392DC6 /* Makefile in Sources */ = {isa = PBXBuildFile; fileRef = 355AA769227394D800392DC6 /* Makefile */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXCopyFilesBuildPhase section */ 15 | 355AA75D22704D0500392DC6 /* CopyFiles */ = { 16 | isa = PBXCopyFilesBuildPhase; 17 | buildActionMask = 2147483647; 18 | dstPath = /usr/share/man/man1/; 19 | dstSubfolderSpec = 0; 20 | files = ( 21 | ); 22 | runOnlyForDeploymentPostprocessing = 1; 23 | }; 24 | /* End PBXCopyFilesBuildPhase section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | 355AA75F22704D0500392DC6 /* ManDictionary */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ManDictionary; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 355AA76222704D0500392DC6 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 29 | 355AA769227394D800392DC6 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = ""; }; 30 | 355AA76A227394D800392DC6 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | 355AA76B227394D800392DC6 /* Dictionary.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = Dictionary.css; sourceTree = ""; }; 32 | 35BC9FA02274632A00896C94 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 355AA75C22704D0500392DC6 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 355AA75622704D0400392DC6 = { 47 | isa = PBXGroup; 48 | children = ( 49 | 35BC9FA02274632A00896C94 /* README.md */, 50 | 355AA76B227394D800392DC6 /* Dictionary.css */, 51 | 355AA76A227394D800392DC6 /* Info.plist */, 52 | 355AA769227394D800392DC6 /* Makefile */, 53 | 355AA76122704D0500392DC6 /* ManDictionary */, 54 | 355AA76022704D0500392DC6 /* Products */, 55 | ); 56 | sourceTree = ""; 57 | }; 58 | 355AA76022704D0500392DC6 /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 355AA75F22704D0500392DC6 /* ManDictionary */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | 355AA76122704D0500392DC6 /* ManDictionary */ = { 67 | isa = PBXGroup; 68 | children = ( 69 | 355AA76222704D0500392DC6 /* main.swift */, 70 | ); 71 | path = ManDictionary; 72 | sourceTree = ""; 73 | }; 74 | /* End PBXGroup section */ 75 | 76 | /* Begin PBXNativeTarget section */ 77 | 355AA75E22704D0500392DC6 /* ManDictionary */ = { 78 | isa = PBXNativeTarget; 79 | buildConfigurationList = 355AA76622704D0500392DC6 /* Build configuration list for PBXNativeTarget "ManDictionary" */; 80 | buildPhases = ( 81 | 355AA75B22704D0500392DC6 /* Sources */, 82 | 355AA75C22704D0500392DC6 /* Frameworks */, 83 | 355AA75D22704D0500392DC6 /* CopyFiles */, 84 | ); 85 | buildRules = ( 86 | ); 87 | dependencies = ( 88 | ); 89 | name = ManDictionary; 90 | productName = ManDictionary; 91 | productReference = 355AA75F22704D0500392DC6 /* ManDictionary */; 92 | productType = "com.apple.product-type.tool"; 93 | }; 94 | /* End PBXNativeTarget section */ 95 | 96 | /* Begin PBXProject section */ 97 | 355AA75722704D0400392DC6 /* Project object */ = { 98 | isa = PBXProject; 99 | attributes = { 100 | LastSwiftUpdateCheck = 1020; 101 | LastUpgradeCheck = 1020; 102 | ORGANIZATIONNAME = usrsse2; 103 | TargetAttributes = { 104 | 355AA75E22704D0500392DC6 = { 105 | CreatedOnToolsVersion = 10.2.1; 106 | }; 107 | }; 108 | }; 109 | buildConfigurationList = 355AA75A22704D0400392DC6 /* Build configuration list for PBXProject "ManDictionary" */; 110 | compatibilityVersion = "Xcode 9.3"; 111 | developmentRegion = en; 112 | hasScannedForEncodings = 0; 113 | knownRegions = ( 114 | en, 115 | ); 116 | mainGroup = 355AA75622704D0400392DC6; 117 | productRefGroup = 355AA76022704D0500392DC6 /* Products */; 118 | projectDirPath = ""; 119 | projectRoot = ""; 120 | targets = ( 121 | 355AA75E22704D0500392DC6 /* ManDictionary */, 122 | ); 123 | }; 124 | /* End PBXProject section */ 125 | 126 | /* Begin PBXSourcesBuildPhase section */ 127 | 355AA75B22704D0500392DC6 /* Sources */ = { 128 | isa = PBXSourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | 355AA76C227394D800392DC6 /* Makefile in Sources */, 132 | 355AA76322704D0500392DC6 /* main.swift in Sources */, 133 | ); 134 | runOnlyForDeploymentPostprocessing = 0; 135 | }; 136 | /* End PBXSourcesBuildPhase section */ 137 | 138 | /* Begin XCBuildConfiguration section */ 139 | 355AA76422704D0500392DC6 /* Debug */ = { 140 | isa = XCBuildConfiguration; 141 | buildSettings = { 142 | ALWAYS_SEARCH_USER_PATHS = NO; 143 | CLANG_ANALYZER_NONNULL = YES; 144 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 145 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 146 | CLANG_CXX_LIBRARY = "libc++"; 147 | CLANG_ENABLE_MODULES = YES; 148 | CLANG_ENABLE_OBJC_ARC = YES; 149 | CLANG_ENABLE_OBJC_WEAK = YES; 150 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 151 | CLANG_WARN_BOOL_CONVERSION = YES; 152 | CLANG_WARN_COMMA = YES; 153 | CLANG_WARN_CONSTANT_CONVERSION = YES; 154 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 155 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 156 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 157 | CLANG_WARN_EMPTY_BODY = YES; 158 | CLANG_WARN_ENUM_CONVERSION = YES; 159 | CLANG_WARN_INFINITE_RECURSION = YES; 160 | CLANG_WARN_INT_CONVERSION = YES; 161 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 162 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 163 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 164 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 165 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 166 | CLANG_WARN_STRICT_PROTOTYPES = YES; 167 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 168 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 169 | CLANG_WARN_UNREACHABLE_CODE = YES; 170 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 171 | CODE_SIGN_IDENTITY = "-"; 172 | COPY_PHASE_STRIP = NO; 173 | DEBUG_INFORMATION_FORMAT = dwarf; 174 | ENABLE_STRICT_OBJC_MSGSEND = YES; 175 | ENABLE_TESTABILITY = YES; 176 | GCC_C_LANGUAGE_STANDARD = gnu11; 177 | GCC_DYNAMIC_NO_PIC = NO; 178 | GCC_NO_COMMON_BLOCKS = YES; 179 | GCC_OPTIMIZATION_LEVEL = 0; 180 | GCC_PREPROCESSOR_DEFINITIONS = ( 181 | "DEBUG=1", 182 | "$(inherited)", 183 | ); 184 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 185 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 186 | GCC_WARN_UNDECLARED_SELECTOR = YES; 187 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 188 | GCC_WARN_UNUSED_FUNCTION = YES; 189 | GCC_WARN_UNUSED_VARIABLE = YES; 190 | MACOSX_DEPLOYMENT_TARGET = 10.14; 191 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 192 | MTL_FAST_MATH = YES; 193 | ONLY_ACTIVE_ARCH = YES; 194 | SDKROOT = macosx; 195 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 196 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 197 | }; 198 | name = Debug; 199 | }; 200 | 355AA76522704D0500392DC6 /* Release */ = { 201 | isa = XCBuildConfiguration; 202 | buildSettings = { 203 | ALWAYS_SEARCH_USER_PATHS = NO; 204 | CLANG_ANALYZER_NONNULL = YES; 205 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 206 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 207 | CLANG_CXX_LIBRARY = "libc++"; 208 | CLANG_ENABLE_MODULES = YES; 209 | CLANG_ENABLE_OBJC_ARC = YES; 210 | CLANG_ENABLE_OBJC_WEAK = YES; 211 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 212 | CLANG_WARN_BOOL_CONVERSION = YES; 213 | CLANG_WARN_COMMA = YES; 214 | CLANG_WARN_CONSTANT_CONVERSION = YES; 215 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 216 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 217 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 218 | CLANG_WARN_EMPTY_BODY = YES; 219 | CLANG_WARN_ENUM_CONVERSION = YES; 220 | CLANG_WARN_INFINITE_RECURSION = YES; 221 | CLANG_WARN_INT_CONVERSION = YES; 222 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 223 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 224 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 225 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 226 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 227 | CLANG_WARN_STRICT_PROTOTYPES = YES; 228 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 229 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 230 | CLANG_WARN_UNREACHABLE_CODE = YES; 231 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 232 | CODE_SIGN_IDENTITY = "-"; 233 | COPY_PHASE_STRIP = NO; 234 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 235 | ENABLE_NS_ASSERTIONS = NO; 236 | ENABLE_STRICT_OBJC_MSGSEND = YES; 237 | GCC_C_LANGUAGE_STANDARD = gnu11; 238 | GCC_NO_COMMON_BLOCKS = YES; 239 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 240 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 241 | GCC_WARN_UNDECLARED_SELECTOR = YES; 242 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 243 | GCC_WARN_UNUSED_FUNCTION = YES; 244 | GCC_WARN_UNUSED_VARIABLE = YES; 245 | MACOSX_DEPLOYMENT_TARGET = 10.14; 246 | MTL_ENABLE_DEBUG_INFO = NO; 247 | MTL_FAST_MATH = YES; 248 | SDKROOT = macosx; 249 | SWIFT_COMPILATION_MODE = wholemodule; 250 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 251 | }; 252 | name = Release; 253 | }; 254 | 355AA76722704D0500392DC6 /* Debug */ = { 255 | isa = XCBuildConfiguration; 256 | buildSettings = { 257 | CODE_SIGN_STYLE = Automatic; 258 | PRODUCT_NAME = "$(TARGET_NAME)"; 259 | SWIFT_VERSION = 5.0; 260 | }; 261 | name = Debug; 262 | }; 263 | 355AA76822704D0500392DC6 /* Release */ = { 264 | isa = XCBuildConfiguration; 265 | buildSettings = { 266 | CODE_SIGN_STYLE = Automatic; 267 | PRODUCT_NAME = "$(TARGET_NAME)"; 268 | SWIFT_VERSION = 5.0; 269 | }; 270 | name = Release; 271 | }; 272 | /* End XCBuildConfiguration section */ 273 | 274 | /* Begin XCConfigurationList section */ 275 | 355AA75A22704D0400392DC6 /* Build configuration list for PBXProject "ManDictionary" */ = { 276 | isa = XCConfigurationList; 277 | buildConfigurations = ( 278 | 355AA76422704D0500392DC6 /* Debug */, 279 | 355AA76522704D0500392DC6 /* Release */, 280 | ); 281 | defaultConfigurationIsVisible = 0; 282 | defaultConfigurationName = Release; 283 | }; 284 | 355AA76622704D0500392DC6 /* Build configuration list for PBXNativeTarget "ManDictionary" */ = { 285 | isa = XCConfigurationList; 286 | buildConfigurations = ( 287 | 355AA76722704D0500392DC6 /* Debug */, 288 | 355AA76822704D0500392DC6 /* Release */, 289 | ); 290 | defaultConfigurationIsVisible = 0; 291 | defaultConfigurationName = Release; 292 | }; 293 | /* End XCConfigurationList section */ 294 | }; 295 | rootObject = 355AA75722704D0400392DC6 /* Project object */; 296 | } 297 | -------------------------------------------------------------------------------- /ManDictionary.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ManDictionary.xcodeproj/xcuserdata/usrsse2.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ManDictionary.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ManDictionary/main.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import CoreFoundation 3 | 4 | class AttributedCharacter { 5 | let value : UInt8 6 | let bold : Bool 7 | let understrike : Bool 8 | init(value : UInt8, bold : Bool, understrike : Bool) { 9 | self.value = value 10 | self.bold = bold 11 | self.understrike = understrike 12 | } 13 | private func understrike(_ str : String) -> String { 14 | if understrike { 15 | return "\(str)" 16 | } 17 | return str 18 | } 19 | private func bold(_ str : String) -> String { 20 | if bold { 21 | return "\(str)" 22 | } 23 | return str 24 | } 25 | 26 | var escapedString : String { 27 | get { 28 | let string = String(bytes: [value], encoding: String.Encoding.isoLatin1)! 29 | if self.value == 0x0a { 30 | return "
" 31 | } 32 | return bold(understrike(CFXMLCreateStringByEscapingEntities(kCFAllocatorDefault, string as CFString, nil)! as String)) 33 | } 34 | } 35 | } 36 | 37 | struct FileOutputStream: TextOutputStream { 38 | let fileHandle : FileHandle 39 | 40 | init(path : String) { 41 | FileManager.default.createFile(atPath: path, contents: nil, attributes: nil) 42 | fileHandle = FileHandle(forWritingAtPath: path)! 43 | } 44 | 45 | func closeFile() { 46 | fileHandle.closeFile() 47 | } 48 | 49 | mutating func write(_ string: String) { 50 | fileHandle.write(string.data(using: String.Encoding.utf8)!) 51 | } 52 | } 53 | 54 | func makeXml(paths : [String], outputFile : String) { 55 | var stream = FileOutputStream(path: outputFile) 56 | var ids = Set() 57 | print("", to: &stream) 58 | print("", to: &stream) 59 | let fileManager = FileManager.default 60 | do { 61 | for section in paths { 62 | if !fileManager.fileExists(atPath: section) { 63 | continue 64 | } 65 | for file in try fileManager.contentsOfDirectory(atPath: section) { 66 | let name = file.split(separator: ".").dropLast().joined(separator: ".") 67 | let sectionNumber = file.split(separator: ".").last! 68 | let id = "\(name)(\(sectionNumber))" 69 | let (inserted, _ ) = ids.insert(id) 70 | if inserted { 71 | print("", to: &stream) 72 | 73 | print("", to: &stream) 74 | print("", to: &stream) 75 | 76 | print("
", to: &stream)
 77 |                     let pipe = Pipe()
 78 |                     let process = Process()
 79 |                     process.launchPath = "/usr/bin/man"
 80 |                     process.arguments = ["\(section)/\(file)"]
 81 |                     process.standardOutput = pipe
 82 |                     process.launch()
 83 |                     let data = pipe.fileHandleForReading.readDataToEndOfFile()
 84 |                     var newData = [AttributedCharacter]()
 85 |                     var i = 0
 86 |                     while i < data.count {
 87 |                         if data[i] == 0x08 {
 88 |                             if newData.count > 0 && i + 1 < data.count {
 89 |                                 let last = newData.last!.value
 90 |                                 newData.removeLast(1)
 91 |                                 newData.append(AttributedCharacter(value: data[i + 1], bold: last == data[i + 1], understrike: last == 0x5f && data[i + 1] != 0x5f))
 92 |                                 i += 1
 93 |                             }
 94 |                         }
 95 |                         else {
 96 |                             newData.append(AttributedCharacter(value: data[i], bold: false, understrike: false))
 97 |                         }
 98 |                         i += 1
 99 |                     }
100 |                     pipe.fileHandleForReading.closeFile()
101 |                     pipe.fileHandleForWriting.closeFile()
102 |                     print(newData.map({$0.escapedString}).joined()
103 |                         .replacingOccurrences(of: "", with: "")
104 |                         .replacingOccurrences(of: "", with: "")
105 |                         //.replacingOccurrences(of: "-
", with: "") // there are spaces; man by itself doesn't handle such case 106 | , to: &stream) 107 | print("
", to: &stream) 108 | 109 | print("
", to: &stream) 110 | } 111 | } 112 | } 113 | } 114 | catch let error as NSError { 115 | print("Ooops! Something went wrong: \(error)") 116 | } 117 | print("
", to: &stream) 118 | stream.closeFile() 119 | } 120 | 121 | let manDirs = ["/usr/share/man", "/usr/local/share/man", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/share/man/"] 122 | var manSections = Set() 123 | let fileManager = FileManager.default 124 | for manDir in manDirs { 125 | if !fileManager.fileExists(atPath: manDir) { 126 | continue 127 | } 128 | for section in try! fileManager.contentsOfDirectory(atPath: manDir).filter({$0.starts(with: "man")}) { 129 | manSections.insert(section) 130 | } 131 | } 132 | 133 | let sectionList = Array(manSections.sorted()) 134 | DispatchQueue.concurrentPerform(iterations: sectionList.count) { (index) in 135 | let section = sectionList[index] 136 | print("Processing section \(section)") 137 | try! fileManager.createDirectory(atPath: section, withIntermediateDirectories: false, attributes: nil) 138 | makeXml(paths: manDirs.map({"\($0)/\(section)"}), outputFile: "\(section)/dictionary.xml") 139 | let infoPlist = NSMutableDictionary(contentsOfFile: "Info.plist")! 140 | infoPlist[kCFBundleNameKey!] = "Man Section \(section.replacingOccurrences(of: "man", with: ""))" 141 | infoPlist.write(toFile: "\(section)/Info.plist", atomically: false) 142 | try! fileManager.copyItem(atPath: "Dictionary.css", toPath: "\(section)/Dictionary.css") 143 | var makefile = "DICT_NAME = \(section)" 144 | makefile.append(try! String(contentsOfFile: "Makefile")) 145 | try! makefile.write(toFile: "\(section)/Makefile", atomically: false, encoding: String.Encoding.utf8) 146 | let task = Process() 147 | task.launchPath = "/usr/bin/make" 148 | task.arguments = ["all", "install"] 149 | task.currentDirectoryPath = section 150 | task.launch() 151 | task.waitUntilExit() 152 | print("") 153 | } 154 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ManToDictionary 2 | This is a program to convert `man` pages to Apple Dictionary dictionaries. It allows to find manuals for shell commands and C functions using **Dictionary** app, **Look Up** context menu item, or **Look up & data detectors** trackpad gesture in **Terminal**, **Safari**, **TextEdit** and other applications. 3 | 4 | ![Lookup from Terminal](https://github.com/usr-sse2/ManToDictionary/raw/master/Terminal.png) 5 | 6 | ![Dictionary app](https://github.com/usr-sse2/ManToDictionary/raw/master/Dictionary.png) 7 | 8 | 9 | ### Usage 10 | 0. Download **Additional Tools for Xcode** from https://developer.apple.com and put Dictionary Development Kit from it to `/DevTools/Utilities/Dictionary Development Kit` (path can be changed in `Makefile`). 11 | 1. Create `~/Library/Dictionaries` directory, if it doesn't exist. 12 | 2. Specify all man page directories in `manDirs` array in `main.swift` 13 | 3. Compile and run the program. It will build dictionaries and install them in `~/Library/Dictionaries`. 14 | 4. Open **Dictionary** application and enable man sections in preferences: 15 | 16 | ![Dictionary Preferences](https://github.com/usr-sse2/ManToDictionary/raw/master/Dictionary%20Preferences.png) 17 | 18 | Now you can use the dictionaries. 19 | -------------------------------------------------------------------------------- /Terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/usr-sse2/ManToDictionary/2dff509acee4196fb49e7e1340d0e972ccba3bfd/Terminal.png --------------------------------------------------------------------------------