DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2539
Version: 1.3-current


Jim Michaels wrote:

> hundreds of errors using mingw-w64.
> I give up on fltk.

Don't give up so fast.

> nothing I try with my program remotely compiles without some sort of
library error.

That's mainly because your program is far from being valid C++ code. See
attached (mostly) corrected file kitchentimer.cxx.

> usually because somebody thought it
> was a good idea to convert a pointer to a long int (bad idea in 64-bit
> target compilers, generates an error).

You're right, that *is* a bad design, but this decision has been made long
before (Windows) 64-bit systems have been available. And this is only a
problem on Windows, because MS were more interested in being compatible
with their own (Windows users') code than in being portable to other
existing 64-bit platforms (where sizeof(long) is 8).

We'll address this in a future version, but in FLTK 1.3 we didn't want to
change the API. There is a way to do it correctly on Windows 64-bit
though.

> I realize my program is not perfect yet, but there are some library bugs
> that are unacceptable which are preventing me from using fltk.

I don't think to. Please see below.

> library compiled with no complaints.  I assume it was because there was
no
> -W -Wall switches on gcc.

This assumption is wrong. Default compilation of the FLTK library is with
-Wall.

> take a look at the errgw file.  the source file is kitchentimer.cpp

This file is *very* long, and there are many, many simple (syntax and
other) bugs in it, so that it can't compile correctly with _any_ C++
compiler (e.g. missing ';', no prototypes for functions defined later in
the program code, wrong class definitions, and so on).

If you encounter compilation errors, a much better way would be to use a
program as simple as possible and work up to a working result.

I took the time to work out the programming errors in your code, though,
and the attached file compiles *almost* w/o errors. The remaining errors
are left as an exercise for you... ;-)

Now back to the *real* problem: casting void* to long. This should only
happen in callbacks that are declared:

 (static) void my_cb(Fl_Widget *w, void *data) {...};

If you want to cast the "void *data" argument to any int or long type, you
can use:

  long (or int) temp = (fl_intptr_t)data;

This *should* work, but I didn't see such code in your posted source code.

Unfortunately this is not documented sufficiently yet, but this is more a
Win64 than a FLTK problem. Note that fl_intptr_t is defined for
convenience only. You can also use

  long (or int) temp = (intptr_t)data;

but this is less portable to other platforms.

I hope that I could help you with this.

Note that the STR system should be used to report real bugs only. If you
have problems compiling your program, this is not necessarily a bug in
FLTK. If you are not sure, please post questions to fltk.general first to
get help compiling your program.

Please fix your program and let us know if all is well. This STR will be
closed in a few days otherwise.


Link: http://www.fltk.org/str.php?L2539
Version: 1.3-current
/*===============================================================================

 Program Name:     kitchentimer
 Abstract:      kitchen timer/stopwatch
 Requirement(s):   None
 Return Value(s):  None
 Author(s):        Jim Michaels <[email protected]>

 Copyright 2007 Jim Michaels

This file is part of timer.

    kitchentimer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    kitchentimer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with phone.  If not, see <http://www.gnu.org/licenses/>.



===============================================================================
*/
#define PROGRAM_VERSION "2.0"

#include <process.h>
#include <stdlib.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Check_Button.H>
#include <FL/Fl_Tooltip.H>
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Timer.H>
#include <windows.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <string>
#include <string.h>
#include <stdio.h>
// #include <tr1/stdint.h>

#include <cstring>
#include <string>
using namespace std;

// declare function prototypes
int64_t gettime();
int64_t stringtoDTIME(string dtimestr);
string elapsedtime();
double GregorianToJulian(int Y,int Mo,int D,int H,int Mi,int S,int ms);

class CMessageBox : public Fl_Window {
    static void OnOK(Fl_Widget *w, void *userdata) {
        //~CMessageBox();
        delete w;
    }
    private:
        Fl_Button *msgButton;
        Fl_Text_Display *td;

