132 lines · 2.2 KB · C
RawDownload
/*  * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include "sam.h" List	file = { 'p' };ushort	tag; File *newfile(void){	File *f; 	f = fileopen();	inslist(&file, 0, f);	f->tag = tag++;	if(downloaded)		outTs(Hnewname, f->tag);	/* already sorted; file name is "" */	return f;} intwhichmenu(File *f){	int i; 	for(i=0; i<file.nused; i++)		if(file.filepptr[i]==f)			return i;	return -1;} voiddelfile(File *f){	int w = whichmenu(f); 	if(w < 0)	/* e.g. x/./D */		return;	if(downloaded)		outTs(Hdelname, f->tag);	dellist(&file, w);	fileclose(f);} voidfullname(String *name){	if(name->n > 0 && name->s[0]!='/' && name->s[0]!=0)		Strinsert(name, &curwd, (Posn)0);} voidfixname(String *name){	String *t;	char *s; 	fullname(name);	s = Strtoc(name);	if(strlen(s) > 0)		s = cleanname(s);	t = tmpcstr(s);	Strduplstr(name, t);	free(s);	freetmpstr(t); 	if(Strispre(&curwd, name))		Strdelete(name, 0, curwd.n);} voidsortname(File *f){	int i, cmp, w;	int dupwarned; 	w = whichmenu(f);	dupwarned = FALSE;	dellist(&file, w);	if(f == cmd)		i = 0;	else{		for(i=0; i<file.nused; i++){			cmp = Strcmp(&f->name, &file.filepptr[i]->name);			if(cmp==0 && !dupwarned){				dupwarned = TRUE;				warn_S(Wdupname, &f->name);			}else if(cmp<0 && (i>0 || cmd==0))				break;		}	}	inslist(&file, i, f);	if(downloaded)		outTsS(Hmovname, f->tag, &f->name);} voidstate(File *f, int cleandirty){	if(f == cmd)		return;	f->unread = FALSE;	if(downloaded && whichmenu(f)>=0){	/* else flist or menu */		if(f->mod && cleandirty!=Dirty)			outTs(Hclean, f->tag);		else if(!f->mod && cleandirty==Dirty)			outTs(Hdirty, f->tag);	}	if(cleandirty == Clean)		f->mod = FALSE;	else		f->mod = TRUE;} File *lookfile(String *s){	int i; 	for(i=0; i<file.nused; i++)		if(Strcmp(&file.filepptr[i]->name, s) == 0)			return file.filepptr[i];	return 0;}