Tested on 2026-11-20 with gcc 14.2 and curl 8.14 on Debian. Disclosure: I help build UnAIMyText, which sits at #3 in the tools list below by my own choice. The code is yours to copy and bend.

On Linux, every app in the menu comes from a .desktop file, and the Comment= line in that file is the tooltip you see when you hover. It's one short line, which makes it a strange place for model-written prose to show up, but it does. Here's a file I was asked to review for a small photo app:

[Desktop Entry] Type=Application Name=Shelfie GenericName=Photo Organizer Comment=This application provides a powerful and intuitive way to seamlessly organize your photos. Exec=shelfie %U Icon=shelfie Categories=Graphics;Photography; Comment=Organize photos 

Ninety characters, a full stop, "This application," three filler words, and a second Comment= added at the bottom instead of fixing the first. So I wrote a linter for that one line: a single C file needing only libc and the curl binary. With --draft it asks AI21's Jamba model for a Comment= line and checks that reply too, before it reaches a package.

What the spec actually asks for

The freedesktop Desktop Entry Specification describes Comment as the tooltip for the entry, gives "View sites on the Internet" as an example, and adds one rule: the value "should not be redundant with the values of Name and GenericName." Name is required; Comment is optional. Elsewhere it says localestring values are UTF-8, that \s, \n, \t, \r and \\ are the escapes allowed in string values, and that one group can't use the same key twice.

Everything else the linter checks is house style: start with a verb, stay under 60 characters, no full stop, no emoji.

The AI21 part

AI21's chat request reference shows a POST to https://api.ai21.com/studio/v1/chat/completions with a bearer key, a model, and a messages list using system, user and assistant roles. You can name a model without a version: jamba-large or jamba-mini. Their models page says jamba-mini currently points to jamba-mini-2-2026-01. The response puts the text in choices[0].message.content. The program defaults to jamba-mini and caps max_tokens at 100, because the answer is one line.

Sent a fake key, AI21's live endpoint returns 401 and {"detail":"Authentication required."}. With no Authorization header at all it's a 400 instead. The program prints the status and body to stderr and exits 2 either way.

Why C, and what it costs

C's standard library has no JSON or HTTP, so three pieces are hand-written:

  • Escaping the request. jesc() escapes quotes, backslashes, \n, \r, \t and writes other control bytes as \u00XX. Exec= lines are full of quotes and backslashes, so one test sends exactly that.
  • Reading one field of the reply. content_of() finds "message", then the next "content", and decodes that string, including \uXXXX and surrogate pairs. It isn't a JSON parser, and it returns NULL for "content": null.
  • Calling curl without a shell. The key is written to a mkstemp file created under umask 077, the body to a second one, and curl runs through fork/execvp with -H @file and --data-binary @file. Both files are deleted right after. No system(), and the key never appears in ps.

What it checks

  • Type=Application with no Comment, and a missing Name
  • A Comment whose words all come from Name or GenericName (plus "a", "the", "app" and similar glue words)
  • Over 60 characters, counted as UTF-8 code points, not bytes
  • A trailing full stop (a trailing ... is fine)
  • Openers like "This application", "This tool", "Allows you", "Helps you"
  • Filler words: seamlessly, comprehensive, leverage, robust, powerful, intuitive, user-friendly and a few more
  • Emoji
  • \n or \t escapes that would put a line break or tab in a tooltip
  • Duplicate keys in [Desktop Entry]

Only [Desktop Entry] is linted; action groups are ignored. The first Comment= is the one that counts. It exits 0 when clean, 1 on problems, and 2 for usage errors, a missing file or key, a curl failure or a non-200 reply.

The program

