projects
/
h316.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
*** empty log message ***
[h316.git]
/
pc-tools
/
ldc2
/
src
/
main.cpp
diff --git
a/pc-tools/ldc2/src/main.cpp
b/pc-tools/ldc2/src/main.cpp
index eabe7fb8cca7d2c0ea78dba908910408c07368e8..35f4ce632b4d10636a6764783c6993819f914a6c 100644
(file)
--- a/
pc-tools/ldc2/src/main.cpp
+++ b/
pc-tools/ldc2/src/main.cpp
@@
-2,25
+2,29
@@
*
* LDC2 source code
*
*
* LDC2 source code
*
- * $Date: 2007/03/26 0
1:00:40
$
+ * $Date: 2007/03/26 0
3:20:31
$
* $Author: hachti $
*
* $Log: main.cpp,v $
* $Author: hachti $
*
* $Log: main.cpp,v $
- * Revision 2.0 2007/03/26 01:00:40 hachti
+ * Revision 2.2 2007/03/26 03:20:31 hachti
+ * *** empty log message ***
+ *
+ * Revision 2.1 2007-03-26 01:15:21 hachti
+ * *** empty log message ***
+ *
+ * Revision 2.0 2007-03-26 01:00:40 hachti
* *** empty log message ***
*
*
******************************************************************************/
* *** empty log message ***
*
*
******************************************************************************/
-/* ldc2 preliminary main program */
-
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <vector>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <vector>
#include <string>
-
+
#include "config.hh"
#include "tool.hh"
#include "config.hh"
#include "tool.hh"
@@
-43,21
+47,29
@@
using namespace std;
/******************************************************************************/
/******************************************************************************/
-static FILE * stdwarn; //! Suppressable warning output file pointer.
-static vector<tape_block*> tape;
//! Represents t
he whole tape contents.
+static FILE * stdwarn;
//! Suppressable warning output file pointer.
+static vector<tape_block*> tape;
//! T
he whole tape contents.
static vector<vector<tape_block*> > objects; //! Tape content in objects.
static vector<vector<tape_block*> > objects; //! Tape content in objects.
-static int errors
=0;
-static int warnings=
0;
-static int errcode
=0; //! Variable for error codes
.
+static int errors
= 0; //! Global error counter.
+static int warnings=
0; //! Global warning counter.
+static int errcode
= 0; //! Error code for error exit routine
.
+/******************************************************************************/
+/*!
+ *\brief Error exit routine.
+ *
+ * This routine tests the global error counter and terminates the program
+ * if necessary.
+ */
void exit_on_error(){
if (errors){
fprintf(stderr,"Failed. (%i)\n",errcode);
exit(errcode);
}
}
void exit_on_error(){
if (errors){
fprintf(stderr,"Failed. (%i)\n",errcode);
exit(errcode);
}
}
+
/******************************************************************************/
/*!
/******************************************************************************/
/*!
@@
-85,12
+97,13
@@
void read_tape(){
while(read_ahead){
while(read_ahead){
- bool err_checksum=false;
- bool err_integrity=false;
+ bool err_checksum=false;
//! Checksum error flag.
+ bool err_integrity=false;
//! Integrity error flag.
- bool warning=false;
- bool error=false;
+ bool warning=false;
//! Warning flag.
+ bool error=false;
//! Error flag.
+ // Try to generate block
try{
block=tape_block::gen_from_fd(in_fd);
}
try{
block=tape_block::gen_from_fd(in_fd);
}
@@
-102,7
+115,8
@@
void read_tape(){
catch(tape_block::io_error_exception){
if (in_fd){
catch(tape_block::io_error_exception){
if (in_fd){
- fprintf(stderr,"Error: Could not read from \"%s\"!\n",cfg_infile.c_str());
+ fprintf(stderr,"Error: Could not read from \"%s\"!\n",
+ cfg_infile.c_str());
} else {
fprintf(stderr,"Error: Could not read from stdin!\n");
}
} else {
fprintf(stderr,"Error: Could not read from stdin!\n");
}
@@
-201,8
+215,11
@@
void read_tape(){
/******************************************************************************/
/******************************************************************************/
+/*!
+ *\brief Do integrity test and object or block dumps.
+ */
void process_tape(){
void process_tape(){
- if (cfg_verbose) fprintf(stdwarn,"
Processing Tape
.\n");
+ if (cfg_verbose) fprintf(stdwarn,"
\nProcessing Data
.\n");
bool in_object=false;
char filename[100];
bool in_object=false;
char filename[100];
@@
-220,7
+237,8
@@
void process_tape(){
objname="EOT";
if (in_object){
if (cfg_ignore_object_integrity_errors){
objname="EOT";
if (in_object){
if (cfg_ignore_object_integrity_errors){
- fprintf(stdwarn,"Warning: Object integrity error!\n");
+ fprintf(stdwarn,"Warning: Object integrity error!\
+ (Object no %i, Block %i unexpected)\n",obj_no,i);
warnings++;
} else {
fprintf(stderr,"Error: Object integrity error!\
warnings++;
} else {
fprintf(stderr,"Error: Object integrity error!\
@@
-231,8
+249,8
@@
void process_tape(){
}
}
}
}
}
}
-
if (!in_object){ // object begin
if (!in_object){ // object begin
+
obj_no++;
obj_start_block=i;
obj_no++;
obj_start_block=i;
@@
-246,7
+264,6
@@
void process_tape(){
objname=objname.substr(0,objname.find_last_not_of(" ")+1);
unknown_count--;
break;
objname=objname.substr(0,objname.find_last_not_of(" ")+1);
unknown_count--;
break;
-
}
}
}
}
@@
-256,27
+273,33
@@
void process_tape(){
// Open file for split objects
if (cfg_split_objects && (block->get_type()!=tape_block::TBT_EOT)){
// Open file for split objects
if (cfg_split_objects && (block->get_type()!=tape_block::TBT_EOT)){
- if (objname=="UNKNOWN")snprintf(filename,99,"UNKNOWN%02i.obj",unknown_count);
+ if (objname=="UNKNOWN")snprintf(filename,99,"UNKNOWN%02i.obj",
+ unknown_count);
else snprintf(filename,99,"%s.obj",objname.c_str());
if (fd>-1) close (fd);
else snprintf(filename,99,"%s.obj",objname.c_str());
if (fd>-1) close (fd);
+ if (cfg_verbose) fprintf(stdwarn,"Writing file: %s\n",filename);
fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666);
fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666);
- printf("opening \"%s\"\n",filename);
if (fd<0){
fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",
filename);
if (fd<0){
fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",
filename);
- exit (1);
+ errors++;
+ errcode=1;
+ return;
}
}
// Open file for split objects numbered
snprintf(filename_numbered,99,"%03i0-%s.obj",obj_no,objname.c_str());
if (cfg_split_objects_numbered){
}
}
// Open file for split objects numbered
snprintf(filename_numbered,99,"%03i0-%s.obj",obj_no,objname.c_str());
if (cfg_split_objects_numbered){
- if (fd_numbered>-1) close (fd_numbered);
+ close (fd_numbered);
+ if (cfg_verbose) fprintf(stdwarn,"Writing file: %s\n",filename_numbered);
fd_numbered=open(filename_numbered,O_WRONLY|O_CREAT|O_TRUNC,0666);
if (fd_numbered<0){
fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",
filename_numbered);
fd_numbered=open(filename_numbered,O_WRONLY|O_CREAT|O_TRUNC,0666);
if (fd_numbered<0){
fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",
filename_numbered);
- exit (1);
+ errors++;
+ errcode=1;
+ return;
}
}
in_object=true;
}
}
in_object=true;
@@
-291,7
+314,9
@@
void process_tape(){
catch (tape_block::io_error_exception e){
fprintf(stderr,"Error: could write to file \"%s\"!\n",
filename);
catch (tape_block::io_error_exception e){
fprintf(stderr,"Error: could write to file \"%s\"!\n",
filename);
- exit (1);
+ errors++;
+ errcode=1;
+ return;
}
} // if (cfg_split_objects)
}
} // if (cfg_split_objects)
@@
-303,19
+328,27
@@
void process_tape(){
catch (tape_block::io_error_exception e){
fprintf(stderr,"Error: could write to file \"%s\"!\n",
filename_numbered);
catch (tape_block::io_error_exception e){
fprintf(stderr,"Error: could write to file \"%s\"!\n",
filename_numbered);
- exit (1);
+ errors++;
+ errcode=1;
+ return;
}
} // if (cfg_split_objects_numbered)
// Output individual block file if desired
if (cfg_split_blocks){
char fname[100];
}
} // if (cfg_split_objects_numbered)
// Output individual block file if desired
if (cfg_split_blocks){
char fname[100];
- snprintf(fname,99,"%03i0-%s-%03i.block",obj_no,objname.c_str(),i-obj_start_block);
+ snprintf(fname,99,"%03i0-%s-%03i.block",obj_no,objname.c_str(),
+ i-obj_start_block);
+ if (cfg_verbose) fprintf(stdwarn,"Writing file: %s\n",fname);
int fd_block=open(fname,O_WRONLY|O_TRUNC|O_CREAT,0666);
if (fd_block<0){
fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",
fname);
int fd_block=open(fname,O_WRONLY|O_TRUNC|O_CREAT,0666);
if (fd_block<0){
fprintf(stderr,"Error: could not open file \"%s\" for writing!\n",
fname);
- exit (1);
+ errors++;
+ errcode=1;
+ close(fd);
+ close(fd_numbered);
+ return;
}
try{
block->dump_to_fd(fd_block);
}
try{
block->dump_to_fd(fd_block);
@@
-323,38
+356,48
@@
void process_tape(){
catch (tape_block::io_error_exception e){
fprintf(stderr,"Error: could write to file \"%s\"!\n",
fname);
catch (tape_block::io_error_exception e){
fprintf(stderr,"Error: could write to file \"%s\"!\n",
fname);
- exit (1);
+ errors++;
+ errcode=1;
+ close(fd);
+ close(fd_numbered);
+ return;
}
close(fd_block);
}
if (block->is_endblock()||(block->get_type()==tape_block::TBT_EOT)) {
in_object=false;
}
close(fd_block);
}
if (block->is_endblock()||(block->get_type()==tape_block::TBT_EOT)) {
in_object=false;
-
if (fd!=-1)
close(fd);
-
if (fd_numbered!=-1)
close(fd_numbered);
+ close(fd);
+ close(fd_numbered);
}
} // for (...)
if (in_object){
if (cfg_ignore_object_integrity_errors){
}
} // for (...)
if (in_object){
if (cfg_ignore_object_integrity_errors){
- fprintf(stdwarn,"Warning: Object integrity error!\n");
+ fprintf(stdwarn,"Warning: Object integrity error!
Last object incomplete!
\n");
warnings++;
} else {
warnings++;
} else {
- fprintf(stdwarn,"Error: Object integrity error!\n");
+ fprintf(stdwarn,"Error: Object integrity error!
Last Object incomplete!
\n");
errors++;
errcode=6;
errors++;
errcode=6;
+ if (fd!=-1) close(fd);
+ if (fd_numbered!=-1) close(fd_numbered);
return;
}
}
return;
}
}
-
-
} // process_tape()
} // process_tape()
-void process_called_imports(){
+/******************************************************************************/
+/*!
+ *\brief Everything that has to do with symbol listing.
+ */
+void process_symbols(){
vector<string>exported;
vector<string>called;
vector <string>unsatisfied;
vector<string>exported;
vector<string>called;
vector <string>unsatisfied;
-
+
+ if (cfg_verbose) fprintf(stdwarn,"\nProcessing Symbols.\n");
+
for (unsigned int i=0; i<tape.size();i++){
merge_vector_unique(exported,tape[i]->get_exported_symbols());
merge_vector_unique(called,tape[i]->get_called_symbols());
for (unsigned int i=0; i<tape.size();i++){
merge_vector_unique(exported,tape[i]->get_exported_symbols());
merge_vector_unique(called,tape[i]->get_called_symbols());
@@
-394,11
+437,12
@@
void process_called_imports(){
dump_vector_fp(unsatisfied,outp);
}
dump_vector_fp(unsatisfied,outp);
}
-}
+}
// process_symbols()
/******************************************************************************/
/*!
*\brief The main routine.
/******************************************************************************/
/*!
*\brief The main routine.
+ *
*/
int main(int argc, char ** args){
*/
int main(int argc, char ** args){
@@
-421,15
+465,22
@@
int main(int argc, char ** args){
process_tape();
exit_on_error();
process_tape();
exit_on_error();
- process_
called_import
s();
+ process_
symbol
s();
exit_on_error();
exit_on_error();
-
-
+
if (warnings>0){
fprintf(stdwarn,"Warnings:%i\n",warnings);
return 99;
}
if (warnings>0){
fprintf(stdwarn,"Warnings:%i\n",warnings);
return 99;
}
- if (cfg_verbose) fprintf(stdwarn,"Success.\n");
+ if (cfg_verbose) fprintf(stdwarn,"
\n
Success.\n");
return 0;
return 0;
+
+ /*
+ * All over this program, no memory is freed. This is not necessary because
+ * everything is allocated once and that's it.
+ * The classes support proper freeing of their internal buffers.
+ */
+
} // main()
} // main()
+/******************************************************************************/