]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: small uri and annotation cleanup
authorKarel Zak <kzak@redhat.com>
Wed, 1 Oct 2025 13:37:31 +0000 (15:37 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Oct 2025 13:37:31 +0000 (15:37 +0200)
- use scols_column_get_uri() and scols_cell_get_uri()
- don't read annotation or URI when unnecessary

Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/print.c

index fffbe6a7fad822c184eea9472b07e30086bc6d25..a2c736ccadd58a5b180b231a1e4f6c36a1bd83b1 100644 (file)
@@ -321,18 +321,18 @@ static const char *mk_cell_uri(struct libscols_column *cl,
                               struct libscols_cell *ce,
                               struct ul_buffer *buf)
 {
-       char *path;
+       const char *path;
 
        /* URI disabled at all */
        if (ce->no_uri)
                return NULL;
 
-       /* No column prefix, return cell URI (or NULL if undefined) */
-       if (!cl->uri)
-               return ce->uri;
+       /* No column prefix, return cell's URI (or NULL if undefined) */
+       if (!scols_column_get_uri(cl))
+               return scols_cell_get_uri(ce);
 
-       /* Compose URI from column-uri + path. The path is ce->uri or cell data. */
-       path = ce->uri;
+       /* Compose URI from column's URI + path. The path is cell's URI or cell data. */
+       path = scols_cell_get_uri(ce);
 
        if (!path && buf) {
                /* The buffer may already contain tree data, so we need to skip it. */
@@ -470,7 +470,7 @@ static int print_pending_data(struct libscols_table *tb, struct ul_buffer *buf)
 
        DBG(COL, ul_debugobj(cl, "printing pending data"));
 
-       if (cl->uri || ce->uri)
+       if (scols_column_get_uri(cl) || scols_cell_get_uri(ce))
                uri = mk_cell_uri(cl, ce, buf);
 
        if (scols_table_is_noencoding(tb))
@@ -638,11 +638,14 @@ static int print_data(struct libscols_table *tb, struct ul_buffer *buf)
                break;          /* continue below */
        }
 
-       if (cl->uri || ce->uri)
+       if (!ln) {
+               /* column header */
+               annot = scols_column_get_annotation(cl);
+       } else if (scols_column_get_uri(cl) || scols_cell_get_uri(ce)) {
+               /* column data */
                uri = mk_cell_uri(cl, ce, buf);
+       }
 
-       if (cl->annotation)
-               annot = scols_column_get_annotation(cl);
 
        /* Encode. Note that 'len' and 'width' are number of glyphs not bytes.
         */
@@ -703,8 +706,8 @@ static int print_data(struct libscols_table *tb, struct ul_buffer *buf)
                                        fputc(data[i], tb->out);
                        }
                        ul_fputs_hyperlink(uri, link, tb->out);
-               } else if (!ln && annot && *annot) {
-                       /* Printing the header with a column annotation as tooltip */
+
+               } else if (annot && *annot) {
                        ul_fputs_hyperlink(annot, data, tb->out);
                } else {
                        fputs(data, tb->out);
@@ -1063,7 +1066,7 @@ int __scols_print_header(struct libscols_table *tb, struct ul_buffer *buf)
                        continue;
 
                ul_buffer_reset_data(buf);
-               if (cl->uri)
+               if (scols_column_get_uri(cl))
                        scols_cell_disable_uri(&cl->header, 1);
                scols_table_set_cursor(tb, NULL, cl, &cl->header);