* 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
110 lines
3.0 KiB
C
110 lines
3.0 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* tools_wchar_t.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: klebon <klebon@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2018/05/18 18:10:11 by klebon #+# #+# */
|
|
/* Updated: 2019/03/16 15:53:50 by tmaze ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
void ft_align_wchar(char *str, t_conv *field)
|
|
{
|
|
int i;
|
|
int len;
|
|
|
|
len = (int)ft_strlen(str);
|
|
len = (len) ? len : 1;
|
|
if (len < field->str_size)
|
|
{
|
|
if (field->fl_minus == 1)
|
|
{
|
|
i = 1;
|
|
while (str[i])
|
|
++i;
|
|
while (i < field->str_size)
|
|
str[i++] = ' ';
|
|
}
|
|
else
|
|
{
|
|
i = 0;
|
|
ft_memmove(str + (field->str_size - len), str, len);
|
|
while (i < field->str_size - len)
|
|
str[i++] = (field->fl_zero) ? '0' : ' ';
|
|
}
|
|
}
|
|
}
|
|
|
|
char *handler_2oct_char(wint_t c, t_conv *field)
|
|
{
|
|
char *output;
|
|
|
|
field->str_size = (field->fl_witdth > 2) ? field->fl_witdth : 2;
|
|
if (!(output = ft_strnew(field->str_size)))
|
|
return (NULL);
|
|
output[0] = (c >> 6) + 0xC0;
|
|
output[1] = (c & 0x3F) + 0x80;
|
|
ft_align_wchar(output, field);
|
|
return (output);
|
|
}
|
|
|
|
char *handler_3oct_char(wint_t c, t_conv *field)
|
|
{
|
|
char *output;
|
|
|
|
field->str_size = (field->fl_witdth > 3) ? field->fl_witdth : 3;
|
|
if (!(output = ft_strnew(field->str_size)))
|
|
return (NULL);
|
|
output[0] = (c >> 12) + 0xE0;
|
|
output[1] = ((c >> 6) & 0x3F) + 0x80;
|
|
output[2] = (c & 0x3F) + 0x80;
|
|
ft_align_wchar(output, field);
|
|
return (output);
|
|
}
|
|
|
|
char *handler_4oct_char(wint_t c, t_conv *field)
|
|
{
|
|
char *output;
|
|
|
|
field->str_size = (field->fl_witdth > 4) ? field->fl_witdth : 4;
|
|
if (!(output = ft_strnew(field->str_size)))
|
|
return (NULL);
|
|
output[0] = (c >> 18) + 0xF0;
|
|
output[1] = ((c >> 12) & 0x3F) + 0x80;
|
|
output[2] = ((c >> 6) & 0x3F) + 0x80;
|
|
output[3] = (c & 0x3F) + 0x80;
|
|
ft_align_wchar(output, field);
|
|
return (output);
|
|
}
|
|
|
|
char *handle_output_wchar(t_conv *field, va_list ap)
|
|
{
|
|
char *output;
|
|
wint_t c;
|
|
|
|
c = (wint_t)va_arg(ap, wint_t);
|
|
if (c < 0 || (MB_CUR_MAX == 1 && c > 0xFF) || (c >= 0xD800 && c <= 0xDFFF))
|
|
return (NULL);
|
|
else if (c <= 0x7F || (MB_CUR_MAX == 1 && c <= 0xFF))
|
|
{
|
|
field->str_size = (field->fl_witdth > 1) ? field->fl_witdth : 1;
|
|
if (!(output = ft_strnew(field->str_size)))
|
|
return (NULL);
|
|
output[0] = (char)c;
|
|
ft_align_wchar(output, field);
|
|
}
|
|
else if (c <= 0x7FF)
|
|
output = handler_2oct_char(c, field);
|
|
else if (c <= 0xFFFF)
|
|
output = handler_3oct_char(c, field);
|
|
else if (c <= 0x10FFFF)
|
|
output = handler_4oct_char(c, field);
|
|
else
|
|
return (NULL);
|
|
return (output);
|
|
}
|