Sun Unix source code. Application module mda2uxa.c.
MS-DOS ASCII to Unix ASCII

     This Sun Unix code, mda2uxa.c, is the application module for a file filter. It receives data from an input file and creates data for the output file. The transfer function is to convert an MS-DOS ASCII file to a Unix output file. There are no EOF bytes in the output file. Unix portability is an issue, so source is given here. Related modules are on other pages.
     There are no HTML tags in the source code below.
/* Filespec= mda2uxa.c, MS-DOS ASCII TO Unix ASCII */ /* In comments, BHM=Being Here Means */ #include <fcntl.h> #include "stdio.h" #include <sys/types.h> #include <unistd.h> /* PURPOSE: This module contains the transfer function of a file filter, where an exsiting input file is read, and a new output file is created. This module reads MS-DOS ASCII data and creates Unix ASCII data. In essence, this module converts all incoming LF characters to CRLF characters. There are cases where the lack or presence of an end-of-line for the last line becomes an issue. Here, if the input file doesn't have one, one will be appended to the output file. The transfer function for this activity is in subroutine "genotp()". */ #define cr 0x0d /* Carriage return */ #define lf 0x0a /* Line feed */ #define eof 0x1a /* End of file */ /* Module Globals */ extern void ship(); /* Declaration */ char mrin_eof; /* mrin_eof holds most recent incoming non-eof byte */ /* It is used by both genotp() and final_wryte() */ genotp() /* BEGIN GENOTP */ { char getnc(); char nc; /* nc is the latest char from the input file */ while(2) /* Use '2' instead of '1' to make it more obvious */ { /* Start of while(2) */ while ( (nc=getnc()) == eof); /* works like fgetc, and ignores eof bytes */ mrin_eof=nc; /* ship everything except CR characters. */ if (nc!=cr ) ship(nc); } /* end of while (2) */ } /* END GENOTP */ void final_wryte() /* BEGIN FINAL_WRYTE */ { extern void wryte(); /* The final invoking of wryte() and any special activities relating to the end of the program are performed here */ if (mrin_eof != lf) ship(lf); /* Append final lf if none present */ wryte(); } /* END FINAL_WRYTE */ /* End of Module */


Return to previously viewed page
Go to Home Page

Arrow to Top