xref: /titanic_44/usr/src/lib/libpp/common/ppline.c (revision 62a24de03df1f2399ceda704cb3874dabc98bbbd)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1986-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22  * Glenn Fowler
23  * AT&T Research
24  *
25  * common preprocessor line sync handler
26  */
27 
28 #include "pplib.h"
29 
30 void
31 ppline(int line, char* file)
32 {
33 	char*		s;
34 	static char	type[5];
35 
36 	if (pp.flags & PP_lineignore)
37 	{
38 		pp.flags &= ~PP_lineignore;
39 		if (!(pp.flags & PP_linetype) || *pp.lineid)
40 		{
41 			ppline(1, file);
42 			file = error_info.file;
43 		}
44 		else
45 			type[1] = PP_sync_ignore;
46 	}
47 	else if (file != pp.lastfile)
48 	{
49 		if (!pp.firstfile)
50 			pp.firstfile = file;
51 		type[1] = ((pp.flags & PP_linetype) && !*pp.lineid && pp.lastfile) ? (line <= 1 ? (file == pp.firstfile ? PP_sync : PP_sync_push) : PP_sync_pop) : PP_sync;
52 		pp.lastfile = file;
53 	}
54 	else
55 	{
56 		if (!(pp.flags & PP_linefile))
57 			file = 0;
58 		type[1] = PP_sync;
59 	}
60 	if (!(pp.flags & PP_linetype) || *pp.lineid || type[1] == PP_sync)
61 		type[0] = 0;
62 	else
63 	{
64 		type[0] = ' ';
65 		if ((pp.flags & (PP_hosted|PP_linehosted)) == (PP_hosted|PP_linehosted))
66 		{
67 			type[2] = ' ';
68 			type[3] = PP_sync_hosted;
69 		}
70 		else
71 			type[2] = 0;
72 	}
73 
74 	/*
75 	 * some front ends can't handle two line syncs in a row
76 	 */
77 
78 	if (pp.pending == pppendout() || pplastout() != '\n')
79 		ppputchar('\n');
80 	if (file)
81 		ppprintf("#%s %d \"%s\"%s\n", pp.lineid, line, (pp.flags & PP_linebase) && (s = strrchr(file, '/')) ? s + 1 : file, type);
82 	else
83 		ppprintf("#%s %d\n", pp.lineid, line);
84 	if (!pp.macref)
85 		pp.pending = pppendout();
86 }
87