#include "main.h"

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* WRITE HANDLE \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
/\*\*
 \* handle\_write\_char - Prints a string
 \* @c: char types.
 \* @buffer: Buffer array to handle print
 \* @flags: Calculates active flags.
 \* @width: get width.
 \* @precision: precision specifier
 \* @size: Size specifier
 \*
 \* Return: Number of chars printed.
 \*/
int handle\_write\_char(char c, char buffer[],
 int flags, int width, int precision, int size)
{ /\* char is stored at left and paddind at buffer's right \*/
 int i = 0;
 char padd = ' ';

 UNUSED(precision);
 UNUSED(size);

 if (flags & F\_ZERO)
 padd = '0';

 buffer[i++] = c;
 buffer[i] = '\0';

 if (width > 1)
 {
 buffer[BUFF\_SIZE - 1] = '\0';
 for (i = 0; i < width - 1; i++)
 buffer[BUFF\_SIZE - i - 2] = padd;

 if (flags & F\_MINUS)
 return (write(1, &buffer[0], 1) +
 write(1, &buffer[BUFF\_SIZE - i - 1], width - 1));
 else
 return (write(1, &buffer[BUFF\_SIZE - i - 1], width - 1) +
 write(1, &buffer[0], 1));
 }

 return (write(1, &buffer[0], 1));
}

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* WRITE NUMBER \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
/\*\*
 \* write\_number - Prints a string
 \* @is\_negative: Lista of arguments
 \* @ind: char types.
 \* @buffer: Buffer array to handle print
 \* @flags: Calculates active flags
 \* @width: get width.
 \* @precision: precision specifier
 \* @size: Size specifier
 \*
 \* Return: Number of chars printed.
 \*/
int write\_number(int is\_negative, int ind, char buffer[],
 int flags, int width, int precision, int size)
{
 int length = BUFF\_SIZE - ind - 1;
 char padd = ' ', extra\_ch = 0;

 UNUSED(size);

 if ((flags & F\_ZERO) && !(flags & F\_MINUS))
 padd = '0';
 if (is\_negative)
 extra\_ch = '-';
 else if (flags & F\_PLUS)
 extra\_ch = '+';
 else if (flags & F\_SPACE)
 extra\_ch = ' ';

 return (write\_num(ind, buffer, flags, width, precision,
 length, padd, extra\_ch));
}

/\*\*
 \* write\_num - Write a number using a bufffer
 \* @ind: Index at which the number starts on the buffer
 \* @buffer: Buffer
 \* @flags: Flags
 \* @width: width
 \* @prec: Precision specifier
 \* @length: Number length
 \* @padd: Pading char
 \* @extra\_c: Extra char
 \*
 \* Return: Number of printed chars.
 \*/
int write\_num(int ind, char buffer[],
 int flags, int width, int prec,
 int length, char padd, char extra\_c)
{
 int i, padd\_start = 1;

 if (prec == 0 && ind == BUFF\_SIZE - 2 && buffer[ind] == '0' && width == 0)
 return (0); /\* printf(".0d", 0) no char is printed \*/
 if (prec == 0 && ind == BUFF\_SIZE - 2 && buffer[ind] == '0')
 buffer[ind] = padd = ' '; /\* width is displayed with padding ' ' \*/
 if (prec > 0 && prec < length)
 padd = ' ';
 while (prec > length)
 buffer[--ind] = '0', length++;
 if (extra\_c != 0)
 length++;
 if (width > length)
 {
 for (i = 1; i < width - length + 1; i++)
 buffer[i] = padd;
 buffer[i] = '\0';
 if (flags & F\_MINUS && padd == ' ')/\* Asign extra char to left of buffer \*/
 {
 if (extra\_c)
 buffer[--ind] = extra\_c;
 return (write(1, &buffer[ind], length) + write(1, &buffer[1], i - 1));
 }
 else if (!(flags & F\_MINUS) && padd == ' ')/\* extra char to left of buff \*/
 {
 if (extra\_c)
 buffer[--ind] = extra\_c;
 return (write(1, &buffer[1], i - 1) + write(1, &buffer[ind], length));
 }
 else if (!(flags & F\_MINUS) && padd == '0')/\* extra char to left of padd \*/
 {
 if (extra\_c)
 buffer[--padd\_start] = extra\_c;
 return (write(1, &buffer[padd\_start], i - padd\_start) +
 write(1, &buffer[ind], length - (1 - padd\_start)));
 }
 }
 if (extra\_c)
 buffer[--ind] = extra\_c;
 return (write(1, &buffer[ind], length));
}

/\*\*
 \* write\_unsgnd - Writes an unsigned number
 \* @is\_negative: Number indicating if the num is negative
 \* @ind: Index at which the number starts in the buffer
 \* @buffer: Array of chars
 \* @flags: Flags specifiers
 \* @width: Width specifier
 \* @precision: Precision specifier
 \* @size: Size specifier
 \*
 \* Return: Number of written chars.
 \*/
