1 /* we_prog.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 "messages.h"
8 #include "edit.h"
9 #include "WeExpArr.h"
10
11 #ifdef PROG
12
13 #include <time.h>
14 #include <fcntl.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <sys/wait.h>
18 #include <signal.h>
19 #if (defined(__unix__) || defined(unix)) && !defined(USG)
20 #include <sys/param.h>
21 #endif
22
23 int e_run_sh(FENSTER *f);
24 int e_make_library(char *library, char *ofile, FENSTER *f);
25 int e_p_exec(int file, FENSTER *f, PIC *pic);
26 struct dirfile **e_make_prj_opt(FENSTER *f);
27
28 int wfildes[2], efildes[2];
29 char *wfile = NULL, *efile = NULL;
30
31 struct e_s_prog e_s_prog = { NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0};
32
33 struct e_prog e_prog = { 0, NULL, NULL, NULL, NULL, NULL };
34
35 struct ERR_LI { char *file, *text, *srch; int x, y, line; } *err_li = NULL;
36 int err_no, err_num;
37
38 int e__project = 0, e_argc, e_p_l_comp;
39 char **e_arg = NULL;
40 char *e__arguments = NULL;
41 M_TIME last_time;
42 char library[80];
43 int e_save_pid;
44 struct dirfile **e_p_df;
45
46 extern BUFFER *e_p_m_buffer;
47 extern char *e_tmp_dir;
48 #ifdef DEBUGGER
49 extern int e_d_swtch;
50 #endif
51
52 /********************************************************/
53 /**** defs for breakpoints and watches manipulations ****/
54 /*** breakpoints ***/
55 extern int e_d_nbrpts;
56 extern char ** e_d_sbrpts;
57 extern int * e_d_ybrpts;
58
59 /*** watches ***/
60 extern int e_d_nwtchs;
61 extern char ** e_d_swtchs;
62 extern int * e_d_nrwtchs;
63
64 /********************************************************/
65
66 char *gnu_intstr = "${?*:warning:}${FILE}:${LINE}:* before `${COLUMN=BEFORE}\'*";
67 char *cc_intstr = "${?*:warning:}\"${FILE}\", line ${LINE}:* at or near * \"${COLUMN=AFTER}\"";
68 char *pc_intstr = "${?0:e}${?0:w}${?0:s}*:*:* * ${FILE}:\n\n* ${LINE} ${CMPTEXT}\n*-------\
69 ${COLUMN=PREVIOUS?^+14}\n[EWew] * line*";
70
71
72 char *e_p_msg[] = {
73 "Not a C - File",
74 "Can\'t open Pipe",
75 "Error in Process",
76 "Error in Pipe\n Pipe Nr.: %d\n",
77 "Error at Command: ",
78 "Return-Code: %d", /* Number 5 */
79 "%s is not a C - File",
80 "No Compiler specified",
81 "No Files to compile",
82 "No Project-Window",
83 };
84
85
e_prog_switch(FENSTER * f,int c)86 int e_prog_switch(FENSTER *f, int c)
87 {
88 switch(c)
89 {
90 case AltU:
91 case CF9:
92 e_run(f);
93 break;
94 case AltM: /* Alt M Make */
95 case F9:
96 e_p_make(f);
97 break;
98 case AltC: /* Alt C Compile */
99 case AF9:
100 e_compile(f);
101 break;
102 case AltL: /* Alt L InstaLl */
103 e_install(f);
104 break;
105 case AltA: /* Alt A Execute MAke */
106 e_exec_make(f);
107 break;
108 case AltT: /* Alt T NexT Error */
109 case AF8:
110 e_next_error(f);
111 break;
112 case AltV: /* Alt V PreVious Error */
113 case AF7:
114 e_previous_error(f);
115 break;
116 #ifdef DEBUGGER
117 case CtrlG: /* Ctrl G DebuG - Modus */
118 e_deb_inp(f);
119 break;
120 default:
121 return(e_debug_switch(f, c));
122 #else
123 default:
124 return(c);
125 #endif
126 }
127 return(0);
128 }
129
e_compile(FENSTER * f)130 int e_compile(FENSTER *f)
131 {
132 int ret;
133
134 WpeMouseChangeShape(WpeWorkingShape);
135 efildes[0] = efildes[1] = -1;
136 wfildes[0] = wfildes[1] = -1;
137 ret = e_comp(f);
138 WpeMouseRestoreShape();
139 return(ret);
140 }
141
e_p_make(FENSTER * f)142 int e_p_make(FENSTER *f)
143 {
144 ECNT *cn = f->ed;
145 char ostr[128], estr[128], mstr[80];
146 int len, i, file = -1;
147 struct stat cbuf[1], obuf[1];
148 PIC *pic = NULL;
149 int linkRequest = 1; /* assume linking has to be done */
150
151 WpeMouseChangeShape(WpeWorkingShape);
152 efildes[0] = efildes[1] = -1;
153 wfildes[0] = wfildes[1] = -1;
154 if (e_comp(f))
155 {
156 WpeMouseRestoreShape();
157 return(-1);
158 }
159 f = cn->f[cn->mxedt-1];
160 if (!e__project)
161 {
162 e_arg = MALLOC(6 * sizeof(char *));
163 e_argc = e_make_arg(&e_arg, e_s_prog.libraries);
164 e_arg[1] = MALLOC(3);
165 strcpy(e_arg[1], "-o");
166 strcpy(mstr, f->datnam);
167 WpeStringCutChar(mstr, '.');
168 len = strlen(e_prog.exedir) - 1;
169 if (e_s_prog.exe_name && e_s_prog.exe_name[0])
170 {
171 if (e_prog.exedir[len] == DIRC)
172 sprintf(estr, "%s%s", e_prog.exedir, e_s_prog.exe_name);
173 else
174 sprintf(estr, "%s%c%s", e_prog.exedir, DIRC, e_s_prog.exe_name);
175 }
176 else
177 {
178 if (e_prog.exedir[len] == DIRC)
179 sprintf(estr, "%s%s.e", e_prog.exedir, mstr);
180 else
181 sprintf(estr, "%s%c%s.e", e_prog.exedir, DIRC, mstr);
182 }
183 if (e_prog.exedir[len] == DIRC)
184 sprintf(ostr, "%s%s.o", e_prog.exedir, mstr);
185 else
186 sprintf(ostr, "%s%c%s.o", e_prog.exedir, DIRC, mstr);
187 e_argc = e_add_arg(&e_arg, estr, 2, e_argc);
188 e_argc = e_add_arg(&e_arg, ostr, 3, e_argc);
189 stat(ostr, cbuf);
190 if (!stat(estr, obuf) && obuf->st_mtime >= cbuf->st_mtime)
191 linkRequest = 0;
192 }
193 else
194 {
195 if (!stat(e_s_prog.exe_name, obuf) && !e_p_l_comp &&
196 obuf->st_mtime >= last_time)
197 linkRequest = 0;
198 }
199 if (linkRequest)
200 {
201 #ifdef DEBUGGER
202 if (e_d_swtch > 0)
203 e_d_quit(f);
204 #endif
205 if (!e_p_mess_win("Linking", e_argc, e_arg, &pic, f))
206 {
207 e_sys_ini();
208 file = e_exec_inf(f, e_arg, e_argc);
209 e_sys_end();
210 }
211 else
212 file = 0;
213 }
214 if (!e__project)
215 {
216 e_free_arg(e_arg, e_argc);
217 }
218 if (file != 0)
219 i = e_p_exec(file, f, pic);
220 else
221 {
222 i = WPE_ESC;
223 if (pic)
224 e_close_view(pic, 1);
225 }
226 WpeMouseRestoreShape();
227 return(i);
228 }
229
e_run(FENSTER * f)230 int e_run(FENSTER *f)
231 {
232 ECNT *cn = f->ed;
233 BUFFER *b;
234 SCHIRM *s;
235 char estr[256];
236 int len, ret;
237
238 efildes[0] = efildes[1] = -1;
239 wfildes[0] = wfildes[1] = -1;
240 if (!e_run_sh(f))
241 return(0);
242 if (e_p_make(f))
243 return(-1);
244 WpeMouseChangeShape(WpeWorkingShape);
245 f = cn->f[cn->mxedt-1];
246 #ifdef DEBUGGER
247 if (e_d_swtch > 0)
248 e_d_quit(f);
249 #endif
250 estr[0] = '\0';
251 if ((!e_s_prog.exe_name) || (e_s_prog.exe_name[0]!=DIRC))
252 {
253 strcat(estr, e_prog.exedir);
254 len = strlen(estr) - 1;
255 if (estr[len] != DIRC)
256 {
257 estr[++len] = DIRC;
258 estr[++len] = '\0';
259 }
260 }
261 if (e_s_prog.exe_name && e_s_prog.exe_name[0])
262 {
263 strcat(estr, e_s_prog.exe_name);
264 }
265 else if (!e__project)
266 {
267 /* Default executable name of the source file - extension + ".e" */
268 strcat(estr, f->datnam);
269 WpeStringCutChar(estr, '.');
270 strcat(estr, ".e");
271 }
272 else /* Default project executable name of "a.out" */
273 strcat(estr, "a.out");
274 strcat(estr, " ");
275 if (e_prog.arguments)
276 strcat(estr, e_prog.arguments);
277 #ifndef NO_XWINDOWS
278 if (WpeIsXwin())
279 ret = (*e_u_system)(estr);
280 else
281 #endif
282 ret = e_system(estr, cn);
283 f = cn->f[cn->mxedt];
284 b = cn->f[cn->mxedt]->b;
285 s = cn->f[cn->mxedt]->s;
286
287 sprintf(estr, e_p_msg[ERR_RETCODE], ret);
288 print_to_end_of_buffer(b, estr, b->mx.x);
289
290 b->b.y = b->mxlines-1;
291 e_cursor(f, 1);
292 e_schirm(f, 1);
293 e_refresh();
294 WpeMouseRestoreShape();
295 return(0);
296 }
297
e_comp(FENSTER * f)298 int e_comp(FENSTER *f)
299 {
300 ECNT *cn = f->ed;
301 PIC *pic = NULL;
302 char **arg = NULL, fstr[128], ostr[128];
303 int i, file = -1, len, argc;
304 #ifdef CHECKHEADER
305 struct stat obuf[1];
306 #else
307 struct stat cbuf[1], obuf[1];
308 #endif
309
310 #ifdef DEBUGGER
311 if (e_d_swtch > 0)
312 {
313 i = e_message(1, "The Debugger is Running\nDo You want to Quit Debugging ?",f);
314 if (i == 'Y')
315 e_d_quit(f);
316 else
317 return(-1);
318 WpeMouseChangeShape(WpeWorkingShape);
319 }
320 #endif
321 if (e_prog.project[0] && !access(e_prog.project, 0))
322 e__project = 1;
323 else
324 e__project = 0;
325 if (e__project)
326 return(e_c_project(f));
327 for (i = cn->mxedt; i > 0; i--)
328 {
329 if (e_check_c_file(cn->f[i]->datnam))
330 break;
331 }
332 if (i == 0)
333 {
334 sprintf(ostr, e_p_msg[ERR_S_NO_CFILE], f->datnam);
335 e_error(ostr, 0, f->fb);
336 return(WPE_ESC);
337 }
338 else if (cn->f[i]->save)
339 e_save(cn->f[i]);
340 f = cn->f[i];
341 e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
342 if (e_new_message(f))
343 return(WPE_ESC);
344 argc = e_make_arg(&arg, e_s_prog.comp_str);
345 arg[1] = MALLOC(3);
346 strcpy(arg[1], "-c");
347 len = strlen(f->dirct) - 1;
348 if (!strcmp(f->ed->dirct, f->dirct))
349 strcpy(fstr, f->datnam);
350 if (f->dirct[len] == DIRC)
351 sprintf(fstr, "%s%s", f->dirct, f->datnam);
352 else
353 sprintf(fstr, "%s%c%s", f->dirct, DIRC, f->datnam);
354 argc = e_add_arg(&arg, fstr, argc, argc);
355 if (e_prog.exedir[strlen(e_prog.exedir)-1] == DIRC)
356 sprintf(ostr, "%s%s", e_prog.exedir, f->datnam);
357 else
358 sprintf(ostr, "%s%c%s", e_prog.exedir, DIRC, f->datnam);
359 WpeStringCutChar(ostr, '.');
360 strcat(ostr, ".o");
361 #ifndef NO_MINUS_C_MINUS_O
362 argc = e_add_arg(&arg, "-o", argc, argc);
363 argc = e_add_arg(&arg, ostr, argc, argc);
364 #endif
365 e_sys_ini();
366 #ifdef CHECKHEADER
367 if ((stat(ostr, obuf) || e_check_header(fstr, obuf->st_mtime, cn, 0)))
368 #else
369 stat(f->datnam, cbuf);
370 if ((stat(ostr, obuf) || obuf->st_mtime < cbuf->st_mtime))
371 #endif
372 {
373 remove(ostr);
374 if (!e_p_mess_win("Compiling", argc, arg, &pic, f) &&
375 (file = e_exec_inf(f, arg, argc)) == 0)
376 {
377 e_sys_end();
378 e_free_arg(arg, argc);
379 if (pic)
380 e_close_view(pic, 1);
381 return(WPE_ESC);
382 }
383 }
384 e_sys_end();
385 e_free_arg(arg, argc);
386 i = e_p_exec(file, f, pic);
387 return(i);
388 }
389
e_exec_inf(FENSTER * f,char ** argv,int n)390 int e_exec_inf(FENSTER *f, char **argv, int n)
391 {
392 int pid;
393 char tstr[128];
394 #ifdef DEBUGGER
395 if (e_d_swtch > 0)
396 e_d_quit(f);
397 #endif
398 fflush(stdout);
399 sprintf(tstr, "%s/we_111", e_tmp_dir);
400 if((efildes[1] = creat(tstr, 0777)) < 0)
401 {
402 e_error(e_p_msg[ERR_PIPEOPEN], 0, f->fb);
403 return(0);
404 }
405 if((efildes[0] = open(tstr, O_RDONLY)) < 0 )
406 {
407 e_error(e_p_msg[ERR_PIPEOPEN], 0, f->fb);
408 return(0);
409 }
410 efile = MALLOC((strlen(tstr)+1)*sizeof(char));
411 strcpy(efile, tstr);
412 sprintf(tstr, "%s/we_112", e_tmp_dir);
413 if((wfildes[1] = creat(tstr, 0777)) < 0)
414 {
415 e_error(e_p_msg[ERR_PIPEOPEN], 0, f->fb);
416 return(0);
417 }
418 if((wfildes[0] = open(tstr, O_RDONLY)) < 0 )
419 {
420 e_error(e_p_msg[ERR_PIPEOPEN], 0, f->fb);
421 return(0);
422 }
423 wfile = MALLOC((strlen(tstr)+1)*sizeof(char));
424 strcpy(wfile, tstr);
425
426 if((e_save_pid = pid = fork()) > 0)
427 return(efildes[1]);
428 else if(pid < 0)
429 {
430 e_error(e_p_msg[ERR_PROCESS], 0, f->fb);
431 return(0);
432 }
433
434 close(2); /* new process */
435 if(fcntl(efildes[1], F_DUPFD, 2) != 2)
436 {
437 fprintf(stderr, e_p_msg[ERR_PIPEEXEC], efildes[1]);
438 exit(1);
439 }
440 close(1);
441 if(fcntl(wfildes[1], F_DUPFD, 1) != 1)
442 {
443 fprintf(stderr, e_p_msg[ERR_PIPEEXEC], wfildes[1]);
444 exit(1);
445 }
446 e_print_arg(stderr, "", argv, n);
447 execvp(argv[0], argv);
448 e_print_arg(stderr, e_p_msg[ERR_IN_COMMAND], argv, n);
449 exit(1);
450 /* Can never get here */
451 return 0;
452 }
453
e_print_arg(FILE * fp,char * s,char ** argv,int n)454 int e_print_arg(FILE *fp, char *s, char **argv, int n)
455 {
456 int i;
457
458 if ((s) && (s[0]))
459 fprintf(fp,"%s ", s);
460 for (i = 0; i < n && argv[i] != NULL; i++)
461 fprintf(fp,"%s ", argv[i]);
462 fprintf(fp,"\n");
463 return(n);
464 }
465
e_p_exec(int file,FENSTER * f,PIC * pic)466 int e_p_exec(int file, FENSTER *f, PIC *pic)
467 {
468 ECNT *cn = f->ed;
469 BUFFER *b = cn->f[cn->mxedt]->b;
470 int ret = 0, i = 0, is, fd, stat_loc;
471 char str[128];
472 char *buff;
473
474 f = cn->f[cn->mxedt];
475 while ((ret = wait(&stat_loc)) >= 0 && ret != e_save_pid)
476 ;
477 ret = 0;
478 for (is = b->mxlines-1, fd = efildes[0]; fd > 0; fd = wfildes[0])
479 {
480 buff=MALLOC(1);
481 buff[0]='\0';
482 while( e_line_read(fd, str, 128) == 0 )
483 {
484 buff=REALLOC(buff, strlen(buff) + strlen(str) + 1);
485 strcat(buff, str);
486
487 fflush(stdout);
488 }
489 print_to_end_of_buffer(b, buff, b->mx.x);
490 FREE(buff);
491
492 if( fd == wfildes[0] )
493 break;
494 }
495 b->b.y = b->mxlines-1;
496 if (efildes[0] >= 0)
497 close(efildes[0]);
498 if (wfildes[0] >= 0)
499 close(wfildes[0]);
500 if (efildes[1] >= 0)
501 close(efildes[0]);
502 if (wfildes[1] >= 0)
503 close(wfildes[0]);
504 if (wfile)
505 {
506 remove(wfile);
507 FREE(wfile);
508 wfile = NULL;
509 }
510 if (efile)
511 {
512 remove(efile);
513 FREE(efile);
514 efile = NULL;
515 }
516 efildes[0] = efildes[1] = -1;
517 wfildes[0] = wfildes[1] = -1;
518 if (pic)
519 e_close_view(pic, 1);
520 if (ret || (b->mxlines - is > 2 && (i = e_make_error_list(f))))
521 {
522 if (i != -2 && !ret)
523 e_show_error(err_no = 0, f);
524 return(-1);
525 }
526
527 print_to_end_of_buffer(b, "Success", b->mx.x);
528
529 e_cursor(f, 1);
530 e_schirm(f, 1);
531 e_refresh();
532 return(0);
533 }
534
535 /* show source-position of error number "n" from actual errorlist */
e_show_error(int n,FENSTER * f)536 int e_show_error(int n, FENSTER *f)
537 {
538 ECNT *cn = f->ed;
539 BUFFER *b = cn->f[cn->mxedt]->b;
540 int i, j, bg = 0;
541 char *filename;
542 unsigned char *cp;
543
544 if (!err_li || n >= err_num || n < 0)
545 return(1);
546 f = cn->f[cn->mxedt];
547 if (err_li[n].file[0] == '.' && err_li[n].file[1] == DIRC)
548 bg = 2;
549 if (err_li[n].file[0] == DIRC)
550 {
551 filename = e_mkfilename(f->dirct, f->datnam);
552 }
553 else
554 filename = f->datnam;
555 if (strcmp(err_li[n].file+bg, filename))
556 {
557 for (i = cn->mxedt - 1; i > 0; i--)
558 {
559 if (filename != cn->f[i+1]->datnam)
560 {
561 FREE(filename);
562 filename = e_mkfilename(cn->f[i]->dirct, cn->f[i]->datnam);
563 }
564 else
565 filename = cn->f[i]->datnam;
566 if (!strcmp(err_li[n].file+bg, filename))
567 {
568 if (filename != cn->f[i]->datnam)
569 FREE(filename);
570 e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
571 break;
572 }
573 }
574 if (i <= 0)
575 {
576 if (filename != cn->f[i+1]->datnam)
577 FREE(filename);
578 if (e_edit(cn, err_li[n].file))
579 return(WPE_ESC);
580 }
581 }
582 else if (filename != f->datnam)
583 FREE(filename);
584 e_pr_str_wsd(1, MAXSLNS - 1, err_li[n].text, f->fb->mt.fb, -1, 0,
585 f->fb->mt.fb, 1, MAXSCOL-2);
586 /* e_pr_nstr(2, MAXSLNS - 1, MAXSCOL-2, err_li[n].text,
587 f->fb->mt.fb, f->fb->mt.fb); */
588 b = cn->f[cn->mxedt]->b;
589 b->b.y = err_li[n].line > b->mxlines ? b->mxlines - 1 : err_li[n].line - 1;
590 if (!err_li[n].srch)
591 {
592 for(i = j = 0; i + j < err_li[n].x && i < b->bf[b->b.y].len; i++)
593 {
594 if (*(b->bf[b->b.y].s + i) == WPE_TAB)
595 j += (f->ed->tabn - ((j + i) % f->ed->tabn) - 1);
596 #ifdef UNIX
597 else if (((unsigned char) *(b->bf[b->b.y].s + i)) > 126)
598 {
599 j++;
600 if (((unsigned char) *(b->bf[b->b.y].s + i)) < 128 + ' ')
601 j++;
602 }
603 else if (*(b->bf[b->b.y].s + i) < ' ')
604 j++;
605 #endif
606 }
607 b->b.x = i;
608 }
609 else
610 {
611 cp = strstr(b->bf[b->b.y].s, err_li[n].srch+1);
612 for (i = 0; b->bf[b->b.y].s + i < cp; i++);
613 if (err_li[n].srch[0] == 'B')
614 {
615 for (i--; i >= 0 && isspace(b->bf[b->b.y].s[i]); i--);
616 if (i < 0 && b->b.y > 0)
617 {
618 (b->b.y)--;
619 i = b->bf[b->b.y].len+1;
620 }
621 else
622 i++;
623 }
624 /* else if(err_li[n].x < -1) i++; */
625 b->b.x = i + err_li[n].x;
626 }
627 e_cursor(cn->f[cn->mxedt],1);
628 return(0);
629 }
630
e_pure_bin(char * str,int ch)631 int e_pure_bin(char *str, int ch)
632 {
633 int i;
634
635 for (i = 0; isspace(str[i]); i++)
636 ;
637 for (; str[i] && str[i] != ch; i++)
638 ;
639 for(; i >= 0 && str[i] != DIRC; i--)
640 ;
641 return(i+1);
642 }
643
e_make_error_list(FENSTER * f)644 int e_make_error_list(FENSTER *f)
645 {
646 char file[256];
647 ECNT *cn = f->ed;
648 BUFFER *b = cn->f[cn->mxedt]->b;
649 int i, j, k = 0, ret = 0;
650 char *spt;
651
652 if (err_li)
653 {
654 for (i = 0; i < err_num; i++)
655 {
656 if(err_li[i].file) FREE(err_li[i].file);
657 if(err_li[i].text) FREE(err_li[i].text);
658 if(err_li[i].srch) FREE(err_li[i].srch);
659 }
660 FREE(err_li);
661 }
662 err_li = MALLOC(sizeof(struct ERR_LI) * b->mxlines);
663 err_num = 0;
664 for (i = 0; i < b->mxlines; i++)
665 {
666 if (!strncmp((char *)b->bf[i].s, "Error at Command:", 17))
667 return(!ret ? -2 : ret);
668 if ((!strncmp((char *)b->bf[i].s, "ld", 2) &&
669 (b->bf[i].s[2] == ' ' || b->bf[i].s[2] == ':')) ||
670 !strncmp((char *)b->bf[i].s, "collect:", 8))
671 ret = -2;
672 else if (!strncmp((char *)b->bf[i].s, "makefile:", 9) ||
673 !strncmp((char *)b->bf[i].s, "Makefile:", 9))
674 {
675 err_li[k].file = MALLOC(9);
676 for (j = 0; j < 8; j++)
677 err_li[k].file[j] = b->bf[i].s[j];
678 err_li[k].file[8] = '\0';
679 err_li[k].line = atoi((char *)b->bf[i].s+9);
680 err_li[k].y = i;
681 err_li[k].x = 0;
682 err_li[k].srch = NULL;
683 err_li[k].text = MALLOC(strlen((char *)b->bf[i].s) + 1);
684 strcpy(err_li[k].text, (char *)b->bf[i].s);
685 err_li[k].text[b->bf[i].len] = '\0';
686 k++;
687 err_num++;
688 ret = -1;
689 continue;
690 }
691 else if (!strncmp((char *)b->bf[i].s, "make:", 5) &&
692 ((spt = strstr((char *)b->bf[i].s, "makefile")) ||
693 (spt = strstr((char *)b->bf[i].s, "Makefile")) ) &&
694 (err_li[k].line = atoi(spt+14)) > 0 )
695 {
696 err_li[k].file = MALLOC(9);
697 for (j = 0; j < 8; j++)
698 err_li[k].file[j] = spt[j];
699 err_li[k].file[8] = '\0';
700 err_li[k].y = i;
701 err_li[k].x = 0;
702 err_li[k].srch = NULL;
703 err_li[k].text = MALLOC(strlen((char *)b->bf[i].s) + 1);
704 strcpy(err_li[k].text, (char *)b->bf[i].s);
705 err_li[k].text[b->bf[i].len] = '\0';
706 k++;
707 err_num++;
708 continue;
709 }
710 else
711 {
712 char *tststr = e_s_prog.comp_sw ? e_s_prog.intstr : gnu_intstr;
713 if (!(ret = e_p_cmp_mess(tststr, b, &i, &k, ret)))
714 {
715 int ip, in;
716 ip = e_pure_bin(e_s_prog.compiler, ' ');
717 in = e_pure_bin(b->bf[i].s, ':');
718 sprintf(file, "%s:", e_s_prog.compiler+ip);
719 if (!strncmp(file, b->bf[i].s+in, strlen(file)))
720 ret = -2;
721 else if (!strncmp("ld:", b->bf[i].s+in, 3))
722 ret = -2;
723 else if (!strncmp("as:", b->bf[i].s+in, 3))
724 ret = -2;
725 }
726 }
727 }
728 if (!(f->ed->edopt & (ED_ERRORS_STOP_AT | ED_MESSAGES_STOP_AT)) &&
729 ret == -1)
730 ret = 0;
731 return(ret);
732 }
733
e_previous_error(FENSTER * f)734 int e_previous_error(FENSTER *f)
735 {
736 if (err_no > 0)
737 return(e_show_error(--err_no, f));
738 e_pr_uul(f->fb);
739 return(0);
740 }
741
e_next_error(FENSTER * f)742 int e_next_error(FENSTER *f)
743 {
744 if (err_no < err_num - 1)
745 return(e_show_error(++err_no, f));
746 e_pr_uul(f->fb);
747 return(0);
748 }
749
e_cur_error(int y,FENSTER * f)750 int e_cur_error(int y, FENSTER *f)
751 {
752 int i;
753
754 if(err_num)
755 {
756 for(i = 1; i < err_num && err_li[i].y <= y; i++);
757 return(e_show_error(err_no = i - 1, f));
758 }
759 e_pr_uul(f->fb);
760 return(0);
761 }
762
e_d_car_ret(FENSTER * f)763 int e_d_car_ret(FENSTER *f)
764 {
765 if (!strcmp(f->datnam, "Messages"))
766 return(e_cur_error(f->ed->f[f->ed->mxedt]->b->b.y, f));
767 #ifdef DEBUGGER
768 if (!strcmp(f->datnam, "Watches"))
769 return(e_edit_watches(f));
770 if(!strcmp(f->datnam, "Stack"))
771 return(e_make_stack(f));
772 #endif
773 return(0);
774 }
775
e_line_read(int n,char * s,int max)776 int e_line_read(int n, char *s, int max)
777 {
778 int i, ret = 0;
779
780 for (i = 0; i < max - 1; i++)
781 if ((ret = read(n, s + i, 1)) != 1 || s[i] == '\n'|| s[i] == '\0')
782 break;
783 if (ret != 1 && i == 0)
784 return(-1);
785 if (i == max - 1)
786 i--;
787 s[i+1] = '\0';
788 return(0);
789 }
790
e_arguments(FENSTER * f)791 int e_arguments(FENSTER *f)
792 {
793 char str[80];
794
795 if (!e_prog.arguments)
796 {
797 e_prog.arguments = MALLOC(1);
798 e_prog.arguments[0] = '\0';
799 }
800 strcpy(str, e_prog.arguments);
801 if (e_add_arguments(str, "Arguments", f, 0 , AltA, NULL))
802 {
803 e_prog.arguments = REALLOC(e_prog.arguments, strlen(str) + 1);
804 strcpy(e_prog.arguments, str);
805 }
806 return(0);
807 }
808
e_check_c_file(char * name)809 int e_check_c_file(char *name)
810 {
811 int i, j;
812 char *postfix;
813
814 postfix = strrchr(name, '.');
815 if (postfix)
816 {
817 for (i = 0; i < e_prog.num; i++)
818 for (j = WpeExpArrayGetSize(e_prog.comp[i]->filepostfix); j; j--)
819 if(!strcmp(e_prog.comp[i]->filepostfix[j - 1], postfix))
820 {
821 e_copy_prog(&e_s_prog, e_prog.comp[i]);
822 return(i+1);
823 }
824 }
825 return(0);
826 }
827
828 #ifdef CHECKHEADER
829
e_check_header(char * file,M_TIME otime,ECNT * cn,int sw)830 int e_check_header(char *file, M_TIME otime, ECNT *cn, int sw)
831 {
832 struct stat cbuf[1];
833 FILE *fp;
834 char *p, str[120], str2[120];
835 int i;
836
837 for (i = cn->mxedt; i > 0; i--)
838 {
839 if (file[0] == DIRC)
840 p = e_mkfilename(cn->f[i]->dirct, cn->f[i]->datnam);
841 else
842 p = cn->f[i]->datnam;
843 if (!strcmp(p, file) && cn->f[i]->save)
844 { e_save(cn->f[i]); if(p != cn->f[i]->datnam) FREE(p); break; }
845 if (p != cn->f[i]->datnam)
846 FREE(p);
847 }
848 if ((fp = fopen(file, "r")) == NULL)
849 return(sw);
850 stat(file, cbuf);
851 if (otime < cbuf->st_mtime)
852 sw++;
853 while (fgets(str, 120, fp))
854 {
855 for (p = str; isspace(*p); p++);
856 if (*p == '/' && *(p+1) == '*')
857 {
858 p++;
859 do
860 {
861 for (p++; *p && *p != '*'; p++)
862 ;
863 if (!*p && !fgets((p = str), 120, fp))
864 break;
865 } while (p != NULL && (*p != '*' || *(p+1) != '/'));
866 if (!p) break;
867 for (p += 2; isspace(*p); p++)
868 ;
869 }
870 if (*p == '#')
871 {
872 for (p++; isspace(*p); p++)
873 ;
874 if (!strncmp(p, "include", 7))
875 {
876 for (p += 8; isspace(*p); p++)
877 ;
878 if (*p == '\"')
879 {
880 for (p++, i = 0; p[i] != '\"' && p[i] != '\0' && p[i] != '\n'; i++)
881 str2[i] = p[i];
882 str2[i] = '\0';
883 sw = e_check_header(str2, otime, cn, sw);
884 }
885 }
886 }
887 }
888 fclose(fp);
889 return(sw);
890 }
891 #endif
892
e_cat_string(char * p,char * str)893 char *e_cat_string(char *p, char *str)
894 {
895 if(str == NULL) return(p = NULL);
896 if(p == NULL)
897 {
898 if((p = MALLOC(strlen(str)+2)) == NULL) return(NULL);
899 p[0] = '\0';
900 }
901 else if ((p = REALLOC(p, strlen(p) + strlen(str)+2)) == NULL)
902 return(NULL);
903 strcat(p, " ");
904 strcat(p, str);
905 return(p);
906 }
907
e_make_arg(char *** arg,char * str)908 int e_make_arg(char ***arg, char *str)
909 {
910 int i, j;
911 char tmp[128], *p = tmp;
912
913 if (!(*arg))
914 *arg = (char **) MALLOC(4*sizeof(char *));
915 else
916 *arg = (char **) REALLOC(*arg, 4*sizeof(char *));
917 (*arg)[0] = MALLOC(strlen(e_s_prog.compiler) + 1);
918 strcpy((*arg)[0], e_s_prog.compiler);
919 if (!str)
920 {
921 (*arg)[1] = NULL;
922 (*arg)[2] = NULL;
923 return(2);
924 }
925 strcpy(tmp, str);
926 for (j = 2, i = 0; p[i] != '\0'; j++)
927 {
928 for (; p[i] != '\0' && p[i] != ' '; i++)
929 ;
930 (*arg)[j] = MALLOC(i + 1);
931 strncpy((*arg)[j], p, i);
932 (*arg)[j][i] = '\0';
933 *arg = (char **) REALLOC(*arg, (j + 3)*sizeof(char *));
934 if (p[i] != '\0')
935 {
936 p += (i + 1);
937 i = 0;
938 }
939 }
940 (*arg)[j] = NULL;
941 return(j);
942 }
943
e_add_arg(char *** arg,char * str,int n,int argc)944 int e_add_arg(char ***arg, char *str, int n, int argc)
945 {
946 int i;
947
948 argc++;
949 *arg = (char **) REALLOC(*arg, (argc+1)*sizeof(char *));
950 for(i = argc; i > n; i--)
951 (*arg)[i] = (*arg)[i-1];
952 (*arg)[n] = MALLOC(strlen(str) + 1);
953 strcpy((*arg)[n], str);
954 return(argc);
955 }
956
e_ini_prog(ECNT * cn)957 int e_ini_prog(ECNT *cn)
958 {
959 int i;
960
961 e_prog.num = 4;
962 if (e_prog.arguments) FREE(e_prog.arguments);
963 e_prog.arguments = WpeStrdup("");
964 if (e_prog.project) FREE(e_prog.project);
965 e_prog.project = WpeStrdup("project.prj");
966 if (e_prog.exedir) FREE(e_prog.exedir);
967 e_prog.exedir = WpeStrdup(".");
968 if (e_prog.sys_include) FREE(e_prog.sys_include);
969 e_prog.sys_include =
970 WpeStrdup("/usr/include:/usr/local/include"
971 #if !defined(NO_XWINDOWS)
972 ":"X_INC
973 #endif
974 );
975 if (e_prog.comp == NULL)
976 e_prog.comp = MALLOC(e_prog.num * sizeof(struct e_s_prog *));
977 else
978 e_prog.comp = REALLOC(e_prog.comp, e_prog.num * sizeof(struct e_s_prog *));
979 for (i = 0; i < e_prog.num; i++)
980 e_prog.comp[i] = MALLOC(sizeof(struct e_s_prog));
981 e_prog.comp[0]->compiler = WpeStrdup("gcc");
982 e_prog.comp[0]->language = WpeStrdup("C");
983 e_prog.comp[0]->filepostfix = (char **)WpeExpArrayCreate(1, sizeof(char *), 1);
984 e_prog.comp[0]->filepostfix[0] = WpeStrdup(".c");
985 e_prog.comp[0]->key = 'C';
986 e_prog.comp[0]->x = 0;
987 e_prog.comp[0]->intstr = WpeStrdup(cc_intstr);
988 e_prog.comp[2]->compiler = WpeStrdup("f77");
989 e_prog.comp[1]->compiler = WpeStrdup("g++");
990 e_prog.comp[1]->language = WpeStrdup("C++");
991 e_prog.comp[1]->filepostfix = (char **)WpeExpArrayCreate(4, sizeof(char *), 1);
992 e_prog.comp[1]->filepostfix[0] = WpeStrdup(".C");
993 e_prog.comp[1]->filepostfix[1] = WpeStrdup(".cc");
994 e_prog.comp[1]->filepostfix[2] = WpeStrdup(".cpp");
995 e_prog.comp[1]->filepostfix[3] = WpeStrdup(".cxx");
996 e_prog.comp[1]->key = '+';
997 e_prog.comp[1]->x = 1;
998 e_prog.comp[1]->intstr = WpeStrdup(cc_intstr);
999 e_prog.comp[2]->language = WpeStrdup("Fortran");
1000 e_prog.comp[2]->filepostfix = (char **)WpeExpArrayCreate(1, sizeof(char *), 1);
1001 e_prog.comp[2]->filepostfix[0] = WpeStrdup(".f");
1002 e_prog.comp[2]->key = 'F';
1003 e_prog.comp[2]->x = 0;
1004 e_prog.comp[2]->intstr = WpeStrdup(cc_intstr);
1005 e_prog.comp[3]->compiler = WpeStrdup("pc");
1006 e_prog.comp[3]->language = WpeStrdup("Pascal");
1007 e_prog.comp[3]->filepostfix = (char **)WpeExpArrayCreate(1, sizeof(char *), 1);
1008 e_prog.comp[3]->filepostfix[0] = WpeStrdup(".p");
1009 e_prog.comp[3]->key = 'P';
1010 e_prog.comp[3]->x = 0;
1011 e_prog.comp[3]->intstr = WpeStrdup(pc_intstr);
1012 for (i = 0; i < e_prog.num; i++)
1013 {
1014 e_prog.comp[i]->comp_str = WpeStrdup("-g");
1015 e_prog.comp[i]->libraries = WpeStrdup("");
1016 e_prog.comp[i]->exe_name = WpeStrdup("");
1017 e_prog.comp[i]->comp_sw = i < 2 ? 0 : 1;
1018 }
1019 e_copy_prog(&e_s_prog, e_prog.comp[0]);
1020 return(0);
1021 }
1022
e_copy_prog(struct e_s_prog * out,struct e_s_prog * in)1023 int e_copy_prog(struct e_s_prog *out, struct e_s_prog *in)
1024 {
1025 int i;
1026
1027 if (out->language) FREE(out->language);
1028 out->language = WpeStrdup(in->language);
1029 if (out->filepostfix)
1030 {
1031 for (i = WpeExpArrayGetSize(out->filepostfix); i; i--)
1032 WpeFree(out->filepostfix[i - 1]);
1033 WpeExpArrayDestroy(out->filepostfix);
1034 }
1035 out->filepostfix = (char **)WpeExpArrayCreate(WpeExpArrayGetSize(in->filepostfix), sizeof(char *), 1);
1036 for (i = WpeExpArrayGetSize(out->filepostfix); i; i--)
1037 out->filepostfix[i - 1] = WpeStrdup(in->filepostfix[i - 1]);
1038 if (out->compiler) FREE(out->compiler);
1039 out->compiler = WpeStrdup(in->compiler);
1040 if (out->comp_str) FREE(out->comp_str);
1041 out->comp_str = WpeStrdup(in->comp_str);
1042 if (out->libraries) FREE(out->libraries);
1043 out->libraries = WpeStrdup(in->libraries);
1044 if (out->exe_name) FREE(out->exe_name);
1045 out->exe_name = WpeStrdup(in->exe_name);
1046 if (out->intstr) FREE(out->intstr);
1047 out->intstr = WpeStrdup(in->intstr);
1048 out->key = in->key;
1049 out->comp_sw = in->comp_sw;
1050 return(0);
1051 }
1052
e_prj_ob_btt(FENSTER * f,int sw)1053 int e_prj_ob_btt(FENSTER *f, int sw)
1054 {
1055 FLWND *fw;
1056
1057 e_data_first(sw+4, f->ed, f->ed->dirct);
1058 if (sw > 0)
1059 {
1060 if (!(f->ed->edopt & ED_CUA_STYLE))
1061 while (e_data_eingabe(f->ed) != AF3)
1062 ;
1063 else
1064 while (e_data_eingabe(f->ed) != CF4)
1065 ;
1066 fw = (FLWND *)f->ed->f[f->ed->mxedt]->b;
1067 fw->df = NULL;
1068 e_close_window(f->ed->f[f->ed->mxedt]);
1069 }
1070 return(0);
1071 }
1072
e_prj_ob_file(FENSTER * f)1073 int e_prj_ob_file(FENSTER *f)
1074 {
1075 return(e_prj_ob_btt(f, 0));
1076 }
1077
e_prj_ob_varb(FENSTER * f)1078 int e_prj_ob_varb(FENSTER *f)
1079 {
1080 return(e_prj_ob_btt(f, 1));
1081 }
1082
e_prj_ob_inst(FENSTER * f)1083 int e_prj_ob_inst(FENSTER *f)
1084 {
1085 return(e_prj_ob_btt(f, 2));
1086 }
1087
e_prj_ob_svas(FENSTER * f)1088 int e_prj_ob_svas(FENSTER *f)
1089 {
1090 return(e_project_name(f) ? 0 : AltS);
1091 }
1092
e_project_options(FENSTER * f)1093 int e_project_options(FENSTER *f)
1094 {
1095 int ret;
1096 W_OPTSTR *o = e_init_opt_kst(f);
1097 char *messagestring;
1098
1099 if (!o)
1100 return(-1);
1101 if (!(e_make_prj_opt(f)))
1102 {
1103 freeostr(o);
1104 return(-1);
1105 }
1106 o->xa = 8; o->ya = 2; o->xe = 68; o->ye = 22;
1107 o->bgsw = 0;
1108 o->name = "Project-Options";
1109 o->crsw = AltS;
1110 e_add_txtstr(4, 12, "Compiler-Style:", o);
1111 e_add_wrstr(4, 2, 22, 2, 36, 128, 0, AltC, "Compiler:", e_s_prog.compiler, NULL, o);
1112 e_add_wrstr(4, 4, 22, 4, 36, 256, 3, AltP, "ComPiler-Options:", e_s_prog.comp_str, NULL, o);
1113 e_add_wrstr(4, 6, 22, 6, 36, 256, 0, AltL, "Loader-Options:", e_s_prog.libraries, NULL, o);
1114 e_add_wrstr(4, 8, 22, 8, 36, 128, 0, AltE, "Executable:", e_s_prog.exe_name, NULL, o);
1115 e_add_wrstr(4, 10, 22, 10, 36, 128, 2, AltB, "LiBrary:", library, NULL, o);
1116 messagestring = WpeStringToValue(e_s_prog.intstr);
1117 e_add_wrstr(22, 12, 22, 13, 36, 256, 0, AltM, "Message-String:", messagestring, NULL, o);
1118 WpeFree(messagestring);
1119 e_add_pswstr(0, 5, 13, 0, AltG, 0, "GNU ", o);
1120 e_add_pswstr(0, 5, 14, 1, AltT, e_s_prog.comp_sw, "OTher ", o);
1121 e_add_bttstr(9, 18, 0, AltS, "Save", NULL, o);
1122 e_add_bttstr(44, 18, -1, WPE_ESC, "Cancel", NULL, o);
1123 e_add_bttstr(26, 18, 5, AltA, "Save As", e_prj_ob_svas, o);
1124 /* e_add_bttstr(7, 16, 0, AltF, "Files ...", e_prj_ob_file, o); */
1125 e_add_bttstr(12, 16, 0, AltV, "Variables ...", e_prj_ob_varb, o);
1126 e_add_bttstr(35, 16, 0, AltI, "Install ...", e_prj_ob_inst, o);
1127 ret = e_opt_kst(o);
1128 if (ret != WPE_ESC)
1129 {
1130 if (e_s_prog.compiler) FREE(e_s_prog.compiler);
1131 e_s_prog.compiler = WpeStrdup(o->wstr[0]->txt);
1132 if (e_s_prog.comp_str) FREE(e_s_prog.comp_str);
1133 e_s_prog.comp_str = WpeStrdup(o->wstr[1]->txt);
1134 if (e_s_prog.libraries) FREE(e_s_prog.libraries);
1135 e_s_prog.libraries = WpeStrdup(o->wstr[2]->txt);
1136 if (e_s_prog.exe_name) FREE(e_s_prog.exe_name);
1137 e_s_prog.exe_name = WpeStrdup(o->wstr[3]->txt);
1138 if (e_s_prog.intstr) FREE(e_s_prog.intstr);
1139 e_s_prog.intstr = WpeValueToString(o->wstr[5]->txt);
1140 strcpy(library, o->wstr[4]->txt);
1141 e_s_prog.comp_sw = o->pstr[0]->num;
1142 e_wrt_prj_fl(f);
1143 }
1144 freeostr(o);
1145 if (f->ed->mxedt > 0)
1146 e_ed_rahmen(f, 1);
1147 return(0);
1148 }
1149
e_run_c_options(FENSTER * f)1150 int e_run_c_options(FENSTER *f)
1151 {
1152 int i, j, ret;
1153 W_OPTSTR *o = e_init_opt_kst(f);
1154 char filepostfix[128];
1155 char *newpostfix;
1156 char *messagestring;
1157
1158 if (!o)
1159 return(-1);
1160 o->xa = 8; o->ya = 2; o->xe = 68; o->ye = 22;
1161 o->bgsw = 0;
1162 o->name = "Compiler-Options";
1163 o->crsw = AltO;
1164 e_add_txtstr(4, 14, "Compiler-Style:", o);
1165 e_add_wrstr(4, 2, 22, 2, 36, 128, 1, AltA, "LAnguage:", e_s_prog.language, NULL, o);
1166 e_add_wrstr(4, 4, 22, 4, 36, 128, 0, AltC, "Compiler:", e_s_prog.compiler, NULL, o);
1167 e_add_wrstr(4, 6, 22, 6, 36, 128, 3, AltP, "ComPiler-Options:", e_s_prog.comp_str, NULL, o);
1168 e_add_wrstr(4, 8, 22, 8, 36, 128, 0, AltL, "Loader-Options:", e_s_prog.libraries, NULL, o);
1169 e_add_wrstr(4, 10, 22, 10, 36, 128, 0, AltE, "Executable:", e_s_prog.exe_name, NULL, o);
1170 filepostfix[0] = 0;
1171 if ((j = WpeExpArrayGetSize(e_s_prog.filepostfix)))
1172 {
1173 strcpy(filepostfix, e_s_prog.filepostfix[0]);
1174 for (i = 1; i < j; i++)
1175 {
1176 strcat(filepostfix, " ");
1177 strcat(filepostfix, e_s_prog.filepostfix[i]);
1178 }
1179 }
1180 e_add_wrstr(4, 12, 22, 12, 36, 128, 0, AltF, "File-Postfix:", filepostfix, NULL, o);
1181 messagestring = WpeStringToValue(e_s_prog.intstr);
1182 e_add_wrstr(22, 14, 22, 15, 36, 128, 0, AltM, "Message-String:", messagestring, NULL, o);
1183 WpeFree(messagestring);
1184 e_add_pswstr(0, 5, 15, 0, AltG, 0, "GNU ", o);
1185 e_add_pswstr(0, 5, 16, 1, AltT, e_s_prog.comp_sw, "OTher ", o);
1186 e_add_bttstr(16, 18, 1, AltO, " Ok ", NULL, o);
1187 e_add_bttstr(37, 18, -1, WPE_ESC, "Cancel", NULL, o);
1188 ret = e_opt_kst(o);
1189 if (ret != WPE_ESC)
1190 {
1191 if (e_s_prog.language) FREE(e_s_prog.language);
1192 e_s_prog.language = WpeStrdup(o->wstr[0]->txt);
1193 if (e_s_prog.compiler) FREE(e_s_prog.compiler);
1194 e_s_prog.compiler = WpeStrdup(o->wstr[1]->txt);
1195 if (e_s_prog.comp_str) FREE(e_s_prog.comp_str);
1196 e_s_prog.comp_str = WpeStrdup(o->wstr[2]->txt);
1197 if (e_s_prog.libraries) FREE(e_s_prog.libraries);
1198 e_s_prog.libraries = WpeStrdup(o->wstr[3]->txt);
1199 if (e_s_prog.exe_name) FREE(e_s_prog.exe_name);
1200 e_s_prog.exe_name = WpeStrdup(o->wstr[4]->txt);
1201 for (i = 0; i < j; i++)
1202 WpeFree(e_s_prog.filepostfix[i]);
1203 WpeExpArrayDestroy(e_s_prog.filepostfix);
1204 e_s_prog.filepostfix = (char **)WpeExpArrayCreate(0, sizeof(char *), 1);
1205 for (i = 0; o->wstr[5]->txt[i]; i++)
1206 {
1207 if (isspace(o->wstr[5]->txt[i]))
1208 continue;
1209 for (j = i; (o->wstr[5]->txt[j]) && (!isspace(o->wstr[5]->txt[j])); j++)
1210 ;
1211 newpostfix = (char *)WpeMalloc(sizeof(char) * j - i + 1);
1212 strncpy(newpostfix, o->wstr[5]->txt + i, j - i);
1213 newpostfix[j - i] = 0;
1214 WpeExpArrayAdd((void **)&e_s_prog.filepostfix, &newpostfix);
1215 i = j - 1;
1216 }
1217 if (e_s_prog.intstr) FREE(e_s_prog.intstr);
1218 e_s_prog.intstr = WpeValueToString(o->wstr[6]->txt);
1219 e_s_prog.comp_sw = o->pstr[0]->num;
1220 }
1221 freeostr(o);
1222 return(0);
1223 }
1224
e_run_options(FENSTER * f)1225 int e_run_options(FENSTER *f)
1226 {
1227 int i, n, xa = 48, ya = 2, num = 2 + e_prog.num;
1228 OPTK *opt = MALLOC(num * sizeof(OPTK));
1229 char tmp[80];
1230
1231 tmp[0] = '\0';
1232 opt[0].t = "Add Compiler "; opt[0].x = 0; opt[0].o = 'A';
1233 opt[1].t = "Remove Compiler"; opt[1].x = 0; opt[1].o = 'R';
1234
1235 for (i = 0; i < e_prog.num; i++)
1236 {
1237 opt[i+2].t = e_prog.comp[i]->language; opt[i+2].x = e_prog.comp[i]->x;
1238 opt[i+2].o = e_prog.comp[i]->key;
1239 }
1240 n = e_opt_sec_box(xa, ya, num, opt, f, 1);
1241
1242 if (n == 0)
1243 {
1244 if (!e_run_c_options(f))
1245 {
1246 e_prog.num++;
1247 e_prog.comp = REALLOC(e_prog.comp, e_prog.num * sizeof(struct e_s_prog *));
1248 e_prog.comp[e_prog.num - 1] = MALLOC(sizeof(struct e_s_prog));
1249 e_prog.comp[e_prog.num - 1]->language = (char *)WpeMalloc(1);
1250 e_prog.comp[e_prog.num - 1]->language[0] = 0;
1251 e_prog.comp[e_prog.num - 1]->compiler = (char *)WpeMalloc(1);
1252 e_prog.comp[e_prog.num - 1]->compiler[0] = 0;
1253 e_prog.comp[e_prog.num - 1]->comp_str = (char *)WpeMalloc(1);
1254 e_prog.comp[e_prog.num - 1]->comp_str[0] = 0;
1255 e_prog.comp[e_prog.num - 1]->libraries = (char *)WpeMalloc(1);
1256 e_prog.comp[e_prog.num - 1]->libraries[0] = 0;
1257 e_prog.comp[e_prog.num - 1]->exe_name = (char *)WpeMalloc(1);
1258 e_prog.comp[e_prog.num - 1]->exe_name[0] = 0;
1259 e_prog.comp[e_prog.num - 1]->intstr = (char *)WpeMalloc(1);
1260 e_prog.comp[e_prog.num - 1]->intstr[0] = 0;
1261 e_prog.comp[e_prog.num - 1]->filepostfix =
1262 (char **)WpeExpArrayCreate(0, sizeof(char *), 1);
1263 e_copy_prog(e_prog.comp[e_prog.num-1], &e_s_prog);
1264 for (n = 0; e_prog.comp[e_prog.num-1]->language[n]; n++)
1265 {
1266 for (i = 0; i <= e_prog.num &&
1267 toupper(e_prog.comp[e_prog.num-1]->language[n]) != opt[i].o; i++)
1268 ;
1269 if (i > e_prog.num)
1270 break;
1271 }
1272 e_prog.comp[e_prog.num-1]->key =
1273 toupper(e_prog.comp[e_prog.num-1]->language[n]);
1274 e_prog.comp[e_prog.num-1]->x = n;
1275 }
1276 }
1277 else if (n == 1)
1278 {
1279 if(e_add_arguments(tmp, "Remove Compiler", f, 0, AltR, NULL))
1280 {
1281 for (i = 0; i < e_prog.num && strcmp(e_prog.comp[i]->language, tmp); i++)
1282 ;
1283 if (i >= e_prog.num)
1284 {
1285 e_error(e_p_msg[ERR_NO_COMPILER], 0, f->fb);
1286 FREE(opt);
1287 return(0);
1288 }
1289 FREE(e_prog.comp[i]);
1290 for(; i < e_prog.num-1; i++) e_prog.comp[i] = e_prog.comp[i+1];
1291 e_prog.num--;
1292 }
1293 }
1294 else if (n > 1)
1295 {
1296 e_copy_prog(&e_s_prog, e_prog.comp[n-2]);
1297 e_run_c_options(f);
1298 e_copy_prog(e_prog.comp[n-2], &e_s_prog);
1299 }
1300 FREE(opt);
1301 return(n < 0 ? WPE_ESC : 0);
1302 }
1303
e_project_name(FENSTER * f)1304 int e_project_name(FENSTER *f)
1305 {
1306 char str[80];
1307
1308 if (!e_prog.project)
1309 {
1310 e_prog.project = MALLOC(1);
1311 e_prog.project[0] = '\0';
1312 }
1313 strcpy(str, e_prog.project);
1314 if (e_add_arguments(str, "Project", f, 0, AltP, NULL))
1315 {
1316 e_prog.project = REALLOC(e_prog.project, strlen(str) + 1);
1317 strcpy(e_prog.project, str);
1318 return(0);
1319 }
1320 return(WPE_ESC);
1321 }
1322
e_project(FENSTER * f)1323 int e_project(FENSTER *f)
1324 {
1325 ECNT *cn = f->ed;
1326 int i;
1327 if (!e_project_name(f))
1328 {
1329 for (i = cn->mxedt; i > 0 && (cn->f[i]->dtmd != DTMD_DATA || cn->f[i]->ins != 4);
1330 i--)
1331 ;
1332 if (i > 0)
1333 {
1334 e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
1335 e_close_window(cn->f[cn->mxedt]);
1336 }
1337 f = cn->f[cn->mxedt];
1338 e_make_prj_opt(f);
1339 e_rel_brkwtch(f);
1340 e_prj_ob_file(f);
1341 return(0);
1342 }
1343 return(WPE_ESC);
1344 }
1345
e_show_project(FENSTER * f)1346 int e_show_project(FENSTER *f)
1347 {
1348 ECNT *cn = f->ed;
1349 int i;
1350
1351 for (i = cn->mxedt; i > 0 && (cn->f[i]->dtmd != DTMD_DATA || cn->f[i]->ins != 4);
1352 i--)
1353 ;
1354 if (i > 0)
1355 e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
1356 else
1357 {
1358 e_make_prj_opt(f);
1359 e_prj_ob_file(f);
1360 }
1361 return(0);
1362 }
1363
e_cl_project(FENSTER * f)1364 int e_cl_project(FENSTER *f)
1365 {
1366 ECNT *cn = f->ed;
1367 int i;
1368
1369 if (!e_prog.project)
1370 e_prog.project = MALLOC(sizeof(char));
1371 else
1372 e_prog.project = REALLOC(e_prog.project, sizeof(char));
1373 e_prog.project[0] = '\0';
1374 for (i = cn->mxedt; i > 0 && (cn->f[i]->dtmd != DTMD_DATA || cn->f[i]->ins != 4);
1375 i--)
1376 ;
1377 if (i > 0)
1378 {
1379 e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
1380 e_close_window(cn->f[cn->mxedt]);
1381 }
1382 return(0);
1383 }
1384
e_p_add_item(FENSTER * f)1385 int e_p_add_item(FENSTER *f)
1386 {
1387 ECNT *cn = f->ed;
1388 int i;
1389
1390 for (i = cn->mxedt; i > 0 && (cn->f[i]->dtmd != DTMD_DATA || cn->f[i]->ins != 4);
1391 i--)
1392 ;
1393 if (i > 0)
1394 e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
1395 else
1396 {
1397 FLWND *fw;
1398
1399 e_make_prj_opt(f);
1400 e_prj_ob_file(f);
1401 fw = (FLWND *) cn->f[cn->mxedt]->b;
1402 fw->nf = fw->df->anz - 1;
1403 }
1404 cn->f[cn->mxedt]->save = 1;
1405 WpeCreateFileManager(5, cn, NULL);
1406 WpeHandleFileManager(cn);
1407 return(0);
1408 }
1409
e_p_del_item(FENSTER * f)1410 int e_p_del_item(FENSTER *f)
1411 {
1412 ECNT *cn = f->ed;
1413 int i;
1414
1415 for (i = cn->mxedt;
1416 i > 0 && (cn->f[i]->dtmd != DTMD_DATA || cn->f[i]->ins != 4); i--)
1417 ;
1418 if (i > 0)
1419 e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
1420 else
1421 return(e_error(e_p_msg[ERR_NOPROJECT], 0, f->fb));
1422 f = cn->f[cn->mxedt];
1423 f->save = 1;
1424 e_p_del_df((FLWND *) f->b, f->ins);
1425 return 0;
1426 }
1427
e_make_library(char * library,char * ofile,FENSTER * f)1428 int e_make_library(char *library, char *ofile, FENSTER *f)
1429 {
1430 char *ar_arg[5] = { NULL, NULL, NULL, NULL, NULL };
1431 int ret = 0, file = -1;
1432 PIC *pic = NULL;
1433
1434 ar_arg[0] = "ar";
1435 if (access(library, 0))
1436 ar_arg[1] = "-cr";
1437 else
1438 ar_arg[1] = "-r";
1439 ar_arg[2] = library;
1440 ar_arg[3] = ofile;
1441 if ((ret = e_p_mess_win("Insert into Archive", 4, ar_arg, &pic, f)) == 0)
1442 {
1443 e_sys_ini();
1444 file = e_exec_inf(f, ar_arg, 4);
1445 e_sys_end();
1446 if ((file) && ((ret = e_p_exec(file, f, pic)) == 0))
1447 {
1448 pic = NULL;
1449 /*
1450 #ifdef RANLIB
1451 ar_arg[0] = "ranlib";
1452 ar_arg[1] = library;
1453 ar_arg[2] = NULL;
1454 if(ret = e_p_mess_win("Convert Archive", 2, ar_arg, &pic, f)) goto m_l_ende;
1455 e_sys_ini();
1456 file = e_exec_inf(f, ar_arg, 2);
1457 e_sys_end();
1458 if(file) ret = e_p_exec(file, f, pic);
1459 #endif
1460 */
1461 }
1462 }
1463 return((!ret && file) ? 0 : -1);
1464 }
1465
e_system(char * estr,ECNT * cn)1466 int e_system(char *estr, ECNT *cn)
1467 {
1468 #if MOUSE
1469 int g[4];
1470 #endif
1471 int ret;
1472 PIC *outp;
1473 FENSTER *f;
1474
1475 #if MOUSE
1476 g[0] = 2;
1477 fk_mouse(g);
1478 #endif
1479 f = cn->f[cn->mxedt-1];
1480 outp = e_open_view(0,0,MAXSCOL-1,MAXSLNS-1,cn->fb->ws,1);
1481 fk_locate(0,0);
1482 fk_cursor(1);
1483 (*e_u_s_sys_ini)();
1484 ret = system(estr);
1485 if (!WpeIsXwin())
1486 {
1487 printf(e_msg[ERR_HITCR]);
1488 fflush(stdout);
1489 fk_getch();
1490 }
1491 (*e_u_s_sys_end)();
1492 e_close_view(outp, 1);
1493 fk_cursor(0);
1494 #if MOUSE
1495 g[0] = 1;
1496 fk_mouse(g);
1497 #endif
1498 return(ret);
1499 }
1500
1501 /* arranges string str into buffer b and eventually wrappes string around
1502 wrap_limit columns */
print_to_end_of_buffer(BUFFER * b,char * str,int wrap_limit)1503 int print_to_end_of_buffer(BUFFER * b,char * str,int wrap_limit)
1504 {
1505 int i,k,j;
1506
1507 k = 0;
1508 do
1509 {
1510 if (wrap_limit != 0)
1511 for (j = 0;
1512 ((j < wrap_limit) && (!((str[j + k] == '\n') || (str[j + k] == '\0'))));
1513 j++)
1514 ;
1515 else
1516 for (j = 0; (!((str[j + k] == '\n') || (str[j + k] == '\0'))); j++)
1517 ;
1518 /* Don't add blank lines */
1519 if (j == k)
1520 break;
1521
1522 /* b->mxlines - count of lines in b
1523 so add one more line at the end of buffer */
1524 e_new_line(b->mxlines, b);
1525 i = b->mxlines-1;
1526
1527 /* copy char from string (str) to buffer */
1528
1529 if (str[j + k]!='\0')
1530 b->bf[i].s = REALLOC(b->bf[i].s, j + 2);
1531 else
1532 b->bf[i].s = REALLOC(b->bf[i].s, j + 1);
1533 strncpy(b->bf[i].s,str + k,j);
1534
1535 /* if this is not end of string, then we created substring
1536 if *(b->bf[i].s+j) is not '\0' then it is soft break is not written to file */
1537
1538 if (str[j + k]!='\0')
1539 {
1540 *(b->bf[i].s + j) = '\n';
1541 *(b->bf[i].s + j + 1) = '\0';
1542 }
1543 else
1544 {
1545 *(b->bf[i].s + j) = '\0';
1546 }
1547 /* update len of line in buffer */
1548 b->bf[i].len = j;
1549 b->bf[i].nrc = j + 1;
1550
1551 if (str[j + k]=='\n')
1552 {
1553 j++;
1554 }
1555
1556 k += j;
1557
1558 /* loop until end of string
1559 } while (str[k] != '\n' && str[k] != '\0');*/
1560 } while (str[k] != '\0');
1561
1562 return 0;
1563 }
1564
1565 /* print to message window */
e_d_p_message(char * str,FENSTER * f,int sw)1566 int e_d_p_message(char *str, FENSTER *f, int sw)
1567 {
1568 ECNT *cn = f->ed;
1569 BUFFER *b;
1570 SCHIRM *s;
1571 int i;
1572
1573 if (str[0] == '\0' || str[0] == '\n')
1574 return(0);
1575 for (i = cn->mxedt; i > 0 && strcmp(cn->f[i]->datnam, "Messages"); i--)
1576 ;
1577 if (i == 0)
1578 {
1579 if (e_edit(cn, "Messages"))
1580 return(-1);
1581 else
1582 i = cn->mxedt;
1583 }
1584
1585 /* f - window */
1586 f = cn->f[i];
1587
1588 /* b - buffer */
1589 b = cn->f[i]->b;
1590
1591 /* s - content of window */
1592 s = cn->f[i]->s;
1593
1594 print_to_end_of_buffer(b, str, b->mx.x);
1595
1596 /* place cursor on the last line */
1597 b->b.y = b->mxlines-1;
1598
1599 if (sw)
1600 e_rep_win_tree(cn);
1601 else if (WpeIsXwin())
1602 {
1603 e_schirm(f, 0);
1604 e_cursor(f, 0);
1605 e_refresh();
1606 }
1607 return(0);
1608 }
1609
1610 #if MOUSE
e_d_car_mouse(FENSTER * f)1611 int e_d_car_mouse(FENSTER *f)
1612 {
1613 extern struct mouse e_mouse;
1614 BUFFER *b = f->ed->f[f->ed->mxedt]->b;
1615 SCHIRM *s = f->ed->f[f->ed->mxedt]->s;
1616
1617 if (e_mouse.y-f->a.y+s->c.y-1 == b->b.y)
1618 return(WPE_CR);
1619 else
1620 {
1621 b->b.y = e_mouse.y-f->a.y+s->c.y-1;
1622 b->b.x = e_mouse.x-f->a.x+s->c.x-1;
1623 }
1624 return(0);
1625 }
1626 #endif
1627
e_exec_make(FENSTER * f)1628 int e_exec_make(FENSTER *f)
1629 {
1630 ECNT *cn = f->ed;
1631 char **arg = NULL;
1632 int i, file, argc;
1633
1634 WpeMouseChangeShape(WpeWorkingShape);
1635 efildes[0] = efildes[1] = -1;
1636 wfildes[0] = wfildes[1] = -1;
1637 for (i = cn->mxedt; i > 0; i--)
1638 if (!strcmp(cn->f[i]->datnam, "Makefile") ||
1639 !strcmp(cn->f[i]->datnam, "makefile"))
1640 {
1641 e_switch_window(cn->edt[i], cn->f[cn->mxedt]);
1642 e_save(cn->f[cn->mxedt]);
1643 }
1644 if (e_new_message(f))
1645 return(WPE_ESC);
1646 f = cn->f[cn->mxedt];
1647 e_sys_ini();
1648 if (e_s_prog.compiler)
1649 FREE(e_s_prog.compiler);
1650 e_s_prog.compiler = MALLOC(5*sizeof(char));
1651 strcpy(e_s_prog.compiler, "make");
1652 argc = e_make_arg(&arg, e_prog.arguments);
1653 if (argc == 0)
1654 {
1655 arg[1] = NULL;
1656 argc = 2;
1657 }
1658 else
1659 {
1660 for (i = 1; i < argc; i++)
1661 arg[i] = arg[i+1];
1662 }
1663 if ((file = e_exec_inf(f, arg, argc)) == 0)
1664 {
1665 e_sys_end();
1666 WpeMouseRestoreShape();
1667 return(WPE_ESC);
1668 }
1669 e_sys_end();
1670 e_free_arg(arg, argc - 1);
1671 i = e_p_exec(file, f, NULL);
1672 WpeMouseRestoreShape();
1673 return(i);
1674 }
1675
e_run_sh(FENSTER * f)1676 int e_run_sh(FENSTER *f)
1677 {
1678 int ret, len = strlen(f->datnam);
1679 char estr[128];
1680
1681 if (strcmp(f->datnam+len-3, ".sh"))
1682 return(1);
1683
1684 WpeMouseChangeShape(WpeWorkingShape);
1685 f->filemode |= 0100;
1686 if (f->save)
1687 e_save(f);
1688 strcpy(estr, f->datnam);
1689 strcat(estr, " ");
1690 if (e_prog.arguments)
1691 strcat(estr, e_prog.arguments);
1692 #ifndef NO_XWINDOWS
1693 if (WpeIsXwin())
1694 {
1695 ret = (*e_u_system)(estr);
1696 }
1697 else
1698 #endif
1699 ret = e_system(estr, f->ed);
1700 WpeMouseRestoreShape();
1701 return(0);
1702 }
1703
1704 /* new project */
1705
1706 struct proj_var { char *var, *string; } **p_v = NULL;
1707 int p_v_n = 0;
1708
1709
e_interpr_var(char * string)1710 char *e_interpr_var(char *string)
1711 {
1712 int i, j;
1713
1714 for (i = 0; string[i]; i++)
1715 {
1716 if (string[i] == '\\')
1717 for (j = i; (string[j] = string[j+1]) != '\0'; j++)
1718 ;
1719 else if (string[i] == '\'' || string[i] == '\"')
1720 {
1721 for(j = i; (string[j] = string[j+1]) != '\0'; j++)
1722 ;
1723 i--;
1724 }
1725 }
1726 return(string);
1727 }
1728
e_expand_var(char * string,FENSTER * f)1729 char *e_expand_var(char *string, FENSTER *f)
1730 {
1731 int i, j = 0, k, len, kl = 0;
1732 char *var = NULL, *v_string, *tmp;
1733
1734 for (i = 0; string[i]; i++)
1735 {
1736 if (string[i] == '\'')
1737 {
1738 kl = kl ? 0 : 1;
1739 for (j = i; (string[j] = string[j+1]) != '\0'; j++);
1740 i--;
1741 continue;
1742 }
1743 if (string[i] == '\\' && (string[i+1] == 'n' || string[i+1] == 'r'))
1744 {
1745 string[i] = string[i+1] == 'n' ? '\n' : '\r';
1746 for (j = i+1; (string[j] = string[j+1]) != '\0'; j++);
1747 continue;
1748 }
1749 if (string[i] == '$' && !kl && (!i || string[i-1] != '\\'))
1750 {
1751 if (string[i+1] == '(')
1752 {
1753 for (j = i+2; string[j] && string[j] != ')'; j++);
1754 if (!string[j]) continue;
1755 }
1756 else if (string[i+1] == '{')
1757 {
1758 for (j = i+2; string[j] && string[j] != '}'; j++);
1759 if (!string[j]) continue;
1760 }
1761 if (string[i+1] == '(' || string[i+1] == '{')
1762 {
1763 if (!(var = MALLOC((j-i-1) * sizeof(char))))
1764 {
1765 e_error(e_msg[ERR_LOWMEM], 0, f->fb);
1766 return(string);
1767 }
1768 for (k = i+2; k < j; k++) var[k-i-2] = string[k];
1769 var[k-i-2] = '\0';
1770 }
1771 else
1772 {
1773 if (!(var = MALLOC(2 * sizeof(char))))
1774 { e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(string); }
1775 var[0] = string[i+1]; var[1] = '\0';
1776 }
1777 if (!(v_string = getenv(var)))
1778 {
1779 for (k = 0; k < p_v_n - 1; k++)
1780 {
1781 if (!strcmp(p_v[k]->var, var))
1782 { v_string = p_v[k]->string; break; }
1783 }
1784 }
1785 if (string[i+1] == '(' || string[i+1] == '{') len = (j-i+1);
1786 else len = 2;
1787 if (!v_string)
1788 {
1789 for(k = i; (string[k] = string[k+len]) != '\0'; k++);
1790 if (!(string = REALLOC(tmp = string, (strlen(string) + 1) * sizeof(char))))
1791 { FREE(var); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(tmp); }
1792 }
1793 else
1794 {
1795 len = strlen(v_string) - len;
1796 if (len >= 0)
1797 {
1798 if (!(string = REALLOC(tmp = string, (k = strlen(string) + len + 1) * sizeof(char))))
1799 { FREE(var); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(tmp); }
1800 for (k--; k > j + len; k--) string[k] = string[k-len];
1801 for (k = i; v_string[k-i]; k++) string[k] = v_string[k-i];
1802 }
1803 else
1804 {
1805 for (k = i; (string[k] = string[k-len]) != '\0'; k++);
1806 for (k = i; v_string[k-i]; k++) string[k] = v_string[k-i];
1807 if (!(string = REALLOC(tmp = string, (strlen(string) + 1) * sizeof(char))))
1808 { FREE(var); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(tmp); }
1809 }
1810 }
1811 FREE(var);
1812 }
1813 }
1814 return(string);
1815 }
1816
e_read_var(FENSTER * f)1817 int e_read_var(FENSTER *f)
1818 {
1819 struct proj_var **tmp;
1820 FILE *fp;
1821 char str[256], *sp1, *sp2, *stmp;
1822 int i;
1823
1824 if ((fp = fopen(e_prog.project, "r")) == NULL) return(-1);
1825 if (p_v)
1826 {
1827 for (i = 0; i < p_v_n; i++)
1828 {
1829 if (p_v[i])
1830 {
1831 if (p_v[i]->var) FREE(p_v[i]->var);
1832 if (p_v[i]->string) FREE(p_v[i]->string);
1833 FREE(p_v[i]);
1834 }
1835 }
1836 FREE(p_v);
1837 }
1838 p_v_n = 0;
1839 if (!(p_v = MALLOC(sizeof(struct proj_var *))))
1840 { fclose(fp); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(-1); }
1841 while (fgets(str, 256, fp))
1842 {
1843 for (i = 0; isspace(str[i]); i++);
1844 if (!str[i]) continue;
1845 else if (str[i] == '#')
1846 {
1847 while (str[strlen(str)-1] != '\n')
1848 { fgets(str, 256, fp); }
1849 continue;
1850 }
1851 sp1 = str + i;
1852 sp2 = strchr(sp1, '=');
1853 if (sp2 == NULL) continue;
1854 for (stmp = sp1; !((isspace(*stmp)) || (*stmp == '=')) && *stmp; stmp++)
1855 ;
1856 *stmp = 0;
1857 for (sp2++; isspace(*sp2) && *sp2 != '\n'; sp2++);
1858 p_v_n++;
1859 if (!(p_v = REALLOC(tmp = p_v, sizeof(struct proj_var *) * p_v_n)))
1860 { p_v = tmp; fclose(fp); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(-1); }
1861 if (!(p_v[p_v_n-1] = MALLOC(sizeof(struct proj_var))))
1862 { fclose(fp); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(-1); }
1863 if (!(p_v[p_v_n-1]->var = MALLOC((strlen(sp1)+1) * sizeof(char))))
1864 { fclose(fp); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(-1); }
1865 strcpy(p_v[p_v_n-1]->var, sp1);
1866 if (!(p_v[p_v_n-1]->string = MALLOC((strlen(sp2)+1) * sizeof(char))))
1867 { fclose(fp); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(-1); }
1868 strcpy(p_v[p_v_n-1]->string, sp2);
1869 while (p_v[p_v_n-1]->string[i = strlen(p_v[p_v_n-1]->string) - 1] != '\n' || (i && p_v[p_v_n-1]->string[i-1] == '\\'))
1870 {
1871 if (p_v[p_v_n-1]->string[i-1] == '\\') p_v[p_v_n-1]->string[i-1] = '\0';
1872 if (!fgets(str, 256, fp)) break;
1873 if (!(p_v[p_v_n-1]->string = REALLOC(stmp = p_v[p_v_n-1]->string,
1874 (strlen(p_v[p_v_n-1]->string)+strlen(str)+1) * sizeof(char))))
1875 {
1876 p_v[p_v_n-1]->string = stmp;
1877 fclose(fp); e_error(e_msg[ERR_LOWMEM], 0, f->fb); return(-1);
1878 }
1879 strcat(p_v[p_v_n-1]->string, str);
1880 }
1881 p_v[p_v_n-1]->string[strlen(p_v[p_v_n-1]->string) - 1] = '\0';
1882 for (i = 0; p_v[p_v_n-1]->string[i]; i++)
1883 if (p_v[p_v_n-1]->string[i] == '\t') p_v[p_v_n-1]->string[i] = ' ';
1884 p_v[p_v_n-1]->string = e_expand_var(p_v[p_v_n-1]->string, f);
1885 }
1886 fclose(fp);
1887 return(0);
1888 }
1889
e_install(FENSTER * f)1890 int e_install(FENSTER *f)
1891 {
1892 char *tp, *sp, *string, *tmp, text[256];
1893 FILE *fp;
1894 int i, j;
1895
1896 if (e_p_make(f)) return(-1);
1897 if (!e__project) return(0);
1898 if ((fp = fopen(e_prog.project, "r")) == NULL)
1899 {
1900 sprintf(text, e_msg[ERR_FOPEN], e_prog.project);
1901 e_error(text, 0, f->fb);
1902 return(WPE_ESC);
1903 }
1904 while ((tp = fgets(text, 256, fp)))
1905 {
1906 if (text[0] == '\t') continue;
1907 for (i = 0; isspace(text[i]); i++)
1908 ;
1909 if (!strncmp(text+i, "install:", 8))
1910 {
1911 while (tp && (text[j = strlen(text)-1] != '\n' || text[j-1] == '\\'))
1912 tp = fgets(text, 256, fp);
1913 break;
1914 }
1915 }
1916 if (!tp)
1917 {
1918 fclose(fp);
1919 return(1);
1920 }
1921 while (tp && (tp = fgets(text, 256, fp)))
1922 {
1923 for (i = 0; isspace(text[i]); i++)
1924 ;
1925 sp = text+i;
1926 if (sp[0] == '#')
1927 {
1928 while (tp && (text[j = strlen(text)-1] != '\n' || text[j-1] == '\\'))
1929 tp = fgets(text, 256, fp);
1930 continue;
1931 }
1932 if (text[0] != '\t')
1933 break;
1934 if (!(string = MALLOC(strlen(sp) + 1)))
1935 {
1936 fclose(fp);
1937 e_error(e_msg[ERR_LOWMEM], 0, f->fb);
1938 return(-1);
1939 }
1940 strcpy(string, sp);
1941 while (tp && (text[j = strlen(text)-1] != '\n' || text[j-1] == '\\'))
1942 {
1943 tp = fgets(text, 256, fp);
1944 if (tp)
1945 {
1946 if (!(string = REALLOC(tmp = string, strlen(string) + strlen(text) + 1)))
1947 {
1948 fclose(fp);
1949 FREE(tmp);
1950 e_error(e_msg[ERR_LOWMEM], 0, f->fb);
1951 return(-1);
1952 }
1953 strcat(string, text);
1954 }
1955 }
1956 if (p_v_n)
1957 p_v_n++;
1958 string = e_expand_var(string, f);
1959 if (p_v_n) p_v_n--;
1960 e_d_p_message(string, f, 1);
1961 system(string);
1962 FREE(string);
1963 }
1964 fclose(fp);
1965 return(0);
1966 }
1967
e_p_get_args(char * string)1968 struct dirfile *e_p_get_args(char *string)
1969 {
1970 struct dirfile *df = MALLOC(sizeof(struct dirfile));
1971 char **tmp;
1972 int i, j, k;
1973
1974 if (!df)
1975 return(NULL);
1976 if (!(df->name = MALLOC(sizeof(char *))))
1977 {
1978 FREE(df);
1979 return(NULL);
1980 }
1981 df->anz = 0;
1982 for (i = 0; string[i]; )
1983 {
1984 for (; isspace(string[i]); i++)
1985 ;
1986 for (j = i; string[j] && !isspace(string[j]); j++)
1987 ;
1988 if (j == i)
1989 break;
1990 df->anz++;
1991 if (!(df->name = REALLOC(tmp = df->name, df->anz * sizeof(char *))))
1992 {
1993 df->anz--;
1994 df->name = tmp;
1995 return(df);
1996 }
1997 if (!(df->name[df->anz-1] = MALLOC((j-i+1)*sizeof(char))))
1998 {
1999 df->anz--;
2000 return(df);
2001 }
2002 for (k = i; k < j; k++)
2003 *(df->name[df->anz-1] + k - i) = string[k];
2004 *(df->name[df->anz-1] + k - i) = '\0';
2005 e_interpr_var(df->name[df->anz-1]);
2006 i = j;
2007 }
2008 return(df);
2009 }
2010
e_p_get_var(char * string)2011 struct dirfile *e_p_get_var(char *string)
2012 {
2013 int i;
2014
2015 for (i = 0; i < p_v_n; i++)
2016 {
2017 if(!strcmp(p_v[i]->var, string))
2018 return(e_p_get_args(p_v[i]->string));
2019 }
2020 return(NULL);
2021 }
2022
e_c_project(FENSTER * f)2023 int e_c_project(FENSTER *f)
2024 {
2025 ECNT *cn = f->ed;
2026 struct dirfile *df = NULL;
2027 char **arg;
2028 int i, j, k, file= -1, len, elen, argc, libsw = 0, exlib = 0, sccs = 0;
2029 char ofile[128];
2030 #ifdef CHECKHEADER
2031 struct stat lbuf[1], obuf[1];
2032 #else
2033 struct stat lbuf[1], cbuf[1], obuf[1];
2034 #endif
2035 PIC *pic = NULL;
2036
2037 last_time = (M_TIME) 0;
2038 e_p_l_comp = 0;
2039 if (e_new_message(f)) return(WPE_ESC);
2040 f = cn->f[cn->mxedt];
2041 if (e_s_prog.comp_str)
2042 {
2043 FREE(e_s_prog.comp_str);
2044 e_s_prog.comp_str = NULL;
2045 }
2046 e_s_prog.comp_sw &= ~1;
2047 e_argc = 1;
2048 argc = 1;
2049 for(i = f->ed->mxedt; i > 0 && (f->ed->f[i]->dtmd != DTMD_DATA ||
2050 f->ed->f[i]->ins != 4 || !f->ed->f[i]->save); i--)
2051 ;
2052 if (i > 0) e_p_update_prj_fl(f);
2053 if (e_read_var(f))
2054 {
2055 sprintf(ofile, e_msg[ERR_FOPEN], e_prog.project);
2056 e_error(ofile, 0, f->fb);
2057 return(-1);
2058 }
2059 e_arg = (char **) MALLOC(e_argc*sizeof(char *));
2060 arg = (char **) MALLOC(argc*sizeof(char *));
2061 df = e_p_get_var("CMP");
2062 if (!df)
2063 {
2064 e_error(e_p_msg[ERR_NOTHING], 0, f->fb);
2065 e_free_arg(arg, argc); e_free_arg(e_arg, e_argc);
2066 return(-1);
2067 }
2068 for (k = 0; k < df->anz; k++, e_argc++, argc++)
2069 {
2070 j = e_argc == 1 ? 1 : 0;
2071 e_arg = REALLOC(e_arg, (e_argc+2)*sizeof(char *));
2072 e_arg[e_argc-j] = MALLOC(strlen(df->name[k]) + 1);
2073 strcpy(e_arg[e_argc-j], df->name[k]);
2074 arg = REALLOC(arg, (argc+2)*sizeof(char *));
2075 arg[argc-j] = MALLOC(strlen(df->name[k]) + 1);
2076 strcpy(arg[argc-j], df->name[k]);
2077 if (e_argc > 1)
2078 e_s_prog.comp_str = e_cat_string(e_s_prog.comp_str, e_arg[e_argc-j]);
2079 }
2080 freedf(df);
2081 arg[1] = MALLOC(3);
2082 strcpy(arg[1], "-c");
2083 e_arg[1] = MALLOC(3);
2084 strcpy(e_arg[1], "-o");
2085 df = e_p_get_var("CMPFLAGS");
2086 if (df)
2087 {
2088 for (k = 0; k < df->anz; k++, e_argc++, argc++)
2089 {
2090 j = e_argc == 1 ? 1 : 0;
2091 e_arg = REALLOC(e_arg, (e_argc+2)*sizeof(char *));
2092 e_arg[e_argc-j] = MALLOC(strlen(df->name[k]) + 1);
2093 strcpy(e_arg[e_argc-j], df->name[k]);
2094 arg = REALLOC(arg, (argc+2)*sizeof(char *));
2095 arg[argc-j] = MALLOC(strlen(df->name[k]) + 1);
2096 strcpy(arg[argc-j], df->name[k]);
2097 if (e_argc > 1)
2098 e_s_prog.comp_str = e_cat_string(e_s_prog.comp_str, e_arg[e_argc-j]);
2099 }
2100 freedf(df);
2101 }
2102 df = e_p_get_var("EXENAME");
2103 elen = strlen(e_prog.exedir)-1;
2104 if (e_prog.exedir[elen] == '/')
2105 sprintf(ofile, "%s%s", e_prog.exedir,
2106 (df && df->anz > 0 && df->name[0][0]) ? df->name[0] : "a.out");
2107 else
2108 sprintf(ofile, "%s/%s", e_prog.exedir,
2109 (df && df->anz > 0 && df->name[0][0]) ? df->name[0] : "a.out");
2110 if (df) freedf(df);
2111 if (e_s_prog.exe_name) FREE(e_s_prog.exe_name);
2112 e_s_prog.exe_name = WpeStrdup(ofile);
2113 e_argc = e_add_arg(&e_arg, e_s_prog.exe_name, 2, e_argc);
2114 df = e_p_get_var("LIBNAME");
2115 if (df)
2116 {
2117 strcpy(library, df->name[0]);
2118 if (access(library, 0)) exlib = 1;
2119 else stat(library, lbuf);
2120 freedf(df);
2121 }
2122 else
2123 library[0] = '\0';
2124 df = e_p_get_var("CMPSWTCH");
2125 if (df)
2126 {
2127 if (!strcmp(df->name[0], "other"))
2128 e_s_prog.comp_sw = 1;
2129 freedf(df);
2130 }
2131 df = e_p_get_var("CMPMESSAGE");
2132 if (df)
2133 {
2134 char *tmpstr = MALLOC(1);
2135 tmpstr[0] = '\0';
2136 for (k = 0; k < df->anz; k++)
2137 {
2138 tmpstr = REALLOC(tmpstr,
2139 (strlen(tmpstr)+strlen(df->name[k])+2)*sizeof(char));
2140 if (k) strcat(tmpstr, " ");
2141 strcat(tmpstr, df->name[k]);
2142 }
2143 if (e_s_prog.intstr) FREE(e_s_prog.intstr);
2144 e_s_prog.intstr = WpeStrdup(tmpstr);
2145 FREE(tmpstr);
2146 freedf(df);
2147 }
2148 else
2149 {
2150 if (e_s_prog.intstr) FREE(e_s_prog.intstr);
2151 e_s_prog.intstr = WpeStrdup(cc_intstr);
2152 }
2153 df = e_p_get_var("FILES");
2154 if (!df)
2155 {
2156 e_error(e_p_msg[ERR_NOTHING], 0, cn->fb);
2157 e_free_arg(arg, argc); e_free_arg(e_arg, e_argc);
2158 return(-1);
2159 }
2160 arg[argc] = NULL;
2161 elen = strlen(e_prog.exedir)-1;
2162 for (k = 0; k < df->anz; k++)
2163 {
2164 for (j = cn->mxedt; j > 0; j--)
2165 if (!strcmp(cn->f[j]->datnam, df->name[k]) && cn->f[j]->save)
2166 e_save(cn->f[j]);
2167 for (j = strlen(df->name[k])-1; j >= 0 && df->name[k][j] != DIRC; j--)
2168 ;
2169 if (e_prog.exedir[elen] == '/')
2170 sprintf(ofile, "%s%s ", e_prog.exedir, df->name[k]+j+1);
2171 else sprintf(ofile, "%s/%s ", e_prog.exedir, df->name[k]+j+1);
2172 for (j = strlen(ofile); j > 0 && ofile[j] != '.'; j--)
2173 ;
2174 ofile[j+1] = 'o';
2175 ofile[j+2] = '\0';
2176 if (!stat(ofile, obuf))
2177 {
2178 if (obuf->st_mtime > last_time) last_time = obuf->st_mtime;
2179 #ifdef CHECKHEADER
2180 if (!e_check_header(df->name[k], obuf->st_mtime, cn, 0)) goto gt_library;
2181 #else
2182 stat(df->name[k], cbuf);
2183 if (obuf->st_mtime >= cbuf->st_mtime) goto gt_library;
2184 #endif
2185 }
2186 argc = e_add_arg(&arg, df->name[k], argc, argc);
2187 #ifndef NO_MINUS_C_MINUS_O
2188 argc = e_add_arg(&arg, "-o", argc, argc);
2189 argc = e_add_arg(&arg, ofile, argc, argc);
2190 #endif
2191 arg[argc] = NULL;
2192 remove(ofile);
2193 sccs = 1;
2194 j = e_p_mess_win("Compiling", argc, arg, &pic, f);
2195 e_sys_ini();
2196 if (j != 0 || (file = e_exec_inf(f, arg, argc)) == 0)
2197 {
2198 e_sys_end();
2199 e_free_arg(arg, argc);
2200 freedf(df);
2201 e_free_arg(e_arg, e_argc);
2202 if (pic) e_close_view(pic, 1);
2203 return(WPE_ESC);
2204 }
2205 e_sys_end();
2206 e_p_l_comp = 1;
2207 if (e_p_exec(file, f, pic))
2208 {
2209 e_free_arg(arg, argc);
2210 e_free_arg(e_arg, e_argc);
2211 freedf(df);
2212 return(-1);
2213 }
2214 pic = NULL;
2215 for (j = strlen(ofile); j >= 0 && ofile[j] != '/'; j--)
2216 ;
2217 if (!exlib && library[0] != '\0' && strcmp(ofile+j+1, "main.o") &&
2218 (strncmp(e_s_prog.exe_name, ofile+j+1,(len = strlen(e_s_prog.exe_name))) ||
2219 ofile[len] == '.'))
2220 {
2221 if(e_make_library(library, ofile, f))
2222 {
2223 e_free_arg(arg, argc);
2224 e_free_arg(e_arg, e_argc);
2225 freedf(df);
2226 return(-1);
2227 }
2228 else libsw = 1;
2229 }
2230 for (j = 0; j < 3; j++) FREE(arg[argc-j-1])
2231 ;
2232 argc -= 3;
2233 gt_library:
2234 for (j = strlen(ofile); j >= 0 && ofile[j] != '/'; j--)
2235 ;
2236 if (library[0] == '\0' || !strcmp(ofile+j+1, "main.o") ||
2237 (!strncmp(e_s_prog.exe_name, ofile+j+1,(len = strlen(e_s_prog.exe_name))) &&
2238 ofile[len] == '.'))
2239 e_argc = e_add_arg(&e_arg, ofile, e_argc, e_argc);
2240 else if (exlib || obuf->st_mtime >= lbuf->st_mtime)
2241 {
2242 if (e_make_library(library, ofile, f))
2243 {
2244 e_free_arg(arg, argc);
2245 e_free_arg(e_arg, e_argc);
2246 freedf(df);
2247 return(-1);
2248 }
2249 else libsw = 1;
2250 }
2251 }
2252 #ifdef RANLIB
2253 if (libsw && library[0] != '\0')
2254 {
2255 char *ar_arg[3];
2256 ar_arg[0] = "ranlib";
2257 ar_arg[1] = library;
2258 ar_arg[2] = NULL;
2259 if (!(j = e_p_mess_win("Convert Archive", 2, ar_arg, &pic, f)))
2260 {
2261 e_sys_ini();
2262 file = e_exec_inf(f, ar_arg, 2);
2263 e_sys_end();
2264 if (file) j = e_p_exec(file, f, pic);
2265 }
2266 if (j || !file)
2267 {
2268 e_free_arg(arg, argc);
2269 e_free_arg(e_arg, e_argc);
2270 freedf(df);
2271 return(-1);
2272 }
2273 }
2274 #endif
2275 if (library[0] != '\0')
2276 e_argc = e_add_arg(&e_arg, library, e_argc, e_argc);
2277 freedf(df);
2278 df = e_p_get_var("LDFLAGS");
2279 if (df)
2280 {
2281 FREE(e_s_prog.libraries);
2282 e_s_prog.libraries = NULL;
2283 for (k = 0; k < df->anz; k++, e_argc++)
2284 {
2285 e_arg = REALLOC(e_arg, (e_argc+2)*sizeof(char *));
2286 e_arg[e_argc] = MALLOC(strlen(df->name[k]) + 1);
2287 strcpy(e_arg[e_argc], df->name[k]);
2288 e_s_prog.libraries = e_cat_string(e_s_prog.libraries, e_arg[e_argc]);
2289 }
2290 freedf(df);
2291 }
2292 e_arg[e_argc] = NULL;
2293 e_free_arg(arg, argc);
2294 if (!sccs) e_p_exec(file, f, pic);
2295 return(0);
2296 }
2297
e_free_arg(char ** arg,int argc)2298 int e_free_arg(char **arg, int argc)
2299 {
2300 int i;
2301
2302 for(i = 0; i < argc; i++)
2303 if(arg[i])
2304 FREE(arg[i]);
2305 FREE(arg);
2306 return(i);
2307 }
2308
e_find_var(char * var)2309 char *e_find_var(char *var)
2310 {
2311 int i;
2312
2313 for(i = 0; i < p_v_n && strcmp(p_v[i]->var, var); i++);
2314 if(i >= p_v_n)
2315 return(NULL);
2316 else
2317 return(p_v[i]->string);
2318 }
2319
2320 /****************************************************/
2321 /**** reloading watches and breakpoints from prj ****/
2322 /**** based on p_v variable ****/
2323
2324 /****
2325 this function is called only on project opening.
2326 It is used for additional parsing variables from
2327 project file, ie for loading BREAKPOINTS and WATCHES.
2328 ****/
2329
e_rel_brkwtch(FENSTER * f)2330 int e_rel_brkwtch(FENSTER *f)
2331 {
2332 int i;
2333
2334 for (i = 0; i < p_v_n; i++)
2335 {
2336 if (!strcmp(p_v[i]->var, "BREAKPOINTS"))
2337 {
2338 e_d_reinit_brks(f,p_v[i]->string);
2339 }
2340 else if (!strcmp(p_v[i]->var, "WATCHES"))
2341 {
2342 e_d_reinit_watches(f,p_v[i]->string);
2343 }
2344 }
2345 return 0;
2346 }
2347
2348 /****************************************************/
2349
2350 /****
2351 this function is called each time options window
2352 is opened. But unfortunately also reloads variables
2353 from project file, which is not good for WATCHES
2354 and BREAKPOINTS.
2355 ****/
e_make_prj_opt(FENSTER * f)2356 struct dirfile **e_make_prj_opt(FENSTER *f)
2357 {
2358 int i, j, ret;
2359 char **tmp, *sp, *tp, text[256];
2360 FILE *fp;
2361 struct dirfile *save_df = NULL;
2362
2363 for (i = f->ed->mxedt; i > 0
2364 && (f->ed->f[i]->dtmd != DTMD_DATA || f->ed->f[i]->ins != 4
2365 || !f->ed->f[i]->save); i--);
2366 if (i > 0) { save_df = e_p_df[0]; e_p_df[0] = NULL; }
2367 if (e_p_df) freedfN(e_p_df, 3);
2368 e_p_df = MALLOC(3 * sizeof(struct dirfile *));
2369 if (!e_p_df) return(e_p_df);
2370 for (i = 0; i < 3; i++) e_p_df[i] = NULL;
2371 e_s_prog.comp_sw = 0;
2372 ret = e_read_var(f);
2373 if (ret)
2374 {
2375 if (e_s_prog.compiler) FREE(e_s_prog.compiler);
2376 e_s_prog.compiler = WpeStrdup("gcc");
2377 if (e_s_prog.comp_str) FREE(e_s_prog.comp_str);
2378 e_s_prog.comp_str = WpeStrdup("-g");
2379 if (e_s_prog.libraries) FREE(e_s_prog.libraries);
2380 e_s_prog.libraries = WpeStrdup("");
2381 if (e_s_prog.exe_name) FREE(e_s_prog.exe_name);
2382 /* Project my_prog.prj defaults to an executable of my_prog BD */
2383 strcpy(text, e_prog.project);
2384 e_s_prog.exe_name = WpeStrdup(WpeStringCutChar(text, '.'));
2385 /*e_s_prog.exe_name = WpeStrdup("a.out");*/
2386 if (e_s_prog.intstr) FREE(e_s_prog.intstr);
2387 e_s_prog.intstr = WpeStrdup(cc_intstr);
2388 strcpy(library, "");
2389 for (i = !save_df ? 0 : 1; i < 3; i++)
2390 {
2391 e_p_df[i] = MALLOC(sizeof(struct dirfile));
2392 e_p_df[i]->name = MALLOC(sizeof(char *));
2393 e_p_df[i]->name[0] = MALLOC(2 * sizeof(char));
2394 *e_p_df[i]->name[0] = ' '; *(e_p_df[i]->name[0] + 1) = '\0';
2395 e_p_df[i]->anz = 1;
2396 }
2397 if (save_df) e_p_df[0] = save_df;
2398 return(e_p_df);
2399 }
2400 if (!(e_p_df[1] = MALLOC(sizeof(struct dirfile)))) return(e_p_df);
2401 if (!(e_p_df[1]->name = MALLOC(sizeof(char *)))) return(e_p_df);
2402 e_p_df[1]->anz = 0;
2403 if (!(e_p_df[2] = MALLOC(sizeof(struct dirfile)))) return(e_p_df);
2404 if (!(e_p_df[2]->name = MALLOC(sizeof(char *)))) return(e_p_df);
2405 e_p_df[2]->anz = 0;
2406 for (i = 0; i < p_v_n; i++)
2407 {
2408 if (!strcmp(p_v[i]->var, "CMP"))
2409 {
2410 if (e_s_prog.compiler) FREE(e_s_prog.compiler);
2411 e_s_prog.compiler = WpeStrdup(p_v[i]->string);
2412 }
2413 else if (!strcmp(p_v[i]->var, "CMPFLAGS"))
2414 {
2415 if (e_s_prog.comp_str) FREE(e_s_prog.comp_str);
2416 e_s_prog.comp_str = WpeStrdup(p_v[i]->string);
2417 }
2418 else if (!strcmp(p_v[i]->var, "LDFLAGS"))
2419 {
2420 if (e_s_prog.libraries) FREE(e_s_prog.libraries);
2421 e_s_prog.libraries = WpeStrdup(p_v[i]->string);
2422 }
2423 else if (!strcmp(p_v[i]->var, "EXENAME"))
2424 {
2425 if (e_s_prog.exe_name) FREE(e_s_prog.exe_name);
2426 e_s_prog.exe_name = WpeStrdup(p_v[i]->string);
2427 }
2428 else if (!strcmp(p_v[i]->var, "CMPMESSAGE"))
2429 {
2430 if (e_s_prog.intstr) FREE(e_s_prog.intstr);
2431 e_s_prog.intstr = WpeStrdup(e_interpr_var(p_v[i]->string));
2432 }
2433
2434 /**************************/
2435 /****
2436 this is needed, because this function needs to understand that
2437 BREAKPOINTS and WATCHES are project variables.
2438 These variables will be processed later on in e_rel_brkwtch
2439 function.
2440 ****/
2441 else if (!strcmp(p_v[i]->var, "BREAKPOINTS"))
2442 {
2443 }
2444 else if (!strcmp(p_v[i]->var, "WATCHES"))
2445 {
2446 }
2447 /**************************/
2448
2449 else if (!strcmp(p_v[i]->var, "LIBNAME"))
2450 strcpy(library, p_v[i]->string);
2451 else if (!strcmp(p_v[i]->var, "CMPSWTCH"))
2452 {
2453 if (!strcmp(p_v[i]->string, "other")) e_s_prog.comp_sw = 1;
2454 }
2455 else if (!strcmp(p_v[i]->var, "FILES"))
2456 e_p_df[0] = e_p_get_args(p_v[i]->string);
2457 else
2458 {
2459 e_p_df[1]->anz++;
2460 if (!(e_p_df[1]->name = REALLOC(tmp =
2461 e_p_df[1]->name, e_p_df[1]->anz * sizeof(char *))))
2462 { e_p_df[1]->anz--; e_p_df[1]->name = tmp; return(e_p_df); }
2463 if (!(e_p_df[1]->name[e_p_df[1]->anz-1] = MALLOC((strlen(p_v[i]->var)
2464 + strlen(p_v[i]->string) + 2)*sizeof(char))))
2465 { e_p_df[1]->anz--; return(e_p_df); }
2466 sprintf(e_p_df[1]->name[e_p_df[1]->anz-1], "%s=%s",
2467 p_v[i]->var, p_v[i]->string);
2468 }
2469 }
2470 if (!e_s_prog.compiler)
2471 e_s_prog.compiler = WpeStrdup("gcc");
2472 if (!e_s_prog.comp_str)
2473 e_s_prog.comp_str = WpeStrdup("-g");
2474 if (!e_s_prog.libraries)
2475 e_s_prog.libraries = WpeStrdup("");
2476 if (!e_s_prog.exe_name)
2477 {
2478 /* Project my_prog.prj defaults to an executable of my_prog BD */
2479 strcpy(text, e_prog.project);
2480 e_s_prog.exe_name = WpeStrdup(WpeStringCutChar(text, '.'));
2481 /*e_s_prog.exe_name = WpeStrdup("a.out");*/
2482 }
2483 if (!e_s_prog.intstr)
2484 e_s_prog.intstr = WpeStrdup(cc_intstr);
2485 if (!e_p_df[0])
2486 {
2487 e_p_df[0] = MALLOC(sizeof(struct dirfile));
2488 e_p_df[0]->anz = 0;
2489 }
2490 if ((fp = fopen(e_prog.project, "r")) == NULL)
2491 {
2492 sprintf(text, e_msg[ERR_FOPEN], e_prog.project);
2493 e_error(text, 0, f->fb);
2494 return(e_p_df);
2495 }
2496 while ((tp = fgets(text, 256, fp)))
2497 {
2498 if (text[0] == '\t') continue;
2499 for (i = 0; isspace(text[i]); i++);
2500 if (!strncmp(text+i, "install:", 8))
2501 {
2502 while(tp && (text[j = strlen(text)-1] != '\n' || text[j-1] == '\\'))
2503 tp = fgets(text, 256, fp);
2504 break;
2505 }
2506 }
2507 if (!tp) { fclose(fp); return(e_p_df); }
2508 while(tp && (tp = fgets(text, 256, fp)))
2509 {
2510 for (i = 0; isspace(text[i]); i++);
2511 sp = text+i;
2512 if (sp[0] == '#')
2513 {
2514 while(tp && (text[j = strlen(text)-1] != '\n' || text[j-1] == '\\'))
2515 tp = fgets(text, 256, fp);
2516 continue;
2517 }
2518 if (text[0] != '\t') break;
2519 if (sp[0] == '\0') continue;
2520 e_p_df[2]->anz++;
2521 if (!(e_p_df[2]->name = REALLOC(tmp =
2522 e_p_df[2]->name, e_p_df[2]->anz * sizeof(char *))))
2523 { e_p_df[2]->anz--; e_p_df[2]->name = tmp; fclose(fp); return(e_p_df); }
2524 if (!(e_p_df[2]->name[e_p_df[2]->anz-1] = MALLOC((strlen(sp) + 1))))
2525 { e_p_df[2]->anz--; fclose(fp); return(e_p_df); }
2526
2527 strcpy(e_p_df[2]->name[e_p_df[2]->anz-1], sp);
2528 while(tp && (text[j = strlen(text)-1] != '\n' || text[j-1] == '\\'))
2529 {
2530 tp = fgets(text, 256, fp);
2531 if (tp)
2532 {
2533 j = strlen(e_p_df[2]->name[e_p_df[2]->anz-1]);
2534 *(e_p_df[2]->name[e_p_df[2]->anz-1]+j-2) = '\0';
2535 if (!(e_p_df[2]->name[e_p_df[2]->anz-1] =
2536 REALLOC(sp = e_p_df[2]->name[e_p_df[2]->anz-1],
2537 strlen(e_p_df[2]->name[e_p_df[2]->anz-1])
2538 + strlen(text) + 1)))
2539 { fclose(fp); FREE(sp); e_error(e_msg[ERR_LOWMEM], 0, f->fb);
2540 return(e_p_df);
2541 }
2542 strcat(e_p_df[2]->name[e_p_df[2]->anz-1], text);
2543 }
2544 }
2545 j = strlen(e_p_df[2]->name[e_p_df[2]->anz-1]);
2546 if (*(e_p_df[2]->name[e_p_df[2]->anz-1]+j-1) == '\n')
2547 *(e_p_df[2]->name[e_p_df[2]->anz-1]+j-1) = '\0';
2548 }
2549 fclose(fp);
2550 for (i = 0; i < 3; i++)
2551 {
2552 if (!e_p_df[i])
2553 {
2554 e_p_df[i] = MALLOC(sizeof(struct dirfile));
2555 e_p_df[i]->name = MALLOC(sizeof(char *));
2556 e_p_df[i]->anz = 0;
2557 }
2558 e_p_df[i]->name = REALLOC(e_p_df[i]->name,
2559 (e_p_df[i]->anz + 1) * sizeof(char *));
2560 e_p_df[i]->name[e_p_df[i]->anz] = MALLOC(2*sizeof(char));
2561 *e_p_df[i]->name[e_p_df[i]->anz] = ' ';
2562 *(e_p_df[i]->name[e_p_df[i]->anz] + 1) = '\0';
2563 e_p_df[i]->anz++;
2564 }
2565 if (save_df) { freedf(e_p_df[0]); e_p_df[0] = save_df; }
2566 return(e_p_df);
2567 }
2568
freedfN(struct dirfile ** df,int n)2569 int freedfN(struct dirfile **df, int n)
2570 {
2571 int i;
2572
2573 for(i = 0; i < n; i++)
2574 if(df[i])
2575 freedf(df[i]);
2576 FREE(df);
2577 return(0);
2578 }
2579
e_wrt_prj_fl(FENSTER * f)2580 int e_wrt_prj_fl(FENSTER *f)
2581 {
2582 int i, len;
2583 FILE *fp;
2584 char text[256];
2585
2586 for (i = f->ed->mxedt;
2587 i > 0 && (f->ed->f[i]->dtmd != DTMD_DATA || f->ed->f[i]->ins != 4); i--)
2588 ;
2589 if (i == 0 || e_prog.project[0] == DIRC)
2590 strcpy(text, e_prog.project);
2591 else
2592 sprintf(text, "%s/%s", f->ed->f[i]->dirct, e_prog.project);
2593 if ((fp = fopen(text, "w")) == NULL)
2594 {
2595 sprintf(text, e_msg[ERR_FOPEN], e_prog.project);
2596 e_error(text, 0, f->fb);
2597 return(-1);
2598 }
2599 fprintf(fp, "#\n# xwpe - project-file: %s\n", e_prog.project);
2600 fprintf(fp, "# created by xwpe version %s\n#\n", VERSION);
2601 for (i = 0; i < e_p_df[1]->anz; i++)
2602 fprintf(fp, "%s\n", e_p_df[1]->name[i]);
2603 fprintf(fp, "\nCMP=\t%s\n", e_s_prog.compiler);
2604 fprintf(fp, "CMPFLAGS=\t%s\n", e_s_prog.comp_str);
2605 fprintf(fp, "LDFLAGS=\t%s\n", e_s_prog.libraries);
2606 fprintf(fp, "EXENAME=\t%s\n", e_s_prog.exe_name);
2607 if (library[0])
2608 fprintf(fp, "LIBNAME=\t%s\n", library);
2609 fprintf(fp, "CMPSWTCH=\t%s\n", e_s_prog.comp_sw ? "other" : "gnu");
2610 fprintf(fp, "CMPMESSAGE=\t\'");
2611 for (i = 0; e_s_prog.intstr[i]; i++)
2612 {
2613 if (e_s_prog.intstr[i] == '\n')
2614 fprintf(fp, "\\n");
2615 else if (e_s_prog.intstr[i] == '\r')
2616 fprintf(fp, "\\r");
2617 else if (e_s_prog.intstr[i] == '\\' || e_s_prog.intstr[i] == '\'' ||
2618 e_s_prog.intstr[i] == '\"' )
2619 {
2620 fputc('\\', fp);
2621 fputc(e_s_prog.intstr[i], fp);
2622 }
2623 else fputc(e_s_prog.intstr[i], fp);
2624 }
2625 fprintf(fp, "\'\n");
2626 fprintf(fp, "\nFILES=\t");
2627 for (i = 0, len = 8; i < e_p_df[0]->anz; i++)
2628 {
2629 len += strlen(e_p_df[0]->name[i]);
2630 if (len > 80)
2631 {
2632 fprintf(fp, " \\\n\t");
2633 len = 1;
2634 }
2635 fprintf(fp, "%s ", e_p_df[0]->name[i]);
2636 }
2637 fprintf(fp, "\n");
2638
2639 /*****************************************/
2640 /**** save WATCHES and BREAKPOINTS ****/
2641 if (e_d_nbrpts > 0)
2642 {
2643 fprintf(fp, "\nBREAKPOINTS=\t");
2644 for (i = 0; i < (e_d_nbrpts-1); i++)
2645 {
2646 fprintf(fp, "%s:%d;",e_d_sbrpts[i],e_d_ybrpts[i]);
2647 }
2648 fprintf(fp, "%s:%d",e_d_sbrpts[e_d_nbrpts-1],e_d_ybrpts[e_d_nbrpts-1]);
2649 }
2650
2651 if (e_d_nwtchs > 0)
2652 {
2653 fprintf(fp, "\nWATCHES=\t");
2654 for (i = 0; i < (e_d_nwtchs-1); i++)
2655 {
2656 fprintf(fp, "%s;",e_d_swtchs[i]);
2657 }
2658 fprintf(fp, "%s",e_d_swtchs[e_d_nwtchs-1]);
2659 }
2660 fprintf(fp, "\n");
2661 /*****************************************/
2662
2663 if (e_p_df[2]->anz > 0)
2664 fprintf(fp, "\ninstall:\n");
2665 for (i = 0; i < e_p_df[2]->anz; i++)
2666 fprintf(fp, "\t%s\n", e_p_df[2]->name[i]);
2667 fclose(fp);
2668 return(0);
2669 }
2670
e_p_update_prj_fl(FENSTER * f)2671 int e_p_update_prj_fl(FENSTER *f)
2672 {
2673 if(!e_make_prj_opt(f))
2674 return(-1);
2675 if(e_wrt_prj_fl(f))
2676 return(-1);
2677 return(0);
2678 }
2679
e_p_add_df(FLWND * fw,int sw)2680 int e_p_add_df(FLWND *fw, int sw)
2681 {
2682 char *title = NULL, str[256];
2683 int i;
2684
2685 if (sw == 4)
2686 title = "Add File";
2687 else if (sw == 5)
2688 title = "Add Variable";
2689 else if (sw == 6)
2690 title = "Add Command";
2691 str[0] = '\0'; /* terminate new string to prevent garbage in display */
2692 if (e_add_arguments(str, title, fw->f, 0, AltA, NULL))
2693 {
2694 fw->df->anz++;
2695 fw->df->name = REALLOC(fw->df->name, fw->df->anz * sizeof(char *));
2696 for (i = fw->df->anz - 1; i > fw->nf; i--)
2697 fw->df->name[i] = fw->df->name[i-1];
2698 fw->df->name[i] = MALLOC(strlen(str)+1);
2699 strcpy(fw->df->name[i], str);
2700 }
2701 return(0);
2702 }
2703
e_p_edit_df(FLWND * fw,int sw)2704 int e_p_edit_df(FLWND *fw, int sw)
2705 {
2706 char *title = NULL, str[256];
2707 int new = 0;
2708 if (sw == 4)
2709 title = "Change Filename";
2710 else if (sw == 5)
2711 title = "Change Variable";
2712 else if (sw == 6)
2713 title = "Change Command";
2714 if (fw->nf < fw->df->anz-1 && fw->df->name[fw->nf])
2715 strcpy(str, fw->df->name[fw->nf]);
2716 else
2717 {
2718 new = 1;
2719 str[0] = '\0';
2720 }
2721 if (e_add_arguments(str, title, fw->f, 0, AltA, NULL))
2722 {
2723 if (fw->nf > fw->df->anz-2)
2724 {
2725 fw->nf = fw->df->anz-1;
2726 fw->df->anz++;
2727 fw->df->name = REALLOC(fw->df->name, fw->df->anz * sizeof(char *));
2728 fw->df->name[fw->df->anz-1] = fw->df->name[fw->df->anz-2];
2729 }
2730 if (!new)
2731 FREE(fw->df->name[fw->nf]);
2732 fw->df->name[fw->nf] = MALLOC(strlen(str)+1);
2733 if (fw->df->name[fw->nf])
2734 strcpy(fw->df->name[fw->nf], str);
2735 }
2736 return(0);
2737 }
2738
e_p_del_df(FLWND * fw,int sw)2739 int e_p_del_df(FLWND *fw, int sw)
2740 {
2741 int i;
2742
2743 if (fw->nf > fw->df->anz-2)
2744 return(0);
2745 fw->df->anz--;
2746 for (i = fw->nf; i < fw->df->anz; i++)
2747 fw->df->name[i] = fw->df->name[i+1];
2748 return(0);
2749 }
2750
e_p_mess_win(char * header,int argc,char ** argv,PIC ** pic,FENSTER * f)2751 int e_p_mess_win(char *header, int argc, char **argv, PIC **pic, FENSTER *f)
2752 {
2753 char *tmp = MALLOC(sizeof(char));
2754 int i, ret;
2755
2756 fk_cursor(0);
2757 tmp[0] = '\0';
2758 for (i = 0; i < argc && argv[i] != NULL; i++)
2759 {
2760 if(!(tmp = REALLOC(tmp, (strlen(tmp)+strlen(argv[i])+2)*sizeof(char))))
2761 return(-2);
2762 strcat(tmp, argv[i]);
2763 strcat(tmp, " ");
2764 }
2765 ret = e_mess_win(header, tmp, pic, f);
2766 FREE(tmp);
2767 fk_cursor(1);
2768 return(ret);
2769 }
2770
2771 /* After this function b has exactly 1 line allocated (b->mxlines==1).
2772 This line is initialized to the string WPE_WR,0 */
e_p_red_buffer(BUFFER * b)2773 int e_p_red_buffer(BUFFER *b)
2774 {
2775 int i;
2776
2777 for (i = 1; i < b->mxlines; i++)
2778 if (b->bf[i].s != NULL)
2779 FREE( b->bf[i].s );
2780 if (b->mxlines==0) e_new_line(0,b);
2781 b->bf[0].s[0] = WPE_WR;
2782 b->bf[0].s[1] = '\0';
2783 b->bf[0].len = 0;
2784 b->bf[0].nrc = 1;
2785 b->mxlines = 1;
2786 return(0);
2787 }
2788
e_new_message(FENSTER * f)2789 int e_new_message(FENSTER *f)
2790 {
2791 int i;
2792
2793 if (e_p_m_buffer)
2794 e_p_red_buffer(e_p_m_buffer);
2795 for (i = f->ed->mxedt; i > 0; i--)
2796 if (!strcmp(f->ed->f[i]->datnam, "Messages"))
2797 {
2798 e_switch_window(f->ed->edt[i], f->ed->f[f->ed->mxedt]);
2799 e_close_window(f->ed->f[f->ed->mxedt]);
2800 }
2801 if (access("Messages", 0) == 0)
2802 remove("Messages");
2803 if (e_edit(f->ed, "Messages"))
2804 return(WPE_ESC);
2805 return(0);
2806 }
2807
e_p_show_messages(FENSTER * f)2808 int e_p_show_messages(FENSTER *f)
2809 {
2810 int i;
2811
2812 for (i = f->ed->mxedt; i > 0; i--)
2813 if (!strcmp(f->ed->f[i]->datnam, "Messages"))
2814 {
2815 e_switch_window(f->ed->edt[i], f->ed->f[f->ed->mxedt]);
2816 break;
2817 }
2818 if (i <= 0 && e_edit(f->ed, "Messages"))
2819 {
2820 return(-1);
2821 }
2822 f = f->ed->f[f->ed->mxedt];
2823 if (f->b->mxlines == 0)
2824 {
2825 e_new_line(0, f->b);
2826 e_ins_nchar(f->b, f->s, "No Messages", 0, 0, 11);
2827 e_schirm(f, 1);
2828 }
2829 return(0);
2830 }
2831
e_p_konv_mess(char * var,char * str,char * txt,char * file,char * cmp,int * y,int * x)2832 int e_p_konv_mess(char *var, char *str, char *txt, char *file, char *cmp,
2833 int *y, int *x)
2834 {
2835 int i;
2836 char *cp;
2837
2838 if (!strncmp(var, "FILE", 4) && !isalnum(var[4]))
2839 {
2840 for (i = strlen(str) - 1; i >= 0 && !isspace(str[i]); i--)
2841 ;
2842 strcpy(file, str+i+1);
2843 }
2844 else if (!strncmp(var, "CMPTEXT", 7) && !isalnum(var[7]))
2845 strcpy(cmp, str);
2846 else if (!strncmp(var, "LINE", 4) && !isalnum(var[4]))
2847 {
2848 if (!isdigit(str[0]))
2849 return(1);
2850 *y = atoi(str);
2851 if (var[4] == '+')
2852 *y += atoi(var+5);
2853 else if (var[4] == '-')
2854 *y -= atoi(var+5);
2855 }
2856 else if (!strncmp(var, "COLUMN", 6) && !isalnum(var[6]))
2857 {
2858 if (!strncmp(var+6, "=BEFORE", 7))
2859 {
2860 txt[0] = 'B';
2861 strcpy(txt+1, str);
2862 *x = 0;
2863 var += 13;
2864 }
2865 else if (!strncmp(var+6, "=AFTER", 6))
2866 {
2867 txt[0] = 'A';
2868 strcpy(txt+1, str);
2869 *x = strlen(str);
2870 var += 12;
2871 }
2872 else if (!strncmp(var+6, "=PREVIOUS?", 10))
2873 {
2874 if (!str[0])
2875 return(1);
2876 for (i = 0; (txt[i] = var[16+i]) && txt[i] != '+' && txt[i] != '-'; i++)
2877 ;
2878 txt[i] = '\0';
2879 var += (16+i);
2880 cp = strstr(str, txt);
2881 for (i = 0; str+i < cp; i++)
2882 ;
2883 *x = i;
2884 txt[0] = 'P'; txt[1] = '\0';
2885 }
2886 else if (!isdigit(str[0]))
2887 return(1);
2888 else
2889 {
2890 *x = atoi(str);
2891 txt[0] = '\0';
2892 var += 6;
2893 }
2894 if (var[0] == '+')
2895 *x += atoi(var+1);
2896 else if (var[0] == '-')
2897 *x -= atoi(var+1);
2898 }
2899 return(0);
2900 }
2901
e_p_comp_mess(char * a,char * b,char * c,char * txt,char * file,char * cmp,int * y,int * x)2902 int e_p_comp_mess(char *a, char *b, char *c, char *txt, char *file, char *cmp,
2903 int *y, int *x)
2904 {
2905 int i, n, k = 0, bsl = 0;
2906 char *ctmp, *cp, *var = NULL, *str = NULL;
2907
2908 if (c > b)
2909 return(0);
2910 if (a[0] == '*' && !a[1])
2911 return(2);
2912 if (!a[0] && !b[0])
2913 return(2);
2914 if (!a[0] || !b[0])
2915 return(0);
2916 if (a[0] == '*' && (a[1] == '*' || a[1] == '$'))
2917 return(e_p_comp_mess(++a, b, c, txt, file, cmp, y, x));
2918 if (a[0] == '$' && a[1] == '{')
2919 {
2920 for (k = 2; a[k] && a[k] != '}'; k++);
2921 var = MALLOC((k-1) * sizeof(char));
2922 for (i = 2; i < k; i++)
2923 var[i-2] = a[i];
2924 var[k-2] = '\0';
2925 if (a[k])
2926 k++;
2927 if (!a[k])
2928 return(!e_p_konv_mess(var, b, txt, file, cmp, y, x));
2929 n = a[k] == '\\' ? k : k+1;
2930 }
2931 else if (a[0] == '*'&& a[1] != '\\')
2932 {
2933 k = 1;
2934 n = 2;
2935 }
2936 else
2937 n = 1;
2938 for(; bsl || (a[n] && a[n] != '*' && a[n] != '?' && a[n] != '[' &&
2939 (a[n] != '$' || a[n+1] != '{' )); n++)
2940 bsl = a[n] == '\\' ? !bsl : 0;
2941 if (a[0] == '*' || a[0] == '$')
2942 {
2943 if (a[k] == '?')
2944 {
2945 cp = MALLOC((strlen(a)+1)*sizeof(char));
2946 for (i = 0; i < k && (cp[i] = a[i]); i++);
2947 for (i++; (cp[i-1] = a[i]) != '\0'; i++);
2948 FREE(var);
2949 n = e_p_comp_mess(cp, ++b, ++c, txt, file, cmp, y, x);
2950 FREE(cp);
2951 return(n);
2952 }
2953 if (a[k] == '[')
2954 {
2955 for (i = 0; b[i] &&
2956 !(n = e_p_comp_mess(a+k, b+i, c+i, txt, file, cmp, y, x)); i++)
2957 ;
2958 if (!b[i])
2959 return(0);
2960 if (a[0] == '$')
2961 {
2962 str = MALLOC((i+1)*sizeof(char));
2963 for (k = 0; k < i; k++)
2964 str[k] = b[k];
2965 str[i] = '\0';
2966 e_p_konv_mess(var, str, txt, file, cmp, y, x);
2967 FREE(var);
2968 FREE(str);
2969 }
2970 return(n);
2971 }
2972 n -= k;
2973 ctmp = MALLOC(n+1);
2974 for (i = 0; i < n; i++)
2975 ctmp[i] = a[i+k];
2976 ctmp[n] = '\0';
2977 cp = strstr(b, ctmp);
2978 FREE(ctmp);
2979 if (cp == NULL)
2980 return(0);
2981 if (a[0] == '$')
2982 {
2983 for (i = 0; c + i < cp; i++);
2984 str = MALLOC((i+1)*sizeof(char));
2985 for (i = 0; c + i < cp; i++)
2986 str[i] = c[i];
2987 str[i] = '\0';
2988 i = e_p_konv_mess(var, str, txt, file, cmp, y, x);
2989 FREE(var);
2990 FREE(str);
2991 if (i)
2992 return(0);
2993 }
2994 if (!a[k+n] && !cp[n])
2995 return(2);
2996 if (!a[k+n])
2997 return(e_p_comp_mess(a, cp+1, cp+1, txt, file, cmp, y, x));
2998 if ((i = e_p_comp_mess(a+k+n, cp+n, cp+n, txt, file, cmp, y, x)))
2999 return(i);
3000 if (file[0] && *y > -1)
3001 return(0);
3002 return(e_p_comp_mess(a, cp+1, a[0] == '$' ? c : cp+1, txt, file, cmp, y, x));
3003 }
3004 else if (a[0] == '?')
3005 {
3006 n--;
3007 a++;
3008 b++;
3009 }
3010 else if (a[0] == '[')
3011 {
3012 if (a[1] == '!')
3013 {
3014 for (k = 2; a[k] && (a[k] != ']' || k == 2) && a[k] != b[0]; k++)
3015 if (a[k+1] == '-' && b[0] >= a[k] && b[0] <= a[k+2])
3016 return(-b[0]);
3017 if (a[k] != ']')
3018 return(-b[0]);
3019 n-=(k+1);
3020 a+=(k+1);
3021 b++;
3022 }
3023 else
3024 {
3025 for (k = 1; a[k] && (a[k] != ']' || k == 1) && a[k] != b[0]; k++)
3026 if (a[k+1] == '-' && b[0] >= a[k] && b[0] <= a[k+2])
3027 break;
3028 if (a[k] == ']' || a[k] == '\0')
3029 return(0);
3030 for(; a[k] && (a[k] != ']'); k++);
3031 n-=(k+1);
3032 a+=(k+1);
3033 b++;
3034 }
3035 }
3036 if (n <= 0)
3037 return(e_p_comp_mess(a, b, c, txt, file, cmp, y, x));
3038 if ((k = strncmp(a, b, n)) != 0)
3039 return(0);
3040 return(e_p_comp_mess(a+n, b+n, c+n, txt, file, cmp, y, x));
3041 }
3042
e_p_cmp_mess(char * srch,BUFFER * b,int * ii,int * kk,int ret)3043 int e_p_cmp_mess(char *srch, BUFFER *b, int *ii, int *kk, int ret)
3044 {
3045 char *cp, cmp[128], file[128], search[80], tmp[4][128], **wtxt = NULL;
3046 int j, l, m, n, iy, iorig, i = *ii, k = *kk, x = 0, y = -1, wnum = 0;
3047 int *wn = NULL;
3048
3049 cmp[0] = search[0] = file[0] = '\0';
3050 wtxt = MALLOC(1);
3051 wn = MALLOC(1);
3052 for (j = 0, n = 0; n < 4 && srch[j]; n++)
3053 {
3054 for (l = 0; (tmp[n][l] = srch[j]); j++, l++)
3055 {
3056 if (j > 1 && srch[j] == '?' && srch[j-1] == '{' && srch[j-2] == '$')
3057 {
3058 wnum++;
3059 wn = REALLOC(wn, wnum * sizeof(int));
3060 wtxt = REALLOC(wtxt, wnum * sizeof(char *));
3061 if (srch[j+1] == '*')
3062 wn[wnum-1] = -1;
3063 else
3064 wn[wnum-1] = atoi(srch+j+1);
3065 for (j++; srch[j] && srch[j] != ':'; j++);
3066 if (!srch[j])
3067 {
3068 wnum--;
3069 break;
3070 }
3071 for (m = 0; srch[j+m] && srch[j+m] != '}'; m++);
3072 wtxt[wnum-1] = MALLOC((m+1) * sizeof(char));
3073 for (m = 0, j++; (wtxt[wnum-1][m] = srch[j]) && srch[j] != '}'; j++, m++);
3074 wtxt[wnum-1][m] = '\0';
3075 l -= 3;
3076 }
3077 else if (srch[j] == '\r' || srch[j] == '\n')
3078 {
3079 if (srch[j+1] == '\r' || srch[j+1] == '\n')
3080 {
3081 tmp[n][l] = '\n';
3082 tmp[n][l+1] = '\0';
3083 j++;
3084 }
3085 else
3086 tmp[n][l] = '\0';
3087 j++;
3088 break;
3089 }
3090 }
3091 }
3092 e_p_comp_mess(tmp[0], b->bf[i].s, b->bf[i].s, search, file, cmp, &y, &x);
3093 iy = i;
3094 iorig = i;
3095 do
3096 {
3097 if (n > 1 && file[0] && i < b->mxlines-1)
3098 {
3099 y = -1;
3100 while (b->bf[i].s[b->bf[i].len-1] == '\\')
3101 i++;
3102 i++;
3103 e_p_comp_mess(tmp[1], b->bf[i].s, b->bf[i].s, search, file, cmp, &y, &x);
3104 iy = i;
3105 }
3106 do
3107 {
3108 if (n > 2 && file[0] && y >= 0 && i < b->mxlines-1)
3109 {
3110 while (b->bf[i].s[b->bf[i].len-1] == '\\')
3111 i++;
3112 i++;
3113 l = e_p_comp_mess(tmp[2], b->bf[i].s, b->bf[i].s, search, file, cmp, &y, &x);
3114 if (!l && n > 3)
3115 l = e_p_comp_mess(tmp[3], b->bf[i].s, b->bf[i].s, search, file, cmp, &y, &x);
3116 }
3117 else
3118 l = 1;
3119 if (file[0] && y >= 0 && l != 0)
3120 {
3121 err_li[k].file = MALLOC((strlen(file)+1)*sizeof(char));
3122 strcpy(err_li[k].file, file);
3123 err_li[k].line = y;
3124 if (search[0] == 'P')
3125 {
3126 cp = strstr(b->bf[iy].s, cmp);
3127 if (!cp)
3128 x = 0;
3129 else
3130 {
3131 for (m = 0; b->bf[iy].s + m < (unsigned char *)cp; m++);
3132 x -= m;
3133 }
3134 err_li[k].srch = MALLOC((strlen(cmp)+2)*sizeof(char));
3135 err_li[k].srch[0] = 'P';
3136 strcpy(err_li[k].srch+1, cmp);
3137 }
3138 else if (search[0])
3139 {
3140 err_li[k].srch = MALLOC((strlen(search)+1)*sizeof(char));
3141 strcpy(err_li[k].srch, search);
3142 }
3143 else
3144 err_li[k].srch = NULL;
3145 err_li[k].x = x;
3146 err_li[k].y = iorig;
3147 err_li[k].text = MALLOC(strlen((char *)b->bf[i].s) + 1);
3148 strcpy(err_li[k].text, (char *)b->bf[i].s);
3149 err_li[k].text[b->bf[i].len] = '\0';
3150 k++;
3151 err_num++;
3152 if (!ret)
3153 {
3154 for (ret = -1, m = 0; ret && m < wnum; m++)
3155 {
3156 if (wn[m] == -1 && !(b->cn->edopt & ED_MESSAGES_STOP_AT) &&
3157 strstr(b->bf[i].s, wtxt[m]))
3158 ret = 0;
3159 else if (wn[m] > -1 && !(b->cn->edopt & ED_MESSAGES_STOP_AT) &&
3160 !strncmp(b->bf[i].s+wn[m], wtxt[m], strlen(wtxt[m])))
3161 ret = 0;
3162 }
3163 }
3164 if (!ret && wnum <= 0)
3165 ret = -1;
3166 while (b->bf[i].s[b->bf[i].len-1] == '\\')
3167 i++;
3168 }
3169 } while (n > 2 && file[0] && y >= 0 && l != 0 && i < b->mxlines-1);
3170 if (n > 2 && file[0] && y >= 0 && l == 0)
3171 i--;
3172 } while (n > 1 && file[0] && y >= 0 && i < b->mxlines-1);
3173 if (n > 1 && file[0] && y < 0)
3174 i--;
3175 *ii = i;
3176 *kk = k;
3177 for (m = 0; m < wnum; m++)
3178 FREE(wtxt[m]);
3179 FREE(wn);
3180 FREE(wtxt);
3181 return(ret);
3182 }
3183
3184 #endif
3185
3186