aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2000-11-17 22:02:45 +0000
committerMark Whitley <markw@lineo.com>2000-11-17 22:02:45 +0000
commit005308758704443f0d100fbcf2628d1f3be1244c (patch)
treee2820fbdf8e8a842af5368201cfd1808e684b55b
parent9028e2c96aa2e8a863c8ad9aa3e870fc160f1c23 (diff)
downloadbusybox-w32-005308758704443f0d100fbcf2628d1f3be1244c.tar.gz
busybox-w32-005308758704443f0d100fbcf2628d1f3be1244c.tar.bz2
busybox-w32-005308758704443f0d100fbcf2628d1f3be1244c.zip
Applied patch from Brent Priddy <brent.priddy@adtran.com> to handle the
special-case of using newlines as field delimiters.
-rw-r--r--coreutils/cut.c61
-rw-r--r--cut.c61
2 files changed, 74 insertions, 48 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c
index 1d36a4e88..2d313cc24 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -102,10 +102,10 @@ static void decompose_list(const char *list)
102static void cut_file(FILE *file) 102static void cut_file(FILE *file)
103{ 103{
104 char *line; 104 char *line;
105 unsigned int cr_hits = 0;
105 106
106 /* go through every line in the file */ 107 /* go through every line in the file */
107 for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) { 108 for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
108
109 /* cut based on chars/bytes */ 109 /* cut based on chars/bytes */
110 if (part == 'c' || part == 'b') { 110 if (part == 'c' || part == 'b') {
111 int i; 111 int i;
@@ -129,34 +129,47 @@ static void cut_file(FILE *file)
129 char *start = line; 129 char *start = line;
130 unsigned int delims_hit = 0; 130 unsigned int delims_hit = 0;
131 131
132 for (ptr = line; (ptr = strchr(ptr, delim)) != NULL; ptr++) { 132 if (delim == '\n') {
133 delims_hit++; 133 cr_hits++;
134 if (delims_hit == (startpos - 1)) { 134 if (cr_hits >= startpos && cr_hits <= endpos) {
135 start = ptr+1; 135 while (*start && *start != '\n') {
136 }
137 if (delims_hit == endpos) {
138 break;
139 }
140 }
141 /* we didn't hit any delimeters */
142 if (delims_hit == 0 && !supress_non_delimited_lines) {
143 fputs(line, stdout);
144 }
145 /* we =did= hit some delimiters */
146 else if (delims_hit > 0) {
147 /* we have a fixed end point */
148 if (ptr) {
149 while (start < ptr) {
150 fputc(*start, stdout); 136 fputc(*start, stdout);
151 start++; 137 start++;
152 } 138 }
153 fputc('\n', stdout); 139 fputc('\n', stdout);
154 } 140 }
155 /* or we're just going til the end of the line */ 141 }
156 else { 142 else {
157 while (*start) { 143 for (ptr = line; (ptr = strchr(ptr, delim)) != NULL; ptr++) {
158 fputc(*start, stdout); 144 delims_hit++;
159 start++; 145 if (delims_hit == (startpos - 1)) {
146 start = ptr+1;
147 }
148 if (delims_hit == endpos) {
149 break;
150 }
151 }
152
153 /* we didn't hit any delimeters */
154 if (delims_hit == 0 && !supress_non_delimited_lines) {
155 fputs(line, stdout);
156 }
157 /* we =did= hit some delimiters */
158 else if (delims_hit > 0) {
159 /* we have a fixed end point */
160 if (ptr) {
161 while (start < ptr) {
162 fputc(*start, stdout);
163 start++;
164 }
165 fputc('\n', stdout);
166 }
167 /* or we're just going til the end of the line */
168 else {
169 while (*start) {
170 fputc(*start, stdout);
171 start++;
172 }
160 } 173 }
161 } 174 }
162 } 175 }
diff --git a/cut.c b/cut.c
index 1d36a4e88..2d313cc24 100644
--- a/cut.c
+++ b/cut.c
@@ -102,10 +102,10 @@ static void decompose_list(const char *list)
102static void cut_file(FILE *file) 102static void cut_file(FILE *file)
103{ 103{
104 char *line; 104 char *line;
105 unsigned int cr_hits = 0;
105 106
106 /* go through every line in the file */ 107 /* go through every line in the file */
107 for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) { 108 for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
108
109 /* cut based on chars/bytes */ 109 /* cut based on chars/bytes */
110 if (part == 'c' || part == 'b') { 110 if (part == 'c' || part == 'b') {
111 int i; 111 int i;
@@ -129,34 +129,47 @@ static void cut_file(FILE *file)
129 char *start = line; 129 char *start = line;
130 unsigned int delims_hit = 0; 130 unsigned int delims_hit = 0;
131 131
132 for (ptr = line; (ptr = strchr(ptr, delim)) != NULL; ptr++) { 132 if (delim == '\n') {
133 delims_hit++; 133 cr_hits++;
134 if (delims_hit == (startpos - 1)) { 134 if (cr_hits >= startpos && cr_hits <= endpos) {
135 start = ptr+1; 135 while (*start && *start != '\n') {
136 }
137 if (delims_hit == endpos) {
138 break;
139 }
140 }
141 /* we didn't hit any delimeters */
142 if (delims_hit == 0 && !supress_non_delimited_lines) {
143 fputs(line, stdout);
144 }
145 /* we =did= hit some delimiters */
146 else if (delims_hit > 0) {
147 /* we have a fixed end point */
148 if (ptr) {
149 while (start < ptr) {
150 fputc(*start, stdout); 136 fputc(*start, stdout);
151 start++; 137 start++;
152 } 138 }
153 fputc('\n', stdout); 139 fputc('\n', stdout);
154 } 140 }
155 /* or we're just going til the end of the line */ 141 }
156 else { 142 else {
157 while (*start) { 143 for (ptr = line; (ptr = strchr(ptr, delim)) != NULL; ptr++) {
158 fputc(*start, stdout); 144 delims_hit++;
159 start++; 145 if (delims_hit == (startpos - 1)) {
146 start = ptr+1;
147 }
148 if (delims_hit == endpos) {
149 break;
150 }
151 }
152
153 /* we didn't hit any delimeters */
154 if (delims_hit == 0 && !supress_non_delimited_lines) {
155 fputs(line, stdout);
156 }
157 /* we =did= hit some delimiters */
158 else if (delims_hit > 0) {
159 /* we have a fixed end point */
160 if (ptr) {
161 while (start < ptr) {
162 fputc(*start, stdout);
163 start++;
164 }
165 fputc('\n', stdout);
166 }
167 /* or we're just going til the end of the line */
168 else {
169 while (*start) {
170 fputc(*start, stdout);
171 start++;
172 }
160 } 173 }
161 } 174 }
162 } 175 }