2022-10-19 20:16:13 +00:00
|
|
|
#include "cmdline.h"
|
2022-10-11 02:18:42 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-01-11 22:29:53 +00:00
|
|
|
SInt16 CharByte(void) {
|
2022-10-11 02:18:42 +00:00
|
|
|
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);
|
|
|
|
}
|