[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fortran testers needed: fsplit



fsplit has numerous issues to solve. The attached patch should take care
of most. However, I am not a Fortran user.

I would appreciate it if someone who is actually using Fortran and fsplit
would take a few minutes to check out this patch and verify that fsplit
is behaving correctly now.
-- 
	Marc Espie		
|anime, sf, juggling, unicycle, acrobatics, comics...
|AmigaOS, OpenBSD, C++, perl, Icon, PostScript...
| `real programmers don't die, they just get out of beta'
Index: fsplit.c
===================================================================
RCS file: /cvs/src/usr.bin/fsplit/fsplit.c,v
retrieving revision 1.5
diff -u -r1.5 fsplit.c
--- fsplit.c	1999/12/06 00:34:26	1.5
+++ fsplit.c	1999/12/07 22:35:48
@@ -51,8 +51,10 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/fcntl.h>
 #include <err.h>
 
 void badparms __P(());
@@ -96,8 +98,11 @@
 
 #define TRUE 1
 #define FALSE 0
-int     extr = FALSE, extrknt = -1, extrfnd[100];
-char    extrbuf[1000], *extrnames[100];
+int     extr = FALSE, extrknt = -1;
+int maxextrknt;
+
+int *extrfnd;
+char **extrnames;
 struct stat sbuf;
 
 #define trim(p)	while (*p == ' ' || *p == '\t') p++
@@ -111,8 +116,13 @@
 	register char *ptr;
 	int     nflag,		/* 1 if got name of subprog., 0 otherwise */
 	        retval, i;
-	char    name[20], *extrptr = extrbuf;
+	/* must be as large as max(sizeof(x), sizeof(mainp), sizeof(blockp)) */
+	char    name[20];	
 
+	maxextrknt = 100;
+	extrnames = malloc(sizeof(char *) * maxextrknt);
+	if (extrnames == NULL)
+		errx(1, "out of memory");
 	/* scan -e options */
 	while (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'e') {
 		extr = TRUE;
@@ -125,28 +135,46 @@
 			ptr = argv[1];
 		}
 		extrknt = extrknt + 1;
-		extrnames[extrknt] = extrptr;
-		extrfnd[extrknt] = FALSE;
-		while (*ptr)
-			*extrptr++ = *ptr++;
-		*extrptr++ = 0;
+		if (extrknt >= maxextrknt) {
+			extrnames = realloc(extrnames, 
+			    sizeof(char *) * maxextrknt);
+			if (extrnames == NULL)
+				errx(1, "too many -e arguments");
+		}
+		if ((extrnames[extrknt] = strdup(ptr)) == NULL)
+			errx(1, "out of memory");
 		argc--;
 		argv++;
 	}
 
+	extrfnd = calloc(extrknt+1, sizeof(int));
+	if (extrfnd == NULL)
+		errx(1, "out of memory");
+
 	if (argc > 2)
 		badparms();
 	else
 		if (argc == 2) {
 			if ((ifp = fopen(argv[1], "r")) == NULL)
-				err(1, argv[1]);
+				err(1, "%s", argv[1]);
 		} else
 			ifp = stdin;
 	for (;;) {
+		int fd;
+
 		/* look for a temp file that doesn't correspond to an existing
 		 * file */
 		get_name(x, 3);
+
+		fd = open(x, O_CREAT|O_EXCL|O_RDWR, 0777);
+		if (fd == -1)
+			err(1, x);
 		ofp = fopen(x, "w");
+		if (ofp == NULL) {
+			close(fd);
+			unlink(x);
+			err(1, x);
+		}
 		nflag = 0;
 		rv = 0;
 		while (getline() > 0) {
@@ -204,16 +232,18 @@
 	char   *name;
 {
 	int     i;
-	char    fname[50], *fptr = fname;
+	size_t 	n;
 
 	if (!extr)
 		return (1);
-	while (*name)
-		*fptr++ = *name++;
-	*--fptr = 0;
-	*--fptr = 0;
+
+	n = strlen(name);
+	if (n < 2)
+		return (0);
+
 	for (i = 0; i <= extrknt; i++)
-		if (strcmp(fname, extrnames[i]) == 0) {
+		if (strncmp(name, extrnames[i], n - 2) == 0 &&
+		extrnames[i][n-2] == '\0') {
 			extrfnd[i] = TRUE;
 			return (1);
 		}
@@ -312,7 +342,7 @@
 	/* copy to buffer and converting to lower case */
 	p = ptr;
 	while (*p && p <= &buf[71]) {
-		*iptr = isupper(*p) ? tolower(*p) : *p;
+		*iptr = tolower(*p);
 		iptr++;
 		p++;
 	}

Visit your host, monkey.org