libalpm
Arch Linux Package Manager Library
Data Structures | Defines | Typedefs | Functions
util.h File Reference
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <alpm_list.h>
Include dependency graph for src/pacman/util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _pm_target_t

Defines

#define _(str)   str
#define _n(str1, str2, ct)   (ct == 1 ? str1 : str2)

Typedefs

typedef struct _pm_target_t pm_target_t

Functions

void trans_init_error (void)
int trans_init (alpm_transflag_t flags, int check_valid)
int trans_release (void)
int needs_root (void)
int check_syncdbs (size_t need_repos, int check_valid)
unsigned short getcols (void)
int rmrf (const char *path)
const char * mbasename (const char *path)
 Parse the basename of a program from a path.
char * mdirname (const char *path)
 Parse the dirname of a program from a path.
void indentprint (const char *str, size_t indent)
char * strtoupper (char *str)
size_t strtrim (char *str)
char * strreplace (const char *str, const char *needle, const char *replace)
alpm_list_tstrsplit (const char *str, const char splitchar)
 Splits a string into a list of strings using the chosen character as a delimiter.
void string_display (const char *title, const char *string)
double humanize_size (off_t bytes, const char target_unit, const char **label)
 Converts sizes in bytes into human readable units.
int table_display (const char *title, const alpm_list_t *header, const alpm_list_t *rows)
 Displays the list in table format.
