Funciones de 32 bits omonimas de 16 bits (Funcky-2)

Funciones de 32 bits omonimas de 16 bits (Funcky-2)

Postby JmGarcia » Mon May 28, 2007 10:12 am

Estoy tratando de pasar programas de 16 bits a 32 bits, y me encuentro con algunos problemas.
Entre ellos estas funciones de FUNCKY-II (16 bits):

Name: dec2hex() - convert decimal value to hexadecimal string
Usage: <string> = dec2hex(<integer>)
Params: an integer in the range 0 - 65535
Returns: a string containing the hexadecimal representation of
the integer passed.

Name: shr() - bitwise shift right of a number
Usage: shr(<int>,<number>)
Params: integer <int> - number to shift, not greater then 65535
integer <number> number of shifts, not greater than 255
Returns: integer equal to the bitwise shr of <int> and <number>

Name: feof() - see if the file pointer is at the end of file
Usage: <logical> = feof(<handle>)
Params: integer <handle> - handle from a previous fopen()
Returns: logical .T. if file pointer is at the beginning of the
file, .F. if it is not

Name: bin2num() - convert 16/8 bit binary string to integer
Usage: <integer> = bin2num(<binstr>)
Params: string <binstr> - a string of 16 or 8 ones and zeros
that form a binary byte or word.
A binary string has the format where a "1" signifies
that the bit is on, and "0" signifies bit is off:
"0001110000111100" or "00111001"
Returns: An integer equal to the decimal value of the binary
string that was sent.

Name: byte2bin() - convert byte value to 8 bit binary string
Usage: <string> = byte2bin(<integer>)
Params: an integer in the range of 0 - 255
Returns: a string filled with ones and zeros representing the
the bit settings that form the binary equivalent of the
integer sent

Name: and() - bitwise and of two numbers
Usage: <integer> = and(<int>,<number>)
Params: integer <int> - number to and, not greater then 65535
integer <number> number to and <int> with
Returns: integer equal to the bitwise and of <int> and <number>

Teniendo en cuenta que las Funcky 6.0 NO traen librerias ".LIB" (o no las he encontrado), como lo hago.
Es decir busco las omonimas en FW+xHARBOUR pero de 32 bits.
Gracias.
Mi abuelo decía: Los aviones vuelan porque Dios quiere, y los helicópteros ni Dios sabe porque vuelan.
FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
User avatar
JmGarcia
 
Posts: 654
Joined: Mon May 29, 2006 3:14 pm
Location: Madrid - ESPAÑA

Postby Antonio Linares » Mon May 28, 2007 11:18 am

>
Name: dec2hex() - convert decimal value to hexadecimal string
Usage: <string> = dec2hex(<integer>)
>

Puedes usar DecToHex() de FWH. Funciona igual.

>
Name: shr() - bitwise shift right of a number
Usage: shr(<int>,<number>)
Params: integer <int> - number to shift, not greater then 65535
integer <number> number of shifts, not greater than 255
Returns: integer equal to the bitwise shr of <int> and <number>
>
Code: Select all  Expand view
HB_FUNC( SHR )
{
   unsigned int ui = hb_parnl( 1 );
   unsigned char uc = hb_parnl( 2 );

   hb_retnl( ui >>= uc );
}

>
Name: feof() - see if the file pointer is at the end of file
Usage: <logical> = feof(<handle>)
>
Code: Select all  Expand view
function feof( nHandle )
   local lEof := ( fseek( nHandle, 1, FS_RELATIVE ) == fseek( nHandle, 0, FS_RELATIVE ) )

   if ! lEof
      fseek( nHandle, -1, FS_RELATIVE )
   endif

return lEof

>
Name: bin2num() - convert 16/8 bit binary string to integer
Usage: <integer> = bin2num(<binstr>)
>
Code: Select all  Expand view
function bin2num( cBinStr )

   local n := 1, nResult := 0

   for n = 1 to Len( cBinStr )
      if SubStr( cBinStr, Len( cBinStr ) - n + 1, 1 ) == "1"
         nResult += ( 2 ^ ( n - 1 ) )
      endif
   next

return Int( nResult )

>
Name: byte2bin() - convert byte value to 8 bit binary string
Usage: <string> = byte2bin(<integer>)
>
Code: Select all  Expand view
function Byte2Bin( nValue )

   local cResult := "", n := 7

   while n >= 0
      if Int( nValue / ( 2 ^ n ) ) != 0
         cResult += "1"
         nValue -= Int( nValue / ( 2 ^ n ) ) * ( 2 ^ n )
      else
         cResult += "0"
      endif
      n--
   end

return cResult

>
Name: and() - bitwise and of two numbers
Usage: <integer> = and(<int>,<number>)
>
Puedes usar nAnd() de FWH. Funciona igual.

OJO: No he probado estas funciones, las he escrito sobre la marcha, pruébalas y asegúrate de que funcionen bien :-)
regards, saludos

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

Postby JmGarcia » Wed Dec 19, 2007 12:10 pm

Y como seria esta funcion:

