1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 3 #include "alloc-util.h" 4 #include "glyph-util.h" 5 #include "string-util.h" 6 #include "sysupdate-update-set.h" 7 #include "terminal-util.h" 8 update_set_free(UpdateSet * us)9UpdateSet *update_set_free(UpdateSet *us) { 10 if (!us) 11 return NULL; 12 13 free(us->version); 14 free(us->instances); /* The objects referenced by this array are freed via resource_free(), not us */ 15 16 return mfree(us); 17 } 18 update_set_cmp(UpdateSet * const * a,UpdateSet * const * b)19int update_set_cmp(UpdateSet *const*a, UpdateSet *const*b) { 20 assert(a); 21 assert(b); 22 assert(*a); 23 assert(*b); 24 assert((*a)->version); 25 assert((*b)->version); 26 27 /* Newest version at the beginning */ 28 return -strverscmp_improved((*a)->version, (*b)->version); 29 } 30 update_set_flags_to_color(UpdateSetFlags flags)31const char *update_set_flags_to_color(UpdateSetFlags flags) { 32 33 if (flags == 0 || (flags & UPDATE_OBSOLETE)) 34 return (flags & UPDATE_NEWEST) ? ansi_highlight_grey() : ansi_grey(); 35 36 if (FLAGS_SET(flags, UPDATE_INSTALLED|UPDATE_NEWEST)) 37 return ansi_highlight(); 38 39 if (FLAGS_SET(flags, UPDATE_INSTALLED|UPDATE_PROTECTED)) 40 return ansi_highlight_magenta(); 41 42 if ((flags & (UPDATE_AVAILABLE|UPDATE_INSTALLED|UPDATE_NEWEST|UPDATE_OBSOLETE)) == (UPDATE_AVAILABLE|UPDATE_NEWEST)) 43 return ansi_highlight_green(); 44 45 return NULL; 46 } 47 update_set_flags_to_glyph(UpdateSetFlags flags)48const char *update_set_flags_to_glyph(UpdateSetFlags flags) { 49 50 if (flags == 0 || (flags & UPDATE_OBSOLETE)) 51 return special_glyph(SPECIAL_GLYPH_MULTIPLICATION_SIGN); 52 53 if (FLAGS_SET(flags, UPDATE_INSTALLED|UPDATE_NEWEST)) 54 return special_glyph(SPECIAL_GLYPH_BLACK_CIRCLE); 55 56 if (FLAGS_SET(flags, UPDATE_INSTALLED|UPDATE_PROTECTED)) 57 return special_glyph(SPECIAL_GLYPH_WHITE_CIRCLE); 58 59 if ((flags & (UPDATE_AVAILABLE|UPDATE_INSTALLED|UPDATE_NEWEST|UPDATE_OBSOLETE)) == (UPDATE_AVAILABLE|UPDATE_NEWEST)) 60 return special_glyph(SPECIAL_GLYPH_CIRCLE_ARROW); 61 62 return " "; 63 } 64