Ayuda con archivos INI (Help With INI File)

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
Mario Mansilla
Posts: 233
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina
Been thanked: 2 times

Ayuda con archivos INI (Help With INI File)

Post by Mario Mansilla » Wed Jul 04, 2018 4:28 pm

Hola amigos :
necesito leer y escribir archivos INI sin seccion ejemplo :

Dato1=Empresa
Dato2=Domicilio
Dato3=Ciudad

No asi :
[Seccion]
Dato1=Empresa
Dato2=Domicilio
Dato3=Ciudad

Alguien tiene una rutina para realizar esto

Saludos
Mario Mansilla

**************************************************
Hello friends :
I need to read and write INI files without example section:

Dato1 = Company
Dato2 = Address
Dato3 = City

Not so:
[Section]
Dato1 = Company
Dato2 = Address
Dato3 = City

Someone has a routine to do this

regards
Mario Mansilla

User avatar
andyglezl
Posts: 939
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 16 times
Been thanked: 37 times
Contact:

Post by andyglezl » Wed Jul 04, 2018 10:45 pm

Hola Mario

No se tu razón de hacerlo así, ya que la SECTION es lo que te facilita
extraer o grabar un cierto dato.
Pero quizá si no pones nada en SECTION te sirva . . .
--------------------------------------------------------------------------------------
Hello Mario

I do not know why you do it, because the SECTION is what makes you
extract or record a certain data.
But maybe if you do not put anything in SECTION it will help. . .



BEGIN INI FILE ( cFileIni )
SET cPath SECTION "" ENTRY "Path" DEFAULT ""
END INI
Andrés González López
Desde Guadalajara, Jalisco. México.

Mario Mansilla
Posts: 233
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina
Been thanked: 2 times

Post by Mario Mansilla » Thu Jul 05, 2018 3:44 am

Hola Andy :
muchas gracias por tu repuesta .
Si probe esa alternativa y otras ( "" ," ",[],[ ]) pero no funciona , el archivo ini que necesito leer y escribir pertenece a LETODB y no posee SECTION y cuando en forma manual se la incorporo ,mi sistema lo lee y escribe a mi necesidad , pero LETODB no , por eso necesito que el formato del archivo no tenga SECTION .

Saludos
Mario Mansilla

SALINETAS24
Posts: 94
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Has thanked: 1 time
Been thanked: 1 time

Post by SALINETAS24 » Thu Jul 05, 2018 9:19 am

Hola, no entiendo lo que quieres hacer, supongo que será grabar un fichero en formato ASC o TXT.
Cuando yo necesitaba hacer algo así en clipper usaba FREAD, FOPEN, FWRITE., incluso llegue a tener una funcion de Backup.
Mira esto, igual te sirve. Un saludo.

https://harbour.edu.pl/clipper/es/ng54fb6.html

User avatar
andyglezl
Posts: 939
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 16 times
Been thanked: 37 times
Contact:

Post by andyglezl » Thu Jul 05, 2018 1:43 pm

Tal vez...

Code: Select all


	IF "LETODB"
		BEGIN INI FILE ( cFileIni ) 
			SET cPath SECTION "" ENTRY "Path" DEFAULT ""
			.
			.
		END INI
		cTempFile := HB_MemoRead( cFileIni )
		cTempFile := STRTRAN( cTempFile, "[]", "" )
		hb_MemoWrit( cFileIni, cTempFile )
	ENDIF
	
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
serge_girard
Posts: 2052
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 411 times
Been thanked: 90 times
Contact:

Post by serge_girard » Thu Jul 05, 2018 2:07 pm

I use this:

Code: Select all

PUBLIC cVAR         := ''

IF FILE('select.ini') 
   BEGIN INI FILE ( 'select.ini')
      GET cVAR SECTION "General" ENTRY "DNLPath"
   END INI 
ELSE
   BEGIN INI FILE ( "select.ini")
      SET SECTION "General" ENTRY "DNLPath" TO cVAR
   END INI
ENDIF

Serge

Mario Mansilla
Posts: 233
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina
Been thanked: 2 times

Post by Mario Mansilla » Thu Jul 05, 2018 3:31 pm

Hola Amigos :
el problema es que el archivo LETODB.INI que lee LETODB.EXE tiene formato sin SECTION , por lo cual el formato del archivo debe ser :

DataPath=c:\LetoDb

Si coloco SECTION por ejemplo :
[General]
DataPath=c:\LetoDb

Mi sistema puede leer y escribir en el archivo INI con las rutinas que usamos en HMG que propone Serge_Girard , pero LETODB directamente no lee el valor almacenado en DATAPATH , devuelve un strig vacio .

Saludos
Mario Mansilla

Hello friends :
the problem is that the LETODB.INI file that reads LETODB.EXE has a format without SECTION, so the format of the file must be:

DataPath = c: \ LetoDb

If I put SECTION for example:
[General]
DataPath = c: \ LetoDb

My system can read and write in the INI file with the routines that we use in HMG that Serge_Girard proposes, but LETODB does not directly read the value stored in DATAPATH, it returns an empty strig.

regards
Mario Mansilla

User avatar
serge_girard
Posts: 2052
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 411 times
Been thanked: 90 times
Contact:

