The parser includes the parser input files and interface unit for the ASIHTTPRequest classes, so we'll use those files as examples and go over each file in some depth. The ASIHTTPRequest classes and header files to parse are available here:
http://allseeing-i.com/ASIHTTPRequest
The ASIHTTPRequest include file is Asihttp.inc and can be found in the parser's /uikit-skel/src/asihttp folder. You can create your own include file wherever you want and point the parser to it, as described below.
Here's what Asihttp.inc looks like:
{$include ASIHTTPRequest.inc} {$include ASIHTTPRequestDelegate.inc} {$include ASIProgressDelegate.inc} {$include ASICacheDelegate.inc} {$include ASIFormDataRequest.inc} {$include ASINetworkQueue.inc} {$include ASIDownloadCache.inc} {$include ASIInputStream.inc} {$include ASIDataDecompressor.inc} {$include ASIDataCompressor.inc} {$include ASIAuthenticationDialog.inc}To save yourself some typing, you can open a Terminal window, change to where the header files are, and use the ls command with the -1 switch (numeric digit "one") to list the header files in a single column. You can then copy and paste this list into your .inc file, add {$include to each line, and change the file extensions from .h to .inc}. For example:
ls -1 *.h ASIAuthenticationDialog.h ASICacheDelegate.h ASIDataCompressor.h ASIDataDecompressor.h ASIDownloadCache.h ASIFormDataRequest.h ASIHTTPRequest.h ASIHTTPRequestConfig.h ASIHTTPRequestDelegate.h ASIInputStream.h ASINetworkQueue.h ASIProgressDelegate.hThis list will be in alphabetical order and you can start out keeping the .inc files in that order too, although you may need to change the order later if you have classes that reference other classes.
Note that there's no include file for ASIHTTPRequestConfig.h - this file does not have anything we need, so we've left it out. Some frameworks or classes will have a small .h file that just includes all the other .h files - you can leave out that file as well.
<?xml version="1.0" encoding="UTF-8" ?> <frameworks> <framework> <name></name> <root></root> <headers></headers> <include_pattern></include_pattern> <header_pattern></header_pattern> <external_macro></external_macro> <ignore_lines> </ignore_lines> <ignore_types></ignore_types> <ignore_methods></ignore_methods> <replace_types> </replace_types> </framework> </frameworks>Note that even though we're defining these classes like a framework, they don't have to be in a framework. Actually, a framework is just a versioned library in a bundle (folder) with a .framework extension that contains the compiled library, headers and other files. From the point of view of the parser, there isn't much difference.
Here's the filled-in asihttp.xml file, with unused elements deleted (consult frameworks.xml for examples of how those elements are used):
<?xml version="1.0" encoding="UTF-8" ?> <frameworks> <framework> <name>asihttp</name> <root>/asihttp/Asihttp.inc</root> <!-- Change the following path if ASI header files (.h) are located elsewhere --> <headers>/Users/Shared/asi-http-request/Classes</headers> <include_pattern>{[$]+include (.*).inc}</include_pattern> <header_pattern>^(.*)\.h</header_pattern> <external_macro>extern</external_macro> </framework> </frameworks>It may still not be obvious what these elements should contain, so here's a brief explanation of each one:
php parser.phpHere's the command line for parsing the ASIHTTPRequest headers using the two files described above. Enter this all on one line:
php parser.php -all -frameworks=^foundation,^uikit,asihttp -aux_config=asihttp.xml -root=`pwd`/uikit-skel/src -framework_path=/Developer/Platforms/iPhoneOS.Platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/FrameworksSince this is quite a bit to type, it makes sense to put it in a script. See the parse-ios.sh script for examples of how to do this.
Here are the switches used:
grep "#import" *.hIf a header file depends on other frameworks, you'll see lines like this:
ASIAuthenticationDialog.h:#import <Foundation/Foundation.h> ASIAuthenticationDialog.h:#import <UIKit/UIKit.h>
unit Asihttp; {$mode delphi} {$modeswitch objectivec1} {$modeswitch cvar} {$packrecords c} interface {$linkframework CFNetwork} {$linkframework SystemConfiguration} {$linkframework MobileCoreServices} {$l libAsihttp.a} //if have static library, use instead of .o files below} (* {$l ASIAuthenticationDialog.o} {$l ASIDataCompressor.o} {$l ASIDataDecompressor.o} {$l ASIDownloadCache.o} {$l ASIFormDataRequest.o} {$l ASIHTTPRequest.o} {$l ASIInputStream.o} {$l ASINetworkQueue.o} {$l Reachability.o} *) {$IFDEF CPUARM} {$linklib libgcc_s.1} {$ENDIF}
http://allseeing-i.com/ASIHTTPRequest/Setup-instructions
Note that the units included in the uses statement (see below) may also do some of the required linking.
uses ctypes, CFStream, CGBase, CFHTTPMessage, CFHTTPAuthentication, {SCNetworkReachability,} SecBase, zlib, iPhoneAll, AnonClassDefinitionsAsihttp;
{$define INTERFACE} type BytefPtr = pBytef; //defined in zlib // sockaddr_inPtr = Pointer; //only needed for Reachability.inc {$define HEADER} {$include asihttp/Asihttp.inc} {$undef HEADER} {$define TYPES} {$include asihttp/Asihttp.inc} {$undef TYPES} {$define RECORDS} {$include asihttp/Asihttp.inc} {$undef RECORDS} type {$define FORWARD} {$include asihttp/Asihttp.inc} {$undef FORWARD} {$define PROTOCOLS} {$include asihttp/Asihttp.inc} {$undef PROTOCOLS} {$define CLASSES} {$include asihttp/Asihttp.inc} {$undef CLASSES} {$define FUNCTIONS} {$include asihttp/Asihttp.inc} {$undef FUNCTIONS} {$define EXTERNAL_SYMBOLS} {$include asihttp/Asihttp.inc} {$undef EXTERNAL_SYMBOLS} {$define USER_PATCHES} {$include asihttp/Asihttp.inc} {$undef USER_PATCHES} {$undef INTERFACE} implementation {$define IMPLEMENTATION} {$define USER_PATCHES} {$include asihttp/Asihttp.inc} {$undef USER_PATCHES} {$undef IMPLEMENTATION} end.
With the ASIDownloadCache.inc file that the parser creates, one edit needs to be made to eliminate a duplicate identifier error when compiling.
diff --unified=1 uikit-skel/src/asihttp/ASIDownloadCache.inc.sav uikit-skel/src/asihttp/ASIDownloadCache.inc >asihttp.patch
patch -p0 < asihttp.patch
macpgmr (at) fastermac (dot) net
First posted Nov. 12, 2011; last edited May 9, 2013.