Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37531425
en ru br
ALT Linux repos
5.0: 1.12-alt2

Group :: Editors
RPM: minised

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Patch: minised-svn-r106.patch
Download


 Makefile  |   15 ++++++++++++---
 sedcomp.c |   42 +++++++++++++++++++++++++-----------------
 sedexec.c |   54 +++++++++++++++++++++++++++---------------------------
 tests/run |    6 +++---
 4 files changed, 67 insertions(+), 50 deletions(-)
diff --git a/Makefile b/Makefile
index a7d387a..24ac2a4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,24 @@
 # Makefile for minised
 
+# If your compiler does not support this flags, just remove them.
+# They only ensure that no new warning regressions make it into the source.
+CFLAGS += -Wall -Wwrite-strings
+
+DESTDIR=
 PREFIX=/usr
+BINDIR=$(PREFIX)/bin
+MANDIR=$(PREFIX)/share/man/man1
 
 minised: sedcomp.o sedexec.o
-	$(CC) $(LFLAGS) sedcomp.o sedexec.o -o minised
+	$(CC) $(LDFLAGS) sedcomp.o sedexec.o -o minised
 
 sedcomp.o: sedcomp.c sed.h
 sedexec.o: sedexec.c sed.h
 
 install:
-	install minised $(PREFIX)/bin/
-	install minised.1 $(PREFIX)/man/man1/
+	install -d -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)
+	install -m 755 minised $(DESTDIR)$(BINDIR)
+	install -m 644 minised.1 $(DESTDIR)$(MANDIR)
 
 clean:
 	rm -f minised sedcomp.o sedexec.o
@@ -18,3 +26,4 @@ clean:
 check: minised
 	cd tests; ./run ../minised
 
+.PHONY: install clean check
diff --git a/sedcomp.c b/sedcomp.c
index 70c662f..95eb8c5 100644
--- a/sedcomp.c
+++ b/sedcomp.c
@@ -65,7 +65,7 @@ static char	AD2NG[]	= "only one address allowed for %s";
 static char	TMCDS[]	= "too many commands, last was %s";
 static char	COCFI[]	= "cannot open command-file %s";
 static char	UFLAG[]	= "unknown flag %c";
-static char	COOFI[]	= "cannot open %s";
+/*static char	COOFI[]	= "cannot open %s";*/
 static char	CCOFI[]	= "cannot create %s";
 static char	ULABL[]	= "undefined label %s";
 static char	TMLBR[]	= "too many {'s";
@@ -82,7 +82,7 @@ static char	RETER[] = "RE not terminated: %s";
 static char	CCERR[] = "unknown character class: %s";
 
 /* cclass to c function mapping ,-) */
