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;j < strlen(s);j++)
30 c = substring(s, j, 1);
36 // we need to keep this tempstring alive even if substring is
37 // called repeatedly, so call strcat even though we're not
47 t = strcat(t, substring(s, i, wlen));
68 for (i = 0;i < strlen(s);i++)
70 c = substring(s, i, 1);
74 else if (c == "\\" && substring(s, i + 1, 1) == "n")
79 word = strcat(word, c);
84 // a space may add some whitespace to the output, and flushes the word buffer
87 if (lleft < strlen(word) + 1)
95 // otherwise just add a space if there's already text in
105 // if this is a double space, add the space
109 else if (dowhat == 1)
115 // we need to keep these tempstrings alive even if substring is
116 // called repeatedly, so call strcat even though we're not doing
138 for(i = 0; i <= strlen(s); ++i)
140 if(i != strlen(s) && substring(s, i, 1) != " ")
142 // we need to keep this tempstring alive even if substring is
143 // called repeatedly, so call strcat even though we're not doing
149 word = substring(s, startidx, i - startidx);
154 t = strcat(t, "\n\n");
157 else if(!l || (strlen(word) < lleft))
165 lleft = lleft - strlen(word);
169 t = strcat(t, "\n", word);
170 lleft = l - strlen(word);
177 float dist_point_line(vector p, vector l0, vector ldir)
179 ldir = normalize(ldir);
181 // remove the component in line direction
182 p = p - (p * ldir) * ldir;
184 // vlen of the remaining vector