Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
utility.c File Reference
#include <locale.h>
#include "common/paths.h"
#include <glib/gstdio.h>
#include "system/macros.h"
#include "gui/screen_metrics.h"
#include "system/mem_alloc.h"
#include "common/file_location.h"
#include "common/grealpath.h"
#include "common/utility.h"
#include <unistd.h>
#include <windows.h>
#include <winbase.h>
#include <fileapi.h>
#include <math.h>
#include <glib/gi18n.h>
#include <sys/stat.h>
#include <ctype.h>
#include <librsvg/rsvg.h>
#include <librsvg/rsvg-cairo.h>
+ Include dependency graph for utility.c:

Go to the source code of this file.

Macros

#define OSD_COORDINATES_CHR_N   "N"
 
#define OSD_COORDINATES_CHR_S   "S"
 
#define OSD_COORDINATES_CHR_E   "E"
 
#define OSD_COORDINATES_CHR_W   "W"
 

Functions

int dt_util_streams_equal (FILE *first, FILE *second)
 Compare the remaining bytes of two borrowed binary streams.
 
size_t safe_strlen (const char *str)
 check if the string is empty or NULL before calling strlen()
 
gchar * dt_util_dstrcat (gchar *str, const gchar *format,...)
 
guint dt_util_str_occurence (const gchar *haystack, const gchar *needle)
 
gchar * dt_util_str_replace (const gchar *string, const gchar *pattern, const gchar *substitute)
 
gchar * dt_util_glist_to_str (const gchar *separator, GList *items)
 
GList * dt_util_glist_uniq (GList *items)
 
gchar * dt_util_fix_path (const gchar *path)
 
size_t dt_utf8_strlcpy (char *dest, const char *src, size_t n)
 
gboolean dt_util_test_image_file (const char *filename)
 
gboolean dt_util_test_writable_dir (const char *path)
 
gboolean dt_util_dir_exist (const char *dir)
 
gboolean dt_util_is_dir_empty (const char *dirname)
 
gchar * dt_util_foo_to_utf8 (const char *string)
 
static void easter (int Y, int *month, int *day)
 
dt_logo_season_t dt_util_get_logo_season (void)
 
static cairo_surface_t * _util_get_svg_img (gchar *logo, const float size)
 
cairo_surface_t * dt_util_get_logo (const float size)
 
cairo_surface_t * dt_util_get_logo_text (const float size)
 
gchar * dt_util_latitude_str (float latitude)
 
gchar * dt_util_longitude_str (float longitude)
 
gchar * dt_util_elevation_str (float elevation)
 
double dt_util_gps_string_to_number (const gchar *input)
 
gboolean dt_util_gps_rationale_to_number (const double r0_1, const double r0_2, const double r1_1, const double r1_2, const double r2_1, const double r2_2, char sign, double *result)
 
gboolean dt_util_gps_elevation_to_number (const double r_1, const double r_2, char sign, double *result)
 
gchar * dt_util_normalize_path (const gchar *_input)
 
gchar * dt_util_path_get_dirname (const gchar *filename)
 
GDateTime * dt_util_get_file_datetime (const char *const path)
 
guint dt_util_string_count_char (const char *text, const char needle)
 
void dt_util_str_to_loc_numbers_format (char *data)
 
GList * dt_util_str_to_glist (const gchar *separator, const gchar *text)
 
char * dt_util_format_exposure (const float exposuretime)
 
char * dt_read_file (const char *const filename, size_t *filesize)
 
void dt_copy_file (const char *const sourcefile, const char *dst)
 
void dt_copy_resource_file (const char *src, const char *dst)
 
RsvgDimensionData dt_get_svg_dimension (RsvgHandle *svg)
 
void dt_render_svg (RsvgHandle *svg, cairo_t *cr, double width, double height, double offset_x, double offset_y)
 
const char * dt_util_path_get_extension (const char *path)
 Locate a normal filename extension in a path basename.
 
gboolean dt_has_same_path_basename (const char *filename1, const char *filename2)
 Test whether two paths are byte-identical before their normal extensions.
 
char * dt_copy_filename_extension (const char *filename1, const char *filename2)
 Replace filename1's normal extension with filename2's normal extension.
 
gchar * dt_str_replace (const char *string, const char *search, const char *replace)
 
gchar * dt_cleanup_separators (gchar *string)
 
gchar * dt_util_remove_whitespace (const gchar *path)
 

Variables

static const char * OSD_ELEVATION_ASL = N_("above sea level")
 
static const char * OSD_ELEVATION_BSL = N_("below sea level")
 

Macro Definition Documentation