/* desklint.c - lint the Comment= tooltip in .desktop files, or ask AI21's * Jamba for a draft and lint that before you paste it. * * Build: cc -std=c11 -Wall -Wextra -O2 -o desklint desklint.c * Lint: ./desklint app.desktop [more.desktop ...] * Draft: AI21_API_KEY=... ./desklint --draft app.desktop * Env: AI21_MODEL (default jamba-mini), AI21_BASE_URL (default * https://api.ai21.com/studio/v1) * Exit: 0 clean, 1 problems, 2 usage, I/O, curl or API error */ #define _POSIX_C_SOURCE 200809L #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> #define MAXCHARS 60 #define VAL 2048 #define MAXKEYS 128 typedef struct { char name[VAL], generic[VAL], comment[VAL], type[64]; int comment_line, name_line; char raw[8192]; /* the [Desktop Entry] group as text, for the prompt */ } Entry; static int problems, io_error, quiet; static void report(const char *where, int line, const char *msg, const char *detail) { if (quiet) return; /* draft mode reads the file without linting it */ printf("%s:%d: %s%s%s\n", where, line, msg, detail ? ": " : "", detail ? detail : ""); problems++; } /* \s \n \t \r \\ are the escapes the spec allows in string values */ static void unescape(char *s) { char *o = s; for (; *s; s++) { if (*s == '\\' && s[1]) { s++; switch (*s) { case 's': *o++ = ' '; break; case 'n': *o++ = '\n'; break; case 't': *o++ = '\t'; break; case 'r': *o++ = '\r'; break; case '\\': *o++ = '\\'; break; default: *o++ = '\\'; *o++ = *s; } } else { *o++ = *s; } } *o = 0; } static char *trim(char *s) { while (*s == ' ' || *s == '\t') s++; size_t n = strlen(s); while (n && (s[n - 1] == ' ' || s[n - 1] == '\t' || s[n - 1] == '\n' || s[n - 1] == '\r')) s[--n] = 0; return s; } /* next UTF-8 code point; bad bytes come back as U+FFFD */ static unsigned long next_cp(const unsigned char **p) { const unsigned char *s = *p; unsigned long c = *s++; int extra = 0; if (c >= 0xF0 && c < 0xF8) { c &= 0x07; extra = 3; } else if (c >= 0xE0) { c &= 0x0F; extra = 2; } else if (c >= 0xC0) { c &= 0x1F; extra = 1; } else if (c >= 0x80) { *p = s; return 0xFFFD; } while (extra--) { if ((*s & 0xC0) != 0x80) { *p = s; return 0xFFFD; } c = (c << 6) | (*s++ & 0x3F); } *p = s; return c; } static size_t char_count(const char *s) { const unsigned char *p = (const unsigned char *)s; size_t n = 0; while (*p) { next_cp(&p); n++; } return n; } static int has_emoji(const char *s) { const unsigned char *p = (const unsigned char *)s; while (*p) { unsigned long c = next_cp(&p); if ((c >= 0x1F000 && c <= 0x1FAFF) || (c >= 0x2600 && c <= 0x27BF) || c == 0xFE0F) return 1; } return 0; } /* lowercase ASCII words of s, one per call; returns 0 at the end */ static int next_word(const char **s, char *w, size_t cap) { const char *p = *s; while (*p && !isalnum((unsigned char)*p)) p++; if (!*p) return 0; size_t n = 0; while (*p && (isalnum((unsigned char)*p) || *p == '-' || *p == '\'')) { if (n + 1 < cap) w[n++] = (char)tolower((unsigned char)*p); p++; } w[n] = 0; *s = p; return 1; } static int word_in(const char *word, const char *text) { char w[128]; const char *p = text; while (next_word(&p, w, sizeof w)) if (!strcmp(w, word)) return 1; return 0; } static const char *FILLER[] = { "seamless", "seamlessly", "comprehensive", "leverage", "robust", "streamline", "utilize", "powerful", "intuitive", "effortless", "effortlessly", "cutting-edge", "elevate", "unleash", "next-generation", "all-in-one", "user-friendly", NULL }; static const char *OPENERS[] = { "this application", "this app ", "this program", "this tool", "an application", "a powerful", "allows you", "enables you", "helps you", NULL }; static const char *GLUE[] = { "a", "an", "the", "and", "for", "of", "your", "app", "application", NULL }; static int in_list(const char *w, const char **list) { for (; *list; list++) if (!strcmp(w, *list)) return 1; return 0; } static void lint_comment(const char *where, int line, const char *c, const char *name, const char *generic) { char w[128], lower[VAL]; size_t n = char_count(c), len = strlen(c), i; if (!*c) { report(where, line, "empty Comment", NULL); return; } if (n > MAXCHARS) { char d[64]; snprintf(d, sizeof d, "%zu characters, limit is %d", n, MAXCHARS); report(where, line, "too long", d); } if (c[len - 1] == '.' && !(len >= 3 && !strcmp(c + len - 3, "..."))) report(where, line, "ends with a full stop", NULL); if (strpbrk(c, "\n\t\r")) report(where, line, "contains a line break or tab", NULL); if (has_emoji(c)) report(where, line, "contains emoji", NULL); for (i = 0; c[i] && i + 1 < sizeof lower; i++) lower[i] = (char)tolower((unsigned char)c[i]); lower[i] = 0; for (const char **o = OPENERS; *o; o++) if (!strncmp(lower, *o, strlen(*o))) { report(where, line, "describes the app instead of what it does", *o); break; } const char *p = c; int words = 0, repeated = 0; while (next_word(&p, w, sizeof w)) { words++; if (in_list(w, FILLER)) report(where, line, "filler word", w); if (in_list(w, GLUE) || word_in(w, name) || word_in(w, generic)) repeated++; } if (words && repeated == words) report(where, line, "only repeats Name/GenericName (the spec says it shouldn't)", NULL); } static int parse(const char *path, Entry *e) { FILE *f = fopen(path, "r"); if (!f) { perror(path); return -1; } memset(e, 0, sizeof *e); char *buf = NULL, seen[MAXKEYS][64]; int seen_line[MAXKEYS], nseen = 0, lineno = 0, in_main = 0, saw_main = 0; size_t cap = 0; while (getline(&buf, &cap, f) != -1) { lineno++; char *s = trim(buf); if (!*s || *s == '#') continue; if (*s == '[') { in_main = !strcmp(s, "[Desktop Entry]"); if (in_main) saw_main = 1; continue; } if (!in_main) continue; if (strlen(e->raw) + strlen(s) + 2 < sizeof e->raw) { strcat(e->raw, s); strcat(e->raw, "\n"); } char *eq = strchr(s, '='); if (!eq) { report(path, lineno, "line without '='", s); continue; } *eq = 0; char *key = trim(Source:https://dev.to/unaimytext_app/humanize-ai21-jamba-output-in-c-a-desktop-file-comment-linter-5-free-tools-2026-1mo5

Related posts