コード例 #1
0
void GameOverState::draw(CL_GraphicContext& gc)
{
	MenuState::draw(gc);

	if(_is_highscore)
	{
		std::string new_score = format_number(to_string(_p_common_resources -> highscore));
		std::string old_score = format_number(to_string(_p_common_resources -> old_highscore));

		int new_score_real_x = _score1_x -
			_p_common_resources -> main_font.get_text_size(gc, new_score).width / 2;

		int old_score_real_x = _score2_x - 
			_p_common_resources -> main_font.get_text_size(gc, old_score).width / 2;

		_p_common_resources -> main_font.draw_text(gc, new_score_real_x, _score1_y, new_score);
		_p_common_resources -> main_font.draw_text(gc, old_score_real_x, _score2_y, old_score);
	}
	else
	{
		std::string current_score = format_number(to_string(_p_common_resources -> player1.get_score()));
		std::string highscore = format_number(to_string(_p_common_resources -> highscore));

		int score1_real_x = _score1_x -
			_p_common_resources -> main_font.get_text_size(gc, current_score).width / 2;

		int score2_real_x = _score2_x - 
			_p_common_resources -> main_font.get_text_size(gc, highscore).width / 2;

		_p_common_resources -> main_font.draw_text(gc, score1_real_x, _score1_y, current_score);
		_p_common_resources -> main_font.draw_text(gc, score2_real_x, _score2_y, highscore);
	}
}
コード例 #2
0
ファイル: format.c プロジェクト: bertrandrustle/Eve
void format_number(string s, u64 x, int base, int pad)
{
    if ((x > 0) || (pad > 0)) {
        format_number(s, x/base, base, pad - 1);
        string_insert(s, hex_digits[x%base]);
    }
}
コード例 #3
0
/* Write an hexadecimal into a buffer, isCap is true for capital alphas.
 * Assumes bufsize > 2 */
static void
format_hex(char *buffer, size_t buffsize, uint64_t value, int isCap)
{
    const char *digits = isCap ? "0123456789ABCDEF" : "0123456789abcdef";

    format_number(buffer, buffsize, value, 16, digits);
}
コード例 #4
0
ファイル: nfdump.c プロジェクト: gitpan/libnf
static void PrintSummary(stat_record_t *stat_record, int plain_numbers, int csv_output) {
static double	duration;
uint64_t	bps, pps, bpp;
char 		byte_str[NUMBER_STRING_SIZE], packet_str[NUMBER_STRING_SIZE];
char 		bps_str[NUMBER_STRING_SIZE], pps_str[NUMBER_STRING_SIZE], bpp_str[NUMBER_STRING_SIZE];

	bps = pps = bpp = 0;
	if ( stat_record->last_seen ) {
		duration = stat_record->last_seen - stat_record->first_seen;
		duration += ((double)stat_record->msec_last - (double)stat_record->msec_first) / 1000.0;
	} else {
		// no flows to report
		duration = 0;
	}
	if ( duration > 0 && stat_record->last_seen > 0 ) {
		bps = ( stat_record->numbytes << 3 ) / duration;	// bits per second. ( >> 3 ) -> * 8 to convert octets into bits
		pps = stat_record->numpackets / duration;			// packets per second
		bpp = stat_record->numpackets ? stat_record->numbytes / stat_record->numpackets : 0;    // Bytes per Packet
	}
	if ( csv_output ) {
		printf("Summary\n");
		printf("flows,bytes,packets,avg_bps,avg_pps,avg_bpp\n");
		printf("%llu,%llu,%llu,%llu,%llu,%llu\n",
			(long long unsigned)stat_record->numflows, (long long unsigned)stat_record->numbytes, 
			(long long unsigned)stat_record->numpackets, (long long unsigned)bps, 
			(long long unsigned)pps, (long long unsigned)bpp );
	} else if ( plain_numbers ) {
		printf("Summary: total flows: %llu, total bytes: %llu, total packets: %llu, avg bps: %llu, avg pps: %llu, avg bpp: %llu\n",
			(long long unsigned)stat_record->numflows, (long long unsigned)stat_record->numbytes, 
			(long long unsigned)stat_record->numpackets, (long long unsigned)bps, 
			(long long unsigned)pps, (long long unsigned)bpp );
	} else {
		format_number(stat_record->numbytes, byte_str, DONT_SCALE_NUMBER, VAR_LENGTH);
		format_number(stat_record->numpackets, packet_str, DONT_SCALE_NUMBER, VAR_LENGTH);
		format_number(bps, bps_str, DONT_SCALE_NUMBER, VAR_LENGTH);
		format_number(pps, pps_str, DONT_SCALE_NUMBER, VAR_LENGTH);
		format_number(bpp, bpp_str, DONT_SCALE_NUMBER, VAR_LENGTH);
		printf("Summary: total flows: %llu, total bytes: %s, total packets: %s, avg bps: %s, avg pps: %s, avg bpp: %s\n",
		(unsigned long long)stat_record->numflows, byte_str, packet_str, bps_str, pps_str, bpp_str );
	}

} // End of PrintSummary
コード例 #5
0
ファイル: value-format.c プロジェクト: svn2github/gwyddion
static void
append_number_to_gstring(GwyValueFormat *format,
                         GString *str,
                         gdouble value)
{
    format_number(format, str, value);

    ValueFormat *priv = format->priv;
    if (priv->style == GWY_VALUE_FORMAT_PANGO)
        fix_utf8_minus(str);
}
コード例 #6
0
/* Write an integer (octal or decimal) into a buffer, assumes buffsize > 2 */
static void
format_integer(char *buffer, size_t buffsize, uint64_t value, int base, int isSigned)
{
    if (isSigned && (int64_t)value < 0) {
        buffer[0] = '-';
        buffer += 1;
        buffsize -= 1;
        value = (uint64_t)(-(int64_t)value);
    }

    format_number(buffer, buffsize, value, base, "0123456789");
}
コード例 #7
0
ファイル: format.cpp プロジェクト: tica/TimbOS
void format_number( output_func_t output, void* ptr, unsigned int number )
{
	static char digit_chars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
	
	int digit = number % 10;
	int remainder = number / 10;

	if( remainder > 0 )
	{
		format_number( output, ptr, remainder );
	}

	output( digit_chars[digit], ptr );
}
コード例 #8
0
/*
 * Format a basic 512-byte "v7tar" header.
 *
 * Returns -1 if format failed (due to field overflow).
 * Note that this always formats as much of the header as possible.
 * If "strict" is set to zero, it will extend numeric fields as
 * necessary (overwriting terminators or using base-256 extensions).
 *
 */
