-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.h
More file actions
138 lines (129 loc) · 2.64 KB
/
global.h
File metadata and controls
138 lines (129 loc) · 2.64 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef GLOBAL_VARIABLES
#define GLOBAL_VARIABLES
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/utsname.h>
#include <pwd.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <grp.h>
#include <signal.h>
char shelldir[1000];
int Shell_Id;
const char *DELIMITER = " \t\r\n\a";
char months[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
const int MAX_ARGUMENTS = 1024;
int numargs;
int numcommands;
int curFgProc;
char **commands;
char **commandsHere;
char **allCommands;
char lastpwd[1000];
char *history[20];
int first_hist, size_hist;
int bgcommands_num = 0;
int bgprocesses_ID[1000];
char bgprocesses_name[1000][1000];
time_t start_sec = 0, end_Sec = 0;
int kb_interrupt = 0;
int copyOfStdIn;
int changedStdIn;
int changedStdOut;
int copyOfStdOut;
int check;
void prompt();
void exit_fun();
char *my_itoa(int val)
{
static char buf[32] = {0};
int i = 30;
for (; val && i; --i, val /= 10)
{
buf[i] = "0123456789abcdef"[val % 10];
}
return &buf[i + 1];
}
int str_is_num(char *str)
{
int len = strlen(str);
for (int i = 0; i < len; i++)
{
if (str[i] < '0' || str[i] > '9')
{
return 0;
}
}
return 1;
}
int my_atoi(char *str)
{
int len = strlen(str);
int ret = 0;
for (int i = 0; i < len; i++)
{
ret *= 10;
ret += (str[i] - '0');
}
return ret;
}
void string_prepend(char *s, char *suffix)
{
char temp[2000] = {'\0'};
for (int i = 0; i < strlen(suffix); i++)
{
temp[i] = suffix[i];
}
for (int i = 0; i < strlen(s); i++)
{
temp[i + strlen(suffix)] = s[i];
}
for (int i = 0; i < strlen(temp); i++)
{
s[i] = temp[i];
}
}
void remove_suffix(char *s, int n)
{
int len = strlen(s);
for (int i = 0; i + n < len; i++)
s[i] = s[i + n];
for (int i = strlen(s) - n; i < len; i++)
s[i] = '\0';
}
int string_contains(char *strtarget, char *strfind)
{
int n = strlen(strtarget);
int m = strlen(strfind);
if (m == 0)
return 1;
for (int i = 0; i < n; i++)
{
int contains = 1;
for (int j = 0; j < m; j++)
{
if (i + j >= n)
{
contains = 0;
break;
}
if (strtarget[i + j] != strfind[j])
{
contains = 0;
break;
}
}
if (contains)
return 1;
}
return 0;
}
#endif