Lay the groundwork
This commit is contained in:
		
							
								
								
									
										22
									
								
								src/graph.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/graph.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include "graph.h"
 | 
			
		||||
 | 
			
		||||
int graph_reduce(struct adjmatrix *graph) {
 | 
			
		||||
   // TODO: Implement a function which checks if a process is blocked
 | 
			
		||||
   // TODO: Use that function to implement the graph reduction algorithm
 | 
			
		||||
   //? Make sure when reducing the graph, you don't try to delete the
 | 
			
		||||
   return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int knot_detect(struct adjmatrix *graph)  {
 | 
			
		||||
   return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int destroy_adjmatrix(struct adjmatrix *matrix) {
 | 
			
		||||
   for (int i = 0; i < matrix->num_processes + matrix->num_resources; i++) {
 | 
			
		||||
      free(matrix->matrix[i]);
 | 
			
		||||
   }
 | 
			
		||||
   free(matrix->matrix);
 | 
			
		||||
   free(matrix->resource_counts);
 | 
			
		||||
   return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								src/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/main.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
/* +-------------+---------+-----------------------+
 | 
			
		||||
   | John Breaux | jab0910 | JohnBreaux@my.unt.edu | //TODO put your name here
 | 
			
		||||
   +-------------+---------+-----------------------+
 | 
			
		||||
   |              Created  2022-04-16              |
 | 
			
		||||
   +-----------------------------------------------+  */
 | 
			
		||||
#include <stdio.h>      // printf
 | 
			
		||||
#include "graph.h"      // Graph reduction/Knot detection, struct adjmatrix
 | 
			
		||||
#include "read_input.h" //TODO: Read input in the associated C file, and provide an interface to that function here
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main(int argc, char** argv) {
 | 
			
		||||
   // TODO: Grab file name from args
 | 
			
		||||
   //? Command line argument structure?
 | 
			
		||||
   //? Other flags? What other features should this have?
 | 
			
		||||
   char* filename = NULL;
 | 
			
		||||
 | 
			
		||||
   //TODO: Implement reading from a file
 | 
			
		||||
   struct adjmatrix *graph;
 | 
			
		||||
   read_file(filename, graph);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   // TODO: Implement graph reduction and/or knot detection
 | 
			
		||||
 | 
			
		||||
   // TODO: Destroy the graph created by read_file
 | 
			
		||||
   destroy_adjmatrix(graph);
 | 
			
		||||
   return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								src/read_input.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/read_input.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
//TODO: Include C file IO header (stdio.h? Whatever it is)
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include "graph.h"      // struct adjmatrix
 | 
			
		||||
#include "read_input.h" // read_input
 | 
			
		||||
 | 
			
		||||
#define MAX_LINE_LEN 1024
 | 
			
		||||
 | 
			
		||||
// TODO: Implement reading from a file
 | 
			
		||||
int read_file(char *filename, struct adjmatrix *graph) {
 | 
			
		||||
   // TODO: Open file with name filename as read-only
 | 
			
		||||
   FILE *f = fopen(filename, "r");
 | 
			
		||||
   // TODO: Check for file IO errors (I might have a solution for that in another project)
 | 
			
		||||
 | 
			
		||||
   int num_processes = 0, num_resources = 0;
 | 
			
		||||
   char line[MAX_LINE_LEN]; // Lines can be no more than 1KB in size, a sensible limitation
 | 
			
		||||
   while (!feof(f)) {
 | 
			
		||||
      //* A line starting with a % is a comment, and should be skipped
 | 
			
		||||
      // if %:
 | 
			
		||||
         continue;
 | 
			
		||||
      //* A blank line should be skipped
 | 
			
		||||
      // if blank:
 | 
			
		||||
         continue;
 | 
			
		||||
      //* A line starting with `num_processes=` contains the number of processes
 | 
			
		||||
      //if "num_processes":
 | 
			
		||||
         num_processes = 0; // TODO: Read file
 | 
			
		||||
      //* A line starting with `num_resources=` contains the number of resources
 | 
			
		||||
      //if "num_resources":
 | 
			
		||||
         num_resources = 0;
 | 
			
		||||
      // TODO: create graph 'object' here
 | 
			
		||||
      //* A line containing num_resources numbers follows, indicating the number of each resource
 | 
			
		||||
      //* Resources are comma-separated, so there can never be more than 1/2 as many as max line length
 | 
			
		||||
         int resource_counts[MAX_LINE_LEN/2];
 | 
			
		||||
      //* A comma-separated, newline-separated adjacency matrix with which to reduce
 | 
			
		||||
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
   // TODO: Close file
 | 
			
		||||
   // TODO: Check for file IO errors (Shouldn't be any)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user