[comp.sources.amiga] v91i045: ToolManager 1.3 - add to the Tools menu of Workbench 2.0, Part01/02

amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator) (03/14/91)

Submitted-by: stefanb@cip-s01.informatik.rwth-aachen.de (Stefan Becker)
Posting-number: Volume 91, Issue 045
Archive-name: utilities/toolmanager-13/part01

[ includes uuencoded executable and icon  ...tad ]

With ToolManager you can add your own programs to the Tools menu of the 2.0
Workbench. The programs can now be started by selecting their entries in the
Tools menu. The user can select icons from the Workbench, which will be the
startup parameters for a tool.

BEWARE: This program makes heavely use of the new 2.0 functions, so its
        completely useless to all people who are still forced to use 1.3 :-)

New features since 1.2:
   - Now supports different configuration files
   - Format of the configuration file slightly changed
   - Tool definitions can be changed at runtime
   - Now supports CLI & Workbench startup method
   - Selected icons are passed as parameters to the tools
   - Now uses the startup icon as program icon if started from Workbench
   - The position of the icon can now be supplied in the configuration file
   - The program icon can now be disabled
   - New menu entry "Show TM Window"
   - Every new started ToolManager passes its startup parameters to the
     already running ToolManager process

#!/bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 2)."
# Contents:  ToolManage0.uu ToolManager.ReadMe ToolManager.config
#   ToolManager.doc src src/DMakefile src/README src/ToolManager.h
#   src/config.c src/data.c src/mainloop.c src/starttools.c
#   src/toollist.c src/toolmanager.c src/window.c
# Wrapped by tadguy@ab20 on Wed Mar 13 18:50:08 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'ToolManage0.uu' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ToolManage0.uu'\"
else
echo shar: Extracting \"'ToolManage0.uu'\" \(700 characters\)
sed "s/^X//" >'ToolManage0.uu' <<'END_OF_FILE'
Xbegin 666 ToolManager.info
XMXQ```0``````=``0`#8`%P`%``$``0?,L80`````````````````````````4
XM```!`P``````!\`C^(````"``````````````````!`````````V`!8``@`$(
XM@N@#```````````````$``````````P````.````#``#P`X'/\`,``^$#@?_A
XM^`P`#XX$!__^#``'_`0'/_\,``'P!``/@8P``?`?``^`#``!\!\`#X`,``'PE
XM'P`/@`P``?`?``^`#``!\!\`#X`,``'P'P`/@`P``?`?``^`#``!\!\`#X`,1
XM``'P'P`/@`P``.`?``^`#```0`X`#X`,``````````P`````````#`!_____"
XM___\`/________@`U55555554`#555%55550`-0545!`%5``T%%14``%4`#0:
XM45%0``%0`-`!45!``%``U`5155!44`#4!4!54%50`-0%0%5055``U`5`55!51
XM4`#4!4!54%50`-0%0%5055``U`5`55!54`#4!4!54%50`-0%0%5055``U`5`8
XM55!54`#5%4!54%50`-45455055``U55555554`#555555550`(``````````?
X2````"`````I$3TY/5%=!250`+
X``
Xend
Xsize 468
END_OF_FILE
if test 700 -ne `wc -c <'ToolManage0.uu'`; then
    echo shar: \"'ToolManage0.uu'\" unpacked with wrong size!
fi
# end of 'ToolManage0.uu'
fi
if test -f 'ToolManager.ReadMe' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ToolManager.ReadMe'\"
else
echo shar: Extracting \"'ToolManager.ReadMe'\" \(1115 characters\)
sed "s/^X//" >'ToolManager.ReadMe' <<'END_OF_FILE'
XReadMe for ToolManager 1.3                                          13.03.1991
X
XWith ToolManager you can add your own programs to the Tools menu of the 2.0
XWorkbench. The programs can now be started by selecting their entries in the
XTools menu. The user can select icons from the Workbench, which will be the
Xstartup parameters for a tool.
X
XBEWARE: This program makes heavely use of the new 2.0 functions, so its
X        completely useless to all people who are still forced to use 1.3 :-)
X
XNew features since 1.2:
X   - Now supports different configuration files
X   - Format of the configuration file slightly changed
X   - Tool definitions can be changed at runtime
X   - Now supports CLI & Workbench startup method
X   - Selected icons are passed as parameters to the tools
X   - Now uses the startup icon as program icon if started from Workbench
X   - The position of the icon can now be supplied in the configuration file
X   - The program icon can now be disabled
X   - New menu entry "Show TM Window"
X   - Every new started ToolManager passes its startup parameters to the
X     already running ToolManager process
X
END_OF_FILE
if test 1115 -ne `wc -c <'ToolManager.ReadMe'`; then
    echo shar: \"'ToolManager.ReadMe'\" unpacked with wrong size!
fi
# end of 'ToolManager.ReadMe'
fi
if test -f 'ToolManager.config' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ToolManager.config'\"
else
echo shar: Extracting \"'ToolManager.config'\" \(321 characters\)
sed "s/^X//" >'ToolManager.config' <<'END_OF_FILE'
XICON:200,10
XWB:Show Text;C:More
XWB:Show IFF;C:Zhow
XWB:Edit Text (WB);C:DME
XCLI:Edit Text (CLI);C:DME
XCLI:--> This is a dummy entry <--;
XWB:Edit Binary;C:Zap
XWB:Edit Icons;Sys:Tools/IconEdit
XCLI:Blanker On;C:DMouse -s30
XCLI:Blanker Off;C:DMouse -s0
XWB:Disk Copy;C:TurboBackup
XWB:Browser;C:Browser
XCLI:New Shell;C:NewShell
END_OF_FILE
if test 321 -ne `wc -c <'ToolManager.config'`; then
    echo shar: \"'ToolManager.config'\" unpacked with wrong size!
fi
# end of 'ToolManager.config'
fi
if test -f 'ToolManager.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ToolManager.doc'\"
else
echo shar: Extracting \"'ToolManager.doc'\" \(11502 characters\)
sed "s/^X//" >'ToolManager.doc' <<'END_OF_FILE'
XDocumentation for ToolManager 1.3                                   13.03.1991
X
XNOTE to first time users: Please read the entire document!
X
XNOTE to users of ToolManager 1.0-1.2: This version contains MANY changes and
X                                      enhancements, so please re-read the
X                                      entire document!
X
XThis program is freeware, but copyrighted by me. This means that you can copy
Xit freely as long as you don't ask any more money for it than a nominal fee for
Xcopying. THIS APPLIES TO GERMAN PD DEALERS TOO!!! This program may be put on PD
Xdisks, especially on Fred Fish's AmigaLibDisks. If you want to distribute this
Xprogram you should keep this document and the source code with it. Program,
Xdocument and source code must be distributed in their original unmodified form.
XOf course you can use an archiver like LHarc to make it available to Mailboxes
Xand FTP sites. This program cannot be used for commercial purposes without
Xwritten permission from the author. The author can not be made responsible for
Xany damage which is caused by using this program.
X
XThis is program is freeware, so you don't have to spend a buck for it. But
Xthis program has costed me a lot of time (and sweat) to create it (especially
Xthe version 1.3), so the only thing that I demand for it is, that you sent me
Xa note if you are using ToolManager.
X
XSend comments, suggestions or bug reports to:
X
X   Snail : Stefan Becker, Holsteinstrasse 9, 5100 Aachen, GERMANY
X   Domain: stefanb@cip-s01.informatik.rwth-aachen.de
X   Bang  : ..mcvax!unido!rwthinf!cip-s01!stefanb
X   FIDO  : 2:242/7.6
X
X
X I. What is ToolManager?
X
XWith ToolManager you can add your own programs to the Tools menu of the 2.0
XWorkbench. The programs can now be started by selecting their entries in the
XTools menu. The user can select icons from the Workbench, which will be the
Xstartup parameters for a tool.
X
XBEWARE: This program makes heavely use of the new 2.0 functions, so its
X        completely useless to all people who are still forced to use 1.3 :-)
X
X
X II. How to start ToolManager
X
XToolManager can be started from the CLI or the Workbench:
X
X   CLI:   Run ToolManager [options] [<program 1>] ... [<program n>]
X
X    Options: '-n'        Don't show the icon
X             '-f <name>' Read "name" as configuration file instead of
X                         "S:ToolManager.config"
X
X    The name of program x will also be the name of its corresponding menu item.
X    All programs will be added as CLI tools.
X
X    NOTE: If you want to start ToolManager at boot time, you can add the
X          following line to your S:Startup-Sequence:
X
X               Run >NIL: ToolManager [parameters...]
X
X    NOTE: For a quick reminder of this options type: ToolManager ?
X
X   Workbench:   <Click on ToolManager's icon>
X                [<Click on program 1's icon>] ...
X                [<Double click program n's icon>]
X
X    ToolTypes: 'SHOWICON=NO|YES' Don't show the icon
X               'INTERNALICON'    Use the internal icon instead of the startup
X                                 icon
X               'CONFIG=<name>'   Read "name" as configuration file instead of
X                                 "S:ToolManager.config"
X
X    If you selected a Tool icon, its name will also be the name of the menu
X    item. If you selected a Project icon, the icon name will be the name of the
X    menu entry. The default tool of this icon will be called if the menu item
X    is selected. All programs will be started as WB tools.
X
X    NOTE: If you want to start ToolManager at Workbench startup time, move its
X          icon into the Wbstartup drawer and add the ToolType 'DONOTWAIT' to
X          it. ToolManager uses the icon from which it was started as its icon,
X          if you don't set the 'INTERNALICON' ToolType.
X
XAfter startup you will notice additional entries in the Workbench Tools menu
Xand a neat icon on the Workbench (if you don't disable it). To stop ToolManager
Xyou can select the menu entry "Quit ToolManager" or send a break signal to his
Xprocess.
X
XNOTE: You can't exit ToolManager if a Workbench tool is still running.
X      ToolManager will flash the screen if you try it.
X
X
X III. The configuration file
X
XAfter processing the startup parameters, ToolManager reads the configuration
Xfile. It is normally called "S:ToolManager.config", but this can be overriden
Xby the CLI Parameter '-f' or the WB Parameter 'CONFIG'. The file consists of
Xlines which look like this:
X
X   <Keyword>:<Parameters>
X
X   ICON:<x>,<y>
X    Set the position of the program icon to (x,y)
X
X   CLI:<Menu entry name>[;<Real program name>]
X    Add a CLI tool. If only one name is given, it will be the name of the menu
X    entry and also of the program to be called for this entry. If two names are
X    given, the first will be the name of the menu entry and the second one will
X    be the name of the program to be called. You can add any command line
X    parameters after the program name.
X
X    NOTE: If the program name contains spaces (e.g. ram disk:prog) you MUST
X          enclose it with double quotes (e.g. "ram disk:prog")
X
X   WB:<Menu entry name>[;<Real program name>]
X    Add a WB tool. For the names apply the same rules as stated above.
X
X    NOTE: You MUST supply an absolute path name for WB tools, otherwise
X          ToolManager can't find the executable.
X
X    NOTE: It is not possible to supply command line parameters for a WB tool.
X
XTo create a dummy entry without function for "aesthetic" reasons, use the
Xfollowing configuration line. Note that the trailing semicolon is mandatory.
X
X   CLI:<Dummy menu entry name>;
X
XEXAMPLES:
X
X   ICON:200,10
X   CLI:Editor
X   CLI:Edit Text;Ed
X   CLI:Blanker off;DMouse -s0
X   WB:C:DME                      (not really useful)
X   WB:Edit Text;C:DME
X
XFor more examples please look into the supplied configuration file.
X
X
X IV. How to use ToolManager
X
XWhen ToolManager is active, you can see additional entries in the Workbench
XTools menu. To start a tool you select its entry. Easy, isn't it? You can also
Xselect some icons on the Workbench to supply the tool with parameters.
XToolManager supports two different startup methods for tools:
X
X   CLI startup
X    The tool is started as a CLI process. The selected icons will be converted
X    to file names, which are then joined with the tool name to a CLI command
X    line. The system default stack size will be used to run the tool.
X
X    NOTE: There is a limitation of 256 characters for the resulting command
X          line.
X
X   Workbench startup
X    The tool is started as a Workbench process. If an icon exists for the tool,
X    ToolManager will read the ToolWindow definition and the stack size from it.
X    If no icon can be found, the ToolWindow will be empty and a default stack
X    size of 4096 Bytes is used. The selected icons will be directly passed to
X    the tool.
X
XThere are two special menu entries. The first one is "Quit ToolManager", which
Xcauses ToolManager to quit if you select it. The second one is "Open TM Window",
Xwhich causes ToolManager to open its status window. You can also open this
Xwindow by double-clicking the program icon.
X
XTo add a new tool, you just drag a Tool (or Project) icon on ToolManager's icon
Xor on the status window and it will be added as a WB tool. If you start
XToolManager a second time, it will pass its startup parameters to the already
Xrunning ToolManager process. They will be added as WB tools if an icon exists
Xfor them, otherwise as CLI tools.
X
XThe status window contains a list of all menu entries and allows you to
Xmanipulate them. You can select a tool by clicking on its name in the list.
X
X   Remove Tool
X    Remove the selected icon.
X
X   Edit Tool Definition
X    A new window will open, which shows the actual definition of the selected
X    tool. It is displayed in the same format which is used in the configuration
X    file. You can now change the definition. If you press the return key, the
X    changes will be taken over by ToolManager. To cancel your action, click on
X    the close gadget of the window.
X
X    NOTE: The changed menu entry will be added to the END of the list. This
X          is because 2.0 provides no choice where to put the menu entry.
X
X   Save Configuration
X    A file requester will open, in which you can select the name of the
X    configuration save file. If you click on the OK gadget, ToolManager will
X    write its actual configuration on this file. Workbench tools will be
X    converted to absolute path names, so they can be found the next time you
X    read in the configuration file,
X
XYou can close the status window by clicking its close gadget. It will remember
Xits current screen position for the next time you open it.
X
X
X V. Caveats
X
XIf you start a program as Workbench tool and it immediately crashes with a
XGURU #87000004, then the startup code of this program contains a bug. This
Xhappened to me as I tried to start programs which were compiled with DICE. I
Xhave informed Matt Dillon and he told me that it will be fixed in the next
Xrelease.
X
XThe configuration files of version 1.0-1.2 will NOT be recognized by the new
Xversion 1.3. Please re-read the corresponding chapter for the changes.
X
XNow to some weird things, that are NOT bugs or 'undocumented features' of my
Xmy program:
X
X - The Workbench seems not to support multiple menu selects.
X
X - The Workbench looses menu select events if a disk is inserted. So if you
X   insert a disk and select a tool at the same time, the tool will NOT be
X   started, because ToolManager didn't receive a menu event.
X
X
X VI. How to compile ToolManager
X
XThis program was developed with DICE (nice job Matt!). You will need the
Xregistered version, because I used the __chip keyword, but DICE is worth its
X$50 anyway. Of course you need the 2.0 include files and the 2.0 amiga.lib.
X
X
X VII. TODO
X
X - Better looking internal icon (hey, I'm not a painter :-)
X - "About" menu entry with a super MEGA demo, containing astonishing 2D & 3D
X   graphics and 16 Bit digitized stereo sound (Hi Juergen :-)
X
X
X VIII. HISTORY
X
X1.3: Release version (13.03.1991)
X   - Now supports different configuration files
X   - Format of the configuration file slightly changed
X   - Tool definitions can be changed at runtime
X   - Now supports CLI & Workbench startup method
X   - Selected icons are passed as parameters to the tools
X   - Now uses the startup icon as program icon if started from Workbench
X   - The position of the icon can now be supplied in the configuration file
X   - The program icon can now be disabled
X   - New menu entry "Show TM Window"
X   - Every new started ToolManager passes its startup parameters to the
X     already running ToolManager process
X
X1.2: Release version (12.01.1991)
X     (First version to appear on a Fish disk: #442)
X   - Status window changed to a no-GZZ & simple refresh type
X     (this should save some bytes)
X   - Status window remembers its last position
X   - New status window gadget "Save Configuration": saves the actual tool
X     list in the configuration file
X   - Small bugs removed in the ListView gadget handling
X   - Name of the icon hard-wired to "ToolManager"
X
X1.1 Release version (01.01.1991)
X   - Icons can be dropped on the status window
X   - Status window contains a list of all tool names
X   - Tools can be removed from the list
X
X1.0 Release version (04.11.1990)
X   - Initial release
X
X
X IX. THANKS TO
X
X   Martin Horneffer, Juergen Lueg, Georg Sassen, Brian Wright
X
Xand anyone I forgot to mention for their suggestions, beta testing, support,
Xflames.....
X
X         Stefan Becker
X
END_OF_FILE
if test 11502 -ne `wc -c <'ToolManager.doc'`; then
    echo shar: \"'ToolManager.doc'\" unpacked with wrong size!
fi
# end of 'ToolManager.doc'
fi
if test ! -d 'src' ; then
    echo shar: Creating directory \"'src'\"
    mkdir 'src'
fi
if test -f 'src/DMakefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/DMakefile'\"
else
echo shar: Extracting \"'src/DMakefile'\" \(307 characters\)
sed "s/^X//" >'src/DMakefile' <<'END_OF_FILE'
XCFLAGS=-proto
XLFLAGS=
XSRCS=toolmanager.c mainloop.c starttools.c window.c config.c toollist.c data.c
XOBJS=$(SRCS:"*.c":"*.o")
X
XToolManager : $(OBJS)
X         dcc $(LFLAGS) -o %(left) %(right)
X
X$(OBJS) : $(SRCS)
X         dcc $(CFLAGS) -o %(left) -c %(right)
X
X$(SRCS) : ToolManager.h
X         SetDate %(left)
END_OF_FILE
if test 307 -ne `wc -c <'src/DMakefile'`; then
    echo shar: \"'src/DMakefile'\" unpacked with wrong size!
fi
# end of 'src/DMakefile'
fi
if test -f 'src/README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/README'\"
else
echo shar: Extracting \"'src/README'\" \(166 characters\)
sed "s/^X//" >'src/README' <<'END_OF_FILE'
XThe source code for ToolManager is freeware, but copyrighted by me. You can use
Xit in your programs but you MUST NOT remove the copyright note from.
X
X         Stefan
END_OF_FILE
if test 166 -ne `wc -c <'src/README'`; then
    echo shar: \"'src/README'\" unpacked with wrong size!
fi
# end of 'src/README'
fi
if test -f 'src/ToolManager.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/ToolManager.h'\"
else
echo shar: Extracting \"'src/ToolManager.h'\" \(2522 characters\)
sed "s/^X//" >'src/ToolManager.h' <<'END_OF_FILE'
X/*
X * ToolManager.h   V1.3
X *
X * main include file
X *
X * (c) 1991 by Stefan Becker
X *
X */
X#include <exec/types.h>
X#include <stdlib.h>
X#include <stdio.h>
X#include <string.h>
X#include <exec/libraries.h>
X#include <exec/memory.h>
X#include <dos/dos.h>
X#include <dos/dostags.h>
X#include <intuition/intuition.h>
X#include <workbench/icon.h>
X#include <workbench/startup.h>
X#include <workbench/workbench.h>
X#include <libraries/asl.h>
X
X/* Prototypes for system functions */
X#include <clib/asl_protos.h>
X#include <clib/dos_protos.h>
X#include <clib/exec_protos.h>
X#include <clib/gadtools_protos.h>
X#include <clib/graphics_protos.h>
X#include <clib/icon_protos.h>
X#include <clib/intuition_protos.h>
X#include <clib/wb_protos.h>
X
X/* Version number & dates */
X#define TM_VERSION "1.3"
X#define TM_CRYEAR "1991"
X#define TM_DATE "13.03.1991"
X
X/* Entry for tool list */
Xstruct ToolNode {
X                 struct Node tn_Node;
X                 BPTR tn_DirLock;
X                 char *tn_RealName;
X                 struct AppMenuItem *tn_MenuItem;
X                 ULONG tn_ID;
X                 BOOL tn_CLI;
X                };
X
X/* Prototypes for library functions */
Xvoid NewList(struct List *);
Xstruct ToolNode *GetHead(struct List *);
Xstruct ToolNode *GetSucc(struct ToolNode *);
X
X/* Prototypes for program functions */
X/* config.c */
Xvoid SetConfigFileName(char *);
XBOOL ScanConfigLine(char *, BPTR);
Xvoid BuildConfigLine(struct ToolNode *, char *);
Xvoid ReadConfigFile(BPTR);
XBOOL WriteConfigFile(struct Window *w);
X/* mainloop.c */
Xvoid mainloop(void);
X/* starttools.c */
XBOOL StartCLITool(struct AppMessage *, struct ToolNode *,char *);
XBOOL StartWBTool(struct AppMessage *, struct ToolNode *, char *);
X/* toollist.c */
XBOOL WBAddToolNode(struct WBArg *, int);
XBOOL AddToolNode(BPTR, char *, char *, BOOL);
Xvoid RemToolNode(struct ToolNode *tn);
Xvoid RemoveTools(void);
X/* toolmanager.c */
Xvoid cleanup(int);
X/* window.c */
XULONG OpenStatusWindow(void);
Xvoid CloseStatusWindow(void);
XBOOL HandleWindowEvent(void);
Xvoid RefreshStatusWindow(void);
Xvoid AttachToolList(void);
Xvoid DetachToolList(void);
X
X/* Global variables */
Xextern struct MsgPort *MyMP;
Xextern struct List ToolList;
Xextern UWORD ToolCount;
Xextern ULONG wbactive;
Xextern char MyName[];
Xextern UBYTE WindowTitle[];
Xextern struct DiskObject *MyIcon;
Xextern LONG IconXPos,IconYPos;
Xextern BOOL ShowIcon;
Xextern struct AppIcon *MyAppIcon;
X
X/* Global defines */
X#define BUFLEN  100  /* Buffer length for one config line */
X#define NAMELEN 256  /* Buffer length for a file name */
END_OF_FILE
if test 2522 -ne `wc -c <'src/ToolManager.h'`; then
    echo shar: \"'src/ToolManager.h'\" unpacked with wrong size!
fi
# end of 'src/ToolManager.h'
fi
if test -f 'src/config.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/config.c'\"
else
echo shar: Extracting \"'src/config.c'\" \(5370 characters\)
sed "s/^X//" >'src/config.c' <<'END_OF_FILE'
X/*
X * config.c   V1.3
X *
X * configuration file handling
X *
X * (c) 1991 by Stefan Becker
X *
X */
X#include "ToolManager.h"
X
X/* Keywords in the configuration file, must end with a ':'!! */
Xstatic char IconKey[]="ICON:";
Xstatic char CLIKey[]="CLI:";
Xstatic char WBKey[]="WB:";
X
X/* miscellaneous */
Xextern char *ConfigName;
Xextern char SCButtonText[];  /* file requester title */
X
X/* Set the name of the config file */
Xvoid SetConfigFileName(char *s)
X{
X if (ConfigName) free(ConfigName);
X ConfigName=strdup(s);
X}
X
X/* Build one config line */
Xvoid BuildConfigLine(struct ToolNode *tn, char *buf)
X{
X if (tn->tn_CLI) strcpy(buf,CLIKey); /* Copy tool type */
X else strcpy(buf,WBKey);
X
X strcat(buf,tn->tn_Node.ln_Name);    /* Append menu entry name */
X if (tn->tn_RealName)                /* Exists a real name? */
X  {
X   strcat(buf,";");                  /* Yes, append it */
X   strcat(buf,tn->tn_RealName);
X  }
X}
X
X/* Scan one config line */
XBOOL ScanConfigLine(char *buf, BPTR fl)
X{
X char *cp1,*cp2;
X BOOL cli,rc=FALSE;
X
X if ((cli=!strnicmp(buf,CLIKey,sizeof(CLIKey)-1)) ||
X     !strnicmp(buf,WBKey,sizeof(WBKey)-1))
X  {
X   cp1=strchr(buf,':')+1;
X
X   if (cp2=strchr(cp1,';'))              /* Scan config line for ';' */
X    {
X     *cp2='\0';                          /* Menu entry ; real program name */
X     rc=AddToolNode(fl,cp1,++cp2,cli);
X    }
X   else rc=AddToolNode(fl,cp1,NULL,cli); /* Menu entry == real program name */
X  }
X
X return(rc);
X}
X
X/* Read configuration file */
Xvoid ReadConfigFile(BPTR fl)
X{
X FILE *fh;                /* Filehandle for config file */
X char ConfigLine[BUFLEN]; /* Buffer for one config file line */
X
X if (fh=fopen(ConfigName,"r")) /* Scan config file */
X  {
X   while (!feof(fh)) /* if not end of file, read one line into buffer */
X    if (fgets(ConfigLine,BUFLEN,fh) && (strlen(ConfigLine)>1))
X     {
X      ConfigLine[strlen(ConfigLine)-1]='\0'; /* Strip newline */
X      if (!strnicmp(ConfigLine,IconKey,sizeof(IconKey)-1))
X       {
X        char *cp;
X
X        IconXPos=strtol(ConfigLine+sizeof(IconKey)-1,&cp,10);
X        IconYPos=strtol(cp+1,&cp,10);
X       }
X      else ScanConfigLine(ConfigLine,fl);
X     }
X   fclose(fh);  /* close config file */
X  }
X}
X
X/* Tiny long to string conversion routine */
Xstatic void ltoa(char *s, long n)
X{
X long i=1000000000;     /* Divisor */
X BOOL inumber=FALSE;    /* Flag */
X
X if (n==-2147483648)    /* Handle special case 2^31*/
X  {
X   strcpy(s,"-2147483648");
X   return;
X  }
X
X if (n<0)               /* Handle negativ numbers */
X  {
X   n=-n;
X   *s++='-';
X  }
X
X if (n==0) *s++='0';    /* Zero is a special case */
X else while (i)         /* Every other numer goes here */
X       {
X        *s=n/i+'0';     /* Retrieve leading digit */
X        if (*s!='0') inumber=TRUE; /* Suppress leading zero's */
X        if (inumber) s++;
X        n%=i;           /* Remove digit from number */
X        i/=10;          /* next divisor */
X       }
X
X *s='\0';               /* Append string terminator */
X}
X
X/* Write configuration file */
XBOOL WriteConfigFile(struct Window *w)
X{
X struct FileRequester *req;
X BOOL rc=FALSE;
X char dir[NAMELEN],file[NAMELEN],*cp;
X
X /* Split file name */
X cp=FilePart(ConfigName);
X if (cp!=ConfigName) strncpy(dir,ConfigName,cp-ConfigName);
X dir[cp-ConfigName]='\0';
X strncpy(file,cp,NAMELEN);
X
X /* Alloc file requester structure */
X if (!(req=AllocAslRequestTags(ASL_FileRequest,ASL_Hail,SCButtonText,
X                                               ASL_Window,w,
X                                               ASL_LeftEdge,w->LeftEdge,
X                                               ASL_TopEdge,w->TopEdge,
X                                               ASL_Dir,dir,
X                                               ASL_File,file,
X                                               ASL_FuncFlags,FILF_SAVE,
X                                               TAG_DONE)))
X  return(TRUE);
X
X /* Open file requester */
X if (AslRequest(req,NULL))
X  if (*req->rf_File)                   /* Valid file name? */
X   {
X    FILE *fh;
X    struct ToolNode *tn;
X
X    strncpy(dir,req->rf_Dir,NAMELEN);  /* Build complete name */
X    AddPart(dir,req->rf_File,NAMELEN);
X    SetConfigFileName(dir);
X
X    if (fh=fopen(ConfigName,"w"))      /* Open config file */
X     {
X      /* Write icon position line */
X      fputs(IconKey,fh);
X      ltoa(dir,IconXPos);
X      fputs(dir,fh);
X      fputc(',',fh);
X      ltoa(dir,IconYPos);
X      fputs(dir,fh);
X      fputc('\n',fh);
X
X      for (tn=GetHead(&ToolList); tn; tn=GetSucc(tn))
X       {
X        if (tn->tn_CLI) fputs(CLIKey,fh); /* Write tool type */
X        else fputs(WBKey,fh);
X
X        fputs(tn->tn_Node.ln_Name,fh); /* Write menu entry name */
X        if (tn->tn_RealName)           /* Exists a real name? */
X         {
X          fputc(';',fh);               /* Yes, append it */
X          if (tn->tn_CLI) fputs(tn->tn_RealName,fh);
X          else
X           if (!NameFromLock(tn->tn_DirLock,dir,NAMELEN) ||
X                !AddPart(dir,tn->tn_RealName,NAMELEN))
X            fputs(tn->tn_RealName,fh);
X           else fputs(dir,fh);
X         }
X        fputc('\n',fh);                /* Append a new line */
X       }
X      fclose(fh);                      /* Close the config file */
X     }
X    else rc=TRUE;                      /* Could not open config file! */
X   }
X  else rc=TRUE;                        /* No valid file name */
X
X FreeAslRequest(req);
X return(rc);
X}
X
END_OF_FILE
if test 5370 -ne `wc -c <'src/config.c'`; then
    echo shar: \"'src/config.c'\" unpacked with wrong size!
fi
# end of 'src/config.c'
fi
if test -f 'src/data.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/data.c'\"
else
echo shar: Extracting \"'src/data.c'\" \(2160 characters\)
sed "s/^X//" >'src/data.c' <<'END_OF_FILE'
X/*
X * data.c   V1.3
X *
X * global data
X *
X * (c) 1991 by Stefan Becker
X *
X */
X#include "ToolManager.h"
X
X/* Version string */
XMyIdent="$VER: ToolManager " TM_VERSION " (" TM_DATE ")";
X
X/* Structures for icon */
Xstatic __chip UWORD ImageData[]={ /* Graphic data (48x48 Pixels) */
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x7ffE,0x0000,0x0000,0x7ffE,0x0000,0x0000,0x7ffE,0x0000,
X 0x0000,0x7ffE,0x0000,0x0000,0x7ffE,0x0000,0x0000,0x7ffE,0x0000,
X 0x3fff,0xffff,0xfffC,0x3fff,0xffff,0xfffC,0x3fff,0xffff,0xfffC,
X 0x3fff,0xffff,0xfffC,0x3fff,0xffff,0xfffC,0x3fff,0xffff,0xfffC,
X 0x0000,0x7ffE,0x0000,0x0000,0x7ffE,0x0000,0x0000,0x7ffE,0x0000,
X 0x0000,0x7ffE,0x0000,0x0000,0x7ffE,0x0000,0x0000,0x7ffE,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
Xstatic struct Image MyIconImage={NULL,NULL,48,24,1,ImageData,1,0,NULL};
Xstatic struct DiskObject InternalIcon={NULL,NULL,
X               /* Gadget definition */ {NULL,NULL,NULL,48,25,NULL,NULL,NULL,
X                                        &MyIconImage,NULL,NULL,NULL,NULL,NULL,
X                                        NULL},
X                                       NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
Xstruct DiskObject *MyIcon=&InternalIcon;
XLONG IconXPos=NO_ICON_POSITION;
XLONG IconYPos=NO_ICON_POSITION;
XBOOL ShowIcon=TRUE;
Xstruct AppIcon *MyAppIcon;
X
X/* Structures for message port */
Xstruct MsgPort *MyMP;
X
X/* List for ToolNodes */
Xstruct List ToolList; /* This list contains ToolNodes */
XUWORD ToolCount=0;    /* Number of tools in ToolList */
XULONG wbactive=0;     /* Active WB tools */
X
X/* Name of the message port & icon */
Xchar MyName[]="ToolManager";
X
X/* Name of the configuration file */
Xchar InternalConfigName[]="S:ToolManager.Config";
Xchar *ConfigName=NULL;
X
X/* Structures for window */
XUBYTE WindowTitle[]="ToolManager V" TM_VERSION " (c)" TM_CRYEAR " by S. Becker";
Xstruct NewWindow nw={20,20,640,256,0,1,CLOSEWINDOW|REFRESHWINDOW|GADGETUP|
X                     GADGETDOWN|MOUSEMOVE|INTUITICKS,WINDOWDRAG|WINDOWDEPTH|
X                     WINDOWCLOSE|SIMPLE_REFRESH|ACTIVATE,NULL,
X                     NULL,WindowTitle,NULL,NULL,0,0,0,0,0};
END_OF_FILE
if test 2160 -ne `wc -c <'src/data.c'`; then
    echo shar: \"'src/data.c'\" unpacked with wrong size!
fi
# end of 'src/data.c'
fi
if test -f 'src/mainloop.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/mainloop.c'\"
else
echo shar: Extracting \"'src/mainloop.c'\" \(5254 characters\)
sed "s/^X//" >'src/mainloop.c' <<'END_OF_FILE'
X/*
X * mainloop.c   V1.3
X *
X * main event loop
X *
X * (c) 1991 by Stefan Becker
X *
X */
X#include "ToolManager.h"
X
X/* The main processing loop */
Xvoid mainloop(void)
X{
X BOOL end=TRUE;                  /* Flag for main loop */
X BOOL windowopen=FALSE;          /* Flag for status window */
X ULONG sigs,bsigs,psigs,wsigs;   /* Buffers for signals */
X
X /* Init icon position */
X MyIcon->do_CurrentX=IconXPos;
X MyIcon->do_CurrentY=IconYPos;
X
X /* Notify Workbench about icon, if ShowIcon is true */
X if (ShowIcon)
X  if (!(MyAppIcon=AddAppIcon(NULL,NULL,MyName,MyMP,NULL,MyIcon,TAG_DONE)))
X   cleanup(8);
X
X bsigs=SIGBREAKF_CTRL_C|         /* break signals */
X       SIGBREAKF_CTRL_D|SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_F;
X psigs=1L<<MyMP->mp_SigBit;      /* port signal */
X sigs=bsigs|psigs;               /* merge signals */
X
X while (end)                     /* main loop */
X  {
X   struct AppMessage *msg;       /* pointer to received message */
X   ULONG gotsigs;                /* received signals */
X
X   gotsigs=Wait(sigs);           /* Wait for specified signals */
X
X   if ((gotsigs&bsigs) && !wbactive) /* Got break signals and is no WB tool */
X    end=FALSE;                       /* running? Yes, quit program */
X
X   if (gotsigs&psigs)            /* Message arrived at message port? */
X    while (msg=GetMsg(MyMP))     /* Yes, empty message queue */
X     if (msg->am_Message.mn_Node.ln_Type==NT_REPLYMSG) /* Replied message? */
X      {
X       /* This is the death message from a tool we started some time ago */
X       struct WBStartup *wbs=(struct WBStartup *) msg;
X       struct WBArg *wa=wbs->sm_ArgList;
X       int i=wbs->sm_NumArgs;
X
X       while (i--)
X        {
X         UnLock(wa->wa_Lock);    /* Free WB argument */
X         if (wa->wa_Name) free(wa->wa_Name);
X         wa++;
X        }
X
X       if (wbs->sm_ToolWindow)   /* Free tool window specification */
X        free(wbs->sm_ToolWindow);
X
X       UnLoadSeg(wbs->sm_Segment); /* Unload code */
X       free(wbs);                  /* Free WBStartup */
X       wbactive--;                 /* One tool closed down */
X      }
X     else
X      {
X       switch(msg->am_Type)       /* Switch between message types */
X        {
X         case MTYPE_APPWINDOW:    /* Window action */
X         case MTYPE_APPICON:      /* Icon action */
X          if (msg->am_NumArgs==0) /* Did the user double click my icon? */
X           {                      /* Yes! If window not open, open it */
X            if ((!windowopen) && (wsigs=OpenStatusWindow()))
X             {
X              sigs|=wsigs;        /* Merge with other signals */
X              windowopen=TRUE;    /* Window is open */
X             }
X           }
X          else                    /* User dropped an icon on my icon */
X           {                      /* Add Workbench parameters to tool list */
X            if (!WBAddToolNode(msg->am_ArgList,msg->am_NumArgs))
X             DisplayBeep(NULL);
X            if (windowopen)       /* Refresh status window if open */
X             RefreshStatusWindow();
X           }
X          break;
X
X         case MTYPE_APPMENUITEM:  /* Menu action */
X          switch(msg->am_ID)
X           {
X            case 0:               /* "Quit ToolManager" menu item */
X             if (wbactive)        /* Yes. Do we have a tool running? */
X              DisplayBeep(NULL);  /*      Yes, we can't quit! */
X             else end=FALSE;      /*      No, quit program */
X             break;
X
X            case 1:               /* "Open TM Window" menu item */
X             if ((!windowopen) && (wsigs=OpenStatusWindow()))
X              {
X               sigs|=wsigs;       /* Merge with other signals */
X               windowopen=TRUE;   /* Window is open */
X              }
X             break;
X
X            default:              /* Default: Tool selected */
X             struct ToolNode *tn;
X             char *cp;
X             BOOL rc;
X
X             /* Scan list for selected tool */
X             for (tn=GetHead(&ToolList); tn; tn=GetSucc(tn))
X              if (tn->tn_ID==msg->am_ID)
X               {                            /* Corresponding tool found */
X                if (!(cp=tn->tn_RealName))  /* Get tool name */
X                 cp=tn->tn_Node.ln_Name;
X
X                /* Tool type? */
X                if (tn->tn_CLI) rc=StartCLITool(msg,tn,cp); /* CLI */
X                else rc=StartWBTool(msg,tn,cp);             /* WB  */
X
X                if (!rc) DisplayBeep(NULL); /* An error occured */
X                break;                      /* leave 'for' loop */
X               }
X             break;
X           }
X          break;
X        } /* end of switch(msg->am_Type) */
X
X       ReplyMsg((struct Message *) msg); /* Reply message to sender */
X      } /* end of if (msg->......) */
X
X   if (windowopen && (gotsigs&wsigs)) /* If window open, got window signal? */
X    if (HandleWindowEvent())          /* Handle window event */
X     {                                /* Window close event? */
X      CloseStatusWindow();            /* Yes, close window */
X      sigs&=~wsigs;                   /* Remove window signals */
X      windowopen=FALSE;               /* Window closed */
X     }
X  } /* end of main loop */
X
X /* If window open, close it */
X if (windowopen) CloseStatusWindow();
X
X /* Exit program */
X cleanup(99);
X}
X
END_OF_FILE
if test 5254 -ne `wc -c <'src/mainloop.c'`; then
    echo shar: \"'src/mainloop.c'\" unpacked with wrong size!
fi
# end of 'src/mainloop.c'
fi
if test -f 'src/starttools.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/starttools.c'\"
else
echo shar: Extracting \"'src/starttools.c'\" \(5192 characters\)
sed "s/^X//" >'src/starttools.c' <<'END_OF_FILE'
X/*
X * starttools.c   V1.3
X *
X * CLI & WB startup procedure
X *
X * (c) 1991 by Stefan Becker
X *
X */
X#include "ToolManager.h"
X
X/* Start tool as a CLI process */
XBOOL StartCLITool(struct AppMessage *msg, struct ToolNode *tn, char *name)
X{
X BPTR fl;                       /* AmigaDOS file handle */
X BOOL rc=TRUE;
X char cmd[NAMELEN];             /* Buffer for command line */
X int cmdlen;                    /* Command line length */
X char dir[NAMELEN];
X struct WBArg *wa=msg->am_ArgList;
X int i;
X
X fl=CurrentDir(tn->tn_DirLock); /* Change to tool's directory */
X
X strcpy(cmd,name);              /* Command name first */
X cmdlen=strlen(cmd);
X
X for (i=msg->am_NumArgs; i; i--,wa++)
X  {
X   char *cp;
X   int namelen;
X
X   if (!wa->wa_Lock) continue;  /* Skip arguments which don't support locks! */
X
X   if (cmdlen>NAMELEN-2) break; /* Append a space for each parameter */
X   strcat(cmd," ");
X   cmdlen++;
X
X   /* Build parameter from Lock & name */
X   if (SameLock(tn->tn_DirLock,wa->wa_Lock)==LOCK_SAME) cp=wa->wa_Name;
X   else
X    {
X     if (!NameFromLock(wa->wa_Lock,dir,NAMELEN)) continue;
X     if (!AddPart(dir,wa->wa_Name,NAMELEN)) continue;
X     cp=dir;
X    }
X
X   namelen=strlen(cp);
X
X   if (strchr(cp,' '))          /* Special case: Space in a filename */
X    if (namelen>NAMELEN-3) break;
X    else
X     {
X      strins(cp,"\"");          /* Set parameter in double quotes */
X      strcat(cp,"\"");
X      namelen+=2;
X     }
X
X   if (cmdlen+namelen>NAMELEN-2) break;
X   strcat(cmd,cp);              /* Append parameter */
X   cmdlen+=namelen;             /* New command line length */
X  }
X
X /* Start tool */
X if (SystemTags(cmd,SYS_Input,Open("NIL:",MODE_NEWFILE),
X                    SYS_Output,Open("NIL:",MODE_NEWFILE),
X                    SYS_Asynch,TRUE, /* Run tools asynchronously */
X                    TAG_DONE)==-1)
X  rc=FALSE; /* An error occured */
X
X CurrentDir(fl);                /* Change to old directory */
X return(rc);
X}
X
X/* Start tool as a WB process */
XBOOL StartWBTool(struct AppMessage *msg, struct ToolNode *tn, char *name)
X{
X BPTR fl;                       /* AmigaDOS file handle */
X struct WBStartup *wbs;         /* WBStartup message for tool */
X struct DiskObject *tdob;       /* Tool icon */
X LONG ssize=4096;               /* StackSize, default */
X struct MsgPort *proc;          /* Process descriptor for tool */
X/* struct Process *proc;  Process descriptor for CreateNewProc */
X struct WBArg *wbad,*wbas;      /* Pointers to WB arguments */
X int i;
X
X /* Allocate memory for WBStartup */
X if (!(wbs=calloc(sizeof(struct WBStartup)+
X                  sizeof(struct WBArg)*(msg->am_NumArgs+1),1))) return (FALSE);
X
X fl=CurrentDir(tn->tn_DirLock); /* Change to tool's directory */
X
X if (!(wbs->sm_Segment=NewLoadSeg(name,NULL))) goto e1; /* Load tool code */
X
X /* Get some information about the tool */
X if (tdob=GetDiskObject(name))
X  {
X   if (tdob->do_Type==WBTOOL) /* Only WBTools supply this type of info! */
X    {
X     if (tdob->do_ToolWindow) wbs->sm_ToolWindow=strdup(tdob->do_ToolWindow);
X     if (tdob->do_StackSize>ssize) ssize=tdob->do_StackSize;
X    }
X   FreeDiskObject(tdob);
X  }
X
X /* Build WBStartup message */
X /* wbs->sm_Message.mn_Node.ln_Type=NT_MESSAGE; PutMsg() does this for us! */
X wbs->sm_Message.mn_ReplyPort=MyMP;
X wbs->sm_Message.mn_Length=sizeof(struct WBStartup);
X wbs->sm_NumArgs=msg->am_NumArgs+1;
X wbs->sm_ArgList=wbs+1;             /* WBArg array starts after WBStartup */
X
X /* Initialize WBArg pointers */
X wbas=msg->am_ArgList;
X wbad=wbs->sm_ArgList;
X
X /* 1. argument is the tool itself! */
X if (!(wbad->wa_Lock=DupLock(tn->tn_DirLock))) goto e2;
X if (!(wbad->wa_Name=strdup(name))) goto e3;
X wbad++;
X
X /* Copy WB arguments */
X for (i=msg->am_NumArgs; i; i--,wbas++,wbad++)
X  {
X   if (!(wbad->wa_Lock=DupLock(wbas->wa_Lock)))
X    {
X     wbad--;             /* Skip parameters, which don't support a lock */
X     wbs->sm_NumArgs--;
X     continue;           /* Next parameter */
X    }
X
X   /* Sanity check for name string... Enforcer is watching you! */
X   if (!wbas->wa_Name || !(wbad->wa_Name=strdup(wbas->wa_Name))) goto e3;
X  }
X
X /* Create process */
X if (!(wbs->sm_Process=CreateProc(wbs->sm_ArgList->wa_Name,0,wbs->sm_Segment,
X                                  ssize))) goto e3;
X
X/* if (!(proc=CreateNewProcTags(NP_Seglist,wbs->sm_Segment,
X                              NP_FreeSeglist,TRUE,
X  Maybe someday I will know   NP_StackSize,ssize,
X  what Tags I need to make    NP_Name,wbs->sm_ArgList->wa_Name,
X  CreateNewProc() behave      NP_CloseInput,FALSE,
X  like CreateProc()           NP_CloseOutput,FALSE,
X                              TAG_DONE))) goto e3; */
X
X /* Send WBStartup message to tool */
X/* wbs->sm_Process=&proc->pr_MsgPort; for CreateNewProc() */
X PutMsg(wbs->sm_Process,(struct Message *) wbs);
X CurrentDir(fl);                /* Change to old directory */
X wbactive++;                    /* Tool started! */
X return(TRUE);
X
X /* An error occurred. Free all resources */
Xe3: wbas=wbs->sm_ArgList;
X    for (i=wbs->sm_NumArgs; i; i--,wbas++)
X     {
X      UnLock(wbas->wa_Lock);
X      if (wbas->wa_Name) free(wbas->wa_Name);
X     }
Xe2: UnLoadSeg(wbs->sm_Segment);
Xe1: CurrentDir(fl);
X    free(wbs);
X    return(FALSE);
X}
X
END_OF_FILE
if test 5192 -ne `wc -c <'src/starttools.c'`; then
    echo shar: \"'src/starttools.c'\" unpacked with wrong size!
fi
# end of 'src/starttools.c'
fi
if test -f 'src/toollist.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/toollist.c'\"
else
echo shar: Extracting \"'src/toollist.c'\" \(3837 characters\)
sed "s/^X//" >'src/toollist.c' <<'END_OF_FILE'
X/*
X * toollist.c   V1.3
X *
X * tool list handling
X *
X * (c) 1991 by Stefan Becker
X *
X */
X#include "ToolManager.h"
X
X/* Add one program to tool list */
XBOOL AddToolNode(BPTR dir, char *name, char *realname, BOOL clitool)
X{
X static ULONG ToolID=1; /* Counter for Tool ID */
X struct ToolNode *tn;
X
X if (ToolCount>=99) goto e1; /* Not more than 99 Tools :-) possible */
X
X /* Get memory for ToolNode */
X if (!(tn=malloc(sizeof(struct ToolNode))))
X  goto e1;
X
X /* Get memory for menu item name and copy it */
X if (!(tn->tn_Node.ln_Name=strdup(name)))
X  goto e2;
X
X /* Does the program have a real name? */
X if (realname)
X  {
X   /* Get memory for real program name and copy it */
X   if (!(tn->tn_RealName=strdup(realname)))
X    goto e3;
X  }
X else
X  tn->tn_RealName=NULL; /* Otherwise: menu item name == real program name */
X
X /* Add a new menu entry */
X if (!(tn->tn_MenuItem=AddAppMenuItem(ToolID+1,NULL,tn->tn_Node.ln_Name,
X                                      MyMP,TAG_DONE)))
X  goto e4;
X
X if (!(tn->tn_DirLock=DupLock(dir))) /* Duplicate directory lock */
X  goto e5;
X
X /* Add node to tool list */
X tn->tn_ID=++ToolID;    /* Set Tool ID */
X tn->tn_CLI=clitool;    /* Set Tool program type */
X ToolCount++;           /* Increment active tool count */
X DetachToolList();      /* Detach list from ListView gadget */
X AddTail(&ToolList,(struct Node *) tn);
X AttachToolList();      /* Attach list to ListView gadget */
X
X /* Node successfully added to list! */
X return(TRUE);
X
X /* Something went wrong.... */
Xe5: RemoveAppMenuItem(tn->tn_MenuItem);
Xe4: if (tn->tn_RealName) free(tn->tn_RealName);
Xe3: free(tn->tn_Node.ln_Name);
Xe2: free(tn);
Xe1: return(FALSE);
X}
X
X/* Scan Workbench parameters and add them to tool list */
XBOOL WBAddToolNode(struct WBArg *wbarg, int numargs)
X{
X int i;
X BOOL rc=TRUE;
X BPTR fl;
X struct DiskObject *dobj;
X
X for (i=numargs; i; i--,wbarg++)            /* Scan all parameters */
X  /* Sanity check */
X  if (wbarg->wa_Lock && wbarg->wa_Name && (strlen(wbarg->wa_Name)!=0))
X   {
X    fl=CurrentDir(wbarg->wa_Lock);          /* Change to icon's directory */
X    if (dobj=GetDiskObject(wbarg->wa_Name)) /* Get icon data */
X     {
X      switch(dobj->do_Type) /* Perform action depending on icon type */
X       {
X        case WBTOOL:    /* Icon is a Tool. Menu entry == real program name */
X         rc&=AddToolNode(wbarg->wa_Lock,wbarg->wa_Name,wbarg->wa_Name,FALSE);
X         break;
X        case WBPROJECT: /* Icon is a Project. Menu entry = icon name,
X                           real program name = default tool name */
X         rc&=AddToolNode(wbarg->wa_Lock,wbarg->wa_Name,
X                         dobj->do_DefaultTool,FALSE);
X         break;
X        default:        /* Every other icon type is erroneous */
X         rc&=FALSE;
X         break;
X       }
X      FreeDiskObject(dobj); /* Release icon data */
X     }
X    else /* Can't get icon data, so we add it as a CLI tool */
X     rc&=AddToolNode(wbarg->wa_Lock,wbarg->wa_Name,wbarg->wa_Name,TRUE);
X
X    CurrentDir(fl); /* Change to old directory */
X   }
X  else
X   rc&=FALSE; /* Error: Bad Workbench parameter */
X
X return(rc); /* Return TRUE if no error */
X}
X
X/* Remove ONE node from the tool list */
Xvoid RemToolNode(struct ToolNode *tn)
X{
X Remove((struct Node *) tn);                 /* Remove node from list */
X UnLock(tn->tn_DirLock);                     /* Free directory */
X RemoveAppMenuItem(tn->tn_MenuItem);         /* Remove menu entry */
X if (tn->tn_RealName) free(tn->tn_RealName); /* Free memory */
X free(tn->tn_Node.ln_Name);
X free(tn);
X ToolCount--;                                /* decrement active tool count */
X}
X
X/* Remove ALL nodes from the tool list */
Xvoid RemoveTools(void)
X{
X struct ToolNode *tn1,*tn2=GetHead(&ToolList); /* Begin of list */
X
X while (tn1=tn2)
X  {
X   tn2=GetSucc(tn1); /* Next in list */
X   RemToolNode(tn1); /* Remove node */
X  }
X}
END_OF_FILE
if test 3837 -ne `wc -c <'src/toollist.c'`; then
    echo shar: \"'src/toollist.c'\" unpacked with wrong size!
fi
# end of 'src/toollist.c'
fi
if test -f 'src/toolmanager.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/toolmanager.c'\"
else
echo shar: Extracting \"'src/toolmanager.c'\" \(7797 characters\)
sed "s/^X//" >'src/toolmanager.c' <<'END_OF_FILE'
X/*
X * toolmanager.c   V1.3
X *
X * startup routines
X *
X * (c) 1991 by Stefan Becker
X *
X */
X#include "ToolManager.h"
X
X/* Library pointers */
Xextern struct Library *SysBase,*IntuitionBase,*GfxBase; /* Autoinit Libs */
Xstruct Library *WorkbenchBase,*IconBase,*GadToolsBase,*AslBase;
X
X/* CLI command line options */
Xstatic char NoIconOpt[]="-n";
Xstatic char ConfigOpt[]="-f";
X
X/* miscellaneous */
Xextern char InternalConfigName[];
Xstatic struct DiskObject *dobj=NULL;
Xstatic struct AppMenuItem *QTMAppMenuItem;
Xstatic struct AppMenuItem *OTWAppMenuItem;
Xstatic APTR OldConsoleTask=NULL;
X
X/* Open libraries and other stuff */
Xstatic BOOL openstuff(void)
X{
X if (SysBase->lib_Version<36)  /* Sanity check */
X  {
X   puts("You need a Kickstart 2.0 or better to run ToolManager!");
X   exit(20);
X  }
X
X /* Open libraries */
X if (!(WorkbenchBase=OpenLibrary(WORKBENCH_NAME,0)))
X  cleanup(1);
X
X if (!(IconBase=OpenLibrary(ICONNAME,0)))
X  cleanup(2);
X
X if (!(GadToolsBase=OpenLibrary("gadtools.library",0)))
X  cleanup(3);
X
X if (!(AslBase=OpenLibrary(AslName,0)))
X  cleanup(4);
X
X Forbid();                     /* Is "ToolManager" already running? */
X MyMP=FindPort(MyName);
X Permit();
X if (MyMP) return(TRUE);       /* Yes, don't start again! */
X
X if (!(MyMP=CreateMsgPort()))  /* No, create message port */
X  cleanup(5);
X MyMP->mp_Node.ln_Pri=0;
X MyMP->mp_Node.ln_Name=MyName; /* Our name */
X AddPort(MyMP);                /* Announce our presence */
X return(FALSE);                /* No, start ToolManager */
X}
X
X/* Init tool stuff */
Xstatic void inittool(void)
X{
X SetConfigFileName(InternalConfigName); /* Copy config file name */
X NewList(&ToolList);                    /* Initialize tool list */
X
X /* Notify Workbench about special menu items. */
X /* 1. If this item is selected, the program will quit */
X if (!(QTMAppMenuItem=AddAppMenuItem(0,NULL,"Quit ToolManager",MyMP,TAG_DONE)))
X  cleanup(6);
X
X /* 2. If this item is selected, the status window will open */
X if (!(OTWAppMenuItem=AddAppMenuItem(1,NULL,"Open TM Window",MyMP,TAG_DONE)))
X  cleanup(7);
X}
X
X/* Send an AppMessage with our parameters to a running ToolManager process */
Xstatic void SendParameters(LONG nargs, struct WBArg *arg)
X{
X struct MsgPort *sp,*rp;
X struct AppMessage *msg;
X
X /* Allocate memory for AppMessage */
X if (!(msg=malloc(sizeof(struct AppMessage)))) goto e1;
X
X /* Create a reply port */
X if (!(rp=CreateMsgPort())) goto e2;
X
X /* Build AppMessage */
X msg->am_Message.mn_Node.ln_Type=NT_MESSAGE;
X msg->am_Message.mn_Node.ln_Pri=0;
X msg->am_Message.mn_ReplyPort=rp;
X msg->am_Type=MTYPE_APPICON;
X msg->am_NumArgs=nargs;
X msg->am_ArgList=arg;
X
X Forbid();                     /* Find "ToolManager" message port */
X sp=FindPort(MyName);
X if (sp) PutMsg(sp,(struct Message *) msg); /* Send AppMessage */
X Permit();
X
X if (sp)
X  {                            /* We have send the message */
X   WaitPort(rp);               /* Wait on the reply */
X   GetMsg(rp);                 /* Remove reply from port */
X  }
X
X    DeleteMsgPort(rp);
Xe2: free(msg);
Xe1: return;
X}
X
X/* Workbench main entry point */
Xvoid wbmain(struct WBStartup *wbarg)
X{
X BPTR fl;
X
X if (openstuff())         /* common startup code */
X  {                       /* ToolManager already running, send parameters */
X   if (wbarg->sm_NumArgs>1)
X    SendParameters(wbarg->sm_NumArgs-1,wbarg->sm_ArgList+1);
X   cleanup(5);            /* All done */
X  }
X
X inittool();              /* Init tool stuff */
X
X /* Process WB startup parameters */
X WBAddToolNode(wbarg->sm_ArgList+1,wbarg->sm_NumArgs-1);
X
X /* Get the program icon */
X fl=CurrentDir(wbarg->sm_ArgList->wa_Lock);
X if (dobj=GetDiskObject(wbarg->sm_ArgList->wa_Name))
X  {
X   char *cp,**ttp=dobj->do_ToolTypes;
X
X   /* Retreive ToolTypes from icon */
X   /* 1. CONFIG=<name> Set configuration file name */
X   if (cp=FindToolType(ttp,"CONFIG")) SetConfigFileName(cp);
X
X   /* 2. INTERNALICON Use the internal icon as AppIcon */
X   if (!FindToolType(ttp,"INTERNALICON")) MyIcon=dobj;
X
X   /* 3. SHOWICON=YES|NO Show AppIcon */
X   if (cp=FindToolType(ttp,"SHOWICON"))
X    if (!(ShowIcon=MatchToolValue(cp,"YES")))
X     {
X      FreeDiskObject(dobj);
X      dobj=NULL;
X     }
X  }
X CurrentDir(fl);
X
X /* Read configuration file */
X ReadConfigFile(wbarg->sm_ArgList->wa_Lock);
X
X mainloop(); /* Go into main loop */
X}
X
X/* CLI main entry point */
Xvoid main(int argc, char **argv)
X{
X int i;
X BPTR fl;
X struct Process *pr=FindTask(NULL);
X
X /* Help requested? */
X if ((argc>1) && (*argv[1]=='?'))
X  { /* Print out usage, but DON'T start ToolManager */
X   puts("\nUsage: ToolManager [-n] [-f <file>] [program 1] ... [program n]");
X   puts("       -n : Don't show the program icon");
X   puts("       -f : Use <file> as configuration file");
X   puts("Requires Kickstart 2.0 or better!\n");
X   exit(0);
X  }
X
X freopen("*","w",stderr);     /* Reopen the stderr for banner line */
X fputs(WindowTitle,stderr);   /* Put out banner line (only in CLI) */
X fputc('\n',stderr);
X fclose(stderr);
X
X if (openstuff())             /* common startup code */
X  {                           /* ToolManager already running, send parameters */
X   struct WBArg *wa,*wat;
X
X   if (argc<2) cleanup(5);    /* No parameters to send */
X
X   /* Allocate memory for WB parameters */
X   if (!(wa=malloc(sizeof(struct WBArg)*(argc-1)))) cleanup(5);
X
X   fl=CurrentDir(NULL);       /* Get current directory lock */
X
X   wat=wa;                    /* Build WBArgs */
X   for (i=argc-1; i; i--,wat++)
X    {
X     ++argv;
X
X     if (strcmp(*argv,NoIconOpt) && strcmp(*argv,ConfigOpt))
X      {
X       wat->wa_Lock=fl;       /* Copy parameters */
X       wat->wa_Name=*argv;
X      }
X     else
X      {
X       argc--;                /* Filter out CLI command line options */
X       wat--;
X      }
X    }
X
X   if (argc>1) SendParameters(argc-1,wa); /* Send parameters */
X
X   CurrentDir(fl);            /* Go back to old directory */
X   free(wa);                  /* Free WB parameters */
X   cleanup(5);                /* All done */
X  }
X
X inittool();                  /* Init tool stuff */
X fl=CurrentDir(NULL);         /* Get current directory lock */
X
X /* Process CLI startup parameters */
X for (i=argc-1; i; i--)
X  {
X   ++argv; /* Next command line parameter */
X
X   /* Process CLI options */
X   /* 1. "-n" Don't show AppIcon */
X   if (!strcmp(*argv,NoIconOpt)) ShowIcon=FALSE;
X
X   /* 2. <name> Add tool */
X   else if (strcmp(*argv,ConfigOpt)) AddToolNode(fl,*argv,NULL,TRUE);
X
X   /* 3. "-f <name>" Set configuration file name */
X   else if (i>1)
X         {
X          i--;
X          SetConfigFileName(*++argv);
X         }
X  }
X
X CurrentDir(DupLock(fl));     /* Go to current directory */
X ReadConfigFile(fl);          /* Read configuration file */
X
X UnLock(CurrentDir(fl));      /* Go back to old directory */
X fclose(stdin);               /* Detach from console window */
X fclose(stdout);
X OldConsoleTask=pr->pr_ConsoleTask;
X pr->pr_ConsoleTask=NULL;
X mainloop();                  /* Go into main loop */
X}
X
X/* Final cleanup routine */
Xvoid cleanup(int i)
X{
X register struct Message *msg;
X
X switch(i)
X  {
X   case 99:
X           if (ShowIcon) RemoveAppIcon(MyAppIcon);
X           if (dobj) FreeDiskObject(dobj);
X   case  8:RemoveTools();
X           RemoveAppMenuItem(OTWAppMenuItem);
X   case  7:RemoveAppMenuItem(QTMAppMenuItem);
X   case  6:RemPort(MyMP);                           /* Remove message port */
X           while (msg=GetMsg(MyMP)) ReplyMsg(msg);  /* Reply all messages */
X           DeleteMsgPort(MyMP);
X   case  5:CloseLibrary(AslBase);
X   case  4:CloseLibrary(GadToolsBase);
X   case  3:CloseLibrary(IconBase);
X   case  2:CloseLibrary(WorkbenchBase);
X   case  1:break;
X  }
X
X /* Did we have a console window? */
X if (OldConsoleTask)
X  {
X   struct Process *pr=FindTask(NULL);
X
X   pr->pr_ConsoleTask=OldConsoleTask; /* Yes, restore old value */
X  }
X
X exit(RETURN_OK);    /* all o.k. */
X}
END_OF_FILE
if test 7797 -ne `wc -c <'src/toolmanager.c'`; then
    echo shar: \"'src/toolmanager.c'\" unpacked with wrong size!
fi
# end of 'src/toolmanager.c'
fi
if test -f 'src/window.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/window.c'\"
else
echo shar: Extracting \"'src/window.c'\" \(12789 characters\)
sed "s/^X//" >'src/window.c' <<'END_OF_FILE'
X/*
X * window.c   V1.3
X *
X * status window
X *
X * (c) 1991 by Stefan Becker
X *
X */
X#include "ToolManager.h"
X
X/* Structures for window */
Xextern UBYTE WindowTitle[];
Xextern struct NewWindow nw;
X#define WDRAGBARLEN 60       /* Width of Close & Drag gadget */
Xstatic struct Window *w=NULL;
Xstatic struct AppWindow *aw;
Xstatic struct MsgPort *wp;
Xstatic ULONG wl=20,wt=20;    /* Window leftedge & topedge */
Xstatic ULONG ww,wh;          /* Window width & height */
Xstatic struct Screen *pubsc; /* Workbench screen */
X
X/* Structures for window gadgets */
Xstatic void *vi;             /* Visual information is a *PRIVATE* data field! */
Xstatic struct Gadget *gl;    /* Gadget list */
Xstatic char StatusText[]="Active Tools: 00"; /* Text gadget text */
Xstatic struct Gadget *lvgad;                 /* ListView gadget */
Xstatic WORD lvord=-1;                        /* LV gadget ordinal number */
Xstatic WORD lvtop=0;                         /* LV gadget top item number */
X#define LVGAD_ID 1
Xstatic char ETButtonText[]="Edit Tool Definition"; /* Edit Tool gadget text */
X#define ETGAD_ID 2
Xstatic char RTButtonText[]="Remove Tool";    /* Remove Tool gadget text */
X#define RTGAD_ID 3
Xchar SCButtonText[]="Save Configuration";    /* Save config gadget text */
X#define SCGAD_ID 4
X
X/* Create & handle edit window */
Xstatic BOOL EditToolWindow(struct ToolNode *tn)
X{
X struct NewGadget ng;
X struct Gadget *g,*gl=NULL;
X static struct TextAttr ta={"topaz.font",8,0,0};
X struct TextFont *f;              /* Window font */
X UWORD topborder,fheight;
X ULONG wh;
X struct Window *ew;
X struct MsgPort *wp;
X BOOL rc=TRUE,end=TRUE;
X char buf[BUFLEN];
X
X if (!(pubsc=LockPubScreen("Workbench"))) /* Lock Workbench screen */
X  goto e1;
X
X if (!(f=OpenFont(pubsc->Font))) goto e2; /* Open window font */
X topborder=pubsc->WBorTop+f->tf_YSize+1;
X CloseFont(f);                            /* Close font */
X
X if (!(f=OpenFont(&ta))) goto e2;         /* Open window font */
X fheight=f->tf_YSize;                     /* Font height */
X CloseFont(f);                            /* Close font */
X
X /* Create gadget list */
X gl=NULL;
X g=CreateContext(&gl);
X
X /* Create edit gadget */
X BuildConfigLine(tn,buf);
X ng.ng_LeftEdge=pubsc->WBorLeft+INTERWIDTH;
X ng.ng_TopEdge=topborder+INTERHEIGHT;
X ng.ng_Height=fheight+INTERHEIGHT+2;
X ng.ng_Width=ww;
X ng.ng_TextAttr=&ta;
X ng.ng_GadgetText=NULL;
X ng.ng_Flags=PLACETEXT_IN;
X ng.ng_VisualInfo=vi;
X ng.ng_UserData=0;
X if (!(g=CreateGadget(STRING_KIND,g,&ng,
X                      GTST_String,buf,
X                      GTST_MaxChars,BUFLEN-1,
X                      TAG_DONE)))
X  goto e3;
X
X /* Calculate window height */
X wh=ng.ng_TopEdge+g->Height+2*INTERHEIGHT-topborder;
X
X /* Open window */
X if (!(ew=OpenWindowTags(&nw,
X                         WA_Left,w->LeftEdge-INTERWIDTH,
X                         WA_Top,w->TopEdge+4*wh,
X                         WA_InnerWidth,ww+2*INTERWIDTH,
X                         WA_InnerHeight,wh,
X                         WA_PubScreen,pubsc,
X                         WA_AutoAdjust,TRUE,
X                         WA_Title,ETButtonText,
X                         TAG_DONE)))
X  goto e3;
X
X wp=ew->UserPort; /* Retrieve window port */
X
X /* Circumvent an intuition.library bug. See AutoDocs for LockPubScreen() */
X UnlockPubScreen(NULL,pubsc);
X pubsc=NULL;
X
X /* Add gadget list to window */
X AddGList(ew,gl,(UWORD) -1,(UWORD) -1,NULL);
X RefreshGList(gl,ew,NULL,(UWORD) -1);
X GT_RefreshWindow(ew,NULL);
X ActivateGadget(g,ew,NULL);
X
X /* All OK */
X rc=FALSE;
X
X while (end)
X  {
X   struct IntuiMessage *msg;
X
X   WaitPort(wp);
X
X   while (msg=GT_GetIMsg(wp))
X    {
X     switch (msg->Class)
X      {
X       case INTUITICKS:           /* Intuition tick received */
X        break;
X       case CLOSEWINDOW:          /* User clicked the close gadget */
X        end=FALSE;                /* Yes, close window */
X        break;
X       case REFRESHWINDOW:        /* Window must be refreshed */
X        GT_BeginRefresh(ew);
X        GT_EndRefresh(ew,TRUE);
X        break;
X       case GADGETUP:             /* User released the gadget */
X        /* Config line changed? */
X        if (strcmp(buf,((struct StringInfo *) g->SpecialInfo)->Buffer))
X         {
X          /* Yes, copy new config line */
X          strcpy(buf,((struct StringInfo *) g->SpecialInfo)->Buffer);
X
X          /* Build new ToolNode */
X          DetachToolList();
X          if (ScanConfigLine(buf,tn->tn_DirLock))
X           {                        /* ToolNode created? */
X            RemToolNode(tn);        /* Yes, remove old tool */
X            lvord=-1;               /* Invalidate ordinal number */
X            end=FALSE;              /* Close window */
X           }
X          else                      /* No, reactivate Gadget */
X           {
X            DisplayBeep(NULL);
X            ActivateGadget(g,ew,NULL);
X           }
X
X          AttachToolList();
X         }
X        else end=FALSE; /* Definition not changed, but close edit window */
X        break;
X      }
X     GT_ReplyIMsg(msg);
X    }
X  }
X
X    CloseWindow(ew);
Xe3: FreeGadgets(gl);
Xe2: if (pubsc) UnlockPubScreen(NULL,pubsc);
Xe1: return(rc);
X}
X
X/* Create status line */
Xstatic void PrintStatusLine(void)
X{
X StatusText[14]=ToolCount/10+'0'; /* Hack */
X StatusText[15]=ToolCount%10+'0';
X}
X
X/* Create all status window gadgets */
Xstatic BOOL CreateWindowGadgets(void)
X{
X struct NewGadget ng;
X struct Gadget *g;
X struct TextAttr *ta=pubsc->Font;
X struct TextFont *f;              /* Window font */
X struct RastPort tmprp;           /* RastPort for font-sensitive trick */
X UWORD width,fheight;
X UWORD leftedge,topborder;
X UWORD lvright;
X
X /* Open window font */
X if (!(f=OpenFont(ta))) return(FALSE);
X fheight=f->tf_YSize; /* Font height */
X leftedge=pubsc->WBorLeft;
X topborder=pubsc->WBorTop+fheight+1;
X
X /* Initialize temporary RastPort */
X InitRastPort(&tmprp);
X SetFont(&tmprp,f);
X
X /* Calculate window width */
X ww=TextLength(&tmprp,WindowTitle,strlen(WindowTitle))+WDRAGBARLEN;
X
X /* Create gadget list */
X gl=NULL;
X g=CreateContext(&gl);
X
X /* 1. gadget: Text, status line */
X PrintStatusLine();
X width=TextLength(&tmprp,StatusText,sizeof(StatusText)-1)+INTERWIDTH;
X ng.ng_LeftEdge=leftedge+(ww-width)/2;
X ng.ng_TopEdge=topborder+INTERHEIGHT;
X ng.ng_Width=width;
X ng.ng_Height=fheight;
X ng.ng_GadgetText=StatusText;
X ng.ng_TextAttr=ta;
X ng.ng_Flags=PLACETEXT_IN;
X ng.ng_VisualInfo=vi;
X ng.ng_UserData=0;
X if (!(g=CreateGadget(TEXT_KIND,g,&ng,TAG_DONE))) goto e1;
X g->GadgetText->DrawMode=JAM2; /* Argh, why doesn't exist a tag for this? */
X
X /* 2. gadget: ListView, tool list */
X ng.ng_LeftEdge=leftedge+WDRAGBARLEN/2;
X ng.ng_TopEdge+=g->Height+INTERHEIGHT;
X ng.ng_Width=ww-WDRAGBARLEN;
X ng.ng_Height=7*fheight;
X ng.ng_GadgetText=NULL;
X ng.ng_GadgetID=LVGAD_ID;
X if (!(lvgad=g=CreateGadget(LISTVIEW_KIND,g,&ng,
X                            GTLV_Labels,&ToolList,
X                            /* If an item was selected, use it as top item */
X                            GTLV_Top,lvtop,
X                            GTLV_ShowSelected,NULL,
X                            GTLV_Selected,lvord,
X                            TAG_DONE))) goto e1;
X lvright=ng.ng_LeftEdge+g->Width;
X
X /* 3. gadget: Button, edit tool definition */
X ng.ng_TopEdge+=g->Height+fheight+2*INTERHEIGHT;
X ng.ng_Width=TextLength(&tmprp,ETButtonText,sizeof(ETButtonText)-1)+INTERWIDTH;
X ng.ng_Height=fheight+INTERHEIGHT;
X ng.ng_GadgetText=ETButtonText;
X ng.ng_GadgetID=ETGAD_ID;
X if (!(g=CreateGadget(BUTTON_KIND,g,&ng,TAG_DONE))) goto e1;
X
X /* 4. gadget: Button, remove tool */
X width=TextLength(&tmprp,RTButtonText,sizeof(RTButtonText)-1)+INTERWIDTH;
X ng.ng_LeftEdge=lvright-width;
X ng.ng_Width=width;
X ng.ng_GadgetText=RTButtonText;
X ng.ng_GadgetID=RTGAD_ID;
X if (!(g=CreateGadget(BUTTON_KIND,g,&ng,TAG_DONE))) goto e1;
X
X /* 5. gadget: Button, save config */
X width=TextLength(&tmprp,SCButtonText,sizeof(SCButtonText)-1)+INTERWIDTH;
X ng.ng_LeftEdge=leftedge+(ww-width)/2;
X ng.ng_TopEdge+=g->Height+INTERHEIGHT;
X ng.ng_Width=width;
X ng.ng_GadgetText=SCButtonText;
X ng.ng_GadgetID=SCGAD_ID;
X if (!(g=CreateGadget(BUTTON_KIND,g,&ng,TAG_DONE))) goto e1;
X
X /* Calculate window height */
X wh=ng.ng_TopEdge+g->Height+INTERHEIGHT-topborder;
X
X CloseFont(f);        /* Close window font */
X if (g) return(TRUE); /* All gadgets created! */
X
X /* Something went wrong.... */
Xe1: CloseFont(f);
X    FreeGadgets(gl);
X    return(FALSE);
X}
X
X/* Open status window */
XULONG OpenStatusWindow(void)
X{
X if (!(pubsc=LockPubScreen("Workbench"))) /* Lock Workbench screen */
X  goto osw1;
X
X if (!(vi=GetVisualInfo(pubsc,TAG_DONE))) /* Get visual information */
X  goto osw2;
X
X if (!CreateWindowGadgets())              /* Create Gadgets */
X  goto osw3;
X
X /* Open window */
X if (!(w=OpenWindowTags(&nw,
X                        WA_Left,wl,
X                        WA_Top,wt,
X                        WA_InnerWidth,ww,
X                        WA_InnerHeight,wh,
X                        WA_PubScreen,pubsc,
X                        WA_AutoAdjust,TRUE,
X                        TAG_DONE)))
X  goto osw4;
X
X wp=w->UserPort; /* Retrieve window port */
X
X /* Circumvent an intuition.library bug. See AutoDocs for LockPubScreen() */
X UnlockPubScreen(NULL,pubsc);
X pubsc=NULL;
X
X /* Add gadget list to window */
X AddGList(w,gl,(UWORD) -1,(UWORD) -1,NULL);
X RefreshGList(gl,w,NULL,(UWORD) -1);
X GT_RefreshWindow(w,NULL);
X
X /* Notify Workbench about window */
X if (!(aw=AddAppWindow(NULL,NULL,w,MyMP,TAG_DONE)))
X  goto osw5;
X
X /* Window open! */
X return(1L<<wp->mp_SigBit);
X
X /* Something went wrong.... */
Xosw5: CloseWindow(w);
X      w=NULL;
Xosw4: FreeGadgets(gl);
Xosw3: FreeVisualInfo(vi);
Xosw2: if (pubsc) UnlockPubScreen(NULL,pubsc);
Xosw1: return(0);
X}
X
X/* Refresh status window gadgets */
Xvoid RefreshStatusWindow(void)
X{
X PrintStatusLine();
X RefreshGList(gl,w,NULL,2); /* Refresh only the first two gadgets */
X}
X
X/* Find tool with lvord */
Xstatic struct ToolNode *FindTool(void)
X{
X if (lvord>=0)             /* Is the ordinal number valid? */
X  {                        /* Yes, search tool */
X   struct ToolNode *tn;
X   WORD i=0;               /* Counter */
X
X   /* Scan tool list until the ordinal number is reached */
X   for (tn=GetHead(&ToolList); tn; tn=GetSucc(tn),i++)
X    if (i>=lvord) break;
X
X   return(tn);
X  }
X return(NULL);
X}
X
X/* If the window is open, detach tool list from ListView gadget */
Xvoid DetachToolList(void)
X{
X if (w) GT_SetGadgetAttrs(lvgad,w,NULL,GTLV_Labels,-1,TAG_DONE);
X}
X
X/* If the window is open, attach tool list to ListView gadget */
Xvoid AttachToolList(void)
X{
X if (w) GT_SetGadgetAttrs(lvgad,w,NULL,
X                          GTLV_Labels,&ToolList,
X                          /* If an item was selected, use it as top item */
X                          GTLV_Top,lvtop,
X                          GTLV_Selected,lvord,
X                          TAG_DONE);
X}
X
X/* Handle window events */
XBOOL HandleWindowEvent(void)
X{
X BOOL rc=FALSE;             /* True if window close event */
X struct IntuiMessage *msg;
X struct ToolNode *tn;
X
X while (msg=GT_GetIMsg(wp)) /* Pre-process Intuition messages */
X  {
X   switch (msg->Class)
X    {
X     case INTUITICKS:       /* Intuition tick received */
X      break;
X     case CLOSEWINDOW:      /* User clicked the close gadget */
X      wl=w->LeftEdge;       /* Retreive window parameters for next open */
X      wt=w->TopEdge;
X      rc=TRUE;              /* Yes, close window */
X      break;
X     case REFRESHWINDOW:    /* Window must be refreshed */
X      GT_BeginRefresh(w);
X      GT_EndRefresh(w,TRUE);
X      break;
X     case GADGETUP:         /* User released a gadget */
X      switch(((struct Gadget *) msg->IAddress)->GadgetID)
X       {
X        case LVGAD_ID:      /* User selected a ListView item */
X         lvtop=lvord=msg->Code; /* Retrieve the ordinal number of the item */
X         break;
X        case RTGAD_ID:      /* User selected the remove tool gadget */
X         tn=FindTool();     /* Search tool */
X         if (tn)            /* Tool found? */
X          {
X           lvord=-1;              /* Invalidate ordinal number */
X
X           DetachToolList();      /* Remove tool from list */
X           RemToolNode(tn);
X           AttachToolList();
X
X           RefreshStatusWindow(); /* Refresh Gadgets */
X          }
X         break;
X        case ETGAD_ID:      /* User selected the edit tool definition gadget */
X         tn=FindTool();
X         if (tn)
X          if (EditToolWindow(tn)) DisplayBeep(NULL);
X         break;
X        case SCGAD_ID:      /* User selected the save config gadget */
X         if (WriteConfigFile(w)) DisplayBeep(NULL);
X         break;
X       }
X      break;
X    }
X   GT_ReplyIMsg(msg); /* Reply pre-processed message */
X  }
X
X return rc;
X}
X
X/* Close status window */
Xvoid CloseStatusWindow(void)
X{
X RemoveAppWindow(aw);
X CloseWindow(w);
X w=NULL;
X FreeGadgets(gl);     /* Release allocated resources */
X FreeVisualInfo(vi);
X}
END_OF_FILE
if test 12789 -ne `wc -c <'src/window.c'`; then
    echo shar: \"'src/window.c'\" unpacked with wrong size!
fi
# end of 'src/window.c'
fi
echo shar: End of archive 1 \(of 2\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
Mail comments to the moderator at <amiga-request@uunet.uu.net>.
Post requests for sources, and general discussion to comp.sys.amiga.misc.