Exemple #1
0
char* coco_string_create_char(const wchar_t *value) {
	int len = coco_string_length(value);
	char *res = new char[len + 1];
	for (int i = 0; i < len; ++i) { res[i] = (char) value[i]; }
	res[len] = 0;
	return res;
}
Exemple #2
0
	void Generator::GenCopyright() {
		FILE *file = NULL;

		if (coco_string_length(tab->frameDir) != 0) {
			wchar_t *copyFr = coco_string_create_append(tab->frameDir, L"/Copyright.frame");
			char *chCopyFr = coco_string_create_char(copyFr);
			file = fopen(chCopyFr, "r");
			delete [] copyFr;
			delete [] chCopyFr;
		}
		if (file == NULL) {
			wchar_t *copyFr = coco_string_create_append(tab->srcDir, L"Copyright.frame");
			char *chCopyFr = coco_string_create_char(copyFr);
			file = fopen(chCopyFr, "r");
			delete [] copyFr;
			delete [] chCopyFr;
		}
		if (file == NULL) {
			return;
		}

		FILE *scannerFram = fram;
		fram = file;

		CopyFramePart(NULL);
		fram = scannerFram;

		fclose(file);
	}
Exemple #3
0
	void Generator::CopyFramePart(const wchar_t* stop, bool generateOutput) {
		wchar_t startCh = 0;
		int endOfStopString = 0;
		wchar_t ch = 0;

		if (stop != NULL) {
			startCh = stop[0];
			endOfStopString = coco_string_length(stop)-1;
		}

		fwscanf(fram, L"%lc", &ch); //	fram.ReadByte();
		while (!feof(fram)) { // ch != EOF
			if (stop != NULL && ch == startCh) {
				int i = 0;
				do {
					if (i == endOfStopString) return; // stop[0..i] found
					fwscanf(fram, L"%lc", &ch); i++;
				} while (ch == stop[i]);
				// stop[0..i-1] found; continue with last read character
				if (generateOutput) {
					wchar_t *subStop = coco_string_create(stop, 0, i);
					fwprintf(gen, L"%ls", subStop);
					coco_string_delete(subStop);
				}
			} else {
				if (generateOutput) { fwprintf(gen, L"%lc", ch); }
				fwscanf(fram, L"%lc", &ch);
			}
		}
		if (stop != NULL) {
			wchar_t *message = coco_string_create_append(L" -- Incomplete or corrupt frame file: ", frameFile);
			errors->Exception(message);
			delete [] message;
		}
	}
Exemple #4
0
	void Generator::GenPrefixFromNamespace() {
		const wchar_t *nsName = tab->nsName;
		if (nsName == NULL || coco_string_length(nsName) == 0) {
			return;
		}
		const int len = coco_string_length(nsName);
		int startPos = 0;
		do {
			int curLen = coco_string_indexof(nsName + startPos, COCO_CPP_NAMESPACE_SEPARATOR);
			if (curLen == -1) { curLen = len - startPos; }
			wchar_t *curNs = coco_string_create(nsName, startPos, curLen);
			fwprintf(gen, L"%ls_", curNs);
			coco_string_delete(curNs);
			startPos = startPos + curLen + 1;
		} while (startPos < len);
	}
Exemple #5
0
wchar_t* coco_string_create_append(const wchar_t *target, const wchar_t appendix) {
	int targetLen = coco_string_length(target);
	wchar_t* data = new wchar_t[targetLen + 2];
	wcsncpy(data, target, targetLen);
	data[targetLen] = appendix;
	data[targetLen + 1] = 0;
	return data;
}
Exemple #6
0
int ParserGen::GenNamespaceOpen(const wchar_t *nsName) {
	if (nsName == NULL || coco_string_length(nsName) == 0) {
		return 0;
	}
	const int len = coco_string_length(nsName);
	int startPos = 0;
	int nrOfNs = 0;
	do {
		int curLen = coco_string_indexof(nsName + startPos, COCO_CPP_NAMESPACE_SEPARATOR);
		if (curLen == -1) { curLen = len - startPos; }
		wchar_t *curNs = coco_string_create(nsName, startPos, curLen);
		fwprintf(gen, L"namespace %ls {\n", curNs);
		coco_string_delete(curNs);
		startPos = startPos + curLen + 1;
		if (startPos < len && nsName[startPos] == COCO_CPP_NAMESPACE_SEPARATOR) {
			++startPos;
		}
		++nrOfNs;
	} while (startPos < len);
	return nrOfNs;
}
Exemple #7
0
	FILE* Generator::OpenFrame(const wchar_t* frame) {
		if (coco_string_length(tab->frameDir) != 0) {
			frameFile = coco_string_create_append(tab->frameDir, L"/");
			coco_string_merge(frameFile, frame);
			char *chFrameFile = coco_string_create_char(frameFile);
			fram = fopen(chFrameFile, "r");
			delete [] chFrameFile;
		}
		if (fram == NULL) {
			delete [] frameFile;
			frameFile = coco_string_create_append(tab->srcDir, frame);  /* pdt */
			char *chFrameFile = coco_string_create_char(frameFile);
			fram = fopen(chFrameFile, "r");
			delete [] chFrameFile;
		}
		if (fram == NULL) {
			wchar_t *message = coco_string_create_append(L"-- Cannot find : ", frame);
			errors->Exception(message);
			delete [] message;
		}

	    return fram;
	}