Commit 4e67a9fd authored by rdubner's avatar rdubner

Modify cobst to include VARIABLE_STRING as a global variable

parent 70ca3a43
......@@ -453,14 +453,18 @@ CreateSymc(PARAMETERS &params,
const COB_LABELS &cob_labels,
const VARIABLE_TREE &var_tree)
{
/* This routine puts the COBOL-identifier/C-identifier cross-reference
information into a single string that will be prepended, as a string
variable, to the cprint.py module embedded in the executable as a
.debug_script
/* This routine creates the .sym.c file, which contains a global
variable comprising the cross-reference information, followed
by the magical construction that puts the cprint.py script
into the .debug_script section of the object file created by
compiling .sym.c
*/
// First, the cross-reference string:
string fname = params.cbl_filename.GetFname();
stringstream ss;
ss << "VARIABLE_STRING=\"";
// Do the line/address information from the .text in the minimal form
// used by cprint.py to figure out which program a trap has occurred in.
......@@ -501,13 +505,58 @@ CreateSymc(PARAMETERS &params,
ss << ZeroIsNull(cs.GetAttrScale()) << "|" ;
ss << ZeroIsNull(cs.GetAttrFlags()) << "~";
}
ss << "\"";
ss << "\n";
// At this point, ss contains a potentially huge literal string.
// We're going to bust it up into smaller pieces.
string s = ss.str();
ss.str("");
ss << "char VARIABLE_STRING_" << Upper(fname) << "[]=" << endl;
const int SEGMENT_LENGTH = 78;
while(s.length() > SEGMENT_LENGTH) {
ss << "\"" << s.substr(0,SEGMENT_LENGTH) << "\"" << endl;
s = s.substr(SEGMENT_LENGTH);
}
if( s.length() ) {
ss << "\"" << s << "\"" << endl;
}
ss << ";" << endl << endl;
params.symc << ss.str();
// Copy over the Python script
ss.str("");
// Copy over the Python script, line by line, getting rid of comments
char *py = new char[___python_cprint_py_len+1];
memcpy(py, ___python_cprint_py,___python_cprint_py_len);
py[___python_cprint_py_len] = '\0';
py[0] = '\0';
size_t index=0;
while(index < ___python_cprint_py_len) {
string seg;
while(index < ___python_cprint_py_len) {
char ch = ___python_cprint_py[index++];
if(ch EQ '\n') {
break;
}
seg += ch;
}
size_t nfound_comment = seg.find("#");
if( nfound_comment != string::npos ) {
// There is a pound sign, which is the Python comment signal
size_t nfound_quote = seg.find_first_of("'\"");
if( nfound_quote > nfound_comment ) {
seg = seg.substr(0,nfound_comment);
seg = RTrim(seg);
}
}
if( !Trim(seg).empty() ) {
seg += '\n';
size_t t = strlen(py);
strcpy(py+t,seg.c_str());
}
}
// memcpy(py, ___python_cprint_py,___python_cprint_py_len);
// py[___python_cprint_py_len] = '\0';
ss << py;
ss << "\n";
......@@ -533,7 +582,7 @@ CreateSymc(PARAMETERS &params,
);
*/
string s = ss.str();
s = ss.str();
params.symc << "asm(" << endl;
params.symc << "\".pushsection \\\".debug_gdb_scripts\\\", \\\"MS\\\",@progbits,1\\n\"" << endl;
......
......@@ -33,7 +33,7 @@
#include <string>
#include <fstream>
#define VERSION "1.1.3"
#define VERSION "1.3.1"
class FILENAME
{
......
......@@ -48,8 +48,23 @@ string Trim(const string &s)
retval = retval.substr(0,nfound);
}
nfound = retval.find_first_not_of(WHITESPACE);
if(nfound != string::npos && nfound > 0) {
if(nfound != string::npos) {
retval = retval.substr(nfound);
} else {
retval = "";
}
return retval;
}
string RTrim(const string &s)
{
PROFILER;
string retval=s;
static const string WHITESPACE = " \t\r\n\f";
size_t nfound = retval.find_last_not_of(WHITESPACE);
if(nfound != string::npos) {
nfound += 1;
retval = retval.substr(0,nfound);
}
return retval;
}
......@@ -108,4 +123,13 @@ string Replace(const string &s,const char was, const char is)
retval += ch;
}
return retval;
}
string Upper(const string &s)
{
string retval;
for(char ch : s) {
retval += toupper(ch);
}
return retval;
}
\ No newline at end of file
......@@ -49,6 +49,8 @@ typedef int64_t LONGLONG;
typedef uint64_t ULONGLONG;
std::string Trim(const std::string &s);
std::string RTrim(const std::string &s);
std::string StripQuotes(const std::string &s);
std::vector<std::string>Split(const std::string &s,const std::string &delimiters);
std::string Replace(const std::string &s,const char was, const char is);
std::string Upper(const std::string&s);
......@@ -417,7 +417,7 @@ void VARIABLE_TREE::ReadFromFile(std::ifstream &ifs)
it = find(tokens.begin(),tokens.end(),"OCCURS");
if( it != tokens.end() ) {
// 'it' points to OCCURS:
auto index = it - tokens.begin();
size_t index = it - tokens.begin();
// Get rid of any comma at the end of index-1:
size_t n = tokens[index-1].find_last_of(',');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment