|
|
1.1 root 1: #include <jerq.h>
2: #include <kbd.h>
3: #include <font.h>
4: #include <setup.h>
5: #include <pf.h>
6:
7: #define xmax ((XMAX-2*XMARGIN)/CW-1)
8: #define ymax ((YMAX-2*YMARGIN)/NS-3)
9:
10: extern Point pt();
11: extern Point cur;
12: extern Rectangle rect();
13: extern Rectangle Rect();
14:
15: pfkey(keynum)
16: int keynum; /* pfkey number pressed */
17: {
18: short edit, ins_mode;
19: int inchar;
20: char tempstr[2];
21: char pfstr[PFKEYLEN + 1];
22: Point savecur;
23:
24: savecur = cur; /* save setup's cursor */
25: clear (Rect(0, ymax+1, xmax, ymax+3)); /* clear converts to points */
26: rectf(&display,rect(Rect(0,ymax+2,7,ymax+3)), F_XOR);
27: rectf(&display,rect(Rect(9,ymax+2,16,ymax+3)), F_XOR);
28: rectf(&display,rect(Rect(18,ymax+2,25,ymax+3)), F_XOR);
29: rectf(&display,rect(Rect(30,ymax+2,36,ymax+3)), F_XOR);
30: rectf(&display,rect(Rect(38,ymax+2,44,ymax+3)), F_XOR);
31: rectf(&display,rect(Rect(49,ymax+2,56,ymax+3)), F_XOR);
32: rectf(&display,rect(Rect(58,ymax+2,65,ymax+3)), F_XOR);
33: rectf(&display,rect(Rect(67,ymax+2,74,ymax+3)), F_XOR);
34: cur.x=0;
35: cur.y=ymax+2;
36: string (&defont, PFBOT_HEADINGS, &display, pt(cur), F_XOR);
37:
38:
39: next_key: /* label for goto (shudder) if user wants to change keys */
40: tempstr[0] = keynum + '0';
41: tempstr[1] = (char) 0;
42: keynum--; /* adjust for storage, which starts with 0 */
43:
44: /* Logic...
45: draw menu to screen
46: switch/wait on chars for fkeys
47: ins/delete as necessary... keep one string
48: on exit update BRAM
49: pfkey is null terminated
50: */
51: clear (Rect(0, ymax+1, xmax, ymax+2)); /* clear converts to points */
52:
53: cur.x = 0;
54: cur.y = ymax + 1;
55: string (&defont, PFTOP_HEADINGS, &display, pt(cur), F_STORE);
56: cur.x = 1;
57: string (&defont, tempstr, &display, pt(cur), F_STORE);
58: cur.x=3;
59: bramgetstr ( keynum, pfstr, EDLEN(0) ); /* put pfkey into str "pfstr" */
60: displaystring (pfstr ,cur); /* print string, display unprintables */
61:
62: /* Now the initial display is set: wait for a char */
63:
64: ins_mode = edit = 0; /* set to editting pf key, may implement labels later */
65: cur.x = PFMINPOS(edit); /* set cursor to start of pfkey def */
66: curse();
67: while(((inchar = kgetc()) == -1) || (inchar == (char) 0)); /* wait until we get a valid character */
68: while ((inchar != PF_EXITKEY) && (inchar != SETUPKEY))
69: {
70: switch(inchar)
71: {
72: /* case PF_ED_KEY:
73: /* case PF_ED_LABEL: /* Not implemented yet */
74: /* if (edit == inchar-PF_ED_KEY) /* turn off current edit mode */
75: /* edit = NOT_EDITTING;
76: /* else
77: /* {
78: /* if (edit != NOT_EDITTING) /* switch editmodes */
79: /* curse(); /* clean up old cursor*/
80: /* edit = inchar - PF_ED_KEY;
81: /* cur.x = PFMINPOS(edit);
82: /* }
83: /* curse(); /* clear/set cursor */
84: /* break; */
85: case PF_INSKEY:
86: /* if (edit == NOT_EDITTING)
87: /* { /* not legal unless editting */
88: /* ringbell();
89: /* break;
90: /* } */
91: /* reverse highlight insert char key */
92: rectf(&display,inset(rect(Rect(0,ymax+2,7,ymax+3)),1), F_XOR);
93: ins_mode = ~ins_mode;
94: break;
95: case PF_DELKEY:
96: if (strlen(pfstr) > 0)
97: {
98: if(strlen(pfstr) == EDPOS(edit,cur.x)) {
99: /* at end of string */
100: curse();
101: cur.x--;
102: curse();
103: }
104: else {
105: scroll(Rect(cur.x + 1, ymax+1,
106: PFMINPOS(edit) + strlen(pfstr), ymax+2),
107: Pt(cur.x, ymax+1),ymax+2);
108: strdelchar(pfstr,cur.x - PFMINPOS(edit));
109: if ((cur.x >= strlen(pfstr) + PFMINPOS(edit)) &&
110: (cur.x > PFMINPOS(edit)))
111: cur.x--;
112: curse(); /* restore creamed cursor */
113: }
114: }
115: else
116: ringbell();
117: break;
118: case PF_NEXTKEY:
119: bramputstr ( keynum, pfstr ); /* Store string into bram */
120: keynum += 2;
121: if (keynum > 8)
122: keynum = 1;
123: if(ins_mode) {
124: /* reverse highlight insert char key */
125: rectf(&display,inset(rect(Rect(0,ymax+2,7,ymax+3)),1), F_XOR);
126: }
127: goto next_key; /* top of routine, load new pfkey */
128: case PF_LEFTKEY:
129: case 0xc4: /* left-arrow */
130: /* if (edit != NOT_EDITTING) */
131: if (cur.x > PFMINPOS(edit))
132: {
133: curse();
134: cur.x--;
135: curse();
136: }
137: break;
138: case PF_RIGHTKEY:
139: case 0xc3: /* right-arrow */
140: /* EDPOS returns the position within the
141: currently editted string that the cursor
142: points at */
143: /* if (edit != NOT_EDITTING) */
144: if (strlen(pfstr) >= EDPOS(edit, cur.x + 1))
145: {
146: curse();
147: cur.x++;
148: curse();
149: }
150: break;
151: case 0x88: /* PF 7 */
152: case 0x89: /* PF 8 */
153: /*
154: * Ignore these keys
155: */
156: break;
157: default:
158: if( ins_mode )
159: if( strlen(pfstr) >= EDLEN(edit) ) /* Can't insert */
160: {
161: ringbell();
162: break;
163: }
164: else {
165: /* First make room on screen */
166: curse(); /* turn off old cursor */
167: scroll(Rect(cur.x, ymax+1,PFMINPOS(edit) + strlen(pfstr) + 1, ymax+2),
168: Pt(cur.x + 1, ymax+1),ymax+2);
169: curse(); /* turn it back on */
170:
171: /* Then update real string */
172: tempstr[0] = inchar;
173: ins_str(pfstr,tempstr,cur.x - PFMINPOS(edit));
174: }
175: else { /* overstrike */
176: if(EDPOS(edit,cur.x) >= EDLEN(edit)) {
177: /* can't insert any more */
178: ringbell();
179: break;
180: }
181: else {
182: /*
183: * see if we are adding characters to the end of the string
184: */
185: if((strlen(pfstr) ) == EDPOS(edit,cur.x))
186: pfstr[EDPOS(edit,cur.x)+1 ] = (char) 0;
187: pfstr[EDPOS(edit,cur.x)] = inchar;
188: tempstr[0] = inchar;
189: }
190: }
191: if( cur.x <= PFMAXPOS(edit) )
192: {
193: curse();
194: displaystring(tempstr,cur);
195: if(cur.x++ > PFMAXPOS(edit)) {
196: ringbell();
197: cur.x--;
198: }
199: curse();
200: }
201: break;
202: }
203: while(((inchar = kgetc()) == -1) || (inchar == (char) 0)); /* wait until we get a valid character */
204: }
205: bramputstr ( keynum, pfstr ); /* Store string into bram */
206: cur = savecur; /* restore cursor */
207: return(inchar);
208: }
209:
210:
211: bramgetstr(keynum,str,maxlen) /* get pfkey "keynum" from bram into "str" */
212: int keynum;
213: register char *str;
214: int maxlen; /* max length allowed for string */
215: {
216: register int i = 0;
217: while ((*str++ = BRAM->pfkeys[keynum][i].byte) && (++i < maxlen));
218: *str = (char) 0; /* guarantee null termination if full length */
219: }
220:
221: bramputstr(keynum,str) /* store string "str" into pfkey "keynum" in bram */
222: int keynum;
223: char *str;
224: {
225: register int i = 0;
226:
227: while (BRAM->pfkeys[keynum][i++].byte = (unsigned char) (*str++));
228: }
229:
230: displaystring(str,cur) /* print the real string with screen printable chars */
231: char *str;
232: Point cur;
233: {
234: register char tmpc;
235: char overstrike[2]; /* string holding overstrike char */
236: char printstr[2];
237:
238: overstrike[0] = overstrike[1] = printstr[1] = (char) 0;
239:
240: str--; /* prepare for the loop */
241: while ((tmpc = *++str) != (char) NULL)
242: {
243: printstr[0] = tmpc; /* printable char */
244: string(&defont, printstr, &display, pt(cur), F_STORE);
245: cur.x++;
246: }
247: }
248:
249: extern int kbdstatus;
250: ringbell()
251: {
252: kbdstatus |= TTY_ALARM;
253: DUART->b_data = kbdstatus; /* ding!!!*/
254: kbdstatus &= ~TTY_ALARM;
255: }
256:
257: strdelchar(str, pos) /* delete char at position pos in string str */
258: char *str;
259: int pos;
260: {
261: str = &(str[pos]);
262: while (*str++ != (char) NULL)
263: *(str - 1) = *str;
264: }
265:
266: ins_str(str,instr, pos) /* insert instr into str at position pos */
267: char *str, *instr;
268: int pos;
269: {
270: register int i, j;
271:
272: i = strlen(str) + 1;
273: j = strlen(instr);
274: while ( --i >= pos ) /* make room for new string */
275: str[i + j] = str[i];
276:
277: /* insert new string */
278: while ( j--)
279: str[++i] = *instr++;
280: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.