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 / ObjcCategory.m < prev    next >
Encoding:
Text File  |  1997-12-07  |  3.2 KB  |  118 lines

  1. //
  2. // $Id: ObjcCategory.m,v 1.3 1997/12/07 22:31:42 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 "ObjcCategory.h"
  29. #import "ObjcMethod.h"
  30. #if NS_TARGET_MAJOR < 4
  31. #import <foundation/NSUtilities.h>
  32. #endif
  33. #import <stdio.h>
  34.  
  35. @implementation ObjcCategory
  36.  
  37. - initWithClassName:(NSString *)className categoryName:(NSString *)categoryName
  38. {
  39.     if ([super init] == nil)
  40.         return nil;
  41.  
  42.     class_name = [className retain];
  43.     category_name = [categoryName retain];
  44.     class_methods = [[NSMutableArray array] retain];
  45.     instance_methods = [[NSMutableArray array] retain];
  46.     protocols = [[NSMutableArray array] retain];
  47.  
  48.     return self;
  49. }
  50.  
  51. - (void) dealloc
  52. {
  53.     [class_name release];
  54.     [category_name release];
  55.     [class_methods release];
  56.     [instance_methods release];
  57.     [protocols release];
  58.     
  59.     [super dealloc];
  60. }
  61.  
  62. - (NSString *) sortableName
  63. {
  64.     return [NSString stringWithFormat:@"%@ %@", class_name, category_name];
  65. }
  66.  
  67. - (void) addClassMethods:(NSArray *)newClassMethods
  68. {
  69.     [class_methods addObjectsFromArray:newClassMethods];
  70. }
  71.  
  72. - (void) addInstanceMethods:(NSArray *)newInstanceMethods
  73. {
  74.     [instance_methods addObjectsFromArray:newInstanceMethods];
  75. }
  76.  
  77. - (void) showDefinition:(int)flags
  78. {
  79.     NSEnumerator *enumerator;
  80.     ObjcMethod *method;
  81.  
  82.     printf ("@interface %s(%s)\n", [class_name cString], [category_name cString]);
  83.  
  84.     if (flags & F_SORT_METHODS)
  85.         enumerator = [[class_methods sortedArrayUsingSelector:@selector (orderByMethodName:)] objectEnumerator];
  86.     else
  87.         enumerator = [class_methods reverseObjectEnumerator];
  88.  
  89.     while (method = [enumerator nextObject])
  90.     {
  91.         [method showMethod:'+'];
  92.         if (flags & F_SHOW_METHOD_ADDRESS)
  93.         {
  94.             printf ("\t// IMP=0x%08lx", [method address]);
  95.         }
  96.         printf ("\n");
  97.     }
  98.  
  99.     if (flags & F_SORT_METHODS)
  100.         enumerator = [[instance_methods sortedArrayUsingSelector:@selector (orderByMethodName:)] objectEnumerator];
  101.     else
  102.         enumerator = [instance_methods reverseObjectEnumerator];
  103.     
  104.     while (method = [enumerator nextObject])
  105.     {
  106.         [method showMethod:'-'];
  107.         if (flags & F_SHOW_METHOD_ADDRESS)
  108.         {
  109.             printf ("\t// IMP=0x%08lx", [method address]);
  110.         }
  111.         printf ("\n");
  112.     }
  113.  
  114.     printf ("@end\n\n");
  115. }
  116.  
  117. @end
  118.