示例#1
0
static int
get_percentage(const char *url)
{
    void *db = metadb_get();
    int remain, done;
    int rval;
    if(db == NULL)
        return 0;

    remain = count_items(db,
                         "SELECT count(*) "
                         "FROM item "
                         "WHERE url LIKE ?1 "
                         "AND contenttype = 1 "
                         "AND indexstatus == 0",
                         url);
    if(remain) {
        done = count_items(db,
                           "SELECT count(*) "
                           "FROM item "
                           "WHERE url LIKE ?1 "
                           "AND contenttype = 1 "
                           "AND indexstatus > 1",
                           url);
        rval = MIN(done * 100 / (done+remain), 100);
    } else {
        rval = 100;
    }
    metadb_close(db);
    return rval;
}
示例#2
0
static av_cold int init(AVFilterContext *ctx)
{
    AudioEchoContext *s = ctx->priv;
    int nb_delays, nb_decays, i;

    if (!s->delays || !s->decays) {
        av_log(ctx, AV_LOG_ERROR, "Missing delays and/or decays.\n");
        return AVERROR(EINVAL);
    }

    count_items(s->delays, &nb_delays);
    count_items(s->decays, &nb_decays);

    s->delay = av_realloc_f(s->delay, nb_delays, sizeof(*s->delay));
    s->decay = av_realloc_f(s->decay, nb_decays, sizeof(*s->decay));
    if (!s->delay || !s->decay)
        return AVERROR(ENOMEM);

    fill_items(s->delays, &nb_delays, s->delay);
    fill_items(s->decays, &nb_decays, s->decay);

    if (nb_delays != nb_decays) {
        av_log(ctx, AV_LOG_ERROR, "Number of delays %d differs from number of decays %d.\n", nb_delays, nb_decays);
        return AVERROR(EINVAL);
    }

    s->nb_echoes = nb_delays;
    if (!s->nb_echoes) {
        av_log(ctx, AV_LOG_ERROR, "At least one decay & delay must be set.\n");
        return AVERROR(EINVAL);
    }

    s->samples = av_realloc_f(s->samples, nb_delays, sizeof(*s->samples));
    if (!s->samples)
        return AVERROR(ENOMEM);

    for (i = 0; i < nb_delays; i++) {
        if (s->delay[i] <= 0 || s->delay[i] > 90000) {
            av_log(ctx, AV_LOG_ERROR, "delay[%d]: %f is out of allowed range: (0, 90000]\n", i, s->delay[i]);
            return AVERROR(EINVAL);
        }
        if (s->decay[i] <= 0 || s->decay[i] > 1) {
            av_log(ctx, AV_LOG_ERROR, "decay[%d]: %f is out of allowed range: (0, 1]\n", i, s->decay[i]);
            return AVERROR(EINVAL);
        }
    }

    s->next_pts = AV_NOPTS_VALUE;

    av_log(ctx, AV_LOG_DEBUG, "nb_echoes:%d\n", s->nb_echoes);
    return 0;
}
示例#3
0
static struct child* find_index(struct folder *start, int index, struct folder **parent)
{
    int i = 0;

    *parent = NULL;

    while (i < start->children_count)
    {
        struct child *foo = &start->children[i];
        if (i == index)
        {
            *parent = start;
            return foo;
        }
        i++;
        if (foo->state == EXPANDED)
        {
            struct child *bar = find_index(foo->folder, index - i, parent);
            if (bar)
            {
                return bar;
            }
            index -= count_items(foo->folder);
        }
    }
    return NULL;
}
示例#4
0
struct folder* load_root(void)
{
    static struct child root_child;

    root_child.name = "/";
    root_child.folder = NULL;
    root_child.state = COLLAPSED;

    static struct folder root = {
        .name = "",
        .children = &root_child,
        .children_count = 1,
        .depth = -1,
        .previous = NULL,
    };

    return &root;
}

