#ifndef DESKTOP_PARSER_H
#define DESKTOP_PARSER_H

#include <stddef.h>  /* size_t */

#define MAX_APPS        256
#define MAX_NAME_LEN    128
#define MAX_EXEC_LEN    512
#define MAX_ICON_LEN    256
#define MAX_COMMENT_LEN 256
#define MAX_CAT_LEN     128

typedef struct {
    char name[MAX_NAME_LEN];
    char exec[MAX_EXEC_LEN];
    char icon[MAX_ICON_LEN];
    char comment[MAX_COMMENT_LEN];
    char categories[MAX_CAT_LEN];
    int  hidden;          /* NoDisplay or Hidden = 1 */
    int  terminal;        /* Terminal = true */
} DesktopEntry;

typedef struct {
    DesktopEntry *entries;
    int           count;
    int           capacity;
} AppList;

/* Initialize an AppList (allocates internal buffer) */
void applist_init(AppList *list);

/* Free all memory in the list */
void applist_free(AppList *list);

/* Parse a single .desktop file, appending to list.
   Returns 1 on success, 0 on skip/error. */
int desktop_parse_file(const char *path, AppList *list);

/* Scan a directory for .desktop files and parse them all */
void desktop_scan_dir(const char *dir, AppList *list);

/* Populate list from the standard XDG locations:
   /usr/share/applications, ~/.local/share/applications */
void desktop_load_all(AppList *list);

/* Strip %u %U %f %F %c %k field codes from an Exec string.
   dst must be at least MAX_EXEC_LEN bytes. */
void exec_strip_field_codes(const char *src, char *dst, size_t dst_len);

#endif /* DESKTOP_PARSER_H */