◆ OSD_COORDINATES_CHR_E

#define OSD_COORDINATES_CHR_E   "E"

Definition at line 570 of file utility.c.

◆ OSD_COORDINATES_CHR_N

#define OSD_COORDINATES_CHR_N   "N"

Definition at line 568 of file utility.c.

◆ OSD_COORDINATES_CHR_S

#define OSD_COORDINATES_CHR_S   "S"

Definition at line 569 of file utility.c.

◆ OSD_COORDINATES_CHR_W

#define OSD_COORDINATES_CHR_W   "W"

Definition at line 571 of file utility.c.

Function Documentation

◆ _util_get_svg_img()

◆ dt_cleanup_separators()

gchar * dt_cleanup_separators ( gchar *  string)

Definition at line 1091 of file utility.c.

References dt_str_replace(), and L.

Referenced by _path_cleanup(), and button_clicked().

◆ dt_copy_file()

void dt_copy_file ( const char *const  sourcefile,
const char *  dst 
)

Definition at line 943 of file utility.c.

References IS_NULL_PTR, and L.

Referenced by dt_copy_resource_file(), and write_image().

◆ dt_copy_filename_extension()

char * dt_copy_filename_extension ( const char *  filename1,
const char *  filename2 
)

Replace filename1's normal extension with filename2's normal extension.

Returns
A newly allocated string owned by the caller and released with dt_free(), or NULL when either input is NULL, either input has no normal extension, or allocation fails.

Definition at line 1062 of file utility.c.

References dt_util_path_get_extension(), IS_NULL_PTR, and L.

Referenced by _test_extension_contract(), and _test_extension_utility_rejections().

◆ dt_copy_resource_file()

void dt_copy_resource_file ( const char *  src,
const char *  dst 
)

Definition at line 975 of file utility.c.

References dt_copy_file(), dt_free, dt_loc_get_datadir(), DT_PATH_MAX, and L.

Referenced by finalize_store().

◆ dt_get_svg_dimension()

RsvgDimensionData dt_get_svg_dimension ( RsvgHandle *  svg)

Definition at line 984 of file utility.c.

References dimension(), height, L, and width.

Referenced by _util_get_svg_img(), and process().

◆ dt_has_same_path_basename()

gboolean dt_has_same_path_basename ( const char *  filename1,
const char *  filename2 
)

Test whether two paths are byte-identical before their normal extensions.

Returns
TRUE only when both paths have extensions under dt_util_path_get_extension() and their complete prefixes through the dot position are identical; FALSE for a NULL input, a missing extension, or a different prefix.

Definition at line 1049 of file utility.c.

References dt_util_path_get_extension(), FALSE, IS_NULL_PTR, and L.

Referenced by _test_extension_contract(), and _test_extension_utility_rejections().

◆ dt_read_file()

char * dt_read_file ( const char *const  filename,
size_t *  filesize 
)

◆ dt_render_svg()

void dt_render_svg ( RsvgHandle *  svg,
cairo_t *  cr,
double  width,
double  height,
double  offset_x,
double  offset_y 
)

Definition at line 1017 of file utility.c.

References height, L, and width.

Referenced by _util_get_svg_img(), and process().

◆ dt_str_replace()

gchar * dt_str_replace ( const char *  string,
const char *  search,
const char *  replace 
)

Definition at line 1082 of file utility.c.

References L, and res.

Referenced by dt_cleanup_separators().

◆ dt_utf8_strlcpy()

size_t dt_utf8_strlcpy ( char *  dest,
const char *  src,
size_t  n 
)

dt_utf8_strlcpy: @dest: buffer to fill with characters from @src @src: UTF-8 encoded string
: size of @dest

Like the BSD-standard strlcpy() function, but is careful not to truncate in the middle of a character. The @src string must be valid UTF-8 encoded text. (Use g_utf8_validate() on all text before trying to use UTF-8 utility functions with it.)

Return value: strlen(src) Implementation by Philip Page, see https://bugzilla.gnome.org/show_bug.cgi?id=520116

Definition at line 316 of file utility.c.

References L, and n.

Referenced by _get_profiles().

◆ dt_util_dir_exist()

gboolean dt_util_dir_exist ( const char *  dir)

returns true if the path represents directories

Definition at line 394 of file utility.c.

References IS_NULL_PTR, and L.

Referenced by _import_copy_file(), and dt_collection_load_filmroll().

◆ dt_util_dstrcat()

◆ dt_util_elevation_str()

gchar * dt_util_elevation_str ( float  elevation)

Definition at line 613 of file utility.c.