static int count_items(struct folder *start)
{
    int count = 0;
    int i;

    for (i=0; i<start->children_count; i++)
    {
        struct child *foo = &start->children[i];
        if (foo->state == EXPANDED)
            count += count_items(foo->folder);
        count++;
    }
    return count;
}
示例#5
0
/* Returns the number of items in a single- or multi-dimensional sequence. */
static int count_items(PyObject *seq, int dim)
{
	int totitem = 0;

	if (dim > 1) {
		const Py_ssize_t seq_size = PySequence_Size(seq);
		Py_ssize_t i;
		for (i = 0; i < seq_size; i++) {
			PyObject *item = PySequence_GetItem(seq, i);
			if (item) {
				const int tot = count_items(item, dim - 1);
				Py_DECREF(item);
				if (tot != -1) {
					totitem += tot;
				}
				else {
					totitem = -1;
					break;
				}
			}
			else {
				totitem = -1;
				break;
			}
		}
	}
	else {
		totitem = PySequence_Size(seq);
	}

	return totitem;
}
示例#6
0
static void
rebuild_menu (RBDisplayPageMenu *menu)
{
	int oldnum;
	oldnum = menu->priv->item_count;
	menu->priv->item_count = count_items (menu, G_MAXINT);
	rb_debug ("building menu, %d => %d items", oldnum, menu->priv->item_count);
	g_menu_model_items_changed (G_MENU_MODEL (menu), 0, oldnum, menu->priv->item_count);
}
示例#7
0
文件: cf_append.c 项目: edhodapp/cf
CF_appendcf(CF a0, ...)
{
  unsigned count_items(va_list *);
  unsigned n;
  va_list va;

  va_start(va, a0);
  n = 1 + count_items(&va);
  va_end(va);
}
示例#8
0
static void
row_deleted_cb (GtkTreeModel *model, GtkTreePath *path, RBDisplayPageMenu *menu)
{
	int index = path_menu_index (menu, path);
	if (index != -1) {
		if (count_items (menu, G_MAXINT) != menu->priv->item_count) {
			menu->priv->item_count--;
			g_menu_model_items_changed (G_MENU_MODEL (menu), index, 1, 0);
		}
	}
}
int receptionist(struct char_data *ch, int cmd, char *arg)
{
  struct char_data *recep = 0;
  static sh_int action_tabel[9] = {23,24,36,105,106,109,111,142,147};
  
  if (!ch->desc)
    return(FALSE); /* You've forgot FALSE - NPC couldn't leave */
  
  recep=FindMobInRoomWithFunction(ch->in_room,receptionist);
  
  if (!recep) {
    log("No receptionist.\n");
    exit(1);
  }
  
  if (IS_NPC(ch))
    return(FALSE);
  
  if (cmd != 92) {
    if (!number(0, 30))
      do_action(recep, "", action_tabel[number(0,8)]);
    return(FALSE);
  }
  
  if (!AWAKE(recep)) {
    act("$e isn't able to talk to you...", FALSE, recep, 0, ch, TO_VICT);
    return(TRUE);
  }
  if (!CAN_SEE(recep, ch)) 
    {
      act("$n says, 'I don't deal with people I can't see!'", FALSE, recep, 0, 0, TO_ROOM);
      return(TRUE);
    }
  
  if (cmd == 92) { /* Rent  */
    if(count_items(ch) > 150){
      act("$n tells you, 'You have too many items to rent.'", FALSE, recep, 0,
        ch, TO_VICT);
      return(TRUE);
    }
    act("$n stores your stuff in the safe, and helps you into your chamber.", FALSE, recep, 0, ch, TO_VICT);
    act("$n helps $N into $S private chamber.",FALSE, recep,0,ch,TO_NOTVICT);
    rent_char(ch);
    ch->specials.was_in_room=ch->in_room;
    extract_char(ch);
  } else {         /* Offer */
    act("$n tells you - Rent is free... for now...",FALSE,recep,0,ch,TO_VICT);
  }
  
  return(TRUE);
}
示例#10
0
bool folder_select(char* setting, int setting_len)
{
    struct folder *root;
    struct simplelist_info info;
    size_t buf_size;
    /* 32 separate folders should be Enough For Everybody(TM) */
    char *vect[32];
    char copy[setting_len];
    int nb_items;

    /* copy onto stack as split_string() modifies it */
    strlcpy(copy, setting, setting_len);
    nb_items = split_string(copy, ':', vect, ARRAYLEN(vect));

    buffer_front = plugin_get_buffer(&buf_size);
    buffer_end = buffer_front + buf_size;
    root = load_root();

    if (nb_items > 0)
    {
        for(int i = 0; i < nb_items; i++)
            select_paths(root, vect[i]);
    }

    simplelist_info_init(&info, str(LANG_SELECT_FOLDER),
            count_items(root), root);
    info.get_name = folder_get_name;
    info.action_callback = folder_action_callback;
    info.get_icon = folder_get_icon;
    simplelist_show_list(&info);

    /* done editing. check for changes */
    save_folders(root, copy, setting_len);
    if (strcmp(copy, setting))
    {   /* prompt for saving changes and commit if yes */
        if (yesno_pop(ID2P(LANG_SAVE_CHANGES)))
        {
            strcpy(setting, copy);
            settings_save();
            return true;
        }
    }
    return false;
}
示例#11
0
static int
path_menu_index (RBDisplayPageMenu *menu, GtkTreePath *path)
{
	GtkTreePath *root;
	GtkTreePath *compare;
	int depth;
	int *indices;
	int index;

	compare = gtk_tree_path_copy (path);
	if (gtk_tree_path_up (compare) == FALSE) {
		gtk_tree_path_free (compare);
		return -1;
	}

	if (gtk_tree_path_get_depth (compare) == 0) {
		gtk_tree_path_free (compare);
		return -1;
	}

	root = get_root_path (menu);
	if (root == NULL) {
		gtk_tree_path_free (compare);
		return -1;
	}

	if (gtk_tree_path_compare (compare, root) != 0) {
		gtk_tree_path_free (root);
		gtk_tree_path_free (compare);
		return -1;
	}

	indices = gtk_tree_path_get_indices_with_depth (path, &depth);
	index = count_items (menu, indices[depth-1]);
	gtk_tree_path_free (root);
	gtk_tree_path_free (compare);
	return index;
}
int main(int argc, char *argv[])
{
  // Open the file.
  FILE *fp = 0;
  if ((fp = fopen(argv[1], "r")) == 0)
  {
    fprintf(stderr, "ERROR: The input file specified cannot be opened.\n");
    return -1;
  }

  int line_count = 0, item_count = 0;
  char buffer[256];
  while (fgets(buffer, 256, fp) != NULL)
  {
    //printf("Next line: %s", buffer);
    ++line_count;
    item_count += count_items(buffer);
  }

  printf("Summary:\n");
  printf("Line count: %d\n", line_count);
  printf("Item count: %d\n", item_count);
  return 0;
}
示例#13
0
static int folder_action_callback(int action, struct gui_synclist *list)
{
    struct folder *root = (struct folder*)list->data;
    struct folder *parent;
    struct child *this = find_index(root, list->selected_item, &parent), *child;
    int i;

    if (action == ACTION_STD_OK)
    {
        switch (this->state)
        {
            case EXPANDED:
                this->state = SELECTED;
                break;
            case SELECTED:
                this->state = COLLAPSED;
                break;
            case COLLAPSED:
                if (this->folder == NULL)
                    this->folder = load_folder(parent, this->name);
                this->state = this->folder ? (this->folder->children_count == 0 ?
                        SELECTED : EXPANDED) : EACCESS;
                break;
            case EACCESS:
                /* cannot open, do nothing */
                return action;
        }
        list->nb_items = count_items(root);
        return ACTION_REDRAW;
    }
    else if (action == ACTION_STD_CONTEXT)
    {
        switch (this->state)
        {
            case EXPANDED:
                for (i = 0; i < this->folder->children_count; i++)
                {
                    child = &this->folder->children[i];
                    if (child->state == SELECTED ||
                        child->state == EXPANDED)
                        child->state = COLLAPSED;
                    else if (child->state == COLLAPSED)
                        child->state = SELECTED;
                }
                break;
            case SELECTED:
            case COLLAPSED:
                if (this->folder == NULL)
                    this->folder = load_folder(parent, this->name);
                this->state = this->folder ? (this->folder->children_count == 0 ?
                        SELECTED : EXPANDED) : EACCESS;
                if (this->state == EACCESS)
                    break;
                for (i = 0; i < this->folder->children_count; i++)
                {
                    child = &this->folder->children[i];
                    child->state = SELECTED;
                }
                break;
            case EACCESS:
                /* cannot open, do nothing */
                return action;
        }
        list->nb_items = count_items(root);
        return ACTION_REDRAW;
    }
            
        
    return action;
}
示例#14
0
boolean item_print(WINDOW *wd, int n, int *list)
{
	int i = 0, button, result = 0;
	boolean noerror = TRUE;

	/* DjV 031 070203 ---vvv--- */
	/* XDINFO info; */
	long nfiles=0, nfolders=0, nbytes=0, error;
	const char *name;
	/* DjV 031 070203 ---^^^--- */

	if (check_print(wd, n, list) == FALSE)
		return FALSE;

	/* DjV 031 080203 ---vvv--- */

	/* rsc_ltoftext(print, NITEMS, n); */

	/* xd_open(print, &info); */
	if ( count_items(wd, n, list, &nfolders, &nfiles, &nbytes) )	/* HR 151102: always display. */
	{	/* DjV 031 140203 */

		cv_fntoform ( copyinfo + CPFOLDER, fn_get_name(dir_path(wd)) );	  	/* DjV 031 140203 */
		cv_fntoform ( copyinfo + CPFILE, itm_name(wd, list[0]) ); 			/* DjV 031 140203 */

		button = open_cfdialog( CF_PRINT, 0L, (long)n, nbytes, CMD_PRINT ); /* DJV 031 070203 */
	} /* DjV 031 140203 */
	else
		button = 0;

	/* if (button == PRINTOK) */ 
	if ( button == COPYOK ) 
	/* DjV 031 080203 ---^^^--- */
	{
		if ((i < n) && (result != XFATAL) && (result != XABORT))
		{
			/* DjV 031 080203 ---vvv--- */
			name = itm_name(wd, list[i]);
			upd_name( dir_path(wd), CPFOLDER );	
			upd_name ( name, CPFILE ); 
			/* DjV 031 080203 ---^^^--- */

			result = print_file(wd, list[i]);

			if (result == XFATAL)
				noerror = FALSE;

			/* DJV 031 070203 150203 ---vvv--- */
			/* 
			rsc_ltoftext(print, NITEMS, n - i - 1);
			xd_draw(&info, NITEMS, 1);
			*/
			if ((error = itm_attrib(wd, list[i], 0, &pattr)) == 0)
			{
				nbytes -= pattr.size;
				upd_copyinfo ( 0L, n - i - 1, nbytes ); 
			}
			else
				result = copy_error(error, name, 0); /* 0= any op but move or delete is "copy" */
			/* DjV 031 070203 150203 ---^^^--- */

			i++;
		}
	}
	else
		noerror = FALSE;

	/* DjV 031 070203 ---vvv--- */
	/*
	xd_change(&info, button, NORMAL, 0);
	xd_close(&info);
	*/
	if ( button != 0 )
		close_cfdialog( button );
	/* DjV 031 070203 ---^^^--- */

	return noerror;
}
示例#15
0
/* Modifies property array length if needed and PROP_DYNAMIC flag is set. */
static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop,
                                 int lvalue_dim, int *totitem, const char *error_prefix)
{
	int dimsize[MAX_ARRAY_DIMENSION];
	int tot, totdim, len;

	totdim = RNA_property_array_dimension(ptr, prop, dimsize);
	tot = count_items(rvalue, totdim - lvalue_dim);

	if (tot == -1) {
		PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, error validating the sequence length",
		             error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
		return -1;
	}
	else if ((RNA_property_flag(prop) & PROP_DYNAMIC) && lvalue_dim == 0) {
		if (RNA_property_array_length(ptr, prop) != tot) {
#if 0
			/* length is flexible */
			if (!RNA_property_dynamic_array_set_length(ptr, prop, tot)) {
				/* BLI_snprintf(error_str, error_str_size,
				 *              "%s.%s: array length cannot be changed to %d",
				 *              RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot); */
				PyErr_Format(PyExc_ValueError, "%s %s.%s: array length cannot be changed to %d",
				             error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot);
				return -1;
			}
#else
			*totitem = tot;
			return 0;

#endif
		}

		len = tot;
	}
	else {
		/* length is a constraint */
		if (!lvalue_dim) {
			len = RNA_property_array_length(ptr, prop);
		}
		/* array item assignment */
		else {
			int i;

			len = 1;

			/* arr[3][4][5]
			 *
			 *    arr[2] = x
			 *    dimsize = {4, 5}
			 *    dimsize[1] = 4
			 *    dimsize[2] = 5
			 *    lvalue_dim = 0, totdim = 3
			 * 
			 *    arr[2][3] = x
			 *    lvalue_dim = 1
			 * 
			 *    arr[2][3][4] = x
			 *    lvalue_dim = 2 */
			for (i = lvalue_dim; i < totdim; i++)
				len *= dimsize[i];
		}

		if (tot != len) {
			/* BLI_snprintf(error_str, error_str_size, "sequence must have length of %d", len); */
			PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, sequence must have %d items total, not %d",
			             error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), len, tot);
			return -1;
		}
	}

	*totitem = len;

	return 0;
}
示例#16
0
文件: ext_apc.cpp 项目: TSMG1972/hhvm
EXTERNALLY_VISIBLE
void apc_load_impl(struct cache_info *info,
                   const char **int_keys, long long *int_values,
                   const char **char_keys, char *char_values,
                   const char **strings, const char **objects,
                   const char **thrifts, const char **others) {
  if (!apcExtension::ForceConstLoadToAPC) {
    if (apcExtension::EnableConstLoad && info && info->use_const) return;
  }
  auto& s = s_apc_store[0];
  {
    int count = count_items(int_keys, 2);
    if (count) {
      vector<KeyValuePair> vars(count);
      const char **k = int_keys;
      long long*v = int_values;
      for (int i = 0; i < count; i++, k += 2) {
        auto& item = vars[i];
        item.key = *k;
        item.len = (int)(int64_t)*(k+1);
        s.constructPrime(*v++, item);
      }
      s.prime(vars);
    }
  }
  {
    int count = count_items(char_keys, 2);
    if (count) {
      vector<KeyValuePair> vars(count);
      const char **k = char_keys;
      char *v = char_values;
      for (int i = 0; i < count; i++, k += 2) {
        auto& item = vars[i];
        item.key = *k;
        item.len = (int)(int64_t)*(k+1);
        switch (*v++) {
        case 0: s.constructPrime(false, item); break;
        case 1: s.constructPrime(true , item); break;
        case 2: s.constructPrime(uninit_null() , item); break;
        default:
          throw Exception("bad apc archive, unknown char type");
        }
      }
      s.prime(vars);
    }
  }
  {
    int count = count_items(strings, 4);
    if (count) {
      vector<KeyValuePair> vars(count);
      const char **p = strings;
      for (int i = 0; i < count; i++, p += 4) {
        auto& item = vars[i];
        item.key = *p;
        item.len = (int)(int64_t)*(p+1);
        // Strings would be copied into APC anyway.
        String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
        s.constructPrime(value, item, false);
      }
      s.prime(vars);
    }
  }
  {
    int count = count_items(objects, 4);
    if (count) {
      vector<KeyValuePair> vars(count);
      const char **p = objects;
      for (int i = 0; i < count; i++, p += 4) {
        auto& item = vars[i];
        item.key = *p;
        item.len = (int)(int64_t)*(p+1);
        String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
        s.constructPrime(value, item, true);
      }
      s.prime(vars);
    }
  }
  {
    int count = count_items(thrifts, 4);
    if (count) {
      vector<KeyValuePair> vars(count);
      const char **p = thrifts;
      for (int i = 0; i < count; i++, p += 4) {
        auto& item = vars[i];
        item.key = *p;
        item.len = (int)(int64_t)*(p+1);
        String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
        Variant success;
        Variant v = f_fb_unserialize(value, ref(success));
        if (same(success, false)) {
          throw Exception("bad apc archive, f_fb_unserialize failed");
        }
        s.constructPrime(v, item);
      }
      s.prime(vars);
    }
  }
  {
    int count = count_items(others, 4);
    if (count) {
      vector<KeyValuePair> vars(count);
      const char **p = others;
      for (int i = 0; i < count; i++, p += 4) {
        auto& item = vars[i];
        item.key = *p;
        item.len = (int)(int64_t)*(p+1);

        String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
        Variant v = unserialize_from_string(value);
        if (same(v, false)) {
          // we can't possibly get here if it was a boolean "false" that's
          // supposed to be serialized as a char
          throw Exception("bad apc archive, unserialize_from_string failed");
        }
        s.constructPrime(v, item);
      }
      s.prime(vars);
    }
  }
}
示例#17
0
static turn_command_t process_input_map(game_t * game, int input)
{
    int move;
    item_t ** itemsel;

    switch (input)
    {
        case 'Q':
            if (prompt_yn("Do you want to quit?"))
                return turn_command_quit;
            return turn_command_void;

        case 'g':
        case ',':
            ;
            item_t * item = game->level->map[game->player.mob->position.y * game->level->width + game->player.mob->position.x].item;

            if (item == 0)
            {
                print_msg("Nothing here!");
                return turn_command_void;
            }

            char item_n[100];
            char line[MSGLEN];

            item_name(item_n, item);

            if (!try_give_item(&(game->player), item))
            {
                print_msg("You're carrying too much shit already.");
                wait();
            }
            else
            {
                snprintf(line, MSGLEN,
                         "Okay -- you now have %s.", item_n);
                print_msg(line);
                wait();
                game->level->map[game->player.mob->position.y * game->level->width + game->player.mob->position.x].item = 0;
            }

            clear_msg();
            return turn_command_complete;

        case 'd':
        case 'u':
            if (count_items(&(game->player)) == 0)
            {
                print_msg("You have no items.");
                return turn_command_void;
            }

            if (input == 'd')
                print_msg("Drop which item?");
            else if (input == 'u')
                print_msg("Use which item?");

            itemsel = list_and_select_items(&(game->player), game->player.inventory);

            /* restore view */
            clear_msg();
            draw_map(game->input_type, game->level);

            if (itemsel != NULL)
            {
                if (input == 'd')
                    drop_item(&(game->player), game->level, itemsel);
                else if (input == 'u')
                    use_item(game, itemsel);

                return turn_command_complete;
            }
            return turn_command_void;

        case '.':
            /* Rest/wait/meditate */
            return turn_command_complete;


        case ' ':
            //clear_msg();
            return turn_command_void;

        case '+':
            chaos_duel();
            return turn_command_void;

        case KEY_LEFT:
        case KEY_RIGHT:
        case KEY_UP:
        case KEY_DOWN:
            move = player_move(game, input);
            return move;

        default:
            return turn_command_void;
    }
}
示例#18
0
文件: gtkam-save.c 项目: ndim/gtkam
static void
on_ok_clicked (GtkButton *button, GtkamSave *save)
{
	guint i, count, j = 1;
	int result = -1;
	GtkWidget *s, *dialog;
	unsigned int id = 0;
	GtkamSaveData *data;
	gchar *progname, *command;
	GError *error = NULL;

	if (count_items (save) == 0) {
		if (!save->priv->err_shown) {
			
			dialog = gtkam_error_new (result, NULL,
					GTK_WIDGET (save), _("There is nothing to be saved."));
			gtk_widget_show (dialog);
		}

		return;
	}
			
	store_save_settings(save);
	gtk_widget_hide (GTK_WIDGET (save));

	count = g_slist_length (save->priv->data);
	if (count == 1)
		s = gtkam_cancel_new (_("Downloading file"));
	else
		s = gtkam_cancel_new (_("Downloading %i files"), count);
	gtk_window_set_transient_for (GTK_WINDOW (s), save->priv->main_window);
	gtk_widget_show (s);

	if (count > 1)
		id = gp_context_progress_start (
			GTKAM_CANCEL (s)->context->context, count,
			_("Downloading %i files..."), count);

	if (!save->priv->toggle_filename_camera->active)
		j = gtk_spin_button_get_value_as_int (
				GTK_SPIN_BUTTON (save->priv->spin_entry));
	
	for (i = 0; i < count; i++) {
		data = g_slist_nth_data (save->priv->data, i);

		/* Check for shutdown */
		if (!GTKAM_IS_SAVE (save))
			return;

		if (save->priv->toggle_normal &&
		    save->priv->toggle_normal->active)
			result = get_file (save, data->camera,
				  data->folder, data->name,
				  GP_FILE_TYPE_NORMAL, i + j,
				  GTKAM_CANCEL (s)->context);
		if (save->priv->toggle_preview &&
		    save->priv->toggle_preview->active &&
		    (!result < 0))
			result = get_file (save, data->camera,
				  data->folder, data->name,
				  GP_FILE_TYPE_PREVIEW, i + j,
				  GTKAM_CANCEL (s)->context);
		if (save->priv->toggle_raw &&
		    save->priv->toggle_raw->active &&
		    (!result < 0))
			result = get_file (save, data->camera,
				  data->folder, data->name, GP_FILE_TYPE_RAW,
				  i + j, GTKAM_CANCEL (s)->context);
		if (save->priv->toggle_audio &&
		    save->priv->toggle_audio->active &&
		    (!result < 0))
			result = get_file (save, data->camera,
				  data->folder, data->name, GP_FILE_TYPE_AUDIO,
				  i + j, GTKAM_CANCEL (s)->context);
		if (save->priv->toggle_exif &&
		    save->priv->toggle_exif->active &&
		    (!result < 0))
			result = get_file (save, data->camera,
				  data->folder, data->name, GP_FILE_TYPE_EXIF,
				  i + j, GTKAM_CANCEL (s)->context);

		if (result < 0)
		{
			if (count > 1)
				gp_context_progress_stop (GTKAM_CANCEL (s)->context->context, id);
			if (!save->priv->err_shown) {
				dialog = gtkam_error_new (result, GTKAM_CANCEL (s)->context,
						GTK_WIDGET (save), _("Problem getting '%s' "
						"from folder '%s'."),
						data->name, data->folder);
				gtk_widget_show (dialog);
				save->priv->err_shown = TRUE;
			}
	
			gtk_object_destroy (GTK_OBJECT (s));
			gtk_object_destroy (GTK_OBJECT (save));
			return;
		}
		
		if (count > 1)
			gp_context_progress_update (
				GTKAM_CANCEL (s)->context->context, id, i + 1);
		gp_context_idle (GTKAM_CANCEL (s)->context->context);
		if (gp_context_cancel (GTKAM_CANCEL (s)->context->context) ==
				GP_CONTEXT_FEEDBACK_CANCEL)
			break;
	}
	if (count > 1)
		gp_context_progress_stop (
				GTKAM_CANCEL (s)->context->context, id);
	
	gtk_object_destroy (GTK_OBJECT (s));

	/* If file(s) were saved and a program specified, load the program
   passing the filenames */
	if (result >= 0)
	{
		progname = gtk_entry_get_text (save->priv->program);

		if (progname && progname[0] != '\0') {
			command = g_strdup_printf ("%s%s", progname, save->priv->filelist->str);

			/* FIXME Report any arising errors */
			if (!g_spawn_command_line_async (command, &error)) {
				g_warning ("Error running command\n");
				g_error_free (error);
			}
			
			g_free (command);
			g_string_free (save->priv->filelist, TRUE);
		} 
	}
	
	gtk_object_destroy (GTK_OBJECT (save));
}
示例#19
0
文件: ext_apc.cpp 项目: TSMG1972/hhvm
EXTERNALLY_VISIBLE
void const_load_impl(struct cache_info *info,
                     const char **int_keys, long long *int_values,
                     const char **char_keys, char *char_values,
                     const char **strings, const char **objects,
                     const char **thrifts, const char **others) {
  if (!apcExtension::EnableConstLoad || !info || !info->use_const) return;
  {
    int count = count_items(int_keys, 2);
    if (count) {
      const char **k = int_keys;
      long long* v = int_values;
      for (int i = 0; i < count; i++, k += 2) {
        String key(*k, (int)(int64_t)*(k+1), CopyString);
        int64_t value = *v++;
        const_load_set(key, value);
      }
    }
  }
  {
    int count = count_items(char_keys, 2);
    if (count) {
      const char **k = char_keys;
      char *v = char_values;
      for (int i = 0; i < count; i++, k += 2) {
        String key(*k, (int)(int64_t)*(k+1), CopyString);
        Variant value;
        switch (*v++) {
        case 0: value = false; break;
        case 1: value = true; break;
        case 2: value = uninit_null(); break;
        default:
          throw Exception("bad apc archive, unknown char type");
        }
        const_load_set(key, value);
      }
    }
  }
  {
    int count = count_items(strings, 4);
    if (count) {
      const char **p = strings;
      for (int i = 0; i < count; i++, p += 4) {
        String key(*p, (int)(int64_t)*(p+1), CopyString);
        String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
        const_load_set(key, value);
      }
    }
  }
  // unserialize_from_string object is extremely slow here;
  // currently turned off: no objects in haste_maps.
  if (false) {
    int count = count_items(objects, 4);
    if (count) {
      const char **p = objects;
      for (int i = 0; i < count; i++, p += 4) {
        String key(*p, (int)(int64_t)*(p+1), CopyString);
        String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
        const_load_set(key, unserialize_from_string(value));
      }
    }
  }
  {
    int count = count_items(thrifts, 4);
    if (count) {
      vector<KeyValuePair> vars(count);
      const char **p = thrifts;
      for (int i = 0; i < count; i++, p += 4) {
        String key(*p, (int)(int64_t)*(p+1), CopyString);
        String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
        Variant success;
        Variant v = f_fb_unserialize(value, ref(success));
        if (same(success, false)) {
          throw Exception("bad apc archive, f_fb_unserialize failed");
        }
        const_load_set(key, v);
      }
    }
  }
  {//Would we use others[]?
    int count = count_items(others, 4);
    if (count) {
      const char **p = others;
      for (int i = 0; i < count; i++, p += 4) {
        String key(*p, (int)(int64_t)*(p+1), CopyString);
        String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
        Variant v = unserialize_from_string(value);
        if (same(v, false)) {
          throw Exception("bad apc archive, unserialize_from_string failed");
        }
        const_load_set(key, v);
      }
    }
  }
}