FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour C贸mo compilar c贸digo en C? (SOLUCIONADO)
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
C贸mo compilar c贸digo en C? (SOLUCIONADO)
Posted: Wed Sep 02, 2015 09:12 PM
Amigos:

Para los maestros en C (Yo soy 帽o帽o :-) ), tengo el siguiente c贸digo en C#

Code (fw): Select all Collapse
using System.Text.RegularExpressions;
using System;
using System.Globalization;

public class RFC
聽 聽 {
聽 聽 聽 聽 public static bool EsRFCValido(string RFC)
聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 if (PersonaFisica_RFC(RFC) && ValidarUltimaLetraRFC(RFC) && ValidarFechaRFC(RFC))
聽 聽 聽 聽 聽 聽 聽 聽 return true;

聽 聽 聽 聽 聽 聽 if (General_RFC(RFC) && ValidarUltimaLetraRFC(RFC) && ValidarFechaRFC(RFC))
聽 聽 聽 聽 聽 聽 聽 聽 return true;

聽 聽 聽 聽 聽 聽 return false;
聽 聽 聽 聽 }

聽 聽 聽 聽 private static bool PersonaFisica_RFC(string RFC)
聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 try
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 if (RFC.Trim().Length == 13 || RFC.Trim().Length == 12)
聽 聽 聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 string pattern = "^[A-Z&]{3,4}(\\d{6})(([A-Z0-9]){3})?$";
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 Match RFCMatch = Regex.Match(RFC, pattern);
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if (RFC != string.Empty)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if (!RFCMatch.Success)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 return false;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 聽 聽 聽 else
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 return false;

聽 聽 聽 聽 聽 聽 聽 聽 return true;
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 聽 catch (Exception ex)
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 Console.WriteLine(string.Format("ExpRegulares.PersonaFisica_RFC: {0}", ex.Message));
聽 聽 聽 聽 聽 聽 聽 聽 return false;
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 }

聽 聽 聽 聽 private static bool General_RFC(string RFC)
聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 try
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 string pattern = "^([A-Z\\s]{3,4})\\d{6}(([A-Z\\w]|[0-9]){3})$";
聽 聽 聽 聽 聽 聽 聽 聽 Match RFCMatch = Regex.Match(RFC.Trim(), pattern);
聽 聽 聽 聽 聽 聽 聽 聽 if (RFC.Trim() != string.Empty)
聽 聽 聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 if (!RFCMatch.Success)
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 return false;
聽 聽 聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 聽 聽 聽 return true;
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 聽 catch (Exception ex)
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 Console.WriteLine(string.Format("ExpRegulares.General_RFC: {0}", ex.Message));
聽 聽 聽 聽 聽 聽 聽 聽 return false;
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 }

聽 聽 聽 聽 private static bool ValidarUltimaLetraRFC(string RFC)
聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 try
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 if (RFC.EndsWith("A") || RFC.EndsWith("0") || RFC.EndsWith("1") || RFC.EndsWith("2") || RFC.EndsWith("3") || RFC.EndsWith("4") || RFC.EndsWith("5")
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 || RFC.EndsWith("6") || RFC.EndsWith("7") || RFC.EndsWith("8") || RFC.EndsWith("9"))
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 return true;
聽 聽 聽 聽 聽 聽 聽 聽 else
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 return false;
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 聽 聽 catch (Exception ex)
聽 聽 聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 聽 聽 Console.WriteLine(string.Format("ExpRegulares.ValidarUltimaLetraRFC: {0}", ex.Message));
聽 聽 聽 聽 聽 聽 聽 聽 return false;
聽 聽 聽 聽 聽 聽 }
聽 聽 聽 聽 }

聽 聽 聽 聽 private static bool ValidarFechaRFC(string RFC)
聽 聽 聽 聽 {
聽 聽 聽 聽 聽 聽 string fecha = string.Empty;
聽 聽 聽 聽 聽 聽 bool esFecha = false;
聽 聽 聽 聽 聽 聽 DateTime resultado;

聽 聽 聽 聽 聽 聽 fecha = RFC.Substring(RFC.Length - 9, 6);
聽 聽 聽 聽 聽 聽 esFecha = DateTime.TryParseExact(fecha, "yyMMdd", null, DateTimeStyles.None, out resultado);

聽 聽 聽 聽 聽 聽 return esFecha;
聽 聽 聽 聽 }
聽 聽 }


Como puedo compilarlo dentro de mi aplicaci贸n hecha con FWH y xHarbour?
Necesita cambios ?

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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: C贸mo compilar c贸digo en C?
Posted: Thu Sep 03, 2015 08:39 AM

Y por qu茅 lo necesitas en C ?

Lo puedes pasar a Harbour, no es dificil de entender :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 346
Joined: Mon Oct 05, 2009 03:35 PM
Re: C贸mo compilar c贸digo en C?
Posted: Thu Sep 03, 2015 01:41 PM
Tocayo:

no se si estoy en lo correcto pero esto te puede ayudar, yo coloco programas en c de esta forma dentro de un prg en xHarbour

Code (fw): Select all Collapse
#pragma BEGINDUMP

   // aqui el programa en C
void * hb_parns( int i )
{
   return 0;
}
  // fin de programa en C

#pragma ENDDUMP


saludos
SkyPe: armando.lagunas@hotmail.com

