annotate toys/posix/cut.c @ 1134:ff22f24c9661 draft

Fix cut. Some commands went in before "pending", and thus need cleanup but are enabled in defconfig. The fact cut used a function out of lib/pending.c is a hint it might be in this category...
author Rob Landley <rob@landley.net>
date Sat, 30 Nov 2013 00:57:26 -0600
parents 2bfdd63382b4
children fc1bb49e58a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* cut.c - Cut from a file.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * Copyright 2012 Ranjan Kumar <ranjankumar.bth@gmail.com>, Kyungwan Han <asura321@gamil.com>
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
6
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
7 USE_CUT(NEWTOY(cut, "b:|c:|f:|d:sn[!cbf]", TOYFLAG_BIN))
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
8
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
9 config CUT
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
10 bool "cut"
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
11 default y
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
12 help
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
13 usage: cut OPTION... [FILE]...
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
14 Print selected parts of lines from each FILE to standard output.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
15 -b LIST select only these bytes from LIST.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
16 -c LIST select only these characters from LIST.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
17 -f LIST select only these fields.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
18 -d DELIM use DELIM instead of TAB for field delimiter.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
19 -s do not print lines not containing delimiters.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
20 -n don't split multibyte characters (Ignored).
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
21 */
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
22 #define FOR_cut
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
23 #include "toys.h"
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
24
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
25 typedef struct _slist {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
26 int start_position;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
27 int end_position;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
28 struct _slist *next;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
29 } SLIST;
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
30
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
31 GLOBALS(
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
32 char *delim;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
33 char *flist;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
34 char *clist;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
35 char *blist;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
36 struct _slist *slist_head;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
37 unsigned nelem;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
38 )
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
39
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
40 void (*do_cut)(int);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
41 static void do_fcut(int fd);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
42 static void do_bccut(int fd);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
43 static void free_list(void);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
44
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
45 /*
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
46 * add items in the slist.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
47 */
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
48 static void add_to_list(int start, int end)
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
49 {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
50 SLIST *current, *head_ref, *temp1_node;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
51
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
52 head_ref = TT.slist_head;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
53 temp1_node = (SLIST *)xzalloc(sizeof(SLIST));
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
54 temp1_node->start_position = start;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
55 temp1_node->end_position = end;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
56 temp1_node->next = NULL;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
57
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
58 /* Special case for the head end */
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
59 if (head_ref == NULL || (head_ref)->start_position >= start) {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
60 temp1_node->next = head_ref;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
61 head_ref = temp1_node;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
62 } else {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
63 /* Locate the node before the point of insertion */
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
64 current = head_ref;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
65 while (current->next!=NULL && current->next->start_position < temp1_node->start_position)
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
66 current = current->next;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
67 temp1_node->next = current->next;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
68 current->next = temp1_node;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
69 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
70 TT.slist_head = head_ref;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
71 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
72
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
73 // parse list and add to slist.
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
74 static void parse_list(char *list)
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
75 {
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
76 for (;;) {
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
77 char *ctoken = strsep(&list, ","), *dtoken;
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
78 int start = 0, end = INT_MAX;
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
79
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
80 if (!ctoken) break;
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
81 if (!*ctoken) continue;
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
82
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
83 //Get start position.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
84 if (*(dtoken = strsep(&ctoken, "-"))) {
1134
ff22f24c9661 Fix cut.
Rob Landley <rob@landley.net>
parents: 1067
diff changeset
85 start = atolx_range(dtoken, 0, INT_MAX);
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
86 start = (start?(start-1):start);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
87 }
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
88
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
89 //Get end position.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
90 if (!ctoken) end = -1; //case e.g. 1,2,3
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
91 else if (*ctoken) {//case e.g. N-M
1134
ff22f24c9661 Fix cut.
Rob Landley <rob@landley.net>
parents: 1067
diff changeset
92 end = atolx_range(ctoken, 0, INT_MAX);
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
93 if (!end) end = INT_MAX;
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
94 end--;
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
95 if(end == start) end = -1;
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
96 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
97 add_to_list(start, end);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
98 TT.nelem++;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
99 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
100 //if list is missing in command line.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
101 if (!TT.nelem) error_exit("missing positions list");
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
102 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
103
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
104 /*
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
105 * retrive data from the file/s.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
106 */
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
107 static void get_data(void)
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
108 {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
109 char **argv = toys.optargs; //file name.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
110 toys.exitval = EXIT_SUCCESS;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
111
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
112 if(!*argv) do_cut(0); //for stdin
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
113 else {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
114 for(; *argv; ++argv) {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
115 if(strcmp(*argv, "-") == 0) do_cut(0); //for stdin
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
116 else {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
117 int fd = open(*argv, O_RDONLY, 0);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
118 if(fd < 0) {//if file not present then continue with other files.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
119 perror_msg(*argv);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
120 continue;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
121 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
122 do_cut(fd);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
123 xclose(fd);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
124 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
125 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
126 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
127 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
128
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
129 void cut_main(void)
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
130 {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
131 char delimiter = '\t'; //default delimiter.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
132 char *list;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
133
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
134 TT.nelem = 0;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
135 TT.slist_head = NULL;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
136
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
137 //Get list and assign the function.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
138 if (toys.optflags & FLAG_f) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
139 list = TT.flist;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
140 do_cut = do_fcut;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
141 } else if (toys.optflags & FLAG_c) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
142 list = TT.clist;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
143 do_cut = do_bccut;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
144 } else {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
145 list = TT.blist;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
146 do_cut = do_bccut;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
147 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
148
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
149 if (toys.optflags & FLAG_d) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
150 //delimiter must be 1 char.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
151 if(TT.delim[0] && TT.delim[1])
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
152 perror_exit("the delimiter must be a single character");
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
153 delimiter = TT.delim[0];
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
154 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
155
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
156 if(!(toys.optflags & FLAG_d) && (toys.optflags & FLAG_f)) {
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
157 TT.delim = xzalloc(2);
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
158 TT.delim[0] = delimiter;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
159 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
160
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
161 //when field is not specified, cutting has some special handling.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
162 if (!(toys.optflags & FLAG_f)) {
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
163 if (toys.optflags & FLAG_s)
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
164 perror_exit("suppressing non-delimited lines operating on fields");
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
165 if (delimiter != '\t')
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
166 perror_exit("an input delimiter may be specified only when operating on fields");
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
167 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
168
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
169 parse_list(list);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
170 get_data();
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
171 if (!(toys.optflags & FLAG_d) && (toys.optflags & FLAG_f)) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
172 free(TT.delim);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
173 TT.delim = NULL;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
174 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
175 free_list();
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
176 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
177
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
178 // perform cut operation on the given delimiter.
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
179 static void do_fcut(int fd)
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
180 {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
181 char *buff;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
182 char *delimiter = TT.delim;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
183
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
184 while ((buff = get_line(fd))) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
185 //does line have any delimiter?.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
186 if (strrchr(buff, (int)delimiter[0]) == NULL) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
187 //if not then print whole line and move to next line.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
188 if (!(toys.optflags & FLAG_s)) xputs(buff);
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
189 continue;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
190 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
191
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
192 unsigned cpos = 0;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
193 int start, ndelimiters = -1;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
194 int nprinted_fields = 0;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
195 char *pfield = xzalloc(strlen(buff) + 1);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
196 SLIST *temp_node = TT.slist_head;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
197
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
198 if (temp_node != NULL) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
199 //process list on each line.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
200 while (cpos < TT.nelem && buff) {
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
201 if (!temp_node) break;
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
202 start = temp_node->start_position;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
203 do {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
204 char *field = NULL;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
205 //count number of delimeters per line.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
206 while (buff) {
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
207 if (ndelimiters < start) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
208 ndelimiters++;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
209 field = strsep(&buff, delimiter);
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
210 } else break;
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
211 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
212 //print field (if not yet printed).
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
213 if (!pfield[ndelimiters]) {
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
214 if (ndelimiters == start) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
215 //put delimiter.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
216 if (nprinted_fields++ > 0) xputc(delimiter[0]);
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
217 if (field) fputs(field, stdout);
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
218 //make sure this field won't print again.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
219 pfield[ndelimiters] = (char) 0x23; //put some char at this position.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
220 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
221 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
222 start++;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
223 if ((temp_node->end_position < 0) || (!buff)) break;
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
224 } while(start <= temp_node->end_position);
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
225 temp_node = temp_node->next;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
226 cpos++;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
227 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
228 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
229 xputc('\n');
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
230 free(pfield);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
231 pfield = NULL;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
232 }//End of while loop.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
233 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
234
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
235 // perform cut operation char or byte.
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
236 static void do_bccut(int fd)
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
237 {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
238 char *buff;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
239
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
240 while ((buff = get_line(fd)) != NULL) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
241 unsigned cpos = 0;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
242 int buffln = strlen(buff);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
243 char *pfield = xzalloc(buffln + 1);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
244 SLIST *temp_node = TT.slist_head;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
245
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
246 if (temp_node != NULL) {
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
247 while (cpos < TT.nelem) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
248 int start;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
249
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
250 if (!temp_node) break;
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
251 start = temp_node->start_position;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
252 while (start < buffln) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
253 //to avoid duplicate field printing.
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
254 if (pfield[start]) {
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
255 if (++start <= temp_node->end_position) continue;
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
256 temp_node = temp_node->next;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
257 break;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
258 } else {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
259 //make sure this field won't print again.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
260 pfield[start] = (char) 0x23; //put some char at this position.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
261 xputc(buff[start]);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
262 }
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
263 if (++start > temp_node->end_position) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
264 temp_node = temp_node->next;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
265 break;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
266 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
267 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
268 cpos++;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
269 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
270 xputc('\n');
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
271 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
272 free(pfield);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
273 pfield = NULL;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
274 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
275 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
276
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
277 /*
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
278 * free the slist.
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
279 */
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
280 static void free_list(void)
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
281 {
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
282 SLIST *temp;
1067
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
283
2bfdd63382b4 First pass of cut cleanup, and make test script slightly happier with the concept of 80 character lines.
Rob Landley <rob@landley.net>
parents: 780
diff changeset
284 while (TT.slist_head != NULL) {
706
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
285 temp = TT.slist_head->next;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
286 free(TT.slist_head);
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
287 TT.slist_head = temp;
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
288 }
35a9f9c5b53f Commit 698 adding cut should ahve included the actual cut.c file. (Oops.)
Rob Landley <rob@landley.net>
parents:
diff changeset
289 }