Beispiel #1
0
/// Print values of all resource limits.
static void print_all(int hard, io_streams_t &streams) {
    int i;
    int w = 0;

    for (i = 0; resource_arr[i].desc; i++) {
        w = maxi(w, fish_wcswidth(resource_arr[i].desc));
    }

    for (i = 0; resource_arr[i].desc; i++) {
        struct rlimit ls;
        rlim_t l;
        getrlimit(resource_arr[i].resource, &ls);
        l = hard ? ls.rlim_max : ls.rlim_cur;

        const wchar_t *unit =
            ((resource_arr[i].resource == RLIMIT_CPU)
                 ? L"(seconds, "
                 : (get_multiplier(resource_arr[i].resource) == 1 ? L"(" : L"(kB, "));

        streams.out.append_format(L"%-*ls %10ls-%lc) ", w, resource_arr[i].desc, unit,
                                  resource_arr[i].switch_char);

        if (l == RLIM_INFINITY) {
            streams.out.append(L"unlimited\n");
        } else {
            streams.out.append_format(L"%d\n", l / get_multiplier(resource_arr[i].resource));
        }
    }
}
Beispiel #2
0
int
get_size_argument(long *number, partition_map_header *map)
{
    partition_map * entry;
    int result = 0;
    unsigned long multiple;

    if (get_number_argument("Length in blocks: ", number, kDefault) == 0) {
	bad_input("Bad length");
    } else {
	multiple = get_multiplier(map->logical_block);
	if (multiple == 0) {
	    bad_input("Bad multiplier");
	} else if (multiple != 1) {
	    *number *= multiple;
	    result = 1;
	} else if (get_partition_modifier()) {
	    entry = find_entry_by_disk_address(*number, map);
	    if (entry == NULL) {
		bad_input("Bad partition number");
	    } else {
		*number = entry->data->dpme_pblocks;
		result = 1;
	    }
	} else {
	    result = 1;
	}
    }
    return result;
}
Beispiel #3
0
/// Print the value of the specified resource limit.
static void print(int resource, int hard, io_streams_t &streams) {
    rlim_t l = get(resource, hard);

    if (l == RLIM_INFINITY)
        streams.out.append(L"unlimited\n");
    else
        streams.out.append_format(L"%d\n", l / get_multiplier(resource));
}
Beispiel #4
0
Timer::Timer()
  :_start_cpu(-1),
   num_calls(0),
   total_cpu(0),
   max_cpu(-std::numeric_limits<double>::max()),
   min_cpu(std::numeric_limits<double>::max()),
   last_cpu(std::numeric_limits<double>::max()){
  _multiplier = get_multiplier();
}
Beispiel #5
0
/**
   Print the value of the specified resource limit
*/
static void print(int resource, int hard)
{
    rlim_t l = get(resource, hard);

    if (l == RLIM_INFINITY)
        stdout_buffer.append(L"unlimited\n");
    else
        append_format(stdout_buffer, L"%d\n", l / get_multiplier(resource));

}
Beispiel #6
0
Datei: spair.c Projekt: ederc/gb
inline void add_spair_generator_to_selection(sel_t *sel, const gb_t *basis,
    const hash_t lcm, const nelts_t gen)
{
  hash_t mul;
  mul = get_multiplier(lcm, basis->eh[gen][0], ht);
  if (sel->load == sel->size)
    adjust_size_of_selection(sel, 2*sel->size);
  sel->mpp[sel->load].mlm = lcm;
  sel->mpp[sel->load].mul = mul;
  sel->mpp[sel->load].bi  = gen;
  sel->mpp[sel->load].eh  = basis->eh[gen];
  sel->mpp[sel->load].cf  = basis->cf[gen];
  sel->mpp[sel->load].nt  = basis->nt[gen];
  sel->load++;
}
Beispiel #7
0
/**
 * ubiutils_get_bytes - convert a string containing amount of bytes into an
 * integer
 * @str: string to convert
 *
 * This function parses @str which may have one of 'KiB', 'MiB', or 'GiB'
 * size specifiers. Returns positive amount of bytes in case of success and %-1
 * in case of failure.
 */
