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

This Sun Unix code, uxa2mda.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 Unix ASCII file data to MS-DOS ASCII file data. There is 1 EOF byte 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= uxa2mda.c, Unix ASCII to MS-DOS 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 existing input file is read, and a new output file is created. This module reads Unix ASCII data and creates MS-DOS ASCII data. In essence, this module converts all incoming LF characters to CRLF characters. In addition, a single EOF byte is appended. There are cases where the lack 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 */ extern char getnc(); /* Declaration */ char nc; /* nc is the latest input char */ genotp() /* BEGIN GENOTP */ { while(2) /* Use '2' instead of '1' to make it more obvious */ { /* Start of while(2) */ nc=getnc(); /* getnc works like fgetc. */ if (nc==lf) { ship(cr); ship(lf); } else 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 (nc != lf) {ship(cr); ship(lf);} /* Append final crlf if none present */ ship(eof); wryte(); } /* END FINAL_WRYTE */ /* End of Module */


Return to previously viewed page
Go to Home Page

Arrow to Top