Пример #1
0
static void menu_action_setting_disp_set_label(file_list_t* list,
      unsigned *w, unsigned type, unsigned i,
      const char *label,
      char *s, size_t len,
      const char *entry_label,
      const char *path,
      char *s2, size_t len2)
{
   rarch_system_info_t *system = rarch_system_info_get_ptr();
   uint32_t hash_label  = menu_hash_calculate(label);
   global_t *global = global_get_ptr();

   *s = '\0';
   *w = 19;

   switch (hash_label)
   {
      case MENU_LABEL_LOAD_CONTENT_HISTORY:
         *w = strlen(label);
         break;
      case MENU_LABEL_SYSTEM_INFORMATION:
         *w = 2;
         break;
      case MENU_LABEL_DEBUG_INFORMATION:
         *w = 2;
         break;
      case MENU_LABEL_ACHIEVEMENT_LIST:
         *w = 2;
         break;
   }

   if (type >= MENU_SETTINGS_PLAYLIST_ASSOCIATION_START)
   {
      char playlist_name_with_ext[PATH_MAX_LENGTH];
      unsigned i;
      bool found_matching_core_association = false;
      settings_t         *settings = config_get_ptr();
      struct string_list *str_list  = string_split(settings->playlist_names, ";");
      struct string_list *str_list2 = string_split(settings->playlist_cores, ";");

      strlcpy(playlist_name_with_ext, path, sizeof(playlist_name_with_ext));
      strlcat(playlist_name_with_ext, ".lpl", sizeof(playlist_name_with_ext));

      for (i = 0; i < str_list->size; i++)
      {
         if (!strcmp(str_list->elems[i].data, playlist_name_with_ext))
         {
            if (str_list->size != str_list2->size)
               break;

            if (str_list2->elems[i].data == NULL)
               break;

            found_matching_core_association = true;
            strlcpy(s, str_list2->elems[i].data, len);
         }
      }

      string_list_free(str_list);
      string_list_free(str_list2);

      if (!strcmp(s, "DETECT") || !found_matching_core_association)
         strlcpy(s, "N/A", len);
      else
      {
         global_t *global = global_get_ptr();
         char buf[PATH_MAX_LENGTH];
         if (core_info_list_get_display_name(global->core_info.list, s, buf, sizeof(buf)))
            strlcpy(s, buf, len);
      }
   }
   else if (type >= MENU_SETTINGS_CORE_OPTION_START)
   {
      const char *core_opt = NULL;
      if (!system)
         return;

      core_opt = core_option_get_val(system->core_options,
               type - MENU_SETTINGS_CORE_OPTION_START);

      strlcpy(s, "", len);

      if (core_opt)
         strlcpy(s, core_opt, len);
   }
   else if (type >= MENU_SETTINGS_CORE_OPTION_CREATE)
   {
      if (!system)
         return;

      strlcpy(s, "", len);

      if (global->name.base[0] != '\0')
         strlcpy(s,  path_basename(global->name.base), len);
   }
   else
      menu_setting_get_label(list, s,
            len, w, type, label, entry_label, i);

   strlcpy(s2, path, len2);
}
Пример #2
0
void menu_cbs_init(void *data,
      menu_file_list_cbs_t *cbs,
      const char *path, const char *label,
      unsigned type, size_t idx)
{
   char elem0[PATH_MAX_LENGTH];
   char elem1[PATH_MAX_LENGTH];
   const char *repr_label       = NULL;
   struct string_list *str_list = NULL;
   const char *menu_label       = NULL;
   int ret                      = 0;
   uint32_t label_hash          = 0;
   uint32_t menu_label_hash     = 0;
   file_list_t *list            = (file_list_t*)data;
   if (!list)
      return;

   elem0[0] = '\0';
   elem1[0] = '\0';

   menu_entries_get_last_stack(NULL, &menu_label, NULL, NULL);

   if (label)
      str_list = string_split(label, "|");

   if (str_list && str_list->size > 0)
      strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
   if (str_list && str_list->size > 1)
      strlcpy(elem1, str_list->elems[1].data, sizeof(elem1));

   if (!label || !menu_label)
      goto error;

   label_hash      = menu_hash_calculate(label);
   menu_label_hash = menu_hash_calculate(menu_label);

#ifdef DEBUG_LOG
   RARCH_LOG("\n");
#endif

   repr_label = (!string_is_empty(label)) ? label : path;

   ret = menu_cbs_init_bind_ok(cbs, path, label, type, idx, elem0, elem1, menu_label, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "OK", cbs->action_ok_ident);

   ret = menu_cbs_init_bind_cancel(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "CANCEL", cbs->action_cancel_ident);

   ret = menu_cbs_init_bind_scan(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "SCAN", cbs->action_scan_ident);

   ret = menu_cbs_init_bind_start(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "START", cbs->action_start_ident);

   ret = menu_cbs_init_bind_select(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "SELECT", cbs->action_select_ident);

   ret = menu_cbs_init_bind_info(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "INFO", cbs->action_info_ident);

   ret = menu_cbs_init_bind_content_list_switch(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "CONTENT SWITCH", cbs->action_content_list_switch_ident);

   ret = menu_cbs_init_bind_up(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "UP", cbs->action_up_ident);

   ret = menu_cbs_init_bind_down(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "DOWN", cbs->action_down_ident);

   ret = menu_cbs_init_bind_left(cbs, path, label, type, idx, elem0, elem1, menu_label, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "LEFT", cbs->action_left_ident);

   ret = menu_cbs_init_bind_right(cbs, path, label, type, idx, elem0, elem1, menu_label, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "RIGHT", cbs->action_right_ident);

   ret = menu_cbs_init_bind_deferred_push(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "DEFERRED PUSH", cbs->action_deferred_push_ident);

   ret = menu_cbs_init_bind_refresh(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "REFRESH", cbs->action_refresh_ident);

   ret = menu_cbs_init_bind_get_string_representation(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "GET VALUE", cbs->action_get_value_ident);

   ret = menu_cbs_init_bind_title(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   menu_cbs_init_log(repr_label, "GET TITLE", cbs->action_get_title_ident);

   ret = menu_driver_bind_init(cbs, path, label, type, idx, elem0, elem1, label_hash, menu_label_hash);

   (void)ret;

error:
   string_list_free(str_list);
   str_list = NULL;
}
Пример #3
0
void
gui_color_buffer_display ()
{
    int y, i, lines, line, col, color, max_color, num_items;
    char str_line[1024], str_color[64], str_rgb[64], **items;
    struct t_gui_color_palette *color_palette;

    if (!gui_color_buffer)
        return;

    gui_buffer_clear (gui_color_buffer);

    /* set title buffer */
    gui_buffer_set_title (gui_color_buffer,
                          _("WeeChat colors | Actions: "
                            "[e] Display extra infos [r] Refresh "
                            "[z] Reset colors [q] Close buffer | "
                            "Keys: [alt-c] Temporarily switch to terminal "
                            "colors"));

    /* display terminal/colors infos */
    y = 0;
    gui_color_info_term_colors (str_line, sizeof (str_line));
    gui_chat_printf_y (gui_color_buffer, y++, "%s", str_line);

    /* display palette of colors */
    y++;
    if (gui_color_use_term_colors)
    {
        gui_color_buffer_display_timer ();
        y++;
    }
    else
    {
        gui_chat_printf_y (gui_color_buffer, y++,
                           _("WeeChat color pairs auto-allocated "
                             "(in use: %d, left: %d):"),
                           gui_color_pairs_used,
                           gui_color_num_pairs - gui_color_pairs_used);
    }
    max_color = (gui_color_use_term_colors) ?
        gui_color_term_colors - 1 : gui_color_num_pairs;
    if (max_color > 255)
        max_color = 255;
    lines = (max_color <= 64) ? 8 : 16;
    for (line = 0; line < lines; line++)
    {
        str_line[0] = '\0';
        for (col = 0; col < 16; col++)
        {
            color = (col * lines) + line;
            if (color <= max_color)
            {
                if (color == 0)
                {
                    snprintf (str_color, sizeof (str_color),
                              "     ");
                }
                else if (gui_color_use_term_colors
                         || (color <= gui_color_pairs_used))
                {
                    snprintf (str_color, sizeof (str_color),
                              "%c%c%05d%c%03d%c",
                              GUI_COLOR_COLOR_CHAR,
                              GUI_COLOR_EXTENDED_CHAR,
                              color,
                              (color == 0) ? '<' : ' ',
                              color,
                              (color == 0) ? '>' : ' ');
                }
                else
                {
                    snprintf (str_color, sizeof (str_color),
                              "%s  -  ",
                              GUI_NO_COLOR);
                }
                strcat (str_line, str_color);
            }
            else
            {
                snprintf (str_color, sizeof (str_color),
                          "%s     ",
                          GUI_COLOR(GUI_COLOR_CHAT));
                strcat (str_line, str_color);
            }
        }
        gui_chat_printf_y (gui_color_buffer, y++,
                           " %s",
                           str_line);
    }
    gui_chat_printf_y (gui_color_buffer, y++,
                       (gui_color_use_term_colors) ?
                       "" : _("(press alt-c to see the colors you can use "
                              "in options)"));

    if (gui_color_buffer_extra_info)
    {
        /* display time of last auto reset of color pairs */
        y++;
        gui_chat_printf_y (gui_color_buffer, y++,
                           _("Last auto reset of pairs: %s"),
                           (gui_color_pairs_auto_reset_last == 0) ?
                           "-" : ctime (&gui_color_pairs_auto_reset_last));

        /* display WeeChat basic colors */
        y++;
        gui_chat_printf_y (gui_color_buffer, y++,
                           _("WeeChat basic colors:"));
        str_line[0] = '\0';
        for (i = 0; i < GUI_CURSES_NUM_WEECHAT_COLORS; i++)
        {
            if (gui_color_use_term_colors)
            {
                snprintf (str_color, sizeof (str_color),
                          " %s",
                          gui_weechat_colors[i].string);
            }
            else
            {
                snprintf (str_color, sizeof (str_color),
                          "%c %c%c%02d%s",
                          GUI_COLOR_RESET_CHAR,
                          GUI_COLOR_COLOR_CHAR,
                          GUI_COLOR_FG_CHAR,
                          i,
                          gui_weechat_colors[i].string);
            }
            if (gui_chat_strlen_screen (str_line) + gui_chat_strlen_screen (str_color) > 80)
            {
                gui_chat_printf_y (gui_color_buffer, y++,
                                   " %s", str_line);
                str_line[0] = '\0';
            }
            strcat (str_line, str_color);
        }
        if (str_line[0])
        {
            gui_chat_printf_y (gui_color_buffer, y++,
                               " %s", str_line);
        }

        /* display nick colors */
        y++;
        gui_chat_printf_y (gui_color_buffer, y++,
                           _("Nick colors:"));
        items = string_split (CONFIG_STRING(config_color_chat_nick_colors),
                              ",", 0, 0, &num_items);
        if (items)
        {
            str_line[0] = '\0';
            for (i = 0; i < num_items; i++)
            {
                if (gui_color_use_term_colors)
                {
                    snprintf (str_color, sizeof (str_color),
                              " %s",
                              items[i]);
                }
                else
                {
                    snprintf (str_color, sizeof (str_color),
                              "%c %s%s",
                              GUI_COLOR_RESET_CHAR,
                              gui_color_get_custom (items[i]),
                              items[i]);
                }
                if (gui_chat_strlen_screen (str_line) + gui_chat_strlen_screen (str_color) > 80)
                {
                    gui_chat_printf_y (gui_color_buffer, y++,
                                       " %s", str_line);
                    str_line[0] = '\0';
                }
                strcat (str_line, str_color);
            }
            if (str_line[0])
            {
                gui_chat_printf_y (gui_color_buffer, y++,
                                   " %s", str_line);
            }
            string_free_split (items);
        }

        /* display palette colors */
        if (gui_color_hash_palette_color->items_count > 0)
        {
            y++;
            gui_chat_printf_y (gui_color_buffer, y++,
                               _("Color aliases:"));
            for (i = 1; i <= gui_color_num_pairs; i++)
            {
                color_palette = gui_color_palette_get (i);
                if (color_palette)
                {
                    str_color[0] = '\0';
                    if (!gui_color_use_term_colors)
                    {
                        snprintf (str_color, sizeof (str_color),
                                  "%c%c%c%05d",
                                  GUI_COLOR_COLOR_CHAR,
                                  GUI_COLOR_FG_CHAR,
                                  GUI_COLOR_EXTENDED_CHAR,
                                  i);
                    }
                    str_rgb[0] = '\0';
                    if ((color_palette->r >= 0) && (color_palette->g >= 0)
                        && (color_palette->b >= 0))
                    {
                        snprintf (str_rgb, sizeof (str_rgb),
                                  " (%d/%d/%d)",
                                  color_palette->r,
                                  color_palette->g,
                                  color_palette->b);
                    }
                    gui_chat_printf_y (gui_color_buffer, y++,
                                       " %5d: %s%s%s",
                                       i,
                                       str_color,
                                       (color_palette->alias) ? color_palette->alias : "",
                                       str_rgb);
                }
            }
        }

        /* display content of colors */
        if (gui_color_term_color_content)
        {
            y++;
            gui_chat_printf_y (gui_color_buffer, y++,
                               _("Content of colors (r/g/b):"));
            for (i = 0; i < gui_color_term_colors; i++)
            {
                gui_chat_printf_y (gui_color_buffer, y++,
                                   " %3d: %4hd / %4hd / %4hd",
                                   i,
                                   gui_color_term_color_content[i * 3],
                                   gui_color_term_color_content[(i* 3) + 1],
                                   gui_color_term_color_content[(i* 3) + 2]);
            }
        }
    }
}
Пример #4
0
void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
{
   settings_t *settings = config_get_ptr();
   QScopedPointer<QMenu> menu;
   QScopedPointer<QMenu> associateMenu;
   QScopedPointer<QMenu> hiddenPlaylistsMenu;
   QScopedPointer<QAction> hideAction;
   QScopedPointer<QAction> newPlaylistAction;
   QScopedPointer<QAction> deletePlaylistAction;
   QPointer<QAction> selectedAction;
   QPoint cursorPos = QCursor::pos();
   QListWidgetItem *selectedItem = m_listWidget->itemAt(m_listWidget->viewport()->mapFromGlobal(cursorPos));
   QDir playlistDir(settings->paths.directory_playlist);
   QString playlistDirAbsPath = playlistDir.absolutePath();
   QString currentPlaylistDirPath;
   QString currentPlaylistPath;
   QString currentPlaylistFileName;
   QFile currentPlaylistFile;
   QByteArray currentPlaylistFileNameArray;
   QFileInfo currentPlaylistFileInfo;
   QMap<QString, const core_info_t*> coreList;
   core_info_list_t *core_info_list = NULL;
   union string_list_elem_attr attr = {0};
   struct string_list *stnames = NULL;
   struct string_list *stcores = NULL;
   unsigned i = 0;
   int j = 0;
   size_t found = 0;
   const char *currentPlaylistFileNameData = NULL;
   char new_playlist_names[PATH_MAX_LENGTH];
   char new_playlist_cores[PATH_MAX_LENGTH];
   bool specialPlaylist = false;
   bool foundHiddenPlaylist = false;

   new_playlist_names[0] = new_playlist_cores[0] = '\0';

   stnames = string_split(settings->arrays.playlist_names, ";");
   stcores = string_split(settings->arrays.playlist_cores, ";");

   if (selectedItem)
   {
      currentPlaylistPath = selectedItem->data(Qt::UserRole).toString();
      currentPlaylistFile.setFileName(currentPlaylistPath);

      currentPlaylistFileInfo = QFileInfo(currentPlaylistPath);
      currentPlaylistFileName = currentPlaylistFileInfo.fileName();
      currentPlaylistDirPath = currentPlaylistFileInfo.absoluteDir().absolutePath();

      currentPlaylistFileNameArray.append(currentPlaylistFileName);
      currentPlaylistFileNameData = currentPlaylistFileNameArray.constData();
   }

   menu.reset(new QMenu(this));
   menu->setObjectName("menu");

   hiddenPlaylistsMenu.reset(new QMenu(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_HIDDEN_PLAYLISTS), this));
   newPlaylistAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST)) + "...", this));

   hiddenPlaylistsMenu->setObjectName("hiddenPlaylistsMenu");

   menu->addAction(newPlaylistAction.data());

   if (currentPlaylistFile.exists())
   {
      deletePlaylistAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DELETE_PLAYLIST)) + "...", this));
      menu->addAction(deletePlaylistAction.data());
   }

   if (selectedItem)
   {
      hideAction.reset(new QAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_HIDE), this));
      menu->addAction(hideAction.data());
   }

   for (j = 0; j < m_listWidget->count(); j++)
   {
      QListWidgetItem *item = m_listWidget->item(j);
      bool hidden = m_listWidget->isItemHidden(item);

      if (hidden)
      {
         QAction *action = hiddenPlaylistsMenu->addAction(item->text());
         action->setProperty("row", j);
         action->setProperty("core_path", item->data(Qt::UserRole).toString());
         foundHiddenPlaylist = true;
      }
   }

   if (!foundHiddenPlaylist)
   {
      QAction *action = hiddenPlaylistsMenu->addAction(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NONE));
      action->setProperty("row", -1);
   }

   menu->addMenu(hiddenPlaylistsMenu.data());

   if (currentPlaylistDirPath != playlistDirAbsPath)
   {
      /* special playlists like history etc. can't have an association */
      specialPlaylist = true;
   }

   if (!specialPlaylist)
   {
      associateMenu.reset(new QMenu(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ASSOCIATE_CORE), this));
      associateMenu->setObjectName("associateMenu");

      core_info_get_list(&core_info_list);

      for (i = 0; i < core_info_list->count && core_info_list->count > 0; i++)
      {
         const core_info_t *core = &core_info_list->list[i];
         coreList[core->core_name] = core;
      }

      {
         QMapIterator<QString, const core_info_t*> coreListIterator(coreList);
         QVector<QHash<QString, QString> > cores;

         while (coreListIterator.hasNext())
         {
            QString key;
            const core_info_t *core = NULL;
            QString name;
            QHash<QString, QString> hash;

            coreListIterator.next();

            key = coreListIterator.key();
            core = coreList.value(key);

            if (string_is_empty(core->core_name))
               name = core->display_name;
            else
               name = core->core_name;

            if (name.isEmpty())
               continue;

            hash["name"] = name;
            hash["core_path"] = core->path;

            cores.append(hash);
         }

         std::sort(cores.begin(), cores.end(), comp_hash_name_key_lower);

         for (j = 0; j < cores.count(); j++)
         {
            const QHash<QString, QString> &hash = cores.at(j);
            QAction *action = associateMenu->addAction(hash.value("name"));

            action->setProperty("core_path", hash.value("core_path"));
         }
      }

      menu->addMenu(associateMenu.data());
   }

   selectedAction = menu->exec(cursorPos);

   if (!selectedAction)
      goto end;

   if (!specialPlaylist && selectedAction->parent() == associateMenu.data())
   {
      found = string_list_find_elem(stnames, currentPlaylistFileNameData);

      if (found)
         string_list_set(stcores, static_cast<unsigned>(found - 1), selectedAction->property("core_path").toString().toUtf8().constData());
      else
      {
         string_list_append(stnames, currentPlaylistFileNameData, attr);
         string_list_append(stcores, "DETECT", attr);

         found = string_list_find_elem(stnames, currentPlaylistFileNameData);

         if (found)
            string_list_set(stcores, static_cast<unsigned>(found - 1), selectedAction->property("core_path").toString().toUtf8().constData());
      }

      string_list_join_concat(new_playlist_names,
            sizeof(new_playlist_names), stnames, ";");
      string_list_join_concat(new_playlist_cores,
            sizeof(new_playlist_cores), stcores, ";");

      strlcpy(settings->arrays.playlist_names,
            new_playlist_names, sizeof(settings->arrays.playlist_names));
      strlcpy(settings->arrays.playlist_cores,
            new_playlist_cores, sizeof(settings->arrays.playlist_cores));
   }
   else if (selectedItem && selectedAction == deletePlaylistAction.data())
   {
      if (currentPlaylistFile.exists())
      {
         if (showMessageBox(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST)).arg(selectedItem->text()), MainWindow::MSGBOX_TYPE_QUESTION_YESNO, Qt::ApplicationModal, false))
         {
            if (currentPlaylistFile.remove())
               reloadPlaylists();
            else
               showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_COULD_NOT_DELETE_FILE), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false);
         }
      }
   }
   else if (selectedAction == newPlaylistAction.data())
   {
      QString name = QInputDialog::getText(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_NEW_PLAYLIST), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ENTER_NEW_PLAYLIST_NAME));
      QString newPlaylistPath = playlistDirAbsPath + "/" + name + file_path_str(FILE_PATH_LPL_EXTENSION);
      QFile file(newPlaylistPath);

      if (file.open(QIODevice::WriteOnly))
         file.close();

      reloadPlaylists();
   }
   else if (selectedItem && selectedAction == hideAction.data())
   {
      int row = m_listWidget->row(selectedItem);

      if (row >= 0)
      {
         QStringList hiddenPlaylists = m_settings->value("hidden_playlists").toStringList();

         if (!hiddenPlaylists.contains(currentPlaylistFileName))
         {
            hiddenPlaylists.append(currentPlaylistFileName);
            m_settings->setValue("hidden_playlists", hiddenPlaylists);
         }

         m_listWidget->setRowHidden(row, true);
      }
   }
   else if (selectedAction->parent() == hiddenPlaylistsMenu.data())
   {
      QVariant rowVariant = selectedAction->property("row");

      if (rowVariant.isValid())
      {
         QStringList hiddenPlaylists = m_settings->value("hidden_playlists").toStringList();
         int row = rowVariant.toInt();

         if (row >= 0)
         {
            QString playlistPath = selectedAction->property("core_path").toString();
            QFileInfo playlistFileInfo(playlistPath);
            QString playlistFileName = playlistFileInfo.fileName();

            if (hiddenPlaylists.contains(playlistFileName))
            {
               hiddenPlaylists.removeOne(playlistFileName);
               m_settings->setValue("hidden_playlists", hiddenPlaylists);
            }

            m_listWidget->setRowHidden(row, false);
         }
      }
   }

   setCoreActions();

