#define get32l(p) ((p)[0] | (p)[1] << 8 | (p)[2] << 16 | (p)[3] << 24)
int autodecomp(int siz0, UCHAR *p0, int siz)
{
unsigned char *b = p0, *c, *c0;
int s, i, e = 0;
if (get32l(b + 0x08) == 0x5341534f && get32l(b + 0x0c) == 0x504d434b) {
if (get32l(b + 0x04) == 0x00000001) {
unsigned int t = get32l(b);
e |= 1;
void put32l(UCHAR *p, unsigned int d)
{
p[0] = d & 0xff;
p[1] = (d >> 8) & 0xff;
p[2] = (d >> 16) & 0xff;
p[3] = (d >> 24) & 0xff;
return;
}
void sar_time2uc(struct sar_attrtime *at, UCHAR *uc24)
{
int i;
put32l(&uc24[0], at->subsec);
/* uc24ではsubsecは1000-1000-1000形式 */
put32l(&uc24[4], at->sec | at->min << 6 | at->hour << 12
| at->day << 17 | at->mon << 22 | (at->year & 0x1f) << 27);
/* yyyyymmm_mmdddddh_hhhhmmmmm_mmssssss */
put32l(&uc24[8], at->year >> 5);
for (i = 12; i < 24; i++)
uc24[i] = 0;
if (at->subsec == -1) {
put32l(&uc24[0], 0);
put32l(&uc24[4], 0x1f << 22); /* 31月にする */
put32l(&uc24[8], 0);
}
return;
}
void sar_uc2time(UCHAR *uc24, struct sar_attrtime *at)
{
unsigned int i = get32l(&uc24[4]);
at->subsec = get32l(&uc24[0]);
at->sec = i & 0x3f;
at->min = (i >> 6) & 0x3f;
at->hour = (i >> 12) & 0x1f;
at->day = (i >> 17) & 0x1f;
at->mon = (i >> 22) & 0x1f;
at->year = i >> 27 | get32l(&uc24[8]) << 5;
if (at->mon == 0x1f)
at->subsec |= -1;
return;
}
以下未完成
void sar_shiftluc24(UCHAR *uc24, int shft)
/* 1〜31 */
{
int i;
while (shft >= 8) {
for (i = 23; i >= 1; i--)
uc24[i] = uc24[i - 1];
uc24[0] = 0;
}
for (i = 24; i >= 0; i--) {
uc24[i] <<= shft;
if (i)
uc24)[i] |= uc24[i - 1] >> (8 - shft);
}
return;
}
void sar_shiftruc24(UCHAR *uc24, int shft)
/* 1〜31 */
{
int i;
for (i = 0; i < 6; i++) {
((unsigned int *) uc24)[i] >>= shft;
if (i < 5)
((unsigned int *) uc24)[i] |= ((unsigned int *) uc24)[i + 1] << (32 - shft);
}
return;
}
- 勝手にコメント欄つけてしまいました。以下、でやってみましたが、だめでした。でも動作をかえてやると時刻の結果がかわるので、関連しているのは間違いなさそうです。 -- くーみん 2005-05-23 (月) 19:28:46
void sar_shiftluc24(UCHAR *uc24, int shft)
/* 1〜31 */
{
int i;
while (shft >= 8) {
for (i = 24; i >= 1; i--)
uc24[i] = uc24[i - 1];
uc24[0] = 0;
shft-=8;
}
for (i = 24; i >= 1; i--) {
uc24[i] <<= shft;
if (i)
uc24[i] |= uc24[i - 1] >> (8 - shft);
}
return;
}
void sar_shiftruc24(UCHAR *uc24, int shft)
/* 1〜31 */
{
int i;
while(shft>=8){
for (i = 0; i <24; i++)
uc24[i] = uc24[i + 1];
uc24[24] = 0;
shft-=8;
}
for (i = 0; i <= 24; i++) {
uc24[i] >>= shft;
if (i<24)
uc24[i] |= uc24[i + 1] << (8 - shft);
}
return;
}