summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/RESTORE/RTT2.C
diff options
context:
space:
mode:
authorGravatar Mark Zbikowski2024-04-25 21:24:10 +0100
committerGravatar Microsoft Open Source2024-04-25 22:32:27 +0000
commit2d04cacc5322951f187bb17e017c12920ac8ebe2 (patch)
tree80ee017efa878dfd5344b44249e6a241f2a7f6e2 /v4.0/src/CMD/RESTORE/RTT2.C
parentMerge pull request #430 from jpbaltazar/typoptbr (diff)
downloadms-dos-main.tar.gz
ms-dos-main.tar.xz
ms-dos-main.zip
MZ is back!HEADmain
Diffstat (limited to 'v4.0/src/CMD/RESTORE/RTT2.C')
-rw-r--r--v4.0/src/CMD/RESTORE/RTT2.C488
1 files changed, 488 insertions, 0 deletions
diff --git a/v4.0/src/CMD/RESTORE/RTT2.C b/v4.0/src/CMD/RESTORE/RTT2.C
new file mode 100644
index 0000000..92d50de
--- /dev/null
+++ b/v4.0/src/CMD/RESTORE/RTT2.C
@@ -0,0 +1,488 @@
1static char *SCCSID = "@(#)rtt2.c 8.4 86/10/19";
2/*  0 */
3#include <direct.h>
4#include "rt.h"
5#include "rt1.h"
6#include "rt2.h"
7#include <comsub.h> /* common subroutine def'n */
8#include <doscalls.h>
9#include <wrwdefs.h> /* wrw! */
10
11extern unsigned char rtswitch;
12extern unsigned char control_flag;
13extern unsigned char control_flag2;
14extern struct internat ctry; /* data area for country info*/
15
16/***************** START OF SPECIFICATION *********************************/
17/* */
18/* SUBROUTINE NAME : valid_input_time */
19/* */
20/* DESCRIPTIVE NAME : to validate and convert the time input from the */
21/* command line. */
22/* */
23/* FUNCTION: This subroutine validate the time input from the command lin */
24/* against the country dependent information, and convert */
25/* the deta into three integers which are hour, minute, and */
26/* second. */
27/* NOTES: */
28/* */
29/* INPUT: (PARAMETERS) */
30/* in_string - the string from command line which contains date */
31/* information. */
32/* OUTPUT: */
33/* inhour - the input hour after converted */
34/* inminute - the input minute after converted */
35/* insecond - the input second after converted */
36/* */
37/* EXIT-NORMAL: returns TRUE if the time is valid */
38/* */
39/* EXIT-ERROR: returns FALSE if the time is invalid */
40/* */
41/* EFFECTS: */
42/* */
43/* INTERNAL REFERENCES: */
44/* ROUTINES: */
45/* usererror */
46/* unexperror */
47/* putmsg */
48/* set_reset_test_flag */
49/* */
50/* EXTERNAL REFERENCES: */
51/* ROUTINES: */
52/* */
53/********************** END OF SPECIFICATIONS *******************************/
54int valid_input_time(in_string, inhour, inminute, insecond)
55 unsigned char *in_string; /*the input string */
56 unsigned int *inhour; /*the input hour */
57 unsigned int *inminute; /*the input minute */
58 unsigned int *insecond; /*the input second */
59{
60 unsigned char chour[10];
61 unsigned char cminute[10];
62 unsigned char csecond[10];
63 unsigned int i,j,z; /*working pointer*/
64 unsigned int no_second = FALSE;
65 unsigned char string[20];
66
67 /*declaration for get country information*/
68 unsigned int byte_len;
69 unsigned buflen = sizeof( struct internat ); /* length of data area */
70 unsigned int retcode;
71 long country = 0L;
72
73 /************************************************/
74 /* find the string for hour */
75 /************************************************/
76 #ifdef DEBUG
77 printf("\ntime to be validate %s",in_string);
78 #endif
79 /*save the pointer of input string*/
80 strcpy(string,in_string);
81
82 /* search the first occurance of country->timesep */
83 for (i = 0; (string[i] != NULLC) && (string[i] != ctry.timesep &&
84 string[i] != ':' && string[i] != '.'); ++i);
85
86 if (string[i] == NULLC) { /*if not found*/
87 #ifdef DEBUG
88 printf("\nno time seperator");
89 #endif
90 return(FALSE);
91 }
92
93 string[i] = NULLC; /*replace it with NULLC*/
94
95 /*get the string which represent hour*/
96 strcpy(chour,string);
97 /*put the rest of the string into cminute*/
98 strcpy(cminute,string+i+1);
99
100 /************************************************/
101 /* validate hour */
102 /************************************************/
103 if (strlen(chour) > MAXHOURLEN || strlen(chour)<1 ) {
104 #ifdef DEBUG
105 printf("\ninvalid hour length");
106 #endif
107 return(FALSE);
108 }
109
110 /* convert the string into integer form*/
111 *inhour = 0;
112 for (j=0; chour[j] != NULLC ; ++j) {
113 if (chour[j] < '0' || chour[j] > '9') {
114 #ifdef DEBUG
115 printf("\nhour value not 0-9");
116 #endif
117 return(FALSE);
118 }
119 *inhour = *inhour*10 + chour[j]-'0';
120 }
121
122 if (*inhour > 23 || *inhour < 0) {
123 #ifdef DEBUG
124 printf("\ninvalid hour value");
125 #endif
126 return(FALSE);
127 }
128
129 /************************************************/
130 /* find the string for minute */
131 /************************************************/
132 /*search the next occurance of country->timesep*/
133 for (i = 0; (cminute[i] != NULLC) && (cminute[i] != ctry.timesep &&
134 cminute[i] != ':' && cminute[i] != '.'); ++i);
135
136 if (cminute[i] == NULLC) { /*if not found*/
137 no_second = TRUE;
138 }
139
140 /*put NULLC at the end of string which represent minute*/
141 cminute[i] = NULLC; /*replace it with NULLC*/
142 strcpy(csecond,cminute+i+1);
143
144 /************************************************/
145 /* validate minute */
146 /************************************************/
147 if (strlen(cminute) > MAXMINUTELEN || strlen(cminute)<1 ) {
148 #ifdef DEBUG
149 printf("\ninvalid min length");
150 #endif
151 return(FALSE);
152 }
153
154 /*convert the string into integer*/
155 *inminute = 0;
156 for (j=0; cminute[j] != NULLC ; ++j) {
157 if (cminute[j] < '0' || cminute[j] > '9') {
158 #ifdef DEBUG
159 printf("\ninvalid min value, not 0-9");
160 #endif
161 return(FALSE);
162 }
163 *inminute = *inminute*10 + cminute[j]-'0';
164 }
165
166 if (*inminute > 59 || *inminute < 0) {
167 #ifdef DEBUG
168 printf("\ninvalid min value");
169 #endif
170 return(FALSE);
171 }
172
173 /***************************************************/
174 /* if user input second, get the string for second */
175 /***************************************************/
176 if (no_second == TRUE)
177 return(TRUE);
178 else {
179
180 /************************************************/
181 /* validate second */
182 /************************************************/
183 if (strlen(csecond) > MAXSECONDLEN || strlen(csecond) < 1 ) {
184 #ifdef DEBUG
185 printf("\ninvalid second length");
186 #endif
187 return(FALSE);
188 }
189
190 /*convert the rest of the string into integer*/
191 *insecond = 0;
192 for (j=0; csecond[j] != NULLC; ++j)
193 {
194 if (csecond[j] < '0' || csecond[j] > '9') {
195 #ifdef DEBUG
196 printf("\ninvalid second, 0-9");
197 #endif
198 return(FALSE);
199 }
200 *insecond = *insecond*10 + csecond[j]-'0';
201 }
202
203 if (*insecond > 59 || *insecond < 0) {
204 #ifdef DEBUG
205 printf("\ninvalid second value");
206 #endif
207 return(FALSE);
208 }
209 } /*end of if no_second is true */
210 return(TRUE);
211
212} /*end of subroutine*/
213/***************** START OF SPECIFICATION *********************************/
214/* */
215/* SUBROUTINE NAME : valid_input_date */
216/* */
217/* DESCRIPTIVE NAME : to validate and convert the date input from the */
218/* command line. */
219/* */
220/* FUNCTION: This subroutine validate the date input from the command lin */
221/* against the country dependent information, and convert */
222/* the deta into three integers which are year, month, and day. */
223/* NOTES: */
224/* */
225/* INPUT: (PARAMETERS) */
226/* in_string - the string from command line which contains date */
227/* information. */
228/* OUTPUT: */
229/* inyear - the input year after converted */
230/* inmonth - the input month after converted */
231/* inday - the input day after converted */
232/* */
233/* EXIT-NORMAL: returns TRUE if the date is valid */
234/* */
235/* EXIT-ERROR: returns FALSE if the date is invalid */
236/* */
237/* EFFECTS: */
238/* */
239/* INTERNAL REFERENCES: */
240/* ROUTINES: */
241/* usererror */
242/* unexperror */
243/* putmsg */
244/* set_reset_test_flag */
245/* */
246/* EXTERNAL REFERENCES: */
247/* ROUTINES: */
248/* */
249/********************** END OF SPECIFICATIONS *******************************/
250int valid_input_date(in_string,inyear,inmonth,inday)
251
252 unsigned char *in_string;
253 unsigned int *inyear;
254 unsigned int *inmonth;
255 unsigned int *inday;
256{
257 unsigned char c1[10];
258 unsigned char c2[10];
259 unsigned char c3[10];
260 unsigned char cyear[10];
261 unsigned char cmonth[10];
262 unsigned char cday[10];
263 unsigned int in1;
264 unsigned int in2;
265 unsigned int in3;
266 unsigned int i,j,z; /*working pointer*/
267 unsigned char string[30];
268 unsigned int remainder;
269
270 #ifdef DEBUG
271 printf("\ndate to be validate %s",in_string);
272 #endif
273 /************************************************/
274 /* separate the input date string into 3 parts */
275 /************************************************/
276 /*save the pointer to the input string*/
277 strcpy(string,in_string);
278
279 /* search the first occurance of country->datesep */
280 for (i = 0; (string[i] != NULLC) && (string[i] != ctry.datesep &&
281 string[i] != '/' && string[i] != '-' && string[i] != '.'); ++i);
282
283 if (string[i] == NULLC) { /*if not found*/
284 #ifdef DEBUG
285 printf("\ninvalid date sep");
286 #endif
287 return(FALSE);
288 }
289
290 string[i] = NULLC; /*replace it with NULLC*/
291
292 /*get the string which represent year*/
293 strcpy(c1,string);
294 /*put the rest of the string into c2*/
295 strcpy(c2,string+i+1);
296
297 /*search the next occurance of country->datesep*/
298 for (i = 0; (c2[i] != NULLC) && (c2[i] != ctry.datesep &&
299 c2[i] != '/' && c2[i] != '-' && c2[i] != '.'); ++i);
300
301 if (c2[i] == NULLC) { /*if not found*/
302 #ifdef DEBUG
303 printf("\nno 2nd date sep");
304 #endif
305 return(FALSE);
306 }
307
308 /*put NULLC at the end of string which represent month*/
309 c2[i] = NULLC; /*replace it with NULLC*/
310 strcpy(c3,c2+i+1);
311
312 /************************************************/
313 /* convert all 3 strings to integers */
314 /************************************************/
315 in1 = 0;
316 for (j=0; c1[j] != NULLC ; ++j) {
317 if (c1[j] < '0' || c1[j] > '9') {
318 #ifdef DEBUG
319 printf("\ninvalid 1st in date not 0-9");
320 #endif
321 return(FALSE);
322 }
323 in1 = in1*10 + c1[j]-'0';
324 }
325
326 in2 = 0;
327 for (j=0; c2[j] != NULLC ; ++j) {
328 if (c2[j] < '0' || c2[j] > '9') {
329 #ifdef DEBUG
330 printf("\ninvalid 2nd in date not 0-9");
331 #endif
332 return(FALSE);
333 }
334 in2 = in2*10 + c2[j]-'0';
335 }
336
337 in3 = 0;
338 for (j=0; c3[j] != NULLC ; ++j) {
339 if (c3[j] < '0' || c3[j] > '9') {
340 #ifdef DEBUG
341 printf("\ninvalid 3rd in date not 0-9");
342 #endif
343 return(FALSE);
344 }
345 in3 = in3*10 + c3[j]-'0';
346 }
347 /************************************************/
348 /* identify what these 3 integers are stand for */
349 /************************************************/
350 switch (ctry.dtformat) {
351 case USA:
352 *inmonth = in1;
353 *inday = in2;
354 *inyear = in3;
355 strcpy(cmonth,c1);
356 strcpy(cday,c2);
357 strcpy(cyear,c3);
358 break;
359 case EUR:
360 *inday = in1;
361 *inmonth = in2;
362 *inyear = in3;
363 strcpy(cday,c1);
364 strcpy(cmonth,c2);
365 strcpy(cyear,c3);
366 break;
367 case JAP:
368 *inyear = in1;
369 *inmonth = in2;
370 *inday = in3;
371 strcpy(cyear,c1);
372 strcpy(cmonth,c2);
373 strcpy(cday,c3);
374 break;
375 default:
376 #ifdef DEBUG
377 printf("\ninvalid country code %d",ctry.dtformat);
378 #endif
379 unexperror(UNEXPECTED);
380 break;
381 }
382 /************************************************/
383 /* validate the value of year */
384 /************************************************/
385 if (strlen(cyear) > MAXYEARLEN || strlen(cyear)<1 ) {
386 #ifdef DEBUG
387 printf("\ninvalid year len");
388 #endif
389 return(FALSE);
390 }
391
392 if (*inyear <= 99 && *inyear >= 80)
393 *inyear = *inyear + 1900;
394 if (*inyear <= 79 && *inyear >= 00)
395 *inyear = *inyear + 2000;
396
397 /*validate the value of year */
398 if (*inyear > MAXYEAR || *inyear < MINYEAR) {
399 #ifdef DEBUG
400 printf("\ninvalid year value");
401 #endif
402 return(FALSE);
403 }
404
405 /************************************************/
406 /* validate the value of month */
407 /************************************************/
408 if (strlen(cmonth) > MAXMONTHLEN || strlen(cmonth)<1 ) {
409 #ifdef DEBUG
410 printf("\ninvalid month length");
411 #endif
412 return(FALSE);
413 }
414
415 /*validate the value of year */
416 if (*inmonth > MAXMONTH || *inmonth <= 0) {
417 #ifdef DEBUG
418 printf("\ninvalid month value");
419 #endif
420 return(FALSE);
421 }
422
423 /************************************************/
424 /* validate the value of day */
425 /************************************************/
426 if (strlen(cday) > MAXDAYLEN || strlen(cday)<1 ) {
427 #ifdef DEBUG
428 printf("\ninvalid day len");
429 #endif
430 return(FALSE);
431 }
432
433 /*validate the value of year */
434 if (*inday > MAXDAY || *inday <= 0 ) {
435 #ifdef DEBUG
436 printf("\ninvalid day value");
437 #endif
438 return(FALSE);
439 }
440 if ((*inmonth == 1 || *inmonth == 3 || *inmonth == 5 ||
441 *inmonth == 7 || *inmonth == 8 || *inmonth == 10 ||
442 *inmonth == 12 ) && (*inday > 31 || *inday < 1)) {
443 #ifdef DEBUG
444 printf("\ninvalid day value");
445 #endif
446 return(FALSE);
447 }
448 else {
449 if ((*inmonth == 4 || *inmonth == 6 || *inmonth == 9 ||
450 *inmonth == 11 ) && (*inday > 30 || *inday < 1)) {
451 #ifdef DEBUG
452 printf("\ninvalid day value");
453 #endif
454 return(FALSE);
455 }
456 else {
457 if (*inmonth == 2) {
458 /*check for leap year */
459 remainder = *inyear % 4;
460 if (remainder == 0) {
461 if (*inday > 29 || *inday < 1) {
462 #ifdef DEBUG
463 printf("\ninvalid day value");
464 #endif
465 return(FALSE);
466 }
467 }
468 else {
469 if (*inday > 28 || *inday < 1) {
470 #ifdef DEBUG
471 printf("\ninvalid day value");
472 #endif
473 return(FALSE);
474 }
475 }
476 }
477 }
478 }
479
480 /************************************************/
481 /* if there is no error found, return TRUE */
482 /************************************************/
483 return(TRUE);
484
485} /*end of subroutine valid_input_date*/
486
487/**************************/
488 \ No newline at end of file