end:
   if (stnames)
      string_list_free(stnames);
   if (stcores)
      string_list_free(stcores);
}
Пример #5
0
bool RunScript(const std::vector<char>& data, std::vector<char>& result)
{
	result.clear();
	std::string text(data.begin(), data.end());

	std::cout << "Run script:" << std::endl << text << std::endl;

	std::vector<std::string> lines = string_split(text, '\n');
	if ( ! lines.empty())
	{
		std::string cmd = lines[0];
		std::map<std::string, std::string> params;
		for (size_t i = 1; i < lines.size(); ++i)
		{
			size_t pos = lines[i].find_first_of(':');
			if (pos != std::string::npos)
			{
				std::string name = lines[i].substr(0, pos);
				std::string value = lines[i].substr(pos + 1);
				if ( ! name.empty())
				{
					params[name] = value;
				}
				std::cout << "  param: " << name << " => " << value << std::endl;
			}
		}

		if (rules.find(cmd) == rules.end())
		{
			std::cerr << "Unknown command: '" << cmd << "'" << std::endl;
		}
		else
		{
			std::string command = rules[cmd];
			for (std::map<std::string, std::string>::iterator it = params.begin(); it != params.end(); ++it)
			{
				std::cout << " Replace " << it->first << " => " << it->second << std::endl;

				command = string_replace(command, "$(" + it->first + ")", it->second);
			}
			command = string_replace(command, "{", "\\{");
			command = string_replace(command, "}", "\\}");
			command = string_replace(command, "\"", "\\\"");
			command = string_replace(command, "$", "\\$");
			std::cout << "Call: " << rules[cmd] << std::endl;
			std::cout << "Run: " << command << std::endl;

			FILE* fp = popen(command.c_str(), "r");
			if ( ! fp)
			{
				std::cerr << "Run script failed!" << std::endl;
				std::string text = CreateJSON(1, "Can not run script!");
				result.insert(result.begin(), text.begin(), text.end());
			}
			else
			{
				std::string text = "";
				while ( ! feof(fp))
				{
					char buffer[1024];
					while (fgets(buffer, sizeof(buffer), fp))
					{
						text += buffer;
					}
				}
				fclose(fp);
				result.insert(result.end(), text.begin(), text.end());
			}
		}
	}
	return true;
}
Пример #6
0
EW_ENTER

op_info::op_info(const String& s,int f):name(s),op_name("__"+string_split(s,".").back()),flag(f){}
Пример #7
0
/**
 * dir_list_new:
 * @dir          : directory path.
 * @ext          : allowed extensions of file directory entries to include.
 * @include_dirs : include directories as part of the finished directory listing?
 *
 * Create a directory listing.
 *
 * Returns: pointer to a directory listing of type 'struct string_list *' on success,
 * NULL in case of error. Has to be freed manually.
 **/
