1 /***************************************************************************
2  *  Pinfo is a ncurses based lynx style info documentation browser
3  *
4  *  Copyright (C) 1999  Przemek Borys <pborys@dione.ids.pl>
5  *  Copyright (C) 2005  Bas Zoetekouw <bas@debian.org>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of version 2 of the GNU General Public License as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful, but
12  *  WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  *  USA
20  ***************************************************************************/
21 
22 #include "common_includes.h"
23 
24 /*
25  * Algorithm: We first print highlights, then we send `\r' to the printer,
26  * and we draw the base line. Thus highlights are printed `twice', and
27  * are darker than the rest :)
28  */
29 void
printnode(char *** message,unsigned long * lines)30 printnode(char ***message, unsigned long *lines)
31 {
32 #define Message	(*message)
33 #define Lines	(*lines)
34 
35 	/* counter, to point at what highlights are already * handled */
36 	unsigned highlight = 0;
37 	/* printer fd */
38 	FILE *prnFD;
39 	/* temporary buffer */
40 	char *buf = xmalloc(1024);
41 
42 	prnFD = popen(printutility, "w");
43 
44 	/* scan through all lines */
45 	for (unsigned i = 1; i < Lines; i++)
46 	{
47 		/*
48 		 * this says, where the printer's head is
49 		 * right now.(offset in cols from the
50 		 * beginning of line
51 		 */
52 		int lineprinted = 0;
53 		/*
54 		 * let's handle the highlights, which belong to our(i'th) line.
55 		 */
56 		while (hyperobjects[highlight].line <= i)
57 		{
58 			/* build a complete highlighted text */
59 			if (hyperobjects[highlight].file[0] == 0)
60 				strcpy(buf, hyperobjects[highlight].node);
61 			else
62 			{
63 				strcpy(buf, "(");
64 				strcat(buf, hyperobjects[highlight].file);
65 				strcat(buf, ")");
66 				strcat(buf, hyperobjects[highlight].node);
67 			}
68 			/* if it's a contiunuation of last's line highlight */
69 			if (hyperobjects[highlight].line == i - 1)
70 			{
71 				int length = 1;
72 				if (hyperobjects[highlight].breakpos == -1)
73 					length = strlen(buf) -
74 						hyperobjects[highlight].breakpos;
75 				fprintf(prnFD, "%s", buf + length -
76 						hyperobjects[highlight].breakpos);
77 				lineprinted += strlen(buf + length -
78 						hyperobjects[highlight].breakpos);
79 			}
80 			else if (hyperobjects[highlight].line == i)
81 			{
82 				for (unsigned j = 0; j < hyperobjects[highlight].col - lineprinted; j++)
83 					fprintf(prnFD, " ");
84 				fprintf(prnFD, "%s", buf);
85 				lineprinted = hyperobjects[highlight].col +
86 					strlen(buf);
87 			}
88 			if (highlight < hyperobjectcount - 1)
89 				highlight++;
90 			else
91 				break;
92 		}
93 		fprintf(prnFD, "\r%s", Message[i]);
94 	}
95 	pclose(prnFD);
96 	xfree(buf);
97 #undef Message
98 #undef Lines
99 }
100