14887Schin /***********************************************************************
24887Schin * *
34887Schin * This software is part of the ast package *
4*10898Sroland.mainz@nrubsig.org * Copyright (c) 1986-2009 AT&T Intellectual Property *
54887Schin * and is licensed under the *
64887Schin * Common Public License, Version 1.0 *
78462SApril.Chin@Sun.COM * by AT&T Intellectual Property *
84887Schin * *
94887Schin * A copy of the License is available at *
104887Schin * http://www.opensource.org/licenses/cpl1.0.txt *
114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
124887Schin * *
134887Schin * Information and Software Systems Research *
144887Schin * AT&T Research *
154887Schin * Florham Park NJ *
164887Schin * *
174887Schin * Glenn Fowler <gsf@research.att.com> *
184887Schin * *
194887Schin ***********************************************************************/
204887Schin #pragma prototyped
214887Schin /*
224887Schin * Glenn Fowler
234887Schin * AT&T Research
244887Schin *
254887Schin * common preprocessor line sync handler
264887Schin */
274887Schin
284887Schin #include "pplib.h"
294887Schin
304887Schin void
ppline(int line,char * file)314887Schin ppline(int line, char* file)
324887Schin {
334887Schin char* s;
344887Schin static char type[5];
354887Schin
364887Schin if (pp.flags & PP_lineignore)
374887Schin {
384887Schin pp.flags &= ~PP_lineignore;
394887Schin if (!(pp.flags & PP_linetype) || *pp.lineid)
404887Schin {
414887Schin ppline(1, file);
424887Schin file = error_info.file;
434887Schin }
444887Schin else
454887Schin type[1] = PP_sync_ignore;
464887Schin }
474887Schin else if (file != pp.lastfile)
484887Schin {
494887Schin if (!pp.firstfile)
504887Schin pp.firstfile = file;
514887Schin 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;
524887Schin pp.lastfile = file;
534887Schin }
544887Schin else
554887Schin {
564887Schin if (!(pp.flags & PP_linefile))
574887Schin file = 0;
584887Schin type[1] = PP_sync;
594887Schin }
604887Schin if (!(pp.flags & PP_linetype) || *pp.lineid || type[1] == PP_sync)
614887Schin type[0] = 0;
624887Schin else
634887Schin {
644887Schin type[0] = ' ';
654887Schin if ((pp.flags & (PP_hosted|PP_linehosted)) == (PP_hosted|PP_linehosted))
664887Schin {
674887Schin type[2] = ' ';
684887Schin type[3] = PP_sync_hosted;
694887Schin }
704887Schin else
714887Schin type[2] = 0;
724887Schin }
734887Schin
744887Schin /*
754887Schin * some front ends can't handle two line syncs in a row
764887Schin */
774887Schin
784887Schin if (pp.pending == pppendout() || pplastout() != '\n')
794887Schin ppputchar('\n');
804887Schin if (file)
814887Schin ppprintf("#%s %d \"%s\"%s\n", pp.lineid, line, (pp.flags & PP_linebase) && (s = strrchr(file, '/')) ? s + 1 : file, type);
824887Schin else
834887Schin ppprintf("#%s %d\n", pp.lineid, line);
844887Schin if (!pp.macref)
854887Schin pp.pending = pppendout();
864887Schin }
87