zIn is either a pointer to a NULL-terminated string in memory obtained ** from malloc(), or a NULL pointer. The string pointed to by zAppend is ** added to zIn, and the result returned in memory obtained from malloc(). ** zIn, if it was not NULL, is freed. ** ** If the third argument, quote, is not '\0', then it is used as a ** quote character for zAppend. */
| 830 | ** quote character for zAppend. |
| 831 | */ |
| 832 | static void appendText(ShellText *p, char const *zAppend, char quote){ |
| 833 | int len; |
| 834 | int i; |
| 835 | int nAppend = strlen30(zAppend); |
| 836 | |
| 837 | len = nAppend+p->n+1; |
| 838 | if( quote ){ |
| 839 | len += 2; |
| 840 | for(i=0; i<nAppend; i++){ |
| 841 | if( zAppend[i]==quote ) len++; |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | if( p->n+len>=p->nAlloc ){ |
| 846 | p->nAlloc = p->nAlloc*2 + len + 20; |
| 847 | p->z = realloc(p->z, p->nAlloc); |
| 848 | if( p->z==0 ) shell_out_of_memory(); |
| 849 | } |
| 850 | |
| 851 | if( quote ){ |
| 852 | char *zCsr = p->z+p->n; |
| 853 | *zCsr++ = quote; |
| 854 | for(i=0; i<nAppend; i++){ |
| 855 | *zCsr++ = zAppend[i]; |
| 856 | if( zAppend[i]==quote ) *zCsr++ = quote; |
| 857 | } |
| 858 | *zCsr++ = quote; |
| 859 | p->n = (int)(zCsr - p->z); |
| 860 | *zCsr = '\0'; |
| 861 | }else{ |
| 862 | memcpy(p->z+p->n, zAppend, nAppend); |
| 863 | p->n += nAppend; |
| 864 | p->z[p->n] = '\0'; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | ** Attempt to determine if identifier zName needs to be quoted, either |
no test coverage detected