Exemple #1
0
void main() 
{sqlist L; 
int i,j,k,b,n,e,m,a,cur_e,pre_e,next_e,s; 
initlist(L); 
cout<<"初始化后的基值地址:"<<L.elem<<" L.length=:"<<L.length<<" L.listsize=:"<<L.listsize<<endl; 
cout<<"新建一顺序表."<<endl; 
cout<<"当前表是否为空表"<<listempty(L)<<endl; 
cout<<"定义该线性表长度:"<<endl; 
cin>>a; 
cout<<"分别输入线性表的各个元素,按ENTER"<<endl; 
for(k=1;k<=a;k++){ 
cin>>j; 
i=listinsert(L,k,j);} 
for(b=1;b<=a;b++) 
cout<<L.elem[b-1]<<endl; 
listlength(L); 
cout<<"当前表长:"<<L.length<<endl; 
cout<<"输入要取的数的位置n(n<=a)"<<endl; 
cin>>n; 
getelem(L,n,e); 
//cout<<L.elem[n-1]<<endl; 
cout<<e<<endl;
cout<<"与该数相等的的一个数的位序为:"<<locateelem(L,e,compare)<<endl; 
cout<<"输入要取前驱的数的位置m(<=a)"<<endl; 
cin>>m; 
getelem(L,m,cur_e); 
if(priorelem(L,cur_e,pre_e)) 
cout<<"cur_e的前驱为:"<<pre_e<<endl; 
else 
cout<<"该元素没前驱"<<endl; 
nextelem(L,cur_e,next_e); 
if(nextelem(L,cur_e,next_e)) 
cout<<"cur_e的后继为:"<<next_e<<endl; 
else 
cout<<"该元素没后继"<<endl;
cout<<"奇数在前,偶数在后,并输出"<<endl; 

move(L);
for(s=1;s<=a;s++) 
cout<<L.elem[s-1]<<endl; 

cout<<"输入要删元素的位序m(<=a)"<<endl; 
cin>>m; 
listdelete(L,m,e); 
cout<<"被删的元素为:"<<e<<endl; 
cout<<"删除元素后表长为"<<L.length<<endl; 
//listtraverse(L,visit); 

cout<<"置为空表"<<clearlist(L)<<endl; 
cout<<"销毁线性表"<<destroylist(L)<<endl;
}
Exemple #2
0
void
cmd_cfs(void)
{
	Filsys *fs;

	if(*cons.arg != ' ') {
		fs = &filesys[0];		/* default */
	} else {
		if(skipbl(1)){
			cprint("skipbl\n");
			return;
		}
		if(!nextelem())
			fs = &filesys[0];	/* default */
		else
			fs = fsstr(elem);
	}
	if(fs == 0) {
		cprint("unknown file system %s\n", elem);
		return;
	}
	if(con_attach(FID1, "adm", fs->name))
		panic("FID1 attach to root");
	cur_fs = fs;
}
Exemple #3
0
void
cmd_create(void)
{
	int uid, gid, err;
	int32_t perm;
	char oelem[NAMELEN];
	char name[NAMELEN];

	if(err = con_clone(FID1, FID2)){
		cprint("clone failed: %s\n", errstring[err]);
		return;
	}
	if(skipbl(1)){
		cprint("skipbl\n");
		return;
	}
	oelem[0] = 0;
	while(nextelem()) {
		if(oelem[0])
			if(err = con_walk(FID2, oelem)){
				cprint("walk failed: %s\n", errstring[err]);
				return;
			}
		memmove(oelem, elem, NAMELEN);
	}
	if(skipbl(1))
		return;
	uid = strtouid(cname(name));
	if(uid == 0){
		cprint("unknown user %s\n", name);
		return;
	}
	gid = strtouid(cname(name));
	if(gid == 0){
		cprint("unknown group %s\n", name);
		return;
	}
	perm = number(0777, 8);
	skipbl(0);
	for(; *cons.arg; cons.arg++){
		if(*cons.arg == 'l')
			perm |= PLOCK;
		else
		if(*cons.arg == 'a')
			perm |= PAPND;
		else
		if(*cons.arg == 'd')
			perm |= PDIR;
		else
			break;
	}
	err = con_create(FID2, elem, uid, gid, perm, 0);
	if(err)
		cprint("can't create %s: %s\n", elem, errstring[err]);
}
Exemple #4
0
void
cmd_remove(void)
{
	if(con_clone(FID1, FID2))
		return;
	if(skipbl(1))
		return;
	while(nextelem())
		if(con_walk(FID2, elem)){
			cprint("can't walk %s\n", elem);
			return;
		}
	con_remove(FID2);
}
Exemple #5
0
Fichier : fs.c Projet : 8l/inferno
int
fswalk(Fs *fs, char *path, File *f)
{
	char element[NAMELEN];

	*f = fs->root;
	if(BADPTR(fs->walk))
		panic("fswalk bad pointer fs->walk");

	f->path = path;
	while(path = nextelem(path, element)){
		switch(fs->walk(f, element)){
		case -1:
			return -1;
		case 0:
			return 0;
		}
	}
	return 1;
}
Exemple #6
0
void
cmd_rename(void)
{
	uint32_t perm;
	Dentry d;
	char stat[DIRREC];
	char oelem[NAMELEN], noelem[NAMELEN], nxelem[NAMELEN];
	int err;

	if(con_clone(FID1, FID2))
		return;
	if(skipbl(1))
		return;
	oelem[0] = 0;
	while(nextelem()) {
		if(oelem[0])
			if(con_walk(FID2, oelem)){
				cprint("file does not exits");
				return;
			}
		memmove(oelem, elem, NAMELEN);
	}
	if(skipbl(1))
		return;
	if(cons.arg[0]=='/'){
		if(con_clone(FID1, FID3))
			return;
		noelem[0] = 0;
		while(nextelem()){
			if(noelem[0])
				if(con_walk(FID3, noelem)){
					cprint("target path %s does not exist", noelem);
					return;
				}
			memmove(noelem, elem, NAMELEN);
		}
		if(!con_walk(FID3, elem)){
			cprint("target %s already exists\n", elem);
			return;
		}
		if(con_walk(FID2, oelem)){
			cprint("src %s does not exist\n", oelem);
			return;
		}
		/*
		 * we know the target does not exist,
		 * the source does exist.
		 * to do the rename, create the target and then
		 * copy the directory entry directly.  then remove the source.
		 */
		if(err = con_stat(FID2, stat)){
			cprint("can't stat file: %s\n", errstring[err]);
			return;
		}
		convM2D9p1(stat, &d);
		perm = (d.mode&0777)|((d.mode&0x7000)<<17);
		if(err = con_create(FID3, elem, d.uid, d.gid, perm, (d.mode&DDIR)?OREAD:ORDWR)){
			cprint("can't create %s: %s\n", elem, errstring[err]);
			return;
		}
		if(err = con_swap(FID2, FID3)){
			cprint("can't swap data: %s\n", errstring[err]);
			return;
		}
		if(err = con_remove(FID2)){
			cprint("can't remove file: %s\n", errstring[err]);
			return;
		}
	}else{
		cname(nxelem);
		if(strchr(nxelem, '/')){
			cprint("bad rename target: not full path, but contains slashes\n");
			return;
		}
		if(!con_walk(FID2, nxelem))
			cprint("file %s already exists\n", nxelem);
		else if(con_walk(FID2, oelem))
			cprint("file does not already exist\n");
		else if(err = con_stat(FID2, stat))
			cprint("can't stat file: %s\n", errstring[err]);
		else{
			convM2D9p1(stat, &d);
			strncpy(d.name, nxelem, NAMELEN);
			convD2M9p1(&d, stat);
			if(err = con_wstat(FID2, stat))
				cprint("can't move file: %s\n", errstring[err]);
		}
	}
}
Exemple #7
0
void MergeRootfile( TFile *source ) {
   TString path(gDirectory->GetPath());
   source->cd( path );
   cerr << "Browsing " << path << endl;

   //gain time, do not add the objects in the list in memory
   TH1::AddDirectory(kFALSE);

   // loop over all keys in this directory
   TIter nextkey( gDirectory->GetListOfKeys() );
   TKey *key, *oldkey=0;
   while ( (key = (TKey*)nextkey())) {

      //keep only the highest cycle number for each key
      if (oldkey && !strcmp(oldkey->GetName(),key->GetName())) continue;

      // read object from first source file
      TObject *obj = key->ReadObj();

      cerr << "NAME IS " << obj->GetName() << endl;

      if ( obj->IsA()->InheritsFrom( TH1::Class() ) ) {
         cerr << "   HELLO, we have the histogram " << obj->GetName() << endl;
         TH1 *h = (TH1*)obj;
         ProcessHisto(h);
      } else if ( obj->IsA()->InheritsFrom( THnBase::Class() )) {
         cerr << "   HELLO-SPARSE " << obj->GetName() << endl;
         THnBase *h = (THnBase*)obj;
         ProcessSparse(h);
      } else if ( obj->IsA()->InheritsFrom( TDirectory::Class() ) ) {
         // it's a subdirectory

         //cerr << "Found subdirectory " << obj->GetName() << endl;
	 source->cd( path + "/" + obj->GetName() );
         MergeRootfile(source);
         source->cd( path );
      } else if ( obj->IsA()->InheritsFrom( TCollection::Class() )) {
        TCollection *coll = (TCollection *)obj;
        //cerr << "List of something in " << obj->GetName() << endl;
        TIter nextelem(coll);
        TObject *elem;
        while ((elem = nextelem())) {
          if (elem->IsA()->InheritsFrom( TH1::Class() )) {
            cerr << "   HELLO, we have the histogram " << elem->GetName() << endl;
            TH1 *h = (TH1 *)elem;
            ProcessHisto(h);
          } else if (elem->IsA()->InheritsFrom( THnBase::Class() )) {
            cerr << "   HELLO-SPARSE " << elem->GetName() << endl;
            THnBase *h = (THnBase *)elem;
            ProcessSparse(h);
          }
        }
      } else {

         // object is of no type that we know or can handle
         cerr << "Unknown object type, name: "
           << obj->GetName() << " title: " << obj->GetTitle() << endl;
      }
      delete obj;

   } // while ( ( TKey *key = (TKey*)nextkey() ) )
}