Skip to content

Commit c032ded

Browse files
committed
Assignment1 added
1 parent 8455a0b commit c032ded

9 files changed

+787
-0
lines changed

_DS_Store

6 KB
Binary file not shown.

dberror.c

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "dberror.h"
2+
3+
#include <string.h>
4+
#include <stdlib.h>
5+
#include <stdio.h>
6+
7+
char *RC_message;
8+
9+
/* print a message to standard out describing the error */
10+
void
11+
printError (RC error)
12+
{
13+
if (RC_message != NULL)
14+
printf("EC (%i), \"%s\"\n", error, RC_message);
15+
else
16+
printf("EC (%i)\n", error);
17+
}
18+
19+
char *
20+
errorMessage (RC error)
21+
{
22+
char *message;
23+
24+
if (RC_message != NULL)
25+
{
26+
message = (char *) malloc(strlen(RC_message) + 30);
27+
sprintf(message, "EC (%i), \"%s\"\n", error, RC_message);
28+
}
29+
else
30+
{
31+
message = (char *) malloc(30);
32+
sprintf(message, "EC (%i)\n", error);
33+
}
34+
35+
return message;
36+
}

dberror.h

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef DBERROR_H
2+
#define DBERROR_H
3+
4+
#include "stdio.h"
5+
6+
/* module wide constants */
7+
#define PAGE_SIZE 4096
8+
9+
/* return code definitions */
10+
typedef int RC;
11+
12+
#define RC_OK 0
13+
#define RC_FILE_NOT_FOUND 1
14+
#define RC_FILE_HANDLE_NOT_INIT 2
15+
#define RC_WRITE_FAILED 3
16+
#define RC_READ_NON_EXISTING_PAGE 4
17+
#define RC_ERROR 5 //added by Rakesh
18+
19+
#define RC_RM_COMPARE_VALUE_OF_DIFFERENT_DATATYPE 200
20+
#define RC_RM_EXPR_RESULT_IS_NOT_BOOLEAN 201
21+
#define RC_RM_BOOLEAN_EXPR_ARG_IS_NOT_BOOLEAN 202
22+
#define RC_RM_NO_MORE_TUPLES 203
23+
#define RC_RM_NO_PRINT_FOR_DATATYPE 204
24+
#define RC_RM_UNKOWN_DATATYPE 205
25+
26+
#define RC_IM_KEY_NOT_FOUND 300
27+
#define RC_IM_KEY_ALREADY_EXISTS 301
28+
#define RC_IM_N_TO_LAGE 302
29+
#define RC_IM_NO_MORE_ENTRIES 303
30+
31+
/* holder for error messages */
32+
extern char *RC_message;
33+
34+
/* print a message to standard out describing the error */
35+
extern void printError (RC error);
36+
extern char *errorMessage (RC error);
37+
38+
#define THROW(rc,message) \
39+
do { \
40+
RC_message=message; \
41+
return rc; \
42+
} while (0) \
43+
44+
// check the return code and exit if it is an error
45+
#define CHECK(code) \
46+
do { \
47+
int rc_internal = (code); \
48+
if (rc_internal != RC_OK) \
49+
{ \
50+
char *message = errorMessage(rc_internal); \
51+
printf("[%s-L%i-%s] ERROR: Operation returned error: %s\n",__FILE__, __LINE__, __TIME__, message); \
52+
free(message); \
53+
exit(1); \
54+
} \
55+
} while(0);
56+
57+
58+
#endif

makefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
CC = gcc
2+
CFLAGS = -g -Wall
3+
4+
default: test1
5+
6+
test1: test_assign1_1.o storage_mgr.o dberror.o
7+
$(CC) $(CFLAGS) -o test1 test_assign1_1.o storage_mgr.o dberror.o -lm
8+
9+
test2: test_assign1_2.o storage_mgr.o dberror.o
10+
$(CC) $(CFLAGS) -o test2 test_assign1_2.o storage_mgr.o dberror.o -lm
11+
12+
test_assign1_1.o: test_assign1_1.c dberror.h storage_mgr.h test_helper.h
13+
$(CC) $(CFLAGS) -c test_assign1_1.c -lm
14+
15+
test_assign1_2.o: test_assign1_2.c dberror.h storage_mgr.h test_helper.h
16+
$(CC) $(CFLAGS) -c test_assign1_2.c -lm
17+
18+
storage_mgr.o: storage_mgr.c storage_mgr.h
19+
$(CC) $(CFLAGS) -c storage_mgr.c -lm
20+
21+
dberror.o: dberror.c dberror.h
22+
$(CC) $(CFLAGS) -c dberror.c
23+
24+
clean:
25+
$(RM) test1 test2 *.o *~
26+
27+
run:
28+
./test1
29+
30+
run2:
31+
./test2

0 commit comments

Comments
 (0)