static void readSizesFile(char *fileName, struct hash *sizes)
/* Read tab-separated file into hash. */
{
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[2];
while (lineFileChopNextTab(lf, row, ArraySize(row)))
    addSize(row[0], lineFileNeedNum(lf, row, 1), sizes);
lineFileClose(&lf);
}
Esempio n. 2
0
size_t DataVector::append() {
	// enlarge, if necessary
	if (unused == 0) {
		addSize(this->inc_elems);
	}

	size_t x = size;
	size++;
	unused--;

	return x;
}
Esempio n. 3
0
VertexIndex::VertexIndex(size_t size)
	: size(size)
{
	// The upper limit is the maximum of GLuint divided by six (the number
	// of indices per size) and divided by the size of GLuint. This guarantees
	// no overflows when calculating the array size in bytes.
	// Memory issues will be handled by other exceptions.
	if (size == 0 || size > ((GLuint) -1) / 6 / sizeof(GLuint))
		throw love::Exception("Invalid size.");

	addSize(size);
}
    ColorLabel(const char* label):
        osgWidget::Label(label, "") {
        setFont("fonts/VeraMono.ttf");
        setFontSize(14);
        setFontColor(1.0f, 1.0f, 1.0f, 1.0f);

        setColor(0.3f, 0.3f, 0.3f, 1.0f);
        setPadding(2.0f);
        setCanFill(true);

        addSize(150.0f, 25.0f);

        setLabel(label);
        setEventMask(osgWidget::EVENT_MOUSE_PUSH | osgWidget::EVENT_MASK_MOUSE_MOVE);
    }
