663 {
664 char include_file_name[
MAXLEN];
666 char *src_p, *dp;
668 char hex_clr_str[8];
671 FILE *config_fp = fopen(config_file_name, "r");
672 char quote_char = '\0';
673 if (!config_fp) {
674 fprintf(stderr, "failed to read file: %s %s\n", config_file_name, strerror(errno));
675 return (-1);
676 }
677 while (fgets(tmp_str, sizeof(tmp_str), config_fp)) {
678 bool inquotes = false;
679 if (tmp_str[0] == '#')
680 continue;
681 src_p = tmp_str;
682 key[0] = '\0';
683 dp = key;
684
685 while (*src_p != '\0') {
686 if (*src_p == '\n')
687 *dp = *src_p = '\0';
688 if (*src_p == '=') {
689 *dp = '\0';
690 src_p++;
691 break;
692 }
693 if (*src_p == '"' && *src_p == ' ') {
694 src_p++;
695 continue;
696 }
697 *dp++ = *src_p++;
698 }
699 value[0] = '\0';
700 dp = value;
701
702 while (*src_p != '\0') {
703 if ((*src_p == '"' || *src_p == '\'') && (*(src_p + 1) != '\\')) {
704 if (!inquotes) {
705 inquotes = true;
706 quote_char = *src_p++;
707 } else if (*src_p == quote_char) {
708 inquotes = false;
709 quote_char = '\0';
710 }
711 }
712 if (!inquotes) {
713 if (*src_p == '#') {
716 dp = value + strlen(value);
717 }
718 break;
719 }
720 }
721 if (*src_p == ' ' || *src_p == ';') {
722 src_p++;
723 continue;
724 }
725 if (*src_p == '\n') {
726 *src_p = '\0';
727 break;
728 }
729 *dp++ = *src_p++;
730 }
731 *dp = '\0';
732 if (key[0] == '\0')
733 continue;
734 if (value[0] == '\0')
735 continue;
736 if (!strcmp(key, "include")) {
740 continue;
741 }
742 if (!strcmp(key, "minitrc")) {
744 continue;
745 }
746 if (!strcmp(key, "lines")) {
747 init->
lines = atoi(value);
748 continue;
749 }
750 if (!strcmp(key, "cols")) {
751 init->
cols = atoi(value);
752 continue;
753 }
754 if (!strcmp(key, "begy")) {
755 init->
begy = atoi(value);
756 continue;
757 }
758 if (!strcmp(key, "begx")) {
759 init->
begx = atoi(value);
760 continue;
761 }
762 if (!strcmp(key, "f_ln")) {
764 continue;
765 }
766 if (!strcmp(key, "f_at_end_remove")) {
768 continue;
769 }
770 if (!strcmp(key, "f_erase_remainder")) {
772 continue;
773 }
774 if (!strcmp(key, "brackets")) {
776 continue;
777 }
778 if (!strcmp(key, "fill_char")) {
779 if (strlen(value) > 1)
780 value[1] = '\0';
781 if (wcwidth((int)value[0]) > 1)
782 value[0] = '?';
784 continue;
785 }
786 if (!strcmp(key, "f_ignore_case")) {
788 continue;
789 }
790 if (!strcmp(key, "p_view_files")) {
792 continue;
793 }
794 if (!strcmp(key, "f_read_theme")) {
796 continue;
797 }
798 if (!strcmp(key, "f_squeeze")) {
800 continue;
801 }
802 if (!strcmp(key, "f_strip_ansi")) {
804 continue;
805 }
806 if (!strcmp(key, "f_multiple_cmd_args")) {
808 continue;
809 }
810 if (!strcmp(key, "select_max")) {
812 continue;
813 }
814 if (!strcmp(key, "tab_stop")) {
816 continue;
817 }
818 if (!strcmp(key, "h_shift")) {
820 continue;
821 }
822 if (!strcmp(key, "wrap")) {
824 continue;
825 }
826 if (!strcmp(key, "title")) {
828 continue;
829 }
830 if (!strcmp(key, "cmd")) {
832 continue;
833 }
834 if (!strcmp(key, "cmd_all")) {
836 continue;
837 }
838 if (!strcmp(key, "parent_cmd")) {
840 continue;
841 }
842 if (!strcmp(key, "provider_cmd")) {
844 continue;
845 }
846 if (!strcmp(key, "receiver_cmd")) {
848 continue;
849 }
850 if (!strcmp(key, "editor")) {
852 continue;
853 }
854 if (!strcmp(key, "border")) {
855 char c = value[0];
856 if (c == 'r' || c == 'R')
858 else if (c == 's' || c == 'S')
860 else if (c == 'd' || c == 'D')
862 else if (c == 'h' || c == 'H')
864 else
866 continue;
867 }
868 if (!strcmp(key, "fg")) {
869 sscanf(value,
"#%06x", &sio->
fg);
870 continue;
871 }
872 if (!strcmp(key, "bg")) {
873 sscanf(value,
"#%06x", &sio->
bg);
874 continue;
875 }
876 if (!strcmp(key, "box_fg")) {
877 sscanf(value,
"#%06x", &sio->
fg);
878 continue;
879 }
880 if (!strcmp(key, "box_bg")) {
881 sscanf(value,
"#%06x", &sio->
box_bg);
882 continue;
883 }
884 if (!strcmp(key, "ind_fg")) {
885 sscanf(value,
"#%06x", &sio->
ind_fg);
886 continue;
887 }
888 if (!strcmp(key, "ind_bg")) {
889 sscanf(value,
"#%06x", &sio->
ind_bg);
890 continue;
891 }
892 if (!strcmp(key, "brackets_fg")) {
894 continue;
895 }
896 if (!strcmp(key, "brackets_bg")) {
898 continue;
899 }
900 if (!strcmp(key, "fill_char_fg")) {
902 continue;
903 }
904 if (!strcmp(key, "fill_char_bg")) {
906 continue;
907 }
908 if (!strcmp(key, "ln_fg")) {
909 sscanf(value,
"#%06x", &sio->
ln_fg);
910 continue;
911 }
912 if (!strcmp(key, "ln_bg")) {
913 sscanf(value,
"#%06x", &sio->
ln_bg);
914 continue;
915 }
916 if (!strcmp(key, "cmdln_fg")) {
917 sscanf(value,
"#%06x", &sio->
cmdln_fg);
918 continue;
919 }
920 if (!strcmp(key, "cmdln_bg")) {
921 sscanf(value,
"#%06x", &sio->
cmdln_bg);
922 continue;
923 }
924 if (!strcmp(key, "nt_fg")) {
925 sscanf(value,
"#%06x", &sio->
nt_fg);
926 continue;
927 }
928 if (!strcmp(key, "nt_bg")) {
929 sscanf(value,
"#%06x", &sio->
nt_bg);
930 continue;
931 }
932 if (!strcmp(key, "nt_rev_fg")) {
934 continue;
935 }
936 if (!strcmp(key, "nt_rev_bg")) {
938 continue;
939 }
940 if (!strcmp(key, "nt_hl_fg")) {
941 sscanf(value,
"#%06x", &sio->
nt_hl_fg);
942 continue;
943 }
944 if (!strcmp(key, "nt_hl_bg")) {
945 sscanf(value,
"#%06x", &sio->
nt_hl_bg);
946 continue;
947 }
948 if (!strcmp(key, "nt_hl_rev_fg")) {
950 continue;
951 }
952 if (!strcmp(key, "nt_hl_rev_bg")) {
954 continue;
955 }
956 if (!strcmp(key, "title_fg")) {
957 sscanf(value,
"#%06x", &sio->
title_fg);
958 continue;
959 }
960 if (!strcmp(key, "title_bg")) {
961 sscanf(value,
"#%06x", &sio->
title_bg);
962 continue;
963 }
964 if (!strcmp(key, "ran_fg")) {
965 sscanf(value,
"#%06x", &sio->
ran_fg);
966 continue;
967 }
968 if (!strcmp(key, "ran_bg")) {
969 sscanf(value,
"#%06x", &sio->
ran_bg);
970 continue;
971 }
972 if (!strcmp(key, "red_gamma")) {
974 continue;
975 }
976 if (!strcmp(key, "green_gamma")) {
978 continue;
979 }
980 if (!strcmp(key, "blue_gamma")) {
982 continue;
983 }
984 if (!strcmp(key, "gray_gamma")) {
986 continue;
987 }
988 if (!strcmp(key, "black")) {
989 sscanf(value,
"#%06x", &sio->
black);
990 continue;
991 }
992 if (!strcmp(key, "red")) {
993 sscanf(value,
"#%06x", &sio->
red);
994 continue;
995 }
996 if (!strcmp(key, "green")) {
997 sscanf(value,
"#%06x", &sio->
green);
998 continue;
999 }
1000 if (!strcmp(key, "yellow")) {
1001 sscanf(value,
"#%06x", &sio->
yellow);
1002 continue;
1003 }
1004 if (!strcmp(key, "blue")) {
1005 sscanf(value,
"#%06x", &sio->
blue);
1006 continue;
1007 }
1008 if (!strcmp(key, "magenta")) {
1009 sscanf(value,
"#%06x", &sio->
magenta);
1010 continue;
1011 }
1012 if (!strcmp(key, "cyan")) {
1013 sscanf(value,
"#%06x", &sio->
cyan);
1014 continue;
1015 }
1016 if (!strcmp(key, "white")) {
1017 sscanf(value,
"#%06x", &sio->
white);
1018 continue;
1019 }
1020 if (!strcmp(key, "orange")) {
1021 sscanf(value,
"#%06x", &sio->
orange);
1022 continue;
1023 }
1024 if (!strcmp(key, "bblack")) {
1025 sscanf(value,
"#%06x", &sio->
bblack);
1026 continue;
1027 }
1028 if (!strcmp(key, "bred")) {
1029 sscanf(value,
"#%06x", &sio->
bred);
1030 continue;
1031 }
1032 if (!strcmp(key, "bgreen")) {
1033 sscanf(value,
"#%06x", &sio->
bgreen);
1034 continue;
1035 }
1036 if (!strcmp(key, "byellow")) {
1037 sscanf(value,
"#%06x", &sio->
byellow);
1038 continue;
1039 }
1040 if (!strcmp(key, "bblue")) {
1041 sscanf(value,
"#%06x", &sio->
bblue);
1042 continue;
1043 }
1044 if (!strcmp(key, "bmagenta")) {
1045 sscanf(value,
"#%06x", &sio->
bmagenta);
1046 continue;
1047 }
1048 if (!strcmp(key, "bcyan")) {
1049 sscanf(value,
"#%06x", &sio->
bcyan);
1050 continue;
1051 }
1052 if (!strcmp(key, "bwhite")) {
1053 sscanf(value,
"#%06x", &sio->
bwhite);
1054 continue;
1055 }
1056 if (!strcmp(key, "borange")) {
1057 sscanf(value,
"#%06x", &sio->
borange);
1058 continue;
1059 }
1060 if (!strcmp(key, "mapp_spec")) {
1062 continue;
1063 }
1064 if (!strcmp(key, "mapp_data")) {
1066 continue;
1067 }
1068 if (!strcmp(key, "mapp_help")) {
1070 continue;
1071 }
1072 if (!strcmp(key, "mapp_home")) {
1074 continue;
1075 }
1076 if (!strcmp(key, "mapp_msrc")) {
1078 continue;
1079 }
1080 if (!strcmp(key, "mapp_user")) {
1082 continue;
1083 }
1084 if (!strcmp(key, "mapp_theme")) {
1086 continue;
1087 }
1088 }
1089 (void)fclose(config_fp);
1090 return 0;
1091}
bool str_to_bool(const char *)
Converts String to boolean true or false.
int process_config_file(char *, Init *)
size_t strnz__cpy(char *, const char *, size_t)
safer alternative to strncpy
double str_to_double(char *)
converts string to double
bool expand_tilde(char *, uint)
Replaces "~/" in string with the user's home directory.
bool unstr_hex_clr(char *, char *)
Validates that a string is a hex color code in the format "#RRGGBB".
The SIO structure encapsulates various aspects of the terminal's state and configuration,...
char receiver_cmd[MAXLEN]
char provider_cmd[MAXLEN]