changeset 20:0555050bada0

Make it pretty
author VilyaemKenyaz
date Wed, 27 Sep 2023 08:51:57 -0400
parents 8fe0b5711413
children 44e906aeea91
files .README.md.swp BUGS README.md based/basedfilelib.h based/basedtermgrx.h basedfilelib.h basedtermgrx.h examples/LINE.SBP harelet.c
diffstat 9 files changed, 373 insertions(+), 335 deletions(-) [+]
line wrap: on
line diff
Binary file .README.md.swp has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BUGS	Wed Sep 27 08:51:57 2023 -0400
@@ -0,0 +1,3 @@
+inconsistent crashes when exporting 
+Display glitches when cursor is a certain distance from the origin
+GCode complier might be off, are newlines being off?
--- a/README.md	Wed Sep 27 01:47:28 2023 -0400
+++ b/README.md	Wed Sep 27 08:51:57 2023 -0400
@@ -33,7 +33,7 @@
 
 ## DVORAK
 
-Harelet has built in Dvorak support, compile with -dvorak.
+Harelet has built in Dvorak support, compile with -DVORAK.
 
 Keys for QWERTY to DVORAK
 
@@ -46,3 +46,15 @@
 Y - Compile
 . - Set step size
 Space - Add point
+
+## CONTRIUTIONS
+
+Notes on commits
+
+Keep it granular
+
+Keep it (C)imple
+
+Keep it consistent with the vision
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/based/basedfilelib.h	Wed Sep 27 08:51:57 2023 -0400
@@ -0,0 +1,132 @@
+/*********************************************
+* Description - BasedFileLib makes file I/O less like *nix and more like 
+* TempleOS
+* Author - William King
+* Date - Sep 25 2023
+* *******************************************/
+
+#define MAX_LINES 100000
+#define MAXLENGTH 512
+
+char* ReadFile(const char* fileName) {
+	FILE* file = fopen(fileName, "rb");
+	if (file == NULL) {
+		perror("Error opening file");
+		return NULL;
+	}
+
+	fseek(file, 0, SEEK_END);
+	long fileSize = ftell(file);
+	rewind(file);
+
+	char* fileContent = (char*)malloc(fileSize * sizeof(char));
+	if (fileContent == NULL) {
+		perror("Error allocating memory for file content");
+		fclose(file);
+		return NULL;
+	}
+
+	size_t readSize = fread(fileContent, sizeof(char), fileSize, file);
+	if (readSize != fileSize) {
+		perror("Error reading file");
+		fclose(file);
+		free(fileContent);
+		return NULL;
+	}
+
+	fclose(file);
+	return fileContent;
+}
+
+void WriteFile(const char* fileName, const char* content) {
+	FILE* file = fopen(fileName, "wb");
+	if (file == NULL) {
+		perror("Error opening file");
+	}
+
+	size_t writeSize = fwrite(content, sizeof(char), strlen(content), file);
+	if (writeSize != strlen(content)) {
+		perror("Error writing to file");
+		fclose(file);
+	}
+
+	fclose(file);
+}
+
+
+char* DeleteLine(char* str, unsigned int line_number) {
+	char* lines[MAX_LINES];
+	char* line;
+	unsigned int current_line = 0;
+
+	line = strtok(str, "\n");
+	while (line != NULL && current_line < MAX_LINES) {
+		lines[current_line++] = line;
+		line = strtok(NULL, "\n");
+	}
+
+	// Delete the specified line
+	if (line_number > 0 && line_number <= current_line) {
+		for (unsigned int i = line_number - 1; i < current_line - 1; i++) {
+			lines[i] = lines[i + 1];
+		}
+		current_line--;
+	}
+
+	// Reconstruct the string with remaining lines
+	str[0] = '\0';
+	for (unsigned int i = 0; i < current_line; i++) {
+		strcat(str, lines[i]);
+		strcat(str, "\n");
+	}
+
+	return str;
+}
+
+
+
+char* ReadLine(const char *str, unsigned int lineNum) {
+	int currentLine = 1;
+	size_t strLen = strlen(str);
+	char *line = NULL;
+
+	line = malloc(strLen + 1);
+	if (line == NULL) {
+		fprintf(stderr, "Error: memory allocation failed.\n");
+		exit(1);
+	}
+
+	int lineStartIndex = 0;
+	int lineEndIndex = 0;
+
+	// Traverse through the string until the desired line or the end of the string
+	while (currentLine <= lineNum && lineEndIndex < strLen) {
+		// Find the start index of the current line
+		while (lineStartIndex < strLen && (str[lineStartIndex] == '\n' || str[lineStartIndex] == '\r')) {
+			lineStartIndex++;
+			lineEndIndex++;
+		}
+
+		// Find the end index of the current line
+		lineEndIndex = lineStartIndex;
+		while (lineEndIndex < strLen && str[lineEndIndex] != '\n' && str[lineEndIndex] != '\r') {
+			lineEndIndex++;
+		}
+
+		// Check if the desired line is found
+		if (currentLine == lineNum) {
+			// Copy the line to the allocated memory
+			strncpy(line, str + lineStartIndex, lineEndIndex - lineStartIndex);
+			line[lineEndIndex - lineStartIndex] = '\0';
+			break;
+		}
+
+		// Move to the start of the next line
+		currentLine++;
+		lineStartIndex = lineEndIndex;
+	}
+
+	return line;
+}
+
+//BasedFileLib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/based/basedtermgrx.h	Wed Sep 27 08:51:57 2023 -0400
@@ -0,0 +1,199 @@
+/*********************************************
+ * Description - Based Term Grx 
+ * Modified for use with Harelet.
+ * Author - William King
+ * Date - Sep 13 2023
+ * *******************************************/
+
+#include <string.h>
+
+//Always have a 2:1 ratio if you want a square picture
+//Terminals are vertically stretched
+#define RESX 98
+#define RESY 48
+
+//Center X & Y
+#define CX	49
+#define CY	24
+
+//Colours
+#define BLACK "\x1b[30m"
+#define RED "\x1b[31m"
+#define GREEN "\x1b[32m"
+#define YELLOW "\x1b[33m"
+#define BLUE "\x1b[34m"
+#define MAGENTA "\x1b[35m"
+#define CYAN "\x1b[36m"
+#define WHITE "\x1b[37m"
+
+#define IBLACK "\x1b[30;1m"
+#define IRED "\x1b[31;1m"
+#define IGREEN "\x1b[32;1m"
+#define IYELLOW "\x1b[33;1m"
+#define IBLUE "\x1b[34;1m"
+#define IMAGENTA "\x1b[35;1m"
+#define ICYAN "\x1b[36;1m"
+#define IWHITE "\x1b[37;1m"
+
+#define BGC_BLACK "\x1b[40m"
+#define BGC_RED "\x1b[41m"
+#define BGC_GREEN "\x1b[42m"
+#define BGC_YELLOW "\x1b[43m"
+#define BGC_BLUE "\x1b[44m"
+#define BGC_MAGENTA "\x1b[45m"
+#define BGC_CYAN "\x1b[46m"
+#define BGC_WHITE "\x1b[47m"
+
+#define BGC_IBLACK "\x1b[40;1m"
+#define BGC_IRED "\x1b[41;1m"
+#define BGC_IGREEN "\x1b[42;1m"
+#define BGC_IYELLOW "\x1b[43;1m"
+#define BGC_IBLUE "\x1b[44;1m"
+#define BGC_IMAGENTA "\x1b[45;1m"
+#define BGC_ICYAN "\x1b[46;1m"
+#define BGC_IWHITE "\x1b[47;1m"
+
+char screen[RESY][RESX];
+
+
+/*********************************************
+ * Description - Clear the screen
+ * Author - William King
+ * Date - Sep 13 2023
+ * *******************************************/
+void ClrScr(){
+	//printf("\x1b[2J");
+	for(int i = 0; i != 32;i++)
+		puts("");
+
+	for(int i = 0; i != RESY; i++){
+
+		for(int j = 0; j != RESX; j++){
+
+			screen[i][j] = ' ';
+
+		}
+
+
+	}
+
+
+}
+
+/*********************************************
+ * Description - Render all the cells to the screen, splashing
+ * Author - William King
+ * Date - Sep 13 2023
+ * *******************************************/
+void Splash(){
+	puts("");
+	for(int i = 0; i != RESY; i++){
+
+		for(int j = 0; j != RESX; j++){
+
+			printf("%c",screen[j][i]);
+
+		}
+
+		puts("");
+
+	}
+
+
+}
+
+/*********************************************
+ * Description - Put a character onto the screen 
+ * Author - William King
+ * Date - Sep 13 2023
+ * *******************************************/
+void DrawChar(int x, int y, char content){
+	//Make sure it's in the screen
+	assert(x <= RESX && y <= RESY);
+
+	screen[x][y] = content;
+}
+
+/*********************************************
+ * Description - Put a string onto the screen
+ * Author - William King
+ * Date - Sep 13 2023
+ * *******************************************/
+void DrawString(int x, int y, char str[128]){
+
+	//Make sure origin is in the screen
+	assert(x <= RESX || y <= RESY);
+
+	//Make sure the string wont run off the screen
+	assert(x + strlen(str) <= RESX);
+
+	for(int i; i != strlen(str);i++){
+
+		DrawChar(x+i,y,str[i]);
+
+	}
+
+
+}
+
+
+/*********************************************
+ * Description - Draw a square
+ * Author - William King
+ * Date - Sep 13 2023
+ * *******************************************/
+void DrawSquare(int x, int y, int length, char fill){
+
+	//Make sure shape is not ridiculous
+	assert(x <= RESX && y <= RESY);
+	assert(x+length <= RESX && y+length <= RESY);
+
+	for(int i = 0; i != length;i++){
+
+		int j = 0;
+		while (j != 0){
+			DrawChar(x+j,y+i,fill);
+			j++;
+		}
+
+	}
+
+
+}
+
+
+/*********************************************
+* Description -  Fill the entire screen with a character
+* Author - William King
+* Date - Sep 15 2023
+* *******************************************/
+void DrawFill(char fill){
+	for(int i = 0; i != RESY; i++){
+		for(int j = 0; j != RESX; j++){
+			screen[i][j] = fill;
+
+		}
+	}
+
+}
+
+
+
+/*********************************************
+* Description - Set the colour
+* Author - William King
+* Date - Sep 13 2023
+* *******************************************/
+void SetColour(char * colour){
+	printf("%s",colour);
+}
+
+
+/*********************************************
+* Description - Reset the colour
+* Author - William King
+* Date - Sep 13 2023
+* *******************************************/
+void ResetColour(char * colour){
+    printf("\x1b[0m");
+}
--- a/basedfilelib.h	Wed Sep 27 01:47:28 2023 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-/*********************************************
-* Description - BasedFileLib makes file I/O less like *nix and more like 
-* TempleOS
-* Author - William King
-* Date - Sep 25 2023
-* *******************************************/
-
-#define MAX_LINES 100000
-#define MAXLENGTH 512
-
-char* ReadFile(const char* fileName) {
-	FILE* file = fopen(fileName, "rb");
-	if (file == NULL) {
-		perror("Error opening file");
-		return NULL;
-	}
-
-	fseek(file, 0, SEEK_END);
-	long fileSize = ftell(file);
-	rewind(file);
-
-	char* fileContent = (char*)malloc(fileSize * sizeof(char));
-	if (fileContent == NULL) {
-		perror("Error allocating memory for file content");
-		fclose(file);
-		return NULL;
-	}
-
-	size_t readSize = fread(fileContent, sizeof(char), fileSize, file);
-	if (readSize != fileSize) {
-		perror("Error reading file");
-		fclose(file);
-		free(fileContent);
-		return NULL;
-	}
-
-	fclose(file);
-	return fileContent;
-}
-
-void WriteFile(const char* fileName, const char* content) {
-	FILE* file = fopen(fileName, "wb");
-	if (file == NULL) {
-		perror("Error opening file");
-	}
-
-	size_t writeSize = fwrite(content, sizeof(char), strlen(content), file);
-	if (writeSize != strlen(content)) {
-		perror("Error writing to file");
-		fclose(file);
-	}
-
-	fclose(file);
-}
-
-
-char* DeleteLine(char* str, unsigned int line_number) {
-	char* lines[MAX_LINES];
-	char* line;
-	unsigned int current_line = 0;
-
-	line = strtok(str, "\n");
-	while (line != NULL && current_line < MAX_LINES) {
-		lines[current_line++] = line;
-		line = strtok(NULL, "\n");
-	}
-
-	// Delete the specified line
-	if (line_number > 0 && line_number <= current_line) {
-		for (unsigned int i = line_number - 1; i < current_line - 1; i++) {
-			lines[i] = lines[i + 1];
-		}
-		current_line--;
-	}
-
-	// Reconstruct the string with remaining lines
-	str[0] = '\0';
-	for (unsigned int i = 0; i < current_line; i++) {
-		strcat(str, lines[i]);
-		strcat(str, "\n");
-	}
-
-	return str;
-}
-
-
-
-char* ReadLine(const char *str, unsigned int lineNum) {
-	int currentLine = 1;
-	size_t strLen = strlen(str);
-	char *line = NULL;
-
-	line = malloc(strLen + 1);
-	if (line == NULL) {
-		fprintf(stderr, "Error: memory allocation failed.\n");
-		exit(1);
-	}
-
-	int lineStartIndex = 0;
-	int lineEndIndex = 0;
-
-	// Traverse through the string until the desired line or the end of the string
-	while (currentLine <= lineNum && lineEndIndex < strLen) {
-		// Find the start index of the current line
-		while (lineStartIndex < strLen && (str[lineStartIndex] == '\n' || str[lineStartIndex] == '\r')) {
-			lineStartIndex++;
-			lineEndIndex++;
-		}
-
-		// Find the end index of the current line
-		lineEndIndex = lineStartIndex;
-		while (lineEndIndex < strLen && str[lineEndIndex] != '\n' && str[lineEndIndex] != '\r') {
-			lineEndIndex++;
-		}
-
-		// Check if the desired line is found
-		if (currentLine == lineNum) {
-			// Copy the line to the allocated memory
-			strncpy(line, str + lineStartIndex, lineEndIndex - lineStartIndex);
-			line[lineEndIndex - lineStartIndex] = '\0';
-			break;
-		}
-
-		// Move to the start of the next line
-		currentLine++;
-		lineStartIndex = lineEndIndex;
-	}
-
-	return line;
-}
-
-//BasedFileLib
--- a/basedtermgrx.h	Wed Sep 27 01:47:28 2023 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,199 +0,0 @@
-/*********************************************
- * Description - Based Term Grx 
- * Modified for use with Harelet.
- * Author - William King
- * Date - Sep 13 2023
- * *******************************************/
-
-#include <string.h>
-
-//Always have a 2:1 ratio if you want a square picture
-//Terminals are vertically stretched
-#define RESX 98
-#define RESY 48
-
-//Center X & Y
-#define CX	49
-#define CY	24
-
-//Colours
-#define BLACK "\x1b[30m"
-#define RED "\x1b[31m"
-#define GREEN "\x1b[32m"
-#define YELLOW "\x1b[33m"
-#define BLUE "\x1b[34m"
-#define MAGENTA "\x1b[35m"
-#define CYAN "\x1b[36m"
-#define WHITE "\x1b[37m"
-
-#define IBLACK "\x1b[30;1m"
-#define IRED "\x1b[31;1m"
-#define IGREEN "\x1b[32;1m"
-#define IYELLOW "\x1b[33;1m"
-#define IBLUE "\x1b[34;1m"
-#define IMAGENTA "\x1b[35;1m"
-#define ICYAN "\x1b[36;1m"
-#define IWHITE "\x1b[37;1m"
-
-#define BGC_BLACK "\x1b[40m"
-#define BGC_RED "\x1b[41m"
-#define BGC_GREEN "\x1b[42m"
-#define BGC_YELLOW "\x1b[43m"
-#define BGC_BLUE "\x1b[44m"
-#define BGC_MAGENTA "\x1b[45m"
-#define BGC_CYAN "\x1b[46m"
-#define BGC_WHITE "\x1b[47m"
-
-#define BGC_IBLACK "\x1b[40;1m"
-#define BGC_IRED "\x1b[41;1m"
-#define BGC_IGREEN "\x1b[42;1m"
-#define BGC_IYELLOW "\x1b[43;1m"
-#define BGC_IBLUE "\x1b[44;1m"
-#define BGC_IMAGENTA "\x1b[45;1m"
-#define BGC_ICYAN "\x1b[46;1m"
-#define BGC_IWHITE "\x1b[47;1m"
-
-char screen[RESY][RESX];
-
-
-/*********************************************
- * Description - Clear the screen
- * Author - William King
- * Date - Sep 13 2023
- * *******************************************/
-void ClrScr(){
-	//printf("\x1b[2J");
-	for(int i = 0; i != 32;i++)
-		puts("");
-
-	for(int i = 0; i != RESY; i++){
-
-		for(int j = 0; j != RESX; j++){
-
-			screen[i][j] = ' ';
-
-		}
-
-
-	}
-
-
-}
-
-/*********************************************
- * Description - Render all the cells to the screen, splashing
- * Author - William King
- * Date - Sep 13 2023
- * *******************************************/
-void Splash(){
-	puts("");
-	for(int i = 0; i != RESY; i++){
-
-		for(int j = 0; j != RESX; j++){
-
-			printf("%c",screen[j][i]);
-
-		}
-
-		puts("");
-
-	}
-
-
-}
-
-/*********************************************
- * Description - Put a character onto the screen 
- * Author - William King
- * Date - Sep 13 2023
- * *******************************************/
-void DrawChar(int x, int y, char content){
-	//Make sure it's in the screen
-	assert(x <= RESX && y <= RESY);
-
-	screen[x][y] = content;
-}
-
-/*********************************************
- * Description - Put a string onto the screen
- * Author - William King
- * Date - Sep 13 2023
- * *******************************************/
-void DrawString(int x, int y, char str[128]){
-
-	//Make sure origin is in the screen
-	assert(x <= RESX || y <= RESY);
-
-	//Make sure the string wont run off the screen
-	assert(x + strlen(str) <= RESX);
-
-	for(int i; i != strlen(str);i++){
-
-		DrawChar(x+i,y,str[i]);
-
-	}
-
-
-}
-
-
-/*********************************************
- * Description - Draw a square
- * Author - William King
- * Date - Sep 13 2023
- * *******************************************/
-void DrawSquare(int x, int y, int length, char fill){
-
-	//Make sure shape is not ridiculous
-	assert(x <= RESX && y <= RESY);
-	assert(x+length <= RESX && y+length <= RESY);
-
-	for(int i = 0; i != length;i++){
-
-		int j = 0;
-		while (j != 0){
-			DrawChar(x+j,y+i,fill);
-			j++;
-		}
-
-	}
-
-
-}
-
-
-/*********************************************
-* Description -  Fill the entire screen with a character
-* Author - William King
-* Date - Sep 15 2023
-* *******************************************/
-void DrawFill(char fill){
-	for(int i = 0; i != RESY; i++){
-		for(int j = 0; j != RESX; j++){
-			screen[i][j] = fill;
-
-		}
-	}
-
-}
-
-
-
-/*********************************************
-* Description - Set the colour
-* Author - William King
-* Date - Sep 13 2023
-* *******************************************/
-void SetColour(char * colour){
-	printf("%s",colour);
-}
-
-
-/*********************************************
-* Description - Reset the colour
-* Author - William King
-* Date - Sep 13 2023
-* *******************************************/
-void ResetColour(char * colour){
-    printf("\x1b[0m");
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/LINE.SBP	Wed Sep 27 08:51:57 2023 -0400
@@ -0,0 +1,23 @@
+'OpenSBP file written by Harelet
+'Harelet, written by William King
+'No responsibilty is taken for any damages to any equipment
+
+'Starting
+SO, 1,1
+Pause 2
+SA,
+&ZUP = 0.25
+MH
+
+'Bulk of instructions
+J2 5 5
+JZ,&ZUP
+J2 5 5
+JZ,&ZUP
+J2 20 5
+JZ,&ZUP
+
+J2,0,0
+SO, 1,0
+'All done. Wait for user.
+PAUSE
\ No newline at end of file
--- a/harelet.c	Wed Sep 27 01:47:28 2023 -0400
+++ b/harelet.c	Wed Sep 27 08:51:57 2023 -0400
@@ -9,8 +9,8 @@
 #include <string.h>
 #include <assert.h>
 
-#include "basedfilelib.h"
-#include "basedtermgrx.h"
+#include "based/basedfilelib.h"
+#include "based/basedtermgrx.h"
 
 #define DEEPNESS 5
 #define MAXPOINT 4096
@@ -51,7 +51,7 @@
  * Author - William King
  * Date - Sep 26 2023
  * *******************************************/
-char * IntToString(int num){
+char * IntToString(unsigned int num){
 	char * s;
 	sprintf(s,"%d",num);
 	return s;