void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encode_special) { for (; ll > 0; ll--, b++) { if ((unsigned char)*b < ' ') continue; if (special_char(*b) && encode_special == 1) { unsigned char h[4]; sprintf(cast_char h, "%%%02X", (unsigned)*b & 0xff); add_to_str(s, l, h); } else if (*b == '%' && encode_special <= -1 && ll > 2 && ((b[1] >= '0' && b[1] <= '9') || (b[1] >= 'A' && b[1] <= 'F') || (b[1] >= 'a' && b[1] <= 'f'))) { unsigned char h = 0; int i; for (i = 1; i < 3; i++) { if (b[i] >= '0' && b[i] <= '9') h = h * 16 + b[i] - '0'; if (b[i] >= 'A' && b[i] <= 'F') h = h * 16 + b[i] - 'A' + 10; if (b[i] >= 'a' && b[i] <= 'f') h = h * 16 + b[i] - 'a' + 10; } if (h >= ' ') add_chr_to_str(s, l, h); ll -= 2; b += 2; } else if (*b == ' ' && (!encode_special || encode_special == -1)) { add_to_str(s, l, cast_uchar " "); } else if (accept_char(*b) || encode_special == -2) { add_chr_to_str(s, l, *b); } else { add_to_str(s, l, cast_uchar "&#"); add_num_to_str(s, l, (int)*b); add_chr_to_str(s, l, ';'); } } }
static int ft_inib(t_cmd *cmd, int index, int rule) { while (cmd->raw[index]) { if ((cmd->raw[index] == '\'' || cmd->raw[index] == '\"') && (!rule || rule == cmd->raw[index])) { if (!rule) rule = cmd->raw[index]; else rule = 0; ft_delete_char(cmd, index); } if (cmd->raw[index] == '\\' && (!rule || (rule == '\"' && special_char(cmd->raw[index + 1])))) { ft_delete_char(cmd, index); if (cmd->raw[index] != '\n') cmd->raw[index] = -1 * cmd->raw[index]; else ft_delete_char(cmd, index); } if (rule == '\'' || (rule == '\"' && !ft_avoid_char(cmd->raw[index]))) cmd->raw[index] = -1 * cmd->raw[index]; index++; } return (rule); }
static void pipe_handler(t_cmds *tmp, t_builtin *b, int fdes[2], int i, int nb) { pid_t child = -1; child = fork(); if (child == 0) { dup2(fdes[1], STDOUT_FILENO); close(fdes[0]); special_char(&tmp->cmd, b); init_builtin(b, tmp->cmd); clean_quote(b->argv); get_command(b->argv[0], b); execve(b->path, b->argv, b->env); exit(EXIT_FAILURE); } }
//str_end points right after the last char of str, the '\0' char static s8 match(void *p,void *str,void *str_end,u8 flgs, struct match_params *end_star) { u8 *pc=p; u8 *sc=str; u8 c; while(1){ c=*pc++; if(c=='\0') break; c=fold(c,flgs); u16 r; switch(c){ case '[': case '*': case '?': case '+': case '@': case '!': case '\\': r=special_char(&c,&pc,&sc,str_end,flgs,end_star); break; default: r=MATCH_NORMAL; } if(!(r&NEXT_STR_CHAR)){ if(r&RETURN_R) return R_GET(r); if(r&NEXT_P_CHAR) continue; if((r&MATCH_NORMAL)||(r&TEST_STR_END_REACHED)) if(sc==str_end) return NOMATCH; if(r&MATCH_NORMAL) if(c!=fold(*sc,flgs)) return NOMATCH; } ++sc; } if(sc==str_end) return MATCH; return NOMATCH; }