summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/RESTORE/RTT2.C
blob: 92d50ded3bd1536e7bc2e9646da77db5bec39c3d (plain) (blame)
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
static char *SCCSID = "@(#)rtt2.c       8.4 86/10/19";
/*  0 */
#include <direct.h>
#include "rt.h"
#include "rt1.h"
#include "rt2.h"
#include <comsub.h>			/* common subroutine def'n */
#include <doscalls.h>
#include <wrwdefs.h>		   /* wrw! */

extern unsigned char rtswitch;
extern unsigned char control_flag;
extern unsigned char control_flag2;
extern struct internat ctry;	       /* data area for country info*/

/*****************  START OF SPECIFICATION  *********************************/
/*									    */
/*  SUBROUTINE NAME :  valid_input_time 				    */
/*									    */
/*  DESCRIPTIVE NAME :	to validate and convert the time input from the     */
/*			command line.					    */
/*									    */
/*  FUNCTION: This subroutine validate the time input from the command lin  */
/*	      against the country dependent information, and convert	    */
/*	      the deta into three integers which are hour, minute, and	    */
/*	      second.							    */
/*  NOTES:								    */
/*									    */
/*  INPUT: (PARAMETERS) 						    */
/*	    in_string - the string from command line which contains date    */
/*		     information.					    */
/*  OUTPUT:								    */
/*	    inhour - the input hour after converted			    */
/*	    inminute - the input minute after converted 		    */
/*	    insecond - the input second after converted 		    */
/*									    */
/*  EXIT-NORMAL: returns TRUE if the time is valid			    */
/*									    */
/*  EXIT-ERROR:  returns FALSE if the time is invalid			    */
/*									    */
/*  EFFECTS:								    */
/*									    */
/*  INTERNAL REFERENCES:						    */
/*	   ROUTINES:							    */
/*		    usererror						    */
/*		    unexperror						    */
/*		    putmsg						    */
/*		    set_reset_test_flag 				    */
/*									    */
/*  EXTERNAL REFERENCES:						    */
/*	   ROUTINES:							    */
/*									    */
/********************** END OF SPECIFICATIONS *******************************/
int valid_input_time(in_string, inhour, inminute, insecond)
    unsigned char *in_string;  /*the input string			*/
    unsigned int  *inhour;     /*the input hour 			*/
    unsigned int  *inminute;   /*the input minute			*/
    unsigned int  *insecond;   /*the input second			*/
{
    unsigned char chour[10];
    unsigned char cminute[10];
    unsigned char csecond[10];
    unsigned int i,j,z;    /*working pointer*/
    unsigned int no_second = FALSE;
    unsigned char string[20];

    /*declaration for get country information*/
    unsigned int byte_len;
    unsigned buflen = sizeof( struct internat );    /* length of data area  */
    unsigned int retcode;
    long country = 0L;

   /************************************************/
   /* find the string for hour			   */
   /************************************************/
   #ifdef DEBUG
   printf("\ntime to be validate %s",in_string);
   #endif
   /*save the pointer of input string*/
   strcpy(string,in_string);

   /* search the first occurance of country->timesep */
   for (i = 0; (string[i] != NULLC) && (string[i] != ctry.timesep &&
   string[i] != ':' && string[i] != '.'); ++i);

   if (string[i] == NULLC) {  /*if not found*/
       #ifdef DEBUG
       printf("\nno time seperator");
       #endif
       return(FALSE);
   }

   string[i] = NULLC;	  /*replace it with NULLC*/

   /*get the string which represent hour*/
   strcpy(chour,string);
   /*put the rest of the string into cminute*/
   strcpy(cminute,string+i+1);

   /************************************************/
   /* validate hour				   */
   /************************************************/
   if (strlen(chour) > MAXHOURLEN || strlen(chour)<1 ) {
       #ifdef DEBUG
       printf("\ninvalid hour length");
       #endif
       return(FALSE);
   }

   /* convert the string into integer form*/
   *inhour = 0;
   for (j=0; chour[j] != NULLC ; ++j) {
       if (chour[j] < '0' || chour[j] > '9') {
	  #ifdef DEBUG
	  printf("\nhour value not 0-9");
	  #endif
	  return(FALSE);
       }
       *inhour = *inhour*10 + chour[j]-'0';
   }

   if (*inhour > 23 || *inhour < 0) {
	   #ifdef DEBUG
	   printf("\ninvalid hour value");
	   #endif
	   return(FALSE);
   }

   /************************************************/
   /* find the string for minute		   */
   /************************************************/
   /*search the next occurance of country->timesep*/
   for (i = 0; (cminute[i] != NULLC) && (cminute[i] != ctry.timesep &&
   cminute[i] != ':' && cminute[i] != '.'); ++i);

   if (cminute[i] == NULLC) {  /*if not found*/
      no_second = TRUE;
   }

   /*put NULLC at the end of string which represent minute*/
   cminute[i] = NULLC;	   /*replace it with NULLC*/
   strcpy(csecond,cminute+i+1);

   /************************************************/
   /* validate minute				   */
   /************************************************/
   if (strlen(cminute) > MAXMINUTELEN || strlen(cminute)<1 ) {
      #ifdef DEBUG
      printf("\ninvalid min length");
      #endif
      return(FALSE);
   }

   /*convert the string into integer*/
   *inminute = 0;
   for (j=0; cminute[j] != NULLC ; ++j) {
       if (cminute[j] < '0' || cminute[j] > '9')  {
	  #ifdef DEBUG
	  printf("\ninvalid min value, not 0-9");
	  #endif
	  return(FALSE);
       }
       *inminute = *inminute*10 + cminute[j]-'0';
   }

   if (*inminute > 59 || *inminute < 0) {
	   #ifdef DEBUG
	   printf("\ninvalid min value");
	   #endif
	   return(FALSE);
   }

   /***************************************************/
   /* if user input second, get the string for second */
   /***************************************************/
   if (no_second == TRUE)
       return(TRUE);
   else {

       /************************************************/
       /* validate second			       */
       /************************************************/
       if (strlen(csecond) > MAXSECONDLEN || strlen(csecond) < 1 ) {
	  #ifdef DEBUG
	  printf("\ninvalid second length");
	  #endif
	  return(FALSE);
       }

       /*convert the rest of the string into integer*/
       *insecond = 0;
       for (j=0; csecond[j] != NULLC; ++j)
       {
	   if (csecond[j] < '0' || csecond[j] > '9') {
	      #ifdef DEBUG
	      printf("\ninvalid second, 0-9");
	      #endif
	      return(FALSE);
	   }
	   *insecond = *insecond*10 + csecond[j]-'0';
       }

       if (*insecond > 59 || *insecond < 0) {
	       #ifdef DEBUG
	       printf("\ninvalid second value");
	       #endif
	       return(FALSE);
       }
   } /*end of if no_second is true */
   return(TRUE);

} /*end of subroutine*/
/*****************  START OF SPECIFICATION  *********************************/
/*									    */
/*  SUBROUTINE NAME :  valid_input_date 				    */
/*									    */
/*  DESCRIPTIVE NAME :	to validate and convert the date input from the     */
/*			command line.					    */
/*									    */
/*  FUNCTION: This subroutine validate the date input from the command lin  */
/*	      against the country dependent information, and convert	    */
/*	      the deta into three integers which are year, month, and day.  */
/*  NOTES:								    */
/*									    */
/*  INPUT: (PARAMETERS) 						    */
/*	    in_string - the string from command line which contains date    */
/*		     information.					    */
/*  OUTPUT:								    */
/*	    inyear - the input year after converted			    */
/*	    inmonth - the input month after converted			    */
/*	    inday - the input day after converted			    */
/*									    */
/*  EXIT-NORMAL: returns TRUE if the date is valid			    */
/*									    */
/*  EXIT-ERROR:  returns FALSE if the date is invalid			    */
/*									    */
/*  EFFECTS:								    */
/*									    */
/*  INTERNAL REFERENCES:						    */
/*	   ROUTINES:							    */
/*		    usererror						    */
/*		    unexperror						    */
/*		    putmsg						    */
/*		    set_reset_test_flag 				    */
/*									    */
/*  EXTERNAL REFERENCES:						    */
/*	   ROUTINES:							    */
/*									    */
/********************** END OF SPECIFICATIONS *******************************/
int valid_input_date(in_string,inyear,inmonth,inday)

    unsigned char *in_string;
    unsigned int  *inyear;
    unsigned int  *inmonth;
    unsigned int  *inday;
{
    unsigned char c1[10];
    unsigned char c2[10];
    unsigned char c3[10];
    unsigned char cyear[10];
    unsigned char cmonth[10];
    unsigned char cday[10];
    unsigned int  in1;
    unsigned int  in2;
    unsigned int  in3;
    unsigned int i,j,z;    /*working pointer*/
    unsigned char string[30];
    unsigned int  remainder;

   #ifdef DEBUG
   printf("\ndate to be validate %s",in_string);
   #endif
   /************************************************/
   /* separate the input date string into 3 parts  */
   /************************************************/
   /*save the pointer to the input string*/
   strcpy(string,in_string);

   /* search the first occurance of country->datesep */
   for (i = 0; (string[i] != NULLC) && (string[i] != ctry.datesep &&
   string[i] != '/' && string[i] != '-' && string[i] != '.'); ++i);

   if (string[i] == NULLC) {  /*if not found*/
      #ifdef DEBUG
      printf("\ninvalid date sep");
      #endif
      return(FALSE);
   }

   string[i] = NULLC;	  /*replace it with NULLC*/

   /*get the string which represent year*/
   strcpy(c1,string);
   /*put the rest of the string into c2*/
   strcpy(c2,string+i+1);

   /*search the next occurance of country->datesep*/
   for (i = 0; (c2[i] != NULLC) && (c2[i] != ctry.datesep &&
   c2[i] != '/' && c2[i] != '-' && c2[i] != '.'); ++i);

   if (c2[i] == NULLC) {  /*if not found*/
      #ifdef DEBUG
      printf("\nno 2nd date sep");
      #endif
      return(FALSE);
   }

   /*put NULLC at the end of string which represent month*/
   c2[i] = NULLC;     /*replace it with NULLC*/
   strcpy(c3,c2+i+1);

   /************************************************/
   /* convert all 3 strings to integers 	   */
   /************************************************/
   in1 = 0;
   for (j=0; c1[j] != NULLC ; ++j) {
       if (c1[j] < '0' || c1[j] > '9') {
	  #ifdef DEBUG
	  printf("\ninvalid 1st in date not 0-9");
	  #endif
	  return(FALSE);
       }
       in1 = in1*10 + c1[j]-'0';
   }

   in2 = 0;
   for (j=0; c2[j] != NULLC ; ++j) {
       if (c2[j] < '0' || c2[j] > '9') {
	  #ifdef DEBUG
	  printf("\ninvalid 2nd in date not 0-9");
	  #endif
	  return(FALSE);
       }
       in2 = in2*10 + c2[j]-'0';
   }

   in3 = 0;
   for (j=0; c3[j] != NULLC ; ++j) {
       if (c3[j] < '0' || c3[j] > '9') {
	  #ifdef DEBUG
	  printf("\ninvalid 3rd in date not 0-9");
	  #endif
	  return(FALSE);
       }
       in3 = in3*10 + c3[j]-'0';
   }
   /************************************************/
   /* identify what these 3 integers are stand for */
   /************************************************/
   switch (ctry.dtformat) {
	 case USA:
		   *inmonth = in1;
		   *inday   = in2;
		   *inyear  = in3;
		   strcpy(cmonth,c1);
		   strcpy(cday,c2);
		   strcpy(cyear,c3);
		   break;
	 case EUR:
		   *inday   = in1;
		   *inmonth = in2;
		   *inyear  = in3;
		   strcpy(cday,c1);
		   strcpy(cmonth,c2);
		   strcpy(cyear,c3);
		   break;
	 case JAP:
		   *inyear  = in1;
		   *inmonth = in2;
		   *inday   = in3;
		   strcpy(cyear,c1);
		   strcpy(cmonth,c2);
		   strcpy(cday,c3);
		   break;
	 default:
		   #ifdef DEBUG
		   printf("\ninvalid country code %d",ctry.dtformat);
		   #endif
		   unexperror(UNEXPECTED);
		   break;
   }
   /************************************************/
   /* validate the value of year		   */
   /************************************************/
   if (strlen(cyear) > MAXYEARLEN || strlen(cyear)<1 ) {
	  #ifdef DEBUG
	  printf("\ninvalid year len");
	  #endif
	  return(FALSE);
   }

   if (*inyear <= 99 && *inyear >= 80)
      *inyear = *inyear + 1900;
   if (*inyear <= 79 && *inyear >= 00)
      *inyear = *inyear + 2000;

   /*validate the value of year  */
   if (*inyear > MAXYEAR || *inyear < MINYEAR) {
	  #ifdef DEBUG
	  printf("\ninvalid year value");
	  #endif
	  return(FALSE);
   }

   /************************************************/
   /* validate the value of month		   */
   /************************************************/
   if (strlen(cmonth) > MAXMONTHLEN || strlen(cmonth)<1 ) {
	  #ifdef DEBUG
	  printf("\ninvalid month length");
	  #endif
	  return(FALSE);
    }

   /*validate the value of year  */
   if (*inmonth > MAXMONTH || *inmonth <= 0) {
	  #ifdef DEBUG
	  printf("\ninvalid month value");
	  #endif
	  return(FALSE);
   }

   /************************************************/
   /* validate the value of day 		   */
   /************************************************/
   if (strlen(cday) > MAXDAYLEN || strlen(cday)<1 ) {
	  #ifdef DEBUG
	  printf("\ninvalid day len");
	  #endif
	  return(FALSE);
   }

   /*validate the value of year  */
   if (*inday > MAXDAY || *inday <= 0 )  {
	   #ifdef DEBUG
	   printf("\ninvalid day value");
	   #endif
	   return(FALSE);
    }
   if ((*inmonth == 1 || *inmonth == 3 || *inmonth == 5 ||
	*inmonth == 7 || *inmonth == 8 || *inmonth == 10 ||
	*inmonth == 12 ) && (*inday > 31 || *inday < 1)) {
	   #ifdef DEBUG
	   printf("\ninvalid day value");
	   #endif
	   return(FALSE);
   }
   else  {
       if ((*inmonth == 4 || *inmonth == 6 || *inmonth == 9 ||
	    *inmonth == 11 ) && (*inday > 30 || *inday < 1)) {
	      #ifdef DEBUG
	      printf("\ninvalid day value");
	      #endif
	      return(FALSE);
       }
       else {
	if (*inmonth == 2) {
	  /*check for leap year */
	  remainder = *inyear % 4;
	  if (remainder == 0) {
	     if (*inday > 29 || *inday < 1) {
		#ifdef DEBUG
		printf("\ninvalid day value");
		#endif
		return(FALSE);
	     }
	  }
	  else {
	     if (*inday > 28 || *inday < 1) {
		#ifdef DEBUG
		printf("\ninvalid day value");
		#endif
		return(FALSE);
	     }
	  }
	}
       }
   }

   /************************************************/
   /* if there is no error found, return TRUE	   */
   /************************************************/
   return(TRUE);

} /*end of subroutine valid_input_date*/

/**************************/