    public:
        Fl_Window *msgWindow;
        CMessageBox(char * wintitle, char * msg)
          : Fl_Window (141, 158, 326, 98, wintitle) {

            td = new Fl_Text_Display(5, 5, 315, 55);
            // td->value(msg);  // use either Fl_Output or attach 
Fl_Text_Buffer to Fl_Text_Display
            msgWindow->add(td);

            msgButton = new Fl_Button(120, 35, 70, 25, "&OK");
            msgButton->callback(OnOK);
            msgWindow->add(msgButton);

            msgWindow->set_modal();
            show();
        }
        ~CMessageBox() {
            delete msgWindow;
        }
};

class CKitchenTimerUI : public Fl_Window {
//    static void OnQuit(Fl_Widget *w, void *userdata) {

//    }
    static void OnBTNStartCountUp(Fl_Widget *w, void *userdata) {
            CKitchenTimerUI *ui = (CKitchenTimerUI*)w;
            ui->starttime=gettime();
            ui->countby=1;
    }
    static void OnBTNStartCountDown(Fl_Widget *w, void *userdata) {
            CKitchenTimerUI *ui = (CKitchenTimerUI*)w;
            int64_t temptimediff=stringtoDTIME(ui->TEXTin->value()); 
//temporary variable
            if (0==temptimediff) {
                ui->msgboxoops = new CMessageBox("kitchentimer input error", 
"the input must be in the format '15 days 23:59:59.999'");
                ui->TEXTin->value("0 days 00:00:00.000");
            } else {
                ui->starttime=gettime()+temptimediff;
                ui->countby=-1;
            }
    }
    static void OnBTNStop(Fl_Widget *w, void *userdata) {
            CKitchenTimerUI *ui = (CKitchenTimerUI*)w;
            ui->countby=0;
            ui->difftime=ui->curtime-ui->starttime;

    }
    static void OnBTNReset(Fl_Widget *w, void *userdata) {
            CKitchenTimerUI *ui = (CKitchenTimerUI*)w;
            ui->countby=0;
            ui->starttime=0;
            ui->difftime=0;
            ui->TEXTout->value("");
    }
    static void OnBTNDown(Fl_Widget *w, void *userdata) {
            CKitchenTimerUI *ui = (CKitchenTimerUI*)w;
            ui->countby=-1;
            
ui->starttime=gettime()+stringtoDTIME(ui->TEXTin->value())+ui->difftime;
            ui->curtime=gettime();
    }
    static void OnBTNUp(Fl_Widget *w, void *userdata) {
            CKitchenTimerUI *ui = (CKitchenTimerUI*)w;
            ui->countby=1;
            ui->starttime=gettime()-ui->difftime;
            ui->curtime=gettime();
    }
//    static void OnQuit(Fl_Widget *w, void *userdata) {

//    }
    public:
        int countby; //-1:countdown, 1:countup, 0:don't count
        int starttime;
        int curtime;
        int difftime;

        int execdone;
        Fl_Window *window;                      // for compatibility only, see 
below
        Fl_Button *BTNStartCountUp;
        Fl_Button *BTNUp;
        Fl_Button *BTNStop;
        Fl_Button *BTNReset;
        Fl_Button *BTNDown;
        Fl_Button *BTNStartCountDown;
        Fl_Input *TEXTin;
        Fl_Input *TEXTcmd;
        Fl_Output *TEXTout;
        Fl_Timer *timer;
        Fl_Check_Button *CHKbeep;
        Fl_Check_Button *CHKexec;
        CMessageBox * msgboxoops;
        CMessageBox * msgboxtimesup;
        //CHelpBox * helpbox;