static int
format_header_v7tar(struct archive_write *a, char h[512],
    struct archive_entry *entry, int strict,
    struct archive_string_conv *sconv)
{
	unsigned int checksum;
	int i, r, ret;
	size_t copy_length;
	const char *p, *pp;
	int mytartype;

	ret = 0;
	mytartype = -1;
	/*
	 * The "template header" already includes the "v7tar"
	 * signature, various end-of-field markers and other required
	 * elements.
	 */
	memcpy(h, &template_header, 512);

	/*
	 * Because the block is already null-filled, and strings
	 * are allowed to exactly fill their destination (without null),
	 * I use memcpy(dest, src, strlen()) here a lot to copy strings.
	 */
	r = archive_entry_pathname_l(entry, &pp, &copy_length, sconv);
	if (r != 0) {
		if (errno == ENOMEM) {
			archive_set_error(&a->archive, ENOMEM,
			    "Can't allocate memory for Pathname");
			return (ARCHIVE_FATAL);
		}
		archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
		    "Can't translate pathname '%s' to %s",
		    pp, archive_string_conversion_charset_name(sconv));
		ret = ARCHIVE_WARN;
	}
	if (strict && copy_length < V7TAR_name_size)
		memcpy(h + V7TAR_name_offset, pp, copy_length);
	else if (!strict && copy_length <= V7TAR_name_size)
		memcpy(h + V7TAR_name_offset, pp, copy_length);
	else {
		/* Prefix is too long. */
		archive_set_error(&a->archive, ENAMETOOLONG,
		    "Pathname too long");
		ret = ARCHIVE_FAILED;
	}

	r = archive_entry_hardlink_l(entry, &p, &copy_length, sconv);
	if (r != 0) {
		if (errno == ENOMEM) {
			archive_set_error(&a->archive, ENOMEM,
			    "Can't allocate memory for Linkname");
			return (ARCHIVE_FATAL);
		}
		archive_set_error(&a->archive,
		    ARCHIVE_ERRNO_FILE_FORMAT,
		    "Can't translate linkname '%s' to %s",
		    p, archive_string_conversion_charset_name(sconv));
		ret = ARCHIVE_WARN;
	}
	if (copy_length > 0)
		mytartype = '1';
	else {
		r = archive_entry_symlink_l(entry, &p, &copy_length, sconv);
		if (r != 0) {
			if (errno == ENOMEM) {
				archive_set_error(&a->archive, ENOMEM,
				    "Can't allocate memory for Linkname");
				return (ARCHIVE_FATAL);
			}
			archive_set_error(&a->archive,
			    ARCHIVE_ERRNO_FILE_FORMAT,
			    "Can't translate linkname '%s' to %s",
			    p, archive_string_conversion_charset_name(sconv));
			ret = ARCHIVE_WARN;
		}
	}
	if (copy_length > 0) {
		if (copy_length >= V7TAR_linkname_size) {
			archive_set_error(&a->archive, ENAMETOOLONG,
			    "Link contents too long");
			ret = ARCHIVE_FAILED;
			copy_length = V7TAR_linkname_size;
		}
		memcpy(h + V7TAR_linkname_offset, p, copy_length);
	}

	if (format_number(archive_entry_mode(entry) & 07777,
	    h + V7TAR_mode_offset, V7TAR_mode_size,
	    V7TAR_mode_max_size, strict)) {
		archive_set_error(&a->archive, ERANGE,
		    "Numeric mode too large");
		ret = ARCHIVE_FAILED;
	}

	if (format_number(archive_entry_uid(entry),
	    h + V7TAR_uid_offset, V7TAR_uid_size, V7TAR_uid_max_size, strict)) {
		archive_set_error(&a->archive, ERANGE,
		    "Numeric user ID too large");
		ret = ARCHIVE_FAILED;
	}

	if (format_number(archive_entry_gid(entry),
	    h + V7TAR_gid_offset, V7TAR_gid_size, V7TAR_gid_max_size, strict)) {
		archive_set_error(&a->archive, ERANGE,
		    "Numeric group ID too large");
		ret = ARCHIVE_FAILED;
	}

	if (format_number(archive_entry_size(entry),
	    h + V7TAR_size_offset, V7TAR_size_size,
	    V7TAR_size_max_size, strict)) {
		archive_set_error(&a->archive, ERANGE,
		    "File size out of range");
		ret = ARCHIVE_FAILED;
	}

	if (format_number(archive_entry_mtime(entry),
	    h + V7TAR_mtime_offset, V7TAR_mtime_size,
	    V7TAR_mtime_max_size, strict)) {
		archive_set_error(&a->archive, ERANGE,
		    "File modification time too large");
		ret = ARCHIVE_FAILED;
	}

	if (mytartype >= 0) {
		h[V7TAR_typeflag_offset] = mytartype;
	} else {
		switch (archive_entry_filetype(entry)) {
		case AE_IFREG: case AE_IFDIR:
			break;
		case AE_IFLNK:
			h[V7TAR_typeflag_offset] = '2';
			break;
		case AE_IFCHR:
			archive_set_error(&a->archive,
			    ARCHIVE_ERRNO_FILE_FORMAT,
			    "tar format cannot archive character device");
			return (ARCHIVE_FAILED);
		case AE_IFBLK:
			archive_set_error(&a->archive,
			    ARCHIVE_ERRNO_FILE_FORMAT,
			    "tar format cannot archive block device");
			return (ARCHIVE_FAILED);
		case AE_IFIFO:
			archive_set_error(&a->archive,
			    ARCHIVE_ERRNO_FILE_FORMAT,
			    "tar format cannot archive fifo");
			return (ARCHIVE_FAILED);
		case AE_IFSOCK:
			archive_set_error(&a->archive,
			    ARCHIVE_ERRNO_FILE_FORMAT,
			    "tar format cannot archive socket");
			return (ARCHIVE_FAILED);
		default:
			archive_set_error(&a->archive,
			    ARCHIVE_ERRNO_FILE_FORMAT,
			    "tar format cannot archive this (mode=0%lo)",
			    (unsigned long)archive_entry_mode(entry));
			ret = ARCHIVE_FAILED;
		}
	}

	checksum = 0;
	for (i = 0; i < 512; i++)
		checksum += 255 & (unsigned int)h[i];
	format_octal(checksum, h + V7TAR_checksum_offset, 6);
	/* Can't be pre-set in the template. */
	h[V7TAR_checksum_offset + 6] = '\0';
	return (ret);
}
コード例 #9
0
ファイル: ViewProjects.cpp プロジェクト: DanAurea/boinc
wxInt32 CViewProjects::FormatResourceShare(double share, double share_pct, wxString& strBuffer) const {
    strBuffer.Printf(wxT("%s (%s%%)"), format_number(share, 0), format_number(share_pct, 2));
        
    return 0;
}
コード例 #10
0
ファイル: format.c プロジェクト: bertrandrustle/Eve
void vbprintf(string s, string fmt, va_list ap)
{
    character i;
    int state = 0;
    int base = 0;
    int pad;
    int count = 0;

    string_foreach(fmt, i) {
        switch (state){
        case 2:
            for (int j = 0; j < count; j++)
                string_insert(s, i);
            state = 0;
            break;

        case 0:
            base = 10;
            pad = 0;
            if (i == '%') state = 3;
            else string_insert(s, i);
            break;

        case 1:
            if ((i >= '0') && (i <= '9')) {
                pad = pad * 10 + digit_of(i);
                break;
            } else {
                state = 3;
            }

        case 3:
            switch (i) {
            case '0':
                state = 1;
                break;

            case '%':
                string_insert(s, '\%');
                break;

            case 't':
                print_time(s, va_arg(ap, ticks));
                break;

            case 'b':
                string_concat(s, (va_arg(ap, string)));
                break;

            case 'n':
                count = va_arg(ap, unsigned int);
                state = 2;
                break;

            case 'c':
                string_insert(s, va_arg(ap, int));
                break;

            case 's':
                {
                    char *c = va_arg(ap, char *);
                    if (!c) c = (char *)"(null)";
                    int len = cstring_length(c);
                    for (int i =0 ; i < pad; i++)
                        string_insert(s, ' ');
                    pad = 0;
                    for (; *c; c++)
                        string_insert(s, *c);
                }
                break;

            case 'S':
                {
                    unsigned int x = va_arg(ap, unsigned int);
                    for (int i =0 ; i < x; i++) string_insert(s, ' ');
                    break;
                }

            case 'p':
                pad = 16;
                unsigned long x = va_arg(ap, unsigned long);
                format_number(s, x, 16, pad?pad:1);
                break;

            case 'l':
                pad = 0;
                unsigned long z = va_arg(ap, unsigned long);
                format_number(s, z, 10, pad?pad:1);
                break;

            case 'x':
                base=16;

            case 'o':
                if (base == 10) base=8;
            case 'u':
                {
                    unsigned int x = va_arg(ap, unsigned int);
                    format_number(s, x, base, pad?pad:1);
                    break;
                }

             // xxx - layer violation..meh
             // also generalize string pad support
            case 'v':
                if (pad) {
                    // xxx  transient or resizable stack head
                    buffer b = allocate_string(s->h);
                    print_value(b, va_arg(ap, void *));
                    // xxx utf token length
                    for (int i =0 ; i < (pad-buffer_length(b)); i++) string_insert(s, ' ');
                    buffer_append(s, bref(b, 0), buffer_length(b));
                    pad = 0;
                    state = 0;
                } else print_value(s, va_arg(ap, void *));
                break;

            case 'r':
                if (pad) {
                    // xxx  transient or resizable stack head
                    buffer b = allocate_string(s->h);
                    print_value_raw(b, va_arg(ap, void *));
                    // xxx utf token length
                    for (int i =0 ; i < (pad-buffer_length(b)); i++) string_insert(s, ' ');
                    buffer_append(s, bref(b, 0), buffer_length(b));
                    pad = 0;
                    state = 0;
                } else print_value_raw(s, va_arg(ap, void *));
                break;

            case 'V':
                print_value_vector(s, va_arg(ap, void *));
                break;

            case 'X':
                // xxx - utf8 will break this
                 {
                  buffer xx = va_arg(ap, buffer);
                  string_foreach(xx, i){
                     print_byte(s, i);
                  }
                 }
                break;

            case 'd': case 'i':
                {
                    int x = va_arg(ap, int);
                    if (x <0){
                        string_insert(s, '-');
                        x = -x;
                    }
                    format_number(s, (unsigned int)x, base, pad?pad:1);
                    break;
                }
            default:
                break;
            }
            // badness
            if (state == 3)
                state = 0;
            break;
        }
    }
コード例 #11
0
void CSimpleProjectPanel::UpdateInterface() {
    int n, count = -1;
    bool b_needMenuRebuild = false;
    wxString str = wxEmptyString;
    wxString projName = wxEmptyString;
    CMainDocument* pDoc = wxGetApp().GetDocument();

    wxASSERT(pDoc);

    // Should we display the synchronize button instead of the
    //   attach to project button?
    if ( pDoc->IsConnected() ) {
        CC_STATUS       status;
        int             is_acct_mgr_detected = 0;

        pDoc->GetCoreClientStatus(status);

        if (pDoc->m_iAcct_mgr_info_rpc_result == 0) {
            // We use an integer rather than a bool to force action the first time
            is_acct_mgr_detected = pDoc->ami.acct_mgr_url.size() ? 1 : 0;
            
            if ((m_UsingAccountManager != is_acct_mgr_detected) || (!m_TaskAddProjectButton->IsEnabled())) {
                m_UsingAccountManager = is_acct_mgr_detected;
                if (is_acct_mgr_detected) {
                    m_TaskAddProjectButton->SetLabel(m_sSynchronizeString);
                    m_TaskAddProjectButton->Enable();
                    m_TaskAddProjectButton->SetToolTip(m_sSynchronizeToolTip);
                } else {
                    m_TaskAddProjectButton->SetLabel(m_sAddProjectString);
                    if (!status.disallow_attach) {
                        m_TaskAddProjectButton->Enable();
                        m_TaskAddProjectButton->SetToolTip(m_sAddProjectToolTip);
                   }
                }
                this->Layout();
            }
        } else {
            m_TaskAddProjectButton->Disable();
        }

        UpdateProjectList();
        
        count = m_ProjectSelectionCtrl->GetCount();
    }
    if (count > 0) {
        n = m_ProjectSelectionCtrl->GetSelection();
        if ((n < 0) || (n > count -1)) {
            m_ProjectSelectionCtrl->SetSelection(0);
            n = 0;
        }
        
        // Check to see if we need to rebuild the menu
        char* ctrl_url = ((ProjectSelectionData*)m_ProjectSelectionCtrl->GetClientData(n))->project_url;
        if (strcmp(m_CurrentSelectedProjectURL, ctrl_url)) {
            b_needMenuRebuild = true;
            strncpy(m_CurrentSelectedProjectURL, ctrl_url, sizeof(m_CurrentSelectedProjectURL));
        }
        
        PROJECT* project = pDoc->state.lookup_project(ctrl_url);
        if ( project != NULL && project->last_rpc_time > m_Project_last_rpc_time ) {
            b_needMenuRebuild = true;
            m_Project_last_rpc_time = project->last_rpc_time;
        }
        
        if (b_needMenuRebuild) {
            m_ProjectWebSitesButton->RebuildMenu();
        }

        m_ProjectWebSitesButton->Enable();
        m_ProjectCommandsButton->Enable();
        
        if (m_fDisplayedCredit != project->user_total_credit) {
            str.Printf(wxT("%s: %s"),
                m_sTotalWorkDoneString.c_str(),
                format_number(project->user_total_credit, 0)
            );
            UpdateStaticText(&m_TotalCreditValue, str);
            m_TotalCreditValue->SetName(str);   // For accessibility on Windows
        }
        projName = m_ProjectSelectionCtrl->GetStringSelection();
        str.Printf(_("Pop up a menu of web sites for project %s"), projName.c_str());
        m_ProjectWebSitesButton->SetToolTip(str);
        str.Printf(_("Pop up a menu of commands to apply to project %s"), projName.c_str());
        m_ProjectCommandsButton->SetToolTip(str);
    } else {
        m_ProjectWebSitesButton->Disable();
        m_ProjectCommandsButton->Disable();
        m_CurrentSelectedProjectURL[0] = '\0';
        m_fDisplayedCredit = -1.0;
        UpdateStaticText(&m_TotalCreditValue, wxEmptyString);
        m_TotalCreditValue->SetName(wxEmptyString);   // For accessibility on Windows
        m_ProjectWebSitesButton->SetToolTip(wxEmptyString);
        m_ProjectCommandsButton->SetToolTip(wxEmptyString);
    }
}
コード例 #12
0
/*
 * Format a basic 512-byte "ustar" header.
 *
 * Returns -1 if format failed (due to field overflow).
 * Note that this always formats as much of the header as possible.
 * If "strict" is set to zero, it will extend numeric fields as
 * necessary (overwriting terminators or using base-256 extensions).
 *
 * This is exported so that other 'tar' formats can use it.
 */
int
__archive_write_format_header_ustar(struct archive_write *a, char h[512],
    struct archive_entry *entry, int tartype, int strict)
{
	unsigned int checksum;
	int i, ret;
	size_t copy_length;
	const char *p, *pp;
	int mytartype;

	ret = 0;
	mytartype = -1;
	/*
	 * The "template header" already includes the "ustar"
	 * signature, various end-of-field markers and other required
	 * elements.
	 */
	memcpy(h, &template_header, 512);

	/*
	 * Because the block is already null-filled, and strings
	 * are allowed to exactly fill their destination (without null),
	 * I use memcpy(dest, src, strlen()) here a lot to copy strings.
	 */

	pp = tk_archive_entry_pathname(entry);
	if (strlen(pp) <= USTAR_name_size)
		memcpy(h + USTAR_name_offset, pp, strlen(pp));
	else {
		/* Store in two pieces, splitting at a '/'. */
		p = strchr(pp + strlen(pp) - USTAR_name_size - 1, '/');
		/*
		 * Look for the next '/' if we chose the first character
		 * as the separator.  (ustar format doesn't permit
		 * an empty prefix.)
		 */
		if (p == pp)
			p = strchr(p + 1, '/');
		/* Fail if the name won't fit. */
		if (!p) {
			/* No separator. */
			tk_archive_set_error(&a->archive, ENAMETOOLONG,
			    "Pathname too long");
			ret = ARCHIVE_FAILED;
		} else if (p[1] == '\0') {
			/*
			 * The only feasible separator is a final '/';
			 * this would result in a non-empty prefix and
			 * an empty name, which POSIX doesn't
			 * explicity forbid, but it just feels wrong.
			 */
			tk_archive_set_error(&a->archive, ENAMETOOLONG,
			    "Pathname too long");
			ret = ARCHIVE_FAILED;
		} else if (p  > pp + USTAR_prefix_size) {
			/* Prefix is too long. */
			tk_archive_set_error(&a->archive, ENAMETOOLONG,
			    "Pathname too long");
			ret = ARCHIVE_FAILED;
		} else {
			/* Copy prefix and remainder to appropriate places */
			memcpy(h + USTAR_prefix_offset, pp, p - pp);
			memcpy(h + USTAR_name_offset, p + 1, pp + strlen(pp) - p - 1);
		}
	}

	p = tk_archive_entry_hardlink(entry);
	if (p != NULL)
		mytartype = '1';
	else
		p = tk_archive_entry_symlink(entry);
	if (p != NULL && p[0] != '\0') {
		copy_length = strlen(p);
		if (copy_length > USTAR_linkname_size) {
			tk_archive_set_error(&a->archive, ENAMETOOLONG,
			    "Link contents too long");
			ret = ARCHIVE_FAILED;
			copy_length = USTAR_linkname_size;
		}
		memcpy(h + USTAR_linkname_offset, p, copy_length);
	}

	p = tk_archive_entry_uname(entry);
	if (p != NULL && p[0] != '\0') {
		copy_length = strlen(p);
		if (copy_length > USTAR_uname_size) {
			tk_archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
			    "Username too long");
			ret = ARCHIVE_FAILED;
			copy_length = USTAR_uname_size;
		}
		memcpy(h + USTAR_uname_offset, p, copy_length);
	}

	p = tk_archive_entry_gname(entry);
	if (p != NULL && p[0] != '\0') {
		copy_length = strlen(p);
		if (strlen(p) > USTAR_gname_size) {
			tk_archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
			    "Group name too long");
			ret = ARCHIVE_FAILED;
			copy_length = USTAR_gname_size;
		}
		memcpy(h + USTAR_gname_offset, p, copy_length);
	}

	if (format_number(tk_archive_entry_mode(entry) & 07777, h + USTAR_mode_offset, USTAR_mode_size, USTAR_mode_max_size, strict)) {
		tk_archive_set_error(&a->archive, ERANGE, "Numeric mode too large");
		ret = ARCHIVE_FAILED;
	}

	if (format_number(tk_archive_entry_uid(entry), h + USTAR_uid_offset, USTAR_uid_size, USTAR_uid_max_size, strict)) {
		tk_archive_set_error(&a->archive, ERANGE, "Numeric user ID too large");
		ret = ARCHIVE_FAILED;
	}

	if (format_number(tk_archive_entry_gid(entry), h + USTAR_gid_offset, USTAR_gid_size, USTAR_gid_max_size, strict)) {
		tk_archive_set_error(&a->archive, ERANGE, "Numeric group ID too large");
		ret = ARCHIVE_FAILED;
	}

	if (format_number(tk_archive_entry_size(entry), h + USTAR_size_offset, USTAR_size_size, USTAR_size_max_size, strict)) {
		tk_archive_set_error(&a->archive, ERANGE, "File size out of range");
		ret = ARCHIVE_FAILED;
	}

	if (format_number(tk_archive_entry_mtime(entry), h + USTAR_mtime_offset, USTAR_mtime_size, USTAR_mtime_max_size, strict)) {
		tk_archive_set_error(&a->archive, ERANGE,
		    "File modification time too large");
		ret = ARCHIVE_FAILED;
	}

	if (tk_archive_entry_filetype(entry) == AE_IFBLK
	    || tk_archive_entry_filetype(entry) == AE_IFCHR) {
		if (format_number(tk_archive_entry_rdevmajor(entry), h + USTAR_rdevmajor_offset,
			USTAR_rdevmajor_size, USTAR_rdevmajor_max_size, strict)) {
			tk_archive_set_error(&a->archive, ERANGE,
			    "Major device number too large");
			ret = ARCHIVE_FAILED;
		}

		if (format_number(tk_archive_entry_rdevminor(entry), h + USTAR_rdevminor_offset,
			USTAR_rdevminor_size, USTAR_rdevminor_max_size, strict)) {
			tk_archive_set_error(&a->archive, ERANGE,
			    "Minor device number too large");
			ret = ARCHIVE_FAILED;
		}
	}

	if (tartype >= 0) {
		h[USTAR_typeflag_offset] = tartype;
	} else if (mytartype >= 0) {
		h[USTAR_typeflag_offset] = mytartype;
	} else {
		switch (tk_archive_entry_filetype(entry)) {
		case AE_IFREG: h[USTAR_typeflag_offset] = '0' ; break;
		case AE_IFLNK: h[USTAR_typeflag_offset] = '2' ; break;
		case AE_IFCHR: h[USTAR_typeflag_offset] = '3' ; break;
		case AE_IFBLK: h[USTAR_typeflag_offset] = '4' ; break;
		case AE_IFDIR: h[USTAR_typeflag_offset] = '5' ; break;
		case AE_IFIFO: h[USTAR_typeflag_offset] = '6' ; break;
		case AE_IFSOCK:
			tk_archive_set_error(&a->archive,
			    ARCHIVE_ERRNO_FILE_FORMAT,
			    "tar format cannot archive socket");
			return (ARCHIVE_FAILED);
		default:
			tk_archive_set_error(&a->archive,
			    ARCHIVE_ERRNO_FILE_FORMAT,
			    "tar format cannot archive this (mode=0%lo)",
			    (unsigned long)tk_archive_entry_mode(entry));
			ret = ARCHIVE_FAILED;
		}
	}

	checksum = 0;
	for (i = 0; i < 512; i++)
		checksum += 255 & (unsigned int)h[i];
	h[USTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */
	/* h[USTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */
	format_octal(checksum, h + USTAR_checksum_offset, 6);
	return (ret);
}
コード例 #13
0
static int
archive_format_gnutar_header(struct archive_write *a, char h[512],
    struct archive_entry *entry, int tartype)
{
	unsigned int checksum;
	int i, ret;
	size_t copy_length;
	const char *p;
	struct gnutar *gnutar;

