home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * wb.c: Workbench interface for MP.
- * Part of MP, the MIDI Playground.
- *
- * Author: Daniel Barrett
- * Version: See the file "version.h".
- * Copyright: None! This program is in the Public Domain.
- * Please share it with others.
- ***************************************************************************/
-
-
- #include "mp.h"
-
-
- #define TOOL_WINDOW "WINDOW"
- #define TOOL_INPUT "INPUTFORMAT"
- #define TOOL_OUTPUT "OUTPUTFORMAT"
- #define TOOL_INFILE "GETFROM"
- #define TOOL_OUTFILE "PUTINTO"
-
-
- struct Library *IconBase = NULL;
- #define ICON_VERSION 33
-
-
- BOOL OpenThings(void);
- void CloseThings(void);
- BOOL ShowTheTools(struct WBArg *wbarg);
- BOOL HandleTools(struct WBArg *wbarg, FLAGS theFlags[], char **infile,
- char **outfile);
- BOOL CheckIOTool(char *toolValue, int flag, FLAGS theFlags[]);
-
- /************************************************************************
- * Workbench interface
- ************************************************************************/
-
- BOOL WorkbenchProgram(char *argv[])
- {
- struct WBStartup *argmsg = (struct WBStartup *)argv;
- struct WBArg *wbarg = argmsg->sm_ArgList;
- BPTR olddir = NULL;
- BOOL success = TRUE;
- FILE *in, *out;
- char *infile, *outfile;
- FLAGS theFlags[NUM_FLAGS];
-
- InitStuff(theFlags, &in, &out, &infile, &outfile);
-
- if (!OpenThings())
- return(FALSE);
-
- if (wbarg->wa_Lock != NULL)
- olddir = CurrentDir(wbarg->wa_Lock);
- else
- olddir = NULL;
-
- if ((success &= HandleTools(wbarg, theFlags, &infile, &outfile))
- && (success &= SetupFiles(infile, outfile, &in, &out)))
- (void)MIDIPlayground(theFlags, in, out);
-
- if (olddir != NULL)
- CurrentDir(olddir);
-
- CloseFiles(in, out, infile, outfile);
- return(success);
- }
-
-
- BOOL OpenThings(void)
- {
- return( (IconBase = OpenLibrary("icon.library", ICON_VERSION))
- ? TRUE
- : FALSE);
- }
-
-
- void CloseThings(void)
- {
- CloseLibrary(IconBase);
- }
-
-
- BOOL HandleTools(struct WBArg *wbarg, FLAGS theFlags[], char **infile,
- char **outfile)
- {
- struct DiskObject *dobj = NULL;
- char **toolarray;
- char *s = NULL;
- BOOL success = TRUE;
-
- if ((wbarg->wa_Name) && (dobj = GetDiskObject(wbarg->wa_Name)))
- {
- toolarray = (char **)dobj->do_ToolTypes;
-
- if (s = (char *)FindToolType(toolarray, TOOL_INPUT))
- {
- success &= CheckIOTool(s, FLAG_ITYPE, theFlags);
- printf("input format=%s\n", s);
- }
-
- if (s = (char *)FindToolType(toolarray, TOOL_OUTPUT))
- {
- success &= CheckIOTool(s, FLAG_OTYPE, theFlags);
- printf("output format=%s\n", s);
- }
-
- if (s = (char *)FindToolType(toolarray, TOOL_INFILE))
- {
- success &= MakeFilename(infile, s);
- printf("input file=%s\n", s);
- }
-
- if (s = (char *)FindToolType(toolarray, TOOL_OUTFILE))
- {
- success &= MakeFilename(outfile, s);
- printf("output file=%s\n", s);
- }
-
- FreeDiskObject(dobj);
- return(success && CheckFlags(theFlags));
- }
- else
- return(FALSE);
- }
-
-
- /* A tooltype value is legal if it starts with the correct letter; case
- * insensitive. */
-
- BOOL CheckIOTool(char *toolValue, int flag, FLAGS theFlags[])
- {
- return(IsIOType(theFlags[flag] = tolower(*toolValue)));
- }
-