Пример #1
0
void
meta_ui_tab_popup_select (MetaTabPopup *popup,
                          MetaTabEntryKey key)
{
  GList *tmp;

  /* Note, "key" may not be in the list of entries; other code assumes
   * it's OK to pass in a key that isn't.
   */

  tmp = popup->entries;
  while (tmp != NULL)
    {
      TabEntry *te;

      te = tmp->data;

      if (te->key == key)
        {
          popup->current = tmp;

          display_entry (popup, te);

          return;
        }

      tmp = tmp->next;
    }
}
Пример #2
0
static void draw_row(int y, int sel, int top, int sbtop, int sbbot)
{
    int i = (y - 4 - VSHIFT) + top;
    int dis = (i < cm->nentries) && is_disabled(cm->menu_entries[i]);

    printf("\033[%d;%dH\1#1\016x\017%s ",
	   y, MARGIN + 1 + HSHIFT,
	   (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3");

    if (i >= cm->nentries) {
	fputs(pad_line("", 0, WIDTH - 2 * MARGIN - 4), stdout);
    } else {
	display_entry(cm->menu_entries[i],
		      (i == sel) ? "\1#5" : dis ? "\2#17" : "\1#3",
		      (i == sel) ? "\1#6" : dis ? "\2#17" : "\1#4",
		      WIDTH - 2 * MARGIN - 4);
    }

    if (cm->nentries <= MENU_ROWS) {
	printf(" \1#1\016x\017");
    } else if (sbtop > 0) {
	if (y >= sbtop && y <= sbbot)
	    printf(" \1#7\016a\017");
	else
	    printf(" \1#1\016x\017");
    } else {
	putchar(' ');		/* Don't modify the scrollbar */
    }
}
Пример #3
0
void
meta_ui_tab_popup_backward (MetaTabPopup *popup)
{
  if (popup->current != NULL)
    popup->current = popup->current->prev;

  if (popup->current == NULL)
    popup->current = g_list_last (popup->entries);

  if (popup->current != NULL)
    {
      TabEntry *te;

      te = popup->current->data;

      display_entry (popup, te);
    }
}
Пример #4
0
void
meta_ui_tab_popup_forward (MetaTabPopup *popup)
{
  if (popup->current != NULL)
    popup->current = popup->current->next;

  if (popup->current == NULL)
    popup->current = popup->entries;

  if (popup->current != NULL)
    {
      TabEntry *te;

      te = popup->current->data;

      display_entry (popup, te);
    }
}
Пример #5
0
void display_results(struct display_t *display, struct search_t *search, int terminal_line_nb)
{
    int i = 0;
    struct entry_t *ptr = search->start;

    for (i = 0; i < display->index; i++)
        ptr = ptr->next;

    for (i = 0; i < terminal_line_nb; i++) {
        if (ptr && display->index + i < search->nbentry) {
            if (i == display->cursor)
                display_entry_with_cursor(ptr, search, i);
             else
                display_entry(ptr, search, i);

            if (ptr->next)
                ptr = ptr->next;
        }
    }
}
int main(int argc, char *argv[])
{
    int i, c;
    char w[MAXLEN], name[MAXLEN];
    char defn[MAXLEN * 15];

    for (c = getword(w, MAXLEN); c != EOF; c = getword(w, MAXLEN)) {
	if (c == DEFINE){
	    c = getword(w, MAXLEN);
	    if (c != NAME)
		printf ("error: name spected\n");
	    strcpy(name, w);
	    _getline(defn, MAXLEN * 15);
	    install(name, defn);
	}
    }


    for (i = 0; i < HASHSIZE; ++i)
	display_entry(i);
    printf ("finished\n");
    return 0;
}
Пример #7
0
static void
sort_and_display_entries(FSP_DIR *dir, const unsigned char dircolor[])
{
	/* fsp_readdir_native in fsplib 0.9 and earlier requires
	 * the third parameter to point to a non-null pointer
	 * even though it does not dereference that pointer
	 * and overwrites it with another one anyway.
	 * http://sourceforge.net/tracker/index.php?func=detail&aid=1875210&group_id=93841&atid=605738
	 * Work around the bug by using non-null &tmp.
	 * Nothing will actually read or write tmp.  */
	FSP_RDENTRY fentry, tmp, *table = NULL;
	FSP_RDENTRY *fresult = &tmp;
	int size = 0;
	int i;

	while (!fsp_readdir_native(dir, &fentry, &fresult)) {
		FSP_RDENTRY *new_table;

		if (!fresult) break;
		if (!strcmp(fentry.name, "."))
			continue;
		new_table = mem_realloc(table, (size + 1) * sizeof(*table));
		if (!new_table)
			continue;
		table = new_table;
		copy_struct(&table[size], &fentry);
		size++;
	}
	/* If size==0, then table==NULL.  According to ISO/IEC 9899:1999
	 * 7.20.5p1, the NULL must not be given to qsort.  */
	if (size > 0)
		qsort(table, size, sizeof(*table), compare);

	for (i = 0; i < size; i++) {
		display_entry(&table[i], dircolor);
	}
}
Пример #8
0
int display_type(int type, int index, char *str)
{
	int i;
	int real_index = 0;

	if (index > num[type])
		return index - num[type];

	i = (first_null[type] >= 0 && index > first_null[type] ?
	     first_null[type] : index);
	real_index = i;
	for (; i < (num[type] + num_null[type])
	     && displayed < DISPLAY_LINES; i++) {
		if (ap[type][i]) {
			if (real_index >= index)
				display_entry(displayed++, ap[type][i], str);
			real_index++;
		}
	}
	index -= num[type];
	if (index < 0)
		index = 0;
	return index;
}
Пример #9
0
static int
CommandProc(struct cmd_syndesc *a_as, void *arock)
{
    int i;
    long code = 0;
    long upos;
    long gpos = 0;
    struct prentry uentry, gentry;
    struct ubik_hdr *uh;
    char *dfile = 0;
    const char *pbase = AFSDIR_SERVER_PRDB_FILEPATH;
    char *pfile = NULL;
    char pbuffer[1028];
    struct cmd_parmdesc *tparm;

    tparm = a_as->parms;

    if (tparm[0].items) {
	wflag++;
	/* so we are treated as admin and can create "mis"owned
	   groups */
	pr_noAuth = 1;
    }
    if (tparm[1].items) {
	flags |= DO_USR;
    }
    if (tparm[2].items) {
	flags |= DO_GRP;
    }
    if (tparm[3].items) {
	flags |= (DO_GRP | DO_MEM);
    }
    if (tparm[4].items) {
	nflag++;
    }
    if (tparm[5].items) {
	flags |= DO_SYS;
    }
    if (tparm[6].items) {
	flags |= DO_OTR;
    }
    if (tparm[7].items) {
	pfile = tparm[7].items->data;
    }
    if (tparm[8].items) {
	dfile = tparm[8].items->data;
    }

    if (pfile == NULL) {
        snprintf(pbuffer, sizeof(pbuffer), "%s.DB0", pbase);
        pfile = pbuffer;
    }
    if ((dbase_fd = open(pfile, (wflag ? O_RDWR : O_RDONLY) | O_CREAT, 0600))
	< 0) {
	fprintf(stderr, "pt_util: cannot open %s: %s\n", pfile,
		strerror(errno));
	exit(1);
    }
    if (read(dbase_fd, buffer, HDRSIZE) < 0) {
	fprintf(stderr, "pt_util: error reading %s: %s\n", pfile,
		strerror(errno));
	exit(1);
    }

    if (dfile) {
	if ((dfp = fopen(dfile, wflag ? "r" : "w")) == 0) {
	    fprintf(stderr, "pt_util: error opening %s: %s\n", dfile,
		    strerror(errno));
	    exit(1);
	}
    } else
	dfp = (wflag ? stdin : stdout);

    uh = (struct ubik_hdr *)buffer;
    if (ntohl(uh->magic) != UBIK_MAGIC)
	fprintf(stderr, "pt_util: %s: Bad UBIK_MAGIC. Is %x should be %x\n",
		pfile, ntohl(uh->magic), UBIK_MAGIC);
    memcpy(&uv, &uh->version, sizeof(struct ubik_version));

    if (wflag && ntohl(uv.epoch) == 0 && ntohl(uv.counter) == 0) {
	uv.epoch = htonl(2); /* a ubik version of 0 or 1 has special meaning */
	memcpy(&uh->version, &uv, sizeof(struct ubik_version));
	lseek(dbase_fd, 0, SEEK_SET);
	if (write(dbase_fd, buffer, HDRSIZE) < 0) {
	    fprintf(stderr, "pt_util: error writing ubik version to %s: %s\n",
		    pfile, strerror(errno));
	    exit(1);
	}
    }

    /* Now that any writeback is done, swap these */
    uv.epoch = ntohl(uv.epoch);
    uv.counter = ntohl(uv.counter);

    fprintf(stderr, "Ubik Version is: %d.%d\n", uv.epoch, uv.counter);
    if (read(dbase_fd, &prh, sizeof(struct prheader)) < 0) {
	fprintf(stderr, "pt_util: error reading %s: %s\n", pfile,
		strerror(errno));
	exit(1);
    }

    Initdb();
    initialize_PT_error_table();

    if (wflag) {
	struct usr_list *u;
	int seenGroup = 0, id = 0, flags = 0;

	while (fgets(buffer, sizeof(buffer), dfp)) {
	    int oid, cid, quota, uid;
	    char name[PR_MAXNAMELEN], mem[PR_MAXNAMELEN];

	    if (isspace(*buffer)) {
		code = sscanf(buffer, "%s %d", mem, &uid);
		if (code != 2) {
		    fprintf(stderr,
			    "Insuffient data provided for group membership\n");
		    exit(1);
		}

		if (!seenGroup) {
		    fprintf(stderr,
			    "Group member %s listed outside of group\n",
			    mem);
		    exit(1);
		}

		for (u = usr_head; u; u = u->next)
		    if (u->uid && u->uid == uid)
			break;
		if (u) {
		    /* Add user - deferred because it is probably foreign */
		    u->uid = 0;
		    if (FindByID(0, uid))
			code = PRIDEXIST;
		    else {
			if (!code
			    && (flags & (PRGRP | PRQUOTA)) ==
			    (PRGRP | PRQUOTA)) {
			    gentry.ngroups++;
			    code = pr_WriteEntry(0, 0, gpos, &gentry);
			    if (code)
				fprintf(stderr,
					"Error setting group count on %s: %s\n",
					name, afs_error_message(code));
			}
			code = CreateEntry(0, u->name, &uid, 1 /*idflag */ ,
					   1 /*gflag */ ,
					   SYSADMINID /*oid */ ,
					   SYSADMINID /*cid */ );
		    }
		    if (code)
			fprintf(stderr, "Error while creating %s: %s\n",
				u->name, afs_error_message(code));
		    continue;
		}
		/* Add user to group */
		if (id == ANYUSERID || id == AUTHUSERID || uid == ANONYMOUSID) {
		    code = PRPERM;
		} else if ((upos = FindByID(0, uid))
			   && (gpos = FindByID(0, id))) {
		    code = pr_ReadEntry(0, 0, upos, &uentry);
		    if (!code)
			code = pr_ReadEntry(0, 0, gpos, &gentry);
		    if (!code)
			code = AddToEntry(0, &gentry, gpos, uid);
		    if (!code)
			code = AddToEntry(0, &uentry, upos, id);
		} else
		    code = PRNOENT;

		if (code)
		    fprintf(stderr, "Error while adding %s to %s: %s\n", mem,
			    name, afs_error_message(code));
	    } else {
		code = sscanf(buffer, "%s %d/%d %d %d %d", name, &flags, &quota, &id,
			      &oid, &cid);
		if (code != 6) {
		    fprintf(stderr,
			    "Insufficient data provided for user/group\n");
		    exit(1);
		}

		seenGroup = 1;

		if (FindByID(0, id))
		    code = PRIDEXIST;
		else
		    code = CreateEntry(0, name, &id, 1 /*idflag */ ,
				       flags & PRGRP, oid, cid);
		if (code == PRBADNAM) {
		    u = malloc(sizeof(struct usr_list));
		    u->next = usr_head;
		    u->uid = id;
		    strcpy(u->name, name);
		    usr_head = u;
		} else if (code) {
		    fprintf(stderr, "Error while creating %s: %s\n", name,
			    afs_error_message(code));
		} else if ((flags & PRACCESS)
			   || (flags & (PRGRP | PRQUOTA)) ==
			   (PRGRP | PRQUOTA)) {
		    gpos = FindByID(0, id);
		    code = pr_ReadEntry(0, 0, gpos, &gentry);
		    if (!code) {
			gentry.flags = flags;
			gentry.ngroups = quota;
			code = pr_WriteEntry(0, 0, gpos, &gentry);
		    }
		    if (code)
			fprintf(stderr,
				"Error while setting flags on %s: %s\n", name,
				afs_error_message(code));
		}
	    }
	}
	for (u = usr_head; u; u = u->next)
	    if (u->uid)
		fprintf(stderr, "Error while creating %s: %s\n", u->name,
			afs_error_message(PRBADNAM));
    } else {
	for (i = 0; i < HASHSIZE; i++) {
	    upos = nflag ? ntohl(prh.nameHash[i]) : ntohl(prh.idHash[i]);
	    while (upos) {
		long newpos;
		newpos = display_entry(upos);
		if (newpos == upos) {
		    fprintf(stderr, "pt_util: hash error in %s chain %d\n",
			    nflag ? "name":"id", i);
		    exit(1);
		} else
		    upos = newpos;
	    }
	}
	if (flags & DO_GRP)
	    display_groups();
    }

    lseek(dbase_fd, 0, L_SET);	/* rewind to beginning of file */
    if (read(dbase_fd, buffer, HDRSIZE) < 0) {
	fprintf(stderr, "pt_util: error reading %s: %s\n", pfile,
		strerror(errno));
	exit(1);
    }
    uh = (struct ubik_hdr *)buffer;

    uh->version.epoch = ntohl(uh->version.epoch);
    uh->version.counter = ntohl(uh->version.counter);

    if ((uh->version.epoch != uv.epoch)
	|| (uh->version.counter != uv.counter)) {
	fprintf(stderr,
		"pt_util: Ubik Version number changed during execution.\n");
	fprintf(stderr, "Old Version = %d.%d, new version = %d.%d\n",
		uv.epoch, uv.counter, uh->version.epoch, uh->version.counter);
    }
    close(dbase_fd);
    exit(0);
}
Пример #10
0
// Handle sniff message
short lister_handle_sniff(Lister *lister,SniffData *data)
{
	DirEntry *entry;
	long off;
	short show=0;

	// Find entry
	if ((entry=find_entry(&data->buffer->entry_list,data->name,&off,data->buffer->more_flags&DWF_CASE)))
	{
		char *version=0,*type=0;
		char buf[40];

		// Got a filetype?
		if (data->type || *data->type_name)
		{
			// Get name pointer
			if ((type=(data->type)?data->type->type.name:data->type_name) && *type)
			{
				// Set filetype description
				direntry_add_string(data->buffer,entry,DE_Filetype,type);

				// Directory sorted by filetype?
				if (data->buffer->buf_ListFormat.sort.sort==DISPLAY_FILETYPE)
				{
					// Remove entry
					remove_file_entry(data->buffer,entry);

					// Add it again
					add_file_entry(data->buffer,entry,0);
					show|=SNIFFF_SHOW;
				}
			}
		}

		// Got a version?
		if (data->flags&SNIFFF_VERSION)
		{
			// Set version
			direntry_add_version(data->buffer,entry,data->ver,data->rev,data->days);

			// Build version string
			build_version_string(buf,data->ver,data->rev,data->days,-1);
			version=buf;

			// Directory sorted by version?
			if (data->buffer->buf_ListFormat.sort.sort==DISPLAY_VERSION)
			{
				// Remove entry
				remove_file_entry(data->buffer,entry);

				// Add it again
				add_file_entry(data->buffer,entry,0);
				show|=SNIFFF_SHOW;
			}
		}

		// Is buffer currently visible?
		if (lister->cur_buffer==data->buffer &&
			!(lister->flags&LISTERF_VIEW_ICONS))
		{
			short len;

			// Type field changed, and don't have a custom width for filetype field?
			if (type && *type && !(data->buffer->buf_CustomWidthFlags&(1<<DISPLAY_FILETYPE)))
			{
				short old;

				// Get new field size
				old=data->buffer->buf_FieldWidth[DISPLAY_FILETYPE];
				lister_check_max_length(lister,type,&len,DISPLAY_FILETYPE);
				old-=data->buffer->buf_FieldWidth[DISPLAY_FILETYPE];

				// Field needs to be bigger?
				if (old<0)
				{
					// Add to width
					data->buffer->buf_HorizLength-=old;
					if (data->buffer->type_length<len)
						data->buffer->type_length=len;
					show|=SNIFFF_SLIDERS;
				}
			}

			// Same for version field
			if (version && !(data->buffer->buf_CustomWidthFlags&(1<<DISPLAY_VERSION)))
			{
				short old;

				// Get new field size
				old=data->buffer->buf_FieldWidth[DISPLAY_VERSION];
				lister_check_max_length(lister,version,&len,DISPLAY_VERSION);
				old-=data->buffer->buf_FieldWidth[DISPLAY_VERSION];

				// Field needs to be bigger?
				if (old<0)
				{
					// Add to width
					data->buffer->buf_HorizLength-=old;
					if (data->buffer->version_length<len)
						data->buffer->version_length=len;
					show|=SNIFFF_SLIDERS;
				}
			}

			// Update slider?
			if (show&SNIFFF_SLIDERS)
				show|=SNIFFF_SHOW;

			// Don't need to redraw?	
			else
			if (!(show&SNIFFF_SHOW))
			{
				// Is entry visible?
				if (off>=lister->cur_buffer->buf_VertOffset &&
					off<lister->cur_buffer->buf_VertOffset+lister->text_height)
				{
					// Show entry
					display_entry(entry,lister,off-lister->cur_buffer->buf_VertOffset);
				}
			}
		}
		else show=0;
	}

	return show;
}