Newsgroups: comp.sys.apple2 Path: news.weeg.uiowa.edu!news.uiowa.edu!hobbes.physics.uiowa.edu!math.ohio-state.edu!usc!elroy.jpl.nasa.gov!ames!aio!erin!mark From: mark@erin.JSC.NASA.GOV (Mark Manning/Metrica) Subject: Re: Kyan Pascal - A question Message-ID: <1993Jul2.151737.15892@aio.jsc.nasa.gov> Sender: usenet@aio.jsc.nasa.gov (USENET News Client) Reply-To: mark@pokey.jsc.nasa.gov Organization: Simulacron I References: Date: Fri, 2 Jul 1993 15:17:37 GMT Lines: 187 Someone sent me some mail but it got deleted accidentally. So I am posting this. Sorry for the inconvience. :/ -------email----email----email----email----email----------- That is what I had thought. A friend of mine who is a Pascal guru basically told me I was screwed. :( The file thing is another idea I had come up with but I just really didn't want to do that. You know. It is very frustrating to get a wonderful compiler like Kyan Pascal and then to have to deal with something which is fundamental to programming but which has been left out. :{. I have gotten around most of the string problems by (I may have posted this already) only passing the address to the procedure and then having a tmpString variable declared as ^char. It is a lot simpler to work with and the numbers only have to be declared as integers when they are passed. Also, it doesn't matter if you are calling from a subprogram or the main program because you are dealing with an address in memory somewhere. The only problem with this approach is that the commands are fairly long due to having to insert the ADDRESS() function. Thus, string copy (ripped off from C) becomes: strcpy( address(AString), address(BString) ); ___ The variables are always defined as going from zero to whatever plus one. type str80 = array [0..81] of char; var MyString : str80; ___ This allows for me to place a length byte into the zero position which will tell me the maximum length of the string. The "plus one" location will always have a zero in it no matter what. This allows for the terminator (zero) to always be present. Within the subroutine I have: procedure strcpy( AString, BString : integer ); { Routine to copy a string. } var tmpString : ^char; { Temporary String Pointer } tmpChar : char; { Temporary Character Holder } j : integer; { Misc. Variable } i : integer; { Misc. Variable } ALength : integer; { Length of first String } BLength : integer; { Length of second string } begin { Find the maximum length of the first string. } tmpString := pointer( AString ); ALength := tmpString^; { Find the maximum length of the second string. } tmpString := pointer( BString ); BLength := tmpString^; { Determine which is the longest and which the shortest. } j := ALength; if( BLength < ALength )then j := BLength; { Copy over the information. } for i := 1 to j do begin tmpString := pointer( BString + i ); tmpChar := tmpString^; tmpString := pointer( AString + i ); tmpString^ := tmpChar; end; { Find the zero and then expand it to the end of the string. } j := 0; for i := 1 to ALength do begin tmpString := pointer( AString + i ); tmpChar := tmpString^; if( tmpChar = chr(0) )then j := i; if( j > 0 )then tmpString^ := chr( 0 ); end; { We are through and can now return. } end; ___ This could probably be done a lot easier in assembly language than in Pascal. In fact, here is a stab at doing just that: procedure strcpy( aString, bString ); begin #a stx _T ; ; Get Everything ; ldy #$08 lda (_SP),y sta _T+2 dey lda (_SP),y sta _T+1 dey lda (_SP),y sta _T+4 dey lda (_SP),y sta _T+3 ; ; Now see which string is shorter. ; ldx #$00 lda (_T+1),x cmp (_T+3),x bpl scpy01 lda (_T+1),x sta _T+5 jmp scpy02 scpy01 lda (_T+3),x sta _T+5 scpy02 ; ; Now transfer the string ; ldy #$01 scpy03 lda (_T+3),y sta (_T+1),y iny dec _T+5 bne scpy03 ; ; Expand the zero field ; scpy04 tya cmp (_T+1),x beq scpy05 lda #$00 sta (_T+1),y iny jmp scpy04 ; ; Done. Return ; scpy05 ldx _T # end; ___ Now, I just wrote this off the top of my head, so it may not work correctly. Check it out and see if it does. At any rate, this is how I have been handling strings. ---------------------------------------------------------- If the buttered side of a piece of bread always lands face down, and a cat always lands on its feet. Then what happens when you tie a piece of buttered bread to the back of a cat and drop the cat? - Steve Wright