Using Clipper C-Functions within FWH ?

Using Clipper C-Functions within FWH ?

Postby ukoenig » Wed Dec 31, 2008 11:31 am

Hello,

because I don't know very much about C-programming,
I have a question using existing C-functions from Clipper-times.
In my collection, there are many useful C-sources ( h - files included ).
Is there something special, to take care of ?

C - sample to calculate the ISO-week-Number ( week-splitting, julian-date and leap-year is calculated ) :

Code: Select all  Expand view
#include "extend.h"
#include "headpwa5.h"

extern int  _dat_pruef(int, int, int), _is_schalt(int);
extern long _jul_datum(int, int, int);
extern void _datum(int *, int *, int *, long);

/*  Call :   WOCHNR( <day>, <month>, <year> )
*            WOCHNR( <date> )
*  Function: ISO-Week-No. of a given Date
*  Return:   Week-Number
*  Note:     expN = <day>, <month>, <year>
*            expD = <date>
*/
CLIPPER WOCHNR()
{
  int  tag, monat, jahr, anz_tg, wochnr, dow;
  long dtm, wrkdtm;
  char *datum;

  if( PCOUNT == 3 && ISNUM(1) && ISNUM(2) && ISNUM(3) )
  {
    tag   = _parni(1);
    monat = _parni(2);
    jahr  = _parni(3);
    jahr += jahr < 100 ? 1900 : 0;
    if(_dat_pruef(tag, monat, jahr) < 0)
    {
      _retni(-1);      /* Error */
      return;
    }
  }
  else if( PCOUNT == 1 && ISDATE(1) )
  {
    datum = _pards(1);
    _date_to_num(datum, &tag, &monat, &jahr);
  }
  else
  {
    _retl(FALSE);   /* .F., because of error */
    return;
  }

  dtm    = _jul_datum(tag, monat, jahr);
  wrkdtm = _jul_datum(1, 1, jahr);     /* Date1.1.jj */
  while(1)
  {
    dow  = (wrkdtm % 7L) + 1;           /* Week-day Mo=1,...So=7 */
    if(dow > 1 && dow <= 4)
      wrkdtm -= 7L;                             /* Week before */

    while(1)
    {
      dow = (wrkdtm % 7L) + 1;           /* Week-day Mo=1,...So=7 */
      if(dow == 1)                                  /* 1. Monday seek */
        break;                                         /* stop */
      wrkdtm++;
    }

    anz_tg = (int)(dtm - wrkdtm);          /* running day from 1. Monday */
    if(anz_tg >= 0)
      break;                                            /* stop */
    wrkdtm = _jul_datum(1, 1, jahr - 1);     /* Date 1.1. year before */
  }

  wochnr = (anz_tg / 7) + 1;                      /* Week-No. */
  if(wochnr == 53)
  {
    wrkdtm = _jul_datum(1, 1, jahr + 1);  /* Date 1.1. next year */
    dow    = (wrkdtm % 7L) + 1;               /* Weekday Mo=1,...So=7 */
    if(dow >= 1 && dow <= 4)
      wochnr = 1;
  }
  _retni(wochnr);
}



Regards
Uwe :roll:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Using Clipper C-Functions within FWH ?

Postby Antonio Linares » Wed Dec 31, 2008 11:45 am

Uwe,

You can easily convert them to work with Harbour/xharbour:

1. Instead of #include "extend.h" use #include <hbapi.h>

2. Use the hb_ prefix for all the extend system functions. i.e.: use hb_parni() instead of _parni(). hb_ret...() instead of _ret...().

3. As we are working in 32 bits, use hb_parnl() instead of hb_parni().

4. Instead of CLIPPER WOCHNR(), use HB_FUNC( WOCHNR )

Thats a good start point :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42080
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using Clipper C-Functions within FWH ?

Postby ukoenig » Wed Dec 31, 2008 1:18 pm

Antonio,

thank You very much for the information.
To convert my existing C-functions, makes many things much better to use.

Regards and < Happy new Year >
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests

cron