[debug]what does the following debug information mean
the information is made by gcc
main.o(.text+0x0): In function `CommonError::CommonError[not-in-charge](int)': /storage/tempproject/project/CommonError.h:20: multiple definition of`CommonError::CommonError[not-in-charge](int)' ~~~~~~~~~ StrView.o(.text+0x0):/storage/tempproject/project/CommonError.h:20: first defined here main.o(.text+0x126): In function `CommonError::CommonError[in-charge](int)': /storage/tempproject/project/CommonError.h:20: multiple definition of`CommonError::CommonError[in-charge](int)' ~~~~~~~~ what is the difference between [in-charge] and [not-in-charge] StrView.o(.text+0x126):/storage/tempproject/project/CommonError.h:20: first defined here |
some more surprising debug information:
i write a class ,compile it with gcc , and get some surprising errors. cd /storage/tempproject/project/ g++ -ggdb3 -c FileList.cpp /usr/include/c++/3.2.2/bits/ios_base.h: In copy constructor `std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)': /usr/include/c++/3.2.2/bits/stl_construct.h:78: instantiated from `void std::_Construct(_T1*, const _T2&) [with _T1 = SunMemString, _T2 = SunMemString]' /usr/include/c++/3.2.2/bits/stl_list.h:328: instantiated from `std::_List_node<_Tp>* std::list<_Tp, _Alloc>::_M_create_node(const _Tp&) [with _Tp = SunMemString, _Alloc = std::allocator<SunMemString>]' /usr/include/c++/3.2.2/bits/stl_list.h:430: instantiated from `std::_List_iterator<_Tp, _Tp&, _Tp*> std::list<_Tp, _Alloc>::insert(std::_List_iterator<_Tp, _Tp&, _Tp*>, const _Tp&) [with _Tp = SunMemString, _Alloc = std::allocator<SunMemString>]' /usr/include/c++/3.2.2/bits/stl_list.h:479: instantiated from `void std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = SunMemString, _Alloc = std::allocator<SunMemString>]' FileList.cpp:9: instantiated from here ~~~~~~~~~~~~~~the 8th and 9th lines in my program are: SunMemString file1(PathStr); AllFile.push_back(file1); SunMemString is my class and list<SunMemString> AllFile; what does information mean? /usr/include/c++/3.2.2/bits/ios_base.h:424: `std::ios_base::ios_base(const std::ios_base&)' is private /usr/include/c++/3.2.2/bits/stl_construct.h:78: within this context /usr/include/c++/3.2.2/streambuf: In copy constructor `std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)': /usr/include/c++/3.2.2/streambuf:479: `std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]' is private /usr/include/c++/3.2.2/bits/stl_construct.h:78: within this context Compilation exited abnormally with code 1 at Fri May 21 16:06:50 |
Hi icoming!
Could you reveal your source or even better create a minimal example to be able to reconstruct the compile-failure of your post #1? bluie |
ok!
#include"All.h" #include"SunMemstring.h" class FileList { list<SunMemString> AllFile; list<SunMemString>::iterator pos; public: FileList(char *); FileList(){pos=AllFile.begin();} ~FileList(){free(PathStr);} bool AddFile(const char *); bool DeleteFile(const char *); }; FileList::FileList(char *filename) { GetPathStr(); SunMemString file1(PathStr); AllFile.push_back(file1);//if i make this line and another line which has 'push_back' comments ,there is no error pos=AllFile.begin(); } bool FileList::AddFile(const char *filename) { GetPathStr(); SunMemString file1(PathStr); AllFile.push_back(file1); pos=AllFile.end(); advance(pos , -1); return true; } do you want me to reveal the class SunMemString? |
Hm. Can't find any sign of CommonError in the posted code.
So please reveal the parts where CommonError occurs and also reveal the includes. StrView.h and/or StrView.cpp and main.cpp are very suspicious to use CommonError. |
oh,i'm sorry the first two error informations posted are made when i compiled two programs.
so there is no relation between two error informations. in the first error information,what i want to know is what does [not-in-charge] in 'CommonError::CommonError[not-in-charge](int)' mean. and in the second error information is what really puzzled me,and the example is posted for the second error.but the example is not good. so i want post all my program here.my program is an editor which simulate 'vi' |
All.h:
#ifndef __ALL_H__ #define __ALL_H__ #include<iostream> #include<string> #include<sstream> #include<fstream> #include<list> using namespace std; #include<curses.h> #include<termio.h> #include<sys/ioctl.h> #include<signal.h> #include<errno.h> #include<string.h> #include<limits.h> #include<unistd.h> #include"CommonError.h" #define KEY_ESC 27 #define KEY_DELETE 263 const int MAXCOMMANDSIZE=100; const int EDITMODE=0; const int COMMANDMODE=1; const int UP=1; const int DOWN=0; extern int errno; struct winsize GetWinSize(); struct Location { int x; int y; }; class FatalError { string str; public: FatalError(char *ch):str(ch){} string GetStr(){return str;} }; #endif |
CommonError.h:
#ifndef __COMMONERROR_H__ #define __COMMONERROR_H__ class CommonError { public: static const int NOPATHNAME=0; static const int UNDERBUF=1; static const int OVERBUF=2; static const int MAXERROR=10; CommonError(int i) { error=i; ErrorStr[0]="can't open file because can't get pathname"; ErrorStr[1]="the index get under buffer"; ErrorStr[2]="the index get over buffer"; } CommonError(){} string GetStr(){return ErrorStr[error];} private: string ErrorStr[MAXERROR]; int error; }; #endif |
Control.cpp:
#include"Control.h" #include"StrView.h" #include"All.h" void Control::EditFile() { for(;;) { int ch=getch(); if(Files.EditFile(ch) == 0) break; } Mode=COMMANDMODE; } bool Control::ReadStr() { for(;;) { int ch=getch(); if(ch == KEY_ESC) break; else if(ch == 10) return true; else if(ch == KEY_LEFT) FirstView.KeyLeft(Command); else if(ch == KEY_RIGHT) FirstView.KeyRight(Command); else if(ch == KEY_UP) History.KeyDownUp(Command , FirstView , UP); else if(ch == KEY_DOWN) History.KeyDownUp(Command , FirstView , DOWN); else { Command.Insert((char)ch); FirstView.GetLocat(); FirstView.DisplayCommand(Command); FirstView.KeyRightAuto(Command); History.ReplaceEnd(Command.GetBuffer()); } } return false; } void Control::Find(istringstream &is) { string str; string parament; for(;;) { is>>str; if(!is) { FirstView.DisplayCommand("there is too few parament"); return; } else if(str[0] == '\"') { parament+=str; if(parament[parament.size()-1] == '\"') { parament.erase(parament.size()-1 , 1); is>>str; if(is) { FirstView.DisplayCommand("there are too many parament"); return; } //call the function of StrMem } else continue; } else { is>>str; if(is) { FirstView.DisplayCommand("there are too many parament"); return; } else ; //call the function of StrMem } }//for } void Control::CommSet(istringstream &is) { string str; is>>str; if(is) { } else FirstView.DisplayCommand("there are too few parament"); } void Control::CommOpen(istringstream &is) { } void Control::TranComm(string strcommand) { strcommand.erase(0 , 1);//remove the ':' istringstream is(strcommand); string str; is>>str; if(str == "find") Find(is); else if(str == "set") CommSet(is); else if(str == "open") CommOpen(is); else if(str == "replace") { } else if(str == "replace all") { } else if(str == "close") { } else if(str == "split") { } else if(str == "showbuf") { } else if(str == "changbuf") { } else if(str == "q") { NowExit=true; return; } else if(str == "x") { } else { FirstView.DisplayCommand("there is no such a commmand"); } } void Control::ReadCommand() { int ch; bool inputcomm=false; for(;!NowExit;) { bool esc_press_twice=false; ch=getch(); switch (ch) { case 'i': { FirstView.ClearComLine(); FirstView.DisplayCommand("insert"); Mode=EDITMODE;//change to edit mode return; } case ':': { FirstView.ClearComLine(); Command.Insert(':'); FirstView.DisplayCommand(Command); FirstView.GetLocat(); inputcomm=true; esc_press_twice=false; break; } case KEY_ESC: { KeyEsc: if(esc_press_twice == false && inputcomm) { Command.Clear(); FirstView.ClearComLine(); move(EditLocat.x , EditLocat.y); esc_press_twice=true; } else beep(); break; }//case KEY_ESC default: { if(inputcomm) { echochar(ch); Command.Insert((char)ch); if(ReadStr()) { History.KeyEnter(Command.GetBuffer()); TranComm(Command.GetBuffer()); } else goto KeyEsc; Command.Clear(); inputcomm=false; } else beep(); } }//switch }//for } |
Control.h
#ifndef __CONTROL_H__ #define __CONTROL_H__ #include"All.h" #include"StrView.h" #include"HistoryCommand.h" #include"SunMemstring.h" #include"FileList.h" extern StrView FirstView; class Control { MemString Command; HistoryCommand History; FileList Files; /* ?? */ string FindRecord; int Mode; bool NowExit; struct Location EditLocat;//remember the edit location of guangbiao public: Control() { Mode=COMMANDMODE;//when it's command mode ,Mode is true.or Mode is false NowExit=false; } Control(char *filename) { try { SunMemString file1(filename); } catch(int error) { } } ~Control(){} void SetEditLocat(); bool GetNowExit(){return NowExit;} int GetMode(); void ReadCode(); void ReadCommand(); void MyMain(); void EditFile(); void TranComm(string); bool ReadStr(); void Find(istringstream &);//?????? void CommSet(istringstream &); void CommOpen(istringstream &); void Replace();//?? void SetIfAuto();//?????????? void OpenFile();//????. void SaveFile();//???? void Help();//?? void ChangeFile();//???? }; inline int Control::GetMode() { return Mode; } inline void Control::SetEditLocat() { EditLocat=FirstView.GetLocat(); } #endif |
FileList.cpp
#include"FileList.h" #include"StrView.h" extern StrView FirstView; FileList::FileList(char *filename) { try { GetPathStr(); SunMemString file1(PathStr); AllFile.push_back(file1); } catch(int) { char *errorstr=strerror(errno); FirstView.DisplayCommand(errorstr); } #ifdef PATH_MAX PathStrLen=PATH_MAX; #else PathStrLen=1024; #endif PathStr=(char *)malloc(sizeof(char)*PathStrLen); if(PathStr == NULL) { throw FatalError("there isn't enough memory space\n"); } pos=AllFile.begin(); } int FileList::TestFileName(const char *filename) const { if(filename[0] == '/') return WHOLEPATH; else { while(filename != 0) if(*filename == '/') return RELATIVEPATH; return ONLYFILE; } } bool FileList::HaveFile(const char *testfilename) { temp=AllFile.begin(); string filename; ToWhole(testfilename); //get the whole path of testfilename while(temp != AllFile.end()) { filename=temp->GetFileName(); if(filename == testfilename) return true; } return false; } bool FileList::GetPathStr() { for(;;) { errno=0; if(getcwd(PathStr , PathStrLen) == NULL) { if(errno == ERANGE) { PathStr=(char *)realloc(PathStr , PathStrLen*8); if(PathStr == NULL) throw FatalError("there isn't enough memory space\n"); PathStrLen*=8; continue; } else throw CommonError(0); } else return true; } } void FileList::ToWhole(const char *filename) { int sign=TestFileName(filename); if(sign == WHOLEPATH) return; else { GetPathStr(); int len=strlen(filename)+strlen(PathStr)+1; if(PathStrLen < len) { PathStr=(char *)realloc(PathStr , len); PathStrLen=len; } if(PathStr == NULL) throw FatalError("there isn't enough memory space\n"); if(sign == RELATIVEPATH) { if(filename[0] == '.' && filename[1] == '/') strcat(PathStr , filename+2); else if(filename[0] == '.' && filename[1] == '.' && filename[2] == '/') strcat(PathStr , filename+3); else strcat(PathStr , filename); } else strcat(PathStr , filename); } } bool FileList::AddFile(const char *filename) { try { GetPathStr(); SunMemString file1(PathStr); AllFile.push_back(file1); pos=AllFile.end(); advance(pos , -1); return true; } catch(int) { char *errorstr=strerror(errno); FirstView.DisplayCommand(errorstr); return false; } } bool FileList::DeleteFile(const char *filename) { if(HaveFile(filename)) { bool samefile=false; if(pos == temp) samefile=true; AllFile.erase(temp); if(samefile) pos=AllFile.begin(); return true; } else return false; } int FileList::EditFile(const int ch) { switch (ch) { /* case KEY_DELETE: FirstView.KeyDelete(*pos); break; */ case KEY_ESC: return 0; case 10: FirstView.KeyEnter(*pos); break; case KEY_LEFT: FirstView.KeyLeft(*pos); break; case KEY_RIGHT: FirstView.KeyRight(*pos); break; case KEY_UP: FirstView.KeyUp(*pos); break; case KEY_DOWN: FirstView.KeyDown(*pos); break; case KEY_BACKSPACE: FirstView.KeyBackSpace(*pos); break; case KEY_PPAGE: FirstView.KeyPageUp(*pos); break; case KEY_NPAGE: FirstView.KeyPageUp(*pos); break; case KEY_HOME: FirstView.KeyHome(*pos); break; case KEY_END: FirstView.KeyEnd(*pos); break; case KEY_IC: FirstView.KeyInsert(); break; default: { if(ch >= 0 && ch <= 255) { pos->Insert(ch); FirstView.GetLocat(); FirstView.DisplayCommand(*pos); FirstView.KeyRightAuto(*pos); } else beep(); } } return 1; } |
FileList.h
#ifndef __FILELIST_H__ #define __FILELIST_H__ #include"All.h" #include"SunMemstring.h" class FileList { static const int WHOLEPATH=1; static const int RELATIVEPATH=2; static const int ONLYFILE=4; list<SunMemString> AllFile; list<SunMemString>::iterator pos; list<SunMemString>::iterator temp; char *PathStr; int PathStrLen; bool HaveFile(const char *); void ToWhole(const char *); bool GetPathStr(); int TestFileName(const char *filename) const; public: FileList(char *); FileList(){pos=AllFile.begin();} ~FileList(){free(PathStr);} bool AddFile(const char *); bool DeleteFile(const char *); bool IsEmpty(); int TestFileName(char *); int EditFile(const int); }; inline bool FileList::IsEmpty() { if(AllFile.size() == 0) return true; else return false; } #endif |
HistoryCommand.h:
#ifndef __HISTORYCOMMAND_H__ #define __HISTORYCOMMAND_H__ #include"All.h" #include"Memstring.h" class HistoryCommand { static const int MAXLEN=100; list<string> HisCom; list<string>::iterator pos; public: HistoryCommand() { HisCom.push_back(" "); pos=HisCom.begin(); } void ReplaceEnd(const string &str); //void PushHis(const string &str); void KeyDownUp(MemString &Command , StrView &view , int sign); void KeyEnter(const string &str); }; inline void HistoryCommand::ReplaceEnd(const string &str) { HisCom.pop_back(); HisCom.push_back(str); } /* inline void HistoryCommand::PushHis(const string &str) { if(HisCom.size() < HisComLen) { HisCom.push_back(str); HisComLen++; } else { HisCom.pop_front(); HisCom.push_back(str); } } */ inline void HistoryCommand::KeyDownUp(MemString &Command , StrView &view , int sign) { if(sign == DOWN) { if(pos == HisCom.end()) { beep(); return; } pos++; if(pos == HisCom.end()) { beep(); return; } } else { if(pos == HisCom.begin()) { beep(); return; } pos--; } Command.Clear(); Command.Insert(*pos); view.DisplayCommand(Command); struct winsize WinSize=view.GetWinSize(); int len=Command.GetLength()%WinSize.ws_col; move(WinSize.ws_row-1 , len); } inline void HistoryCommand::KeyEnter(const string &str) { if(HisCom.size() == MAXLEN) HisCom.pop_front(); HisCom.push_back(" "); pos=HisCom.end(); advance(pos , -1); } #endif |
main.cpp:
#include "All.h" #include "Control.h" #include "StrView.h" struct winsize GetWinSize() { struct winsize size; if(ioctl(1 , TIOCGWINSZ , (char *)&size) < 0) cout<<"TIOCGWINSZ error"; return size; } StrView FirstView; int main (int argc , char *argv) { try { Control control; //signal(SIGWINCH , FirstView.SigWinch); //signal(SIGALRM , control.SigAlrm); for(;!control.GetNowExit();) { control.SetEditLocat(); if(control.GetMode() == COMMANDMODE) control.ReadCommand(); else control.EditFile(); } } catch(FatalError error) { cout<<error.GetStr(); } } |
Memstring.cpp:
#include"Memstring.h" #include"StrView.h" extern StrView FirstView; string& MemString::CopyString(int i,int j) { char temp[BUFFERSIZE]; TempBuffer.copy(temp,i,j-i); int n; for(n=0;n<j-i;n++) { stemp+=temp[n]; } return stemp; } MemString::MemString() { Locate=0; LineLen=0; OneLine=NULL; StartLocate=0; StartPage=0; } MemString::MemString(const char* s):TempBuffer(s) { Locate=0; LineLen=0; OneLine=NULL; StartLocate=0; StartPage=0; } char* MemString::GetLine(const int ScreenWidth) { if(ScreenWidth > LineLen) { OneLine=(char *)realloc(OneLine , (ScreenWidth+1)*sizeof(char));//haven't consider about '\t' LineLen=ScreenWidth; } int i,j; if(StartLocate >= TempBuffer.size()) return NULL; else { if(FirstView.GetAutoEndl()) { int index=TempBuffer.find("\n" , StartLocate , ScreenWidth); if(index == -1) { if(StartLocate+ScreenWidth > TempBuffer.size()) { TempBuffer.copy(OneLine , TempBuffer.size()-StartLocate , StartLocate); OneLine[TempBuffer.size()-StartLocate]=0; StartLocate=TempBuffer.size(); } else { TempBuffer.copy(OneLine , ScreenWidth , StartLocate); OneLine[ScreenWidth]=0; StartLocate+=ScreenWidth; } }//there is no '\n' in the line else { TempBuffer.copy(OneLine , index-StartLocate+1 , StartLocate); OneLine[index-StartLocate+1]=0; StartLocate=index+1; }//there is '\n' in the line }//if AutoEndl else { int index=TempBuffer.find("\n" , StartLocate); if(index == -1) { if(TempBuffer.size()-StartLocate-1 <= ScreenWidth) { TempBuffer.copy(OneLine , TempBuffer.size()-StartLocate , StartLocate); OneLine[TempBuffer.size()-StartLocate]=0; } else { TempBuffer.copy(OneLine , ScreenWidth , StartLocate); OneLine[ScreenWidth]=0; } StartLocate=TempBuffer.size(); }//there is no '\n' in the buffer else { if(index-StartLocate <= ScreenWidth) { TempBuffer.copy(OneLine , index-StartLocate , StartLocate); OneLine[index-StartLocate+1]=0; } else { TempBuffer.copy(OneLine , ScreenWidth , StartLocate); OneLine[ScreenWidth]=0; } StartLocate=index+1; }//there is '\n' in the buffer }//if nonAutoEndl }//StartLocate doesn't reach the end of buffer return OneLine; } |
Memstring.h:
#ifndef MEMSTRING_H #define MEMSTRING_H #include"All.h" const unsigned int BUFFERSIZE=1024*1024; class MemString //?????????? { string stemp; char *OneLine; int LineLen;//the length of OneLine int LocateInLine;//the location in a line in the NonAutoEndl mode int StartLocate;//the location where the returning lines start int StartPage;//the location where one page start protected: string TempBuffer; int Locate;//???? public: MemString(const char *); //??????,?????????!--! MemString(); ~MemString(){free(OneLine);} void DelString(const int i ,const int j){TempBuffer.replace(i,j-i+1,"");} //???????????????--! void ChangeLocate(const int i); //????????--! void Insert(const string &); //??--! void Insert(const char); string& CopyString(int ,int); //?????--! char *GetLine(const int); void SetStartLocate(const int i){StartLocate=i;} int GetSize(){return TempBuffer.size();} string GetBuffer(){return TempBuffer;} void Clear(); bool NowLineEnd()const; bool NowLineStart()const; int GetLength(){return TempBuffer.size();} virtual bool IsEndBuf()const; virtual bool IsStartBuf()const; static const int TOFRONT=0; static const int TOBACK=1; }; /* inline void MemString::SetStartPage(const int i) { if(StartPage+i < 0) throw CommonError(CommonError::UNDERBUF); else if(Locate+i >= TempBuffer.size()) throw CommonError(CommonError::OVERBUF); else StartPage+=i; } */ inline void MemString::ChangeLocate(const int i) { if(Locate+i < 0) throw CommonError(CommonError::UNDERBUF); else if(Locate+i >= TempBuffer.size()) throw CommonError(CommonError::OVERBUF); else Locate+=i; } inline bool MemString::IsStartBuf()const { if(Locate == 0) return true; else return false; } inline bool MemString::IsEndBuf()const { if(Locate == TempBuffer.size()) return true; else return false; } inline bool MemString::NowLineStart()const { if(Locate == 0) return true; else if(TempBuffer[Locate-1] == '\n') return true; else return false; } inline bool MemString::NowLineEnd()const { if(Locate == TempBuffer.size()) return true; if(TempBuffer[Locate] == '\n') return true; else return false; } inline void MemString::Clear() { TempBuffer.erase(); StartLocate=0; Locate=0; for(int i=0 ; i < LineLen ; i++) OneLine[i]=0; } inline void MemString::Insert(const char ch) { char str[2]; str[0]=ch; str[1]='\0'; TempBuffer.insert(Locate++ , str); } inline void MemString::Insert(const string &temp) { TempBuffer.insert(Locate,temp,0,temp.length()); Locate+=temp.length(); } #endif |
StrView.cpp:
#include<iostream> using namespace std; #include "StrView.h" void StrView::KeyRightNonAuto(MemString &str) { if(str.NowLineEnd()) { if(WinLocat.x < WinSize.ws_row-1) ; } } void StrView::KeyRight(MemString &str) { //code for MemString if(str.IsEndBuf()) { beep(); return; } //some code else str.ChangeLocate(1); //code for screen getyx(win , WinLocat.x , WinLocat.y); if(AutoEndl) KeyRightAuto(str); else { } } void StrView::KeyLeft(MemString &str) { //code for MemString if(str.IsStartBuf()) { beep(); return; } //some code else str.ChangeLocate(-1); //code for screen getyx(win , WinLocat.x , WinLocat.y); if(AutoEndl) { if(str.NowLineStart() && WinLocat.x != 0) //for some code ; //move(WinLocat.x-1 , ); else if(WinLocat.y <= WinSize.ws_col-1 && WinLocat.y > 0) move(WinLocat.x , --(WinLocat.y)); else if(WinLocat.y == 0 && WinLocat.x > 0) move(WinLocat.x-1 , WinSize.ws_col-1); else { move(0 , WinSize.ws_col-1); //for(); } } else { } } void StrView::SigWinch(int signo) { } /*void StrView::Display(char *str) { }*/ struct Location StrView::GetLocat() { getyx(win , WinLocat.x , WinLocat.y); return WinLocat; } void StrView::ClearComLine() { int y=CommandLines; if(WinSize.ws_row > y) for(; y > 0 ; y--) { move(WinSize.ws_row-y , 0); clrtoeol(); } else clear(); } void StrView::DisplayCommand(char *s , const bool sign) { MemString str(s); DisplayCommand(str , sign); } void StrView::DisplayCommand(MemString &str , const bool sign) { int y; int size=str.GetSize(); bool tempAutoEndl=AutoEndl; AutoEndl=true; if(size%WinSize.ws_col == 0) y=size/WinSize.ws_col; else y=size/WinSize.ws_col+1; ClearComLine(); CommandLines=y; int startline; if(WinSize.ws_row > y) { startline=WinSize.ws_row-CommandLines; move(WinSize.ws_row-CommandLines , 0); str.SetStartLocate(0); } else { startline=0; move(0 , 0); int templocate=(y-WinSize.ws_row)*WinSize.ws_col; str.SetStartLocate(templocate); } char *line=NULL; for(;;) { line=str.GetLine(WinSize.ws_col); if(line == NULL) break; else addstr(line); move(++startline , 0); } AutoEndl=tempAutoEndl; } |
StrView.h:
#ifndef __STRVIEW_H__ #define __STRVIEW_H__ #include"All.h" #include"Memstring.h" class StrView { int x; int y; int CommandLines; struct Location WinLocat; struct winsize WinSize; bool AutoEndl; WINDOW *win; int count;//??????????????? int MaxLineLength; //?????80???,???? int MaxLineNumber;//??????20?,???? public: StrView() { AutoEndl=true; WinSize=::GetWinSize(); CommandLines=1; MaxLineLength=80; MaxLineNumber=20; x=0; y=0; win=initscr(); if(win == NULL) { cout<<"can't initial"<<endl; exit(1); } cbreak(); nl(); noecho(); intrflush(stdscr,false); keypad(stdscr,true); refresh(); } ~StrView() { endwin(); } bool SetMaxLineLength();//?????????? bool SetMaxLineNumber();//??????? void Display(const string &); void DisplayCommand(MemString & , const bool sign=false); void DisplayCommand(char * , const bool sign=false); void ClearComLine(); struct Location GetLocat(); void ChangColor(); void SigWinch(int signo); struct winsize GetWinSize(){return WinSize;} bool GetAutoEndl(){return AutoEndl;} void KeyLeft(MemString &str); void KeyLeftAuto(const MemString &str); void KeyRight(MemString &str); void KeyRightAuto(const MemString &str); void KeyRightNonAuto(MemString &str); void KeyBackSpace(MemString &str){} void KeyEnter(MemString &str){} void KeyPageUp(MemString &str){} void KeyPageDown(MemString &str){} void KeyHome(MemString &str){} void KeyEnd(MemString &str){} void KeyDelete(MemString &str){} void KeyUp(MemString &str){} void KeyDown(MemString &str){} void KeyInsert(){} }; inline void StrView::KeyRightAuto(const MemString &str) { if(str.NowLineEnd() && WinLocat.x != WinSize.ws_row-1) move(WinLocat.x+1 , 0); else if(WinLocat.y < WinSize.ws_col-1 && WinLocat.y >= 0) move(WinLocat.x , ++(WinLocat.y)); else if(WinLocat.y == WinSize.ws_col-1 && WinLocat.x < WinSize.ws_row-1) move(WinLocat.x+1 , 0); else { move(WinSize.ws_row-1 , 0); //for(); } } #endif |
SunMemstring.cpp:
#include "SunMemstring.h" string& SunMemString::CopyString(int i,int j) { char temp[BUFFERSIZE]; TempBuffer.copy(temp,i,j-i); temp[j-i]=0; stemp=temp; return stemp; } void SunMemString::ReadFile() { if(fs.eof()) { IsFileEnd=1; Locate--; return; } if(Locate>BUFFERSIZE)//????;;???locate?????BUFFERSIZE/2 { int count=0; int fl; fl=Locate-BUFFERSIZE; char temp[BUFFERSIZE/2]; Locate=BUFFERSIZE/2; while(!fs.eof()&&(count!=Locate)) { fs.get(temp[count]); count++; FileLocate++; TrueSize++; } TempBuffer+=temp; SaveFile(); TempBuffer.replace(0,Locate,""); TrueSize-=Locate; Locate=TempBuffer.size()-count; Locate+=fl; } else if(Locate<0)//????;; { char temp[BUFFERSIZE/2]; int flu; flu=-Locate; Locate=BUFFERSIZE/2; fs.seekg(-TempBuffer.size()-BUFFERSIZE/2,ios::cur);//?????????BUFFERSIZE/2 fs.read(temp,BUFFERSIZE/2);//?BUFFERSIZE/2??? TrueSize+=BUFFERSIZE/2; FileLocate-=BUFFERSIZE/2; TempBuffer.insert(0,temp,0,BUFFERSIZE/2); SaveFile(); fs.seekg(-BUFFERSIZE/2,ios::cur);//???????? TempBuffer.replace(Locate,Locate,""); TrueSize-=Locate; Locate-=flu; } } void SunMemString::SaveFile()//?? { const int EndPoint=FileLocate-TrueSize;//?????????????? double count=0.0; char temp[1024]; char ch; fstream TempFile("tempfile.tmp",ios::out); fs.seekg(0,ios::beg); while((count+1024)<EndPoint) { fs.read(temp,1024); TempFile.write(temp,1024); count+=1024; } while(count<EndPoint) { fs.get(ch); TempFile.put(ch); count++; } TempFile.write(TempBuffer.c_str(),TempBuffer.size()); fs.seekg(FileLocate,ios::beg); while(!fs.eof()) { fs.get(ch); TempFile.put(ch); } TempFile.close(); fs.close(); string del="rm -f "; del+=FileName; char dele[50]; del.copy(dele,del.size()); dele[del.size()]=0; system(dele); string chan="mv tempfile.tmp "; chan+=FileName; char chang[50]; chan.copy(chang,chan.size()); chang[chan.size()]=0; system(chang); char tempname[50]; FileName.copy(tempname,FileName.size()); tempname[FileName.size()]=0; FileLocate=EndPoint+TempBuffer.size(); fs.open(tempname,ios::in|ios::out); fs.seekg(EndPoint+TempBuffer.size(),ios::beg); } int SunMemString::Find(char* s) { int ReturnValue; int OldLocate;//???????Locate OldLocate=Locate; const int Length=strlen(s); if (Length<1) { //cout<<"Command in find error"<<endl; return -1; } else { if (s[0]=='^') { if (s[strlen(s)-1]=='$') { int i; char *ss=(char*)malloc(strlen(s)); for(i=0;i<(strlen(s)-1);i++) ss[i]=s[i]; ReturnValue=FindHead(ss); } else { ReturnValue=FindHead(s); } } if (s[Length-1]=='$') { if(s[0]!='^') { ReturnValue=FindEnd(s); } else { int i; char* ss=(char*)malloc(strlen(s)); for(i=1;i<strlen(s);i++) ss[i-1]=s[i]; ReturnValue=FindEnd(ss); } } if (s[0]!='^'&&s[Length-1]!='$') { ReturnValue=FindNormal(s); } } if (ReturnValue==-1) Locate=OldLocate; return ReturnValue; } int SunMemString::FindHead(char* s) { // int SearchPoint=Locate; int PointToS;//??s?? int PointTot;//???TempBuffer?? char temp; int i=0; int ismatch=0; while(TempBuffer[Locate]!=s[1])//s[0]?'^',????s[o] { Locate++; ReadFile(); if(IsFileEnd==1) { return -1; } } if ((TempBuffer[Locate-1]!='\n')&&(Locate!=0)) { return -1; } else { PointToS=1; PointTot=Locate; while((TempBuffer[PointTot]!='\n')&&(PointToS!=strlen(s))&&(Locate+PointTot<TempBuffer.size())) { temp=TempBuffer[PointTot]; if(s[PointToS]=='[') { char *t=(char*)malloc(strlen(s)); for(PointToS=PointToS++;TempBuffer[PointToS]!=']';PointToS++) { t[i]=TempBuffer[PointToS]; i++; } PointToS++; int n; for(n=0;n<i;n++) { if(t[n]==temp) ismatch=1; } if(ismatch==0) { return -1; } } else if (s[PointToS]=='.') { PointToS++; } else if (s[PointToS]=='*') { if (s[PointToS-1]==temp) ismatch=1; else if (s[PointToS+1]==temp) { ismatch=1; PointToS+=2; } else if((PointToS+1)==strlen(s)) { ismatch=1; PointToS++; } if (ismatch==0) return -1; } else if(temp==s[PointToS]) { PointToS++; } else { return -1; } PointTot++; ismatch=0; } if (PointToS!=strlen(s)) return -1; while(TempBuffer[PointTot]!='\n') PointTot++; return PointTot; } } int SunMemString::FindEnd(char* s) { int PointToS;//??s?? int PointTot;//???TempBuffer?? char temp; int i=0; int ismatch=0; while((TempBuffer[Locate]!=s[strlen(s)-2])||(TempBuffer[Locate+1]!='\n')) { Locate++; ReadFile(); if(IsFileEnd==1) { return -1; } } if ((TempBuffer[Locate+1]!='\n')&&((Locate+1)!=TempBuffer.size())) { return -1; } else { PointToS=strlen(s)-2; PointTot=Locate; while((TempBuffer[PointTot]!='\n')&&(PointToS>0)&&(Locate-PointTot>0)) { temp=TempBuffer[PointTot]; if(s[PointToS]==']') { char *t=(char*)malloc(strlen(s)); for(PointToS=PointToS--;TempBuffer[PointToS]!='[';PointToS--) { t[i]=TempBuffer[PointToS]; i--; } PointToS--; int n; for(n=0;n<i;n++) { if(t[n]==temp) ismatch=1; } if(ismatch==0) { return -1; } } else if (s[PointToS]=='.') { PointToS--; } else if (s[PointToS]=='*') { if (s[PointToS-1]==temp) ismatch=1; else if (s[PointToS-2]==temp) { ismatch=1; PointToS-=3; } else if((PointToS-2)<0) { ismatch=1; PointToS-=2; } if (ismatch==0) return -1; } else if(temp==s[PointToS]) { PointToS--; } else { return -1; } PointTot--; ismatch=0; } if (PointToS<0) return -1; while(TempBuffer[PointTot]!='\n') PointTot--; int ttm; ttm=PointTot; PointTot=Locate; Locate=ttm+1; return PointTot; } } int SunMemString::FindNormal(char* s) { int PointToS;//??s?? int PointTot;//???TempBuffer?? char temp; int i=0; int ismatch=0; while(TempBuffer[Locate]!=s[0]) { Locate++; ReadFile(); if(IsFileEnd==1) { return -1; } } PointToS=0; PointTot=Locate; while((TempBuffer[PointTot]!='\n')&&(PointToS!=strlen(s))&&(Locate+PointTot<TempBuffer.size())) { temp=TempBuffer[PointTot]; if(s[PointToS]=='[') { char *t=(char*)malloc(strlen(s)); for(PointToS=PointToS++;TempBuffer[PointToS]!=']';PointToS++) { t[i]=TempBuffer[PointToS]; i++; } PointToS++; int n; for(n=0;n<i;n++) { if(t[n]==temp) ismatch=1; } if(ismatch==0) { return -1; } } else if (s[PointToS]=='.') { PointToS++; } else if (s[PointToS]=='*') { if (s[PointToS-1]==temp) ismatch=1; else if (s[PointToS+1]==temp) { ismatch=1; PointToS+=2; } if (ismatch==0) return -1; } else if(temp==s[PointToS]) { PointToS++; } else { return -1; } PointTot++; ismatch=0; } if (PointToS!=strlen(s)) return -1; return PointTot; } int SunMemString::Replace(char* s,char* so) { int isfind; isfind=Find(s); if (isfind<0) { //cout<<"There is no strings named "<<'\"'<<s<<'\"'<<endl; return -1; } else { TempBuffer.replace(Locate,(isfind-Locate),so); return 1; } } int SunMemString::ReplaceAll(char* s,char* so) { int is; is=Replace(s,so); if(is<0) { ///cout<<"There is no strings named "<<'\"'<<s<<'\"'<<endl; return -1; } else { while ((is=Replace(s,so))>0); return 1; } } |
SunMemstring.h:
#ifndef SUNMEMSTRING_H #define SUNMEMSTRING_H #include"Memstring.h" #include"All.h" class SunMemString:public MemString //?????????? { int TrueSize;//????????????? string stemp; int FileLocate;//???????? string FileName;//??? !-- fstream fs; int IsFileEnd; int Locate; public: SunMemString(char *); //??????,?????????!--! ~SunMemString(){} void ReadFile(); // !--! void SaveFile(); //?? string& CopyString(int ,int); //?????--! int Find(char *); //??,???????,????????????? int Replace(char *,char *); int ReplaceAll(char *,char *); int FindHead(char *); int FindEnd(char *); int FindNormal(char *); const string &GetFileName()const{return FileName;} int GetLocate(); bool IsEndBuf()const; bool IsStartBuf()const; }; bool SunMemString::IsStartBuf()const { if(FileLocate == 0) return true; else return false; } bool SunMemString::IsEndBuf()const { } inline SunMemString::SunMemString(char* s):fs(s,ios::in|ios::out) { if(fs.eof()) throw -1; char temp[BUFFERSIZE]; FileName=s; Locate=0; FileLocate=0; TrueSize=0; fs.read(temp,BUFFERSIZE); TempBuffer=temp; FileLocate+=BUFFERSIZE; TrueSize=BUFFERSIZE; IsFileEnd=0; } #endif //SUNMEMSTRING_H |
Makefile:
all:StrView.o main.o Control.o Memstring.o SunMemstring.o FileList.o g++ -ggdb3 -o myvi StrView.o main.o Control.o Memstring.o FileList.o -lcurses StrView.o:StrView.cpp StrView.h g++ -ggdb3 -c StrView.cpp main.o:main.cpp g++ -ggdb3 -c main.cpp Control.o:Control.cpp Control.h g++ -ggdb3 -c Control.cpp Memstring.o:Memstring.cpp Memstring.h g++ -ggdb3 -c Memstring.cpp SunMemstring.o:SunMemstring.cpp SunMemstring.h g++ -ggdb3 -c SunMemstring.cpp FileList.o:FileList.cpp FileList.h g++ -ggdb3 -c FileList.cpp |
Hi icoming!
Yeah! The stuff compiles. 'myvi' exists. The essential step was providing a copy-constructor for SunMemString like the following Code:
SunMemString(const SunMemString& rhs) into the list. Maybe you shoud better use a list of pointers. I remember that Scott Meyer wrote something about this. Could not reproduce the "in charge" thing. Also googling gave me no real insight. Ciao, bluie PS: Hey! Why not wrapping code in these cute code-tags? |
All times are GMT -5. The time now is 09:23 AM. |