#!/bin/bash #-------- Make AS Def Script ----------------------------------------------------------------------------- #Author: Michael Bianco, , http://developer.mabwebdesign.com/ #Description: Parses through AS files ending in .as, or .actionscript and pulls out variable, class, and function defitions # and prepares them for use in xcode. This script is *not* bullet proof, and will include all variables declared with the 'var' keyword in the # output file. Because of this the different type of definitions are seperated into differenet temporary files so you can easily include only # which definitions you want (I.E. Functions, Variables, Class definitions) by changing the cat command near the end of the script. # This script only supports AS2 class construction syntax Functions that have no arguments (Ex. doSomething()), are stripped of their parenthesis. #--------------------------------------------------------------------------------------------------------- #SAMPLE COMMAND: makeXcodeDefFile.bash "/Users/Mike/Library/Application Support/Macromedia/Flash MX 2004/en/Configuration/Classes" ~/Desktop/out.txt #Pattern comparison, string operators good ref page: http://linuxreviews.org/beginner/abs-guide/en/x2689.html if (($# < 2)); then echo "You must specify the class directory for the first argument, and a path to the output actionscript def file for the second argument." exit 0 fi #set the global variables CLASS_PATH="$1" DEF_FILE="$2" #clear the output file if it has already been created if [ -e "$DEF_FILE" ]; then : > $DEF_FILE fi #temp def files CLASS_DEF_FILE=`mktemp` FUNCTION_DEF_FILE=`mktemp` VAR_DEF_FILE=`mktemp` #addition AS language keywords ADDITIONAL_KEYWORDS=" import extends implements intrinsic class public private var static super null undefined false true Void this for while do return new if else switch case break function continue try catch finally" ADD_ADDITIONAL_KEYWORDS=1 ADD_FUNCTION_KEYWORDS=1 ADD_FUNCTION_WITH_ARGS=1 find "$CLASS_PATH" -name *.as -or -name *.actionscript | \ while read path; do path=${path/\/\//\/} #get rid of two /'s in the file name classDef=`grep "class [^{]*" "$path"` echo $classDef | egrep "(//|/\*)" > /dev/null #check to make sure the word class isn't being used in a comment. This is a lazy check, only checking to see if 'class' is on the same line as the comment if [ $? != 0 ]; then classDef=`echo $classDef | grep -o 'class [^ ]*\b'` classDef=${classDef:6} #get rid of 'class ' echo "\"$classDef\"," >> $CLASS_DEF_FILE fi #--------- extract variable definitions ---------- varDefs=`egrep -o 'var [^:;=]*' "$path"` #sweet, setting multiline output to a single var strips all newlines #remove all commas & double spaces varDefs=${varDefs//,/" "} varDefs=${varDefs//" "/" "} for var in $varDefs; do len=${#var} if [ "$var" != "var" ] && (( ${#var} >= 2 )); then echo "\"$var\"," >> $VAR_DEF_FILE fi done #extract all function defs functionDefs=`egrep -o 'function [^)]+\)' "$path"` #get rid of all the non-seperating spaces functionDefs=${functionDefs//function/} functionDefs=${functionDefs//" ,"/,} functionDefs=${functionDefs//", "/,} functionDefs=${functionDefs//": "/:} functionDefs=${functionDefs//"( "/(} functionDefs=${functionDefs//" )"/)} functionDefs=${functionDefs//" ("/"("} for funct in $functionDefs; do tempStr=${funct:(-2)} #must put negative index in paranthesis if [ "$tempStr" == "()" ]; then #no arguments in the function echo "\"${funct/()/}\"," >> $FUNCTION_DEF_FILE else #there is arguments. group all arguments with <#'s & #>'s funct=${funct/(/"(<#"} funct=${funct/)/"#>)"} funct=${funct//,/"#>,<#"} if [ $ADD_FUNCTION_WITH_ARGS == 1 ]; then echo "\"$funct\"," >> $FUNCTION_DEF_FILE fi if [ $ADD_FUNCTION_KEYWORDS == 1 ]; then funct=${funct/(*/} #remove the () part of the function echo "\"$funct\"," >> $FUNCTION_DEF_FILE fi fi done done cat $FUNCTION_DEF_FILE $VAR_DEF_FILE $CLASS_DEF_FILE > "$DEF_FILE" #combine all the temp def files into the main output file #is wanted, add all the additional keywords if [ $ADD_ADDITIONAL_KEYWORDS ]; then for keyword in $ADDITIONAL_KEYWORDS; do echo "\"$keyword\"," >> "$DEF_FILE" done fi sort "$DEF_FILE" | uniq > "$DEF_FILE" #sort the file and remove duplicates #clean up the temporary files made rm -f $FUNCTION_DEF_FILE rm -f $VAR_DEF_FILE rm -f $CLASS_DEF_FILE exit 0