/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1996 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#endif
/*LINTLIBRARY*/
#include <locale.h>
#include <time.h>
#include <string.h>
static char *getstr(/*char *p, char **strp*/);
static char *itoa();
extern int stat();
extern char *getenv();
extern char *malloc();
extern int openlocale(/*char *category, int cat_id, char *locale, char *newlocale */);
extern void init_statics();
extern char _my_time[];
char *getlocale_time();
int
{
register char *cp, *p, c;
int size;
int i, temp;
(void) getlocale_time();
/* Build date string by parsing format string */
size = 0;
while ((c = *format++) != '\0') {
if (c == '%') {
switch (*format++) {
case '%': /* Percent sign */
return (0);
*cp++ = '%';
break;
case 'a': /* Abbreviated weekday name */
*p != '\0'; p++) {
return (0);
*cp++ = *p;
}
break;
case 'A': /* Weekday name */
*p != '\0'; p++) {
return (0);
*cp++ = *p;
}
break;
case 'h':
case 'b': /* Abbreviated month name */
*p != '\0'; p++) {
return (0);
*cp++ = *p;
}
break;
case 'B': /* Month name */
*p != '\0'; p++) {
return (0);
*cp++ = *p;
}
break;
case 'c': /* date and time representation */
if (i == 0)
return (0);
cp += i;
size += i;
break;
case 'C': /* long date and time representation */
if (i == 0)
return (0);
cp += i;
size += i;
break;
case 'd': /* Day of month, with leading zero */
return (0);
break;
case 'D': /* Shorthand for %m/%d/%y */
tm);
if (i == 0)
return (0);
cp += i;
size += i;
break;
case 'e': /* Day of month without leading zero */
return (0);
*cp++ = ' ';
} else
break;
case 'H': /* Hour (24 hour version) */
return (0);
break;
case 'I': /* Hour (12 hour version) */
return (0);
cp, 2);
break;
case 'j': /* Julian date */
return (0);
break;
case 'k': /* Hour (24 hour version) */
return (0);
*cp++ = ' ';
} else
break;
case 'l': /* Hour (12 hour version) */
return (0);
if (temp < 10) {
*cp++ = ' ';
} else
break;
case 'm': /* Month number */
return (0);
break;
case 'M': /* Minute */
return (0);
break;
case 'n': /* Newline */
return (0);
*cp++ = '\n';
break;
case 'p': /* AM or PM */
else
for (; *p != '\0'; p++) {
return (0);
*cp++ = *p;
}
break;
case 'r': /* Shorthand for %I:%M:%S AM or PM */
tm);
if (i == 0)
return (0);
cp += i;
size += i;
break;
case 'R': /* Time as %H:%M */
if (i == 0)
return (0);
cp += i;
size += i;
break;
case 'S': /* Seconds */
return (0);
break;
case 't': /* Tab */
return (0);
*cp++ = '\t';
break;
case 'T': /* Shorthand for %H:%M:%S */
tm);
if (i == 0)
return (0);
cp += i;
size += i;
break;
case 'U': /* Weekday number, taking Sunday as
* the first day of the week */
return (0);
if (temp >= -3 ) {
i++;
} else
i = 52;
break;
case 'w': /* Weekday number */
return (0);
break;
case 'W': /* Week number of year, taking Monday as
* first day of week */
return (0);
else
if (temp >= -3) {
-tm->tm_wday */
i++;
} else
i = 52; /* less than 4 days in the first
week causes it to belong to
the tail of prev year */
break;
case 'x': /* Localized date format */
if (i == 0)
return (0);
cp += i;
size += i;
break;
case 'X': /* Localized time format */
if (i == 0)
return (0);
cp += i;
size += i;
break;
case 'y': /* Year in the form yy */
return (0);
break;
case 'Y': /* Year in the form ccyy */
return (0);
break;
case 'Z': /* Timezone */
return (0);
*cp++ = *p;
}
break;
default:
return (0);
*cp++ = c;
break;
}
} else {
return (0);
*cp++ = c;
}
}
*cp = '\0';
return(size);
}
static char *
register int i;
register char *ptr;
register int dig;
{
switch(dig) {
case 4:
i = i - i / 1000 * 1000;
case 3:
i = i - i / 100 * 100;
case 2:
case 1:
}
return(ptr);
}
char *
{
register int fd;
char *str;
register char *p;
register int i;
if (_locales[0][0] == '\0')
init_statics();
/* Here we use the string newlocales to set time constants
* which should have been saved
* from a previous call to setlocale. We deferred the read until now
*/
if (dtconv_str == NULL) {
/*
* Below is executed if getlocale_time()
* is called when LC_TIME locale is initial
* C locale.
*/
/*
* Just to make openlocale() to read LC_TIME file.
*/
goto initial;
}
return dtconv_str;
}
return (NULL);
if (fd == 0)
return dtconv_str;
return (NULL);
return (NULL);
}
return (NULL);
}
/* Set last character of str to '\0' */
*p++ = '\n';
*p = '\0';
/* p will "walk thru" str */
p = str;
for (i = 0; i < 12; i++) {
if (p == NULL)
goto fail;
}
for (i = 0; i < 12; i++) {
if (p == NULL)
goto fail;
}
for (i = 0; i < 7; i++) {
if (p == NULL)
goto fail;
}
for (i = 0; i < 7; i++) {
if (p == NULL)
goto fail;
}
if (p == NULL)
goto fail;
if (p == NULL)
goto fail;
if (p == NULL)
goto fail;
if (p == NULL)
goto fail;
if (p == NULL)
goto fail;
if (p == NULL)
goto fail;
/*
* set info.
*/
if (dtconv_str != NULL)
dtconv_str = str;
/* The following is to get space malloc'd for _dtconv */
if (_dtconv == 0)
(void) localdtconv();
return (dtconv_str);
fail:
return (NULL);
}
static char *
register char *p;
char **strp;
{
*strp = p;
p = strchr(p, '\n');
if (p == NULL)
return (NULL); /* no end-of-line */
*p++ = '\0';
return (p);
}