From 48c626678442526589750899cf07ac06ec3f574d Mon Sep 17 00:00:00 2001 From: TinXie Date: Wed, 24 Apr 2019 17:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=89=E8=A3=9D=20Logos=20?= =?UTF-8?q?=E8=AA=9E=E6=B3=95=E9=AB=98=E4=BA=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Logos-Xcode/src/AdditionalLanguages.plist | 37 +++++++++ Logos-Xcode/src/Logos.xc | 0 Logos-Xcode/src/Logos.xcspec | 15 ++++ Logos-Xcode/src/install.sh | 74 ++++++++++++++++++ Logos-Xcode/src/xclangspec_generator.py | 91 +++++++++++++++++++++++ bin/md-install | 14 ++++ 6 files changed, 231 insertions(+) create mode 100644 Logos-Xcode/src/AdditionalLanguages.plist create mode 100755 Logos-Xcode/src/Logos.xc create mode 100644 Logos-Xcode/src/Logos.xcspec create mode 100755 Logos-Xcode/src/install.sh create mode 100755 Logos-Xcode/src/xclangspec_generator.py diff --git a/Logos-Xcode/src/AdditionalLanguages.plist b/Logos-Xcode/src/AdditionalLanguages.plist new file mode 100644 index 0000000..e4eb2b9 --- /dev/null +++ b/Logos-Xcode/src/AdditionalLanguages.plist @@ -0,0 +1,37 @@ + + + + + Xcode.SourceCodeLanguage.Logos + + languageSpecification + xcode.lang.logos + fileDataType + + + identifier + com.apple.xcode.logos-source + + + id + Xcode.SourceCodeLanguage.Logos + point + Xcode.SourceCodeLanguage + languageName + Logos + version + 1.0 + documentationAbbreviation + logos + conformsTo + + + identifier + Xcode.SourceCodeLanguage.Generic + + + name + Logos Language + + + diff --git a/Logos-Xcode/src/Logos.xc b/Logos-Xcode/src/Logos.xc new file mode 100755 index 0000000..e69de29 diff --git a/Logos-Xcode/src/Logos.xcspec b/Logos-Xcode/src/Logos.xcspec new file mode 100644 index 0000000..afaf067 --- /dev/null +++ b/Logos-Xcode/src/Logos.xcspec @@ -0,0 +1,15 @@ +/* +* Logos.xcspec: Xcode file type for Logos +* +**/ + +( + { + Type = FileType; + Identifier = sourcecode.logos; + BasedOn = sourcecode; + Name = "Logos file"; + Extensions = ( xm ); + Language = "xcode.lang.logos"; + } +) \ No newline at end of file diff --git a/Logos-Xcode/src/install.sh b/Logos-Xcode/src/install.sh new file mode 100755 index 0000000..4db6c95 --- /dev/null +++ b/Logos-Xcode/src/install.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# +# pr0crustes version. +# Edited version of the work of Tiago Bastos and Alex Karahalios. +# Last edited 15/9/2018 +# + +set -e + +# Path were this script is located +Script_Path="/opt/MonkeyDev/Logos-Xcode/src" +# "$(dirname "$(realpath "$0")")" + +# Checks if has enought permission +echo "Checking Permissions..." +if [ $EUID -ne 0 ]; then + echo "$0 needs to be run as root." + echo " Check README for info." + echo " Aborting..." + exit 2 +fi + +# Assumes Xcode 4+. +echo "Checking Xcode..." +XCODE_MAJOR_VERSION=`xcodebuild -version | awk 'NR == 1 {print int($2)}'` +if [ "$XCODE_MAJOR_VERSION" -lt "4" ]; then + echo "Xcode 4+ not found." + exit 1 +fi + +# Check if Logos.xclangspec is present in the same folder +echo "Finding Logos.xclangspec..." +if [ ! -f $Script_Path/Logos.xclangspec ]; then + echo "Logos.xclangspec was not found." + echo "You probably forgot to run 'python(3) xclangspec_generator.py'" + exit 1 +fi + + +echo "It's highly recommended that, if you are installing for the first time, you make a backup of the folder /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources" +while true; do + read -p "Do you wish to continue? (Y)es, (N)o " yn + case $yn in + [Yy]*) + # This framework is found withing the Xcode.app package and is used when Xcode is a monolithic install (all contained in Xcode.app) + DVTFountain_Path="/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/" + + # Backup + cp "$DVTFountain_Path/DVTFoundation.xcplugindata" "$DVTFountain_Path/DVTFoundation.xcplugindata.bak" + + # Now merge in the additonal languages to DVTFoundation.xcplugindata + echo "Merging..." + /usr/libexec/PlistBuddy "$DVTFountain_Path/DVTFoundation.xcplugindata" -c "Merge $Script_Path/AdditionalLanguages.plist plug-in:extensions" + + # Copy in the xclangspecs for the languages (assumes in same directory as this shell script) + cp "$Script_Path/Logos.xclangspec" "$DVTFountain_Path" + + # Remove any cached Xcode plugins + rm -rf /private/var/folders/*/*/*/com.apple.DeveloperTools/*/Xcode/PlugInCache.xcplugincache + + # Final message + echo "Sucessfully Installed." + echo "Syntax coloring must be manually selected from the Editor - Syntax Coloring menu in Xcode." + exit 0 + ;; + [Nn]*) + echo "Exiting..." + exit 1 + ;; + *) + ;; + esac +done diff --git a/Logos-Xcode/src/xclangspec_generator.py b/Logos-Xcode/src/xclangspec_generator.py new file mode 100755 index 0000000..12aeb07 --- /dev/null +++ b/Logos-Xcode/src/xclangspec_generator.py @@ -0,0 +1,91 @@ +''' +# +# Run with python3 +# Script that generates the Logos xclangspec +# +# xclangspec_generator is a script created by pr0crustes (https://github.com/pr0crustes) +# that is provided as it is, without any warranty. +# pr0crustes @ 2018 - all rights reserved. +# +''' +import os + +global_new_keywords = [ + "// Start Logos Keywords", + "%group", + "%hook", + "%new", + "%subclass", + "%property", + "%end", + "%config", + "%hookf", + "%ctor", + "%dtor", + "%init", + "%class", + "%c", + "%orig", + "%log", + "// End Logos Keywords", + "// Start Other Keywords", + "NSLog", + "NSString", + "NSInteger", + "NSObject", + "// End Other Keywords" +] + + +global_ident1 = "Words = (" +global_ident2 = "Chars = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\";" +global_ident3 = "StartChars = \"@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_\";" + + +class XClangGenerator(object): + + def __init__(self): + self.objc_spec_file = "/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/ObjectiveC.xclangspec" + self.objc_spec_content = [] + self.new_lines = [] + + def __get_loaded_file(self): + print("Reading File...") + for line in open(self.objc_spec_file, 'r'): + if line.strip() and not line.strip().startswith("/"): + self.objc_spec_content.append(line) + + def __get_parsed_file(self): + print("Parsing File...") + for i in range(len(self.objc_spec_content)): + line = self.objc_spec_content[i].replace("objc", "logos") + self.new_lines.append(line) + if global_ident1 in line and i > 3 and global_ident2 in self.objc_spec_content[i-1] and global_ident3 in self.objc_spec_content[i-2]: + print("Inserting Logos Keywords Into New File...") + for new_word in global_new_keywords: + if new_word.strip().startswith("//"): + self.new_lines.append("\t\t\t\t" + new_word + "\n") + else: + self.new_lines.append("\t\t\t\t\"" + new_word + "\",\n") + + def __save_file(self): + print("Saving New File...") + with open("Logos.xclangspec", "w") as file: + file.write("// Logos xclangspec was generated by spec_gen\n") + file.write("// Script made by pr0crustes\n") + for line in self.new_lines: + file.write(line) + + def execute(self): + self.__get_loaded_file() + self.__get_parsed_file() + self.__save_file() + print("XClangSpec Generator was successfully runned.") + + +if __name__ == '__main__': + + os.rename("/opt/MonkeyDev/Logos-Xcode/src/Logos.xc", "/opt/MonkeyDev/Logos-Xcode/src/Logos.xclangspec") + gen = XClangGenerator() + gen.execute() + diff --git a/bin/md-install b/bin/md-install index bfbb882..000bd27 100755 --- a/bin/md-install +++ b/bin/md-install @@ -295,6 +295,18 @@ function writeDictToSpecification(){ #args: filePath, content /usr/libexec/PlistBuddy -x -c "merge $tempfile 0" "$filePath" > /dev/null } +# 安裝Logos語法高亮 +function installXcode10LogosSupports(){ + + echo "install Xcode10 Logos Supports..." + chmod +x $MonkeyDevPath/Logos-Xcode/src/xclangspec_generator.py + python $MonkeyDevPath/Logos-Xcode/src/xclangspec_generator.py + chmod +x $MonkeyDevPath/Logos-Xcode/src/install.sh + sudo sh -x $MonkeyDevPath/Logos-Xcode/src/install.sh + +} + + # start it # 创建/opt/MonkeyDev mkdir -p "$MonkeyDevPath" || \ @@ -374,4 +386,6 @@ if [[ $hasProductTypeForCommandLineTool != "true" ]]; then writeDictToSpecification "$specificationFile" "$toolDict" fi +installXcode10LogosSupports + exit 0