[BusyBox-cvs] busybox/editors awk.c,1.3,1.4 sed.c,1.107,1.108 vi.c,1.27,1.28

Manuel Novoa III mjn3 at busybox.net
Wed Mar 19 09:13:25 UTC 2003


Update of /var/cvs/busybox/editors
In directory winder:/home/mjn3/work/busybox/editors

Modified Files:
	awk.c sed.c vi.c 
Log Message:
Major coreutils update.


Index: awk.c
===================================================================
RCS file: /var/cvs/busybox/editors/awk.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- awk.c	28 Nov 2002 11:27:23 -0000	1.3
+++ awk.c	19 Mar 2003 09:11:45 -0000	1.4
@@ -463,7 +463,7 @@
 
 static void syntax_error(const char * const message)
 {
-	error_msg("%s:%i: %s", programname, lineno, message);
+	bb_error_msg("%s:%i: %s", programname, lineno, message);
 	awk_exit(1);
 }
 
@@ -546,7 +546,7 @@
 		if (++hash->nel / hash->csize > 10)
 			hash_rebuild(hash);
 
-		l = xstrlen(name) + 1;
+		l = bb_strlen(name) + 1;
 		hi = xcalloc(sizeof(hash_item) + l, 1);
 		memcpy(hi->name, name, l);
 
@@ -571,7 +571,7 @@
 	while (*phi) {
 		hi = *phi;
 		if (strcmp(hi->name, name) == 0) {
-			hash->glen -= (xstrlen(name) + 1);
+			hash->glen -= (bb_strlen(name) + 1);
 			hash->nel--;
 			*phi = hi->next;
 			free(hi);
@@ -609,7 +609,7 @@
 
 	c = *((*s)++);
 	pps = *s;
-	if (c == '\\') c = process_escape_sequence((const char**)s);
+	if (c == '\\') c = bb_process_escape_sequence((const char**)s);
 	if (c == '\\' && *s == pps) c = *((*s)++);
 	return c;
 }
@@ -621,7 +621,7 @@
 
 static FILE *afopen(const char *path, const char *mode) {
 
-	return (*path == '-' && *(path+1) == '\0') ? stdin : xfopen(path, mode);
+	return (*path == '-' && *(path+1) == '\0') ? stdin : bb_xfopen(path, mode);
 }
 
 /* -------- working with variables (set/get/copy/etc) -------- */
@@ -683,7 +683,7 @@
 /* same as setvar_p but make a copy of string */
 static var *setvar_s(var *v, char *value) {
 
-	return setvar_p(v, (value && *value) ? xstrdup(value) : NULL);
+	return setvar_p(v, (value && *value) ? bb_xstrdup(value) : NULL);
 }
 
 /* same as setvar_s but set USER flag */
@@ -720,7 +720,7 @@
 	/* if v is numeric and has no cached string, convert it to string */
 	if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
 		fmt_num(buf, MAXVARFMT, getvar_s(V[CONVFMT]), v->number, TRUE);
-		v->string = xstrdup(buf);
+		v->string = bb_xstrdup(buf);
 		v->type |= VF_CACHED;
 	}
 	return (v->string == NULL) ? "" : v->string;
@@ -755,7 +755,7 @@
 		dest->type |= (src->type & ~VF_DONTTOUCH);
 		dest->number = src->number;
 		if (src->string)
-			dest->string = xstrdup(src->string);
+			dest->string = bb_xstrdup(src->string);
 	}
 	handle_special(dest);
 	return dest;
@@ -903,7 +903,7 @@
 					syntax_error(EMSG_UNEXP_EOS);
 				if ((*s++ = *p++) == '\\') {
 					pp = p;
-					*(s-1) = process_escape_sequence((const char **)&p);
+					*(s-1) = bb_process_escape_sequence((const char **)&p);
 					if (*pp == '\\') *s++ = '\\';
 					if (p == pp) *s++ = *p++;
 				}
@@ -1153,7 +1153,7 @@
 	if (seq->programname != programname) {
 		seq->programname = programname;
 		n = chain_node(OC_NEWSOURCE);
-		n->l.s = xstrdup(programname);
+		n->l.s = bb_xstrdup(programname);
 	}
 
 	n = seq->last;
@@ -1373,7 +1373,7 @@
 		regfree(re);
 		regfree(ire);
 	}
