Index: src/driver/as.cc
===================================================================
--- src/driver/as.cc	(revision fde66c23cacb445af864df0eb609e9cbcd51ccf9)
+++ src/driver/as.cc	(revision 0a76d8456d64af211f4ff09a58e7800b23b143d9)
@@ -10,47 +10,20 @@
 // Created On       : Wed Aug  1 10:49:42 2018
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Aug  2 12:06:23 2018
-// Update Count     : 78
+// Last Modified On : Thu Aug  2 16:18:14 2018
+// Update Count     : 84
 // 
 
-#include <iostream>
-#include <fstream>
-using namespace std;
 #include <cstdio>										// perror
-#include <cstdlib>										// exit, mkstemps
-#include <unistd.h>										// execvp, unlink
-#include <csignal>										// signal
+#include <cstdlib>										// exit
+#include <fcntl.h>										// open
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/mman.h>									// mmap
+#include <string.h>
 
 //#define __DEBUG_H__
 
-
-#define SUFFIX ".s"
-char tmpname[] = P_tmpdir "/CFAXXXXXX" SUFFIX;
-int tmpfilefd = -1;
-
-
-void rmfile( const char * fname ) {
-	if ( unlink( fname ) == -1 ) {						// remove tmpname
-		perror ( "CFA Translator error: cpp failed" );
-		exit( EXIT_FAILURE );
-	} // if
-} // rmtmpfile
-
-
-void sigTermHandler( __attribute__((unused)) int signal ) {
-	if ( tmpfilefd != -1 ) {							// RACE, file created ?
-		rmfile( tmpname );								// remove
-		exit( EXIT_FAILURE );							// terminate 
-	} // if
-	tmpfilefd = -1;										// mark closed
-} // sigTermHandler
-
-
-int main( const int argc, const char * argv[], __attribute__((unused)) const char * const env[] ) {
+int main( const int argc, const char * argv[] ) {
 	#ifdef __DEBUG_H__
-	for ( int i = 0; env[i] != NULL; i += 1 ) {
-		cerr << env[i] << endl;
-	} // for
-
 	for ( int i = 0; i < argc; i += 1 ) {
 		cerr << argv[i] << endl;
@@ -58,55 +31,27 @@
 	#endif // __DEBUG_H__
 
-	signal( SIGINT,  sigTermHandler );					// try to delete temporary file on interrupt
-	signal( SIGTERM, sigTermHandler );
+	int fd = open( argv[argc - 1], O_RDWR );
+	if ( fd < 0 ) { perror( "open" ); exit( EXIT_FAILURE ); };
 
-	// Create a temporary file to store output of the modified assembler.
+	struct stat mystat = {};
+	if ( fstat( fd, &mystat ) ) { perror( "fstat" ); exit( EXIT_FAILURE ); };
+	off_t size = mystat.st_size;
 
-	tmpfilefd = mkstemps( tmpname, sizeof( SUFFIX ) - 1 );
-	if ( tmpfilefd == -1 ) {
-		perror( "CFA Translator error: cpp level, mkstemp" );
-		exit( EXIT_FAILURE );
-	} // if
-	FILE * tmpfilest = fdopen( tmpfilefd, "w" );		// wrap C stream (cannot wrap C++ stream)
+	if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); };
 
-	#ifdef __DEBUG_H__
-	cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl;
-	#endif // __DEBUG_H__
+	char * start = (char *)mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
+	if ( start == (void *)-1 ) { perror( "mmap" ); exit( EXIT_FAILURE ); };
 
-	ifstream in;
-	in.exceptions( ios_base::failbit );					// use exceptions versus return codes
-	try {
-		in.open( argv[argc - 1] );						// assume .s file is last argument
-	} catch( ios_base::failure ) {
-		perror ( "CFA Translator error: cpp failed" );
-		exit( EXIT_FAILURE );
-	} // try
+	char * cursor = strstr( start, ".Ldebug_info0:" );	// debug information ?
+	for ( int i = 0; i < 8; i += 1 ) {					// move N (magic) lines forward
+		cursor = strstr( cursor, "\n" ) + 1;
+	} // for
+	cursor -= 2;										// backup over "c\n" language value
+	if ( *(cursor - 1) != 'x' ) { fprintf( stderr, "invalid C language code\n" ); exit( EXIT_FAILURE ); };
+	memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move text 1 character right
+	*(cursor) = '2';									// replace with CFA language value
+	*(cursor + 1) = '5';
 
-	try {
-		string line;
-		for ( ;; ) {									// loop until end-of-file
-			getline( in, line );
-			line += '\n';
-			fprintf( tmpfilest, "%s", line.c_str() );
-			if ( line == ".Ldebug_info0:\n" ) {			// debug information ?
-				for ( int i = 0; i < 6; i += 1 ) {		// move 6 lines forward
-					getline( in, line );
-					line += '\n';
-					fprintf( tmpfilest, "%s", line.c_str() );
-				} // for
-				getline( in, line );					// ignore C language line
-				fprintf( tmpfilest, "%s", "\t.byte\t0x25\n" ); // replace with CFA language line
-			} // if
-		} // for
-	} catch ( ios_base::failure ) {
-		fclose( tmpfilest );							// flush buffers
-	} // try
-
-	rmfile( argv[argc - 1] );							// remove given file
-
-	if ( rename( tmpname, argv[argc - 1] ) == -1 ) {	// rename temp file to original file
-		perror ( "CFA Translator error: cpp failed" );
-		exit( EXIT_FAILURE );
-	} // if
+	if ( munmap( start, size ) ) { perror( "munmap" ); exit( EXIT_FAILURE ); };
 
 	argv[0] = "as";
