home *** CD-ROM | disk | FTP | other *** search
- #include <Files.h>
- #include <Types.h>
- #include <errno.h>
- #include <string.h>
- #include "ui.h"
-
- #if defined(__MWERKS__) || defined(THINK_C)
- #include <stdio.h>
- #include "os_mac_str.h"
- #include <LowMem.h>
- #ifndef ENOENT
- #define ENOENT ERANGE
- #endif
- #endif
-
- #if ui_eventcheck_profiling_P
-
- /* 17Jan95 e - to find good value for PERIODIC_ACTION_FREQ */
-
- /* see interp.c for use of ui_periodic_action */
-
- int ui_period_counts = 4096;
-
- #define UI_PERIOD_COUNT_UNIT 128
- #define MIN_UI_PERIOD_COUNT 256
- #define MAX_UI_PERIOD_COUNT 262144
-
- void ui_periodic_action(void)
- { /* looks like MAYBE_EVENTCHK() but tunes ui_period_counts */
- long ticks = LMGetTicks();
- if ( ticks >= next_eventchk_ticks )
- { if ( ticks > (next_eventchk_ticks + 2) && ui_period_counts > MIN_UI_PERIOD_COUNT )
- ui_period_counts -= UI_PERIOD_COUNT_UNIT;
- os_event_check();
- }
- else if ( ui_period_counts < MAX_UI_PERIOD_COUNT )
- ui_period_counts += UI_PERIOD_COUNT_UNIT;
- }
-
- #endif
-
- #if defined( __MWERKS__ )
-
- #undef chdir
-
- int e_chdir(char *dirname)
- {
- unsigned char buf [256];
- short vrefnum;
- long dirid;
- HGetVol( NULL, &vrefnum, &dirid );
- c_to_p (dirname, buf);
- // MSL broken, was: chdir(dirname); // for MWERKS & std file dialog
- return HSetVol( buf, vrefnum, dirid ); // for mosml
- }
-
- #else
-
- /* from Caml Light Mac 0.6 */
-
- static short prev_wd = 0;
-
- int chdir(char * dirname)
- {
- unsigned char buf [256];
- WDPBRec paramblock;
-
- if (prev_wd != 0){
- paramblock.ioCompletion = NULL;
- paramblock.ioVRefNum = prev_wd;
- PBCloseWD (¶mblock, 0);
- }
-
- #if defined( THINK_C ) || defined( __MWERKS__ )
- if ( strlen(dirname) > 255 ) { errno = EDOM; return -1; }
- #ifdef __MWERKS__
- c_to_p (dirname, buf);
- #else
- __c2p (dirname, buf);
- #endif
- #else
- strncpy (buf, dirname, 255);
- buf [255] = 0;
- c2pstr (buf);
- #endif
- paramblock.ioCompletion = NULL;
- #if defined( THINK_C ) || defined( __MWERKS__ )
- paramblock.ioNamePtr = (unsigned char *)buf;
- #else
- paramblock.ioNamePtr = buf;
- #endif
- paramblock.ioVRefNum = 0;
- paramblock.ioWDProcID = 'Caml';
- paramblock.ioWDDirID = 0;
- if (PBOpenWD (¶mblock, 0) != noErr){
- errno = ENOENT;
- return -1;
- }
- prev_wd = paramblock.ioVRefNum;
-
- paramblock.ioCompletion = NULL;
- paramblock.ioNamePtr = NULL;
- paramblock.ioVRefNum = prev_wd;
- paramblock.ioWDDirID = 0;
- if (PBSetVol ((ParmBlkPtr) ¶mblock, 0) != noErr){
- errno = ENOENT;
- return -1;
- }
- return 0;
- }
-
- #endif
-
- char * searchpath(char * name)
- {
- return name;
- }
-
- void set_file_type (char * name, long type)
- {
- Str255 pname;
- FInfo info;
-
- c_to_p( name, pname );
- GetFInfo (pname, 0, &info);
- info.fdType = type;
- SetFInfo (pname, 0, &info);
- }
-
- #if defined(THINK_C) || defined(__MWERKS__)
-
- /* 04Jan95 e */
- static char *
- strcatbut( char *s1, char *s2 )
- { char c, *last_dot = 0;
- while ( *s1 != 0 ) s1++;
- do
- switch ( c = *s2++ )
- { case '.':
- if ( *s2 == '.' )
- { s2++; /* skip '..' */
- if ( *s2 )
- continue; /* '..' becomes '' */
- else
- c = ':'; /* final '..' becomes ':' */
- }
- else if ( *s2 == '/' ) { s2++; continue; } /* skip './' */
- else if ( *s2 == 0 ) return last_dot; /* drop final '.' */
- else last_dot = s2 - 1;
- break;
- case '/':
- c = ':'; /* '/' becomes ':' */
- break;
- }
- while ( *s1++ = c );
- return last_dot;
- }
-
- #ifdef THINK_C
-
- char *
- unix_to_mac_filename (char *name, char *buffer, int buffer_len)
- {
- int name_len = strlen(name);
- /* unix name to mac name -- 11Aug93 e */
- if ( ( 1 + name_len ) > buffer_len )
- { fprintf(stderr, "\nexpand_file_name: supplied buffer is too small\n");
- return(NULL);
- }
- if ( strchr( name, ':' ) )
- strcpy( buffer, name );
- else
- { if ( *name == '/' ) { *buffer = 0; name++; }
- else strcpy( buffer, ":" );
- strcatbut( buffer, name );
- }
- return(buffer);
- }
-
- #else
-
- // 14Sep95 -- didn't work well with Metrowerks' open() & SFdialog
-
- static void setMWcurdir( void )
- {
- long cur_dir;
- short cur_vol;
- HGetVol( NULL, &cur_vol, &cur_dir );
- LMSetCurDirStore( cur_dir );
- LMSetSFSaveDisk( - cur_vol );
- }
-
- char *
- unix_to_mac_filename (char *name, char *buffer, int buffer_len)
- {
- char *posn;
- int name_len;
- /* unix name to mac name -- 11Aug93 e */
- if ( (posn = strchr( name, '/' )) != NULL )
- { name_len = strlen(name);
- if ( ( 1 + name_len ) > buffer_len )
- { fprintf(stderr, "\nexpand_file_name: supplied buffer is too small\n");
- return(NULL);
- }
- if ( posn == name ) { *buffer = 0; name++; }
- else { strcpy( buffer, ":" ); setMWcurdir(); }
- strcatbut( buffer, name );
- return buffer;
- }
- else
- {
- if ( *name == ':' ) setMWcurdir();
- return name;
- }
- }
-
- #endif
-
- #endif
-