add MKSH_UNIXTIME
This commit is contained in:
		
							
								
								
									
										4
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.c
									
									
									
									
									
								
							| @@ -34,7 +34,7 @@ | ||||
| #include <locale.h> | ||||
| #endif | ||||
|  | ||||
| __RCSID("$MirOS: src/bin/mksh/main.c,v 1.239 2012/11/20 17:42:29 tg Exp $"); | ||||
| __RCSID("$MirOS: src/bin/mksh/main.c,v 1.240 2012/11/20 18:07:42 tg Exp $"); | ||||
|  | ||||
| extern char **environ; | ||||
|  | ||||
| @@ -59,7 +59,7 @@ static void x_sigwinch(int); | ||||
| static const char initifs[] = "IFS= \t\n"; | ||||
|  | ||||
| static const char initsubs[] = | ||||
|     "${PS2=> } ${PS3=#? } ${PS4=+ } ${SECONDS=0} ${TMOUT=0}"; | ||||
|     "${PS2=> } ${PS3=#? } ${PS4=+ } ${SECONDS=0} ${TMOUT=0} ${MKSH_UNIXTIME=}"; | ||||
|  | ||||
| static const char *initcoms[] = { | ||||
| 	Ttypeset, "-r", initvsn, NULL, | ||||
|   | ||||
							
								
								
									
										12
									
								
								mksh.1
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								mksh.1
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | ||||
| .\" $MirOS: src/bin/mksh/mksh.1,v 1.297 2012/11/20 17:42:30 tg Exp $ | ||||
| .\" $MirOS: src/bin/mksh/mksh.1,v 1.298 2012/11/20 18:07:43 tg Exp $ | ||||
| .\" $OpenBSD: ksh.1,v 1.144 2012/07/08 08:13:20 guenther Exp $ | ||||
| .\"- | ||||
| .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, | ||||
| @@ -1863,6 +1863,16 @@ executed. | ||||
| .It Ev LINES | ||||
| Set to the number of lines on the terminal or window. | ||||
| Always set, defaults to 24. | ||||
| .It Ev MKSH_UNIXTIME | ||||
| Time since the epoch, as returned by | ||||
| .Xr gettimeofday 2 , | ||||
| formatted as decimal | ||||
| .Va tv_sec | ||||
| followed by a dot | ||||
| .Pq Sq .\& | ||||
| and | ||||
| .Va tv_usec | ||||
| padded to exactly six decimal digits. | ||||
| .It Ev OLDPWD | ||||
| The previous working directory. | ||||
| Unset if | ||||
|   | ||||
							
								
								
									
										19
									
								
								var.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								var.c
									
									
									
									
									
								
							| @@ -27,7 +27,7 @@ | ||||
| #include <sys/sysctl.h> | ||||
| #endif | ||||
|  | ||||
| __RCSID("$MirOS: src/bin/mksh/var.c,v 1.157 2012/11/20 18:06:53 tg Exp $"); | ||||
| __RCSID("$MirOS: src/bin/mksh/var.c,v 1.158 2012/11/20 18:07:45 tg Exp $"); | ||||
|  | ||||
| /*- | ||||
|  * Variables | ||||
| @@ -130,7 +130,7 @@ initvar(void) | ||||
| 	struct tbl *tp; | ||||
|  | ||||
| 	ktinit(APERM, &specials, | ||||
| 	    /* currently 13 specials: 75% of 32 = 2^5 */ | ||||
| 	    /* currently 14 specials: 75% of 32 = 2^5 */ | ||||
| 	    5); | ||||
| 	while (i < V_MAX - 1) { | ||||
| 		tp = ktenter(&specials, initvar_names[i], | ||||
| @@ -1087,6 +1087,7 @@ getspec(struct tbl *vp) | ||||
| { | ||||
| 	register mksh_ari_t i; | ||||
| 	int st; | ||||
| 	struct timeval tv; | ||||
|  | ||||
| 	switch ((st = special(vp->name))) { | ||||
| 	case V_BASHPID: | ||||
| @@ -1111,6 +1112,18 @@ getspec(struct tbl *vp) | ||||
| 	case V_LINES: | ||||
| 		i = x_lins; | ||||
| 		break; | ||||
| 	case V_MKSH_UNIXTIME: { | ||||
| 		/* 10(%u) + 1(.) + 6 + NUL */ | ||||
| 		char buf[18]; | ||||
|  | ||||
| 		vp->flag &= ~SPECIAL; | ||||
| 		mksh_TIME(tv); | ||||
| 		shf_snprintf(buf, sizeof(buf), "%u.%06u", | ||||
| 		    (unsigned)tv.tv_sec, (unsigned)tv.tv_usec); | ||||
| 		setstr(vp, buf, KSH_RETURN_ERROR | 0x4); | ||||
| 		vp->flag |= SPECIAL; | ||||
| 		return; | ||||
| 	} | ||||
| 	case V_OPTIND: | ||||
| 		i = user_opt.uoptind; | ||||
| 		break; | ||||
| @@ -1124,8 +1137,6 @@ getspec(struct tbl *vp) | ||||
| 		 * (see initcoms[] in main.c). | ||||
| 		 */ | ||||
| 		if (vp->flag & ISSET) { | ||||
| 			struct timeval tv; | ||||
|  | ||||
| 			mksh_TIME(tv); | ||||
| 			i = tv.tv_sec - seconds; | ||||
| 		} else | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| #if defined(VARSPEC_DEFNS) | ||||
| __RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.3 2012/11/20 17:42:32 tg Exp $"); | ||||
| __RCSID("$MirOS: src/bin/mksh/var_spec.h,v 1.4 2012/11/20 18:07:45 tg Exp $"); | ||||
| #define FN(name)			/* nothing */ | ||||
| #elif defined(VARSPEC_ENUMS) | ||||
| #define FN(name)			V_##name, | ||||
| @@ -28,6 +28,7 @@ FN(HISTSIZE) | ||||
| FN(IFS) | ||||
| FN(LINENO) | ||||
| FN(LINES) | ||||
| FN(MKSH_UNIXTIME) | ||||
| FN(OPTIND) | ||||
| FN(PATH) | ||||
| FN(RANDOM) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user