diff --git a/src/check_structs.c b/src/check_structs.c new file mode 100644 index 0000000..177157a --- /dev/null +++ b/src/check_structs.c @@ -0,0 +1,517 @@ +#include +#include + +#include + +#if defined(USE_VDRIVER_H) +# include +#endif + +#include +#include +#include + +#include + +#define check(type, expected_size) \ + do { \ + if (sizeof(type) != expected_size) \ + fprintf(stderr, "Expected sizeof(" #type ") to be %zu, got %zu\n", \ + (size_t) expected_size, sizeof(type)); \ + } while (false) + +void check_structs(void) +{ + check(VBLTask, 14); /* VRetraceMgr.h */ + +#if defined(USE_VDRIVER_H) + check (VDParamBlock, TODO); /* VDriver.h */ + check (VDEntryRecord, TODO); + check (VDGammaRecord, TODO); + check (VDPgInfo, TODO); + check (VDFlagRec, TODO); + check (VDDefModeRec, TODO); +#endif /* defined(USE_VDRIVER_H) */ + + check (HMStringResType, 4); /* HelpMgr.h */ + check (HMMessageRecord, 258); + + check (ProcessSerialNumber, 8); /* ProcessMgr.h */ + check (LaunchParamBlockRec, 44); + check (ProcessInfoRec, 60); + + check (SndCommand, 8); /* SoundMgr.h */ + check (SndChannel, 1060); + check (SoundHeader, 22); + check (ExtSoundHeader, 0); /* FIXME */ + check (SndDoubleBuffer, 16); + check (SndDoubleBufferHeader, 24); + check (SCStatus, 0); /* FIXME */ + + check(fcbrec, 94); /* rsys/file.h */ +} + +#if false + +TODO: These .c files have structs that refer to Mac memory and should + be size checked + +./font.c:267:typedef struct { +./segment.c:66:typedef struct { +./resOpen.c:31: struct { /* empty resource template */ +./ctlMouse.c:72:typedef struct { +./icon.c:352:typedef struct +./ctlInit.c:110:typedef struct { +./menu.c:224:typedef struct mct_res +./menu.c:738:typedef struct { +./menu.c:806:typedef struct { +./mkvol/mkvol.c:487: typedef struct +./mkvol/mkvol.c:505: typedef struct +./mkvol/mkvol.c:519: static struct +./stdmdef.c:45:typedef struct +./ctlArrows.c:698:struct lsastr +./qCGrafPort.c:420:struct pixpat_res +./fileDouble.c:50:PRIVATE struct defaulthead { +./fileDouble.c:115:PRIVATE struct defaultentries { +./screen-dump.c:60:struct header +./screen-dump.c:67:struct directory_entry +./screen-dump.c:75:struct ifd +./windInit.c:550:typedef struct { +./process.c:28:typedef struct size_resource +./syserr.c:36:PRIVATE struct { +./syserr.c:165:struct adef { +./syserr.c:175:struct tdef { +./syserr.c:182:struct idef { +./syserr.c:189:struct pdef { +./syserr.c:196:struct bdef { +./syserr.c:200: struct but { +./syserr.c:207:struct sdef { +./launch.c:375:typedef struct { +./qCursor.c:221:typedef struct ccrsr_res +./dialAlert.c:29:static struct +./toolevent.c:160:typedef struct { +./alias.c:384:typedef struct +./alias.c:404:typedef struct /* 0x0000 */ +./alias.c:411:typedef struct /* 0x0001 */ +./alias.c:418:typedef struct /* 0x0002 */ +./alias.c:425:typedef struct /* 0x0009 */ +./alias.c:437:typedef struct +./resMod.c:332:typedef struct { +./fileVolumes.c:69:typedef struct { +./fileVolumes.c:76:typedef struct { +./emustubs.c:229:typedef struct +./emustubs.c:1783:typedef struct comm_toolbox_dispatch_args +./emustubs.c:2604:typedef struct +./AE_desc.c:29:typedef struct +./AE_desc.c:36:typedef struct +./AE_desc.c:44:typedef struct list_header +./AE_desc.c:82:typedef struct ae_header +./serial.c:128: struct { + +These .h files have structs that should be size checked + +./mkvol/mkvol_internal.h:80:typedef struct { +./mkvol/mkvol_internal.h:89:typedef struct { +./mkvol/mkvol_internal.h:98:typedef struct { +./mkvol/mkvol_internal.h:103:typedef struct { +./mkvol/mkvol_internal.h:136:typedef struct { +./mkvol/mkvol_internal.h:147:typedef struct { +./mkvol/mkvol_internal.h:154:typedef struct { +./mkvol/mkvol_internal.h:169:typedef struct { +./mkvol/mkvol_internal.h:194:typedef struct { +./mkvol/mkvol_internal.h:210:typedef struct { +./mkvol/mkvol_internal.h:224:typedef struct { +./config/arch/powerpc/ppc_stubs.h:11:typedef struct +./config/arch/powerpc/ppc_stubs.h:18:typedef struct +./config/arch/powerpc/ppc_stubs.h:25:typedef struct +./config/arch/powerpc/ppc_stubs.h:34:typedef struct +./config/arch/powerpc/ppc_stubs.h:41:typedef struct +./config/arch/powerpc/ppc_stubs.h:48:typedef struct +./config/arch/powerpc/ppc_stubs.h:55:typedef struct +./config/arch/powerpc/ppc_stubs.h:62:typedef struct +./config/arch/powerpc/ppc_stubs.h:69:typedef struct +./config/arch/powerpc/ppc_stubs.h:76:typedef struct +./config/arch/powerpc/ppc_stubs.h:84:typedef struct + +./include/VRetraceMgr.h:14:typedef struct { +./include/VDriver.h:13:typedef struct +./include/VDriver.h:24:typedef struct +./include/VDriver.h:34:typedef struct +./include/VDriver.h:42:typedef struct +./include/VDriver.h:53:typedef struct +./include/VDriver.h:61:typedef struct +./include/HelpMgr.h:15:typedef struct HMStringResType +./include/HelpMgr.h:21:typedef struct HMMessageRecord +./include/ProcessMgr.h:16:typedef struct ProcessSerialNumber +./include/ProcessMgr.h:32:typedef struct +./include/ProcessMgr.h:44:typedef struct +./include/ProcessMgr.h:70:typedef struct ProcessInfoRec +./include/SoundMgr.h:13:typedef struct { +./include/SoundMgr.h:28:typedef struct _SndChannel { +./include/SoundMgr.h:77:typedef struct { +./include/SoundMgr.h:87:typedef struct _SoundHeader { +./include/SoundMgr.h:98:typedef struct _ExtSoundHeader { +./include/SoundMgr.h:145:typedef struct +./include/SoundMgr.h:158:typedef struct +./include/SoundMgr.h:169:typedef struct _SCSTATUS { +./include/FileMgr.h:73:typedef struct { +./include/FileMgr.h:81:typedef struct { +./include/FileMgr.h:88:typedef struct { +./include/FileMgr.h:95:typedef struct { +./include/FileMgr.h:120:typedef struct { +./include/FileMgr.h:133:typedef struct { +./include/FileMgr.h:153:typedef struct { +./include/FileMgr.h:171:typedef struct { +./include/FileMgr.h:186:typedef struct { +./include/FileMgr.h:199:typedef struct { +./include/FileMgr.h:219:typedef struct { +./include/FileMgr.h:265:typedef struct { +./include/FileMgr.h:283:typedef struct { +./include/FileMgr.h:302:typedef struct { +./include/FileMgr.h:313:typedef struct { +./include/FileMgr.h:324:typedef struct { +./include/FileMgr.h:342:typedef struct { +./include/FileMgr.h:393:typedef struct { +./include/FileMgr.h:406:struct FSSpec +./include/MacTypes.h:58:typedef struct { +./include/MacTypes.h:71:typedef struct Point +./include/MacTypes.h:81:typedef struct Rect +./include/WindowMgr.h:81:struct __wr { +./include/WindowMgr.h:101:typedef struct { +./include/WindowMgr.h:117:typedef struct AuxWinRec { +./include/PPC.h:13:typedef struct EntityName +./include/PPC.h:18:typedef struct LocationNameRec +./include/PPC.h:29:typedef struct PPCPortRec +./include/PPC.h:39: struct +./include/FontMgr.h:54:typedef struct { +./include/FontMgr.h:62:typedef struct { +./include/FontMgr.h:83:typedef struct { +./include/FontMgr.h:107:typedef struct { +./include/FontMgr.h:117:typedef struct { +./include/FontMgr.h:138:typedef struct { +./include/DeviceMgr.h:21:typedef struct { +./include/DeviceMgr.h:30:typedef struct { +./include/DeviceMgr.h:49:typedef struct { +./include/DeviceMgr.h:92:typedef struct { +./include/StartMgr.h:13: struct { +./include/StartMgr.h:19: struct { +./include/StartMgr.h:26:typedef struct { +./include/StartMgr.h:31:typedef struct { +./include/Serial.h:70:typedef struct { +./include/Serial.h:81:typedef struct { +./include/ScrapMgr.h:16:typedef struct { +./include/CQuickDraw.h:7:typedef struct +./include/CQuickDraw.h:17:typedef struct +./include/CQuickDraw.h:37:typedef struct SProcRec +./include/CQuickDraw.h:45:typedef struct CProcRec +./include/CQuickDraw.h:53:typedef struct GDevice +./include/CQuickDraw.h:82:typedef struct ColorInfo +./include/CQuickDraw.h:91:typedef struct Palette +./include/CQuickDraw.h:147:typedef struct ReqListRec +./include/CQuickDraw.h:155:typedef struct OpenCPicParams +./include/CQuickDraw.h:165:typedef struct CommonSpec +./include/CQuickDraw.h:175:typedef struct FontSpec +./include/CQuickDraw.h:188:typedef struct PictInfo +./include/OSUtil.h:27:typedef struct { +./include/OSUtil.h:53:typedef struct { +./include/OSUtil.h:63:typedef struct { +./include/Components.h:11:typedef struct ComponentRecord +./include/Components.h:19:typedef struct ComponentInstanceRecord +./include/QuickTime.h:15:typedef struct MovieRecord +./include/AppleEvents.h:19:typedef struct AEDesc +./include/AppleEvents.h:34:typedef struct AEKeyDesc +./include/AppleEvents.h:115:typedef struct AE_hdlr +./include/AppleEvents.h:121:typedef struct AE_hdlr_selector +./include/AppleEvents.h:127:typedef struct AE_hdlr_table_elt +./include/AppleEvents.h:148:typedef struct AE_hdlr_table +./include/AppleEvents.h:164:typedef struct AE_zone_tables +./include/AppleEvents.h:185:typedef struct AE_info +./include/MemoryMgr.h:27:typedef struct Zone +./include/Disk.h:36:typedef struct { +./include/ADB.h:11:typedef struct +./include/ADB.h:19:typedef struct +./include/ToolboxUtil.h:21:typedef struct { +./include/CommTool.h:11:typedef struct +./include/CommTool.h:35:typedef struct +./include/OSEvent.h:18:typedef struct { +./include/OSEvent.h:58:typedef struct size_info +./include/OSEvent.h:98:typedef struct TargetID +./include/OSEvent.h:106:typedef struct HighLevelEventMsg +./include/DialogMgr.h:33:typedef struct +./include/DialogMgr.h:63:typedef struct +./include/DialogMgr.h:80:typedef struct { +./include/DialogMgr.h:95:typedef struct { +./include/NotifyMgr.h:11:typedef struct { +./include/SegmentLdr.h:21:typedef struct { +./include/ScriptMgr.h:99:typedef struct DateCacheRec +./include/ScriptMgr.h:104:typedef struct LongDateRec +./include/ScriptMgr.h:133:typedef struct +./include/ScriptMgr.h:148:typedef struct +./include/ScriptMgr.h:155:typedef struct +./include/ScriptMgr.h:175:typedef struct +./include/SoundDvr.h:17:typedef struct { +./include/SoundDvr.h:24:typedef struct { +./include/SoundDvr.h:31:typedef struct { +./include/SoundDvr.h:46:typedef struct { +./include/SoundDvr.h:64:typedef struct { +./include/Iconutil.h:98:typedef struct CIcon +./include/ControlMgr.h:87:struct __cr { +./include/ControlMgr.h:103:typedef struct { +./include/ControlMgr.h:117:typedef struct AuxCtlRec { +./include/IntlUtil.h:57:typedef struct { +./include/IntlUtil.h:90:typedef struct { +./include/SANE.h:14: struct { +./include/SANE.h:25: struct { +./include/SANE.h:37:typedef struct { +./include/SANE.h:41: struct { /* Here for added efficiency when BIGENDIAN. */ +./include/SANE.h:51: struct { +./include/SANE.h:68:typedef struct { +./include/SANE.h:77:typedef struct { +./include/SANE.h:93:typedef struct { +./include/StdFilePkg.h:31:typedef struct { +./include/StdFilePkg.h:47:typedef struct +./include/TimeMgr.h:12:typedef struct { +./include/TextEdit.h:53:typedef struct { +./include/TextEdit.h:92:typedef struct { +./include/TextEdit.h:97:typedef struct { +./include/TextEdit.h:113:typedef struct { +./include/TextEdit.h:123:typedef struct { +./include/TextEdit.h:131:typedef struct { +./include/TextEdit.h:144:typedef struct { +./include/TextEdit.h:153:typedef struct { +./include/TextEdit.h:162:typedef struct { +./include/Finder.h:11:typedef struct +./include/EditionMgr.h:16:typedef struct type ## Record type ## Record; \ +./include/EditionMgr.h:22:typedef struct type type; \ +./include/EditionMgr.h:38:struct SectionRecord +./include/EditionMgr.h:56:struct EditionContainerSpec +./include/EditionMgr.h:68:struct EditionInfoRecord +./include/EditionMgr.h:80:struct NewPublisherReply +./include/EditionMgr.h:94:struct NewSubscriberReply +./include/EditionMgr.h:104:struct SectionOptionsReply +./include/EditionMgr.h:123:struct EditionOpenerParamBlock +./include/EditionMgr.h:145:struct FormatIOParamBlock +./include/MenuMgr.h:23:typedef struct { +./include/MenuMgr.h:35:typedef struct MCEntry +./include/OLDSANE.h:11:typedef struct { +./include/OLDSANE.h:16:typedef struct { +./include/OLDSANE.h:22:typedef struct { +./include/OLDSANE.h:29:typedef struct { +./include/OLDSANE.h:44:typedef struct { +./include/PrintMgr.h:40:typedef struct { +./include/PrintMgr.h:49:typedef struct { +./include/PrintMgr.h:58:typedef struct { +./include/PrintMgr.h:67:typedef struct { +./include/PrintMgr.h:81:typedef struct { +./include/PrintMgr.h:94:typedef struct { +./include/PrintMgr.h:110:typedef struct { +./include/PrintMgr.h:124:typedef struct { +./include/ListMgr.h:26:typedef struct { +./include/QuickDraw.h:71:typedef struct { +./include/QuickDraw.h:81:typedef struct { +./include/QuickDraw.h:90:typedef struct { +./include/QuickDraw.h:107:typedef struct { +./include/QuickDraw.h:117:typedef struct { +./include/QuickDraw.h:124:typedef struct { +./include/QuickDraw.h:146:typedef struct { +./include/QuickDraw.h:178:typedef struct { +./include/QuickDraw.h:187:typedef struct { +./include/QuickDraw.h:205:typedef struct { +./include/QuickDraw.h:211:typedef struct { +./include/QuickDraw.h:217:typedef struct { +./include/QuickDraw.h:223:typedef struct { +./include/QuickDraw.h:229:typedef struct ColorSpec +./include/QuickDraw.h:237:typedef struct { +./include/QuickDraw.h:248:typedef struct { +./include/QuickDraw.h:271:typedef struct { +./include/QuickDraw.h:301:typedef struct { +./include/QuickDraw.h:314:typedef struct { +./include/QuickDraw.h:351:typedef struct { +./include/QuickDraw.h:367:typedef struct { +./include/EventMgr.h:66:typedef struct { + +These .h files may have structs that need to be size checked + +./include/rsys/common.h:50:typedef struct +./include/rsys/stdbits.h:4:struct cleanup_info +./include/rsys/file.h:27:typedef struct { +./include/rsys/file.h:34:typedef struct { +./include/rsys/file.h:70:typedef struct { +./include/rsys/file.h:92:typedef struct { +./include/rsys/file.h:99:typedef struct { /* add new elements to the beginning of this struct */ +./include/rsys/file.h:197:typedef struct hashlink_str { +./include/rsys/file.h:204:typedef struct { +./include/rsys/file.h:211: struct { +./include/rsys/file.h:251:typedef struct +./include/rsys/float.h:57: struct { +./include/rsys/float.h:69:typedef struct { +./include/rsys/float.h:77:typedef struct { +./include/rsys/float.h:98: struct { +./include/rsys/tempalloc.h:44:typedef struct +./include/rsys/hfs_plus.h:27:typedef struct HFSUniStr255 +./include/rsys/hfs_plus.h:40:typedef struct HFSPlusPermissions +./include/rsys/hfs_plus.h:49:typedef struct HFSPlusExtentDescriptor +./include/rsys/hfs_plus.h:58:typedef struct HFSPlusForkData +./include/rsys/hfs_plus.h:67:typedef struct HFSPlusVolumeHeader +./include/rsys/hfs_plus.h:98:typedef struct BTNodeDescriptor +./include/rsys/hfs_plus.h:109:typedef struct BTHeaderRec +./include/rsys/hfs_plus.h:129:typedef struct HFSPlusCatalogKey +./include/rsys/hfs_plus.h:137:typedef struct HFSPlusCatalogFolder +./include/rsys/hfs_plus.h:156:typedef struct HFSPlusCatalogFile +./include/rsys/hfs_plus.h:177:typedef struct HFSPlusCatalogThread +./include/rsys/hfs_plus.h:186:typedef struct HFSPlusExtentKey +./include/rsys/hfs_plus.h:196:typedef struct HFSPlusAttrForkData +./include/rsys/hfs_plus.h:204:typedef struct HFSPlusAttrExtents +./include/rsys/commonevt.h:11:typedef struct { +./include/rsys/mactype.h:21:typedef struct { int32 l PACKED; } HIDDEN_LONGINT; +./include/rsys/mactype.h:22:typedef struct { uint32 u PACKED; } HIDDEN_ULONGINT; +./include/rsys/ini.h:15:typedef struct pair_link_str +./include/rsys/options.h:11:typedef struct { +./include/rsys/int386.h:8: struct +./include/rsys/int386.h:12: struct +./include/rsys/int386.h:22: struct +./include/rsys/itm.h:13:typedef struct { +./include/rsys/itm.h:55:typedef struct { +./include/rsys/itm.h:65:typedef struct +./include/rsys/itm.h:81:typedef struct item_style_info +./include/rsys/itm.h:92:typedef struct item_color_info +./include/rsys/print.h:83:typedef struct +./include/rsys/print.h:91:typedef struct +./include/rsys/print.h:98:typedef struct +./include/rsys/print.h:105:typedef struct +./include/rsys/print.h:118:typedef struct +./include/rsys/print.h:129:typedef struct +./include/rsys/print.h:168:typedef struct +./include/rsys/gworld.h:4:typedef struct gw_info +./include/rsys/mixed_mode.h:33:typedef struct RoutineRecord +./include/rsys/mixed_mode.h:45:typedef struct RoutineDescriptor +./include/rsys/mman_private.h:15:typedef struct block_header +./include/rsys/mman_private.h:186:typedef struct +./include/rsys/vgavdriver.h:6:typedef struct +./include/rsys/keyboard.h:15:typedef struct +./include/rsys/keyboard.h:21:typedef struct +./include/rsys/keyboard.h:32:typedef struct +./include/rsys/keyboard.h:56:typedef struct +./include/rsys/menu.h:32:typedef struct { +./include/rsys/menu.h:75:typedef struct { +./include/rsys/menu.h:80:typedef struct menu_elt +./include/rsys/menu.h:115:typedef struct menu_list +./include/rsys/menu.h:128:typedef struct { +./include/rsys/menu.h:160:typedef struct { /* from MPW Private.a */ +./include/rsys/menu.h:174:typedef struct { +./include/rsys/menu.h:242:typedef struct icon_info +./include/rsys/sounddriver.h:6:struct _sound_driver_t +./include/rsys/font.h:8:typedef struct { +./include/rsys/fauxdbm.h:6:typedef struct +./include/rsys/blockdev.h:4:typedef struct _blockdev_t +./include/rsys/resource.h:18:typedef struct { +./include/rsys/resource.h:25:typedef struct { +./include/rsys/resource.h:30:typedef struct { +./include/rsys/resource.h:55:typedef struct { +./include/rsys/resource.h:61:typedef struct { +./include/rsys/resource.h:193:typedef struct +./include/rsys/cquick.h:14:typedef struct GrafVars +./include/rsys/cquick.h:564:typedef struct draw_state +./include/rsys/cquick.h:585:extern struct qd_color_elt +./include/rsys/cquick.h:591:typedef struct write_back_data +./include/rsys/depthconv.h:73:typedef struct +./include/rsys/depthconv.h:81:typedef struct +./include/rsys/newvga.h:13:typedef struct +./include/rsys/newvga.h:42:typedef struct +./include/rsys/newvga.h:52:typedef struct +./include/rsys/newvga.h:82:typedef struct +./include/rsys/newvga.h:87:typedef struct +./include/rsys/licensetext.h:4:typedef struct +./include/rsys/partition.h:15:typedef struct { +./include/rsys/partition.h:43:typedef struct { +./include/rsys/partition.h:51:typedef struct { +./include/rsys/mmanstubs.h:55: struct { +./include/rsys/pef.h:13:typedef struct PEFContainerHeader +./include/rsys/pef.h:59:typedef struct PEFSectionHeader +./include/rsys/pef.h:93:typedef struct PEFLoaderInfoHeader +./include/rsys/pef.h:154:typedef struct PEFImportedLibrary +./include/rsys/pef.h:174:typedef struct PEFLoaderRelocationHeader +./include/rsys/pef.h:214:typedef struct PEFExportedSymbol +./include/rsys/pef.h:248:typedef struct pef_hash +./include/rsys/hfs.h:42:typedef struct { +./include/rsys/hfs.h:47:typedef struct { +./include/rsys/hfs.h:87:typedef struct { +./include/rsys/hfs.h:98:typedef struct { +./include/rsys/hfs.h:105:typedef struct { +./include/rsys/hfs.h:120:typedef struct { +./include/rsys/hfs.h:145:typedef struct { +./include/rsys/hfs.h:161:typedef struct { +./include/rsys/hfs.h:179:typedef struct { +./include/rsys/hfs.h:212:typedef struct { +./include/rsys/hfs.h:254:typedef struct _cacheentry { +./include/rsys/hfs.h:271:typedef struct { +./include/rsys/hfs.h:282:typedef struct { +./include/rsys/hfs.h:295:typedef struct { +./include/rsys/hfs.h:306:typedef struct { /* from MPW equates */ +./include/rsys/custom.h:44:typedef struct +./include/rsys/custom.h:51:typedef struct +./include/rsys/custom.h:59:typedef struct +./include/rsys/custom.h:66:typedef struct +./include/rsys/custom.h:73:typedef struct +./include/rsys/xdata.h:9:typedef struct +./include/rsys/xdata.h:20:typedef struct _xdata_t +./include/rsys/rawblt.h:4:typedef struct +./include/rsys/keycode.h:13:typedef struct +./include/rsys/splash.h:4:struct splash_screen_rect +./include/rsys/splash.h:12:struct splash_screen_header +./include/rsys/splash.h:36: struct splash_screen_rect button_rects[4] +./include/rsys/splash.h:43:struct splash_screen_color +./include/rsys/option.h:20:typedef struct option +./include/rsys/option.h:55:typedef struct opt_val +./include/rsys/option.h:68:typedef struct opt_database +./include/rsys/ctl.h:93:struct popup_data +./include/rsys/cfm.h:18:typedef struct +./include/rsys/cfm.h:37:typedef struct +./include/rsys/cfm.h:111:typedef struct MemFragment +./include/rsys/cfm.h:119:typedef struct DiskFragment +./include/rsys/cfm.h:127:typedef struct SegmentedFragment +./include/rsys/cfm.h:135:typedef struct FragmentLocator +./include/rsys/cfm.h:148:typedef struct InitBlock +./include/rsys/cfm.h:180:typedef struct +./include/rsys/cfm.h:189:typedef struct CFragConnection +./include/rsys/cfm.h:207:typedef struct +./include/rsys/cfm.h:224:typedef struct +./include/rsys/cfm.h:236:typedef struct +./include/rsys/soundopts.h:54:typedef struct _ModifierStub { +./include/rsys/soundopts.h:88:struct hunger_info +./include/rsys/iv.h:13:typedef struct color +./include/rsys/iv.h:18:typedef struct image_header +./include/rsys/checkpoint.h:13:typedef struct +./include/rsys/nextprint.h:24:typedef struct { +./include/rsys/nextprint.h:31:typedef struct { +./include/rsys/nextprint.h:36:typedef struct { +./include/rsys/nextprint.h:42:typedef struct { +./include/rsys/nextprint.h:60:typedef struct { +./include/rsys/nextprint.h:67:typedef struct { +./include/rsys/nextprint.h:73:typedef struct { +./include/rsys/nextprint.h:94:typedef struct { +./include/rsys/vdriver.h:5:struct ColorSpec; +./include/rsys/vdriver.h:21:struct \ +./include/rsys/vdriver.h:25: struct { short width, height; } size[num_entries]; \ +./include/rsys/vdriver.h:34:typedef struct +./include/rsys/image.h:4:typedef struct pixel_image +./include/rsys/image.h:21:typedef struct image_bits_desc +./include/rsys/image.h:28:typedef struct pixel_image_desc +./include/rsys/picture.h:56:typedef struct { +./include/rsys/trapglue.h:4:typedef struct { +./include/rsys/trapglue.h:10:typedef struct { +./include/rsys/trapglue.h:15:typedef struct { +./include/rsys/tesave.h:13:typedef struct +./include/rsys/tesave.h:62:typedef struct generic_elt +./include/rsys/tesave.h:128:typedef struct { /* from MPW: ToolEqu.a */ +./include/rsys/rgbutil.h:8:struct rgb_spec; +./include/rsys/rgbutil.h:13:typedef struct +./include/rsys/rgbutil.h:21:typedef void (*rgb_extract_func_t) (const struct rgb_spec *rgb_spec, +./include/rsys/rgbutil.h:26:typedef struct rgb_spec +./include/rsys/rgbutil.h:49: uint32 (*rgbcolor_to_pixel) (const struct rgb_spec *rgb_spec, +./include/rsys/filedouble.h:30:typedef struct { +./include/rsys/filedouble.h:36:typedef struct { +./include/rsys/filedouble.h:43:typedef struct { +./include/rsys/filedouble.h:50:typedef struct { + +#endif diff --git a/src/config/arch/powerpc/powerpc.make b/src/config/arch/powerpc/powerpc.make index cf13023..da9a8da 100644 --- a/src/config/arch/powerpc/powerpc.make +++ b/src/config/arch/powerpc/powerpc.make @@ -21,3 +21,6 @@ endif ppc_stubs.o: ppc_stubs.c ppc_stubs.h $(TARGET_GCC) $(TARGET_CFLAGS) $(CALL_AIX_FLAG) -c $< + +clean:: + rm -f $(TARGET_ARCH_OBJ) diff --git a/src/executor.make b/src/executor.make index 2442a8d..da2b55b 100644 --- a/src/executor.make +++ b/src/executor.make @@ -74,7 +74,7 @@ AUX_SRC = \ redrawscreen.c ini.c checkpoint.c qt.c cleanup.c paramline.c \ fauxdbm.c custom.c commtool.c cfm.c local_charset.c pef_hash.c \ mathlib.c interfacelib.c mixed_mode.c suffix_maps.c appearance.c \ - lockrange.c unix_like.c + lockrange.c unix_like.c check_structs.c ROMLIB_SRC = $(CTL_SRC) $(DIAL_SRC) $(FILE_SRC) $(HFS_SRC) $(LIST_SRC) \ $(MENU_SRC) $(PR_SRC) $(QD_SRC) $(RES_SRC) $(TE_SRC) $(WIND_SRC) \ diff --git a/src/include/rsys/check_structs.h b/src/include/rsys/check_structs.h new file mode 100644 index 0000000..cf5ab0a --- /dev/null +++ b/src/include/rsys/check_structs.h @@ -0,0 +1,6 @@ +#if !defined(__rsys_check_structs_h__) +#define __rsys_check_structs_h__ + +extern void check_structs(void); + +#endif diff --git a/src/include/rsys/launch.c b/src/include/rsys/launch.c deleted file mode 100644 index cdccb60..0000000 --- a/src/include/rsys/launch.c +++ /dev/null @@ -1,1333 +0,0 @@ -/* Copyright 1994 - 1996 by Abacus Research and - * Development, Inc. All rights reserved. - */ - -#if !defined (OMIT_RCSID_STRINGS) -char ROMlib_rcsid_launch[] = - "$Id: launch.c 63 2004-12-24 18:19:43Z ctm $"; -#endif - -#include "rsys/common.h" - -#include "QuickDraw.h" -#include "CQuickDraw.h" -#include "ResourceMgr.h" -#include "SegmentLdr.h" -#include "MemoryMgr.h" -#include "StdFilePkg.h" -#include "EventMgr.h" -#include "VRetraceMgr.h" -#include "OSUtil.h" -#include "FontMgr.h" -#include "ScrapMgr.h" -#include "ToolboxUtil.h" -#include "FileMgr.h" -#include "ControlMgr.h" -#include "DeviceMgr.h" -#include "SoundDvr.h" -#include "TextEdit.h" -#include "SysErr.h" -#include "SysError.h" -#include "MenuMgr.h" -#include "ScriptMgr.h" -#include "DeskMgr.h" -#include "AppleTalk.h" -#include "PrintMgr.h" -#include "StartMgr.h" -#include "ToolboxEvent.h" -#include "TimeMgr.h" -#include "ProcessMgr.h" -#include "AppleEvents.h" -#include "Gestalt.h" -#include "Package.h" - -#include "rsys/trapglue.h" -#include "rsys/file.h" -#include "rsys/next.h" -#include "rsys/sounddriver.h" -#include "rsys/pstuff.h" -#include "rsys/jumpvectors.h" -#include "rsys/prefs.h" -#include "rsys/flags.h" -#include "rsys/aboutpanel.h" -#include "rsys/segment.h" -#include "rsys/misc.h" -#include "rsys/pstuff.h" -#include "rsys/tesave.h" -#include "rsys/blockinterrupts.h" -#include "rsys/resource.h" -#include "rsys/hfs.h" -#include "rsys/osutil.h" -#include "rsys/memory_layout.h" -#include "rsys/stdfile.h" -#include "rsys/notmac.h" -#include "rsys/ctl.h" -#include "rsys/refresh.h" - -#include "rsys/options.h" -#include "rsys/cquick.h" -#include "rsys/desk.h" -#include "rsys/parse.h" -#include "rsys/executor.h" -#include "rsys/crc.h" -#include "rsys/float.h" -#include "rsys/mman.h" -#include "rsys/vdriver.h" -#include "rsys/font.h" -#include "rsys/emustubs.h" - -#include "rsys/adb.h" -#include "rsys/print.h" -#include "rsys/gestalt.h" -#include "rsys/osevent.h" -#include "rsys/license.h" - -#include "rsys/cfm.h" - -PRIVATE boolean_t ppc_launch_p = FALSE; - -PUBLIC void ROMlib_set_ppc (boolean_t val) -{ - ppc_launch_p = val; -} - -#define CONFIGEXTENSION ".ecf" -#define OLD_CONFIG_EXTENSION ".econf" /* must be longer than configextension */ - -FILE *configfile; - -int32 ROMlib_options; - -static int16 name0stripappl(StringPtr name) -{ - char *p; - int16 retval; - - retval = name[0]; - if (name[0] >= 5) { - p = (char *)name + name[0] + 1 - 5; - if ( p[0] == '.' && - (p[1] == 'a' || p[1] == 'A') && - (p[2] == 'p' || p[2] == 'P') && - (p[3] == 'p' || p[3] == 'P') && - (p[4] == 'l' || p[4] == 'L')) - retval -= 5; - } - return retval; -} - -/* - * NOTE: ParseConfigFile now has three arguments. The second is a standard - * OSType and will be expanded to 0x1234ABCD.ecf if exefname.ecf - * doesn't open. The third is whether or not to do resizes (based on whether - * the user has changed things by hand). - */ - -PUBLIC int ROMlib_nowarn32; - -PUBLIC char *ROMlib_configfilename = NULL; - -PUBLIC int ROMlib_pretend_help = FALSE; -PUBLIC int ROMlib_pretend_alias = FALSE; -PUBLIC int ROMlib_pretend_edition = FALSE; -PUBLIC int ROMlib_pretend_script = FALSE; - -void -remalloc (char **strp) -{ - char *new_string; - long len; - - if (*strp) - { - len = strlen (*strp) + 1; - new_string = malloc (len); - if (new_string) - memcpy (new_string, *strp, len); - *strp = new_string; - } -} - -void -reset_string (char **strp) -{ - if (*strp) - free (*strp); - *strp = 0; -} - -int ROMlib_desired_bpp; - -PRIVATE void ParseConfigFile(StringPtr exefname, OSType type) -{ - Ptr strdst, savestrdst; - INTEGER allocsize, dirsize; - int strwidth; - char *newtitle; - char *dot; - INTEGER fname0; - - reset_string (&ROMlib_WindowName); - reset_string (&ROMlib_Comments); - ROMlib_desired_bpp = 0; - fname0 = name0stripappl(exefname); - allocsize = fname0; - if (allocsize < (int) sizeof("0x1234ABCD")-1) /* IMPORTANT TO CODE */ - allocsize = sizeof("0x1234ABCD")-1; /* BELOW */ - dirsize = strlen(ROMlib_ConfigurationFolder); - ROMlib_configfilename = - realloc(ROMlib_configfilename, - dirsize + 1 + allocsize + sizeof(OLD_CONFIG_EXTENSION)); - strdst = (Ptr) ROMlib_configfilename; - BlockMove((Ptr) ROMlib_ConfigurationFolder, strdst, dirsize); - strdst += dirsize; - *strdst++ = '/'; - BlockMove((Ptr) exefname+1, strdst, fname0); - savestrdst = strdst; - strdst += fname0; - BlockMove((Ptr) CONFIGEXTENSION, strdst, sizeof(CONFIGEXTENSION)); - configfile = Ufopen(ROMlib_configfilename, "r"); - if (!configfile) { - BlockMove((Ptr) OLD_CONFIG_EXTENSION, strdst, sizeof(OLD_CONFIG_EXTENSION)); - configfile = Ufopen(ROMlib_configfilename, "r"); - } - if (!configfile && type != 0) { - strdst = savestrdst; - sprintf((char *) strdst, "%08x", type); - strdst += sizeof("1234ABCD")-1; - BlockMove((Ptr) CONFIGEXTENSION, strdst, sizeof(CONFIGEXTENSION)); - configfile = Ufopen(ROMlib_configfilename, "r"); - } - if (configfile) { - yyparse(); - - /* Stash away the system version. */ - gestalt_set_system_version (system_version); - SysVersion = CW (system_version); - -#if 0 - if (ROMlib_options & ROMLIB_NOCLOCK_BIT) - ROMlib_noclock = 1; -#endif - if (ROMlib_options & ROMLIB_BLIT_OS_BIT) - ROMlib_WriteWhen(WriteInOSEvent); - if (ROMlib_options & ROMLIB_BLIT_TRAP_BIT) - ROMlib_WriteWhen(WriteAtEndOfTrap); - if (ROMlib_options & ROMLIB_BLIT_OFTEN_BIT) - ROMlib_WriteWhen(WriteInBltrgn); -#if 0 - if (ROMlib_options & ROMLIB_ACCELERATED_BIT) - ROMlib_accelerated = TRUE; - else - ROMlib_accelerated = FALSE; -#endif - if (ROMlib_options & ROMLIB_REFRESH_BIT) - ROMlib_refresh = 10; - if (ROMlib_options & ROMLIB_DIRTY_VARIANT_BIT) - ROMlib_dirtyvariant = TRUE; - else - ROMlib_dirtyvariant = FALSE; - if (ROMlib_options & ROMLIB_SOUNDOFF_BIT) - ROMlib_PretendSound = soundoff; - if (ROMlib_options & ROMLIB_PRETENDSOUND_BIT) - ROMlib_PretendSound = soundpretend; - if (ROMlib_options & ROMLIB_SOUNDON_BIT) - ROMlib_PretendSound = SOUND_WORKS_P () ? soundon : soundpretend; -#if 0 - if (ROMlib_options & ROMLIB_PASSPOSTSCRIPT_BIT) - ROMlib_passpostscript = TRUE; - else - ROMlib_passpostscript = FALSE; -#else -/* #warning ROMlib_passpostscript wired to TRUE */ - ROMlib_passpostscript = TRUE; -#endif - if (ROMlib_options & ROMLIB_NEWLINETOCR_BIT) - ROMlib_newlinetocr = TRUE; - else - ROMlib_newlinetocr = FALSE; - if (ROMlib_options & ROMLIB_DIRECTDISKACCESS_BIT) - ROMlib_directdiskaccess = TRUE; - else - ROMlib_directdiskaccess = FALSE; - if (ROMlib_options & ROMLIB_NOWARN32_BIT) - ROMlib_nowarn32 = TRUE; - else - ROMlib_nowarn32 = FALSE; - if (ROMlib_options & ROMLIB_FLUSHOFTEN_BIT) - ROMlib_flushoften = TRUE; - else - ROMlib_flushoften = FALSE; - - if (ROMlib_options & ROMLIB_PRETEND_HELP_BIT) - ROMlib_pretend_help = TRUE; - else - ROMlib_pretend_help = FALSE; - - if (ROMlib_options & ROMLIB_PRETEND_ALIAS_BIT) - ROMlib_pretend_alias = TRUE; - else - ROMlib_pretend_alias = FALSE; - - if (ROMlib_options & ROMLIB_PRETEND_EDITION_BIT) - ROMlib_pretend_edition = TRUE; - else - ROMlib_pretend_edition = FALSE; - - if (ROMlib_options & ROMLIB_PRETEND_SCRIPT_BIT) - ROMlib_pretend_script = TRUE; - else - ROMlib_pretend_script = FALSE; - - if (ROMlib_desired_bpp) - SetDepth (MR (MainDevice), ROMlib_desired_bpp, 0, 0); - fclose(configfile); - } - -#if !defined (VDRIVER_DISPLAYED_IN_WINDOW) -#define ROMlib_SetTitle(x) do { ROMlib_WindowName = x; } while (0) -#endif - - if (ROMlib_WindowName) - ROMlib_SetTitle(ROMlib_WindowName); - else { - strwidth = fname0; - newtitle = alloca(strwidth + 1); - memcpy(newtitle, exefname+1, strwidth); - newtitle[strwidth] = 0; - dot = strrchr(newtitle, '.'); - if (dot && (strcmp(dot, ".appl") == 0 || - strcmp(dot, ".APPL") == 0)) - *dot = 0; - ROMlib_SetTitle(newtitle); - } -#if 0 - if (ROMlib_ScreenLocation.first != INITIALPAIRVALUE) - ROMlib_HideScreen(); - if (ROMlib_ScreenLocation.first != INITIALPAIRVALUE) { - ROMlib_SetLocation(&ROMlib_ScreenLocation); - ROMlib_ShowScreen(); - } -#endif - - remalloc (&ROMlib_WindowName); - remalloc (&ROMlib_Comments); -} - -PRIVATE void beginexecutingat( LONGINT startpc ) -{ -#if defined (SYN68K) -#define ALINETRAPNUMBER 0xA - trap_install_handler( ALINETRAPNUMBER, alinehandler, (void *) 0); -#endif - - EM_D0 = 0; - EM_D1 = 0xFFFC000; - EM_D2 = 0; - EM_D3 = 0x800008; - EM_D4 = 0x408; - EM_D5 = 0x10204000; - EM_D6 = 0x7F0000; - EM_D7 = 0x80000800; - - EM_A0 = 0x3EF796; - EM_A1 = 0x910; - EM_A2 = EM_D3; - EM_A3 = 0; - EM_A4 = 0; - EM_A5 = CL((LONGINT) CurrentA5); /* was smashed when we - initialized above */ - EM_A6 = 0x1EF; - - CALL_EMULATOR(startpc); - C_ExitToShell(); -} - -PUBLIC LONGINT ROMlib_appbit; - -size_info_t size_info; - -#define VERSFMT "(0x%02x, 0x%02x, 0x%02x, 0x%02x, %d)" -#define VERSSIZE(vp) (sizeof(VERSFMT) + (vp)->shortname[0] + 6) -typedef struct { - unsigned char c[4] PACKED; - short loc PACKED; - unsigned char shortname[1] PACKED; -} vers_t; - -LONGINT ROMlib_creator; - -PUBLIC void *ROMlib_foolgcc; /* to force the alloca to be done */ - -PUBLIC void SFSaveDisk_Update (INTEGER vrefnum, Str255 filename) -{ - ParamBlockRec pbr; - Str255 save_name; - - str255assign (save_name, filename); - pbr.volumeParam.ioNamePtr = (Ptr) RM ((long) save_name); - pbr.volumeParam.ioVolIndex = CWC (-1); - pbr.volumeParam.ioVRefNum = CW (vrefnum); - PBGetVInfo (&pbr, FALSE); - SFSaveDisk = CW (-CW (pbr.volumeParam.ioVRefNum)); -} - -PUBLIC uint32 ROMlib_version_long; - -PRIVATE void -cfm_launch (Handle cfrg0, OSType desired_arch, FSSpecPtr fsp) -{ - cfrg_resource_t *cfrgp; - int n_descripts; - cfir_t *cfirp; - OSType desired_arch_x; - - cfrgp = (cfrg_resource_t *) STARH (cfrg0); - cfirp = (cfir_t *) ((char *) cfrgp + sizeof *cfrgp); - desired_arch_x = CL (desired_arch); - for (n_descripts = CFRG_N_DESCRIPTS (cfrgp); - n_descripts > 0 && CFIR_ISA_X (cfirp) != desired_arch_x; - --n_descripts, cfirp = (cfir_t *) ((char *) cfirp + CFIR_LENGTH(cfirp))) - ; - -#if defined (powerpc) || defined (__ppc__) - if (CFIR_ISA_X(cfirp) == desired_arch_x) - { - Ptr mainAddr; - Str255 errName; - ConnectionID c_id; - -#warning were ignoring a lot of the cfir attributes - GetDiskFragment (fsp, CFIR_OFFSET_TO_FRAGMENT (cfirp), - CFIR_FRAGMENT_LENGTH (cfirp), "", - kLoadLib, - &c_id, - &mainAddr, - errName); - { - uint32 new_toc; - void *new_pc; - - new_toc = ((uint32 *)mainAddr)[1]; - new_pc = ((void **)mainAddr)[0]; - ppc_call (new_toc, new_pc, 0); - } - } -#endif - - C_ExitToShell (); -} - -PUBLIC int ROMlib_uaf; - -PRIVATE void launchchain(StringPtr fName, INTEGER vRefNum, BOOLEAN resetmemory, - LaunchParamBlockRec *lpbp) -{ - OSErr err; - FInfo finfo; - Handle code0; - Handle cfrg0; - Handle h; - vers_t *vp; - char *versbuf, *namebuf; - int namelen; - LONGINT abovea5, belowa5, jumplen, jumpoff, *lp; - INTEGER exevrefnum, toskip; - Byte *p; - WDPBRec wdpb; - StringPtr ename; - INTEGER elen; - - for (p = fName + fName[0] + 1; p > fName && *--p != ':';) - ; - toskip = p - fName; - CurApName[0] = MIN(fName[0]-toskip, 31); - BlockMove((Ptr) fName+1+toskip, (Ptr) CurApName+1, - (Size) CurApName[0]); -#if 0 - Munger(MR(AppParmHandle), 2L*sizeof(INTEGER), (Ptr) 0, - (LONGINT) sizeof(AppFile), (Ptr) "", 0L); -#endif - if (!lpbp || lpbp->launchBlockID != CWC (extendedBlock)) - { - CInfoPBRec hpb; - - hpb.hFileInfo.ioNamePtr = RM(&fName[0]); - hpb.hFileInfo.ioVRefNum = CW(vRefNum); - hpb.hFileInfo.ioFDirIndex = CWC (0); - hpb.hFileInfo.ioDirID = 0; - PBGetCatInfo(&hpb, FALSE); - wdpb.ioVRefNum = CW(vRefNum); - wdpb.ioWDDirID = hpb.hFileInfo.ioFlParID; - } - else - { - FSSpecPtr fsp; - - fsp = MR (lpbp->launchAppSpec); - wdpb.ioVRefNum = fsp->vRefNum; - wdpb.ioWDDirID = fsp->parID; - } - /* Do not do this -- Loser does it SFSaveDisk_Update (vRefNum, fName); */ - wdpb.ioWDProcID = T('X','c','t','r'); - wdpb.ioNamePtr = 0; - PBOpenWD(&wdpb, FALSE); - exevrefnum = CW(wdpb.ioVRefNum); - ROMlib_exefname = CurApName; -#if 0 -/* I'm skeptical that this is correct */ - if (CurMap != SysMap) - CloseResFile(CurMap); -#endif - SetVol((StringPtr) 0, exevrefnum); - CurApRefNum = CW(OpenResFile(ROMlib_exefname)); - - /* setupsignals(); */ - - err = GetFInfo(ROMlib_exefname, exevrefnum, &finfo); - - process_create (FALSE, finfo.fdType, finfo.fdCreator); - - if (ROMlib_exeuname) - free (ROMlib_exeuname); - ROMlib_exeuname = ROMlib_newunixfrommac((char *) ROMlib_exefname+1, - ROMlib_exefname[0]); - elen = strlen(ROMlib_exeuname); - ename = (StringPtr) alloca(elen+1); - BlockMove((Ptr) ROMlib_exeuname, (Ptr) ename+1, elen); - ename[0] = elen; - - ROMlib_creator = CL(finfo.fdCreator); - -#define LEMMINGSHACK -#if defined(LEMMINGSHACK) - { - if (finfo.fdCreator == CL(TICK("Psyg")) - || finfo.fdCreator == CL(TICK("Psod"))) - ROMlib_flushoften = TRUE; - } -#endif /* defined(LEMMINGSHACK) */ - -#if defined (ULTIMA_III_HACK) - ROMlib_ultima_iii_hack = (finfo.fdCreator == CL(TICK("Ult3"))); -#endif - - h = GetResource(T('v','e','r','s'), 2); - if (!h) - h = GetResource(T('v','e','r','s'), 1); - - ROMlib_version_long = 0; - if (h) { - vp = (vers_t *) STARH(h); - versbuf = alloca(VERSSIZE(vp)); - memcpy(versbuf, vp->shortname+1, vp->shortname[0]); - sprintf(versbuf+vp->shortname[0], VERSFMT, - (LONGINT) vp->c[0], - (LONGINT) vp->c[1], - (LONGINT) vp->c[2], - (LONGINT) vp->c[3], - (LONGINT) vp->loc); - ROMlib_version_long = ((vp->c[0] << 24)| - (vp->c[1] << 16)| - (vp->c[2] << 8)| - (vp->c[3] << 0)); - } else - versbuf = ""; - - ROMlib_ScreenSize.first = INITIALPAIRVALUE; - ROMlib_MacSize.first = INITIALPAIRVALUE; - ROMlib_directdiskaccess = FALSE; - ROMlib_clear_gestalt_list (); - ParseConfigFile ((StringPtr) "\017ExecutorDefault", 0); - ParseConfigFile (ename, err == noErr ? CL(finfo.fdCreator) : 0); - ROMlib_clockonoff(!ROMlib_noclock); - if ((ROMlib_ScreenSize.first != INITIALPAIRVALUE - || ROMlib_MacSize.first != INITIALPAIRVALUE)) - { - if (ROMlib_ScreenSize.first == INITIALPAIRVALUE) - ROMlib_ScreenSize = ROMlib_MacSize; - if (ROMlib_MacSize.first == INITIALPAIRVALUE) - ROMlib_MacSize = ROMlib_ScreenSize; - } - code0 = Get1Resource (T('C','O','D','E'), 0); - cfrg0 = Get1Resource (T('c','f','r','g'), 0); - - if (cfrg0 && ppc_launch_p) - code0 = NULL; - else if (!code0) - { - if (cfrg0) - ParamText ("\062CFM-requiring binaries are not currently supported", - 0, 0, 0); - else - ParamText ("\061This binary appears damaged (lacks CODE and cfrg)", - 0, 0, 0); - NoteAlert (GENERIC_COMPLAINT_ID, (ProcPtr) 0); - C_ExitToShell (); - } - - { - Handle size_resource_h; - int16 size_flags; - - size_resource_h = Get1Resource (T ('S','I','Z','E'), 0); - if (size_resource_h == NULL) - size_resource_h = Get1Resource (T ('S','I','Z','E'), -1); - if (size_resource_h) - { - size_info_t *size_resource; - - size_resource = (size_info_t *) STARH (size_resource_h); - size_info.size_flags = CW (size_resource->size_flags); - size_info.preferred_size = CL (size_resource->preferred_size); - size_info.minimum_size = CL (size_resource->minimum_size); - size_info.size_resource_present_p = TRUE; - } - else - { - memset (&size_info, '\000', sizeof size_info); - size_info.size_resource_present_p = FALSE; - } - size_info.application_p = TRUE; - - size_flags = size_info.size_flags; - - /* we don't accept open app events until a handler is installed */ - application_accepts_open_app_aevt_p = FALSE; - send_application_open_aevt_p - = system_version >= 0x700 - && ((size_flags & SZisHighLevelEventAware) - == SZisHighLevelEventAware); - } - - h = GetResource(CL(finfo.fdCreator), 0); - if (h) { - namelen = *MR(*(unsigned char **)h); - namebuf = alloca(namelen+1); - memcpy(namebuf, (char *) STARH(h)+1, namelen); - namebuf[namelen] = 0; - } else - namebuf = ""; - - if (!code0) - { - lp = 0; /* just to shut GCC up */ - jumplen = jumpoff = 0; /* just to shut GCC up */ - } - else - { - HLock(code0); - - lp = (LONGINT *) STARH(code0); - abovea5 = CL(*lp++); - belowa5 = CL(*lp++); - jumplen = CL(*lp++); - jumpoff = CL(*lp++); - - /* - * NOTE: The stack initialization code that was here has been moved - * to ROMlib_InitZones in mman.c - */ -/* #warning Stack is getting reinitialized even when Chain is called ... */ - -#if defined(SYN68K) - EM_A7 -= abovea5 + belowa5; - CurStackBase = (Ptr) CL(EM_A7); -#else /* !defined(SYN68K) */ - ROMlib_foolgcc = alloca(abovea5 + belowa5); - CurStackBase - = CL(MAC_STACK_START + MAC_STACK_SIZE - (abovea5 + belowa5)); -#endif /* !defined(SYN68K) */ - - CurrentA5 = RM(MR(CurStackBase) + belowa5); /* set CurrentA5 */ - BufPtr = RM(MR(CurrentA5) + abovea5); - CurJTOffset = CW(jumpoff); - a5 = CL((LONGINT) CurrentA5); - } - - GetDateTime((LONGINT *) &Time); - ROMBase = RM((Ptr) ROMlib_phoneyrom); - dodusesit = ROMBase; - QDExist = WWExist = EXIST_NO; - TheZone = ApplZone; - ROMlib_memnomove_p = TRUE; - -#if defined(NEXTSTEP) - ROMlib_startapp(); -#endif -/* - * NOTE: this memcpy has to be done after all local variables have been used - * because it will quite possibly smash stuff that's on our stack. - * In reality, we only see this if we compile without optimization, - * but trust me, it was *very* confusing when this memcpy was up - * before we were done with our local varibles. - */ - if (code0) - { - memcpy(MR(CurrentA5) + jumpoff, lp, jumplen); /* copy in the - jump table */ - ROMlib_destroy_blocks (0, ~0, FALSE); -#if defined(ONLY_DESTROY_BETWEEN_CODE_SEGMENTS) - ROMlib_num_code_resources = 0; /* Force a recompute. */ -#endif - } - SetCursor(STARH(GetCursor(watchCursor))); - - /* Call this routine in case the refresh value changed, either just - * now or when the config file was parsed. We want to do this - * before the screen's depth might be changed. - */ - { - int save_ROMlib_refresh = ROMlib_refresh; - dequeue_refresh_task (); - set_refresh_rate (0); - set_refresh_rate (save_ROMlib_refresh); - } - - ROMlib_uaf = 0; - - if (code0) - beginexecutingat(CL((LONGINT) CurrentA5) + CW(CurJTOffset) + 2); - else - { - FSSpec fs; - - FSMakeFSSpec (exevrefnum, 0, ROMlib_exefname, &fs); - cfm_launch (cfrg0, T('p','w','p','c'), &fs); - } -} - -A2(PUBLIC trap, void, Chain, StringPtr, fName, INTEGER, vRefNum) -{ - launchchain(fName, vRefNum, FALSE, 0); -} - -PRIVATE void reset_low_globals(void) -{ -/* - * we're about to smash applzone ... we may want to verify a few low-mem - * globals beforehand - */ - - ProcPtr saveDABeeper; - THz saveSysZone; - uint32 saveTicks; - INTEGER saveBootDrive; - LONGINT saveLo3Bytes; - LONGINT save20, save28, save58, save5C; - Ptr saveSoundBase; - Ptr saveVIA; - Ptr saveSCCRd; - Ptr saveSCCWr; - Handle saveAppParmHandle; - QHdr saveVCBQHdr; - QHdr saveFSQHdr; - QHdr saveDrvQHdr; - QHdr saveEventQueue; - QHdr saveVBLQueue; - Ptr saveFCBSPtr; - Ptr saveWDCBsPtr; - LONGINT saveCurDirStore; - INTEGER saveSFSaveDisk; - VCBPtr saveDefVCBPtr; - char saveCurApName[sizeof(CurApName)]; - INTEGER saveCurApRefNum; - INTEGER saveCurMap; - Handle saveTopMapHndl; - Handle saveSysMapHndl; - INTEGER saveSysMap; - LONGINT saveScrapSize; - Handle saveScrapHandle; - INTEGER saveScrapCount; - INTEGER saveScrapState; - StringPtr saveScrapName; - Handle saveROMFont0; - Handle saveWidthListHand; - Byte saveSPValid; - Byte saveSPATalkA; - Byte saveSPATalkB; - Byte saveSPConfig; - INTEGER saveSPPortA; - INTEGER saveSPPortB; - LONGINT saveSPAlarm; - INTEGER saveSPFont; - Byte saveSPKbd; - Byte saveSPPrint; - Byte saveSPVolCtl; - Byte saveSPClikCaret; - Byte saveSPMisc2; - INTEGER saveKeyThresh; - INTEGER saveKeyRepThresh; - INTEGER saveMenuFlash; - LONGINT saveCaretTime; - LONGINT saveDoubleTime; - LONGINT saveDefDirID; - HIDDEN_Handle saveDAStrings[4]; - Ptr saveMemTop; - DCtlHandlePtr saveUTableBase; - INTEGER saveUnitNtryCnt; - Point saveMouseLocation; - CGrafPtr saveWMgrCPort; - Handle saveMBDFHndl; - ProcPtr saveJCrsrTask; - - AE_info_t *saveAE_info; - - RGBColor saveHiliteRGB; - GDHandle saveTheGDevice, saveMainDevice, saveDeviceList; - char saveKeyMap[sizeof_KeyMap]; - - Byte saveFinderName[sizeof(FinderName)]; - virtual_int_state_t bt; - - bt = block_virtual_ints (); - saveSysZone = SysZone; - saveTicks = Ticks; - saveBootDrive = BootDrive; - saveLo3Bytes = Lo3Bytes; - save20 = *(LONGINT *) SYN68K_TO_US(0x20); - save28 = *(LONGINT *) SYN68K_TO_US(0x28); - save58 = *(LONGINT *) SYN68K_TO_US(0x58); - save5C = *(LONGINT *) SYN68K_TO_US(0x5C); - saveVIA = VIA; - saveSCCRd = SCCRd_H.p; - saveSCCWr = SCCWr_H.p; - saveSoundBase = SoundBase; - saveAppParmHandle = AppParmHandle; - saveVCBQHdr = VCBQHdr; - saveFSQHdr = FSQHdr; - saveDrvQHdr = DrvQHdr; - saveFCBSPtr = FCBSPtr; - saveWDCBsPtr = WDCBsPtr; - saveSFSaveDisk = SFSaveDisk; - saveCurDirStore = CurDirStore; - saveEventQueue = EventQueue; - saveVBLQueue = VBLQueue; - saveDefVCBPtr = DefVCBPtr; - memcpy(saveCurApName, CurApName, sizeof(CurApName)); - saveCurApRefNum = CurApRefNum; - saveCurMap = CurMap; - saveTopMapHndl = TopMapHndl; - saveSysMapHndl = SysMapHndl; - saveSysMap = SysMap; - saveScrapSize = ScrapSize; - saveScrapHandle = ScrapHandle; - saveScrapCount = ScrapCount; - saveScrapState = ScrapState; - saveScrapName = ScrapName; - saveROMFont0 = ROMFont0; - saveWidthListHand = WidthListHand; - saveSPValid = SPValid; - saveSPATalkA = SPATalkA; - saveSPATalkB = SPATalkB; - saveSPConfig = SPConfig; - saveSPPortA = SPPortA; - saveSPPortB = SPPortB; - saveSPAlarm = SPAlarm; - saveSPFont = SPFont; - saveSPKbd = SPKbd; - saveSPPrint = SPPrint; - saveSPVolCtl = SPVolCtl; - saveSPClikCaret = SPClikCaret; - saveSPMisc2 = SPMisc2; - saveKeyThresh = KeyThresh; - saveKeyRepThresh = KeyRepThresh; - saveMenuFlash = MenuFlash; - saveCaretTime = CaretTime; - saveDoubleTime = DoubleTime; - saveDefDirID = DefDirID; - - saveHiliteRGB = HiliteRGB; - saveTheGDevice = TheGDevice; - saveMainDevice = MainDevice; - saveDeviceList = DeviceList; - saveDAStrings[0] = DAStrings_H[0]; - saveDAStrings[1] = DAStrings_H[1]; - saveDAStrings[2] = DAStrings_H[2]; - saveDAStrings[3] = DAStrings_H[3]; - saveMemTop = MemTop; - saveUTableBase = UTableBase; - saveUnitNtryCnt = UnitNtryCnt; - - saveMouseLocation = MouseLocation; - saveDABeeper = DABeeper; - - memcpy(saveFinderName, FinderName, sizeof(saveFinderName)); - saveWMgrCPort = WMgrCPort; - saveMBDFHndl = MBDFHndl; - - saveJCrsrTask = JCrsrTask; - - saveAE_info = AE_info; - memcpy (saveKeyMap, KeyMap, sizeof_KeyMap); - - /* Set low globals to 0xFF, but don't touch exception vectors. */ - memset ((char *)&nilhandle + 64 * sizeof (ULONGINT), - 0xFF, - ((char *)&lastlowglobal - (char *)&nilhandle - - 64 * sizeof (ULONGINT))); - - AE_info = saveAE_info; - - JCrsrTask = saveJCrsrTask; - - MBDFHndl = saveMBDFHndl; - WMgrCPort = saveWMgrCPort; - WindowList = NULL; - memcpy(FinderName, saveFinderName, sizeof(FinderName)); - - DABeeper = saveDABeeper; - MouseLocation = saveMouseLocation; - MouseLocation2 = saveMouseLocation; - - UTableBase = saveUTableBase; - UnitNtryCnt = saveUnitNtryCnt; - MemTop = saveMemTop; - DAStrings_H[3] = saveDAStrings[3]; - DAStrings_H[2] = saveDAStrings[2]; - DAStrings_H[1] = saveDAStrings[1]; - DAStrings_H[0] = saveDAStrings[0]; - DefDirID = saveDefDirID; - DoubleTime = saveDoubleTime; - CaretTime = saveCaretTime; - MenuFlash = saveMenuFlash; - KeyRepThresh = saveKeyRepThresh; - KeyThresh = saveKeyThresh; - SPMisc2 = saveSPMisc2; - SPClikCaret = saveSPClikCaret; - SPVolCtl = saveSPVolCtl; - SPPrint = saveSPPrint; - SPKbd = saveSPKbd; - SPFont = saveSPFont; - SPAlarm = saveSPAlarm; - SPPortB = saveSPPortB; - SPPortA = saveSPPortA; - SPConfig = saveSPConfig; - SPATalkB = saveSPATalkB; - SPATalkA = saveSPATalkA; - SPValid = saveSPValid; - WidthListHand = saveWidthListHand; - ROMFont0 = saveROMFont0; - ScrapName = saveScrapName; - ScrapState = saveScrapState; - ScrapCount = saveScrapCount; - ScrapHandle = saveScrapHandle; - ScrapSize = saveScrapSize; - SysMap = saveSysMap; - SysMapHndl = saveSysMapHndl; - TopMapHndl = saveTopMapHndl; - CurMap = saveCurMap; - CurApRefNum = saveCurApRefNum; - memcpy(CurApName, saveCurApName, sizeof(CurApName)); - DefVCBPtr = saveDefVCBPtr; - VBLQueue = saveVBLQueue; - EventQueue = saveEventQueue; - CurDirStore = saveCurDirStore; - SFSaveDisk = saveSFSaveDisk; - WDCBsPtr = saveWDCBsPtr; - FCBSPtr = saveFCBSPtr; - DrvQHdr = saveDrvQHdr; - FSQHdr = saveFSQHdr; - VCBQHdr = saveVCBQHdr; - Lo3Bytes = saveLo3Bytes; - VIA = saveVIA; - SCCRd_H.p = saveSCCRd; - SCCWr_H.p = saveSCCWr; - SoundBase = saveSoundBase; - Ticks_UL.u = saveTicks; - SysZone = saveSysZone; - BootDrive = saveBootDrive; - AppParmHandle = saveAppParmHandle; - - HiliteRGB = saveHiliteRGB; - TheGDevice = saveTheGDevice; - MainDevice = saveMainDevice; - DeviceList = saveDeviceList; - - restore_virtual_ints (bt); - - nilhandle = 0; /* so nil dereferences "work" */ - - CrsrBusy = 0; - TESysJust = 0; - DSAlertTab = 0; - ResumeProc = 0; - GZRootHnd = 0; - ANumber = 0; - ResErrProc = 0; -#if 0 - FractEnable = 0xff; /* NEW MOD -- QUESTIONABLE */ -#else - FractEnable = 0; -#endif - SEvtEnb = 0; - MenuList = 0; - MBarEnable = 0; - MenuFlash = 0; - TheMenu = 0; - MBarHook = 0; - MenuHook = 0; - HeapEnd = 0; - ApplLimit = 0; - SoundActive = soundactiveoff; - PortBUse = 2; /* configured for Serial driver */ - - memcpy (KeyMap, saveKeyMap, sizeof_KeyMap); - OneOne = CLC(0x00010001); - DragHook = 0; - MBDFHndl = 0; - MenuList = 0; - MBSaveLoc = 0; - SysFontFam = 0; - - SysVersion = CW (system_version); - FSFCBLen = CWC (94); - -/* - * TODO: how does this relate to Launch? - */ - /* Set up default floating point environment. */ - { - INTEGER env = 0; - ROMlib_Fsetenv (&env, 0); - } - - TEDoText = RM((ProcPtr) P_ROMlib_dotext); /* where should this go ? */ - - WWExist = QDExist = EXIST_NO; /* TODO: LOOK HERE! */ - SCSIFlags = CWC (0xEC00); /* scsi+clock+xparam+mmu+adb - (no fpu,aux or pwrmgr) */ - - MMUType = 5; - KbdType = 2; - - MCLKPCmiss1 = 0; /* &MCLKPCmiss1 = 0x358 + 72 (MacLinkPC starts - adding the 72 byte offset to VCB pointers too - soon, starting with 0x358, which is not the - address of a VCB) */ - - MCLKPCmiss2 = 0; /* &MCLKPCmiss1 = 0x358 + 78 (MacLinkPC misses) */ - AuxCtlHead = 0; - CurDeactive = 0; - CurActivate = 0; - macfpstate[0] = 0; - fondid = 0; - PrintErr = 0; - mouseoffset = 0; - heapcheck = 0; - DefltStack = CLC(0x2000); /* nobody really cares about these two */ - MinStack = CLC(0x400); /* values ... */ - IAZNotify = 0; - CurPitch = 0; - JSwapFont = (ProcPtr) RM(P_FMSwapFont); - JInitCrsr = (ProcPtr) RM(P_InitCursor); - - JHideCursor = (ProcPtr) RM(P_HideCursor); - JShowCursor = (ProcPtr) RM(P_ShowCursor); - JShieldCursor = (ProcPtr) RM(P_ShieldCursor); - JSetCrsr = (ProcPtr) RM(P_SetCursor); - JCrsrObscure = (ProcPtr) RM(P_ObscureCursor); - -#if 0 - JUnknown574 = (ProcPtr) RM(P_Unknown574); -#else - *(long *)(0x574 + ROMlib_offset) = (long) RM(P_Unknown574); -#endif - - Key1Trans = (Ptr) RM(P_Key1Trans); - Key2Trans = (Ptr) RM(P_Key2Trans); - JFLUSH = (ProcPtr) RM(P_flushcache); - JResUnknown1 = JFLUSH; /* I don't know what these are supposed to */ - JResUnknown2 = JFLUSH; /* do, but they're not called enough for - us to worry about the cache flushing - overhead */ - - CPUFlag = 4; /* mc68040 */ - UnitNtryCnt = 0; /* how many units in the table */ - - TheZone = ApplZone; - -#if !defined(SYN68K) - bzero((char *) &nilhandle, 0xc0); /* exception vectors */ - /* pagemaker 2.0 looks at 108 - and doesn't want to see -1 */ -#endif /* !defined(SYN68K) */ - *(LONGINT *) SYN68K_TO_US(0x20) = save20; - *(LONGINT *) SYN68K_TO_US(0x28) = save28; - *(LONGINT *) SYN68K_TO_US(0x58) = save58; - *(LONGINT *) SYN68K_TO_US(0x5C) = save5C; - - HiliteMode = CB(0xFF); /* I think this is correct */ - ROM85 = CWC(0x3FFF); /* We be color now */ - MMU32Bit = 0x01; - loadtrap = 0; - *(LONGINT *) SYN68K_TO_US(0x1008) = CLC (0x4); /* Quark XPress 3.0 references 0x1008 - explicitly. It takes the value - found there, subtracts four from - it and dereferences that value. - Yahoo */ - *(short *) SYN68K_TO_US(4) = CWC (0x4e75); /* RTS, so when we dynamically recompile - code starting at 0 we won't get far */ - - /* Micro-cap dereferences location one of the AppPacks locations */ - - { - int i; - - for (i = 0; i < (int) NELEM (AppPacks_H); ++i) - AppPacks_H[i].p = 0; - } - SysEvtMask = CWC(~(1L<< keyUp)); /* EVERYTHING except keyUp */ - SdVolume = 7; /* for Beebop 2 */ - CurrentA5 = (Ptr) CL (EM_A5); -} - -PRIVATE void reset_traps(void) -{ - static void *savetooltraptable[0x400]; - static void *saveostraptable[0x100]; - static BOOLEAN beenhere = FALSE; - - ROMlib_reset_bad_trap_addresses (); - if (!beenhere) { - memcpy( saveostraptable, ostraptable, sizeof( saveostraptable)); - memcpy(savetooltraptable, tooltraptable, sizeof(savetooltraptable)); - beenhere = TRUE; - } else { -/* - * NOTE: I'm not preserving patches that go into the SystemZone. Right now - * that just seems like an unnecessary source of mystery bugs. - */ - memcpy( ostraptable, saveostraptable, sizeof( saveostraptable)); - memcpy(tooltraptable, savetooltraptable, sizeof(savetooltraptable)); - } -} - -PRIVATE boolean_t -our_special_map (resmaphand map) -{ - boolean_t retval; - Handle h; - - CurMap = STARH(map)->resfn; - h = Get1Resource (TICK("nUSE"), 0); - retval = h ? TRUE : FALSE; - - return retval; -} - - -void -empty_timer_queues (void) -{ - TMTask *tp, *nexttp; - VBLTaskPtr vp, nextvp; - virtual_int_state_t bt; - - bt = block_virtual_ints (); - - dequeue_refresh_task (); - clear_pending_sounds (); - for (vp = (VBLTaskPtr) MR (VBLQueue.qHead); vp; vp = nextvp) - { - nextvp = (VBLTaskPtr) MR (vp->qLink); - VRemove (vp); - } - for (tp = MR ((TMTask *) ROMlib_timehead.qHead); tp; tp = nexttp) - { - nexttp = (TMTask *) MR (tp->qLink); - RmvTime ((QElemPtr) tp); - } - - restore_virtual_ints (bt); -} - - -PRIVATE void reinitialize_things(void) -{ - resmaphand map, nextmap; - filecontrolblock *fcbp, *efcbp; - INTEGER length; - INTEGER special_fn; - int i; - - ROMlib_shutdown_font_manager (); - SetZone (MR(SysZone)); - /* NOTE: we really shouldn't be closing desk accessories at all, but - since we don't properly handle them when they're left open, it is - better to close them down than not. */ - - for (i = DESK_ACC_MIN; i <= DESK_ACC_MAX; ++i) - CloseDriver (-i - 1); - - empty_timer_queues (); - ROMlib_clock = 0; /* CLOCKOFF */ - - special_fn = 0; - for (map = (resmaphand) MR(TopMapHndl); map; map = nextmap) { - nextmap = (resmaphand) HxP(map, nextmap); - if (HxX(map, resfn) == SysMap) - UpdateResFile (Hx (map, resfn)); - else - { - if (!our_special_map (map)) - CloseResFile(Hx(map, resfn)); - else - { - special_fn = Hx(map, resfn); - UpdateResFile (special_fn); - } - } - } - - length = CW(*(short *)MR(FCBSPtr)); - fcbp = (filecontrolblock *) ((short *)MR(FCBSPtr)+1); - efcbp = (filecontrolblock *) ((char *)MR(FCBSPtr) + length); - for (;fcbp < efcbp; - fcbp = (filecontrolblock *) ((char *)fcbp + CW(FSFCBLen))) - { - INTEGER rn; - - rn = (char *) fcbp - (char *) MR(FCBSPtr); - if (fcbp->fcbCName[0] - /* && rn != Param_ram_rn */ - && rn != CW (SysMap) - && rn != special_fn) - FSClose((char *) fcbp - (char *) MR(FCBSPtr)); - } - - CurMap = STARH((resmaphand)MR(TopMapHndl))->resfn; - - /* TODO replace the code in main.c with this stuff */ -#if !defined(MSDOS) -/* - * In the GO32 environment we're not guaranteed to have a floating point - * coprocessor, so we delay floating point environment initialization until - * we actually use it. - */ - /* Set up default floating point environment. */ - { - INTEGER env = 0; - ROMlib_Fsetenv (&env, 0); - } -#endif - - ROMlib_destroy_blocks (0, ~0, FALSE); -#if defined(ONLY_DESTROY_BETWEEN_CODE_SEGMENTS) - ROMlib_num_code_resources = 0; /* Force a recompute. */ -#endif -} - -PUBLIC void -NewLaunch (StringPtr fName_arg, INTEGER vRefNum_arg, LaunchParamBlockRec *lpbp) -{ - static char beenhere = FALSE; - static jmp_buf buf; - static Str255 fName; - static INTEGER vRefNum; - static LaunchParamBlockRec lpb; - - if (lpbp && lpbp->launchBlockID == CWC (extendedBlock)) - { - lpb = *lpbp; - str255assign (fName, (MR (lpbp->launchAppSpec))->name); - } - else - { - lpb.launchBlockID = 0; - str255assign (fName, fName_arg); - vRefNum = vRefNum_arg; - } - - /* This setjmp/longjmp code might be better put in launchchain */ - if (!beenhere) - { - beenhere = TRUE; - setjmp(buf); - } - else - longjmp(buf, 1); - - reset_adb_vector (); - reinitialize_things(); - reset_traps(); - reset_low_globals(); - ROMlib_InitZones(offset_no_change); /* too late to change memory offset */ - ROMlib_InitGWorlds(); - hle_reinit (); - AE_reinit (); - print_reinit (); - - gd_set_bpp (MR (MainDevice), !vdriver_grayscale_p, vdriver_fixed_clut_p, - vdriver_bpp); - ROMlib_init_stdfile(); -#if ERROR_SUPPORTED_P (ERROR_UNEXPECTED) - if (ERROR_ENABLED_P (ERROR_UNEXPECTED)) - { - long lp; - - for (lp = (long) &nilhandle_H; lp <= (long) &lastlowglobal; lp += 2) - if ( lp != (long) &TheZone_H - && lp != (long) &ApplZone_H - && lp != (long) &FSFCBLen - && lp != (long) &SysMap - && lp != (long) SYN68K_TO_US(0x2f6) - && lp != (long) SYN68K_TO_US(0x8e6) - && lp != (long) SYN68K_TO_US(0x900) - && lp != (long) &CurMap - && lp != (long) SYN68K_TO_US(0x8a6) - && lp != (long) SYN68K_TO_US(0x8aa) - && lp != (long) SYN68K_TO_US(0x268) - && lp != (long) SYN68K_TO_US(0x982) - && lp != (long) SYN68K_TO_US(0xaee) - && lp != (long) SYN68K_TO_US(0xcca) - && lp != (long) SYN68K_TO_US(0xd50) - && lp != (long) SYN68K_TO_US(0x18e) - && lp != (long) SYN68K_TO_US(0x190) - && lp != (long) SYN68K_TO_US(0x2f2) - && lp != (long) SYN68K_TO_US(0x11e) - && lp != (long) SYN68K_TO_US(0x15c) - && lp != (long) SYN68K_TO_US(0x27e) - && lp != (long) SYN68K_TO_US(0x31a) - && lp != (long) SYN68K_TO_US(0x82c) - && lp != (long) SYN68K_TO_US(0x82e) - && lp != (long) SYN68K_TO_US(0x830) - && lp != (long) SYN68K_TO_US(0x832) - && lp != (long) SYN68K_TO_US(0xa4a) - && lp != (long) SYN68K_TO_US(0xa52) - && lp != (long) SYN68K_TO_US(0xa56) - && lp != (long) SYN68K_TO_US(0xbf4) - && lp != (long) SYN68K_TO_US(0x828) - && lp != (long) SYN68K_TO_US(0x82a) - && lp != (long) SYN68K_TO_US(0x16c) - ) - if (MR(*(int32 *)lp) >= (int32) MR(ApplZone) - && MR(*(int32 *)lp) < (int32) MR(MR(ApplZone)->bkLim)) - warning_unexpected ("Low global at 0x%lx may point into " - "ApplZone and probably shouldn't.", - (unsigned long) US_TO_SYN68K (lp)); - } -#endif - launchchain(fName, vRefNum, TRUE, &lpb); -} - -A2(PUBLIC trap, void, Launch, StringPtr, fName_arg, INTEGER, vRefNum_arg) -{ -#if 0 - /* NOTE: we're messing with launch between Executor 2 beta 1 and Executor 2 - proper. We really shouldn't do anything differently from what we were - doing before, so we don't have the liberty to do things cleanly */ - - LaunchParamBlockRec pbr; - - memset (&pbr, 0, sizeof pbr); - pbr.launchBlockID = CWC (extendedBlock); - pbr.launchEPBLength = CLC (extendedBlockLen); - pbr.launchControlFlags = CWC (launchNoFileFlags|launchInhibitDaemon); - FSMakeFSSpec (vRefNum_arg, 0, fName_arg, &pbr.launchAppSpec); - pbr.launchAppSpec.vRefNum = vRefNum_arg); - NewLaunch (&pbr); -#else - NewLaunch (fName_arg, vRefNum_arg, 0); -#endif -} diff --git a/src/main.c b/src/main.c index 4b22bb4..50902fc 100644 --- a/src/main.c +++ b/src/main.c @@ -93,6 +93,8 @@ char ROMlib_rcsid_main[] = #include "rsys/appearance.h" #include "rsys/hfs_plus.h" +#include "rsys/check_structs.h" + #include "paramline.h" #if defined (MSDOS) @@ -1266,6 +1268,8 @@ win_drive_to_bit (const char *drive_namep) A2 (PUBLIC, int, main, int, argc, char **, argv) { + check_structs (); + INTEGER i; static unsigned short jmpl_to_ResourceStub[3] = { diff --git a/src/stdfile-new.c b/src/stdfile-new.c deleted file mode 100644 index 1e2de7a..0000000 --- a/src/stdfile-new.c +++ /dev/null @@ -1,2513 +0,0 @@ -/* - * NOTE: currently we only do an automount when crossing a filesystem. - * This is might be bad: currently we're seeing an error when - * we try to open "/tmp" on roland, because 4 has already been - * specified as "/Net" from iclone. I'm really not convinced - * that the proper solution is to do an automount, though. - */ - -/* Copyright 1987 - 1997 by Abacus Research and - * Development, Inc. All rights reserved. - */ - -#if !defined (OMIT_RCSID_STRINGS) -char ROMlib_rcsid_stdfile[] = - "$Id: stdfile-new.c 63 2004-12-24 18:19:43Z ctm $"; -#endif - -/* Forward declarations in StdFilePkg.h (DO NOT DELETE THIS LINE) */ - -#include "rsys/common.h" - -#if defined (LINUX) -#include -#include -#include -#include -#include -#include -#endif - -#include "DialogMgr.h" -#include "FileMgr.h" -#include "EventMgr.h" -#include "StdFilePkg.h" -#include "ControlMgr.h" -#include "MenuMgr.h" -#include "ResourceMgr.h" -#include "ToolboxEvent.h" -#include "ToolboxUtil.h" -#include "MemoryMgr.h" -#include "OSUtil.h" -#include "ScriptMgr.h" - -#include "rsys/cquick.h" -#include "rsys/wind.h" -#include "rsys/hfs.h" -#include "rsys/file.h" -#include "rsys/stdfile.h" -#include "rsys/arrowkeys.h" -#include "rsys/screen.h" -#include "rsys/glue.h" -#include "rsys/resource.h" -#include "rsys/pstuff.h" -#include "rsys/hfs.h" -#include "rsys/time.h" -#include "rsys/flags.h" -#include "rsys/tempalloc.h" -#include "rsys/hook.h" -#include "rsys/toolevent.h" -#include "rsys/license.h" -#include "rsys/string.h" -#include "rsys/dcache.h" -#include "rsys/menu.h" - -#include "rsys/executor.h" - -PUBLIC int nodrivesearch_p = FALSE; - -#if defined (MSDOS) || defined (CYGWIN32) -#include "dosdisk.h" -#include "aspi.h" -#include "rsys/checkpoint.h" -#endif - -typedef enum { original_sf, new_sf, new_custom_sf } sf_flavor_t; - -typedef union -{ - SFReply *oreplyp; - StandardFileReply *nreplyp; -} -reply_u; - -typedef union -{ - ProcPtr oflfilef; - FileFilterYDProcPtr cflfilef; -} -file_filter_u; - -typedef union -{ - ProcPtr ofilterp; - ModalFilterYDProcPtr cfilterp; -} -filter_u; - -typedef union -{ - ProcPtr odh; - DlgHookYDProcPtr cdh; -} -dialog_hook_u; - -typedef struct { - sf_flavor_t flavor; - reply_u flreplyp; - ControlHandle flsh; - INTEGER flnmfil; - INTEGER flnmlin; - INTEGER fllinht; - INTEGER flascent; - INTEGER flsel; - Rect flrect; - Rect flcurdirrect; - struct flinfostr { - INTEGER floffs; - INTEGER flicns; - } **flinfo; - char **flstrs; - file_filter_u flfilef; - INTEGER flnumt; - OSType * fltl; - ControlHandle flch; - INTEGER flgraynondirs; - Str255 flcurdirname; - filter_u magicfp; - INTEGER fl_cancel_item; - UNIV Ptr mydata; -} fltype; - -A1(PRIVATE, INTEGER, movealert, INTEGER, id) -{ - Handle h; - INTEGER dh, dv; - Rect *rp; - - h = GetResource(TICK("ALRT"), id); - if (!(*h).p) - LoadResource(h); - rp = (Rect *) STARH(h); - dh = CW(rp->right) - CW(rp->left); - dv = CW(rp->bottom) - CW(rp->top); - rp->left = CWC(150); - rp->top = CWC(30); - rp->right = CW(150 + dh); - rp->bottom = CW(30 + dv); - return(Alert(id, (ProcPtr)0)); -} - -#define SICONS -15744 - -A1(PRIVATE, void, drawminiicon, INTEGER, icon) -{ - Handle h; - BitMap bm; - Rect r; - - h = ROMlib_getrestid(TICK("SICN"), SICONS); - if (!h) -/*-->*/ return; /* badness */ - HLock(h); - bm.baseAddr = RM((Ptr) STARH(h) + icon * 16 * 16 / 8); - bm.rowBytes = CWC(2); - bm.bounds.left = bm.bounds.top = CWC(0); - bm.bounds.right = bm.bounds.bottom = CWC(16); - r.top = PORT_PEN_LOC (thePort).v; - r.left = PORT_PEN_LOC (thePort).h; - r.bottom = CW(CW(r.top) + 16); - r.right = CW(CW(r.left) + 16); - CopyBits(&bm, PORT_BITS_FOR_COPY (thePort), - &bm.bounds, &r, srcCopy, NULL); - HUnlock(h); -} - -/* - * NOTE: the Rect pointed to below has a normal top, left and right, - * BUT the bottom is the amount to add to the top for drawing - * text, not the real bottom. - */ - -A3(PRIVATE, void, drawinboxwithicon, StringPtr, str, Rect *, rp, INTEGER, icon) -{ - Rect r; - INTEGER width, strlen, strwidths[255], lengthavail, *widp; - static char *ellipsis = "\003..."; - - /* - * Note: the ellipsis code is a bit shabby, not truncating at a character - * boundary, nor leaving space on either side, but for now, it's - * ok. - */ - - MoveTo(CW(rp->left) + 2, CW(rp->top)); - drawminiicon(icon); - MoveTo(CW(rp->left) + 2 + 16 + 3 , CW(rp->top) + CW(rp->bottom)-1); /* see note above */ - r.left = rp->left; - r.right = rp->right; - r.top = rp->top; - r.bottom = CWC(32766); - ClipRect(&r); - strlen = *str; - MeasureText(strlen, (Ptr) (str + 1), (Ptr) strwidths); - lengthavail = CW(rp->right) - (CW(rp->left) + 2 + 16 + 3); - if (CW(strwidths[strlen]) > lengthavail) { - width = StringWidth((StringPtr) ellipsis); -/* 4 might be the space on the right of the ellipsis. */ -/* TODO: figure out exactly what the number is. */ - lengthavail -= (width + 4); - widp = strwidths; - while (CW(*++widp) < lengthavail) - DrawChar(*++str); - DrawString((StringPtr) ellipsis); - } else - DrawString(str); - r.top = CWC(-32767); - r.left = CWC(-32767); - r.right = CWC(32766); - ClipRect(&r); -} - -A2(PRIVATE, void, safeflflip, fltype *, f, INTEGER, sel) -{ - Rect r; - INTEGER fltop = GetCtlValue(f->flsh); - - if (sel >= fltop && sel < fltop + f->flnmlin) { - r.left = f->flrect.left; - r.right = f->flrect.right; - r.top = CW(CW(f->flrect.top) + (sel - fltop) * f->fllinht); - r.bottom = CW(CW(r.top) + f->fllinht); - if (EmptyRgn(MR(((WindowPeek)thePort)->updateRgn))) /* stuff to draw? */ - InvertRect(&r); /* no: we can flip */ - else - InvalRect(&r); /* yes: flip later */ - } -} - -#define GRAYBIT (1 << 5 ) -#define ICONMASK (~GRAYBIT) - -A3(PRIVATE, void, flupdate, fltype *, f, INTEGER, st, INTEGER, n) -{ - INTEGER i; - struct flinfostr *ip; - INTEGER sel = f->flsel; - INTEGER fltop; - Rect r; - - fltop = GetCtlValue(f->flsh); - r.top = CW(CW(f->flrect.top) + (st - fltop) * f->fllinht); - r.bottom = CW(f->flascent); - r.left = f->flrect.left; - r.right = f->flrect.right; - - ip = MR(*f->flinfo) + st; - HLock((Handle) f->flstrs); - for (i = st; i < st + n && i < fltop + f->flnmlin && i < f->flnmfil; i++) { - drawinboxwithicon((StringPtr) (MR(*f->flstrs) + ip->floffs), &r, - ip->flicns & ICONMASK); - if (ip->flicns & GRAYBIT) { - r.bottom = CW(CW(r.top) + f->fllinht); - PenMode(notPatBic); - PenPat(gray); - PaintRect(&r); - PenPat(black); - PenMode(patCopy); - r.bottom = CW(f->flascent); - } - ip++; - r.top = CW(CW(r.top) + (f->fllinht)); - } - HUnlock((Handle) f->flstrs); - if (sel >= st && sel < st + n) - safeflflip(f, sel); -} - -A3(PRIVATE, void, flscroll, fltype *, f, INTEGER, from, INTEGER, to) -{ - RgnHandle rh; - INTEGER toscroll; - - if (from != to) { - rh = NewRgn(); - ScrollRect(&f->flrect, 0, (from - to) * f->fllinht, rh); - if (to > from) { - toscroll = to - from; - if (toscroll >= f->flnmlin) - flupdate(f, to, f->flnmlin); - else - flupdate(f, from+f->flnmlin, toscroll); - } else { - toscroll = from - to; - if (toscroll > f->flnmlin) - toscroll = f->flnmlin; - flupdate(f, to, toscroll); - } - DisposeRgn(rh); - } -} - -#define CTLFL(sh) \ - ((fltype *)(long) MR(MR((WindowPeek)STARH((sh))->contrlOwner)->refCon)) - -/* - * this hack is necessary because Excel 4 can bring up a dialog on top of - * stdfile at a time when the refcon has been set to 'stdf'. - */ - -static LONGINT emergency_save_ref_con; - -PRIVATE fltype * -WINDFL (void *dp) -{ - fltype *retval; - - retval = (fltype *) (long) MR(((WindowPeek)dp)->refCon); - if ((long) retval == (long) TICK("stdf")) - retval = (fltype *) emergency_save_ref_con; - return retval; -} - -#if 0 -#define WINDFL(dp) \ - ((fltype *)(long) MR(((WindowPeek)dp)->refCon)) -#endif - -P2 (PUBLIC, pascal void, ROMlib_stdftrack, ControlHandle, sh, INTEGER, part) -{ - const uint32 min_between_scroll_msecs = 100; - static uint32 last_scroll_msecs; - uint32 current_msecs; - int16 from, pg; - - current_msecs = msecs_elapsed (); - - if (current_msecs - min_between_scroll_msecs < last_scroll_msecs) - return; - else - last_scroll_msecs = current_msecs; - - from = GetCtlValue (sh); - pg = CTLFL(sh)->flnmlin - 1; - switch (part) - { - case inUpButton: - SetCtlValue(sh, from-1); - break; - case inDownButton: - SetCtlValue(sh, from+1); - break; - case inPageUp: - SetCtlValue(sh, from-pg); - break; - case inPageDown: - SetCtlValue(sh, from+pg); - break; - } - flscroll (CTLFL (sh), from, GetCtlValue (sh)); -} - -PRIVATE INTEGER cachedvrn = 32767; -PRIVATE INTEGER savesel = -1; -PRIVATE LONGINT oldticks = -1000; -PRIVATE LONGINT lastkeydowntime = 0; -PRIVATE Str255 prefix = { 0 }; -PRIVATE char **holdstr; - -PUBLIC void ROMlib_init_stdfile(void) -{ - cachedvrn = 32767; - savesel = -1; - oldticks = -1000; - lastkeydowntime = 0; - prefix[0] = 0; - holdstr = 0; -} - -A1(PRIVATE, StringPtr, getdiskname, BOOLEAN *, ejectablep) -{ - static BOOLEAN ejectable; - static Str255 retval; - ParamBlockRec pbr; - - if (SFSaveDisk != cachedvrn) { - OSErr err; - - pbr.volumeParam.ioNamePtr = RM(&retval[0]); - pbr.volumeParam.ioVolIndex = 0; - pbr.volumeParam.ioVRefNum = CW(-CW(SFSaveDisk)); - err = PBGetVInfo(&pbr, FALSE); - cachedvrn = SFSaveDisk; - if (err == noErr) - ejectable = !(pbr.volumeParam.ioVAtrb & CWC(VNONEJECTABLEBIT)); - else - { - warning_unexpected ("surprising PBGetVInfo retval = %d\n", err); - ejectable = FALSE; - } - } - *ejectablep = ejectable; - return retval; -} - -A1(PRIVATE, void, drawjobberattop, DialogPeek, dp) -{ - INTEGER icon; - Rect *rp; - fltype *flp; - INTEGER savebottom; - BOOLEAN ejectable; - PenState ps; - - GetPenState(&ps); - PenNormal(); - if (CL(CurDirStore) == 2) { -#if 1 -/* TODO: ask cliff about a better way to do this */ - /* unused = */ getdiskname( &ejectable ); - icon = ejectable ? MICONFLOPPY : MICONDISK; -#else /* 0 */ - icon = MICONDISK; -#endif /* 0 */ - } else - icon = MICONOFOLDER; - flp = WINDFL(dp); - rp = &flp->flcurdirrect; - savebottom = rp->bottom; - rp->bottom = CW(flp->flascent); - rp->left = CW(CW(rp->left) + (2)); - drawinboxwithicon(flp->flcurdirname, rp, icon); - rp->left = CW(CW(rp->left) - (2)); - rp->bottom = savebottom; - FrameRect(rp); - MoveTo(CW(rp->left)+1, CW(rp->bottom)); - LineTo(CW(rp->right), CW(rp->bottom)); - LineTo(CW(rp->right), CW(rp->top)+1); - SetPenState(&ps); -} - -A1(PRIVATE, LONGINT, getdirid, StringPtr, fname) -{ - CInfoPBRec hpb; - LONGINT retval; - OSErr err; - - hpb.dirInfo.ioCompletion = 0; - hpb.dirInfo.ioNamePtr = RM(fname); - hpb.dirInfo.ioVRefNum = CW(-CW(SFSaveDisk)); - hpb.dirInfo.ioFDirIndex = 0; - hpb.dirInfo.ioDrDirID = CurDirStore; - err = PBGetCatInfo(&hpb, FALSE); - if (err == noErr) - retval = CL (hpb.dirInfo.ioDrDirID); - else - { - warning_unexpected ("PBGetCatInfo return value err = %d\n", err); - retval = 2; /* known good id ... an error might be better here */ - } - return retval; -} - -#define MAXPREFIX 64 - -PRIVATE void -set_type_and_name (fltype *f, OSType type, Str255 name) -{ - switch (f->flavor) - { - case original_sf: - f->flreplyp.oreplyp->fType = CL (type); - str63assign (f->flreplyp.oreplyp->fName, name); - break; - case new_sf: - case new_custom_sf: - f->flreplyp.nreplyp->sfType = CL (type); - str63assign (f->flreplyp.nreplyp->sfFile.name, name); - f->flreplyp.nreplyp->sfIsFolder = !!type; - break; - default: - warning_unexpected ("flavor = %d", f->flavor); - break; - } -} - -A2(PRIVATE, void, settype, fltype *, f, INTEGER, newsel) -{ - char *ip; - - ip = MR(*f->flstrs) + MR(*f->flinfo)[newsel].floffs; - if (MR(*f->flinfo)[newsel].flicns == MICONCFOLDER) - set_type_and_name (f, getdirid ((StringPtr) ip), (StringPtr) ""); - else - set_type_and_name (f, 0, ip); -} - -A2(PRIVATE, INTEGER, flwhich, fltype *, f, Point, p) -{ - INTEGER retval; - INTEGER bump, from; - - if (!PtInRect(p, &f->flrect)) { - bump = 0; - if (p.v < CW(f->flrect.top)) - bump = -1; - else if (p.v >= CW(f->flrect.bottom)) - bump = 1; - if (bump) { - from = GetCtlValue(f->flsh); - SetCtlValue(f->flsh, from+bump); - flscroll(f, from, GetCtlValue(f->flsh)); - } -/*-->*/ return(-1); - } - retval = (p.v - CW(f->flrect.top)) / f->fllinht + GetCtlValue(f->flsh); - if (retval >= f->flnmfil || MR(*f->flinfo)[retval].flicns & GRAYBIT) -/*-->*/ retval = -1; - return(retval); -} - -A3(PRIVATE, void, flmouse, fltype *, f, Point, p, ControlHandle, ch) -{ - INTEGER newsel; - EventRecord evt; - boolean_t done; - boolean_t have_travelled; - boolean_t seen_up_already; - - evt.where = p; - have_travelled = FALSE; - seen_up_already = FALSE; - do { - GlobalToLocal(&evt.where); - p.h = CW(evt.where.h); - p.v = CW(evt.where.v); - if ((newsel = flwhich(f, p)) != f->flsel) { - have_travelled = TRUE; - if (f->flsel != -1) { - safeflflip(f, f->flsel); - if (newsel == -1) { - if (!f->flgraynondirs) - HiliteControl(ch, 255); - set_type_and_name (f, 0, (StringPtr) ""); - } - } - if (newsel != -1) { - safeflflip(f, newsel); - if (f->flsel == -1) - HiliteControl(ch, 0); - settype(f, newsel); - } - f->flsel = newsel; - } - if (!ROMlib_sticky_menus_p) - done = GetNextEvent(mUpMask, &evt); - else { - if (OSEventAvail (mUpMask, &evt)) { - if (seen_up_already || have_travelled) - done = TRUE; - else { - done = FALSE; - GetOSEvent (mUpMask, &evt); - seen_up_already = TRUE; - } - } - if (!done && OSEventAvail (mDownMask, &evt)) { - GetOSEvent (mDownMask, &evt); - done = f->flsel != -1; - } - } - } while (!done); -} - -typedef pascal BOOLEAN (*filtp)(DialogPtr dp, EventRecord *evp, INTEGER *ith); - -#define CALLFILTERPROC(dp, evt, ith, fp) \ - ROMlib_CALLFILTERPROC((dp), (evt), (ith), (filtp) (fp)) - -A4(static inline, BOOLEAN, ROMlib_CALLFILTERPROC, DialogPtr, dp, - EventRecord *, evtp, INTEGER, *ith, filtp, fp) -{ - BOOLEAN retval; - - ROMlib_hook(stdfile_filtnumber); - HOOKSAVEREGS(); - retval = CToPascalCall(fp, CTOP_SectRect, dp, evtp, ith); - HOOKRESTOREREGS(); - return retval; -} - -#if 0 /* Needed to generate a CTOP value */ -P4 (PUBLIC pascal trap, BOOLEAN, unused_stdfile, DialogPtr, dp, EventRecord *, - evp, INTEGER *, ith, UNIV Ptr, data) -{ -} -#endif - -typedef pascal BOOLEAN (*custom_filtp)(DialogPtr dp, EventRecord *evp, - INTEGER *ith, UNIV Ptr data); - -#define CALL_NEW_FILTER_PROC(dp, evt, ith, data, fp) \ - ROMlib_CALL_NEW_FILTER_PROC((dp), (evt), (ith), (data), \ - (custom_filtp) (fp)) - -PRIVATE BOOLEAN -ROMlib_CALL_NEW_FILTER_PROC (DialogPtr dp, EventRecord *evtp, INTEGER *ith, - UNIV Ptr data, custom_filtp fp) -{ - BOOLEAN retval; - - ROMlib_hook(stdfile_filtnumber); - HOOKSAVEREGS(); - retval = CToPascalCall(fp, CTOP_unused_stdfile, dp, evtp, ith, data); - HOOKRESTOREREGS(); - return retval; -} - -A1(PRIVATE, void, getcurname, fltype *, f) -{ - int w; - CInfoPBRec hpb; - Rect *r; - OSErr err; - - hpb.dirInfo.ioCompletion = 0; - hpb.dirInfo.ioNamePtr = RM(&f->flcurdirname[0]); - f->flcurdirname[0] = 0; - hpb.dirInfo.ioVRefNum = CW(-CW(SFSaveDisk)); - hpb.dirInfo.ioFDirIndex = CWC(-1); - hpb.dirInfo.ioDrDirID = CurDirStore; - err = PBGetCatInfo(&hpb, FALSE); - if (err != noErr) - { - warning_unexpected ("PBGetCatInfo err = %d\n", err); - str255_from_c_string (f->flcurdirname, "?error?"); - } - r = &f->flrect; - w = StringWidth(f->flcurdirname) + 2 + 16 + 3 + 2 + 2 + 4; -#if 1 - if (w > CW(r->right) - CW(r->left) + 17) { - f->flcurdirrect.left = r->left; - f->flcurdirrect.right = CW(CW(r->right) + 17); - } else { - f->flcurdirrect.left = CW((CW(r->left) + CW(r->right) + 17 - w) / 2 - 2); - f->flcurdirrect.right = CW(CW(f->flcurdirrect.left) + w); - } -#else /* 1 */ - f->flcurdirrect.left = (CW(r->left) + CW(r->right) + 17 - w) / 2 - 2; - f->flcurdirrect.right = CW(CW(f->flcurdirrect.left) + w); -#endif /* 1 */ -} - -A1(PRIVATE, void, flfinit, fltype *, fp) -{ - DisposeControl(fp->flsh); - DisposHandle((Handle) fp->flinfo); - DisposHandle((Handle) fp->flstrs); -} - -A3(PRIVATE, void, flinsert, fltype *, f, StringPtr, p, INTEGER, micon) -{ - struct flinfostr finfo; - - finfo.floffs = GetHandleSize((Handle) f->flstrs); - finfo.flicns = micon; - PtrAndHand((Ptr) p, (Handle) f->flstrs, (LONGINT)U(p[0])+1); - PtrAndHand((Ptr) &finfo, (Handle) f->flinfo, - (LONGINT)sizeof(struct flinfostr)); - ++f->flnmfil; -} - -A3(PRIVATE, int, typeinarray, OSType, ft, INTEGER, numt, SFTypeList, tl) -{ - OSType *ostp = tl; - - while (numt--) - if (ft == *ostp++) -/*-->*/ return(TRUE); - return(FALSE); -} - -/* - * NOTE: stdfcmp is called from qsort, so we can't smash d2. - */ - -/* ip1 and ip2 would really be "void *" in ANSI C */ - -A2(PRIVATE, LONGINT, stdfcmp, char *, ip1, char *, ip2) -{ - struct flinfostr *fp1, *fp2; - LONGINT retval; - - fp1 = (struct flinfostr *) ip1; - fp2 = (struct flinfostr *) ip2; - retval = ROMlib_strcmp((StringPtr) (MR(*holdstr) + fp1->floffs), - (StringPtr) (MR(*holdstr) + fp2->floffs)); - return retval; -} - -typedef pascal BOOLEAN (*filefiltp)( ParmBlkPtr pbp ); - -#define CALLFILEFILT(pbp, fp) ROMlib_CALLFILEFILT((pbp), (filefiltp)(fp)) - -A2(static inline, BOOLEAN, ROMlib_CALLFILEFILT, ParmBlkPtr, pbp, filefiltp, fp) -{ - BOOLEAN retval; - - ROMlib_hook(stdfile_filefiltnumber); - HOOKSAVEREGS(); - retval = CToPascalCall(fp, CTOP_SystemEvent, pbp); - HOOKRESTOREREGS(); - return retval; -} - -typedef pascal BOOLEAN (*custom_file_filtp) (ParmBlkPtr pbp, UNIV Ptr data); - -#define CALL_CUSTOM_FILE_FILT(pbp, data, fp) \ - ROMlib_CALL_CUSTOM_FILE_FILT ((pbp), (data), (custom_file_filtp) (fp)) - -PRIVATE BOOLEAN -ROMlib_CALL_CUSTOM_FILE_FILT (ParmBlkPtr pbp, UNIV Ptr data, - custom_file_filtp fp) -{ - BOOLEAN retval; - - ROMlib_hook(stdfile_filefiltnumber); - HOOKSAVEREGS(); - retval = CToPascalCall(fp, CTOP_GetAuxCtl, pbp, data); - HOOKRESTOREREGS(); - return retval; -} - -PRIVATE boolean_t -passes_filter (fltype *f, CInfoPBRec *cinfop, INTEGER numt) -{ - boolean_t retval; - - switch (f->flavor) - { - case original_sf: - /* NOTE: the code for original_sf was changed after we ran into - some trouble with Accordance. It's not clear whether or not - the new code here should also be used for new_sf. */ - retval = (!f->flfilef.oflfilef - || (numt == 0 - && (cinfop->hFileInfo.ioFlAttrib & ATTRIB_ISADIR)) - || !CALLFILEFILT ((ParmBlkPtr) cinfop, f->flfilef.oflfilef)); - case new_sf: - retval = (!f->flfilef.oflfilef - || (cinfop->hFileInfo.ioFlAttrib & ATTRIB_ISADIR) - || !CALLFILEFILT ((ParmBlkPtr) cinfop, f->flfilef.oflfilef)); - break; - case new_custom_sf: - retval = (!f->flfilef.cflfilef - || !CALL_CUSTOM_FILE_FILT ((ParmBlkPtr) cinfop, f->mydata, - f->flfilef.cflfilef)); - break; - default: - warning_unexpected ("flavor = %d", f->flavor); - retval = TRUE; - break; - } - return retval; -} - -A1(PRIVATE, void, flfill, fltype *, f) -{ - CInfoPBRec pb; - OSErr err; - Str255 s; - int micon; - CursHandle watchh; - INTEGER errcount; - INTEGER dirindex; - - SetCursor(STARH((watchh = GetCursor(watchCursor)))); - - pb.hFileInfo.ioNamePtr = RM(&s[0]); - pb.hFileInfo.ioVRefNum = CW(-CW(SFSaveDisk)); - err = noErr; - errcount = 0; - for (dirindex = 1; err != fnfErr && errcount != 3; dirindex++) { - pb.hFileInfo.ioFDirIndex = CW(dirindex); - pb.hFileInfo.ioDirID = CurDirStore; - err = PBGetCatInfo(&pb, FALSE); - if (err) { - if (err != fnfErr) { - warning_unexpected ("PBGetCatInfo err = %d\n", err); - ++errcount; - /* register int d7 = err; */ - - } - } else { - errcount = 0; - if (f->flnumt <= 0 || (pb.hFileInfo.ioFlAttrib & ATTRIB_ISADIR) || - typeinarray(pb.hFileInfo.ioFlFndrInfo.fdType, f->flnumt, - f->fltl)) - if (passes_filter (f, &pb, f->flnumt)) - { - if (pb.hFileInfo.ioFlAttrib & ATTRIB_ISADIR) - micon = MICONCFOLDER; - else if (pb.hFileInfo.ioFlFndrInfo.fdType == TICKX("APPL")) - micon = MICONAPP | f->flgraynondirs; - else - micon = MICONLETTER | f->flgraynondirs; - flinsert(f, MR(pb.hFileInfo.ioNamePtr), micon); - } - } - } - if (f->flnmfil > f->flnmlin) { - SetCtlMax(f->flsh, f->flnmfil - f->flnmlin); - SetCtlValue(f->flsh, 0); - } else - SetCtlMax(f->flsh, 0); - - if (f->flnmfil > 0) { - holdstr = f->flstrs; - qsort(MR(*f->flinfo), f->flnmfil, sizeof(**f->flinfo), (void *) stdfcmp); - if (!(MR(*f->flinfo)[0].flicns&GRAYBIT) && !f->flgraynondirs) { - f->flsel = 0; - settype(f, 0); - HiliteControl(f->flch, 0); - } - } else - if (!f->flgraynondirs) - HiliteControl(f->flch, 255); - /* i'm not sure this is right, but there is no obvious way to - save/restore the cursor */ - SetCursor (&arrowX); -} - -/* - * ROMlib_filebox should be renamed to reflect the fact that it also draws the - * dotted line (whopee!) - */ - -P2(PUBLIC, pascal void, ROMlib_filebox, DialogPeek, dp, INTEGER, which) -{ - HIDDEN_Handle h; - Rect r, r2; - INTEGER i; - int width, strwidth, offset; - StringPtr diskname; - HIDDEN_Handle ejhand; - BOOLEAN ejectable; - PenState ps; - - GetPenState(&ps); - PenNormal(); - - GetDItem((DialogPtr) dp, which, &i, &h, &r); -/* h.p = CL(h.p); we don't really use h */ - switch (which) { - case getNmList: - case putNmList: - FrameRect(&r); - flupdate(WINDFL(dp), GetCtlValue(WINDFL(dp)->flsh), - WINDFL(dp)->flnmlin); - break; - case getDotted: - FillRect(&r, gray); - break; - case getDiskName: -/* case putDiskName: getDiskName and putDiskName are the same */ - EraseRect(&r); - width = CW(r.right) - CW(r.left); - diskname = getdiskname( &ejectable ); - GetDItem((DialogPtr) dp, putEject, &i, &ejhand, &r2); - ejhand.p = MR(ejhand.p); - if (ejectable) - HiliteControl((ControlHandle) ejhand.p, 0); - else - HiliteControl((ControlHandle) ejhand.p, 255); - strwidth = StringWidth(diskname) + 2 + 16 + 3; - offset = (width - strwidth) / 2; - if (offset < 3) - r.left = CW(CW(r.left) + (3)); - else - r.left = CW(CW(r.left) + (offset)); - r.bottom = CW(WINDFL(dp)->flascent); - drawinboxwithicon(diskname, &r, ejectable ? MICONFLOPPY : MICONDISK); - break; - } - SetPenState(&ps); -} - - -A2(PRIVATE, void, realcd, DialogPeek, dp, LONGINT, dir) -{ - fltype *fp; - - CurDirStore = CL(dir); - fp = WINDFL(dp); - SetHandleSize((Handle) fp->flinfo, (Size) 0); - SetHandleSize((Handle) fp->flstrs, (Size) 0); - fp->flnmfil = 0; - fp->flsel = -1; - set_type_and_name (fp, 0, (StringPtr) ""); - flfill(fp); - fp->flcurdirrect.right = CW(CW(fp->flcurdirrect.right ) + 1); - fp->flcurdirrect.bottom = CW(CW(fp->flcurdirrect.bottom) + 1); - EraseRect(&fp->flcurdirrect); - getcurname(fp); - fp->flcurdirrect.bottom = CW(CW(fp->flcurdirrect.bottom) - 1); - /* don't need to do right; getcurname does */ - drawjobberattop(dp); - C_ROMlib_filebox(dp, getDiskName); - EraseRect(&fp->flrect); - if (fp->flgraynondirs) - C_ROMlib_filebox(dp, putNmList); - else - C_ROMlib_filebox(dp, getNmList); -} - -A1(PRIVATE, LONGINT, getparent, LONGINT, dirid) -{ - OSErr err; - CInfoPBRec cb; - LONGINT retval; - - cb.dirInfo.ioCompletion = 0; - cb.dirInfo.ioNamePtr = 0; - cb.dirInfo.ioVRefNum = CW(-CW(SFSaveDisk)); - cb.dirInfo.ioFDirIndex = -1; - cb.dirInfo.ioDrDirID = CL(dirid); - err = PBGetCatInfo(&cb, FALSE); - if (err == noErr) - retval = CL(cb.dirInfo.ioDrParID); - else - { - warning_unexpected ("PBGetCatInfo return = %d\n", err); - retval = 2; - } - return retval; -} - -PRIVATE BOOLEAN findparent(INTEGER *vrefp, LONGINT *diridp) -{ - HVCB *vcbp; - BOOLEAN retval; - struct stat sbuf; - char *namecpy, *slashp; - INTEGER namelen; - - vcbp = ROMlib_vcbbyvrn(CW(*vrefp)); - retval = FALSE; - if (!vcbp->vcbCTRef) { - namelen = strlen(((VCBExtra *) vcbp)->unixname); - if (namelen != 1 + SLASH_CHAR_OFFSET) { /* i.e. "/" */ - namecpy = alloca(namelen + 1); - strcpy(namecpy, ((VCBExtra *) vcbp)->unixname); - slashp = strrchr(namecpy, '/'); - if (slashp == namecpy + SLASH_CHAR_OFFSET) { - slashp[1] = 0; - } else { - slashp[0] = 0; - } - if (Ustat(namecpy, &sbuf) == 0 && - (vcbp = ROMlib_vcbbybiggestunixname(namecpy))) { - *vrefp = vcbp->vcbVRefNum; - *diridp = CL((LONGINT) sbuf.st_ino); - retval = TRUE; - } - } - } - return retval; -} - -A1(PRIVATE, BOOLEAN, moveuponedir, DialogPtr, dp) -{ - LONGINT parent; - INTEGER vrn; - BOOLEAN retval; - - parent = getparent(CL(CurDirStore)); - if (parent != CL(CurDirStore) && parent != 1) { - CurDirStore = CL(parent); - retval = TRUE; - } else { - vrn = CW(-CW(SFSaveDisk)); - retval = findparent(&vrn, &CurDirStore); - SFSaveDisk = CW(-CW(vrn)); - } - return retval; -} - -BOOLEAN keyarrow(fltype *fl, INTEGER incr) /* -1: up, 1: down */ -{ - INTEGER nsel, oldval, newval; - struct flinfostr *flp; -/* - * If there's no selection we start at the top or bottom, depending on - * whether we're going down or p - */ - if (fl->flsel == -1) - nsel = incr > 0 ? 0 : fl->flnmfil - 1; - else - nsel = fl->flsel + incr; - -/* - * If we land on a grayed out file, advance until non-grayed - */ - - for (flp = MR(*fl->flinfo) + nsel; - (flp->flicns & GRAYBIT) && nsel >= 0 && nsel < fl->flnmfil; - nsel += incr, flp += incr) - ; - -/* - * If we don't find a non-grayed out entry, we leave - */ - if (nsel < 0 || nsel >= fl->flnmfil) -/*-->*/ return FALSE; - -/* - * Figure out what should be visible and scroll there if necessary - */ - - newval = oldval = GetCtlValue(fl->flsh); - if (nsel < oldval) - newval = nsel; - else if (nsel >= oldval + fl->flnmlin) - newval = nsel - fl->flnmlin + 1; - if (newval != oldval) { - SetCtlValue(fl->flsh, newval); - flscroll(fl, oldval, newval); - } - -/* - * Get rid of the previously selected rectangle - */ - if (fl->flsel != -1) - safeflflip(fl, fl->flsel); -/* - * Flip the new rectangle, set up the type information and make assignment - */ - safeflflip(fl, nsel); - settype(fl, nsel); - fl->flsel = nsel; - return TRUE; -} - -PRIVATE boolean_t -folder_selected_p (fltype *fl) -{ - boolean_t retval; - - switch (fl->flavor) - { - case original_sf: - retval = !!fl->flreplyp.oreplyp->fType; - break; - case new_sf: - case new_custom_sf: - retval = fl->flreplyp.nreplyp->sfIsFolder; - break; - default: - warning_unexpected ("flavor = %d", fl->flavor); - retval = FALSE; - break; - } - - return retval; -} - -PRIVATE INTEGER -call_magicfp (fltype *fl, DialogPeek dp, EventRecord *evt, INTEGER *ith) -{ - INTEGER retval; - - switch (fl->flavor) - { - case original_sf: - case new_sf: - retval = fl->magicfp.ofilterp - ? CALLFILTERPROC ((DialogPtr) dp, evt, ith, fl->magicfp.ofilterp) - : FALSE; - break; - case new_custom_sf: - retval = fl->magicfp.cfilterp - ? CALL_NEW_FILTER_PROC ((DialogPtr) dp, evt, ith, fl->mydata, - fl->magicfp.cfilterp) - : FALSE; - break; - default: - warning_unexpected ("flavor = %d", fl->flavor); - retval = FALSE; - } - - return retval; -} - -#define keydownbit 0x1000 - -P3(PUBLIC, pascal INTEGER, ROMlib_stdffilt, DialogPeek, dp, - EventRecord *, evt, INTEGER *, ith) /* handle disk insert */ -{ - LONGINT ticks; - INTEGER i, from; - HIDDEN_ControlHandle h; - Rect r; - Point p; - INTEGER t; - fltype *fl; - INTEGER opentoken; - struct flinfostr *flp, *flep; - INTEGER nsel, fltop; - INTEGER part; - INTEGER retval, retval2; - - fl = WINDFL(dp); - opentoken = getOpen; /* getOpen and putSave are both 1 */ - retval = FALSE; - switch (CW(evt->what)) { - case keyDown: - *ith = CW((CL(evt->message) & 0xFF) + keydownbit); - switch (CL(evt->message) & 0xFF) { - case '\r' : - GetDItem((DialogPtr) dp, CW(dp->aDefItem), &i, (HIDDEN_Handle *) &h, &r); - h.p = MR(h.p); - if (Hx(h.p, contrlVis) && U(Hx(h.p, contrlHilite)) != 255) - { - prefix[0] = 0; - oldticks = -1000; - *ith = CW(opentoken); - retval = -1; -#if !defined(NEXTSTEP) - HiliteControl(h.p, inButton); - Delay((LONGINT)5, (LONGINT *) 0); - HiliteControl(h.p, 0); -#endif - } - break; - case ASCIIUPARROW: - if (CW(evt->modifiers) & cmdKey) - *ith = CWC(getDiskName); /* the same as putDiskName */ - else - keyarrow(fl, -1); - retval = -1; - break; - case ASCIIDOWNARROW: - if ((CW(evt->modifiers) & cmdKey) && fl->flsel != -1 && - (MR(*fl->flinfo) + fl->flsel)->flicns == MICONCFOLDER) { - prefix[0] = 0; - oldticks = -1000; - *ith = CWC(opentoken); - } else - keyarrow(fl, 1); - retval = -1; - break; - case '\t': - *ith = CWC(putDrive); /* PutDrive is 6 which is also getDrive. */ - retval = -1; - break; - case '.': - if (evt->modifiers & CWC(cmdKey)) - { - *ith = CW(fl->fl_cancel_item); - retval = -1; - break; - } - default: -/* - * The Cx(dp->editField) check was made to get HFS_XFer to work. There - * may be a better place to put it, but not enough tests have been done - * to say where. - */ - if (!fl->flgraynondirs && dp->editField == -1) { - flep = MR(*fl->flinfo) + fl->flnmfil - 1; - if (CL(evt->when) > lastkeydowntime + CL(DoubleTime)) { - flp = MR(*fl->flinfo); - prefix[0] = 0; - oldticks = -1000; - } else - flp = MR(*fl->flinfo) + ((fl->flsel) == -1 ? 0 : fl->flsel); - lastkeydowntime = CL(evt->when); - prefix[++prefix[0]] = CL(evt->message) & 0xff; - while (flp < flep && - RelString((StringPtr) (MR(*fl->flstrs) + - flp->floffs), prefix, FALSE, TRUE) < 0) - ++flp; - nsel = flp - MR(*fl->flinfo); - if (nsel != fl->flsel) { - safeflflip(fl, fl->flsel); - fltop = GetCtlValue(fl->flsh); - if (nsel < fltop || nsel >= fltop + fl->flnmlin) { - SetCtlValue(fl->flsh, nsel - fl->flnmlin / 2); - flscroll(fl, fltop, GetCtlValue(fl->flsh)); - } - safeflflip(fl, fl->flsel = nsel); - settype(fl, nsel); - } - retval = -1; - } - break; - } - break; - case mouseDown: - p = evt->where; - GlobalToLocal(&p); - p.h = CW(p.h); - p.v = CW(p.v); - if (PtInRect(p, &fl->flrect)) { - GetDItem((DialogPtr) dp, getOpen, &i, (HIDDEN_Handle *) &h, &r); - h.p = MR(h.p); - flmouse(fl, evt->where, h.p); - ticks = TickCount(); - if (fl->flsel != -1 && savesel == fl->flsel && - (ticks < oldticks + CL(DoubleTime))) { - prefix[0] = 0; - *ith = CWC(opentoken); - oldticks = -1000; - retval = -1; - } else - oldticks = ticks; - savesel = fl->flsel; - } else if ((t = TestControl(fl->flsh, p))) { - if (t == inThumb) { - from = GetCtlValue(fl->flsh); - TrackControl(fl->flsh, p, (ProcPtr) 0); - flscroll(fl, from, GetCtlValue(fl->flsh)); - } else - TrackControl(fl->flsh, p, (ProcPtr) P_ROMlib_stdftrack); - } else if (PtInRect(p, &fl->flcurdirrect)) { - *ith = CWC(FAKECURDIR); - retval = -1; - } else { - GetDItem((DialogPtr) dp, getOpen, &i, (HIDDEN_Handle *) &h, &r); - h.p = MR(h.p); - if ((part = TestControl(h.p, p)) && - TrackControl(h.p, p, (ProcPtr) 0)) { - prefix[0] = 0; - oldticks = -1000; - *ith = CWC(opentoken); - retval = -1; - } - } - break; - case nullEvent: - *ith = CWC(100); - retval = -1; - break; - case updateEvt: - if ((DialogPeek) MR(evt->message) == dp) - drawjobberattop(dp); - break; - } - retval2 = call_magicfp (fl, dp, evt, ith); - - if (*ith == CWC(getOpen) && folder_selected_p (fl)) /* 1 is getOpen and putSave */ - *ith = CWC(FAKEOPENDIR); - - return retval ? retval : retval2; -} - -A3(PRIVATE, void, flinit, fltype *, f, Rect *, r, ControlHandle, sh) -{ - FontInfo fi; - THz savezone; - - GetFontInfo(&fi); - - f->flsh = sh; - f->flrect = *r; - f->fllinht = CW(fi.ascent) + CW(fi.descent) + CW(fi.leading); - - f->flcurdirrect.top = CW(CW(r->top) - f->fllinht - 5); - f->flcurdirrect.bottom = CW(CW(f->flcurdirrect.top) + f->fllinht); - getcurname(f); - - f->flascent = CW(fi.ascent); - f->flnmlin = (CW(r->bottom) - CW(r->top)) / f->fllinht; - f->flnmfil = 0; - f->flsel = -1; - savezone = TheZone; - TheZone = SysZone; - f->flinfo = (struct flinfostr **) NewHandle((Size)0); - f->flstrs = (char **) NewHandle((Size)0); - TheZone = savezone; -} - -A3(PRIVATE, void, stdfflip, Rect *, rp, INTEGER, n, INTEGER, height) -{ - INTEGER savetop; - - savetop = rp->top; - rp->top = CW(CW(rp->top) + (n * height + 1)); - rp->bottom = CW(CW(rp->top) + height - 2); - InvertRect(rp); - rp->top = savetop; -} - -A1(PRIVATE, BOOLEAN, trackdirs, DialogPeek, dp) -{ - WRAPPER_PIXMAP_FOR_COPY (wrapper); - PixMapHandle save_bits; - Rect therect, fillinrect; - struct link - { - Str255 name; - LONGINT dirid; - struct link *next; - INTEGER vrefnum; - } first, *next; - int count, i; - CInfoPBRec hpb; - int max_width; - fltype *fl; - EventRecord evt; - LONGINT id; - int sel, newsel; - BOOLEAN done; - ALLOCABEGIN - BOOLEAN ejectable; - TEMP_ALLOC_DECL (temp_save_bits); - - THEPORT_SAVE_EXCURSION - (MR (wmgr_port), - { - int str_width; - - next = &first; - hpb.dirInfo.ioCompletion = 0; - hpb.dirInfo.ioNamePtr = RM (&next->name[0]); - next->name[0] = 0; - hpb.dirInfo.ioVRefNum = CW (-CW(SFSaveDisk)); - hpb.dirInfo.ioFDirIndex = -1; - hpb.dirInfo.ioDrDirID = CurDirStore; - max_width = 0; - count = 0; - done = FALSE; - - do - { - OSErr err; - - err = PBGetCatInfo (&hpb, FALSE); - if (err != noErr) - { - warning_unexpected ("PBGetCatInfo returns err = %d\n", err); - done = TRUE; - } - id = next->dirid = CL (hpb.dirInfo.ioDrDirID); - next->vrefnum = CW (hpb.dirInfo.ioVRefNum); - next->next = (struct link *) ALLOCA (sizeof (struct link)); - gui_assert (next->next); - str_width = StringWidth (next->name); - if (str_width > max_width) - max_width = str_width; - next = next->next; /* make Steve Jobs happy */ - hpb.dirInfo.ioDrDirID = hpb.dirInfo.ioDrParID; - hpb.dirInfo.ioNamePtr = RM (&next->name[0]); - next->name[0] = 0; - count++; - if (id == 2) - { - if (!findparent (&hpb.dirInfo.ioVRefNum, &hpb.dirInfo.ioDrDirID)) - done = TRUE; - } - } while (!done); - fl = WINDFL(dp); - therect.top = CW (CW (fl->flcurdirrect.top) - - CW (PORT_BOUNDS (dp).top)); - therect.left = CW (CW (fl->flcurdirrect.left) - - CW (PORT_BOUNDS (dp).left)); - therect.bottom = CW (CW (therect.top) + count * fl->fllinht + 1); - therect.right = CW (CW (therect.left) + 2 + 16 + 3 + max_width + 4 + 2 + 3); - ClipRect(&therect); - - { - Rect *bounds; - PixMapHandle port_pixmap; - INTEGER save_bpp_x; - int row_bytes; - void *save_bits_mem; - - save_bits = NewPixMap (); - port_pixmap = CPORT_PIXMAP (thePort); - - bounds = &PIXMAP_BOUNDS (save_bits); - bounds->top = CWC (0); - bounds->left = CWC (0); - bounds->bottom = CW (RECT_HEIGHT (&therect)); - bounds->right = CW (RECT_WIDTH (&therect)); - PIXMAP_PIXEL_SIZE_X (save_bits) = save_bpp_x - = PIXMAP_PIXEL_SIZE_X (port_pixmap); - ROMlib_copy_ctab (PIXMAP_TABLE (port_pixmap), - PIXMAP_TABLE (save_bits)); - row_bytes = ((CW (bounds->right) * CW (save_bpp_x) + 31) / 32) * 4; - PIXMAP_SET_ROWBYTES_X (save_bits, CW (row_bytes)); - - /* Allocate potentially large temporary pixmap space. */ - TEMP_ALLOC_ALLOCATE (save_bits_mem, temp_save_bits, - CW (bounds->bottom) * row_bytes); - PIXMAP_BASEADDR_X (save_bits) = RM (save_bits_mem); - WRAPPER_SET_PIXMAP_X (wrapper, RM (save_bits)); - - CopyBits (PORT_BITS_FOR_COPY (thePort), wrapper, - &therect, bounds, srcCopy, NULL); - } - - EraseRect(&therect); - - /* loop through, displaying stuff */ - /* highlite the appropriate box, etc. */ - - fillinrect.top = therect.top; - fillinrect.left = CW(CW(therect.left) + 2); - fillinrect.bottom = CW(fl->flascent); - fillinrect.right = therect.right; - - for (i = count, next = &first; --i >= 0; next = next->next) - { - - /* TODO: ask cliff about a better way to do this */ - /* unused = */ - getdiskname (&ejectable); - drawinboxwithicon(next->name, &fillinrect, - i ? MICONCFOLDER : ejectable ? MICONFLOPPY : MICONDISK); -/* - drawinboxwithicon(next->name, &fillinrect, - i ? MICONCFOLDER : MICONDISK); -*/ - fillinrect.top = CW(CW(fillinrect.top) + (fl->fllinht)); - } - - therect.right = CW(CW(therect.right) - (1)); - therect.bottom = CW(CW(therect.bottom) - (1)); - FrameRect(&therect); - MoveTo(CW(therect.left)+1, CW(therect.bottom)); - LineTo(CW(therect.right), CW(therect.bottom)); - LineTo(CW(therect.right), CW(therect.top)+1); - therect.right = CW(CW(therect.right) + (1)); - - sel = 0; - fillinrect.top = therect.top; - fillinrect.left = CW (CW (fillinrect.left) - 1); - fillinrect.right = CW (CW (fillinrect.right) - 2); - stdfflip (&fillinrect, sel, fl->fllinht); - done = FALSE; - while (!GetNextEvent (mUpMask, &evt)) - { - evt.where.h = CW (evt.where.h); - evt.where.v = CW (evt.where.v); - if (PtInRect (evt.where, &therect)) - newsel = (evt.where.v - CW(therect.top)) / fl->fllinht; - else - newsel = -1; - if (newsel != sel) - { - if (sel != -1) - stdfflip (&fillinrect, sel, fl->fllinht); - if (newsel != -1) - stdfflip (&fillinrect, newsel, fl->fllinht); - sel = newsel; - } - } - - therect.bottom = CW (CW (therect.bottom) + 1); - - /* restore the rect and clean up after ourselves */ - CopyBits(wrapper, PORT_BITS_FOR_COPY (thePort), - &PIXMAP_BOUNDS (save_bits), &therect, srcCopy, NULL); - DisposPixMap (save_bits); - }); - if (sel != -1) - { - for (i = 0, next = &first; i != sel; ++i, next = next->next) - ; - CurDirStore = CL(next->dirid); - SFSaveDisk = CW(-next->vrefnum); - return TRUE; - } - ALLOCAEND - - TEMP_ALLOC_FREE (temp_save_bits); - - return FALSE; -} - -PRIVATE void -makeworking (fltype *f) -{ - - switch (f->flavor) - { - case original_sf: - { - WDPBRec wdpb; - OSErr err; - - wdpb.ioVRefNum = CW(-CW(SFSaveDisk)); - wdpb.ioWDDirID = CurDirStore; - wdpb.ioWDProcID = TICKX("STDF"); - wdpb.ioNamePtr = 0; - err = PBOpenWD(&wdpb, FALSE); - if (err != noErr) - warning_unexpected ("PBOpenWD returns %d\n", err); - - f->flreplyp.oreplyp->vRefNum = wdpb.ioVRefNum; - } - break; - case new_sf: - case new_custom_sf: - f->flreplyp.nreplyp->sfFile.vRefNum = CW(-CW(SFSaveDisk)); - f->flreplyp.nreplyp->sfFile.parID = CurDirStore; - break; - default: - warning_unexpected ("flavor = %d", f->flavor); - break; - } -} - -A1(PRIVATE, BOOLEAN, ejected, HParmBlkPtr, pb) -{ - return pb->volumeParam.ioVDrvInfo == 0; -} - -/* - * returns true if the filesystem that pb refers to is part of a single - * tree, as in UNIX. Under MSDOS, filesystems are distinct (i.e. C:, D:, - * etc.) - */ - -PRIVATE boolean_t single_tree_fs_p(HParmBlkPtr pb) -{ -#if defined(MSDOS) || defined (CYGWIN32) - return FALSE; -#else - HVCB *vcbp; - - vcbp = ROMlib_vcbbyvrn(CW(pb->volumeParam.ioVRefNum)); - return vcbp && !vcbp->vcbCTRef; -#endif -} - -#if defined(LINUX) -PUBLIC int linuxfloppy_open(int disk, LONGINT *bsizep, - drive_flags_t *flagsp, const char *dname) -{ - int retval; - struct cdrom_subchnl sub_info; - boolean_t force_read_only; - - force_read_only = FALSE; - *flagsp = 0; -#define FLOPPY_PREFIX "/dev/fd" - if (strncmp (dname, FLOPPY_PREFIX, sizeof(FLOPPY_PREFIX)-1) == 0) - *flagsp |= DRIVE_FLAGS_FLOPPY; - - if (!force_read_only) - retval = Uopen (dname, O_RDWR); - if (force_read_only || retval < 0) - { - retval = Uopen (dname, O_RDONLY); - if (retval >= 0) - *flagsp |= DRIVE_FLAGS_LOCKED; - } - - if (retval >= 0 && ioctl (retval, CDROMSUBCHNL, &sub_info) != -1) - { - switch (sub_info.cdsc_audiostatus) - { - case CDROM_AUDIO_PLAY: - case CDROM_AUDIO_PAUSED: - case CDROM_AUDIO_COMPLETED: - case CDROM_AUDIO_ERROR: - close (retval); - return -1; - } - } - - - *bsizep = 512; - if (retval >= 0) - { - /* *ejectablep = TRUE; DRIVE_FLAGS_FIXED not set */ - } - - return retval; -} - -PRIVATE int linuxfloppy_close(int disk) -{ - return close(disk); -} -#endif - -typedef struct { - const char *dname; - DrvQExtra *dqp; - BOOLEAN loaded; - int fd; -} dosdriveinfo_t; - -#define IGNORED (-1) /* doesn't really matter */ - -#if defined(MSDOS) || defined (CYGWIN32) - -#define N_DRIVES (32) - -PRIVATE boolean_t drive_loaded [N_DRIVES] = { 0 }; - -PRIVATE char * -drive_name_of (int i) -{ - static char retval[] = "A:"; - - retval[0] = 'A' + i; - return retval; -} - -enum { NUM_FLOPPIES = 2, NON_FLOPPY_BIT = 0x80 }; - -PRIVATE int -fd_of (int i) -{ - int retval; - -#if defined (CYGWIN32) - retval = i; -#else - if (i < NUM_FLOPPIES) - retval = i; - else - retval = i - NUM_FLOPPIES + NON_FLOPPY_BIT; -#endif - return retval; -} - -#define DRIVE_NAME_OF(x) drive_name_of (x) -#define FD_OF(x) fd_of (x) -#define DRIVE_LOADED(x) drive_loaded[x] - -#else - -#define DRIVE_NAME_OF(x) drives[x].dname - -#define FD_OF(x) drives[x].fd - -#define DRIVE_LOADED(x) drives[x].loaded - -#endif - -PUBLIC void futzwithdosdisks( void ) -{ -#if defined (MSDOS) || defined (LINUX) || defined(CYGWIN32) - int i, fd; - LONGINT mess; - LONGINT blocksize; - drive_flags_t flags; -#if defined(MSDOS) || defined (CYGWIN32) -/* #warning "We're cheating on DOS drive specs: ejectable, bsize, maxsize, writable" */ -#define OPEN_ROUTINE dosdisk_open -#define CLOSE_ROUTINE dosdisk_close -#define EXTRA_CLOSE_PARAM , FALSE -#define MARKER DOSFDBIT -#define EXTRA_PARAM -#define ROMLIB_MACDRIVES ROMlib_macdrives -#elif defined(LINUX) - static dosdriveinfo_t drives[] = { - { "/dev/fd0", (DrvQExtra *) 0, FALSE, IGNORED }, - { "/dev/cdrom", (DrvQExtra *) 0, FALSE, IGNORED }, -#if 0 - { "/dev/fd1", (DrvQExtra *) 0, FALSE, IGNORED }, -#endif - }; -#define N_DRIVES NELEM(drives) -#define OPEN_ROUTINE linuxfloppy_open -#define CLOSE_ROUTINE linuxfloppy_close -#define EXTRA_CLOSE_PARAM -#define MARKER 0 -#define EXTRA_PARAM , (DRIVE_NAME_OF (i)) -#define ROMLIB_MACDRIVES (~0) -#endif - - /* Since we're scanning for new disks, let's be paranoid and - * flush all cached disk information. - */ - dcache_invalidate_all (); - -#if defined (MSDOS) - aspi_rescan (); -#endif - - if (!nodrivesearch_p) - { - for (i = 0; i < N_DRIVES; ++i) { - if (/* DRIVE_LOADED(i) */ ROMLIB_MACDRIVES & (1 << i)) { -#if defined (MSDOS) || defined (CYGWIN32) - checkpoint_macdrive (checkpointp, begin, 1 << i); -#endif - if (((fd = OPEN_ROUTINE(FD_OF (i), &blocksize, &flags - EXTRA_PARAM)) >= 0) - || (flags & DRIVE_FLAGS_FLOPPY)) { - try_to_mount_disk( DRIVE_NAME_OF (i), fd|MARKER, &mess, - blocksize, 16 * PHYSBSIZE, - flags, 0); - mess = CL(mess); - if (mess) { - if (mess >> 16 == 0) { - DRIVE_LOADED(i) = TRUE; - PPostEvent(diskEvt, mess, (HIDDEN_EvQElPtr *) 0); - /* TODO: we probably should post if mess returns an - error, but I think we get confused if we do */ - } else { - if (!(flags & DRIVE_FLAGS_FLOPPY)) - CLOSE_ROUTINE(fd EXTRA_CLOSE_PARAM); - } - } else { - if (!(flags & DRIVE_FLAGS_FLOPPY)) - CLOSE_ROUTINE(fd EXTRA_CLOSE_PARAM); - } - } -#if defined (MSDOS) || defined (CYGWIN32) - checkpoint_macdrive (checkpointp, end, 1 << i); -#endif - } - } - } -#endif -} - - -A2(PRIVATE, void, bumpsavedisk, DialogPtr, dp, BOOLEAN, always) -{ - INTEGER current; - HParamBlockRec pb; - INTEGER vref; - OSErr err; - BOOLEAN is_single_tree_fs, seenus; - -#if defined (MSDOS) || defined (CYGWIN32) -/* static BOOLEAN beenhere = FALSE; */ - - if (ROMlib_drive_check /* || !beenhere */) { - futzwithdosdisks(); -/* beenhere = TRUE; */ - } -#endif - pb.volumeParam.ioVRefNum = CW(-CW(SFSaveDisk)); - pb.volumeParam.ioNamePtr = 0; - pb.volumeParam.ioVolIndex = 0; - err = PBHGetVInfo(&pb, FALSE); - if (err != noErr) - warning_unexpected ("PBHGetVInfo returns %d", err); - else if (!SFSaveDisk || ISWDNUM(-CW(SFSaveDisk))) - SFSaveDisk = CW(-CW(pb.volumeParam.ioVRefNum)); - if (always || pb.ioParam.ioResult != noErr || ejected(&pb)) { - current = pb.volumeParam.ioVRefNum; - is_single_tree_fs = single_tree_fs_p(&pb); - pb.volumeParam.ioVolIndex = 0; - seenus = FALSE; - vref = 0; - do { - pb.volumeParam.ioVolIndex = CW(CW(pb.volumeParam.ioVolIndex) + 1); - err = PBHGetVInfo(&pb, FALSE); - if (err != noErr) - warning_unexpected ("PBHGetVInfo = %d\n", err); - else { - if (pb.volumeParam.ioVRefNum == current) - seenus = TRUE; - else if (!ejected(&pb) && - (!is_single_tree_fs || !single_tree_fs_p(&pb))) { - if (!vref || seenus) - vref = CW(pb.volumeParam.ioVRefNum); - if (seenus) -/*-->*/ break; - } - } - } while (err == noErr); - if (vref) { - SFSaveDisk = CW(-vref); - CurDirStore = CLC(2); - } - } -} - -#if 0 /* needed to construct ctopflags */ -P3 (PUBLIC pascal trap, INTEGER, unused_stdfile_2, INTEGER, ihit, - DialogPtr, dp, UNIV Ptr, data) -{ -} -#endif - -/* - * NOTE: we no longer swap out the refcon when making the sfHookFirstCall (-1) - * or the sfHookLastCall (-2). This fixes the bug that had Photoshop 3.0 - * dying the second time that SFCustomGetFile was called. This fix - * was determined by trial and error. - * - * I have just verified that the fix is incorrect. It works because we - * bypass some startup code that Photoshop 3.0 uses to set up its type list. - * This means that the type list won't work properly. However if we don't - * swap in 'stdf' then we wind up making calls to InsMenuItem that add - * entries to the "Format" menu which somehow results in a crash eventually. - * If we have ROMlib_CALLDHOOK temporarily disable InsMenuItem then PS3.0 - * will work even w/ 'stdf' in the refcon. It will also work if we rig - * CountMItems to always return 0 inside ROMlib_CALLDHOOK. So something - * appears to go wrong if we call the startup code and actually add (and - * notice that we add) items the Format menu. - */ - -PRIVATE INTEGER -ROMlib_CALLDHOOK (fltype *fl, INTEGER ihit, DialogPtr dp, dialog_hook_u dhu) -{ - INTEGER retval; - LONGINT save_ref_con; - - ROMlib_hook(stdfile_dialhooknumber); - HOOKSAVEREGS(); - - save_ref_con = GetWRefCon (dp); - emergency_save_ref_con = save_ref_con; - SetWRefCon (dp, TICK("stdf")); - - switch (fl->flavor) - { - case original_sf: - case new_sf: - retval = CToPascalCall (dhu.odh, CTOP_Alert, ihit, dp); - break; - case new_custom_sf: - retval = CToPascalCall (dhu.cdh, CTOP_unused_stdfile_2, ihit, dp, - fl->mydata); - break; - default: - warning_unexpected ("flavor = %d", fl->flavor); - retval = 0; - break; - } - HOOKRESTOREREGS(); - SetWRefCon (dp, save_ref_con); - return retval; -} - -A4(PRIVATE, void, transformsfpdialog, DialogPtr, dp, Point *, offset, - Rect *, scrollrect, BOOLEAN, getting) -{ - INTEGER numitems, windheight, i, j, extrasizeneeded; - HIDDEN_Handle h; - Rect r; - TEPtr tep; - - if (getting) { - extrasizeneeded = 20; - } else { - extrasizeneeded = 110; - SetRect(scrollrect, 16, 24, 231, 106); - tep = STARH(MR(((DialogPeek)dp)->textH)); - tep->destRect.top = CW(CW(tep->destRect.top) + (extrasizeneeded)); - tep->destRect.bottom = CW(CW(tep->destRect.bottom) + (extrasizeneeded)); - tep->viewRect.top = CW(CW(tep->viewRect.top) + (extrasizeneeded)); - tep->viewRect.bottom = CW(CW(tep->viewRect.bottom) + (extrasizeneeded)); - } - numitems = CW(*(INTEGER *)STARH((MR(((DialogPeek)dp)->items)))) + 1; - for (j = 1 ; j <= numitems ; j++) { - GetDItem(dp, j, &i, &h, &r); - i = CW(i); - h.p = MR(h.p); - if (!getting || CW(r.bottom) > CW(scrollrect->top)) { - r.top = CW(CW(r.top) + (extrasizeneeded)); - r.bottom = CW(CW(r.bottom) + (extrasizeneeded)); - if (i <= 7 && i >= 4) /* It's a control */ - MoveControl((ControlHandle) h.p, CW(r.left), CW(r.top)); - SetDItem(dp, j, i, h.p, &r); - } - } - windheight = CW(dp->portRect.bottom) - CW(dp->portRect.top) + extrasizeneeded; - SizeWindow( (WindowPtr) dp, CW(dp->portRect.right) - CW(dp->portRect.left), - windheight, FALSE); - if (getting) { - scrollrect->top = CW(CW(scrollrect->top) + (extrasizeneeded)); - scrollrect->bottom = CW(CW(scrollrect->bottom) + (extrasizeneeded)); - } - InvalRect(&dp->portRect); - offset->v = CW(CW(offset->v) - (extrasizeneeded / 2)); -} - -void adjustdrivebutton(DialogPtr dp) -{ - INTEGER count; - HIDDEN_Handle drhand; - INTEGER i; - Rect r; -#if !defined(MSDOS) - HVCB *vcbp; - BOOLEAN seenunix; - - count = 0; - seenunix = FALSE; - for (vcbp = (HVCB *) MR(VCBQHdr.qHead); vcbp; - vcbp = (HVCB *) MR(vcbp->qLink)) - if (vcbp->vcbCTRef && vcbp->vcbDrvNum) - ++count; - else if (!seenunix) { - ++count; - seenunix = TRUE; - } -#else /* defined(MSDOS) */ - count = 2; /* always allow the user to hit the drive button */ -#endif /* defined(MSDOS) */ - GetDItem(dp, putDrive, &i, &drhand, &r); /* putDrive == getDrive */ - drhand.p = MR(drhand.p); - HiliteControl((ControlHandle) drhand.p, count > 1 ? 0 : 255); -} - -A1(PRIVATE, void, doeject, DialogPtr, dp) -{ - Eject((StringPtr) "", -CW(SFSaveDisk)); - adjustdrivebutton(dp); - bumpsavedisk(dp, TRUE); -} - -A3(PRIVATE, OSType, gettypeX, StringPtr, name, INTEGER, vref, LONGINT, dirid) -{ - OSType retval; - OSErr err; - HParamBlockRec pbr; - - pbr.fileParam.ioNamePtr = RM (name); - pbr.fileParam.ioVRefNum = CW (vref); - pbr.fileParam.ioFVersNum = 0; - pbr.fileParam.ioFDirIndex = 0; - pbr.fileParam.ioDirID = CL (dirid); - err = PBHGetFInfo (&pbr, FALSE); - if (err == noErr) - retval = pbr.fileParam.ioFlFndrInfo.fdType; - else - retval = 0; - return retval; -} - -typedef enum { get, put } getorput_t; - -PRIVATE OSErr -unixcore (StringPtr namep, INTEGER *vrefnump, LONGINT *diridp) -{ - INTEGER vrefnum; - HVCB *vcbp; - char *newname; - INTEGER namelen; - OSErr err; - ParamBlockRec pb; - char *pathname, *filename, *endname; - VCBExtra *vcbp2; - struct stat sbuf; - LONGINT templ; - char *tempcp; - ParamBlockRec pbr; - - vrefnum = *vrefnump; -#if 0 - vcbp = ROMlib_vcbbyvrn(vrefnum); -#else - pbr.ioParam.ioNamePtr = CLC(0); - pbr.ioParam.ioVRefNum = CW(vrefnum); - vcbp = ROMlib_breakoutioname(&pbr, &templ, &tempcp, (BOOLEAN *) 0, TRUE); - free (tempcp); -#endif - if (vcbp && !vcbp->vcbCTRef) - { - pb.ioParam.ioNamePtr = CLC(0); - pb.ioParam.ioVRefNum = pbr.ioParam.ioVRefNum; - err = ROMlib_nami(&pb, *diridp, NoIndex, &pathname, &filename, - &endname, FALSE, &vcbp2, &sbuf); - if (err == noErr) - { - VCBExtra *vcbextrap; - - namelen = endname - pathname - 1; - newname = alloca(namelen + 1 + namep[0] + 1); - strncpy(newname, pathname, namelen); - newname[namelen] = '/'; - strncpy(newname + namelen + 1, (char *) namep+1, namep[0]); - newname[namelen + 1 + namep[0]] = 0; - ROMlib_automount(newname); - vcbextrap = ROMlib_vcbbyunixname(newname); - if (vcbextrap) - { - *vrefnump = CW(vcbextrap->vcb.vcbVRefNum); - if (*diridp == vcbextrap->u.ufs.ino) - *diridp = 2; - } - else - err = nsvErr; - free (pathname); - } - } - else - err = nsvErr; - return err; -} - -P1(PUBLIC pascal trap, OSErr, unixmount, CInfoPBRec *, cbp) -{ - OSErr err; - - if (!cbp) - { - dofloppymount(); - err = noErr; - } - else - { - INTEGER vrefnum; - LONGINT dirid; - - vrefnum = CW(cbp->hFileInfo.ioVRefNum); - dirid = CL (cbp->hFileInfo.ioDirID); - err = unixcore(MR(cbp->hFileInfo.ioNamePtr), &vrefnum, &dirid); - if (err == noErr) - { - cbp->hFileInfo.ioVRefNum = CW (vrefnum); - cbp->hFileInfo.ioDirID = CW (dirid); - } - } - return err; -} - -PRIVATE void unixcd(fltype *f) -{ - StringPtr name; - INTEGER vrefnum; - LONGINT dirid; - - name = (StringPtr) (MR(*f->flstrs) + MR(*f->flinfo)[f->flsel].floffs); - vrefnum = -CW(SFSaveDisk); - dirid = CL (CurDirStore); - if (unixcore(name, &vrefnum, &dirid) == noErr) - { - SFSaveDisk = CW (-vrefnum); - CurDirStore = CL (dirid); - } -} - -#if 0 - if (U(rep->fName[0]) > 63) /* remember to clip to 63 characters */ - rep->fName[0] = 63; -#endif - -PRIVATE void -get_starting_point (Point *pp) -{ - INTEGER screen_width, screen_height; - Rect main_gd_rect; - - main_gd_rect = PIXMAP_BOUNDS (GD_PMAP (MR (MainDevice))); - screen_width = CW (main_gd_rect.right); - screen_height = CW (main_gd_rect.bottom); - pp->h = (screen_width - STANDARD_WIDTH) / 2; - pp->v = (screen_height - STANDARD_HEIGHT) / 2; -} - -#define SF_NAME(fp) ((fp)->flavor == original_sf \ - ? (fp)->flreplyp.oreplyp->fName \ - : (fp)->flreplyp.nreplyp->sfFile.name) - -#define SF_GOOD_X(fp) ((fp)->flavor == original_sf \ - ? (fp)->flreplyp.oreplyp->good \ - : (fp)->flreplyp.nreplyp->sfGood) - -#define SF_FTYPE_X(fp) ((fp)->flavor == original_sf \ - ? (fp)->flreplyp.oreplyp->fType \ - : (fp)->flreplyp.nreplyp->sfType) - -#define SF_VREFNUM_X(fp) ((fp)->flavor == original_sf \ - ? (fp)->flreplyp.oreplyp->vRefNum \ - : (fp)->flreplyp.nreplyp->sfFile.vRefNum) - -#define SF_VREFNUM(fp) (CW (SF_VREFNUM_X (fp))) - -#define SF_DIRID_X(fp) ((fp)->flavor == original_sf \ - ? 0 \ - : (fp)->flreplyp.nreplyp->sfFile.parID) - -#define SF_DIRID(fp) (CL (SF_DIRID_X (fp))) - -PUBLIC void spfcommon(Point p, StringPtr prompt, StringPtr name, - dialog_hook_u dh, reply_u rep, INTEGER dig, filter_u fp, - file_filter_u filef, INTEGER numt, SFTypeList tl, - getorput_t getorput, sf_flavor_t flavor, - Ptr activeList, ActivateYDProcPtr activateproc, - UNIV Ptr yourdatap) -{ - HIDDEN_Handle h; - DialogPtr dp; - INTEGER ihit, i; - int done, sav; - Rect r, scrollrect; - HIDDEN_Handle pnhand, ejhand, drhand, sahand; - char *ip; - OSErr err; - ControlHandle scrollh; - fltype f; - GrafPtr gp; - INTEGER openorsave, promptitem, nmlistitem, diskname, ejectitem, driveitem; - BOOLEAN transform; - EventRecord evt; - ParamBlockRec pbr; - CInfoPBRec hpb; - - TRAPBEGIN(); - done = FALSE; - memset (&f, 0, sizeof f); - f.magicfp = fp; - f.mydata = yourdatap; - f.flavor = flavor; - f.flreplyp = rep; - - if (p.h == -1 && p.v == -1) - get_starting_point (&p); - - SF_GOOD_X (&f) = CBC (FALSE); - if (f.flavor == original_sf) - f.flreplyp.oreplyp->version = CBC (0); - else - { - f.flreplyp.nreplyp->sfIsFolder = 0; - f.flreplyp.nreplyp->sfIsVolume = 0; - } - SF_FTYPE_X (&f) = CLC (0); - - if ( getorput == put) { - str63assign (SF_NAME (&f), name); - if (f.flavor == original_sf) - { - openorsave = putSave; - promptitem = putPrompt; - nmlistitem = putNmList; - diskname = putDiskName; - ejectitem = putEject; - driveitem = putDrive; - f.fl_cancel_item = putCancel; - } - else - { - openorsave = sfItemOpenButton; - promptitem = sfItemPromptStaticText; - nmlistitem = sfItemFileListUser; - diskname = sfItemVolumeUser; - ejectitem = sfItemEjectButton; - driveitem = sfItemDesktopButton; - f.fl_cancel_item = sfItemCancelButton; - } - } else { - if (f.flavor == original_sf) - { - openorsave = getOpen; - promptitem = 10; /* according to whom? bill? */ - nmlistitem = getNmList; - diskname = getDiskName; - ejectitem = getEject; - driveitem = getDrive; - f.fl_cancel_item = getCancel; - } - else - { - openorsave = sfItemOpenButton; - promptitem = sfItemPromptStaticText; - nmlistitem = sfItemFileListUser; - diskname = sfItemVolumeUser; - ejectitem = sfItemEjectButton; - driveitem = sfItemDesktopButton; - f.fl_cancel_item = sfItemCancelButton; - } - } - gp = thePort; - dp = GetNewDialog(dig, (Ptr)0, (WindowPtr)-1); - bumpsavedisk(dp, FALSE); - SetPort(dp); - GetDItem(dp, openorsave, &i, &sahand, &r); - sahand.p = MR(sahand.p); - if (getorput == put && SF_NAME (&f)[0]) - sav = TRUE; - else { - HiliteControl((ControlHandle) sahand.p, 255); - sav = FALSE; - } - GetDItem(dp, ejectitem, &i, &ejhand, &r); - ejhand.p = MR(ejhand.p); - HiliteControl((ControlHandle) ejhand.p, 255); - GetDItem(dp, driveitem, &i, &drhand, &r); - drhand.p = MR(drhand.p); - adjustdrivebutton(dp); - - if (getorput == put) - { - GetDItem(dp, promptitem, &i, &h, &r); - h.p = MR(h.p); - SetIText(h.p, prompt ? prompt : (StringPtr) ""); - } - - GetDItem(dp, nmlistitem, &i, &h, &scrollrect); - h.p = MR(h.p); - - if (getorput == put) { - INTEGER putname; - - if (f.flavor == original_sf) - { - putname = putName; - transform = CW(scrollrect.right) - CW(scrollrect.left) == 1; - } - else - { - putname = sfItemFileNameTextEdit; - transform = FALSE; - } - - GetDItem(dp, putname, &i, &pnhand, &r); - pnhand.p = MR(pnhand.p); - SetIText(pnhand.p, SF_NAME (&f)); - SelIText((DialogPtr) dp, putname, 0, 32767); - } else { - if (f.flavor == original_sf) - { - GetDItem(dp, getScroll, &i, &h, &r); - h.p = MR(h.p); - transform = CW(r.right) - CW(r.left) == 16; - GetDItem(dp, getDotted, &i, &h, &r); - h.p = MR(h.p); - SetDItem(dp, getDotted, userItem, (Handle) P_ROMlib_filebox, &r); - } - else - transform = FALSE; - } - - if ( transform ) - transformsfpdialog(dp, &p, &scrollrect, getorput == get); - - SetDItem(dp, nmlistitem, userItem, (Handle) P_ROMlib_filebox, &scrollrect); - - GetDItem(dp, diskname, &i, &h, &r); - h.p = MR(h.p); - SetDItem(dp, diskname, userItem, (Handle) P_ROMlib_filebox, &r); - - r.left = CW(CW(scrollrect.left) + 1); - r.right = CW(CW(scrollrect.right) - 16); - r.top = CW(CW(scrollrect.top) + 1); - r.bottom = CW(CW(scrollrect.bottom) - 1); - scrollrect.left = CW(CW(scrollrect.right) - 16); - scrollh = NewControl((WindowPtr) dp, &scrollrect, (StringPtr) "", TRUE, - 0, 0, 0, scrollBarProc, 0L); - flinit(&f, &r, scrollh); - f.flfilef = filef; - f.flnumt = numt; - f.fltl = tl; - f.flch = (ControlHandle) sahand.p; - f.flgraynondirs = getorput == get ? 0 : GRAYBIT; - - if (getorput == get) { - if (f.flnmfil > 0) { - ip = MR(*f.flstrs) + MR(*f.flinfo)[0].floffs; - str63assign (SF_NAME (&f), ip); - } else - (SF_NAME (&f))[0] = 0; - } - SetWRefCon((WindowPtr) dp, (LONGINT)(long)US_TO_SYN68K(&f)); - if (CW(dp->portRect.bottom) + p.v + 7 > CW(screenBitsX.bounds.bottom)) - p.v = CW(screenBitsX.bounds.bottom) - CW(dp->portRect.bottom) - 7; - if (p.v < CW(MBarHeight) + 7) - p.v = CW(MBarHeight) + 7; - MoveWindow((WindowPtr) dp, p.h, p.v, FALSE); - - if (dh.odh) - ihit = ROMlib_CALLDHOOK(&f, -1, dp, dh); /* the mac does this */ - - flfill(&f); /* moved to after dhook call of -1 suggested by - Wieslaw Kuzmicz */ - - ShowWindow((WindowPtr) dp); - SelectWindow((WindowPtr) dp); - while (!done) { - ModalDialog((ProcPtr) P_ROMlib_stdffilt, &ihit); - ihit = CW(ihit); - if (getorput == put) - GetIText(pnhand.p, SF_NAME (&f)); - if (dh.odh) - ihit = ROMlib_CALLDHOOK(&f, ihit, dp, dh); - if (ihit == openorsave) { - makeworking (&f); - if (getorput == get) { - if (SF_FTYPE_X (&f)) /* will never happen unless someone */ - (SF_NAME (&f)) [0] = 0;/* has a tricky filterproc */ - else - SF_FTYPE_X (&f) = gettypeX(SF_NAME (&f), SF_VREFNUM (&f), - SF_DIRID (&f)); - done = TRUE; - SF_GOOD_X (&f) = CBC (TRUE); - } else { - GetIText(pnhand.p, SF_NAME (&f)); - hpb.dirInfo.ioCompletion = 0; - hpb.dirInfo.ioNamePtr = RM((char *) SF_NAME (&f)); - hpb.dirInfo.ioVRefNum = SF_VREFNUM_X (&f); - hpb.dirInfo.ioFDirIndex = 0; - hpb.dirInfo.ioDrDirID = 0; - err = PBGetCatInfo(&hpb, FALSE); - switch (err) { - case noErr: - ParamText(SF_NAME (&f), (StringPtr)0, (StringPtr)0, - (StringPtr)0); - if (movealert(-3996) == 1) /* overwrite ... */ - break; - SF_FTYPE_X (&f) = hpb.hFileInfo.ioFlFndrInfo.fdType; - /* FALL THROUGH */ - default: - warning_unexpected ("err = %d", err); - /* FALL THROUGH */ - case fnfErr: - done = TRUE; - SF_GOOD_X (&f) = CBC (TRUE); /* great. That's a take */ - break; - case bdNamErr: - case nsvErr: - case paramErr: - movealert(-3994); /* disknotfound */ - break; - } - } - } else if ((ihit == f.fl_cancel_item) || - (ihit == putCancel)) { /* MYM 6.0 suggests that putCancel - cancels a get, too */ - done = TRUE; - } else if (ihit == ejectitem) { - doeject(dp); - ihit = FAKEREDRAW; - } else if (ihit == driveitem) { - bumpsavedisk(dp, TRUE); - ihit = FAKEREDRAW; - } else if (ihit == diskname) { - if (moveuponedir(dp)) - ihit = FAKEREDRAW; - } else if (ihit == FAKECURDIR) { - if (trackdirs((DialogPeek) dp)) - ihit = FAKEREDRAW; - } else if (ihit == FAKEOPENDIR) { - CurDirStore = SF_FTYPE_X (&f); - unixcd(&f); - ihit = FAKEREDRAW; - } - if (getorput == put) { - Str255 file_name; - - GetIText(pnhand.p, file_name); - str63assign (SF_NAME (&f), file_name); - if ((SF_NAME (&f))[0] && !sav) { - HiliteControl((ControlHandle) sahand.p, 0); - sav = TRUE; - } else if (!(SF_NAME (&f)[0]) && sav) { - HiliteControl((ControlHandle) sahand.p, 255); - sav = FALSE; - } - } - if (WaitNextEvent(diskMask, &evt, 4, 0) && - (evt.message & CLC(0xFFFF0000)) == 0) { - pbr.volumeParam.ioNamePtr = 0; - pbr.volumeParam.ioVolIndex = 0; - pbr.volumeParam.ioVRefNum = CW(CL(evt.message) & 0xFFFF); - err = PBGetVInfo(&pbr, FALSE); - gui_assert(err == noErr); - if (err == noErr) { - adjustdrivebutton(dp); - SFSaveDisk = CW(-CW(pbr.volumeParam.ioVRefNum)); - CurDirStore = CLC(2); - ihit = FAKEREDRAW; - } - } - if (ihit == FAKEREDRAW) - realcd((DialogPeek) dp, CL(CurDirStore)); - } - if (f.flavor != original_sf && dh.odh) - ihit = ROMlib_CALLDHOOK(&f, -2, dp, dh); /* the mac does this */ - flfinit(&f); - CloseDialog((DialogPtr) dp); - makeworking (&f); - SetPort(gp); - TRAPEND(); -} - -P7(PUBLIC pascal trap, void, SFPPutFile, Point, p, StringPtr, prompt, - StringPtr, name, ProcPtr, dh, SFReply *, rep, INTEGER, dig, ProcPtr, fp) -{ - dialog_hook_u dhu; - reply_u repu; - filter_u filteru; - file_filter_u zero_file_filter = { 0 }; - - dhu.odh = dh; - repu.oreplyp = rep; - filteru.ofilterp = fp; - - spfcommon(p, prompt, name, dhu, repu, dig, filteru, zero_file_filter, -1, - (OSType *) 0, put, original_sf, 0, 0, 0); -} - -P5(PUBLIC pascal trap, void, SFPutFile, Point, p, StringPtr, prompt, - StringPtr, name, ProcPtr, dh, SFReply *, rep) -{ - SFPPutFile(p, prompt, name, dh, rep, putDlgID, (ProcPtr) 0); -} - -P9(PUBLIC pascal trap, void, SFPGetFile, Point, p, StringPtr, prompt, - ProcPtr, filef, INTEGER, numt, SFTypeList, tl, ProcPtr, dh, - SFReply *, rep, INTEGER, dig, ProcPtr, fp) -{ - dialog_hook_u dhu; - reply_u repu; - filter_u filteru; - file_filter_u file_filteru; - - dhu.odh = dh; - repu.oreplyp = rep; - filteru.ofilterp = fp; - file_filteru.oflfilef = filef; - - spfcommon(p, prompt, (StringPtr) "", dhu, repu, dig, filteru, file_filteru, - numt, tl, get, original_sf, 0, 0, 0); -} - -P7(PUBLIC pascal trap, void, SFGetFile, Point, p, StringPtr, prompt, - ProcPtr, filef, INTEGER, numt, SFTypeList, tl, ProcPtr, dh, SFReply *, rep) -{ - SFPGetFile(p, prompt, filef, numt, tl, dh, rep, getDlgID, (ProcPtr) 0); -} - -P10(PUBLIC pascal trap, void, CustomPutFile, Str255, prompt, - Str255, defaultName, StandardFileReply *, replyp, INTEGER, dlgid, - Point, where, DlgHookYDProcPtr, dlghook, ModalFilterYDProcPtr, filterproc, - Ptr, activeList, ActivateYDProcPtr, activateproc, UNIV Ptr, yourdatap) -{ - dialog_hook_u dhu; - reply_u repu; - filter_u filteru; - file_filter_u file_filteru; - - dhu.cdh = dlghook; - repu.nreplyp = replyp; - file_filteru.cflfilef = 0; - filteru.cfilterp = filterproc; - - if (dlgid == 0) - dlgid = putDlgID; - - - spfcommon (where, prompt, defaultName, dhu, repu, dlgid, filteru, - file_filteru, -1, 0, put, new_custom_sf, activeList, - activateproc, yourdatap); -} - -P11(PUBLIC pascal trap, void, CustomGetFile, FileFilterYDProcPtr, filefilter, - INTEGER, numtypes, SFTypeList, typelist, StandardFileReply *, replyp, - INTEGER, dlgid, Point, where, DlgHookYDProcPtr, dlghook, - ModalFilterYDProcPtr, filterproc, Ptr, activeList, - ActivateYDProcPtr, activateproc, UNIV Ptr, yourdatap) -{ - dialog_hook_u dhu; - reply_u repu; - filter_u filteru; - file_filter_u file_filteru; - - dhu.cdh = dlghook; - repu.nreplyp = replyp; - filteru.cfilterp = filterproc; - file_filteru.cflfilef = filefilter; - - if (dlgid == 0) - dlgid = getDlgID; - - spfcommon (where, "", "", dhu, repu, dlgid, filteru, file_filteru, numtypes, - typelist, get, new_custom_sf, activeList, activateproc, - yourdatap); -} - -P4(PUBLIC pascal trap, void, StandardGetFile, ProcPtr, filef, INTEGER, numt, - SFTypeList, tl, StandardFileReply *, replyp) -{ - Point p; - reply_u repu; - file_filter_u file_filteru; - dialog_hook_u dhu; - filter_u filteru; - - repu.nreplyp = replyp; - file_filteru.oflfilef = filef; - dhu.cdh = 0; - filteru.cfilterp = 0; - - p.h = -1; - p.v = -1; - spfcommon (p, "", (StringPtr) "", dhu, repu, sfGetDialogID, filteru, - file_filteru, numt, tl, get, new_sf, 0, 0, 0); -} - -P3(PUBLIC pascal trap, void, StandardPutFile, Str255, prompt, - Str255, defaultname, StandardFileReply *, replyp) -{ - Point p; - reply_u repu; - file_filter_u file_filteru; - dialog_hook_u dhu; - filter_u filteru; - - filteru.cfilterp = 0; - repu.nreplyp = replyp; - file_filteru.cflfilef = 0; - dhu.cdh = 0; - - p.h = -1; - p.v = -1; - spfcommon (p, prompt, defaultname, dhu, repu, sfPutDialogID, filteru, - file_filteru, -1, 0, put, new_sf, 0, 0, 0); -}