struct string_list *dir_list_new(const char *dir,
      const char *ext, bool include_dirs)
{
#ifdef _WIN32
   WIN32_FIND_DATA ffd;
   HANDLE hFind = INVALID_HANDLE_VALUE;
#else
   DIR *directory = NULL;
   const struct dirent *entry = NULL;
#endif
   char path_buf[PATH_MAX_LENGTH] = {0};
   struct string_list *ext_list   = NULL;
   struct string_list *list       = NULL;

   (void)path_buf;

   if (!(list = string_list_new()))
      return NULL;

   if (ext)
      ext_list = string_split(ext, "|");

#ifdef _WIN32
   snprintf(path_buf, sizeof(path_buf), "%s\\*", dir);

   hFind = FindFirstFile(path_buf, &ffd);
   if (hFind == INVALID_HANDLE_VALUE)
      goto error;

   do
   {
      int ret                         = 0;
      char file_path[PATH_MAX_LENGTH] = {0};
      const char *name                = ffd.cFileName;
      const char *file_ext            = path_get_extension(name);
      bool is_dir                     = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;

      fill_pathname_join(file_path, dir, name, sizeof(file_path));

      ret = parse_dir_entry(name, file_path, is_dir,
            include_dirs, list, ext_list, file_ext);

      if (ret == -1)
         goto error;

      if (ret == 1)
         continue;
   }while (FindNextFile(hFind, &ffd) != 0);

   FindClose(hFind);
   string_list_free(ext_list);
   return list;

error:
   if (hFind != INVALID_HANDLE_VALUE)
      FindClose(hFind);
#else
   directory = opendir(dir);
   if (!directory)
      goto error;

   while ((entry = readdir(directory)))
   {
      int ret                         = 0;
      char file_path[PATH_MAX_LENGTH] = {0};
      const char *name                = entry->d_name;
      const char *file_ext            = path_get_extension(name);
      bool is_dir                     = false;

      fill_pathname_join(file_path, dir, name, sizeof(file_path));

      is_dir = dirent_is_directory(file_path, entry);

      ret = parse_dir_entry(name, file_path, is_dir,
            include_dirs, list, ext_list, file_ext);

      if (ret == -1)
         goto error;

      if (ret == 1)
         continue;
   }

   closedir(directory);

   string_list_free(ext_list);
   return list;

error:

   if (directory)
      closedir(directory);

#endif
   string_list_free(list);
   string_list_free(ext_list);
   return NULL;
}
Пример #8
0
//[[Rcpp::export]]
std::vector < std::string > string_split_single(std::string str, std::string delimiter){
  return string_split(str, delimiter);
}
Пример #9
0
//[[Rcpp::export]]
std::list < std::vector < std::string > > string_split_vector(std::vector < std::string > strs, std::string delimiter){
  return string_split(strs, delimiter);
}
Пример #10
0
static void netplay_announce_cb(void *task_data, void *user_data, const char *error)
{
   RARCH_LOG("[netplay] announcing netplay game... \n");

   if (task_data)
   {
      http_transfer_data_t *data = (http_transfer_data_t*)task_data;
      struct string_list *lines;
      unsigned i, ip_len, port_len;
      const char *mitm_ip = NULL;
      const char *mitm_port = NULL;
      char *buf;
      char *host_string;

      if (data->len == 0)
      {
         free(task_data);
         return;
      }

      buf = (char*)calloc(1, data->len + 1);

      memcpy(buf, data->data, data->len);

      lines = string_split(buf, "\n");

      if (lines->size == 0)
      {
         string_list_free(lines);
         free(buf);
         free(task_data);
         return;
      }

      for (i = 0; i < lines->size; i++)
      {
         const char *line = lines->elems[i].data;

         if (!strncmp(line, "mitm_ip=", 8))
            mitm_ip = line + 8;

         if (!strncmp(line, "mitm_port=", 10))
            mitm_port = line + 10;
      }

      if (mitm_ip && mitm_port)
      {
         RARCH_LOG("[netplay] joining relay server: %s:%s\n", mitm_ip, mitm_port);

         ip_len   = (unsigned)strlen(mitm_ip);
         port_len = (unsigned)strlen(mitm_port);

         /* Enable Netplay client mode */
         if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
         {
            command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
            is_mitm = true;
         }

         netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);

         host_string = (char*)calloc(1, ip_len + port_len + 2);

         memcpy(host_string, mitm_ip, ip_len);
         memcpy(host_string + ip_len, "|", 1);
         memcpy(host_string + ip_len + 1, mitm_port, port_len);

         /* Enable Netplay */
         command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, (void*)host_string);
         command_event(CMD_EVENT_NETPLAY_INIT, (void*)host_string);

         free(host_string);
      }

      string_list_free(lines);
      free(buf);
      free(task_data);
   }

   return;
}
Пример #11
0
static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pugi::xml_node graph_node)
{
	ShaderGraph *graph = new ShaderGraph();

	map<string, ShaderNode*> nodemap;

	nodemap["output"] = graph->output();

	for(pugi::xml_node node = graph_node.first_child(); node; node = node.next_sibling()) {
		ShaderNode *snode = NULL;

		if(string_iequals(node.name(), "image_texture")) {
			ImageTextureNode *img = new ImageTextureNode();

			xml_read_string(&img->filename, node, "src");
			img->filename = path_join(state.base, img->filename);

			snode = img;
		}
		else if(string_iequals(node.name(), "environment_texture")) {
			EnvironmentTextureNode *env = new EnvironmentTextureNode();

			xml_read_string(&env->filename, node, "src");
			env->filename = path_join(state.base, env->filename);

			snode = env;
		}
		else if(string_iequals(node.name(), "sky_texture")) {
			SkyTextureNode *sky = new SkyTextureNode();

			xml_read_float3(&sky->sun_direction, node, "sun_direction");
			xml_read_float(&sky->turbidity, node, "turbidity");
			
			snode = sky;
		}
		else if(string_iequals(node.name(), "noise_texture")) {
			snode = new NoiseTextureNode();
		}
		else if(string_iequals(node.name(), "checker_texture")) {
			snode = new CheckerTextureNode();
		}
		else if(string_iequals(node.name(), "gradient_texture")) {
			GradientTextureNode *blend = new GradientTextureNode();
			xml_read_enum(&blend->type, GradientTextureNode::type_enum, node, "type");
			snode = blend;
		}
		else if(string_iequals(node.name(), "voronoi_texture")) {
			VoronoiTextureNode *voronoi = new VoronoiTextureNode();
			xml_read_enum(&voronoi->coloring, VoronoiTextureNode::coloring_enum, node, "coloring");
			snode = voronoi;
		}
		else if(string_iequals(node.name(), "musgrave_texture")) {
			MusgraveTextureNode *musgrave = new MusgraveTextureNode();
			xml_read_enum(&musgrave->type, MusgraveTextureNode::type_enum, node, "type");
			snode = musgrave;
		}
		else if(string_iequals(node.name(), "magic_texture")) {
			MagicTextureNode *magic = new MagicTextureNode();
			xml_read_int(&magic->depth, node, "depth");
			snode = magic;
		}
		else if(string_iequals(node.name(), "noise_texture")) {
			NoiseTextureNode *dist = new NoiseTextureNode();
			snode = dist;
		}
		else if(string_iequals(node.name(), "wave_texture")) {
			WaveTextureNode *wood = new WaveTextureNode();
			xml_read_enum(&wood->type, WaveTextureNode::type_enum, node, "type");
			snode = wood;
		}
		else if(string_iequals(node.name(), "normal")) {
			snode = new NormalNode();
		}
		else if(string_iequals(node.name(), "mapping")) {
			snode = new MappingNode();
		}
		else if(string_iequals(node.name(), "ward_bsdf")) {
			snode = new WardBsdfNode();
		}
		else if(string_iequals(node.name(), "diffuse_bsdf")) {
			snode = new DiffuseBsdfNode();
		}
		else if(string_iequals(node.name(), "translucent_bsdf")) {
			snode = new TranslucentBsdfNode();
		}
		else if(string_iequals(node.name(), "transparent_bsdf")) {
			snode = new TransparentBsdfNode();
		}
		else if(string_iequals(node.name(), "velvet_bsdf")) {
			snode = new VelvetBsdfNode();
		}
		else if(string_iequals(node.name(), "glossy_bsdf")) {
			GlossyBsdfNode *glossy = new GlossyBsdfNode();
			xml_read_enum(&glossy->distribution, GlossyBsdfNode::distribution_enum, node, "distribution");
			snode = glossy;
		}
		else if(string_iequals(node.name(), "glass_bsdf")) {
			GlassBsdfNode *diel = new GlassBsdfNode();
			xml_read_enum(&diel->distribution, GlassBsdfNode::distribution_enum, node, "distribution");
			snode = diel;
		}
		else if(string_iequals(node.name(), "emission")) {
			EmissionNode *emission = new EmissionNode();
			xml_read_bool(&emission->total_power, node, "total_power");
			snode = emission;
		}
		else if(string_iequals(node.name(), "background")) {
			snode = new BackgroundNode();
		}
		else if(string_iequals(node.name(), "transparent_volume")) {
			snode = new TransparentVolumeNode();
		}
		else if(string_iequals(node.name(), "isotropic_volume")) {
			snode = new IsotropicVolumeNode();
		}
		else if(string_iequals(node.name(), "geometry")) {
			snode = new GeometryNode();
		}
		else if(string_iequals(node.name(), "texture_coordinate")) {
			snode = new TextureCoordinateNode();
		}
		else if(string_iequals(node.name(), "lightPath")) {
			snode = new LightPathNode();
		}
		else if(string_iequals(node.name(), "value")) {
			ValueNode *value = new ValueNode();
			xml_read_float(&value->value, node, "value");
			snode = value;
		}
		else if(string_iequals(node.name(), "color")) {
			ColorNode *color = new ColorNode();
			xml_read_float3(&color->value, node, "value");
			snode = color;
		}
		else if(string_iequals(node.name(), "mix_closure")) {
			snode = new MixClosureNode();
		}
		else if(string_iequals(node.name(), "add_closure")) {
			snode = new AddClosureNode();
		}
		else if(string_iequals(node.name(), "invert")) {
			snode = new InvertNode();
		}
		else if(string_iequals(node.name(), "mix")) {
			MixNode *mix = new MixNode();
			xml_read_enum(&mix->type, MixNode::type_enum, node, "type");
			snode = mix;
		}
		else if(string_iequals(node.name(), "gamma")) {
			snode = new GammaNode();
		}
		else if(string_iequals(node.name(), "brightness")) {
			snode = new BrightContrastNode();
		}
		else if(string_iequals(node.name(), "combine_rgb")) {
			snode = new CombineRGBNode();
		}
		else if(string_iequals(node.name(), "separate_rgb")) {
			snode = new SeparateRGBNode();
		}
		else if(string_iequals(node.name(), "hsv")) {
			snode = new HSVNode();
		}
		else if(string_iequals(node.name(), "attribute")) {
			AttributeNode *attr = new AttributeNode();
			xml_read_ustring(&attr->attribute, node, "attribute");
			snode = attr;
		}
		else if(string_iequals(node.name(), "camera")) {
			snode = new CameraNode();
		}
		else if(string_iequals(node.name(), "fresnel")) {
			snode = new FresnelNode();
		}
		else if(string_iequals(node.name(), "math")) {
			MathNode *math = new MathNode();
			xml_read_enum(&math->type, MathNode::type_enum, node, "type");
			snode = math;
		}
		else if(string_iequals(node.name(), "vector_math")) {
			VectorMathNode *vmath = new VectorMathNode();
			xml_read_enum(&vmath->type, VectorMathNode::type_enum, node, "type");
			snode = vmath;
		}
		else if(string_iequals(node.name(), "connect")) {
			/* connect nodes */
			vector<string> from_tokens, to_tokens;

			string_split(from_tokens, node.attribute("from").value());
			string_split(to_tokens, node.attribute("to").value());

			if(from_tokens.size() == 2 && to_tokens.size() == 2) {
				/* find nodes and sockets */
				ShaderOutput *output = NULL;
				ShaderInput *input = NULL;

				if(nodemap.find(from_tokens[0]) != nodemap.end()) {
					ShaderNode *fromnode = nodemap[from_tokens[0]];

					foreach(ShaderOutput *out, fromnode->outputs)
						if(string_iequals(xml_socket_name(out->name), from_tokens[1]))
							output = out;

					if(!output)
						fprintf(stderr, "Unknown output socket name \"%s\" on \"%s\".\n", from_tokens[1].c_str(), from_tokens[0].c_str());
				}
				else
Пример #12
0
int
upgrade_file_write_object (struct t_upgrade_file *upgrade_file, int object_id,
                           struct t_infolist *infolist)
{
    int i, argc, length;
    char **argv;
    const char *fields;
    void *buf;

    /* write all infolist variables */
    infolist_reset_item_cursor (infolist);
    while (infolist_next (infolist))
    {
        /* write object start with id */
        if (!upgrade_file_write_integer (upgrade_file, UPGRADE_TYPE_OBJECT_START))
        {
            UPGRADE_ERROR(_("write - object type"), "object start");
            return 0;
        }
        if (!upgrade_file_write_integer (upgrade_file, object_id))
        {
            UPGRADE_ERROR(_("write - object id"), "");
            return 0;
        }

        fields = infolist_fields (infolist);
        if (fields)
        {
            argv = string_split (fields, ",", 0, 0, &argc);
            if (argv && (argc > 0))
            {
                for (i = 0; i < argc; i++)
                {
                    switch (argv[i][0])
                    {
                        case 'i': /* integer */
                            if (!upgrade_file_write_integer (upgrade_file, UPGRADE_TYPE_OBJECT_VAR))
                            {
                                UPGRADE_ERROR(_("write - object type"), "object var");
                                return 0;
                            }
                            if (!upgrade_file_write_string (upgrade_file, argv[i] + 2))
                            {
                                UPGRADE_ERROR(_("write - variable name"), "");
                                return 0;
                            }
                            if (!upgrade_file_write_integer (upgrade_file, INFOLIST_INTEGER))
                            {
                                UPGRADE_ERROR(_("write - infolist type"), "integer");
                                return 0;
                            }
                            if (!upgrade_file_write_integer (upgrade_file,
                                                             infolist_integer (infolist, argv[i] + 2)))
                            {
                                UPGRADE_ERROR(_("write - variable"), "integer");
                                return 0;
                            }
                            break;
                        case 's': /* string */
                            if (!upgrade_file_write_integer (upgrade_file, UPGRADE_TYPE_OBJECT_VAR))
                            {
                                UPGRADE_ERROR(_("write - object type"), "object var");
                                return 0;
                            }
                            if (!upgrade_file_write_string (upgrade_file, argv[i] + 2))
                            {
                                UPGRADE_ERROR(_("write - variable name"), "");
                                return 0;
                            }
                            if (!upgrade_file_write_integer (upgrade_file, INFOLIST_STRING))
                            {
                                UPGRADE_ERROR(_("write - infolist type"), "string");
                                return 0;
                            }
                            if (!upgrade_file_write_string (upgrade_file,
                                                            infolist_string (infolist, argv[i] + 2)))
                            {
                                UPGRADE_ERROR(_("write - variable"), "string");
                                return 0;
                            }
                            break;
                        case 'p': /* pointer */
                            /* pointer in not used in upgrade files, only buffer is */
                            break;
                        case 'b': /* buffer */
                            buf = infolist_buffer (infolist, argv[i] + 2, &length);
                            if (buf && (length > 0))
                            {
                                if (!upgrade_file_write_integer (upgrade_file, UPGRADE_TYPE_OBJECT_VAR))
                                {
                                    UPGRADE_ERROR(_("write - object type"), "object var");
                                    return 0;
                                }
                                if (!upgrade_file_write_string (upgrade_file, argv[i] + 2))
                                {
                                    UPGRADE_ERROR(_("write - variable name"), "");
                                    return 0;
                                }
                                if (!upgrade_file_write_integer (upgrade_file, INFOLIST_BUFFER))
                                {
                                    UPGRADE_ERROR(_("write - infolist type"), "buffer");
                                    return 0;
                                }
                                if (!upgrade_file_write_buffer (upgrade_file, buf, length))
                                {
                                    UPGRADE_ERROR(_("write - variable"), "buffer");
                                    return 0;
                                }
                            }
                            break;
                        case 't': /* time */
                            if (!upgrade_file_write_integer (upgrade_file, UPGRADE_TYPE_OBJECT_VAR))
                            {
                                UPGRADE_ERROR(_("write - object type"), "object var");
                                return 0;
                            }
                            if (!upgrade_file_write_string (upgrade_file, argv[i] + 2))
                            {
                                UPGRADE_ERROR(_("write - variable name"), "");
                                return 0;
                            }
                            if (!upgrade_file_write_integer (upgrade_file, INFOLIST_TIME))
                            {
                                UPGRADE_ERROR(_("write - infolist type"), "time");
                                return 0;
                            }
                            if (!upgrade_file_write_time (upgrade_file,
                                                          infolist_time (infolist, argv[i] + 2)))
                            {
                                UPGRADE_ERROR(_("write - variable"), "time");
                                return 0;
                            }
                            break;
                    }
                }
            }
            if (argv)
                string_free_split (argv);
        }

        /* write object end */
        if (!upgrade_file_write_integer (upgrade_file, UPGRADE_TYPE_OBJECT_END))
            return 0;
    }

    return 1;
}
Пример #13
0
struct string_list *menu_entry_enum_values(uint32_t i)
{
   rarch_setting_t *setting = menu_entry_get_setting(i);
   return string_split(setting->values, "|");
}
Пример #14
0
static int playlist_association_left(unsigned type, const char *label,
      bool wraparound)
{
   unsigned i;
   char core_path[PATH_MAX_LENGTH];
   char new_playlist_cores[PATH_MAX_LENGTH];
   int next, found, current         = 0;
   core_info_t *info                = NULL;
   struct string_list *stnames      = NULL;
   struct string_list *stcores      = NULL;
   settings_t *settings             = config_get_ptr();
   const char *path                 = path_basename(label);
   core_info_list_t           *list = NULL;

   core_info_get_list(&list);

   if (!list)
      return menu_cbs_exit();

   core_path[0] = new_playlist_cores[0] = '\0';

   stnames = string_split(settings->arrays.playlist_names, ";");
   stcores = string_split(settings->arrays.playlist_cores, ";");

   if (!menu_content_playlist_find_associated_core(path,
            core_path, sizeof(core_path)))
         strlcpy(core_path,
               file_path_str(FILE_PATH_DETECT),
               sizeof(core_path));

   for (i = 0; i < list->count; i++)
   {
      core_info_t *info = core_info_get(list, i);
      if (string_is_equal(info->path, core_path))
         current = i;
   }

   next = current - 1;
   if (next < 0)
   {
      if (wraparound)
         next = (int)(list->count-1);
      else
         next = 0;
   }

   info  = core_info_get(list, next);
   found = string_list_find_elem(stnames, path);
   if (found && info)
      string_list_set(stcores, found-1, info->path);

   string_list_join_concat(new_playlist_cores,
         sizeof(new_playlist_cores), stcores, ";");

   strlcpy(settings->arrays.playlist_cores,
         new_playlist_cores, sizeof(settings->arrays.playlist_cores));

   string_list_free(stnames);
   string_list_free(stcores);

   return 0;
}
Пример #15
0
/* Generic compressed file loader.
 * Extracts to buf, unless optional_filename != 0
 * Then extracts to optional_filename and leaves buf alone.
 */
static int content_file_compressed_read(
      const char * path, void **buf,
      const char* optional_filename, ssize_t *length)
{
   int ret                            = 0;
   const char* file_ext               = NULL;
   struct string_list *str_list       = string_split(path, "#");

   /* Safety check.
    * If optional_filename and optional_filename 
    * exists, we simply return 0,
    * hoping that optional_filename is the 
    * same as requested.
    */
   if (optional_filename && path_file_exists(optional_filename))
   {
      *length = 0;
      return 1;
   }

   /* We assure that there is something after the '#' symbol.
    *
    * This error condition happens for example, when
    * path = /path/to/file.7z, or
    * path = /path/to/file.7z#
    */
   if (str_list->size <= 1)
      goto error;

#if defined(HAVE_7ZIP) || defined(HAVE_ZLIB)
   file_ext        = path_get_extension(str_list->elems[0].data);
#endif

#ifdef HAVE_7ZIP
   if (string_is_equal_noncase(file_ext, "7z"))
   {
      *length = content_7zip_file_read(str_list->elems[0].data,
            str_list->elems[1].data, buf, optional_filename);
      if (*length != -1)
         ret = 1;
   }
#endif
#ifdef HAVE_ZLIB
   if (string_is_equal_noncase(file_ext, "zip"))
   {
      *length        = content_zip_file_read(str_list->elems[0].data,
            str_list->elems[1].data, buf, optional_filename);
      if (*length != -1)
         ret = 1;
   }

   string_list_free(str_list);
#endif
   return ret;

error:
   RARCH_ERR("Could not extract string and substring from "
         ": %s.\n", path);
   string_list_free(str_list);
   *length = 0;
   return 0;
}
Пример #16
0
struct t_gui_filter *
gui_filter_new (int enabled, const char *name, const char *buffer_name,
                const char *tags, const char *regex)
{
    struct t_gui_filter *new_filter;
    regex_t *regex1, *regex2;
    char *pos_tab, *regex_prefix, **tags_array, buf[512], str_error[512];
    const char *ptr_start_regex, *pos_regex_message;
    int i, rc;

    if (!name || !buffer_name || !tags || !regex)
    {
        gui_filter_new_error (name, _("not enough arguments"));
        return NULL;
    }

    if (gui_filter_search_by_name (name))
    {
        gui_filter_new_error (name,
                              _("a filter with same name already exists"));
        return NULL;
    }

    ptr_start_regex = regex;
    if ((ptr_start_regex[0] == '!')
        || ((ptr_start_regex[0] == '\\') && (ptr_start_regex[1] == '!')))
    {
        ptr_start_regex++;
    }

    regex1 = NULL;
    regex2 = NULL;

    if (strcmp (ptr_start_regex, "*") != 0)
    {
        pos_tab = strstr (ptr_start_regex, "\\t");
        if (pos_tab)
        {
            regex_prefix = string_strndup (ptr_start_regex,
                                           pos_tab - ptr_start_regex);
            pos_regex_message = pos_tab + 2;
        }
        else
        {
            regex_prefix = NULL;
            pos_regex_message = ptr_start_regex;
        }

        if (regex_prefix && regex_prefix[0])
        {
            regex1 = malloc (sizeof (*regex1));
            if (regex1)
            {
                rc = string_regcomp (regex1, regex_prefix,
                                     REG_EXTENDED | REG_ICASE | REG_NOSUB);
                if (rc != 0)
                {
                    regerror (rc, regex1, buf, sizeof (buf));
                    snprintf (str_error, sizeof (str_error),
                              /* TRANSLATORS: %s is the error returned by regerror */
                              _("invalid regular expression (%s)"),
                              buf);
                    gui_filter_new_error (name, str_error);
                    free (regex_prefix);
                    free (regex1);
                    return NULL;
                }
            }
        }

        if (pos_regex_message && pos_regex_message[0])
        {
            regex2 = malloc (sizeof (*regex2));
            if (regex2)
            {
                rc = string_regcomp (regex2, pos_regex_message,
                                     REG_EXTENDED | REG_ICASE | REG_NOSUB);
                if (rc != 0)
                {
                    regerror (rc, regex2, buf, sizeof (buf));
                    snprintf (str_error, sizeof (str_error),
                              /* TRANSLATORS: %s is the error returned by regerror */
                              _("invalid regular expression (%s)"),
                              buf);
                    gui_filter_new_error (name, str_error);
                    if (regex_prefix)
                        free (regex_prefix);
                    if (regex1)
                    {
                        regfree (regex1);
                        free (regex1);
                    }
                    free (regex2);
                    return NULL;
                }
            }
        }

        if (regex_prefix)
            free (regex_prefix);
    }

    /* create new filter */
    new_filter = malloc (sizeof (*new_filter));
    if (new_filter)
    {
        /* init filter */
        new_filter->enabled = enabled;
        new_filter->name = strdup (name);
        new_filter->buffer_name = strdup ((buffer_name) ? buffer_name : "*");
        new_filter->buffers = string_split (new_filter->buffer_name,
                                            ",", 0, 0,
                                            &new_filter->num_buffers);
        new_filter->tags = (tags) ? strdup (tags) : NULL;
        new_filter->tags_count = 0;
        new_filter->tags_array = NULL;
        if (new_filter->tags)
        {
            tags_array = string_split (new_filter->tags, ",", 0, 0,
                                       &new_filter->tags_count);
            if (tags_array)
            {
                new_filter->tags_array = malloc (new_filter->tags_count *
                                                 sizeof (*new_filter->tags_array));
                if (new_filter->tags_array)
                {
                    for (i = 0; i < new_filter->tags_count; i++)
                    {
                        new_filter->tags_array[i] = string_split (tags_array[i],
                                                                  "+", 0, 0,
                                                                  NULL);
                    }
                }
                string_free_split (tags_array);
            }
        }
        new_filter->regex = strdup (regex);
        new_filter->regex_prefix = regex1;
        new_filter->regex_message = regex2;

        /* add filter to filters list */
        new_filter->prev_filter = last_gui_filter;
        if (gui_filters)
            last_gui_filter->next_filter = new_filter;
        else
            gui_filters = new_filter;
        last_gui_filter = new_filter;
        new_filter->next_filter = NULL;

        (void) hook_signal_send ("filter_added",
                                 WEECHAT_HOOK_SIGNAL_POINTER, new_filter);
    }
    else
    {
        gui_filter_new_error (name, _("not enough memory"));
    }

    return new_filter;
}
Пример #17
0
int main(int argc, char *argv[])
{
    char *temp;
    int did_explicit_auth = 0;
    char *tickets = NULL;
    char prompt[CHIRP_LINE_MAX];
    char line[CHIRP_LINE_MAX];
    char **user_argv = 0;
    int user_argc;
    signed char c;
    int result = 0;

    debug_config(argv[0]);

    static struct option long_options[] = {
        {"auth", required_argument, 0, 'a'},
        {"debug", required_argument, 0, 'd'},
        {"debug-file", required_argument, 0, 'o'},
        {"tickets", required_argument, 0, 'i'},
        {"verbose", no_argument, 0, 'l'},
        {"timeout", required_argument, 0, 't'},
        {"version", no_argument, 0, 'v'},
        {"help", no_argument, 0, 'h'},
        {0, 0, 0, 0}
    };

    while((c = getopt_long(argc, argv, "+a:d:hi:lt:v", long_options, NULL)) > -1) {
        switch (c) {
        case 'a':
            auth_register_byname(optarg);
            did_explicit_auth = 1;
            break;
        case 'd':
            debug_flags_set(optarg);
            break;
        case 'o':
            debug_config_file(optarg);
            break;
        case 'h':
            show_help(argv[0]);
            exit(0);
            break;
        case 'i':
            tickets = strdup(optarg);
            break;
        case 'l':
            long_information = 1;
            break;
        case 't':
            timeout = string_time_parse(optarg);
            break;
        case 'v':
            cctools_version_print(stdout, argv[0]);
            exit(0);
            break;
        }
    }

    cctools_version_debug(D_DEBUG, argv[0]);

    if(!did_explicit_auth)
        auth_register_all();
    if(tickets) {
        auth_ticket_load(tickets);
        free(tickets);
    } else if(getenv(CHIRP_CLIENT_TICKETS)) {
        auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS));
    } else {
        auth_ticket_load(NULL);
    }

    getcwd(current_local_dir, CHIRP_PATH_MAX);

    /* interactive mode if input is a TTY but we are not simply executing a
     * command from argv */
    interactive_mode = isatty(0) && !((argc - optind) > 1);

    if(optind < argc) {
        stoptime = time(0) + timeout;
        if(do_open(1, &argv[optind - 1])) {
            fprintf(stderr, "couldn't open %s: %s\n", argv[optind], strerror(errno));
            return 1;
        }
    }

    if((argc - optind) > 1) {
        return !process_command(argc - optind - 1, &argv[optind + 1]);
    }

    while(1) {
        if(interactive_mode) {
            sprintf(prompt, " chirp:%s:%s> ", current_host, current_remote_dir);
        } else {
            prompt[0] = 0;
        }

#ifdef HAS_LIBREADLINE
        temp = readline(prompt);
        if(!temp)
            break;
        strcpy(line, temp);
        free(temp);
#else
        printf("%s", prompt);
        fflush(stdout);
        if(!fgets(line, CHIRP_LINE_MAX, stdin))
            break;
#endif

        if(!line[0])
            continue;

        if(!interactive_mode && (temp = strchr(line, '#'))) {	/* comment? */
            for(temp--; temp > line && isspace((int) *temp); temp--);	/* preceding space? */
            if(temp <= line)
                continue;	/* else not comment */
        }
#ifdef HAS_LIBREADLINE
        add_history(line);
#endif

        {
            char *start = line, *last = strlen(line) + line;
            while(*start != '\0') {	/* process compound commands */
                char *end = strchr(start, ';');
                while(end != NULL && end != start && *(end - 1) == '\\')
                    end = strchr(end + 1, ';');
                if(end == NULL)
                    end = start + strlen(start);
                *end = '\0';

                if(user_argv)
                    free(user_argv);
                string_split(start, &user_argc, &user_argv);
                if(user_argc == 0) {
                    start++;
                    continue;
                }
                result = process_command(user_argc, user_argv);
                start = end == last ? last : end + 1;
            }
        }
        if(!interactive_mode && !result)
            break;
    }

    if(result) {
        return 0;
    } else {
        return 1;
    }
}
Пример #18
0
static void *udev_input_init(void)
{
   udev_input_t *udev = (udev_input_t*)calloc(1, sizeof(*udev));

   if (!udev)
      return NULL;

   udev->udev = udev_new();
   if (!udev->udev)
   {
      RARCH_ERR("Failed to create udev handle.\n");
      goto error;
   }

   udev->monitor = udev_monitor_new_from_netlink(udev->udev, "udev");
   if (udev->monitor)
   {
      udev_monitor_filter_add_match_subsystem_devtype(udev->monitor, "input", NULL);
      udev_monitor_enable_receiving(udev->monitor);
   }

#ifdef HAVE_XKBCOMMON
   udev->mod_map_idx = (xkb_mod_index_t *)calloc(MOD_MAP_SIZE, sizeof(xkb_mod_index_t));

   if (!udev->mod_map_idx)
      goto error;

   udev->mod_map_bit = (uint16_t*)calloc(MOD_MAP_SIZE, sizeof(uint16_t));

   if (!udev->mod_map_bit)
      goto error;

   udev->xkb_ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
   if (udev->xkb_ctx)
   {
      struct string_list *list = NULL;
      struct xkb_rule_names rule = {0};

      rule.rules = "evdev";

      if (*g_settings.input.keyboard_layout)
      {
         list = string_split(g_settings.input.keyboard_layout, ":");
         if (list && list->size >= 2)
            rule.variant = list->elems[1].data;
         if (list && list->size >= 1)
            rule.layout = list->elems[0].data;
      }

      udev->xkb_map = xkb_keymap_new_from_names(udev->xkb_ctx, &rule, XKB_MAP_COMPILE_NO_FLAGS);
      if (list)
         string_list_free(list);
   }
   if (udev->xkb_map)
   {
      xkb_mod_index_t *map_idx = (xkb_mod_index_t*)&udev->mod_map_idx[0];
      uint16_t        *map_bit = (uint16_t*)&udev->mod_map_bit[0];

      udev->xkb_state = xkb_state_new(udev->xkb_map);

      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_CAPS);
      map_idx++;
      *map_bit = RETROKMOD_CAPSLOCK;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_SHIFT);
      map_idx++;
      *map_bit = RETROKMOD_SHIFT;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_CTRL);
      map_idx++;
      *map_bit = RETROKMOD_CTRL;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_ALT);
      map_idx++;
      *map_bit = RETROKMOD_ALT;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_LOGO);
      *map_bit = RETROKMOD_META;
   }
