summaryrefslogtreecommitdiff
path: root/command_line/CmdLine/Src/MacEmul/TextUtils.c
diff options
context:
space:
mode:
Diffstat (limited to 'command_line/CmdLine/Src/MacEmul/TextUtils.c')
-rw-r--r--command_line/CmdLine/Src/MacEmul/TextUtils.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/command_line/CmdLine/Src/MacEmul/TextUtils.c b/command_line/CmdLine/Src/MacEmul/TextUtils.c
new file mode 100644
index 0000000..a23ac7e
--- /dev/null
+++ b/command_line/CmdLine/Src/MacEmul/TextUtils.c
@@ -0,0 +1,132 @@
+#include "mwcc_decomp.h"
+
+StringPtr c2pstr(char *s) {
+ unsigned int l;
+ l = strlen(s);
+ if (l > 255)
+ l = 255;
+ memmove(s + 1, s, l);
+ s[0] = l;
+ return (StringPtr) s;
+}
+
+char *p2cstr(StringPtr s) {
+ unsigned int l;
+ l = s[0];
+ memmove(s, s + 1, l);
+ s[l] = 0;
+ return (char *) s;
+}
+
+SInt16 CharacterByteType(Ptr textBuf, SInt16 textOffset, ScriptCode script) {
+ return 0;
+}
+
+SInt16 CharByte() {
+ return 0;
+}
+
+void GetDateTime(UInt32 *secs) {
+ time_t time;
+ OS_GetTime(&time);
+ OS_TimeToMac(time, secs);
+}
+
+Boolean EqualString(ConstStr255Param strA, ConstStr255Param strB, Boolean caseSens, Boolean diacSens) {
+ int i, length;
+ Boolean equal;
+
+ equal = 0;
+ length = strA[0];
+ if (strA && strB && length == strB[0]) {
+ if (caseSens) {
+ equal = !memcmp(strA + 1, strB + 1, length);
+ } else {
+ equal = 1;
+ i = 0;
+ while (equal && i < length) {
+ equal = toupper(strA[i]) == toupper(strB[i]);
+ ++i;
+ }
+ }
+ }
+
+ return equal;
+}
+
+void GetIndString(Str255 theString, SInt16 strListID, SInt16 index) {
+ SInt16 last;
+ SInt16 idc;
+ SInt32 len;
+ Handle strs;
+ const char *ret;
+ StringPtr ptr;
+ StringPtr dptr;
+ Str255 tmp;
+
+ ret = Res_GetResource(strListID, index);
+ if (ret) {
+ strcpy((char *) tmp, ret);
+ c2pstr((char *) tmp);
+ } else {
+ sprintf((char *) tmp, "[Resource string id=%d index=%d not found]", strListID, index);
+ c2pstr((char *) tmp);
+
+ strs = GetResource('STR#', strListID);
+ if (strs) {
+ last = (((unsigned char) (*strs)[0]) << 8) + ((unsigned char) (*strs)[1]);
+ if (index > 0 && index <= last) {
+ len = GetHandleSize(strs);
+ HLock(strs);
+ ptr = (StringPtr) (*strs + 2);
+ idc = index;
+ dptr = (StringPtr) (*strs + len);
+ while (ptr < dptr && --idc) {
+ ptr += *ptr + 1;
+ }
+ if (ptr < dptr)
+ _pstrcpy(tmp, ptr);
+ HUnlock(strs);
+ }
+ }
+ }
+
+ ptr = &tmp[1];
+ dptr = &theString[1];
+ while (ptr <= &tmp[tmp[0]]) {
+ if (*ptr == 0xD4) {
+ *dptr = '`';
+ } else if (*ptr == 0xD5) {
+ *dptr = '\'';
+ } else if (*ptr == 0xD2 || *ptr == 0xD3) {
+ *dptr = '"';
+ } else if (*ptr == 0xC9 && (dptr - theString) < 253) {
+ dptr[0] = '.';
+ dptr[1] = '.';
+ dptr[2] = '.';
+ dptr += 2;
+ } else {
+ *dptr = *ptr;
+ }
+ ++ptr;
+ ++dptr;
+ }
+
+ theString[0] = (dptr - theString) - 1;
+}
+
+char *getindstring(char *theString, SInt16 strListID, SInt16 index) {
+ GetIndString((StringPtr) theString, strListID, index);
+ return p2cstr((StringPtr) theString);
+}
+
+void NumToString(SInt32 theNum, Str255 theString) {
+ sprintf((char *) theString, "%d", theNum);
+ c2pstr((char *) theString);
+}
+
+void StringToNum(ConstStr255Param theString, SInt32 *theNum) {
+ p2cstr((StringPtr) theString);
+ sscanf((char *) theString, "%d", theNum);
+ c2pstr((char *) theString);
+}