Post by serge_girard » Thu Jul 05, 2018 4:35 pm

Mario,

I cannot help on this because I don't use LEToDB, perhaps Marek or Harbour Users in google-group?

Serge

User avatar
mol
Posts: 3002
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 164 times
Been thanked: 90 times
Contact:

Post by mol » Fri Jul 06, 2018 6:18 am

In my previous Clipper project, I've used such a construction of reading INI file.
It works quite good. I've prepared working sample, where whole ini file is placed into association table.
You can modify it as you want.

Code: Select all

#include "hmg.ch"

function MAIN

	msgdebug(ReadIniFile("letodb.ini"))

return
*---------------------

function ReadIniFile
	param cIniFile
	local nError, Row, nRowCount
	local ahIniFile := { => }

	private FToken := { 0, 0, "", 0, 0, .F. }, cFtokBuffer := ""
	nError := FTokenInit(cIniFile, chr(13)+chr(10)+chr(26),2)
	
	if nError < 0
		return .f.
	endif

	do while .not. FTokenEnd()
		cRow = alltrim(FTokenNext())
		if (left(cRow,1) $ ";#/")
			// comment line
			loop
		endif
		
		if ( nPos := at("=",cRow) ) = 0
			* incorrect line without equal charater '='
			loop
		endif
		
		cVariable	:= alltrim(upper(left(cRow,nPos-1)))
		xParameter	:= ltrim(substr(cRow,nPos+1))
	
		if len(cVariable) == 0
			loop
		endif
	
		ahIniFile[ cVariable ] := xParameter
	enddo

	FTokenClose()	  // for assurance

 return ahIniFile
*----------------------------------*

FUNCTION fTokenInit(cFile, cSep, nSkip)
 LOCAL nRetVal := 0

 FToken[1] := FOPEN(cFile)

 IF FToken[1] < 0
  nRetVal := -FERROR()
 ELSE
  FToken[2]   := FSEEK(FToken[1], 0, 2)
  FToken[3]   := cSep
  FToken[4]   := nSkip
  FToken[5]   := MIN(MIN(10000, MEMORY(1)*1024), FToken[2])
  FToken[6]   := .F.
  cFtokBuffer := REPLICATE(CHR(0), FToken[5])

  FSEEK(FToken[1], 0, 0)
  FREAD(FToken[1], @cFtokBuffer, FToken[5])

  TOKENINIT(@cFtokBuffer, FToken[3], nSkip)
 ENDIF
RETURN(nRetVal)
*--------------------------------
FUNCTION fTokenNext()
 LOCAL cToken, nFilePos, nStill2Read

 cToken = TOKENNEXT(cFtokBuffer)

  IF LEN(cToken) >= FToken[5]
   * Token and buffer have the same size, a token is not
   * recognizable. The buffer has to be enhanced or it has
   * been tried to read text from a binary file.
   *
   cToken = ""
   fTokenClose()
  ELSE
   IF TOKENEND()
    * Last token for the current buffer. If the file contains
    * further data, this last token has to be 'illegal' and
    * read again with further data.

    IF FSEEK(FToken[1], 0, 1) < FToken[2]
     * new loading of the buffer
     *
     * If the file has not reached EOF, the last token of the
     * buffer will be ignored, because it is not sure if the
     * token is complete. The file pointer will be moved back to
     * the beginning of the token and a new buffer will be
     * loaded.
     *
     nFilePos    := FSEEK(FToken[1], -((FToken[5] -TOKENAT()) +1) , 1)
     nStill2Read := FToken[2] -nFilePos

      * creating a new, smaller buffer
      *
      IF nStill2Read < FToken[5]
       FToken[5]   := nStill2Read
       cFtokBuffer := REPLICATE(CHR(0), FToken[5])
      ENDIF

     * read the following data into the buffer
     *
     FREAD(FToken[1], @cFtokBuffer, FToken[5])
     TOKENINIT(@cFtokBuffer, FToken[3], FToken[4])
     cToken := TOKENNEXT(cFtokBuffer)
    ELSE
     fTokenClose()
    ENDIF
   ENDIF
  ENDIF
RETURN(cToken)


//* displays if further tokens are existing *//

FUNCTION fTokenEnd()
RETURN(FToken[6])


//* closes the file *//

FUNCTION fTokenClose()
  FCLOSE(FToken[1])
  cFtokBuffer := ""
  FToken := { 0, 0, "", 0, 0, .T. }
RETURN(Nil)

Mario Mansilla
Posts: 233
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina
Been thanked: 2 times

Post by Mario Mansilla » Fri Jul 06, 2018 12:49 pm

Hola Amigos :
muchas gracias por su ayuda , pude solucionar el inconveniente en particular con el archivo ini de LetoDb investigando en harbour users colocando como SECTION [Main] y "letodb.ini" solo con minusculas . De esta manera podemos trabajar con las rutinas de HMG sin problemas y Letodb puede leer sin problemas el archivo .

Saludos cordiales
Mario Mansilla

Hello friends :
Thank you very much for your help, I was able to solve the problem in particular with the LetoDb ini file investigating in harbor users placing as SECTION [Main] and "letodb.ini" only with lowercase. In this way we can work with the HMG routines without problems and Letodb can read the file without problems.

Best regards
Mario Mansilla

Post Reply