forked from paxed/dgamelaunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ee.c
3625 lines (3394 loc) · 81.6 KB
/
ee.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
| ee (easy editor)
|
| An easy to use, simple screen oriented editor.
|
| written by Hugh Mahon
|
| THIS MATERIAL IS PROVIDED "AS IS". THERE ARE
| NO WARRANTIES OF ANY KIND WITH REGARD TO THIS
| MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND
| FITNESS FOR A PARTICULAR PURPOSE. Neither
| Hewlett-Packard nor Hugh Mahon shall be liable
| for errors contained herein, nor for
| incidental or consequential damages in
| connection with the furnishing, performance or
| use of this material. Neither Hewlett-Packard
| nor Hugh Mahon assumes any responsibility for
| the use or reliability of this software or
| documentation. This software and
| documentation is totally UNSUPPORTED. There
| is no support contract available. Hewlett-
| Packard has done NO Quality Assurance on ANY
| of the program or documentation. You may find
| the quality of the materials inferior to
| supported materials.
|
| This software is not a product of Hewlett-Packard, Co., or any
| other company. No support is implied or offered with this software.
| You've got the source, and you're on your own.
|
| This software may be distributed under the terms of Larry Wall's
| Artistic license, a copy of which is included in this distribution.
|
| This notice must be included with this software and any derivatives.
|
| This editor was purposely developed to be simple, both in
| interface and implementation. This editor was developed to
| address a specific audience: the user who is new to computers
| (especially UNIX).
|
| ee is not aimed at technical users; for that reason more
| complex features were intentionally left out. In addition,
| ee is intended to be compiled by people with little computer
| experience, which means that it needs to be small, relatively
| simple in implementation, and portable.
|
| This software and documentation contains
| proprietary information which is protected by
| copyright. All rights are reserved.
|
| $Header: /var/cvs/dgamelaunch/ee.c,v 1.10 2004/01/26 16:54:02 joshk Exp $
|
*/
#include <wchar.h>
wchar_t *ee_copyright_message =
L"Copyright (c) 1986, 1990, 1991, 1992, 1993, 1994, 1995, 1996 Hugh Mahon ";
wchar_t *ee_long_notice[] = {
L"This software and documentation contains",
L"proprietary information which is protected by",
L"copyright. All rights are reserved."
};
wchar_t *version = L"@(#) ee, version 1.4.1 $Revision: 1.10 $";
#include <locale.h>
#include <curses.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <pwd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <ctype.h>
#ifndef SIGCHLD
#define SIGCHLD SIGCLD
#endif
#define MAX_FILE 1048576
#define TAB 9
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
/*
| defines for type of data to show in info window
*/
#define CONTROL_KEYS 1
#define COMMANDS 2
struct text {
wchar_t *line; /* line of characters */
int line_number; /* line number */
int line_length; /* actual number of characters in the line */
int max_length; /* maximum number of characters the line handles */
struct text *next_line; /* next line of text */
struct text *prev_line; /* previous line of text */
};
struct text *first_line; /* first line of current buffer */
struct text *dlt_line; /* structure for info on deleted line */
struct text *curr_line; /* current line cursor is on */
struct text *tmp_line; /* temporary line pointer */
struct text *srch_line; /* temporary pointer for search routine */
int d_wrd_len; /* length of deleted word */
int position; /* offset in bytes from begin of line */
int scr_pos; /* horizontal position */
int scr_vert; /* vertical position on screen */
int scr_horz; /* horizontal position on screen */
int tmp_vert, tmp_horz;
int input_file; /* indicate to read input file */
int recv_file; /* indicate reading a file */
int edit; /* continue executing while true */
int gold; /* 'gold' function key pressed */
int fildes; /* file descriptor */
int case_sen; /* case sensitive search flag */
int last_line; /* last line for text display */
int last_col; /* last column for text display */
int horiz_offset = 0; /* offset from left edge of text */
int clear_com_win; /* flag to indicate com_win needs clearing */
int text_changes = FALSE; /* indicate changes have been made to text */
int get_fd; /* file descriptor for reading a file */
int info_window = TRUE; /* flag to indicate if help window visible */
int info_type = CONTROL_KEYS; /* flag to indicate type of info to display */
int expand_tabs = TRUE; /* flag for expanding tabs */
int right_margin = 0; /* the right margin */
int observ_margins = TRUE; /* flag for whether margins are observed */
int out_pipe; /* flag that info is piped out */
int in_pipe; /* flag that info is piped in */
int formatted = FALSE; /* flag indicating paragraph formatted */
int nohighlight = FALSE; /* turns off highlighting */
int eightbit = TRUE; /* eight bit character flag */
int local_LINES = 0; /* copy of LINES, to detect when win resizes */
int local_COLS = 0; /* copy of COLS, to detect when win resizes */
int curses_initialized = FALSE; /* flag indicating if curses has been started*/
int emacs_keys_mode = TRUE; /* mode for if emacs key binings are used */
wchar_t *point; /* points to current position in line */
wchar_t *srch_str; /* pointer for search string */
wchar_t *u_srch_str; /* pointer to non-case sensitive search */
wchar_t *srch_1; /* pointer to start of suspect string */
wchar_t *srch_2; /* pointer to next character of string */
wchar_t *srch_3;
char *in_file_name = NULL; /* name of input file */
char *tmp_file; /* temporary file name */
wchar_t *d_char; /* deleted character */
wchar_t *d_word; /* deleted word */
wchar_t *d_line; /* deleted line */
wchar_t *start_at_line = NULL; /* move to this line at start of session*/
int in; /* input character */
FILE *temp_fp; /* temporary file pointer */
wchar_t *table[] = {
L"^@", L"^A", L"^B", L"^C", L"^D", L"^E", L"^F", L"^G", L"^H", L"\t", L"^J",
L"^K", L"^L", L"^M", L"^N", L"^O", L"^P", L"^Q", L"^R", L"^S", L"^T", L"^U",
L"^V", L"^W", L"^X", L"^Y", L"^Z", L"^[", L"^\\", L"^]", L"^^", L"^_"
};
WINDOW *com_win;
WINDOW *text_win;
WINDOW *help_win;
WINDOW *info_win;
#if defined(__STDC__) || defined(__cplusplus)
#define P_(s) s
#else
#define P_(s) ()
#endif
/*
| The following structure allows menu items to be flexibly declared.
| The first item is the string describing the selection, the second
| is the address of the procedure to call when the item is selected,
| and the third is the argument for the procedure.
|
| For those systems with i18n, the string should be accompanied by a
| catalog number. The 'int *' should be replaced with 'void *' on
| systems with that type.
|
| The first menu item will be the title of the menu, with NULL
| parameters for the procedure and argument, followed by the menu items.
|
| If the procedure value is NULL, the menu item is displayed, but no
| procedure is called when the item is selected. The number of the
| item will be returned. If the third (argument) parameter is -1, no
| argument is given to the procedure when it is called.
*/
struct menu_entries
{
wchar_t *item_string;
int (*procedure)P_((struct menu_entries *));
struct menu_entries *ptr_argument;
int (*iprocedure)P_((int));
void (*nprocedure)P_((void));
int argument;
};
int main(int argc, char *argv[]);
wchar_t *resiz_line(int factor, struct text *rline, int rpos);
void insert(int character);
void delete(int disp);
void scanline(wchar_t *pos);
int tabshift(int temp_int);
int out_char(WINDOW *window, int character, int column);
int len_char(wchar_t character, int column);
void draw_line(int vertical, int horiz, wchar_t *ptr, int t_pos, int length);
void insert_line(int disp);
struct text *txtalloc(void);
wchar_t *next_word(wchar_t *string);
void prev_word(void);
void control(void);
void emacs_control(void);
void bottom(void);
void top(void);
void nextline(void);
void prevline(void);
void left(int disp);
void right(int disp);
void find_pos(void);
void up(void);
void down(void);
void function_key(void);
void command_prompt(void);
void command(wchar_t *cmd_str1);
int scan(wchar_t *line, int offset, int column);
wchar_t *get_string(wchar_t *prompt, int advance);
int compare(wchar_t *string1, wchar_t *string2, int sensitive);
void goto_line(wchar_t *cmd_str);
void midscreen(int line, wchar_t *pnt);
void check_fp(void);
void get_file(char *file_name);
void get_line(int length, char *in_string, int *append);
void draw_screen(void);
void ee_finish(void);
int quit(int noverify);
void edit_abort(int arg);
void delete_text(void);
int write_file(char *file_name, int fd);
int search(int display_message);
void search_prompt(void);
void del_char(void);
void undel_char(void);
void del_word(void);
void undel_word(void);
void del_line(void);
void undel_line(void);
void adv_word(void);
void move_rel(char direction, int lines);
void eol(void);
void bol(void);
void adv_line(void);
void set_up_term(void);
void resize_check(void);
int menu_op(struct menu_entries menu_list[]);
void paint_menu(struct menu_entries menu_list[], int max_width, int max_height, int list_size, int top_offset, WINDOW *menu_win, int off_start, int vert_size);
void help(void);
void paint_info_win(void);
void no_info_window(void);
void create_info_window(void);
int file_op(int arg);
void leave_op(void);
void redraw(void);
int Blank_Line(struct text *test_line);
void echo_string(wchar_t *string);
int first_word_len(struct text *test_line);
wchar_t *is_in_string(wchar_t *string, wchar_t *substring);
int unique_test(wchar_t *string, wchar_t *list[]);
void strings_init(void);
#undef P_
/*
| allocate space here for the strings that will be in the menu
*/
struct menu_entries leave_menu[] = {
{L"", NULL, NULL, NULL, NULL, -1},
{L"", NULL, NULL, NULL, ee_finish, -1},
{L"", NULL, NULL, quit, NULL, TRUE},
{NULL, NULL, NULL, NULL, NULL, -1}
};
#define READ_FILE 1
#define WRITE_FILE 2
#define SAVE_FILE 3
struct menu_entries search_menu[] = {
{L"", NULL, NULL, NULL, NULL, 0},
{L"", NULL, NULL, NULL, search_prompt, -1},
{L"", NULL, NULL, search, NULL, TRUE},
{NULL, NULL, NULL, NULL, NULL, -1}
};
struct menu_entries main_menu[] = {
{L"", NULL, NULL, NULL, NULL, -1},
{L"", NULL, NULL, NULL, leave_op, -1},
{L"", NULL, NULL, NULL, help, -1},
{L"", NULL, NULL, file_op, NULL, SAVE_FILE},
{L"", NULL, NULL, NULL, redraw, -1},
{L"", menu_op, search_menu, NULL, NULL, -1},
{NULL, NULL, NULL, NULL, NULL, -1}
};
wchar_t *help_text[23];
wchar_t *control_keys[5];
wchar_t *emacs_help_text[22];
wchar_t *emacs_control_keys[5];
wchar_t *command_strings[5];
wchar_t *commands[32];
#define MENU_WARN 1
#define max_alpha_char 36
/*
| Declarations for strings for localization
*/
wchar_t *com_win_message; /* to be shown in com_win if no info window */
char *no_file_string;
wchar_t *ascii_code_str;
wchar_t *command_str;
char *char_str;
char *unkn_cmd_str;
wchar_t *non_unique_cmd_msg;
char *line_num_str;
char *line_len_str;
char *current_file_str;
wchar_t *usage0;
wchar_t *usage1;
wchar_t *usage2;
wchar_t *usage3;
wchar_t *usage4;
char *file_is_dir_msg;
char *new_file_msg;
char *cant_open_msg;
wchar_t *open_file_msg;
char *file_read_fin_msg;
char *reading_file_msg;
char *read_only_msg;
char *file_read_lines_msg;
wchar_t *save_file_name_prompt;
char *file_not_saved_msg;
wchar_t *changes_made_prompt;
wchar_t *yes_char;
wchar_t *file_exists_prompt;
char *create_file_fail_msg;
char *writing_file_msg;
char *file_written_msg;
char *searching_msg;
char *str_not_found_msg;
wchar_t *search_prompt_str;
wchar_t *continue_msg;
wchar_t *menu_cancel_msg;
wchar_t *menu_size_err_msg;
wchar_t *press_any_key_msg;
wchar_t *ON;
wchar_t *OFF;
wchar_t *HELP;
wchar_t *SAVE;
wchar_t *READ;
wchar_t *LINE;
wchar_t *FILE_str;
wchar_t *CHARACTER;
wchar_t *REDRAW;
wchar_t *RESEQUENCE;
wchar_t *AUTHOR;
wchar_t *ee_VERSION;
wchar_t *CASE;
wchar_t *NOCASE;
wchar_t *EXPAND;
wchar_t *NOEXPAND;
wchar_t *Exit_string;
wchar_t *QUIT_string;
wchar_t *INFO;
wchar_t *NOINFO;
wchar_t *MARGINS;
wchar_t *NOMARGINS;
wchar_t *AUTOFORMAT;
wchar_t *NOAUTOFORMAT;
wchar_t *Echo;
wchar_t *PRINTCOMMAND;
wchar_t *RIGHTMARGIN;
wchar_t *HIGHLIGHT;
wchar_t *NOHIGHLIGHT;
wchar_t *EIGHTBIT;
wchar_t *NOEIGHTBIT;
wchar_t *EMACS_string;
wchar_t *NOEMACS_string;
wchar_t *cancel_string;
char *menu_too_lrg_msg;
wchar_t *more_above_str, *more_below_str;
#ifndef __STDC__
#ifndef HAS_STDLIB
extern char *malloc();
extern char *realloc();
extern char *getenv();
FILE *fopen(); /* declaration for open function */
#endif /* HAS_STDLIB */
#endif /* __STDC__ */
int
main(argc, argv) /* beginning of main program */
int argc;
char *argv[];
{
int counter;
setlocale(LC_ALL, "");
for (counter = 1; counter < 24; counter++)
{
if (!(counter == SIGKILL || counter == SIGSTOP))
signal(counter, SIG_IGN);
}
signal(SIGCHLD, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGINT, edit_abort);
d_char = malloc(3 * sizeof(wchar_t)); /* provide a buffer for multi-byte chars */
d_word = malloc(150 * sizeof(wchar_t));
*d_word = '\0';
d_line = NULL;
dlt_line = txtalloc();
dlt_line->line = d_line;
dlt_line->line_length = 0;
curr_line = first_line = txtalloc();
curr_line->line = point = malloc(10 * sizeof(wchar_t));
curr_line->line_length = 1;
curr_line->max_length = 10;
curr_line->prev_line = NULL;
curr_line->next_line = NULL;
curr_line->line_number = 1;
srch_str = NULL;
u_srch_str = NULL;
position = 1;
scr_pos =0;
scr_vert = 0;
scr_horz = 0;
edit = TRUE;
gold = case_sen = FALSE;
strings_init();
if (argc != 2)
{
puts("need a filename! bailing out.");
return 1;
}
else
{
tmp_file = strdup(argv[1]);
input_file = recv_file = TRUE;
}
set_up_term();
if (right_margin == 0)
right_margin = COLS - 1;
if (!tmp_file)
{
wprintw(com_win, no_file_string);
wrefresh(com_win);
}
else
check_fp();
clear_com_win = TRUE;
while(edit)
{
int keyt;
wrefresh(text_win);
keyt = wget_wch(text_win, &in);
if (keyt == ERR)
exit(0);
resize_check();
if (clear_com_win)
{
clear_com_win = FALSE;
wmove(com_win, 0, 0);
werase(com_win);
if (!info_window)
{
wprintw(com_win, "%S", com_win_message);
}
wrefresh(com_win);
}
if (keyt == KEY_CODE_YES)
function_key();
else if ((in == '\10') || (in == 127))
{
in = 8; /* make sure key is set to backspace */
delete(TRUE);
}
else if ((in > 31) || (in == 9))
insert(in);
else if ((in >= 0) && (in <= 31))
{
if (emacs_keys_mode)
emacs_control();
else
control();
}
}
return(0);
}
wchar_t *
resiz_line(factor, rline, rpos) /* resize the line to length + factor*/
int factor; /* resize factor */
struct text *rline; /* position in line */
int rpos;
{
wchar_t *rpoint;
int resiz_var;
rline->max_length += factor;
rpoint = rline->line = realloc(rline->line, rline->max_length * sizeof(wchar_t));
for (resiz_var = 1 ; (resiz_var < rpos) ; resiz_var++)
rpoint++;
return(rpoint);
}
void
insert(character) /* insert character into line */
int character; /* new character */
{
int counter;
int value;
wchar_t *temp; /* temporary pointer */
wchar_t *temp2; /* temporary pointer */
if ((character == '\011') && (expand_tabs))
{
counter = len_char('\011', scr_horz);
for (; counter > 0; counter--)
insert(' ');
return;
}
text_changes = TRUE;
if ((curr_line->max_length - curr_line->line_length) < 5)
point = resiz_line(10, curr_line, position);
curr_line->line_length++;
temp = point;
counter = position;
while (counter < curr_line->line_length) /* find end of line */
{
counter++;
temp++;
}
temp++; /* increase length of line by one */
while (point < temp)
{
temp2=temp - 1;
*temp= *temp2; /* shift characters over by one */
temp--;
}
*point = character; /* insert new character */
wclrtoeol(text_win);
if ((character >= 0) && (character < ' ')) /* check for TAB character*/
{
scr_pos = scr_horz += out_char(text_win, character, scr_horz);
point++;
position++;
}
else
{
waddnwstr(text_win, &character, 1);
scr_pos = ++scr_horz;
point++;
position ++;
}
if ((observ_margins) && (right_margin < scr_pos))
{
counter = position;
while (scr_pos > right_margin)
prev_word();
if (scr_pos == 0)
{
while (position < counter)
right(TRUE);
}
else
{
counter -= position;
insert_line(TRUE);
for (value = 0; value < counter; value++)
right(TRUE);
}
}
if ((scr_horz - horiz_offset) > last_col)
{
horiz_offset += 8;
midscreen(scr_vert, point);
}
else if ((character != ' ') && (character != '\t'))
formatted = FALSE;
draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
}
void
delete(disp) /* delete character */
int disp;
{
wchar_t *tp;
wchar_t *temp2;
struct text *temp_buff;
int temp_vert;
int temp_pos;
int del_width = 1;
if (point != curr_line->line) /* if not at beginning of line */
{
text_changes = TRUE;
temp2 = tp = point;
tp -= del_width;
point -= del_width;
position -= del_width;
temp_pos = position;
curr_line->line_length -= del_width;
if ((*tp < ' ') || (*tp >= 127)) /* check for TAB */
scanline(tp);
else
scr_horz -= del_width;
scr_pos = scr_horz;
if (in == 8)
{
if (del_width == 1)
*d_char = *point; /* save deleted character */
else
{
d_char[0] = *point;
d_char[1] = *(point + 1);
}
d_char[del_width] = '\0';
}
while (temp_pos <= curr_line->line_length)
{
temp_pos++;
*tp = *temp2;
tp++;
temp2++;
}
if (scr_horz < horiz_offset)
{
horiz_offset -= 8;
midscreen(scr_vert, point);
}
}
else if (curr_line->prev_line != NULL)
{
text_changes = TRUE;
left(disp); /* go to previous line */
temp_buff = curr_line->next_line;
point = resiz_line(temp_buff->line_length, curr_line, position);
if (temp_buff->next_line != NULL)
temp_buff->next_line->prev_line = curr_line;
curr_line->next_line = temp_buff->next_line;
temp2 = temp_buff->line;
if (in == 8)
{
d_char[0] = '\n';
d_char[1] = '\0';
}
tp = point;
temp_pos = 1;
while (temp_pos < temp_buff->line_length)
{
curr_line->line_length++;
temp_pos++;
*tp = *temp2;
tp++;
temp2++;
}
*tp = '\0';
free(temp_buff->line);
free(temp_buff);
temp_buff = curr_line;
temp_vert = scr_vert;
scr_pos = scr_horz;
if (scr_vert < last_line)
{
wmove(text_win, scr_vert + 1, 0);
wdeleteln(text_win);
}
while ((temp_buff != NULL) && (temp_vert < last_line))
{
temp_buff = temp_buff->next_line;
temp_vert++;
}
if ((temp_vert == last_line) && (temp_buff != NULL))
{
tp = temp_buff->line;
wmove(text_win, last_line,0);
wclrtobot(text_win);
draw_line(last_line, 0, tp, 1, temp_buff->line_length);
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
}
}
draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
formatted = FALSE;
}
void
scanline(pos) /* find the proper horizontal position for the pointer */
wchar_t *pos;
{
int temp;
wchar_t *ptr;
ptr = curr_line->line;
temp = 0;
while (ptr < pos)
{
if (*ptr <= 8)
temp += 2;
else if (*ptr == 9)
temp += tabshift(temp);
else if ((*ptr >= 10) && (*ptr <= 31))
temp += 2;
else if ((*ptr >= 32) && (*ptr < 127))
temp++;
else if (*ptr == 127)
temp += 2;
else if (!eightbit)
temp += 5;
else
temp++;
ptr++;
}
scr_horz = temp;
if ((scr_horz - horiz_offset) > last_col)
{
horiz_offset = (scr_horz - (scr_horz % 8)) - (COLS - 8);
midscreen(scr_vert, point);
}
else if (scr_horz < horiz_offset)
{
horiz_offset = max(0, (scr_horz - (scr_horz % 8)));
midscreen(scr_vert, point);
}
}
int
tabshift(temp_int) /* give the number of spaces to shift */
int temp_int;
{
int leftover;
leftover = ((temp_int + 1) % 8);
if (leftover == 0)
return (1);
else
return (9 - leftover);
}
int
out_char(window, character, column) /* output non-printing character */
WINDOW *window;
int character;
int column;
{
int i1, i2;
wchar_t *string;
if (character == TAB)
{
i1 = tabshift(column);
for (i2 = 0;
(i2 < i1) && (((column+i2+1)-horiz_offset) < last_col); i2++)
{
waddch(window, ' ');
}
return(i1);
}
else if ((character >= '\0') && (character < ' '))
{
string = table[(int) character];
}
else
{
waddnwstr(window, &character, 1);
return(1);
}
for (i2 = 0; (string[i2] != '\0') && (((column+i2+1)-horiz_offset) < last_col); i2++)
waddch(window, string[i2]);
return(wcslen(string));
}
int
len_char(character, column) /* return the length of the character */
wchar_t character;
int column; /* the column must be known to provide spacing for tabs */
{
int length;
if (character == '\t')
length = tabshift(column);
else if ((character >= 0) && (character < 32))
length = 2;
else if ((character >= 32) && (character <= 126))
length = 1;
else if (character == 127)
length = 2;
else if (((character > 126) || (character < 0)) && (!eightbit))
length = 5;
else
length = 1;
return(length);
}
void
draw_line(vertical, horiz, ptr, t_pos, length) /* redraw line from current position */
int vertical; /* current vertical position on screen */
int horiz; /* current horizontal position on screen */
wchar_t *ptr; /* pointer to line */
int t_pos; /* current position (offset in bytes) from bol */
int length; /* length (in bytes) of line */
{
int d; /* partial length of special or tab char to display */
wchar_t *temp; /* temporary pointer to position in line */
int abs_column; /* offset in screen units from begin of line */
int column; /* horizontal position on screen */
int row; /* vertical position on screen */
int posit; /* temporary position indicator within line */
abs_column = horiz;
column = horiz - horiz_offset;
row = vertical;
temp = ptr;
d = 0;
posit = t_pos;
if (column < 0)
{
wmove(text_win, row, 0);
wclrtoeol(text_win);
}
while (column < 0)
{
d = len_char(*temp, abs_column);
abs_column += d;
column += d;
posit++;
temp++;
}
wmove(text_win, row, column);
wclrtoeol(text_win);
while ((posit < length) && (column <= last_col))
{
if (*temp < 32)
{
column += len_char(*temp, abs_column);
abs_column += out_char(text_win, *temp, abs_column);
}
else
{
abs_column++;
column++;
waddnwstr(text_win, temp, 1);
}
posit++;
temp++;
}
if (column < last_col)
wclrtoeol(text_win);
wmove(text_win, vertical, (horiz - horiz_offset));
}
void
insert_line(disp) /* insert new line */
int disp;
{
int temp_pos;
int temp_pos2;
wchar_t *temp;
wchar_t *extra;
struct text *temp_nod;
text_changes = TRUE;
wmove(text_win, scr_vert, (scr_horz - horiz_offset));
wclrtoeol(text_win);
temp_nod= txtalloc();
temp_nod->line = extra= malloc(10 * sizeof(wchar_t));
temp_nod->line_length = 1;
temp_nod->max_length = 10;
temp_nod->line_number = curr_line->line_number + 1;
temp_nod->next_line = curr_line->next_line;
if (temp_nod->next_line != NULL)
temp_nod->next_line->prev_line = temp_nod;
temp_nod->prev_line = curr_line;
curr_line->next_line = temp_nod;
temp_pos2 = position;
temp = point;
if (temp_pos2 < curr_line->line_length)
{
temp_pos = 1;
while (temp_pos2 < curr_line->line_length)
{
if ((temp_nod->max_length - temp_nod->line_length)< 5)
extra = resiz_line(10, temp_nod, temp_pos);
temp_nod->line_length++;
temp_pos++;
temp_pos2++;
*extra= *temp;
extra++;
temp++;
}
temp=point;
*temp = '\0';
temp = resiz_line((1 - temp_nod->line_length), curr_line, position);
curr_line->line_length = 1 + temp - curr_line->line;
}
curr_line->line_length = position;
curr_line = temp_nod;
*extra = '\0';
position = 1;
point= curr_line->line;
if (disp)
{
if (scr_vert < last_line)
{
scr_vert++;
wclrtoeol(text_win);
wmove(text_win, scr_vert, 0);
winsertln(text_win);
}
else
{
wmove(text_win, 0,0);
wdeleteln(text_win);
wmove(text_win, last_line,0);
wclrtobot(text_win);
}
scr_pos = scr_horz = 0;
if (horiz_offset)
{
horiz_offset = 0;
midscreen(scr_vert, point);
}
draw_line(scr_vert, scr_horz, point, position,
curr_line->line_length);
}
}
struct text *txtalloc() /* allocate space for line structure */
{
return((struct text *) malloc(sizeof( struct text)));
}
wchar_t *next_word(string) /* move to next word in string */
wchar_t *string;
{
while ((*string != '\0') && ((*string != 32) && (*string != 9)))
string++;
while ((*string != '\0') && ((*string == 32) || (*string == 9)))
string++;
return(string);
}
int watoi(wchar_t *s)
{
int x = 0;
while (*s >= '0' && *s <= '9')
x = x * 10 + *s++ - '0';
return x;
}
void
prev_word() /* move to start of previous word in text */
{
if (position != 1)
{
if ((position != 1) && ((point[-1] == ' ') || (point[-1] == '\t')))
{ /* if at the start of a word */
while ((position != 1) && ((*point != ' ') && (*point != '\t')))
left(TRUE);
}