aboutsummaryrefslogtreecommitdiff
path: root/sdep.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-05-15 17:51:31 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2023-05-15 17:51:31 +0200
commite7142d86490389fd66a1a31cdc30118478047902 (patch)
tree04f4153789dac46fb73d7d18dd438e690181afe9 /sdep.c
parent886b4e504e4e8cf665fe92f0fadb68bd7205e628 (diff)
downloadsdep-e7142d86490389fd66a1a31cdc30118478047902.tar.gz
sdep-e7142d86490389fd66a1a31cdc30118478047902.zip
Changed compare function type to avoid casting
Diffstat (limited to 'sdep.c')
-rw-r--r--sdep.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/sdep.c b/sdep.c
index 6f2b517..33e96de 100644
--- a/sdep.c
+++ b/sdep.c
@@ -48,8 +48,8 @@ struct Options {
48}; 48};
49 49
50static void add_event(struct tm t, char *text, EventList *evlist); 50static void add_event(struct tm t, char *text, EventList *evlist);
51static int compare_tm(struct tm *t1, struct tm *t2); 51static int compare_tm(const void *, const void *);
52static int compare_event(Event *event1, Event *event2); 52static int compare_event(const void *, const void *);
53static Options default_op(void); 53static Options default_op(void);
54static int events_in_range(EventList *evlist, Options op, Event *sel); 54static int events_in_range(EventList *evlist, Options op, Event *sel);
55static char *format_line(Event ev, Options op, char *out); 55static char *format_line(Event ev, Options op, char *out);
@@ -81,8 +81,11 @@ add_event(struct tm t, char *text, EventList *evlist)
81} 81}
82 82
83static int 83static int
84compare_tm(struct tm *t1, struct tm *t2) 84compare_tm(const void *v1, const void *v2)
85{ 85{
86 const struct tm *t1 = v1;
87 const struct tm *t2 = v2;
88
86 if (t1->tm_year != t2->tm_year) 89 if (t1->tm_year != t2->tm_year)
87 return t1->tm_year - t2->tm_year; 90 return t1->tm_year - t2->tm_year;
88 if (t1->tm_mon != t2->tm_mon) 91 if (t1->tm_mon != t2->tm_mon)
@@ -95,8 +98,11 @@ compare_tm(struct tm *t1, struct tm *t2)
95} 98}
96 99
97static int 100static int
98compare_event(Event *ev1, Event *ev2) 101compare_event(const void *v1, const void *v2)
99{ 102{
103 const Event *ev1 = v1;
104 const Event *ev2 = v2;
105
100 return compare_tm(&ev1->time, &ev2->time); 106 return compare_tm(&ev1->time, &ev2->time);
101} 107}
102 108
@@ -129,14 +135,12 @@ events_in_range(EventList *evlist, Options op, Event *sel)
129 EventNode *i; 135 EventNode *i;
130 int n = 0; 136 int n = 0;
131 137
132
133 for (i = evlist->first; i != NULL; i = i->next) 138 for (i = evlist->first; i != NULL; i = i->next)
134 if (compare_tm(&i->ev.time, &op.from) >= 0 && 139 if (compare_tm(&i->ev.time, &op.from) >= 0 &&
135 compare_tm(&i->ev.time, &op.to) <= 0) 140 compare_tm(&i->ev.time, &op.to) <= 0)
136 sel[n++] = i->ev; 141 sel[n++] = i->ev;
137 142
138 qsort(sel, n, sizeof(Event), 143 qsort(sel, n, sizeof(Event), compare_event);
139 (int (*)(const void *, const void *))compare_event);
140 144
141 return n; 145 return n;
142} 146}

Generated with cgit - Back to sebastiano.tronto.net