static void parseSizesStr(char* sizesStr, struct hash* sizes)
/* parse string with pairs of name and value */
{
char **words;
int numWords = chopByWhite(sizesStr, NULL, 0);
int i;

if (numWords % 1)
    errAbort("sizes string must contain whitespace seprated pairs of name and size: %s",
             sizesStr);
words = needMem(numWords);
chopByWhite(sizesStr, words, numWords);
for (i = 0; i < numWords; i += 2)
    addSize(words[i], sqlUnsigned(words[i+1]), sizes);
freez(&words);
}
Esempio n. 6
0
//METHID TO SEND A FILE.
int sendFile(struct wrkrTrack workers, char * fname, FILE * fp){
	char * buff;	/*Buffer for sending the file*/
	int i, fd;
	long size;

	//SIGNAL THE WORKERS TO ACCEPT THE FILE.
	fseek(fp, 0L, SEEK_END);	/*Go to the end of the file*/
	size = ftell(fp);		/*Getting the size of the file*/
	rewind(fp);			/*Go back to the start of the file*/
	buff = (char *)malloc(size);
	addSize(fname, size);		/*Add the file size to the sent file name*/
	broadcastCmd(workers, SAVE, fname);

	//SENDING THE CONTENTS.
	while(fread(buff, 1, size, fp) != EOF){
		for(i = 0; i < workers.workerCount; i++)
			write(workers.worker_fd[i], buff, size);
	}

}
Esempio n. 7
0
main(int argc, char **argv)
{	struct EXE_header exe;
	unsigned tosize;

	if(argc <= 1) {
		puts("Patch heap size into FreeCOM executable\n"
			"\nuseage: PTCHSIZE freecom [{ size }]\n"
			"\nSize may be given hexadecimal (0x###) or decimal.\n"
			"If 'KB' is appended to size, it's multiplied with 1024.\n"
			"A leading plus sign is ignored.\n"
			"A plus sign by its own is treated as estimated minimum size.\n"
			"More than one sizes are summed up.\n"
			"If size evaluates to 0 (zero), the restriction is disabled.\n"
			"\ne.g.: PTCHSIZE freecom + 5K\n"
			"means: reserve 5*1024 bytes in addition to minimum size."
		);
		return 127;
	}

	if(enumFileResources(argv[1], RES_ID_INFO, getInfo, 0) != 1) {
		puts("Failed to locate FreeCOM's info resource\n"
			"Possible errors:\n"
			"\tAn error is issued above.\n"
			"\tThe file could not be opened.\n"
			"\tThe version of FreeCOM is too old.\n"
			"\tFile read error.");
		return 80;
	}

	if((freecom = fopen(argv[1], "r+b")) == 0) {
		printf("Cannot open FreeCOM: %s\n", argv[1]);
		return 30;
	}

	if(fread(&exe, sizeof(exe), 1, freecom) != 1) {
		printf("Read error from: %s\n", argv[1]);
		return 44;
	}
	/* exe.extraMin is not trustworthy as it might have been tweak
		in a previous run */

	assert(info);
	/* Decompose the info resource */
	getInfoValues();
	minSize = ival.extraSpace				/* default stuff */
		+ 5 * (unsigned long)ival.bufsize	/* command lines */
		+ 3 * (64 + 3 + 8 + 5)				/* filenames */
		+ 256								/* env var buffer %PATH% etc */
		;
	addUns(ival.alias);
	addUns(ival.hist);
	addUns(ival.dirs);
	if(minSize >= INT_MAX) {
		puts("Estimated minimum heap size exceeds 64KB.\n"
			"There is most probably a corrupted info resource.");
		return 71;
	}

	if(argc == 2 || ival.heapPos == ~0) {
		prUns(ival.alias, "Aliases");
		prUns(ival.hist, "Command line history");
		prUns(ival.dirs, "Directory stack");
		prUns(ival.bufsize, "Command line buffer");
		if(ival.heapPos == ~0)
			puts("Missing heap position -> cannot change heap size");
		else {
			if(fseek(freecom, ival.heapPos, SEEK_SET) != 0) {
				printf("Failed to seek to heap size offset in %s\n", argv[1]);
				return 43;
			}
			assert(sizeof(tosize) == 2);
			if(fread(&tosize, sizeof(tosize), 1, freecom) != 1) {
				puts("Failed to read heap size from FreeCOM executable.");
				return 76;
			}
			fclose(freecom);
			if(tosize)
				printf("Heap size restricted to %u bytes\n"
				 , tosize);
			else
				puts("Heap size is currently not restricted");
		}
		printf("Estimated minimum of heap: %u\n", (unsigned)minSize);
		return 0;
	}

	tosize = 0;
	argc = 1;
	while(argv[++argc])
		addSize(&tosize, argv[argc]);
	if(tosize && tosize < minSize) {
		printf("size smaller than estimated minimum size: %u\n"
		 , (unsigned)minSize);
		return 72;
	}

	printf("Patching '%s' to heap size of %u bytes\n"
	 , argv[1], tosize);
	if(tosize)
		exe.extraMin = exe.extraMax = ival.extraSpace + tosize / 16;
	else {
		exe.extraMax = 0xffff;
		exe.extraMin = ival.extraSpace;
	}
	rewind(freecom);
	if(fwrite(&exe, sizeof(exe), 1, freecom) != 1) {
		printf("Failed to patch heap size into FreeCOM executable.\n"
			"File most probably corrupted now: %s\n", argv[1]);
		return 77;
	}

	if(fseek(freecom, ival.heapPos, SEEK_SET) != 0) {
		printf("Failed to seek to heap size offset in %s\n", argv[1]);
		return 42;
	}
	assert(sizeof(tosize) == 2);
	if(fwrite(&tosize, sizeof(tosize), 1, freecom) != 1) {
		printf("Failed to patch heap size into FreeCOM executable.\n"
			"File most probably corrupted now: %s\n", argv[1]);
		return 75;
	}

	fflush(freecom);
	if(ferror(freecom)) {
		printf("Failed to patch heap size into FreeCOM executable.\n"
			"File most probably corrupted now: %s\n", argv[1]);
		return 76;
	}
	fclose(freecom);
	return 0;
}