Пример #1
0
static void		convert_value(char *s, int v, int b, int i)
{
	if (v >= 0)
	{
		if (v >= b)
		{
			convert_value(s, (v / b), b, i - 1);
			s[i] = v % b;
		}
		else
			s[i] = v;
	}
	else
	{
		if (v <= -b)
		{
			convert_value(s, ((v / b) * -1), b, i - 1);
			s[i] = (v % b) * -1;
		}
		else
			s[i] = v * -1;
	}
	if (s[i] >= 0 && s[i] <= 9)
		s[i] += 48;
	else
		s[i] += 65 - 10;
}
Пример #2
0
int compare(list_value_t* avalue, list_value_t* bvalue) {
    if(avalue->type==STRING_TYPE)
        return strcmp(avalue->value,bvalue->value);

    if((avalue->type==DOUBLE_TYPE?*(double*)convert_value(avalue):*(int*)convert_value(avalue)) > (bvalue->type==DOUBLE_TYPE?*(double*)convert_value(bvalue):*(int*)convert_value(bvalue))) {
        return 1;
    }
    else {
        if((avalue->type==DOUBLE_TYPE?*(double*)convert_value(avalue):*(int*)convert_value(avalue)) < (bvalue->type==DOUBLE_TYPE?*(double*)convert_value(bvalue):*(int*)convert_value(bvalue))) {
            return -1;
        } else {
            return 0;
        }
    }
}
Пример #3
0
// Search for a sequence of conversions from expression `e` to a destination
// category c and type t.
Expr&
standard_conversion(Context& cxt, Expr& e, Type& t)
{
  // No conversions are required if the types are the same.
  if (is_equivalent(e.type(), t))
    return e;

  // Try a categorical conversion.
  Expr& c1 = convert_category(cxt, e, t);
  if (is_equivalent(c1.type(), t))
    return c1;

  // Try a value conversion.
  Expr& c2 = convert_value(cxt, c1, t);
  if (is_equivalent(c2.type(), t))
    return c2;

  // Try a qualification adjustment.
  Expr& c3 = convert_qualifier(cxt, c2, t);
  if (is_equivalent(c3.type(), t))
    return c3;

  error(cxt, "cannot convert '{}' (type '{}') to '{}'", e, e.type(), t);
  throw Type_error();
}
Пример #4
0
static mustache_value_t* convert_object(
  VALUE rb_object,
  char* key,
  mustache_context_t* m_lookup_context,
  mustache_context_t* m_exection_context)
{
    ID id = rb_intern(key);
    if (rb_respond_to(rb_object, id)) {
        rb_ivar_set(rb_object, rb_intern("@context"), (VALUE) m_exection_context->data);

        double start = 0;
        if (m_lookup_context->debug_mode) {
            start = get_time();
        }

        VALUE result = rb_funcall(rb_object, id, 0, 0);

        if (m_lookup_context->debug_mode) {
            log_ruby_callback_execution_time(m_lookup_context, id, get_time() - start);
        }

        return convert_value(result, m_lookup_context);
    }
    return NULL;
}
Пример #5
0
/* Update the sensitivity of the evaluate button
 */
static void
notify_entry_text (GtkWidget *entry, GParamSpec *pspec, GschemTranslateWidget *widget)
{
  g_return_if_fail (widget != NULL);

  gtk_widget_set_sensitive (widget->evaluate_button,
                            convert_value (gtk_entry_get_text (GTK_ENTRY (widget->entry)), NULL));
}
Пример #6
0
/* Callback for when the user clicks the evaluate button
 */
static void
click_evaluate (GtkWidget *entry, GschemTranslateWidget *widget)
{
  g_return_if_fail (widget != NULL);

  if (convert_value (gtk_entry_get_text (GTK_ENTRY (widget->entry)), NULL)) {
    gtk_info_bar_response (GTK_INFO_BAR (widget), GTK_RESPONSE_OK);
  }
}
Пример #7
0
/*! \brief Get the value in the entry
 *
 *  If the value inside the entry is invalid, this function returns 0. However,
 *  this function will return a valid response in the handler for the response
 *  signal, since the response signal will not be emitted if the value is
 *  invalid.
 *
 *  \param [in] widget This GschemTranslateWidget
 *  \return The value in the entry
 */
