summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.c
AgeCommit message (Collapse)AuthorFilesLines
2014-09-30table_display: only check width when non-zeroAndrew Gregory1-1/+1
A width of 0 indicates that either pacman is not attached to a tty or the user does not want line wrapping. Either way pacman should not fall back to the basic display. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2014-09-30avoid line wrapping if not in a tty or COLUMNS=0Andrew Gregory1-8/+16
Scripts that parse pacman's output (like pacsearch) generally do not want wrapped lines. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2014-09-23wrap fgets to retry on EINTRAndrew Gregory1-4/+4
The read() underlying fgets() can be interrupted by a signal handler causing fgets() to return NULL. Before we started handling SIGWINCH, the odds of interrupting a read were low and typically resulted in termination anyway. Replace all fgets calls with a wrapper that retries in EINTR. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2014-06-29cache terminal size, add SIGWINCH handler to resetDave Reisner1-15/+45
Refactoring getcols, yet again. We do the following: 1) Introduce a static global in src/pacman/util.c 2) getcols always prefers this cached value, but will derive it from the COLUMNS environment var, the characteristics of stdout, or a sane default (in that order). 3) Introduce a SIGWINCH signal handler to reset the cached value, meaning we only call ioctl when we don't know the value. On my machine, pacman -Syy goes from ~4300 ioctl calls to 3.
2014-05-22util: Use off_t instead of int for size valuesFlorian Pritz1-1/+1
Old output: > Total Installed Size: -1527.44 MiB Fixed: > Total Installed Size: 2568.56 MiB Bug introduced in 7b8f8753b15037bf4a88126ffde8195416432c72. Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-04-21strtrim: reset pointer after trimming leading whitespaceDave Reisner1-0/+1
Breakage introduced in 92216c5864efccac when we changed the signature of strtrim to return something more useful. Fixes FS#39976. Signed-off-by: Allan McRae <allan@archlinux.org>
2014-03-03Add events on pacnew/pacsave/pacorig file creationOlivier Brunel1-0/+13
ALPM still adds a warning to the log, but doesn't emit an event about said warning, instead using a specific event to let the frontend what happened/how to inform the user. Note that there are 2 cases for installing a .pacnew file, to not overwrite user changes and because file is in NoUpgrade. In the later case the warning was a bit different: it happened before and said "extracting" instead of "installed." Now both happen after and are phrased the same. Signed-off-by: Olivier Brunel <jjk@jjacky.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-30table_display: free memory on errorsAndrew Gregory1-4/+8
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-30Another unneeded NULL check removedSilvan Jegen1-6/+4
Signed-off-by: Silvan Jegen <s.jegen@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-28Remove ts and sw from vim modeline when noet is setFlorian Pritz1-1/+1
Forcing vim users to view files with a tabstop of 2 seems really unnecessary when noet is set. I find it much easier to read code with ts=4 and I dislike having to override the modeline by hand. Command run: find . -type f -exec sed -i '/vim.* noet/s# ts=2 sw=2##' {} + Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-10create_verbose_row: free malloc'd stringsAndrew Gregory1-5/+5
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2014-01-06Update copyright years for 2014Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-12-15Color output from pm_vasprintfAllan McRae1-2/+4
This makes sure warning and error messages from _alpm_log are colored. Fixes FS#35160. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-11-15Fix whitespace and other formatting issuesJason St. John1-1/+1
This commit: -- replaces space-based indents with tabs per the coding standards -- removes extraneous whitespace (e.g. extra spaces between function args) -- adds missing braces for a one-line if statement Signed-off-by: Jason St. John <jstjohn@purdue.edu>
2013-11-08Remove spaces between the opening "if" and the opening parenthesisJason St. John1-1/+1
Signed-off-by: Jason St. John <jstjohn@purdue.edu> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-10-14pacman/util: remove strsplitAndrew Gregory1-34/+0
strsplit was used in only one place and did the same thing as strtok. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-09-04pacman/util.c: use switch when there are fall through statementsSami Kerola1-8/+6
An 'if' clause with empty statement is allowed, but unusual construct. When 'if' is used this way the statement should at least have orphan semicolon ';'. For empty statements 'switch' feels like a native way express what is meant. Signed-off-by: Sami Kerola <kerolasa@iki.fi> [Allan] Keep comment Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-08-21Do not refer to FlySpray numbersAllan McRae1-2/+2
These references to bug numbers assume we will forever be using that bug tracker. It is better to properly comment the code instead (which was done in almost all cases anyway). Signed-off-by: Allan McRae <allan@archlinux.org>
2013-07-05Consolidate and improve table implementationsSimon Gomizelj1-115/+122
Implement both the VerbosePkgList and the summary message with the same table. Improve VerbosePkgList by caching attributes and cell's lengths instead of recaculating them. Right align every cell that containing a file size in both the VerbosePkgList and the summary. Simplify the printf statements and the alignment application. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-05-07pacman/util.c: add missing bracesAndrew Gregory1-1/+2
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-05-07pacman/util.c: fix output flushing in questionsAndrew Gregory1-3/+3
Flush stream before taking input in select_question() and only flush once during question(). Also fix some tabs inside related fprintf statements. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-04-18Fix spelling errors using 'codespell' toolAnatol Pomozov1-4/+4
Signed-off-by: Allan McRae <allan@archlinux.org>
2013-04-06use off_t for table_row_t.sizeAndrew Gregory1-2/+2
size went from off_t in _display_targets to int in add_transaction_sizes and back to off_t in humanize_size leading to potential overflows. Fixes FS#34616. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-31pm_asprintf logs 'failed to allocate' alreadySimon Gomizelj1-1/+0
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-26signature_display should also be colourizedSimon Gomizelj1-1/+1
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-14Make "[removal]" translatableAllan McRae1-2/+2
Fixes FS#34241 Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-10remove the duplicate strnlen and strndupSimon Gomizelj1-22/+0
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07colourize the output of -Qi/SiSimon Gomizelj1-3/+3
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07colourize table outputSimon Gomizelj1-1/+3
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07colourize warnings and errorsSimon Gomizelj1-2/+4
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07colourize colon_printf and questionSimon Gomizelj1-2/+7
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07standardize format functionsSimon Gomizelj1-8/+8
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07remove format from statistic messagesSimon Gomizelj1-11/+46
Remove the format component of the "Total Download Size" and related messages. The heading will be colourized, the size won't. However since the length of these messages can vary by language, we need a pretty printer to format them nicely. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07split "Packages (%zd):" messageSimon Gomizelj1-1/+1
Basically all translation messages that need colouring but _also_ happen to be format strings need to be split up. This makes it easy to conditionally embed colour codes into the output at runtime. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-03-07remove :: prefix from all messageSimon Gomizelj1-2/+15
This will substantially simplify the logic to add colours to messages. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-02-13Add format attributes to all required functionsAllan McRae1-2/+3
Fixes all clang warnings with -Wformat-literal. Also, fix genuine formating issue discovered once adding these attributes and add a cast to prevent a gcc warning. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-04Fix open braces styleGerardo Exequiel Pozzi1-1/+2
Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-04Fix missing spaces in operatorsGerardo Exequiel Pozzi1-3/+3
Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-04Split common utility functions for libalpm and pacmanAllan McRae1-50/+0
There is duplicated code in the util.c files in the libalpm and pacman source code. Split this into a separate file so that it can be shared via a symlink. This prevents code divergence between the two code bases. Also, move mbasename and mdirname from pacman/util.c into util-common.c in preparation for the following patch that uses them to add an extension to pacsave files. Signed-off-by: Allan McRae <allan@archlinux.org>
2013-01-03Update copyright year for 2013Allan McRae1-1/+1
Signed-off-by: Allan McRae <allan@archlinux.org>
2012-12-14Plug various minor memory leaksAndrew Gregory1-0/+2
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
2012-12-14Display install status of optdependenciesAllan McRae1-2/+18
When a packages (new) optdepends are printed in install (update), add a note of their current installation status. Packages currently installed are labelled with [installed] and packages to be installed in this transaction are labelled [pending]. Signed-off-by: Allan McRae <allan@archlinux.org>
2012-09-18Avoid interger overflow when calculating remaining line lengthAllan McRae1-1/+1
When the len and cidx were changed to size_t in a8a1b093, it was possible to have an integer overflow when a line ended right at the edge of the terminal width. Signed-off-by: Allan McRae <allan@archlinux.org>
2012-09-18query_fileowner, mdirname: add error checksAndrew Gregory1-1/+4
Also consolidates cleanup for query_fileowner. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2012-09-18query_fileowner: remove assumption that root is "/"Andrew Gregory1-0/+5
Returning "/" from mdirname removes it as a special case which allows us to test it like any other directory. This corrects a false positive when querying a file in / and root is not set to /. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
2012-05-20pacman: support group selection delimited by commasDave Reisner1-1/+1
We support multiple arguments being comma separated elsewhere, so this seems like a natural extension to support in our multiparse selection code. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-04-29Output "Packages" instead of "Targets"Allan McRae1-1/+1
Prefix the list of packages being installed/removed with "Packages" instead of "Targets" as they are package names by this stage. Fixes FS#23123. Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
2012-04-08Various tweaks to support building with excessive GCC warning flagsDan McGee1-1/+1
This fixes a bunch of small issues in order to enable a clean successful build with a crazy number of GCC warning flags. A lot of these changes are covered by -Wshadow, -Wformat-security, and -Wstrict-overflow=5. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-16Change table_display() to be staticDan McGee1-1/+1
It is only used inside util.c. Signed-off-by: Dan McGee <dan@archlinux.org>
2012-03-16Reduce calls to getcolsDan McGee1-28/+35
This dramatically improves upon a much older attempt in 2008 in commit ce3d70aa99ab86. We don't need to call it once per line we print unless there is a reasonable expectation of being able to resize the terminal mid-operation; this is really only the case during our callback progress bars. Some before and after numbers of ioctl() calls, gleaned from strace of the following operations (no targets to any of them to maximize the amount of output): pacman -Qii : 37768 -> 2616 (93.1% decrease) pacman -Qs : 2616 -> 4 (99.8%) pacman -Sii : 133036 -> 10926 (91.8%) pacman -Ss : 10926 -> 14 (99.9%) Obviously the search results are astounding; we only call getcols() once in the case of -Qs, and once per repo in the case of -Ss. For -Qii and -Sii we are still calling it once per package, but this is much better than once per line of info output. Signed-off-by: Dan McGee <dan@archlinux.org>