	gnutar = (struct gnutar *)a->format_data;

	ret = 0;

	/*
	 * The "template header" already includes the signature,
	 * various end-of-field markers, and other required elements.
	 */
	memcpy(h, &template_header, 512);

	/*
	 * Because the block is already null-filled, and strings
	 * are allowed to exactly fill their destination (without null),
	 * I use memcpy(dest, src, strlen()) here a lot to copy strings.
	 */

	if (tartype == 'K' || tartype == 'L') {
		p = archive_entry_pathname(entry);
		copy_length = strlen(p);
	} else {
		p = gnutar->pathname;
		copy_length = gnutar->pathname_length;
	}
	if (copy_length > GNUTAR_name_size)
		copy_length = GNUTAR_name_size;
	memcpy(h + GNUTAR_name_offset, p, copy_length);

	if ((copy_length = gnutar->linkname_length) > 0) {
		if (copy_length > GNUTAR_linkname_size)
			copy_length = GNUTAR_linkname_size;
		memcpy(h + GNUTAR_linkname_offset, gnutar->linkname,
		    copy_length);
	}

	/* TODO: How does GNU tar handle unames longer than GNUTAR_uname_size? */
	if (tartype == 'K' || tartype == 'L') {
		p = archive_entry_uname(entry);
		copy_length = strlen(p);
	} else {
		p = gnutar->uname;
		copy_length = gnutar->uname_length;
	}
	if (copy_length > 0) {
		if (copy_length > GNUTAR_uname_size)
			copy_length = GNUTAR_uname_size;
		memcpy(h + GNUTAR_uname_offset, p, copy_length);
	}

	/* TODO: How does GNU tar handle gnames longer than GNUTAR_gname_size? */
	if (tartype == 'K' || tartype == 'L') {
		p = archive_entry_gname(entry);
		copy_length = strlen(p);
	} else {
		p = gnutar->gname;
		copy_length = gnutar->gname_length;
	}
	if (copy_length > 0) {
		if (strlen(p) > GNUTAR_gname_size)
			copy_length = GNUTAR_gname_size;
		memcpy(h + GNUTAR_gname_offset, p, copy_length);
	}

	/* By truncating the mode here, we ensure it always fits. */
	format_octal(archive_entry_mode(entry) & 07777,
	    h + GNUTAR_mode_offset, GNUTAR_mode_size);

	/* GNU tar supports base-256 here, so should never overflow. */
	if (format_number(archive_entry_uid(entry), h + GNUTAR_uid_offset,
		GNUTAR_uid_size, GNUTAR_uid_max_size)) {
		archive_set_error(&a->archive, ERANGE,
		    "Numeric user ID %jd too large",
		    (intmax_t)archive_entry_uid(entry));
		ret = ARCHIVE_FAILED;
	}

	/* GNU tar supports base-256 here, so should never overflow. */
	if (format_number(archive_entry_gid(entry), h + GNUTAR_gid_offset,
		GNUTAR_gid_size, GNUTAR_gid_max_size)) {
		archive_set_error(&a->archive, ERANGE,
		    "Numeric group ID %jd too large",
		    (intmax_t)archive_entry_gid(entry));
		ret = ARCHIVE_FAILED;
	}

