/* WebDownloader for X-Window * Copyright (C) 1999-2002 Koshelev Maxim * This Program is free but not GPL!!! You can't modify it * without agreement with author. You can't distribute modified * program but you can distribute unmodified program. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include #include #include #include #include "autoadd.h" #include "dbc.h" #include "locstr.h" struct d4xAASubStr:tNode{ int type; int left_int,right_int,cur_int,int_len; char *left_str,*right_str,*cur_str; int str_len; int end_flag; int period; d4xAASubStr(); void print(); char *first(); char *next(); char *last(); char *scan(char *str); ~d4xAASubStr(); private: char *last_str; int sub_scan(char **cur); void next_str(); void set_last(char *str); }; enum D4X_AUTO_ADD_ENUM{ DAA_STR, DAA_INT_INT, DAA_STR_STR, DAA_STRS, DAA_UNKNOWN }; /******************************************************************/ d4xAASubStr::d4xAASubStr(){ type=DAA_UNKNOWN; period=1; left_int=right_int=cur_int=int_len=0; left_str=right_str=cur_str=NULL; last_str=NULL; }; char *d4xAASubStr::last(){ return(copy_string(last_str)); }; void d4xAASubStr::set_last(char *a){ if (last_str) delete[] last_str; last_str=copy_string(a); }; void d4xAASubStr::print(){ switch(type){ case DAA_STR: printf("%s",left_str); break; case DAA_INT_INT: printf("%i - %i",left_int,right_int); break; case DAA_STR_STR: printf("%s - %s",left_str,right_str); break; case DAA_STRS:{ char *cur=left_str; for (int i=0;iright_str[i]?-1:1; break; }; if (cur_str[i]==right_str[i]) cur_str[i]=left_str[i]; }; if (strcmp(cur_str,right_str)==0) break; }; }; char *d4xAASubStr::next(){ if (type==DAA_STR){ end_flag=1; set_last(left_str); return(copy_string(left_str)); }; if (type==DAA_INT_INT){ if (cur_int!=right_int){ for (int per=0;per=left_int){ end_flag=1; }else{ cur_int+=1; }; for (int i=0;iscan(cur); if (a==cur){ delete(tmp); return(1); }; list.insert(tmp); cur=a; }; // print(); return(0); }; char *d4xAutoGenerator::first(){ d4xAASubStr *tmp=(d4xAASubStr *)list.first(); if (tmp==NULL) return(NULL); char *rval=tmp->first(); tmp=(d4xAASubStr *)(tmp->prev); while(tmp){ char *a=tmp->first(); char *b=sum_strings(rval,a,NULL); delete[] rval; delete[] a; rval=b; tmp=(d4xAASubStr *)(tmp->prev); }; return(rval); }; char *d4xAutoGenerator::next(){ d4xAASubStr *tmp=(d4xAASubStr *)list.first(); if (tmp==NULL) return(NULL); char *rval=NULL; int end_flag=0; int last=0; if (tmp->end_flag){ end_flag=1; last=1; rval=tmp->first(); }else{ rval=tmp->next(); }; tmp=(d4xAASubStr *)(tmp->prev); int flast=1; while(tmp){ char *a=NULL; if (last && flast){ if (tmp->end_flag){ last=1; a=tmp->first(); }else{ flast=0; a=tmp->next(); }; }else{ a=tmp->last(); }; char *b=sum_strings(rval,a,NULL); delete[] rval; delete[] a; rval=b; if (tmp->end_flag && tmp->prev==NULL && flast) end_flag=1; else end_flag=0; tmp=(d4xAASubStr *)(tmp->prev); }; if (end_flag){ delete[] rval; rval=NULL; }; return(rval); }; void d4xAutoGenerator::print(){ d4xAASubStr *tmp=(d4xAASubStr *)list.first(); while(tmp){ tmp->print(); tmp=(d4xAASubStr *)(tmp->prev); }; }; d4xAutoGenerator::~d4xAutoGenerator(){ //do nothing? };