'Dosify' a file by converting all instances of newline (with or without the preceeding carriage return) into the carriage return newline sequence.

Return TypeFunction nameArguments
hzEcodeDosifyFile(hzString&,hzString&,)

Declared in file: hzTextproc.h
Defined in file : hzTextproc.cpp

Function Logic:

0:START 1:unknown 2:items 3:Return E_ARGUMENT 4:unknown 5:items 6:Return E_ARGUMENT 7:unknown 8:bSame tgt target 9:bSame target 10:rc 11:unknown 12:Return rc 13:items 14:unknown 15:Return E_WRITEFAIL 16:unknown 17:items 18:unknown 19:unknown 20:rc 21:unknown 22:unknown 23:unknown 24:buf items 25:items 26:items 27:unknown 28:rc 29:items items 30:unknown 31:items items 32:Return rc

Function body:

hzEcode DosifyFile (hzString& tgt)hzString& src, 
{
   //  Category: Text Processing
   //  
   //  'Dosify' a file by converting all instances of newline (with or without the preceeding carriage return) into the carriage return newline sequence.
   //  
   //  Arguments: 1) tgt  The pathname of the target file
   //     2) src  The pathname of the source file
   //  
   //  Returns: E_NODATA If the source file has not been supplied
   //     E_ARGUMENT If the target file has not been supplied
   //     E_NOTFOUND If the source file cannot be found
   //     E_OPENFAIL If the source file cannot be opened
   //     E_READFAIL If the source file cannot be read
   //     E_WRITEFAIL If the target file cannot be created or written to
   //     E_OK  If the operation was successful
   _hzfunc(__func__) ;
   ifstream    is ;            //  Input stream
   ofstream    os ;            //  Output stream
   hzString    target ;        //  Intermeadiate filename
   char        buf [1024]; //  Working buffer
   bool        bSame ;         //  Target/Source match indicator
   hzEcode     rc = E_OK ;     //  Return code
   if (!src)
   {
       hzerr(E_ARGUMENT, "No source file specified") ;
       return E_ARGUMENT ;
   }
   if (!tgt)
   {
       hzerr(E_ARGUMENT, "No target file specified") ;
       return E_ARGUMENT ;
   }
   //  If source and target file are the same
   if (tgt == src)
       { bSame = true ; target = tgt + ".x" ; }
   else
       { bSame = false ; target = tgt ; }
   //  Seek to open source file
   rc = OpenInputStrm(is, src) ;
   if (rc != E_OK)
       return rc ;
   //  Open target for writing
   os.open(*target) ;
   if (os.fail())
       return E_WRITEFAIL ;
   for (; rc == E_OK ;)
   {
       is.getline(buf, 1024);
       if (!is.gcount())
           break ;
       if (is.fail())
           { rc = E_READFAIL ; break ; }
       if (!buf[0])
           continue ;
       if (is.gcount() == 1024)
       {
           if (buf[1023]==CHAR_CR)
           {
               buf[1023]=0;
               os << buf << "\r\n" ;
               continue ;
           }
           os.write(buf, 1024);
           continue ;
       }
       os << buf << "\r\n" ;
       if (os.fail())
           rc = E_WRITEFAIL ;
   }
   is.close() ;
   os.close() ;
   if (bSame)
   {
       //  Lose the source file and rename the target back to the original
       unlink(*src) ;
       rename(*target, *tgt) ;
   }
   return rc ;
}