fluffos/testsuite/std/break_string.lpc
Yucong Sun 592dfc0688 Prefer .lpc source extension; rename testsuite to .lpc
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>
2026-07-09 20:48:48 -04:00

113 lines
2.8 KiB
Text

// From MorgenGrauen MUDlib
// Rewirtten by lonely for driver of fluffos v2019
#include "break_string.h"
private string stretch(string str, int width)
{
int len = strwidth(str);
string trimmed, *words;
int start_spaces, word_count, space_count, space_per_word, rest;
if (len == width) return str;
trimmed = ltrim(str);
if (trimmed == "") return str;
start_spaces = len - strwidth(trimmed);
words = explode(trimmed, " ");
word_count = sizeof(words) - 1;
if (!word_count)
return sprintf("%*' 's", start_spaces, "") + words[0];
space_count = width - len;
space_per_word = (word_count + space_count) / word_count;
rest = (word_count + space_count) % word_count;
for (int pos = 0; pos < rest; pos++) words[pos] += " ";
return sprintf("%*' 's", start_spaces, "") + implode(words, sprintf("%*' 's", space_per_word, ""));
}
private varargs string block_string(string str, int width, int flags)
{
string *tmp;
if ((flags & BS_LEAVE_MY_LFS) && !(flags & BS_NO_PARINDENT))
{
str = " " + replace_string(str, "\n", "\n ");
}
str = sprintf("%-*=s", width, str);
tmp = explode(str, "\n");
if (sizeof(tmp) > 1)
return implode(map_array(tmp[0.. < 2], (: stretch($1, $(width)) :)), "\n") + "\n" + tmp[ < 1];
return str;
}
varargs string break_string(string str, int width, mixed indent, int flags)
{
int indentlen, indent2;
string prefix = "", temp;
if (!str || str == "") return "";
if (!width) width = 78;
if (intp(indent))
{
temp = sprintf("%*' 's", indent, "");
indent = indent ? temp : "";
}
indentlen = stringp(indent) ? strwidth(indent) : 0;
if (indentlen > width)
{
error(sprintf("break_string: indent longer %d than width %d\n", indentlen, width));
}
if (!(flags & BS_LEAVE_MY_LFS))
str = replace_string(str, "\n", " ");
if (flags & BS_SINGLE_SPACE)
{
str = replace_string(str, "\n", " ");
str = implode(explode(str, " ") - ({""}), " ");
}
if (indentlen && (flags & BS_PREPEND_INDENT))
{
if (indentlen + strwidth(str) > width || (flags & BS_LEAVE_MY_LFS) && strsrch(str, "\n") > -1)
{
prefix = indent + "\n";
indent = (flags & BS_NO_PARINDENT) ? "" : " ";
indentlen = strwidth(indent);
}
}
if (flags & BS_BLOCK)
{
str = block_string(str, width - indentlen, flags);
}
else
{
str = sprintf("%-1.*=s", width - indentlen, str);
}
if (str[ < 1] != '\n') str += "\n";
if (!indentlen) return prefix + str;
indent2 = (flags & BS_INDENT_ONCE) ? sprintf("%*' 's", indentlen, "") : indent;
return prefix + indent + replace_string(str[0.. < 2], "\n", "\n" + indent2) + "\n";
}