This is CRLFToNeXTText.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 CRLFToNeXTText 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 "CRLFToNeXTText.h" #import <memory.h> // for memcpy #include <strings.h> @implementation CRLFToNeXTText // // Note: an init method isn't needed, nor is a ConvertCharacter. The latter is no // good because we only get 1 char at a time, so we'd never see a CFLF... // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 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: // Hokay. This routine will take a string that may have CRLF line endings in // it, and effecively removes all the CR's so we end up with a nice NeXT text // file. // Bugs: // we don't really check for errors anywhere (not taht there are many oportunities)... // History // 93.07.05 djb Created for 1.1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (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+1); // worst case: nothing changes, and we add a null [self ResetResults]; for (index = 0; index < length; index++) { // // I hate these multiple logical conditions things. I believe this says: // If we find a CRLF and we're before the very end of the string (that is, // where the LF would be hangin off the end) then negate this whole condition. // under those circumstances, we want to copy the character (otherwise, the // carriage return is part of the CRLF, and we want to not write it out. // if (! ((source[index] == '\r') && (source[index+1] == '\n') && (index < (length-1)))) { 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.