1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include "wily.h"
#include "data.h"
/*************************************************************
Various routines to do with a Data's label and/or path
*************************************************************/
static void data_restat(Data*d);
#define DATALABEL(d) ((d)?(d)->label:wilydir)
void
data_addcontext(Data*d, char*dest, char*orig) {
addcontext(dest, DATALABEL(d), orig);
labelclean(dest);
}
/* Copy d's label (or wilydir) to 'dest' */
void
data_getlabel(Data*d, char*dest){
strcpy(dest, DATALABEL(d));
}
/* D's label has been changed to 's',
* update our internal structures.
*/
void
data_setlabel(Data*d, char *s) {
assert(d);
/* Just record the new label, only update
* other stuff on demand.
*/
strcpy(d->label, s);
if(STRSAME(d->label, d->cachedlabel)) {
if(!data_isdirty(d)) {
tag_rmtool(d->tag, "Put");
}
} else {
tag_addtool(d->tag, "Get");
tag_addtool(d->tag, "Put");
}
}
/* Return pointer to View with same 'label', or null. */
View *
data_find(char*label) {
Data *d;
Stat buf;
Path path;
/* Search for data with same label */
for(d=dataroot; d; d=d->next) {
if (STRSAME(d->label, label))
return text_view(d->t);
}
/* Search for data with same stat buffer */
label2path(path,label);
if(stat(path,&buf))
return 0;
for(d=dataroot; d; d=d->next) {
data_restat(d);
if (d->has_stat && !statcmp(&buf, &d->stat))
return text_view(d->t);
}
return 0;
}
/* If 'label' has changed under us, update
* some other information.
*/
static void
data_restat(Data*d) {
if(strcmp(d->label, d->cachedlabel)) {
Path path;
strcpy(d->cachedlabel, d->label);
label2path(path, d->label);
d->has_stat = !stat(path, &d->stat);
}
}
|