-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.c
191 lines (151 loc) · 3.18 KB
/
general.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
General C Routines Source Code
Copyright (c) 1993, 1994 Boyd C. Fletcher
*/
#include "general.h"
void Remove_CR(char *str)
{
int i;
for (i=0;i <= strlen(str); i++)
{
if (str[i] == '\n')
{
str[i] = '\0';
}
}
}
void UpcaseWord(char *str)
{
int i;
for (i=0;i <= strlen(str); i++)
{
str[i] = toupper(str[i]);
}
}
void Remove_CTRL(char *str)
{
int i;
for (i=0;i <= strlen(str); i++)
{
if (str[i] != '\0')
{
if ((str[i] < 32) || (str[i] >= 127))
{
str[i] = '\0';
}
}
}
}
int Is_All_Spaces(char *str)
{
int i;
int All_Spaces = TRUE;
for (i=0;i < strlen(str); i++)
{
if (str[i] != ' ')
{
All_Spaces = FALSE;
}
}
return (All_Spaces);
}
void Add_Hrs_Mins(int *New_Hours,
int *New_Minutes,
int Old_Hours,
int Old_Minutes)
{
int Hrs = 0,
Mins = 0;
/* printf("OLD HOURS: %d MINUTES: %d\n",Old_Hours,Old_Minutes); */
Mins = (Old_Hours*60) + Old_Minutes;
Hrs = Mins / 60;
Mins = Mins % 60;
*New_Hours = Hrs;
*New_Minutes = Mins;
/* printf("HOURS: %d MINUTES: %d\n",Hrs,Mins); */
/* printf("NEW HOURS: %d MINUTES: %d\n",*New_Hours,*New_Minutes); */
}
void Subtract_Hrs_Mins(int *New_Hours,
int *New_Minutes,
int Old_Hours,
int Old_Minutes)
{
int Hrs = 0,
Mins = 0;
printf("OLD HOURS: %d MINUTES: %d\n",Old_Hours,Old_Minutes);
Mins = (Old_Hours*60) + Old_Minutes;
Hrs = Mins / 60;
Mins = Mins % 60;
printf("HOURS: %d MINUTES: %d\n",Hrs,Mins);
*New_Hours = Hrs;
*New_Minutes = Mins;
printf("NEW HOURS: %d MINUTES: %d\n",*New_Hours,*New_Minutes);
}
char *Get_Current_Date()
{
static char Date_Str[80];
time_t Date_Enc;
struct tm *Date_Struct;
time(&Date_Enc);
Date_Struct = localtime(&Date_Enc);
strftime(Date_Str,80,"%x",Date_Struct);
return Date_Str;
}
#ifdef SUNOS
time_t Get_Current_Date_Num()
{
time_t Date_Enc;
struct tm *Date_Struct;
time(&Date_Enc);
Date_Struct = localtime(&Date_Enc);
return timelocal(Date_Struct);
}
#endif
char *Return_Current_Date(time_t Date_Enc)
{
static char Date_Str[80];
struct tm *Date_Struct;
Date_Struct = localtime(&Date_Enc);
strftime(Date_Str,80,"%x",Date_Struct);
return Date_Str;
}
char *Return_Current_Date_Time(time_t Date_Enc)
{
static char Date_Str[80];
struct tm *Date_Struct;
Date_Struct = localtime(&Date_Enc);
strftime(Date_Str,80,"%x %X: ",Date_Struct);
return Date_Str;
}
char *Get_Current_Time()
{
static char Time_Str[80];
time_t Time_Enc;
struct tm *Time_Struct;
time(&Time_Enc);
Time_Struct = localtime(&Time_Enc);
strftime(Time_Str,80,"%X",Time_Struct);
return Time_Str;
}
char *Get_Current_Date_Time(char *Format)
{
static char Time_Str[80];
time_t Time_Enc;
struct tm *Time_Struct;
time(&Time_Enc);
Time_Struct = localtime(&Time_Enc);
strftime(Time_Str,80,Format,Time_Struct);
return Time_Str;
}
void Strip_White(char *string)
{
register int i = 0;
while (whitespace (string[i]))
i++;
if (i)
strcpy (string, string + i);
i = strlen (string) - 1;
while (i > 0 && whitespace (string[i]))
i--;
string[++i] = '\0';
}