-
- f++;
-
- /* keep going as long as we have a line to work with, this is a
- * list, and we're not at the end of that list */
- } while (line && cut_lists[c].endpos != NON_RANGE && f <= cut_lists[c].endpos);
- }
-
- /* if we printed anything at all, we need to finish it with a newline cuz
- * we were handed a chomped line */
- putchar('\n');
-
- free(printed);
-}
-
-
-static void cut_file_by_lines(const char *line, unsigned int linenum)
-{
- static int c = 0;
- static int l = -1;
-
- /* I can't initialize this above cuz the "initializer isn't
- * constant" *sigh* */
- if (l == -1)
- l = cut_lists[c].startpos;
-
- /* get out if we have no more lists to process or if the lines are lower
- * than what we're interested in */
- if (c >= nlists || linenum < l)
- return;
-
- /* if the line we're looking for is lower than the one we were passed, it
- * means we displayed it already, so move on */
- while (l < linenum) {
- l++;
- /* move on to the next list if we're at the end of this one */
- if (cut_lists[c].endpos == NON_RANGE || l > cut_lists[c].endpos) {
- c++;
- /* get out if there's no more lists to process */
- if (c >= nlists)
- return;
- l = cut_lists[c].startpos;
- /* get out if the current line is lower than the one we just became
- * interested in */
- if (linenum < l)
- return;
- }
- }
-
- /* If we made it here, it means we've found the line we're looking for, so print it */
- puts(line);
-}
-
-
-/*
- * snippy-snip
- */
-static void cut_file(FILE *file)
-{
- char *line = NULL;
- unsigned int linenum = 0; /* keep these zero-based to be consistent */
-
- /* go through every line in the file */
- while ((line = bb_get_chomped_line_from_file(file)) != NULL) {
-
- /* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
- if ((part & (OPT_CHAR_FLGS | OPT_BYTE_FLGS)))
- cut_line_by_chars(line);
-
- /* cut based on fields */
- else {
- if (delim == '\n')
- cut_file_by_lines(line, linenum);
- else
- cut_line_by_fields(line);