-	if (xstrlen(s) > 1) {
+	if (bb_strlen(s) > 1) {
 		mk_re_node(s, n, re);
 	} else {
 		n->info = (unsigned long) *s;
@@ -1441,7 +1441,7 @@
 	regmatch_t pmatch[2];
 
 	/* in worst case, each char would be a separate field */
-	*slist = s1 = xstrndup(s, xstrlen(s) * 2 + 3);
+	*slist = s1 = bb_xstrndup(s, bb_strlen(s) * 2 + 3);
 
 	c[0] = c[1] = (char)spl->info;
 	c[2] = c[3] = '\0';
@@ -1536,12 +1536,12 @@
 
 		/* recalculate $0 */
 		sep = getvar_s(V[OFS]);
-		sl = xstrlen(sep);
+		sl = bb_strlen(sep);
 		b = NULL;
 		len = 0;
 		for (i=0; i<n; i++) {
 			s = getvar_s(&Fields[i]);
-			l = xstrlen(s);
+			l = bb_strlen(s);
 			if (b) {
 				memcpy(b+len, sep, sl);
 				len += sl;
@@ -1744,7 +1744,7 @@
 	var *v, *arg;
 
 	v = nvalloc(1);
-	fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), v)));
+	fmt = f = bb_xstrdup(getvar_s(evaluate(nextarg(&n), v)));
 
 	i = 0;
 	while (*f) {
@@ -1767,7 +1767,7 @@
 
 		} else if (c == 's') {
 		    s1 = getvar_s(arg);
-			qrealloc(&b, incr+i+xstrlen(s1), &bsize);
+			qrealloc(&b, incr+i+bb_strlen(s1), &bsize);
 			i += sprintf(b+i, s, s1);
 
 		} else {
@@ -1807,7 +1807,7 @@
 
 	i = di = 0;
 	sp = getvar_s(src);
-	rl = xstrlen(repl);
+	rl = bb_strlen(repl);
 	while (regexec(re, sp, 10, pmatch, sp==getvar_s(src) ? 0:REG_NOTBOL) == 0) {
 		so = pmatch[0].rm_so;
 		eo = pmatch[0].rm_eo;
@@ -1920,7 +1920,7 @@
 		break;
 
 	  case B_ss:
-		l = xstrlen(as[0]);
+		l = bb_strlen(as[0]);
 		i = getvar_i(av[1]) - 1;
 		if (i>l) i=l; if (i<0) i=0;
 		n = (nargs > 2) ? getvar_i(av[2]) : l-i;
@@ -1938,7 +1938,7 @@
 	  case B_up:
 		to_xxx = toupper;
 lo_cont:
-		s1 = s = xstrdup(as[0]);
+		s1 = s = bb_xstrdup(as[0]);
 		while (*s1) {
 			*s1 = (*to_xxx)(*s1);
 			s1++;
@@ -1948,8 +1948,8 @@
 
 	  case B_ix:
 		n = 0;
-		ll = xstrlen(as[1]);
-		l = xstrlen(as[0]) - ll;
+		ll = bb_strlen(as[1]);
+		l = bb_strlen(as[0]) - ll;
 		if (ll > 0 && l >= 0) {
 			if (! icase) {
 				s = strstr(as[0], as[1]);
@@ -2112,10 +2112,10 @@
 				if (! X.rsm->F) {
 					if (opn == '|') {
 						if((X.rsm->F = popen(R.s, "w")) == NULL)
-							perror_msg_and_die("popen");
+							bb_perror_msg_and_die("popen");
 						X.rsm->is_pipe = 1;
 					} else {
-						X.rsm->F = xfopen(R.s, opn=='w' ? "w" : "a");
+						X.rsm->F = bb_xfopen(R.s, opn=='w' ? "w" : "a");
 					}
 				}
 				X.F = X.rsm->F;
@@ -2269,7 +2269,7 @@
 						X.rsm->F = popen(L.s, "r");
 						X.rsm->is_pipe = TRUE;
 					} else {
-						X.rsm->F = fopen(L.s, "r");		/* not xfopen! */
+						X.rsm->F = fopen(L.s, "r");		/* not bb_xfopen! */
 					}
 				}
 			} else {
@@ -2351,7 +2351,7 @@
 			  case F_le:
 			  	if (! op1)
 					L.s = getvar_s(V[F0]);
-				R.d = xstrlen(L.s);
+				R.d = bb_strlen(L.s);
 				break;
 
 			  case F_sy:
@@ -2439,12 +2439,12 @@
 		  /* concatenation (" ") and index joining (",") */
 		  case XC( OC_CONCAT ):
 		  case XC( OC_COMMA ):
-			opn = xstrlen(L.s) + xstrlen(R.s) + 2;
+			opn = bb_strlen(L.s) + bb_strlen(R.s) + 2;
 		  	X.s = (char *)xmalloc(opn);
 			strcpy(X.s, L.s);
 			if ((opinfo & OPCLSMASK) == OC_COMMA) {
 				L.s = getvar_s(V[SUBSEP]);
-				X.s = (char *)xrealloc(X.s, opn + xstrlen(L.s));
+				X.s = (char *)xrealloc(X.s, opn + bb_strlen(L.s));
 				strcat(X.s, L.s);
 			}
 			strcat(X.s, R.s);
@@ -2554,7 +2554,7 @@
 
 	char *exprc, *s, *s0, *s1;
 
-	exprc = xstrdup(expr);
+	exprc = bb_xstrdup(expr);
 	if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) {
 		free(exprc);
 		return FALSE;
@@ -2649,7 +2649,7 @@
 	}
 
 	for (envp=environ; *envp; envp++) {
-		s = xstrdup(*envp);
+		s = bb_xstrdup(*envp);
 		s1 = strchr(s, '=');
 		*(s1++) = '\0';
 		setvar_u(findvar(iamarray(V[ENVIRON]), s), s1);
@@ -2663,7 +2663,7 @@
 				break;
 			case 'v':
 				if (! is_assignment(optarg))
-					show_usage();
+					bb_show_usage();
 				break;
 			case 'f':
 				from_file = TRUE;
@@ -2680,17 +2680,17 @@
 				free(s);
 				break;
 			case 'W':
-				error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg);
+				bb_error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg);
 				break;
 
 			default:
-				show_usage();
+				bb_show_usage();
 		}
 	}
 
 	if (!from_file) {
 		if (argc == optind)
-			show_usage();
+			bb_show_usage();
 		programname="cmd. line";
 		parse_program(argv[optind++]);
 

Index: sed.c
===================================================================
RCS file: /var/cvs/busybox/editors/sed.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- sed.c	18 Mar 2003 08:37:57 -0000	1.107
+++ sed.c	19 Mar 2003 09:11:45 -0000	1.108
@@ -200,7 +200,7 @@
 		}
 		idx = index_of_next_unescaped_regexp_delim(*delimiter, my_str, ++idx);
 		if (idx == -1) {
-			error_msg_and_die("unterminated match expression");
+			bb_error_msg_and_die("unterminated match expression");
 		}
 		my_str[idx] = '\0';
 		*regex = (regex_t *)xmalloc(sizeof(regex_t));
