wrong cursor position in c_show
[unix-history] / usr / src / usr.bin / window / lcmd1.c
CommitLineData
bd002416 1#ifndef lint
8aee01cc 2static char *sccsid = "@(#)lcmd1.c 3.3 83/08/12";
bd002416
EW
3#endif
4
5#include "defs.h"
6
7struct ww *openwin();
8struct ww *idtowin();
9
10l_window()
11{
12 register char **pp = argv;
13 register struct ww *w;
14 int col, row, ncol, nrow, id;
15
16 if ((id = findid()) < 0) {
17 error("Too many windows.");
18 return;
19 }
20 if (**++pp == '*')
21 row = 1;
22 else
23 row = atoi(*pp);
24 if (**++pp == '*')
25 col = 0;
26 else
27 col = atoi(*pp);
28 if (**++pp == '*')
29 nrow = wwnrow - row;
30 else
31 nrow = atoi(*pp);
32 if (**++pp == '*')
33 ncol = wwncol - col;
34 else
35 ncol = atoi(*pp);
36 w = openwin(id, nrow, ncol, row, col);
37 if (w == 0)
38 error("Can't open window: row %d col %d, %d rows %d cols.",
39 row, col, nrow, ncol);
40}
41
42l_select()
43{
44 struct ww *w;
45
46 if ((w = idtowin(*argv + 1)) == 0)
47 return;
48 setselwin(w);
49}
50
51l_escape()
52{
53 setescape(argv[1]);
54}
55
56l_label()
57{
58 struct ww *w;
59
60 if ((w = idtowin(argv[1])) == 0)
61 return;
62 if (setlabel(w, argv[2]) < 0)
63 error("Out of memory.");
64 reframe();
65}
66
67l_terse()
68{
69 char oldterse = terse;
70
71 if (argc < 2)
72 terse = 1;
73 else if (strcmp(argv[1], "off") == 0)
74 terse = 0;
75 else
76 terse = 1;
77 if (terse && !oldterse)
78 wwdelete(cmdwin);
79 else if (!terse && oldterse)
80 wwadd(cmdwin, &wwhead);
81 reframe();
82}
83
84l_source()
85{
86 if (insource) {
87 error("Recursive source.");
88 return;
89 }
90 if (dosource(argv[1]) < 0)
91 error("Can't open %s.", argv[1]);
92}
93
94l_write()
95{
96 struct ww *w;
97
98 if ((w = idtowin(argv[1])) == 0)
99 return;
100 (void) write(w->ww_pty, argv[2], strlen(argv[2]));
101}
102
8aee01cc
EW
103l_close()
104{
105 register i;
106 register struct ww *w;
107 char didit = 0;
108
109 for (i = 1; i < argc; i++) {
110 if ((w = idtowin(argv[i])) == 0)
111 continue;
112 closewin(w);
113 didit++;
114 }
115 if (selwin == 0) {
116 for (i = 0; i < NWINDOW && window[i] != 0; i++)
117 ;
118 if (i < NWINDOW)
119 setselwin(window[i]);
120 }
121 if (didit)
122 reframe();
123}
124
bd002416
EW
125struct ww *
126idtowin(idstr)
127char *idstr;
128{
129 register id;
130 struct ww *w;
131
132 id = atoi(idstr) - 1;
133 if (id < 0 || id >= NWINDOW || (w = window[id]) == 0) {
134 error("%d: No such window.", id + 1);
135 return 0;
136 }
137 return w;
138}