1 /* Text in a 'window'
2 
3  * Copyright (C) 1998 J.A. Bezemer
4  *
5  * Licensed under the terms of the GNU General Public License.
6  * ABSOLUTELY NO WARRANTY.
7  * See the file `COPYING' in this directory.
8  */
9 
10 #include "textwindow.h"
11 #include <stdlib.h>
12 #include <string.h>
13 #ifndef OLD_CURSES
14 #include <ncurses.h>
15 #else
16 #include <curses.h>
17 #endif
18 
19 
20 void
display_textwin(char * text,int y,int x,int h,int w)21 display_textwin (char *text, int y, int x, int h, int w)
22 			/* (y,x): upper left position of 'text block'
23 			   h = heigth, w = width of block */
24 {
25 
26   int current_y;
27   char mytext[DISPLAYMENU_MAXTEXTLEN];
28   char mytext2[DISPLAYMENU_MAXTEXTLEN];
29   char helptext[DISPLAYMENU_MAXTEXTLEN];
30   char *lastspace;
31   int i;
32 
33   current_y = y;
34   strncpy (mytext, text, DISPLAYMENU_MAXTEXTLEN);
35 
36   do
37     {
38       strncpy (mytext2, mytext, w + 1);
39       mytext2[w + 1] = '\0';
40 
41       if (strlen (mytext2) > w)
42 	{
43 	  lastspace = strrchr (mytext2, ' ');
44 	  if (lastspace != NULL)
45 	    {
46 	      mytext2[lastspace - mytext2] = '\0';
47 
48 	      strcpy (helptext, mytext + (lastspace - mytext2 + 1));
49 
50 	      strcpy (mytext, helptext);
51 	    }
52 	  else
53 	    /* no space... */
54 	    {
55 	      mytext2[w] = '\0';
56 
57 	      strcpy (helptext, mytext + w);
58 	      strcpy (mytext, helptext);
59 	    }
60 	}
61       else			/* strlen(mytext2) <= w */
62 	mytext[0] = '\0';
63 
64       mvaddstr (current_y, x, mytext2);
65 
66       for (i = strlen (mytext2) + 1; i <= w; i++)
67 	addch (' ');
68 
69       current_y++;
70     }
71   while (current_y < y + h /*&& strlen(mytext) > 0 */ );
72 }
73