2 Copyright © 2009-2011, The AROS Development Team. All rights reserved.
5 Desc: autoinit library - open IO window when started from WB
8 #include <aros/startup.h>
10 #include <proto/dos.h>
13 #include <aros/debug.h>
15 /* programmers can define the __stdiowin for opening the win that will be used for
16 IO to the standard file descriptors.
17 If none is provided a default value will be used
19 extern char const __stdiowin
[];
21 int __nostdiowin
__attribute__((weak
)) = 0;
23 static BPTR __iowinr
= BNULL
, __iowinw
= BNULL
, __iowine
= BNULL
;
24 static BPTR __old_in
, __old_out
, __old_err
;
26 static BPTR
DupFH(BPTR fh
, LONG mode
, struct DosLibrary
* DOSBase
)
33 old
= SetConsoleTask(((struct FileHandle
*)BADDR(fh
))->fh_Type
);
34 nfh
= Open("*", mode
);
39 static void __startup_stdiowin(struct ExecBase
*SysBase
)
43 D(bug("[__startup_stdiowin] Entering\n"));
47 __startup_entries_next();
51 D(bug("[__startup_stdiowin] Opening console window: '%s'\n", __stdiowin
));
53 __iowinw
= Open(__stdiowin
, MODE_OLDFILE
);
54 __iowinr
= DupFH(__iowinw
, MODE_OLDFILE
, DOSBase
);
56 /* this is so ugly but ReadArgs() needs EOF or
57 * console window will always open and program
58 * pauses until RETURN is pressed.
60 struct FileHandle
*fh
= BADDR(__iowinr
);
61 SetVBuf(__iowinr
, NULL
, BUF_LINE
, 1);
63 fh
->fh_Pos
= fh
->fh_End
+ 1;
65 __iowine
= DupFH(__iowinw
, MODE_OLDFILE
, DOSBase
);
67 if (!__iowinr
|| !__iowinw
|| !__iowine
)
72 D(bug("[__startup_stdiowin] Failed!\n"));
76 D(bug("[__startup_stdiowin] Setting standard file handles\n"));
77 D(bug("[__startup_stdiowin] in %p out %p err %p\n", __iowinr
, __iowinw
, __iowine
));
79 __old_in
= SelectInput(__iowinr
);
80 __old_out
= SelectOutput(__iowinw
);
81 me
= (struct Process
*)FindTask(NULL
);
82 __old_err
= me
->pr_CES
;
83 me
->pr_CES
= __iowine
;
85 D(bug("[__startup_stdiowin] old in %p out %p err %p\n", __old_in
, __old_out
, __old_err
));
87 __startup_entries_next();
89 D(bug("[__startup_stdiowin] Program executed\n"));
91 SelectInput(__old_in
);
92 SelectOutput(__old_out
);
93 me
->pr_CES
= __old_err
;
99 D(bug("[__startup_stdiowin] Done!\n"));
102 ADD2SET(__startup_stdiowin
, PROGRAM_ENTRIES
, -20);