/****************************************************************** * cvarc.c * * * * This program converts Y2K format fpfit messages to * * pre-Y2K format. * * * * This is a filter program, ie the input mec message is read * * from stdin, and the output mec message is written to stdout. * * * * If the length of an input line exceeds 255 characters, the * * program will print a message to stderr and then exit. * * * * Otherwise, the program rearranges the fields of each line * * without checking for errors. * * * * The only difference between the Y2K format and the pre-Y2K * * format is that the Y2K format has the century in the first * * 2 columns, and therefore the line is 2 characters longer. * * * * Written by Doug Neuhauser, NCEDC, modelled after cvarc.c * * * ******************************************************************/ #include #include #include #define MAXCHR 256 /* Max number of characters per line */ void cvmec( char *line_in, char *line_out ) { int len = strlen( line_in ); char firstChar = line_in[0]; if (len != 141) { fprintf( stderr, "Mec line wrong length - expected 141, found %d.\n", len ); exit( -1 ); } memcpy( line_out, line_in+2, len-2 ); line_out[len-2] = '\0'; return; } /********************************************************************** * The following is a filter program that calls the cvmec function. * **********************************************************************/ int main( int argc, char *argv[] ) { char line_in[MAXCHR]; /* Unconverted line */ char line_out[MAXCHR]; /* Converted line */ /* Read one line from the mec message into line_in ***********************************************/ while ( fgets( line_in, MAXCHR, stdin ) != NULL ) { int len = strlen( line_in ); /* Make sure we didn't overflow the input line *******************************************/ if ( (len == MAXCHR-1) && (line_in[len-1] != '\n') ) { fprintf( stderr, "Input line length exceeds max value of %d. Exiting.\n", MAXCHR-1 ); return -1; } /* Remove the trailing newline character *************************************/ line_in[len-1] = '\0'; /* Convert the line to pre-Y2K format **********************************/ cvmec( line_in, line_out ); /* Write the convert line to standard output *****************************************/ puts( line_out ); } return 0; }