long long ubiutils_get_bytes(const char *str)
{
	char *endp;
	long long bytes = strtoull(str, &endp, 0);

	if (endp == str || bytes < 0) {
		my_fprintf(stderr, "incorrect amount of bytes: \"%s\"\n", str);
		return -1;
	}

	if (*endp != '\0') {
		int mult = get_multiplier(endp);

		if (mult == -1) {
			my_fprintf(stderr, "bad size specifier: \"%s\" - "
			        "should be 'KiB', 'MiB' or 'GiB'\n", endp);
			return -1;
		}
		bytes *= mult;
	}

	return bytes;
}
Beispiel #8
0
/// The ulimit builtin, used for setting resource limits.
int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
    wgetopter_t w;
    int hard = 0;
    int soft = 0;

    int what = RLIMIT_FSIZE;
    int report_all = 0;

    int argc = builtin_count_args(argv);

    w.woptind = 0;

    while (1) {
        static const struct woption long_options[] = {
            {L"all", no_argument, 0, 'a'},
            {L"hard", no_argument, 0, 'H'},
            {L"soft", no_argument, 0, 'S'},
            {L"core-size", no_argument, 0, 'c'},
            {L"data-size", no_argument, 0, 'd'},
            {L"file-size", no_argument, 0, 'f'},
            {L"lock-size", no_argument, 0, 'l'},
            {L"resident-set-size", no_argument, 0, 'm'},
            {L"file-descriptor-count", no_argument, 0, 'n'},
            {L"stack-size", no_argument, 0, 's'},
            {L"cpu-time", no_argument, 0, 't'},
            {L"process-count", no_argument, 0, 'u'},
            {L"virtual-memory-size", no_argument, 0, 'v'},
            {L"help", no_argument, 0, 'h'},
            {0, 0, 0, 0}};

        int opt_index = 0;

        int opt = w.wgetopt_long(argc, argv, L"aHScdflmnstuvh", long_options, &opt_index);
        if (opt == -1) break;

        switch (opt) {
            case 0: {
                if (long_options[opt_index].flag != 0) break;
                streams.err.append_format(BUILTIN_ERR_UNKNOWN, argv[0],
                                          long_options[opt_index].name);
                builtin_print_help(parser, streams, argv[0], streams.err);
                return 1;
            }
            case L'a': {
                report_all = 1;
                break;
            }
            case L'H': {
                hard = 1;
                break;
            }
            case L'S': {
                soft = 1;
                break;
            }
            case L'c': {
                what = RLIMIT_CORE;
                break;
            }
            case L'd': {
                what = RLIMIT_DATA;
                break;
            }
            case L'f': {
                what = RLIMIT_FSIZE;
                break;
            }
#ifdef RLIMIT_MEMLOCK
            case L'l': {
                what = RLIMIT_MEMLOCK;
                break;
            }
#endif
#ifdef RLIMIT_RSS
            case L'm': {
                what = RLIMIT_RSS;
                break;
            }
#endif
            case L'n': {
                what = RLIMIT_NOFILE;
                break;
            }
            case L's': {
                what = RLIMIT_STACK;
                break;
            }
            case L't': {
                what = RLIMIT_CPU;
                break;
            }
#ifdef RLIMIT_NPROC
            case L'u': {
                what = RLIMIT_NPROC;
                break;
            }
#endif
#ifdef RLIMIT_AS
            case L'v': {
                what = RLIMIT_AS;
                break;
            }
#endif
            case L'h': {
                builtin_print_help(parser, streams, argv[0], streams.out);
                return 0;
            }
            case L'?': {
                builtin_unknown_option(parser, streams, argv[0], argv[w.woptind - 1]);
                return 1;
            }
        }
    }

    if (report_all) {
        if (argc - w.woptind == 0) {
            print_all(hard, streams);
        } else {
            streams.err.append(argv[0]);
            streams.err.append(L": Too many arguments\n");
            builtin_print_help(parser, streams, argv[0], streams.err);
            return 1;
        }

        return 0;
    }

    switch (argc - w.woptind) {
        case 0: {  // show current limit value
            print(what, hard, streams);
            break;
        }
        case 1: {  // change current limit value
            rlim_t new_limit;
            wchar_t *end;

            // Set both hard and soft limits if nothing else was specified.
            if (!(hard + soft)) {
                hard = soft = 1;
            }

            if (wcscasecmp(argv[w.woptind], L"unlimited") == 0) {
                new_limit = RLIM_INFINITY;
            } else if (wcscasecmp(argv[w.woptind], L"hard") == 0) {
                new_limit = get(what, 1);
            } else if (wcscasecmp(argv[w.woptind], L"soft") == 0) {
                new_limit = get(what, soft);
            } else {
                errno = 0;
                new_limit = wcstol(argv[w.woptind], &end, 10);
                if (errno || *end) {
                    streams.err.append_format(L"%ls: Invalid limit '%ls'\n", argv[0],
                                              argv[w.woptind]);
                    builtin_print_help(parser, streams, argv[0], streams.err);
                    return 1;
                }
                new_limit *= get_multiplier(what);
            }

            return set(what, hard, soft, new_limit, streams);
        }
        default: {
            streams.err.append(argv[0]);
            streams.err.append(L": Too many arguments\n");
            builtin_print_help(parser, streams, argv[0], streams.err);
            return 1;
        }
    }
    return 0;
}
Beispiel #9
0
/// The ulimit builtin, used for setting resource limits.
int builtin_ulimit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
    wchar_t *cmd = argv[0];
    int argc = builtin_count_args(argv);
    bool report_all = false;
    bool hard = false;
    bool soft = false;
    int what = RLIMIT_FSIZE;

    const wchar_t *short_options = L":HSacdflmnstuvh";
    const struct woption long_options[] = {{L"all", no_argument, NULL, 'a'},
                                           {L"hard", no_argument, NULL, 'H'},
                                           {L"soft", no_argument, NULL, 'S'},
                                           {L"core-size", no_argument, NULL, 'c'},
                                           {L"data-size", no_argument, NULL, 'd'},
                                           {L"file-size", no_argument, NULL, 'f'},
                                           {L"lock-size", no_argument, NULL, 'l'},
                                           {L"resident-set-size", no_argument, NULL, 'm'},
                                           {L"file-descriptor-count", no_argument, NULL, 'n'},
                                           {L"stack-size", no_argument, NULL, 's'},
                                           {L"cpu-time", no_argument, NULL, 't'},
                                           {L"process-count", no_argument, NULL, 'u'},
                                           {L"virtual-memory-size", no_argument, NULL, 'v'},
                                           {L"help", no_argument, NULL, 'h'},
                                           {NULL, 0, NULL, 0}};

    int opt;
    wgetopter_t w;
    while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
        switch (opt) {
            case 'a': {
                report_all = true;
                break;
            }
            case 'H': {
                hard = true;
                break;
            }
            case 'S': {
                soft = true;
                break;
            }
            case 'c': {
                what = RLIMIT_CORE;
                break;
            }
            case 'd': {
                what = RLIMIT_DATA;
                break;
            }
            case 'f': {
                what = RLIMIT_FSIZE;
                break;
            }
#ifdef RLIMIT_MEMLOCK
            case 'l': {
                what = RLIMIT_MEMLOCK;
                break;
            }
#endif
#ifdef RLIMIT_RSS
            case 'm': {
                what = RLIMIT_RSS;
                break;
            }
#endif
            case 'n': {
                what = RLIMIT_NOFILE;
                break;
            }
            case 's': {
                what = RLIMIT_STACK;
                break;
            }
            case 't': {
                what = RLIMIT_CPU;
                break;
            }
#ifdef RLIMIT_NPROC
            case 'u': {
                what = RLIMIT_NPROC;
                break;
            }
#endif
#ifdef RLIMIT_AS
            case 'v': {
                what = RLIMIT_AS;
                break;
            }
#endif
            case 'h': {
                builtin_print_help(parser, streams, cmd, streams.out);
                return 0;
            }
            case ':': {
                streams.err.append_format(BUILTIN_ERR_MISSING, cmd, argv[w.woptind - 1]);
                return STATUS_BUILTIN_ERROR;
            }
            case '?': {
                builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
                return STATUS_BUILTIN_ERROR;
            }
            default: {
                DIE("unexpected retval from wgetopt_long");
                break;
            }
        }
    }

    if (report_all) {
        print_all(hard, streams);
        return STATUS_BUILTIN_OK;
    }

    int arg_count = argc - w.woptind;
    if (arg_count == 0) {
        // Show current limit value.
        print(what, hard, streams);
        return STATUS_BUILTIN_OK;
    } else if (arg_count != 1) {
        streams.err.append_format(BUILTIN_ERR_TOO_MANY_ARGUMENTS, cmd);
        builtin_print_help(parser, streams, cmd, streams.err);
        return STATUS_BUILTIN_ERROR;
    }

    // Change current limit value.
    if (!hard && !soft) {
        // Set both hard and soft limits if neither was specified.
        hard = soft = true;
    }

    rlim_t new_limit;
    if (*argv[w.woptind] == L'\0') {
        streams.err.append_format(_(L"%ls: New limit cannot be an empty string\n"), cmd);
        builtin_print_help(parser, streams, cmd, streams.err);
        return STATUS_BUILTIN_ERROR;
    } else if (wcscasecmp(argv[w.woptind], L"unlimited") == 0) {
        new_limit = RLIM_INFINITY;
    } else if (wcscasecmp(argv[w.woptind], L"hard") == 0) {
        new_limit = get(what, 1);
    } else if (wcscasecmp(argv[w.woptind], L"soft") == 0) {
        new_limit = get(what, soft);
    } else {
        new_limit = fish_wcstol(argv[w.woptind]);
        if (errno) {
            streams.err.append_format(_(L"%ls: Invalid limit '%ls'\n"), cmd, argv[w.woptind]);
            builtin_print_help(parser, streams, cmd, streams.err);
            return STATUS_BUILTIN_ERROR;
        }
        new_limit *= get_multiplier(what);
    }

    return set_limit(what, hard, soft, new_limit, streams);
}
u_long32 
sge_parse_num_val(sge_rlim_t *rlimp, double *dvalp, 
                  const char *str, const char *where, 
                  char *err_str, int err_len)
{
   double dummy;
   sge_rlim_t rlim, rlmuli;
   double dval;
   u_long32 ldummy;
   char *dptr;
   double muli;

   if (!rlimp)
      rlimp = &rlim;
   if (!dvalp)
      dvalp = &dval;

   if (err_str)
      err_str[0] = '\0';

   if (!strcasecmp(str, "true")) {
      /* C-language says bool is a numeric. For reasons of simplicity we 
         agree. */
      *dvalp = 1;
      *rlimp = 1;
      return 1;
   } else if (!strcasecmp(str, "false")) {
      *dvalp = 0;
      *rlimp = 0;
      return 0;
   } else if (!strcasecmp(str, "infinity")) {
      *dvalp = DBL_MAX;       /* use this for comparing limits */
      *rlimp = RLIM_INFINITY; /* use this for limit setting */
      return 0xFFFFFFFF;      /* return max ulong in 32 bit */
   } else if (strchr(str, ':')) {
      /* This is a time value in the format hr:min:sec */

      /* find the hours first */
      double t = strtod(str, &dptr);
      if (t > 0x7fffffff) {
         snprintf(err_str, err_len, MSG_GDI_NUMERICALVALUEFORHOUREXCEEDED_SS , where, str);
         return 0;
      }
      ldummy = (u_long32)(3600 * t);
      *rlimp = (sge_rlim_t)(long)mul_infinity(t, 3600.0);
      *dvalp = 3600 * t;

      if ((*dptr) != ':') {  
         snprintf(err_str, err_len, MSG_GDI_NUMERICALVALUEINVALID_SS , where, str);
         return 0;
      }
      /* now go for the minutes */
      dptr++;
      t = strtod(dptr, &dptr);
      if (t > 0x7fffffff) {
         snprintf(err_str, err_len, MSG_GDI_NUMERICALVALUEFORMINUTEEXCEEDED_SS , where, str);
         return 0;
      }
      ldummy += (u_long32)(60 * t);
      *rlimp = add_infinity(*rlimp, (sge_rlim_t)(60*t));
      *dvalp += 60 * t;

      if ((*dptr) != ':') {
         snprintf(err_str, err_len, MSG_GDI_NUMERICALVALUEINVALID_SS , where, str);
         return 0;
      }
      /* the seconds finally */
      dptr++;

      t = strtod(dptr, &dptr);
      ldummy += (u_long32)t;
      *rlimp = (sge_rlim_t)(long)add_infinity(*rlimp, t);
      *dvalp += t;

      while(*dptr) {
         if (!isspace((int) *dptr)) {
            snprintf(err_str, err_len, MSG_GDI_NUMERICALVALUEINVALID_SS , where, str);
            return 0;
         }
         dptr++;
      }

      return (ldummy);

   } else if (strchr(str, '.') || *str != '0') {
      /* obviously this is no hex and no oct
       * ==> allow for both decimal and fixed float
       */
       
      double t = strtod(str, &dptr);
      
      if (t > 0x7fffffff)
         dummy = 0x7fffffff;
      else
         dummy = t;
   
      if ((dummy == 0.0) && (dptr == str)) {    /* no valid number ==> bail */
         snprintf(err_str, err_len, MSG_GDI_NUMERICALVALUEINVALIDNONUMBER_SS , where, str);
         return 0;
      }

      /* OK, we got it */
      if (!(muli = get_multiplier(&rlmuli, &dptr, where, err_str, err_len)))
         return 0;
      dummy =    (u_long32) (dummy * muli);
      *dvalp =              t * muli;

      if (t > RLIM_MAX || rlmuli>= RLIM_MAX || (double)(RLIM_MAX/muli)<t)
         *rlimp = RLIM_INFINITY;
      else 
         *rlimp = (sge_rlim_t)(t*rlmuli);

      return (u_long32)dummy;

   } else { /* if (strchr(str, '.') || *str != '0') */
      /* This is either a hex or an octal ==> no fixed float allowed;
       * just use strtol
       */
      u_long32 t = strtol(str, &dptr, 0);   /* base=0 will handle both hex and oct */
      ldummy = t;
      *rlimp = t;
      *dvalp = t;

      if (dptr == str) {        /* no valid number ==> bail */
         snprintf(err_str, err_len, MSG_GDI_NUMERICALVALUEINVALIDNOHEXOCTNUMBER_SS , where, str);
         return 0;
      }
      /* OK, we got it */
      if (!(muli = get_multiplier(&rlmuli, &dptr, where, err_str, err_len)))
         return 0;
      ldummy *= (u_long32)muli;
      *rlimp = mul_infinity(*rlimp, rlmuli);
      *dvalp *= muli;

      return (u_long32)ldummy;
   }
}
Beispiel #11
0
/*!
  \brief bind_data() is a recursive function that is called for every container
  widget in a glade frame and it's purpose is to search the datamap file passed
  for the widget names in the glade file and if it's fond in the datamap to
  load all the attribues listed and bind them to the object using GTK+'s
  object model.
  \param widget is the widget passed to load attributes on
  \param user_data is the pointer to a BingGroup structure.
  */