#endif

   udev->epfd = epoll_create(32);
   if (udev->epfd < 0)
   {
      RARCH_ERR("Failed to create epoll FD.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_KEYBOARD", udev_handle_keyboard))
   {
      RARCH_ERR("Failed to open keyboard.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_MOUSE", udev_handle_mouse))
   {
      RARCH_ERR("Failed to open mouse.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_TOUCHPAD", udev_handle_touchpad))
   {
      RARCH_ERR("Failed to open touchpads.\n");
      goto error;
   }

   /* If using KMS and we forgot this, 
    * we could lock ourselves out completely. */
   if (!udev->num_devices)
      RARCH_WARN("[udev]: Couldn't open any keyboard, mouse or touchpad. Are permissions set correctly for /dev/input/event*?\n");

   udev->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
   input_keymaps_init_keyboard_lut(rarch_key_map_linux);

   disable_terminal_input();
   return udev;

error:
   udev_input_free(udev);
   return NULL;
}
Пример #19
0
core_info_list_t *core_info_list_new(void)
{
   size_t i;
   core_info_t *core_info = NULL;
   core_info_list_t *core_info_list = NULL;
   settings_t *settings = config_get_ptr();
   struct string_list *contents = dir_list_new_special(NULL, DIR_LIST_CORES, NULL);

   if (!contents)
      return NULL;

   core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
   if (!core_info_list)
      goto error;

   core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
   if (!core_info)
      goto error;

   core_info_list->list = core_info;
   core_info_list->count = contents->size;

   for (i = 0; i < contents->size; i++)
   {
      config_file_t *conf                  = NULL;
      char info_path_base[PATH_MAX_LENGTH] = {0};
      char info_path[PATH_MAX_LENGTH]      = {0};
      core_info[i].path = strdup(contents->elems[i].data);

      if (!core_info[i].path)
         break;

      fill_pathname_base(info_path_base, contents->elems[i].data,
            sizeof(info_path_base));
      path_remove_extension(info_path_base);

#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP))
      char *substr = strrchr(info_path_base, '_');
      if (substr)
         *substr = '\0';
#endif

      strlcat(info_path_base, ".info", sizeof(info_path_base));

      fill_pathname_join(info_path, (*settings->libretro_info_path) ?
            settings->libretro_info_path : settings->libretro_directory,
            info_path_base, sizeof(info_path));

      conf = config_file_new(info_path);

      if (conf)
      {
         unsigned count = 0;
         config_get_string(conf, "display_name",
               &core_info[i].display_name);
         config_get_string(conf, "corename",
               &core_info[i].core_name);
         config_get_string(conf, "systemname",
               &core_info[i].systemname);
         config_get_string(conf, "manufacturer",
               &core_info[i].system_manufacturer);
         config_get_uint(conf, "firmware_count", &count);
         core_info[i].firmware_count = count;
         if (config_get_string(conf, "supported_extensions",
                  &core_info[i].supported_extensions) &&
               core_info[i].supported_extensions)
            core_info[i].supported_extensions_list =
               string_split(core_info[i].supported_extensions, "|");

         if (config_get_string(conf, "authors",
                  &core_info[i].authors) &&
               core_info[i].authors)
            core_info[i].authors_list =
               string_split(core_info[i].authors, "|");

         if (config_get_string(conf, "permissions",
                  &core_info[i].permissions) &&
               core_info[i].permissions)
            core_info[i].permissions_list =
               string_split(core_info[i].permissions, "|");

         if (config_get_string(conf, "license",
                  &core_info[i].licenses) &&
               core_info[i].licenses)
            core_info[i].licenses_list =
               string_split(core_info[i].licenses, "|");

         if (config_get_string(conf, "categories",
                  &core_info[i].categories) &&
               core_info[i].categories)
            core_info[i].categories_list =
               string_split(core_info[i].categories, "|");

         if (config_get_string(conf, "database",
                  &core_info[i].databases) &&
               core_info[i].databases)
            core_info[i].databases_list =
               string_split(core_info[i].databases, "|");

         if (config_get_string(conf, "notes",
                  &core_info[i].notes) &&
               core_info[i].notes)
            core_info[i].note_list = string_split(core_info[i].notes, "|");

         config_get_bool(conf, "supports_no_game",
               &core_info[i].supports_no_game);

         core_info[i].config_data = conf;
      }

      if (!core_info[i].display_name)
         core_info[i].display_name = strdup(path_basename(core_info[i].path));
   }

   core_info_list_resolve_all_extensions(core_info_list);
   core_info_list_resolve_all_firmware(core_info_list);

   dir_list_free(contents);
   return core_info_list;

error:
   if (contents)
      dir_list_free(contents);
   core_info_list_free(core_info_list);
   return NULL;
}
Пример #20
0
void console_start() {
	char **parameters;
	char command[512];
	int exit = 0;

	strcpy(currentDirPrompt, "/");
	strcpy(currentDirId, ROOT_DIR_ID);

	do {
		printf("%s > ", currentDirPrompt);
		readCommand(command);
		// El trim de las commons tira error a veces.. string_trim(&command);

		// Ignore empty enter
		if (command[0] != '\0') {
			parameters = string_split(command, " ");

			if (string_equals_ignore_case(parameters[0], "format")) {
				format();
			} else if (string_equals_ignore_case(parameters[0], "df")) {
				diskFree();
			} else if (string_equals_ignore_case(parameters[0], "rm")) {
				deleteResource(parameters);
			} else if (string_equals_ignore_case(parameters[0], "mv")) {
				moveResource(parameters[1], parameters[2]);
			} else if (string_equals_ignore_case(parameters[0], "rename")) {
				renameResource(parameters[1], parameters[2]);
			} else if (string_equals_ignore_case(parameters[0], "mkdir")) {
				makeDir(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "cd")) {
				changeDir(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "ll")) {
				listResources();
			} else if (string_equals_ignore_case(parameters[0], "md5sum")) {
				md5sum(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "cp")) {
				copyFile(parameters);
			} else if (string_equals_ignore_case(parameters[0], "blocks")) {
				printFileBlocks(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "catb")) {
				saveBlockContents(parameters);
			} else if (string_equals_ignore_case(parameters[0], "cpb")) {
				copyBlock(parameters);
			} else if (string_equals_ignore_case(parameters[0], "rmb")) {
				deleteBlock(parameters);
			} else if (string_equals_ignore_case(parameters[0], "nodestat")) {
				printNodeStatus(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "enablen")) {
				enableNode(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "disablen")) {
				disableNode(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "help")) {
				help();
			} else if (string_equals_ignore_case(parameters[0], "exit")) {
				exit = 1;
			} else if (string_equals_ignore_case(parameters[0], "\n")) {
				// ignore enter
			} else {
				printf("Invalid command \n");
			}
			freeSplits(parameters);
		}
	} while (!exit);

	printf("bye\n");
}
Пример #21
0
static int database_cursor_iterate(libretrodb_cursor_t *cur,
      database_info_t *db_info)
{
   unsigned i;
   struct rmsgpack_dom_value item;
   const char* str                = NULL;

   if (libretrodb_cursor_read_item(cur, &item) != 0)
      return -1;

   if (item.type != RDT_MAP)
   {
      rmsgpack_dom_value_free(&item);
      return 1;
   }

   db_info->analog_supported       = -1;
   db_info->rumble_supported       = -1;

   for (i = 0; i < item.val.map.len; i++)
   {
      uint32_t                 value = 0;
      struct rmsgpack_dom_value *key = &item.val.map.items[i].key;
      struct rmsgpack_dom_value *val = &item.val.map.items[i].value;

      if (!key || !val)
         continue;

      str   = key->val.string.buff;
      value = msg_hash_calculate(str);

      switch (value)
      {
         case DB_CURSOR_SERIAL:
            db_info->serial = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_ROM_NAME:
            db_info->rom_name = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_NAME:
            db_info->name = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_DESCRIPTION:
            db_info->description = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_PUBLISHER:
            db_info->publisher = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_DEVELOPER:
            db_info->developer = string_split(val->val.string.buff, "|");
            break;
         case DB_CURSOR_ORIGIN:
            db_info->origin = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_FRANCHISE:
            db_info->franchise = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_BBFC_RATING:
            db_info->bbfc_rating = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_ESRB_RATING:
            db_info->esrb_rating = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_ELSPA_RATING:
            db_info->elspa_rating = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_CERO_RATING:
            db_info->cero_rating = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_PEGI_RATING:
            db_info->pegi_rating = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_ENHANCEMENT_HW:
            db_info->enhancement_hw = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_EDGE_MAGAZINE_REVIEW:
            db_info->edge_magazine_review = strdup(val->val.string.buff);
            break;
         case DB_CURSOR_EDGE_MAGAZINE_RATING:
            db_info->edge_magazine_rating = val->val.uint_;
            break;
         case DB_CURSOR_EDGE_MAGAZINE_ISSUE:
            db_info->edge_magazine_issue = val->val.uint_;
            break;
         case DB_CURSOR_FAMITSU_MAGAZINE_RATING:
            db_info->famitsu_magazine_rating = val->val.uint_;
            break;
         case DB_CURSOR_MAX_USERS:
            db_info->max_users = val->val.uint_;
            break;
         case DB_CURSOR_RELEASEDATE_MONTH:
            db_info->releasemonth = val->val.uint_;
            break;
         case DB_CURSOR_RELEASEDATE_YEAR:
            db_info->releaseyear = val->val.uint_;
            break;
         case DB_CURSOR_RUMBLE_SUPPORTED:
            db_info->rumble_supported = val->val.uint_;
            break;
         case DB_CURSOR_ANALOG_SUPPORTED:
            db_info->analog_supported = val->val.uint_;
            break;
         case DB_CURSOR_SIZE:
            db_info->size = val->val.uint_;
            break;
         case DB_CURSOR_CHECKSUM_CRC32:
            db_info->crc32 = swap_if_little32(*(uint32_t*)val->val.binary.buff);
            break;
         case DB_CURSOR_CHECKSUM_SHA1:
            db_info->sha1 = bin_to_hex_alloc((uint8_t*)val->val.binary.buff, val->val.binary.len);
            break;
         case DB_CURSOR_CHECKSUM_MD5:
            db_info->md5 = bin_to_hex_alloc((uint8_t*)val->val.binary.buff, val->val.binary.len);
            break;
         default:
            RARCH_LOG("Unknown key: %s\n", str);
            break;
      }
   }

   rmsgpack_dom_value_free(&item);

   return 0;
}
Пример #22
0
int
gui_chat_hsignal_quote_line_cb (void *data, const char *signal,
                                struct t_hashtable *hashtable)
{
    const char *time, *prefix, *message, *date, *nick, *tags;
    unsigned int length_time, length_prefix, length_message, length;
    char *str, *ptr_str_time, *custom_nick_prefix;
    static char str_time[128];
    struct tm local_time;
    int tags_count, i, custom_nick_ok = 0;
    char **tags_array;

