int TclpGetTimeZone ( unsigned long currentTime) /* Ignored on Mac. */ { MachineLocation loc; long int offset; ReadLocation(&loc); offset = loc.u.gmtDelta & 0x00ffffff; if (offset & 0x00700000) { offset |= 0xff000000; } /* * Convert the Mac offset from seconds to minutes and * add an hour if we have daylight savings time. */ offset = -offset; offset /= 60; if (loc.u.dlsDelta < 0) { offset += 60; } return offset; }
void TclpGetTime( Tcl_Time *timePtr) /* Location to store time information. */ { UnsignedWide micro; #ifndef NO_LONG_LONG long long *microPtr; #endif if (initalized == false) { MachineLocation loc; long int offset; ReadLocation(&loc); offset = loc.u.gmtDelta & 0x00ffffff; if (offset & 0x00800000) { offset = offset | 0xff000000; } if (ReadDateTime(&baseSeconds) != noErr) { /* * This should never happen! */ return; } /* * Remove the local offset that ReadDateTime() adds. */ baseSeconds -= offset; Microseconds(µOffset); initalized = true; } Microseconds(µ); #ifndef NO_LONG_LONG microPtr = (long long *) µ *microPtr -= *((long long *) µOffset); timePtr->sec = baseSeconds + (*microPtr / 1000000); timePtr->usec = *microPtr % 1000000; #else SubtractUnsignedWide(µ, µOffset, µ); /* * This lovely computation is equal to: base + (micro / 1000000) * For the .hi part the ratio of 0x100000000 / 1000000 has been * reduced to avoid overflow. This computation certainly has * problems as the .hi part gets large. However, your application * would have to run for a long time to make that happen. */ timePtr->sec = baseSeconds + (micro.lo / 1000000) + (long) (micro.hi * ((double) 33554432.0 / 15625.0)); timePtr->usec = micro.lo % 1000000; #endif }
/* * The geographic location and time zone information of a Mac * are stored in extended parameter RAM. The ReadLocation * produdure uses the geographic location record, MachineLocation, * to read the geographic location and time zone information in * extended parameter RAM. * * Because serial port and SLIP conflict with ReadXPram calls, * we cache the call here. * * Caveat: this caching will give the wrong result if a session * extend across the DST changeover time, but * this function resets itself every 2 hours. */ static void myReadLocation(MachineLocation * loc) { static MachineLocation storedLoc; /* InsideMac, OSUtilities, page 4-20 */ static time_t first_call = 0, last_call = 86400; if ((last_call - first_call) > 7200) { GetDateTime(&first_call); ReadLocation(&storedLoc); } GetDateTime(&last_call); *loc = storedLoc; }
static void do_date (char *date,char *fmt) { long tz,tzm; time_t ti = time (0); struct tm *t = localtime (&ti); MachineLocation loc; ReadLocation (&loc); /* get location/timezone poop */ /* get sign-extended time zone */ tz = (loc.gmtFlags.gmtDelta & 0x00ffffff) | ((loc.gmtFlags.gmtDelta & 0x00800000) ? 0xff000000 : 0); tz /= 60; /* get timezone in minutes */ tzm = tz % 60; /* get minutes from the hour */ /* output time */ strftime (date,MAILTMPLEN,fmt,t); /* now output time zone */ sprintf (date += strlen (date),"%+03ld%02ld",tz/60,tzm >= 0 ? tzm : -tzm); }
static void initmactimezone(void) { MachineLocation loc; long delta; ReadLocation(&loc); if (loc.latitude == 0 && loc.longitude == 0 && loc.u.gmtDelta == 0) return; delta = loc.u.gmtDelta & 0x00FFFFFF; if (delta & 0x00800000) delta |= 0xFF000000; timezone = -delta; }
unsigned long TclpGetSeconds() { unsigned long seconds; MachineLocation loc; long int offset; ReadLocation(&loc); offset = loc.u.gmtDelta & 0x00ffffff; if (offset & 0x00800000) { offset = offset | 0xff000000; } if (ReadDateTime(&seconds) == noErr) { return (seconds - offset); } else { panic("Can't get time."); return 0; } }
struct tm * TclpGetDate( TclpTime_t time, /* Time struct to fill. */ int useGMT) /* True if date should reflect GNT time. */ { const time_t *tp = (const time_t *)time; DateTimeRec dtr; MachineLocation loc; long int offset; static struct tm statictime; static const short monthday[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; ReadLocation(&loc); if (useGMT) { SecondsToDate(*tp, &dtr); } else { offset = loc.u.gmtDelta & 0x00ffffff; if (offset & 0x00700000) { offset |= 0xff000000; } SecondsToDate(*tp + offset, &dtr); } statictime.tm_sec = dtr.second; statictime.tm_min = dtr.minute; statictime.tm_hour = dtr.hour; statictime.tm_mday = dtr.day; statictime.tm_mon = dtr.month - 1; statictime.tm_year = dtr.year - 1900; statictime.tm_wday = dtr.dayOfWeek - 1; statictime.tm_yday = monthday[statictime.tm_mon] + statictime.tm_mday - 1; if (1 < statictime.tm_mon && !(statictime.tm_year & 3)) { ++statictime.tm_yday; } statictime.tm_isdst = loc.u.dlsDelta; return(&statictime); }
static void MyReadLocation(MachineLocation * loc) { static MachineLocation storedLoc; /* InsideMac, OSUtilities, page 4-20 */ static JSBool didReadLocation = JS_FALSE; if (!didReadLocation) { MacintoshInitializeTime(); ReadLocation(&storedLoc); /* install a sleep queue routine, so that when the machine wakes up, time can be recomputed. */ if (&SleepQInstall != (void*)kUnresolvedCFragSymbolAddress #if !TARGET_CARBON && NGetTrapAddress(0xA28A, OSTrap) != NGetTrapAddress(_Unimplemented, ToolTrap) #endif ) { if ((gSleepQEntry.sleepQProc = NewSleepQUPP(MySleepQProc)) != NULL) { SleepQInstall(&gSleepQEntry); gSleepQEntryInstalled = JS_TRUE; } } didReadLocation = JS_TRUE; } *loc = storedLoc; }
//----------------------------------------------------------------------------- bool psNPCLoader::LoadFromFile(csString &filename) { area.Clear(); CPrintf(CON_DEBUG, "Importing NPC from file: %s\n",filename.GetData()); // try to read data from the file csRef<iVFS> vfs = csQueryRegistry<iVFS> (psserver->GetObjectReg()); csRef<iDataBuffer> data(vfs->ReadFile(filename.GetData())); if(!data || !data->GetSize()) { CPrintf(CON_ERROR, "Error: Couldn't load file '%s'.\n", filename.GetData()); return false; } csRef<iDocumentSystem> xml; xml.AttachNew(new csTinyDocumentSystem); csRef<iDocument> doc = xml->CreateDocument(); const char* error = doc->Parse(data); if(error) { Error2("Error in XML: %s", error); return false; } npcRoot = doc->GetRoot()->GetNode("npc"); if(!npcRoot) { CPrintf(CON_ERROR, "Error: no <npc> tag found\n"); return false; } dialogManager = new psDialogManager; npc = new psCharacter; npc->SetCharType(PSCHARACTER_TYPE_NPC); // process xml data if(!ReadBasicInfo() || !ReadLocation()) { CPrintf(CON_ERROR, "Error: Failed to load NPC data\n"); return false; } ReadDescription(); ReadTraits(); ReadStats(); ReadMoney(); ReadSkills(); ReadTrainerInfo(); ReadMerchantInfo(); ReadFactions(); ReadKnowledgeAreas(); ReadSpecificKnowledge(); ReadSpecialResponses(); // insert processed data into the database if(!WriteToDatabase()) { CPrintf(CON_ERROR, "Error: Failed to insert data into the database\n"); return false; } return true; }
void slowPoll( void ) { RANDOM_STATE randomState; BYTE buffer[ RANDOM_BUFSIZE + 8 ]; ProcessSerialNumber psn; GDHandle deviceHandle; GrafPtr currPort; QElemPtr queuePtr; QHdrPtr queueHdr; static BOOLEAN addedFixedItems = FALSE; initRandomData( randomState, buffer, RANDOM_BUFSIZE ); /* Walk through the list of graphics devices adding information about a device (IM VI 21-21) */ deviceHandle = GetDeviceList(); while( deviceHandle != NULL ) { GDHandle currentHandle = deviceHandle; GDPtr devicePtr; HLock( ( Handle ) currentHandle ); devicePtr = *currentHandle; deviceHandle = devicePtr->gdNextGD; addRandomData( randomState, devicePtr, sizeof( GDevice ) ); HUnlock( ( Handle ) currentHandle ); } /* Walk through the list of processes adding information about each process, including the name and serial number of the process, file and resource information, memory usage information, the name of the launching process, launch time, and accumulated CPU time (IM VI 29-17) */ psn.highLongOfPSN = 0; psn.lowLongOfPSN = kNoProcess; while( !GetNextProcess( &psn ) ) { ProcessInfoRec infoRec; GetProcessInformation( &psn, &infoRec ); addRandomData( randomState, &infoRec, sizeof( ProcessInfoRec ) ); } /* Get the command type, trap address, and parameters for all commands in the file I/O queue. The parameters are quite complex and are listed on page 117 of IM IV, and include reference numbers, attributes, time stamps, length and file allocation information, finder info, and large amounts of other volume and filesystem-related data */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( ( queueHdr = GetFSQHdr() ) != NULL ) queuePtr = queueHdr->qHead; while( queuePtr != NULL ) { /* The queue entries are variant records of variable length so we need to adjust the length parameter depending on the record type */ addRandomData( randomState, queuePtr, 32 ); /* dunno how big.. */ queuePtr = queuePtr->qLink; } #endif /* The following are fixed for the lifetime of the process so we only add them once */ if( !addedFixedItems ) { Str255 appName, volName; GDHandle deviceHandle; Handle appHandle; DrvSts driveStatus; MachineLocation machineLocation; ProcessInfoRec processInfo; QHdrPtr vblQueue; SysEnvRec sysEnvirons; SysPPtr pramPtr; DefStartRec startupInfo; DefVideoRec videoInfo; DefOSRec osInfo; XPPParamBlock appleTalkParams; unsigned char *driverNames[] = { "\p.AIn", "\p.AOut", "\p.AppleCD", "\p.ATP", "\p.BIn", "\p.BOut", "\p.MPP", "\p.Print", "\p.Sony", "\p.Sound", "\p.XPP", NULL }; SInt16 count, dummy, i, node, net, vRefNum, script; SInt32 lcount, volume; /* Get the current font family ID, node ID of the local AppleMumble router, caret blink delay, CPU speed, double-click delay, sound volume, application and system heap zone, the number of resource types in the application, the number of sounds voices available, the FRef of the current resource file, volume of the sysbeep, primary line direction, computer SCSI disk mode ID, timeout before the screen is dimmed and before the computer is put to sleep, number of available threads in the thread pool, whether hard drive spin-down is disabled, the handle to the i18n resources, timeout time for the internal HDD, */ addRandomValue( randomState, GetAppFont() ); #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON addRandomValue( randomState, GetBridgeAddress() ); #endif addRandomValue( randomState, GetCaretTime() ); /* addRandomValue( randomState, GetCPUSpeed() ); */ addRandomValue( randomState, GetDblTime() ); GetSysBeepVolume( &volume ); addRandomValue( randomState, volume ); GetDefaultOutputVolume( &volume ); addRandomValue( randomState, volume ); #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON addRandomValue( randomState, ApplicationZone() ); addRandomValue( randomState, SystemZone() ); #endif addRandomValue( randomState, CountTypes() ); /* CountVoices( &count ); ** seems to crash addRandomValue( randomState, count ); */ addRandomValue( randomState, CurResFile() ); GetSysBeepVolume( &lcount ); addRandomValue( randomState, lcount ); addRandomValue( randomState, GetSysDirection() ); /* addRandomValue( randomState, GetSCSIDiskModeAddress() ); addRandomValue( randomState, GetDimmingTimeout() ); addRandomValue( randomState, GetSleepTimeout() ); */ GetFreeThreadCount( kCooperativeThread, &count ); addRandomValue( randomState, count ); /* addRandomValue( randomState, IsSpindownDisabled() ); */ addRandomValue( randomState, GetIntlResource( 0 ) ); #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON GetTimeout( &count ); addRandomValue( randomState, count ); #endif /* Get the number of documents/files which were selected when the app started and for each document get the vRefNum, name, type, and version -- OBSOLETE CountAppFiles( &dummy, &count ); addRandomValue( randomState, count ); while( count > 0 ) { AppFile theFile; GetAppFiles( count, &theFile ); addRandomData( randomState, &theFile, sizeof( AppFile ) ); count--; } */ /* Get the app's name, resource file reference number, and handle to the finder information -- OBSOLETE GetAppParams( appName, appHandle, &count ); addRandomData( randomState, appName, sizeof( Str255 ) ); addRandomValue( randomState, appHandle ); addRandomValue( randomState, count ); */ /* Get all sorts of statistics such as physical information, disk and write-protect present status, error status, and handler queue information, on floppy drives attached to the system. Also get the volume name, volume reference number and number of bytes free, for the volume in the drive */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( !DriveStatus( 1, &driveStatus ) ) addRandomData( randomState, &driveStatus, sizeof (DrvSts) ); #endif #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( !GetVInfo( 1, volName, &vRefNum, &lcount ) ) { addRandomData( randomState, volName, sizeof( Str255 ) ); addRandomValue( randomState, vRefNum ); addRandomValue( randomState, lcount ); } #endif #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( !DriveStatus( 2, &driveStatus ) ) addRandomData( randomState, &driveStatus, sizeof (DrvSts) ); #endif #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( !GetVInfo( 2, volName, &vRefNum, &lcount ) ) { addRandomData( randomState, volName, sizeof( Str255 ) ); addRandomValue( randomState, vRefNum ); addRandomValue( randomState, lcount ); } #endif /* Get information on the head and tail of the vertical retrace queue */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( ( vblQueue = GetVBLQHdr() ) != NULL ) addRandomData( randomState, vblQueue, sizeof( QHdr ) ); #endif /* Get the parameter RAM settings */ pramPtr = GetSysPPtr(); addRandomData( randomState, pramPtr, sizeof( SysParmType ) ); /* Get information about the machines geographic location */ ReadLocation( &machineLocation ); addRandomData( randomState, &machineLocation, sizeof( MachineLocation ) ); /* Get information on current graphics devices including device information such as dimensions and cursor information, and a number of handles to device-related data blocks and functions, and information about the dimentions and contents of the devices pixel image as well as the images resolution, storage format, depth, and colour usage */ deviceHandle = GetDeviceList(); do { GDPtr gdPtr; addRandomValue( randomState, deviceHandle ); HLock( ( Handle ) deviceHandle ); gdPtr = ( GDPtr ) *deviceHandle; addRandomData( randomState, gdPtr, sizeof( GDevice ) ); addRandomData( randomState, gdPtr->gdPMap, sizeof( PixMap ) ); HUnlock( ( Handle ) deviceHandle ); } while( ( deviceHandle = GetNextDevice( deviceHandle ) ) != NULL ); /* Get the current system environment, including the machine and system software type, the keyboard type, where there's a colour display attached, the AppleTalk driver version, and the VRefNum of the system folder */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON SysEnvirons( curSysEnvVers, &sysEnvirons ); addRandomData( randomState, &sysEnvirons, sizeof( SysEnvRec ) ); #endif /* Get the AppleTalk node ID and network number for this machine */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( GetNodeAddress( &node, &net ) ) { addRandomValue( randomState, node ); addRandomValue( randomState, net ); } #endif /* Get information on each device connected to the ADB including the device handler ID, the devices ADB address, and the address of the devices handler and storage area */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON count = CountADBs(); while( count-- > 0 ) { ADBDataBlock adbInfo; GetIndADB( &adbInfo, count ); addRandomData( randomState, &adbInfo, sizeof( ADBDataBlock ) ); } #endif /* Open the most common device types and get the general device status information and (if possible) device-specific status. The general device information contains the device handle and flags, I/O queue information, event information, and other driver-related details */ /* Try something like this again.. and ur a dead man, Peter ;-) -xmath */ /* for( count = 0; driverNames[ count ] != NULL; count++ ) { AuxDCEHandle dceHandle; short driverRefNum; ** Try and open the driver ** if( OpenDriver( driverNames[ count ], &driverRefNum ) ) continue; ** Get a handle to the driver control information (this could also be done with GetDCtlHandle()) ** Status( driverRefNum, 1, &dceHandle ); HLock( dceHandle ); addRandomData( randomState, *dceHandle, sizeof( AuxDCE ) ); HUnlock( dceHandle ); CloseDriver( driverRefNum ); } */ /* Get the name and volume reference number for the current volume */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON GetVol( volName, &vRefNum ); addRandomData( randomState, volName, sizeof( Str255 ) ); addRandomValue( randomState, vRefNum ); #endif /* Get the time information, attributes, directory information and bitmap, volume allocation information, volume and drive information, pointers to various pieces of volume-related information, and details on path and directory caches, for each volume */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( ( queueHdr = GetVCBQHdr() ) != NULL ) queuePtr = queueHdr->qHead; while ( queuePtr != NULL ) { addRandomData( randomState, queuePtr, sizeof( VCB ) ); queuePtr = queuePtr->qLink; } #endif /* Get the driver reference number, FS type, and media size for each drive */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON if( ( queueHdr = GetDrvQHdr() ) != NULL ) queuePtr = queueHdr->qHead; while ( queuePtr != NULL ) { addRandomData( randomState, queuePtr, sizeof( DrvQEl ) ); queuePtr = queuePtr->qLink; } #endif /* Get global script manager variables and vectors, including the globals changed count, font, script, and i18n flags, various script types, and cache information */ for( count = 0; count < 30; count++ ) addRandomValue( randomState, GetScriptManagerVariable( count ) ); /* Get the script code for the font script the i18n script, and for each one add the changed count, font, script, i18n, and display flags, resource ID's, and script file information */ script = FontScript(); addRandomValue( randomState, script ); for( count = 0; count < 30; count++ ) addRandomValue( randomState, GetScriptVariable( script, count ) ); script = IntlScript(); addRandomValue( randomState, script ); for( count = 0; count < 30; count++ ) addRandomValue( randomState, GetScriptVariable( script, count ) ); /* Get the device ID, partition, slot number, resource ID, and driver reference number for the default startup device */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON GetDefaultStartup( &startupInfo ); addRandomData( randomState, &startupInfo, sizeof( DefStartRec ) ); #endif /* Get the slot number and resource ID for the default video device */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON GetVideoDefault( &videoInfo ); addRandomData( randomState, &videoInfo, sizeof( DefVideoRec ) ); #endif /* Get the default OS type */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON GetOSDefault( &osInfo ); addRandomData( randomState, &osInfo, sizeof( DefOSRec ) ); #endif /* Get the AppleTalk command block and data size and number of sessions */ #if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON ASPGetParms( &appleTalkParams, FALSE ); addRandomData( randomState, &appleTalkParams, sizeof( XPPParamBlock ) ); #endif addedFixedItems = TRUE; } /* Flush any remaining data through */ endRandomData( randomState, 100 ); }