- Added CStrings function definitions
- Added code for CString.Compare
This commit is contained in:
@@ -1 +1,49 @@
|
||||
(****************************************************************************
|
||||
* File name: CSTRINGS.I
|
||||
* Created On: Sat 03 Oct 2020 03:18:19 PM CEST
|
||||
* Last Modified: Sat 03 Oct 2020 03:18:19 PM CEST
|
||||
* Author: Jali <jali@orca-central.de>
|
||||
****************************************************************************
|
||||
* Implementation for handling C-Like strings
|
||||
****************************************************************************)
|
||||
|
||||
IMPLEMENTATION MODULE CStrings;
|
||||
|
||||
PROCEDURE Compare(strA : CString, strB : CString) : CompareResult
|
||||
(* $L- *)
|
||||
BEGIN
|
||||
ASSEMBLER
|
||||
MOVE.L -(A3),A1 ; Read strB from the stack
|
||||
MOVE.L -(A3),A0 ; Read strA from the stack
|
||||
MOVE.W 1,D2 ; Preset the return value to CompareResult.Equal
|
||||
Loop:
|
||||
MOVE.S D0,(A0)+ ; Read a byte from strA into D0, and increase the pointer
|
||||
CMP.S 0,D0 ; Check if the value is NULL
|
||||
BEQ Return ; Reached the end of the first string; break
|
||||
MOVE.S D1,(A1)+ ; Read a byte from strB into S1 and increase the pointer
|
||||
CMP.S 0,D0 ; Check if the byte is NULL
|
||||
BEQ Return ; Reached the end of the second string; break
|
||||
CMP.S D0,D1 ; Compare the two values for equality
|
||||
BEQ Loop ; If equal, continue with the next bytes.
|
||||
MOVE.W 2,D2 ; Set the result register to ComepareResult.After
|
||||
BHI Return ; Break and retrun result
|
||||
MOVE.W 0,D2 ; Set the result register to CompareResult.Before
|
||||
Return:
|
||||
MOVE D2,(A3)+ ; Push the result to the stack
|
||||
END;
|
||||
(* $L+ *)
|
||||
END Compare;
|
||||
|
||||
PROCEDURE Concat(strA, strB : CString) : CString
|
||||
VAR
|
||||
len : LONGCARD;
|
||||
newString : ARRAY
|
||||
resultString : POINTER TO CHAR;
|
||||
BEGIN
|
||||
len := Length(strA) + Length(strB);
|
||||
|
||||
END Concat;
|
||||
|
||||
END CStrings;
|
||||
|
||||
(* vim: set filetype=modula2: *)
|
||||
|
||||
Reference in New Issue
Block a user