shithub: scc

Download patch

ref: 41c4d8d974869cdaef2940836203a5994366a912
parent: 1b8dcd44d13ee59c6e19fd22684b5e3071f5b774
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Apr 13 12:53:58 EDT 2018

[ld] Remove the object item list

This job can be done better with argc and argv.

--- a/ld/main.c
+++ b/ld/main.c
@@ -131,55 +131,20 @@
 }
 
 static void
-pass1(struct items *list)
+pass1(int argc, char *argv[])
 {
-	unsigned i;
-
-	pass = 1;
-	for (i = 0; i < list->n; ++i)
-		process(list->s[i]);
+	while (*argv)
+		process(*argv++);
 }
 
 static void
-pass2(struct items *list)
+pass2(int argc, char *argv[])
 {
-	unsigned i;
-
-	pass = 2;
-	for (i = 0; i < list->n; ++i)
-		process(list->s[i]);
+	while (*argv)
+		process(*argv++);
 }
 
 static void
-readflist(struct items *list, char *fname)
-{
-	FILE *fp;
-	char line[FILENAME_MAX];
-	unsigned char *s, *t;
-
-	if ((fp = fopen(fname, "rb")) == NULL)
-		die("ld: %s: %s", fname, strerror(errno));
-
-	while (fgets(line, sizeof(line), fp)) {
-		size_t n = strlen(line);
-		if (n == 0)
-			continue;
-		if (line[n-1] != '\n')
-			die("ld: %s: line too long", fname);
-		for (s = line; isspace(*s); ++s)
-			*s = '\0';
-		for (t = &line[n-1]; isspace(*t); --t)
-			*t = '\0';
-		newitem(list, xstrdup(s));
-	}
-
-	if (ferror(fp))
-		die("ld: %s: %s", fname, strerror(errno));
-
-	fclose(fp);
-}
-
-static void
 usage(void)
 {
 	fputs("usage: ld [options] [@file] file ...\n", stderr);
@@ -190,7 +155,6 @@
 main(int argc, char *argv[])
 {
 	unsigned i;
-	struct items flist = {.n = 0};
 
 	ARGBEGIN {
 	case 's':
@@ -215,16 +179,8 @@
 	if (argc == 0)
 		usage();
 
-	if (*argv[0] == '@') {
-		readflist(&flist, *argv + 1);
-		++argv;
-	}
-
-	for (; *argv; ++argv)
-		newitem(&flist, *argv);
-
-	pass1(&flist);
-	pass2(&flist);
+	pass1(argc, argv);
+	pass2(argc, argv);
 
 	return 0;
 }