home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / _wb_parse.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  4KB  |  146 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  _wb_parse.c,v 1.1.1.1 1994/04/04 04:30:42 amiga Exp
  20.  *
  21.  *  _wb_parse.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:42  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.2  1992/08/09  20:42:46  amiga
  26.  *  get rid of some warnings
  27.  *
  28.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  29.  *  Initial revision
  30.  *
  31.  */
  32.  
  33. /*
  34.  * Originally written by Olaf "Olsen" Barthel. Thanks Olsen!
  35.  * I left his indentation style...
  36.  */
  37.  
  38. #define _KERNEL
  39. #include "ixemul.h"
  40.  
  41. #include <workbench/workbench.h>
  42. #include <workbench/startup.h>
  43.  
  44. #include <proto/icon.h>
  45.  
  46. #include <string.h>
  47.  
  48. /* wb_parse():
  49.  *
  50.  *    A more or less decent rewrite of Manx' original
  51.  *    wb_parse() routine which will do the following:
  52.  *
  53.  *    - if open_wb_window is zero no console window
  54.  *      will be opened.
  55.  *
  56.  *    - if default_wb_window points to a valid string
  57.  *      it will be used to open the window.
  58.  *
  59.  *    - if everything fails, read the icon file,
  60.  *      scan it for a "WINDOW" tool type and take
  61.  *      the corresponding tool type entry string
  62.  *      (somewhat primitive if compared to the Macintosh
  63.  *      way of doing it...).
  64.  *
  65.  *    This routine will return TRUE if it was able to
  66.  *    open an output file, FALSE otherwise.
  67.  */
  68.  
  69. int
  70. _wb_parse(struct Process *ThisProcess, struct WBStartup *WBenchMsg,
  71.       char *default_wb_window)
  72. {
  73.   struct Library *IconBase;
  74.   char    *WindowName = NULL;
  75.   int    fd = -1;
  76.  
  77.   /* Are we to open a console window? */
  78.  
  79.   if (default_wb_window != (char *)-1)
  80.     {
  81.       /* Any special name preference? */
  82.  
  83.       if (default_wb_window)
  84.     WindowName = default_wb_window;
  85.       else
  86.     {
  87.       /* Do we have a valid tool window? */
  88.  
  89.       if (WBenchMsg->sm_ToolWindow)
  90.         WindowName = WBenchMsg->sm_ToolWindow;
  91.       else
  92.         {
  93.           /* Open icon.library. */
  94.  
  95.           if ((IconBase = OpenLibrary("icon.library", 0)))
  96.         {
  97.           struct DiskObject *Icon;
  98.  
  99.           /* Try to load the icon file. */
  100.  
  101.           if ((Icon = GetDiskObject(WBenchMsg->sm_ArgList[0].wa_Name)))
  102.             {
  103.               /* Look for a "WINDOW" tool type. */
  104.  
  105.               WindowName = (u_char *) FindToolType((u_char **)Icon->do_ToolTypes, "WINDOW");
  106.               if (WindowName)
  107.             WindowName = strdup (WindowName);
  108.               FreeDiskObject(Icon);
  109.             }
  110.           CloseLibrary(IconBase);
  111.         }
  112.         }
  113.     }
  114.  
  115.     /* Are we to open a file? */
  116.  
  117.     if (WindowName)
  118.       fd = syscall (SYS_open, WindowName, 2);
  119.     if (fd != -1)
  120.       {
  121.         /* this fd "should" be 0, since we didn't open any files
  122.          * till now when running under workbench */
  123.         if (fd != 0)
  124.           ix_warning("_wb_parse: first opened fd != 0!");
  125.  
  126.         ThisProcess->pr_ConsoleTask = u.u_ofile[fd]->f_fh->fh_Type;
  127.         syscall (SYS_dup2, fd, 2); 
  128.         /* now dup() the descriptor to cover an additional descriptor, 
  129.          * so that by closing 0-2 pr_ConsoleTask doesn't vanish yet */
  130.         syscall (SYS_dup2, fd, NOFILE - 1);
  131.         syscall (SYS_close, fd);
  132.  
  133.             /* Apparently use of CONSOLE: gave problems with
  134.                Emacs, so we continue to use "*" instead. */
  135.         fd = syscall (SYS_open, "*", 0);
  136.         if (fd != -1)
  137.           ThisProcess->pr_CIS = CTOBPTR (u.u_ofile[fd]->f_fh);
  138.  
  139.         fd = syscall (SYS_open, "*", 1);
  140.         ThisProcess->pr_COS = CTOBPTR (u.u_ofile[fd]->f_fh);
  141.         return 1;
  142.       }
  143.     }
  144.   return FALSE;
  145. }
  146.