-char* cclasses[] = {
+const char* cclasses[] = {
 	"alnum", "a-zA-Z0-9",
 	"lower", "a-z",
 	"space", " \f\n\r\t\v",
@@ -297,11 +297,14 @@ static void compile(void)
 
 		SKIPWS(cp);			/* look for trailing stuff */
 		if (*cp != '\0')
-			if (*cp == ';') {
+		{
+			if (*cp == ';')
+			{
 				continue;
 			}
 			else if (*cp != '#' && *cp != '}')
 				die(TRAIL);
+		}
 	}
 }
 
@@ -309,7 +312,7 @@ static void compile(void)
 static int cmdcomp(char cchar)
 {
 	static sedcmd	**cmpstk[MAXDEPTH];	/* current cmd stack for {} */
-	static char	*fname[WFILES];		/* w file name pointers */
+	static const char *fname[WFILES];	/* w file name pointers */
 	static FILE	*fout[WFILES];		/* w file file ptrs */
 	static int	nwfiles	= 2;		/* count of open w files */
 	int		i;			/* indexing dummy used in w */
@@ -346,7 +349,7 @@ static int cmdcomp(char cchar)
 	case ':':	/* label declaration */
 		if (cmdp->addr1) die(AD1NG);	/* no addresses allowed */
 		fp = gettext(lab->name = fp);	/* get the label name */
-		if (lpt = search(lab))		/* does it have a double? */
+		if ((lpt = search(lab)))	/* does it have a double? */
 		{
 			if (lpt->address) die(DLABL);	/* yes, abort */
 		}
@@ -366,9 +369,9 @@ static int cmdcomp(char cchar)
 		if (*cp == '\0')	/* if branch is to start of cmds... */
 		{
 			/* add current command to end of label last */
-			if (sp1 = lablst->last) 
+			if ((sp1 = lablst->last)) 
 			{
-				while(sp2 = sp1->u.link)
+				while((sp2 = sp1->u.link))
 					sp1 = sp2;
 				sp1->u.link = cmdp;
 			}
@@ -377,14 +380,14 @@ static int cmdcomp(char cchar)
 			break;
 		}
 		fp = gettext(lab->name = fp);	/* else get label into pool */
-		if (lpt = search(lab))		/* enter branch to it */
+		if ((lpt = search(lab)))	/* enter branch to it */
 		{
 			if (lpt->address)
 				cmdp->u.link = lpt->address;
 			else
 			{
 				sp1 = lpt->last;
-				while(sp2 = sp1->u.link)
+				while((sp2 = sp1->u.link))
 					sp1 = sp2;
 				sp1->u.link = cmdp;
 			}
@@ -458,7 +461,8 @@ static int cmdcomp(char cchar)
 	case 'w':	/* write-pattern-space command */
 	case 'W':	/* write-first-line command */
 		if (nwfiles >= WFILES) die(TMWFI);
-		fp=gettext(fname[nwfiles]=fp);	/* filename will be in pool */
+		fname[nwfiles] = fp;
+		fp = gettext((fname[nwfiles] = fp, fp));	/* filename will be in pool */
 		for(i = nwfiles-1; i >= 0; i--)	/* match it in table */
 			if (strcmp(fname[nwfiles], fname[i]) == 0)
 			{
@@ -555,7 +559,7 @@ static char *recomp(char *expbuf, char redelim)	/* uses cp, bcount */
 	brnestp = brnest;		/* initialize ptr to brnest array */
 	tags = bcount = 0;		/* initialize counters */
 
-	if (*ep++ = (*sp == '^'))	/* check for start-of-line syntax */
+	if ((*ep++ = (*sp == '^')))	/* check for start-of-line syntax */
 		sp++;
 
 	for (;;)
@@ -656,7 +660,7 @@ static char *recomp(char *expbuf, char redelim)	/* uses cp, bcount */
 			if (ep + 17 >= expbuf + RELIMIT)
 				die(REITL);
 			*ep++ = CCL;		/* insert class mark */
-			if (negclass = ((c = *sp++) == '^'))
+			if ((negclass = ((c = *sp++) == '^')))
 				c = *sp++;
 			svclass = sp;		/* save ptr to class start */
 			do {
@@ -665,13 +669,15 @@ static char *recomp(char *expbuf, char redelim)	/* uses cp, bcount */
 				if (c == '[' && *sp == ':')
 				{
 				  /* look for the matching ":]]" */
-				  char *p, *p2;
+				  char *p;
+				  const char *p2;
 				  for (p = sp+3; *p; p++)
 				    if  (*p == ']' &&
 				         *(p-1) == ']' &&
 					 *(p-2) == ':')
 					{
-					  char cc[8], **it;
+					  char cc[8];
+					  const char **it;
 					  p2 = sp+1;
 					  for (p2 = sp+1;
 					       p2 < p-2 && p2-sp-1 < sizeof(cc);
@@ -709,12 +715,14 @@ static char *recomp(char *expbuf, char redelim)	/* uses cp, bcount */
 
 				/* handle escape sequences in sets */
 				if (c == '\\')
+				{
 					if ((c = *sp++) == 'n')
 						c = '\n';
 					else if (c == 't')
 						c = '\t';
 					else if (c == 'r')
 						c = '\r';
+				}
 
 				/* enter (possibly translated) char in set */
 				if (c)
@@ -759,7 +767,7 @@ static int cmdline(char	*cbuf)		/* uses eflag, eargc, cmdf */
 
 			/* else transcribe next e argument into cbuf */
 			p = *++eargv;
-			while(*++cbuf = *p++)
+			while((*++cbuf = *p++))
 				if (*cbuf == '\\')
 				{
 					if ((*++cbuf = *p++) == '\0')
@@ -781,7 +789,7 @@ static int cmdline(char	*cbuf)		/* uses eflag, eargc, cmdf */
 		if ((p = savep) == NULL)
 			return(-1);
 
-		while(*++cbuf = *p++)
+		while((*++cbuf = *p++))
 			if (*cbuf == '\\')
 			{
 				if ((*++cbuf = *p++) == '0')
@@ -889,7 +897,7 @@ static void resolve(void)			/* uses global lablst */
 		else if (lptr->last)		/* if last is non-null */
 		{
 			rptr = lptr->last;		/* chase it */
-			while(trptr = rptr->u.link)	/* resolve refs */
+			while((trptr = rptr->u.link))	/* resolve refs */
 			{
 				rptr->u.link = lptr->address;
 				rptr = trptr;
diff --git a/sedexec.c b/sedexec.c
index fcc874e..236d3df 100644
--- a/sedexec.c
+++ b/sedexec.c
@@ -156,7 +156,7 @@ static int selected(sedcmd *ipc)
 {
 	register char	*p1 = ipc->addr1;	/* point p1 at first address */
 	register char	*p2 = ipc->addr2;	/*   and p2 at second */
-	char		c;
+	unsigned char	c;
 	int selected = FALSE;
 
 	if (ipc->flags.inrange)
@@ -206,7 +206,7 @@ static int match(char *expbuf, int gf)	/* uses genbuf */
 		if (*expbuf)
 			return(FALSE);
 		p1 = linebuf; p2 = genbuf;
-		while (*p1++ = *p2++);
+		while ((*p1++ = *p2++));
 		if (needs_advance) {
 			loc2++;
 		}
@@ -297,7 +297,7 @@ static int advance(char* lp, char* ep, char** eob)
 			return(FALSE);		/* else return false */
 
 		case CBRA:		/* start of tagged pattern */
-			brastart[*ep++] = lp;	/* mark it */
+			brastart[(unsigned char)*ep++] = lp;	/* mark it */
 			continue;		/* and go */
 
 		case CKET:		/* end of tagged pattern */
@@ -307,12 +307,12 @@ static int advance(char* lp, char* ep, char** eob)
 				return (TRUE);
 			}
 			else
-				bracend[*ep++] = lp;    /* mark it */
+				bracend[(unsigned char)*ep++] = lp;    /* mark it */
 			continue;		/* and go */
 
 		case CBACK:		/* match back reference */
-			bbeg = brastart[*ep];
-			ct = bracend[*ep++] - bbeg;
+			bbeg = brastart[(unsigned char)*ep];
+			ct = bracend[(unsigned char)*ep++] - bbeg;
 
 			if (memcmp(bbeg, lp, ct) == 0)
 			{
@@ -327,12 +327,12 @@ static int advance(char* lp, char* ep, char** eob)
 			curlp = lp;
 
 			if (*ep > bcount)
-				brastart[*ep] = bracend[*ep] = lp;
+				brastart[(unsigned char)*ep] = bracend[(unsigned char)*ep] = lp;
 
 			while (advance(lastlp=lp, ep+1, &lp)) {
 				if (*ep > bcount && lp != lastlp) {
-					bracend[*ep] = lp;    /* mark it */
-					brastart[*ep] = lastlp;
+					bracend[(unsigned char)*ep] = lp;    /* mark it */
+					brastart[(unsigned char)*ep] = lastlp;
 				}
 				if (lp == lastlp) break;
 			}
@@ -350,8 +350,8 @@ static int advance(char* lp, char* ep, char** eob)
 			goto star;
 		}
 		case CBACK|STAR:	/* \n* */
-			bbeg = brastart[*ep];
-			ct = bracend[*ep++] - bbeg;
+			bbeg = brastart[(unsigned char)*ep];
+			ct = bracend[(unsigned char)*ep++] - bbeg;
 			curlp = lp;
 			while(memcmp(bbeg, lp, ct) == 0)
 				lp += ct;
@@ -436,7 +436,7 @@ static int advance(char* lp, char* ep, char** eob)
    ipc:	ptr to s command struct */
 static int substitute(sedcmd *ipc)
 {
-	int n = 1;
+	unsigned int n = 1;
 	/* find a match */
 	/* the needs_advance code got a bit tricky - might needs a clean
 	   refactoring */
@@ -474,7 +474,7 @@ static void dosub(char *rhsbuf)		/* uses linebuf, genbuf, spend */
 	lp = linebuf; sp = genbuf;
 	while (lp < loc1) *sp++ = *lp++;
 
-	for (rp = rhsbuf; c = *rp++; )
+	for (rp = rhsbuf; (c = *rp++); )
 	{
 		if (c & 0200 && (c & 0177) == '0')
 		{
@@ -493,11 +493,11 @@ static void dosub(char *rhsbuf)		/* uses linebuf, genbuf, spend */
 	}
 	lp = loc2;
 	loc2 = sp - genbuf + linebuf;
-	while (*sp++ = *lp++)
+	while ((*sp++ = *lp++))
 		if (sp >= genbuf + MAXBUF)
 			fprintf(stderr, LTLMSG);
 	lp = linebuf; sp = genbuf;
-	while (*lp++ = *sp++);
+	while ((*lp++ = *sp++));
 	spend = lp-1;
 }
 
@@ -594,10 +594,10 @@ static void command(sedcmd *ipc)
 	case CDCMD:		/* delete a line in hold space */
 		p1 = p2 = linebuf;
 		while(*p1 != '\n')
-			if (delete = (*p1++ == 0))
+			if ((delete = (*p1++ == 0)))
 				return;
 		p1++;
-		while(*p2++ = *p1++) continue;
+		while((*p2++ = *p1++)) continue;
 		spend = p2-1;
 		jump++;
 		break;
@@ -607,7 +607,7 @@ static void command(sedcmd *ipc)
 		break;
 
 	case GCMD:		/* copy hold space to pattern space */
-		p1 = linebuf;	p2 = holdsp;	while(*p1++ = *p2++);
+		p1 = linebuf;	p2 = holdsp;	while((*p1++ = *p2++));
 		spend = p1-1;
 		break;
 
@@ -620,14 +620,13 @@ static void command(sedcmd *ipc)
 				p1[-1] = 0;
   				break;
 			}
-		} while
-		    (*p1++ = *p2++);
+		} while((*p1++ = *p2++));
 
 		spend = p1-1;
 		break;
 
 	case HCMD:		/* copy pattern space to hold space */
-		p1 = holdsp;	p2 = linebuf;	while(*p1++ = *p2++);
+		p1 = holdsp;	p2 = linebuf;	while((*p1++ = *p2++));
 		hspend = p1-1;
 		break;
 
@@ -640,8 +639,7 @@ static void command(sedcmd *ipc)
 				p1[-1] = 0;
   				break;
 			}
-		} while
-		    (*p1++ = *p2++);
+		} while((*p1++ = *p2++));
 
 		hspend = p1-1;
 		break;
@@ -718,10 +716,12 @@ static void command(sedcmd *ipc)
 	case SCMD:		/* substitute RE */
 		didsub = substitute(ipc);
 		if (ipc->flags.print && didsub)
+		{
 			if (ipc->flags.print == TRUE)
 				puts(linebuf);
 			else
 				goto cpcom;
+		}
 		if (didsub && ipc->fout)
 			fprintf(ipc->fout, "%s\n", linebuf);
 		break;
@@ -745,16 +745,16 @@ static void command(sedcmd *ipc)
 		break;
 
 	case XCMD:		/* exchange pattern and hold spaces */
-		p1 = linebuf;	p2 = genbuf;	while(*p2++ = *p1++) continue;
-		p1 = holdsp;	p2 = linebuf;	while(*p2++ = *p1++) continue;
+		p1 = linebuf;	p2 = genbuf;	while((*p2++ = *p1++)) continue;
+		p1 = holdsp;	p2 = linebuf;	while((*p2++ = *p1++)) continue;
 		spend = p2 - 1;
-		p1 = genbuf;	p2 = holdsp;	while(*p2++ = *p1++) continue;
+		p1 = genbuf;	p2 = holdsp;	while((*p2++ = *p1++)) continue;
 		hspend = p2 - 1;
 		break;
 
 	case YCMD:
 		p1 = linebuf;	p2 = ipc->u.lhs;
-		while(*p1 = p2[*p1])
+		while((*p1 = p2[(unsigned char)*p1]))
 			p1++;
 		break;
 	}
diff --git a/tests/run b/tests/run
index 8f8c66f..785aaba 100755
--- a/tests/run
+++ b/tests/run
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 verbose=1
 time=0
@@ -21,7 +21,7 @@ tmp=`mktemp`
 errors=0
 
 for x in *.sed ; do
-	x=${x/.sed/}
+	x=${x%.sed}
 	echo -n "Running test $x ..."
 	$1 -f $x.sed $x.in > $tmp 2>&1
 	error=$?
@@ -46,7 +46,7 @@ if [ $errors -ne 0 ]; then
 elif [ $time -ne 0 ]; then
 	echo "Timing:"
 	time for x in *.sed ; do
-		x=${x/.sed/}
+		x=${x%.sed}
 		echo -n . >&2
 		$1 -f $x.sed $x.in > $tmp
 	done
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin