<commit_before>/* Stopgap, until Paul does the right thing */
#define ESC 27
#define TAB 9

#include <stdlib.h>
#include <limits.h>
#include <sys/types.h>
#include <string.h>

#include <string.h>
#include <dialog.h>
#include "sysinstall.h"

int
edit_line(WINDOW *window, int y, int x, char *field, int width, int maxlen)
{
	int len;
	int key = 0;
	int fpos, dispos, curpos;
	int i;
	int done = 0;

	len = strlen(field);
	if (len < width) {
		fpos = len;
		curpos = len;
		dispos = 0;
	} else {
		fpos = width;
		curpos = width;
		dispos = len - width;
	};


	do {
		wattrset(window, item_selected_attr);
		wmove(window, y, x);
		for (i=0; i < width; i++)
			if (i < (len - dispos))
				waddch(window, field[dispos+i]);
			else
				waddch(window, ' ');
		wmove(window, y, x + curpos);
		wrefresh(window);

		key = wgetch(window);
		switch (key) {
			case TAB:
			case KEY_BTAB:
			case KEY_UP:
			case KEY_DOWN:
			case ESC:
			case '\n':
			case '\r':
				done = 1;
				break;
			case KEY_HOME:
				if (len < width) {
					fpos = len;
					curpos = len;
					dispos = 0;
				} else {
					fpos = width;
					curpos = width;
					dispos = len - width;
				};
				break;
			case KEY_END:
				if (len < width) {
					dispos = 0;
					curpos = len - 1;
				} else {
					dispos = len - width - 1;
					curpos = width - 1;
				}
				fpos = len - 1;
				break;
			case KEY_LEFT:
				if ((!curpos) && (!dispos)) {
					beep();
					break;
				}
				if (--curpos < 0) {
					curpos = 0;
					if (--dispos < 0)
						dispos = 0;
				}
				if (--fpos < 0)
					fpos = 0;
				break;
			case KEY_RIGHT:
				if ((curpos + dispos) == len) {
					beep();
					break;
				}
				if ((curpos == (width-1)) && (dispos == (maxlen - width -1))) {
					beep();
					break;
				}
				if (++curpos >= width) {
					curpos = width - 1;
					dispos++;
				}
				if (dispos >= len)
					dispos = len - 1;
				if (++fpos >= len) {
					fpos = len;
				}
				break;
			case KEY_BACKSPACE:
			case KEY_DC:
				if ((!curpos) && (!dispos)) {
					beep();
					break;
				}
				if (fpos > 0) {
					memmove(field+fpos-1, field+fpos, len - fpos);
					len--;
					fpos--;
					if (curpos > 0)
						--curpos;
					if (!curpos)
						--dispos;
					if (dispos < 0)
						dispos = 0;
				} else
					beep();
				break;
			default:
				if (len < maxlen - 1) {
					memmove(field+fpos+1, field+fpos, len - fpos);
					field[fpos] = key;
					len++;
					fpos++;
					if (++curpos == width) {
						--curpos;
						dispos++;
					}
					if (len == (maxlen - 1)) {
						dispos = (maxlen - width - 1);
					}
				} else
					beep();
				break;
		}
	} while (!done);
	wattrset(window, dialog_attr);
	wmove(window, y, x);
	for (i=0; i < width; i++)
		if (i < (len - dispos))
			waddch(window, field[dispos+i]);
		else
			waddch(window, ' ');
	wmove(window, y, x + curpos);
	wstandend(window);
	field[len] = 0;
	wrefresh(window);
	return (key);
}

int
AskEm(WINDOW *w,char *prompt, char *answer, int len)
{
    int x,y;
    mvwprintw(w,23,0,prompt);
    getyx(w,y,x);
    addstr("                             ");
    return edit_line(w,y,x,answer,len,len+1);
}

void
ShowFile(char *filename, char *header)
{
    char buf[256];
    if (access(filename, R_OK)) {
	sprintf(buf, "Odd, I thought I had a file called %s around here somewhere,\nbut I can't seem to find it now that I need it.  Sorry about that!", filename);
	dialog_msgbox("Sorry!", buf, 6, 75, 1);
	return;
    }
    dialog_clear();
    sprintf(buf, "/stand/gzip -c -d %s", filename);
    dialog_prgbox(header, buf, LINES-1, COLS, TRUE, TRUE);
    dialog_clear();
}<commit_msg>Don't use a shell, silly, we don't have one!<commit_after>/* Stopgap, until Paul does the right thing */
#define ESC 27
#define TAB 9

