#include #include #include #include #include #include using namespace std; string select_word (string& s) { int i; string st; i=s.find_first_not_of(' '); if (s[i]=='\"') { i=s.find_first_of('\"',1); st=s.substr(1,i-1); s.erase (0,i+2); return st; } if (s[i]!='\"') { i=s.find_first_of(' '); st=s.substr(0,i); s.erase (0,i+1); return st; } } string new_list_name() { char* S; S=new char [11]; strcpy(S, "list_XXXXXX"); S=mktemp(S); return S; } //------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------- Class Element ----------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------------------------------------------- class Element { private: string a; public: Element (string a): a(a) {} void writeln (ostream& f) { f< SonDirs; string name; string filename; //------------------------------------------------------------------------------------------------------------------------------------------------------- List(string s1, string s2) //constructer #1 { int pos; parent=NULL; SonDirs.clear(); name=s1; filename=s2; } //------------------------------------------------------------------------------------------------------------------------------------------------------- ~List() //destructer { SonDirs.clear(); } //------------------------------------------------------------------------------------------------------------------------------------------------------- void LinkList (List *l1, List *l2) //adding list l2 to tree l1 { l1->SonDirs.push_back (l2); l2->parent=l1; } //------------------------------------------------------------------------------------------------------------------------------------------------------- void AddElem(Element e) //adding element to current list { ofstream f; f.open(filename.c_str(), ios::app); e.writeln (f); f.close(); } //------------------------------------------------------------------------------------------------------------------------------------------------------- void abcfg_build (ofstream& ab) { ab<abcfg_build(ab); } void show_lists (int k) { int i,p; for(p=0;pshow_lists(k+1); } //------------------------------------------------------------------------------------------------------------------------------------------------------- void show_contacts() { string s; int i; ifstream f; f.open(filename.c_str(), ios::in); while (getline (f,s)) cout<=0) ftemp1<<"|"<1) sn=select_word(s); else k=0;//name if (sn=="\"\"") k=0; else k=1; if ((sn.size()!=0)&&(k!=0)) { while (getline (ftemp1,str)) { i=str.find(sn); if (i>=0) ftemp2<1) sn=select_word(s); else k=0;//second name if (sn=="\"\"") k=0; else k=1; if ((sn.size()!=0)&&(k!=0)) { while (getline (ftemp3,str)) { i=str.find(sn); if (i>=0) ftemp2<SonDirs.size();i++) { namf=new_list_name(); sys="cp "+R->SonDirs[i]->filename+" "+namf; system (sys.c_str()); nam="copy_of_"+R->SonDirs[i]->name; K=new List(nam,namf); LinkList (this,K); if (R->SonDirs[i]->SonDirs.size()!=0) { R=R->SonDirs[i]; SonDirs[i]->copy_sons(R); return; } } } void kill_all_children () { int i; remove (filename.c_str()); for(i=0;ikill_all_children(); } }; //------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------- Just functions ---------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------------------------------------------- List *L; // string addr; void abcfgbuild () { ofstream ab; ab.open("ab.cfg"); L->abcfg_build(ab); ab.close(); } string s_w_f_abcfg (int& i, int& pos, string s) { string st; pos=s.find_first_not_of('-',pos); i=s.find_first_of('-',pos); st=s.substr(pos,i-pos); pos=i+1; return st; } string first_path_extract (string &s) { int i; string st; if (s.length()==0) return ""; i=s.find_first_of('/',1); st=s.substr(1,i-1); s.erase (0,i); return st; } string last_path_extract (string &s) { int pos,i; string st; if (s.length()==0) return ""; pos=s.find_last_not_of('/',pos); i=s.find_last_of('/'); st=s.substr(i+1,pos-i); s.erase (i,pos-i+1); return st; } void abcfg_analise (istream &ab, List *L) { ifstream content; List *R; char* str; char t; string s,s1,s2,temp; int i=0,pos=0,n=0,o=0; getline (ab,s); sscanf (s.c_str(),"%d",&n); while (n!=0) { n--; getline(ab,s); s1=s_w_f_abcfg(i,pos,s); s2=s_w_f_abcfg(i,pos,s); content.open("content", ios::in); while ((content.good())&&(!content.eof())) { getline(content,temp); o=temp==s2; if (o) break; if (temp.empty()) break; } if (!o) {cout<LinkList(L, R); abcfg_analise (ab, R); } return; } List* tree_find (List *L, string s) { int n,pos=0; string st; pos=s.find_first_of('/'); if (pos==string::npos) return L; st=first_path_extract (s); n=L->SonDirs.size(); if ((n==0)&&(s.length()==0)) return L; if ((n==0)&&(s.length()!=0)) return NULL; while (n!=0) { n--; if (L->SonDirs[n]->name.compare (st)==0) return tree_find (L->SonDirs[n], s); } //return NULL; cout<AddElem(*el); } //------------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------- Main -------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------------------------------------------- int main (int argc, char** argv) { string temp,com,sys,root,moot,nam,namf,s,st,str,s1,s2,s3; List *P,*R,*K; int q=0,z,i,pos,w; ifstream content,fftemp,f,ab; ofstream newf; i=0;pos=0; if (argc<2) {cout<<" ERROR: not enough arguments."<2) {cout<<" ERROR: too many arguments."< content"; system(moot.c_str()); content.open("content", ios::in); abcfg_analise (ab,L); ab.close(); content.close(); cout<<" ab.cfg is correct"<>str; cout<name) { R=tree_find (L, str); } namf=new_list_name(); newf.open(namf.c_str(), ios::out); newf.close(); K=new List(nam,namf); R->LinkList (R,K); abcfgbuild(); } else { str=select_word(com); nam=last_path_extract (str); root=first_path_extract (str); if (root==L->name) { R=tree_find (L, str); } namf=new_list_name(); newf.open(namf.c_str(), ios::out); newf.close(); K=new List(nam,namf); R->LinkList (R,K); abcfgbuild(); } cout<show_lists(0); cout<name) { R=tree_find (L, str); } cout<<" And now plz input a new person`s surname..."<>st; str=st; str.append(" "); cout<<" And now plz input a new person`s name..."<>st; str.append(st); str.append(" "); cout<<" And now plz input a new person`s second name..."<>st; str.append(st); str.append(" "); cout<<" And now plz input a new person`s telephone..."<>st; str.append(st); str.append(" "); cout<<" Plz input a new person`s e-mail..."<>st; str.append(st); new_contact2 (R,str); } else { str=select_word(com); root=first_path_extract (str); if (root==L->name) { R=tree_find (L, str); } new_contact2 (R,com); } } //---------------------------------------------------- delete_list ---------------------------------------------------- else if (str=="delete_list") { if (z==1) { str=select_word(com); } else { cout<<" Please enter full path to a list you wish me to delete"<>str; getchar(); } if (str.size()==0) { cout<<"Not enough arguments"; break; } root=first_path_extract (str); if (root==L->name) { if (str.size()==0) { cout<<" ERROR: you`re trying to delete a root"<kill_all_children(); for(i=0;iparent->SonDirs.size();i++) if (R->parent->SonDirs[i]->name==R->name) R->parent->SonDirs.erase(R->parent->SonDirs.begin()+i); abcfgbuild(); } //---------------------------------------------------- rename_list ---------------------------------------------------- else if (str=="rename_list") { if (z==1) { s1=select_word(com); s2=select_word(com); if ((s1.size()<1)||(s2.size()<1)) { cout<<" ERROR: Not enough arguments"<>s1; cout<<" Please enter full name (path) of the new list"<>s2; if ((s1.find("\"")name) { if (s1.size()==0) { cout<<" ERROR: you`re trying to move a root"<name) { K=tree_find (L, s2); } for(i=0;iparent->SonDirs.size();i++) if (R->parent->SonDirs[i]->name==R->name) R->parent->SonDirs.erase(R->parent->SonDirs.begin()+i); K->SonDirs.push_back(R); R->parent=K; R->name=nam; abcfgbuild(); if (z==0) getchar(); } //---------------------------------------------------- make_list_copy ------------------------------------------------- else if (str=="make_list_copy") { if (z==1) { s1=select_word(com); s2=select_word(com); } else { cout<<" Please enter full path to the original list"<>s1; cout<<" Please enter full path to the copied list"<>s2; } root=first_path_extract (s1); if (root==L->name) { if (s1.size()==0) { cout<<" ERROR: you`re trying to move a root"<name) { P=tree_find (L,s2); } namf=new_list_name(); sys="cp "+R->filename+" "+namf; system (sys.c_str()); K=new List(nam,namf); K->LinkList (P,K); if(R->SonDirs.size()!=0) { K->copy_sons(R); } abcfgbuild(); if (z==0) getchar(); } //---------------------------------------------------- show_contacts ----------------------------------------------- else if (str=="show_contacts") { if (z==0) { cout<<" Please enter full path to a list for me reveal"<>com; cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } cout<<" "<name<<"`s contact list"<<" "<show_contacts(); cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } str=select_word(com); sscanf (str.c_str(),"%d",&i); } else { cout<<" Please enter full path to a list with a contact you want to be deleted"<>str; root=first_path_extract (str); if (root==L->name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } i=0; fftemp.open(K->filename.c_str(), ios::in); while (getline (fftemp,s)) {cout<>str; sscanf (str.c_str(),"%d",&i); } K->delete_contact(i); cout<name) { if (str.size()!=0) K=tree_find (L,s1); else K=L; } str=select_word(com); sscanf (str.c_str(),"%d",&i); str=com; } else { cout<<" Please enter full path to a list from which a contact should be edit"<>s1; root=first_path_extract (s1); if (root==L->name) { if (str.size()!=0) K=tree_find (L,s1); else K=L; } cout<filename.c_str(), ios::in); while (getline (fftemp,s)) {cout<>i; sscanf (str.c_str(),"%d",&i); cout<<" And now plz input a person`s new surname..."<>st; str=st; str.append(" "); cout<<" And now plz input a person`s new name..."<>st; str.append(st); str.append(" "); cout<<" And now plz input a person`s new second name..."<>st; str.append(st); str.append(" "); cout<<" And now plz input a person`s new telephone..."<>st; str.append(st); str.append(" "); cout<<" Plz input a person`s new e-mail..."<>st; str.append(st); } K->edit_contact(str,i); cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } str=select_word(com); sscanf (str.c_str(),"%d",&i); str=select_word(com); root=first_path_extract (str); if (root==L->name) { if (str.size()!=0) P=tree_find (L,str); else P=L; } } else { cout<<" Please enter full path to a source list"<>str; cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } i=0; cout<<" "<name<<"`s numbered contacts:"<filename.c_str(), ios::in); while (getline (fftemp,s)) {cout<>i; cout<<" Now please enter full path to a destination list"<>str; root=first_path_extract (str); if (root==L->name) { if (str.size()!=0) P=tree_find (L,str); else P=L; } } K->make_contact_copy(P->filename,i,w); if (z==0) getchar(); } //---------------------------------------------------- find_contact ------------------------------------------------ else if (str=="find_contact") { if (z==1) { str=select_word(com); s=com; } else { cout<<" Please enter full path to a list where to search"<>str; } root=first_path_extract (str); if (root==L->name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } if (z==0) { cout<<" Please enter a person`s surname to look for..."<1) { s.append(" "); } cout<<" And now plz enter a person`s name to look for..."<1) { s.append(" "); } cout<<" And now plz enter a person`s second name to look for..."<1) { s.append(" "); } } K->find_contact(s); cout<>root; } else { root=select_word(com); } f.open(root.c_str(), ios::in); if (!f.is_open()){ cout << " This file is corrupted. Shame on you. I`m leaving."<name) { R=tree_find (L, str); } namf=new_list_name(); newf.open(namf.c_str(), ios::out); newf.close(); K=new List(nam,namf); R->LinkList (R,K); abcfgbuild(); } else //--------------------------------------------------- new_contact if (st.compare ("new_contact")==0) { str=select_word(s); root=first_path_extract (str); if (root==L->name) { R=tree_find (L, str); } new_contact2 (R,s); } else //--------------------------------------------------- show_lists if (st.compare ("show_lists")==0) { cout<<" Adress Book Lists "<show_lists(0); cout<name) { if (str.size()==0) { cout<<"ERROR: you`re trying to delete a root"<kill_all_children(); for(i=0;iparent->SonDirs.size();i++) if (R->parent->SonDirs[i]->name==R->name) R->parent->SonDirs.erase(R->parent->SonDirs.begin()+i); abcfgbuild(); } //-------------------------------------------------- rename_list else if (st.compare ("rename_list")==0) { s1=select_word(s); s2=select_word(s); root=first_path_extract (s1); if (root==L->name) { if (s1.size()==0) { cout<<"ERROR: you`re trying to move a root"<name) { K=tree_find (L, s2); } for(i=0;iparent->SonDirs.size();i++) if (R->parent->SonDirs[i]->name==R->name) R->parent->SonDirs.erase(R->parent->SonDirs.begin()+i); K->SonDirs.push_back(R); R->parent=K; R->name=nam; abcfgbuild(); } //------------------------------------------------ make_list_copy else if (st.compare ("make_list_copy")==0) { s1=select_word(s); s2=select_word(s); root=first_path_extract (s1); if (root==L->name) { if (s1.size()==0) { cout<<"ERROR: you`re trying to move a root"<name) { P=tree_find (L,s2); } namf=new_list_name(); sys="cp "+R->filename+" "+namf; system (sys.c_str()); K=new List(nam,namf); K->LinkList (P,K); if(R->SonDirs.size()!=0) // cout<name<<"***"<copy_sons(R); } abcfgbuild(); } //------------------------------------------------- show_conacts else if (st.compare ("show_contacts")==0) { str=select_word(s); root=first_path_extract (str); if (root==L->name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } cout<<" "<name<<"`s contact list"<<" "<show_contacts(); cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } str=select_word(s); sscanf (str.c_str(),"%d",&i); K->delete_contact(i); cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } str=select_word(s); sscanf (str.c_str(),"%d",&i); K->edit_contact(s,i); cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } str=select_word(s); sscanf (str.c_str(),"%d",&i); str=select_word(s); root=first_path_extract (str); if (root==L->name) { if (str.size()!=0) P=tree_find (L,str); else P=L; } K->make_contact_copy(P->filename,i,1); cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } str=select_word(s); sscanf (str.c_str(),"%d",&i); str=select_word(s); root=first_path_extract (str); if (root==L->name) { if (str.size()!=0) P=tree_find (L,str); else P=L; } K->make_contact_copy(P->filename,i,0);// zero instead of one in make_list_copy cout<name) { if (str.size()!=0) K=tree_find (L,str); else K=L; } K->find_contact(s); cout<