Name: freadline() - read in one line from a file
Usage: <string> = freadline(<handle>,[<linelen>])
Params: integer <handle> from a previous fopen() or fcreate()
integer <linelen> - maximum line length to read in, if not
specified than the default is a maximum length of 512.
Returns: a string filled with one line of text
Mi abuelo decía: Los aviones vuelan porque Dios quiere, y los helicópteros ni Dios sabe porque vuelan.
FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
User avatar
JmGarcia
 
Posts: 654
Joined: Mon May 29, 2006 3:14 pm
Location: Madrid - ESPAÑA

Postby Antonio Linares » Wed Dec 19, 2007 1:04 pm

No la he probado, pero debería funcionar :-)
Code: Select all  Expand view
function freadline( nHandle, nLineLen )

   local cBuffer, nBytes, nAt

   DEFAULT nLineLen := 512

   cBuffer := Space( nLineLen )
   nBytes = FRead( nHandle, @cBuffer, nLineLen )
   nAt = At( Chr( 13 ) + Chr( 10 ), cBuffer )
   if nAt != 0
      FSeek( nHandle, -( nBytes - nAt + 2 ), FS_RELATIVE )
   endif

return If( nAt != 0, SubStr( cBuffer, 1, nAt - 1 ), SubStr( cBuffer, 1, nBytes ) )
regards, saludos

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

Postby JmGarcia » Wed Dec 19, 2007 10:37 pm

Gracias Antonio.
Ya me puedo despedir de las LIB de Funcky, en desarrollos de 32bits.
Mi abuelo decía: Los aviones vuelan porque Dios quiere, y los helicópteros ni Dios sabe porque vuelan.
FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
User avatar
JmGarcia
 
Posts: 654
Joined: Mon May 29, 2006 3:14 pm
Location: Madrid - ESPAÑA

Postby JmGarcia » Mon Jan 21, 2008 7:34 pm

Al compilar esta funcion con BCC551+FWH75+Make030
Antonio Linares wrote:
Code: Select all  Expand view
HB_FUNC( SHR )
{ // Esta es la linea 1175
   unsigned int ui = hb_parnl( 1 );
   unsigned char uc = hb_parnl( 2 );
   hb_retnl( ui >>= uc );
} // Esta es la linea 1179
Me da este error:
E:\Bases\Practicas\InyectaS.prg(1175) Error E0020 Incomplete statement or unbalanced delimiters
E:\Bases\Practicas\InyectaS.prg(1179) Error E0030 Syntax error: "parse error at 'INT'"




Esta otra funcion siempre me da TRUE, es decir FIN DE FICHERO
Antonio Linares wrote:
Code: Select all  Expand view
function feof( nHandle )
   local lEof := ( fseek( nHandle, 1, FS_RELATIVE ) == fseek( nHandle, 0, FS_RELATIVE ) )
   if ! lEof
      fseek( nHandle, -1, FS_RELATIVE )
   endif
return lEof
Me he "inventado" esta (y voy tirando) y me funciona, pero si se arregla la de arriba mejor:
Code: Select all  Expand view
function feof( nHandle )
   local BLOCK_SIZE := 1 // 1 o lo que sea mayor de 0 (cero)
   LOCAL cBuffer    := Space( BLOCK_SIZE )
   LOCAL nRead      := 0
   local lEof       := .T.
   nRead := FRead( nHandle, @cBuffer, BLOCK_SIZE )
   IF nRead == BLOCK_SIZE
      fseek( nHandle, -BLOCK_SIZE, FS_RELATIVE )
      lEof:= .F.
   ELSE
      lEof:= .T.
   ENDIF
return lEof
En realidad quiero que sea haga lo mismo que la de FuncKy:
Name: feof() - see if the file pointer is at the end of file
Usage: <logical> = feof(<handle>)
Params: integer <handle> - handle from a previous fopen()
Returns: logical .T. if file pointer is at the beginning of the
file, .F. if it is not
Mi abuelo decía: Los aviones vuelan porque Dios quiere, y los helicópteros ni Dios sabe porque vuelan.
FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
User avatar
JmGarcia
 
Posts: 654
Joined: Mon May 29, 2006 3:14 pm
Location: Madrid - ESPAÑA

Postby JmGarcia » Tue Jun 24, 2008 10:51 am

La funcion LASTDAY de Funcky cual es la de FWH.

Name: lastday() - get the last day in a month
Usage: <integer> = lastday(<date>)
Params: <date> - a date type variable
Returns: an integer equal to the last day in the month specified
by the date variable.
Mi abuelo decía: Los aviones vuelan porque Dios quiere, y los helicópteros ni Dios sabe porque vuelan.
FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
User avatar
JmGarcia
 
Posts: 654
Joined: Mon May 29, 2006 3:14 pm
Location: Madrid - ESPAÑA

Postby Armando » Tue Jun 24, 2008 11:13 am

JmGarcía:

Te servirá EOM(Date()) de xHarbour ?

Saludos
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3061
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Postby mmercado » Tue Jun 24, 2008 12:27 pm

JmGarcia wrote:La funcion LASTDAY de Funcky cual es la de FWH.

