/
shared.c
67 lines (54 loc) · 1.43 KB
/
shared.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* shared.c
*
* Implements all shared subroutines
*/
#include "shared.h"
/* -----------------------------------------------------------------------
* Returns a hashkey value for the given lexeme
* -----------------------------------------------------------------------
*/
int makekey(char* lexeme, int max_hashkeys)
{
int len;
int i;
long charsum = 0;
len = strlen(lexeme);
for (i = 0; i < len; i++){
charsum += lexeme[i];
}
return charsum % max_hashkeys;
}
/* -----------------------------------------------------------------------
* Prints the specified amount of tabs
* -----------------------------------------------------------------------
*/
void print_tabs(int numOfTabs)
{
int i = 0;
while (i < numOfTabs) {
printf("\t");
i++;
}
}
/* -----------------------------------------------------------------------
* Returns a string representation of the int value
* -----------------------------------------------------------------------
*/
char *inttostring(int value)
{
char *s;
s = (char *) malloc(MAX_NEW_CHAR_SIZE);
sprintf(s, "%d", value);
return s;
}
/* -----------------------------------------------------------------------
* Returns a string representation of the long value
* -----------------------------------------------------------------------
*/
char *longtostring(long value)
{
char *s;
s = (char *) malloc(MAX_NEW_CHAR_SIZE);
sprintf(s, "%ld", value);
return s;
}