void float_string(float n, char *res, int afterpoint) {
	int ipart = (int) n;
	float fpart = n - (float) ipart;
	
	int i = int_string(ipart, res, 0);
	
	if (afterpoint != 0) {
		res[i] = '.';
		fpart = fpart * pow(10, afterpoint); 
		int_string((int)fpart, res + i + 1, afterpoint);
	}
}
 static string int_string(int n) {
     if(n >= 1000000000)   return int_string(n / 1000000000) + " Billion" + int_string(n - 1000000000 * (n / 1000000000));
     else if(n >= 1000000) return int_string(n / 1000000) + " Million" + int_string(n - 1000000 * (n / 1000000));
     else if(n >= 1000)    return int_string(n / 1000) + " Thousand" + int_string(n - 1000 * (n / 1000));
     else if(n >= 100)     return int_string(n / 100) + " Hundred" + int_string(n - 100 * (n / 100));
     else if(n >= 20)      return string(" ") + below_100[n / 10 - 2] + int_string(n - 10 * (n / 10));
     else if(n >= 1)       return string(" ") + below_20[n - 1];
     else return "";
 }
Example #3
0
static void
mi_inferior_exit (struct inferior *inf)
{
  struct mi_interp *mi = top_level_interpreter_data ();

  target_terminal_ours ();
  if (inf->has_exit_code)
    fprintf_unfiltered (mi->event_channel,
			"thread-group-exited,id=\"i%d\",exit-code=\"%s\"",
			inf->num, int_string (inf->exit_code, 8, 0, 0, 1));
  else
    fprintf_unfiltered (mi->event_channel,
			"thread-group-exited,id=\"i%d\"", inf->num);

  gdb_flush (mi->event_channel);  
}
 static string numberToWords(int n) {
     if(n == 0) return "Zero";
     else return int_string(n).substr(1);
 }