    /* make C compiler happy */
    (void) data;

    if (!gui_current_window->buffer->input)
        return WEECHAT_RC_OK;

    if (strstr(signal, "time"))
    {
        if (!CONFIG_STRING(config_look_quote_time_format) ||
            !CONFIG_STRING(config_look_quote_time_format)[0])
            time = hashtable_get (hashtable, "_chat_line_time");
        else
        {
            date = hashtable_get (hashtable, "_chat_line_date");
            if (date && date[0] && strptime (date, "%s", &local_time) && mktime(&local_time) != 0)
            {
                str_time[0] = '\0';
                strftime (str_time, sizeof (str_time),
                    CONFIG_STRING(config_look_quote_time_format),
                    &local_time);
                length_time = strlen(str_time);
                ptr_str_time = malloc (length_time);
                strncpy (ptr_str_time, str_time, length_time);
                time = ptr_str_time;
            }
            else
                time = NULL;
        }
    }
    else
        time = NULL;
    prefix = (strstr (signal, "prefix")) ?
        hashtable_get (hashtable, "_chat_line_prefix") : NULL;
    message = hashtable_get (hashtable, "_chat_line_message");

    if (!message)
        return WEECHAT_RC_OK;

    length_time = (time) ? strlen (time) : 0;
    length_prefix = (prefix) ? strlen (prefix) : 0;
    length_message = strlen (message);

    nick = hashtable_get (hashtable, "_chat_line_nick");
    tags = hashtable_get (hashtable, "_chat_line_tags");

    if (prefix && nick && nick[0] &&
        CONFIG_STRING(config_look_quote_nick_format) &&
        CONFIG_STRING(config_look_quote_nick_format)[0])
    {
        tags_array = string_split (tags, ",", 0, 0, &tags_count);
        if (tags_array)
        {
            for (i = 0; i < tags_count; i++)
            {
                if (!strcmp (tags_array[i], "irc_privmsg"))
                    custom_nick_ok = 1;
                else if (!strcmp (tags_array[i], "irc_action"))
                {
                    custom_nick_ok = 0;
                    break;
                }
            }
            string_free_split(tags_array);
            if (custom_nick_ok)
            {
                custom_nick_prefix = malloc (255);
                length_prefix = snprintf (custom_nick_prefix, sizeof (custom_nick_prefix), CONFIG_STRING(config_look_quote_nick_format), nick);
                if (length_prefix >= sizeof (custom_nick_prefix))
                {
                    custom_nick_prefix = realloc (custom_nick_prefix, length_prefix + 1);
                    snprintf (custom_nick_prefix, length_prefix, CONFIG_STRING(config_look_quote_nick_format), nick);
                }
            }
        }
    }
    length = length_time + 1 + length_prefix + 1 +
        strlen (CONFIG_STRING(config_look_prefix_suffix)) + 1 +
        length_message + 1 + 1;
    str = malloc (length);
    if (str)
    {
        if (custom_nick_ok)
        {
            snprintf (str, length, "%s%s%s%s%s ",
                      (time) ? time : "",
                      (time) ? " " : "",
                      (prefix) ? custom_nick_prefix : "",
                      (prefix) ? " " : "",
                      message);
        }
        else
        {
            snprintf (str, length, "%s%s%s%s%s%s%s ",
                      (time) ? time : "",
                      (time && !(prefix && prefix[0] == ' ')) ? " " : "",
                      (prefix) ? prefix : "",
                      (prefix && prefix[0]) ? " " : "",
                      ((time || prefix) && CONFIG_BOOLEAN(config_look_quote_show_prefix_suffix)) ? CONFIG_STRING(config_look_prefix_suffix) : "",
                      ((time || prefix) && CONFIG_BOOLEAN(config_look_quote_show_prefix_suffix) && CONFIG_STRING(config_look_prefix_suffix)
                       && CONFIG_STRING(config_look_prefix_suffix)[0]) ? " " : "",
                      message);
        }
        gui_input_insert_string (gui_current_window->buffer, str, -1);
        gui_input_text_changed_modifier_and_signal (gui_current_window->buffer,
                                                    1, /* save undo */
                                                    1); /* stop completion */
        free (str);
    }

    return WEECHAT_RC_OK;
}
Пример #23
0
void xml_read_node(XMLReader& reader, Node *node, xml_node xml_node)
{
	xml_attribute name_attr = xml_node.attribute("name");
	if(name_attr) {
		node->name = ustring(name_attr.value());
	}

	foreach(const SocketType& socket, node->type->inputs) {
		if(socket.type == SocketType::CLOSURE || socket.type == SocketType::UNDEFINED) {
			continue;
		}
		if(socket.flags & SocketType::INTERNAL) {
			continue;
		}

		xml_attribute attr = xml_node.attribute(socket.name.c_str());

		if(!attr) {
			continue;
		}

		switch(socket.type)
		{
			case SocketType::BOOLEAN:
			{
				node->set(socket, xml_read_boolean(attr.value()));
				break;
			}
			case SocketType::BOOLEAN_ARRAY:
			{
				vector<string> tokens;
				string_split(tokens, attr.value());

				array<bool> value;
				value.resize(tokens.size());
				for(size_t i = 0; i < value.size(); i++)
					value[i] = xml_read_boolean(tokens[i].c_str());
				node->set(socket, value);
				break;
			}
			case SocketType::FLOAT:
			{
				node->set(socket, (float)atof(attr.value()));
				break;
			}
			case SocketType::FLOAT_ARRAY:
			{
				array<float> value;
				xml_read_float_array<1>(value, attr);
				node->set(socket, value);
				break;
			}
			case SocketType::INT:
			{
				node->set(socket, (int)atoi(attr.value()));
				break;
			}
			case SocketType::UINT:
			{
				node->set(socket, (uint)atoi(attr.value()));
				break;
			}
			case SocketType::INT_ARRAY:
			{
				vector<string> tokens;
				string_split(tokens, attr.value());

				array<int> value;
				value.resize(tokens.size());
				for(size_t i = 0; i < value.size(); i++) {
					value[i] = (int)atoi(attr.value());
				}
				node->set(socket, value);
				break;
			}
			case SocketType::COLOR:
			case SocketType::VECTOR:
			case SocketType::POINT:
			case SocketType::NORMAL:
			{
				array<float3> value;
				xml_read_float_array<3>(value, attr);
				if(value.size() == 1) {
					node->set(socket, value[0]);
				}
				break;
			}
			case SocketType::COLOR_ARRAY:
			case SocketType::VECTOR_ARRAY:
			case SocketType::POINT_ARRAY:
			case SocketType::NORMAL_ARRAY:
			{
				array<float3> value;
				xml_read_float_array<3>(value, attr);
				node->set(socket, value);
				break;
			}
			case SocketType::POINT2:
			{
				array<float2> value;
				xml_read_float_array<2>(value, attr);
				if(value.size() == 1) {
					node->set(socket, value[0]);
				}
				break;
			}
			case SocketType::POINT2_ARRAY:
			{
				array<float2> value;
				xml_read_float_array<2>(value, attr);
				node->set(socket, value);
				break;
			}
			case SocketType::STRING:
			{
				node->set(socket, attr.value());
				break;
			}
			case SocketType::ENUM:
			{
				ustring value(attr.value());
				if(socket.enum_values->exists(value)) {
					node->set(socket, value);
				}
				else {
					fprintf(stderr, "Unknown value \"%s\" for attribute \"%s\".\n", value.c_str(), socket.name.c_str());
				}
				break;
			}
			case SocketType::STRING_ARRAY:
			{
				vector<string> tokens;
				string_split(tokens, attr.value());

				array<ustring> value;
				value.resize(tokens.size());
				for(size_t i = 0; i < value.size(); i++) {
					value[i] = ustring(tokens[i]);
				}
				node->set(socket, value);
				break;
			}
			case SocketType::TRANSFORM:
			{
				array<Transform> value;
				xml_read_float_array<12>(value, attr);
				if(value.size() == 1) {
					node->set(socket, value[0]);
				}
				break;
			}
			case SocketType::TRANSFORM_ARRAY:
			{
				array<Transform> value;
				xml_read_float_array<12>(value, attr);
				node->set(socket, value);
				break;
			}
			case SocketType::NODE:
			{
				ustring value(attr.value());
				map<ustring, Node*>::iterator it = reader.node_map.find(value);
				if(it != reader.node_map.end())
				{
					Node *value_node = it->second;
					if(value_node->type == *(socket.node_type))
						node->set(socket, it->second);
				}
				break;
			}
			case SocketType::NODE_ARRAY:
			{
				vector<string> tokens;
				string_split(tokens, attr.value());

				array<Node*> value;
				value.resize(tokens.size());
				for(size_t i = 0; i < value.size(); i++)
				{
					map<ustring, Node*>::iterator it = reader.node_map.find(ustring(tokens[i]));
					if(it != reader.node_map.end())
					{
						Node *value_node = it->second;
						value[i] = (value_node->type == *(socket.node_type)) ? value_node : NULL;
					}
					else
					{
						value[i] = NULL;
					}
				}
				node->set(socket, value);
				break;
			}
			case SocketType::CLOSURE:
			case SocketType::UNDEFINED:
				break;
		}
	}

	if(!node->name.empty())
		reader.node_map[node->name] = node;
}
Пример #24
0
config_file_t *config_file_new_from_string(const char *from_string)
{
   size_t i;
   bool no_checks            = false;
   struct string_list *lines = NULL;
   struct config_file *conf  = (struct config_file*)malloc(sizeof(*conf));
   if (!conf)
      return NULL;

   if (!from_string)
      return conf;

   conf->path                     = NULL;
   conf->entries                  = NULL;
   conf->tail                     = NULL;
   conf->last                     = NULL;
   conf->includes                 = NULL;
   conf->include_depth            = 0;
   conf->guaranteed_no_duplicates = false ;

   lines = string_split(from_string, "\n");
   if (!lines)
      return conf;

   for (i = 0; i < lines->size; i++)
   {
      struct config_entry_list *list = (struct config_entry_list*)malloc(sizeof(*list));
      char                    *line  = lines->elems[i].data;

      if (!list)
      {
         string_list_free(lines);
         config_file_free(conf);
         return NULL;
      }

      list->readonly  = false;
      list->key       = NULL;
      list->value     = NULL;
      list->next      = NULL;

      if (line && conf)
      {
         if (*line && parse_line(conf, list, line, NULL, no_checks))
         {
            if (conf->entries)
               conf->tail->next = list;
            else
               conf->entries = list;

            conf->tail = list;
         }
      }

      if (list != conf->tail)
         free(list);
   }

   string_list_free(lines);

   return conf;
}
Пример #25
0
void
gui_bar_window_draw (struct t_gui_bar_window *bar_window,
                     struct t_gui_window *window)
{
    int x, y, items_count, num_lines, line;
    enum t_gui_bar_filling filling;
    char *content, **items;
    static char str_start_input[16] = { '\0' };
    static char str_start_input_hidden[16] = { '\0' };
    static char str_cursor[16] = { '\0' };
    char *pos_start_input, *pos_after_start_input, *pos_cursor, *buf;
    char *new_start_input, *ptr_string;
    static int length_start_input, length_start_input_hidden;
    int length_on_screen;
    int chars_available, index, size;
    int length_screen_before_cursor, length_screen_after_cursor;
    int diff, max_length, optimal_number_of_lines;
    int some_data_not_displayed;
    int index_item, index_subitem, index_line;

