imapext-2007
diff src/osdep/mac/env_mac.c @ 0:ada5e610ab86
imap-2007e
author | yuuji@gentei.org |
---|---|
date | Mon, 14 Sep 2009 15:17:45 +0900 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/osdep/mac/env_mac.c Mon Sep 14 15:17:45 2009 +0900 1.3 @@ -0,0 +1,236 @@ 1.4 +/* ======================================================================== 1.5 + * Copyright 1988-2006 University of Washington 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * 1.14 + * ======================================================================== 1.15 + */ 1.16 + 1.17 +/* 1.18 + * Program: Mac environment routines 1.19 + * 1.20 + * Author: Mark Crispin 1.21 + * Networks and Distributed Computing 1.22 + * Computing & Communications 1.23 + * University of Washington 1.24 + * Administration Building, AG-44 1.25 + * Seattle, WA 98195 1.26 + * Internet: MRC@CAC.Washington.EDU 1.27 + * 1.28 + * Date: 26 January 1992 1.29 + * Last Edited: 30 August 2006 1.30 + */ 1.31 + 1.32 + 1.33 +static char *myHomeDir = NIL; /* home directory name */ 1.34 +static char *myLocalHost = NIL; /* local host name */ 1.35 +static char *myNewsrc = NIL; /* newsrc file name */ 1.36 + 1.37 +#include "pmatch.c" /* include wildcard pattern matcher */ 1.38 + 1.39 +/* Environment manipulate parameters 1.40 + * Accepts: function code 1.41 + * function-dependent value 1.42 + * Returns: function-dependent return value 1.43 + */ 1.44 + 1.45 +void *env_parameters (long function,void *value) 1.46 +{ 1.47 + void *ret = NIL; 1.48 + char tmp[MAILTMPLEN]; 1.49 + switch ((int) function) { 1.50 + case SET_HOMEDIR: 1.51 + if (myHomeDir) fs_give ((void **) &myHomeDir); 1.52 + myHomeDir = cpystr ((char *) value); 1.53 + case GET_HOMEDIR: 1.54 + /* set home directory if not defined */ 1.55 + if (!myHomeDir) myHomeDir = cpystr (""); 1.56 + ret = (void *) myHomeDir; 1.57 + break; 1.58 + case SET_LOCALHOST: 1.59 + myLocalHost = cpystr ((char *) value); 1.60 + case GET_LOCALHOST: 1.61 + ret = (void *) myLocalHost ? myLocalHost : "random-mac"; 1.62 + break; 1.63 + case SET_NEWSRC: 1.64 + if (myNewsrc) fs_give ((void **) &myNewsrc); 1.65 + myNewsrc = cpystr ((char *) value); 1.66 + case GET_NEWSRC: 1.67 + if (!myNewsrc) { /* set news file name if not defined */ 1.68 + sprintf (tmp,"%s:News State",myhomedir ()); 1.69 + myNewsrc = cpystr (tmp); 1.70 + } 1.71 + ret = (void *) myNewsrc; 1.72 + break; 1.73 + } 1.74 + return ret; 1.75 +} 1.76 + 1.77 +/* Write current time 1.78 + * Accepts: destination string 1.79 + * format of date and time 1.80 + * 1.81 + * This depends upon the ReadLocation() call in System 7 and the 1.82 + * user properly setting his location/timezone in the Map control 1.83 + * panel. 1.84 + * Nothing is done about the gmtFlags.dlsDelta byte yet, since I 1.85 + * don't know how it's supposed to work. 1.86 + */ 1.87 + 1.88 +static void do_date (char *date,char *fmt) 1.89 +{ 1.90 + long tz,tzm; 1.91 + time_t ti = time (0); 1.92 + struct tm *t = localtime (&ti); 1.93 + MachineLocation loc; 1.94 + ReadLocation (&loc); /* get location/timezone poop */ 1.95 + /* get sign-extended time zone */ 1.96 + tz = (loc.gmtFlags.gmtDelta & 0x00ffffff) | 1.97 + ((loc.gmtFlags.gmtDelta & 0x00800000) ? 0xff000000 : 0); 1.98 + tz /= 60; /* get timezone in minutes */ 1.99 + tzm = tz % 60; /* get minutes from the hour */ 1.100 + /* output time */ 1.101 + strftime (date,MAILTMPLEN,fmt,t); 1.102 + /* now output time zone */ 1.103 + sprintf (date += strlen (date),"%+03ld%02ld",tz/60,tzm >= 0 ? tzm : -tzm); 1.104 +} 1.105 + 1.106 + 1.107 +/* Write current time in RFC 822 format 1.108 + * Accepts: destination string 1.109 + */ 1.110 + 1.111 +void rfc822_date (char *date) 1.112 +{ 1.113 + do_date (date,"%a, %d %b %Y %H:%M:%S "); 1.114 +} 1.115 + 1.116 + 1.117 +/* Write current time in internal format 1.118 + * Accepts: destination string 1.119 + */ 1.120 + 1.121 +void internal_date (char *date) 1.122 +{ 1.123 + do_date (date,"%2d-%b-%Y %H:%M:%S "); 1.124 +} 1.125 + 1.126 +/* Return my local host name 1.127 + * Returns: my local host name 1.128 + */ 1.129 + 1.130 +char *mylocalhost (void) 1.131 +{ 1.132 + return (char *) mail_parameters (NIL,GET_LOCALHOST,NIL); 1.133 +} 1.134 + 1.135 + 1.136 +/* Return my home directory name 1.137 + * Returns: my home directory name 1.138 + */ 1.139 + 1.140 +char *myhomedir () 1.141 +{ 1.142 + return (char *) mail_parameters (NIL,GET_HOMEDIR,NIL); 1.143 +} 1.144 + 1.145 + 1.146 +/* Determine default prototype stream to user 1.147 + * Accepts: type (NIL for create, T for append) 1.148 + * Returns: default prototype stream 1.149 + */ 1.150 + 1.151 +MAILSTREAM *default_proto (long type) 1.152 +{ 1.153 + extern MAILSTREAM dummyproto; 1.154 + return &dummyproto; /* return default driver's prototype */ 1.155 +} 1.156 + 1.157 +/* Block until event satisfied 1.158 + * Called as: while (wait_condition && wait ()); 1.159 + * Returns T if OK, NIL if user wants to abort 1.160 + * 1.161 + * Allows user to run a desk accessory, select a different window, or go 1.162 + * to another application while waiting for the event to finish. COMMAND/. 1.163 + * will abort the wait. 1.164 + * Assumes the Apple menu has the apple character as its first character, 1.165 + * and that the main program has disabled all other menus. 1.166 + */ 1.167 + 1.168 +long wait () 1.169 +{ 1.170 + EventRecord event; 1.171 + WindowPtr window; 1.172 + MenuInfo **m; 1.173 + long r; 1.174 + Str255 tmp; 1.175 + /* wait for an event */ 1.176 + WaitNextEvent (everyEvent,&event,(long) 6,NIL); 1.177 + switch (event.what) { /* got one -- what is it? */ 1.178 + case mouseDown: /* mouse clicked */ 1.179 + switch (FindWindow (event.where,&window)) { 1.180 + case inMenuBar: /* menu bar item? */ 1.181 + /* yes, interesting event? */ 1.182 + if (r = MenuSelect (event.where)) { 1.183 + /* round-about test for Apple menu */ 1.184 + if ((*(m = GetMHandle (HiWord (r))))->menuData[1] == appleMark) { 1.185 + /* get desk accessory name */ 1.186 + GetItem (m,LoWord (r),tmp); 1.187 + OpenDeskAcc (tmp); /* fire it up */ 1.188 + SetPort (window); /* put us back at our window */ 1.189 + } 1.190 + else SysBeep (60); /* the fool forgot to disable it! */ 1.191 + } 1.192 + HiliteMenu (0); /* unhighlight it */ 1.193 + break; 1.194 + case inContent: /* some window was selected */ 1.195 + if (window != FrontWindow ()) SelectWindow (window); 1.196 + break; 1.197 + default: /* ignore all others */ 1.198 + break; 1.199 + } 1.200 + break; 1.201 + case keyDown: /* key hit - if COMMAND/. then punt */ 1.202 + if ((event.modifiers & cmdKey) && (event.message & charCodeMask) == '.') 1.203 + return NIL; 1.204 + break; 1.205 + default: /* ignore all others */ 1.206 + break; 1.207 + } 1.208 + return T; /* try wait test again */ 1.209 +} 1.210 + 1.211 +/* Return random number 1.212 + */ 1.213 + 1.214 +long random () 1.215 +{ 1.216 + return (long) rand () << 16 + rand (); 1.217 +} 1.218 + 1.219 + 1.220 +/* Emulator for BSD syslog() routine 1.221 + * Accepts: priority 1.222 + * message 1.223 + * parameters 1.224 + */ 1.225 + 1.226 +void syslog (int priority,const char *message,...) 1.227 +{ 1.228 +} 1.229 + 1.230 + 1.231 +/* Emulator for BSD openlog() routine 1.232 + * Accepts: identity 1.233 + * options 1.234 + * facility 1.235 + */ 1.236 + 1.237 +void openlog (const char *ident,int logopt,int facility) 1.238 +{ 1.239 +}