#define _CRT_SECURE_NO_WARNINGS
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define WEEK "日 月 火 水 木 金 土"
// プロトタイプ宣言
void dispcal(int year, int month);
void subcal(int year, int month, int col);
void strfmt(void* dest, char* fmt, int i);
void normalize(int* pyear, int* pmonth);
int scanym(char* buf, int* pyear, int* pmonth);
// グローバル変数
char disp[8][80];
int main(int argc, char* argv[])
{
struct tm* ptm;
time_t timer;
char buf[8];
int year;
int month;
int ch;
int flag;
int i;
year = ptm->tm_year + 1900;
month = ptm->tm_mon + 1;
if (argc == 2) {
scanym(argv[1], &year, &month);
}
while (1) {
dispcal(year, month);
i = 0;
do {
ch = _getch();
flag = 0;
switch (ch) {
case 0x0d: // Enter
buf[i] = '\0';
if (scanym(buf, &year, &month)) {
dispcal(year, month);
_getch();
}
break;
case 0x1b: // ESC
return 0;
case 0x48: // up
month -= 3;
break;
case 0x49: // PageUp
year--;
break;
case 0x4b: // left
month--;
break;
case 0x4d: // right
month++;
break;
case 0x50: // down
month += 3;
break;
case 0x51: // PageDown
year++;
break;
case 0xe0: // 読み飛ばし
default:
flag = 1;
}
if (i < 7) {
buf[i++] = ch;
}
}
} while (flag);
normalize(&year, &month);
}
return 0;
}
// 3ヶ月分のカレンダーを表示
void dispcal(int year, int month)
{
int i;
for (i = 0; i < 8; i++) {
disp[i][79] = '\0';
}
subcal(year, month - 1, 0);
subcal(year, month, 24);
subcal(year, month + 1, 24 * 2);
for (i = 0; i < 8; i++) {
}
}
// 1ヶ月分のカレンダーを作成
void subcal(int year, int month, int col)
{
struct tm tm;
struct tm* ptm;
time_t timer;
int line;
int i;
normalize(&year, &month);
strfmt(disp[0] + col, "%d", year);
strfmt(disp[0] + col + 8, "%d月", month);
tm.tm_year = year - 1900;
tm.tm_mon = month - 1;
tm.tm_mday = 1;
line = 2;
for (i = 1; i <= 31; i++) {
if (ptm->tm_mon != month - 1) {
break;
}
if (ptm->tm_wday == 0 && 1 < i) {
line++;
}
strfmt(disp[line] + col + ptm->tm_wday * 3, "%2d", i);
timer += 24 * 60 * 60;
}
}
// 整数を指定書式でメモリにコピー
void strfmt(void* dest, char* fmt, int i)
{
char buf[8];
}
// 年月を正常化
void normalize(int* pyear, int* pmonth)
{
if (*pmonth < 1) {
*pyear--;
*pmonth += 12;
}
if (12 < *pmonth) {
*pyear++;
*pmonth -= 12;
}
}
// 年月を解釈
int scanym(char* buf, int* pyear, int* pmonth)
{
struct tm* ptm;
time_t timer;
int year;
int month;
switch (sscanf(buf
, "%d/%d", &year
, &month
)) { case 1:
if (year < 100) { // MM
month = year;
year = ptm->tm_year + 1900;
} else { // YYYYMM
month = year % 100;
year /= 100;
}
break;
case 2:
if (year < 100) { // YY/MM
year += (year < 75) ? 2000 : 1900;
}
break;
default:
return -1;
}
if (year < 1975 || 3000 < year) {
return -1;
}
if (month < 1 || 12 < month) {
return -1;
}
*pyear = year;
*pmonth = month;
return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZSA8Y29uaW8uaD4KI2luY2x1ZGUgPGN0eXBlLmg+CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPHRpbWUuaD4KCiNkZWZpbmUgV0VFSwki5pelIOaciCDngasg5rC0IOacqCDph5Eg5ZyfIgoKLy8g44OX44Ot44OI44K/44Kk44OX5a6j6KiACnZvaWQJZGlzcGNhbChpbnQgeWVhciwgaW50IG1vbnRoKTsKdm9pZAlzdWJjYWwoaW50IHllYXIsIGludCBtb250aCwgaW50IGNvbCk7CnZvaWQJc3RyZm10KHZvaWQqIGRlc3QsIGNoYXIqIGZtdCwgaW50IGkpOwp2b2lkCW5vcm1hbGl6ZShpbnQqIHB5ZWFyLCBpbnQqIHBtb250aCk7CmludAlzY2FueW0oY2hhciogYnVmLCBpbnQqIHB5ZWFyLC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