Converter arquivo no formato dos para unix
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version. // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Additional notes.
//
// The author of the original source code is unknown.
//
// Modified by Clem Dye (clem@bastet.com), December 1998, to compile cleanly
// under Microsoft Visual C/C++ v4.0 (or later) for use on Windows NT. Added
// exit(1) statements in main() to improve error reporting when the program is
// used in batch scripts.
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/utime.h> #ifndef TRUE
# define TRUE (1)
# define FALSE (0)
#endif #define R_CNTRL "rb"
#define W_CNTRL "wb" struct stat s_buf; int dos2u (path)
char *path;
{
FILE *in, *out;
int ch,
rval = FALSE;
char temppath [16];
struct _utimbuf ut_buf;
strcpy (temppath, "./clntmp");
strcat (temppath, "XXXXXX");
mktemp (temppath);
if ((in=fopen (path, R_CNTRL)) == (FILE *) 0)
return TRUE;
if ((out=fopen (temppath, W_CNTRL)) == (FILE *) 0)
{
fclose (in);
return TRUE;
}
while ((ch = getc (in)) != EOF)
if ((ch != '\015' && ch != '\032') &&
(putc (ch, out) == EOF))
{
rval = TRUE;
break;
}
if (fclose (in) == EOF)
{
rval = TRUE;
}
if (fclose (out) == EOF)
{
rval = TRUE;
}
ut_buf.actime = s_buf.st_atime;
ut_buf.modtime = s_buf.st_mtime;
if (_utime (temppath, &ut_buf) == -1)
rval = TRUE;
if (unlink (path) == -1)
rval = TRUE;
if (rval)
{
unlink (temppath);
return TRUE;
}
if (rename (temppath,path) == -1)
{
fprintf (stderr, "Dos2Unix: Problems renaming '%s' to '%s'.\n", temppath, path);
fprintf (stderr, " However, file '%s' remains.\n", temppath);
exit (1);
}
unlink (temppath);
return FALSE;
}
void main (argc, argv)
int argc;
char **argv;
{
char *path;
while (--argc>0)
{
if (stat (path=*++argv, &s_buf) != -1)
{
printf ("Dos2Unix: Processing file %s ...\n", path);
if (dos2u (path))
{
fprintf (stderr, "Dos2Unix: Problems processing file %s.\n", path);
exit (1);
}
}
else
{
fprintf (stderr, "Dos2Unix: Can't stat '%s'.\n", path);
exit (1);
}
}
}
Frigorifico Sa
Respostas
Wesley Yamazack
07/05/2009
Bom pelo que estou analisando aqui a única coisa que este programa faz é substituir os caracteres de fim de linha no caso CR. Exemplo #13, #10, muito comuns em integração TXT do Windows. Se for isso mesmo o problema é tranquilo de se resolver, criamos um programa para dar um Replace nos caracter de fim de linha, e teria seu problema resolvido
Att,
Wesley Y
Wesley Yamazack
07/05/2009
Bom pelo que estou analisando aqui a única coisa que este programa faz é substituir os caracteres de fim de linha no caso CR. Exemplo #13, #10, muito comuns em integração TXT do Windows. Se for isso mesmo o problema é tranquilo de se resolver, criamos um programa para dar um Replace nos caracter de fim de linha, e teria seu problema resolvido
Att,
Wesley Y
Wesley Yamazack
07/05/2009
A duvida sobre o chamado foi esclarecida ? Aguardamos informações para concluirmos o chamado.
Att,
Wesley Y
Frigorifico Sa
07/05/2009
Frigorifico Sa
07/05/2009
Wesley Yamazack
07/05/2009
Segue um codigo abaixo em delphi, para descobrir o caracter ascii de uma tecla.
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Label1.Caption := Format('O código da tecla pressionada é: %d', [Key]);
end;
Com relação ao 13 este é o enter, o 10 trabalha junto com o 13, quando esta separado, senão me engano seria como se fosse uma quebra de linha parecido com o enter.
Espero que ajude.
Att,
Wesley Y
Frigorifico Sa
07/05/2009
Não entendi a questão acima. Tem que substituir os dois CR? O meu arquivo não tinha CR de LF. Como posso resolver esta questão converter arquivos no formato Windows para unix?
Wesley Yamazack
07/05/2009
Seria possível enviar uma parte do arquivo para podermos analisar ?
Att,
Wesley Y
Frigorifico Sa
07/05/2009
Wesley Yamazack
07/05/2009
Me mande o arquivo completo para que eu possa analisar melhor, pois pelo que foi dito anteriormente seria substituir os caracteres de fim de linha e funcionaria, porém pelo visto voce nao achou nenhum caracter de final de linha. Nao conheco os arquivos Unix, tenho que analisar o mesmo e ver se seria somente a substituição para resolver este problema. Fico no aguardo
Att,
Wesley Y
Frigorifico Sa
07/05/2009
0 02 021001
0 02 021002
0 26 021003
0 02 021004
0 02 021005
0 02 021006
0 02 021007
0 02 021010
0 03 030800
0 03 033200
0 03 033600
0 03 034300
0 03 035400
0 04 041900
0 05 100400
0 10 100501
0 10 100502
0 10 101200
0 03 101300
0 03 101501
0 10 101600
0 10 101601
0 10 101602
0 03 102001
0 10 102200
0 10 102901
0 03 103201
0 10 103500
0 10 103501
0 10 103502
0 10 103900
0 10 103901
0 10 103902
0 10 103903
0 03 104001
0 03 104002
0 03 104401
0 10 105200
0 10 105300
0 11 110100
0 11 110500
0 11 110700
0 11 111400
0 11 111700
0 11 112100
0 11 112900
0 11 113900
0 11 113901
0 11 114100
0 11 118800
0 03 120400
0 12 120500
0 12 120501
0 12 120502
0 12 120503
0 12 120504
0 12 120505
0 12 120506
0 12 120700
0 12 120701
0 12 121100
0 03 121101
0 12 121200
0 12 121201
0 12 121400
0 12 121600
0 12 121601
0 12 121602
0 12 121603
0 12 121604
0 12 121605
0 12 121606
0 12 121607
0 12 121801
0 03 122001
0 03 122002
0 12 122003
0 12 122004
0 12 122200
0 12 122600
0 12 122900
0 12 122901
0 12 122902
0 12 123000
0 12 123001
0 03 123201
0 12 123500
0 12 123501
0 12 123502
0 12 123503
0 12 123504
0 12 123505
0 12 123506
0 12 123507
0 12 123508
0 03 123700
0 03 123701
0 03 123702
0 12 123800
0 12 123801
0 12 123802
0 12 123803
0 12 123900
0 12 123901
0 12 123902
0 12 123903
0 12 123904
0 12 123905
0 12 123906
0 12 123907
0 12 123908
0 12 123909
0 03 124001
0 03 124002
0 03 124401
0 12 124501
0 12 124502
0 12 124503
0 12 124504
0 03 124901
0 03 124902
0 12 125200
0 12 125201
0 12 125202
0 12 125203
0 12 125300
0 12 125301
0 12 125302
0 12 125600
0 03 125900
0 12 128400
0 03 128500
0 13 130100
0 13 130500
0 13 130700
0 13 131400
0 13 131700
0 13 131701
0 13 132100
0 13 132900
0 13 133900
0 13 133901
0 13 133902
0 13 134100
0 13 138800
0 14 140100
0 14 140500
0 14 140700
0 14 141600
0 14 141601
0 14 141602
0 14 141603
0 14 142200
0 14 142600
0 14 142900
0 14 142901
0 14 143900
0 14 143901
0 14 143902
0 14 143903
0 14 144100
0 14 144500
0 14 145200
0 14 145201
0 20 202801
0 20 202802
0 20 202803
0 20 202804
0 20 202805
0 20 202806
0 20 202807
0 20 202808
0 20 202809
0 20 202810
0 20 202811
0 20 202812
0 20 202813
0 20 202814
0 20 202815
0 20 202816
0 20 202817
0 20 202818
0 20 202819
0 20 202820
0 20 202821
0 20 202822
0 20 202823
0 20 202824
0 20 202825
0 21 210300
0 21 210301
0 21 210302
0 21 210303
0 21 210304
0 21 210305
0 21 210306
0 21 210307
0 21 211400
0 21 211600
0 21 211601
0 21 212200
0 21 212500
0 21 212900
0 21 213200
0 21 213201
0 21 213500
0 21 213900
0 21 213901
0 21 214000
0 21 214001
0 21 214100
0 21 214400
0 21 214401
0 22 220501
0 22 220801
0 22 221601
0 22 221602
0 22 221603
0 22 221801
0 22 222001
0 22 222301
0 22 222701
0 22 222901
0 22 223001
0 22 223200
0 22 223501
0 22 223901
0 22 224001
0 22 224401
0 22 224801
0 22 225201
0 22 225301
0 22 225500
0 22 225501
0 22 225502
0 22 225503
0 22 225504
0 22 225505
0 22 225506
0 22 225507
0 22 225508
0 22 225509
0 26 260400
0 26 260500
0 26 260501
0 26 260800
0 26 261200
0 26 261201
0 26 261600
0 12 261800
0 26 261801
0 26 262000
0 26 262200
0 26 262600
0 26 262700
0 26 262902
0 26 262903
0 26 263000
0 26 263001
0 26 263200
0 26 263500
0 26 263503
0 26 263700
0 26 263901
0 26 263902
0 26 263903
0 26 263904
0 26 264000
0 26 264001
0 26 264200
0 26 264400
0 26 264800
0 26 264900
0 26 265300
0 26 265301
0 26 265302
0 26 269204
0 27 270900
0 27 270901
0 27 270902
0 27 270903
0 27 270904
0 27 270905
0 27 270906
0 27 270907
0 27 270908
0 27 270909
0 27 270910
0 27 270911
0 27 270912
0 27 272600
0 27 272900
0 27 272901
0 27 273400
0 27 273401
0 28 280200
0 28 280201
0 28 285700
0 28 288600
0 28 288601
0 28 288602
0 28 288603
0 29 290600
0 29 290601
0 29 290602
0 29 290603
0 29 292400
0 29 292401
0 29 292402
0 29 292403
0 29 292404
0 29 292405
0 29 292406
0 29 292407
0 29 292408
0 29 298100
0 29 298101
0 29 298200
0 29 298201
0 30 308300
0 30 308301
0 30 308302
0 30 308303
0 30 308304
Windos 0 02 021000
0 02 021001
0 02 021002
0 26 021003
0 02 021004
0 02 021005
0 02 021006
0 02 021007
0 02 021010
0 03 030800
0 03 033200
0 03 033600
0 03 034300
0 03 035400
0 04 041900
0 05 100400
0 10 100501
0 10 100502
0 10 101200
0 03 101300
0 03 101501
0 10 101600
0 10 101601
0 10 101602
0 03 102001
0 10 102200
0 10 102901
0 03 103201
0 10 103500
0 10 103501
0 10 103502
0 10 103900
0 10 103901
0 10 103902
0 10 103903
0 03 104001
0 03 104002
0 03 104401
0 10 105200
0 10 105300
0 11 110100
0 11 110500
0 11 110700
0 11 111400
0 11 111700
0 11 112100
0 11 112900
0 11 113900
0 11 113901
0 11 114100
0 11 118800
0 03 120400
0 12 120500
0 12 120501
0 12 120502
0 12 120503
0 12 120504
0 12 120505
0 12 120506
0 12 120700
0 12 120701
0 12 121100
0 03 121101
0 12 121200
0 12 121201
0 12 121400
0 12 121600
0 12 121601
0 12 121602
0 12 121603
0 12 121604
0 12 121605
0 12 121606
0 12 121607
0 12 121801
0 03 122001
0 03 122002
0 12 122003
0 12 122004
0 12 122200
0 12 122600
0 12 122900
0 12 122901
0 12 122902
0 12 123000
0 12 123001
0 03 123201
0 12 123500
0 12 123501
0 12 123502
0 12 123503
0 12 123504
0 12 123505
0 12 123506
0 12 123507
0 12 123508
0 03 123700
0 03 123701
0 03 123702
0 12 123800
0 12 123801
0 12 123802
0 12 123803
0 12 123900
0 12 123901
0 12 123902
0 12 123903
0 12 123904
0 12 123905
0 12 123906
0 12 123907
0 12 123908
0 12 123909
0 03 124001
0 03 124002
0 03 124401
0 12 124501
0 12 124502
0 12 124503
0 12 124504
0 03 124901
0 03 124902
0 12 125200
0 12 125201
0 12 125202
0 12 125203
0 12 125300
0 12 125301
0 12 125302
0 12 125600
0 03 125900
0 12 128400
0 03 128500
0 13 130100
0 13 130500
0 13 130700
0 13 131400
0 13 131700
0 13 131701
0 13 132100
0 13 132900
0 13 133900
0 13 133901
0 13 133902
0 13 134100
0 13 138800
0 14 140100
0 14 140500
0 14 140700
0 14 141600
0 14 141601
0 14 141602
0 14 141603
0 14 142200
0 14 142600
0 14 142900
0 14 142901
0 14 143900
0 14 143901
0 14 143902
0 14 143903
0 14 144100
0 14 144500
0 14 145200
0 14 145201
0 20 202801
0 20 202802
0 20 202803
0 20 202804
0 20 202805
0 20 202806
0 20 202807
0 20 202808
0 20 202809
0 20 202810
0 20 202811
0 20 202812
0 20 202813
0 20 202814
0 20 202815
0 20 202816
0 20 202817
0 20 202818
0 20 202819
0 20 202820
0 20 202821
0 20 202822
0 20 202823
0 20 202824
0 20 202825
0 21 210300
0 21 210301
0 21 210302
0 21 210303
0 21 210304
0 21 210305
0 21 210306
0 21 210307
0 21 211400
0 21 211600
0 21 211601
0 21 212200
0 21 212500
0 21 212900
0 21 213200
0 21 213201
0 21 213500
0 21 213900
0 21 213901
0 21 214000
0 21 214001
0 21 214100
0 21 214400
0 21 214401
0 22 220501
0 22 220801
0 22 221601
0 22 221602
0 22 221603
0 22 221801
0 22 222001
0 22 222301
0 22 222701
0 22 222901
0 22 223001
0 22 223200
0 22 223501
0 22 223901
0 22 224001
0 22 224401
0 22 224801
0 22 225201
0 22 225301
0 22 225500
0 22 225501
0 22 225502
0 22 225503
0 22 225504
0 22 225505
0 22 225506
0 22 225507
0 22 225508
0 22 225509
0 26 260400
0 26 260500
0 26 260501
0 26 260800
0 26 261200
0 26 261201
0 26 261600
0 12 261800
0 26 261801
0 26 262000
0 26 262200
0 26 262600
0 26 262700
0 26 262902
0 26 262903
0 26 263000
0 26 263001
0 26 263200
0 26 263500
0 26 263503
0 26 263700
0 26 263901
0 26 263902
0 26 263903
0 26 263904
0 26 264000
0 26 264001
0 26 264200
0 26 264400
0 26 264800
0 26 264900
0 26 265300
0 26 265301
0 26 265302
0 26 269204
0 27 270900
0 27 270901
0 27 270902
0 27 270903
0 27 270904
0 27 270905
0 27 270906
0 27 270907
0 27 270908
0 27 270909
0 27 270910
0 27 270911
0 27 270912
0 27 272600
0 27 272900
0 27 272901
0 27 273400
0 27 273401
0 28 280200
0 28 280201
0 28 285700
0 28 288600
0 28 288601
0 28 288602
0 28 288603
0 29 290600
0 29 290601
0 29 290602
0 29 290603
0 29 292400
0 29 292401
0 29 292402
0 29 292403
0 29 292404
0 29 292405
0 29 292406
0 29 292407
0 29 292408
0 29 298100
0 29 298101
0 29 298200
0 29 298201
0 30 308300
0 30 308301
0 30 308302
0 30 308303
0 30 308304
Wesley Yamazack
07/05/2009
Fico no aguardo
Att,
Wesley Y
Frigorifico Sa
07/05/2009
Frigorifico Sa
07/05/2009
Frigorifico Sa
07/05/2009
[#VIDEO-115#]
Wesley Yamazack
07/05/2009
Bom, o arquivo que você postou, ele não tem os espaços pois você consegue ver os mesmos, me mande o arquivo para que eu possa baixar aqui o mesmo. Pois isso não é tão simples não, só mandar o texto não tem como analisar, fico no aguardo do arquivo.
Att,
Wesley Y
Frigorifico Sa
07/05/2009
[#VIDEO-118#]
Wesley Yamazack
07/05/2009
Zipa os arquivos, ou colca no winrar, e me manda, pois se você olhar nas imagens vai ver que os arquivos tem tipo que um Retangulo em pé, e uns espaços. Estes são os caracteres especias que você não consegue ver. Me manda os txt zipados. Pois se mandar direto o brownser abre ele direto.
Fico no aguardo
Att,
Wesley Y
Frigorifico Sa
07/05/2009
[#VIDEO-119#]
Wesley Yamazack
07/05/2009
Wesley Yamazack
07/05/2009
Segue abaixo o link dos fontes do exemplo.
Dica : Clique no botão Load, ele ira carregar o arquivo no primeiro memo.
Clique no botão >>>>> e ele irá remover os caracteres especiais do teu arquivo.
http://www.4shared.com/file/107973097/ce058601/Chamado_unix.html
Att,
Wesley Y
Frigorifico Sa
07/05/2009
Var
I : Integer;
F : TStringList;
begin
For I := 0 to Memo2.Lines.Count -1 do
begin
Memo1.Lines.Add( StringReplace(Memo2.Lines.Strings[I], ' ',' ',[rfReplaceAll])); // o Caracter que esta em ' ' é caracter diferente, não é espaço não
end; F := TStringList.Create; F.Text := Memo1.Text;
F.SaveToFile('teste.txt');
F.Free;
end;
Se vc salvar o arquivo vera que não esta igual ao que eu te enviei. Abra o arquivo grupo0 unix.txt no bloco de notas que é o formato que preciso vera a diferença para o grupo0 windos.txt e o teste.txt. Att.. Ricardo horoi
Wesley Yamazack
07/05/2009
O que eu fiz foi, copiar o caracter que você tem separando os textos, e joguei dentro do meu replace, depois eu substitui ele por um espaço somente.
Você quer colocar tudo em uma única linha ?
Qual é o caracter que você quer separar ?
Att,
Wesley Y
Frigorifico Sa
07/05/2009
> utilities that will do things like parse a string based on a token
> separator, or split a string into multiple strings (like in an array of
> strings or such) based on end-of-line characters (dos uses cr/lf; unix uses
> lf), etc.
TStringlist can do much of what you want.
Código:
Var
sl: TStringlist;
sl:= TStringlist.Create;
try
sl.Text := SomeStringWithLinebreaks;
This would dissect the string into individual lines, It can handle both DOS
and Unix-style lineends.
For Delphi 6 you can use the following to split a string on a delimiter:
sl.Delimiter := someChar;
sl.DelimitedText := someTextWithDelimiters;
For older Delphi versions you have to write your own routine to do that but
that is not really *that* much work, since you do it only once. Here are a
couple of routines you may find useful.
Unit Utils;
interface
Uses Classes;
{: Return the position of the first instance of ch in S, or 0 if
ch was not found. }
Function Scan( ch: Char; Const S: String ): Integer;
{: Return the position of the first instance of ch in S after
position fromPos, or 0 if ch was not found. }
Function IScan( ch: Char; Const S: String; fromPos: Integer ): Integer;
{: Return the position of the last instance of ch in S, or 0 if
ch was not found. }
Function RScan( ch: Char; Const S: String ): Integer;
{: Return the position of the last instance of ch in S before fromPos,
or 0 if ch was not found. }
Function RIScan( ch: Char; Const S: String; fromPos: Integer ): Integer;
{: Split the passed string into substrings at the position of the
separator character and add the substrings to the passed list.
The list is not cleared first! }
Procedure SplitString( Const S: String; separator: Char;
substrings: TStringList );
{: Split the passed string into substrings at the position of the
separator string and add the substrings to the passed list.
The list is not cleared first! }
Procedure SplitString2( S: String; const separator: String;
substrings: TStringList );
{: Concatenate the items of the passed list into a single string,
separating the items with the separator string. }
Function ConcatSubstrings( const separator: String;
substrings: TStringList ): String;
{: Concatenate the items of the passed list into a single string,
separating the items with the separator string and enclosing
each item with the quote characters. Instances of the quote
character inside an item will be doubled. }
Function ConcatQuotedSubstrings( separator, quote : Char;
substrings: TStringList ): String;
{: Pad a string to a given length by adding characters on the left. }
Function PadLeft( Const S: String; toLength: Integer;
withChar: Char ): String;
{: Pad a string to a given length by adding characters on the right. }
Function PadRight( Const S: String; toLength: Integer;
withChar: Char ): String;
implementation
Uses SysUtils;
Function IScan( ch: Char; Const S: String; fromPos: Integer ): Integer;
Var
i: Integer;
Begin
Result := 0;
For i := fromPos To Length(S) Do Begin
If S[i] = ch Then Begin
Result := i;
Break;
End; { If }
End; { For }
End; { IScan }
Function Scan( ch: Char; Const S: String): Integer;
Begin
Result := IScan( ch, S, 1 );
End; { Scan }
Function RIScan( ch: Char; Const S: String; fromPos: Integer ): Integer;
Var
i: Integer;
Begin
Result := 0;
For i := fromPos DownTo 1 Do Begin
If S[i] = ch Then Begin
Result := i;
Break;
End; { If }
End; { For }
End; { RIScan }
Function RScan( ch: Char; Const S: String ): Integer;
Begin
Result := RIScan( ch, S, Length(S) );
End; { RScan }
Procedure SplitString( Const S: String; separator: Char; substrings:
TStringList );
Var
i, n: Integer;
Begin
If Assigned( substrings ) and ( Length( S )>0 ) Then Begin
i:= 1;
Repeat
n := IScan( separator, S, i );
If n = 0 Then
n:= Length( S )+1;
substrings.Add( Copy( S,i,n-i ));
i:= n+1;
Until i>Length( S );
End; { If }
End; { SplitString }
Procedure SplitString2( S: String; const separator: String;
substrings: TStringList );
Var
i: Integer;
Begin
If Assigned( substrings ) and ( Length( S )>0 ) Then Begin
Repeat
i:= Pos( separator, S );
If i > 0 Then Begin
substrings.Add( Copy( S, 1, i-1 ));
Delete( S, 1, i + Length( separator ) -1 );
End { If }
Else Begin
substrings.Add( S );
Break;
End; { Else }
Until Length( S ) = 0;
End;
End; { SplitString2 }
Function PadLeft( Const S: String; toLength: Integer;
withChar: Char ): String;
Begin { PadLeft }
If Length(S) < toLength Then
Result := StringOfChar( withChar, toLength - Length(S)) + S
Else
Result := S;
End; { PadLeft }
Function PadRight( Const S: String; toLength: Integer;
withChar: Char ): String;
Begin { PadRight }
If Length(S) < toLength Then
Result := S + StringOfChar( withChar, toLength - Length(S))
Else
Result := S;
End; { PadRight }
Function ConcatSubstrings( const separator: String;
substrings: TStringList ): String;
Var
i: Integer;
Begin
Result := EmptyStr;
For i := 0 To substrings.count-1 Do Begin
If i > 0 Then
Result:= Result + separator;
Result:= Result + substrings[i];
End; { For }
End; { ConcatSubstrings }
Function ConcatQuotedSubstrings( separator, quote : Char;
substrings: TStringList ): String;
Var
i: Integer;
Begin
Result := EmptyStr;
For i := 0 To substrings.count-1 Do Begin
If i > 0 Then
Result:= Result + separator;
Result:= Result + AnsiQuotedStr( substrings[i], quote );
End; { For }
End; { ConcatQuotedSubstrings }
end.
Wesley Yamazack
07/05/2009
As funções podem até funcionar e tudo mais, porém quero saber por qual caracter você quer substituir, como o arquivo tem que ficar ? As funções vou analisar.
Att,
Wesley Y
Frigorifico Sa
07/05/2009
Frigorifico Sa
07/05/2009
A codificaçao dos arquivos é apenas UNIX. Att.. Ricardo Horoi
Wesley Yamazack
07/05/2009
Irei baixar o programa e analisar. Peço que aguarde um pouco.
Att,
Wesley Y
Wesley Yamazack
07/05/2009
Consegui ver o programa que você me mandou, porém ele abre normal, como se fosse um bloco de notas. O teu arquivo do Unix fica igual ao do Windows. Como faço para ver o arquivo da mesma forma que você visualiza ? Me manda um PrintScreen da tua tela com o formato para eu entender, pois estou pesquisando sobre isso mas não tenho achado nada, infelizmente.
Att,
Wesley Y
Frigorifico Sa
07/05/2009
[#VIDEO-124#]
Rodrigo Mourão
07/05/2009
Estou agora como o consultor deste chamado. Antes de mais nada queria colocar algumas definições para você entender:
Arquivos texto não são representados da mesma forma nos diversos sistemas operacionais existentes. Enquanto a representação da MicroSoft usa um valor 13, seguido de um valor 10 para representar um fim de linha (escrito quando você digita o [ENTER]), a representação Unix (também usadas nos Macs modernos) usa apenas o valor 10. O resultado é que se um arquivo ASCII for transferido byte a byte de um sistema para outro, ele pode não ser apresentado corretamente na tela do sistema para onde foi copiado. Alguns editores de texto detectam esse tipo de problema e fazem a correção automaticamente, para apresentar o arquivo de maneira correta para o usuário. Outros, apresentam o arquivo da maneira como ele realmente é.Veja bem: O Windows não entende o caracter 10 como final de linha, então mostra arquivos Unix sem as quebras de linha e com um caracter esquisito onde deveria haver a quebra de linha. O Linux por sua vez não entende o caracter 13 como início do código para fim de linha e mostra o caracter 13 (como um símbolo esquisito), depois vê o caracter 10 e muda de linha O problema se agrava ainda mais se a pessoa tenta editar isso "na mão", não arruma todos os finais de linha e depois faz novas transferências do arquivo, entre Linux e Windows, aumentando a quantidade de caracteres estranhos até que o arquivo fique ilegível (já casos em que o próprio compilador não conseguia interpretar o arquivo...). Neste caso temos duas opções para não ter problemas com os arquivos texto: Usar um editor de texto que faça a conversão automaticamente, ou usar um programa (Delphi) que altere o código ASCII do seu texto.O caminho e mesmo o replace que o Wesley falou mas não feito desta maneira. Assim vou criar um exemplo que acredito que va resolver. Peço que aguarde que em breve estarei enviando !!
Abs
Atenciosamente,
Rodrigo Carreiro Mourão
Borland Instructor Certified
Coordenador da Consultoria em Delphi
Rodrigo Mourão
07/05/2009
Depois de brigar comigo mesmo acho que rolou, a lógica estava certa até agora porém se usar TStrings, ou seja, Memo, TStringList, etc ele sempre iria gerar formato Windows, enfim. Eu criou uma função para remover o #13 do arquivo. Segue:
procedure ConvertToUnix(SourceFile, TargetFile:String);
var
Out: TFileStream;
Buffer: array[0..1] of Char;
&In: TFileStream;
Lidos: Integer;
begin
&In := TFileStream.Create(SourceFile, fmOpenRead);
Out := TFileStream.Create(TargetFile, fmCreate);
repeat
Lidos := &In.Read(Buffer, 1);
if Buffer[0] = ''#13'' then
Continue;
Out.Write(Buffer, Lidos);
until Lidos = 0;
&In.Free;
out.Free;
end;
Para usar:
ConvertToUnix('C:\ArquivoNoFormatoWindows.txt','C:\ArquivoNoFormatoUnix.txt');
Aguardo ansioso uma posição sua.
Abs.
Atenciosamente,
Rodrigo Carreiro Mourão
Borland Instructor Certified
Coordenador da Consultoria em Delphi
Frigorifico Sa
07/05/2009
[Error] uExporta.pas(94): Illegal character in input file: '&' ($26)
Att.. Ricardo Horoi
Rodrigo Mourão
07/05/2009
Troca para Entrada e Saida.
procedure ConvertToUnix(SourceFile, TargetFile:String);
var
SAIDA: TFileStream;
Buffer: array[0..1] of Char;
Entrada: TFileStream;
Lidos: Integer;
begin
Entrada := TFileStream.Create(SourceFile, fmOpenRead);
SAIDA := TFileStream.Create(TargetFile, fmCreate);
repeat
Lidos := Entrada.Read(Buffer, 1);
if Buffer[0] = ''#13'' then
Continue;
SAIDA.Write(Buffer, Lidos);
until Lidos = 0;
Entrada.Free;
SAIDA.Free;
end;
Abs !!!
Frigorifico Sa
07/05/2009
Rodrigo Mourão
07/05/2009
Abs
Atenciosamente,
Rodrigo Carreiro Mourão
Borland Instructor Certified
Coordenador da Consultoria em Delphi
Frigorifico Sa
07/05/2009
Rodrigo Mourão
07/05/2009
Este foi um dos meus maiores desafios.
Fico muito feliz que tenho funcionado.
Abs.
Atenciosamente,
Rodrigo Carreiro Mourão
Borland Instructor Certified
Coordenador da Consultoria em Delphi