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