Originally Posted by
Adak
You can, but I wouldn't:
Because it's non-standard and system dependent
Because it's ugly code
Post up an example of your strings/substrings, and also the kind of output you want.
Let's find a better answer.
Sorry for Very Very Very late response. I have no excuses - more than that I wasn't
proud for my code and needed to fix it before posting.
In the meantime I come across a lot of errors which delayed it all.
Ok, here comes my code. It's not that good, but good enough to serve as
a scratch book for what I am going to do in the near future.
Code:
//main_W_wrap_primitive
//read one string in turn from rgwsz[pos_rg][]
//and pass it to W_wrap_wsz
int main_W_wrap_primitive( int top , int bot , int lef , int rig )
{
int lines=0;
int hight = bot-top;
int width = rig- lef;
int rgp = pos_rg;
while ( lines < hight )
{
lines += W_wrap_wsz (top + lines, bot, lef, rig, rgwsz[ rgp ] );
if ( (wcslen(rgwsz [ rgp +1]) /( width + lines) ) >= hight)
break;
rgp++;
}
return lines;
}
Here is W_wrap_wsz
Code:
//W_wrap_wsz, takes a string as input and print it as a window,
//return number of lines written.
int W_wrap_wsz (int top, int bot, int lef, int rig, const wchar_t *wsz )
{
wchar_t wsz_tmp[ LINES * COLS ];
int beg, end, old_end;
int lines=0;
beg = 0;
end = rig - lef;
old_end = end;
if (end > wcslen(wsz)) //wszlen will be replaced with length stored in variable
{ //I have the variable and use it in other pieces
//of my code, just didn't implicate it here yet.
print_wsz_YX( top+lines , lef, wsz);
lines++;
return lines;
}
else
if ( end < wcslen(wsz) )
{
while (lines < (bot - top) && beg < wcslen(wsz))
{
wsz_nn_cpy( wsz_tmp, wsz, beg, end);
print_wsz_YX( top + lines, lef, wsz_tmp);
lines++;
beg=end;
end = (end + old_end);
if ( lines >= bot - top )
{
return lines;
}
}
}
return lines;
}
wsz_nn_cpy calls wscncpy, and adds a '\0'; att the end of the string.
print_wsz_YX just performes move and prints the string.
Why I asked about write dierectly to the screen.?
In the dos-days I created a pointer to the screenbuffert, and if I should write a line at the bottom, I just moved the adress of that pointer (don't remember xactly how I did it) one step. and below that I put the line,s of text.
I really would love to do the same thing in linux, if that's possible.
If the code is not portable, well - I could just check for which platform it's compiled under - and If the platform not supported I'll relay on the routines I posted above.
Is the code ugly.? Well - I think that even if I can't use it in the program- I could learn something from the code.
I also appreciate all comments about my code.