Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!dali.cs.montana.edu!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!ub!uhura.cc.rochester.edu!ee.rochester.edu!rochgate!erik From: erik@rochgate.FIDONET.ORG (Erik VanRiper) Newsgroups: comp.sources.wanted Subject: System V-compatible ctime(3)??? Message-ID: <8.26DD7F2B@rochgate.FIDONET.ORG> Date: 30 Aug 90 20:57:20 GMT Organization: Erik -N- Chris's Nest BBS, Rochester, NY (716-328-3405) Lines: 191 > From: wnp@iiasa.AT (wolf paul) > Date: 30 Aug 90 12:40:16 GMT > Organization: IIASA, Laxenburg/Vienna, Austria, Europe > Message-ID: <862@iiasa.UUCP> > Newsgroups: alt.sources.d,comp.sources.wanted,comp.sources.d,comp.lang.c > > In order to compile the recently-posted "ago" program, I am looking > for a System V or POSIX-compatible ctime(3) library. Specifically, > I need a cftime() or strftime() routine. > > Thanks! > -- > Wolf N. Paul, IIASA, A - 2361 Laxenburg, Austria, Europe > PHONE: +43-2236-71521-465 FAX: +43-2236-71313 UUCP: > uunet!iiasa.at!wnp > INTERNET: wnp%iiasa.at@uunet.uu.net BITNET: > tuvie!iiasa!wnp@awiuni01.BITNET > * * * * Kurt Waldheim for President (of Mars, of course!) * * * * Here is a routine for you.....strftime() #include #include #include #include char months[][10]={"January","February","March","April","May", "June","July","August","September","October", "November","December"}; char months_ab[][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul", "Aug","Sep","Oct","Nov","Dec"}; char weekday[][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday", "Friday","Saturday"}; char weekday_ab[][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; /* Note: TZ environment variable MUST be defined to use the %Z function! */ int strftime(char *string,int maxsize,char *format,struct tm *current_time) { char *in, *out, *scrptr; char temp[250]; maxsize=min(maxsize,230); for (in=format,out=temp;*in;in++) { if ((int)(out-(int)temp) >= maxsize) break; if (*in=='%') { switch(*++in) { case 'a': strcpy(out,weekday_ab[current_time->tm_wday]); break; case 'A': strcpy(out,weekday[current_time->tm_wday]); break; case 'b': strcpy(out,months_ab[current_time->tm_mon]); break; case 'B': strcpy(out,months[current_time->tm_mon]); break; case 'c': sprintf(out,"%02d-%02d-%02d %02d:%02d:%02d", current_time->tm_mon+1, current_time->tm_mday, current_time->tm_year, current_time->tm_hour, current_time->tm_min, current_time->tm_sec); break; case 'd': sprintf(out,"%02d",current_time->tm_mday); break; case 'H': sprintf(out,"%02d",current_time->tm_hour); break; case 'I': sprintf(out,"%02d", (current_time->tm_hour >= 0 && current_time->tm_hour <= 12 ? current_time->tm_hour : current_time->tm_hour-12)); break; case 'j': sprintf(out,"%03d",current_time->tm_yday+1); break; case 'm': sprintf(out,"%02d",(current_time->tm_mon)+1); break; case 'M': sprintf(out,"%02d",current_time->tm_min); break; case 'p': strcpy(out,(current_time->tm_hour < 12 ? "am" : "pm")); break; case 'S': sprintf(out,"%02d",current_time->tm_sec); break; case 'U': /* ??? */ sprintf(out,"%02d",(current_time->tm_yday)/7); break; case 'w': sprintf(out,"%d",current_time->tm_wday); break; case 'W': /* ??? */ sprintf(out,"%02d",(current_time->tm_yday)/7); break; case 'x': sprintf(out,"%02d-%02d-%02d", (current_time->tm_mon)+1, current_time->tm_mday, current_time->tm_year); break; case 'X': sprintf(out,"%02d:%02d:%02d", current_time->tm_hour, current_time->tm_min, current_time->tm_sec); break; case 'y': sprintf(out,"%02d",current_time->tm_year); break; case 'Y': sprintf(out,"%02d",current_time->tm_year+1900); break; case 'Z': /* ??? */ if ((scrptr=getenv("TZ")) != 0) { scrptr[3]=0; strcpy(out,strupr(scrptr)); } else strcpy(string,"??T"); break; case '%': strcpy(out,"%"); break; } out += strlen(out); } else *out++=*in; } *out='\0'; strcpy(string,temp); return(strlen(string)); } --- FD 1.99c * Origin: ENC BBS. A Nodeling in Disguise HST/V42b (1:260/230) -- --------------------------------------------- Programmers Distribution Network Coordinator FidoNet: 1:260/230 ---------------------------------------------