#!/bin/bash

cat << EOF > ui_index.c
// This file was generated by ui_index.gen.sh, do not edit it manually
#include "ui_index.h"

ui_obj_map ui_objects[] = {
$(grep -h "lv_obj_t \*" ui/screens.h | sed 's/lv_obj_t \*//g' | sed 's/;//g' | while read -r line; do
    echo "    {\"$line\", &(objects.$line)},"
done)
};

const int ui_objects_size = sizeof(ui_objects) / sizeof(ui_objects[0]);

ui_style_map ui_styles[] = {
$(grep 'lv_style_t \*get_style_' ui/styles.h | sed 's/lv_style_t \*get_style_//g' | sed 's/_MAIN_DEFAULT();//g' | sed 's/\r//' | while read -r line; do
echo "    {\"$line\", &get_style_${line}_MAIN_DEFAULT},"
done)
};

const int ui_styles_size = sizeof(ui_styles) / sizeof(ui_styles[0]);

ui_img_map ui_images[] = {
$(grep "extern const lv_img_dsc_t " ui/images.h | sed 's/extern const lv_img_dsc_t //g' | sed 's/;//g' | while read -r line; do
    echo "    {\"$line\", &$line},"
done)
};

const int ui_images_size = sizeof(ui_images) / sizeof(ui_images[0]);

ui_var_map ui_vars[] = {
$(grep 'extern const char \*get_var_' ui/vars.h | sed 's/extern const char \*get_var_//g' | sed 's/();//g' | sed 's/\r//' | while read -r line; do
echo "    {\"$line\", &get_var_$line, &set_var_$line},"
done)
};

const int ui_vars_size = sizeof(ui_vars) / sizeof(ui_vars[0]);
EOF

echo "ui_index.c has been generated successfully."