@@ -230,7 +230,7 @@
 	/* verify that the 's' is followed by something.  That something
 	 * (typically a 'slash') is now our regexp delimiter... */
 	if (substr[idx] == '\0')
-		error_msg_and_die("bad format in substitution expression");
+		bb_error_msg_and_die("bad format in substitution expression");
 	else
 	    sed_cmd->delimiter=substr[idx];
 
@@ -238,8 +238,8 @@
 	oldidx = idx+1;
 	idx = index_of_next_unescaped_regexp_delim(sed_cmd->delimiter, substr, ++idx);
 	if (idx == -1)
-		error_msg_and_die("bad format in substitution expression");
-	match = xstrndup(substr + oldidx, idx - oldidx);
+		bb_error_msg_and_die("bad format in substitution expression");
+	match = bb_xstrndup(substr + oldidx, idx - oldidx);
 
 	/* determine the number of back references in the match string */
 	/* Note: we compute this here rather than in the do_subst_command()
@@ -257,8 +257,8 @@
 	oldidx = idx+1;
 	idx = index_of_next_unescaped_regexp_delim(sed_cmd->delimiter, substr, ++idx);
 	if (idx == -1)
-		error_msg_and_die("bad format in substitution expression");
-	sed_cmd->replace = xstrndup(substr + oldidx, idx - oldidx);
+		bb_error_msg_and_die("bad format in substitution expression");
+	sed_cmd->replace = bb_xstrndup(substr + oldidx, idx - oldidx);
 
 	/* process the flags */
 	while (substr[++idx]) {
@@ -278,7 +278,7 @@
 				if (strchr(semicolon_whitespace, substr[idx]))
 					goto out;
 				/* else */
-				error_msg_and_die("bad option in substitution expression");
+				bb_error_msg_and_die("bad option in substitution expression");
 		}
 	}
 
