Index: s_main.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_main.c,v retrieving revision 1.2 diff -u -r1.2 s_main.c --- s_main.c 23 Sep 2003 00:18:14 -0000 1.2 +++ s_main.c 25 Jan 2004 09:00:03 -0000 @@ -79,6 +79,9 @@ int sys_choutlist[MAXAUDIOOUTDEV]; /* } IOhannes */ +/* Matju { */ +int console_scrollback = 0; +/* } */ typedef struct _fontinfo { @@ -748,7 +751,15 @@ goto usage; argc -= 2; argv += 2; } - else + /* Matju { */ + else if (!strcmp(*argv,"-console")) + { + console_scrollback = atoi(argv[1]); + fprintf(stderr,"pd_console_scrollback: %s\n",argv[1]); + argc-=2; argv+=2; + } + /* } */ + else { unsigned int i; usage: @@ -757,6 +768,13 @@ return (1); } } + /* Matju { */ + { + char buf[64]; + sprintf(buf,"%d",console_scrollback); + setenv("pd_console_scrollback",buf,1); + } + /* } */ if (!sys_defaultfont) sys_defaultfont = DEFAULTFONT; for (; argc > 0; argc--, argv++) Index: s_print.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_print.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 s_print.c --- s_print.c 29 Jul 2002 17:06:00 -0000 1.1.1.1 +++ s_print.c 25 Jan 2004 09:00:03 -0000 @@ -9,15 +9,25 @@ #include #include +extern int console_scrollback; +static const int console_ln=1024; +static int console_li=0; +static char console_line[1024]=""; + void post(char *fmt, ...) { va_list ap; t_int arg[8]; - int i; va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + if (console_scrollback) { + vsnprintf(console_line, console_ln, fmt, ap); + console_line[console_ln-1]=0; + } else { + vfprintf(stderr, fmt, ap); + } va_end(ap); - putc('\n', stderr); + endpost(); + } void startpost(char *fmt, ...) @@ -29,13 +39,24 @@ for (i = 0 ; i < 8; i++) arg[i] = va_arg(ap, t_int); va_end(ap); - fprintf(stderr, fmt, arg[0], arg[1], arg[2], arg[3], - arg[4], arg[5], arg[6], arg[7]); + if (console_scrollback) { + console_li = snprintf(console_line, console_ln, fmt, arg[0], arg[1], arg[2], arg[3], + arg[4], arg[5], arg[6], arg[7]); + } else { + fprintf(stderr, fmt, arg[0], arg[1], arg[2], arg[3], + arg[4], arg[5], arg[6], arg[7]); + } } void poststring(char *s) { - fprintf(stderr, " %s", s); + if (console_scrollback) { + if (console_li=0; i--) if (console_line[i]=='}') countbrace++; + while (n+countbrace>=(int)sizeof(console_line)) n--; + for (i=n-1; i>=0; i--) { + console_line[i+countbrace]=console_line[i]; + if (console_line[i]=='}') console_line[i+(--countbrace)]='\\'; + } + sys_vgui("post_to_gui {%s\n}\n",console_line); + console_li=0; + console_line[0]=0; + } else { + fprintf(stderr, "\n"); + } } void error(char *fmt, ...) @@ -68,10 +102,10 @@ t_int arg[8]; int i; va_start(ap, fmt); - fprintf(stderr, "error: "); - vfprintf(stderr, fmt, ap); + startpost("error: "); + vsnprintf(console_line+console_li, console_ln-console_li, fmt, ap); va_end(ap); - putc('\n', stderr); + endpost(); } /* here's the good way to log errors -- keep a pointer to the Index: t_tkcmd.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/t_tkcmd.c,v retrieving revision 1.1.1.4 diff -u -r1.1.1.4 t_tkcmd.c --- t_tkcmd.c 9 May 2003 16:03:44 -0000 1.1.1.4 +++ t_tkcmd.c 25 Jan 2004 09:00:03 -0000 @@ -319,15 +319,17 @@ char buf[GUISTRING]; sprintf(buf, "set pd_guidir \"%s\"\n", pdgui_path); tcl_mess(buf); - strcpy(buf, pdgui_path); - strcat(buf, "/bin/"); - strcat(buf, s); - if (Tcl_EvalFile(interp, buf) != TCL_OK) + sprintf(buf, "set script {%s/bin/%s}\n" + "if {[catch {source $script} err]} " + "{puts stderr \"tcl: ERROR loading $script: $err\"}",pdgui_path,s); + /* is there a way to do a Tcl [catch] from C ? */ + if (Tcl_Eval(interp, buf) != TCL_OK) { char buf2[1000]; sprintf(buf2, "puts [concat tcl: %s: can't open script]\n", buf); tcl_mess(buf2); + tcl_mess("puts stderr {tcl: should not get here}"); } } Index: u_main.tk =================================================================== RCS file: /cvsroot/pure-data/pd/src/u_main.tk,v retrieving revision 1.2 diff -u -r1.2 u_main.tk --- u_main.tk 23 Sep 2003 00:18:14 -0000 1.2 +++ u_main.tk 25 Jan 2004 09:00:03 -0000 @@ -3288,3 +3288,34 @@ global $var set $var $value } + +# Matju { +#puts "pd_console_scrollback = $env(pd_console_scrollback)" +set errMsg "" +catch { +if {$env(pd_console_scrollback) != 0} { + frame .log + text .log.1 -width 80 -height 10 -yscrollcommand ".log.2 set" + scrollbar .log.2 -command ".log.1 yview" + .log.1 insert end "This is the PureData log\n" + pack .log.1 -side left -fill both -expand yes + pack .log.2 -side left -fill y -expand yes + pack .log -fill both -expand yes +}} errMsg +if {[string compare "" $errMsg] != 0} { + puts stderr "ERROR: $errMsg" +} + +set console_scrollback_count 0 +proc post_to_gui {x} { + global env + global console_scrollback_count + .log.1 insert end $x + incr console_scrollback_count + if {$console_scrollback_count >= $env(pd_console_scrollback)} { + .log.1 delete 1.0 2.0 + } +} + +## } +