Mail: armando.lagunas@gmail.com
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: C贸mo compilar c贸digo en C?
Posted: Thu Sep 03, 2015 02:40 PM

Antonio:

No es precisamente que lo necesite en C, solo que el c贸digo que encontr茅
est谩 en C y yo de C solo se que NO C :D , Si alguna alma caritativa lo
convierte a [x]Harbour, estar茅 muy agradecido.

Tocayo:
Gracias por el aporte, lo intentar茅., a ver si pasa el c贸digo as铆 como esta.
Saludos a todos

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
Posts: 120
Joined: Wed Mar 11, 2009 07:32 PM
Re: C贸mo compilar c贸digo en C?
Posted: Thu Sep 03, 2015 04:37 PM
Hola armando

buenos dias

ay va la conversion, nomas faltaria validar que los numeros sean fecha estan en cfecha


Code (fw): Select all Collapse
Function main()
Local cRfc:="visaf741020tu2"

聽 聽
聽 聽
聽 聽 ? 聽valrfc(crfc)
聽 聽 
聽 聽 
聽 聽 
Return Nil



Function Valrfc(xrfc)
Local dev:=.f.
local cletras:=""
local cfecha:=""
local chomoclave:=""

xrfc:=upper(alltrim(xrfc))
// validar el tamano 聽 12 persona moral 聽 13 persona fisica
if !(len(xrfc)>=12 .and. len(xrfc)<=13)
聽 聽 Return .f.
endif


//fso0311035u8
//camb720214b32

if len(xrfc)=12 聽 聽// validar persona moral
聽 聽cletras:=substr(xrfc,1,3)
聽 聽cfecha :=substr(xrfc,4,6)
聽 聽chomoclave:=substr(xrfc,10,3)
聽 聽if !lletras(cletras)
聽 聽 聽 聽return .f.
聽 聽endif
聽 聽if !lnumeros(cfecha)
聽 聽 聽 聽return .f.
聽 聽endif
聽 聽
聽 聽 if !lmixto(chomoclave)
聽 聽 聽 聽return .f.
聽 聽endif
聽 聽
聽 聽 聽 
聽 聽
聽 聽
聽 聽

else 聽 聽 聽 聽 聽 聽 聽 // validar persona fisica
聽 聽cletras:=substr(xrfc,1,4)
聽 聽cfecha :=substr(xrfc,5,6)
聽 聽chomoclave:=substr(xrfc,11,3)
聽 聽if !lletras(cletras)
聽 聽 聽 聽return .f.
聽 聽endif
聽 聽if !lnumeros(cfecha)
聽 聽 聽 聽return .f.
聽 聽endif
聽 聽
聽 聽if !lmixto(chomoclave)
聽 聽 聽 聽return .f.
聽 聽endif
聽 聽
聽 聽

endif



return .t.



Function lletras(xtexto)
local i
local dev:=.t.

for i:=1 to len(xtexto)
聽 聽 IF asc(substr(xtexto,i,1))>=65 .and. asc(substr(xtexto,i,1))<=90
聽 聽 else
聽 聽 聽 聽dev:=.f.
聽 聽 endif
next i
Return dev


return .t.


Function lnumeros(xtexto)
local i
local dev:=.t.
for i:=1 to len(xtexto)
聽 聽 IF asc(substr(xtexto,i,1))>=48 .and. asc(substr(xtexto,i,1))<=57
聽 聽 else
聽 聽 聽 聽dev:=.f.
聽 聽 endif
next i
Return dev


Function lmixto(xtexto)
local i
local dev:=.t.
for i:=1 to len(xtexto)
聽 聽 IF (asc(substr(xtexto,i,1))>=48 .and. asc(substr(xtexto,i,1))<=57) .or. (asc(substr(xtexto,i,1))>=65 .and. asc(substr(xtexto,i,1))<=90)
聽 聽 else
聽 聽 聽 聽dev:=.f.
聽 聽 endif
next i



return dev
Benjamin Casarrubias Moreno
Cd. Obreg贸n, Sonora, M茅xico
chino72vale@hotmail.com
Fivewin 24.04, Harbour 3.3, xharbour 1.2.1, Fivelinux, Visual Estudio 2022
Oracle Api Rest, SDK Contpaq, Facturaci贸n Electr贸nica, XML DIOT 2025
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: C贸mo compilar c贸digo en C?
Posted: Thu Sep 03, 2015 05:16 PM

Benji:

Muy agradecido, voy a probarla, ya te contar茅 el resultado.

Lo de la fecha es muy sencillo, hasta yo lo puedo hacer :wink: , tambi茅n
ya tengo la validaci贸n del d铆gito verificador.

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
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: C贸mo compilar c贸digo en C?
Posted: Thu Sep 03, 2015 06:45 PM

Benji:

Muchas gracias, prob茅 tu c贸digo y funciona bien con xHarbour, es el que uso,
la validaci贸n de la fecha no es problema.

Muchas gracias nuevamente, saludos a todo el foro

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
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: C贸mo compilar c贸digo en C? (SOLUCIONADO)
Posted: Thu Sep 03, 2015 09:29 PM

Harbour soporta expresiones regulares.
Pasar ese c贸digo sin casi modificaciones es facil. Podeis mirar regex.prg y regex2.prg de la carpeta tests de harbour :D

______________________________________________________________________________

Sevilla - Andaluc铆a

Continue the discussion