static void
formatUnknownContentLength(char* buf, PRUint32 len, PRUint32 bytesReceived, PRUint32 elapsed)
{
    char rate[32];
    *rate = 0;

    // the transfer rate
    double bytes_per_sec = 0;
    if (elapsed > 0)
        bytes_per_sec = ((double) bytesReceived) / ((double) elapsed);

    formatRate(rate, sizeof(rate), bytes_per_sec);

    // the number of bytes received
    char bytes_received[32];

    if (bytesReceived < KILOBYTE)
        PR_snprintf(bytes_received, sizeof(bytes_received),
                    XP_GetString(XP_THERMO_UH),
                    bytesReceived, IS_PLURAL(bytesReceived));
    else
        PR_snprintf(bytes_received, sizeof(bytes_received),
                    XP_GetString(XP_THERMO_KBYTE_FORMAT),
                    bytesReceived / KILOBYTE);

    if (*rate) {
        /* "%s read (at %s)" */
        PR_snprintf(buf, len, XP_GetString(XP_THERMO_PERCENT_RATE_FORM), bytes_received, rate);
    }
    else {
        PR_snprintf(buf, len, XP_GetString(XP_THERMO_RAW_COUNT_FORM), bytes_received);
    }
}
static void
formatKnownContentLength(char* buf,
                         PRUint32 len,
                         PRUint32 bytesReceived,
                         PRUint32 contentLength,
                         PRUint32 elapsed)
{
    char rate[32];
    *rate = 0;

    // the transfer rate
    double bytes_per_sec = 0;
    if (elapsed > 0)
        bytes_per_sec = ((double) bytesReceived) / ((double) elapsed);

    formatRate(rate, sizeof(rate), bytes_per_sec);
    

    // format the content length
    char length[32];
    *length = 0;

    if (contentLength < KILOBYTE)
        PR_snprintf(length, sizeof(length), XP_GetString(XP_THERMO_BYTE_FORMAT), contentLength);
    else
        PR_snprintf(length, sizeof(length), XP_GetString(XP_THERMO_KBYTE_FORMAT), contentLength / KILOBYTE);
	

    // the percentage complete
    char percent[32];

    PRUint32 p = (bytesReceived * 100) / contentLength;
    if (p >= 100 && bytesReceived != contentLength)
        p = 99;

    PR_snprintf(percent, sizeof(percent), XP_GetString(XP_THERMO_PERCENTAGE_FORMAT), p);

    // the amount of time remaining
    char tleft[32];
    *tleft = 0;

    if (bytes_per_sec >= KILOBYTE && elapsed >= ENOUGH_TIME_TO_GUESS) {
        PRUint32 secs_left =
            (PRUint32) (((double) (contentLength - bytesReceived)) / bytes_per_sec);

        if (secs_left >= HOUR) {
            PR_snprintf(tleft, sizeof(tleft),
                        XP_GetString(XP_THERMO_HOURS_FORMAT),
                        secs_left / HOUR,
                        (secs_left / MINUTE) % MINUTE,
                        secs_left % MINUTE);
        }
        else if (secs_left >= MINUTE) {
            PR_snprintf(tleft, sizeof(tleft),
                        XP_GetString(XP_THERMO_MINUTES_FORMAT),
                        secs_left / MINUTE,
                        secs_left % MINUTE);
        }
        else if (secs_left > 0) {
            PR_snprintf(tleft, sizeof(tleft),
                        XP_GetString(XP_THERMO_SECONDS_FORMAT),
                        secs_left,
                        IS_PLURAL(secs_left));
        }
    }

    if (*tleft) {
        /* "%s of %s (at %s, %s remaining)" */
        PR_snprintf(buf, len,
                    XP_GetString(XP_THERMO_RATE_REMAINING_FORM),
                    percent, length, rate, tleft);
    }
    else if (*rate) {
        /* "%s of %s (at %s)" */
        PR_snprintf(buf, len,
                    XP_GetString(XP_THERMO_RATE_FORM),
                    percent, length, rate);
    }
    else {
        /* "%s of %s" */
        PR_snprintf(buf, len,
                    XP_GetString(XP_THERMO_PERCENT_FORM),
                    percent, length);
    }
}
Esempio n. 3
0
int
shoot(void)
{
	int     firstnumber, value;

	firstnumber = wordnumber;
	if (!TestBit(inven, LASER))
		puts("You aren't holding a blaster.");
	else {
		wordnumber++;
		while(wordnumber <= wordcount && wordtype[wordnumber] == OBJECT) {
			value = wordvalue[wordnumber];
			printf("%s:\n", objsht[value]);
			if (TestBit(location[position].objects, value)) {
				ClearBit(location[position].objects, value);
				ourtime++;
				printf("The %s explode%s\n", objsht[value],
				    (IS_PLURAL(value) ? "." : "s."));
				if (value == BOMB)
					die(0);
			} else
				printf("I don't see any %s around here.\n", objsht[value]);
			if (wordnumber < wordcount - 1 && wordvalue[++wordnumber] == AND)
				wordnumber++;
			else
				return (firstnumber);
		}
		/* special cases with their own return()'s */

		if (wordnumber <= wordcount && wordtype[wordnumber] == NOUNS) {
			ourtime++;
			switch (wordvalue[wordnumber]) {

			case DOOR:
				switch(position) {
				case 189:
				case 231:
					puts("The door is unhinged.");
					location[189].north = 231;
					location[231].south = 189;
					whichway(location[position]);
					break;
				case 30:
					puts("The wooden door splinters.");
					location[30].west = 25;
					whichway(location[position]);
					break;
				case 31:
					puts("The laser blast has no effect on the door.");
					break;
				case 20:
					puts("The blast hits the door and it explodes into flame.  The magnesium burns");
					puts("so rapidly that we have no chance to escape.");
					die(0);
				default:
					puts("Nothing happens.");
				}
				break;

			case NORMGOD:
			case BATHGOD:
				if (TestBit(location[position].objects, BATHGOD)) {
					puts("The goddess is hit in the chest and splashes back against the rocks.");
					puts("Dark blood oozes from the charred blast hole.  Her naked body floats in the");
					puts("pools and then off downstream.");
					ClearBit(location[position].objects, BATHGOD);
					SetBit(location[180].objects, DEADGOD);
					power += 5;
					ego -= 10;
					notes[JINXED]++;
				} else
					if (TestBit(location[position].objects, NORMGOD)) {
						puts("The blast catches the goddess in the stomach, knocking her to the ground.");
						puts("She writhes in the dirt as the agony of death taunts her.");
						puts("She has stopped moving.");
						ClearBit(location[position].objects, NORMGOD);
						SetBit(location[position].objects, DEADGOD);
						power += 5;
						ego -= 10;
						notes[JINXED]++;
						if (wintime)
							live();
						break;
					} else
						puts("I don't see any goddess around here.");
				break;

			case TIMER:
				if (TestBit(location[position].objects, TIMER)) {
					puts("The old man slumps over the bar.");
					power++;
					ego -= 2;
					notes[JINXED]++;
					ClearBit(location[position].objects, TIMER);
					SetBit(location[position].objects, DEADTIME);
				} else
					puts("What old-timer?");
				break;
			case MAN:
				if (TestBit(location[position].objects, MAN)) {
					puts("The man falls to the ground with blood pouring all over his white suit.");
					puts("Your fantasy is over.");
					die(0);
				} else
					puts("What man?");
				break;
			case NATIVE:
				if (TestBit(location[position].objects, NATIVE)) {
					puts("The girl is blown backwards several feet and lies in a pool of blood.");
					ClearBit(location[position].objects, NATIVE);
					SetBit(location[position].objects, DEADNATIVE);
					power += 5;
					ego -= 2;
					notes[JINXED]++;
				} else
					puts("There is no girl here.");
				break;
			case -1:
				puts("Shoot what?");
				break;

			default:
				printf("You can't shoot the %s.\n", objsht[wordvalue[wordnumber]]);
			}
		} else
			puts("You must be a looney.");
	}
	return (firstnumber);
}