cal.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <langinfo.h>
#include <locale.h>
#include <nl_types.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
static int number(char *);
static int jan1(const int);
static void badmonth(void);
static void badyear(void);
static void usage(void);
static void cal(const int, const int, char *, const int);
static void load_months(void);
static void pstr(char *, const int);
#define DAYW " S M Tu W Th F S"
#define TITLE " %s %u\n"
#define YEAR "\n\n\n\t\t\t\t%u\n\n"
#define MONTH "\t%4.3s\t\t\t%.3s\t\t%10.3s\n"
static char *months[] = {
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December",
};
static char *short_months[] = {
"Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec",
};
static char mon[] = {
0,
31, 29, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31,
};
static char *myname;
static char string[432];
int
{
int y, i, j;
int m;
char *time_locale;
char *ldayw;
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
usage();
load_months();
/*
* TRANSLATION_NOTE
* This message is to be used for displaying
* the names of the seven days, from Sunday to Saturday.
* The length of the name of each one should be two or less.
*/
switch (argc) {
case 0:
break;
case 1:
goto xlong;
case 2:
break;
default:
usage();
}
/*
* print out just month
*/
if (m < 1 || m > 12)
badmonth();
if (y < 1 || y > 9999)
badyear();
/*
* TRANSLATION_NOTE
* This message is to be used for displaying
* specified month and year.
*/
for (i = 0; i < 6*24; i += 24)
return (0);
/*
* print out complete year
*/
if (y < 1 || y > 9999)
badyear();
/*
* TRANSLATION_NOTE
* This message is to be used for displaying
* specified year.
*/
for (i = 0; i < 12; i += 3) {
for (j = 0; j < 6*72; j++)
string[j] = '\0';
/*
* TRANSLATION_NOTE
* This message is to be used for displaying
* names of three months per a line and should be
* correctly translated according to the display width
* of the names of months.
*/
(void) printf(
for (j = 0; j < 6*72; j += 72)
}
(void) printf("\n\n\n");
return (0);
}
static int
{
int n, c;
char *s;
n = 0;
s = str;
/*LINTED*/
while (c = *s++) {
if (c < '0' || c > '9')
return (0);
n = n*10 + c-'0';
}
return (n);
}
static void
{
int i;
char *s;
s = str;
i = n;
while (i--)
if (*s++ == '\0')
s[-1] = ' ';
i = n+1;
while (i--)
if (*--s != ' ')
break;
s[1] = '\0';
}
static void
cal(const int m, const int y, char *p, const int w)
{
int d, i;
char *s;
s = (char *)p;
d = jan1(y);
/*
* non-leap year
*/
case 1:
break;
/*
* 1752
*/
default:
break;
/*
* leap year
*/
case 2:
;
}
for (i = 1; i < m; i++)
d += mon[i];
d %= 7;
s += 3*d;
for (i = 1; i <= mon[m]; i++) {
i += 11;
mon[m] += 11;
}
if (i > 9)
*s = i/10+'0';
s++;
*s++ = i%10+'0';
s++;
if (++d == 7) {
d = 0;
s = p+w;
p = s;
}
}
}
/*
* return day of the week
* of jan 1 of given year
*/
static int
{
int y, d;
/*
* normal gregorian calendar
* one extra day per four years
*/
y = yr;
d = 4+y+(y+3)/4;
/*
* julian calendar
* regular gregorian
* less three days per 400
*/
if (y > 1800) {
d -= (y-1701)/100;
d += (y-1601)/400;
}
/*
* great calendar changeover instant
*/
if (y > 1752)
d += 3;
return (d%7);
}
static void
load_months(void)
{
int month;
}
static void
badmonth()
{
usage();
}
static void
badyear()
{
usage();
}
static void
usage(void)
{
exit(1);
}