I am doing some new functions and while writing I seen several approaches from some sample code styles, and want it to find out a much cleaner/better "way" "form" if is possible.
Here is one of the new functions I am working:
//call in autolisp: (getweeknumber 2005 12 22)
static int ads_getweeknumber(void)
{
struct resbuf *rb=acedGetArgs();
int year,month,day;
if (!rb ||
rb->restype != RTSHORT ||
!rb->rbnext ||
rb->rbnext->restype != RTSHORT ||
!rb->rbnext->rbnext ||
rb->rbnext->rbnext->restype != RTSHORT ||
rb->rbnext->rbnext->rbnext
) {
acutPrintf("\nInvalid: function expects three integer arguments!\n" );
return RSERR;
}
else {
// get the first argument
year=rb->resval.rint;
// get the second argument
rb=rb->rbnext;
month=rb->resval.rint;
// get the third argument
rb=rb->rbnext;
day=rb->resval.rint;
// is not required
////acutRelRb(rb);
CWeek date;
date.setDate(year,month,day); //(2005,12,22);
int nWeeknumber=date.getWeeknumber();
// return to autolisp the week number or nil
acedRetInt(nWeeknumber);
//int nWeekday=date.getWeekday();
}//else
return (RSRSLT) ;
}
Or...
static int ads_getweeknumber(void)
{
struct resbuf *rb=acedGetArgs();
int year,month,day;
if (rb->restype != RTSHORT){
acutPrintf("\n1st. argument invalid.");
return RSERR;
}
year=rb->resval.rint;
rb=rb->rbnext;
if (rb==NULL || rb->restype != RTSHORT){
acutPrintf("\n2nd. argument invalid.");
return RSERR;
}
month=rb->resval.rint;
rb=rb->rbnext;
if (rb==NULL || rb->restype != RTSHORT){
acutPrintf("\n3rd. argument invalid.");
return RSERR;
}
day=rb->resval.rint;
// is not required
//acutRelRb(rb);
CWeek date;
date.setDate(year,month,day); //(2005,12,22);
int nWeeknumber=date.getWeeknumber();
// return to autolisp the week number or nil
acedRetInt(nWeeknumber);
//int nWeekday=date.getWeekday();
return (RSRSLT) ;
}
Or... something like the following [I did not including any error handler, it is just prototype]
static int ads_getweeknumber(void)
{
struct resbuf *rb=acedGetArgs();
int year,month,day;
// get the first argument
if (rb && (rb->restype==RTSHORT)){
year=rb->resval.rint;
rb=rb->rbnext;
}
// get the second argument
if (rb && (rb->restype==RTSHORT)){
month=rb->resval.rint;
rb=rb->rbnext;
}
// get the third argument
if (rb && (rb->restype==RTSHORT)){
day=rb->resval.rint;
rb=rb->rbnext;
}
// is not required
//acutRelRb(rb);
CWeek date;
date.setDate(year,month,day); //(2005,12,22);
int nWeeknumber=date.getWeeknumber();
// return to autolisp the week number or nil
acedRetInt(nWeeknumber);
return (RSRSLT) ;
}
Thanks.