        CKitchenTimerUI()
         : Fl_Window (9, 30, 628, 171, "") {            // Window title 
assigned later
            window = /* (Fl_Window*) */ this;           // you don't need the 
"window" member,
                                                        // because 
CKitchenTimerUI *is* an Fl_Window
            countby=starttime=curtime=execdone=0;
            difftime=curtime-starttime;
            string scaption("KitchenTimer v");          // local variable, will 
go out of scope
            scaption += PROGRAM_VERSION;
            window->copy_label(scaption.c_str());               // use 
copy_label() - see above -

            TEXTin = new Fl_Input(300, 10, 325, 25, "countdown time (format: 0 
days 00:00:00.000)");
            TEXTin->value("0 days 00:00:00.000");
            TEXTin->tooltip("format is '9999999 days 23:59:59.999'  no maximum 
on number of days.");
            window->add(TEXTin);

            TEXTout = new Fl_Output(300, 40, 325, 25, "Elapsed Time");
            TEXTout->tooltip("elapsed time or time counter");
            window->add(TEXTout);

            BTNStartCountUp = new Fl_Button(5, 70, 180, 25, "Reset and Start 
Count U&p");
            BTNStartCountUp->callback(OnBTNStartCountUp);
            window->add(BTNStartCountUp);

            BTNUp = new Fl_Button(190, 70, 50, 25, "&Up");
            BTNUp->callback(OnBTNUp);
            window->add(BTNUp);

            BTNStop = new Fl_Button(250, 70, 45, 25, "&Stop");
            BTNStop->callback(OnBTNStop);
            window->add(BTNStop);

            BTNReset = new Fl_Button(305, 70, 55, 25, "&Reset");
            BTNReset->callback(OnBTNReset);
            window->add(BTNReset);

            BTNDown = new Fl_Button(370, 70, 50, 25, "&Down");
            BTNDown->callback(OnBTNDown);
            window->add(BTNDown);

            BTNStartCountDown = new Fl_Button(430, 70, 195, 25, "Reset and 
Start Count Dow&n");
            BTNStartCountDown->callback(OnBTNStartCountDown);
            window->add(BTNStartCountDown);

            CHKbeep = new Fl_Check_Button(85, 100, 25, 25, "Turn on countdown 
alarm");
            CHKbeep->tooltip("turns on repeating beep alarm when checked.  
alarm stops with the stop button.");
            CHKbeep->value(1);//checked
            window->add(CHKbeep);

            CHKexec = new Fl_Check_Button(285, 100, 25, 25, "execute command on 
countdown alarm");
            CHKexec->tooltip("turns on repeating beep alarm when checked.  
alarm stops with the stop button.");
            //CHKexec->value(1);
            window->add(CHKexec);

            TEXTcmd = new Fl_Input(155, 130, 470, 25, "&Command to execute");
            TEXTcmd->value("Notepad.exe");
            TEXTcmd->tooltip("command should be a full path or be in the PATH");
            window->add(TEXTcmd);

            //start timer
            timer = new Fl_Timer(FL_HIDDEN_TIMER, 0, 0, 1, 1, "");
            timer->direction(0);//count up
            // timer->callback(OnTimer);        // OnTimer undeclared
            window->add(timer);
            window->end();

            //start window
            show();
            //callback(OnQuit);
        }

        //string getInputValue() { return string(TEXTin->value()); }
        bool isbeep() { return 0 != CHKbeep->value(); }
        bool isexec() { return 0 != CHKexec->value(); }

        void Run() {
            while (window->shown()) {

                //the following code is executed in a "while forever" windows 
message loop.
                //as long as messages are being processed, this will execute.
                if (0 != countby) {
                    TEXTout->value(elapsedtime().c_str());
                    //now handle the alarm...
                    //if counting down and time difference passed 0 into 
negative, ...
                    if (-1 == countby && curtime >= starttime) {
                        if (isexec() && !execdone) {
                            system(TEXTcmd->value()); //execute system command
                            execdone=true; //make sure it's done only once.
                        }
                        if (isbeep()) {
                            //make repeated noise at regular intervals.
                            if (gettime() % 2*400 >=400
                            && gettime() % 8*2*400 >= 4*400) {
                                Beep(880,150);      // sound frequency,ms
                            }
                        } else {
                            //display a messagebox instead and don't do 
anything special. it already makes a noise.
                            msgboxtimesup = new 
CMessageBox("KitchenTimer","Times up!");
                            window->add(msgboxtimesup->msgWindow);
                            countby=0;
                        }
                    }
                }//if 0 != countby
                Fl::wait(0);//waste no time!  But process window messages.
            }//while
        }//Run()
}



//func timediff()
//      curtime = gettime()
//      return curtime - starttime
//}




//---------------------------------------------------------------------------


//gregorian-julian calendar conversion routines.  do not use with
//gregorian dates under 1500AD.  cerain events occurred which interrupted
//the calendar.
//algorithm from http://en.wikipedia.org/wiki/Julian_day




//Author: Jim Michaels <[email protected]>
//Abstract: func library for conversion and time extraction from Julian and
//      Gregorian Dates and Javascript Date() objects.
//Create Date:  , 2008
//Current Date: Oct 24, 2009
//Version 2.2


//If you want to do Gregorian date differences based on Julian date differences,
//      make sure you add 4713 to the year component. e.g.
//              $y=GregorianY($jdiff)+4713//
//      everything else is normal.



//Copyright 2008,2009 Jim Michaels
//
//   This program is free software: you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY// without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program.  If not, see <http://www.gnu.org/licenses/>.

double curtimeToJDN() {
    SYSTEMTIME tCur;
    GetSystemTime(&tCur);
    return GregorianToJulian(tcur.wYear, tCur.wMonth, tCur.wDay, tCur.wHour, 
tCur.wMinute, tCur.wSecond, tCur.wMilliseconds);
}

int64_t curtimeToDTIME() {
    SYSTEMTIME tCur;
    GetSystemTime(&tCur);
    return numstoDTIME(tcur.wYear*12*31+(tCur.wMonth-1)*31+tCur.wDay-1, 
tCur.wHour, tCur.wMinute, tCur.wSecond, tCur.wMilliseconds);
}



double fdiv(double a, double b) {
        return a/b;
}
double epoch=GregorianToJulian(0,0,0,0,0,0,0);
// epoch is julian(-4713,11,24,12,0,0)// hours are 0..23, months are 1..12, 
days are 1..31, years start with -4713.
double GregorianToJulian(int Y,int Mo,int D,int H,int Mi,int S,int ms) {
        double a=floor((14-Mo)/12);
        double y=Y+4800-a;
        double m=Mo+(12*a)-3;
        return D + floor((153*m+2)/5) + (365*y) + floor(y/4) - floor(y/100) + 
floor(y/400) - 32045 + ((H-12)/24) + (Mi/1440) + (S/86400) + (ms/86400000);
}

//func JulianFromDate(date) {
//      $a=floor((14-(date.getMonth()+1))/12);
//      $y=date.getFullYear()+4800-$a;
//      $m=(date.getMonth()+1)+(12*$a)-3;
//      return date.getDate() + floor((153*$m+2)/5) + (365*$y) + floor($y/4) - 
floor($y/100) + floor($y/400) - 32045 + ((date.getHours()-12)/24) + 
(date.getMinutes()/1440) + (date.getSeconds()/86400) + 
(date.getMilliseconds()/86400000);
//}
//func DateToJulian(date) {
//      $a=floor((14-(date.getMonth()+1))/12);
//      $y=date.getFullYear()+4800-$a;
//      $m=(date.getMonth()+1)+(12*$a)-3;
//      return date.getDate() + floor((153*$m+2)/5) + (365*$y) + floor($y/4) - 
floor($y/100) + floor($y/400) - 32045 + ((date.getHours()-12)/24) + 
(date.getMinutes()/1440) + (date.getSeconds()/86400) + 
(date.getMilliseconds()/86400000);
//}
//func to2DigitString($n) {
//      $s=n.toString();
//      if (StringLen(s)=1) {
//              string ss("0");
//      ss += s;
//      }
//      return ss;
//}


//func JulianToDate($JDN)
//      Dim $J = $JDN+0.5// //shifts epoch 1/2 day
//      Dim $j = $J + 32044// //shifts epoch back to astronomical year -4800
//      Dim $g = fdiv($j , 146097)//
//      Dim $dg = fmod($j , 146097)//
//      Dim $c = fdiv((fdiv($dg , 36524) + 1) * 3 , 4)//
//      Dim $dc = $dg - ($c * 36524)//
//      Dim $b = fdiv($dc , 1461)//
//      Dim $db = fmod($dc , 1461)//
//      Dim $a = fdiv((fdiv($db , 365) + 1) * 3 , 4)//
//      Dim $da = $db - ($a * 365)//
//      Dim $y = ($g * 400) + ($c * 100) + ($b * 4) + $a// //integer number of 
full years elapsed since March 1, 4801 BC at 00:00 UTC
//      Dim $m = fdiv(($da * 5 + 308) , 153) - 2// //integer number of full 
months elapsed since the last March 1 at 00:00 UTC
//      Dim $d = $da - fdiv(($m + 4) * 153 , 5) + 122// //number of days 
elapsed since day 1 of the month at 00:00 UTC, including fractions of one day
//      Dim $Y = $y - 4800 + fdiv(($m + 2), 12)//
//      Dim $Mo = fmod(($m + 2) , 12) + 1//
//      Dim $D = $d + 1//
//    Dim $t=$J-floor($J)//
//    Dim $HH=fmod(24*$t+12, 24)//
//    $t=fdiv(24*$t+12, 24)//
//    Dim $MM=fmod(60*$t, 60)//
//    $t=fdiv(60*$t, 60)//
//    Dim $SS=fmod(60*$t, 60)//
//    $t=fdiv(60*$t, 60)//
//    Dim $MS=fmod(1000*$t, 1000)//
//    $t=fdiv(1000*$t, 1000)//
//
//    Dim $date=new Date($Y, $Mo-1, $D, $HH, $MM, $SS, $MS)//
//
//      return $date//
//}
//func DateFromJulian($JDN)
//      Dim $J = $JDN+0.5//
//      Dim $j = $J + 32044//
//      Dim $g = fdiv($j , 146097)//
//      Dim $dg = fmod($j , 146097)//
//      Dim $c = fdiv((fdiv($dg , 36524) + 1) * 3 , 4)//
//      Dim $dc = $dg - ($c * 36524)//
//      Dim $b = fdiv($dc , 1461)//
//      Dim $db = fmod($dc , 1461)//
//      Dim $a = fdiv((fdiv($db , 365) + 1) * 3 , 4)//
//      Dim $da = $db - ($a * 365)//
//      Dim $y = ($g * 400) + ($c * 100) + ($b * 4) + $a//
//      Dim $m = fdiv(($da * 5 + 308) , 153) - 2//
//      Dim $d = $da - fdiv(($m + 4) * 153 , 5) + 122//
//      Dim $Y = $y - 4800 + fdiv(($m + 2), 12)//
//      Dim $Mo = fmod(($m + 2) , 12) + 1//
//      Dim $D = $d + 1//
//    Dim $t=$J-floor($J)//
//    Dim $HH=fmod(24*$t+12, 24)//
//    $t=fdiv(24*$t+12, 24)//
//    Dim $MM=fmod(60*$t, 60)//
//    $t=fdiv(60*$t, 60)//
//    Dim $SS=fmod(60*$t, 60)//
//    $t=fdiv(60*$t, 60)//
//    Dim $MS=fmod(1000*$t, 1000)//
//    $t=fdiv(1000*$t, 1000)//
//
//    Dim $date=new Date($Y, $Mo-1, $D, $HH, $MM, $SS, $MS)//
//
//      return $date//
//}

string GregorianStringFromJulian(double JDN) {
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
    double t=J-floor(J);
    double HH=fmod(24*t+12, 24);
    t=fdiv(24*t+12, 24);
    double MM=fmod(60*t, 60);
    t=fdiv(60*t, 60);
    double SS=fmod(60*t, 60);
    t=fdiv(60*t, 60);
    double MS=fmod(1000*t, 1000);
    t=fdiv(1000*t, 1000);
        return StringFormat("%d/%d/%d %02d:%02d:%02d.%03d",Mo-1, D, Y, HH, MM, 
SS, MS)
}



int JulianToGregorianY(double JDN)
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
        double H = (d - floor(d))*24;
        double Mi= (H - floor(H))*60;
        double S= (Mi - floor(Mi))*60;
        double Ms = (S - floor(S))*1000;
        return Y;
}

int JulianToGregorianMo(double JDN)
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
        double H = (d - floor(d))*24;
        double Mi= (H - floor(H))*60;
        double S= (Mi - floor(Mi))*60;
        double Ms = (S - floor(S))*1000;
        return Mo;
}

int JulianToGregorianD(double JDN)
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
        double H = (d - floor(d))*24;
        double Mi= (H - floor(H))*60;
        double S= (Mi - floor(Mi))*60;
        double Ms = (S - floor(S))*1000;
        return floor(D);
}

int JulianToGregorianH(double JDN)
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
        double H = (d - floor(d))*24;
        double Mi= (H - floor(H))*60;
        double S= (Mi - floor(Mi))*60;
        double Ms = (S - floor(S))*1000;
        return floor(H);
}

int JulianToGregorianMi(double JDN)
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
        double H = (d - floor(d))*24;
        double Mi= (H - floor(H))*60;
        double S= (Mi - floor(Mi))*60;
        double Ms = (S - floor(S))*1000;
        return floor(Mi);
}

int JulianToGregorianS(double JDN)
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
        double H = (d - floor(d))*24;
        double Mi= (H - floor(H))*60;
        double S= (Mi - floor(Mi))*60;
        double Ms = (S - floor(S))*1000;
        return floor(S);
}

int JulianToGregorianMs(double JDN)
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
        double H = (d - floor(d))*24;
        double Mi= (H - floor(H))*60;
        double S= (Mi - floor(Mi))*60;
        double Ms = (S - floor(S))*1000;
        return floor(Ms);
}