References L, OSD_ELEVATION_ASL, and OSD_ELEVATION_BSL.

Referenced by _metadata_view_update_values().

◆ dt_util_fix_path()

gchar * dt_util_fix_path ( const gchar *  path)

fixes the given path by replacing a possible tilde with the correct home directory

Definition at line 249 of file utility.c.

References dt_free, dt_loc_get_home_dir(), IS_NULL_PTR, and L.

Referenced by _update_preview(), dt_loc_init_generic(), and store().

◆ dt_util_foo_to_utf8()

gchar * dt_util_foo_to_utf8 ( const char *  string)

returns a valid UTF-8 string for the given char array. has to be freed with g_free().

Definition at line 419 of file utility.c.

References IS_NULL_PTR, and L.

Referenced by _exif_decode_iptc_data(), and _sanitize_db().

◆ dt_util_format_exposure()

char * dt_util_format_exposure ( const float  exposuretime)

◆ dt_util_get_file_datetime()

GDateTime * dt_util_get_file_datetime ( const char *const  path)

Definition at line 815 of file utility.c.

References error(), IS_NULL_PTR, and L.

Referenced by _init_expansion().

◆ dt_util_get_logo()

cairo_surface_t * dt_util_get_logo ( const float  size)

Definition at line 547 of file utility.c.

References _util_get_svg_img(), DT_LOGO_SEASON_NONE, dt_util_get_logo_season(), L, and size.

Referenced by size_allocate_callback().

◆ dt_util_get_logo_season()

dt_logo_season_t dt_util_get_logo_season ( void  )

returns the dt logo season to use right now

Definition at line 461 of file utility.c.

References DT_LOGO_SEASON_EASTER, DT_LOGO_SEASON_HALLOWEEN, DT_LOGO_SEASON_NONE, DT_LOGO_SEASON_XMAS, easter(), and L.

Referenced by dt_util_get_logo().

◆ dt_util_get_logo_text()

cairo_surface_t * dt_util_get_logo_text ( const float  size)

Definition at line 559 of file utility.c.

References _util_get_svg_img(), L, and size.

◆ dt_util_glist_to_str()

gchar * dt_util_glist_to_str ( const gchar *  separator,
GList *  items 
)

generate a string from the elements of the list, separated by separator. the result has to be freed.

Definition at line 193 of file utility.c.

References dt_free, i, IS_NULL_PTR, items, and L.

Referenced by _event_dnd_get(), _expand_geometry_and_misc(), _expand_rating_and_metadata(), _save_last_tag_used(), dt_history_get_items_as_string(), dt_styles_get_item_list_as_string(), dt_tag_import(), and get_query_string().

◆ dt_util_glist_uniq()

GList * dt_util_glist_uniq ( GList *  items)

take a list of strings and remove all duplicates. the result will be sorted.

Definition at line 220 of file utility.c.

References dt_free, IS_NULL_PTR, items, L, and value.

Referenced by dt_tag_get_list(), and dt_tag_get_list_export().

◆ dt_util_gps_elevation_to_number()

gboolean dt_util_gps_elevation_to_number ( const double  r_1,
const double  r_2,
char  sign,
double *  result 
)

Definition at line 688 of file utility.c.

References FALSE, IS_NULL_PTR, L, res, sign, and TRUE.

Referenced by _exif_decode_exif_data(), and dt_exif_decode_xmp_data().

◆ dt_util_gps_rationale_to_number()

gboolean dt_util_gps_rationale_to_number ( const double  r0_1,
const double  r0_2,
const double  r1_1,
const double  r1_2,
const double  r2_1,
const double  r2_2,
char  sign,
double *  result 
)

Definition at line 650 of file utility.c.

References FALSE, IS_NULL_PTR, L, min, res, sign, and TRUE.

Referenced by _exif_decode_exif_data().

◆ dt_util_gps_string_to_number()

double dt_util_gps_string_to_number ( const gchar *  input)

Definition at line 632 of file utility.c.

References L, and res.

Referenced by _lrop(), and dt_exif_decode_xmp_data().

◆ dt_util_is_dir_empty()

gboolean dt_util_is_dir_empty ( const char *  dirname)

returns true if dirname is empty

Definition at line 402 of file utility.c.

References FALSE, IS_NULL_PTR, L, n, and TRUE.

Referenced by dt_film_remove_empty().

◆ dt_util_latitude_str()

gchar * dt_util_latitude_str ( float  latitude)

◆ dt_util_longitude_str()

gchar * dt_util_longitude_str ( float  longitude)

◆ dt_util_normalize_path()

◆ dt_util_path_get_dirname()