int write\_unsgnd(int is\_negative, int ind,
 char buffer[],
 int flags, int width, int precision, int size)
{
 /\* The number is stored at the bufer's right and starts at position i \*/
 int length = BUFF\_SIZE - ind - 1, i = 0;
 char padd = ' ';

 UNUSED(is\_negative);
 UNUSED(size);

 if (precision == 0 && ind == BUFF\_SIZE - 2 && buffer[ind] == '0')
 return (0); /\* printf(".0d", 0) no char is printed \*/

 if (precision > 0 && precision < length)
 padd = ' ';

 while (precision > length)
 {
 buffer[--ind] = '0';
 length++;
 }

 if ((flags & F\_ZERO) && !(flags & F\_MINUS))
 padd = '0';

 if (width > length)
 {
 for (i = 0; i < width - length; i++)
 buffer[i] = padd;

 buffer[i] = '\0';

 if (flags & F\_MINUS) /\* Asign extra char to left of buffer [buffer>padd]\*/
 {
 return (write(1, &buffer[ind], length) + write(1, &buffer[0], i));
 }
 else /\* Asign extra char to left of padding [padd>buffer]\*/
 {
 return (write(1, &buffer[0], i) + write(1, &buffer[ind], length));
 }
 }

 return (write(1, &buffer[ind], length));
}

/\*\*
 \* write\_pointer - Write a memory address
 \* @buffer: Arrays of chars
 \* @ind: Index at which the number starts in the buffer
 \* @length: Length of number
 \* @width: Wwidth specifier
 \* @flags: Flags specifier
 \* @padd: Char representing the padding
 \* @extra\_c: Char representing extra char
 \* @padd\_start: Index at which padding should start
 \*
 \* Return: Number of written chars.
 \*/
int write\_pointer(char buffer[], int ind, int length,
 int width, int flags, char padd, char extra\_c, int padd\_start)
{
 int i;

 if (width > length)
 {
 for (i = 3; i < width - length + 3; i++)
 buffer[i] = padd;
 buffer[i] = '\0';
 if (flags & F\_MINUS && padd == ' ')/\* Asign extra char to left of buffer \*/
 {
 buffer[--ind] = 'x';
 buffer[--ind] = '0';
 if (extra\_c)
 buffer[--ind] = extra\_c;
 return (write(1, &buffer[ind], length) + write(1, &buffer[3], i - 3));
 }
 else if (!(flags & F\_MINUS) && padd == ' ')/\* extra char to left of buffer \*/
 {
 buffer[--ind] = 'x';
 buffer[--ind] = '0';
 if (extra\_c)
 buffer[--ind] = extra\_c;
 return (write(1, &buffer[3], i - 3) + write(1, &buffer[ind], length));
 }
 else if (!(flags & F\_MINUS) && padd == '0')/\* extra char to left of padd \*/
 {
 if (extra\_c)
 buffer[--padd\_start] = extra\_c;
 buffer[1] = '0';
 buffer[2] = 'x';
 return (write(1, &buffer[padd\_start], i - padd\_start) +
 write(1, &buffer[ind], length - (1 - padd\_start) - 2));
 }
 }
 buffer[--ind] = 'x';
 buffer[--ind] = '0';
 if (extra\_c)
 buffer[--ind] = extra\_c;
 return (write(1, &buffer[ind], BUFF\_SIZE - ind - 1));
}
include "main.h"

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* WRITE HANDLE \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
/\*\*
 \* handle\_write\_char - 문자열을 인쇄합니다.
 \* @c: 문자 유형.
 \* @버퍼: 인쇄를 처리할 버퍼 배열
 \* @flags: 활성 플래그를 계산합니다.
 \* @width: 너비 가져오기.
 \* @precision: 정밀도 지정자
 \* @size: 크기 지정자
 \*
 반환값 \*: 인쇄된 문자 수.
 \*/
int handle\_write\_char(char c, char buffer[],
 int 플래그, int 너비, int 정밀도, int 크기)
{ /\* 문자는 왼쪽에, 패드는 버퍼의 오른쪽에 저장됩니다 \*/
 int i = 0;
 char padd = ' ';

 UNUSED(precision);
 UNUSED(size);

 if (flags & F\_ZERO)
 padd = '0';

 buffer[i++] = c;
 buffer[i] = '\0';

 if (width > 1)
 {
 buffer[BUFF\_SIZE - 1] = '\0';
 for (i = 0; i < width - 1; i++)
 buffer[BUFF\_SIZE - i - 2] = pad;

 if (flags & F\_MINUS)
 return (write(1, &buffer[0], 1) +.
 write(1, &buffer[BUFF\_SIZE - i - 1], width - 1));
 else
 return (write(1, &buffer[BUFF\_SIZE - i - 1], width - 1) +.
 write(1, &buffer[0], 1));
 }

 return (write(1, &buffer[0], 1));
}

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* WRITE NUMBER \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
/\*\*
 \* write\_number - 문자열을 인쇄합니다.
 \* @is\_negative: 인자 목록
 \* @ind: 문자 유형
 \* @버퍼: 인쇄를 처리할 버퍼 배열
 \* @flags: 활성 플래그를 계산합니다.
 \* @width: 너비 가져오기
 \* @precision: 정밀도 지정자
 \* @size: 크기 지정자
 \*
 반환값 \*: 인쇄된 문자 수.
 \*/
