home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / UNIX / Programming / class-dump-2.1.1-MIS / src / ObjcProtocol.m < prev    next >
Encoding:
Text File  |  1997-12-07  |  3.1 KB  |  129 lines

  1. //
  2. // $Id: ObjcProtocol.m,v 1.3 1997/12/07 22:31:45 nygard Exp $
  3. //
  4.  
  5. //
  6. //  This file is a part of class-dump v2, a utility for examining the
  7. //  Objective-C segment of Mach-O files.
  8. //  Copyright (C) 1997  Steve Nygard
  9. //
  10. //  This program is free software; you can redistribute it and/or modify
  11. //  it under the terms of the GNU General Public License as published by
  12. //  the Free Software Foundation; either version 2 of the License, or
  13. //  (at your option) any later version.
  14. //
  15. //  This program is distributed in the hope that it will be useful,
  16. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. //  GNU General Public License for more details.
  19. //
  20. //  You should have received a copy of the GNU General Public License
  21. //  along with this program; if not, write to the Free Software
  22. //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. //
  24. //  You may contact the author by:
  25. //     e-mail:  nygard@telusplanet.net
  26. //
  27.  
  28. #import "ObjcProtocol.h"
  29. #if NS_TARGET_MAJOR < 4
  30. #import <foundation/NSUtilities.h>
  31. #endif
  32. #import <stdio.h>
  33.  
  34. @implementation ObjcProtocol
  35.  
  36. - initWithProtocolName:(NSString *)protocolName
  37. {
  38.     if ([super init] == nil)
  39.         return nil;
  40.  
  41.     protocol_name = [protocolName retain];
  42.     protocol_names = [[NSMutableArray array] retain];
  43.     protocol_methods = [[NSMutableArray array] retain];
  44.  
  45.     return self;
  46. }
  47.  
  48. - (void) dealloc
  49. {
  50.     [protocol_name release];
  51.     [protocol_names release];
  52.     [protocol_methods release];
  53.  
  54.     [super dealloc];
  55. }
  56.  
  57. - (NSString *) protocolName
  58. {
  59.     return protocol_name;
  60. }
  61.  
  62. - (NSString *) sortableName
  63. {
  64.     return protocol_name;
  65. }
  66.  
  67. - (void) addProtocolNames:(NSArray *)newProtocolNames
  68. {
  69.     [protocol_names addObjectsFromArray:newProtocolNames];
  70. }
  71.  
  72. - (void) addProtocolMethod:(ObjcMethod *)newMethod
  73. {
  74.     [protocol_methods addObject:newMethod];
  75. }
  76.  
  77. - (void) addProtocolMethods:(NSArray *)newProtocolMethods
  78. {
  79.     [protocol_methods addObjectsFromArray:newProtocolMethods];
  80. }
  81.  
  82. - (void) showDefinition:(int)flags
  83. {
  84.     NSEnumerator *enumerator;
  85.     ObjcMethod *method;
  86.     NSString *protocolName;
  87.  
  88.     printf ("@protocol %s", [protocol_name cString]);
  89.  
  90.     if ([protocol_names count] > 0)
  91.     {
  92.         enumerator = [protocol_names objectEnumerator];
  93.         printf (" <");
  94.         protocolName = [enumerator nextObject];
  95.         if (protocolName != nil)
  96.         {
  97.             printf ("%s", [protocolName cString]);
  98.             
  99.             while (protocolName = [enumerator nextObject])
  100.             {
  101.                 printf (", %s", [protocolName cString]);
  102.             }
  103.         }
  104.  
  105.         printf (">");
  106.     }
  107.  
  108.     printf ("\n");
  109.  
  110.     if (flags & F_SORT_METHODS)
  111.         enumerator = [[protocol_methods sortedArrayUsingSelector:@selector (orderByMethodName:)] objectEnumerator];
  112.     else
  113.         enumerator = [protocol_methods objectEnumerator];
  114.  
  115.     while (method = [enumerator nextObject])
  116.     {
  117.         [method showMethod:'-'];
  118.         if (flags & F_SHOW_METHOD_ADDRESS)
  119.         {
  120.             printf ("\t// IMP=0x%08lx", [method address]);
  121.         }
  122.         printf ("\n");
  123.     }
  124.  
  125.     printf ("@end\n\n");
  126. }
  127.  
  128. @end
  129.