Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Mar 2002 13:52:11 +1100 (EST)
From:      "Tim J. Robbins" <tim@robbins.dropbear.id.au>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   standards/36075: P1003.1-2001 m4(1) -s option
Message-ID:  <200203190252.g2J2qBC00914@descent.robbins.dropbear.id.au>

next in thread | raw e-mail | index | archive | help

>Number:         36075
>Category:       standards
>Synopsis:       P1003.1-2001 m4(1) -s option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 18 19:00:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Tim J. Robbins
>Release:        FreeBSD 4.5-STABLE i386
>Organization:
>Environment:
System: FreeBSD descent.robbins.dropbear.id.au 4.5-STABLE FreeBSD 4.5-STABLE #8: Tue Mar 19 08:46:39 EST 2002 tim@descent.robbins.dropbear.id.au:/usr/obj/usr/src/sys/DESCENT i386


	
>Description:
FreeBSD m4 is missing the P1003.1-2001 -s option. This patch adds it.
It also adds an EXIT STATUS section to the manual page.

-s	Enable line synchronization output for the c99 preprocessor phase
	(that is, #line directives). 

>How-To-Repeat:
N/A
>Fix:

Index: eval.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/m4/eval.c,v
retrieving revision 1.14
diff -u -r1.14 eval.c
--- eval.c	2001/07/24 14:09:47	1.14
+++ eval.c	2002/03/19 02:49:44
@@ -584,7 +584,11 @@
 		errx(1, "too many include files");
 	if ((infile[ilevel + 1] = fopen(ifile, "r")) != NULL) {
 		ilevel++;
+		if ((inname[ilevel] = strdup(ifile)) == NULL)
+			err(1, NULL);
+		inlineno[ilevel] = 1;
 		bbase[ilevel] = bufbase = bp;
+		emitline();
 		return (1);
 	}
 	else
@@ -604,9 +608,11 @@
 	register int c;
 
 	if ((pf = fopen(pfile, "r")) != NULL) {
+		fprintf(active, "#line 1 \"%s\"\n", pfile);
 		while ((c = getc(pf)) != EOF)
 			putc(c, active);
 		(void) fclose(pf);
+		emitline();
 		return (1);
 	}
 	else
Index: extern.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/m4/extern.h,v
retrieving revision 1.5
diff -u -r1.5 extern.h
--- extern.h	2001/07/24 14:09:47	1.5
+++ extern.h	2002/03/19 02:49:44
@@ -53,6 +53,7 @@
 void	dopushdef __P((char *, char *));
 void	dosub __P((char *[], int));
 void	doundiv __P((char *[], int));
+void	emitline __P((void));
 void	eval __P((char *[], int, int));
 void	expand __P((char *[], int));
 void	getdiv __P((int));
@@ -72,6 +73,8 @@
 extern stae mstack[];		/* stack of m4 machine */
 extern FILE *active;		/* active output file pointer */
 extern FILE *infile[];		/* input file stack (0=stdin) */
+extern char *inname[];		/* names of these input files  */
+extern int inlineno[];		/* current number in each input*/
 extern FILE *outfile[];		/* diversion array(0=bitbucket) */
 extern int fp; 			/* m4 call frame pointer */
 extern int ilevel;		/* input file stack pointer */
@@ -92,3 +95,5 @@
 extern char *null;		/* as it says.. just a null. */
 extern char rquote;		/* right quote character (') */
 extern char scommt;		/* start character for comment */
+extern int synccpp;		/* Line synchronisation for C preprocessor */
+extern int chscratch;		/* Scratch space for gpbc() macro */  
Index: m4.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/m4/m4.1,v
retrieving revision 1.12
diff -u -r1.12 m4.1
--- m4.1	2001/07/15 08:01:24	1.12
+++ m4.1	2002/03/19 02:49:45
@@ -10,9 +10,9 @@
 .Sh SYNOPSIS
 .Nm
 .Oo
-.Fl D Ns Ar name Ns Op Ar =value
+.Fl D Ar name Ns Op Ar =value
 .Oc
-.Op Fl U Ns Ar name
+.Op Fl U Ar name
 .Op Ar filename
 \|.\|.\|.
 .Sh DESCRIPTION
@@ -41,13 +41,18 @@
 .Pp
 The options are as follows:
 .Bl -tag -width "-Dname[=value]xxx"
-.It Fl D Ns Ar name Ns Oo
+.It Fl s
+Emit
+.Em #line
+directives for
+.Xr cpp 1 .
+.It Fl D Ar name Ns Oo
 .Ar =value
 .Oc
 Define the symbol
 .Ar name
 to have some value (or NULL).
-.It Fl "U" Ns Ar "name"
+.It Fl "U" Ar "name"
 Undefine the symbol
 .Ar name .
 .El
@@ -177,7 +182,34 @@
 .It unix
 A pre-defined macro for testing the OS platform.
 .El
+.Sh DIAGNOSTICS
+.Ex -std
+.Pp
+The exit status can be specified by the input file using the
+.Em m4exit
+macro.
+.Sh STANDARDS
+The
+.Nm
+utility is compatible with the
+.St -p1003.1-2001
+specification with the exception of the
+.Em traceon
+and
+.Em traceoff
+built-in macros, which are not implemented.
+.Pp
+The
+.Em expr ,
+.Em paste ,
+.Em spaste
+and
+.Em unix
+built-in macros are extensions to the standard.
+.Sh "SEE ALSO"
+.Xr cpp 1
 .Sh AUTHORS
 .An Ozan Yigit Aq oz@sis.yorku.ca
-and
 .An Richard A. O'Keefe Aq ok@goanna.cs.rmit.OZ.AU
+.Sh BUGS
+The tracing macros are not implemented.
Index: main.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/m4/main.c,v
retrieving revision 1.11
diff -u -r1.11 main.c
--- main.c	2001/07/24 14:09:47	1.11
+++ main.c	2002/03/19 02:49:46
@@ -80,6 +80,8 @@
 int sp; 			/* current m4  stack pointer   */
 int fp; 			/* m4 call frame pointer       */
 FILE *infile[MAXINP];		/* input file stack (0=stdin)  */
+char *inname[MAXINP];		/* names of these input files  */
+int inlineno[MAXINP];		/* current number in each input*/
 FILE *outfile[MAXOUT];		/* diversion array(0=bitbucket)*/
 FILE *active;			/* active output file pointer  */
 char *m4temp;			/* filename for diversions     */
@@ -92,6 +94,8 @@
 char rquote = RQUOTE;		/* right quote character (')   */
 char scommt = SCOMMT;		/* start character for comment */
 char ecommt = ECOMMT;		/* end character for comment   */
+int synccpp = 0;		/* Line synchronisation for C preprocessor */
+int chscratch = 0;		/* Scratch space for gpbc() macro */
 
 struct keyblk keywrds[] = {	/* m4 keywords to be installed */
 	"include",      INCLTYPE,
@@ -159,7 +163,7 @@
 
 	initkwds();
 
-	while ((c = getopt(argc, argv, "tD:U:o:")) != -1)
+	while ((c = getopt(argc, argv, "D:U:s")) != -1)
 		switch(c) {
 
 		case 'D':               /* define something..*/
@@ -173,7 +177,9 @@
 		case 'U':               /* undefine...       */
 			remhash(optarg, TOP);
 			break;
-		case 'o':		/* specific output   */
+		case 's':
+			synccpp = 1;
+			break;
 		case '?':
 			usage();
 		}
@@ -195,6 +201,10 @@
  		sp = -1;		/* stack pointer initialized */
 		fp = 0; 		/* frame pointer initialized */
 		infile[0] = stdin;	/* default input (naturally) */
+		if ((inname[0] = strdup("-")) == NULL)
+			err(1, NULL);
+		inlineno[0] = 1;
+		emitline();
 		macro();
 	} else
 		for (; argc--; ++argv) {
@@ -206,6 +216,10 @@
 			sp = -1;
 			fp = 0;
 			infile[0] = ifp;
+			if ((inname[0] = strdup(p)) == NULL)
+				err(1, NULL);
+			inlineno[0] = 1;
+			emitline();
 			macro();
 			if (ifp != stdin)
 				(void)fclose(ifp);
@@ -282,7 +296,9 @@
 				break;			/* all done thanks.. */
 			--ilevel;
 			(void) fclose(infile[ilevel+1]);
+			free(inname[ilevel+1]);
 			bufbase = bbase[ilevel];
+			emitline();
 			continue;
 		}
 	/*
@@ -418,4 +434,13 @@
 		p->defn = null;
 		p->type = keywrds[i].ktyp | STATIC;
 	}
+}
+
+/* Emit preprocessor #line directive if -s option used. */
+void
+emitline()
+{
+	if (synccpp)
+		fprintf(active, "#line %d \"%s\"\n", inlineno[ilevel],
+		    inname[ilevel]);
 }
Index: mdef.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/m4/mdef.h,v
retrieving revision 1.3
diff -u -r1.3 mdef.h
--- mdef.h	1995/05/30 06:31:35	1.3
+++ mdef.h	2002/03/19 02:49:47
@@ -142,7 +142,9 @@
  *      pushf() - push a call frame entry onto stack
  *      pushs() - push a string pointer onto stack
  */
-#define gpbc()   (bp > bufbase) ? (*--bp ? *bp : EOF) : getc(infile[ilevel])
+#define gpbc()   (bp > bufbase) ? (*--bp ? *bp : EOF) : \
+	((chscratch = getc(infile[ilevel])) == '\n' && ++inlineno[ilevel], \
+	chscratch)
 #define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x)
 #define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x)
 
Index: misc.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/m4/misc.c,v
retrieving revision 1.8
diff -u -r1.8 misc.c
--- misc.c	2001/07/24 14:09:47	1.8
+++ misc.c	2002/03/19 02:49:47
@@ -219,6 +219,7 @@
 void
 usage()
 {
-	fprintf(stderr, "usage: m4 [-Dname[=val]] [-Uname]\n");
+	fprintf(stderr,
+"usage: m4 [-s] [-D name[=val]]... [-U name]... file...\n");
 	exit(1);
 }
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203190252.g2J2qBC00914>