Changeset View
Changeset View
Standalone View
Standalone View
contrib/ee/ee.c
| Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | |||||
| unsigned char *point; /* points to current position in line */ | unsigned char *point; /* points to current position in line */ | ||||
| unsigned char *srch_str; /* pointer for search string */ | unsigned char *srch_str; /* pointer for search string */ | ||||
| unsigned char *u_srch_str; /* pointer to non-case sensitive search */ | unsigned char *u_srch_str; /* pointer to non-case sensitive search */ | ||||
| unsigned char *srch_1; /* pointer to start of suspect string */ | unsigned char *srch_1; /* pointer to start of suspect string */ | ||||
| unsigned char *srch_2; /* pointer to next character of string */ | unsigned char *srch_2; /* pointer to next character of string */ | ||||
| unsigned char *srch_3; | unsigned char *srch_3; | ||||
| unsigned char *in_file_name = NULL; /* name of input file */ | unsigned char *in_file_name = NULL; /* name of input file */ | ||||
| char *tmp_file; /* temporary file name */ | char *tmp_file; /* temporary file name */ | ||||
| unsigned char *d_char; /* deleted character */ | unsigned char d_char[5]; /* deleted character */ | ||||
| unsigned char *d_word; /* deleted word */ | unsigned char *d_word; /* deleted word */ | ||||
| unsigned char *d_line; /* deleted line */ | unsigned char *d_line; /* deleted line */ | ||||
| char in_string[513]; /* buffer for reading a file */ | char in_string[513]; /* buffer for reading a file */ | ||||
| unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */ | unsigned char *print_command = (unsigned char *)"lpr"; /* string to use for the print command */ | ||||
| unsigned char *start_at_line = NULL; /* move to this line at start of session*/ | unsigned char *start_at_line = NULL; /* move to this line at start of session*/ | ||||
| int in; /* input character */ | int in; /* input character */ | ||||
| FILE *temp_fp; /* temporary file pointer */ | FILE *temp_fp; /* temporary file pointer */ | ||||
| ▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) { | ||||
| fprintf(stderr, | fprintf(stderr, | ||||
| "ee's standard input and output must be a terminal\n"); | "ee's standard input and output must be a terminal\n"); | ||||
| exit(1); | exit(1); | ||||
| } | } | ||||
| signal(SIGCHLD, SIG_DFL); | signal(SIGCHLD, SIG_DFL); | ||||
| signal(SIGSEGV, SIG_DFL); | signal(SIGSEGV, SIG_DFL); | ||||
| signal(SIGINT, edit_abort); | signal(SIGINT, edit_abort); | ||||
| d_char = malloc(5); /* UTF-8 chars can be up to 4 bytes + NUL */ | |||||
| d_word = malloc(150); | d_word = malloc(150); | ||||
| *d_word = '\0'; | *d_word = '\0'; | ||||
| d_line = NULL; | d_line = NULL; | ||||
| dlt_line = txtalloc(); | dlt_line = txtalloc(); | ||||
| dlt_line->line = d_line; | dlt_line->line = d_line; | ||||
| dlt_line->line_length = 0; | dlt_line->line_length = 0; | ||||
| curr_line = first_line = txtalloc(); | curr_line = first_line = txtalloc(); | ||||
| curr_line->line = point = malloc(10); | curr_line->line = point = malloc(10); | ||||
| ▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* insert a complete multi-byte UTF-8 character into line */ | /* insert a complete multi-byte UTF-8 character into line */ | ||||
| void | void | ||||
| insert_utf8(const unsigned char *mb, int len) | insert_utf8(const unsigned char *mb, int len) | ||||
| { | { | ||||
| int counter; | int counter; | ||||
| unsigned char *temp; | unsigned char *temp; | ||||
| unsigned char *temp2; | |||||
| int i; | int i; | ||||
| text_changes = TRUE; | text_changes = TRUE; | ||||
| if ((curr_line->max_length - curr_line->line_length) < (len + 5)) | if ((curr_line->max_length - curr_line->line_length) < (len + 5)) | ||||
| point = resiz_line(len + 10, curr_line, position); | point = resiz_line(len + 10, curr_line, position); | ||||
| /* shift the tail of the line right by len bytes */ | /* shift the tail of the line right by len bytes */ | ||||
| curr_line->line_length += len; | curr_line->line_length += len; | ||||
| temp = point; | temp = point; | ||||
| counter = position; | counter = position; | ||||
| while (counter < curr_line->line_length) | while (counter < curr_line->line_length) | ||||
| { | { | ||||
| counter++; | counter++; | ||||
| temp++; | temp++; | ||||
| } | } | ||||
| temp++; | temp += len; | ||||
| while (point < temp) | while (point + len - 1 < temp) | ||||
| { | { | ||||
| unsigned char *temp2; | |||||
| temp2 = temp - len; | temp2 = temp - len; | ||||
| *temp = *temp2; | *temp = *temp2; | ||||
| temp--; | temp--; | ||||
| } | } | ||||
| /* copy all bytes of the UTF-8 character */ | /* copy all bytes of the UTF-8 character */ | ||||
| for (i = 0; i < len; i++) | memmove(point, mb, len); | ||||
| point[i] = mb[i]; | |||||
| /* display the character before advancing past it */ | /* display the character before advancing past it */ | ||||
| wclrtoeol(text_win); | wclrtoeol(text_win); | ||||
| { | { | ||||
| char buf[5]; | char buf[5]; | ||||
| memcpy(buf, point, len); | memcpy(buf, point, len); | ||||
| buf[len] = '\0'; | buf[len] = '\0'; | ||||
| waddstr(text_win, buf); | waddstr(text_win, buf); | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (point != curr_line->line) /* if not at beginning of line */ | ||||
| point -= del_width; | point -= del_width; | ||||
| position -= del_width; | position -= del_width; | ||||
| temp_pos = position; | temp_pos = position; | ||||
| curr_line->line_length -= del_width; | curr_line->line_length -= del_width; | ||||
| scanline(point); | scanline(point); | ||||
| scr_pos = scr_horz; | scr_pos = scr_horz; | ||||
| if (in == 8) | if (in == 8) | ||||
| { | { | ||||
| memcpy(d_char, point, del_width); | size_t width = min(del_width, 4); | ||||
| d_char[del_width] = '\0'; | |||||
| memcpy(d_char, point, width); | |||||
| d_char[width] = '\0'; | |||||
| } | } | ||||
| while (temp_pos <= curr_line->line_length) | while (temp_pos <= curr_line->line_length) | ||||
| { | { | ||||
| temp_pos++; | temp_pos++; | ||||
| *tp = *temp2; | *tp = *temp2; | ||||
| tp++; | tp++; | ||||
| temp2++; | temp2++; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 2,044 Lines • ▼ Show 20 Lines | del_word(void) | ||||
| int difference; | int difference; | ||||
| unsigned char *d_word2; | unsigned char *d_word2; | ||||
| unsigned char *d_word3; | unsigned char *d_word3; | ||||
| unsigned char tmp_char[5]; | unsigned char tmp_char[5]; | ||||
| if (d_word != NULL) | if (d_word != NULL) | ||||
| free(d_word); | free(d_word); | ||||
| d_word = malloc(curr_line->line_length); | d_word = malloc(curr_line->line_length); | ||||
| memcpy(tmp_char, d_char, 5); | memcpy(tmp_char, d_char, sizeof(tmp_char)); | ||||
| d_word3 = point; | d_word3 = point; | ||||
| d_word2 = d_word; | d_word2 = d_word; | ||||
| tposit = position; | tposit = position; | ||||
| while ((tposit < curr_line->line_length) && | while ((tposit < curr_line->line_length) && | ||||
| ((*d_word3 != ' ') && (*d_word3 != '\t'))) | ((*d_word3 != ' ') && (*d_word3 != '\t'))) | ||||
| { | { | ||||
| tposit++; | tposit++; | ||||
| *d_word2 = *d_word3; | *d_word2 = *d_word3; | ||||
| Show All 16 Lines | while (tposit < curr_line->line_length) | ||||
| tposit++; | tposit++; | ||||
| *d_word2 = *d_word3; | *d_word2 = *d_word3; | ||||
| d_word2++; | d_word2++; | ||||
| d_word3++; | d_word3++; | ||||
| } | } | ||||
| curr_line->line_length -= difference; | curr_line->line_length -= difference; | ||||
| *d_word2 = '\0'; | *d_word2 = '\0'; | ||||
| draw_line(scr_vert, scr_horz,point,position,curr_line->line_length); | draw_line(scr_vert, scr_horz,point,position,curr_line->line_length); | ||||
| memcpy(d_char, tmp_char, 5); | memcpy(d_char, tmp_char, sizeof(d_char)); | ||||
| text_changes = TRUE; | text_changes = TRUE; | ||||
| formatted = FALSE; | formatted = FALSE; | ||||
| } | } | ||||
| /* undelete last deleted word */ | /* undelete last deleted word */ | ||||
| void | void | ||||
| undel_word(void) | undel_word(void) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 1,098 Lines • ▼ Show 20 Lines | Format(void) | ||||
| int tmp_af; | int tmp_af; | ||||
| int counter; | int counter; | ||||
| unsigned char *line; | unsigned char *line; | ||||
| unsigned char *tmp_srchstr; | unsigned char *tmp_srchstr; | ||||
| unsigned char *temp1, *temp2; | unsigned char *temp1, *temp2; | ||||
| unsigned char *temp_dword; | unsigned char *temp_dword; | ||||
| unsigned char temp_d_char[5]; | unsigned char temp_d_char[5]; | ||||
| memcpy(temp_d_char, d_char, 5); | memcpy(temp_d_char, d_char, sizeof(temp_d_char)); | ||||
| /* | /* | ||||
| | if observ_margins is not set, or the current line is blank, | | if observ_margins is not set, or the current line is blank, | ||||
| | do not format the current paragraph | | do not format the current paragraph | ||||
| */ | */ | ||||
| if ((!observ_margins) || (Blank_Line(curr_line))) | if ((!observ_margins) || (Blank_Line(curr_line))) | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | |||||
| */ | */ | ||||
| if (d_word != NULL) | if (d_word != NULL) | ||||
| free(d_word); | free(d_word); | ||||
| d_word = temp_dword; | d_word = temp_dword; | ||||
| case_sen = temp_case; | case_sen = temp_case; | ||||
| free(srch_str); | free(srch_str); | ||||
| srch_str = tmp_srchstr; | srch_str = tmp_srchstr; | ||||
| memcpy(d_char, temp_d_char, 5); | memcpy(d_char, temp_d_char, sizeof(d_char)); | ||||
| auto_format = tmp_af; | auto_format = tmp_af; | ||||
| midscreen(scr_vert, point); | midscreen(scr_vert, point); | ||||
| werase(com_win); | werase(com_win); | ||||
| wrefresh(com_win); | wrefresh(com_win); | ||||
| } | } | ||||
| unsigned char *init_name[3] = { | unsigned char *init_name[3] = { | ||||
| ▲ Show 20 Lines • Show All 367 Lines • ▼ Show 20 Lines | Auto_Format(void) | ||||
| char not_blank; | char not_blank; | ||||
| unsigned char *line; | unsigned char *line; | ||||
| unsigned char *tmp_srchstr; | unsigned char *tmp_srchstr; | ||||
| unsigned char *temp1, *temp2; | unsigned char *temp1, *temp2; | ||||
| unsigned char *temp_dword; | unsigned char *temp_dword; | ||||
| unsigned char temp_d_char[5]; | unsigned char temp_d_char[5]; | ||||
| unsigned char *tmp_d_line; | unsigned char *tmp_d_line; | ||||
| memcpy(temp_d_char, d_char, 5); | memcpy(temp_d_char, d_char, sizeof(temp_d_char)); | ||||
| /* | /* | ||||
| | if observ_margins is not set, or the current line is blank, | | if observ_margins is not set, or the current line is blank, | ||||
| | do not format the current paragraph | | do not format the current paragraph | ||||
| */ | */ | ||||
| if ((!observ_margins) || (Blank_Line(curr_line))) | if ((!observ_margins) || (Blank_Line(curr_line))) | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | */ | ||||
| if (d_word != NULL) | if (d_word != NULL) | ||||
| free(d_word); | free(d_word); | ||||
| d_word = temp_dword; | d_word = temp_dword; | ||||
| d_wrd_len = temp_dwl; | d_wrd_len = temp_dwl; | ||||
| case_sen = temp_case; | case_sen = temp_case; | ||||
| free(srch_str); | free(srch_str); | ||||
| srch_str = tmp_srchstr; | srch_str = tmp_srchstr; | ||||
| memcpy(d_char, temp_d_char, 5); | memcpy(d_char, temp_d_char, sizeof(d_char)); | ||||
| auto_format = TRUE; | auto_format = TRUE; | ||||
| dlt_line->line_length = tmp_d_line_length; | dlt_line->line_length = tmp_d_line_length; | ||||
| d_line = tmp_d_line; | d_line = tmp_d_line; | ||||
| formatted = TRUE; | formatted = TRUE; | ||||
| midscreen(scr_vert, point); | midscreen(scr_vert, point); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 558 Lines • Show Last 20 Lines | |||||