home *** CD-ROM | disk | FTP | other *** search
- #include <Dialogs.h>
- #include <Events.h>
- #include <Files.h>
- #include <Stdlib.h>
- #include <Types.h>
- #include <Resources.h>
- #include <console.h>
- #include "ui.h"
-
- #if defined( THINK_C ) || defined ( __MWERKS__ )
- #include <stdio.h>
- #include <string.h>
- #include <strings.h>
- #include "os_mac_eventchk.h"
- #ifdef THINK_C
- #include <fcntl.h>
- #include <stat.h>
- #else
- #include <unix.h>
- #endif
- #endif
-
- void CenterRect(Rect *r)
- {
- short d;
- Rect *bounds;
-
- bounds = &qd.screenBits.bounds;
- d = r->right - r->left;
- r->left = bounds->left + (bounds->right - bounds->left - d) / 2;
- r->right = r->left + d;
- d = r->bottom - r->top;
- r->top = bounds->top + (bounds->bottom - bounds->top - d) / 3;
- r->bottom = r->top + d;
- }
-
- void eDoDialog(int sel)
- {
- Handle h = GetResource('ALRT', 1025);
- CenterRect((Rect *) *h);
- Alert(1025, nil);
- }
-
- char *get_wd_name (short wd_refnum, char *postfix)
- {
- #if defined( THINK_C ) || defined( __MWERKS__ )
- unsigned char buf [64];
- #else
- char buf [64];
- #endif
- char *temp, *result;
- DirInfo cinfo;
- WDPBRec wd;
-
- wd.ioCompletion = NULL;
- wd.ioNamePtr = NULL;
- wd.ioVRefNum = wd_refnum;
- wd.ioWDIndex = 0;
- wd.ioWDProcID = 0;
- wd.ioWDVRefNum = 0;
- if (PBGetWDInfo (&wd, 0) != noErr) return postfix;
- cinfo.ioDrParID = wd.ioWDDirID;
- result = malloc (strlen (postfix) + 1);
- if (result == NULL) return postfix;
- strcpy (result, postfix);
- do{
- cinfo.ioCompletion = NULL;
- cinfo.ioNamePtr = buf;
- cinfo.ioVRefNum = wd.ioWDVRefNum;
- cinfo.ioFDirIndex = -1;
- cinfo.ioDrDirID = cinfo.ioDrParID;
- if (PBGetCatInfo ((CInfoPBPtr) &cinfo, 0) != noErr) return postfix;
- #ifdef THINK_C
- temp = malloc (strlen (result) + buf[0] + 2);
- #else
- p2cstr (buf);
- temp = malloc (strlen (result) + strlen ((char *)buf) + 2);
- #endif
- if (temp == NULL){
- free (result);
- return postfix;
- }
- #ifdef THINK_C
- sprintf (temp, ":%#s%s", buf, result);
- #else
- sprintf (temp, ":%s%s", buf, result);
- #endif
- free (result);
- result = temp;
- }while (cinfo.ioDrDirID != 2);
- return result + 1;
- }
-
- extern int sub_main (int argc, char *argv []);
-
- extern unsigned char *console_title;
-
- /* CAMLRUN 10Jan95 e
- 0 for a command line interface to load any Caml link'd file
- 1 to load image named in string resource
- */
-
- #define CAMLRUN 1
-
- #ifdef THINK_C
- extern WindowPeek cflush(FILE *fp);
- #endif
-
- main ()
- {
- int argc, fd;
- char **argv;
- WDPBRec wd;
- char *args[6];
- KeyMap kMap;
- long len;
- Str255 pstr;
-
- if ( GetApplLimit() > ( LMGetCurStackBase() - 40000 ) )
- { SetApplLimit ( LMGetCurStackBase() - 40000 );
- }
-
- /* 10Jan95 e -- data fork is now PPC code...
- char apname[32];
- unsigned char *CurApName = LMGetCurApName();
- memcpy(apname,((char *)CurApName + 1),*((char *)CurApName));
- apname[*((char *)CurApName)] = 0;
- */
-
- #if CAMLRUN
-
- wd.ioCompletion = NULL;
- wd.ioNamePtr = NULL;
- PBHGetVol ( &wd, 0 );
-
- /* arg 0 */
- GetIndString(pstr, 357, 1); /* image name */
- p2cstr(pstr);
- args[0] = get_wd_name( wd.ioVRefNum, (char *)pstr );
- fd = open( args[0], O_RDONLY | O_BINARY);
- if (fd != -1){
- len = lseek( fd, 0, SEEK_END );
- close( fd );
- GetKeys( kMap );
- // fd = ((len < 12000) || (kMap[1] & 4)) ? -1 : 0; -- option key
- fd = ((len < 1200) || (kMap[1] & 32768L)) ? -1 : 0;
- } /* probe image, insure big enough, command key for command line */
-
- /* arg 1 */
- args[1] = "-stdlib";
-
- /* arg 2 */
- GetIndString(pstr, 357, 2); /* stdlib directory name */
- p2cstr(pstr);
- args[2] = get_wd_name( wd.ioVRefNum, (char *)pstr );
-
- argc = 3;
-
- /* optional arg 3 */
- GetIndString(pstr, 357, 3); /* options, e.g., -P */
- if ( pstr[0] != 0 )
- {
- args[3] = malloc( pstr[0] );
- if( args[3] != NULL )
- { argc = 4;
- p_to_c( pstr, args[3] );
- /* optional arg 4 */
- GetIndString(pstr, 357, 4); /* options, e.g., {full,none,etc.} */
- if ( pstr[0] != 0 )
- {
- args[4] = malloc( pstr[0] );
- if( args[4] != NULL )
- { argc = 5;
- p_to_c( pstr, args[4] );
- }
- }
- }
- }
-
- #else
-
- fd = -1;
-
- #endif
-
- GetIndString(pstr, 357, 5); /* console title */
- if ( pstr[0] == 0 )
- console_title = "\pMosml Console";
- else
- console_title = pstr;
-
- if ( fd != -1 )
- {
- argv = args;
- argv[argc] = NULL;
- #ifdef THINK_C
- cflush(stdin);
- #else
- puts(" ");
- fflush(stdout);
- #endif
- }
- else
- {
- if ( 1 /* kMap[1] & 1 */ ) // shift key
- {
- fputs(args[0],stdout);
- fputs(" ",stdout);
- fputs(args[1],stdout);
- fputs(" ",stdout);
- fputs(args[2],stdout);
- fputs(" ",stdout);
- fputs(args[3],stdout);
- fputs(" ",stdout);
- puts(args[4]);
- }
- argc = ecommand( (unsigned char ***)&argv );
- }
-
- init_timers();
-
- return caml_main (argc, argv);
- }
-
- // end of uio.c
-