2 string wordwrap(string s, float l)
5 local float lleft, i, j, wlen;
10 for (i = 0;i < strlen(s);i++)
12 if (substring(s, i, 2) == "\\n")
18 else if (substring(s, i, 1) == " ")
28 for (j = i+1;j < strlen(s);j++)
29 // ^^ this skips over the first character of a word, which
30 // is ALWAYS part of the word
31 // this is safe since if i+1 == strlen(s), i will become
32 // strlen(s)-1 at the end of this block and the function
33 // will terminate. A space can't be the first character we
34 // read here, and neither can a \n be the start, since these
35 // two cases have been handled above.
37 c = substring(s, j, 1);
42 // we need to keep this tempstring alive even if substring is
43 // called repeatedly, so call strcat even though we're not
53 t = strcat(t, substring(s, i, wlen));
74 for (i = 0;i < strlen(s);i++)
76 c = substring(s, i, 1);
80 else if (c == "\\" && substring(s, i + 1, 1) == "n")
85 word = strcat(word, c);
90 // a space may add some whitespace to the output, and flushes the word buffer
93 if (lleft < strlen(word) + 1)
101 // otherwise just add a space if there's already text in
111 // if this is a double space, add the space
115 else if (dowhat == 1)
121 // we need to keep these tempstrings alive even if substring is
122 // called repeatedly, so call strcat even though we're not doing
144 for(i = 0; i <= strlen(s); ++i)
146 if(i != strlen(s) && substring(s, i, 1) != " ")
148 // we need to keep this tempstring alive even if substring is
149 // called repeatedly, so call strcat even though we're not doing
155 word = substring(s, startidx, i - startidx);
160 t = strcat(t, "\n\n");
163 else if(!l || (strlen(word) < lleft))
171 lleft = lleft - strlen(word);
175 t = strcat(t, "\n", word);
176 lleft = l - strlen(word);
183 float dist_point_line(vector p, vector l0, vector ldir)
185 ldir = normalize(ldir);
187 // remove the component in line direction
188 p = p - (p * ldir) * ldir;
190 // vlen of the remaining vector