<commit_before>/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <<EMAIL>> wrote this file.  As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return.   <NAME>
 * ----------------------------------------------------------------------------
 *
 * $Id: utils.c,v 1.6 1994/10/21 04:43:07 ache Exp $
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <dialog.h>
#include <errno.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/reboot.h>

#include "sysinstall.h"

void
TellEm(char *fmt, ...)
{
	char *p;
	va_list ap;
	p = Malloc(2048);
	va_start(ap,fmt);
	vsnprintf(p, 2048, fmt, ap);
	va_end(ap);
	dialog_msgbox("Progress", p, 3, 75, 0);
	dialog_clear();
	free(p);
}

void
Fatal(char *fmt, ...)
{
	char *p;
	va_list ap;
	p = Malloc(2048);
	va_start(ap,fmt);
	vsnprintf(p, 2048, fmt, ap);
	va_end(ap);
	if (dialog_active) {
		dialog_msgbox("Fatal", p, 12, 75, 1);
		end_dialog();
	} else
		fprintf(stderr, "Fatal -- %s", p);
	free(p);
	ExitSysinstall();
}

void
AskAbort(char *fmt, ...)
{
	char *p;
	va_list ap;

	p = Malloc(2048);
	va_start(ap,fmt);
	vsnprintf(p, 2048, fmt, ap);
	va_end(ap);
	strcat(p, "\n\nDo you wish to abort the installation?");
	if (!dialog_yesno("Abort", p, 15, 60)) {
		dialog_clear();
		Abort();
	}
	dialog_clear();
	free(p);
}

void
Abort()
{
	if (dialog_yesno("Exit sysinstall","\n\nAre you sure you want to quit?",
						  10, 40)) {
		dialog_clear();
		return;
	}
	ExitSysinstall();
}

void
ExitSysinstall()
{
	if (getpid() == 1) {
		clear();
		if (reboot(RB_AUTOBOOT) == -1)
			if (dialog_active) {
				dialog_clear();
				dialog_msgbox(TITLE, "\n\nCan't reboot machine -- hit reset button",
						  5,30,0);
			} else
				fprintf(stderr, "Can't reboot the machine -- hit the reset button");
			while(1);
	} else
		clear();
		refresh();
		end_dialog();
		exit(0);
}

void *
Malloc(size_t size)
{
	void *p = malloc(size);
	if (!p) {
		exit(7); /* XXX longjmp bad */
	}
	return p;
}

char *
StrAlloc(char *str) 
{
	char *p;

	p = (char *)Malloc(strlen(str) + 1);
	strcpy(p,str);
	return p;
}

void
MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir)
{
	struct ufs_args ufsargs;
	char dbuf[90];
	char pbuf[90];

	memset(&ufsargs,0,sizeof ufsargs);<commit_msg>ExitSysinstall() fixed: use dialog functions properly. don't clear screen with last message on exit(0), I want to see it still. relay on dialog_active properly.<commit_after>/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <<EMAIL>> wrote this file.  As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return.   <NAME>
 * ----------------------------------------------------------------------------
 *
 * $Id: utils.c,v 1.7 1994/10/21 18:08:33 paul Exp $
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <dialog.h>
#include <errno.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/reboot.h>

#include "sysinstall.h"

void
TellEm(char *fmt, ...)
{
	char *p;
	va_list ap;
	p = Malloc(2048);
	va_start(ap,fmt);
	vsnprintf(p, 2048, fmt, ap);
	va_end(ap);
	dialog_msgbox("Progress", p, 3, 75, 0);
	dialog_clear();
	free(p);
}

void
Fatal(char *fmt, ...)
{
	char *p;
	va_list ap;
	p = Malloc(2048);
	va_start(ap,fmt);
	vsnprintf(p, 2048, fmt, ap);
	va_end(ap);
	if (dialog_active) {
		dialog_msgbox("Fatal", p, 12, 75, 1);
		end_dialog();
	} else
		fprintf(stderr, "Fatal -- %s", p);
	free(p);
	ExitSysinstall();
}

void
AskAbort(char *fmt, ...)
{
	char *p;
	va_list ap;

	p = Malloc(2048);
	va_start(ap,fmt);
	vsnprintf(p, 2048, fmt, ap);
	va_end(ap);
	strcat(p, "\n\nDo you wish to abort the installation?");
	if (!dialog_yesno("Abort", p, 15, 60)) {
		dialog_clear();
		Abort();
	}
	dialog_clear();
	free(p);
}

void
Abort()
{
	if (dialog_yesno("Exit sysinstall","\n\nAre you sure you want to quit?",
						  10, 40)) {
		dialog_clear();
		return;
	}
	ExitSysinstall();
}

void
ExitSysinstall()
{
	if (getpid() == 1) {
		if (dialog_active) {
		clear();
			dialog_update();
		}
		if (reboot(RB_AUTOBOOT) == -1)
			if (dialog_active) {
				clear();
				dialog_msgbox(TITLE, "\n\nCan't reboot machine -- hit reset button",
						  5,30,0);
			} else
				fprintf(stderr, "Can't reboot the machine -- hit the reset button");
			while(1);
	} else {
		if (dialog_active) {
			dialog_update();
		end_dialog();
		}
		exit(0);
	}
}

void *
Malloc(size_t size)
{
	void *p = malloc(size);
	if (!p) {
		exit(7); /* XXX longjmp bad */
	}
	return p;
}

char *
StrAlloc(char *str) 
{
	char *p;

	p = (char *)Malloc(strlen(str) + 1);
	strcpy(p,str);
	return p;
}

void
MountUfs(char *device, char *prefix, char *mountpoint, int do_mkdir)
{
	struct ufs_args ufsargs;
	char dbuf[90];
	char pbuf[90];

	memset(&ufsargs,0,sizeof ufsargs);
{'fraction_non_alphanumeric': 0.22469368520263902, 'fraction_numerical': 0.028086710650329878, 'mean_word_length': 2.844927536231884, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3707738', 'n_tokens_mistral': 2313, 'n_tokens_neox': 2094, 'n_words': 552}