Changeset 128 in MondoRescue for branches/2.05/mondo/mondo/common/newt-specific.c
- Timestamp:
- Nov 19, 2005, 2:27:41 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.05/mondo/mondo/common/newt-specific.c
r126 r128 124 124 //static char cvsid[] = "$Id$"; 125 125 126 extern pid_t g_mastermind_pid;127 extern char *g_tmpfs_mountpt;128 extern char *g_boot_mountpt;129 extern char *g_mondo_home;130 131 extern char g_version[];132 133 extern void set_signals(int);126 extern pid_t g_mastermind_pid; 127 extern char *g_tmpfs_mountpt; 128 extern char *g_boot_mountpt; 129 extern char *g_mondo_home; 130 131 extern char g_version[]; 132 133 extern void set_signals(int); 134 134 135 135 /** … … 140 140 * Whether we are currently in a nested call of fatal_error(). 141 141 */ 142 bool g_exiting=FALSE;142 bool g_exiting = FALSE; 143 143 144 144 /** 145 145 * Padding below the Newt components, to overcome bugs in Newt. 146 146 */ 147 char g_haharrrrr[500];148 149 150 newtComponent g_timeline=NULL,///< The line of the progress form that shows the time elapsed/remaining151 g_percentline=NULL,///< The line of the progress form that shows the percent completed/remaining152 g_scale=NULL,///< The progress bar component in the progress form153 g_progressForm=NULL,///< The progress form component itself154 g_blurb1=NULL,///< The component for line 1 of the blurb in the progress form155 g_blurb2=NULL,///< The component for line 2 of the blurb in the progress form156 g_blurb3=NULL,///< The component for line 3 (updated continuously) of the blurb in the progress form157 g_label=NULL;///< ????? @bug ?????147 char g_haharrrrr[500]; 148 149 150 newtComponent g_timeline = NULL, ///< The line of the progress form that shows the time elapsed/remaining 151 g_percentline = NULL, ///< The line of the progress form that shows the percent completed/remaining 152 g_scale = NULL, ///< The progress bar component in the progress form 153 g_progressForm = NULL, ///< The progress form component itself 154 g_blurb1 = NULL, ///< The component for line 1 of the blurb in the progress form 155 g_blurb2 = NULL, ///< The component for line 2 of the blurb in the progress form 156 g_blurb3 = NULL, ///< The component for line 3 (updated continuously) of the blurb in the progress form 157 g_label = NULL; ///< ????? @bug ????? 158 158 159 159 /** 160 160 * Padding above the Newt components, to overcome bugs in Newt. 161 161 */ 162 char g_jim_lad_yarr[500];163 char **err_log_lines = NULL,///< The list of log lines to show on the screen.164 g_blurb_str_1[MAX_NEWT_COMMENT_LEN] = "",///< The string for line 1 of the blurb in the progress form165 g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "",///< The string for line 2 of the blurb in the progress form166 g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = "";///< The string for line 3 (updated continuously) of the blurb in the progress form167 newtComponent g_isoform_main = NULL,///< The evalcall form component itself168 g_isoform_header=NULL,///< The component for the evalcall form title169 g_isoform_scale=NULL,///< The progress bar component in the evalcall form170 g_isoform_timeline=NULL,///< The line of the evalcall form that shows the time elapsed/remaining171 g_isoform_pcline=NULL;///< The line of the evalcall form that shows the percent completed/remaining172 long g_isoform_starttime;///< The time (in seconds since the epoch) that the evalcall form was opened.173 int g_isoform_old_progress = -1;///< The most recent progress update of the evalcall form (percent).174 char g_isoform_header_str[MAX_STR_LEN]=" ";///< The string for the evalcall form title.175 int g_mysterious_dot_counter;///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3176 int g_noof_log_lines = 6;///< The number of lines to show in the log at the bottom of the screen.177 int g_noof_rows = 25;///< The number of rows on the screen.178 179 int g_currentY = 3;///< The row to write background progress messages to. Incremented each time a message is written.180 extern int g_current_media_number;181 pid_t g_main_pid = 0;///< The PID of the main Mondo process.182 long g_maximum_progress = 999;///< The maximum amount of progress (100%) for the currently opened progress form.183 long g_current_progress = -999;///< The current amount of progress (filelist #, etc.) for the currently opened progress form.184 long g_start_time = 0;///< The time (in seconds since the epoch) that the progress form was opened.185 bool g_text_mode = TRUE;///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface.186 char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN],///< ... @bug Unneeded w/current XMondo.187 g_xmondo_stdout[MAX_NEWT_COMMENT_LEN];///< .... @bug Unneeded w/current XMondo.188 bool g_called_by_xmondo=FALSE;///< @bug Unneeded w/current XMondo.189 char *g_erase_tmpdir_and_scratchdir;///< The command to run to erase the tmpdir and scratchdir at the end of Mondo.190 char *g_selfmounted_isodir;///< Holds the NFS mountpoint if mounted via mondoarchive.162 char g_jim_lad_yarr[500]; 163 char **err_log_lines = NULL, ///< The list of log lines to show on the screen. 164 g_blurb_str_1[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 1 of the blurb in the progress form 165 g_blurb_str_2[MAX_NEWT_COMMENT_LEN] = "", ///< The string for line 2 of the blurb in the progress form 166 g_blurb_str_3[MAX_NEWT_COMMENT_LEN] = ""; ///< The string for line 3 (updated continuously) of the blurb in the progress form 167 newtComponent g_isoform_main = NULL, ///< The evalcall form component itself 168 g_isoform_header = NULL, ///< The component for the evalcall form title 169 g_isoform_scale = NULL, ///< The progress bar component in the evalcall form 170 g_isoform_timeline = NULL, ///< The line of the evalcall form that shows the time elapsed/remaining 171 g_isoform_pcline = NULL; ///< The line of the evalcall form that shows the percent completed/remaining 172 long g_isoform_starttime; ///< The time (in seconds since the epoch) that the evalcall form was opened. 173 int g_isoform_old_progress = -1; ///< The most recent progress update of the evalcall form (percent). 174 char g_isoform_header_str[MAX_STR_LEN] = " "; ///< The string for the evalcall form title. 175 int g_mysterious_dot_counter; ///< The counter for the twirling baton (/ | \\ - ...) on percentage less than 3 176 int g_noof_log_lines = 6; ///< The number of lines to show in the log at the bottom of the screen. 177 int g_noof_rows = 25; ///< The number of rows on the screen. 178 179 int g_currentY = 3; ///< The row to write background progress messages to. Incremented each time a message is written. 180 extern int g_current_media_number; 181 pid_t g_main_pid = 0; ///< The PID of the main Mondo process. 182 long g_maximum_progress = 999; ///< The maximum amount of progress (100%) for the currently opened progress form. 183 long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form. 184 long g_start_time = 0; ///< The time (in seconds since the epoch) that the progress form was opened. 185 bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface. 186 char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN], ///< ... @bug Unneeded w/current XMondo. 187 g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo. 188 bool g_called_by_xmondo = FALSE; ///< @bug Unneeded w/current XMondo. 189 char *g_erase_tmpdir_and_scratchdir; ///< The command to run to erase the tmpdir and scratchdir at the end of Mondo. 190 char *g_selfmounted_isodir; ///< Holds the NFS mountpoint if mounted via mondoarchive. 191 191 192 192 /* @} - end of globalGroup */ … … 194 194 //int g_fd_in=-1, g_fd_out=-1; 195 195 196 void popup_and_OK(char*);196 void popup_and_OK(char *); 197 197 198 198 … … 206 206 * @return TRUE for yes; FALSE for no. 207 207 */ 208 bool 209 ask_me_yes_or_no (char *prompt) 210 { 211 212 /*@ buffers ***********************************************************/ 213 char *tmp; 214 int i; 215 216 tmp = malloc(MAX_NEWT_COMMENT_LEN); 217 assert_string_is_neither_NULL_nor_zerolength(prompt); 218 219 if (g_text_mode) 220 { 221 while(1) 222 { 223 system("sync"); 224 printf ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ", prompt); 225 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 226 if (tmp[strlen (tmp) - 1] == '\n') 227 tmp[strlen (tmp) - 1] = '\0'; 228 229 i = (int) strlen(tmp); 230 if (i>0 && tmp[i-1]<32) { tmp[i-1]='\0'; } 231 if (strstr ("yesYES", tmp)) 232 { 233 paranoid_free(tmp); 234 return (TRUE); 235 } 236 else if (strstr ("NOno", tmp)) 237 { 238 paranoid_free(tmp); 239 return (FALSE); 240 } 241 else 242 { 243 system("sync"); 244 printf("Please enter either YES or NO (or yes or no, or y or n, or...)\n"); 245 } 246 } 247 } 248 else 249 { 250 paranoid_free(tmp); 251 return (popup_with_buttons (prompt, "Yes", "No")); 252 } 253 } 208 bool ask_me_yes_or_no(char *prompt) { 209 210 /*@ buffers ********************************************************** */ 211 char *tmp; 212 int i; 213 214 tmp = malloc(MAX_NEWT_COMMENT_LEN); 215 assert_string_is_neither_NULL_nor_zerolength(prompt); 216 217 if (g_text_mode) { 218 while (1) { 219 system("sync"); 220 printf 221 ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ", 222 prompt); 223 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 224 if (tmp[strlen(tmp) - 1] == '\n') 225 tmp[strlen(tmp) - 1] = '\0'; 226 227 i = (int) strlen(tmp); 228 if (i > 0 && tmp[i - 1] < 32) { 229 tmp[i - 1] = '\0'; 230 } 231 if (strstr("yesYES", tmp)) { 232 paranoid_free(tmp); 233 return (TRUE); 234 } else if (strstr("NOno", tmp)) { 235 paranoid_free(tmp); 236 return (FALSE); 237 } else { 238 system("sync"); 239 printf 240 ("Please enter either YES or NO (or yes or no, or y or n, or...)\n"); 241 } 242 } 243 } else { 244 paranoid_free(tmp); 245 return (popup_with_buttons(prompt, "Yes", "No")); 246 } 247 } 254 248 255 249 … … 260 254 * @return TRUE for OK, FALSE for Cancel. 261 255 */ 262 bool 263 ask_me_OK_or_cancel (char *prompt) 264 { 265 266 /*@ buffer ************************************************************/ 267 char *tmp; 268 int i; 269 270 tmp = malloc(MAX_NEWT_COMMENT_LEN); 271 assert_string_is_neither_NULL_nor_zerolength(prompt); 272 if (g_text_mode) 273 { 274 system("sync"); 275 printf ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ", prompt); 276 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 277 if (tmp[strlen (tmp) - 1] == '\n') 278 tmp[strlen (tmp) - 1] = '\0'; 279 280 i = (int) strlen(tmp); 281 if (i>0 && tmp[i-1]<32) { tmp[i-1]='\0'; } 282 if (strstr ("okOKOkYESyes", tmp)) 283 { 284 paranoid_free(tmp); 285 return (TRUE); 286 } 287 else 288 { 289 paranoid_free(tmp); 290 return (FALSE); 291 } 292 } 293 else 294 { 295 paranoid_free(tmp); 296 return (popup_with_buttons (prompt, " Okay ", "Cancel")); 297 } 298 } 256 bool ask_me_OK_or_cancel(char *prompt) { 257 258 /*@ buffer *********************************************************** */ 259 char *tmp; 260 int i; 261 262 tmp = malloc(MAX_NEWT_COMMENT_LEN); 263 assert_string_is_neither_NULL_nor_zerolength(prompt); 264 if (g_text_mode) { 265 system("sync"); 266 printf 267 ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ", 268 prompt); 269 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 270 if (tmp[strlen(tmp) - 1] == '\n') 271 tmp[strlen(tmp) - 1] = '\0'; 272 273 i = (int) strlen(tmp); 274 if (i > 0 && tmp[i - 1] < 32) { 275 tmp[i - 1] = '\0'; 276 } 277 if (strstr("okOKOkYESyes", tmp)) { 278 paranoid_free(tmp); 279 return (TRUE); 280 } else { 281 paranoid_free(tmp); 282 return (FALSE); 283 } 284 } else { 285 paranoid_free(tmp); 286 return (popup_with_buttons(prompt, " Okay ", "Cancel")); 287 } 288 } 299 289 300 290 … … 303 293 * Close the currently opened evalcall form. 304 294 */ 305 void 306 close_evalcall_form (void) 307 { 308 if (g_text_mode) {return;} 309 if (g_isoform_main == NULL) {return; } 310 update_evalcall_form (100); 311 usleep (500000); 312 if (g_text_mode) 313 { 314 log_msg (2, "Closing evalcall form"); 315 return; 316 } 317 newtPopHelpLine (); 318 newtFormDestroy (g_isoform_main); 319 newtPopWindow (); 320 g_isoform_main = NULL; 321 g_isoform_old_progress = -1; 322 } 295 void 296 close_evalcall_form(void) { 297 if (g_text_mode) { 298 return; 299 } 300 if (g_isoform_main == NULL) { 301 return; 302 } 303 update_evalcall_form(100); 304 usleep(500000); 305 if (g_text_mode) { 306 log_msg(2, "Closing evalcall form"); 307 return; 308 } 309 newtPopHelpLine(); 310 newtFormDestroy(g_isoform_main); 311 newtPopWindow(); 312 g_isoform_main = NULL; 313 g_isoform_old_progress = -1; 314 } 323 315 324 316 … … 326 318 * Close the currently opened progress form. 327 319 */ 328 void329 close_progress_form () 330 {331 if (g_text_mode) {return;} 332 if (g_current_progress == -999) 333 334 log_msg (2, "Trying to close the progress form when it ain't open!"); 335 return;336 } 337 g_current_progress = g_maximum_progress; 338 update_progress_form ("Complete");339 sleep (1);340 if (g_text_mode) 341 342 log_msg(2, "Closing progress form");343 344 345 newtPopHelpLine();346 newtFormDestroy(g_progressForm);347 newtPopWindow();348 349 350 }320 void 321 close_progress_form() { 322 if (g_text_mode) { 323 return; 324 } 325 if (g_current_progress == -999) { 326 log_msg(2, 327 "Trying to close the progress form when it ain't open!"); 328 return; 329 } 330 g_current_progress = g_maximum_progress; 331 update_progress_form("Complete"); 332 sleep(1); 333 if (g_text_mode) { 334 log_msg(2, "Closing progress form"); 335 return; 336 } 337 newtPopHelpLine(); 338 newtFormDestroy(g_progressForm); 339 newtPopWindow(); 340 g_progressForm = NULL; 341 g_current_progress = -999; 342 } 351 343 352 344 … … 358 350 * @note This function never returns. 359 351 */ 360 void 361 fatal_error (char *error_string) 362 { 363 /*@ buffers ******************************************************/ 364 char fatalstr[MAX_NEWT_COMMENT_LEN] = "-------FATAL ERROR---------"; 365 char *tmp; 366 char *command; 367 static bool already_exiting=FALSE; 368 int i; 369 370 /*@ end vars *****************************************************/ 371 372 malloc_string(command); 373 tmp = malloc(MAX_NEWT_COMMENT_LEN); 374 set_signals(FALSE); // link to external func 375 g_exiting = TRUE; 376 log_msg(1, "Fatal error received - '%s'", error_string); 377 printf("Fatal error... %s\n", error_string); 378 if (getpid() == g_mastermind_pid) 379 { 380 log_msg(2, "mastermind %d is exiting", (int)getpid()); 381 kill(g_main_pid, SIGTERM); 382 paranoid_free(tmp); 383 finish(1); 384 } 385 386 if (getpid() != g_main_pid) 387 { 388 if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) 389 { 390 log_msg(2, "non-m/m %d is exiting", (int)getpid()); 391 kill(g_main_pid, SIGTERM); 392 paranoid_free(tmp); 393 finish(1); 394 } 395 } 396 397 log_msg (3, "OK, I think I'm the main PID."); 398 if (already_exiting) 399 { 400 log_msg(3, "...I'm already exiting. Give me time, Julian!"); 401 paranoid_free(tmp); 402 finish(1); 403 } 404 405 already_exiting = TRUE; 406 log_msg(2, "I'm going to do some cleaning up now."); 407 paranoid_system("killall mindi 2> /dev/null"); 408 kill_anything_like_this("/mondo/do-not"); 409 kill_anything_like_this("tmp.mondo"); 410 kill_anything_like_this("partimagehack"); 411 sync(); 412 sprintf(tmp, "umount %s", g_tmpfs_mountpt); 413 chdir("/"); 414 for(i=0; i<10 && run_program_and_log_output(tmp, 5); i++) 415 { 416 log_msg(2, "Waiting for child processes to terminate"); 417 sleep(1); 418 run_program_and_log_output(tmp, 5); 419 } 420 421 if (g_erase_tmpdir_and_scratchdir[0]) 422 { run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5); } 423 424 if (g_selfmounted_isodir) { 425 sprintf(command, "umount %s", g_selfmounted_isodir); 426 run_program_and_log_output(command, 5); 427 sprintf(command, "rmdir %s", g_selfmounted_isodir); 428 run_program_and_log_output(command, 5); 429 } 430 431 if (!g_text_mode) 432 { 433 log_msg (0, fatalstr); 434 log_msg (0, error_string); 435 // popup_and_OK (error_string); 436 newtFinished (); 437 } 438 439 printf ("---FATALERROR--- %s\n", error_string); 440 system("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null"); 441 if (!strstr(g_version, "cvs") && !strstr(g_version, "svn")) 442 { 443 printf("Please try the snapshot (the version with 'cvs' and the date in its filename)"); 444 printf("to see if that fixes the problem. Please don't bother the mailing list with"); 445 printf("your problem UNTIL you've tried the snapshot. The snapshot contains bugfixes"); 446 printf("which might help you. Go to http://www.mondorescue.org/download/download.html"); 447 printf("For more information.\n"); 448 log_msg(0, "Please DON'T contact the mailing list. Try the SNAPSHOTS."); 449 } 450 else 451 { 452 printf("If you require technical support, please contact the mailing list.\n"); 453 printf("See http://www.mondorescue.org for details.\n"); 454 printf("The list's members can help you, if you attach that file to your e-mail.\n"); 455 } 456 printf("Log file: %s\n", MONDO_LOGFILE); 457 // printf("VERSION=%s\n", g_version); 458 if (does_file_exist("/tmp/MA.log.gz")) 459 { 460 printf("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n"); 461 } 462 printf ("Mondo has aborted.\n"); 463 register_pid(0, "mondo"); // finish() does this too, FYI 464 if (!g_main_pid) { log_msg(3, "FYI - g_main_pid is blank"); } 465 paranoid_free(tmp); 466 paranoid_free(command); 467 finish (254); 468 } 352 void 353 fatal_error(char *error_string) { 354 /*@ buffers ***************************************************** */ 355 char fatalstr[MAX_NEWT_COMMENT_LEN] = 356 "-------FATAL ERROR---------"; 357 char *tmp; 358 char *command; 359 static bool already_exiting = FALSE; 360 int i; 361 362 /*@ end vars **************************************************** */ 363 364 malloc_string(command); 365 tmp = malloc(MAX_NEWT_COMMENT_LEN); 366 set_signals(FALSE); // link to external func 367 g_exiting = TRUE; 368 log_msg(1, "Fatal error received - '%s'", error_string); 369 printf("Fatal error... %s\n", error_string); 370 if (getpid() == g_mastermind_pid) { 371 log_msg(2, "mastermind %d is exiting", (int) getpid()); 372 kill(g_main_pid, SIGTERM); 373 paranoid_free(tmp); 374 finish(1); 375 } 376 377 if (getpid() != g_main_pid) { 378 if (g_mastermind_pid != 0 && getpid() != g_mastermind_pid) { 379 log_msg(2, "non-m/m %d is exiting", (int) getpid()); 380 kill(g_main_pid, SIGTERM); 381 paranoid_free(tmp); 382 finish(1); 383 } 384 } 385 386 log_msg(3, "OK, I think I'm the main PID."); 387 if (already_exiting) { 388 log_msg(3, "...I'm already exiting. Give me time, Julian!"); 389 paranoid_free(tmp); 390 finish(1); 391 } 392 393 already_exiting = TRUE; 394 log_msg(2, "I'm going to do some cleaning up now."); 395 paranoid_system("killall mindi 2> /dev/null"); 396 kill_anything_like_this("/mondo/do-not"); 397 kill_anything_like_this("tmp.mondo"); 398 kill_anything_like_this("partimagehack"); 399 sync(); 400 sprintf(tmp, "umount %s", g_tmpfs_mountpt); 401 chdir("/"); 402 for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) { 403 log_msg(2, "Waiting for child processes to terminate"); 404 sleep(1); 405 run_program_and_log_output(tmp, 5); 406 } 407 408 if (g_erase_tmpdir_and_scratchdir[0]) { 409 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5); 410 } 411 412 if (g_selfmounted_isodir) { 413 sprintf(command, "umount %s", g_selfmounted_isodir); 414 run_program_and_log_output(command, 5); 415 sprintf(command, "rmdir %s", g_selfmounted_isodir); 416 run_program_and_log_output(command, 5); 417 } 418 419 if (!g_text_mode) { 420 log_msg(0, fatalstr); 421 log_msg(0, error_string); 422 // popup_and_OK (error_string); 423 newtFinished(); 424 } 425 426 printf("---FATALERROR--- %s\n", error_string); 427 system 428 ("cat /var/log/mondo-archive.log | gzip -9 > /tmp/MA.log.gz 2> /dev/null"); 429 if (!strstr(g_version, "cvs") && !strstr(g_version, "svn")) { 430 printf 431 ("Please try the snapshot (the version with 'cvs' and the date in its filename)"); 432 printf 433 ("to see if that fixes the problem. Please don't bother the mailing list with"); 434 printf 435 ("your problem UNTIL you've tried the snapshot. The snapshot contains bugfixes"); 436 printf 437 ("which might help you. Go to http://www.mondorescue.org/download/download.html"); 438 printf("For more information.\n"); 439 log_msg(0, 440 "Please DON'T contact the mailing list. Try the SNAPSHOTS."); 441 } else { 442 printf 443 ("If you require technical support, please contact the mailing list.\n"); 444 printf("See http://www.mondorescue.org for details.\n"); 445 printf 446 ("The list's members can help you, if you attach that file to your e-mail.\n"); 447 } 448 printf("Log file: %s\n", MONDO_LOGFILE); 449 // printf("VERSION=%s\n", g_version); 450 if (does_file_exist("/tmp/MA.log.gz")) { 451 printf 452 ("FYI, I have gzipped the log and saved it to /tmp/MA.log.gz\n"); 453 } 454 printf("Mondo has aborted.\n"); 455 register_pid(0, "mondo"); // finish() does this too, FYI 456 if (!g_main_pid) { 457 log_msg(3, "FYI - g_main_pid is blank"); 458 } 459 paranoid_free(tmp); 460 paranoid_free(command); 461 finish(254); 462 } 469 463 470 464 … … 476 470 * @note This function never returns. 477 471 */ 478 void 479 finish (int signal) 480 { 472 void 473 finish(int signal) { 481 474 char *command; 482 475 malloc_string(command); 483 476 484 /* if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */ 485 486 /* newtPopHelpLine(); */ 487 488 register_pid(0, "mondo"); 489 chdir("/"); 490 run_program_and_log_output("umount "MNT_CDROM, FALSE); 491 run_program_and_log_output("rm -Rf /mondo.scratch.* /tmp.mondo.*", FALSE); 492 if (g_erase_tmpdir_and_scratchdir) 493 { 494 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1); 495 } 496 if (g_selfmounted_isodir) { 497 sprintf(command, "umount %s", g_selfmounted_isodir); 498 run_program_and_log_output(command, 1); 499 sprintf(command, "rmdir %s", g_selfmounted_isodir); 500 run_program_and_log_output(command, 1); 501 } 502 477 /* if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */ 478 479 /* newtPopHelpLine(); */ 480 481 register_pid(0, "mondo"); 482 chdir("/"); 483 run_program_and_log_output("umount " MNT_CDROM, FALSE); 484 run_program_and_log_output("rm -Rf /mondo.scratch.* /tmp.mondo.*", 485 FALSE); 486 if (g_erase_tmpdir_and_scratchdir) { 487 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 1); 488 } 489 if (g_selfmounted_isodir) { 490 sprintf(command, "umount %s", g_selfmounted_isodir); 491 run_program_and_log_output(command, 1); 492 sprintf(command, "rmdir %s", g_selfmounted_isodir); 493 run_program_and_log_output(command, 1); 494 } 503 495 // iamhere("foo"); 504 496 /* system("clear"); */ 505 497 // iamhere("About to call newtFinished"); 506 if (!g_text_mode) 507 { 508 if (does_file_exist("/THIS-IS-A-RAMDISK")) 509 { 510 log_msg(1, "Calling newtFinished()"); 511 newtFinished(); 512 } 513 else 514 { 515 log_msg(1, "Calling newtSuspend()"); 516 newtSuspend(); 517 } 518 } 498 if (!g_text_mode) { 499 if (does_file_exist("/THIS-IS-A-RAMDISK")) { 500 log_msg(1, "Calling newtFinished()"); 501 newtFinished(); 502 } else { 503 log_msg(1, "Calling newtSuspend()"); 504 newtSuspend(); 505 } 506 } 519 507 // system("clear"); 520 508 // iamhere("Finished calling newtFinished"); 521 printf("Execution run ended; result=%d\n", signal);522 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);523 524 exit(signal);525 }509 printf("Execution run ended; result=%d\n", signal); 510 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE); 511 free_libmondo_global_strings(); 512 exit(signal); 513 } 526 514 527 515 … … 535 523 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression. 536 524 */ 537 void 538 log_file_end_to_screen (char *filename, char *grep_for_me) 539 { 540 541 /*@ buffers ***********************************************************/ 542 char *command; 543 char *tmp; 544 545 /*@ pointers **********************************************************/ 546 FILE *fin; 547 548 /*@ int ***************************************************************/ 549 int i = 0; 550 551 malloc_string(command); 552 malloc_string(tmp); 553 assert_string_is_neither_NULL_nor_zerolength(filename); 554 assert(grep_for_me!=NULL); 555 556 if (!does_file_exist (filename)) 557 { 558 paranoid_free(command); 559 paranoid_free(tmp); 560 return; 561 } 562 if (grep_for_me[0] != '\0') 563 { 564 sprintf (command, "grep '%s' %s | tail -n%d", 565 grep_for_me, filename, 566 g_noof_log_lines); 567 } 568 else 569 { 570 sprintf (command, "cat %s | tail -n%d %s", g_noof_log_lines, filename); 571 } 572 fin = popen (command, "r"); 573 if (!fin) 574 { 575 log_OS_error(command); 576 } 577 else 578 { 579 for (i = 0; i < g_noof_log_lines; i++) 580 { 581 for (err_log_lines[i][0] = '\0'; 582 strlen (err_log_lines[i]) < 2 && !feof (fin);) 583 { 584 (void) fgets (err_log_lines[i], MAX_NEWT_COMMENT_LEN, fin); 585 strip_spaces (err_log_lines[i]); 586 if (!strncmp (err_log_lines[i], "root:", 5)) 587 { 588 strcpy (tmp, err_log_lines[i] + 6); 589 strcpy (err_log_lines[i], tmp); 590 } 591 if (feof (fin)) 592 { 593 break; 594 } 595 } 596 } 597 paranoid_pclose (fin); 598 } 599 refresh_log_screen (); 600 paranoid_free(command); 601 paranoid_free(tmp); 602 } 525 void 526 log_file_end_to_screen(char *filename, char *grep_for_me) { 527 528 /*@ buffers ********************************************************** */ 529 char *command; 530 char *tmp; 531 532 /*@ pointers ********************************************************* */ 533 FILE *fin; 534 535 /*@ int ************************************************************** */ 536 int i = 0; 537 538 malloc_string(command); 539 malloc_string(tmp); 540 assert_string_is_neither_NULL_nor_zerolength(filename); 541 assert(grep_for_me != NULL); 542 543 if (!does_file_exist(filename)) { 544 paranoid_free(command); 545 paranoid_free(tmp); 546 return; 547 } 548 if (grep_for_me[0] != '\0') { 549 sprintf(command, "grep '%s' %s | tail -n%d", 550 grep_for_me, filename, g_noof_log_lines); 551 } else { 552 sprintf(command, "cat %s | tail -n%d %s", g_noof_log_lines, 553 filename); 554 } 555 fin = popen(command, "r"); 556 if (!fin) { 557 log_OS_error(command); 558 } else { 559 for (i = 0; i < g_noof_log_lines; i++) { 560 for (err_log_lines[i][0] = '\0'; 561 strlen(err_log_lines[i]) < 2 && !feof(fin);) { 562 (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN, 563 fin); 564 strip_spaces(err_log_lines[i]); 565 if (!strncmp(err_log_lines[i], "root:", 5)) { 566 strcpy(tmp, err_log_lines[i] + 6); 567 strcpy(err_log_lines[i], tmp); 568 } 569 if (feof(fin)) { 570 break; 571 } 572 } 573 } 574 paranoid_pclose(fin); 575 } 576 refresh_log_screen(); 577 paranoid_free(command); 578 paranoid_free(tmp); 579 } 603 580 604 581 … … 608 585 * @note The message is also written to the logfile. 609 586 */ 610 void 611 log_to_screen (const char *fmt, ...) 612 { 613 614 /*@ int ***************************************************************/ 615 int i = 0; 616 int j = 0; 617 va_list args; 618 619 /*@ buffers ***********************************************************/ 620 char *output; 621 622 malloc_string(output); 623 624 va_start(args, fmt); 625 vsprintf(output, fmt, args); 626 log_msg(0, output); 627 output[80] = '\0'; 628 va_end(args); 629 i = (int) strlen (output); 630 if (i>0 && output[i - 1] < 32) 631 { 632 output[i - 1] = '\0'; 633 } 634 635 if (err_log_lines) { 636 for (i = 1; i < g_noof_log_lines; i++) 637 { 638 strcpy (err_log_lines[i - 1], 639 " "); 640 strcpy (err_log_lines[i - 1], err_log_lines[i]); 641 } 642 } 643 while (strlen(output)>0 && output[strlen (output) - 1] < 32) 644 { 645 output[strlen (output) - 1] = '\0'; 646 } 647 for (j = 0; j < (int) strlen (output); j++) 648 { 649 if (output[j] < 32) 650 { 651 output[j] = ' '; 652 } 653 } 654 if (err_log_lines) 655 strcpy (err_log_lines[g_noof_log_lines - 1], output); 656 if (g_text_mode) 657 { 658 printf("%s\n", output); 659 } 660 else 661 { 662 refresh_log_screen (); 663 } 664 paranoid_free(output); 665 } 587 void 588 log_to_screen(const char *fmt, ...) { 589 590 /*@ int ************************************************************** */ 591 int i = 0; 592 int j = 0; 593 va_list args; 594 595 /*@ buffers ********************************************************** */ 596 char *output; 597 598 malloc_string(output); 599 600 va_start(args, fmt); 601 vsprintf(output, fmt, args); 602 log_msg(0, output); 603 output[80] = '\0'; 604 va_end(args); 605 i = (int) strlen(output); 606 if (i > 0 && output[i - 1] < 32) { 607 output[i - 1] = '\0'; 608 } 609 610 if (err_log_lines) { 611 for (i = 1; i < g_noof_log_lines; i++) { 612 strcpy(err_log_lines[i - 1], 613 " "); 614 strcpy(err_log_lines[i - 1], err_log_lines[i]); 615 } 616 } 617 while (strlen(output) > 0 && output[strlen(output) - 1] < 32) { 618 output[strlen(output) - 1] = '\0'; 619 } 620 for (j = 0; j < (int) strlen(output); j++) { 621 if (output[j] < 32) { 622 output[j] = ' '; 623 } 624 } 625 if (err_log_lines) 626 strcpy(err_log_lines[g_noof_log_lines - 1], output); 627 if (g_text_mode) { 628 printf("%s\n", output); 629 } else { 630 refresh_log_screen(); 631 } 632 paranoid_free(output); 633 } 666 634 667 635 … … 674 642 * @param output The string to write. 675 643 */ 676 void 677 mvaddstr_and_log_it (int y, int x, char *output) 678 { 679 assert_string_is_neither_NULL_nor_zerolength(output); 680 log_msg (0, output); 681 if (g_text_mode) 682 { 683 printf ("%s\n", output); 684 } 685 else 686 { 687 newtDrawRootText (x, y, output); 688 newtRefresh (); 689 } 690 } 644 void 645 mvaddstr_and_log_it(int y, int x, char *output) { 646 assert_string_is_neither_NULL_nor_zerolength(output); 647 log_msg(0, output); 648 if (g_text_mode) { 649 printf("%s\n", output); 650 } else { 651 newtDrawRootText(x, y, output); 652 newtRefresh(); 653 } 654 } 691 655 692 656 … … 697 661 * @param ttl The title to use for the evalcall form. 698 662 */ 699 void 700 open_evalcall_form (char *ttl) 701 { 702 703 /*@ buffers **********************************************************/ 704 char *title; 705 char *tmp; 706 707 /*@ initialize *******************************************************/ 708 g_isoform_old_progress = -1; 709 g_mysterious_dot_counter = 0; 710 malloc_string(title); 711 malloc_string(tmp); 712 713 assert(ttl!=NULL); 714 strcpy (title, ttl); 715 strcpy (g_isoform_header_str, title); 663 void 664 open_evalcall_form(char *ttl) { 665 666 /*@ buffers ********************************************************* */ 667 char *title; 668 char *tmp; 669 670 /*@ initialize ****************************************************** */ 671 g_isoform_old_progress = -1; 672 g_mysterious_dot_counter = 0; 673 malloc_string(title); 674 malloc_string(tmp); 675 676 assert(ttl != NULL); 677 strcpy(title, ttl); 678 strcpy(g_isoform_header_str, title); 716 679 // center_string (title, 80); 717 if (g_text_mode) 718 { 719 log_msg (0, title); 720 } 721 else 722 { 723 strcpy(tmp, title); 724 center_string(tmp, 80); 725 newtPushHelpLine (tmp); 726 } 727 center_string (g_isoform_header_str, 36); 728 g_isoform_starttime = get_time (); 729 if (g_text_mode) 730 { 731 log_msg (0, g_isoform_header_str); 732 } 733 else 734 { 735 g_isoform_header = newtLabel (1, 1, g_isoform_header_str); 736 g_isoform_scale = newtScale (3, 3, 34, 100); 737 // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait"); 738 newtCenteredWindow (40, 7, title); 739 g_isoform_main = newtForm (NULL, NULL, 0); 740 g_isoform_timeline = newtLabel (1, 5, "This is the timeline"); 741 g_isoform_pcline = newtLabel (1, 6, "This is the pcline"); 742 newtFormAddComponents (g_isoform_main, g_isoform_timeline, 743 g_isoform_pcline, g_isoform_header, 744 g_isoform_scale, NULL); 745 newtRefresh (); 746 } 747 update_evalcall_form (0); 748 paranoid_free(tmp); 749 paranoid_free(title); 750 } 680 if (g_text_mode) { 681 log_msg(0, title); 682 } else { 683 strcpy(tmp, title); 684 center_string(tmp, 80); 685 newtPushHelpLine(tmp); 686 } 687 center_string(g_isoform_header_str, 36); 688 g_isoform_starttime = get_time(); 689 if (g_text_mode) { 690 log_msg(0, g_isoform_header_str); 691 } else { 692 g_isoform_header = newtLabel(1, 1, g_isoform_header_str); 693 g_isoform_scale = newtScale(3, 3, 34, 100); 694 // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait"); 695 newtCenteredWindow(40, 7, title); 696 g_isoform_main = newtForm(NULL, NULL, 0); 697 g_isoform_timeline = newtLabel(1, 5, "This is the timeline"); 698 g_isoform_pcline = newtLabel(1, 6, "This is the pcline"); 699 newtFormAddComponents(g_isoform_main, g_isoform_timeline, 700 g_isoform_pcline, g_isoform_header, 701 g_isoform_scale, NULL); 702 newtRefresh(); 703 } 704 update_evalcall_form(0); 705 paranoid_free(tmp); 706 paranoid_free(title); 707 } 751 708 752 709 … … 761 718 * @param max_val The maximum amount of progress (number of filesets, etc.) 762 719 */ 763 void 764 open_progress_form (char *title, char *b1, char *b2, char *b3, long max_val) 765 { 766 767 /*@ buffers **********************************************************/ 768 char *b1c; 769 char *blurb1; 770 char *blurb2; 771 char *blurb3; 772 773 /*@ initialize *******************************************************/ 774 g_mysterious_dot_counter = 0; 775 776 malloc_string(b1c); 777 malloc_string(blurb1); 778 malloc_string(blurb2); 779 malloc_string(blurb3); 780 781 assert(title!=NULL); 782 assert(b1!=NULL); 783 assert(b2!=NULL); 784 assert(b3!=NULL); 785 786 strcpy (blurb1, b1); 787 strcpy (blurb2, b2); 788 strcpy (blurb3, b3); 789 strcpy (b1c, b1); 790 center_string (b1c, 80); 791 if (max_val <= 0) 792 { 793 max_val = 1; 794 } 795 796 g_start_time = get_time (); 797 g_maximum_progress = max_val; 798 g_current_progress = 0; 799 strcpy (g_blurb_str_1, blurb1); 800 strcpy (g_blurb_str_2, blurb3); 801 strcpy (g_blurb_str_3, blurb2); 802 if (g_text_mode) 803 { 804 log_msg (0, blurb1); 805 log_msg (0, blurb2); 806 log_msg (0, blurb3); 807 } 808 else 809 { 810 g_blurb1 = newtLabel (2, 1, blurb1); 811 g_blurb2 = newtLabel (2, 2, blurb3); 812 g_blurb3 = newtLabel (2, 4, blurb2); 813 // newtOpenWindow (10, 4, 60, 11, title); 814 newtCenteredWindow (60, 11, title); 815 g_scale = newtScale (3, 6, 54, g_maximum_progress); 816 g_progressForm = newtForm (NULL, NULL, 0); 817 g_percentline = newtLabel (10, 9, "This is the percentline"); 818 g_timeline = newtLabel (10, 8, "This is the timeline"); 819 newtFormAddComponents (g_progressForm, g_percentline, g_timeline, 820 g_scale, g_blurb1, g_blurb3, g_blurb2, NULL); 821 newtPushHelpLine (b1c); 822 newtRefresh (); 823 } 824 update_progress_form_full (blurb1, blurb2, blurb3); 825 paranoid_free(b1c); 826 paranoid_free(blurb1); 827 paranoid_free(blurb2); 828 paranoid_free(blurb3); 829 } 720 void 721 open_progress_form(char *title, char *b1, char *b2, char *b3, 722 long max_val) { 723 724 /*@ buffers ********************************************************* */ 725 char *b1c; 726 char *blurb1; 727 char *blurb2; 728 char *blurb3; 729 730 /*@ initialize ****************************************************** */ 731 g_mysterious_dot_counter = 0; 732 733 malloc_string(b1c); 734 malloc_string(blurb1); 735 malloc_string(blurb2); 736 malloc_string(blurb3); 737 738 assert(title != NULL); 739 assert(b1 != NULL); 740 assert(b2 != NULL); 741 assert(b3 != NULL); 742 743 strcpy(blurb1, b1); 744 strcpy(blurb2, b2); 745 strcpy(blurb3, b3); 746 strcpy(b1c, b1); 747 center_string(b1c, 80); 748 if (max_val <= 0) { 749 max_val = 1; 750 } 751 752 g_start_time = get_time(); 753 g_maximum_progress = max_val; 754 g_current_progress = 0; 755 strcpy(g_blurb_str_1, blurb1); 756 strcpy(g_blurb_str_2, blurb3); 757 strcpy(g_blurb_str_3, blurb2); 758 if (g_text_mode) { 759 log_msg(0, blurb1); 760 log_msg(0, blurb2); 761 log_msg(0, blurb3); 762 } else { 763 g_blurb1 = newtLabel(2, 1, blurb1); 764 g_blurb2 = newtLabel(2, 2, blurb3); 765 g_blurb3 = newtLabel(2, 4, blurb2); 766 // newtOpenWindow (10, 4, 60, 11, title); 767 newtCenteredWindow(60, 11, title); 768 g_scale = newtScale(3, 6, 54, g_maximum_progress); 769 g_progressForm = newtForm(NULL, NULL, 0); 770 g_percentline = newtLabel(10, 9, "This is the percentline"); 771 g_timeline = newtLabel(10, 8, "This is the timeline"); 772 newtFormAddComponents(g_progressForm, g_percentline, 773 g_timeline, g_scale, g_blurb1, g_blurb3, 774 g_blurb2, NULL); 775 newtPushHelpLine(b1c); 776 newtRefresh(); 777 } 778 update_progress_form_full(blurb1, blurb2, blurb3); 779 paranoid_free(b1c); 780 paranoid_free(blurb1); 781 paranoid_free(blurb2); 782 paranoid_free(blurb3); 783 } 830 784 831 785 /** … … 833 787 * @param prompt The message. 834 788 */ 835 void 836 popup_and_OK (char *prompt) 837 { 838 char ch; 839 840 assert_string_is_neither_NULL_nor_zerolength(prompt); 841 842 log_msg (0, prompt); 843 if (g_text_mode) 844 { 845 printf 846 ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ", prompt); 847 while (((ch = getchar()) != '\n') && (ch != EOF)) 848 ; 849 } 850 else 851 { 852 (void) popup_with_buttons (prompt, " OK ", ""); 853 } 854 } 789 void 790 popup_and_OK(char *prompt) { 791 char ch; 792 793 assert_string_is_neither_NULL_nor_zerolength(prompt); 794 795 log_msg(0, prompt); 796 if (g_text_mode) { 797 printf 798 ("---promptpopup---1--- %s\r\n---promptpopup---Q--- [OK] ---\r\n--> ", 799 prompt); 800 while (((ch = getchar()) != '\n') && (ch != EOF)); 801 } else { 802 (void) popup_with_buttons(prompt, " OK ", ""); 803 } 804 } 855 805 856 806 /** … … 862 812 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel. 863 813 */ 864 bool 865 popup_and_get_string (char *title, char *b, char *output, int maxsize) 866 { 867 868 /*@ newt *************************************************************/ 869 newtComponent myForm; 870 newtComponent b_1; 871 newtComponent b_2; 872 newtComponent b_res; 873 newtComponent text; 874 newtComponent type_here; 875 876 /*@ pointers **********************************************************/ 877 char *entry_value; 878 879 /*@ buffers ***********************************************************/ 880 char *blurb; 881 char *original_contents; 882 883 blurb = malloc(MAX_NEWT_COMMENT_LEN); 884 original_contents = malloc(MAX_NEWT_COMMENT_LEN); 885 assert_string_is_neither_NULL_nor_zerolength(title); 886 assert(b!=NULL); 887 assert(output!=NULL); 888 889 if (g_text_mode) 890 { 891 printf ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n--> ", title, b); 892 (void) fgets(output, maxsize, stdin); 893 if (output[strlen (output) - 1] == '\n') 894 output[strlen (output) - 1] = '\0'; 895 paranoid_free(blurb); 896 paranoid_free(original_contents); 897 return (TRUE); 898 } 899 strcpy (blurb, b); 900 text = newtTextboxReflowed (2, 1, blurb, 48, 5, 5, 0); 901 strcpy (original_contents, output); 902 output[0] = '\0'; 903 type_here = 904 newtEntry (2, newtTextboxGetNumLines (text) + 2, original_contents, 50, 814 bool popup_and_get_string(char *title, char *b, char *output, 815 int maxsize) { 816 817 /*@ newt ************************************************************ */ 818 newtComponent myForm; 819 newtComponent b_1; 820 newtComponent b_2; 821 newtComponent b_res; 822 newtComponent text; 823 newtComponent type_here; 824 825 /*@ pointers ********************************************************* */ 826 char *entry_value; 827 828 /*@ buffers ********************************************************** */ 829 char *blurb; 830 char *original_contents; 831 832 blurb = malloc(MAX_NEWT_COMMENT_LEN); 833 original_contents = malloc(MAX_NEWT_COMMENT_LEN); 834 assert_string_is_neither_NULL_nor_zerolength(title); 835 assert(b != NULL); 836 assert(output != NULL); 837 838 if (g_text_mode) { 839 printf 840 ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n--> ", 841 title, b); 842 (void) fgets(output, maxsize, stdin); 843 if (output[strlen(output) - 1] == '\n') 844 output[strlen(output) - 1] = '\0'; 845 paranoid_free(blurb); 846 paranoid_free(original_contents); 847 return (TRUE); 848 } 849 strcpy(blurb, b); 850 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 851 strcpy(original_contents, output); 852 output[0] = '\0'; 853 type_here = 854 newtEntry(2, newtTextboxGetNumLines(text) + 2, 855 original_contents, 50, 905 856 #ifdef __cplusplus 906 857 0, NEWT_FLAG_RETURNEXIT 907 858 #else 908 (void*)&entry_value, NEWT_FLAG_RETURNEXIT859 (void *) &entry_value, NEWT_FLAG_RETURNEXIT 909 860 #endif 910 ); 911 b_1 = newtButton (6, newtTextboxGetNumLines (text) + 4, " OK "); 912 b_2 = newtButton (18, newtTextboxGetNumLines (text) + 4, "Cancel"); 913 // newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title); 914 newtCenteredWindow (54, newtTextboxGetNumLines (text) + 9, title); 915 myForm = newtForm (NULL, NULL, 0); 916 newtFormAddComponents (myForm, text, type_here, b_1, b_2, NULL); 917 center_string (blurb, 80); 918 newtPushHelpLine (blurb); 919 b_res = newtRunForm (myForm); 920 strcpy (output, entry_value); 921 newtPopHelpLine (); 922 newtFormDestroy (myForm); 923 newtPopWindow (); 924 if (b_res == b_2) 925 { 926 strcpy (output, original_contents); 927 paranoid_free(blurb); 928 paranoid_free(original_contents); 929 return (FALSE); 930 } 931 else 932 { 933 paranoid_free(blurb); 934 paranoid_free(original_contents); 935 return (TRUE); 936 } 937 } 861 ); 862 b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, " OK "); 863 b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel"); 864 // newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title); 865 newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title); 866 myForm = newtForm(NULL, NULL, 0); 867 newtFormAddComponents(myForm, text, type_here, b_1, b_2, NULL); 868 center_string(blurb, 80); 869 newtPushHelpLine(blurb); 870 b_res = newtRunForm(myForm); 871 strcpy(output, entry_value); 872 newtPopHelpLine(); 873 newtFormDestroy(myForm); 874 newtPopWindow(); 875 if (b_res == b_2) { 876 strcpy(output, original_contents); 877 paranoid_free(blurb); 878 paranoid_free(original_contents); 879 return (FALSE); 880 } else { 881 paranoid_free(blurb); 882 paranoid_free(original_contents); 883 return (TRUE); 884 } 885 } 938 886 939 887 … … 945 893 * @return TRUE if @p button1 was pushed, FALSE otherwise. 946 894 */ 947 bool 948 popup_with_buttons (char *p, char *button1, char *button2) 949 { 950 951 /*@ buffers ************************************************************/ 952 char *prompt, *tmp; 953 954 /*@ newt ***************************************************************/ 955 newtComponent myForm; 956 newtComponent b_1; 957 newtComponent b_2; 958 newtComponent b_res; 959 newtComponent text; 960 961 prompt = malloc(MAX_NEWT_COMMENT_LEN); 962 tmp = malloc(MAX_NEWT_COMMENT_LEN); 963 assert_string_is_neither_NULL_nor_zerolength(p); 964 assert(button1!=NULL); 965 assert(button2!=NULL); 966 if (g_text_mode) 967 { 968 if (strlen(button2)==0) 969 { printf("%s (%s) --> ", p, button1); } 970 else 971 { printf("%s (%s or %s) --> ", p, button1, button2); } 972 for(tmp[0]='\0'; strcmp(tmp, button1) && (strlen(button2)==0 || strcmp(tmp, button2)); ) 973 { 974 printf("--> "); 975 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 976 } 977 if (!strcmp(tmp, button1)) { paranoid_free(tmp); paranoid_free(prompt); return(TRUE); } 978 else { paranoid_free(tmp); paranoid_free(prompt); return(FALSE); } 979 } 980 981 strcpy (prompt, p); 982 text = newtTextboxReflowed (1, 1, prompt, 40, 5, 5, 0); 983 b_1 = 984 newtButton (20 - 985 ((button2[0] != 986 '\0') ? strlen (button1) + 2 : strlen (button1) / 2), 987 newtTextboxGetNumLines (text) + 3, button1); 988 if (button2[0] != '\0') 989 { 990 b_2 = newtButton (24, newtTextboxGetNumLines (text) + 3, button2); 991 } 992 else 993 { 994 b_2 = NULL; 995 } 996 // newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert"); 997 newtCenteredWindow (46, newtTextboxGetNumLines (text) + 7, "Alert"); 998 myForm = newtForm (NULL, NULL, 0); 999 newtFormAddComponents (myForm, text, b_1, b_2, NULL); 1000 center_string (prompt, 80); 1001 newtPushHelpLine (prompt); 1002 b_res = newtRunForm (myForm); 1003 newtPopHelpLine (); 1004 newtFormDestroy (myForm); 1005 newtPopWindow (); 1006 if (b_res == b_1) 1007 { 1008 paranoid_free(tmp); paranoid_free(prompt); return (TRUE); 1009 } 1010 else 1011 { 1012 paranoid_free(tmp); paranoid_free(prompt); return (FALSE); 1013 } 1014 } 895 bool popup_with_buttons(char *p, char *button1, char *button2) { 896 897 /*@ buffers *********************************************************** */ 898 char *prompt, *tmp; 899 900 /*@ newt ************************************************************** */ 901 newtComponent myForm; 902 newtComponent b_1; 903 newtComponent b_2; 904 newtComponent b_res; 905 newtComponent text; 906 907 prompt = malloc(MAX_NEWT_COMMENT_LEN); 908 tmp = malloc(MAX_NEWT_COMMENT_LEN); 909 assert_string_is_neither_NULL_nor_zerolength(p); 910 assert(button1 != NULL); 911 assert(button2 != NULL); 912 if (g_text_mode) { 913 if (strlen(button2) == 0) { 914 printf("%s (%s) --> ", p, button1); 915 } else { 916 printf("%s (%s or %s) --> ", p, button1, button2); 917 } 918 for (tmp[0] = '\0'; 919 strcmp(tmp, button1) && (strlen(button2) == 0 920 || strcmp(tmp, button2));) { 921 printf("--> "); 922 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 923 } 924 if (!strcmp(tmp, button1)) { 925 paranoid_free(tmp); 926 paranoid_free(prompt); 927 return (TRUE); 928 } else { 929 paranoid_free(tmp); 930 paranoid_free(prompt); 931 return (FALSE); 932 } 933 } 934 935 strcpy(prompt, p); 936 text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0); 937 b_1 = 938 newtButton(20 - 939 ((button2[0] != 940 '\0') ? strlen(button1) + 941 2 : strlen(button1) / 2), 942 newtTextboxGetNumLines(text) + 3, button1); 943 if (button2[0] != '\0') { 944 b_2 = 945 newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 946 } else { 947 b_2 = NULL; 948 } 949 // newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert"); 950 newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, "Alert"); 951 myForm = newtForm(NULL, NULL, 0); 952 newtFormAddComponents(myForm, text, b_1, b_2, NULL); 953 center_string(prompt, 80); 954 newtPushHelpLine(prompt); 955 b_res = newtRunForm(myForm); 956 newtPopHelpLine(); 957 newtFormDestroy(myForm); 958 newtPopWindow(); 959 if (b_res == b_1) { 960 paranoid_free(tmp); 961 paranoid_free(prompt); 962 return (TRUE); 963 } else { 964 paranoid_free(tmp); 965 paranoid_free(prompt); 966 return (FALSE); 967 } 968 } 1015 969 1016 970 … … 1021 975 * on the screen. 1022 976 */ 1023 void 1024 refresh_log_screen () 1025 { 1026 1027 /*@ int ************************************************************/ 1028 int i = 0; 1029 1030 1031 if (g_text_mode || !err_log_lines) 1032 { 1033 return; 1034 } 1035 for (i = g_noof_log_lines - 1; i >= 0; i--) 1036 { 1037 newtDrawRootText (0, i + g_noof_rows - 1 - g_noof_log_lines, 1038 " "); 1039 } 1040 newtRefresh (); 1041 for (i = g_noof_log_lines - 1; i >= 0; i--) 1042 { 1043 err_log_lines[i][79] = '\0'; 1044 newtDrawRootText (0, i + g_noof_rows - 1 - g_noof_log_lines, err_log_lines[i]); 1045 } 1046 newtRefresh (); 1047 } 977 void 978 refresh_log_screen() { 979 980 /*@ int *********************************************************** */ 981 int i = 0; 982 983 984 if (g_text_mode || !err_log_lines) { 985 return; 986 } 987 for (i = g_noof_log_lines - 1; i >= 0; i--) { 988 newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines, 989 " "); 990 } 991 newtRefresh(); 992 for (i = g_noof_log_lines - 1; i >= 0; i--) { 993 err_log_lines[i][79] = '\0'; 994 newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines, 995 err_log_lines[i]); 996 } 997 newtRefresh(); 998 } 1048 999 1049 1000 … … 1052 1003 * only allocate some memory. 1053 1004 */ 1054 void 1055 setup_newt_stuff () 1056 { 1057 1058 /*@ int ************************************************************/ 1059 int i = 0; 1060 int cols; 1061 1062 if (!g_text_mode) 1063 { 1064 newtInit(); 1065 newtCls(); 1066 newtPushHelpLine 1067 ("Welcome to Mondo Rescue, by Hugo Rabson and the Internet. All rights reversed."); 1068 /* newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */ 1069 newtDrawRootText (18, 0, WELCOME_STRING); 1070 newtRefresh(); 1071 newtGetScreenSize (&cols, &g_noof_rows); 1072 g_noof_log_lines = (g_noof_rows / 5) + 1; 1073 } 1074 1075 err_log_lines = (char **) malloc (sizeof (char *) * g_noof_log_lines); 1076 if (!err_log_lines) { 1077 fatal_error ("Out of memory"); 1078 } 1079 1080 for (i = 0; i < g_noof_log_lines; i++) { 1081 err_log_lines[i] = (char *) malloc (MAX_NEWT_COMMENT_LEN); 1082 if (!err_log_lines[i]) { 1083 fatal_error ("Out of memory"); 1084 } 1085 } 1086 1087 for (i = 0; i < g_noof_log_lines; i++) 1088 { 1089 err_log_lines[i][0] = '\0'; 1090 } 1091 } 1005 void 1006 setup_newt_stuff() { 1007 1008 /*@ int *********************************************************** */ 1009 int i = 0; 1010 int cols; 1011 1012 if (!g_text_mode) { 1013 newtInit(); 1014 newtCls(); 1015 newtPushHelpLine 1016 ("Welcome to Mondo Rescue, by Hugo Rabson and the Internet. All rights reversed."); 1017 /* newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */ 1018 newtDrawRootText(18, 0, WELCOME_STRING); 1019 newtRefresh(); 1020 newtGetScreenSize(&cols, &g_noof_rows); 1021 g_noof_log_lines = (g_noof_rows / 5) + 1; 1022 } 1023 1024 err_log_lines = 1025 (char **) malloc(sizeof(char *) * g_noof_log_lines); 1026 if (!err_log_lines) { 1027 fatal_error("Out of memory"); 1028 } 1029 1030 for (i = 0; i < g_noof_log_lines; i++) { 1031 err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN); 1032 if (!err_log_lines[i]) { 1033 fatal_error("Out of memory"); 1034 } 1035 } 1036 1037 for (i = 0; i < g_noof_log_lines; i++) { 1038 err_log_lines[i][0] = '\0'; 1039 } 1040 } 1092 1041 1093 1042 … … 1097 1046 * @param denom The denomenator of the ratio. 1098 1047 */ 1099 void 1100 update_evalcall_form_ratio (int num, int denom) 1101 { 1102 1103 /*@ long *************************************************************/ 1104 long current_time = 0; 1105 long time_taken = 0; 1106 long time_total_est = 0; 1107 long time_remaining = 0; 1108 1109 /*@ buffers ***********************************************************/ 1110 char *timeline_str; 1111 char *pcline_str; 1112 char *taskprogress; 1113 1114 /*@ int ***************************************************************/ 1115 int percentage = 0; 1116 int i = 0; 1117 int j = 0; 1118 1119 malloc_string(timeline_str); 1120 malloc_string(pcline_str); 1121 malloc_string(taskprogress); 1122 timeline_str[0] = '\0'; 1048 void 1049 update_evalcall_form_ratio(int num, int denom) { 1050 1051 /*@ long ************************************************************ */ 1052 long current_time = 0; 1053 long time_taken = 0; 1054 long time_total_est = 0; 1055 long time_remaining = 0; 1056 1057 /*@ buffers ********************************************************** */ 1058 char *timeline_str; 1059 char *pcline_str; 1060 char *taskprogress; 1061 1062 /*@ int ************************************************************** */ 1063 int percentage = 0; 1064 int i = 0; 1065 int j = 0; 1066 1067 malloc_string(timeline_str); 1068 malloc_string(pcline_str); 1069 malloc_string(taskprogress); 1070 timeline_str[0] = '\0'; 1123 1071 // log_it("update_eval_call_form called"); 1124 if (num * 100 < denom) 1125 { 1126 percentage = 1; 1127 } 1128 else 1129 { 1130 percentage = (num * 100 + denom / 2) / denom ; 1131 } 1132 1133 current_time = get_time (); 1134 time_taken = current_time - g_isoform_starttime; 1135 if (num) 1136 { 1137 time_total_est = time_taken * denom / num; 1138 time_remaining = time_total_est - time_taken; 1139 } 1140 else 1141 { 1142 time_remaining = 0; 1143 } 1144 if (!g_text_mode) 1145 { 1146 newtLabelSetText (g_isoform_header, g_isoform_header_str); 1147 } 1148 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1149 if ((percentage < 3 && g_isoform_old_progress < 3) 1150 || percentage > g_isoform_old_progress) 1151 { 1152 g_isoform_old_progress = percentage; 1153 sprintf (timeline_str, 1154 "%2ld:%02ld taken %2ld:%02ld remaining", 1155 time_taken / 60, time_taken % 60, time_remaining / 60, 1156 time_remaining % 60); 1157 if (percentage < 3) 1158 { 1159 sprintf (pcline_str, " Working"); 1160 for (j = 0; j < g_mysterious_dot_counter; j++) 1161 { 1162 strcat (pcline_str, "."); 1163 } 1164 for (; j < 27; j++) 1165 { 1166 strcat (pcline_str, " "); 1167 } 1168 sprintf (pcline_str + strlen (pcline_str), " %c", 1169 special_dot_char (g_mysterious_dot_counter)); 1170 } 1171 else 1172 { 1173 sprintf (pcline_str, " %3d%% done %3d%% to go", 1174 percentage, 100 - percentage); 1175 } 1176 if (g_text_mode) 1177 { 1178 sprintf (taskprogress, "TASK: ["); 1179 for (i = 0; i < percentage; i += 5) 1180 { 1181 strcat (taskprogress, "*"); 1182 } 1183 for (; i < 100; i += 5) 1184 { 1185 strcat (taskprogress, "."); 1186 } 1187 if (percentage >= 3) 1188 { 1189 sprintf (taskprogress + strlen (taskprogress), 1190 "] %3d%% done; %2ld:%02ld to go", percentage, 1191 time_remaining / 60, time_remaining % 60); 1192 printf ("---evalcall---1--- %s\r\n", g_isoform_header_str); 1193 printf ("---evalcall---2--- %s\r\n", taskprogress); 1194 printf ("---evalcall---E---\r\n"); 1195 } 1196 } 1197 else 1198 { 1199 newtScaleSet (g_isoform_scale, (unsigned long long) percentage); 1200 newtLabelSetText (g_isoform_pcline, pcline_str); 1201 if (percentage >= 3) 1202 { 1203 newtLabelSetText (g_isoform_timeline, timeline_str); 1204 } 1205 } 1206 } 1207 if (!g_text_mode) 1208 { 1072 if (num * 100 < denom) { 1073 percentage = 1; 1074 } else { 1075 percentage = (num * 100 + denom / 2) / denom; 1076 } 1077 1078 current_time = get_time(); 1079 time_taken = current_time - g_isoform_starttime; 1080 if (num) { 1081 time_total_est = time_taken * denom / num; 1082 time_remaining = time_total_est - time_taken; 1083 } else { 1084 time_remaining = 0; 1085 } 1086 if (!g_text_mode) { 1087 newtLabelSetText(g_isoform_header, g_isoform_header_str); 1088 } 1089 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1090 if ((percentage < 3 && g_isoform_old_progress < 3) 1091 || percentage > g_isoform_old_progress) { 1092 g_isoform_old_progress = percentage; 1093 sprintf(timeline_str, 1094 "%2ld:%02ld taken %2ld:%02ld remaining", 1095 time_taken / 60, time_taken % 60, time_remaining / 60, 1096 time_remaining % 60); 1097 if (percentage < 3) { 1098 sprintf(pcline_str, " Working"); 1099 for (j = 0; j < g_mysterious_dot_counter; j++) { 1100 strcat(pcline_str, "."); 1101 } 1102 for (; j < 27; j++) { 1103 strcat(pcline_str, " "); 1104 } 1105 sprintf(pcline_str + strlen(pcline_str), " %c", 1106 special_dot_char(g_mysterious_dot_counter)); 1107 } else { 1108 sprintf(pcline_str, " %3d%% done %3d%% to go", 1109 percentage, 100 - percentage); 1110 } 1111 if (g_text_mode) { 1112 sprintf(taskprogress, "TASK: ["); 1113 for (i = 0; i < percentage; i += 5) { 1114 strcat(taskprogress, "*"); 1115 } 1116 for (; i < 100; i += 5) { 1117 strcat(taskprogress, "."); 1118 } 1119 if (percentage >= 3) { 1120 sprintf(taskprogress + strlen(taskprogress), 1121 "] %3d%% done; %2ld:%02ld to go", percentage, 1122 time_remaining / 60, time_remaining % 60); 1123 printf("---evalcall---1--- %s\r\n", 1124 g_isoform_header_str); 1125 printf("---evalcall---2--- %s\r\n", taskprogress); 1126 printf("---evalcall---E---\r\n"); 1127 } 1128 } else { 1129 newtScaleSet(g_isoform_scale, 1130 (unsigned long long) percentage); 1131 newtLabelSetText(g_isoform_pcline, pcline_str); 1132 if (percentage >= 3) { 1133 newtLabelSetText(g_isoform_timeline, timeline_str); 1134 } 1135 } 1136 } 1137 if (!g_text_mode) { 1209 1138 // log_it("refreshing"); 1210 newtRefresh();1211 1212 1213 1214 1215 }1139 newtRefresh(); 1140 } 1141 paranoid_free(timeline_str); 1142 paranoid_free(pcline_str); 1143 paranoid_free(taskprogress); 1144 } 1216 1145 1217 1146 … … 1221 1150 * @param curr The current amount of progress (percentage) in the evalcall form. 1222 1151 */ 1223 void 1224 update_evalcall_form (int curr) 1225 { 1226 update_evalcall_form_ratio (curr, 100); 1227 } 1152 void 1153 update_evalcall_form(int curr) { 1154 update_evalcall_form_ratio(curr, 100); 1155 } 1228 1156 1229 1157 … … 1234 1162 * @param blurb3 The new third line of the blurb; use @p g_blurb_str_2 (no, that's not a typo) to keep it the same. 1235 1163 */ 1236 void 1237 update_progress_form (char *blurb3) 1238 { 1239 /* log_it("update_progress_form --- called"); */ 1240 if (g_current_progress == -999) 1241 { 1242 /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */ 1243 return; 1244 } 1245 strcpy (g_blurb_str_2, blurb3); 1246 update_progress_form_full (g_blurb_str_1, g_blurb_str_2, g_blurb_str_3); 1247 } 1164 void 1165 update_progress_form(char *blurb3) { 1166 /* log_it("update_progress_form --- called"); */ 1167 if (g_current_progress == -999) { 1168 /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */ 1169 return; 1170 } 1171 strcpy(g_blurb_str_2, blurb3); 1172 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, 1173 g_blurb_str_3); 1174 } 1248 1175 1249 1176 … … 1254 1181 * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same. 1255 1182 */ 1256 void 1257 update_progress_form_full (char *blurb1, char *blurb2, char *blurb3) 1258 { 1259 /*@ long ******************************************************/ 1260 long current_time = 0; 1261 long time_taken = 0; 1262 long time_remaining = 0; 1263 long time_total_est = 0; 1264 1265 /*@ int ********************************************************/ 1266 int percentage = 0; 1267 int i = 0; 1268 1269 /*@ buffers ****************************************************/ 1270 char *percentline_str; 1271 char *timeline_str; 1272 char *taskprogress; 1273 char *tmp; 1183 void 1184 update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1185 /*@ long ***************************************************** */ 1186 long current_time = 0; 1187 long time_taken = 0; 1188 long time_remaining = 0; 1189 long time_total_est = 0; 1190 1191 /*@ int ******************************************************* */ 1192 int percentage = 0; 1193 int i = 0; 1194 1195 /*@ buffers *************************************************** */ 1196 char *percentline_str; 1197 char *timeline_str; 1198 char *taskprogress; 1199 char *tmp; 1274 1200 1275 1201 // log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3); 1276 percentline_str = malloc(MAX_NEWT_COMMENT_LEN); 1277 timeline_str = malloc(MAX_NEWT_COMMENT_LEN); 1278 taskprogress = malloc(MAX_NEWT_COMMENT_LEN); 1279 malloc_string(tmp); 1280 if (!g_text_mode) 1281 { 1282 assert(blurb1!=NULL); 1283 assert(blurb2!=NULL); 1284 assert(blurb3!=NULL); 1285 assert(g_timeline!=NULL); 1286 } 1287 1288 percentline_str[0] = '\0'; 1289 1290 current_time = get_time (); 1291 time_taken = current_time - g_start_time; 1292 if (g_maximum_progress == 0) 1293 { 1294 percentage = 0; 1295 } 1296 else 1297 { 1298 if (g_current_progress > g_maximum_progress) 1299 { 1300 sprintf (tmp, 1301 "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", 1302 blurb1, blurb2, blurb3, g_current_progress, 1303 g_maximum_progress); 1304 log_msg (0, tmp); 1305 g_current_progress = g_maximum_progress; 1306 } 1307 percentage = (int) ((g_current_progress * 100L) / g_maximum_progress); 1308 } 1309 if (percentage < 1) 1310 { 1311 percentage = 1; 1312 } 1313 if (percentage > 100) 1314 { 1315 percentage = 100; 1316 } 1317 if (g_current_progress) 1318 { 1319 time_total_est = time_taken * (long) g_maximum_progress / (long) (g_current_progress); 1320 time_remaining = time_total_est - time_taken; 1321 } 1322 else 1323 { 1324 time_remaining = 0; 1325 } 1326 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1327 sprintf (timeline_str, 1328 "%2ld:%02ld taken %2ld:%02ld remaining ", 1329 time_taken / 60, time_taken % 60, time_remaining / 60, 1330 time_remaining % 60); 1331 sprintf (percentline_str, " %3d%% done %3d%% to go", 1332 percentage, 100 - percentage); 1333 1334 if (g_text_mode) 1335 { 1336 printf("---progress-form---1--- %s\r\n", blurb1); 1337 printf("---progress-form---2--- %s\r\n", blurb2); 1338 printf("---progress-form---3--- %s\r\n", blurb3); 1339 printf("---progress-form---E---\n"); 1340 sprintf (taskprogress, "TASK: ["); 1341 for (i = 0; i < percentage; i += 5) 1342 { 1343 strcat (taskprogress, "*"); 1344 } 1345 for (; i < 100; i += 5) 1346 { 1347 strcat (taskprogress, "."); 1348 } 1349 if (percentage>100) { log_msg(2, "percentage = %d", percentage); } 1350 sprintf (taskprogress + strlen (taskprogress), 1351 "] %3d%c", percentage, '%'); 1352 sprintf (taskprogress + strlen (taskprogress), 1353 " done; %2ld:%02ld to go", 1354 time_remaining / 60, time_remaining % 60); 1355 printf("---progress-form---4--- %s\r\n", taskprogress); 1356 } 1357 else 1358 { 1359 center_string (blurb1, 54); 1360 center_string (blurb2, 54); 1361 center_string (blurb3, 54); 1362 newtLabelSetText (g_blurb1, blurb1); 1363 newtLabelSetText (g_blurb2, blurb3); 1364 newtLabelSetText (g_blurb3, blurb2); 1365 newtScaleSet (g_scale, (unsigned long long) g_current_progress); 1366 if (percentage >= 2) 1367 { 1368 newtLabelSetText (g_timeline, timeline_str); 1369 } 1370 newtLabelSetText (g_percentline, percentline_str); 1371 newtRefresh (); 1372 } 1373 paranoid_free(percentline_str); 1374 paranoid_free(timeline_str); 1375 paranoid_free(taskprogress); 1376 paranoid_free(tmp); 1377 } 1202 percentline_str = malloc(MAX_NEWT_COMMENT_LEN); 1203 timeline_str = malloc(MAX_NEWT_COMMENT_LEN); 1204 taskprogress = malloc(MAX_NEWT_COMMENT_LEN); 1205 malloc_string(tmp); 1206 if (!g_text_mode) { 1207 assert(blurb1 != NULL); 1208 assert(blurb2 != NULL); 1209 assert(blurb3 != NULL); 1210 assert(g_timeline != NULL); 1211 } 1212 1213 percentline_str[0] = '\0'; 1214 1215 current_time = get_time(); 1216 time_taken = current_time - g_start_time; 1217 if (g_maximum_progress == 0) { 1218 percentage = 0; 1219 } else { 1220 if (g_current_progress > g_maximum_progress) { 1221 sprintf(tmp, 1222 "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", 1223 blurb1, blurb2, blurb3, g_current_progress, 1224 g_maximum_progress); 1225 log_msg(0, tmp); 1226 g_current_progress = g_maximum_progress; 1227 } 1228 percentage = 1229 (int) ((g_current_progress * 100L) / g_maximum_progress); 1230 } 1231 if (percentage < 1) { 1232 percentage = 1; 1233 } 1234 if (percentage > 100) { 1235 percentage = 100; 1236 } 1237 if (g_current_progress) { 1238 time_total_est = 1239 time_taken * (long) g_maximum_progress / 1240 (long) (g_current_progress); 1241 time_remaining = time_total_est - time_taken; 1242 } else { 1243 time_remaining = 0; 1244 } 1245 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1246 sprintf(timeline_str, 1247 "%2ld:%02ld taken %2ld:%02ld remaining ", 1248 time_taken / 60, time_taken % 60, time_remaining / 60, 1249 time_remaining % 60); 1250 sprintf(percentline_str, " %3d%% done %3d%% to go", 1251 percentage, 100 - percentage); 1252 1253 if (g_text_mode) { 1254 printf("---progress-form---1--- %s\r\n", blurb1); 1255 printf("---progress-form---2--- %s\r\n", blurb2); 1256 printf("---progress-form---3--- %s\r\n", blurb3); 1257 printf("---progress-form---E---\n"); 1258 sprintf(taskprogress, "TASK: ["); 1259 for (i = 0; i < percentage; i += 5) { 1260 strcat(taskprogress, "*"); 1261 } 1262 for (; i < 100; i += 5) { 1263 strcat(taskprogress, "."); 1264 } 1265 if (percentage > 100) { 1266 log_msg(2, "percentage = %d", percentage); 1267 } 1268 sprintf(taskprogress + strlen(taskprogress), 1269 "] %3d%c", percentage, '%'); 1270 sprintf(taskprogress + strlen(taskprogress), 1271 " done; %2ld:%02ld to go", 1272 time_remaining / 60, time_remaining % 60); 1273 printf("---progress-form---4--- %s\r\n", taskprogress); 1274 } else { 1275 center_string(blurb1, 54); 1276 center_string(blurb2, 54); 1277 center_string(blurb3, 54); 1278 newtLabelSetText(g_blurb1, blurb1); 1279 newtLabelSetText(g_blurb2, blurb3); 1280 newtLabelSetText(g_blurb3, blurb2); 1281 newtScaleSet(g_scale, (unsigned long long) g_current_progress); 1282 if (percentage >= 2) { 1283 newtLabelSetText(g_timeline, timeline_str); 1284 } 1285 newtLabelSetText(g_percentline, percentline_str); 1286 newtRefresh(); 1287 } 1288 paranoid_free(percentline_str); 1289 paranoid_free(timeline_str); 1290 paranoid_free(taskprogress); 1291 paranoid_free(tmp); 1292 } 1378 1293 1379 1294 … … 1398 1313 * @return The backup type chosen, or @c none if the user chose "Exit to shell". 1399 1314 */ 1400 t_bkptype 1401 which_backup_media_type (bool restoring) 1402 { 1403 1404 /*@ char *************************************************************/ 1405 t_bkptype output; 1406 1407 1408 /*@ newt *************************************************************/ 1409 char *title_sz; 1410 char *minimsg_sz; 1411 static t_bkptype possible_bkptypes[] = { none,cdr,cdrw,dvd,tape,cdstream,udev,nfs,iso }; 1412 static char *possible_responses[] = {"none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", "nfs", "iso", NULL }; 1413 char *outstr; 1414 t_bkptype backup_type; 1415 int i; 1416 1417 newtComponent b1; 1418 newtComponent b2; 1419 newtComponent b3; 1420 newtComponent b4; 1421 newtComponent b5; 1422 newtComponent b6; 1423 newtComponent b7; 1424 newtComponent b8; 1425 newtComponent b_res; 1426 newtComponent myForm; 1427 1428 title_sz = malloc(MAX_NEWT_COMMENT_LEN); 1429 minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN); 1430 outstr = malloc(MAX_NEWT_COMMENT_LEN); 1431 if (g_text_mode) 1432 { 1433 for(backup_type = none; backup_type == none; ) 1434 { 1435 printf("Backup type ("); 1436 for(i=0; possible_responses[i]; i++) 1437 { 1438 printf("%c%s", (i==0)?'\0':' ', possible_responses[i]); 1439 } 1440 printf(")\n--> "); 1441 (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin); 1442 strip_spaces(outstr); 1443 for(i=0; possible_responses[i]; i++) 1444 { 1445 if (!strcmp(possible_responses[i], outstr)) 1446 { backup_type = possible_bkptypes[i]; } 1447 } 1448 } 1449 paranoid_free(title_sz); 1450 paranoid_free(minimsg_sz); 1451 paranoid_free(outstr); 1452 return(backup_type); 1453 } 1454 newtDrawRootText (18, 0, WELCOME_STRING); 1455 if (restoring) 1456 { 1457 strcpy(title_sz, "Please choose the backup media from which you want to read data."); 1458 strcpy(minimsg_sz, "Read from:"); 1459 } 1460 else 1461 { 1462 strcpy(title_sz, "Please choose the backup media to which you want to archive data."); 1463 strcpy(minimsg_sz, "Backup to:"); 1464 } 1465 newtPushHelpLine (title_sz); 1466 // newtOpenWindow (23, 3, 34, 17, minimsg_sz); 1467 newtCenteredWindow (34, 17, minimsg_sz); 1468 b1 = newtButton ( 1, 1, "CD-R disks "); 1469 b2 = newtButton (17, 1, "CD-RW disks"); 1470 b3 = newtButton ( 1, 9, "Tape drive "); 1471 b4 = newtButton (17, 5, "CD streamer"); 1472 b5 = newtButton ( 1, 5, " DVD disks "); 1473 b6 = newtButton (17, 9, " NFS mount "); 1474 b7 = newtButton ( 1,13, " Hard disk "); 1475 b8 = newtButton (17,13, " Exit "); 1476 myForm = newtForm (NULL, NULL, 0); 1477 newtFormAddComponents (myForm, b1, b5, b3, b7, b2, b4, b6, b8, NULL); 1478 b_res = newtRunForm (myForm); 1479 newtFormDestroy (myForm); 1480 newtPopWindow (); 1481 if (b_res == b1) { output = cdr; } 1482 else if (b_res == b2) { output = cdrw; } 1483 else if (b_res == b3) { output = tape; } 1484 else if (b_res == b4) { output = cdstream; } 1485 else if (b_res == b5) { output = dvd; } 1486 else if (b_res == b6) { output = nfs; } 1487 else if (b_res == b7) { output = iso; } 1488 else { output = none; } 1489 newtPopHelpLine (); 1490 paranoid_free(title_sz); 1491 paranoid_free(minimsg_sz); 1492 paranoid_free(outstr); 1493 return (output); 1494 } 1315 t_bkptype which_backup_media_type(bool restoring) { 1316 1317 /*@ char ************************************************************ */ 1318 t_bkptype output; 1319 1320 1321 /*@ newt ************************************************************ */ 1322 char *title_sz; 1323 char *minimsg_sz; 1324 static t_bkptype possible_bkptypes[] = 1325 { none, cdr, cdrw, dvd, tape, cdstream, udev, nfs, iso }; 1326 static char *possible_responses[] = 1327 { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", 1328 "nfs", "iso", NULL }; 1329 char *outstr; 1330 t_bkptype backup_type; 1331 int i; 1332 1333 newtComponent b1; 1334 newtComponent b2; 1335 newtComponent b3; 1336 newtComponent b4; 1337 newtComponent b5; 1338 newtComponent b6; 1339 newtComponent b7; 1340 newtComponent b8; 1341 newtComponent b_res; 1342 newtComponent myForm; 1343 1344 title_sz = malloc(MAX_NEWT_COMMENT_LEN); 1345 minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN); 1346 outstr = malloc(MAX_NEWT_COMMENT_LEN); 1347 if (g_text_mode) { 1348 for (backup_type = none; backup_type == none;) { 1349 printf("Backup type ("); 1350 for (i = 0; possible_responses[i]; i++) { 1351 printf("%c%s", (i == 0) ? '\0' : ' ', 1352 possible_responses[i]); 1353 } 1354 printf(")\n--> "); 1355 (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin); 1356 strip_spaces(outstr); 1357 for (i = 0; possible_responses[i]; i++) { 1358 if (!strcmp(possible_responses[i], outstr)) { 1359 backup_type = possible_bkptypes[i]; 1360 } 1361 } 1362 } 1363 paranoid_free(title_sz); 1364 paranoid_free(minimsg_sz); 1365 paranoid_free(outstr); 1366 return (backup_type); 1367 } 1368 newtDrawRootText(18, 0, WELCOME_STRING); 1369 if (restoring) { 1370 strcpy(title_sz, 1371 "Please choose the backup media from which you want to read data."); 1372 strcpy(minimsg_sz, "Read from:"); 1373 } else { 1374 strcpy(title_sz, 1375 "Please choose the backup media to which you want to archive data."); 1376 strcpy(minimsg_sz, "Backup to:"); 1377 } 1378 newtPushHelpLine(title_sz); 1379 // newtOpenWindow (23, 3, 34, 17, minimsg_sz); 1380 newtCenteredWindow(34, 17, minimsg_sz); 1381 b1 = newtButton(1, 1, "CD-R disks "); 1382 b2 = newtButton(17, 1, "CD-RW disks"); 1383 b3 = newtButton(1, 9, "Tape drive "); 1384 b4 = newtButton(17, 5, "CD streamer"); 1385 b5 = newtButton(1, 5, " DVD disks "); 1386 b6 = newtButton(17, 9, " NFS mount "); 1387 b7 = newtButton(1, 13, " Hard disk "); 1388 b8 = newtButton(17, 13, " Exit "); 1389 myForm = newtForm(NULL, NULL, 0); 1390 newtFormAddComponents(myForm, b1, b5, b3, b7, b2, b4, b6, b8, 1391 NULL); 1392 b_res = newtRunForm(myForm); 1393 newtFormDestroy(myForm); 1394 newtPopWindow(); 1395 if (b_res == b1) { 1396 output = cdr; 1397 } else if (b_res == b2) { 1398 output = cdrw; 1399 } else if (b_res == b3) { 1400 output = tape; 1401 } else if (b_res == b4) { 1402 output = cdstream; 1403 } else if (b_res == b5) { 1404 output = dvd; 1405 } else if (b_res == b6) { 1406 output = nfs; 1407 } else if (b_res == b7) { 1408 output = iso; 1409 } else { 1410 output = none; 1411 } 1412 newtPopHelpLine(); 1413 paranoid_free(title_sz); 1414 paranoid_free(minimsg_sz); 1415 paranoid_free(outstr); 1416 return (output); 1417 } 1495 1418 1496 1419 … … 1502 1425 * @return The compression level (0-9) chosen, or -1 for "Exit". 1503 1426 */ 1504 int 1505 which_compression_level () 1506 { 1507 1508 /*@ char *************************************************************/ 1509 int output = none; 1510 1511 1512 /*@ newt *************************************************************/ 1513 1514 newtComponent b1; 1515 newtComponent b2; 1516 newtComponent b3; 1517 newtComponent b4; 1518 newtComponent b5; 1519 newtComponent b_res; 1520 newtComponent myForm; 1521 1522 newtDrawRootText (18, 0, WELCOME_STRING); 1523 newtPushHelpLine 1524 (" Please specify the level of compression that you want."); 1525 // newtOpenWindow (23, 3, 34, 13, "How much compression?"); 1526 newtCenteredWindow (34, 13, "How much compression?"); 1527 b1 = newtButton ( 4, 1, "Maximum"); 1528 b2 = newtButton (18, 1, "Average"); 1529 b3 = newtButton ( 4, 5, "Minumum"); 1530 b4 = newtButton (18, 5, " None "); 1531 b5 = newtButton ( 4, 9, " Exit "); 1532 myForm = newtForm (NULL, NULL, 0); 1533 newtFormAddComponents (myForm, b1, b3, b2, b4, b5, NULL); 1534 b_res = newtRunForm (myForm); 1535 newtFormDestroy (myForm); 1536 newtPopWindow (); 1537 if (b_res == b1) { output = 9; } 1538 else if (b_res == b2) { output = 4; } 1539 else if (b_res == b3) { output = 1; } 1540 else if (b_res == b4) { output = 0; } 1541 else if (b_res == b5) { output = -1; } 1542 newtPopHelpLine (); 1543 return (output); 1544 } 1427 int 1428 which_compression_level() { 1429 1430 /*@ char ************************************************************ */ 1431 int output = none; 1432 1433 1434 /*@ newt ************************************************************ */ 1435 1436 newtComponent b1; 1437 newtComponent b2; 1438 newtComponent b3; 1439 newtComponent b4; 1440 newtComponent b5; 1441 newtComponent b_res; 1442 newtComponent myForm; 1443 1444 newtDrawRootText(18, 0, WELCOME_STRING); 1445 newtPushHelpLine 1446 (" Please specify the level of compression that you want."); 1447 // newtOpenWindow (23, 3, 34, 13, "How much compression?"); 1448 newtCenteredWindow(34, 13, "How much compression?"); 1449 b1 = newtButton(4, 1, "Maximum"); 1450 b2 = newtButton(18, 1, "Average"); 1451 b3 = newtButton(4, 5, "Minumum"); 1452 b4 = newtButton(18, 5, " None "); 1453 b5 = newtButton(4, 9, " Exit "); 1454 myForm = newtForm(NULL, NULL, 0); 1455 newtFormAddComponents(myForm, b1, b3, b2, b4, b5, NULL); 1456 b_res = newtRunForm(myForm); 1457 newtFormDestroy(myForm); 1458 newtPopWindow(); 1459 if (b_res == b1) { 1460 output = 9; 1461 } else if (b_res == b2) { 1462 output = 4; 1463 } else if (b_res == b3) { 1464 output = 1; 1465 } else if (b_res == b4) { 1466 output = 0; 1467 } else if (b_res == b5) { 1468 output = -1; 1469 } 1470 newtPopHelpLine(); 1471 return (output); 1472 } 1545 1473 1546 1474 … … 1554 1482 * @param source_file The file containing a list of filenames to load into @p filelist. 1555 1483 */ 1556 int load_filelist_into_array(struct s_filelist *filelist, char *source_file) 1557 { 1558 int i; 1559 bool done; 1560 char *tmp; 1561 FILE*fin; 1562 struct s_filelist_entry dummy_fle; 1563 1564 malloc_string(tmp); 1565 assert(filelist!=NULL); 1566 assert_string_is_neither_NULL_nor_zerolength(source_file); 1567 1568 iamhere("entering"); 1569 if (!(fin=fopen(source_file, "r"))) { log_OS_error(source_file); log_msg(2, "Can't open %s; therefore, cannot popup list", source_file); paranoid_free(tmp); return(1); } 1570 log_msg(2, "Loading %s", source_file); 1571 for(filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; filelist->entries++) 1572 { 1573 god_i_hate_gotos: 1574 if (feof(fin)) { break; } 1575 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin); 1576 i = (int) strlen(tmp); 1577 if (i<2) { goto god_i_hate_gotos; } 1578 if (tmp[i-1]<32) { tmp[--i]='\0'; } 1579 if (i<2) { goto god_i_hate_gotos; } 1580 if (!does_file_exist(tmp)) { goto god_i_hate_gotos; } 1581 filelist->el[filelist->entries].severity = severity_of_difference(tmp, NULL); 1582 strcpy(filelist->el[filelist->entries].filename, tmp); 1583 if (feof(fin)) { break; } 1584 } 1585 paranoid_fclose(fin); 1586 if (filelist->entries >= ARBITRARY_MAXIMUM) 1587 { 1588 log_to_screen ("Arbitrary limits suck, man!"); 1589 paranoid_free(tmp); 1590 return(1); 1591 } 1592 for(done=FALSE;!done;) 1593 { 1594 done = TRUE; 1595 for(i=0; i<filelist->entries-1; i++) 1596 { 1484 int load_filelist_into_array(struct s_filelist *filelist, 1485 char *source_file) { 1486 int i; 1487 bool done; 1488 char *tmp; 1489 FILE *fin; 1490 struct s_filelist_entry dummy_fle; 1491 1492 malloc_string(tmp); 1493 assert(filelist != NULL); 1494 assert_string_is_neither_NULL_nor_zerolength(source_file); 1495 1496 iamhere("entering"); 1497 if (!(fin = fopen(source_file, "r"))) { 1498 log_OS_error(source_file); 1499 log_msg(2, "Can't open %s; therefore, cannot popup list", 1500 source_file); 1501 paranoid_free(tmp); 1502 return (1); 1503 } 1504 log_msg(2, "Loading %s", source_file); 1505 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; 1506 filelist->entries++) { 1507 god_i_hate_gotos: 1508 if (feof(fin)) { 1509 break; 1510 } 1511 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin); 1512 i = (int) strlen(tmp); 1513 if (i < 2) { 1514 goto god_i_hate_gotos; 1515 } 1516 if (tmp[i - 1] < 32) { 1517 tmp[--i] = '\0'; 1518 } 1519 if (i < 2) { 1520 goto god_i_hate_gotos; 1521 } 1522 if (!does_file_exist(tmp)) { 1523 goto god_i_hate_gotos; 1524 } 1525 filelist->el[filelist->entries].severity = 1526 severity_of_difference(tmp, NULL); 1527 strcpy(filelist->el[filelist->entries].filename, tmp); 1528 if (feof(fin)) { 1529 break; 1530 } 1531 } 1532 paranoid_fclose(fin); 1533 if (filelist->entries >= ARBITRARY_MAXIMUM) { 1534 log_to_screen("Arbitrary limits suck, man!"); 1535 paranoid_free(tmp); 1536 return (1); 1537 } 1538 for (done = FALSE; !done;) { 1539 done = TRUE; 1540 for (i = 0; i < filelist->entries - 1; i++) { 1597 1541 // if (strcmp(filelist->el[i].filename, filelist->el[i+1].filename) > 0) 1598 if (filelist->el[i].severity < filelist->el[i+1].severity || (filelist->el[i].severity==filelist->el[i+1].severity && strcmp(filelist->el[i].filename, filelist->el[i+1].filename)>0)) 1599 { 1600 memcpy((void*)&dummy_fle, (void*)&(filelist->el[i]), sizeof(struct s_filelist_entry)); 1601 memcpy((void*)&(filelist->el[i]), (void*)&(filelist->el[i+1]), sizeof(struct s_filelist_entry)); 1602 memcpy((void*)&(filelist->el[i+1]), (void*)&dummy_fle, sizeof(struct s_filelist_entry)); 1603 log_msg(2, "Swapping %s and %s", filelist->el[i].filename, filelist->el[i+1].filename); 1604 done = FALSE; 1605 } 1606 } 1607 } 1608 paranoid_free(tmp); 1609 iamhere("leaving"); 1610 return(0); 1611 } 1542 if (filelist->el[i].severity < filelist->el[i + 1].severity 1543 || (filelist->el[i].severity == 1544 filelist->el[i + 1].severity 1545 && strcmp(filelist->el[i].filename, 1546 filelist->el[i + 1].filename) > 0)) { 1547 memcpy((void *) &dummy_fle, 1548 (void *) &(filelist->el[i]), 1549 sizeof(struct s_filelist_entry)); 1550 memcpy((void *) &(filelist->el[i]), 1551 (void *) &(filelist->el[i + 1]), 1552 sizeof(struct s_filelist_entry)); 1553 memcpy((void *) &(filelist->el[i + 1]), 1554 (void *) &dummy_fle, 1555 sizeof(struct s_filelist_entry)); 1556 log_msg(2, "Swapping %s and %s", 1557 filelist->el[i].filename, 1558 filelist->el[i + 1].filename); 1559 done = FALSE; 1560 } 1561 } 1562 } 1563 paranoid_free(tmp); 1564 iamhere("leaving"); 1565 return (0); 1566 } 1612 1567 1613 1568 … … 1619 1574 * @note The returned value points to static storage that will be overwritten with each call. 1620 1575 */ 1621 char*filelist_entry_to_string(struct s_filelist_entry *flentry) 1622 { 1623 static char comment[100]; 1624 char *tmp; 1625 1626 iamhere("entering"); 1627 malloc_string(tmp); 1628 assert(flentry!=NULL); 1629 if (flentry->severity==0) { strcpy(tmp, "0 "); } 1630 else if (flentry->severity==1) { strcpy(tmp, "low "); } 1631 else if (flentry->severity==2) { strcpy(tmp, "med "); } 1632 else { strcpy(tmp, "high"); } 1633 strcat(tmp, " "); 1634 strncat(tmp, flentry->filename, 100); 1635 tmp[98] = '\0'; 1636 strcpy(comment, tmp); 1637 paranoid_free(tmp); 1638 iamhere("leaving"); 1639 return(comment); 1640 } 1576 char *filelist_entry_to_string(struct s_filelist_entry *flentry) { 1577 static char comment[100]; 1578 char *tmp; 1579 1580 iamhere("entering"); 1581 malloc_string(tmp); 1582 assert(flentry != NULL); 1583 if (flentry->severity == 0) { 1584 strcpy(tmp, "0 "); 1585 } else if (flentry->severity == 1) { 1586 strcpy(tmp, "low "); 1587 } else if (flentry->severity == 2) { 1588 strcpy(tmp, "med "); 1589 } else { 1590 strcpy(tmp, "high"); 1591 } 1592 strcat(tmp, " "); 1593 strncat(tmp, flentry->filename, 100); 1594 tmp[98] = '\0'; 1595 strcpy(comment, tmp); 1596 paranoid_free(tmp); 1597 iamhere("leaving"); 1598 return (comment); 1599 } 1641 1600 1642 1601 … … 1649 1608 * @param source_file The file containing a list of changed files. 1650 1609 */ 1651 void popup_changelist_from_file(char*source_file) 1652 { 1653 char *reason; 1654 newtComponent myForm; 1655 newtComponent bClose; 1656 newtComponent bSelect; 1657 newtComponent b_res; 1658 newtComponent fileListbox; 1659 newtComponent headerMsg; 1660 1661 /*@ ???? *************************************************************/ 1662 void *curr_choice; 1663 void *keylist[ARBITRARY_MAXIMUM]; 1664 1665 /*@ int **************************************************************/ 1666 int i = 0; 1667 int currline = 0; 1668 int finished = FALSE; 1669 long lng = 0; 1670 1671 /*@ buffers **********************************************************/ 1672 char *tmp; 1673 char *differ_sz; 1674 1675 struct s_filelist *filelist; 1676 malloc_string(reason); 1677 tmp = malloc(5000); 1678 malloc_string(differ_sz); 1679 assert_string_is_neither_NULL_nor_zerolength(source_file); 1680 if (g_text_mode) 1681 { 1682 log_msg(2, "Text mode. Therefore, no popup list."); 1683 goto free_to_go; 1684 } 1685 log_msg (2, "Examining file %s", source_file); 1686 1687 lng = count_lines_in_file(source_file); 1688 if (lng < 1) 1689 { 1690 log_msg (2, "No lines in file. Therefore, no popup list."); paranoid_free(reason); 1691 goto free_to_go; 1692 } 1693 else if (lng >= ARBITRARY_MAXIMUM) 1694 { 1695 log_msg(2, "Too many files differ for me to list."); 1696 goto free_to_go; 1697 } 1698 1699 filelist = (struct s_filelist*)malloc(sizeof(struct s_filelist)); 1700 fileListbox = 1701 newtListbox (2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1702 newtListboxClear (fileListbox); 1703 1704 if (load_filelist_into_array(filelist, source_file)) { log_msg (2, "Can't open %s; therefore, cannot popup list", source_file); paranoid_free(reason); return; } 1705 log_msg(2, "%d files loaded into filelist array", filelist->entries); 1706 for(i=0; i<filelist->entries; i++) 1707 { 1708 keylist[i] = (void *) i; 1709 newtListboxAppendEntry (fileListbox, filelist_entry_to_string(&(filelist->el[i])), keylist[i]); 1710 } 1711 sprintf(differ_sz, " %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", i); 1712 newtPushHelpLine(differ_sz); 1713 bClose = newtCompactButton (10, 15, " Close "); 1714 bSelect = newtCompactButton (30, 15, " Select "); 1715 sprintf (tmp, "%-10s %-20s", "Priority", "Filename"); 1716 headerMsg = newtLabel (2, 1, tmp); 1717 newtOpenWindow (5, 4, 70, 16, "Non-matching files"); 1718 myForm = newtForm (NULL, NULL, 0); 1719 newtFormAddComponents (myForm, headerMsg, fileListbox, bClose, bSelect, NULL); 1720 while (!finished) 1721 { 1722 b_res = newtRunForm (myForm); 1723 if (b_res == bClose) 1724 { 1725 finished = TRUE; 1726 } 1727 else 1728 { 1729 curr_choice = newtListboxGetCurrent (fileListbox); 1730 for (i = 0; i < filelist->entries && keylist[i] != curr_choice; 1731 i++); 1732 if (i == filelist->entries && filelist->entries > 0) 1733 { 1734 log_to_screen ("I don't know what that button does!"); 1735 } 1736 else 1737 { 1738 currline = i; 1739 if (filelist->entries > 0) 1740 { 1741 severity_of_difference(filelist->el[currline].filename, reason); 1742 sprintf(tmp, "%s --- %s", filelist->el[currline].filename, reason); 1743 popup_and_OK(tmp); 1744 } 1745 } 1746 } 1747 } 1748 newtFormDestroy (myForm); 1749 newtPopWindow (); 1750 newtPopHelpLine (); 1751 free_to_go: 1752 paranoid_free(reason); 1753 paranoid_free(tmp); 1754 paranoid_free(differ_sz); 1755 return; 1756 } 1610 void popup_changelist_from_file(char *source_file) { 1611 char *reason; 1612 newtComponent myForm; 1613 newtComponent bClose; 1614 newtComponent bSelect; 1615 newtComponent b_res; 1616 newtComponent fileListbox; 1617 newtComponent headerMsg; 1618 1619 /*@ ???? ************************************************************ */ 1620 void *curr_choice; 1621 void *keylist[ARBITRARY_MAXIMUM]; 1622 1623 /*@ int ************************************************************* */ 1624 int i = 0; 1625 int currline = 0; 1626 int finished = FALSE; 1627 long lng = 0; 1628 1629 /*@ buffers ********************************************************* */ 1630 char *tmp; 1631 char *differ_sz; 1632 1633 struct s_filelist *filelist; 1634 malloc_string(reason); 1635 tmp = malloc(5000); 1636 malloc_string(differ_sz); 1637 assert_string_is_neither_NULL_nor_zerolength(source_file); 1638 if (g_text_mode) { 1639 log_msg(2, "Text mode. Therefore, no popup list."); 1640 goto free_to_go; 1641 } 1642 log_msg(2, "Examining file %s", source_file); 1643 1644 lng = count_lines_in_file(source_file); 1645 if (lng < 1) { 1646 log_msg(2, "No lines in file. Therefore, no popup list."); 1647 paranoid_free(reason); 1648 goto free_to_go; 1649 } else if (lng >= ARBITRARY_MAXIMUM) { 1650 log_msg(2, "Too many files differ for me to list."); 1651 goto free_to_go; 1652 } 1653 1654 filelist = (struct s_filelist *) malloc(sizeof(struct s_filelist)); 1655 fileListbox = 1656 newtListbox(2, 2, 12, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1657 newtListboxClear(fileListbox); 1658 1659 if (load_filelist_into_array(filelist, source_file)) { 1660 log_msg(2, "Can't open %s; therefore, cannot popup list", 1661 source_file); 1662 paranoid_free(reason); 1663 return; 1664 } 1665 log_msg(2, "%d files loaded into filelist array", 1666 filelist->entries); 1667 for (i = 0; i < filelist->entries; i++) { 1668 keylist[i] = (void *) i; 1669 newtListboxAppendEntry(fileListbox, 1670 filelist_entry_to_string(& 1671 (filelist-> 1672 el[i])), 1673 keylist[i]); 1674 } 1675 sprintf(differ_sz, 1676 " %d files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", 1677 i); 1678 newtPushHelpLine(differ_sz); 1679 bClose = newtCompactButton(10, 15, " Close "); 1680 bSelect = newtCompactButton(30, 15, " Select "); 1681 sprintf(tmp, "%-10s %-20s", "Priority", "Filename"); 1682 headerMsg = newtLabel(2, 1, tmp); 1683 newtOpenWindow(5, 4, 70, 16, "Non-matching files"); 1684 myForm = newtForm(NULL, NULL, 0); 1685 newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, 1686 bSelect, NULL); 1687 while (!finished) { 1688 b_res = newtRunForm(myForm); 1689 if (b_res == bClose) { 1690 finished = TRUE; 1691 } else { 1692 curr_choice = newtListboxGetCurrent(fileListbox); 1693 for (i = 0; 1694 i < filelist->entries && keylist[i] != curr_choice; 1695 i++); 1696 if (i == filelist->entries && filelist->entries > 0) { 1697 log_to_screen("I don't know what that button does!"); 1698 } else { 1699 currline = i; 1700 if (filelist->entries > 0) { 1701 severity_of_difference(filelist->el[currline]. 1702 filename, reason); 1703 sprintf(tmp, "%s --- %s", 1704 filelist->el[currline].filename, reason); 1705 popup_and_OK(tmp); 1706 } 1707 } 1708 } 1709 } 1710 newtFormDestroy(myForm); 1711 newtPopWindow(); 1712 newtPopHelpLine(); 1713 free_to_go: 1714 paranoid_free(reason); 1715 paranoid_free(tmp); 1716 paranoid_free(differ_sz); 1717 return; 1718 } 1757 1719 1758 1720 /* @} - end of guiGroup */ … … 1760 1722 1761 1723 #if __cplusplus 1762 } 1724 } /* extern "C" */ 1763 1725 #endif 1764 1726 1765 1727 1766 void wait_until_software_raids_are_prepped(char *mdstat_file, int wait_for_percentage);1767 1728 void wait_until_software_raids_are_prepped(char *mdstat_file, 1729 int wait_for_percentage);
Note:
See TracChangeset
for help on using the changeset viewer.