1 static char *SCCSID = "@(#)rtt2.c 8.4 86/10/19";
7 #include <comsub.h> /* common subroutine def'n */
9 #include <wrwdefs.h> /* wrw! */
11 extern unsigned char rtswitch;
12 extern unsigned char control_flag;
13 extern unsigned char control_flag2;
14 extern struct internat ctry; /* data area for country info*/
16 /***************** START OF SPECIFICATION *********************************/
18 /* SUBROUTINE NAME : valid_input_time */
20 /* DESCRIPTIVE NAME : to validate and convert the time input from the */
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 */
29 /* INPUT: (PARAMETERS) */
30 /* in_string - the string from command line which contains date */
33 /* inhour - the input hour after converted */
34 /* inminute - the input minute after converted */
35 /* insecond - the input second after converted */
37 /* EXIT-NORMAL: returns TRUE if the time is valid */
39 /* EXIT-ERROR: returns FALSE if the time is invalid */
43 /* INTERNAL REFERENCES: */
48 /* set_reset_test_flag */
50 /* EXTERNAL REFERENCES: */
53 /********************** END OF SPECIFICATIONS *******************************/
54 int 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 */
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];
67 /*declaration for get country information*/
68 unsigned int byte_len;
69 unsigned buflen = sizeof( struct internat ); /* length of data area */
73 /************************************************/
74 /* find the string for hour */
75 /************************************************/
77 printf("\ntime to be validate %s",in_string);
79 /*save the pointer of input string*/
80 strcpy(string,in_string);
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);
86 if (string[i] == NULLC) { /*if not found*/
88 printf("\nno time seperator");
93 string[i] = NULLC; /*replace it with NULLC*/
95 /*get the string which represent hour*/
97 /*put the rest of the string into cminute*/
98 strcpy(cminute,string+i+1);
100 /************************************************/
102 /************************************************/
103 if (strlen(chour) > MAXHOURLEN || strlen(chour)<1 ) {
105 printf("\ninvalid hour length");
110 /* convert the string into integer form*/
112 for (j=0; chour[j] != NULLC ; ++j) {
113 if (chour[j] < '0' || chour[j] > '9') {
115 printf("\nhour value not 0-9");
119 *inhour = *inhour*10 + chour[j]-'0';
122 if (*inhour > 23 || *inhour < 0) {
124 printf("\ninvalid hour value");
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);
136 if (cminute[i] == NULLC) { /*if not found*/
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);
144 /************************************************/
145 /* validate minute */
146 /************************************************/
147 if (strlen(cminute) > MAXMINUTELEN || strlen(cminute)<1 ) {
149 printf("\ninvalid min length");
154 /*convert the string into integer*/
156 for (j=0; cminute[j] != NULLC ; ++j) {
157 if (cminute[j] < '0' || cminute[j] > '9') {
159 printf("\ninvalid min value, not 0-9");
163 *inminute = *inminute*10 + cminute[j]-'0';
166 if (*inminute > 59 || *inminute < 0) {
168 printf("\ninvalid min value");
173 /***************************************************/
174 /* if user input second, get the string for second */
175 /***************************************************/
176 if (no_second == TRUE)
180 /************************************************/
181 /* validate second */
182 /************************************************/
183 if (strlen(csecond) > MAXSECONDLEN || strlen(csecond) < 1 ) {
185 printf("\ninvalid second length");
190 /*convert the rest of the string into integer*/
192 for (j=0; csecond[j] != NULLC; ++j)
194 if (csecond[j] < '0' || csecond[j] > '9') {
196 printf("\ninvalid second, 0-9");
200 *insecond = *insecond*10 + csecond[j]-'0';
203 if (*insecond > 59 || *insecond < 0) {
205 printf("\ninvalid second value");
209 } /*end of if no_second is true */
212 } /*end of subroutine*/
213 /***************** START OF SPECIFICATION *********************************/
215 /* SUBROUTINE NAME : valid_input_date */
217 /* DESCRIPTIVE NAME : to validate and convert the date input from the */
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. */
225 /* INPUT: (PARAMETERS) */
226 /* in_string - the string from command line which contains date */
229 /* inyear - the input year after converted */
230 /* inmonth - the input month after converted */
231 /* inday - the input day after converted */
233 /* EXIT-NORMAL: returns TRUE if the date is valid */
235 /* EXIT-ERROR: returns FALSE if the date is invalid */
239 /* INTERNAL REFERENCES: */
244 /* set_reset_test_flag */
246 /* EXTERNAL REFERENCES: */
249 /********************** END OF SPECIFICATIONS *******************************/
250 int valid_input_date(in_string,inyear,inmonth,inday)
252 unsigned char *in_string;
253 unsigned int *inyear;
254 unsigned int *inmonth;
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];
266 unsigned int i,j,z; /*working pointer*/
267 unsigned char string[30];
268 unsigned int remainder;
271 printf("\ndate to be validate %s",in_string);
273 /************************************************/
274 /* separate the input date string into 3 parts */
275 /************************************************/
276 /*save the pointer to the input string*/
277 strcpy(string,in_string);
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);
283 if (string[i] == NULLC) { /*if not found*/
285 printf("\ninvalid date sep");
290 string[i] = NULLC; /*replace it with NULLC*/
292 /*get the string which represent year*/
294 /*put the rest of the string into c2*/
295 strcpy(c2,string+i+1);
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);
301 if (c2[i] == NULLC) { /*if not found*/
303 printf("\nno 2nd date sep");
308 /*put NULLC at the end of string which represent month*/
309 c2[i] = NULLC; /*replace it with NULLC*/
312 /************************************************/
313 /* convert all 3 strings to integers */
314 /************************************************/
316 for (j=0; c1[j] != NULLC ; ++j) {
317 if (c1[j] < '0' || c1[j] > '9') {
319 printf("\ninvalid 1st in date not 0-9");
323 in1 = in1*10 + c1[j]-'0';
327 for (j=0; c2[j] != NULLC ; ++j) {
328 if (c2[j] < '0' || c2[j] > '9') {
330 printf("\ninvalid 2nd in date not 0-9");
334 in2 = in2*10 + c2[j]-'0';
338 for (j=0; c3[j] != NULLC ; ++j) {
339 if (c3[j] < '0' || c3[j] > '9') {
341 printf("\ninvalid 3rd in date not 0-9");
345 in3 = in3*10 + c3[j]-'0';
347 /************************************************/
348 /* identify what these 3 integers are stand for */
349 /************************************************/
350 switch (ctry.dtformat) {
377 printf("\ninvalid country code %d",ctry.dtformat);
379 unexperror(UNEXPECTED);
382 /************************************************/
383 /* validate the value of year */
384 /************************************************/
385 if (strlen(cyear) > MAXYEARLEN || strlen(cyear)<1 ) {
387 printf("\ninvalid year len");
392 if (*inyear <= 99 && *inyear >= 80)
393 *inyear = *inyear + 1900;
394 if (*inyear <= 79 && *inyear >= 00)
395 *inyear = *inyear + 2000;
397 /*validate the value of year */
398 if (*inyear > MAXYEAR || *inyear < MINYEAR) {
400 printf("\ninvalid year value");
405 /************************************************/
406 /* validate the value of month */
407 /************************************************/
408 if (strlen(cmonth) > MAXMONTHLEN || strlen(cmonth)<1 ) {
410 printf("\ninvalid month length");
415 /*validate the value of year */
416 if (*inmonth > MAXMONTH || *inmonth <= 0) {
418 printf("\ninvalid month value");
423 /************************************************/
424 /* validate the value of day */
425 /************************************************/
426 if (strlen(cday) > MAXDAYLEN || strlen(cday)<1 ) {
428 printf("\ninvalid day len");
433 /*validate the value of year */
434 if (*inday > MAXDAY || *inday <= 0 ) {
436 printf("\ninvalid day value");
440 if ((*inmonth == 1 || *inmonth == 3 || *inmonth == 5 ||
441 *inmonth == 7 || *inmonth == 8 || *inmonth == 10 ||
442 *inmonth == 12 ) && (*inday > 31 || *inday < 1)) {
444 printf("\ninvalid day value");
449 if ((*inmonth == 4 || *inmonth == 6 || *inmonth == 9 ||
450 *inmonth == 11 ) && (*inday > 30 || *inday < 1)) {
452 printf("\ninvalid day value");
458 /*check for leap year */
459 remainder = *inyear % 4;
460 if (remainder == 0) {
461 if (*inday > 29 || *inday < 1) {
463 printf("\ninvalid day value");
469 if (*inday > 28 || *inday < 1) {
471 printf("\ninvalid day value");
480 /************************************************/
481 /* if there is no error found, return TRUE */
482 /************************************************/
485 } /*end of subroutine valid_input_date*/
487 /**************************/