diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-05-15 17:51:31 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-05-15 17:51:31 +0200 |
| commit | e7142d86490389fd66a1a31cdc30118478047902 (patch) | |
| tree | 04f4153789dac46fb73d7d18dd438e690181afe9 | |
| parent | 886b4e504e4e8cf665fe92f0fadb68bd7205e628 (diff) | |
| download | sdep-e7142d86490389fd66a1a31cdc30118478047902.tar.gz sdep-e7142d86490389fd66a1a31cdc30118478047902.zip | |
Changed compare function type to avoid casting
Diffstat (limited to '')
| -rw-r--r-- | sdep.c | 18 |
1 files changed, 11 insertions, 7 deletions
| @@ -48,8 +48,8 @@ struct Options { | |||
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | static void add_event(struct tm t, char *text, EventList *evlist); | 50 | static void add_event(struct tm t, char *text, EventList *evlist); |
| 51 | static int compare_tm(struct tm *t1, struct tm *t2); | 51 | static int compare_tm(const void *, const void *); |
| 52 | static int compare_event(Event *event1, Event *event2); | 52 | static int compare_event(const void *, const void *); |
| 53 | static Options default_op(void); | 53 | static Options default_op(void); |
| 54 | static int events_in_range(EventList *evlist, Options op, Event *sel); | 54 | static int events_in_range(EventList *evlist, Options op, Event *sel); |
| 55 | static char *format_line(Event ev, Options op, char *out); | 55 | static 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 | ||
| 83 | static int | 83 | static int |
| 84 | compare_tm(struct tm *t1, struct tm *t2) | 84 | compare_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 | ||
| 97 | static int | 100 | static int |
| 98 | compare_event(Event *ev1, Event *ev2) | 101 | compare_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 | } |
