Example #1
0
int main(int argc, string argv[])
{
  string prog, itags[MaxBodyFields], otags[MaxBodyFields];
  stream xstr, ostr;
  bodyptr btab = NULL;
  int nbody;
  real tnow;

  initparam(argv, defv);
  exprs[0] = getparam("weight");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  new_field(&WeightField, RealType, "Weight");
  new_field(&WeightField + 1, NULL, NULL);
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE)) {
    snaprect(btab, nbody);
    del_tag(otags, itags, "Weight");
    put_snap(ostr, &btab, &nbody, &tnow, otags);
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getargv0(), prog);
  return (0);
}
Example #2
0
int main(int argc, string argv[])
{
  string prog, itags[MaxBodyFields];
  stream xstr, ostr;
  int nold = -1;

  initparam(argv, defv);
  exprs[0] = getparam("group");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  new_field(&GroupField, IntType, "Group");
  new_field(&GroupField + 1, NULL, NULL);
  layout_body(btags, Precision, NDIM);
  while (get_snap(xstr, &bodytab, &nbody, &tbody, itags, FALSE)) {
    snaptrak();
    put_snap(ostr, &traktab, &ntrak, &tbody, otags);
    if (ntrak != nold)
      eprintf("[%s: wrote %d groups at t = %f]\n",
	      getprog(), ntrak, tbody);
    nold = ntrak;
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getprog(), prog);
  return (0);
}
Example #3
0
int main(int argc, string argv[])
{
  string prog, coords, itags[MaxBodyFields], otags[MaxBodyFields];
  stream xstr, ostr;
  bodyptr btab = NULL, bp;
  int nbody;
  real tnow;
  vector cmpos, cmvel, cmacc;

  initparam(argv, defv);
  exprs[0] = getparam("weight");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  coords = getparam("coords");
  new_field(&WeightField, RealType, "Weight");
  new_field(&WeightField + 1, NULL, NULL);
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE, NULL)) {
    if (scanopt(coords, PosTag) && set_member(itags, PosTag)) {
      snapcmpos(cmpos, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Pos(bp), Pos(bp), cmpos);
      }
      eprintf("[%s: centroid position: %f,%f,%f]\n", getprog(),
	      cmpos[0], cmpos[1], cmpos[2]);
    }
    if (scanopt(coords, VelTag) && set_member(itags, VelTag)) {
      snapcmvel(cmvel, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Vel(bp), Vel(bp), cmvel);
      }
      eprintf("[%s: centroid velocity: %f,%f,%f]\n", getprog(),
	      cmvel[0], cmvel[1], cmvel[2]);
    }
    if (scanopt(coords, AccTag) && set_member(itags, AccTag)) {
      snapcmacc(cmacc, btab, nbody, WeightField.offset);
      for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	SUBV(Acc(bp), Acc(bp), cmacc);
      }
      eprintf("[%s: cen. acceleration: %f,%f,%f]\n", getprog(),
	      cmacc[0], cmacc[1], cmacc[2]);
    }
    del_tag(otags, itags, "Weight");
    put_snap(ostr, &btab, &nbody, &tnow, otags);
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getprog(), prog);
  return (0);
}
Example #4
0
static GSList *
parse_list (const char *header, char delim)
{
	GSList *list = NULL;
	const char *end;

	header = skip_delims (header, delim);
	while (*header) {
		end = skip_item (header, delim);
		list = g_slist_prepend (list, g_strndup (header, end - header));
		header = skip_delims (end, delim);
	}

	return g_slist_reverse (list);
}
Example #5
0
/* key: item key
 * data: item data
 * return: skip item or NULL when out of memory;
 * insert data item */
ITEM* LIST_Insert (LIST *list, void *key, void *data)
{
  ITEM *header, **update, *x;
  int maxlevel, level, i, n;
  LIST_Compare compare;

  maxlevel = list->maxlevel;
  compare = list->compare;
  header = &list->header;
  update = list->update;
  level = list->level;
  x = header;

  for (i = level; i >= 0; i --)
  {
    if (compare) while (x->forward [i] && compare (x->forward [i]->key, key) < 0) x = x->forward [i];
    else while (x->forward [i] && x->forward [i]->key < key) x = x->forward [i];

    update [i] = x;
  }

  x = x->forward [0];

  if (x && ((compare && compare (x->key, key) == 0) || ((!compare) && x->key == key))) x->data = data;
  else
  {
    n = random_level (maxlevel);

    if (n > level)
    {
      for (i = level + 1; i <= maxlevel; i ++) update [i] = header;

      list->level = n;
    }

    if(!(x = skip_item (list, key, data))) return NULL;

    for (i = 0; i <= n; i ++)
    {
      x->forward [i] = update [i]->forward [i];
      update [i]->forward [i] = x;
    }

    list->size ++;
  }

  return x;
}
Example #6
0
/**
 * soup_header_contains:
 * @header: An HTTP header suitable for parsing with
 * soup_header_parse_list()
 * @token: a token
 *
 * Parses @header to see if it contains the token @token (matched
 * case-insensitively). Note that this can't be used with lists
 * that have qvalues.
 *
 * Return value: whether or not @header contains @token
 **/
gboolean
soup_header_contains (const char *header, const char *token)
{
	const char *end;
	guint len = strlen (token);

	g_return_val_if_fail (header != NULL, FALSE);
	g_return_val_if_fail (token != NULL, FALSE);

	header = skip_delims (header, ',');
	while (*header) {
		end = skip_item (header, ',');
		if (end - header == len &&
		    !g_ascii_strncasecmp (header, token, len))
			return TRUE;
		header = skip_delims (end, ',');
	}

	return FALSE;
}
Example #7
0
Account Parser::parse_account(std::string const &chunk, std::string const &encryption_key)
{
    std::istringstream s(chunk); // TODO: Get rid of the copy!

    auto id = read_item(s);
    auto name = read_item(s);
    auto group = read_item(s);
    auto url = read_item(s);

    for (int i = 0; i < 3; ++i)
        skip_item(s);

    auto username = read_item(s);
    auto password = read_item(s);

    return {std::move(id),
            decrypt_aes256(name, encryption_key),
            decrypt_aes256(username, encryption_key),
            decrypt_aes256(password, encryption_key),
            decode_hex(url),
            decrypt_aes256(group, encryption_key)};

}
Example #8
0
inline rtok_t const* skip_item(rtok_t const* i) { return skip_item((rtok_t*)i); }