double JulianToGregorianFracSec(double JDN)
        double J = JDN+0.5;
        double j = J + 32044;
        double g = fdiv(j , 146097);
        double dg = fmod(j , 146097);
        double c = fdiv((fdiv(dg , 36524) + 1) * 3 , 4);
        double dc = dg - (c * 36524);
        double b = fdiv(dc , 1461);
        double db = fmod(dc , 1461);
        double a = fdiv((fdiv(db , 365) + 1) * 3 , 4);
        double da = db - (a * 365);
        double y = (g * 400) + (c * 100) + (b * 4) + a;
        double m = fdiv((da * 5 + 308) , 153) - 2;
        double d = da - fdiv((m + 4) * 153 , 5) + 122;
        double Y = y - 4800 + fdiv((m + 2), 12);
        double Mo = fmod((m + 2) , 12) + 1;
        double D = d + 1;
        double H = (d - floor(d))*24;
        double Mi= (H - floor(H))*60;
        double S= (Mi - floor(Mi))*60;
        double fracSec = S - floor(S);
        return fracSec;
}


int64_t numstoDTIME(int64_t days, int H, int M, int S, int MS) {
        return MS + S*1000 + M*1000*60 + H*1000*60*60 + days*1000*60*60*24;
}
string numstoDTIMEstring(int64_t days, int H, int M, int S, int MS) {
    char s[1000];
    sprintf(s, "%I64d days %02d:%02d:%02d.%03d", days, H, M, S, MS);
        return string(s);
}
string DTIMEtostring(int64_t dtime) {
        int ms=DTIMEtoMS($dtime);
        int s=DTIMEtoS($dtime);
        int m=DTIMEtoM($dtime);
        int h=DTIMEtoH($dtime);
        int64_t days=DTIMEtodays($dtime);
    char s[1000];
    sprintf(s, "%I64d days %02d:%02d:%02d.%03d", abs($days), abs($h), abs($m), 
abs($s), abs($ms));
        return string(s);
}
int64_t stringtoDTIME(string dtimestr) {
        string sdays(" days ");
        int sldays=sdays.length();
        int idays=dtimestr.find(sdays);
        int firstcolon=dtimestr.find(":");
        int lastcolon=dtimestr.find(":",firstcolon+1);
        int dot=dtimestr.find(".");
        if (0==lastcolon
        || 0==firstcolon
        || 0==idays) {
            return 0;
    }
        int64_t days =  _atoi64(dtimestr.substr(0,idays).c_str());
        int ms =                _atoi64(dtimestr.substr(dot+1).c_str());
        int seconds =   
_atoi64(dtimestr.substr(lastcolon+1,1+dot-(lastcolon+1)));
        int minutes =   
_atoi64(dtimestr.substr(firstcolon+1,1+lastcolon-(firstcolon+1)).c_str());
        int hours =     
_atoi64(dtimestr.substr(idays+sldays,1+firstcolon-(idays+sldays)).c_str());
        //$t=numstoDTIME($days, $hours, $minutes, $seconds, $ms)
        
//msgbox(0,$t,$days&"days"&$hours&"hours"&$minutes&"minutes"&$seconds&"seconds"&$ms&"ms")
        return numstoDTIME(days, hours, minutes, seconds, $ms);
}

