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