Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Programming languages > Help convert C function to Pascal function
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 19th October 02:04
ian
External User
 
Posts: 1
Default Help convert C function to Pascal function



As I am not familiar with the C programming language, I would
greatly appreciate it if someone could please convert the C
function below to a Pascal function. Thanks!


/* converts time into units of milliseconds */
long mytime(void)
{
static struct time t;
static struct date d;
static long mama;

getdate(&d);
gettime(&t);

mama = ((((dostounix(&d,&t)-unixstart)*100)+t.ti_hund)*10);

return(mama);
}
  Reply With Quote


  sponsored links


2 19th October 02:04
robert ah prins
External User
 
Posts: 1
Default Help convert C function to Pascal function



It takes the current timestamp (yyyy-mm-dd-hh.mm.ss.uu) and converts it
to milliseconds since, IIRC, 1970. I'm sure you can do that yourself.

Robert
--
Robert AH Prins
prino at prino dot plus dot com
  Reply With Quote
3 19th October 02:04
hubblebubble
External User
 
Posts: 1
Default Help convert C function to Pascal function


Hi,

Let's be nice and unsnotty to newbies shall we?

I think this might help.

program Whatever;

uses DOS

(* Structure used by DOS - Date & time record used by PackTime and
UnpackTime
You don't need to define this since the structure is already built
into TP
(**)

type
DateTime = record
Year,Month,Day,Hour,
Min,Sec: Word;
end;

{Look at the DOS unit for other Time/Date functions}
var
Hour, Min, Sec, S100 : word;
Mama : Real;

begin
GetTime(Hour,Min,Sec,S100);
Mama := (Hour * 3600) + (Min * 60) + Sec + (S100 / 100);
Writeln(Mama);
Readln;
end.

Untested so don't hold me to it . Enjoy
  Reply With Quote
4 19th October 02:04
robert ah prins
External User
 
Posts: 1
Default Help convert C function to Pascal function


Obviously untested, completely missed the date!

Robert
--
Robert AH Prins
prino at prino dot plus dot com
  Reply With Quote
5 19th October 02:05
hubblebubble
External User
 
Posts: 1
Default Help convert C function to Pascal function


See this line

{Look at the DOS unit for other Time/Date functions}

Obviously does not read comments
  Reply With Quote
6 19th October 02:05
william j leary jr
External User
 
Posts: 1
Default Help convert C function to Pascal function


I assumed when he said "I think this might help." he meant that, rather than
give a complete solution, it would give the original poster an idea on how
to start. In fact, except for a missing semi-colon after "uses DOS" it does
compile and run.

As a few additional clues for the OP; in addition to not including the date,
HB's code delivers seconds rather than milliseconds. In order to get
milliseconds since 00:00:00 01/01/1970 the result type would have to be
Double under TP5.5. A Real doesn't have enough precision for that scope at
that resolution. I'm assuming the C code must have sourced from a UNIX
system where "long" is a 64 bit integer. Yes, I tested it, but I couldn't
come up with a *simple* solution to the leap year issue, so I dropped it.

- Bill
  Reply With Quote
7 19th October 02:05
dr john stockton
External User
 
Posts: 1
Default Help convert C function to Pascal function


JRS: In article <3pkj4mFanvkgU1@individual.net>, dated Sat, 24 Sep 2005
09:04:22, seen in news:comp.lang.pascal.borland, Robert AH Prins
<prino@onetel.com> posted :


But since when in 1970? The beginning, I expect you mean. But which
beginning? 1970-01-01 began in New Zealand long before it began in
Hawaii. The UNIX standard is 1970.0 GMT (which was at 01:00 hours
here).

If C getdate and gettime get local date and time, maybe dostounix allows
for that.

ISTM that the OP should first ask in a C group to get the code
translated into English, and then translate that into Pascal.

It's quite likely that the milliseconds are used exclusively for
differencing with other similar milliseconds, in which case the base of
the count does not matter. However, if the OP is in a country which has
Summer Time (he gives no indication, so is assumed American), he should
be aware that days can have 23,24,25 hours.

I don't know what a C long is; but a Pascal longint will only store a
little under 25 days-worth of milliseconds - it may be necessary to use
a comp variable (unless the OP is a Delphi user who has not yet
understood the wisdom of posting Delphi questions to Delphi newsgroups).

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
  Reply With Quote
8 19th October 02:05
ian
External User
 
Posts: 1
Default Help convert C function to Pascal function


<snip>


Yes, I am in the US.

According to the notes in the C source code, it is inded a
longint. Also, I'm not using Delphi; I am using Borland Turbo
Pascal 7. The C code I originally posted is from a program
someone wrote in Borland C++ back in 1994. I'm trying to use
some functions from their C program for mine.
  Reply With Quote
9 19th October 02:05
dr john stockton
External User
 
Posts: 1
Default Help convert C function to Pascal function


JRS: In article <L8CdnSIHLfQUaaveRVn-og@comcast.com>, dated Sun, 25 Sep
2005 15:04:25, seen in news:comp.lang.pascal.borland, William J. Leary
Jr. <Bill_Leary@msn.com> posted :

Within the nominal validity range of DOS, 1980-2099, there is a Leap
Year every 4 years. It's easy enough to convert from years starting in
January to ones starting in March, and then the Leap Year correction is
just Year div 4.

For more on conversion of Y M D to DayCount and back, see
<URL:http://www.merlyn.demon.co.uk/daycount.htm>,
<URL:http://www.merlyn.demon.co.uk/zeller-c.htm> and linked pages; and
<URL:http://www.merlyn.demon.co.uk/programs/dateprox.pas>.

The date is *maintained* in DOS as a word count of days; ISTM a pity
that it's kept at an undefined address, unlike the time which is kept at
longint $40:$6C. In true DOS, that address can be found - my
<URL:http://www.merlyn.demon.co.uk/programs/int_test.pas> will do it -
but it's easier and safer to code the legitimate conversion.


function ZelCMJD(Y, M, D : word) : longint ;
begin { Inc(Y, 7e5) ; Dec(Result, 7e5*365.2425) ;; 153 = 13 + 5*28 }
if M<3 then begin Inc(M, 12) ; Dec(Y) end ;
ZelCMJD := longint(Y)*365 - 678973 + (D + (M*153-2) div 5 +
Y div 4 - Y div 100 + Y div 400) end {ZelCMJD} ;

The 7e5 bit is needed only for very old years. That gives local days
from 1858-11-17.

The OP will still need to consider Time Zone and Summer Time; and, if
the code is to be used in the US (or maybe Canada) both before and after
the end of next year, will have to allow for the recently-legislated
change in the US DST rules:
<URL:http://www.merlyn.demon.co.uk/uksumtim.htm>.


--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
  Reply With Quote
10 19th October 02:05
william j leary jr
External User
 
Posts: 1
Default Help convert C function to Pascal function


Yes. I understand that as a simple solution. I also worked out the 100 and
400 rules, on paper, and had run across some notes about a millenia rule as
well, which I hadn't looked up yet, but I hadn't gotten around to actually
coding any of it by the time ((whatever the name was)) had posted his "leg
up" code, so I dropped it. It was getting to be a bit too much like work.


OK. Maybe mine actually wouldn't have been as opaque as I though it was going to be.

Very nice. I wasn't worrying about dates prior to 1970 because the original
C code didn't seem to be doing so either.


That's going to be a joyful annoyance. I expect to have to adjust four
computers, four PDAs and two camera for those.

- Bill
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666