Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more regexp boiler plate reduction #29

Closed
wants to merge 8 commits into from
Closed
155 changes: 80 additions & 75 deletions src/bauhaus/bauhaus.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/common/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void dt_cache_cleanup(dt_cache_t *cache)
g_hash_table_destroy(cache->hashtable);
for(GList *l = cache->lru; l; l = g_list_next(l))
{
dt_cache_entry_t *entry = (dt_cache_entry_t *)l->data;
dt_cache_entry_t *entry = l->data;

if(cache->cleanup)
{
Expand Down Expand Up @@ -340,7 +340,7 @@ void dt_cache_gc(dt_cache_t *cache,
GList *l = cache->lru;
while(l)
{
dt_cache_entry_t *entry = (dt_cache_entry_t *)l->data;
dt_cache_entry_t *entry = l->data;
assert(entry->link->data == entry);
l = g_list_next(l); // we might remove this element, so walk to
// the next one while we still have the
Expand Down
5 changes: 2 additions & 3 deletions src/common/colorlabels.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void _pop_undo(gpointer user_data,
{
for(GList *list = (GList *)data; list; list = g_list_next(list))
{
dt_undo_colorlabels_t *undocolorlabels = (dt_undo_colorlabels_t *)list->data;
dt_undo_colorlabels_t *undocolorlabels = list->data;

const uint8_t before = (action == DT_ACTION_UNDO)
? undocolorlabels->after : undocolorlabels->before;
Expand Down Expand Up @@ -219,8 +219,7 @@ static void _colorlabels_execute(const GList *imgs,

if(undo_on)
{
dt_undo_colorlabels_t *undocolorlabels =
(dt_undo_colorlabels_t *)malloc(sizeof(dt_undo_colorlabels_t));
dt_undo_colorlabels_t *undocolorlabels = malloc(sizeof(dt_undo_colorlabels_t));
undocolorlabels->imgid = imgid;
undocolorlabels->before = before;
undocolorlabels->after = after;
Expand Down
12 changes: 6 additions & 6 deletions src/common/colorspaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ static void _update_display_profile(guchar *tmp_data,
{
for(GList *iter = darktable.color_profiles->profiles; iter; iter = g_list_next(iter))
{
dt_colorspaces_color_profile_t *p = (dt_colorspaces_color_profile_t *)iter->data;
dt_colorspaces_color_profile_t *p = iter->data;
if(p->type == DT_COLORSPACE_DISPLAY)
{
if(p->profile) dt_colorspaces_cleanup_profile(p->profile);
Expand Down Expand Up @@ -1279,7 +1279,7 @@ static void _update_display2_profile(guchar *tmp_data,
{
for(GList *iter = darktable.color_profiles->profiles; iter; iter = g_list_next(iter))
{
dt_colorspaces_color_profile_t *p = (dt_colorspaces_color_profile_t *)iter->data;
dt_colorspaces_color_profile_t *p = iter->data;
if(p->type == DT_COLORSPACE_DISPLAY2)
{
if(p->profile) dt_colorspaces_cleanup_profile(p->profile);
Expand Down Expand Up @@ -1599,7 +1599,7 @@ dt_colorspaces_t *dt_colorspaces_init()
temp_profiles = load_profile_from_dir("in");
for(GList *iter = temp_profiles; iter; iter = g_list_next(iter))
{
dt_colorspaces_color_profile_t *prof = (dt_colorspaces_color_profile_t *)iter->data;
dt_colorspaces_color_profile_t *prof = iter->data;
prof->in_pos = ++in_pos;
}
res->profiles = g_list_concat(res->profiles, temp_profiles);
Expand All @@ -1608,7 +1608,7 @@ dt_colorspaces_t *dt_colorspaces_init()
temp_profiles = load_profile_from_dir("out");
for(GList *iter = temp_profiles; iter; iter = g_list_next(iter))
{
dt_colorspaces_color_profile_t *prof = (dt_colorspaces_color_profile_t *)iter->data;
dt_colorspaces_color_profile_t *prof = iter->data;
// FIXME: do want to filter out non-RGB profiles for cases besides
// histogram profile? colorin is OK with RGB or XYZ, print is OK
// with anything which LCMS likes, otherwise things are more
Expand Down Expand Up @@ -1706,7 +1706,7 @@ void dt_colorspaces_cleanup(dt_colorspaces_t *self)

for(GList *iter = self->profiles; iter; iter = g_list_next(iter))
{
dt_colorspaces_color_profile_t *p = (dt_colorspaces_color_profile_t *)iter->data;
dt_colorspaces_color_profile_t *p = iter->data;
dt_colorspaces_cleanup_profile(p->profile);
}
g_list_free_full(self->profiles, free);
Expand Down Expand Up @@ -2222,7 +2222,7 @@ static const dt_colorspaces_color_profile_t *_get_profile
{
for(GList *iter = self->profiles; iter; iter = g_list_next(iter))
{
dt_colorspaces_color_profile_t *p = (dt_colorspaces_color_profile_t *)iter->data;
dt_colorspaces_color_profile_t *p = iter->data;
if(((direction & DT_PROFILE_DIRECTION_IN && p->in_pos > -1)
|| (direction & DT_PROFILE_DIRECTION_OUT && p->out_pos > -1)
|| (direction & DT_PROFILE_DIRECTION_WORK && p->work_pos > -1)
Expand Down
3 changes: 1 addition & 2 deletions src/common/darktable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,7 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load
if(*c == '=' && *(c + 1) != '\0')
{
*c++ = '\0';
dt_conf_string_entry_t *entry =
(dt_conf_string_entry_t *)g_malloc(sizeof(dt_conf_string_entry_t));
dt_conf_string_entry_t *entry = g_malloc(sizeof(dt_conf_string_entry_t));
entry->key = g_strdup(keyval);
entry->value = g_strdup(c);
config_override = g_slist_append(config_override, entry);
Expand Down
3 changes: 1 addition & 2 deletions src/common/darktable_ucs_22_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ static inline struct dt_iop_order_iccprofile_info_t * D65_adapt_iccprofile(struc
if(work_profile) // && !isnan(work_profile->matrix_in[0][0]))
{
// Alloc
struct dt_iop_order_iccprofile_info_t *white_adapted_profile =
(dt_iop_order_iccprofile_info_t *)dt_alloc_aligned(sizeof(dt_iop_order_iccprofile_info_t));
struct dt_iop_order_iccprofile_info_t *white_adapted_profile = dt_alloc_aligned(sizeof(dt_iop_order_iccprofile_info_t));

// Init a new temp profile by copying the base profile
memcpy(white_adapted_profile, work_profile, sizeof(dt_iop_order_iccprofile_info_t));
Expand Down
8 changes: 4 additions & 4 deletions src/common/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version)
// it will be used to create the pipe and update the iop_order on history
for(GList *priorities = prior_v1; priorities; priorities = g_list_next(priorities))
{
dt_iop_order_entry_t *prior = (dt_iop_order_entry_t *)priorities->data;
dt_iop_order_entry_t *prior = priorities->data;

sqlite3_prepare_v2(
db->handle,
Expand Down Expand Up @@ -1280,7 +1280,7 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version)

while(e)
{
dt_iop_order_entry_t *e_entry = (dt_iop_order_entry_t *)e->data;
dt_iop_order_entry_t *e_entry = e->data;

GList *s = iop_order_list;
while(s && strcmp(((dt_iop_order_entry_t *)s->data)->operation, e_entry->operation))
Expand All @@ -1307,7 +1307,7 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version)

for(e = item_list; e; e = g_list_next(e))
{
dt_iop_order_entry_t *e_entry = (dt_iop_order_entry_t *)e->data;
dt_iop_order_entry_t *e_entry = e->data;
iop_order_list = g_list_prepend(iop_order_list, e_entry);
}

Expand Down Expand Up @@ -2877,7 +2877,7 @@ static int _upgrade_data_schema_step(dt_database_t *db, int version)
// it will be used to create the pipe and update the iop_order on history
for(GList *priorities = prior_v1; priorities; priorities = g_list_next(priorities))
{
dt_iop_order_entry_t *prior = (dt_iop_order_entry_t *)priorities->data;
dt_iop_order_entry_t *prior = priorities->data;

sqlite3_prepare_v2(
db->handle,
Expand Down
10 changes: 5 additions & 5 deletions src/common/gpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ gboolean dt_gpx_get_location(struct dt_gpx_t *gpx, GDateTime *timestamp, dt_imag

for(GList *item = gpx->trkpts; item; item = g_list_next(item))
{
dt_gpx_track_point_t *tp = (dt_gpx_track_point_t *)item->data;
dt_gpx_track_point_t *tp = item->data;

/* if timestamp is out of time range return false but fill
closest location value start or end point */
Expand All @@ -169,7 +169,7 @@ gboolean dt_gpx_get_location(struct dt_gpx_t *gpx, GDateTime *timestamp, dt_imag
return FALSE;
}

dt_gpx_track_point_t *tp_next = (dt_gpx_track_point_t *)item->next->data;
dt_gpx_track_point_t *tp_next = item->next->data;
/* check if timestamp is within current and next trackpoint */
const gint cmp_n = g_date_time_compare(timestamp, tp_next->time);
if(item->next && cmp_n <= 0)
Expand Down Expand Up @@ -405,7 +405,7 @@ void _gpx_parser_text(GMarkupParseContext *context, const gchar *text, gsize tex
dt_print(DT_DEBUG_ALWAYS,
"broken GPX file, failed to pars is8601 time '%s' for trackpoint\n", text);
}
dt_gpx_track_segment_t *ts = (dt_gpx_track_segment_t *)gpx->trksegs->data;
dt_gpx_track_segment_t *ts = gpx->trksegs->data;
if(ts)
{
ts->nb_trkpt++;
Expand All @@ -431,12 +431,12 @@ GList *dt_gpx_get_trkpts(struct dt_gpx_t *gpx, const guint segid)
GList *pts = NULL;
GList *ts = g_list_nth(gpx->trksegs, segid);
if(!ts) return pts;
dt_gpx_track_segment_t *tsd = (dt_gpx_track_segment_t *)ts->data;
dt_gpx_track_segment_t *tsd = ts->data;
GList *tps = g_list_find(gpx->trkpts, tsd->trkpt);
if(!tps) return pts;
for(GList *tp = tps; tp; tp = g_list_next(tp))
{
dt_gpx_track_point_t *tpd = (dt_gpx_track_point_t *)tp->data;
dt_gpx_track_point_t *tpd = tp->data;
if(tpd->segid != segid) return pts;
dt_geo_map_display_point_t *p = g_malloc0(sizeof(dt_geo_map_display_point_t));
p->lat = tpd->latitude;
Expand Down
23 changes: 11 additions & 12 deletions src/common/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static dt_dev_history_item_t *_search_history_by_module(dt_develop_t *dev,
dt_dev_history_item_t *hist_mod = NULL;
for(GList *history = dev->history; history; history = g_list_next(history))
{
dt_dev_history_item_t *hist = (dt_dev_history_item_t *)(history->data);
dt_dev_history_item_t *hist = history->data;

if(hist->module == module)
{
Expand All @@ -254,7 +254,7 @@ static dt_iop_module_t *_search_list_iop_by_module(GList *modules_list,
dt_iop_module_t *mod_ret = NULL;
for(GList *modules = modules_list; modules; modules = g_list_next(modules))
{
dt_iop_module_t *mod = (dt_iop_module_t *)(modules->data);
dt_iop_module_t *mod = modules->data;

if(mod == module)
{
Expand Down Expand Up @@ -289,7 +289,7 @@ static void _fill_used_forms(GList *forms_list,
{
for(GList *grpts = form->points; grpts; grpts = g_list_next(grpts))
{
dt_masks_point_group_t *grpt = (dt_masks_point_group_t *)grpts->data;
dt_masks_point_group_t *grpt = grpts->data;
_fill_used_forms(forms_list, grpt->formid, used, nb);
}
}
Expand Down Expand Up @@ -346,7 +346,7 @@ gboolean dt_history_merge_module_into_history(dt_develop_t *dev_dest,
modules_dest;
modules_dest = g_list_next(modules_dest))
{
dt_iop_module_t *mod_dest = (dt_iop_module_t *)modules_dest->data;
dt_iop_module_t *mod_dest = modules_dest->data;

// look for not yet used module
if(strcmp(mod_src->op, mod_dest->op) == 0
Expand Down Expand Up @@ -461,7 +461,7 @@ gboolean dt_history_merge_module_into_history(dt_develop_t *dev_dest,
modules_dest;
modules_dest = g_list_next(modules_dest))
{
dt_iop_module_t *mod = (dt_iop_module_t *)(modules_dest->data);
dt_iop_module_t *mod = modules_dest->data;

if(module_duplicate != NULL)
{
Expand Down Expand Up @@ -676,7 +676,7 @@ static gboolean _history_copy_and_paste_on_image_merge(const dt_imgid_t imgid,
modules_src;
modules_src = g_list_next(modules_src))
{
dt_iop_module_t *mod_src = (dt_iop_module_t *)(modules_src->data);
dt_iop_module_t *mod_src = modules_src->data;

// copy from history only if
if((_search_history_by_module(dev_src, mod_src) != NULL)
Expand Down Expand Up @@ -708,7 +708,7 @@ static gboolean _history_copy_and_paste_on_image_merge(const dt_imgid_t imgid,

for(GList *l = mod_list; l; l = g_list_next(l))
{
dt_iop_module_t *mod = (dt_iop_module_t *)l->data;
dt_iop_module_t *mod = l->data;
const gboolean autoinit = GPOINTER_TO_INT(ai->data);

dt_history_merge_module_into_history
Expand Down Expand Up @@ -780,7 +780,7 @@ static gboolean _history_copy_and_paste_on_image_overwrite(const dt_imgid_t imgi
{
for(GList *modules = darktable.iop; modules; modules = g_list_next(modules))
{
dt_iop_module_so_t *module = (dt_iop_module_so_t *)modules->data;
dt_iop_module_so_t *module = modules->data;

if(dt_history_module_skip_copy(module->flags()))
{
Expand Down Expand Up @@ -1479,7 +1479,7 @@ gboolean dt_history_check_module_exists_list(GList *hist,
{
for(GList *h = hist; h; h = g_list_next(h))
{
const dt_history_item_t *item = (dt_history_item_t *)(h->data);
const dt_history_item_t *item = h->data;

if(!g_strcmp0(item->op, operation) && (item->enabled || !enabled))
return TRUE;
Expand All @@ -1493,10 +1493,9 @@ GList *dt_history_duplicate(GList *hist)

for(GList *h = hist; h; h = g_list_next(h))
{
const dt_dev_history_item_t *old = (dt_dev_history_item_t *)(h->data);
const dt_dev_history_item_t *old = h->data;

dt_dev_history_item_t *new =
(dt_dev_history_item_t *)malloc(sizeof(dt_dev_history_item_t));
dt_dev_history_item_t *new = malloc(sizeof(dt_dev_history_item_t));

memcpy(new, old, sizeof(dt_dev_history_item_t));

Expand Down
16 changes: 6 additions & 10 deletions src/common/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ static void _image_set_monochrome_flag(const dt_imgid_t imgid,

if(undo_on)
{
dt_undo_monochrome_t *undomono =
(dt_undo_monochrome_t *)malloc(sizeof(dt_undo_monochrome_t));
dt_undo_monochrome_t *undomono = malloc(sizeof(dt_undo_monochrome_t));
undomono->imgid = imgid;
undomono->before = mask_bw;
undomono->after = mask;
Expand Down Expand Up @@ -644,7 +643,7 @@ static void _pop_undo(gpointer user_data,

for(GList *list = (GList *)data; list; list = g_list_next(list))
{
dt_undo_geotag_t *undogeotag = (dt_undo_geotag_t *)list->data;
dt_undo_geotag_t *undogeotag = list->data;
const dt_image_geoloc_t *geoloc =
(action == DT_ACTION_UNDO) ? &undogeotag->before : &undogeotag->after;

Expand All @@ -670,7 +669,7 @@ static void _pop_undo(gpointer user_data,

for(GList *list = (GList *)data; list; list = g_list_next(list))
{
dt_undo_datetime_t *undodatetime = (dt_undo_datetime_t *)list->data;
dt_undo_datetime_t *undodatetime = list->data;

_set_datetime(undodatetime->imgid, (action == DT_ACTION_UNDO)
? undodatetime->before : undodatetime->after);
Expand Down Expand Up @@ -1462,8 +1461,7 @@ static dt_imgid_t _image_duplicate_with_version(const dt_imgid_t imgid,
{
if(undo)
{
dt_undo_duplicate_t *dupundo =
(dt_undo_duplicate_t *)malloc(sizeof(dt_undo_duplicate_t));
dt_undo_duplicate_t *dupundo = malloc(sizeof(dt_undo_duplicate_t));
dupundo->orig_imgid = imgid;
dupundo->version = newversion;
dupundo->new_imgid = newid;
Expand Down Expand Up @@ -3001,8 +2999,7 @@ static void _image_set_datetimes(const GList *img,
const _datetime_t *datetime = &g_array_index(dtime, _datetime_t, i);
if(undo_on)
{
dt_undo_datetime_t *undodatetime =
(dt_undo_datetime_t *)malloc(sizeof(dt_undo_datetime_t));
dt_undo_datetime_t *undodatetime = malloc(sizeof(dt_undo_datetime_t));
undodatetime->imgid = imgid;
dt_image_get_datetime(imgid, undodatetime->before);

Expand Down Expand Up @@ -3045,8 +3042,7 @@ static void _image_set_datetime(const GList *img,
const dt_imgid_t imgid = GPOINTER_TO_INT(imgs->data);
if(undo_on)
{
dt_undo_datetime_t *undodatetime =
(dt_undo_datetime_t *)malloc(sizeof(dt_undo_datetime_t));
dt_undo_datetime_t *undodatetime = malloc(sizeof(dt_undo_datetime_t));
undodatetime->imgid = imgid;
dt_image_get_datetime(imgid, undodatetime->before);

Expand Down
Loading
Loading