int DTIMEtoMS(int64_t dtime) {
        return dtime % 1000;
}
int DTIMEtoS(int64_t dtime) {
        return int64_t(dtime/1000) % 60;
}
int DTIMEtoM(int64_t dtime) {
        return int64_t(dtime/(1000*60)) % 60;
}
int DTIMEtoH(int64_t dtime) {
        return int64_t (dtime/(1000*60*60)) % 24;
}
int64_t DTIMEtodays(int64_t dtime) {
        return int64_t(dtime/(1000*60*60*24));
}

//---------------------------------------------------------------------------



int64_t gettime() {
        return curtimeToDTIME()
}


string stringtotimediff(string s) {
        string sdays(" days ");
        int sldays=sdays.length();
        int idays=s.find(sdays);
        int firstcolon=s.find(":");
        int lastcolon=s.find(":",firstcolon+1);
        int dot=s.find(".");
        if (0==lastcolon
        || 0==firstcolon
        || 0==idays) {
            return string("0 days 00:00:00.000");
    }
        int64_t days =  _atoi64(s.substr(1,idays).c_str());
        int ms =                _atoi64($s.substr(dot+1).c_str());
        int seconds =   
_atoi64($s.substr(lastcolon+1,1+dot-(lastcolon+1)).c_str());
        int minutes =   
_atoi64($s.substr(firstcolon+1,1+lastcolon-(firstcolon+1)).c_str());
        int hours =     
_atoi64($s.substr(idays+sldays,1+firstcolon-(idays+sldays)).c_str());
        
//msgbox(0,$t,$days&"days"&$hours&"hours"&$minutes&"minutes"&$seconds&"seconds"&$ms&"ms")
        return numstoDTIMEstring(days, hours, minutes, seconds, ms);
}

