📄 rgl_comp.c
字号:
// rgl_comp.c
// Copyright (c) 2002 Cisco Systems Inc.
// Author: M. A. Ramalho, Cisco Systems, Wall Township, NJ 07719
// Last Revision: May 21, 2002/
//
// The program is called as:
// rg_comp [input_file_name]
//
// This program does a byte-by-byte comparison of two files which should be
// identical:
//
// The first file should have one the extension "mu" (short for mu-law encoded file) or
// the extension "al" (short for A-law encoded file).
//
// The second file should have the extension "muo" (should be identical to the "mu" file)
// or the extension "alo" (should be identical to the "al" file).
//
// The base name for the file comparison must also be the same (e.g., foo.mu and
// foo.muo for the base file name "foo" and a mu-law encodings).
// The A-law or mu-law input file must be specified as the first argument (e.g.
// "foo.mu" or "foo.al"). The second comparison file is assumed to have the same base
// file name with a "muo" or "alo" extension (e.g., foo.muo or foo.alo).
//
// Examples: If the input file to rgl_encode was "foo.mu", then the output file created
// was named "foo.rlm" (a RGL encoded file). When "foo.rgm" is then input to rgl_decode,
// the output file created is "foo.muo". Ideally "foo.mu" and "foo.muo" should be
// identical. Likewise, if the input file to rgl_encode was "foo.al", then the output
// file created was named "foo.rla" (a RGL encoded file). When "foo.rga" is then input
// to rgl_decode, the output file created is "foo.alo". Ideally "foo.al" and "foo.alo"
// should be identical.
//
// This program was developed as an aid to debugging either rgl_encode or
// rgl_decode - whichever one was responsible for creating a non-idential
// output.
//
// The program checks for the presence of both input files (foo.mu and foo.muo
// for mu-law the example above) and terminates if they are not present and available
// for opening. It also checks to make sure that the input file has a "mu" or "al"
// extension. If no input_file_mame is provided, the user is prompted from the
// console to provide one.
//
// The program then compares the two files and stops at the very first point
// of differnece between the two files, if any. If there is a difference in the
// files, the first disagreement is written to the console (in hexadecimal) and the
// number of bytes from the beginning of the input file is also written to the
// console (note: the first byte is byte 1, not zero as in an array). If the files
// are identical (as they should be), this message is printed to the console along
// with the number of bytes compared.
//
//
/************************VOVIDA LICENSE******************************/
//
//The Vovida Software License, Version 1.0
//Copyright (c) 2002 Vovida Networks, Inc. All rights reserved.
//
//Redistribution and use in source and binary forms, with or without
//modification, are permitted provided that the following conditions
//are met:
//
//1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
//2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
//
//3. The names "VOCAL", "Vovida Open Communication Application Library",
// and "Vovida Open Communication Application Library (VOCAL)" must
// not be used to endorse or promote products derived from this
// software without prior written permission. For written
// permission, please contact vocal@vovida.org.
//
//4. Products derived from this software may not be called "VOCAL", nor
// may "VOCAL" appear in their name, without prior written
// permission.
//
//THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
//NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
//NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DAMAGES
//IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
//OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
//(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
//USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
//DAMAGE.
//
/************************VOVIDA LICENSE******************************/
//
//
#include <stdlib.h>
#include <stdio.h>
//
//Some elementary definitions
//
#define false 0
#define true 1
#define error(msg) { fprintf (stderr, "%s\n", msg); exit (1); }
#define max_frame_size 100 /* reads files in 100 byte chunks, except last chunk */
typedef unsigned char uint8;
int main (int argc, char *argv[])
{
char name_buffer [80];
char *input1_file_name;
char input2_file_name [80];
FILE *input1_file, *input2_file;
int i, j, number_read, number_read1, number_read2, mu_or_a;
unsigned long int byte_counter;
uint8 input1_frame[max_frame_size]; /*create buffer for input1_frame array */
uint8 input2_frame[max_frame_size]; /* create buffer for input2_frame array */
// get base file name
switch (argc) {
case 1:
printf(" \n Ramalho G.711 Compare File Utility: mu-law or A-law version \n");
printf(" Copyright (c) 2002 Cisco Systems Inc. \n \n");
printf (" Enter name of G711 input file to compare (with extension): ");
fflush (stdout);
scanf ("%s", name_buffer);
input1_file_name = name_buffer;
break;
case 2:
input1_file_name = argv [1];
break;
case 3:
default:
error ("\n Error: rg711l code presented with unexpectednumber of arguments");
break;
}
// make sure input file has a ".mu" or "al" extension
i = 0;
while ( (input1_file_name [i] != 0) && (input1_file_name [++i] != '.' ) ) i=i;
j = i;
if ( (input1_file_name [++i] == 'a') && (input1_file_name [++i] == 'l') ) {
mu_or_a = false; /* an A-law comparison is required */
}
else if ( (input1_file_name [++j] == 'm') && (input1_file_name [++j] == 'u') ) {
mu_or_a = true; /* a mu-law comparison is required */
}
else {
error ( "\n Error: Input file name must have a \".mu\" or \".al\" extension");
}
// print space to console
(void) fprintf(stdout, "\n");
// check for presense of both files and prepare both files for reading
i = 0;
while (input1_file_name [i] && (input1_file_name [i] != '.')) {
input2_file_name [i] = input1_file_name [i]; i++;
}
input2_file_name [i++] = '.';
if ( mu_or_a == true ) {
input2_file_name [i++] = 'm'; input2_file_name [i++] = 'u';
input2_file_name [i++] = 'o'; input2_file_name [i++] = 0;
}
else {
input2_file_name [i++] = 'a'; input2_file_name [i++] = 'l';
input2_file_name [i++] = 'o'; input2_file_name [i++] = 0;
}
input1_file = fopen (input1_file_name, "rb");
if (input1_file == NULL) error ("can't open \"mu\" or \"al\" input file for reading");
input2_file = fopen (input2_file_name, "rb");
if (input2_file == NULL) error ("can't open \"muo\" or \"alo\" input file for reading");
// write to console
(void) fprintf(stdout, " Comparing files: %s and %s \n", input1_file_name,
input2_file_name);
byte_counter = 1;
do {
// first read "mu" and "muo" files
number_read1 = (int) fread (input1_frame, sizeof(uint8), max_frame_size, input1_file);
number_read2 = (int) fread (input2_frame, sizeof(uint8), max_frame_size, input2_file);
if (number_read1 != number_read2) {
(void) fprintf(stdout, " Warning: \"mu\" and \"muo\" or \"al\" and \"alo\" files have \n");
(void) fprintf(stdout, " different sizes - comparing bytes to limit of shorter file \n \n");
}
if (number_read1 < number_read2) number_read = number_read1;
else number_read = number_read2;
if (number_read > 0 ) {
for(i=0; i< number_read; i++){
if (input1_frame[i] == input2_frame[i]) byte_counter++;
else {
(void) fprintf(stdout, " Difference at byte number: %lu \n", byte_counter);
(void) fprintf(stdout, " \"mu \" file has (decimal) value: %d \n", input1_frame[i]);
(void) fprintf(stdout, " \"muo\" file has (decimal) value: %d \n", input2_frame[i]);
error ("****Program Termination at difference noted above ****\n\n");
}
}
}
} while (number_read > 0);
// print to console
(void) fprintf(stdout, " Data in files is identical\n Total bytes compared: %lu \n",
(byte_counter-1));
// tidy up
fclose(input1_file);
fclose(input2_file);
return(0); /* end of main program */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -