Category : C Source Code
Archive   : WTWG12B.ZIP
Filename : WROWCOL.C

 
Output of file : WROWCOL.C contained in archive : WTWG12B.ZIP
/*! wstrrowcol
*
* a 2-dimensional strlen() function, this routine computes the
* number of rows and columns needed to display a string.
*
* Assumptions: new lines are flagged with \n
* Lines do not wrap around the window edge.
* (routine may be used to compute size of next window)
*
* This routine will FAIL
* if the string contains embedded \t tab chars
* if the string is longer than the current window width
*
*
* parameters: text is ptr to a string.
* the number of rows and columns needed are placed in
* *rows, *cols.
* RETURN: void.
*/



#include "wsys.h"





void wstrrowcol (char *text, int *rows, int*cols )
{
int linecnt; /* #lines in text */
int longest; /* longest line in text */
int len;


char *ptr;
char *last_ptr;

/* 'normalize' the pointers (if the memory model requires it)
* so we can add to them without wrapping around
* segment boundaries
*/
_NORMALIZE (text);




/* count lines in text and size of largest line */

ptr = last_ptr = text;

linecnt = longest = 0;

while (NULL != (ptr = strchr (ptr+1, '\n')) )
{
++linecnt;

if ( longest < (int)(ptr - last_ptr) )
{
/* longest line so far */
longest = (int) (ptr - last_ptr);
}
last_ptr = ptr;
}

/*now look over the last line (or only line) for line length.
*/
len = strlen(last_ptr);
if ( longest < len )
{
longest = len;
}

*rows = linecnt;
*cols = longest;

return;
} /*end of wstrrowcol */




  3 Responses to “Category : C Source Code
Archive   : WTWG12B.ZIP
Filename : WROWCOL.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/