#include <stdlib.h>
#include <limits.h>
#include <sys/types.h>
#include <string.h>

#include <string.h>
#include <dialog.h>
#include "sysinstall.h"

int
edit_line(WINDOW *window, int y, int x, char *field, int width, int maxlen)
{
	int len;
	int key = 0;
	int fpos, dispos, curpos;
	int i;
	int done = 0;

	len = strlen(field);
	if (len < width) {
		fpos = len;
		curpos = len;
		dispos = 0;
	} else {
		fpos = width;
		curpos = width;
		dispos = len - width;
	};


	do {
		wattrset(window, item_selected_attr);
		wmove(window, y, x);
		for (i=0; i < width; i++)
			if (i < (len - dispos))
				waddch(window, field[dispos+i]);
			else
				waddch(window, ' ');
		wmove(window, y, x + curpos);
		wrefresh(window);

		key = wgetch(window);
		switch (key) {
			case TAB:
			case KEY_BTAB:
			case KEY_UP:
			case KEY_DOWN:
			case ESC:
			case '\n':
			case '\r':
				done = 1;
				break;
			case KEY_HOME:
				if (len < width) {
					fpos = len;
					curpos = len;
					dispos = 0;
				} else {
					fpos = width;
					curpos = width;
					dispos = len - width;
				};
				break;
			case KEY_END:
				if (len < width) {
					dispos = 0;
					curpos = len - 1;
				} else {
					dispos = len - width - 1;
					curpos = width - 1;
				}
				fpos = len - 1;
				break;
			case KEY_LEFT:
				if ((!curpos) && (!dispos)) {
					beep();
					break;
				}
				if (--curpos < 0) {
					curpos = 0;
					if (--dispos < 0)
						dispos = 0;
				}
				if (--fpos < 0)
					fpos = 0;
				break;
			case KEY_RIGHT:
				if ((curpos + dispos) == len) {
					beep();
					break;
				}
				if ((curpos == (width-1)) && (dispos == (maxlen - width -1))) {
					beep();
					break;
				}
				if (++curpos >= width) {
					curpos = width - 1;
					dispos++;
				}
				if (dispos >= len)
					dispos = len - 1;
				if (++fpos >= len) {
					fpos = len;
				}
				break;
			case KEY_BACKSPACE:
			case KEY_DC:
				if ((!curpos) && (!dispos)) {
					beep();
					break;
				}
				if (fpos > 0) {
					memmove(field+fpos-1, field+fpos, len - fpos);
					len--;
					fpos--;
					if (curpos > 0)
						--curpos;
					if (!curpos)
						--dispos;
					if (dispos < 0)
						dispos = 0;
				} else
					beep();
				break;
			default:
				if (len < maxlen - 1) {
					memmove(field+fpos+1, field+fpos, len - fpos);
					field[fpos] = key;
					len++;
					fpos++;
					if (++curpos == width) {
						--curpos;
						dispos++;
					}
					if (len == (maxlen - 1)) {
						dispos = (maxlen - width - 1);
					}
				} else
					beep();
				break;
		}
	} while (!done);
	wattrset(window, dialog_attr);
	wmove(window, y, x);
	for (i=0; i < width; i++)
		if (i < (len - dispos))
			waddch(window, field[dispos+i]);
		else
			waddch(window, ' ');
	wmove(window, y, x + curpos);
	wstandend(window);
	field[len] = 0;
	wrefresh(window);
	return (key);
}

int
AskEm(WINDOW *w,char *prompt, char *answer, int len)
{
    int x,y;
    mvwprintw(w,23,0,prompt);
    getyx(w,y,x);
    addstr("                             ");
    return edit_line(w,y,x,answer,len,len+1);
}

void
ShowFile(char *filename, char *header)
{
    char buf[256];
    if (access(filename, R_OK)) {
	sprintf(buf, "Odd, I thought I had a file called %s around here somewhere,\nbut I can't seem to find it now that I need it.  Sorry about that!", filename);
	dialog_msgbox("Sorry!", buf, 6, 75, 1);
	return;
    }
    dialog_clear();
    sprintf(buf, "/stand/gzip -c -d %s", filename);
    dialog_prgbox(header, buf, LINES-1, COLS, TRUE, FALSE);
    dialog_clear();
}
{'fraction_non_alphanumeric': 0.16602049293824425, 'fraction_numerical': 0.013015785101080033, 'mean_word_length': 2.103996562097121, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 25, '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': '2856020', 'n_tokens_mistral': 3706, 'n_tokens_neox': 2878, 'n_words': 778}