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 85 86
|
#include "wily.h"
#include "tile.h"
enum {TSIZE=401};
static Tile* placetable[TSIZE]; /* hashed array of column tiles */
static Bool iserror(char*label);
static Bool validcolumn(Tile*c);
static unsigned long hashpath(char *path);
static Tile * find(char *label);
/* Save the window column for later lookup. */
void
placedcol(char*label, Tile *c) {
if (label && !iserror(label))
placetable[hashpath(label)] = c;
}
/* Return the column to use for a new window with label 'path' */
Tile*
findcol(char*label) {
Tile *c;
if(!wily->down){
col_new(wily->tag,0);
return wily->down;
}
if(iserror(label))
return last_visible(wily->down, 0);
if (!(c= find(label))) {
c = biggest_visible(wily->down, 0);
assert(c);
placedcol(label, c);
}
return c;
}
/******************************************************
static functions
******************************************************/
static Bool
iserror(char*label) {
static char *errors = "+Errors";
int elen = strlen(errors);
int len = strlen(label);
return (len >= elen && !strncmp(label + (len - elen), errors, elen));
}
/* Is 'c' still a valid pointer for a visible column? */
static Bool
validcolumn(Tile*c)
{
return list_contains(wily->down, 0, c);
}
/* Hash from directory name into 'placetable' */
static unsigned long
hashpath(char *path)
{
char *s;
unsigned long hash = 0;
assert(path);
for (s = strrchr(path, '/'); path < s; path++)
hash = (hash << 5) ^ *path;
return hash % TSIZE;
}
static Tile *
find(char *label)
{
Tile *c;
if (label) {
c = placetable[hashpath(label)];
if (validcolumn(c))
return c;
}
return 0;
}
|