ftp.nice.ch/pub/next/graphics/convertors/Convert.s.tar.gz#/Converters/Convert_TEXT/NeXTToCRLFText.m

This is NeXTToCRLFText.m in view mode; [Download] [Up]

/***********************************************************************
CRLF Converter class for Convert TEXT which converts between Mac and NeXT text.
Copyright (C) 1993 David John Burrowes

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

The author, David John Burrowes, can be reached at:
	davidjohn@kira.net.netcom.com
	David John Burrowes
	1926 Ivy #10
	San Mateo, CA 94403-1367
***********************************************************************/

/*====================================================================
This is the implementation file for the NeXTToCRLFText class.  Check the doc for NeXTToMacText.rtf to give you a suggestion of what this otherwise undocumented class is like..

NOTE: You may find that text doesn't line up properly unless you use the New Century Schoolbook Roman typeface, since this was created with it.

INFORMATION:
	This is $Revision: 1.2 $ of this file
	It was last modifiFed by $Author: death $ on $Date: 93/04/04 23:44:44 $
 	$Log:	NeXTToCRLFText.m,v $
====================================================================*/


#import "NeXTToCRLFText.h"
#import <memory.h>	// for memcpy
#include <strings.h>


@implementation NeXTToCRLFText




//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	Routine:		ConvertString:WithLength:
//	Parameters:	a pointer to a string of data to be converted
//				the length of the data the poiner poins to.
//	Returns:		a poiner to a new block of data to be converted
//	Stores:		the pointer we are returning
//				the length of the new data
//	Description:
//		This takes the specified string, and copies it into a new buffer, 'converting' it as
//		it goes.  This 'conversion' is actually pretty trivial.  If we find a LF, we write out
//		a CRLF.  Otherwise we write out litterally.   Yawn.
//	Bugs:
//		we don't really check for errors anywhere (not taht there are many oportunities)...
//	History
//		93.07.05	djb	Created...
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (Pointer) ConvertString: (Pointer) theData WithLength: (Integer) length
{
	Character*	source = (Character*) theData; // getting a better typed ptr.
	Integer		index;
	PositiveInteger	destindex = 0;
	Character*	dest = (Character*) NewPointer((length*2)+1); // worst case: every char  a LF, plus need room for final null
	
	[self	ResetResults];
	
	for (index = 0; index < length; index++)
	{
		if (source[index] == '\n')
		{
			dest[destindex] = '\r';
			destindex++;
		}
		dest[destindex] = source[index];
		destindex++;
	}
	//
	//	Put a null on, just for the heck of it. 
	//
	dest[destindex] = EndOfCString;
	//
	//	Store the result, and return.  (note that destindex always ends up pointing to
	//	the next byte to be used, and thus is also a count of the total number of bytes
	//	in the dest string.
	//
	[self	StorePointer: dest];
	[self	PutPositiveInteger: destindex Into: SECOND_RESULT];
	[self	StoreErrorCode: errOK AndText: "Nothing could go wrong (pathetic program)!"];
	return dest;
}
@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.