void list_display (const char *title, const alpm_list_t *list)
void list_display_linebreak (const char *title, const alpm_list_t *list)
void signature_display (const char *title, alpm_siglist_t *siglist)
void display_targets (void)
int str_cmp (const void *s1, const void *s2)
void display_new_optdepends (alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg)
void display_optdepends (alpm_pkg_t *pkg)
void print_packages (const alpm_list_t *packages)
void select_display (const alpm_list_t *pkglist)
int select_question (int count)
int multiselect_question (char *array, int count)
int yesno (char *fmt,...)
int noyes (char *fmt,...)
int pm_printf (alpm_loglevel_t level, const char *format,...) __attribute__((format(printf
int int pm_asprintf (char **string, const char *format,...)
int pm_vfprintf (FILE *stream, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf
int int pm_vasprintf (char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf
int int char * strndup (const char *s, size_t n)
 Copies a string.

Define Documentation

#define _ (   str)    str

Definition at line 35 of file src/pacman/util.h.

#define _n (   str1,
  str2,
  ct 
)    (ct == 1 ? str1 : str2)

Definition at line 36 of file src/pacman/util.h.

Referenced by cb_question().


Typedef Documentation

typedef struct _pm_target_t pm_target_t

Function Documentation

int check_syncdbs ( size_t  need_repos,
int  check_valid 
)

Definition at line 103 of file src/pacman/util.c.

References _, alpm_db_get_name(), alpm_db_get_valid(), alpm_errno(), alpm_list_next(), ALPM_LOG_ERROR, alpm_option_get_syncdbs(), alpm_strerror(), config, __alpm_list_t::data, __config_t::handle, and pm_printf().

Referenced by main(), pacman_query(), pacman_sync(), and trans_init().

Here is the call graph for this function:

Here is the caller graph for this function:

void display_new_optdepends ( alpm_pkg_t oldpkg,
alpm_pkg_t newpkg 
)

Definition at line 1147 of file src/pacman/util.c.

References _, alpm_list_diff(), alpm_list_free(), alpm_pkg_get_name(), alpm_pkg_get_optdepends(), list_display_linebreak(), and str_cmp().

Referenced by cb_event().

Here is the call graph for this function:

Here is the caller graph for this function:

void display_optdepends ( alpm_pkg_t pkg)

Definition at line 1159 of file src/pacman/util.c.

References _, alpm_pkg_get_name(), alpm_pkg_get_optdepends(), and list_display_linebreak().

Referenced by cb_event().

Here is the call graph for this function:

Here is the caller graph for this function:

void display_targets ( void  )
unsigned short getcols ( void  )

Definition at line 141 of file src/pacman/util.c.

Referenced by cb_dl_progress(), cb_progress(), indentprint(), list_display(), and table_display().

Here is the caller graph for this function:

double humanize_size ( off_t  bytes,
const char  target_unit,
const char **  label 
)

Converts sizes in bytes into human readable units.

Parameters:
bytesthe size in bytes
target_unit'\0' or a short label. If equal to one of the short unit labels ('B', 'K', ...) bytes is converted to target_unit; if '\0', the first unit which will bring the value to below a threshold of 2048 will be chosen.
long_labelswhether to use short ("K") or long ("KiB") unit labels
labelwill be set to the appropriate unit label
Returns:
the size in the appropriate unit

Definition at line 1061 of file src/pacman/util.c.

Referenced by cb_dl_progress(), and dump_pkg_full().

Here is the caller graph for this function:

void indentprint ( const char *  str,
size_t  indent 
)

Definition at line 253 of file src/pacman/util.c.

References getcols().

Referenced by list_display_linebreak(), signature_display(), and string_display().

Here is the call graph for this function:

Here is the caller graph for this function:

void list_display ( const char *  title,
const alpm_list_t list 
)

Definition at line 656 of file src/pacman/util.c.

References _, alpm_list_next(), __alpm_list_t::data, and getcols().

Referenced by cb_question(), dump_pkg_full(), main(), and pacman_sync().

Here is the call graph for this function:

Here is the caller graph for this function:

void list_display_linebreak ( const char *  title,
const alpm_list_t list 
)

Definition at line 697 of file src/pacman/util.c.

References _, alpm_list_next(), __alpm_list_t::data, and indentprint().

Referenced by display_new_optdepends(), display_optdepends(), and dump_pkg_full().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* mbasename ( const char *  path)

Parse the basename of a program from a path.

Parameters:
pathpath to parse basename from
Returns:
everything following the final '/'

Definition at line 214 of file src/pacman/util.c.

char* mdirname ( const char *  path)

Parse the dirname of a program from a path.

The path returned should be freed.

Parameters:
pathpath to parse dirname from
Returns:
everything preceding the final '/'

Definition at line 229 of file src/pacman/util.c.

int multiselect_question ( char *  array,
int  count 
)

Definition at line 1279 of file src/pacman/util.c.

References _, config, __config_t::noconfirm, and strtrim().

Here is the call graph for this function:

int needs_root ( void  )
int noyes ( char *  fmt,
  ... 
)

Definition at line 1454 of file src/pacman/util.c.

Referenced by cb_question(), and pacman_remove().

Here is the caller graph for this function:

int int pm_asprintf ( char **  string,
const char *  format,
  ... 
)

Definition at line 1479 of file src/pacman/util.c.

References _, ALPM_LOG_ERROR, and pm_printf().

Referenced by pm_vasprintf(), print_packages(), select_display(), and signature_display().

Here is the call graph for this function:

Here is the caller graph for this function:

int pm_printf ( alpm_loglevel_t  level,
const char *  format,
  ... 
)
int int pm_vasprintf ( char **  string,
alpm_loglevel_t  level,
const char *  format,
va_list  args 
)
int pm_vfprintf ( FILE *  stream,
alpm_loglevel_t  level,
const char *  format,
va_list  args 
)
void print_packages ( const alpm_list_t packages)

Definition at line 1086 of file src/pacman/util.c.

References alpm_db_get_name(), alpm_list_next(), alpm_pkg_get_db(), alpm_pkg_get_name(), alpm_pkg_get_version(), config, __alpm_list_t::data, pm_asprintf(), __config_t::print_format, and strreplace().

Referenced by pacman_remove(), and sync_prepare_execute().

Here is the call graph for this function:

Here is the caller graph for this function:

int rmrf ( const char *  path)

Definition at line 166 of file src/pacman/util.c.

References rmrf().

Referenced by rmrf().

Here is the call graph for this function:

Here is the caller graph for this function:

void select_display ( const alpm_list_t pkglist)

Definition at line 1177 of file src/pacman/util.c.

References alpm_db_get_name(), alpm_list_add(), alpm_pkg_get_db(), alpm_pkg_get_name(), __alpm_list_t::data, FREELIST, __alpm_list_t::next, and pm_asprintf().

Referenced by cb_question().

Here is the call graph for this function:

Here is the caller graph for this function:

int select_question ( int  count)

Definition at line 1353 of file src/pacman/util.c.

References _, config, __config_t::noconfirm, and strtrim().

Referenced by cb_question().

Here is the call graph for this function:

Here is the caller graph for this function:

void signature_display ( const char *  title,
alpm_siglist_t siglist 
)
int str_cmp ( const void *  s1,
const void *  s2 
)

Definition at line 1142 of file src/pacman/util.c.

Referenced by display_new_optdepends().

Here is the caller graph for this function:

void string_display ( const char *  title,
const char *  string 
)

Definition at line 473 of file src/pacman/util.c.

References _, and indentprint().

Referenced by dump_pkg_full().

Here is the call graph for this function:

Here is the caller graph for this function:

int int char* strndup ( const char *  s,
size_t  n 
)

Copies a string.

Returned string needs to be freed

Parameters:
sstring to be copied
nmaximum number of characters to copy
Returns:
pointer to the new string on success, NULL on error

Definition at line 1307 of file lib/libalpm/util.c.

Referenced by strsplit().

Here is the caller graph for this function:

char* strreplace ( const char *  str,
const char *  needle,
const char *  replace 
)

Definition at line 365 of file src/pacman/util.c.

References alpm_list_add(), alpm_list_count(), alpm_list_free(), alpm_list_next(), and __alpm_list_t::data.

Referenced by print_packages().

Here is the call graph for this function:

Here is the caller graph for this function:

alpm_list_t* strsplit ( const char *  str,
const char  splitchar 
)

Splits a string into a list of strings using the chosen character as a delimiter.

Parameters:
strthe string to split
splitcharthe character to split at
Returns:
a list containing the duplicated strings

Definition at line 429 of file src/pacman/util.c.

References alpm_list_add(), and strndup().

Here is the call graph for this function:

char* strtoupper ( char *  str)

Definition at line 315 of file src/pacman/util.c.

size_t strtrim ( char *  str)

Definition at line 328 of file src/pacman/util.c.

Referenced by multiselect_question(), and select_question().

Here is the caller graph for this function:

int table_display ( const char *  title,
const alpm_list_t header,
const alpm_list_t rows 
)

Displays the list in table format.

Parameters:
titlethe tables title
headerthe column headers. column count is determined by the nr of headers
rowsthe rows to display as a list of lists of strings. the outer list represents the rows, the inner list the cells (= columns)
Returns:
-1 if not enough terminal cols available, else 0

Definition at line 615 of file src/pacman/util.c.

References _, alpm_list_count(), alpm_list_next(), ALPM_LOG_WARNING, __alpm_list_t::data, getcols(), and pm_printf().

Here is the call graph for this function:

int trans_init ( alpm_transflag_t  flags,
int  check_valid 
)

Definition at line 50 of file src/pacman/util.c.

References alpm_trans_init(), check_syncdbs(), config, __config_t::handle, and trans_init_error().

Referenced by pacman_database(), pacman_remove(), pacman_sync(), and pacman_upgrade().

Here is the call graph for this function:

Here is the caller graph for this function:

void trans_init_error ( void  )

Definition at line 64 of file src/pacman/util.c.

References _, ALPM_ERR_HANDLE_LOCK, alpm_errno(), ALPM_LOG_ERROR, alpm_option_get_lockfile(), alpm_strerror(), config, __config_t::handle, and pm_printf().

Referenced by trans_init().

Here is the call graph for this function:

Here is the caller graph for this function:

int trans_release ( void  )

Definition at line 76 of file src/pacman/util.c.

References _, alpm_errno(), ALPM_LOG_ERROR, alpm_strerror(), alpm_trans_release(), config, __config_t::handle, and pm_printf().

Referenced by pacman_database(), pacman_remove(), pacman_sync(), pacman_upgrade(), and sync_prepare_execute().

Here is the call graph for this function:

Here is the caller graph for this function:

int yesno ( char *  fmt,
  ... 
)

Definition at line 1442 of file src/pacman/util.c.

Referenced by cb_question(), pacman_remove(), pacman_sync(), and sync_prepare_execute().

Here is the caller graph for this function: