Exemplo n.º 1
0
int users_search(mongo* conn, User* users, int limit) {
  int pos = 0;
  mongo_cursor cursor[1];
  bson_iterator iterator[1];
  mongo_cursor_init(cursor, conn, "ruby-mongo-console.users");
  // mongo_cursor_set_query
  mongo_cursor_set_limit(cursor, limit);

  while(mongo_cursor_next(cursor) == MONGO_OK) {
    const char* s;

    s = get_field_value(iterator, cursor, "name");
    if (s) {
      users[pos].name_len = strlen(s);
      users[pos].name = new_str(s, users[pos].name_len);
    } else {
      users[pos].name_len = 0;
      users[pos].name = NULL;
    }

    s = get_field_value(iterator, cursor, "bio");
    if (s) {
      users[pos].bio_len = strlen(s);
      users[pos].bio = new_str(s, users[pos].bio_len);
    } else {
      users[pos].bio_len = 0;
      users[pos].bio = NULL;
    }

    pos++;
  }

  mongo_cursor_destroy(cursor);
  return pos;
}
Exemplo n.º 2
0
void int_update_driver_data(hd_data_t *hd_data, hd_t *hd)
{
  hd_sysfsdrv_t *sf;
  str_list_t *sl;

  hd->driver_modules = free_str_list(hd->driver_modules);

  for(sl = hd->drivers; sl; sl = sl->next) {
    for(sf = hd_data->sysfsdrv; sf; sf = sf->next) {
      if(sf->module && !strcmp(sf->driver, sl->str)) {
        add_str_list(&hd->driver_modules, sf->module);
      }
    }
  }

  hd->driver = free_mem(hd->driver);
  hd->driver_module = free_mem(hd->driver_module);

  if(hd->drivers && hd->drivers->str) {
    hd->driver = new_str(hd->drivers->str);

    for(sf = hd_data->sysfsdrv; sf; sf = sf->next) {
      if(sf->module && !strcmp(sf->driver, hd->driver)) {
        hd->driver_module = new_str(sf->module);
      }
    }
  }
}
Exemplo n.º 3
0
void tex::end_name ()
	{
	int	n;
	
	if (area_str == null_str) {
		cur_area = null_str;
		area_str = name_of_file;
		} 
	else {
		n = area_str - name_of_file;
		cur_area = new_str(n);
		strncpy(cur_area, name_of_file, n);
		}
	if (ext_str == null_str) {
		cur_ext = null_str;
		ext_str = name_str;
		} 
	else {
		n = name_str - ext_str;
		cur_ext = new_str(n);
		strncpy(cur_ext, ext_str, n);
		}
	n = ext_str - area_str;
	if (n == 0) {
		cur_name = null_str;
		}
	else {
		cur_name = new_str(n);
		strncpy(cur_name, area_str, n);
		}	
	}
Exemplo n.º 4
0
SpecialFolderItem::SpecialFolderItem(LPCTSTR pszTitle, const TCHAR *pszPath, struct pidl_node* pidl_list, const TCHAR  *optional_command, const TCHAR* pszIcon)
    : FolderItem(NULL, pszTitle, NULL)
{
	m_pidl_list = pidl_list;
	m_ItemID    = MENUITEM_ID_SF;
	m_pszPath   = new_str(pszPath);
	// command to apply to files, optional
	m_pszExtra  = new_str(optional_command);
	m_phIcon = GetIcon(pszIcon);
}
Exemplo n.º 5
0
/*
 * Go through serial mouse data and add hd entries.
 */
void add_serial_mouse(hd_data_t *hd_data)
{
  hd_t *hd;
  char buf[4];
  ser_device_t *sm;

  for(sm = hd_data->ser_mouse; sm; sm = sm->next) {
    if(sm->is_mouse) {
      hd = add_hd_entry(hd_data, __LINE__, 0);
      hd->base_class.id = bc_mouse;
      hd->sub_class.id = sc_mou_ser;
      hd->bus.id = bus_serial;
      hd->unix_dev_name = new_str(sm->dev_name);
      hd->attached_to = sm->hd_idx;
      if(*sm->pnp_id) {
        strncpy(buf, sm->pnp_id, 3);
        buf[3] = 0;
        hd->vendor.id = name2eisa_id(buf);
        if(!hd->vendor.id) {	/* in case it's a really strange one... */
          hd->vendor.name = new_str(buf);
        }
        hd->device.id = MAKE_ID(TAG_EISA, strtol(sm->pnp_id + 3, NULL, 16));

        hd->serial = new_str(sm->serial);
        if(sm->user_name) hd->device.name = new_str(sm->user_name);
        if(sm->vend) {
          free_mem(hd->vendor.name);
          hd->vendor.name = new_str(sm->vend);
        }

        if(sm->dev_id && strlen(sm->dev_id) >= 7) {
          char buf[5], *s;
          unsigned u1, u2;

          u1 = name2eisa_id(sm->dev_id);
          if(u1) {
            strncpy(buf, sm->dev_id + 3, 4);
            buf[4] = 0;
            u2 = strtol(sm->dev_id + 3, &s, 16);
            if(!*s) {
              hd->compat_vendor.id = u1;
              hd->compat_device.id = MAKE_ID(TAG_EISA, u2);
            }
          }
        }
      }
      else {
        hd->vendor.id = MAKE_ID(TAG_SPECIAL, 0x0200);
        hd->device.id = MAKE_ID(TAG_SPECIAL, 0x0003);
      }
    }
  }
}
Exemplo n.º 6
0
char*		exec_cmd(char* cmd, t_client* client, t_data* data)
{
  char*		res;
  char**	parse;

  parse = cut_cmd(data, cmd);
  if (channel(parse, client, data) == 1)
    return (NULL);
  else if (strcmp(parse[0], "/nick") == 0)
    return (nickname(data, client, parse));
  else if (strcmp(parse[0], "/quit") == 0)
    return (quit(data, client));
  else if (strcmp(parse[0], "/msg") == 0)
    return (msg_private(data, client, parse));
  else if (strcmp(parse[0], "/server") == 0)
    return (quit(data, client));
  else if (strcmp(parse[0], "/send_file") == 0)
    return (NULL);
  else if (strcmp(parse[0], "/accept_file") == 0)
    return (NULL);
  else if (parse[0][0] != '/')
    return (msg_general(data, client, parse));
  else
    return (new_str(NULL, strcat(parse[0], " : command not found"), data));
  return (res);
}
Exemplo n.º 7
0
/* Allocates memory */
string* factor_vm::reallot_string(string* str_, cell capacity) {
  data_root<string> str(str_, this);

  if (reallot_string_in_place_p(str.untagged(), capacity)) {
    str->length = tag_fixnum(capacity);

    if (to_boolean(str->aux)) {
      byte_array* aux = untag<byte_array>(str->aux);
      aux->capacity = tag_fixnum(capacity * 2);
    }

    return str.untagged();
  } else {
    cell to_copy = string_capacity(str.untagged());
    if (capacity < to_copy)
      to_copy = capacity;

    data_root<string> new_str(allot_string_internal(capacity), this);

    memcpy(new_str->data(), str->data(), to_copy);

    if (to_boolean(str->aux)) {
      byte_array* new_aux = allot_uninitialized_array<byte_array>(capacity * 2);
      new_str->aux = tag<byte_array>(new_aux);
      write_barrier(&new_str->aux);

      byte_array* aux = untag<byte_array>(str->aux);
      memcpy(new_aux->data<uint16_t>(), aux->data<uint16_t>(),
             to_copy * sizeof(uint16_t));
    }

    fill_string(new_str.untagged(), to_copy, capacity, '\0');
    return new_str.untagged();
  }
}
Exemplo n.º 8
0
str
_(const char* fmt, ...)
{
	va_list args;
	va_start(args,fmt);
	return new_str(fmt,args);
}
Exemplo n.º 9
0
int main(int argc, char **argv)
{
    Subst subst;

    message_setseverity(MSG_NOTICE | MSG_ERR);

    subst_construct(&subst);            /* construct the Subst object   */

    subst_insert(&subst, "DEMO", "one", "ONE SUBST");
    subst_insert(&subst, "DEMO", "one", "TWO SUBST");
    subst_insert(&subst, "DEMO", "\\'e", "&eacute;");

    while (true)
    {
        char *cp;
        puts("Enter text: ");
        if (!fgets(buffer, 80, stdin) || buffer[0] == '\n')
            break;

        for (cp = buffer; *cp && *cp != '\n'; cp++)
        {
            printf("Inspecting char `%c': ", *cp);
            if (subst_find(&subst, *cp))
                printf("found.     Swallowed by subst\n");
            else
            {
                char *txt = new_str(subst_text(&subst));
                printf("Not found. Next returned: `%c(`%s')\n",
                        subst_get(&subst), txt ? txt : "");
                free(txt);
            }
        }
    }
}
Exemplo n.º 10
0
char const *s_state_insert(register State *sp, char const *key,
                                               char const *subst)
{
    while (*key)
    {
        register char const *cp;
                                        /* if key is in the set, switch to  */
        if ((cp = strchr(sp->d_str, *key)) != 0)         /*  that state  */
            sp = sp->d_next[cp - sp->d_str];
        else
        {                               /* if not, add a new state to the   */
            size_t last = string_length(&sp->d_set);      /*          set */

            string_addchar(&sp->d_set, (char)*key); /* add key's 1st char */
            sp->d_str = string_str(&sp->d_set); /* and set the state's ptr  */

                                                /* add a new state          */
            new_size(&sp->d_next, last + 1, last, sizeof(State *));
            sp = sp->d_next[last] = s_state_new();
        }
        key++;                          /* inspect the next key char        */
    }

                                        /* all key chars exhausted: insert  */
                                        /* replacement text                 */

    if (sp->d_replacement)              /* oops, it's already there         */
        return sp->d_replacement;       /* return the one found             */

    sp->d_replacement = new_str(subst);
    return 0;                           /* here 0 indicates SUCCESS         */
}
Exemplo n.º 11
0
void int_bios(hd_data_t *hd_data)
{
  hd_t *hd, *hd_boot;
  int i, start, bios = 0x80;
  int ide_1st;
  char ide_name[] = "/dev/hda";
  char scsi_name[] = "/dev/sda";
  char *s;

  hd_boot = hd_get_device_by_idx(hd_data, hd_boot_disk(hd_data, &i));

  if(hd_boot) {
    free_mem(hd_boot->rom_id);
    hd_boot->rom_id = new_str("0x80");
  }

  if(!hd_boot || i != 1) return;

  if(strstr(hd_boot->unix_dev_name, "/dev/sd") == hd_boot->unix_dev_name) {
    ide_1st = 0;
    start = hd_boot->unix_dev_name[sizeof "/dev/sd" - 1] - 'a';
  }
  else if(strstr(hd_boot->unix_dev_name, "/dev/hd") == hd_boot->unix_dev_name) {
    ide_1st = 1;
    start = hd_boot->unix_dev_name[sizeof "/dev/hd" - 1] - 'a';
  }
  else {
    return;
  }

  if(start < 0) return;

  for(hd = hd_data->hd; hd; hd = hd->next) {
    if(
      hd->base_class.id == bc_storage_device &&
      hd->sub_class.id == sc_sdev_disk
    ) {
      hd->rom_id = free_mem(hd->rom_id);
    }
  }

  s = ide_1st ? ide_name : scsi_name;

  for(i = start; i < 26; i++) {
    s[strlen(s) - 1] = 'a' + i;
    bios += set_bios_id(hd_data, s, bios);
  }

  for(i = 0; i < start; i++) {
    s[strlen(s) - 1] = 'a' + i;
    bios += set_bios_id(hd_data, s, bios);
  }

  s = ide_1st ? scsi_name : ide_name;

  for(i = 0; i < 26; i++) {
    s[strlen(s) - 1] = 'a' + i;
    bios += set_bios_id(hd_data, s, bios);
  }
}
Exemplo n.º 12
0
MenuItem::MenuItem(const char* pszTitle)
{
	next        = NULL;

	m_pMenu     =
		m_pSubMenu  = NULL;

	m_nWidth    =
		m_nHeight   = 0;

	m_isNOP     =
		m_bActive   =
			m_isChecked = false;

	m_nSortPriority = M_SORT_NORMAL;
	m_ItemID    = MENUITEM_ID_NORMAL;

	m_pszTitle  = new_str(pszTitle);
	m_pszCommand = NULL;
	m_pidl      = NULL;
	m_hIcon     = NULL;
	m_iconMode  = IM_NONE;

	++g_menu_item_count;
}
Exemplo n.º 13
0
HashItem *construct_preset(char const *setkey, char *rest)
{
    char *key;
    HashItem *mapItem;

    if (!(key = string_firstword(&rest)))               /* get the key      */
    {                                                   /* e.g., title      */
        message_error("`preset ...: missing key");
        return 0;
    }

    if (strcmp(key, "nohtmlfive") == 0)
        global.d_html5 = 0;
    else
    {
        if (!*string_strip(&rest))                      /* get the value    */
            warning("Empty value of symbol `%s'", key); /* e.g., This is... */
    
        if (strcmp(key, "styleopt") == 0)               /* store styleopts  */
            lines_add(&global.d_styleopt, rest);
        else
        {                                                   
                                                        /* look up the key  */
            mapItem = hashmap_find(&global.d_symbol, key, ANY); 
    
            if (mapItem != PFAILED)                     /* reassign         */
                hashitem_set(mapItem, rest, free);      /* existing value   */
            else                                        /* or insert new    */
                hashmap_insert(&global.d_symbol,        /* element          */
                    hashitem_construct(VOIDPTR, key, new_str(rest), free));
        }
    }
    free(key);
    return hashitem_construct(VOIDPTR, "", 0, root_nop);
}
Exemplo n.º 14
0
static int		loop(t_str *str, t_hist *historic,\
char **line, int success)
{
	int				i;

	while (success && str)
	{
		i = -1;
		while (str->str[++i] && str->str[i] != '\n' && str->str[i] != '\r')
			;
		if (str->str[i] == '\n' || str->str[i] == '\r')
		{
			while (str->str[i] == '\n')
				str->str[i++] = '\0';
			historic->garbage = &str->str[i];
			return (achievement(historic, line));
		}
		str->next = new_str();
		str = str->next;
		str->str = (char *)malloc(sizeof(char) * BUFF_SIZE + 1);
		ft_bzero(str->str, BUFF_SIZE + 1);
		success = read(historic->fd, str->str, BUFF_SIZE);
	}
	return (0);
}
Exemplo n.º 15
0
CommandItem::CommandItem(const char* pszCommand, const char* pszTitle, bool bChecked)
    : MenuItem(pszTitle)
{
    m_pszCommand = new_str(pszCommand);
    m_bChecked = bChecked;
    m_ItemID = MENUITEM_ID_CMD;
}
Exemplo n.º 16
0
/*
 * Check if str has str2 in it.
 */
int contains_word(char *str, char *str2)
{
  int i, len, len2, found = 0;
  char *s;

  if(!str2 || !*str2 || !str || !*str) return 0;

  str = new_str(str);

  len = strlen(str);
  len2 = strlen(str2);

  for(i = 0; i < len; i++) {
    if(str[i] >= 'a' && str[i] <= 'z') str[i] -= 'a' - 'A';
  }

  for(s = str; (s = strstr(s, str2)); s++) {
    if(
      (s == str || s[-1] < 'A' || s[-1] > 'Z') &&
      (s[len2] < 'A' || s[len2] > 'Z')
    ) {
      found = 1;
      break;
    }
  }

  free_mem(str);

  return found;
}
Exemplo n.º 17
0
 _menuitemint(n_menu *m, const char *_text, const char *_cmd, int _initval, int _minval, int _maxval)
 : _menuitem(m, _text, i_int)
 {
     cmd = new_str(_cmd);
     initval = _initval;
     minval = _minval;
     maxval = _maxval;
 }
Exemplo n.º 18
0
 _menuitem(n_menu *m, const char *_text, int _mode)
 {
     mode = _mode;
     text = new_str(_text);
     next = NULL;
     disabled = false;
     m->additem(this);
 }
Exemplo n.º 19
0
str tex::make_name_str()
	{
	str	s;
	
	s = new_str(name_length);
	strcpy(s, name_of_file);
	return (s);
	}
