From 3a847d245e9eedf0a353432219b99804af8964ab Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 30 Sep 2021 18:37:54 -0500 Subject: [PATCH] Add strcoll and strxfrm functions. This is currently a minimalistic implementation in which strcoll always sorts strings the same way as strcmp. --- string.asm | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ string.macros | 12 ++++++++++ 2 files changed, 78 insertions(+) diff --git a/string.asm b/string.asm index 91cd8b2..a39a467 100644 --- a/string.asm +++ b/string.asm @@ -763,6 +763,31 @@ lb4 long M rtl end +**************************************************************** +* +* int strcoll(const char *s1, const char *s2); +* +* Compare *s1 to *s2 based on current locale's collation order. +* If *s1 < *s2 then return a negative number; if they are +* equal, return 0; otherwise, return a positive number. +* +* Inputs: +* s1 - first string ptr +* s2 - second string ptr +* +* Outputs: +* A - result +* +* Notes: +* The current implementation assumes all supported locales +* have the same collation order as given by strcmp. +* +**************************************************************** +* +strcoll start + jml strcmp + end + **************************************************************** * * strcpy - string copy @@ -1790,3 +1815,44 @@ lb10 ldx set+2 get the return value isp ds 4 internal state pointer (isp) end + +**************************************************************** +* +* size_t strxfrm(char *s1, const char *s2, size_t n); +* +* Transform string *s2 into *s1, such that two output strings +* from strxfrm will compare the same way with strcmp that the +* input strings would with strcoll. Writes at most n bytes. +* +* Inputs: +* s1 - output string pointer +* s2 - input string pointer +* n - max length to write +* +* Outputs: +* *s1 - transformed output string (if it fits) +* A - length of full transformed string +* (not including terminating null) +* +* Notes: +* The current implementation assumes all supported locales +* have the same collation order as given by strcmp. +* +**************************************************************** +* +strxfrm start + + csubroutine (4:s1,4:s2,4:n),4 +len equ 1 length of s2 + + ph4 s2 len = strlen(s2) + jsl strlen + sta len + stx len+2 + cmpl len,n if len < n + bge ret + ph4 s2 + ph4 s1 + jsl strcpy strcpy(s1,s2) +ret creturn 4:len return len + end diff --git a/string.macros b/string.macros index e13001c..da86bdb 100644 --- a/string.macros +++ b/string.macros @@ -555,3 +555,15 @@ &l bne *+5 brl &bp mend + macro +&l cmpl &n1,&n2 + lclb &yistwo +&l ~setm + ~lda.h &n1 + ~op.h cmp,&n2 + bne ~a&SYSCNT + ~lda &n1 + ~op cmp,&n2 +~a&SYSCNT anop + ~restm + mend