- for (i = 0; psi_plist_get(tokens, i, &exp_tokens[i]); ++i) {
- exp_tokens[i] = psi_token_copy(exp_tokens[i]);
+ while (psi_plist_get(tokens, i++, &tok)) {
+ struct psi_token *new_tok;
+
+ if (tok->type == PSI_T_HASH) {
+ if (stringify) {
+ stringify = false;
+ paste = true;
+ } else {
+ stringify = true;
+ }
+ continue;
+ }
+
+ if (paste && n > 0 && exp_tokens[n - 1] &&
+ (new_tok = psi_token_cat(NULL, 2, exp_tokens[n - 1], tok))) {
+ free(exp_tokens[n - 1]);
+ exp_tokens[n - 1] = new_tok;
+ } else {
+ struct psi_token *cpy = psi_token_copy(tok);
+
+ if (stringify) {
+ cpy = psi_token_append(NULL,
+ psi_token_prepend(NULL, cpy, 1, "\""), 1, "\"");
+ cpy->type = PSI_T_QUOTED_STRING;
+ }
+ exp_tokens[n++] = cpy;
+ }