string elapsedtime() {
        //msgbox(0,"",starttime)
        curtime = gettime();
        //msgbox(0,"gettime",curtime)
        int64_t diff=curtime - starttime;
        int64_t absdiff=($diff);

        return DTIMEtostring($absdiff)
}

int main(int argc, char * argv[]) {
    argc--;argv++;
    if (argc >= 1) {
        if (
            0==_stricmp(argv[0],"--version")||
            0==_stricmp(argv[0],"--ver")||
            0==_stricmp(argv[0],"--v")||
            0==_stricmp(argv[0],"-version")||
            0==_stricmp(argv[0],"-ver")||
            0==_stricmp(argv[0],"-v")||
            0==_stricmp(argv[0],"/help")||
            0==_stricmp(argv[0],"/ver")||
            0==_stricmp(argv[0],"/v")
        ) {
            printf("Version %s\n", PROGRAM_VERSION);
            return 0;
        } else if (
            0==_stricmp(argv[0],"--help")||
            0==_stricmp(argv[0],"--h")||
            0==_stricmp(argv[0],"--?")||
            0==_stricmp(argv[0],"-help")||
            0==_stricmp(argv[0],"-h")||
            0==_stricmp(argv[0],"-?")||
            0==_stricmp(argv[0],"/help")||
            0==_stricmp(argv[0],"/h")||
            0==_stricmp(argv[0],"/?")
        ) {
            help();
            return 0;
        } else {
            printf("ERROR: invalid switch '%s'\n", arg[0]);
            help();
            return 1;
        }
    }

    KitchenTimerUI ktui();
    ktui.run();

    // Run the GUI until the dialog is closed
    while (Fl::wait()) {

    }
    return 0;
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to