Package: fpc-xcode-syntax-coloring
Version: 1.0
Revision: 2
Description: FreePascal syntax coloring for Xcode 
Suggests: fpc
License: GPL

# Unpack Phase:
Source: mirror:sourceforge:fink/XcodePascalSyntaxColoring-%v.zip
Source-Checksum: SHA256(459e8de83f7266e7700ef5e1c7cd1eb99da4c3a705a7ff6f3c4cc21943276e75)
SourceDirectory: Xcode Pascal Syntax Coloring

CompileScript:  echo Nothing to compile.

# Install Phase:
InstallScript: <<
#!/bin/sh -ev
  ls -alh

# create the file tmp.plist
  OBJP_VERSION="1.0"

  cat >'%b'/tmp.plist <<EOFCFG
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
	<dict>
		<key>Xcode.SourceCodeLanguage.Pascal</key>
		<dict>
			<key>conformsTo</key>
			<array>
				<dict>
					<key>identifier</key>
					<string>Xcode.SourceCodeLanguage.Generic</string>
				</dict>
			</array>
			<key>documentationAbbreviation</key>
			<string>pascal</string>
			<key>fileDataType</key>
			<array>
				<dict>
					<key>identifier</key>
					<string>public.pascal-source</string>
				</dict>
			</array>
			<key>id</key>
			<string>Xcode.SourceCodeLanguage.Pascal</string>
			<key>languageName</key>
			<string>Pascal</string>
			<key>languageSpecification</key>
			<string>xcode.lang.pascal</string>
			<key>name</key>
			<string>The Pascal Programming Language</string>
			<key>point</key>
			<string>Xcode.SourceCodeLanguage</string>
			<key>version</key>
			<string>$OBJP_VERSION</string>
		</dict>
	</dict>
</plist>
EOFCFG
  
  mkdir             -p %i/share/fpc-xcode-syntax-coloring
  mv tmp.plist         %i/share/fpc-xcode-syntax-coloring
  mv Pascal.xclangspec %i/share/fpc-xcode-syntax-coloring
<<

DocFiles: Pascal-READ-ME.txt

PostInstScript: <<
  if [ -x /usr/bin/xcode-select ]; then
    XCODE_PATH=`xcode-select -print-path`/..
  else
    echo Error: could not find the tool xcode-select
    exit 1
  fi

  if [ -z "$XCODE_PATH" ]; then
    echo Error: XCODE_PATH is empty
    exit 1
  else
    echo found: $XCODE_PATH
  fi

  DVTFOUNDATION_DIR=`find $XCODE_PATH/SharedFrameworks -name DVTFoundation.framework`

  if [ -z "$DVTFOUNDATION_DIR" ]; then
    echo Error: DVTFOUNDATION_DIR is empty
    exit 1
  else
    echo found: $DVTFOUNDATION_DIR
  fi

  PLUGINDATA_FILE=`find $DVTFOUNDATION_DIR -name DVTFoundation.xcplugindata`

  if [ -z "$PLUGINDATA_FILE" ]; then
    echo Error: PLUGINDATA_FILE is empty
    exit 1
  else
    echo found: $PLUGINDATA_FILE
  fi

  cp -p $PLUGINDATA_FILE $PLUGINDATA_FILE.bak

  if [ -x /usr/libexec/PlistBuddy ]; then
    echo Adding Pascal language specification entry.
    /usr/libexec/PlistBuddy -c "Merge %p/share/fpc-xcode-syntax-coloring/tmp.plist :plug-in:extensions" $PLUGINDATA_FILE
  else
    echo Error: could not find the tool PlistBuddy
    exit 1
  fi

  echo Adding link to Pascal language specification file.
  cp %p/share/fpc-xcode-syntax-coloring/Pascal.xclangspec $DVTFOUNDATION_DIR/Versions/A/Resources/

	echo
	echo "*** Restart Xcode to update the changes. ***"
<<

PostRmScript: <<
  if [ -x /usr/bin/xcode-select ]; then
    XCODE_PATH=`xcode-select -print-path`/..
  else
    echo Error: could not find the tool xcode-select
    exit 1
  fi

  if [ -z "$XCODE_PATH" ]; then
    echo Error: XCODE_PATH is empty
    exit 1
  else
    echo found: $XCODE_PATH
  fi

  DVTFOUNDATION_DIR=`find $XCODE_PATH/SharedFrameworks -name DVTFoundation.framework`

  if [ -z "$DVTFOUNDATION_DIR" ]; then
    echo Error: DVTFOUNDATION_DIR is empty
    exit 1
  else
    echo found: $DVTFOUNDATION_DIR
  fi

  PLUGINDATA_FILE=`find $DVTFOUNDATION_DIR -name DVTFoundation.xcplugindata`

  if [ -z "$PLUGINDATA_FILE" ]; then
    echo Error: PLUGINDATA_FILE is empty
    exit 1
  else
    echo found: $PLUGINDATA_FILE
  fi

  if [ -x /usr/libexec/PlistBuddy ]; then
    CHECK_ENTRY=`grep Xcode.SourceCodeLanguage.Pascal $PLUGINDATA_FILE`
    echo entry found: $CHECK_ENTRY
    if [ -n "$CHECK_ENTRY" ]; then
      echo Removing Pascal language specification entry.
      /usr/libexec/PlistBuddy -c "Delete :plug-in:extensions:Xcode.SourceCodeLanguage.Pascal" $PLUGINDATA_FILE
    fi
  else
    echo Error: could not find the tool PlistBuddy
    exit 1
  fi

  echo Removing Pascal language specification file.
  if [ -e $DVTFOUNDATION_DIR/Versions/A/Resources/Pascal.xclangspec ]
  then
    rm -f $DVTFOUNDATION_DIR/Versions/A/Resources/Pascal.xclangspec
  fi

	echo
	echo "*** Restart Xcode to update the changes. ***"
	echo
<<

DescDetail: <<
This package enables Pascal source code highlighting in Xcode.
<<

DescUsage: <<
After installation, Pascal files should have syntax coloring in Xcode.
<<

DescPort: <<
  The package is derived from Andy Hall's message on the Macintosh Pascal
  Mailing List <mac-pascal@lists.sonic.net> from 03-FEB-2017. 
  The scripts are derived from the installation script in the package.
<<

Maintainer: Karl-Michael Schindler <karl-michael.schindler@web.de>