@@ -317,7 +317,7 @@
 	 *
 	 */
 	if ((*editstr != '\\') || ((editstr[1] != '\n') && (editstr[1] != '\r'))) {
-		error_msg_and_die("bad format in edit expression");
+		bb_error_msg_and_die("bad format in edit expression");
 	}
 
 	/* store the edit line text */
@@ -390,20 +390,20 @@
 	/* handle edit cmds: (a)ppend, (i)nsert, and (c)hange */
 	else if (strchr("aic", sed_cmd->cmd)) {
 		if ((sed_cmd->end_line || sed_cmd->end_match) && sed_cmd->cmd != 'c')
-			error_msg_and_die("only a beginning address can be specified for edit commands");
+			bb_error_msg_and_die("only a beginning address can be specified for edit commands");
 		cmdstr += parse_edit_cmd(sed_cmd, cmdstr);
 	}
 	/* handle file cmds: (r)ead */
 	else if (sed_cmd->cmd == 'r') {
 		if (sed_cmd->end_line || sed_cmd->end_match)
-			error_msg_and_die("Command only uses one address");
+			bb_error_msg_and_die("Command only uses one address");
 		cmdstr += parse_file_cmd(sed_cmd, cmdstr);
 	}
 	/* if it wasnt a single-letter command that takes no arguments
 	 * then it must be an invalid command.
 	 */
 	else if (strchr("nNpPqd=", sed_cmd->cmd) == 0) {
-		error_msg_and_die("Unsupported command %c", sed_cmd->cmd);
+		bb_error_msg_and_die("Unsupported command %c", sed_cmd->cmd);
 	}
 
 	/* give back whatever's left over */
