#include "openaxiom-c-macros.h"
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include "edible.h"
#include "prt.h"
#include "edin.h"
void
myputchar(char c)
{
if (ECHOIT)
putchar(c);
return;
}
void
clear_buff(void)
{
int count;
if (buff_pntr > 0) {
for (count = curr_pntr; count > 0; count--)
myputchar(_BKSPC);
for (count = 0; count < buff_pntr; count++) {
myputchar(_BLANK);
}
for (count = buff_pntr; count > 0; count--)
myputchar(_BKSPC);
init_buff(buff, buff_pntr);
init_flag(buff_flag, buff_pntr);
curr_pntr = buff_pntr = 0;
}
}
void
move_end(void)
{
if (curr_pntr == buff_pntr) {
putchar(_BELL);
}
else {
for (; curr_pntr < buff_pntr;) {
myputchar(buff[curr_pntr++]);
}
}
fflush(stdout);
}
void
move_home(void)
{
if (curr_pntr > 0) {
for (; curr_pntr > 0;) {
myputchar(_BKSPC);
curr_pntr--;
}
}
else {
putchar(_BELL);
}
fflush(stdout);
}
void
move_fore_word(void)
{
if (curr_pntr != buff_pntr) {
myputchar(buff[curr_pntr]);
curr_pntr++;
while (curr_pntr < buff_pntr && buff[curr_pntr] != ' ') {
myputchar(buff[curr_pntr]);
curr_pntr++;
}
}
else
putchar(_BELL);
fflush(stdout);
return;
}
void
move_back_word(void)
{
if (curr_pntr > 0) {
myputchar(_BKSPC);
curr_pntr--;
while (curr_pntr > 0 && buff[curr_pntr - 1] != ' ') {
myputchar(_BKSPC);
curr_pntr--;
}
}
else
putchar(_BELL);
fflush(stdout);
return;
}
void
delete_current_char(void)
{
if (curr_pntr != buff_pntr) {
if (buff_flag[curr_pntr] == 1 || buff_flag[curr_pntr] == 0) {
myputchar(_BLANK);
myputchar(_BKSPC);
strcpy(&buff[curr_pntr],
&buff[curr_pntr + 1]);
flagcpy(&buff_flag[curr_pntr],
&buff_flag[curr_pntr + 1]);
buff_pntr--;
del_print(curr_pntr, 1);
}
else {
myputchar(_BLANK);
myputchar(_BLANK);
myputchar(_BKSPC);
myputchar(_BKSPC);
strcpy(&buff[curr_pntr],
&buff[curr_pntr + 2]);
flagcpy(&buff_flag[curr_pntr],
&buff_flag[curr_pntr + 2]);
buff_pntr -= 2;
del_print(curr_pntr, 2);
}
}
else {
putchar(_BELL);
fflush(stdout);
}
num_proc = num_proc + 3;
}
void
delete_to_end_of_line(void)
{
int count;
if (curr_pntr == buff_pntr)
return;
for (count = curr_pntr; count < buff_pntr; count++) {
myputchar(_BLANK);
}
for (count = buff_pntr; count > curr_pntr; count--)
myputchar(_BKSPC);
buff_pntr = curr_pntr;
fflush(stdout);
return;
}
void
delete_line(void)
{
int count;
if (buff_pntr == 0)
return;
for (count = curr_pntr; count > 0; count--)
myputchar(_BKSPC);
for (count = 0; count < buff_pntr; count++) {
myputchar(_BLANK);
}
for (count = buff_pntr; count > 0; count--)
myputchar(_BKSPC);
init_buff(buff, buff_pntr);
init_flag(buff_flag, buff_pntr);
buff_pntr = curr_pntr = 0;
fflush(stdout);
return;
}
void
printbuff(int start,int num)
{
int trace;
for (trace = start; trace < start + num; trace++)
if (buff[trace] != '\0')
myputchar(buff[trace]);
fflush(stdout);
}
void
del_print(int start, int num)
{
int count;
for (count = start; count < buff_pntr; count++) {
myputchar(buff[count]);
}
for (count = 0; count < num; count++)
myputchar(_BLANK);
for (count = buff_pntr + num; count > start; count--)
myputchar(_BKSPC);
fflush(stdout);
}
void
ins_print(int start,int num)
{
int count;
for (count = start; count < buff_pntr + num; count++) {
myputchar(buff[count]);
}
for (count = buff_pntr; count > start; count--)
myputchar(_BKSPC);
fflush(stdout);
}
void
reprint(int start)
{
if (buff[start] == '\0')
myputchar(_BLANK);
else
myputchar(buff[start]);
myputchar(_BKSPC);
fflush(stdout);
return;
}
void
back_up(int num_chars)
{
int cnt;
for (cnt = 0; cnt < num_chars; cnt++)
myputchar(_BKSPC);
for (cnt = 0; cnt < num_chars; cnt++)
myputchar(_BLANK);
for (cnt = 0; cnt < num_chars; cnt++)
myputchar(_BKSPC);
fflush(stdout);
}
void
back_it_up(int num_chars)
{
int cnt;
for (cnt = 0; cnt < num_chars; cnt++)
myputchar(_BKSPC);
fflush(stdout);
}
void
print_whole_buff(void)
{
int trace;
for (trace = 0; trace < buff_pntr; trace++)
if (buff[trace] != '\0')
myputchar(buff[trace]);
fflush(stdout);
}
void
move_ahead(void)
{
if (curr_pntr == buff_pntr) {
putchar(_BELL);
}
else {
if (buff_flag[curr_pntr] == 2) {
myputchar(buff[curr_pntr++]);
}
myputchar(buff[curr_pntr++]);
}
fflush(stdout);
}
void
move_back(void)
{
if (curr_pntr == 0) {
putchar(_BELL);
}
else {
if (!buff_flag[curr_pntr - 1]) {
myputchar(_BKSPC);
curr_pntr--;
}
myputchar(_BKSPC);
curr_pntr--;
}
fflush(stdout);
}
void
back_over_current_char(void)
{
if (curr_pntr == 0) {
putchar(_BELL);
}
else {
if (!buff_flag[curr_pntr - 1]) {
myputchar(_BKSPC);
myputchar(_BKSPC);
myputchar(_BLANK);
myputchar(_BLANK);
myputchar(_BKSPC);
myputchar(_BKSPC);
strcpy(&buff[curr_pntr - 2],
&buff[curr_pntr]);
flagcpy(&buff_flag[curr_pntr - 2],
&buff_flag[curr_pntr]);
buff_pntr -= 2;
curr_pntr -= 2;
del_print(curr_pntr, 2);
}
else {
myputchar(_BKSPC);
myputchar(_BLANK);
myputchar(_BKSPC);
strcpy(&buff[curr_pntr - 1],
&buff[curr_pntr]);
flagcpy(&buff_flag[curr_pntr - 1],
&buff_flag[curr_pntr]);
curr_pntr--;
buff_pntr--;
del_print(curr_pntr, 1);
}
}
fflush(stdout);
return;
}