imapext-2007
diff src/osdep/wce/env_wce.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/wce/env_wce.c Mon Sep 14 15:17:45 2009 +0900 1.3 @@ -0,0 +1,301 @@ 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: WCE 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: 1 August 1988 1.29 + * Last Edited: 30 August 2006 1.30 + */ 1.31 + 1.32 + 1.33 +static char *myUserName = NIL; /* user name */ 1.34 +static char *myLocalHost = NIL; /* local host name */ 1.35 +static char *myClientHost = NIL;/* client host name */ 1.36 +static char *myServerHost = NIL;/* server host name */ 1.37 +static char *myHomeDir = NIL; /* home directory name */ 1.38 +static char *myNewsrc = NIL; /* newsrc file name */ 1.39 +static char *sysInbox = NIL; /* system inbox name */ 1.40 +static long list_max_level = 5; /* maximum level of list recursion */ 1.41 +static short no822tztext = NIL; /* disable RFC [2]822 timezone text */ 1.42 + /* home namespace */ 1.43 +static NAMESPACE nshome = {"",'\\',NIL,NIL}; 1.44 + /* namespace list */ 1.45 +static NAMESPACE *nslist[3] = {&nshome,NIL,NIL}; 1.46 +static long alarm_countdown = 0;/* alarm count down */ 1.47 +static void (*alarm_rang) (); /* alarm interrupt function */ 1.48 +static unsigned int rndm = 0; /* initial `random' number */ 1.49 + 1.50 + 1.51 +/* Dummy definitions to prevent errors */ 1.52 + 1.53 +#define server_login(user,pass,authuser,argc,argv) NIL 1.54 +#define authserver_login(user,authuser,argc,argv) NIL 1.55 +#define myusername() "" 1.56 +#define MD5ENABLE "\\.nosuch.." 1.57 + 1.58 +#include "pmatch.c" /* include wildcard pattern matcher */ 1.59 + 1.60 +/* Environment manipulate parameters 1.61 + * Accepts: function code 1.62 + * function-dependent value 1.63 + * Returns: function-dependent return value 1.64 + */ 1.65 + 1.66 +void *env_parameters (long function,void *value) 1.67 +{ 1.68 + void *ret = NIL; 1.69 + switch ((int) function) { 1.70 + case GET_NAMESPACE: 1.71 + ret = (void *) nslist; 1.72 + break; 1.73 + case SET_HOMEDIR: 1.74 + myHomeDir = cpystr ((char *) value); 1.75 + case GET_HOMEDIR: 1.76 + ret = (void *) myHomeDir; 1.77 + break; 1.78 + case SET_LOCALHOST: 1.79 + myLocalHost = cpystr ((char *) value); 1.80 + case GET_LOCALHOST: 1.81 + ret = (void *) myLocalHost; 1.82 + break; 1.83 + case SET_NEWSRC: 1.84 + if (myNewsrc) fs_give ((void **) &myNewsrc); 1.85 + myNewsrc = cpystr ((char *) value); 1.86 + case GET_NEWSRC: 1.87 + if (!myNewsrc) { /* set news file name if not defined */ 1.88 + char tmp[MAILTMPLEN]; 1.89 + sprintf (tmp,"%s\\NEWSRC",myhomedir ()); 1.90 + myNewsrc = cpystr (tmp); 1.91 + } 1.92 + ret = (void *) myNewsrc; 1.93 + break; 1.94 + case SET_SYSINBOX: 1.95 + if (sysInbox) fs_give ((void **) &sysInbox); 1.96 + sysInbox = cpystr ((char *) value); 1.97 + case GET_SYSINBOX: 1.98 + ret = (void *) sysInbox; 1.99 + break; 1.100 + case SET_LISTMAXLEVEL: 1.101 + list_max_level = (long) value; 1.102 + case GET_LISTMAXLEVEL: 1.103 + ret = (void *) list_max_level; 1.104 + break; 1.105 + case SET_DISABLE822TZTEXT: 1.106 + no822tztext = value ? T : NIL; 1.107 + case GET_DISABLE822TZTEXT: 1.108 + ret = (void *) (no822tztext ? VOIDT : NIL); 1.109 + break; 1.110 + } 1.111 + return ret; 1.112 +} 1.113 + 1.114 +/* Write current time 1.115 + * Accepts: destination string 1.116 + * optional format of day-of-week prefix 1.117 + * format of date and time 1.118 + * flag whether to append symbolic timezone 1.119 + */ 1.120 + 1.121 +static void do_date (char *date,char *prefix,char *fmt,int suffix) 1.122 +{ 1.123 + time_t tn = time (0); 1.124 + struct tm *t = gmtime (&tn); 1.125 + int zone = t->tm_hour * 60 + t->tm_min; 1.126 + int julian = t->tm_yday; 1.127 + t = localtime (&tn); /* get local time now */ 1.128 + /* minus UTC minutes since midnight */ 1.129 + zone = t->tm_hour * 60 + t->tm_min - zone; 1.130 + /* julian can be one of: 1.131 + * 36x local time is December 31, UTC is January 1, offset -24 hours 1.132 + * 1 local time is 1 day ahead of UTC, offset +24 hours 1.133 + * 0 local time is same day as UTC, no offset 1.134 + * -1 local time is 1 day behind UTC, offset -24 hours 1.135 + * -36x local time is January 1, UTC is December 31, offset +24 hours 1.136 + */ 1.137 + if (julian = t->tm_yday -julian) 1.138 + zone += ((julian < 0) == (abs (julian) == 1)) ? -24*60 : 24*60; 1.139 + if (prefix) { /* want day of week? */ 1.140 + sprintf (date,prefix,days[t->tm_wday]); 1.141 + date += strlen (date); /* make next sprintf append */ 1.142 + } 1.143 + /* output the date */ 1.144 + sprintf (date,fmt,t->tm_mday,months[t->tm_mon],t->tm_year+1900, 1.145 + t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60); 1.146 + if (suffix) { /* append timezone suffix if desired */ 1.147 + char *tz; 1.148 + tzset (); /* get timezone from TZ environment stuff */ 1.149 + tz = tzname[daylight ? (((struct tm *) t)->tm_isdst > 0) : 0]; 1.150 + if (tz && tz[0]) sprintf (date + strlen (date)," (%s)",tz); 1.151 + } 1.152 +} 1.153 + 1.154 + 1.155 +/* Write current time in RFC 822 format 1.156 + * Accepts: destination string 1.157 + */ 1.158 + 1.159 +void rfc822_date (char *date) 1.160 +{ 1.161 + do_date (date,"%s, ","%d %s %d %02d:%02d:%02d %+03d%02d", 1.162 + no822tztext ? NIL : T); 1.163 +} 1.164 + 1.165 + 1.166 +/* Write current time in internal format 1.167 + * Accepts: destination string 1.168 + */ 1.169 + 1.170 +void internal_date (char *date) 1.171 +{ 1.172 + do_date (date,NIL,"%02d-%s-%d %02d:%02d:%02d %+03d%02d",NIL); 1.173 +} 1.174 + 1.175 +/* Return random number 1.176 + */ 1.177 + 1.178 +long random () 1.179 +{ 1.180 + if (!rndm) srand (rndm = (unsigned) time (0L)); 1.181 + return (long) rand (); 1.182 +} 1.183 + 1.184 +/* Return default drive 1.185 + * Returns: default drive 1.186 + */ 1.187 + 1.188 +static char *defaultDrive (void) 1.189 +{ 1.190 + char *s; 1.191 + return ((s = getenv ("SystemDrive")) && *s) ? s : "C:"; 1.192 +} 1.193 + 1.194 + 1.195 +/* Return home drive from environment variables 1.196 + * Returns: home drive 1.197 + */ 1.198 + 1.199 +static char *homeDrive (void) 1.200 +{ 1.201 + char *s; 1.202 + return ((s = getenv ("HOMEDRIVE")) && *s) ? s : defaultDrive (); 1.203 +} 1.204 + 1.205 + 1.206 +/* Return home path from environment variables 1.207 + * Accepts: path to write into 1.208 + * Returns: home path or NIL if it can't be determined 1.209 + */ 1.210 + 1.211 +static char *homePath (char *path) 1.212 +{ 1.213 + int i; 1.214 + char *s; 1.215 + if (!((s = getenv ("HOMEPATH")) && (i = strlen (s)))) return NIL; 1.216 + if (((s[i-1] == '\\') || (s[i-1] == '/'))) s[i-1] = '\0'; 1.217 + sprintf (path,"%s%s",homeDrive (),s); 1.218 + return path; 1.219 +} 1.220 + 1.221 +/* Return my home directory name 1.222 + * Returns: my home directory name 1.223 + */ 1.224 + 1.225 +char *myhomedir () 1.226 +{ 1.227 + char tmp[MAILTMPLEN]; 1.228 + /* initialize if first time */ 1.229 + if (!myHomeDir) myHomeDir = homePath (tmp); 1.230 + return myHomeDir ? myHomeDir : homeDrive (); 1.231 +} 1.232 + 1.233 +/* Return system standard INBOX 1.234 + * Accepts: buffer string 1.235 + */ 1.236 + 1.237 +char *sysinbox () 1.238 +{ 1.239 + char tmp[MAILTMPLEN]; 1.240 + if (!sysInbox) { /* initialize if first time */ 1.241 + sprintf (tmp,"%s\\INBOX",myhomedir ()); 1.242 + sysInbox = cpystr (tmp); /* system inbox is from mail spool */ 1.243 + } 1.244 + return sysInbox; 1.245 +} 1.246 + 1.247 + 1.248 +/* Return mailbox file name 1.249 + * Accepts: destination buffer 1.250 + * mailbox name 1.251 + * Returns: file name 1.252 + */ 1.253 + 1.254 +char *mailboxfile (char *dst,char *name) 1.255 +{ 1.256 + char *dir = myhomedir (); 1.257 + *dst = '\0'; /* default to empty string */ 1.258 + if (((name[0] == 'I') || (name[0] == 'i')) && 1.259 + ((name[1] == 'N') || (name[1] == 'n')) && 1.260 + ((name[2] == 'B') || (name[2] == 'b')) && 1.261 + ((name[3] == 'O') || (name[3] == 'o')) && 1.262 + ((name[4] == 'X') || (name[4] == 'x')) && !name[5]) name = NIL; 1.263 + /* reject namespace names or names with / */ 1.264 + if (name && ((*name == '#') || strchr (name,'/'))) return NIL; 1.265 + else if (!name) return dst; /* driver selects the INBOX name */ 1.266 + /* absolute path name? */ 1.267 + else if ((*name == '\\') || (name[1] == ':')) return strcpy (dst,name); 1.268 + /* build resulting name */ 1.269 + sprintf (dst,"%s\\%s",dir,name); 1.270 + return dst; /* return it */ 1.271 +} 1.272 + 1.273 + 1.274 +/* Determine default prototype stream to user 1.275 + * Accepts: type (NIL for create, T for append) 1.276 + * Returns: default prototype stream 1.277 + */ 1.278 + 1.279 +MAILSTREAM *default_proto (long type) 1.280 +{ 1.281 + extern MAILSTREAM CREATEPROTO,APPENDPROTO; 1.282 + return type ? &APPENDPROTO : &CREATEPROTO; 1.283 +} 1.284 + 1.285 +/* Emulator for BSD syslog() routine 1.286 + * Accepts: priority 1.287 + * message 1.288 + * parameters 1.289 + */ 1.290 + 1.291 +void syslog (int priority,const char *message,...) 1.292 +{ 1.293 +} 1.294 + 1.295 + 1.296 +/* Emulator for BSD openlog() routine 1.297 + * Accepts: identity 1.298 + * options 1.299 + * facility 1.300 + */ 1.301 + 1.302 +void openlog (const char *ident,int logopt,int facility) 1.303 +{ 1.304 +}