Skip to content

Instantly share code, notes, and snippets.

@ChiChou
Created March 27, 2017 05:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ChiChou/e9d3569af22cadd3c8f925e9fcfdd4bd to your computer and use it in GitHub Desktop.
Save ChiChou/e9d3569af22cadd3c8f925e9fcfdd4bd to your computer and use it in GitHub Desktop.
fix header generated from class-dump
#!/bin/bash
#
# NOTE: You need to `brew install gnu-sed` on Mac
#
# by @codecolorist
# http://github.com/chichou
#
# fix some compilation error of headers generated by class-dump
#
# usage: fixheader.sh DIRECTORY
usage() {
echo "Fix compilation error of headers generated by class-dump"
echo
echo "Usage: $0 {PATH}"
}
if [ ! -d "$1" ]; then
echo "Invalid path $1"
usage
exit 1
fi
for filename in $1/*.h; do
if [ 'Darwin' == $(uname) ]; then
sed="gsed"
else
sed="sed"
fi
# remove "- (void).cxx_destruct;"
# replace "CDUnknownBlockType" with "id"
# fix missing NSObject.h
$sed -i -e '/- (void).cxx_destruct;/d' -e "s/\bCDUnknownBlockType\b/id/g" \
-e "s/#import \"NSObject.h\"/#import <Foundation\/NSObject.h>/" $flag $filename
# remove -Protocol suffix
if [[ $filename == *"-Protocol.h" ]]; then
echo "rename $filename"
mv "$filename" "${filename%-Protocol.h}.h";
fi
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment