Please tell me to go away if this request is inappropriate
Im trying to convert a C function into 4D
I know very very little C, so after 2 days I'm looking for some help
The C function looks like

struct toc {
        int     min;

        int     sec;
        int     frame;

struct toc cdtoc[100];



/* Do whatever is appropriate to read the TOC of the CD
 * into the cdtoc[] structure array.


return (tot_trks);

cddb_sum(int n)


int     ret;
/* For backward compatibility this algorithm must not change */
ret = 0;

while (n > 0) {
        ret = ret + (n % 10);

        n = n / 10;
return (ret);



unsigned long
cddb_discid(int tot_trks)


int i,
t = 0,

        n = 0;
/* For backward compatibility this algorithm must not change */
i = 0;

while (i < tot_trks) {
        n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec);

i++; }

t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) -
    ((cdtoc[0].min * 60) + cdtoc[0].sec);

        return ((n % 0xff) << 24 | t << 8 | tot_trks);

} {


int tot_trks;

tot_trks = read_cdtoc_from_drive();
printf("The discid is %08x", cddb_discid(tot_trks));

My version Looks Like

For ($i;1;$NoTracks)
End for
$DisckIDNo:=(n%255) << 24 | t << 8 | $NoTracks  // (n%255)<<24 results in a
huge negative number
DiscID:=substring($temp;3)    //This should result in an 8 character string
in hex

and the subroutine cddb_sum Like This

While ($Position>0)
End while

I think Im misunderstanding the functioning of cddb_sum

But I dont get anything sensible at the end

This is supposed to calculate a discID used in the lookup for CD titles
from FreeDB
The TOC (Table of contents) is derived from the information retreived from
"drutil TOC"
There is some code that creates an array of start times (in Seconds). an
end time and the number of tracks
This is the code that does that is

ARRAY LONGINT(StartSeconds;0)
Array Longint(StartFrames;0)
LAUNCH EXTERNAL PROCESS("Drutil toc";$in;$out;$err)
$pos:=Position("Last Track:";$out)


ConvertTOCToSeconds ($LastTrackString)

ConvertTOCToSeconds ($TrackStartString)
APPEND TO ARRAY(StartSeconds;<>Seconds)
End for

4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com

Reply via email to