	/* GNU tar supports base-256 here, so should never overflow. */
	if (format_number(archive_entry_size(entry), h + GNUTAR_size_offset,
		GNUTAR_size_size, GNUTAR_size_max_size)) {
		archive_set_error(&a->archive, ERANGE,
		    "File size out of range");
		ret = ARCHIVE_FAILED;
	}

	/* Shouldn't overflow before 2106, since mtime field is 33 bits. */
	format_octal(archive_entry_mtime(entry),
	    h + GNUTAR_mtime_offset, GNUTAR_mtime_size);

	if (archive_entry_filetype(entry) == AE_IFBLK
	    || archive_entry_filetype(entry) == AE_IFCHR) {
		if (format_octal(archive_entry_rdevmajor(entry),
		    h + GNUTAR_rdevmajor_offset,
			GNUTAR_rdevmajor_size)) {
			archive_set_error(&a->archive, ERANGE,
			    "Major device number too large");
			ret = ARCHIVE_FAILED;
		}

		if (format_octal(archive_entry_rdevminor(entry),
		    h + GNUTAR_rdevminor_offset,
			GNUTAR_rdevminor_size)) {
			archive_set_error(&a->archive, ERANGE,
			    "Minor device number too large");
			ret = ARCHIVE_FAILED;
		}
	}

