[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Script polluted by DOS formatting



Hi Francesco,

On Thu, 2007-07-12 at 09:28 -0700, Bob McGowan wrote:
> Francesco Pietra wrote:
> be sure you get this.  Apologies if you are subscribed and get mail twice.

Ditto.

...
> VIM, if configured to do so (see 'set fileformat' and 'set fileformats' 
> in VIM help), will do auto conversion from/to DOS and so will hide the 
> file type being edited.  The only indication is when the file is first 
> read in, in the status line:
> 
>    "filename" [dos] linesL, charsC

Emacs (he :-) does the same thing.  However, a nice work around is to
do 

	$ echo "" > foo 
	$ cat dosfile >> foo 
	$ emacs foo 
	M-% ^Q^M RET RET
	C-x C-s
	$ mv foo dosfile 

> So you may have missed it, assuming it was printed.
> 
> > 
> > od -c scriptfilename > od.dmp
> > 
> > that revealed non printing characters, octal 302 followed by octal 240 at each
> > script line.
> 
> Here's the issue:  in ASCII, the DOS format <CR><NL> in octal would be 
> 015 followed by 012, not the numbers you provide.
> 
> The dos2unix/unix2dos and vim programs are looking for the ASCII value 
> and so would not touch the 302 240 pair you found.  So the file would be 
> unchanged.


Why not write a small C++ program that does what you want: 

	#include <iostream> 
	int main() 
	{
	   while (!std::cin.eof()) { 
	      char c = std::cin.get();
	      if (std::cin.fail()) break;
	      if (c == 0302 || c == 0240) continue;
	      std::cout.put(c);
           }
           return 0;
        } 
	
	$ g++ foo.cc -o foo 
	$ foo < dosfile > fixedfile 

:-)

Yours,

-- 
 ___  |  Christian Holm Christensen 
  |_| |  -------------------------------------------------------------
    | |  Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|           DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|            Denmark                    Office: (+45) 353  25 404
 ____|   Email:   cholm@nbi.dk               Web:    www.nbi.dk/~cholm
 | |



Reply to: