The former getopts segment gave impression unknown options will
cause the program to exit with error and help is available with
-h. Neither work quite as designed, all unknown options made the
program to exit with success; and none of the options where
known.
The fix also has support for long options, and new --version
switch.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Moving the malloc out of loop will make leak to disappear, and
the command might run few jiffie quicker when there are 1+N
arguments.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This was TODO item from commit 947a7c9c. The patch also
introduces version and help switches.
[kzak@redhat.com: rewrite old_style_option()]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
New usage help screen and print version switch. Also fixes to
exit codes, util linux xmalloc replaced emalloc and every error
print is using libc error function.
[kzak@redhat.com: - minor changes in formatting and coding style]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Usage output screen got to be completely rewrote. Aim is to
assist user to determe which switches to use without reading
manual page. The change also introduced new option to see command
version.
Determination if the executable name is `page' is now easy to see
in source, and effect of using the name is mentioned in manual
page.
Rest of the change is trivial; exit values to compiler warning
removals, magic constants to preprocessor definitions, symbolic
exit values, comment pretty printing and #endif markups.
[kzak@redhat.com: - coding style
- add __unused__ attribute to signal handlers]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Solaris lacks err, errx, warn and warnx. This also means the err.h header
doesn't exist. Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Following warnings will longer appear when one will compile with
gcc flags -Wall -Wextra -pedantic
column.c:364:2: warning: comparison of unsigned expression < 0 is always false
column.c:369:2: warning: comparison of unsigned expression < 0 is always false
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This patch replaces a few functions used throughout the source:
* Renames getnum (from schedutils) to strtol_or_err
* Moves strtosize (from lib/strtosize.c)
* Moves xstrncpy (from include/xstrncpy.h)
* Adds strnlen, strnchr and strndup if not available (remove it from libmount utils)
A few Makefile.am files were modified to compile accordingly along with trivial renaming
in schedutils source code.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
For the last line of the file lenght of line should be determined
where the EOF is instead of new line. Old output was
$ printf "1 2\n3" | column -t
column: line too long
1 2
which this commit will change to
$ printf "1 2\n3" | column -t
1 2
3
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
The 'obuf' variable is not being freed after usage and this includes
when SIGINTs occur, hence add some basic signal handling.
[kzak@redhat.com - remove if-before-free ]
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
The issue is that in roll_file() we fstat() to find the file size, then read()
as much data as we can and then use the previously saved file size to mark our
position. The bug occurs if we read past the file size reported by fstat()
because more data has arrived while we were reading it. The attached patch uses
the current file position as the location marker instead, with some extra logic
to handle tailing truncated files.
[kzak@redhat.com: - fix coding style]
Signed-off-by: Dima Kogan <dkogan@cds.caltech.edu>
Signed-off-by: Karel Zak <kzak@redhat.com>
* Change indentation to 8 characters and coding style, for better reading the code.
* Add some memory allocation error handling.
* Fix memory leaks. In cases when Ctrl-C is used to exit the program,
'p' cannot be freed, so made it a global var, to share between main()
and sig_handler(). Signal handing is necessary to fix some leaks, so
added a very basic, non invasive, mechanism.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
In a multibyte locale such as en_GB.UTF-8, the pg command cannot handle files
containing a form feed character (ASCII 0x0c) at the start of a line. The
program enters an infinite loop.
I've traced the problem to the function endline_for_mb in file pg.c. The code
assumes that the libc function wcwidth will return a nonnegative value, which
is not true for a form feed character. wcwidth returns -1 and the unsigned
variable "pos" goes into underflow.
I'll attach a patch which tests whether the character is printable before
calling wcwidth. If not, it uses instead the width of the constant L'?' which
is later used to replace nonprintable characters. I trust that we can assume
printability of this constant :-)
Steps to Reproduce:
1. Select a multibyte locale (tested with en_GB.UTF-8)
2. Create a file with a form feed character (0x0c) at the start of a line.
3. Try to display this file using the pg command.
Reported-by: Mark Calderbank <m.calderbank@iname.com>
Reported-by: Mike Frysinger <vapier@gentoo.org>
Addresses: https://bugs.gentoo.org/297717
Signed-off-by: Karel Zak <kzak@redhat.com>