// ---------------------------------------------------------------------
// Copyright (C) 2002 by Codeon GmbH. All rights reserved.
//
// Autor: nat
//
// $Id: NSDictionary+PListOldSkool.m,v 1.1 2002/09/09 10:42:11 nat Exp $
//
// $Log: NSDictionary+PListOldSkool.m,v $
// Revision 1.1  2002/09/09 10:42:11  nat
// OldSkool PList writing for Solaris compatibility
//
//
// ---------------------------------------------------------------------
#import "NSDictionary+PListOldSkool.h"


@implementation NSDictionary ( PListOldSkool)

- (NSString *) plistDescription:(NSString *) prefix
{
   NSMutableString   *string;
   NSEnumerator      *rover;
   id                key;
   NSString          *prefix2;
   
   prefix2 = [@"   " stringByAppendingString:prefix];
   
   string = [NSMutableString string];
   
   if( [self count] > 0)
   {
      [string appendString:@"{\n"];
      
      rover = [[[self allKeys] sortedArrayUsingSelector:@selector( compare:)] objectEnumerator];
      key = [rover nextObject];
      do
      {
         [string appendString:prefix2];
         [string appendString:key];
         [string appendString:@" = "];
         [string appendString:[[self objectForKey:key] plistDescription:prefix2]];
         key = [rover nextObject];
         if( key)
            [string appendString:@";"];
         [string appendString:@"\n"];
      }
      while( key);
      [string appendString:prefix];
      [string appendString:@"}"];
   }
   else
      [string appendString:@"{}"];
   return( string);
}


- (BOOL) writeOldSkoolFormatToFileHandle:(NSFileHandle *) handle
{
   NSString  *string;
   NSData    *data;
   
   string = [self plistDescription:@""];
   data   = [string dataUsingEncoding:NSISOLatin1StringEncoding];
   [handle writeData:data];
   return( YES);
}

@end