1 /* we_unix.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 "model.h"		/* exchange for D.S.  */
8 
9 #ifdef XWPE_DLL
10 #include <dlfcn.h>
11 #else
12 int WpeXtermInit(int *argc, char **argv);
13 int WpeTermInit(int *argc, char **argv);
14 #endif
15 
16 #include <termios.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <sys/wait.h>
20 #include <dirent.h>
21 #include <signal.h>
22 #include <locale.h>
23 #ifndef TERMCAP
24 #ifndef DJGPP
25 #include<curses.h>
26 #endif
27 #endif
28 
29 #include "edit.h"		/*   exchange for D.S.  */
30 #include "attrb.h"
31 
32 #ifdef NOSYMLINKS
33 #define lstat(x,y)  stat(x,y)
34 #undef S_ISLNK
35 #define S_ISLNK(x)  0
36 #endif
37 
38 
39 char *schirm = NULL;
40 char e_we_sw = 0;
41 
42 void WpeSignalUnknown(int sig);
43 void WpeSignalChild(int sig);
44 
45 void (*WpeMouseChangeShape)(WpeMouseShape new_shape);
46 void (*WpeMouseRestoreShape)(void);
47 void (*WpeDisplayEnd)(void);
48 int (*fk_u_locate)(int x, int y);
49 int (*fk_u_cursor)(int x);
50 int (*e_u_initscr)(int argc, char *argv[]);
51 int (*fk_u_putchar)(int c);
52 int (*u_bioskey)(void);
53 int (*e_frb_u_menue)(int sw, int xa, int ya, FENSTER *f, int md);
54 COLOR (*e_s_u_clr)(int f, int b);
55 COLOR (*e_n_u_clr)(int fb);
56 void (*e_pr_u_col_kasten)(int xa, int ya, int x, int y, FENSTER *f, int sw);
57 int (*fk_mouse)(int g[]);
58 int (*e_u_refresh)(void);
59 int (*e_u_getch)(void);
60 int (*e_u_sys_ini)(void);
61 int (*e_u_sys_end)(void);
62 int (*e_u_system)(const char *exe);
63 int (*e_make_urect)(int xa, int ya, int xe, int ye, int sw);
64 int (*e_make_urect_abs)(int xa, int ya, int xe, int ye, int sw);
65 int (*e_u_d_switch_out)(int sw);
66 int (*e_u_switch_screen)(int sw);
67 int (*e_u_deb_out)(struct FNST *f);
68 int (*e_u_cp_X_to_buffer)(struct FNST *f);
69 int (*e_u_copy_X_buffer)(struct FNST *f);
70 int (*e_u_paste_X_buffer)(struct FNST *f);
71 int (*e_u_kbhit)(void);
72 int (*e_u_change)(PIC *pic);
73 int (*e_u_ini_size)(void);
74 int (*e_get_pic_urect)(int xa, int ya, int xe, int ye, struct PICSTR *pic);
75 int (*e_u_s_sys_end)(void);
76 int (*e_u_s_sys_ini)(void);
77 void (*e_u_setlastpic)(PIC *pic);
78 
79 FARBE *u_fb, *x_fb;
80 
81 char MCI, MCA, RD1, RD2, RD3, RD4, RD5, RD6, WBT;
82 char RE1, RE2, RE3, RE4, RE5, RE6;
83 char *ctree[5];
84 int MENOPT = 8;
85 int e_mn_men = 3;
86 
87 int MAXSLNS = 24;
88 int MAXSCOL = 80;
89 int col_num = 0;
90 char *att_no;
91 struct termios otermio, ntermio, ttermio;
92 int cur_x = -1, cur_y = -1;
93 void *libxwpe;
94 
95 #ifdef NEWSTYLE
96 char *extbyte = NULL, *altextbyte = NULL;
97 #endif
98 char *altschirm = NULL;
99 PIC *e_X_l_pic = NULL;
100 
WpeNullFunction(void)101 void WpeNullFunction(void)
102 {
103 }
104 
WpeZeroFunction(void)105 int WpeZeroFunction(void)
106 {
107  return(0);
108 }
109 
e_ini_unix(int * argc,char ** argv)110 int e_ini_unix(int *argc, char **argv)
111 {
112  extern OPT opt[];
113  int i, debug;
114  struct sigaction act;
115  int (*initfunc)(int *argc, char **argv);
116 
117  setlocale(LC_ALL, "");
118  u_fb = NULL;
119  x_fb = NULL;
120  debug = 0;
121  for (i = 1; i < *argc; i++)
122  {
123   if (strcmp("--debug", argv[i]) == 0)
124   {
125    debug = 1;
126   }
127  }
128  for (i = strlen(argv[0])-1; i >= 0 && *(argv[0] + i) != DIRC; i--)
129   ;
130 #ifndef NO_XWINDOWS
131  if (*(argv[0]+i+1) == 'x')
132   e_we_sw = 1;
133  else
134   e_we_sw = 0;
135 #endif
136 #ifdef PROG
137  if (!strncmp("wpe", (argv[0] + i + e_we_sw + 1), 3))
138   e_we_sw |= 2;
139 #endif
140 #ifdef XWPE_DLL
141  if (WpeIsXwin())
142  {
143   libxwpe = dlopen(LIBRARY_DIR"/libxwpe-x11.so", RTLD_NOW);
144  }
145  else
146  {
147   libxwpe = dlopen(LIBRARY_DIR"/libxwpe-term.so",RTLD_NOW);
148  }
149  if (!libxwpe)
150  {
151   printf("%s\n", dlerror());
152   exit(0);
153  }
154  initfunc = dlsym(libxwpe, "WpeDllInit");
155  if (initfunc)
156  {
157   (*initfunc)(argc, argv);
158  }
159  else
160  {
161   printf("%s\n", dlerror());
162   exit(0);
163  }
164 #else
165 #ifndef NO_XWINDOWS
166  if (WpeIsXwin())
167  {
168   WpeXtermInit(argc, argv);
169  }
170  else
171 #endif
172  {
173   WpeTermInit(argc, argv);
174  }
175 #endif
176  if (WpeIsProg())
177  {
178 #ifndef DEBUGGER
179   opt[0].x = 2, opt[1].x = 7, opt[2].x = 14; opt[3].x = 21; opt[4].x = 30;
180   opt[9].t = opt[7].t; opt[9].x = 74; opt[9].s = opt[7].s; opt[9].as = opt[7].as;
181   opt[8].t = opt[6].t; opt[8].x = 65; opt[8].s = opt[6].s; opt[8].as = opt[6].as;
182   opt[7].t = opt[5].t; opt[7].x = 55; opt[7].s = opt[5].s; opt[7].as = opt[5].as;
183   opt[6].t = "Project"; opt[6].x = 45; opt[6].s = 'P'; opt[6].as = AltP;
184   opt[5].t = "Run"; opt[5].x = 38; opt[5].s = 'R'; opt[5].as = AltR;
185   MENOPT = 10;
186   e_mn_men = 2;
187 #else
188   opt[0].x = 2, opt[1].x = 6, opt[2].x = 12; opt[3].x = 18; opt[4].x = 26;
189   opt[10].t = opt[7].t; opt[10].x = 74; opt[10].s = opt[7].s; opt[10].as = opt[7].as;
190   opt[9].t = opt[6].t; opt[9].x = 65; opt[9].s = opt[6].s; opt[9].as = opt[6].as;
191   opt[8].t = opt[5].t; opt[8].x = 56; opt[8].s = opt[5].s; opt[8].as = opt[5].as;
192   opt[7].t = "Project"; opt[7].x = 47; opt[7].s = 'P'; opt[7].as = AltP;
193   opt[6].t = "Debug"; opt[6].x = 40; opt[6].s = 'D'; opt[6].as = AltD;
194   opt[5].t = "Run"; opt[5].x = 34; opt[5].s = 'R'; opt[5].as = AltR;
195   MENOPT = 11;
196   e_mn_men = 1;
197 #endif
198  }
199 
200  /* Unknown error signal handling */
201  act.sa_handler = WpeSignalUnknown;
202  sigfillset(&act.sa_mask); /* Mask all signals while running */
203  act.sa_flags = 0;
204  if (!debug)
205  {
206   sigaction(SIGQUIT, &act, NULL);
207   sigaction(SIGILL, &act, NULL);
208   sigaction(SIGABRT, &act, NULL);
209   sigaction(SIGFPE, &act, NULL);
210   sigaction(SIGSEGV, &act, NULL);
211 #ifdef SIGTRAP
212   sigaction(SIGTRAP, &act, NULL);
213 #endif
214 #ifdef SIGIOT
215   sigaction(SIGIOT, &act, NULL);
216 #endif
217 #ifdef SIGBUS
218   sigaction(SIGBUS, &act, NULL);
219 #endif
220  }
221  /* Ignore SIGINT */
222  act.sa_handler = SIG_IGN;
223  sigaction(SIGINT, &act, NULL);
224  /* Catch SIGCHLD */
225  act.sa_handler = WpeSignalChild;
226  act.sa_flags = SA_NOCLDSTOP;
227  sigaction(SIGCHLD, &act, NULL);
228  return(*argc);
229 }
230 
e_abs_refr()231 int e_abs_refr()
232 {
233  extern char *altschirm;
234  int i;
235 
236  for(i = 0; i < 2 * MAXSCOL * MAXSLNS; i++)
237   altschirm[i] = 0;
238  return(0);
239 }
240 
e_refresh_area(int x,int y,int width,int height)241 void e_refresh_area(int x, int y, int width, int height)
242 {
243  extern char *altschirm;
244  char *curloc;
245  int i,j;
246 
247  if (width + x > MAXSCOL)
248  {
249   width = MAXSCOL - x;
250  }
251  if (height + y > MAXSLNS)
252  {
253   height = MAXSLNS - y;
254  }
255  curloc = altschirm + ((x + (y * MAXSCOL)) * 2);
256  for (j = 0; j < height; j++, curloc += MAXSCOL * 2)
257  {
258   for (i = 0; i < width; i ++)
259   {
260    curloc[i * 2] = 0;
261    curloc[i * 2 + 1] = 0;
262   }
263  }
264 }
265 
e_tast_sim(int c)266 int e_tast_sim(int c)
267 {
268  if (c >= 'A' && c <= 'Z')
269   return(c + 1024 - 'A');
270  switch(c)
271  {
272   case 'a':  return(AltA);
273   case 'b':  return(AltB);
274   case 'c':  return(AltC);
275   case 'd':  return(AltD);
276   case 'e':  return(AltE);
277   case 'f':  return(AltF);
278   case 'g':  return(AltG);
279   case 'h':  return(AltH);
280   case 'i':  return(AltI);
281   case 'j':  return(AltJ);
282   case 'k':  return(AltK);
283   case 'l':  return(AltL);
284   case 'm':  return(AltM);
285   case 'n':  return(AltN);
286   case 'o':  return(AltO);
287   case 'p':  return(AltP);
288   case 'q':  return(AltQ);
289   case 'r':  return(AltR);
290   case 's':  return(AltS);
291   case 't':  return(AltT);
292   case 'u':  return(AltU);
293   case 'v':  return(AltV);
294   case 'w':  return(AltW);
295   case 'x':  return(AltX);
296   case 'y':  return(AltY);
297   case 'z':  return(AltZ);
298   case '1':  return(Alt1);
299   case '2':  return(Alt2);
300   case '3':  return(Alt3);
301   case '4':  return(Alt4);
302   case '5':  return(Alt5);
303   case '6':  return(Alt6);
304   case '7':  return(Alt7);
305   case '8':  return(Alt8);
306   case '9':  return(Alt9);
307   case '0':  return(Alt0);
308   case ' ':  return(AltBl);
309   case '#':  return(AltSYS);
310   case CtrlA:  return(CBUP);
311   case CtrlE:  return(CBDO);
312   case CtrlB:  return(CCLE);
313   case CtrlF:  return(CCRI);
314   case CtrlP:  return(CPS1);
315   case CtrlN:  return(CEND);
316   case CtrlH:  return(AltBS);
317   default:  return(0);
318  }
319 }
320 
WpeSignalUnknown(int sig)321 void WpeSignalUnknown(int sig)
322 {
323 /*    psignal(sig, "Xwpe");   */
324  printf("Xwpe: unexpected signal %d, exiting ...\n", sig);
325  e_exit(1);
326 }
327 
WpeSignalChild(int sig)328 void WpeSignalChild(int sig)
329 {
330  int statloc;
331 
332  wait(&statloc);
333 }
334 
335 static int e_bool_exit = 0;
336 
e_err_save()337 void e_err_save()
338 {
339  ECNT *cn = WpeEditor;
340  int i;
341  long maxname;
342  FENSTER *f;
343  BUFFER *b;
344 
345  /* Quick fix to multiple emergency save problems */
346  if (e_bool_exit)
347   return ;
348  e_bool_exit = 1;
349  for (i = 0; i <= cn->mxedt; i++)
350  {
351   if (DTMD_ISTEXT(cn->f[i]->dtmd))
352   {
353    f = cn->f[i];
354    b = cn->f[i]->b;
355    if (b->mxlines > 1 || b->bf[0].len > 0)
356    {
357     /* Check if file system could have an autosave or emergency save file
358        >12 check is to eliminate dos file systems */
359     if ((maxname = pathconf(f->dirct, _PC_NAME_MAX) >= strlen(f->datnam) + 4) &&
360       (maxname > 12))
361     {
362      strcat(f->datnam, ".ESV");
363      printf("Try to save %s!\n", f->datnam);
364      if (!e_save(f))
365       printf("File %s saved!\n", f->datnam);
366     }
367    }
368   }
369  }
370 }
371 
e_exit(int n)372 void e_exit(int n)
373 {
374 #ifdef DEBUGGER
375  extern int e_d_pid;
376 
377  if (e_d_pid)
378   kill(e_d_pid, 7);
379 #endif
380  (*WpeDisplayEnd)();
381  e_switch_screen(0);
382  if (n != 0)
383  {
384   printf("\nError-Exit!   Code: %d!\n", n);
385   e_err_save();
386  }
387  exit(n);
388 }
389 
e_mkfilepath(char * dr,char * fn,char * fl)390 char *e_mkfilepath(char *dr, char *fn, char *fl)
391 {
392  strcpy(fl, dr);
393  if (dr[strlen(dr)-1] != DIRC)
394  {
395   strcat(fl, DIRS);
396  }
397  strcat(fl, fn);
398  return(fl);
399 }
400 
e_compstr(char * a,char * b)401 int e_compstr(char *a, char *b)
402 {
403  int n, k;
404  char *ctmp, *cp;
405 
406  if (a[0] == '*' && !a[1])
407   return(0);
408  if (!a[0] || !b[0])
409   return(a[0] - b[0]);
410  if (a[0] == '*' && a[1] == '*')
411   return(e_compstr(++a, b));
412  for (n = a[0] == '*' ? 2 : 1;
413    a[n] != '*' && a[n] != '?' && a[n] != '[' && a[n]; n++)
414   ;
415  if (a[0] == '*')
416  {
417   n--;
418   a++;
419   if (a[0] == '?')
420   {
421    cp = MALLOC((strlen(a)+1)*sizeof(char));
422    strcpy(cp, a);
423    cp[0] = '*';
424    n = e_compstr(cp, ++b);
425    FREE(cp);
426    return(n);
427   }
428   else if (a[0] == '[')
429   {
430    while (*b && (n = e_compstr(a, b)))
431     b++;
432    return(n);
433   }
434   ctmp = MALLOC(n+1);
435   for (k = 0; k < n; k++)
436    ctmp[k] = a[k];
437   ctmp[n] = '\0';
438   cp = strstr(b, ctmp);
439   FREE(ctmp);
440   if (cp == NULL)
441    return((a[0] - b[0]) ? a[0] - b[0] : -1);
442   if (!a[n] && !cp[n])
443    return(0);
444   if (!a[n])
445    return(e_compstr(a-1, cp+1));
446   if (!(k = e_compstr(a+n, cp+n)))
447    return(0);
448   return(e_compstr(a-1, cp+1));
449  }
450  else if (a[0] == '?')
451  {
452   n--;  a++;  b++;
453  }
454  else if (a[0] == '[')
455  {
456   if (a[1] == '!')
457   {
458    for (k = 2; a[k] && (a[k] != ']' || k == 2) && a[k] != b[0]; k++)
459     if (a[k+1] == '-' && b[0] >= a[k] && b[0] <= a[k+2])
460      return(-b[0]);
461    if (a[k] != ']')
462     return(-b[0]);
463    n-=(k+1);  a+=(k+1);  b++;
464   }
465   else
466   {
467    for (k = 1; a[k] && (a[k] != ']' || k == 1) && a[k] != b[0]; k++)
468     if (a[k+1] == '-' && b[0] >= a[k] && b[0] <= a[k+2])
469      break;
470    if (a[k] == ']' || a[k] == '\0')
471     return(-b[0]);
472    for (; a[k] && (a[k] != ']'); k++)
473     ;
474    n-=(k+1);  a+=(k+1);  b++;
475   }
476  }
477  if (n <= 0)
478   return(e_compstr(a, b));
479  if ((k = strncmp(a, b, n)) != 0)
480   return(k);
481  return(e_compstr(a+n, b+n));
482 }
483 
e_find_files(char * sufile,int sw)484 struct dirfile *e_find_files(char *sufile, int sw)
485 {
486  char           *stmp, *tmpst, *sfile, *sdir;
487  struct dirfile *df = MALLOC(sizeof(struct dirfile));
488  DIR            *dirp;
489  struct dirent  *dp;
490  struct stat     buf;
491  struct stat     lbuf;
492  int             i, n, cexist, sizeStmp, sizeSdir;
493 
494  df->name = NULL;
495  df->anz = 0;
496  for (n = strlen(sufile); n >= 0 && sufile[n] != DIRC; n--);
497  sfile = sufile + 1 + n;
498  if (n <= 0)
499  {
500   sizeSdir = 2;
501   sdir = (char *)WpeMalloc(2 * sizeof(char));
502   sdir[0] = n ? '.' : DIRC;
503   sdir[1] = '\0';
504  }
505  else
506  {
507   sizeSdir = n + 1;
508   sdir = (char *)WpeMalloc((n + 1) * sizeof(char));
509   for (i = 0; i < n; i++)
510    sdir[i] = sufile[i];
511   sdir[n] = '\0';
512  }
513  if (!(dirp = opendir(sdir)))
514  {
515   FREE(sdir);
516   return(df);
517  }
518  sizeStmp = 256;
519  stmp = (char *)WpeMalloc(sizeStmp);
520  while((dp = readdir(dirp)) != NULL)
521  {
522   if (!(sw & 1) && dp->d_name[0] == '.' && sfile[0] != '.')
523    continue;
524   if (!e_compstr(sfile, dp->d_name))
525   {
526    if (sizeSdir + strlen(dp->d_name) + 10 > sizeStmp)
527    {
528     while (sizeSdir + strlen(dp->d_name) + 10 > sizeStmp)
529      sizeStmp <<= 1;
530     stmp = (char *)WpeRealloc(stmp, sizeStmp);
531    }
532 
533    e_mkfilepath(sdir, dp->d_name, stmp);
534    lstat(stmp, &lbuf);
535    stat(stmp, &buf);
536 
537    /* check existence of the file */
538    cexist = access(stmp, F_OK);
539 
540    /* we accept it as a file if
541       - a regular file
542       - link and it does not point to anything
543       - link and it points to a non-directory */
544    if ((S_ISREG(buf.st_mode) ||
545      (S_ISLNK(lbuf.st_mode) &&
546      (cexist || (cexist == 0 && !S_ISDIR(buf.st_mode))))) &&
547      (!(sw & 2) || (buf.st_mode & 0111)) )
548    {
549     if (df->anz == 0)
550      df->name = MALLOC((df->anz + 1) * sizeof(char *));
551     else
552      df->name = REALLOC(df->name, (df->anz + 1) * sizeof(char *));
553     if (df->name == NULL || !(tmpst = MALLOC(strlen(dp->d_name) + 1)))
554     {
555      df->anz = 0;
556      closedir(dirp);
557      WpeFree(stmp);
558      WpeFree(sdir);
559      return(df);
560     }
561     strcpy(tmpst, dp->d_name);
562     for (n = df->anz; n > 0 && strcmp(*(df->name + n - 1), tmpst) > 0; n--)
563      *(df->name + n) = *(df->name + n - 1);
564     *(df->name + n) = tmpst;
565     (df->anz)++;
566    }
567   }
568  }
569  closedir(dirp);
570  WpeFree(stmp);
571  WpeFree(sdir);
572  return(df);
573 }
574 
e_find_dir(char * sufile,int sw)575 struct dirfile *e_find_dir(char *sufile, int sw)
576 {
577  char           *stmp, *tmpst, *sfile, *sdir;
578  struct dirfile *df = MALLOC(sizeof(struct dirfile));
579  DIR            *dirp;
580  struct dirent  *dp;
581  struct stat     buf;
582  int             i, n, sizeStmp, sizeSdir;
583 
584  df->name = NULL;
585  df->anz = 0;
586  for (n = strlen(sufile); n >= 0 && sufile[n] != DIRC; n--);
587  sfile = sufile + 1;
588  sfile = sfile + n;
589  if (n <= 0)
590  {
591   sizeSdir = 2;
592   sdir = MALLOC(2 * sizeof(char));
593   sdir[0] = n ? '.' : DIRC;
594   sdir[1] = '\0';
595  }
596  else
597  {
598   sizeSdir = n + 1;
599   sdir = MALLOC((n + 1) * sizeof(char));
600   for (i = 0; i < n; i++)
601    sdir[i] = sufile[i];
602   sdir[n] = '\0';
603  }
604  if (!(dirp = opendir(sdir)))
605  {
606   FREE(sdir);
607   return(df);
608  }
609  sizeStmp = 256;
610  stmp = (char *)WpeMalloc(sizeStmp);
611  while ((dp = readdir(dirp)) != NULL)
612  {
613   if (!sw && dp->d_name[0] == '.' && sfile[0] != '.')
614    continue;
615   if (!e_compstr(sfile, dp->d_name) && strcmp(dp->d_name, ".") &&
616     strcmp(dp->d_name, ".."))
617   {
618    if (sizeSdir + strlen(dp->d_name) + 10 > sizeStmp)
619    {
620     while (sizeSdir + strlen(dp->d_name) + 10 > sizeStmp)
621      sizeStmp <<= 1;
622     stmp = (char *)WpeRealloc(stmp, sizeStmp);
623    }
624    stat(e_mkfilepath(sdir, dp->d_name, stmp), &buf);
625 
626    /* we accept _only_ real, existing directories */
627    if (S_ISDIR(buf.st_mode))
628    {
629 
630     if (df->anz == 0)
631      df->name = MALLOC((df->anz + 1) * sizeof(char *));
632     else
633      df->name = REALLOC(df->name, (df->anz + 1) * sizeof(char *));
634     if (df->name == NULL || !(tmpst = MALLOC(strlen(dp->d_name) + 1)))
635     {
636      df->anz = 0;
637      closedir(dirp);
638      FREE(sdir);
639      WpeFree(stmp);
640      return(df);
641     }
642     strcpy(tmpst, dp->d_name);
643     for (n = df->anz; n > 0 && strcmp(*(df->name + n - 1), tmpst) > 0; n--)
644      *(df->name + n) = *(df->name + n - 1);
645     *(df->name + n) = tmpst;
646     (df->anz)++;
647    }
648   }
649  }
650  closedir(dirp);
651  FREE(sdir);
652  WpeFree(stmp);
653  return(df);
654 }
655 
656 #include <time.h>
657 
e_file_info(char * filen,char * str,int * num,int sw)658 char *e_file_info(char *filen, char *str, int *num, int sw)
659 {
660  struct tm *ttm;
661  struct stat buf[1];
662 
663  stat(filen, buf);
664  ttm = localtime(&(buf->st_mtime));
665  sprintf(str, "%c%c%c%c%c%c%c%c%c%c  %-13s  %6ld  %2.2u.%2.2u.%4.4u  %2.2u.%2.2u",
666    buf->st_mode & 040000 ? 'd' : '-',
667    buf->st_mode & 0400 ? 'r' : '-',
668    buf->st_mode & 0200 ? 'w' : '-',
669    buf->st_mode & 0100 ? 'x' : '-',
670    buf->st_mode & 040 ? 'r' : '-',
671    buf->st_mode & 020 ? 'w' : '-',
672    buf->st_mode & 010 ? 'x' : '-',
673    buf->st_mode & 04 ? 'r' : '-',
674    buf->st_mode & 02 ? 'w' : '-',
675    buf->st_mode & 01 ? 'x' : '-',
676    filen,
677    buf->st_size, ttm->tm_mday,
678    ttm->tm_mon + 1, ttm->tm_year + 1900, ttm->tm_hour, ttm->tm_min);
679  if (sw & 1) *num = buf->st_mtime;
680  else if (sw & 2) *num = buf->st_size;
681  return(str);
682 }
683 
ini_repaint(ECNT * cn)684 void ini_repaint(ECNT *cn)
685 {
686  e_cls(cn->fb->df.fb, cn->fb->dc);
687  e_ini_desk(cn);
688 }
689 
end_repaint()690 void end_repaint()
691 {
692    e_refresh();
693 }
694 
e_recover(ECNT * cn)695 int e_recover(ECNT *cn)
696 {
697  struct dirfile *files;
698  FENSTER *f = NULL;
699  BUFFER *b;
700  SCHIRM *s;
701  int i;
702 
703  files = e_find_files("*.ESV", 1);
704  for (i = 0; i < files->anz; i++)
705  {
706   e_edit(cn, files->name[i]);
707   f = cn->f[cn->mxedt];
708   f->datnam[strlen(f->datnam)-4] = '\0';
709   if (!strcmp(f->datnam, BUFFER_NAME))
710   {
711    s = cn->f[cn->mxedt]->s;
712    b = cn->f[cn->mxedt]->b;
713    s->mark_end.y = b->mxlines - 1;
714    s->mark_end.x = b->bf[b->mxlines-1].len;
715    e_edt_copy(f);
716    e_close_window(f);
717   }
718   else f->save = 1;
719 #ifdef PROG
720   if (WpeIsProg()) e_add_synt_tl(f->datnam, f);
721 #endif
722   if ((f->ed->edopt & ED_ALWAYS_AUTO_INDENT) ||
723     ((f->ed->edopt & ED_SOURCE_AUTO_INDENT) && f->c_st))
724    f->flg = 1;
725  }
726  freedf(files);
727  return(0);
728 }
729 
e_frb_t_menue(int sw,int xa,int ya,FENSTER * f,int md)730 int e_frb_t_menue(int sw, int xa, int ya, FENSTER *f, int md)
731 {
732  COLOR *frb = &(f->fb->er);
733  int i, j, y, c=1, fb, fsv;
734 
735  if (md == 1) sw += 11;
736  else if (md == 2) sw += 16;
737  else if (md == 3) sw += 32;
738  fsv = fb = frb[sw].fb;
739  if (fb == 0) y = 0;
740  else
741   for (y = 1, j = fb; j > 1; y++)
742    j /= 2;
743  do
744  {
745   if (c == CDO) y = y < 6 ? y + 1 : 0;
746   else if (c == CUP) y = y > 0 ? y - 1 : 6;
747   if (y == 0) fb = 0;
748   else
749    for (i = 1, fb = 1; i < y; i++)
750     fb *= 2;
751   frb[sw] = e_n_clr(fb);
752   e_pr_t_col_kasten(xa, ya, fb, fb, f, 1);
753   e_pr_ed_beispiel(1, 2, f, sw, md);
754 #if  MOUSE
755   if ((c=e_getch()) == -1) c = e_opt_ck_mouse(xa, ya, md);
756 #else
757   c = e_getch();
758 #endif
759  } while (c != WPE_ESC && c != WPE_CR && c > -2);
760  if (c == WPE_ESC || c < -1) frb[sw] = e_n_clr(fsv);
761  return(frb[sw].fb);
762 }
763 
764 /*   draw colors box  */
e_pr_t_col_kasten(int xa,int ya,int x,int y,FENSTER * f,int sw)765 void e_pr_t_col_kasten(int xa, int ya, int x, int y, FENSTER * f, int sw)
766 {
767  int rfrb, xe = xa + 14, ye = ya + 8;
768 
769  if (x == 0) y = 0;
770  else
771   for (rfrb = x, y = 1; rfrb > 1; y++)
772    rfrb /= 2;
773  rfrb = sw == 0 ? f->fb->nt.fb : f->fb->fs.fb;
774  e_std_rahmen(xa, ya, xe, ye, "Colors", 0, rfrb, 0);
775 /*     e_pr_str((xa+xe-8)/2, ya, "Colors", rfrb, 0, 1,
776                                         f->fb->ms.f+16*(rfrb/16), 0);
777 */
778  e_pr_nstr(xa+2, ya+1, xe-xa-1, "A_NORMAL   ", 0, 0);
779  e_pr_nstr(xa+2, ya+2, xe-xa-1, "A_STANDOUT ", A_STANDOUT, A_STANDOUT);
780  e_pr_nstr(xa+2, ya+3, xe-xa-1, "A_UNDERLINE", A_UNDERLINE, A_UNDERLINE);
781  e_pr_nstr(xa+2, ya+4, xe-xa-1, "A_REVERSE  ", A_REVERSE, A_REVERSE);
782  e_pr_nstr(xa+2, ya+5, xe-xa-1, "A_BLINK    ", A_BLINK, A_BLINK);
783  e_pr_nstr(xa+2, ya+6, xe-xa-1, "A_DIM      ", A_DIM, A_DIM);
784  e_pr_nstr(xa+2, ya+7, xe-xa-1, "A_BOLD     ", A_BOLD, A_BOLD);
785 
786  fk_locate(xa+4, ya + y + 1);
787 }
788 
789