mirror of
https://github.com/fluffos/fluffos
synced 2026-08-12 18:26:06 -04:00
Source resolution is now explicit-extension-exact: load_object("/foo.c")
probes only foo.c, never foo.lpc (and vice versa); extension-less names
prefer .lpc and fall back to .c. Object identity stays extension-blind:
object names carry no extension, any spelling finds a loaded object, and
the registry is consulted before the filesystem. The caller's raw
spelling now flows through find_object()/inherit/master/simul_efun loads
instead of being pre-stripped away.
- filename_to_obname and otable basename() strip .lpc too (children())
- save_object() strips either source extension before appending .o
- replace_program()/function_exists() handle both suffixes
- testsuite: all LPC sources renamed to .lpc; runner globs, master
get_include_path cases, and program-name assertions updated;
README.md rewritten with the extension rules and suite conventions
- new single/tests/efuns/dual_extension.lpc pins exact-pick, fallback,
no-crossover, identity, and registry-before-filesystem with .c/.lpc
fixture pairs in /clone
Verified: ctest 297/297 and driver-autotest x3 (ASan Debug) plus
RelWithDebInfo ctest + autotest.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
119 lines
2.7 KiB
Text
119 lines
2.7 KiB
Text
/**
|
|
* Lovingly ripped off from http://lpmuds.net/smf/index.php?topic=1531.msg8465#msg8465
|
|
* Minor modifications by Gesslar@ThresholdRPG
|
|
*/
|
|
|
|
private nosave string b64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ;
|
|
|
|
string base64encode(string source_str)
|
|
{
|
|
string *b ;
|
|
string r = "";
|
|
string p = "";
|
|
int i;
|
|
int n;
|
|
int n1, n2, n3, n4;
|
|
int rlen, slen, plen;
|
|
buffer source = string_encode(source_str, "UTF-8");
|
|
|
|
if( nullp( source_str ) || !sizeof( source_str ) )
|
|
{
|
|
error("Missing argument 1 to base64encode") ;
|
|
}
|
|
|
|
slen = sizeof(source);
|
|
plen = slen % 3;
|
|
b = explode(b64chars, "");
|
|
|
|
for (i = 0; i < slen; i += 3)
|
|
{
|
|
n = source[i] << 16;
|
|
|
|
if ((i+1) < slen)
|
|
n += source[i+1] << 8;
|
|
|
|
if ((i+2) < slen)
|
|
n += source[i+2];
|
|
|
|
n1 = (n >> 18) & 63;
|
|
n2 = (n >> 12) & 63;
|
|
n3 = (n >> 6) & 63;
|
|
n4 = n & 63;
|
|
|
|
r += "" + b[n1] + b[n2];
|
|
|
|
if ((i+1) < slen)
|
|
r += "" + b[n3];
|
|
|
|
if ((i+2) < slen)
|
|
r += "" + b[n4];
|
|
}
|
|
|
|
if (plen > 0)
|
|
for (; plen < 3; plen++) r += "=";
|
|
|
|
return r;
|
|
}
|
|
|
|
string base64decode(string source)
|
|
{
|
|
string *b ;
|
|
string f = "";
|
|
int i, j;
|
|
int c;
|
|
int n;
|
|
int plen = 0;
|
|
buffer result;
|
|
|
|
if( nullp( source ) || !strlen( source ) )
|
|
{
|
|
error("Missing argument 1 to base64decode") ;
|
|
}
|
|
|
|
b = explode( b64chars, "" );
|
|
|
|
for (i = 0; i < sizeof(source); i++) {
|
|
c = strsrch(b64chars, source[i]);
|
|
if (c == -1) {
|
|
// not found
|
|
if (source[i] == 61) {
|
|
// We found an "=", meaning we hit the padding.
|
|
// For decoding purposes, "A" is a zero pad value here.
|
|
f += "A";
|
|
plen++;
|
|
continue;
|
|
} else if(source[i] == 32 || source[i] == 10 || source[i] == 9 || source[i] = 13) {
|
|
// We found whitespace, skip it
|
|
continue;
|
|
} else {
|
|
// invalid character
|
|
return "Invalid input.";
|
|
}
|
|
} else {
|
|
f += b[c];
|
|
}
|
|
}
|
|
|
|
if (sizeof(f) % 4)
|
|
return "Invalid input.";
|
|
|
|
result = allocate_buffer(sizeof(f) / 4 * 3);
|
|
j = 0;
|
|
for (i = 0; i < sizeof(f); i += 4)
|
|
{
|
|
c = strsrch(b64chars, f[i]);
|
|
n = c << 18;
|
|
c = strsrch(b64chars, f[i+1]);
|
|
n += c << 12;
|
|
c = strsrch(b64chars, f[i+2]);
|
|
n += c << 6;
|
|
c = strsrch(b64chars, f[i+3]);
|
|
n += c;
|
|
|
|
result[j++] = (n >> 16) & 0xFF;
|
|
result[j++] = (n >> 8) & 0xFF;
|
|
result[j++] = n & 0xFF;
|
|
}
|
|
|
|
return string_decode(result, "UTF-8");
|
|
}
|