@@ -442,7 +442,7 @@
 		cmdstr++;
 		idx = get_address(&(sed_cmd->delimiter), cmdstr, &sed_cmd->end_line, &sed_cmd->end_match);
 		if (idx == 0) {
-			error_msg_and_die("get_address: no address found in string\n"
+			bb_error_msg_and_die("get_address: no address found in string\n"
 				"\t(you probably didn't check the string you passed me)");
 		}
 		cmdstr += idx;
@@ -465,7 +465,7 @@
 		 * with <blank>s.
 		 */
 		if (isblank(cmdstr[idx]) {
-			error_msg_and_die("blank follows '!'");
+			bb_error_msg_and_die("blank follows '!'");
 		}
 #else 
 		/* skip whitespace before the command */
@@ -478,7 +478,7 @@
 
 	/* last part (mandatory) will be a command */
 	if (*cmdstr == '\0')
-		error_msg_and_die("missing command");
+		bb_error_msg_and_die("missing command");
 
 	sed_cmd->cmd = *cmdstr;
 	cmdstr++;
@@ -517,14 +517,16 @@
 	FILE *cmdfile;
 	char *line;
 	char *nextline;
+	char *e;
 
-	cmdfile = xfopen(filename, "r");
+	cmdfile = bb_xfopen(filename, "r");
 
-	while ((line = get_line_from_file(cmdfile)) != NULL) {
+	while ((line = bb_get_line_from_file(cmdfile)) != NULL) {
 		/* if a line ends with '\' it needs the next line appended to it */
-		while (line[strlen(line)-2] == '\\' &&
-				(nextline = get_line_from_file(cmdfile)) != NULL) {
-			line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
+		while (((e = last_char_is(line, '\n')) != NULL)
+			   && (e > line) && (e[-1] == '\\')
+			   && ((nextline = bb_get_line_from_file(cmdfile)) != NULL)) {
+			line = xrealloc(line, (e - line) + 1 + strlen(nextline) + 1);
 			strcat(line, nextline);
 			free(nextline);
 		}
@@ -677,20 +679,18 @@
 	int altered;
 	int i;
 
-	line = get_line_from_file(file);
+	line = bb_get_chomped_line_from_file(file);
 	if (line == NULL) {
 		return;
 	}
-	chomp(line);
 
 	/* go through every line in the file */
 	do {
 		char *next_line;
 
 		/* Read one line in advance so we can act on the last line, the '$' address */
-		next_line = get_line_from_file(file);
+		next_line = bb_get_chomped_line_from_file(file);
 
-		chomp(next_line);
 		linenum++;
 		altered = 0;
 
@@ -805,7 +805,7 @@
 							puts(line);
 							outfile = fopen(sed_cmd->filename, "r");
 							if (outfile)
-								print_file(outfile);
+								bb_xprint_and_close_file(outfile);
 								/* else if we couldn't open the output file,
 								 * no biggie, just don't print anything */
 								altered++;
@@ -817,16 +817,14 @@
 					case 'n':	/* Read next line from input */
 						free(line);
 						line = next_line;
-						next_line = get_line_from_file(file);
-						chomp(next_line);
+						next_line = bb_get_chomped_line_from_file(file);
 						linenum++;
 						break;
 					case 'N':	/* Append the next line to the current line */
 						line = realloc(line, strlen(line) + strlen(next_line) + 2);
 						strcat(line, "\n");
 						strcat(line, next_line);
-						next_line = get_line_from_file(file);
-						chomp(next_line);
+						next_line = bb_get_chomped_line_from_file(file);
 						linenum++;
 				}
 			}
@@ -880,7 +878,7 @@
 #ifdef CONFIG_FEATURE_CLEAN_UP
 	/* destroy command strings on exit */
 	if (atexit(destroy_cmd_strs) == -1)
-		perror_msg_and_die("atexit");
+		bb_perror_msg_and_die("atexit");
 #endif
 
 	/* do normal option parsing */
@@ -896,7 +894,7 @@
 				load_cmd_file(optarg);
 				break;
 			default:
-				show_usage();
+				bb_show_usage();
 		}
 	}
 
@@ -904,7 +902,7 @@
 	 * argv[optind] should be the pattern. no pattern, no worky */
 	if (ncmds == 0) {
 		if (argv[optind] == NULL)
-			show_usage();
+			bb_show_usage();
 		else {
 			add_cmd_str(argv[optind]);
 			optind++;
@@ -921,7 +919,7 @@
 		int i;
 		FILE *file;
 		for (i = optind; i < argc; i++) {
-			file = wfopen(argv[i], "r");
+			file = bb_wfopen(argv[i], "r");
 			if (file) {
 				process_file(file);
 				fclose(file);

Index: vi.c
===================================================================
RCS file: /var/cvs/busybox/editors/vi.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- vi.c	3 Dec 2002 21:48:15 -0000	1.27
+++ vi.c	19 Mar 2003 09:11:45 -0000	1.28
@@ -403,7 +403,7 @@
 		for (; optind < argc; optind++) {
 			editing = 1;	// 0=exit, 1=one file, 2+ =many files
 			free(cfn);
-			cfn = (Byte *) xstrdup(argv[optind]);
+			cfn = (Byte *) bb_xstrdup(argv[optind]);
 			edit_file(cfn);
 		}
 	}
@@ -597,7 +597,7 @@
 			*q++ = *p;
 			*q = '\0';
 		}
-		pat = (Byte *) xstrdup((char *) buf);	// save copy of pattern
+		pat = (Byte *) bb_xstrdup((char *) buf);	// save copy of pattern
 		if (*p == '/')
 			p++;
 		q = char_search(dot, pat, FORWARD, FULL);
@@ -811,7 +811,7 @@
 
 		// There is a read-able regular file
 		// make this the current file
-		q = (Byte *) xstrdup((char *) fn);	// save the cfn
+		q = (Byte *) bb_xstrdup((char *) fn);	// save the cfn
 		free(cfn);		// free the old name
 		cfn = q;			// remember new cfn
 
@@ -862,7 +862,7 @@
 		if (strlen((char *) args) > 0) {
 			// user wants a new filename
 			free(cfn);
-			cfn = (Byte *) xstrdup((char *) args);
+			cfn = (Byte *) bb_xstrdup((char *) args);
 		} else {
 			// user wants file status info
 			edit_status();
@@ -2432,7 +2432,7 @@
 	}
 	refresh(FALSE);
 	free(obufp);
-	obufp = (Byte *) xstrdup((char *) buf);
+	obufp = (Byte *) bb_xstrdup((char *) buf);
 	return (obufp);
 }
 
@@ -3263,7 +3263,7 @@
 		// Stuff the last_modifying_cmd back into stdin
 		// and let it be re-executed.
 		if (last_modifying_cmd != 0) {
-			ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd);
+			ioq = ioq_start = (Byte *) bb_xstrdup((char *) last_modifying_cmd);
 		}
 		break;
 #endif							/* CONFIG_FEATURE_VI_DOT_CMD */
@@ -3278,7 +3278,7 @@
 		if (strlen((char *) q) > 1) {	// new pat- save it and find
 			// there is a new pat
 			free(last_search_pattern);
-			last_search_pattern = (Byte *) xstrdup((char *) q);
+			last_search_pattern = (Byte *) bb_xstrdup((char *) q);
 			goto dc3;	// now find the pattern
 		}
 		// user changed mind and erased the "/"-  do nothing




More information about the busybox-cvs mailing list