int
gschem_translate_widget_get_value (GschemTranslateWidget *widget)
{
  int value = 0;

  g_return_val_if_fail (widget != NULL, value);

  convert_value (gtk_entry_get_text (GTK_ENTRY (widget->entry)), &value);

  return value;
}
Пример #8
0
static mustache_value_t* convert_hash(
  VALUE hash,
  char* key,
  mustache_context_t* m_lookup_context,
  mustache_context_t* m_exection_context)
{
    VALUE rb_value;
    if (NIL_P(rb_value = rb_hash_aref(hash, ID2SYM(rb_intern(key))))) {
        return NULL;
    }
    return convert_value(rb_value, m_lookup_context);
}
Пример #9
0
/* Callback for when the user presses enter in the entry widget
 */
static void
activate_entry (GtkWidget *entry, GschemTranslateWidget *widget)
{
  g_return_if_fail (widget != NULL);

  if (gtk_entry_get_text_length (GTK_ENTRY (widget->entry)) == 0) {
    gtk_info_bar_response (GTK_INFO_BAR (widget), GTK_RESPONSE_CANCEL);
  }
  else if (convert_value (gtk_entry_get_text (GTK_ENTRY (widget->entry)), NULL)) {
    gtk_info_bar_response (GTK_INFO_BAR (widget), GTK_RESPONSE_OK);
  }
}
Пример #10
0
/*
 * Convert v to a constant term
 */
term_t convert_value_to_term(term_table_t *terms, value_table_t *vtbl, value_t v) {
  val_converter_t convert;
  term_t t;

  t = convert_simple_value(terms, vtbl, v);
  if (t == CONVERT_NOT_PRIMITIVE) {
    init_val_converter(&convert, vtbl, terms);
    t = convert_value(&convert, v);
    delete_val_converter(&convert);
  }

  return t;
}
Пример #11
0
static void		convert_value(char *s, t_uint v, t_uint b, int i)
{
	if (v >= b)
	{
		convert_value(s, (v / b), b, i - 1);
		s[i] = v % b;
	}
	else
		s[i] = v;
	if (s[i] >= 0 && s[i] <= 9)
		s[i] += 48;
	else
		s[i] += 65 - 10;
}
Пример #12
0
char			*ft_uitoa_base(t_uint value, t_uint base)
{
	char		*res;
	int			len;

	len = get_value_len(value, base);
	res = (char *)malloc(sizeof(*res) * (len + 1));
	if (res)
	{
		res[len] = '\0';
		convert_value(res, value, base, len - 1);
	}
	return (res);
}
Пример #13
0
mustache_value_t* convert_type(
  char* key,
  void* context,
  mustache_context_t* m_lookup_context,
  mustache_context_t* m_exection_context)
{
    if (strcmp(key, ".") == 0) {
        return convert_value((VALUE)context, m_lookup_context);
    }

    VALUE rb_context = (VALUE) context;
    switch (TYPE(rb_context)) {
        case T_OBJECT: return convert_object(rb_context, key, m_lookup_context, m_exection_context);
        case T_HASH:   return convert_hash(rb_context, key, m_lookup_context, m_exection_context);
        default:       return NULL;
    }
}
Пример #14
0
char			*ft_itoa_base(int value, int base)
{
	char		*res;
	int			len;

	len = get_value_len(value, base);
	if (value < 0 && base == 10)
		len++;
	res = (char *)malloc(sizeof(*res) * (len + 1));
	if (res)
	{
		if (value < 0 && base == 10)
			res[0] = '-';
		res[len] = '\0';
		convert_value(res, value, base, len - 1);
	}
	return (res);
}
Пример #15
0
// Try to find a standard conversion sequence from a source
// expression `e` and a destination type `t`.
//
// FIXME: Should `t` be an object type? That is we should perform
// conversions iff we can declare an object of type T?
Expr&
standard_conversion(Expr& e, Type& t)
{
  Expr& c1 = convert_category(e, t);
  if (is_equivalent(c1.type(), t))
    return c1;

  Expr& c2 = convert_value(c1, t);
  if (is_equivalent(c2.type(), t))
    return c2;

  Expr& c3 = convert_qualifier(c2, t);
  if (is_equivalent(c3.type(), t))
    return c3;

  // FIXME: Emit better diagnostics.
  throw std::runtime_error("conversion error");
}
Пример #16
0
void
var_copy(struct variable *dst, struct variable *src)
{
	int types[] = {VAR_BIGNUM, VAR_OCTSTRING, VAR_STRING};
	int i;

	assert(dst != NULL && src != NULL);

	dst->type = 0;

	for (i = 0; i < ARRSZ(types); i++) {
		if ((src->type & types[i]) == 0)
			continue;
		convert_value(dst, types[i], src, types[i]);

		dst->type |= types[i];
	}
	DEBUG(LOG_VERBOSE, "after copy dst types %.4x\n", dst->type);
}
Пример #17
0
/*! \brief
 * Does a type conversion on a list of values.
 *
 * \param[in,out] values   Values to convert.
 * \param[in]     type     Type to convert to.
 * \param[in]     scanner  Scanner data structure.
 * \returns       0 on success, a non-zero value on error.
 */
