Changeset 87 in MondoRescue for trunk/mondo/mondo/common/libmondo-string.c
- Timestamp:
- Oct 27, 2005, 10:03:00 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-string.c
r58 r87 68 68 /** 69 69 * Pad a string on both sides so it appears centered. 70 * @param in_out The string to be center-padded (modified). 70 * @param in_out The string to be center-padded (modified). The caller needs to free this string 71 71 * @param width The width of the final result. 72 72 */ … … 74 74 { 75 75 char *scratch; 76 char *out; 76 77 char *p; 77 78 int i; /* purpose */ … … 87 88 } 88 89 for (p = in_out; *p == ' '; p++); 89 asprintf(&scratch, "%s",p);90 asprintf(&scratch, p); 90 91 len = (int) strlen(scratch); 91 92 mid = width / 2; … … 95 96 } 96 97 in_out[i] = '\0'; 97 strcat(in_out, scratch);98 asprintf(&out, "%s%s", in_out, scratch); 98 99 paranoid_free(scratch); 100 in_out = out; 99 101 } 100 102 … … 863 865 int severity_of_difference(char *fn, char *out_reason) 864 866 { 865 int sev ;867 int sev = 0; 866 868 char *reason; 867 869 char *filename; 868 870 869 malloc_string(reason); 870 // out_reason might be null on purpose, so don't bomb if it is :) OK? 871 // out_reason might be null on purpose, so don't bomb if it is :) OK? 871 872 assert_string_is_neither_NULL_nor_zerolength(fn); 872 873 if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) { … … 878 879 } 879 880 880 sev = 3;881 sprintf(reason,882 "Changed since backup. Consider running a differential backup in a day or two.");883 881 if (!strncmp(filename, "/var/", 5)) { 884 882 sev = 2; 885 sprintf(reason,883 asprintf(&reason, 886 884 "/var's contents will change regularly, inevitably."); 887 885 } 888 886 if (!strncmp(filename, "/home", 5)) { 889 887 sev = 2; 890 sprintf(reason,888 asprintf(&reason, 891 889 "It's in your /home partiton. Therefore, it is important."); 892 890 } 893 891 if (!strncmp(filename, "/usr/", 5)) { 894 892 sev = 3; 895 sprintf(reason,893 asprintf(&reason, 896 894 "You may have installed/removed software during the backup."); 897 895 } 898 896 if (!strncmp(filename, "/etc/", 5)) { 899 897 sev = 3; 900 sprintf(reason,898 asprintf(&reason, 901 899 "Do not edit config files while backing up your PC."); 902 900 } … … 904 902 || !strcmp(filename, "/etc/mtab")) { 905 903 sev = 1; 906 sprintf(reason, "This file changes all the time. It's OK.");904 asprintf(&reason, "This file changes all the time. It's OK."); 907 905 } 908 906 if (!strncmp(filename, "/root/", 6)) { 909 907 sev = 3; 910 sprintf(reason, "Were you compiling/editing something in /root?");908 asprintf(&reason, "Were you compiling/editing something in /root?"); 911 909 } 912 910 if (!strncmp(filename, "/root/.", 7)) { 913 911 sev = 2; 914 sprintf(reason, "Temp or 'dot' files changed in /root.");912 asprintf(&reason, "Temp or 'dot' files changed in /root."); 915 913 } 916 914 if (!strncmp(filename, "/var/lib/", 9)) { 917 915 sev = 2; 918 sprintf(reason, "Did you add/remove software during backing?");916 asprintf(&reason, "Did you add/remove software during backing?"); 919 917 } 920 918 if (!strncmp(filename, "/var/lib/rpm", 12)) { 921 919 sev = 3; 922 sprintf(reason, "Did you add/remove software during backing?");920 asprintf(&reason, "Did you add/remove software during backing?"); 923 921 } 924 922 if (!strncmp(filename, "/var/lib/slocate", 16)) { 925 923 sev = 1; 926 sprintf(reason,924 asprintf(&reason, 927 925 "The 'update' daemon ran during backup. This does not affect the integrity of your backup."); 928 926 } … … 931 929 || !strcmp(filename + strlen(filename) - 4, ".log")) { 932 930 sev = 1; 933 sprintf(reason,931 asprintf(&reason, 934 932 "Log files change frequently as the computer runs. Fret not."); 935 933 } 936 934 if (!strncmp(filename, "/var/spool", 10)) { 937 935 sev = 1; 938 sprintf(reason,936 asprintf(&reason, 939 937 "Background processes or printers were active. This does not affect the integrity of your backup."); 940 938 } 941 939 if (!strncmp(filename, "/var/spool/mail", 10)) { 942 940 sev = 2; 943 sprintf(reason, "Mail was sent/received during backup.");941 asprintf(&reason, "Mail was sent/received during backup."); 944 942 } 945 943 if (filename[strlen(filename) - 1] == '~') { 946 944 sev = 1; 947 sprintf(reason,945 asprintf(&reason, 948 946 "Backup copy of another file which was modified recently."); 949 947 } 950 948 if (strstr(filename, "cache")) { 951 949 sev = 1; 952 sprintf(reason,950 asprintf(&reason, 953 951 "Part of a cache of data. Caches change from time to time. Don't worry."); 954 952 } … … 958 956 || strstr(filename, "/.Xauthority")) { 959 957 sev = 1; 960 sprintf(reason,958 asprintf(&reason, 961 959 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."); 962 960 } 963 961 paranoid_free(filename); 964 962 965 if (out_reason) { 966 strcpy(out_reason, reason); 967 } 968 paranoid_free(reason); 963 if (sev == 0) { 964 sev = 3; 965 asprintf(&reason, 966 "Changed since backup. Consider running a differential backup in a day or two."); 967 } 968 969 out_reason = reason; 969 970 return (sev); 970 971 } … … 1000 1001 * - @c bkpinfo->media_size 1001 1002 * - @c bkpinfo->scratchdir 1002 * @return The string indicating media fill. 1003 * @return The string indicating media fill. Needs to be freed by caller 1003 1004 * @note The returned string points to static storage that will be overwritten with each call. 1004 1005 */ … … 1006 1007 { 1007 1008 /*@ int *********************************************** */ 1008 int percentage; 1009 int percentage = 0; 1010 int i; 1009 1011 int j; 1010 1012 1011 1013 /*@ buffers ******************************************* */ 1012 static char outstr[MAX_STR_LEN]; 1013 char *pos_w_commas, *tmp; 1014 char *outstr; 1015 char *tmp; 1016 char *tmp1; 1017 char *tmp2; 1018 char *prepstr; 1019 char *p; 1014 1020 1015 1021 assert(bkpinfo != NULL); 1016 malloc_string(pos_w_commas); 1017 malloc_string(tmp); 1018 sprintf(tmp, "%lld", g_tape_posK); 1019 strcpy(pos_w_commas, commarize(tmp)); 1020 1021 1022 1023 if (bkpinfo->media_size[g_current_media_number] <= 0) 1024 // { fatal_error( "percentage_media_full_comment() - unknown media size"); } 1025 { 1026 sprintf(outstr, "Volume %d: %s kilobytes archived so far", 1027 g_current_media_number, pos_w_commas); 1022 1023 if (bkpinfo->media_size[g_current_media_number] <= 0) { 1024 asprintf(&tmp, "%lld", g_tape_posK); 1025 asprintf(&outstr, "Volume %d: %s kilobytes archived so far", 1026 g_current_media_number, commarize(tmp)); 1027 paranoid_free(tmp); 1028 1028 return (outstr); 1029 1029 } … … 1034 1034 (int) (g_tape_posK / 10 / 1035 1035 bkpinfo->media_size[g_current_media_number]); 1036 if (percentage > 100) { 1037 percentage = 100; 1038 } 1039 sprintf(outstr, "Volume %d: [", g_current_media_number); 1036 asprintf(&prepstr, "Volume %d: [", g_current_media_number); 1040 1037 } else { 1041 1038 percentage = 1042 1039 (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / 1043 1040 bkpinfo->media_size[g_current_media_number]); 1044 sprintf(outstr, "%s %d: [",1041 asprintf(&prepstr, "%s %d: [", 1045 1042 media_descriptor_string(bkpinfo->backup_media_type), 1046 1043 g_current_media_number); 1047 1044 } 1048 for (j = 0; j < percentage; j += 5) { 1049 strcat(outstr, "*"); 1050 } 1051 for (; j < 100; j += 5) { 1052 strcat(outstr, "."); 1053 } 1054 j = (int) strlen(outstr); 1055 sprintf(outstr + j, "] %d%% used", percentage); 1056 paranoid_free(pos_w_commas); 1057 paranoid_free(tmp); 1045 if (percentage > 100) { 1046 percentage = 100; 1047 } 1048 j = trunc(percentage/5); 1049 tmp1 = (char *)malloc((j + 1) * sizeof(char)); 1050 for (i = 0, p = tmp1 ; i < j ; i++, p++) { 1051 *p = '*'; 1052 } 1053 *p = '\0'; 1054 1055 tmp2 = (char *)malloc((20 - j + 1) * sizeof(char)); 1056 for (i = 0, p = tmp2 ; i < 20 - j ; i++, p++) { 1057 *p = '.'; 1058 } 1059 *p = '\0'; 1060 1061 /* BERLIOS There is a bug here I can't solve for the moment. If you 1062 * replace %% in the asprintf below by 'percent' it just works, but 1063 * like this it creates a huge number. Memory pb somewhere */ 1064 /* 1065 log_it("percentage: %d", percentage); 1066 asprintf(&outstr, "%s%s%s] %3d%% used", prepstr, tmp1, tmp2, percentage); 1067 */ 1068 asprintf(&outstr, "%s%s%s] %3d percent used", prepstr, tmp1, tmp2, percentage); 1069 paranoid_free(prepstr); 1070 paranoid_free(tmp1); 1071 paranoid_free(tmp2); 1058 1072 return (outstr); 1059 1073 }
Note:
See TracChangeset
for help on using the changeset viewer.