aboutsummaryrefslogtreecommitdiffstats
path: root/core/picture.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-14 19:08:49 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-05-06 13:58:09 -0700
commitdb24f16686b7e704e625f499140848681b31cfde (patch)
tree59ae7a6ed2218c1137f7da1ee6ccd6ef3b1425c0 /core/picture.c
parent4e25912fd335159f6bd5d27eb423c5289e35cba5 (diff)
downloadsubsurface-db24f16686b7e704e625f499140848681b31cfde.tar.gz
core: add get_picture_idx() function
A function that gets the index of a picture in a picture table given its filename. Since we are going to identify pictures by their filename, we will need this function in the undo code. Use the function in the remove_picture() function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/picture.c')
-rw-r--r--core/picture.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/core/picture.c b/core/picture.c
index 727500afd..df1304ab8 100644
--- a/core/picture.c
+++ b/core/picture.c
@@ -58,14 +58,21 @@ void add_picture(struct picture_table *t, struct picture newpic)
add_to_picture_table(t, idx, newpic);
}
-// Return true if picture was found and deleted
-bool remove_picture(struct picture_table *t, const char *filename)
+int get_picture_idx(const struct picture_table *t, const char *filename)
{
for (int i = 0; i < t->nr; ++i) {
- if (same_string(t->pictures[i].filename, filename)) {
- remove_from_picture_table(t, i);
- return true;
- }
+ if (same_string(t->pictures[i].filename, filename))
+ return i;
}
- return false;
+ return -1;
+}
+
+// Return true if picture was found and deleted
+bool remove_picture(struct picture_table *t, const char *filename)
+{
+ int idx = get_picture_idx(t, filename);
+ if (idx < 0)
+ return false;
+ remove_from_picture_table(t, idx);
+ return true;
}