gchar * dt_util_path_get_dirname ( const gchar *  filename)

Definition at line 800 of file utility.c.

References L.

Referenced by _import_job(), and update_preview_cb().

◆ dt_util_path_get_extension()

const char * dt_util_path_get_extension ( const char *  path)

Locate a normal filename extension in a path basename.

Both '/' and '\' delimit the basename on every platform. The final '.' qualifies only when it is not the basename's first byte and at least one byte follows it. Thus extensionless names, single-component dotfiles, empty basenames, and trailing dots have no extension; .profile.jpg has extension jpg.

Parameters
pathCaller-owned, NUL-terminated path. The public caller contract requires a non-NULL pointer.
Returns
A borrowed pointer to the first byte after the qualifying '.', or NULL when no extension exists. The pointer remains valid only while path is valid and must never be freed or modified through this return value.

Definition at line 1033 of file utility.c.

References IS_NULL_PTR, and L.

Referenced by _expand_file_and_folder(), _image_import_internal(), _init_expansion(), _test_extension_contract(), dt_copy_filename_extension(), dt_has_same_path_basename(), and dt_import_sequence_assign().

◆ dt_util_remove_whitespace()

gchar * dt_util_remove_whitespace ( const gchar *  path)

Definition at line 1102 of file utility.c.

References i, and L.

Referenced by _path_cleanup().

◆ dt_util_str_occurence()

guint dt_util_str_occurence ( const gchar *  haystack,
const gchar *  needle 
)

count the number of occurrences of needle in haystack

Definition at line 146 of file utility.c.

References L, and p.

Referenced by dt_util_str_replace().

◆ dt_util_str_replace()

gchar * dt_util_str_replace ( const gchar *  string,
const gchar *  pattern,
const gchar *  substitute 
)

◆ dt_util_str_to_glist()

GList * dt_util_str_to_glist ( const gchar *  separator,
const gchar *  text 
)

◆ dt_util_str_to_loc_numbers_format()

void dt_util_str_to_loc_numbers_format ( char *  data)

Definition at line 848 of file utility.c.

References L.

Referenced by dt_get_printer_info().

◆ dt_util_streams_equal()

int dt_util_streams_equal ( FILE *  first,
FILE *  second 
)

Compare the remaining bytes of two borrowed binary streams.

Reads bounded chunks until a mismatch or EOF, without closing either stream. The caller retains ownership and decides whether equality permits deletion.

Returns
1 for identical streams, 0 for different content, -1 on allocation or read failure.

Definition at line 94 of file utility.c.

References dt_free, IS_NULL_PTR, and L.

Referenced by _import_image(), and _test_stream_comparison_boundaries().

◆ dt_util_string_count_char()

guint dt_util_string_count_char ( const char *  text,
const char  needle 
)

returns the number of occurence of character in a text.

Definition at line 837 of file utility.c.

References L.

Referenced by dt_tag_get_subtags().

◆ dt_util_test_image_file()

gboolean dt_util_test_image_file ( const char *  filename)

returns true if a file is regular, has read access and a filesize > 0

Definition at line 345 of file utility.c.

References dt_free, FALSE, and L.

Referenced by _generate_one(), _image_import_internal(), _prerender_job(), dt_image_find_xmps(), and preload_image_cache().

◆ dt_util_test_writable_dir()

gboolean dt_util_test_writable_dir ( const char *  path)

returns true if the path represents a directory with write access

Definition at line 371 of file utility.c.

References dt_free, FALSE, IS_NULL_PTR, L, and TRUE.

Referenced by _directory_failure_setup(), _import_copy_file(), dt_folder_survey_can_start(), and dt_folder_survey_destination_preview().

◆ easter()

static void easter ( int  Y,
int *  month,
int *  day 
)
static

Definition at line 442 of file utility.c.

References d, day, f, g, i, k, L, and m.

Referenced by dt_util_get_logo_season().

◆ safe_strlen()

size_t safe_strlen ( const char *  str)

check if the string is empty or NULL before calling strlen()

Parameters
str
Returns
size_t length of the string

Definition at line 117 of file utility.c.

References L.

Referenced by dt_control_merge_hdr_job_run(), and dt_import_duplicate_get_dest_name().

Variable Documentation

◆ OSD_ELEVATION_ASL

const char* OSD_ELEVATION_ASL = N_("above sea level")
static

Definition at line 573 of file utility.c.

Referenced by dt_util_elevation_str().

◆ OSD_ELEVATION_BSL

const char* OSD_ELEVATION_BSL = N_("below sea level")
static

Definition at line 574 of file utility.c.

Referenced by dt_util_elevation_str().