changeset 2:1b0ebe86b44c

Automated Vimcurial commmit
author VilyaemKenyaz
date Fri, 08 Sep 2023 07:54:05 -0400
parents 47e1b1039d7b
children eb7a7364994c
files .basedfilelib.h.swp .harelet.c.swp README.md basedfilelib.h harelet.c
diffstat 5 files changed, 177 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
diff -r 47e1b1039d7b -r 1b0ebe86b44c .basedfilelib.h.swp
Binary file .basedfilelib.h.swp has changed
diff -r 47e1b1039d7b -r 1b0ebe86b44c .harelet.c.swp
Binary file .harelet.c.swp has changed
diff -r 47e1b1039d7b -r 1b0ebe86b44c README.md
--- a/README.md	Fri Sep 08 07:12:34 2023 -0400
+++ b/README.md	Fri Sep 08 07:54:05 2023 -0400
@@ -1,4 +1,4 @@
-#harelet 
+# Harelet 
 CNC CAD program for milling machines
 You may export RAW gcode or Superhare machines
 To configure some settings edit the definitions in 
diff -r 47e1b1039d7b -r 1b0ebe86b44c basedfilelib.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/basedfilelib.h	Fri Sep 08 07:54:05 2023 -0400
@@ -0,0 +1,129 @@
+// Based File Library
+//
+// Makes File I/O two functions, more like TempleOS, instead of *nix.
+
+#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
diff -r 47e1b1039d7b -r 1b0ebe86b44c harelet.c
--- a/harelet.c	Fri Sep 08 07:12:34 2023 -0400
+++ b/harelet.c	Fri Sep 08 07:54:05 2023 -0400
@@ -10,7 +10,8 @@
 
 #define DEEPNESS 5
 #define MAXPOINT 4096
-
+#define UNITS	"G20"
+#define SPEED	20
 
 typedef struct{
 	unsigned int X,Y,down;
@@ -60,6 +61,7 @@
  * *******************************************/
 void Compile(){
 	char * filename;
+	char * file;
 	int choice;
 
 	puts("Select your format\n1. RAW GCODE\n2. Superhare INO");
@@ -70,10 +72,32 @@
 	scanf("%s",filename);
 
 	if(choice == 1){
-
+		//Set the miller
+		strcat(file,UNITS);
+		
+		//Meat of instructions
+		for(int i = 0;i != numpoints;i++){
+		//Compose
+		char * instruction;
+		strcat(instruction,"G0 X");
+		strcat(instruction,sprintf("%d",points[i].X));
+		strcat(instruction," Y");
+		strcat(inustrction,sprintf
+		//Write to string
+		strcat(file,instruction);
+		}
+		//Finish
+		strcat(file,"G0, X0, Y0, Z0");
+		WriteFile(filename,file);
 	}
 	else{
+		//Set the miller
+		
 
+		//Meat of instructions
+	
+
+		//Finish
 
 	}
 
@@ -90,11 +114,29 @@
 void main(int argc, char* argv[]){
 	scanf("%c",&action);
 	switch(action){
-		case 'a':		numpoints++;
+		case 'a':		points[numpoints].X = X;
+					points[numpoints].Y = Y;
+					points[numpoints].down = down;
+					numpoints++;
+					break;
+		case 'h': 
+					X+=step;
+					break;
+		case 'j': 
+					Y+=step;
 					break;
-case: 
+		case 'k': 
+					Y-=step;
+					break;
+		case 'l': 
+					X-=step;
 					break;
-default:
+
+		case 's':		
+					puts("Enter new step:");
+					scanf("%d",&step);
+					break;
+		default:
 					break;
 	}
 	exit(0);