00001
00020 func clean_string(s) [buf, t]
00021 {
00022 buf = "";
00023 t = buf;
00024 while (*s)
00025 {
00026 if ((*s >= ' ') || (*s == '\n'))
00027 *t++ = *s++;
00028 else
00029 {
00030 *t++ = '^';
00031 *t++ = *s++ + '@';
00032 }
00033 }
00034 return buf;
00035 }
00036
00044 func fold_newlines(s) [buf, p, q, i]
00045 {
00046 buf = "";
00047 while (*s == ' ' || *s == '\n')
00048 s++;
00049 while (*s)
00050 {
00051 strcat(buf, " ");
00052 p = strchr(s, '\n');
00053 if (p)
00054 {
00055 strcat(buf, s, p - s);
00056 s = p + 1;
00057 while (*s == ' ' || *s == '\n')
00058 s++;
00059 }
00060 else
00061 {
00062 strcat(buf, s);
00063 q = buf+strlen(buf);
00064 break;
00065 }
00066 }
00067 return (*buf == ' ') ? buf + 1 : buf;
00068 }
00069
00076 func sh_quote(s) [r, p] {
00077 r = "'";
00078 while (p = strchr(s, '\'')) {
00079 strcat(r, s, p - s);
00080 strcat(r, "'\\''");
00081 s = p + 1;
00082 }
00083 strcat(r, s);
00084 strcat(r, "'");
00085 return r;
00086 }
00087
00098 func softwrap(str, width) [result, p]
00099 {
00100 result = "";
00101 while (strlen(str) > width)
00102 {
00103 p = strrchr(str, ' ', width) ?: strchr(str + width, ' ') ?:
00104 str + strlen(str);
00105 strcat(result, str, p - str);
00106 strcat(result, "\n");
00107 str = skipspaces(p);
00108 }
00109 return result + str;
00110 }