int write\_number(int is\_negative, int ind, char buffer[],
 int flags, int width, int precision, int size)
{
 int length = BUFF\_SIZE - ind - 1;
 char pad = ' ', extra\_ch = 0;

 UNUSED(size);

 if ((flags & F\_ZERO) && !(flags & F\_MINUS))
 padd = '0';
 if (is\_negative)
 extra\_ch = '-';
 else if (flags & F\_PLUS)
 extra\_ch = '+';
 else if (flags & F\_SPACE)
 extra\_ch = ' ';

 반환 (쓰기\_num(ind, 버퍼, 플래그, 너비, 정밀도,
 길이, 패드, 추가\_ch));
}

/\*\*
 \* write\_num - 버퍼를 사용하여 숫자 쓰기
 \* @ind: 버퍼에서 숫자가 시작되는 인덱스
 \* @버퍼: 버퍼
 \* @flags: 플래그
 \* @width: 너비
 \* @prec: 정밀도 지정자
 \* @length: 숫자 길이
 \* @padd: 패딩 문자
 \* @extra\_c: 추가 문자
 \*
 \* 반환: 인쇄된 문자 수입니다.
 \*/
int write\_num(int ind, char buffer[],
 int flags, int width, int prec,
 int length, char pad, char extra\_c)
{
 int i, pad\_start = 1;

 if (prec == 0 && ind == BUFF\_SIZE - 2 && buffer[ind] == '0' && width == 0)
 return (0); /\* printf(".0d", 0) 문자 출력 없음 \*/
 if (prec == 0 && ind == BUFF\_SIZE - 2 && buffer[ind] == '0')
 buffer[ind] = padd = ' '; /\* 너비는 ' ' 패딩으로 표시 \*/
 if (prec > 0 && prec < length)
 padd = ' ';
 while (prec > length)
 buffer[--ind] = '0', length++;
 if (extra\_c != 0)
 length++;
 if (너비 > 길이)
 {
 for (i = 1; i < width - length + 1; i++)
 buffer[i] = pad;
 buffer[i] = '\0';
 if (flags & F\_MINUS && padd == ' ')/\* 버퍼 왼쪽에 추가 문자 할당 \*/
 {
 if (extra\_c)
 buffer[--ind] = extra\_c;
 return (write(1, &buffer[ind], length) + write(1, &buffer[1], i - 1));
 }
 else if (!(flags & F\_MINUS) && padd == ' ')/\* buff의 왼쪽에 추가 문자 \*/
 {
 if (extra\_c)
 buffer[--ind] = extra\_c;
 return (write(1, &buffer[1], i - 1) + write(1, &buffer[ind], length));
 }
 else if (!(flags & F\_MINUS) && padd == '0')/\* padd 왼쪽에 추가 문자 \*/
 {
 if (extra\_c)
 buffer[--padd\_start] = extra\_c;
 return (write(1, &buffer[padd\_start], i - padd\_start) +.
 write(1, &buffer[ind], length - (1 - padd\_start)));
 }
 }
 if (extra\_c)
 buffer[--ind] = extra\_c;
 반환 (쓰기(1, &버퍼[ind], 길이));
}

/\*\*
 \* write\_unsgnd - 부호 없는 숫자를 씁니다.
 \* @is\_negative: 숫자가 음수인지 여부를 나타내는 숫자
 \* @ind: 버퍼에서 숫자가 시작되는 인덱스
 \* @버퍼: 문자 배열
 \* @flags: 플래그 지정자
 \* @width: 너비 지정자
 \* @precision: 정밀도 지정자
 \* @size: 크기 지정자
 \*
 \* 반환: 기록된 문자 수.
 \*/
int write\_unsgnd(int is\_negative, int ind,
 char buffer[],
 int flags, int width, int precision, int size)
{
 /\* 숫자는 버퍼의 오른쪽에 저장되며 위치 i \*/부터 시작됩니다.
 int length = BUFF\_SIZE - ind - 1, i = 0;
 char pad = ' ';

 UNUSED(is\_negative);
 UNUSED(size);

 if (precision == 0 && ind == BUFF\_SIZE - 2 && buffer[ind] == '0')
 return (0); /\* printf(".0d", 0) no char is printed \*/

 if (정밀도 > 0 && 정밀도 < 길이)
 padd = ' ';

 동안 (정밀도 > 길이)
 {
 buffer[--ind] = '0';
 length++;
 }

 if ((flags & F\_ZERO) && !(flags & F\_MINUS))
 padd = '0';

 if (너비 > 길이)
 {
 for (i = 0; i < width - length; i++)
 buffer[i] = padd;

 buffer[i] = '\0';

 if (flags & F\_MINUS) /\* 버퍼 왼쪽에 추가 문자 할당 [buffer>padd]\*/
 {
 반환 (쓰기(1, &버퍼[ind], 길이) + 쓰기(1, &버퍼[0], i));
 }
 else /\* 패딩 왼쪽에 추가 문자 할당 [padd>buffer]\*/
 {
 return (write(1, &buffer[0], i) + w