diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 5a2d48c7a2b9..7e40a187cf01 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -827,22 +827,25 @@ static void match2d(struct match *mp) int i; Namarr_t *ap; nv_disc(SH_MATCHNOD, &mp->hdr, NV_POP); - np = nv_namptr(mp->nodes, 0); - for(i=0; i < mp->nmatch; i++) + if(mp->nodes) { - np->nvname = mp->names + 3 * i; - if(i > 9) + np = nv_namptr(mp->nodes, 0); + for(i=0; i < mp->nmatch; i++) { - *np->nvname = '0' + i / 10; - np->nvname[1] = '0' + (i % 10); + np->nvname = mp->names + 3 * i; + if(i > 9) + { + *np->nvname = '0' + i / 10; + np->nvname[1] = '0' + (i % 10); + } + else + *np->nvname = '0' + i; + nv_putsub(np, NULL, 1); + nv_putsub(np, NULL, 0); + nv_putsub(SH_MATCHNOD, NULL, i); + nv_arraychild(SH_MATCHNOD, np, 0); + np = nv_namptr(np + 1, 0); } - else - *np->nvname = '0' + i; - nv_putsub(np, NULL, 1); - nv_putsub(np, NULL, 0); - nv_putsub(SH_MATCHNOD, NULL, i); - nv_arraychild(SH_MATCHNOD, np, 0); - np = nv_namptr(np + 1, 0); } if(ap = nv_arrayptr(SH_MATCHNOD)) ap->nelem = mp->nmatch; @@ -864,25 +867,28 @@ void sh_setmatch(const char *v, int vsize, int nmatch, int match[], int index) sh.subshell = 0; if(index<0) { - np = nv_namptr(mp->nodes,0); - if(mp->index==0) - match2d(mp); - for(i=0; i < mp->nmatch; i++) + if(mp->nodes) { - nv_disc(np,&mp->hdr,NV_LAST); - nv_putsub(np,NULL,mp->index); - for(x=mp->index; x >=0; x--) - { - n = i + x*mp->nmatch; - if(mp->match[2*n+1]>mp->match[2*n]) - nv_putsub(np,Empty,ARRAY_ADD|x); - } - if((ap=nv_arrayptr(np)) && array_elem(ap)==0) + np = nv_namptr(mp->nodes,0); + if(mp->index==0) + match2d(mp); + for(i=0; i < mp->nmatch; i++) { - nv_putsub(SH_MATCHNOD,NULL,i); - _nv_unset(SH_MATCHNOD,NV_RDONLY); + nv_disc(np,&mp->hdr,NV_LAST); + nv_putsub(np,NULL,mp->index); + for(x=mp->index; x >=0; x--) + { + n = i + x*mp->nmatch; + if(mp->match[2*n+1]>mp->match[2*n]) + nv_putsub(np,Empty,ARRAY_ADD|x); + } + if((ap=nv_arrayptr(np)) && array_elem(ap)==0) + { + nv_putsub(SH_MATCHNOD,NULL,i); + _nv_unset(SH_MATCHNOD,NV_RDONLY); + } + np = nv_namptr(np+1,0); } - np = nv_namptr(np+1,0); } sh.subshell = savesub; return; diff --git a/src/lib/libast/include/proc.h b/src/lib/libast/include/proc.h index 954d6fc25c9a..cb3a7d291c69 100644 --- a/src/lib/libast/include/proc.h +++ b/src/lib/libast/include/proc.h @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -64,8 +64,8 @@ #define PROC_fd_ctty 0xc -#define PROC_op1(o,a) (((o)<<(2*PROC_ARG_BIT))|((a)&((PROC_ARG_NULL<