    if (!gui_init_ok)
        return;

    if (gui_window_bare_display)
        return;

    if ((bar_window->x < 0) || (bar_window->y < 0))
        return;

    if (!str_start_input[0])
    {
        snprintf (str_start_input, sizeof (str_start_input), "%c%c%c",
                  GUI_COLOR_COLOR_CHAR,
                  GUI_COLOR_BAR_CHAR,
                  GUI_COLOR_BAR_START_INPUT_CHAR);
        length_start_input = strlen (str_start_input);

        snprintf (str_start_input_hidden, sizeof (str_start_input_hidden), "%c%c%c",
                  GUI_COLOR_COLOR_CHAR,
                  GUI_COLOR_BAR_CHAR,
                  GUI_COLOR_BAR_START_INPUT_HIDDEN_CHAR);
        length_start_input_hidden = strlen (str_start_input_hidden);

        snprintf (str_cursor, sizeof (str_cursor), "%c%c%c",
                  GUI_COLOR_COLOR_CHAR,
                  GUI_COLOR_BAR_CHAR,
                  GUI_COLOR_BAR_MOVE_CURSOR_CHAR);
    }

    /*
     * these values will be overwritten later (by gui_bar_window_print_string)
     * if cursor has to move somewhere in bar window
     */
    bar_window->cursor_x = -1;
    bar_window->cursor_y = -1;

    /* remove coords */
    gui_bar_window_coords_free (bar_window);
    index_item = -1;
    index_subitem = -1;
    index_line = 0;

    gui_window_current_emphasis = 0;

    filling = gui_bar_get_filling (bar_window->bar);

