#include <sys/types.h>
|
#include <time.h>
|
#include "maplec.h"
|
ALGEB M_DECL MyTimeList( MKernelVector kv, ALGEB *args )
|
{
|
time_t c;
|
struct tm *t;
|
ALGEB list, elem, val;
|
char *code;
|
M_INT n, i;
|
if( MapleNumArgs(kv,(ALGEB)args) != 1 ) {
|
MapleRaiseError(kv,"one argument expected");
|
return( NULL );
|
}
|
if( !IsMapleList(kv,args[1]) ) {
|
MapleRaiseError(kv,"list expected");
|
return( NULL );
|
}
|
n = MapleNumArgs(kv,args[1]);
|
list = MapleListAlloc(kv,n);
|
c = time(&c);
|
t = localtime(&c);
|
for( i=1; i<=n; ++i ) {
|
elem = MapleListSelect(kv,args[1],i);
|
if( !IsMapleString(kv,elem) ) {
|
MapleRaiseError1(kv,"string expected for %-1 parameter",
|
ToMapleInteger(kv,i));
|
return( NULL );
|
}
|
code = MapleToString(kv,elem);
|
if( strcmp(code,"SS") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_sec);
|
}
|
else if( strcmp(code,"MM") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_min);
|
}
|
else if( strcmp(code,"HH") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_hour);
|
}
|
else if( strcmp(code,"dd") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_mday);
|
}
|
else if( strcmp(code,"mm") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_mon);
|
}
|
else if( strcmp(code,"yy") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_year+1900);
|
}
|
else if( strcmp(code,"ww") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_wday);
|
}
|
else if( strcmp(code,"jj") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_yday);
|
}
|
else if( strcmp(code,"vv") == 0 ) {
|
val = ToMapleInteger(kv,t->tm_isdst);
|
}
|
else {
|
MapleRaiseError1(kv,"unrecognized format code, %1",elem);
|
return( NULL );
|
}
|
MapleListAssign(kv,list,i,val);
|
}
|
return( list );
|
}
|