home *** CD-ROM | disk | FTP | other *** search
- /*
- * sgettime.c
- * contains: sgettime(),fmttime(),ggettime()
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include "gfuncts.h"
-
-
- void GF_CONV_xstrncpy();
-
- static char stam[]="am";
- static char stpm[]="pm";
-
- /*
- * struct TIMEDATE *
- * sgettime(f)
- *
- * ARGUMENT
- * (int) f - format specifier (see manual)
- *
- * DESCRIPTION
- * This function obtains the time from the system and places integer and
- * ASCII string values in the respective buffer positions.
- *
- * RETURNS
- * Pointer to structure containing the time and date. This is set to 0 if
- * the time has not been set.. i.e. if the system indicates Jan 1, 1980.
- */
- struct TIMEDATE * GF_CONV sgettime(f)
- int f;
- {
- static struct TIMEDATE buf,*ptd;
-
- fetchtime(&buf);
- ptd=fmttime(&buf,f);
- return ptd;
- }
-
- /*
- * struct TIMEDATE *
- * fmttime(ptd,f)
- *
- * ARGUMENT
- * (struct TIMEDATE *) ptd - structure containing integer variables
- * (int) f - as above in sgettime
- *
- * DESCRIPTION
- * Examines the integer values in a TIMEDATE structure and produces a string
- * result suitable for printing. Formatting is according to the format
- * specification f.
- *
- * RETURNS
- * Pointer to structure containing string.
- */
- struct TIMEDATE * GF_CONV fmttime(ptd,f)
- struct TIMEDATE *ptd;
- int f;
- {
- char *pm, *pwkday,*am_pm,adate[40],atime[25],temp[45],aday[12];
- int wday,hr;
-
- pm=monthname(ptd->month);
- wday=dayweek(ptd->month,ptd->day,ptd->year);
- pwkday=wkday(wday);
- strcpy(aday,pwkday);
- switch (f) {
- case 2:
- case 3:
- case 12:
- case 13:
- case 22:
- case 23:
- sprintf(adate,"%9s %2d, %4d",pm,ptd->day,ptd->year);
- break;
- case 4:
- case 5:
- case 14:
- case 15:
- case 24:
- case 25:
- sprintf(adate,"%2d/%2d/%2d",ptd->month,ptd->day,
- (ptd->year%100));
- break;
- case 6:
- case 7:
- case 16:
- case 17:
- case 26:
- case 27:
- sprintf(adate,"%2d %.3s %2d",ptd->day,pm,
- (ptd->year%100));
- break;
- case 8:
- case 9:
- case 18:
- case 19:
- case 28:
- case 29:
- sprintf(adate,"%2d %.3s %4d",ptd->day,pm,ptd->year);
- break;
- case 0:
- case 10:
- case 20:
- case 30:
- sprintf(adate,"%02d-%.3s-%02d",ptd->day,pm,
- (ptd->year%100));
- break;
- default:
- case 1:
- case 11:
- case 21:
- sprintf(adate,"%.3s %2d, %4d",pm,ptd->day,ptd->year);
- break;
- }
- if(ptd->hours<=12)
- hr=(ptd->hours==0)?12:ptd->hours;
- if(f==3||f==5||f==7||f==13||f==15||f==17||f==23||f==25||f==27||
- f==29||f==9||f==19||f==19)
- sprintf(atime,"%02d:%02d:%02d.%02d",ptd->hours,ptd->minutes,
- ptd->seconds,ptd->hsecs);
- else if(f==0||f==10||f==20||f==30) {
- am_pm=(ptd->hours>=12)?stpm:stam;
-
- if(ptd->hours>12)
- sprintf(atime,"%2d:%02d:%02d%s ",(ptd->hours-12),
- ptd->minutes,ptd->seconds,am_pm );
- else
- sprintf(atime,"%2d:%02d:%02d%s ",hr,ptd->minutes,
- ptd->seconds,am_pm);
- } else
- sprintf(atime,"%02d:%02d:%02d ",ptd->hours,ptd->minutes,
- ptd->seconds);
- if((f>=10&&f<=30)||f==0) {
- strcpy(temp,adate);
- if(f==0||(f>=20&&f<=30))
- _xstrncpy(adate,aday,3);
- else
- strcpy(adate,aday);
- if(f>=11&&f<=19)
- strcat( adate, ", " );
- else
- strcat( adate, " " );
- strcat(adate,temp);
- }
- strcpy(ptd->dateline,adate);
- strcat(ptd->dateline," - ");
- strcat(ptd->dateline, atime);
- return ptd;
- }
-
- /* special no-return string copy n characters for fmttime().
- */
- void GF_CONV _xstrncpy(to,fro,n)
- char *to,*fro;
- unsigned n;
- {
- char *p;
-
- for(p=to;n--&&(*p++ = *fro++);)
- ;
- if(n==0xFFFF)
- *p=0;
- }
-
- /*
- * struct TIMEDATE *
- * ggettime(void)
- *
- * ARGUMENT
- * none
- *
- * DESCRIPTION
- * Obtain the time from the system and places integer and ASCII string
- * values in the respective buffer positions.
- *
- * RETURNS
- * Pointer to structure containing the time and date.
- * This is set to 0 if the time has not been set.. i.e.
- * if the system indicates Jan 1, 1980.
- * MODIFICATIONS
- * David Nienhiser Wed 11-Jan-1989 10:50:46
- * Renamed to ggettime() from gettime() to avoid name collisions with
- * compiler library.
- */
- struct TIMEDATE * GF_CONV ggettime()
- {
- struct TIMEDATE * GF_CONV sgettime();
- return sgettime(0);
- }
-