	h[GNUTAR_typeflag_offset] = tartype;

	checksum = 0;
	for (i = 0; i < 512; i++)
		checksum += 255 & (unsigned int)h[i];
	h[GNUTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */
	/* h[GNUTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */
	format_octal(checksum, h + GNUTAR_checksum_offset, 6);
	return (ret);
}
コード例 #14
0
ファイル: ViewProjects.cpp プロジェクト: DanAurea/boinc
static void format_total_credit(double credit, wxString& strBuffer)  {
    strBuffer = format_number(credit, 0);
}
コード例 #15
0
ファイル: num2word.c プロジェクト: 4honor/QConf
void
print_number (unsigned long num)
{
  format_number (num);
  printf ("%lu\t%s\n", num, buffer + bufoff);
}
コード例 #16
0
ファイル: viv_gpu_top.c プロジェクト: lplachno/etna_viv
int main()
{
    struct viv_conn *conn = 0;
    int rv;
    rv = viv_open(VIV_HW_3D, &conn);
    if(rv!=0)
    {
        fprintf(stderr, "Error opening device\n");
        exit(1);
    }
    uint32_t num_profile_counters = viv_get_num_profile_counters();

    /* XXX parameter parsing */
    int samples_per_second = 100;
    bool interactive = true;
    int mode = MODE_ALL;
    //int mode = MODE_SORTED;
    bool color = true;

    uint32_t *counter_data = calloc(num_profile_counters, 4);
    uint32_t *counter_data_last = calloc(num_profile_counters, 4);
    uint64_t *events_per_s = calloc(num_profile_counters, 8);
    struct counter_rec *sorted = calloc(num_profile_counters, sizeof(struct counter_rec));
    /* reset counters and initial values */
    if(viv_read_profile_counters_3d(conn, counter_data_last) != 0)
    {
        fprintf(stderr, "Error querying counters (probably unsupported with this kernel, or not built into libetnaviv)\n");
        exit(1);
    }
    uint32_t begin_time = gettime();
    useconds_t interval = 1000000 / samples_per_second;
    while(true)
    {
        /* Scale counters by real elapsed time */
        for(int c=0; c<num_profile_counters; ++c)
        {
            events_per_s[c] = 0;
        }

        for(int sample=0; sample<samples_per_second; ++sample)
        {
            if(viv_read_profile_counters_3d(conn, counter_data) != 0)
            {
                fprintf(stderr, "Error querying counters (probably unsupported with this kernel, or not built into libetnaviv)\n");
                exit(1);
            }
            for(int c=0; c<num_profile_counters; ++c)
            {
                /* some counters don't reset when read */
                if(c == VIV_PROF_PS_INST_COUNTER ||
                   c == VIV_PROF_VS_INST_COUNTER ||
                   c == VIV_PROF_RENDERED_PIXEL_COUNTER ||
                   c == VIV_PROF_RENDERED_VERTICE_COUNTER ||
                   c == VIV_PROF_PXL_TEXLD_INST_COUNTER ||
                   c == VIV_PROF_PXL_BRANCH_INST_COUNTER ||
                   c == VIV_PROF_VTX_TEXLD_INST_COUNTER ||
                   c == VIV_PROF_VTX_BRANCH_INST_COUNTER ||
                   c == VIV_PROF_SE_CULLED_TRIANGLE_COUNT ||
                   c == VIV_PROF_SE_CULLED_LINES_COUNT)
                    events_per_s[c] += counter_data[c] - counter_data_last[c];
                else
                    events_per_s[c] += counter_data[c];
            }
            for(int c=0; c<num_profile_counters; ++c)
                counter_data_last[c] = counter_data[c];

            usleep(interval);
        }
        uint32_t end_time = gettime();
        uint32_t diff_time = end_time - begin_time;

        /* Scale counters by real elapsed time */
        for(int c=0; c<num_profile_counters; ++c)
        {
            events_per_s[c] = events_per_s[c] * 1000000LL / (uint64_t)diff_time;
        }

        /* Sort counters descending */
        for(int c=0; c<num_profile_counters; ++c)
        {
            sorted[c].id = c;
            sorted[c].events_per_s = events_per_s[c];
        }
        qsort(sorted, num_profile_counters, sizeof(struct counter_rec), &counter_rec_compar);

        if(interactive)
        {
            int line = 0; /* current screen line */
            printf("%s", clear_screen);
            int max_lines = get_screen_lines() - line - 1;
            if(mode == MODE_SORTED)
            {
                int count = (num_profile_counters > max_lines) ? max_lines : num_profile_counters;
                for(int c=0; c<count; ++c)
                {
                    char num[100];
                    struct viv_profile_counter_info *info = viv_get_profile_counter_info(sorted[c].id);
                    format_number(num, sizeof(num), sorted[c].events_per_s);
                    if(color)
                        printf("%s", sorted[c].events_per_s == 0 ? color_num_zero : color_num);
                    printf("%15.15s", num);
                    if(color)
                        printf("%s", color_reset);
                    printf(" ");
                    printf("%-30.30s", info->name);
                    printf("\n");
                }
            } else if(mode == MODE_ALL)
            {
                /* XXX check that width doesn't exceed screen width */
                for(int l=0; l<max_lines; ++l)
                {
                    int c = VIV_PROF_GPU_CYCLES_COUNTER + l;
                    while(c < num_profile_counters)
                    {
                        char num[100];
                        struct viv_profile_counter_info *info = viv_get_profile_counter_info(c);
                        format_number(num, sizeof(num), events_per_s[c]);
                        if(color)
                            printf("%s", events_per_s[c] == 0 ? color_num_zero : color_num);
                        printf("%15.15s", num);
                        if(color)
                            printf("%s", color_reset);
                        printf(" ");
                        printf("%-30.30s", info->name);
                        printf("  ");
                        c += max_lines;
                    }
                    printf("\n");
                }
            }
        }
        begin_time = end_time;
    }
    /*
     * XXX define new mode MODE_OCCUPANCY and some derived percentage bars:
     * - [PA] Number of primitives per vertex (max 1)
     * - [PA] % of primitives culled
     * - VS -> PA -> SE -> RA primitives/vertices in each stage
     * - RA -> PS -> PE pixels/quads in each stage
     * - Pixels per PS inst
     * - Vertices per VS inst
     * - % of texture requests trilinear/bilinear
     * - overdraw (killed by depth)
     */

    return 0;
}
コード例 #17
0
ファイル: dimer.c プロジェクト: luolingqi/fragmap_2
int get_residue_range(char line[LINE_LEN +1],int *ipos,
		      char start_residue[6],char end_residue[6],char *chain,
		      int *end)
{
  char residue_number[6], token[TOKEN_LEN + 1];

  int ipstn;
  int done, have_range, have_token;

  /* Initialise chain-id */
  *chain = ' ';
  *end = FALSE;
  start_residue[0] = '\0';
  end_residue[0] = '\0';
  done = FALSE;
  have_range = FALSE;
  ipstn = *ipos;

  /* Loop until domain number found */
  while (have_range == FALSE && done == FALSE && *ipos < LINE_LEN)
    {
      /* Get the next token from the line */
      have_token = get_token(line,&ipstn,token,&done);

      /* If have a valid token, then extract appropriate part of range */
      if (have_token == TRUE)
	{
	  /* Check that haven't found a range separator */
	  if (!strncmp(token,"&",1))
	    have_range = TRUE;

	  /* Otherwise, store appropriate part of range */
	  else if (strncmp(token,"-",1))
	    {
	      /* If don't have a start of range, then take this to be it */
	      if (start_residue[0] == '\0')
		{
		  /* Format the residue number and store */
		  format_number(residue_number,token);
		  strcpy(start_residue,residue_number);
		}

	      /* If don't have an end of range, then take this to be it */
	      else if (end_residue[0] == '\0')
		{
		  /* Format the residue number and store */
		  format_number(residue_number,token);
		  strcpy(end_residue,residue_number);
		}

	      /* Otherwise, take this to be the chain-id */
	      else
		*chain = token[0];
	    }
	}
    }

  /* Check whether have a range */
  if (start_residue[0] != '\0' && end_residue[0] != '\0')
    have_range = TRUE;

  /* Return current position in the line */
  *ipos = ipstn;
  *end = done;

  /* Return the done flag */
  return(have_range);
} 
コード例 #18
0
ファイル: ViewProjects.cpp プロジェクト: DanAurea/boinc
static void format_avg_credit(double credit, wxString& strBuffer)  {
    strBuffer = format_number(credit, 2);
}