Code: Select all  Expand view
Function LastDay( dDate, dLast ) // dLast solo para ahorrar definiciones
Return ( dLast := If( dDate == Nil, Date(), dDate ) + If( Month( dDate + 28 ) == Month( dDate ), 31, 28 ) ) - Day( dLast )

Saludos

Manuel Mercado
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Postby Biel EA6DD » Tue Jun 24, 2008 2:14 pm

Bonita implementacion la de Manuel, yo tengo una funcion parecida, aunque haciendo honor a la verdad, la de Manuel queda mas corta y elegante.
Para ser igual que la de funcky, debiera devolver day( dlasta:= ... ).
Y prevenir el pase de nil, que se tiene en cuenta con dLast, pero no con dDate, y produciria un error en ejecución.

Otra función alternativa seria en lugar de sumar dias, montar la fecha de dia 1 del mes siguiente, y restarle un dia, algo así.
Code: Select all  Expand view
FUNCTION LastDay(dDate)
   DEFAULT dDate:=Date()
RETURN IF(Day(dDate:=StoD(Str(Year(dDate),4)+PadL(lTrim(Str(Month(dDate)+1)),2,'0')+'01')-1)==0,31,Day(dDate))
Last edited by Biel EA6DD on Wed Jun 25, 2008 7:40 am, edited 2 times in total.
Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
User avatar
Biel EA6DD
 
Posts: 682
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca

Postby Antonio Linares » Tue Jun 24, 2008 2:27 pm

Jose Maria,

Te respondo con mucho retraso, pero es cuando he visto el mensaje (a veces se me pasan mensajes :-)

>
E:\Bases\Practicas\InyectaS.prg(1175) Error E0020 Incomplete statement or unbalanced delimiters
E:\Bases\Practicas\InyectaS.prg(1179) Error E0030 Syntax error: "parse error at 'INT'"
>

Tienes que usar ese código desde C incluyendo #include <hbapi.h> ó desde un PRG usando #pragma BEGINDUMP y #pragma ENDDUMP y tambien usando ese include.
regards, saludos

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

Postby mmercado » Tue Jun 24, 2008 3:03 pm

Biel EA6DD wrote:Para ser igual que la de funcky, debiera devolver day( dlasta:= ... ).
Hola Biel:

Lo pensé pero según mi experiencia tiene más uso como variable de fecha que como día del mes. Además creo que el nombre de la función quedaría mejor como dFinalMes() o dMonthEnd()

Biel EA6DD wrote:Y prevenir el pase de nil, que se tiene en cuenta con dLast, pero no con dDate, y produciria un error en ejecución.
Si observas bien, verás que también traté de considerarlo pero no escribí adecuadamente la expresión (con dDate = Nil asume la fecha del sistema), también te darás cuenta que la acabo de inventar.

Aquí está ya correctamente escrita:
Code: Select all  Expand view
Function dFinalMes( dDate, dLast )
Return ( dLast := ( dDate := If( dDate == Nil, Date(), dDate ) ) + If( Month( dDate + 28 ) == Month( dDate ), 31, 28 ) ) - Day( dLast )

Un abrazo.

Manuel Mercado
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Postby JmGarcia » Tue Jun 24, 2008 9:29 pm

Mmercado y Biel muchas gracias.

¿ Hemos considerado los años bisiestos ?

La función la necesito para poner la fecha interna del S.O.Solaris (SUN) que es en formato de 4 octetos, esa que empieza el 01/01/1987.

Así la cifra 1211636418 es 24/05/2008 13:40:18

Gracias de nuevo.
Mi abuelo decía: Los aviones vuelan porque Dios quiere, y los helicópteros ni Dios sabe porque vuelan.
FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
User avatar
JmGarcia
 
Posts: 654
Joined: Mon May 29, 2006 3:14 pm
Location: Madrid - ESPAÑA

Postby Biel EA6DD » Wed Jun 25, 2008 7:43 am

Hola Manuel,
con este último cambio queda perfecta. :)

JM, ambas funciones tienen en cuenta los bisisestos.
Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
User avatar
Biel EA6DD
 
Posts: 682
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca

Re: Funciones de 32 bits omonimas de 16 bits (Funcky-2)

Postby George » Wed Feb 23, 2011 9:41 pm

Pregunta sobre codigo C implementado en [x]Harbour

Antonio Linares escribio:
Jose Maria,
Te respondo con mucho retraso, pero es cuando he visto el mensaje (a veces se me pasan mensajes :-)
>
E:\Bases\Practicas\InyectaS.prg(1175) Error E0020 Incomplete statement or unbalanced delimiters
E:\Bases\Practicas\InyectaS.prg(1179) Error E0030 Syntax error: "parse error at 'INT'"
>
Tienes que usar ese código desde C incluyendo #include <hbapi.h> ó desde un PRG usando #pragma BEGINDUMP y #pragma ENDDUMP y tambien usando ese include.

Que diferencia hay entre usar codigo C en un archivo externo y usarlo dentro de un PRG?
Cual de los dos se ejecuta mas rapido?

George
George
 
Posts: 724
Joined: Tue Oct 18, 2005 6:49 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: richard-service and 69 guests