Example #5
0
/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */
SDL_bool
SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
                                int *seconds, int *percent)
{
    SDL_bool need_details = SDL_FALSE;
    int ac_status = 0;
    int battery_status = 0;
    int battery_flag = 0;
    int battery_percent = 0;
    int battery_time = 0;
    const int fd = open(proc_apm_path, O_RDONLY);
    char buf[128];
    char *ptr = &buf[0];
    char *str = NULL;
    ssize_t br;

    if (fd == -1) {
        return SDL_FALSE;       /* can't use this interface. */
    }

    br = read(fd, buf, sizeof (buf) - 1);
    close(fd);

    if (br < 0) {
        return SDL_FALSE;
    }

    buf[br] = '\0';             /* null-terminate the string. */
    if (!next_string(&ptr, &str)) {     /* driver version */
        return SDL_FALSE;
    }
    if (!next_string(&ptr, &str)) {     /* BIOS version */
        return SDL_FALSE;
    }
    if (!next_string(&ptr, &str)) {     /* APM flags */
        return SDL_FALSE;
    }

    if (!next_string(&ptr, &str)) {     /* AC line status */
        return SDL_FALSE;
    } else if (!int_string(str, &ac_status)) {
        return SDL_FALSE;
    }

    if (!next_string(&ptr, &str)) {     /* battery status */
        return SDL_FALSE;
    } else if (!int_string(str, &battery_status)) {
        return SDL_FALSE;
    }
    if (!next_string(&ptr, &str)) {     /* battery flag */
        return SDL_FALSE;
    } else if (!int_string(str, &battery_flag)) {
        return SDL_FALSE;
    }
    if (!next_string(&ptr, &str)) {     /* remaining battery life percent */
        return SDL_FALSE;
    }
    if (str[strlen(str) - 1] == '%') {
        str[strlen(str) - 1] = '\0';
    }
    if (!int_string(str, &battery_percent)) {
        return SDL_FALSE;
    }

    if (!next_string(&ptr, &str)) {     /* remaining battery life time */
        return SDL_FALSE;
    } else if (!int_string(str, &battery_time)) {
        return SDL_FALSE;
    }

    if (!next_string(&ptr, &str)) {     /* remaining battery life time units */
        return SDL_FALSE;
    } else if (strcmp(str, "min") == 0) {
        battery_time *= 60;
    }

    if (battery_flag == 0xFF) { /* unknown state */
        *state = SDL_POWERSTATE_UNKNOWN;
    } else if (battery_flag & (1 << 7)) {       /* no battery */
        *state = SDL_POWERSTATE_NO_BATTERY;
    } else if (battery_flag & (1 << 3)) {       /* charging */
        *state = SDL_POWERSTATE_CHARGING;
        need_details = SDL_TRUE;
    } else if (ac_status == 1) {
        *state = SDL_POWERSTATE_CHARGED;        /* on AC, not charging. */
        need_details = SDL_TRUE;
    } else {
        *state = SDL_POWERSTATE_ON_BATTERY;
        need_details = SDL_TRUE;
    }

    *percent = -1;
    *seconds = -1;
    if (need_details) {
        const int pct = battery_percent;
        const int secs = battery_time;

        if (pct >= 0) {         /* -1 == unknown */
            *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
        }
        if (secs >= 0) {        /* -1 == unknown */
            *seconds = secs;
        }
    }

    return SDL_TRUE;
}
Example #6
0
void
ada_print_type (struct type *type0, const char *varstring,
                struct ui_file *stream, int show, int level,
                const struct type_print_options *flags)
{
    struct type *type = ada_check_typedef (ada_get_base_type (type0));
    char *type_name = decoded_type_name (type0);
    int is_var_decl = (varstring != NULL && varstring[0] != '\0');

    if (type == NULL)
    {
        if (is_var_decl)
            fprintf_filtered (stream, "%.*s: ",
                              ada_name_prefix_len (varstring), varstring);
        fprintf_filtered (stream, "<null type?>");
        return;
    }

    if (show > 0)
        type = ada_check_typedef (type);

    if (is_var_decl && TYPE_CODE (type) != TYPE_CODE_FUNC)
        fprintf_filtered (stream, "%.*s: ",
                          ada_name_prefix_len (varstring), varstring);

    if (type_name != NULL && show <= 0 && !ada_is_aligner_type (type))
    {
        fprintf_filtered (stream, "%.*s",
                          ada_name_prefix_len (type_name), type_name);
        return;
    }

    if (ada_is_aligner_type (type))
        ada_print_type (ada_aligned_type (type), "", stream, show, level, flags);
    else if (ada_is_constrained_packed_array_type (type)
             && TYPE_CODE (type) != TYPE_CODE_PTR)
        print_array_type (type, stream, show, level, flags);
    else
        switch (TYPE_CODE (type))
        {
        default:
            fprintf_filtered (stream, "<");
            c_print_type (type, "", stream, show, level, flags);
            fprintf_filtered (stream, ">");
            break;
        case TYPE_CODE_PTR:
        case TYPE_CODE_TYPEDEF:
            fprintf_filtered (stream, "access ");
            ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                            flags);
            break;
        case TYPE_CODE_REF:
            fprintf_filtered (stream, "<ref> ");
            ada_print_type (TYPE_TARGET_TYPE (type), "", stream, show, level,
                            flags);
            break;
        case TYPE_CODE_ARRAY:
            print_array_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_BOOL:
            fprintf_filtered (stream, "(false, true)");
            break;
        case TYPE_CODE_INT:
            if (ada_is_fixed_point_type (type))
                print_fixed_point_type (type, stream);
            else
            {
                const char *name = ada_type_name (type);

                if (!ada_is_range_type_name (name))
                    fprintf_filtered (stream, _("<%d-byte integer>"),
                                      TYPE_LENGTH (type));
                else
                {
                    fprintf_filtered (stream, "range ");
                    print_range_type (type, stream);
                }
            }
            break;
        case TYPE_CODE_RANGE:
            if (ada_is_fixed_point_type (type))
                print_fixed_point_type (type, stream);
            else if (ada_is_modular_type (type))
                fprintf_filtered (stream, "mod %s",
                                  int_string (ada_modulus (type), 10, 0, 0, 1));
            else
            {
                fprintf_filtered (stream, "range ");
                print_range (type, stream);
            }
            break;
        case TYPE_CODE_FLT:
            fprintf_filtered (stream, _("<%d-byte float>"), TYPE_LENGTH (type));
            break;
        case TYPE_CODE_ENUM:
            if (show < 0)
                fprintf_filtered (stream, "(...)");
            else
                print_enum_type (type, stream);
            break;
        case TYPE_CODE_STRUCT:
            if (ada_is_array_descriptor_type (type))
                print_array_type (type, stream, show, level, flags);
            else if (ada_is_bogus_array_descriptor (type))
                fprintf_filtered (stream,
                                  _("array (?) of ? (<mal-formed descriptor>)"));
            else
                print_record_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_UNION:
            print_unchecked_union_type (type, stream, show, level, flags);
            break;
        case TYPE_CODE_FUNC:
            print_func_type (type, stream, varstring, flags);
            break;
        }
}
Example #7
0
/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */
bool PowerX11::GetPowerInfo_Linux_proc_apm() {
	bool need_details = false;
	int ac_status = 0;
	int battery_status = 0;
	int battery_flag = 0;
	int battery_percent = 0;
	int battery_time = 0;
	FileAccessRef fd = FileAccess::open(proc_apm_path, FileAccess::READ);
	char buf[128];
	char *ptr = &buf[0];
	char *str = NULL;
	ssize_t br;

	if (!fd) {
		return false; /* can't use this interface. */
	}

	br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), sizeof(buf) - 1);
	fd->close();

	if (br < 0) {
		return false;
	}

	buf[br] = '\0'; /* null-terminate the string. */
	if (!next_string(&ptr, &str)) { /* driver version */
		return false;
	}
	if (!next_string(&ptr, &str)) { /* BIOS version */
		return false;
	}
	if (!next_string(&ptr, &str)) { /* APM flags */
		return false;
	}

	if (!next_string(&ptr, &str)) { /* AC line status */
		return false;
	} else if (!int_string(str, &ac_status)) {
		return false;
	}

	if (!next_string(&ptr, &str)) { /* battery status */
		return false;
	} else if (!int_string(str, &battery_status)) {
		return false;
	}
	if (!next_string(&ptr, &str)) { /* battery flag */
		return false;
	} else if (!int_string(str, &battery_flag)) {
		return false;
	}
	if (!next_string(&ptr, &str)) { /* remaining battery life percent */
		return false;
	}
	String sstr = str;
	if (sstr[sstr.length() - 1] == '%') {
		sstr[sstr.length() - 1] = '\0';
	}
	if (!int_string(str, &battery_percent)) {
		return false;
	}

	if (!next_string(&ptr, &str)) { /* remaining battery life time */
		return false;
	} else if (!int_string(str, &battery_time)) {
		return false;
	}

	if (!next_string(&ptr, &str)) { /* remaining battery life time units */
		return false;
	} else if (String(str) == "min") {
		battery_time *= 60;
	}

	if (battery_flag == 0xFF) { /* unknown state */
		this->power_state = OS::POWERSTATE_UNKNOWN;
	} else if (battery_flag & (1 << 7)) { /* no battery */
		this->power_state = OS::POWERSTATE_NO_BATTERY;
	} else if (battery_flag & (1 << 3)) { /* charging */
		this->power_state = OS::POWERSTATE_CHARGING;
		need_details = true;
	} else if (ac_status == 1) {
		this->power_state = OS::POWERSTATE_CHARGED; /* on AC, not charging. */
		need_details = true;
	} else {
		this->power_state = OS::POWERSTATE_ON_BATTERY;
		need_details = true;
	}

	this->percent_left = -1;
	this->nsecs_left = -1;
	if (need_details) {
		const int pct = battery_percent;
		const int secs = battery_time;

		if (pct >= 0) { /* -1 == unknown */
			this->percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
		}
		if (secs >= 0) { /* -1 == unknown */
			this->nsecs_left = secs;
		}
	}

	return true;
}