    content = gui_bar_window_content_get_with_filling (bar_window, window);
    if (content)
    {
        if ((filling == GUI_BAR_FILLING_HORIZONTAL)
            && (bar_window->scroll_x > 0))
        {
            length_on_screen = gui_chat_strlen_screen (content);
            if (bar_window->scroll_x > length_on_screen - bar_window->width)
            {
                bar_window->scroll_x = length_on_screen - bar_window->width;
                if (bar_window->scroll_x < 0)
                    bar_window->scroll_x = 0;
            }
        }

        items = string_split (content, "\n", 0, 0, &items_count);
        if (items_count == 0)
        {
            if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SIZE]) == 0)
                gui_bar_window_set_current_size (bar_window, window, 1);
            gui_window_clear (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                              CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]),
                              CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
        }
        else
        {
            /* bar with auto size ? then compute new size, according to content */
            if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SIZE]) == 0)
            {
                /* search longer line and optimal number of lines */
                max_length = 0;
                optimal_number_of_lines = 0;
                for (line = 0; line < items_count; line++)
                {
                    length_on_screen = gui_chat_strlen_screen (items[line]);

                    pos_cursor = strstr (items[line], str_cursor);
                    if (pos_cursor && (gui_chat_strlen_screen (pos_cursor) == 0))
                        length_on_screen++;

                    if (length_on_screen > max_length)
                        max_length = length_on_screen;

                    if (length_on_screen % bar_window->width == 0)
                        num_lines = length_on_screen / bar_window->width;
                    else
                        num_lines = (length_on_screen / bar_window->width) + 1;
                    if (num_lines == 0)
                        num_lines = 1;
                    optimal_number_of_lines += num_lines;
                }
                if (max_length == 0)
                    max_length = 1;

                switch (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_POSITION]))
                {
                    case GUI_BAR_POSITION_BOTTOM:
                    case GUI_BAR_POSITION_TOP:
                        if (filling == GUI_BAR_FILLING_HORIZONTAL)
                            num_lines = optimal_number_of_lines;
                        else
                            num_lines = items_count;
                        gui_bar_window_set_current_size (bar_window, window,
                                                         num_lines);
                        break;
                    case GUI_BAR_POSITION_LEFT:
                    case GUI_BAR_POSITION_RIGHT:
                        gui_bar_window_set_current_size (bar_window, window,
                                                         max_length);
                        break;
                    case GUI_BAR_NUM_POSITIONS:
                        break;
                }
            }

            gui_window_clear (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                              CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]),
                              CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
            x = 0;
            y = 0;
            some_data_not_displayed = 0;
            if ((bar_window->scroll_y > 0)
                && (bar_window->scroll_y > items_count - bar_window->height))
            {
                bar_window->scroll_y = items_count - bar_window->height;
                if (bar_window->scroll_y < 0)
                    bar_window->scroll_y = 0;
            }
            for (line = 0;
                 (line < items_count) && (y < bar_window->height);
                 line++)
            {
                pos_start_input = strstr (items[line], str_start_input);
                if (pos_start_input)
                {
                    pos_after_start_input = pos_start_input + strlen (str_start_input);
                    pos_cursor = strstr (pos_after_start_input, str_cursor);
                    if (pos_cursor)
                    {
                        chars_available =
                            ((bar_window->height - y - 1) * bar_window->width) + /* next lines */
                            (bar_window->width - x - 1); /* chars on current line */

                        length_screen_before_cursor = -1;
                        length_screen_after_cursor = -1;

                        buf = string_strndup (items[line], pos_cursor - items[line]);
                        if (buf)
                        {
                            length_screen_before_cursor = gui_chat_strlen_screen (buf);
                            length_screen_after_cursor = gui_chat_strlen_screen (pos_cursor);
                            free (buf);
                        }

                        if ((length_screen_before_cursor < 0) || (length_screen_after_cursor < 0))
                            length_screen_before_cursor = gui_chat_strlen_screen (items[line]);

                        diff = length_screen_before_cursor - chars_available;
                        if (diff > 0)
                        {
                            if (CONFIG_INTEGER(config_look_input_cursor_scroll) > 0)
                            {
                                diff += (CONFIG_INTEGER(config_look_input_cursor_scroll)
                                         - 1
                                         - (diff % CONFIG_INTEGER(config_look_input_cursor_scroll)));
                            }

                            /* compute new start for displaying input */
                            new_start_input = pos_after_start_input +
                                gui_chat_string_real_pos (pos_after_start_input,
                                                          diff, 1);
                            if (new_start_input > pos_cursor)
                                new_start_input = pos_cursor;

                            buf = malloc (strlen (items[line]) + length_start_input_hidden + 1);
                            if (buf)
                            {
                                /* add string before start of input */
                                index = 0;
                                if (pos_start_input > items[line])
                                {
                                    size = pos_start_input - items[line];
                                    memmove (buf, items[line], size);
                                    index += size;
                                }
                                /* add tag "start_input_hidden" */
                                memmove (buf + index, str_start_input_hidden, length_start_input_hidden);
                                index += length_start_input_hidden;
                                /* add hidden part of input */
                                size = new_start_input - pos_after_start_input;
                                memmove (buf + index, pos_after_start_input, size);
                                index += size;
                                /* add tag "start_input" */
                                memmove (buf + index, str_start_input, length_start_input);
                                index += length_start_input;
                                /* add input (will be displayed) */
                                size = strlen (new_start_input) + 1;
                                memmove (buf + index, new_start_input, size);

                                free (items[line]);
                                items[line] = buf;
                            }
                        }

                    }
                }

                if ((bar_window->scroll_y == 0)
                    || (line >= bar_window->scroll_y))
                {
                    if (!gui_bar_window_print_string (bar_window, filling,
                                                      &x, &y,
                                                      items[line], 1, 1,
                                                      &index_item,
                                                      &index_subitem,
                                                      &index_line))
                    {
                        some_data_not_displayed = 1;
                    }

                    if (x < bar_window->width)
                    {
                        if (filling == GUI_BAR_FILLING_HORIZONTAL)
                        {
                            gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                                                               CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]),
                                                               CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
                            gui_window_remove_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                                                           A_ALL_ATTR);
                            wclrtobot (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
                        }
                        else
                        {
                            gui_window_remove_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                                                           A_ALL_ATTR);
                        }
                        while (x < bar_window->width)
                        {
                            gui_bar_window_print_string (bar_window, filling,
                                                         &x, &y, " ", 0, 0,
                                                         &index_item,
                                                         &index_subitem,
                                                         &index_line);
                        }
                    }

                    x = 0;
                    y++;
                }
            }
            if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
                && ((bar_window->scroll_x > 0) || (bar_window->scroll_y > 0)))
            {
                if (filling == GUI_BAR_FILLING_HORIZONTAL)
                {
                    ptr_string = CONFIG_STRING(config_look_bar_more_left);
                    x = 0;
                }
                else
                {
                    ptr_string = CONFIG_STRING(config_look_bar_more_up);
                    x = bar_window->width - utf8_strlen_screen (ptr_string);
                    if (x < 0)
                        x = 0;
                }
                y = 0;
                if (ptr_string && ptr_string[0])
                {
                    gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                                                       CONFIG_COLOR(config_color_bar_more),
                                                       CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
                    mvwaddstr (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                               y, x, ptr_string);
                }
            }
            if ((bar_window->cursor_x < 0) && (bar_window->cursor_y < 0)
                && (some_data_not_displayed || (line < items_count)))
            {
                ptr_string = (filling == GUI_BAR_FILLING_HORIZONTAL) ?
                    CONFIG_STRING(config_look_bar_more_right) :
                    CONFIG_STRING(config_look_bar_more_down);
                x = bar_window->width - utf8_strlen_screen (ptr_string);
                if (x < 0)
                    x = 0;
                y = (bar_window->height > 1) ? bar_window->height - 1 : 0;
                if (ptr_string && ptr_string[0])
                {
                    gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                                                       CONFIG_COLOR(config_color_bar_more),
                                                       CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
                    mvwaddstr (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                               y, x, ptr_string);
                }
            }
        }
        if (items)
            string_free_split (items);
        free (content);
    }
    else
    {
        if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SIZE]) == 0)
            gui_bar_window_set_current_size (bar_window, window, 1);
        gui_window_clear (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
                          CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]),
                          CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
    }

    /*
     * move cursor if it was asked in an item content (input_text does that
     * to move cursor in user input text)
     */
    if ((!window || (gui_current_window == window))
        && (bar_window->cursor_x >= 0) && (bar_window->cursor_y >= 0))
    {
        y = bar_window->cursor_y - bar_window->y;
        x = bar_window->cursor_x - bar_window->x;
        if (x > bar_window->width - 2)
            x = bar_window->width - 2;
        wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, y, x);
        wrefresh (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
        if (!gui_cursor_mode)
        {
            gui_window_cursor_x = bar_window->cursor_x;
            gui_window_cursor_y = bar_window->cursor_y;
            move (bar_window->cursor_y, bar_window->cursor_x);
        }
    }
    else
        wnoutrefresh (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);

    if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SEPARATOR]))
    {
        switch (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_POSITION]))
        {
            case GUI_BAR_POSITION_BOTTOM:
                gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
                                              GUI_COLOR_SEPARATOR);
                gui_window_hline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
                                  0, 0, bar_window->width,
                                  CONFIG_STRING(config_look_separator_horizontal));
                break;
            case GUI_BAR_POSITION_TOP:
                gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
                                              GUI_COLOR_SEPARATOR);
                gui_window_hline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
                                  0, 0, bar_window->width,
                                  CONFIG_STRING(config_look_separator_horizontal));
                break;
            case GUI_BAR_POSITION_LEFT:
                gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
                                              GUI_COLOR_SEPARATOR);
                gui_window_vline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
                                  0, 0, bar_window->height,
                                  CONFIG_STRING(config_look_separator_vertical));
                break;
            case GUI_BAR_POSITION_RIGHT:
                gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
                                              GUI_COLOR_SEPARATOR);
                gui_window_vline (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator,
                                  0, 0, bar_window->height,
                                  CONFIG_STRING(config_look_separator_vertical));
                break;
            case GUI_BAR_NUM_POSITIONS:
                break;
        }
        wnoutrefresh (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_separator);
    }

    refresh ();
}
Пример #26
0
TEST(String, Split)
{
    char **argv;
    int argc;

    POINTERS_EQUAL(NULL, string_split (NULL, NULL, 0, 0, NULL));
    POINTERS_EQUAL(NULL, string_split (NULL, "", 0, 0, NULL));
    POINTERS_EQUAL(NULL, string_split ("", NULL, 0, 0, NULL));
    POINTERS_EQUAL(NULL, string_split ("", "", 0, 0, NULL));

    argc = -1;
    POINTERS_EQUAL(NULL, string_split (NULL, NULL, 0, 0, &argc));
    LONGS_EQUAL(0, argc);
    argc = -1;
    POINTERS_EQUAL(NULL, string_split (NULL, "", 0, 0, &argc));
    LONGS_EQUAL(0, argc);
    argc = -1;
    POINTERS_EQUAL(NULL, string_split ("", NULL, 0, 0, &argc));
    LONGS_EQUAL(0, argc);
    argc = -1;
    POINTERS_EQUAL(NULL, string_split ("", "", 0, 0, &argc));
    LONGS_EQUAL(0, argc);

    /* free split with NULL */
    string_free_split (NULL);

    /* standard split */
    argv = string_split (" abc de  fghi ", " ", 0, 0, &argc);
    LONGS_EQUAL(3, argc);
    CHECK(argv);
    STRCMP_EQUAL("abc", argv[0]);
    STRCMP_EQUAL("de", argv[1]);
    STRCMP_EQUAL("fghi", argv[2]);
    POINTERS_EQUAL(NULL, argv[3]);
    string_free_split (argv);

    /* max 2 items */
    argv = string_split (" abc de  fghi ", " ", 0, 2, &argc);
    LONGS_EQUAL(2, argc);
    CHECK(argv);
    STRCMP_EQUAL("abc", argv[0]);
    STRCMP_EQUAL("de", argv[1]);
    POINTERS_EQUAL(NULL, argv[2]);
    string_free_split (argv);

    /* keep eol == 1 */
    argv = string_split (" abc de  fghi ", " ", 1, 0, &argc);
    LONGS_EQUAL(3, argc);
    CHECK(argv);
    STRCMP_EQUAL("abc de  fghi", argv[0]);
    STRCMP_EQUAL("de  fghi", argv[1]);
    STRCMP_EQUAL("fghi", argv[2]);
    POINTERS_EQUAL(NULL, argv[3]);
    string_free_split (argv);

    /* keep eol == 1 and max 2 items */
    argv = string_split (" abc de  fghi ", " ", 1, 2, &argc);
    LONGS_EQUAL(2, argc);
    CHECK(argv);
    STRCMP_EQUAL("abc de  fghi", argv[0]);
    STRCMP_EQUAL("de  fghi", argv[1]);
    POINTERS_EQUAL(NULL, argv[2]);
    string_free_split (argv);

    /* keep eol == 2 */
    argv = string_split (" abc de  fghi ", " ", 2, 0, &argc);
    LONGS_EQUAL(3, argc);
    CHECK(argv);
    STRCMP_EQUAL("abc de  fghi ", argv[0]);
    STRCMP_EQUAL("de  fghi ", argv[1]);
    STRCMP_EQUAL("fghi ", argv[2]);
    POINTERS_EQUAL(NULL, argv[3]);
    string_free_split (argv);

    /* keep eol == 2 and max 2 items */
    argv = string_split (" abc de  fghi ", " ", 2, 2, &argc);
    LONGS_EQUAL(2, argc);
    CHECK(argv);
    STRCMP_EQUAL("abc de  fghi ", argv[0]);
    STRCMP_EQUAL("de  fghi ", argv[1]);
    POINTERS_EQUAL(NULL, argv[2]);
    string_free_split (argv);
}
Пример #27
0
struct t_gui_color_palette *
gui_color_palette_new (int number, const char *value)
{
    struct t_gui_color_palette *new_color_palette;
    char **items, *pos, *pos2, *error1, *error2, *error3;
    char *str_alias, *str_rgb, str_number[64];
    int num_items, i, r, g, b;

    if (!value)
        return NULL;

    new_color_palette = malloc (sizeof (*new_color_palette));
    if (new_color_palette)
    {
        new_color_palette->alias = NULL;
        new_color_palette->r = -1;
        new_color_palette->g = -1;
        new_color_palette->b = -1;

        str_alias = NULL;
        str_rgb = NULL;

        items = string_split (value, ";", 0, 0, &num_items);
        if (items)
        {
            for (i = 0; i < num_items; i++)
            {
                pos = strchr (items[i], '/');
                if (pos)
                    str_rgb = items[i];
                else
                {
                    pos = strchr (items[i], ',');
                    if (!pos)
                        str_alias = items[i];
                }
            }

            if (str_alias)
            {
                new_color_palette->alias = strdup (str_alias);
            }

            if (str_rgb)
            {
                pos = strchr (str_rgb, '/');
                if (pos)
                {
                    pos[0] = '\0';
                    pos2 = strchr (pos + 1, '/');
                    if (pos2)
                    {
                        pos2[0] = '\0';
                        error1 = NULL;
                        r = (int)strtol (str_rgb, &error1, 10);
                        error2 = NULL;
                        g = (int)strtol (pos + 1, &error2, 10);
                        error3 = NULL;
                        b = (int)strtol (pos2 + 1, &error3, 10);
                        if (error1 && !error1[0] && error2 && !error2[0]
                            && error3 && !error3[0]
                            && (r >= 0) && (r <= 1000)
                            && (g >= 0) && (g <= 1000)
                            && (b >= 0) && (b <= 1000))
                        {
                            new_color_palette->r = r;
                            new_color_palette->g = g;
                            new_color_palette->b = b;
                        }
                    }
                }
            }
            string_free_split (items);
        }
        if (!new_color_palette->alias)
        {
            snprintf (str_number, sizeof (str_number), "%d", number);
            new_color_palette->alias = strdup (str_number);
        }
    }

    return new_color_palette;
}
Пример #28
0
static struct string_list *compressed_7zip_file_list_new(
      const char *path, const char* ext)
{
   CFileInStream archiveStream;
   CLookToRead lookStream;
   CSzArEx db;
   ISzAlloc allocImp;
   ISzAlloc allocTempImp;
   size_t temp_size             = 0;
   struct string_list     *list = NULL;
   
   /* These are the allocation routines - currently using 
    * the non-standard 7zip choices. */
   allocImp.Alloc     = SzAlloc;
   allocImp.Free      = SzFree;
   allocTempImp.Alloc = SzAllocTemp;
   allocTempImp.Free  = SzFreeTemp;

   if (InFile_Open(&archiveStream.file, path))
   {
      RARCH_ERR("Could not open %s as 7z archive.\n",path);
      return NULL;
   }

   list = string_list_new();

   if (!list)
   {
      File_Close(&archiveStream.file);
      return NULL;
   }

   FileInStream_CreateVTable(&archiveStream);
   LookToRead_CreateVTable(&lookStream, False);
   lookStream.realStream = &archiveStream.s;
   LookToRead_Init(&lookStream);
   CrcGenerateTable();
   SzArEx_Init(&db);

   if (SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp) == SZ_OK)
   {
      uint32_t i;
      struct string_list *ext_list = ext ? string_split(ext, "|"): NULL;
      SRes res                     = SZ_OK;
      uint16_t *temp               = NULL;

      for (i = 0; i < db.db.NumFiles; i++)
      {
         union string_list_elem_attr attr;
         char infile[PATH_MAX_LENGTH];
         const char *file_ext         = NULL;
         size_t                   len = 0;
         bool supported_by_core       = false;
         const CSzFileItem         *f = db.db.Files + i;

         /* we skip over everything, which is a directory. */
         if (f->IsDir)
            continue;

         len = SzArEx_GetFileNameUtf16(&db, i, NULL);

         if (len > temp_size)
         {
            free(temp);
            temp_size = len;
            temp      = (uint16_t *)malloc(temp_size * sizeof(temp[0]));

            if (temp == 0)
            {
               res = SZ_ERROR_MEM;
               break;
            }
         }

         SzArEx_GetFileNameUtf16(&db, i, temp);
         res      = utf16_to_char_string(temp, infile, sizeof(infile)) 
            ? SZ_OK : SZ_ERROR_FAIL;
         file_ext = path_get_extension(infile);

         if (string_list_find_elem_prefix(ext_list, ".", file_ext))
            supported_by_core = true;

         /*
          * Currently we only support files without subdirs in the archives.
          * Folders are not supported (differences between win and lin.
          * Archives within archives should imho never be supported.
          */

         if (!supported_by_core)
            continue;

         attr.i = RARCH_COMPRESSED_FILE_IN_ARCHIVE;

         if (!string_list_append(list, infile, attr))
         {
            res = SZ_ERROR_MEM;
            break;
         }
      }

      string_list_free(ext_list);
      free(temp);

      if (res != SZ_OK)
      {
         /* Error handling */
         RARCH_ERR("Failed to open compressed_file: \"%s\"\n", path);

         string_list_free(list);
         list = NULL;
      }
   }

   SzArEx_Free(&db, &allocImp);
   File_Close(&archiveStream.file);

   return list;
}
Пример #29
0
int init_xkb(int fd, size_t size)
{
   char *map_str;
   settings_t *settings = config_get_ptr();
   mod_map_idx          = (xkb_mod_index_t *)calloc(MOD_MAP_SIZE, sizeof(xkb_mod_index_t));

   if (!mod_map_idx)
      goto error;

   mod_map_bit = (uint16_t*)calloc(MOD_MAP_SIZE, sizeof(uint16_t));

   if (!mod_map_bit)
      goto error;

   xkb_ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
   if (xkb_ctx)
   {
      if (fd >= 0)
      {
         map_str = (char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
         if (map_str == MAP_FAILED)
            goto error;

         xkb_map = xkb_keymap_new_from_string(xkb_ctx, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
         munmap(map_str, size);
      }
      else
      {
         struct string_list *list = NULL;
         struct xkb_rule_names rule = {0};

         rule.rules = "evdev";

         if (*settings->input.keyboard_layout)
         {
            list = string_split(settings->input.keyboard_layout, ":");
            if (list && list->size >= 2)
               rule.variant = list->elems[1].data;
            if (list && list->size >= 1)
               rule.layout = list->elems[0].data;
         }

         xkb_map = xkb_keymap_new_from_names(xkb_ctx, &rule, XKB_MAP_COMPILE_NO_FLAGS);
         if (list)
            string_list_free(list);
      }
   }
   if (xkb_map)
   {
      xkb_mod_index_t *map_idx = (xkb_mod_index_t*)&mod_map_idx[0];
      uint16_t        *map_bit = (uint16_t*)&mod_map_bit[0];

      xkb_state = xkb_state_new(xkb_map);

      *map_idx = xkb_keymap_mod_get_index(xkb_map, XKB_MOD_NAME_CAPS);
      map_idx++;
      *map_bit = RETROKMOD_CAPSLOCK;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(xkb_map, XKB_MOD_NAME_SHIFT);
      map_idx++;
      *map_bit = RETROKMOD_SHIFT;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(xkb_map, XKB_MOD_NAME_CTRL);
      map_idx++;
      *map_bit = RETROKMOD_CTRL;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(xkb_map, XKB_MOD_NAME_ALT);
      map_idx++;
      *map_bit = RETROKMOD_ALT;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(xkb_map, XKB_MOD_NAME_LOGO);
      *map_bit = RETROKMOD_META;
   }

   return 0;

error:
   free_xkb();

   return -1;
}
Пример #30
0
static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb,
      void *userdata, void *ctx)
{
   bool core_chooser = (userdata) ? *(rgui_file_type_t *)userdata == RGUI_SETTINGS_CORE : false;

   if (!*directory)
   {
#ifdef HW_RVL
      file_cb(ctx, "sd:", RGUI_FILE_DEVICE, 0);
      file_cb(ctx, "usb:", RGUI_FILE_DEVICE, 0);
#endif
      file_cb(ctx, "carda:", RGUI_FILE_DEVICE, 0);
      file_cb(ctx, "cardb:", RGUI_FILE_DEVICE, 0);
      return true;
   }

#ifdef HW_RVL
   LWP_MutexLock(gx_device_mutex);
   int dev = gx_get_device_from_path(directory);

   if (dev != -1 && !gx_devices[dev].mounted && gx_devices[dev].interface->isInserted())
      fatMountSimple(gx_devices[dev].name, gx_devices[dev].interface);

   LWP_MutexUnlock(gx_device_mutex);
#endif

   char exts[256];
   if (core_chooser)
      strlcpy(exts, "dol|DOL", sizeof(exts));
   else
      strlcpy(exts, g_extern.system.valid_extensions, sizeof(exts));
   struct string_list *ext_list = string_split(exts, "|");

   char _dir[PATH_MAX];
   snprintf(_dir, sizeof(_dir), "%s/", directory);
   DIR *dir = opendir(_dir);
   if (!dir)
      return false;

   struct dirent *entry;
   while ((entry = readdir(dir)))
   {
      char stat_path[PATH_MAX];
      const char *file_ext = path_get_extension(entry->d_name);
      snprintf(stat_path, sizeof(stat_path), "%s/%s", directory, entry->d_name);
      bool is_dir;

#ifdef _DIRENT_HAVE_D_TYPE
      is_dir = (entry->d_type == DT_DIR);
      if (entry->d_type != DT_REG && !is_dir)
         continue;
#else
      struct stat st;
      if (stat(stat_path, &st) < 0)
         continue;

      is_dir = S_ISDIR(st.st_mode);
      if (!S_ISREG(st.st_mode) && !is_dir)
         continue;
#endif

      if (core_chooser && (is_dir || strcasecmp(entry->d_name, default_paths.salamander_file) == 0))
         continue;

      if (!is_dir && ext_list && !string_list_find_elem_prefix(ext_list, ".", file_ext))
         continue;

      file_cb(ctx,
            entry->d_name,
            is_dir ? RGUI_FILE_DIRECTORY : RGUI_FILE_PLAIN, 0);
   }

   closedir(dir);
   string_list_free(ext_list);
   return true;
}