Exemplo n.º 20
0
Str *str_concat(Str *a, Str *b) {
    Str *out = (Str*)new_str();
    for(int i = 0; i < a->size; i++)
        str_append(out, a->array[i]);
    for(int i = 0; i < b->size; i++)
        str_append(out, b->array[i]);
    return out;
}
Exemplo n.º 21
0
FolderItem::FolderItem(Menu* pSubMenu, const char* pszTitle, const char* pszIcon) : MenuItem(pszTitle)
{
	m_nSortPriority = M_SORT_FOLDER;
	m_ItemID = MENUITEM_ID_FOLDER;
	LinkSubmenu(pSubMenu);
	m_pszIcon = new_str(pszIcon);
	GetIcon();
}
Exemplo n.º 22
0
/*
 * Add udev info.
 */
void int_udev(hd_data_t *hd_data)
{
  hd_udevinfo_t *ui;
  hd_t *hd;
  str_list_t *sl;

  if(!hd_data->udevinfo) read_udevinfo(hd_data);

  if(!hd_data->udevinfo) return;

  for(hd = hd_data->hd; hd; hd = hd->next) {
    if(!hd->unix_dev_names && hd->unix_dev_name) {
      add_str_list(&hd->unix_dev_names, hd->unix_dev_name);
    }

    if(!hd->sysfs_id) continue;

    for(ui = hd_data->udevinfo; ui; ui = ui->next) {
      if(ui->name && !strcmp(ui->sysfs, hd->sysfs_id)) {
        if(!search_str_list(hd->unix_dev_names, ui->name)) {
          add_str_list(&hd->unix_dev_names, ui->name);
        }
        for(sl = ui->links; sl; sl = sl->next) {
          if(!search_str_list(hd->unix_dev_names, sl->str)) {
            add_str_list(&hd->unix_dev_names, sl->str);
          }
        }

        if(!hd->unix_dev_name || hd_data->flags.udev) {
          sl = hd->unix_dev_names;

          if(hd_data->flags.udev) {
            /* use first link as canonical device name */
            if(ui->links) sl = sl->next;
          }

          hd->unix_dev_name = new_str(sl->str);
        }

        break;
      }
    }
  }

  for(hd = hd_data->hd; hd; hd = hd->next) {
    if(!hd->unix_dev_names) continue;

    for(ui = hd_data->udevinfo; ui; ui = ui->next) {
      if(search_str_list(hd->unix_dev_names, ui->name)) {
        for(sl = ui->links; sl; sl = sl->next) {
          if(!search_str_list(hd->unix_dev_names, sl->str)) {
            add_str_list(&hd->unix_dev_names, sl->str);
          }
        }
      }
    }
  }
}
Exemplo n.º 23
0
//================================================
void SpecialFolder::UpdateFolder(void)
{
	// ---------------------------------------
	// remember the active item as text

	MenuItem *ActiveItem = m_pActiveItem;
	TCHAR *active_item_text = NULL;

	m_pLastChild = m_pChild;
	if (m_pLastChild) ActiveItem = m_pLastChild->m_pParentItem;
	if (ActiveItem) active_item_text = new_str(ActiveItem->m_pszTitle);

	// delete_old items
	DeleteMenuItems();

	// load the folder contents
	MenuItem *Items = NULL; int r = 0;

	struct pidl_node *p;
	dolist (p, m_pidl_list)
		r |= MenuMaker_LoadFolder(&Items, p->v, m_pszExtra);

	if (Items) add_folder_contents(Items, NULL != m_pidl_list->next);
	else if (r) MakeMenuNOP(this, NLS0(_T("No Files")));
	else MakeMenuNOP(this, NLS0(_T("Invalid Path")));

	// ---------------------------------------
	// search by text the previously active item

	if (active_item_text)
	{
		dolist (ActiveItem, m_pMenuItems)
			if (0 == _tcscmp(active_item_text, ActiveItem->m_pszTitle))
				break;

		free_str(&active_item_text);
	}

	// ---------------------------------------
	// possibly reconnect to an open child-folder

	if (m_pLastChild)
	{
		if (ActiveItem)
		{
			m_pLastChild->incref();
			ActiveItem->LinkSubmenu(m_pLastChild);
			m_pLastChild->LinkToParentItem(ActiveItem);
		}
		else
		{
			m_pLastChild->Hide(); // lost child
		}
		m_pLastChild = NULL;
	}

	if (ActiveItem) ActiveItem->Active(2);
}
Exemplo n.º 24
0
static String HHVM_FUNCTION(mysql_escape_string,
                            const String& unescaped_string) {
  String new_str((size_t)unescaped_string.size() * 2 + 1, ReserveString);
  unsigned long new_len = mysql_escape_string(new_str.mutableData(),
                                    unescaped_string.data(),
                                    unescaped_string.size());
  new_str.shrink(new_len);
  return new_str;
}
Exemplo n.º 25
0
MenuItem::MenuItem(const char* pszTitle)
{
    memset(&next, 0, sizeof *this - sizeof(void*));

    m_Justify   = MENUITEM_STANDARD_JUSTIFY;
    //m_ItemID    = MENUITEM_ID_NORMAL;
    //m_nSortPriority = M_SORT_NORMAL;
    m_pszTitle  = new_str(pszTitle);

    ++g_menu_item_count;
}
Exemplo n.º 26
0
static void load_nls(void)
{
	const char *lang_file =
		ReadString(extensionsrcPath(), "blackbox.options.language:", NULL);
	if (NULL == lang_file) return;

	char full_path[MAX_PATH];
	FILE *fp = fopen (make_bb_path(full_path, lang_file), "rb");
	if (NULL == fp) return;

	char line[4000], key[200], new_text[4000], *np;
	int nl;
	key[0] = 0;

	new_text[0] = 0;
	np = new_text;
	nl = 0;
	for (;;)
	{
		bool eof = false == read_next_line(fp, line, sizeof line);
		char *s = line, c = *s;
		if ('$' == c || eof)
		{
			if (key[0] && new_text[0])
			{
				struct nls *t = (struct nls *)c_alloc(sizeof *t + strlen(key));
				t->hash = calc_hash(t->key, key, &t->k);
				t->translation = new_str(new_text);
				cons_node(&pNLS, t);
			}
			if (eof) break;
			if (' ' == s[1]) s += 2;
			decode_escape(key, s);
			new_text[0] = 0;
			np = new_text;
			nl = 0;
			continue;
		}

		if ('#' == c || '!' == c) continue;

		if ('\0' != c)
		{
			while (nl--) *np++ = '\n';
			np += decode_escape(np, s);
			nl = 0;
		}

		nl ++;
	}
	fclose(fp);
	reverse_list(&pNLS);
}
Exemplo n.º 27
0
/*
*   Private helper function to create a new block for a new file and initialize file params.
*   Parameters:
*       o const char* name - name of file.
*       Return : pointer to new block of file data
*/
static struct mfs_file* mfs_construct(const char* name)
{
	void *fileHeaderMemory = myMalloc(sizeof(struct mfs_file));
	setMemoryPid(fileHeaderMemory,SPECIAL_PID);
	struct mfs_file* newfile = (struct mfs_file*)fileHeaderMemory;
	void * blockMemory = myMalloc(BLOCK_SIZE);
	setMemoryPid(blockMemory,SPECIAL_PID);
	newfile->data = (unsigned char *)blockMemory;
	newfile->size = 0;
	newfile->fname = new_str(name);
	return newfile;
}
Exemplo n.º 28
0
void hd2prop_add_str(hal_prop_t **list, const char *key, const char *str)
{
  hal_prop_t *prop;

  if(str) {
    prop = hal_get_new(list, key);
    prop->type = p_string;
    prop->val.str = new_str(str);
  }
  else {
    hal_invalidate_all(*list, key);
  }
}
Exemplo n.º 29
0
void Log::outDB(LogTypes type, const char * str)
{
    if(!str || type >= MAX_LOG_TYPES)
         return;

    std::string new_str(str);
    if(new_str.empty())
        return;
    LoginDatabase.EscapeString(new_str);

    LoginDatabase.PExecute("INSERT INTO logs (time, realm, type, string) "
        "VALUES (" UI64FMTD ", %u, %u, '%s');", uint64(time(0)), realm, type, new_str.c_str());
}
Exemplo n.º 30
0
str
make_str ()
{
	int	n;
	str	s;

	n = cur_length();
	s = new_str(n);
	memcpy(s, cur_str, n);
	cur_str_ptr = cur_str;

	return s;
}