, .
, script script .
script 'first.myint' 'myinterpreter', C. .
#!/usr/local/bin/myinterpreter
% 1
2 xxxxxxxxxxx
333
444
% the last comment
:
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFERSIZE 256
int
main ( int argc, char *argv[] )
{
char comment_leader = '%';
char *line = NULL;
size_t len = 0;
ssize_t read;
FILE *input;
char *input_file_name = argv[1];
input = fopen( input_file_name, "r" );
if ( input == NULL ) {
fprintf ( stderr, "couldn't open file '%s'; %s\n",
input_file_name, strerror(errno) );
exit (EXIT_FAILURE);
}
while ((read = getline(&line, &len, input)) != -1) {
if ( line[0] != comment_leader ) {
printf( "%s", line );
}
else {
printf ( "Skipped a comment!\n" );
}
}
free(line);
if( fclose(input) == EOF ) {
fprintf ( stderr, "couldn't close file '%s'; %s\n",
input_file_name, strerror(errno) );
exit (EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
script ( ) :
...~> ./first.myint
Skipped a comment!
2 xxxxxxxxxxx
333
444
Skipped a comment!