1 /* we_e_aus.c                                             */
2 /* Copyright (C) 1993 Fred Kruse                          */
3 /* This is free software; you can redistribute it and/or  */
4 /* modify it under the terms of the                       */
5 /* GNU General Public License, see the file COPYING.      */
6 
7 #include "edit.h"
8 
9 /*
10    draw entire screen with uniform chars and color */
e_cls(int frb,int chr)11 void e_cls(int frb, int chr)
12 {
13  int i, j;
14 
15  for (j = 0; j < MAXSLNS; j++)
16   for (i = 0; i < MAXSCOL; i++)
17    e_pr_char(i, j, chr, frb);
18 }
19 
20 /*
21    write text string */
e_puts(char * s,int xa,int ya,int frb)22 int e_puts(char *s, int xa, int ya, int frb)
23 {
24  int i;
25 
26  if (xa >= MAXSCOL || ya > MAXSLNS)
27   return(-1);
28  for (i = 0; s[i] != '\0' && i < 2000; i++)
29   e_pr_char(i + xa, ya, s[i], frb);
30  return(0);
31 }
32 
33 /* write text string (sic!, R.H.)
34    - characters between b2 and n2 will be drawn with color 'col2'
35      other characters in the string with color 'col'
36    - one character before the text is space with color 'col'
37    - one character after the text is space with color 'col'
38    - color 'col3' is used in old style
39 */
e_pr_str(int x,int y,char * str,int col,int b2,int n2,int col2,int col3)40 void e_pr_str(int x, int y, char *str, int col, int b2, int n2, int col2,
41   int col3)
42 {
43  int i, sw = 0;
44 
45  if (n2 < 0)
46  {
47   sw = 1; n2 = -n2;
48  }
49  e_pr_char(x-1, y, 32, col);
50  for (i=0; *(str+i) != '\0'; i++)
51  {
52   if (i>=b2 && i<b2+n2)
53    e_pr_char(x+i, y, *(str+i), col2);
54   else
55    e_pr_char(x+i, y, *(str+i), col);
56  }
57  e_pr_char(x+i, y, 32, col);
58  if (sw == 1 && WpeIsXwin())
59 #ifdef NEWSTYLE
60   e_make_xrect(x-1, y, x+i, y, 0);
61 #else
62  {
63   i++;
64   e_pr_char(x+i, y, SCR, col3);
65   for (; i >= 0; i--)
66    e_pr_char(x+i+MAXSCOL, y, SCD, col3);
67  }
68 #endif
69 }
70 
71 /* - characters between b2 and n2 will be drawn with color 'col2',
72      other characters in the string with color 'col'
73    - spaces between bg and x are drawn with 'col'
74    - spaces after text and before nd are drawnd with 'col'
75 */
e_pr_str_wsd(int x,int y,char * str,int col,int b2,int n2,int col2,int bg,int nd)76 int e_pr_str_wsd(int x, int y, char *str, int col, int b2, int n2, int col2,
77   int bg, int nd)
78 {
79  int i;
80 
81  for (i = bg; i < x; i++)
82   e_pr_char(i, y, ' ', col);
83  for (i = 0; str[i] && i <= nd-x; i++)
84  {
85   if (i>=b2 && i<b2+n2)
86    e_pr_char(i+x, y, *(str+i), col2);
87   else
88    e_pr_char(i+x, y, *(str+i), col);
89  }
90  for (i+=x; i <= nd; i++)
91   e_pr_char(i, y, ' ', col);
92 #ifdef NEWSTYLE
93  if (WpeIsXwin())
94   e_make_xrect(bg, y, nd, y, 0);
95 #endif
96  return(0);
97 }
98 
e_pr_str_scan(int x,int y,char * str,int col,int b2,int n2,int col2,int bg,int nd)99 int e_pr_str_scan(int x, int y, char *str, int col, int b2, int n2, int col2,
100   int bg, int nd)
101 {
102  char txt[30], *pt;
103 
104  if (WpeIsXwin())
105   return(e_pr_str_wsd(x, y, str, col, b2, n2, col2, bg, nd));
106  strcpy(txt, str);
107  if ((pt = strstr(txt, "Alt")) != NULL)
108  {
109   pt[0] = 'E'; pt[1] = 'S'; pt[2] = 'C';
110  }
111  else if (!strncmp(txt, "^F4 Close", 9))
112   strcpy(txt, "ESC X Cl.");
113  return(e_pr_str_wsd(x, y, txt, col, b2, n2, col2, bg, nd));
114 }
115 
116 /*
117    write string of numbers */
e_pr_zstring(char * s,int x,int y,int n,int fb)118 int e_pr_zstring(char *s, int x, int y, int n, int fb)
119 {
120  int i, len = strlen(s);
121 
122  for (i = 0; i < n - len; i++)
123   e_pr_char(x+i, y, ' ', fb);
124  for(; i < n; i++)
125   e_pr_char(x+i, y, s[i-n+len], fb);
126 #ifdef NEWSTYLE
127  if (WpeIsXwin())
128   e_make_xrect(x, y, x+n-1, y, 1);
129 #endif
130  return(len);
131 }
132 
133 /*
134    Write N chars to screen */
e_schr_nchar(char * s,int x,int y,int n,int max,int frb)135 int e_schr_nchar(char *s, int x, int y, int n, int max, int frb)
136 {
137  int i, j;
138 
139  e_pr_char(x, y, ' ', frb);
140  for (i = 1, j = 0; i < max-1 && s[n+j] !='\0'; i++, j++)
141  {
142   if ((unsigned char) s[n+j] < ' ')
143   {
144    e_pr_char(x+i, y, '^', frb);
145    i++;
146    e_pr_char(x+i, y, s[n+j] + '@', frb);
147   }
148   else
149    e_pr_char(x+i, y, s[n+j], frb);
150  }
151  for (; i < max; i++)
152   e_pr_char(x+i, y, ' ', frb);
153 #ifdef NEWSTYLE
154  e_make_xrect(x, y, x+max-1, y, 1);
155 #endif
156  return(i);
157 }
158 
159 /*
160 	  Writing of a text string       */
e_pr_nstr(int x,int y,int n,char * str,int col,int col2)161 void e_pr_nstr(int x, int y, int n, char *str, int col, int col2)
162 {
163  int i;
164 
165  e_pr_char(x-1, y, ' ', col);
166  for (i=0; *(str+i) != '\0' && i < n-1; i++)
167   e_pr_char(x+i, y, *(str+i), col);
168  if (i < n-1)
169   e_pr_char(x+i, y, ' ', col);
170  for (i++; i < n-1; i++)
171   e_pr_char(x+i, y, ' ', col2);
172 }
173 
174 /*
175    Enter digits */
e_schreib_zif(int * num,int x,int y,int max,int ft,int fs)176 int e_schreib_zif(int *num, int x, int y, int max, int ft, int fs)
177 {
178 #if  MOUSE
179  extern struct mouse e_mouse;
180 #endif
181  int c, i, jc = max-1, ntmp = *num, nnum = WpeNumberOfPlaces(ntmp);
182  int first = 1;
183  char *s = MALLOC((max+1)*sizeof(char));
184 
185  e_pr_zstring(WpeNumberToString(ntmp, max, s), x, y, max, fs);
186  fk_locate(x+jc, y);
187  fk_cursor(1);
188  while ((c = e_getch()) != WPE_ESC)
189  {
190 #if  MOUSE
191   if (c < 0)
192   {
193    if (e_mouse.y == y && e_mouse.x >= x && e_mouse.x < x+max)
194    {
195     jc = e_mouse.x-x > max-nnum ? e_mouse.x-x : max-nnum;
196    }
197    else
198    {
199     if (c > -2)
200      *num = WpeStringToNumber(s);
201     FREE(s);
202     return(c);
203    }
204   }
205 #endif
206   if (c == 332) {  if(jc < max-1) jc++;  }
207   else if (c == 330) {  if(jc > max-nnum) jc--;  }
208   else if (c == 326) jc = max-nnum;
209   else if (c == 334) jc = max-1;
210   else if (c == WPE_DC)
211   {
212    if (jc > max-nnum)
213    {
214     for (i = jc-1; i > 0; i--)
215      s[i] = s[i-1];
216     s[0] = 32;
217     nnum--;
218    }
219   }
220   else if (c == ENTF)
221   {
222    if (nnum == 1)
223    {
224     s[jc] = '0';
225    }
226    else if (jc < max)
227    {
228     for (i = jc; i > 0; i--)
229      s[i] = s[i-1];
230     s[0] = 32;
231     nnum--;
232    }
233   }
234   else if (first == 1 && c >='0' && c <= '9')
235   {
236    for (i = 0; i < max - 1; i++)
237     s[i] = 32;
238    s[i] = c;
239    s[max] = '\0';
240    nnum = 1;
241   }
242   else if (c >='0' && c <= '9')
243   {
244    for (i = 0; i < jc; i++)
245     s[i] = s[i+1];
246    s[jc] = c;
247    if (nnum < max)
248     nnum++;
249   }
250   else if (c > 0 && (c < 32 || c > 255))
251   {
252    if (c != WPE_ESC)
253     *num = WpeStringToNumber(s);
254    FREE(s);
255    return(c);
256   }
257   if (jc > max -1)
258    jc = max-1;
259   else if (jc < max - nnum) jc = max-nnum;
260 
261   e_pr_zstring(s, x, y, max, ft);
262   fk_locate(x+jc, y);
263   first = 0;
264  }
265  return(c);
266 }
267 
268 /*
269    write chars in text line */
e_schreib_leiste(char * s,int x,int y,int n,int max,int ft,int fs)270 int e_schreib_leiste(char *s, int x, int y, int n, int max, int ft, int fs)
271 {
272 #if  MOUSE
273  extern struct mouse e_mouse;
274 #endif
275  int c, i, ja = 0, jc, l = strlen(s);
276  int jd;
277  int sond = 0, first = 1;
278  unsigned char *tmp = MALLOC(max+1);
279 
280  fk_cursor(1);
281  strcpy(tmp, s);
282  jc = l;
283  for (jd = 0, i = ja; tmp[i] && i <= n-3 + jd; i++)
284   if (tmp[i] < ' ') jd++;
285  if (jc + jd > n-2) jc = n-3-jd;
286  e_schr_nchar(tmp, x, y, 0, n, fs);
287  e_pr_char(x, y, ' ', ft);
288  e_pr_char(x+n-1, y, ' ', ft);
289  fk_locate(x+jc+jd+1, y);
290 #ifdef NEWSTYLE
291  e_make_xrect(x, y, x+n-1, y, 1);
292 #endif
293  while ((c = e_getch()) != WPE_ESC)
294  {
295 #if  MOUSE
296   if (c < 0)
297   {
298    if (e_mouse.y == y && e_mouse.x > x && e_mouse.x < x+n)
299    {
300     jc = e_mouse.x-x-1 < l ? e_mouse.x-x-1 : l;
301     if (c == -2)
302     {
303      int len = WpeEditor->f[0]->b->bf[0].len;
304 #ifndef NO_XWINDOWS
305      if (bioskey() & 8)
306      e_cp_X_to_buffer(WpeEditor->f[WpeEditor->mxedt]);
307 #endif
308      while (e_mshit())
309       ;
310      if (first == 1)
311      {
312       tmp[0] = '\0';
313       l = 0;
314       jc = 0;
315      }
316      if (len + l > max) len = max - l;
317      for (i = l; i >= jc; i--)
318       tmp[i+len] = tmp[i];
319      for (i = jc; i < jc + len; i++)
320       tmp[i] = WpeEditor->f[0]->b->bf[0].s[i-jc];
321      jc += len;
322      l += len;
323     }
324    }
325    else
326    {
327     if (c > -4) strcpy(s, tmp);
328     FREE(tmp);
329     fk_cursor(0);
330     return(c);
331    }
332   }
333 #endif
334   if (c == CRI || (!sond && c == CtrlF)) {  if(jc < l) jc++;  }
335   else if (c == CLE || (!sond && c == CtrlB)) {  if(jc > 0) jc--;  }
336   else if (c == CCLE && jc > 0) jc = e_su_rblk(jc, tmp);
337   else if (c == CCRI && jc < l) jc = e_su_lblk(jc, tmp);
338   else if (c == POS1 || (!sond && c == CtrlA)) jc = 0;
339   else if (c == ENDE || (!sond && c == CtrlE)) jc = l;
340   else if (c == AltJ || c == F9) sond = !sond;
341   else if (c == PASTE || c == ShiftEin || c == CtrlV || c == AltEin)
342   {
343    int len = WpeEditor->f[0]->b->bf[0].len;
344 #ifndef NO_XWINDOWS
345    if (WpeIsXwin() && c == AltEin)
346     e_cp_X_to_buffer(WpeEditor->f[WpeEditor->mxedt]);
347 #endif
348    if (first == 1)
349    {
350     tmp[0] = '\0';
351     l = 0;
352     jc = 0;
353    }
354    if (len + l > max) len = max - l;
355    for (i = l; i >= jc; i--)
356     tmp[i+len] = tmp[i];
357    for (i = jc; i < jc + len; i++)
358     tmp[i] = WpeEditor->f[0]->b->bf[0].s[i-jc];
359    jc += len;
360    l += len;
361   }
362   else if (c == WPE_DC && !sond)
363   {
364    if (jc > 0)
365    {
366     for (i = jc-1; i < l; i++)
367      tmp[i] = tmp[i+1];
368     jc--;
369     l--;
370    }
371   }
372   else if (c == ENTF || (!sond && c == CtrlD))
373   {
374    if (jc < l)
375    {
376     for (i = jc; i < l; i++)
377      tmp[i] = tmp[i+1];
378     l--;
379    }
380   }
381   else if (!sond && c == CtrlT)
382   {
383    c = e_su_lblk(jc, tmp) - jc;
384    {
385     for (i = jc; i <= l-c; i++)
386      tmp[i] = tmp[i+c];
387     l -= c;
388    }
389   }
390   else if (!sond && c == CtrlO)
391   {
392    if ((c = e_getch()) != CtrlT && toupper(c) != 'T') continue;
393    c = jc - e_su_rblk(jc, tmp);
394    {
395     for( i = jc-c; i <= l-c; i++)
396     tmp[i] = tmp[i+c];
397     jc -= c;
398     l -= c;
399    }
400   }
401   else if (first == 1 &&
402     ((c != WPE_CR && c != CtrlP && c != CtrlN && c != WPE_TAB &&
403     c != WPE_BTAB) || sond) && c > 0 && c < 0x7f)
404   {
405    tmp[0] = c;
406    tmp[1] = '\0';
407    l = 1;
408    jc = 1;
409   }
410   else if (((c != WPE_CR && c != WPE_TAB && c != WPE_BTAB && c != CtrlP &&
411     c != CtrlN ) || sond) && c > 0 && c < 0xff)
412   {
413    if (l < max)
414    {
415     for (i = l; i >= jc; i--) tmp[i+1] = tmp[i];tmp[jc] = c;
416     l++; jc++;
417    }
418   }
419   else if (c > 0)
420   {
421    if (c != WPE_ESC) strcpy(s, tmp);
422    FREE(tmp);fk_cursor(0);
423    if (c == CtrlP) c = CUP;
424    else if (c == CtrlN) c = CDO;
425    return(c);
426   }
427   for (jd = 0, i = ja; i < jc; i++) if(tmp[i] < ' ') jd++;
428   if (jc+jd-ja > n-3) ja=jc+jd-n+3 ;
429   else if (jc-ja < 0) ja = jc;
430 
431   e_schr_nchar(tmp, x, y, ja, n, ft);
432 
433   e_pr_char(x, y, ja > 0 ? MCL : ' ', ft);
434   e_pr_char(x+n-1, y, l-ja > n-2 ? MCR : ' ', ft);
435   fk_locate(x+jc+jd-ja+1, y);
436   first = 0;
437 #ifdef NEWSTYLE
438   e_make_xrect(x, y, x+n-1, y, 1);
439 #endif
440  }
441  fk_cursor(0);
442  return(c);
443 }
444 
e_schr_nzif(int num,int x,int y,int max,int col)445 int e_schr_nzif(int num, int x, int y, int max, int col)
446 {
447  char *str = MALLOC((max+1)*sizeof(char));
448  int i, nt;
449 
450  for (i = 0, nt = 1; i < max; i++) nt *= 10;
451  if (num >= nt)
452   num = nt - 1;
453  e_pr_zstring(WpeNumberToString(num, max, str), x, y, max, col);
454  FREE(str);
455  return(0);
456 }
457 
458