* Restart from scratch branched out on dev removed all previous source files started test on new env2lst function * norm: splitted functions in main into appropriate file Moved lstdelenvelem & env2lst to ms_env.c Normed out files * Feat(WIP): Added possibility to cmd_env to execute commands with altered env. Added dummy function for cd, echo, setenv & unsetenv Started work on env copy feature * feature: switched env from ft_list to specific list * feature: added execution of commands from path * feature: added env, setenv & unsetenv builtins added -i option & command execution to env added setenv & unsetenv builtins * Clean-up: normed out files * Changed comportment on error for check_path functions * feature: added completion for ~ and ${} WIP leaks detected on ${} completion * fix leak on ext need test * feature: added echo cmd changed printf ref to ft_printf * feature: add cd built-in * Simple norm-out * moved env functions to libft * fixed out-of-memory access in extension * Resolved infinite loop in extension revolving WIP norming in cd * Normedout cmd_cd.c * Normed out functions in cmd_cd * Normed out funtions sorting out needed * removed -fsanitize from Makefile * corrected env -i crash & SHLVL * Delete norm.txt * added put_error_cd2 in put_error_cd.c * added inline environment
90 lines
2.7 KiB
C
90 lines
2.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* tools_wstr.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: klebon <klebon@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2018/05/23 19:48:06 by klebon #+# #+# */
|
|
/* Updated: 2019/03/07 22:25:19 by tmaze ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
void handler_2oct_wstr(wint_t c, char *output, int *i)
|
|
{
|
|
output[(*i)++] = (c >> 6) + 0xC0;
|
|
output[(*i)++] = (c & 0x3F) + 0x80;
|
|
}
|
|
|
|
void handler_3oct_wstr(wint_t c, char *output, int *i)
|
|
{
|
|
output[(*i)++] = (c >> 12) + 0xE0;
|
|
output[(*i)++] = ((c >> 6) & 0x3F) + 0x80;
|
|
output[(*i)++] = (c & 0x3F) + 0x80;
|
|
}
|
|
|
|
void handler_4oct_wstr(wint_t c, char *output, int *i)
|
|
{
|
|
output[(*i)++] = (c >> 18) + 0xF0;
|
|
output[(*i)++] = ((c >> 12) & 0x3F) + 0x80;
|
|
output[(*i)++] = ((c >> 6) & 0x3F) + 0x80;
|
|
output[(*i)++] = (c & 0x3F) + 0x80;
|
|
}
|
|
|
|
void convert_wstr_to_str(const wint_t *str, char *output, t_conv *field)
|
|
{
|
|
int i;
|
|
int j;
|
|
int tmp;
|
|
|
|
i = 0;
|
|
j = 0;
|
|
while (str[i] && j <= field->fl_prec)
|
|
{
|
|
tmp = j;
|
|
if (j + 1 <= field->fl_prec
|
|
&& (str[i] <= 0x7F || (MB_CUR_MAX == 1 && str[i] <= 0xFF)))
|
|
output[j++] = (char)str[i];
|
|
else if (j + 2 <= field->fl_prec && str[i] <= 0x7FF)
|
|
handler_2oct_wstr(str[i], output, &j);
|
|
else if (j + 3 <= field->fl_prec && str[i] <= 0xFFFF)
|
|
handler_3oct_wstr(str[i], output, &j);
|
|
else if (j + 4 <= field->fl_prec)
|
|
handler_4oct_wstr(str[i], output, &j);
|
|
++i;
|
|
if (tmp == j)
|
|
break ;
|
|
}
|
|
}
|
|
|
|
char *handle_output_wstr(t_conv *field, va_list ap)
|
|
{
|
|
char *output;
|
|
const wint_t *str;
|
|
|
|
str = (wint_t *)va_arg(ap, const wint_t *);
|
|
if (str == NULL)
|
|
str = L"(null)";
|
|
if (field->fl_prec != -1)
|
|
{
|
|
if (set_prec_size_wstr(str, field) == 0)
|
|
return (NULL);
|
|
}
|
|
else
|
|
{
|
|
if ((field->str_size = ft_wstrlen(str)) == -1)
|
|
return (NULL);
|
|
}
|
|
if (field->fl_prec == -1)
|
|
field->fl_prec = field->str_size;
|
|
if (field->fl_witdth > field->str_size)
|
|
field->str_size += (field->fl_witdth - field->str_size);
|
|
if (!(output = ft_strnew(field->str_size)))
|
|
return (NULL);
|
|
convert_wstr_to_str(str, output, field);
|
|
ft_align_wstr(output, field);
|
|
return (output);
|
|
}
|