static int
convert_values(t_selexpr_value *values, e_selvalue_t type, void *scanner)
{
    t_selexpr_value *value;
    int              rc, rc1;

    rc = 0;
    value = values;
    while (value)
    {
        rc1 = convert_value(value, type, scanner);
        if (rc1 != 0 && rc == 0)
        {
            rc = rc1;
        }
        value = value->next;
    }
    /* FIXME: More informative error messages */
    return rc;
}
Пример #18
0
/*
 * In-place conversion of values b[0 ... n-1] to constant terms
 * - returns the number of values that could be successfully converted to terms
 *   (this is an integer between 0 and n).
 */
uint32_t convert_value_array(term_table_t *terms, value_table_t *vtbl, uint32_t n, int32_t *b) {
  val_converter_t convert;
  uint32_t i, s;
  term_t t;

  s = 0;
  if (n > 0) {
    init_val_converter(&convert, vtbl, terms);
    for (i=0; i<n; i++) {
      t = convert_value(&convert, b[i]);
      b[i] = t;
      if (t >= 0) { // no error
	s ++;
      }
    }
    delete_val_converter(&convert);
  }

  return s;
}
Пример #19
0
static void
compute_slider(Slider s, int *ny, int *vx, int *vy, int *lx, int *ly, int *sx, int *sy, int *hx, int *hy)
{ int hv = (s->show_value == ON ? valInt(getHeightFont(s->value_font)) : 0);
  int hl, hm;

  compute_label_slider(s, vx, &hl);
  hm = max(hl, max(hv, SLIDER_HEIGHT));

  *ny = (hm - hl) / 2;
  *sy = (hm - SLIDER_HEIGHT) / 2;
  *vy = *ly = *hy = (hm - hv) / 2;

  if ( s->show_value == ON )
  { int shw, slw, sh, cw = 4, tw;
    char buf[100];
    string str;

    buf[0] = '[';
    format_value(s, &buf[1], s->high);
    strcat(buf, "]");
    str_set_ascii(&str, buf);
    str_size(&str, s->value_font, &shw, &sh);
    format_value(s, buf, s->low);
    str_set_ascii(&str, buf);
    str_size(&str, s->value_font, &slw, &sh);
    if ( convert_value(s->low) < 0.0 &&
	 (tw = (c_width('-', s->value_font) + slw)) > shw )
      shw = tw;

    *lx = *vx + shw + cw;
    *sx = *lx + slw + cw;
    *hx = *sx + valInt(s->width) + cw;
  } else
  { *lx = *sx = *vx;
    *hx = *sx + valInt(s->width);
  }
}
Пример #20
0
static mustache_value_t* convert_value(
    VALUE rb_value,
    mustache_context_t* m_ctx)
{
    switch (TYPE(rb_value)) {
        case T_OBJECT: return create_mustache_object(m_ctx, rb_value);
        case T_STRUCT: return create_mustache_object(m_ctx, rb_value);
        case T_HASH:   return create_mustache_object(m_ctx, rb_value);
        case T_TRUE:   return create_mustache_value(m_ctx, rb_str_new2("true"));
        case T_FALSE:  return create_mustache_value(m_ctx, Qnil);
        case T_NONE:   return create_mustache_value(m_ctx, Qnil);
        case T_NIL:    return create_mustache_value(m_ctx, Qnil);
        case T_FLOAT:  return create_mustache_value(m_ctx, rb_funcall(rb_value, rb_intern("to_s"), 0, 0));
        case T_STRING: return create_mustache_value(m_ctx, rb_value);
        case T_FIXNUM: return create_mustache_value(m_ctx, rb_fix2str(rb_value, 10));
        case T_BIGNUM: return create_mustache_value(m_ctx, rb_big2str(rb_value, 10));
        case T_ARRAY:  return create_mustache_list(m_ctx, rb_value);
        default:
            if (rb_class_of(rb_value) == rb_cProc) {
                return convert_value(rb_funcall(rb_value, rb_intern("call"), 0, 0), m_ctx);
            }
            return create_mustache_value(m_ctx, rb_any_to_s(rb_value));
    }
}
Пример #21
0
static void *
var_convert_type(struct variable *var, var_type_t to_type)
{
	int from_type;

	assert(var != NULL && (
	    to_type == VAR_BIGNUM ||
	    to_type == VAR_STRING ||
	    to_type == VAR_OCTSTRING));

	if (var->type != VAR_BIGNUM &&
	    var->type != VAR_OCTSTRING &&
	    var->type != VAR_STRING)
		printf("composite type");

	//type exist
	if ((var->type & to_type) != 0) {
		if (var->type & VAR_BIGNUM)
			return &var->bnum;
		if (var->type & VAR_OCTSTRING)
			return &var->octstr;
		if (var->type & VAR_STRING)
			return &var->str;
	}

	if (var->type & VAR_BIGNUM)
		from_type = VAR_BIGNUM;
	else if (var->type & VAR_OCTSTRING)
		from_type = VAR_OCTSTRING;
	else if (var->type & VAR_STRING)
		from_type = VAR_STRING;

	var->type |= to_type;

	return convert_value(var, to_type, var, from_type);
}
Пример #22
0
static int query(pid_t pid,
                 opal_pstats_t *stats,
                 opal_node_stats_t *nstats)
{
    char data[4096];
    int fd;
    size_t numchars;
    char *ptr, *eptr;
    int i;
    int len, itime;
    double dtime;
    FILE *fp;
    char *dptr, *value;
    char **fields;
    opal_diskstats_t *ds;
    opal_netstats_t *ns;

    if (NULL != stats) {
        /* record the time of this sample */
        gettimeofday(&stats->sample_time, NULL);
        /* check the nstats - don't do gettimeofday twice
         * as it is expensive
         */
        if (NULL != nstats) {
            nstats->sample_time.tv_sec = stats->sample_time.tv_sec;
            nstats->sample_time.tv_usec = stats->sample_time.tv_usec;
        }
    } else if (NULL != nstats) {
        /* record the time of this sample */
        gettimeofday(&nstats->sample_time, NULL);
    }

    if (NULL != stats) {
        /* create the stat filename for this proc */
        numchars = snprintf(data, sizeof(data), "/proc/%d/stat", pid);
        if (numchars >= sizeof(data)) {
            return OPAL_ERR_VALUE_OUT_OF_BOUNDS;
        }

        if (0 > (fd = open(data, O_RDONLY))) {
            /* can't access this file - most likely, this means we
             * aren't really on a supported system, or the proc no
             * longer exists. Just return an error
             */
            return OPAL_ERR_FILE_OPEN_FAILURE;
        }

        /* absorb all of the file's contents in one gulp - we'll process
         * it once it is in memory for speed
         */
        memset(data, 0, sizeof(data));
        len = read(fd, data, sizeof(data)-1);
        if (len < 0) {
            /* This shouldn't happen! */
            close(fd);
            return OPAL_ERR_FILE_OPEN_FAILURE;
        }
        close(fd);

        /* remove newline at end */
        data[len] = '\0';

        /* the stat file consists of a single line in a carefully formatted
         * form. Parse it field by field as per proc(3) to get the ones we want
         */

        /* we don't need to read the pid from the file - we already know it! */
        stats->pid = pid;

        /* the cmd is surrounded by parentheses - find the start */
        if (NULL == (ptr = strchr(data, '('))) {
            /* no cmd => something wrong with data, return error */
            return OPAL_ERR_BAD_PARAM;
        }
        /* step over the paren */
        ptr++;

        /* find the ending paren */
        if (NULL == (eptr = strchr(ptr, ')'))) {
            /* no end to cmd => something wrong with data, return error */
            return OPAL_ERR_BAD_PARAM;
        }

        /* save the cmd name, up to the limit of the array */
        i = 0;
        while (ptr < eptr && i < OPAL_PSTAT_MAX_STRING_LEN) {
            stats->cmd[i++] = *ptr++;
        }

        /* move to the next field in the data */
        ptr = next_field(eptr, len);

        /* next is the process state - a single character */
        stats->state[0] = *ptr;
        /* move to next field */
        ptr = next_field(ptr, len);

        /* skip fields until we get to the times */
        ptr = next_field(ptr, len); /* ppid */
        ptr = next_field(ptr, len); /* pgrp */
        ptr = next_field(ptr, len); /* session */
        ptr = next_field(ptr, len); /* tty_nr */
        ptr = next_field(ptr, len); /* tpgid */
        ptr = next_field(ptr, len); /* flags */
        ptr = next_field(ptr, len); /* minflt */
        ptr = next_field(ptr, len); /* cminflt */
        ptr = next_field(ptr, len); /* majflt */
        ptr = next_field(ptr, len); /* cmajflt */

        /* grab the process time usage fields */
        itime = strtoul(ptr, &ptr, 10);    /* utime */
        itime += strtoul(ptr, &ptr, 10);   /* add the stime */
        /* convert to time in seconds */
        dtime = (double)itime / (double)HZ;
        stats->time.tv_sec = (int)dtime;
        stats->time.tv_usec = (int)(1000000.0 * (dtime - stats->time.tv_sec));
        /* move to next field */
        ptr = next_field(ptr, len);

        /* skip fields until we get to priority */
        ptr = next_field(ptr, len); /* cutime */
        ptr = next_field(ptr, len); /* cstime */

        /* save the priority */
        stats->priority = strtol(ptr, &ptr, 10);
        /* move to next field */
        ptr = next_field(ptr, len);

        /* skip nice */
        ptr = next_field(ptr, len);

        /* get number of threads */
        stats->num_threads = strtoul(ptr, &ptr, 10);
        /* move to next field */
        ptr = next_field(ptr, len);

        /* skip fields until we get to processor id */
        ptr = next_field(ptr, len);  /* itrealvalue */
        ptr = next_field(ptr, len);  /* starttime */
        ptr = next_field(ptr, len);  /* vsize */
        ptr = next_field(ptr, len);  /* rss */
        ptr = next_field(ptr, len);  /* rss limit */
        ptr = next_field(ptr, len);  /* startcode */
        ptr = next_field(ptr, len);  /* endcode */
        ptr = next_field(ptr, len);  /* startstack */
        ptr = next_field(ptr, len);  /* kstkesp */
        ptr = next_field(ptr, len);  /* kstkeip */
        ptr = next_field(ptr, len);  /* signal */
        ptr = next_field(ptr, len);  /* blocked */
        ptr = next_field(ptr, len);  /* sigignore */
        ptr = next_field(ptr, len);  /* sigcatch */
        ptr = next_field(ptr, len);  /* wchan */
        ptr = next_field(ptr, len);  /* nswap */
        ptr = next_field(ptr, len);  /* cnswap */
        ptr = next_field(ptr, len);  /* exit_signal */

        /* finally - get the processor */
        stats->processor = strtol(ptr, NULL, 10);

        /* that's all we care about from this data - ignore the rest */

        /* now create the status filename for this proc */
        memset(data, 0, sizeof(data));
        numchars = snprintf(data, sizeof(data), "/proc/%d/status", pid);
        if (numchars >= sizeof(data)) {
            return OPAL_ERR_VALUE_OUT_OF_BOUNDS;
        }

        if (NULL == (fp = fopen(data, "r"))) {
            /* ignore this */
            return OPAL_SUCCESS;
        }

        /* parse it according to proc(3) */
        while (NULL != (dptr = local_getline(fp))) {
            if (NULL == (value = local_stripper(dptr))) {
                /* cannot process */
                continue;
            }
            /* look for VmPeak */
            if (0 == strncmp(dptr, "VmPeak", strlen("VmPeak"))) {
                stats->peak_vsize = convert_value(value);
            } else if (0 == strncmp(dptr, "VmSize", strlen("VmSize"))) {
                stats->vsize = convert_value(value);
            } else if (0 == strncmp(dptr, "VmRSS", strlen("VmRSS"))) {
                stats->rss = convert_value(value);
            }
        }
        fclose(fp);
    }

    if (NULL != nstats) {
        /* get the loadavg data */
        if (0 > (fd = open("/proc/loadavg", O_RDONLY))) {
            /* not an error if we don't find this one as it
             * isn't critical
             */
            goto diskstats;
        }

        /* absorb all of the file's contents in one gulp - we'll process
         * it once it is in memory for speed
         */
        memset(data, 0, sizeof(data));
        len = read(fd, data, sizeof(data)-1);
        close(fd);
        if (len < 0) {
            goto diskstats;
        }

        /* remove newline at end */
        data[len] = '\0';

        /* we only care about the first three numbers */
        nstats->la = strtof(data, &ptr);
        nstats->la5 = strtof(ptr, &eptr);
        nstats->la15 = strtof(eptr, NULL);

        /* see if we can open the meminfo file */
        if (NULL == (fp = fopen("/proc/meminfo", "r"))) {
            /* ignore this */
            goto diskstats;
        }

        /* read the file one line at a time */
        while (NULL != (dptr = local_getline(fp))) {
            if (NULL == (value = local_stripper(dptr))) {
                /* cannot process */
                continue;
            }
            if (0 == strcmp(dptr, "MemTotal")) {
                nstats->total_mem = convert_value(value);
            } else if (0 == strcmp(dptr, "MemFree")) {
                nstats->free_mem = convert_value(value);
            } else if (0 == strcmp(dptr, "Buffers")) {
                nstats->buffers = convert_value(value);
            } else if (0 == strcmp(dptr, "Cached")) {
                nstats->cached = convert_value(value);
            } else if (0 == strcmp(dptr, "SwapCached")) {
                nstats->swap_cached = convert_value(value);
            } else if (0 == strcmp(dptr, "SwapTotal")) {
                nstats->swap_total = convert_value(value);
            } else if (0 == strcmp(dptr, "SwapFree")) {
                nstats->swap_free = convert_value(value);
            } else if (0 == strcmp(dptr, "Mapped")) {
                nstats->mapped = convert_value(value);
            }
        }
        fclose(fp);

    diskstats:
        /* look for the diskstats file */
        if (NULL == (fp = fopen("/proc/diskstats", "r"))) {
            /* not an error if we don't find this one as it
             * isn't critical
             */
            goto netstats;
        }
        /* read the file one line at a time */
        while (NULL != (dptr = local_getline(fp))) {
            /* look for the local disks */
            if (NULL == strstr(dptr, "sd")) {
                continue;
            }
            /* parse to extract the fields */
            fields = NULL;
            local_getfields(dptr, &fields);
            if (NULL == fields) {
                continue;
            }
            if (14 < opal_argv_count(fields)) {
                opal_argv_free(fields);
                continue;
            }
            /* pack the ones of interest into the struct */
            ds = OBJ_NEW(opal_diskstats_t);
            ds->disk = strdup(fields[2]);
            ds->num_reads_completed = strtoul(fields[3], NULL, 10);
            ds->num_reads_merged = strtoul(fields[4], NULL, 10);
            ds->num_sectors_read = strtoul(fields[5], NULL, 10);
            ds->milliseconds_reading = strtoul(fields[6], NULL, 10);
            ds->num_writes_completed = strtoul(fields[7], NULL, 10);
            ds->num_writes_merged = strtoul(fields[8], NULL, 10);
            ds->num_sectors_written = strtoul(fields[9], NULL, 10);
            ds->milliseconds_writing = strtoul(fields[10], NULL, 10);
            ds->num_ios_in_progress = strtoul(fields[11], NULL, 10);
            ds->milliseconds_io = strtoul(fields[12], NULL, 10);
            ds->weighted_milliseconds_io = strtoul(fields[13], NULL, 10);
            opal_list_append(&nstats->diskstats, &ds->super);
            opal_argv_free(fields);
        }
        fclose(fp);

    netstats:
        /* look for the netstats file */
        if (NULL == (fp = fopen("/proc/net/dev", "r"))) {
            /* not an error if we don't find this one as it
             * isn't critical
             */
            goto complete;
        }
        /* skip the first two lines as they are headers */
        local_getline(fp);
        local_getline(fp);
        /* read the file one line at a time */
        while (NULL != (dptr = local_getline(fp))) {
            /* the interface is at the start of the line */
            if (NULL == (ptr = strchr(dptr, ':'))) {
                continue;
            }
            *ptr = '\0';
            ptr++;
            /* parse to extract the fields */
            fields = NULL;
            local_getfields(ptr, &fields);
            if (NULL == fields) {
                continue;
            }
            /* pack the ones of interest into the struct */
            ns = OBJ_NEW(opal_netstats_t);
            ns->net_interface = strdup(dptr);
            ns->num_bytes_recvd = strtoul(fields[0], NULL, 10);
            ns->num_packets_recvd = strtoul(fields[1], NULL, 10);
            ns->num_recv_errs = strtoul(fields[2], NULL, 10);
            ns->num_bytes_sent = strtoul(fields[8], NULL, 10);
            ns->num_packets_sent = strtoul(fields[9], NULL, 10);
            ns->num_send_errs = strtoul(fields[10], NULL, 10);
            opal_list_append(&nstats->netstats, &ns->super);
            opal_argv_free(fields);
        }
        fclose(fp);
    }

 complete:
    return OPAL_SUCCESS;
}
Пример #23
0
static status
RedrawAreaSlider(Slider s, Area a)
{ int x, y, w, h;
  int ny, vx, vy, lx, ly, sx, sy, hx, hy;
  int vv;
  int bw = (s->look == NAME_x ? BAR_WIDTH : OL_BOX_WIDTH);
  float lv = convert_value(s->low);
  float hv = convert_value(s->high);
  float dv = convert_value(s->displayed_value);
  int lflags = (s->active == ON ? 0 : LABEL_INACTIVE);

  if ( dv < lv )
    dv = lv;
  else if ( dv > hv )
    dv = hv;

  if ( hv > lv )
    vv = rfloat(((float) (valInt(s->width) - bw) * (dv - lv)) / (hv - lv));
  else
    vv = 0;

  initialiseDeviceGraphical(s, &x, &y, &w, &h);
  NormaliseArea(x, y, w, h);
  r_thickness(valInt(s->pen));
  r_dash(s->texture);

  compute_slider(s, &ny, &vx, &vy, &lx, &ly, &sx, &sy, &hx, &hy);
  r_clear(x, y, w, h);

  if ( s->show_label == ON )
  { int ex = valInt(getExFont(s->label_font));

    RedrawLabelDialogItem(s,
			  accelerator_code(s->accelerator),
			  x, y+ny, vx-ex, 0,
			  s->label_format, NAME_top,
			  lflags);
  }

  if ( s->look == NAME_motif )
  { int by = y+sy+(SLIDER_HEIGHT-OL_BAR_HEIGHT)/2;
    int ex  = x + sx + valInt(s->width);
    Elevation z = getClassVariableValueObject(s, NAME_elevation);

    r_3d_box(x+sx, by, vv, OL_BAR_HEIGHT, 0, z, FALSE);
    r_3d_box(x+sx+vv+bw, by, ex-(x+sx+vv+bw), OL_BAR_HEIGHT, 0, z, FALSE);
    r_3d_box(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, 0, z, TRUE);
  } else if ( s->look == NAME_openLook )
  { int by = y+sy+(SLIDER_HEIGHT-OL_BAR_HEIGHT)/2;
    int ly2 = by+OL_BAR_HEIGHT-1;
    int ex  = x + sx + valInt(s->width);

    r_fill(x+sx, by+1, 1, OL_BAR_HEIGHT-2, BLACK_IMAGE);
    r_fill(x+sx+1, by, vv-2, OL_BAR_HEIGHT, BLACK_IMAGE);
    r_line(x+sx+1+vv+bw, by, ex-2, by);
    r_line(x+sx+1+vv+bw, ly2, ex-2, ly2);
    r_line(ex-1, by+1, ex-1, ly2-1);
    r_shadow_box(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, 0, 1, NIL);
  } else
  { r_fill(x+sx, y+sy, vv, SLIDER_HEIGHT, GREY50_IMAGE);
    r_box(x+sx, y+sy, valInt(s->width), SLIDER_HEIGHT, 0, NIL);
    r_fill(x+sx+vv, y+sy, bw, SLIDER_HEIGHT, BLACK_IMAGE);
  }

  if ( s->show_value == ON )
  { char buf[100];
    string str;

    buf[0] = '[';
    format_value(s, &buf[1], s->displayed_value);
    strcat(buf, "]");
    str_set_ascii(&str, buf);
    str_label(&str, 0, s->value_font,
	      x+vx, y+vy, 0, 0, NAME_left, NAME_top, lflags);
    format_value(s, buf, s->low);
    str_set_ascii(&str, buf);
    str_label(&str, 0, s->value_font,
	      x+lx, y+ly, 0, 0, NAME_left, NAME_top, lflags);
    format_value(s, buf, s->high);
    str_set_ascii(&str, buf);
    str_label(&str, 0, s->value_font,
	      x+hx, y+hy, 0, 0, NAME_left, NAME_top, lflags);
  }

  return RedrawAreaGraphical(s, a);
}