/* "allocate" a tcp_session */ static Tcp_session zts_alloc(int ztflags) { Tcp_session sess; sess = (Tcp_session)zshcalloc(sizeof(struct tcp_session)); if (!sess) return NULL; sess->fd=-1; sess->flags=ztflags; zinsertlinknode(ztcp_sessions, lastnode(ztcp_sessions), (void *)sess); return sess; }
ListNode *sortList(ListNode *head) { if(head==NULL) return NULL; SortRec(head,lastnode(head));//2,1 return head; }
LinkNode stringsubst(LinkList list, LinkNode node, int ssub) { int qt; char *str3 = (char *)getdata(node); char *str = str3; while (!errflag && *str) { if ((qt = *str == Qstring) || *str == String) if (str[1] == Inpar) { str++; goto comsub; } else if (str[1] == Inbrack) { /* $[...] */ char *str2 = str; str2++; if (skipparens(Inbrack, Outbrack, &str2)) { zerr("closing bracket missing", NULL, 0); return NULL; } str2[-1] = *str = '\0'; str = arithsubst(str + 2, &str3, str2); setdata(node, (void *) str3); continue; } else { node = paramsubst(list, node, &str, qt, ssub); if (errflag || !node) return NULL; str3 = (char *)getdata(node); continue; } else if ((qt = *str == Qtick) || *str == Tick) comsub: { LinkList pl; char *s, *str2 = str; char endchar; int l1, l2; if (*str == Inpar) { endchar = Outpar; str[-1] = '\0'; if (skipparens(Inpar, Outpar, &str)) DPUTS(1, "Oops. parse error in command substitution"); str--; } else { endchar = *str; *str = '\0'; while (*++str != endchar) DPUTS(!*str, "Oops. parse error in command substitution"); } *str++ = '\0'; if (endchar == Outpar && str2[1] == '(' && str[-2] == ')') { /* Math substitution of the form $((...)) */ str = arithsubst(str2 + 1, &str3, str); setdata(node, (void *) str3); continue; } /* It is a command substitution, which will be parsed again * * by the lexer, so we untokenize it first, but we cannot use * * untokenize() since in the case of `...` some Bnulls should * * be left unchanged. Note that the lexer doesn't tokenize * * the body of a command substitution so if there are some * * tokens here they are from a ${(e)~...} substitution. */ for (str = str2; *++str; ) if (itok(*str) && *str != Nularg && !(endchar != Outpar && *str == Bnull && (str[1] == '$' || str[1] == '\\' || str[1] == '`' || (qt && str[1] == '"')))) *str = ztokens[*str - Pound]; str++; if (!(pl = getoutput(str2 + 1, qt || ssub))) { zerr("parse error in command substitution", NULL, 0); return NULL; } if (endchar == Outpar) str2--; if (!(s = (char *) ugetnode(pl))) { str = strcpy(str2, str); continue; } if (!qt && ssub && isset(GLOBSUBST)) tokenize(s); l1 = str2 - str3; l2 = strlen(s); if (nonempty(pl)) { LinkNode n = lastnode(pl); str2 = (char *) ncalloc(l1 + l2 + 1); strcpy(str2, str3); strcpy(str2 + l1, s); setdata(node, str2); insertlinklist(pl, node, list); s = (char *) getdata(node = n); l1 = 0; l2 = strlen(s); } str2 = (char *) ncalloc(l1 + l2 + strlen(str) + 1); if (l1) strcpy(str2, str3); strcpy(str2 + l1, s); str = strcpy(str2 + l1 + l2, str); str3 = str2; setdata(node, str3); continue; } str++; } return errflag ? NULL : node; }