|
|
| version 1.2, 2025/03/09 15:20:18 | version 1.8, 2025/05/01 17:02:30 |
|---|---|
| Line 1 | Line 1 |
| /* | /* |
| * * | * $Id$ |
| * * * | |
| * * * | |
| * *************** | |
| * * * * * | |
| * * MUMPS * | |
| * * * * * | |
| * *************** | |
| * * * | |
| * * * | |
| * * | |
| * | |
| * strings.c | |
| * freem string library | * freem string library |
| * | * |
| * | * |
| * Author: Serena Willis <snw@coherent-logic.com> | * Author: Serena Willis <snw@coherent-logic.com> |
| * Copyright (C) 1998 MUG Deutschland | * Copyright (C) 1998 MUG Deutschland |
| * Copyright (C) 2020 Coherent Logic Development LLC | * Copyright (C) 2020, 2025 Coherent Logic Development LLC |
| * | * |
| * | * |
| * This file is part of FreeM. | * This file is part of FreeM. |
| Line 35 | Line 23 |
| * You should have received a copy of the GNU Affero Public License | * You should have received a copy of the GNU Affero Public License |
| * along with FreeM. If not, see <https://www.gnu.org/licenses/>. | * along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
| * | * |
| * $Log$ | |
| * Revision 1.8 2025/05/01 17:02:30 snw | |
| * Further debugging improvements | |
| * | |
| * Revision 1.7 2025/04/15 02:24:43 snw | |
| * Improve FreeM logging capabilities | |
| * | |
| * Revision 1.6 2025/04/13 04:22:43 snw | |
| * Fix snprintf calls | |
| * | |
| * Revision 1.5 2025/04/10 01:24:39 snw | |
| * Remove C++ style comments | |
| * | |
| * Revision 1.4 2025/04/09 19:52:02 snw | |
| * Eliminate as many warnings as possible while building with -Wall | |
| * | |
| * Revision 1.3 2025/03/09 19:50:47 snw | |
| * Second phase of REUSE compliance and header reformat | |
| * | |
| * | |
| * SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC | |
| * SPDX-License-Identifier: AGPL-3.0-or-later | |
| **/ | **/ |
| #include "mpsdef.h" | #include "mpsdef.h" |
| Line 42 | Line 52 |
| #include <stdarg.h> | #include <stdarg.h> |
| #include <string.h> | #include <string.h> |
| #include <stdlib.h> | #include <stdlib.h> |
| #include <stdarg.h> | |
| /* length of 'source' string in bytes */ | /* length of 'source' string in bytes */ |
| long int stlen (const char *source) | long int stlen (const char *source) |
| Line 62 long int stnlen (const char *source, siz | Line 73 long int stnlen (const char *source, siz |
| return length; | return length; |
| } | } |
| /* copy string from 'source' to 'dest' */ | /* copy string from 'source' to 'dest' */ |
| long int stcpy (char *dest, const char *source) | long int stcpy (char *dest, const char *source) |
| { | { |
| Line 113 short int stcat (char *dest, const char | Line 123 short int stcat (char *dest, const char |
| while ((dest[i] = *source++) != EOL) { | while ((dest[i] = *source++) != EOL) { |
| if (i++ >= STRLEN) { | if (i++ >= STRLEN) { |
| //printf("i = %d\r\n", i); | |
| dest[--i] = EOL; | dest[--i] = EOL; |
| return FALSE; | return FALSE; |
| } | } |
| Line 123 short int stcat (char *dest, const char | Line 132 short int stcat (char *dest, const char |
| return TRUE; | return TRUE; |
| } | } |
| long int stncat (char *dest, const char *source, size_t siz) | |
| { | |
| long int srclen; | |
| long int dstlen; | |
| srclen = stnlen (source, siz); | |
| dstlen = stnlen (dest, siz); | |
| return 0; | |
| } | |
| /* compare str1 and str2 */ | /* compare str1 and str2 */ |
| short int stcmp (char *str1, char *str2) | short int stcmp (char *str1, char *str2) |
| { | { |
| Line 187 char *trim (char *s) | Line 184 char *trim (char *s) |
| } | } |
| /* | |
| int stnprintf(char *dst, int size, char *fmt, ...) | |
| { | |
| va_list ptr; | |
| va_start (ptr, fmt); | |
| char ch; | |
| char typ; | |
| register int i; | |
| register int k; | |
| k = 0; | |
| for (i = 0; fmt[i] != '\201'; i++) { | |
| ch = fmt[i]; | |
| if ((k + 1) == size) { | |
| dst[k + 1] = '\201'; | |
| return k; | |
| } | |
| if (ch == '%') { | |
| typ = fmt[++i]; | |
| switch (typ) { | |
| case '%': | |
| dst[k++] = '%'; | |
| break; | |
| case 's': | |
| } | |
| } | |
| else if (ch == '\') { | |
| } | |
| } | |
| } | |
| */ | |
| /* convert EOL-terminated string 'mstr' to NUL-terminated string in-place */ | /* convert EOL-terminated string 'mstr' to NUL-terminated string in-place */ |
| void stcnv_m2c(char *mstr) | void stcnv_m2c(char *mstr) |
| Line 230 void stncnv_c2m(char *cstr, size_t siz) | Line 269 void stncnv_c2m(char *cstr, size_t siz) |
| return; | return; |
| } | } |
| /* convert at most 'count' characters of *key into human-readable format in *buf */ | /* convert at most 'count' characters of *key into human-readable format in *buf */ |
| size_t key_to_name(char *buf, const char *key, size_t count) | size_t key_to_name(char *buf, const char *key, size_t count) |
| { | { |
| Line 254 size_t key_to_name(char *buf, const char | Line 294 size_t key_to_name(char *buf, const char |
| c = key[i]; | c = key[i]; |
| next = key[i + 1]; | next = key[i + 1]; |
| switch (key[i]) { | switch (c) { |
| case EOL: | case EOL: |
| Line 424 size_t name_to_key(char *buf, const char | Line 464 size_t name_to_key(char *buf, const char |
| } | } |
| n_to_k_done: | n_to_k_done: |
| buf[j] = '\201'; | |
| return j; | return j; |
| } | } |
| Line 490 void uuid_v4 (char *buf) | Line 531 void uuid_v4 (char *buf) |
| seg2[4] = '\0'; | seg2[4] = '\0'; |
| snprintf (seg3, 5, "%04x", seg3num); | snprintf (seg3, sizeof (seg3), "%04x", seg3num); |
| snprintf (seg4, 5, "%04x", seg4num); | snprintf (seg4, sizeof (seg4), "%04x", seg4num); |
| for (i = 0; i < 12; i++) { | for (i = 0; i < 12; i++) { |
| seg5[i] = chars[rand () % 16]; | seg5[i] = chars[rand () % 16]; |