690 {
691 char include_file_name[
MAXLEN];
693 char *src_p, *dp;
695 char hex_clr_str[8];
698 FILE *config_fp = fopen(config_file_name, "r");
699 char quote_char = '\0';
700 if (!config_fp) {
701 fprintf(stderr, "failed to read file: %s %s\n", config_file_name, strerror(errno));
702 return (-1);
703 }
704 while (fgets(tmp_str, sizeof(tmp_str), config_fp)) {
705 bool inquotes = false;
706 if (tmp_str[0] == '#')
707 continue;
708 src_p = tmp_str;
709 key[0] = '\0';
710 dp = key;
711
712 while (*src_p != '\0') {
713 if (*src_p == '\n')
714 *dp = *src_p = '\0';
715 if (*src_p == '=') {
716 *dp = '\0';
717 src_p++;
718 break;
719 }
720 if (*src_p == '"' && *src_p == ' ') {
721 src_p++;
722 continue;
723 }
724 *dp++ = *src_p++;
725 }
726 value[0] = '\0';
727 dp = value;
728
729 while (*src_p != '\0') {
730 if ((*src_p == '"' || *src_p == '\'') && (*(src_p + 1) != '\\')) {
731 if (!inquotes) {
732 inquotes = true;
733 quote_char = *src_p++;
734 } else if (*src_p == quote_char) {
735 inquotes = false;
736 quote_char = '\0';
737 }
738 }
739 if (!inquotes) {
740 if (*src_p == '#') {
743 dp = value + strlen(value);
744 }
745 break;
746 }
747 }
748 if (*src_p == ' ' || *src_p == ';') {
749 src_p++;
750 continue;
751 }
752 if (*src_p == '\n') {
753 *src_p = '\0';
754 break;
755 }
756 *dp++ = *src_p++;
757 }
758 *dp = '\0';
759 if (key[0] == '\0')
760 continue;
761 if (value[0] == '\0')
762 continue;
763 if (!strcmp(key, "include")) {
767 continue;
768 }
769 if (!strcmp(key, "minitrc")) {
771 continue;
772 }
773 if (!strcmp(key, "lines")) {
774 init->
lines = atoi(value);
775 continue;
776 }
777 if (!strcmp(key, "cols")) {
778 init->
cols = atoi(value);
779 continue;
780 }
781 if (!strcmp(key, "begy")) {
782 init->
begy = atoi(value);
783 continue;
784 }
785 if (!strcmp(key, "begx")) {
786 init->
begx = atoi(value);
787 continue;
788 }
789 if (!strcmp(key, "f_ln")) {
791 continue;
792 }
793 if (!strcmp(key, "f_at_end_remove")) {
795 continue;
796 }
797 if (!strcmp(key, "f_erase_remainder")) {
799 continue;
800 }
801 if (!strcmp(key, "brackets")) {
803 continue;
804 }
805 if (!strcmp(key, "fill_char")) {
806 if (strlen(value) > 1)
807 value[1] = '\0';
808 if (wcwidth((int)value[0]) > 1)
809 value[0] = '?';
811 continue;
812 }
813 if (!strcmp(key, "f_ignore_case")) {
815 continue;
816 }
817 if (!strcmp(key, "p_view_files")) {
819 continue;
820 }
821 if (!strcmp(key, "f_read_theme")) {
823 continue;
824 }
825 if (!strcmp(key, "f_squeeze")) {
827 continue;
828 }
829 if (!strcmp(key, "f_strip_ansi")) {
831 continue;
832 }
833 if (!strcmp(key, "f_multiple_cmd_args")) {
835 continue;
836 }
837 if (!strcmp(key, "select_max")) {
839 continue;
840 }
841 if (!strcmp(key, "tab_stop")) {
843 continue;
844 }
845 if (!strcmp(key, "timeout_secs")) {
847 continue;
848 }
849 if (!strcmp(key, "h_shift")) {
851 continue;
852 }
853 if (!strcmp(key, "wrap")) {
855 continue;
856 }
857 if (!strcmp(key, "title")) {
859 continue;
860 }
861 if (!strcmp(key, "cmd")) {
863 continue;
864 }
865 if (!strcmp(key, "cmd_all")) {
867 continue;
868 }
869 if (!strcmp(key, "parent_cmd")) {
871 continue;
872 }
873 if (!strcmp(key, "provider_cmd")) {
875 continue;
876 }
877 if (!strcmp(key, "receiver_cmd")) {
879 continue;
880 }
881 if (!strcmp(key, "editor")) {
883 continue;
884 }
885 if (!strcmp(key, "border")) {
886 char c = value[0];
887 if (c == 'r' || c == 'R')
889 else if (c == 's' || c == 'S')
891 else if (c == 'd' || c == 'D')
893 else if (c == 'h' || c == 'H')
895 else
897 continue;
898 }
899 if (!strcmp(key, "fg")) {
900 sscanf(value,
"#%06x", &sio->
fg);
901 continue;
902 }
903 if (!strcmp(key, "bg")) {
904 sscanf(value,
"#%06x", &sio->
bg);
905 continue;
906 }
907 if (!strcmp(key, "box_fg")) {
908 sscanf(value,
"#%06x", &sio->
fg);
909 continue;
910 }
911 if (!strcmp(key, "box_bg")) {
912 sscanf(value,
"#%06x", &sio->
box_bg);
913 continue;
914 }
915 if (!strcmp(key, "ind_fg")) {
916 sscanf(value,
"#%06x", &sio->
ind_fg);
917 continue;
918 }
919 if (!strcmp(key, "ind_bg")) {
920 sscanf(value,
"#%06x", &sio->
ind_bg);
921 continue;
922 }
923 if (!strcmp(key, "brackets_fg")) {
925 continue;
926 }
927 if (!strcmp(key, "brackets_bg")) {
929 continue;
930 }
931 if (!strcmp(key, "fill_char_fg")) {
933 continue;
934 }
935 if (!strcmp(key, "fill_char_bg")) {
937 continue;
938 }
939 if (!strcmp(key, "ln_fg")) {
940 sscanf(value,
"#%06x", &sio->
ln_fg);
941 continue;
942 }
943 if (!strcmp(key, "ln_bg")) {
944 sscanf(value,
"#%06x", &sio->
ln_bg);
945 continue;
946 }
947 if (!strcmp(key, "cmdln_fg")) {
948 sscanf(value,
"#%06x", &sio->
cmdln_fg);
949 continue;
950 }
951 if (!strcmp(key, "cmdln_bg")) {
952 sscanf(value,
"#%06x", &sio->
cmdln_bg);
953 continue;
954 }
955 if (!strcmp(key, "nt_fg")) {
956 sscanf(value,
"#%06x", &sio->
nt_fg);
957 continue;
958 }
959 if (!strcmp(key, "nt_bg")) {
960 sscanf(value,
"#%06x", &sio->
nt_bg);
961 continue;
962 }
963 if (!strcmp(key, "nt_rev_fg")) {
965 continue;
966 }
967 if (!strcmp(key, "nt_rev_bg")) {
969 continue;
970 }
971 if (!strcmp(key, "nt_hl_fg")) {
972 sscanf(value,
"#%06x", &sio->
nt_hl_fg);
973 continue;
974 }
975 if (!strcmp(key, "nt_hl_bg")) {
976 sscanf(value,
"#%06x", &sio->
nt_hl_bg);
977 continue;
978 }
979 if (!strcmp(key, "nt_hl_rev_fg")) {
981 continue;
982 }
983 if (!strcmp(key, "nt_hl_rev_bg")) {
985 continue;
986 }
987 if (!strcmp(key, "title_fg")) {
988 sscanf(value,
"#%06x", &sio->
title_fg);
989 continue;
990 }
991 if (!strcmp(key, "title_bg")) {
992 sscanf(value,
"#%06x", &sio->
title_bg);
993 continue;
994 }
995 if (!strcmp(key, "ran_fg")) {
996 sscanf(value,
"#%06x", &sio->
ran_fg);
997 continue;
998 }
999 if (!strcmp(key, "ran_bg")) {
1000 sscanf(value,
"#%06x", &sio->
ran_bg);
1001 continue;
1002 }
1003 if (!strcmp(key, "red_gamma")) {
1005 continue;
1006 }
1007 if (!strcmp(key, "green_gamma")) {
1009 continue;
1010 }
1011 if (!strcmp(key, "blue_gamma")) {
1013 continue;
1014 }
1015 if (!strcmp(key, "gray_gamma")) {
1017 continue;
1018 }
1019 if (!strcmp(key, "black")) {
1020 sscanf(value,
"#%06x", &sio->
black);
1021 continue;
1022 }
1023 if (!strcmp(key, "red")) {
1024 sscanf(value,
"#%06x", &sio->
red);
1025 continue;
1026 }
1027 if (!strcmp(key, "green")) {
1028 sscanf(value,
"#%06x", &sio->
green);
1029 continue;
1030 }
1031 if (!strcmp(key, "yellow")) {
1032 sscanf(value,
"#%06x", &sio->
yellow);
1033 continue;
1034 }
1035 if (!strcmp(key, "blue")) {
1036 sscanf(value,
"#%06x", &sio->
blue);
1037 continue;
1038 }
1039 if (!strcmp(key, "magenta")) {
1040 sscanf(value,
"#%06x", &sio->
magenta);
1041 continue;
1042 }
1043 if (!strcmp(key, "cyan")) {
1044 sscanf(value,
"#%06x", &sio->
cyan);
1045 continue;
1046 }
1047 if (!strcmp(key, "white")) {
1048 sscanf(value,
"#%06x", &sio->
white);
1049 continue;
1050 }
1051 if (!strcmp(key, "orange")) {
1052 sscanf(value,
"#%06x", &sio->
orange);
1053 continue;
1054 }
1055 if (!strcmp(key, "bblack")) {
1056 sscanf(value,
"#%06x", &sio->
bblack);
1057 continue;
1058 }
1059 if (!strcmp(key, "bred")) {
1060 sscanf(value,
"#%06x", &sio->
bred);
1061 continue;
1062 }
1063 if (!strcmp(key, "bgreen")) {
1064 sscanf(value,
"#%06x", &sio->
bgreen);
1065 continue;
1066 }
1067 if (!strcmp(key, "byellow")) {
1068 sscanf(value,
"#%06x", &sio->
byellow);
1069 continue;
1070 }
1071 if (!strcmp(key, "bblue")) {
1072 sscanf(value,
"#%06x", &sio->
bblue);
1073 continue;
1074 }
1075 if (!strcmp(key, "bmagenta")) {
1076 sscanf(value,
"#%06x", &sio->
bmagenta);
1077 continue;
1078 }
1079 if (!strcmp(key, "bcyan")) {
1080 sscanf(value,
"#%06x", &sio->
bcyan);
1081 continue;
1082 }
1083 if (!strcmp(key, "bwhite")) {
1084 sscanf(value,
"#%06x", &sio->
bwhite);
1085 continue;
1086 }
1087 if (!strcmp(key, "borange")) {
1088 sscanf(value,
"#%06x", &sio->
borange);
1089 continue;
1090 }
1091 if (!strcmp(key, "mapp_spec")) {
1093 continue;
1094 }
1095 if (!strcmp(key, "mapp_data")) {
1097 continue;
1098 }
1099 if (!strcmp(key, "mapp_help")) {
1101 continue;
1102 }
1103 if (!strcmp(key, "mapp_home")) {
1105 continue;
1106 }
1107 if (!strcmp(key, "mapp_msrc")) {
1109 continue;
1110 }
1111 if (!strcmp(key, "mapp_user")) {
1113 continue;
1114 }
1115 if (!strcmp(key, "mapp_theme")) {
1117 continue;
1118 }
1119 if (!strcmp(key, "log_level")) {
1121 if (!strcmp(value, "SILENT"))
1123 else if (!strcmp(value, "DEBUG"))
1125 else if (!strcmp(value, "INFO"))
1127 else if (!strcmp(value, "WARN"))
1129 else if (!strcmp(value, "ERROR"))
1131 else if (!strcmp(value, "FATAL"))
1133 else
1135 continue;
1136 }
1137 }
1138 (void)fclose(config_fp);
1139 return 0;
1140}
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
bool str_to_upper(char *)
Converts a string to uppercase.
double str_to_double(char *)
converts string to double
bool expand_tilde(char *, uint)
Expand a tilde (~) in a file path to the user's home directory.
bool unstr_hex_clr(char *, char *)
Validates that a string is a hex color code in the format "#RRGGBB".
char receiver_cmd[MAXLEN]
char provider_cmd[MAXLEN]