G_MODULE_EXPORT void bind_data(GtkWidget *widget, gpointer user_data)
{
	BindGroup *bindgroup = (BindGroup *)user_data;
	ConfigFile *cfgfile = bindgroup->cfgfile;
	GHashTable *groups = bindgroup->groups;
	gchar * tmpbuf = NULL;
	gchar * section = NULL;
	gchar ** keys = NULL;
	gint num_keys = 0;
	gint offset = 0;
	gint page = 0;
	gint index = 0;
	gchar * initializer = NULL;
	GdkColor color;
	gchar *size = NULL;
	gint count = 0;
	gint tmpi = 0;
	gboolean hidden = FALSE;
	gchar *ptr = NULL;
	gchar **vector = NULL;
	gchar **vec2 = NULL;
	void (*func)(void) = NULL;
	GList *list = NULL;
	GList *list2 = NULL;
	const gchar *name = NULL;
	gboolean indexed = FALSE;
	Firmware_Details *firmware = NULL;
	GList ***ecu_widgets = NULL;
	GList *tab_widgets = NULL;
	void (*load_dep_obj)(GObject *, ConfigFile *,const gchar *,const gchar *) = NULL;

	ENTER();
	MTXDBG(TABLOADER,_("Entered"));
	ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets");
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	g_return_if_fail(ecu_widgets);
	g_return_if_fail(firmware);

	if (!GTK_IS_WIDGET(widget))
	{
		EXIT();
		return;
	}

	if (GTK_IS_WIDGET(widget))
		if (GTK_IS_CONTAINER(widget))
			gtk_container_foreach(GTK_CONTAINER(widget),bind_data,user_data);
	name = gtk_widget_get_name(widget);
	if (!name)
	{
		EXIT();
		return;
	}

	if (NULL != (ptr = g_strrstr_len(name,strlen(name),"_of_")))
	{
		indexed = TRUE;
		ptr = g_strrstr_len(name,ptr-name,"_");
		tmpbuf = g_strdelimit(g_strdup(ptr),"_",' ');
		section = g_strndup(name,ptr-name);
		/*printf("(indexed) section is %s\n",section);*/
		gint result = sscanf(tmpbuf,"%d of %d",&index,&count);
		/*printf("sscanf result %i\n",result);*
		* printf("Found indexed value for \"%s\", index %i, count %i\n",tmpbuf,index,count);
		*/
		g_free(tmpbuf);
	}
	else
		section = g_strdup(name);

	if(cfg_read_string(cfgfile, section, "keys", &tmpbuf))
	{
		keys = parse_keys(tmpbuf,&num_keys,",");
		MTXDBG(TABLOADER,_("Number of keys for %s is %i\n"),section,num_keys);
		g_free(tmpbuf);
	}
	else 
	{
		g_free(section);
		EXIT();
		return;
	}

	page = -1;
	/* Store ptr to self in qdata, needed for bind_to_lists from groups*/
	OBJ_SET(widget,"self",widget);
	/* Bind the data in the "defaults" group per tab to EVERY var in that
	 * tab
	 */
	page = bind_group_data(cfgfile, G_OBJECT(widget), groups, "defaults");

	if(cfg_read_string(cfgfile, section, "group", &tmpbuf))
	{
		page = bind_group_data(cfgfile,G_OBJECT(widget),groups,tmpbuf);
		g_free(tmpbuf);
	}

	if ((!cfg_read_int(cfgfile, section, "page", &page)) && (page == -1))
	{
		MTXDBG(TABLOADER|CRITICAL,_("Object %s doesn't have a page assigned!!!!\n"),section);	

	}
	/* Bind widgets to lists if they have the bind_to_list flag set...
	 */
	tmpbuf = NULL;
	if (cfg_read_string(cfgfile, section, "bind_to_list", &tmpbuf))
	{
		bind_to_lists(widget, tmpbuf);
		g_free(tmpbuf);
	}
	if (cfg_read_boolean(cfgfile,section,"ellipsize",&tmpi))
	{
		if ((GTK_IS_LABEL(widget)) && (tmpi))
		{
			OBJ_SET(widget,"ellipsize_preferred",GINT_TO_POINTER(TRUE));
			if (DATA_GET(global_data,"ellipsize_tabs"))
				gtk_label_set_ellipsize(GTK_LABEL(widget),PANGO_ELLIPSIZE_END);
		}
	}

	/* Color selections */
	if (cfg_read_string(cfgfile, section, "active_fg", &tmpbuf))
	{
		gdk_color_parse(tmpbuf, &color);
		gtk_widget_modify_fg(widget, GTK_STATE_NORMAL, &color);
		g_free(tmpbuf);
	}
	if (cfg_read_string(cfgfile, section, "inactive_fg", &tmpbuf))
	{
		gdk_color_parse(tmpbuf, &color);
		gtk_widget_modify_fg(widget, GTK_STATE_INSENSITIVE, &color);
		g_free(tmpbuf);
	}

	/* If this widget has a "depend_on" tag we need to load the dependancy
	 * information  and store it for use when needed...
	 */
	if (cfg_read_string(cfgfile,section,"depend_on",&tmpbuf))
	{
		if (get_symbol("load_dependencies_obj",(void **)&load_dep_obj))
			load_dep_obj(G_OBJECT(widget),cfgfile,section,"depend_on");
		g_free(tmpbuf);
	}

	/* If this widget (a textview) has "create_tags" we call a special
	 * handler just for that..
	 */
	if (cfg_read_string(cfgfile,section,"create_tags",&tmpbuf))
	{
		load_tags(G_OBJECT(widget),cfgfile,section);
		g_free(tmpbuf);
	}

	/* If this widget has "tooltip" set the tip on the widget */
	if (cfg_read_string(cfgfile,section,"tooltip",&tmpbuf))
	{
		gtk_widget_set_tooltip_text(widget,tmpbuf);
		g_free(tmpbuf);
	}

	/* If this widget (a label) has "set_label" we set the label on it
	 */
	if (cfg_read_string(cfgfile,section,"set_label",&tmpbuf))
	{
/*		printf("setting label on %s to \"%s\"\n",glade_get_widget_name(widget),tmpbuf);*/
		gtk_label_set_text(GTK_LABEL(widget),tmpbuf);
		g_free(tmpbuf);
	}

	/* If this widget is temp dependant, set the current units on it 
	 */
	if (cfg_read_string(cfgfile,section,"temp_dep",&tmpbuf))
	{
		OBJ_SET(widget,"widget_temp",DATA_GET(global_data,"mtx_temp_units"));
		g_free(tmpbuf);
	}

	/* If this widget has "register_as", register it with the supplied name
	 */
	if (cfg_read_string(cfgfile,section,"register_as",&tmpbuf))
	{
		register_widget(tmpbuf,widget);
		g_free(tmpbuf);
	}
	/* If this widget has visible_functions defined */
	if (cfg_read_string(cfgfile,section,"visible_functions",&tmpbuf))
	{
		vector = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
		for (guint i=0;i<g_strv_length(vector);i++)
		{
			vec2 = g_strsplit(vector[i],":",2);
			if (g_strv_length(vec2) != 2)
			{
				printf("ERROR in %s, visible_functions param is missing the framerate parameter (func:fps)\n",cfgfile->filename);
				g_strfreev(vec2);
				continue;
			}
			gint fps = (GINT)g_strtod(vec2[1],NULL);
			get_symbol(vec2[0],(void **)&func);
			if (func)
			{
				list = g_list_prepend(list,(gpointer)func);
				list2 = g_list_prepend(list2,GINT_TO_POINTER(fps));
			}
			g_strfreev(vec2);
		}
		g_strfreev(vector);
		OBJ_SET_FULL(widget,"func_list",list,g_list_free);
		OBJ_SET_FULL(widget,"func_fps_list",list2,g_list_free);
	}

	/* If this widget has "initializer" there's a global variable 
	 * with it's name on it 
	 */
	if (cfg_read_string(cfgfile,section,"initializer",&initializer))
	{
		gint widget_type = 0;
		if (!cfg_read_string(cfgfile,section,"widget_type",&tmpbuf))
			MTXDBG(TABLOADER|CRITICAL,_("Object %s has initializer, but no widget_type!!!!\n"),section);
		else
			widget_type = translate_string(tmpbuf);
		g_free(tmpbuf);
		switch (widget_type)
		{
			case MTX_RANGE:
				gtk_range_set_value(GTK_RANGE(widget),(GINT)DATA_GET(global_data,initializer));
				break;

			case MTX_SPINBUTTON:
				gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),(GINT)DATA_GET(global_data,initializer));
				break;
			case MTX_ENTRY:
				gtk_entry_set_text(GTK_ENTRY(widget),(gchar *)DATA_GET(global_data,initializer));

			default:
				break;

		}
		g_free(initializer);
	}
	/* Hidden widgets have special handlers and should NOT be updated normally */
	cfg_read_boolean(cfgfile,section, "hidden", &hidden);
	offset = -1;
	cfg_read_int(cfgfile,section, "offset", &offset);
	if (offset >= 0 && indexed)
	{
		/*printf("indexed widget %s\n",name); */
		if (cfg_read_string(cfgfile, section, "size", &size))
		{
			offset += index * get_multiplier ((DataSize)translate_string (size));
			g_free(size);
		}
		else
		{
			if(OBJ_GET(widget, "size"))
			{
				offset += index * get_multiplier ((DataSize)(GINT)OBJ_GET(widget, "size"));
			}
			else
			{
				MTXDBG(TABLOADER|CRITICAL,_("Indexed Object %s has index and offset, but no size!!!!\n"),section);
				g_free(section);
				EXIT();
				return;
			}
		}
		/*printf("widget %s, offset %i\n",name,offset);*/
		OBJ_SET(widget,"offset",GINT_TO_POINTER(offset));
	}
	if (offset >= 0)
	{
		/* The way we do it now is to STORE widgets in LISTS for each
		 * offset, thus we can have multiple on screen controls bound
		 * to single data offset in the ECU
		 */
		if (page < 0)
		{
			MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters,  there is a bug with this datamap widget %s, page %i, at offset %i...\n\n"),section,page,offset);
			g_free(section);
			EXIT();
			return;
		}
		if (page < firmware->total_pages)
		{
			if (offset >= firmware->page_params[page]->length)
				MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters,  there is a bug with this datamap widget %s, at offset %i...\n\n"),section,offset);
			else if (!hidden)
			{

				tab_widgets = OBJ_GET(bindgroup->topframe,"tab_widgets");
				tab_widgets = g_list_prepend(tab_widgets, widget);
				OBJ_SET(bindgroup->topframe,"tab_widgets",tab_widgets);
				ecu_widgets[page][offset] = g_list_prepend(
						ecu_widgets[page][offset],
						(gpointer)widget);
			}
		}
		else
			MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap for widget %s, at page %i offset %i...\n\n"),section,page,offset);
	}

	/* If there is a "group" key in a section it means that it gets the
	 * rest of it's setting from the groupname listed.  This reduces
	 * redundant keys all throughout the file...
	 */
	bind_keys(G_OBJECT(widget), cfgfile, section, keys, num_keys);
	g_strfreev(keys);

	/* If this widget has the "choices" key (combobox)
	 */
	if (cfg_read_string(cfgfile,section,"choices",&tmpbuf))
	{
		combo_setup(G_OBJECT(widget),cfgfile,section);
		g_free(tmpbuf);
	}

	if (cfg_read_string(cfgfile,section,"post_functions_with_arg",&tmpbuf))
	{
		run_post_functions_with_arg(tmpbuf,widget);
		g_free(tmpbuf);
	}
	if (cfg_read_string(cfgfile,section,"post_functions",&tmpbuf))
	{
		run_post_functions(tmpbuf);
		g_free(tmpbuf);
	}
	if (cfg_read_boolean(cfgfile,section,"show_widget",&tmpi))
	{
		if (tmpi)
			gtk_widget_show(widget);
		else
			gtk_widget_hide(widget);
	}
	if (cfg_read_string(cfgfile,section,"set_tab_labels",&tmpbuf))
	{
		if (GTK_IS_NOTEBOOK(widget))
		{
			vector=g_strsplit(tmpbuf,",",-1);
			if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(widget)) == g_strv_length(vector))
			{
				for (int i=0;i<g_strv_length(vector);i++)
				{
					gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(widget),
							gtk_notebook_get_nth_page(GTK_NOTEBOOK(widget),i),
							vector[i]);
				}
			}
			g_strfreev(vector);
		}
		g_free(tmpbuf);
	}
	g_free(section);
	MTXDBG(TABLOADER,_("Leaving"));
	EXIT();
	return;
}
Beispiel #12
0
partition_map_header *
create_partition_map(char *name, partition_map_header *oldmap, int oflag)
{
    MEDIA m;
    partition_map_header * map;
    DPME *data;
    unsigned long default_number;
    unsigned long number;
    long size;
    unsigned long multiple;

    m = open_pathname_as_media(name, oflag);
    if (m == 0) {
	error(errno, "can't open file '%s' for %sing", name,
		(oflag == O_RDONLY)?"read":"writ");
	return NULL;
    }

    map = (partition_map_header *) malloc(sizeof(partition_map_header));
    if (map == NULL) {
	error(errno, "can't allocate memory for open partition map");
	close_media(m);
	return NULL;
    }
    map->name = name;
    map->writable = (oflag == O_RDONLY)?0:1;
    map->changed = 1;
    map->disk_order = NULL;
    map->base_order = NULL;

    if (oldmap != NULL) {
	size = oldmap->physical_block;
    } else {
	size = media_granularity(m);
    }
    m = open_deblock_media(PBLOCK_SIZE, m);
    map->m = m;
    if (interactive) {
	printf("A physical block is %ld bytes: ", size);
	flush_to_newline(0);
	get_number_argument("what should be the physical block size? ",
		&size, size);
	size = (size / PBLOCK_SIZE) * PBLOCK_SIZE;
	if (size < PBLOCK_SIZE) {
	    size = PBLOCK_SIZE;
	}
    }
    if (map->physical_block > MAXIOSIZE) {
	map->physical_block = MAXIOSIZE;
    }
    map->physical_block = size;
    // printf("block size is %d\n", map->physical_block);

    if (oldmap != NULL) {
	size = oldmap->logical_block;
    } else {
	size = PBLOCK_SIZE;
    }
    if (interactive) {
	printf("A logical block is %ld bytes: ", size);
	flush_to_newline(0);
	get_number_argument("what should be the logical block size? ",
		&size, size);
	size = (size / PBLOCK_SIZE) * PBLOCK_SIZE;
	if (size < PBLOCK_SIZE) {
	    size = PBLOCK_SIZE;
	}
    }
#if 0
    if (size > map->physical_block) {
	size = map->physical_block;
    }
#endif
    map->logical_block = size;

    map->blocks_in_map = 0;
    map->maximum_in_map = -1;

    number = compute_device_size(map, oldmap);
    if (interactive) {
	printf("size of 'device' is %lu blocks (%d byte blocks): ",
		number, map->logical_block);
	default_number = number;
	flush_to_newline(0);
	do {
	    if (get_number_argument("what should be the size? ", 
		    (long *)&number, default_number) == 0) {
		printf("Not a number\n");
		flush_to_newline(1);
		number = 0;
	    } else {
		multiple = get_multiplier(map->logical_block);
		if (multiple == 0) {
		    printf("Bad multiplier\n");
		    number = 0;
		} else if (multiple != 1) {
		    if (0xFFFFFFFF/multiple < number) {
			printf("Number too large\n");
			number = 0;
		    } else {
			number *= multiple;
		    }
		}
	    }
	    default_number = kDefault;
	} while (number == 0);

	if (number < 4) {
	    number = 4;
	}
	printf("new size of 'device' is %lu blocks (%d byte blocks)\n",
		number, map->logical_block);
    }
    map->media_size = number;

    map->misc = (Block0 *) calloc(1, PBLOCK_SIZE);
    if (map->misc == NULL) {
	error(errno, "can't allocate memory for block zero buffer");
    } else {
	// got it!
	coerce_block0(map);
	sync_device_size(map);
	
	data = (DPME *) calloc(1, PBLOCK_SIZE);
	if (data == NULL) {
	    error(errno, "can't allocate memory for disk buffers");
	} else {
	    // set data into entry
	    data->dpme_signature = DPME_SIGNATURE;
	    data->dpme_map_entries = 1;
	    data->dpme_pblock_start = 1;
	    data->dpme_pblocks = map->media_size - 1;
	    strncpy(data->dpme_name, kFreeName, DPISTRLEN);
	    strncpy(data->dpme_type, kFreeType, DPISTRLEN);
	    data->dpme_lblock_start = 0;
	    data->dpme_lblocks = data->dpme_pblocks;
	    dpme_writable_set(data, 1);
	    dpme_readable_set(data, 1);
	    dpme_bootable_set(data, 0);
	    dpme_in_use_set(data, 0);
	    dpme_allocated_set(data, 0);
	    dpme_valid_set(data, 1);

	    if (add_data_to_map(data, 1, map) == 0) {
		free(data);
	    } else {
		return map;
	    }
	}
    }
    close_partition_map(map);
    return NULL;
}
Beispiel #13
0
	int32_t CharStats::get_primary_stat() const
	{
		Equipstat::Id primary = job.get_primary(weapontype);
		return static_cast<int32_t>(get_multiplier() * get_total(primary));
	}