Skip to content

Commit

Permalink
Rising Felix
Browse files Browse the repository at this point in the history
  • Loading branch information
ph0cx committed May 24, 2023
1 parent 9f32123 commit 1254bc6
Show file tree
Hide file tree
Showing 12 changed files with 974 additions and 0 deletions.
89 changes: 89 additions & 0 deletions errors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "shell.h"

/**
* _eputs -|Function|that|prints|an|input|string
* @ristrvi: |Represents|the|string|to|be|printed
*
* Return: |void|
*/

void _eputs(char *ristrvi)
{
int riivi = 0;

if (!ristrvi)
return;
while (ristrvi[riivi] != '\0')
{
_eputchar(ristrvi[riivi]);
riivi++;
}
}

/**
* _eputchar -|Functions|that|writes|the|character|c|to|stderr
* @ricvi: |Represents|the|character|to|print
*
* Return: |1|when successful,|when|on|error|-1|is|returned
* |and|errno|is|set|appropriately.
*/

int _eputchar(char ricvi)
{
static int riivi;
static char ribufvi[RIWRITE_BUF_SIZEVI];

if (ricvi == RIBUF_FLUSHVI || riivi >= RIWRITE_BUF_SIZEVI)
{
write(2, ribufvi, riivi);
riivi = 0;
}
if (ricvi != RIBUF_FLUSHVI)
ribufvi[riivi++] = ricvi;
return (1);
}

/**
* _putfd - |Function|thatwrites|the|character|c|to|given|fd
* @ricvi: |The|character|value|to|print
* @rifdvi: |The|file|descriptor|value|to|write|to
*
* Return:|On|error|-1|returned|but|1|when|success|1|
* and|errno|is|set|appropriately.
*/

int _putfd(char ricvi, int rifdvi)
{
static int riivi;
static char ribufvi[RIWRITE_BUF_SIZEVI];

if (ricvi == RIBUF_FLUSHVI || riivi >= RIWRITE_BUF_SIZEVI)
{
write(rifdvi, ribufvi, riivi);
riivi = 0;
}
if (ricvi != RIBUF_FLUSHVI)
ribufvi[riivi++] = ricvi;
return (1);
}

/**
* _putsfd - |Function|that|prints|an|input|string
* @ristrvi:|the|string|value|to|be|printed
* @rifdvi:|the|filedescriptor|value|to|write|to
*
* Return:|the|number|of|chars|put
*/

int _putsfd(char *ristrvi, int rifdvi)
{
int riivi = 0;

if (!ristrvi)
return (0);
while (*ristrvi)
{
riivi += _putfd(*ristrvi++, rifdvi);
}
return (riivi);
}
146 changes: 146 additions & 0 deletions errors1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#include "shell.h"

/**
* _erratoi - Function|that|converts|a|string|to|an|integer
* @risvi:|the|string|value|to|be|converted
* Return:|-1|on|error|else|0|if|no|converted|numbers|in|string
*
*/

int _erratoi(char *risvi)
{
int riivi = 0;
unsigned long int riresultvi = 0;

if (*risvi == '+')
risvi++; /*|TODO:|why|does|this|make|main|return|255?|*/
for (riivi = 0; risvi[riivi] != '\0'; riivi++)
{
if (risvi[riivi] >= '0' && risvi[riivi] <= '9')
{
riresultvi *= 10;
riresultvi += (risvi[riivi] - '0');
if (riresultvi > INT_MAX)
return (-1);
}
else
return (-1);
}
return (riresultvi);
}

/**
* print_error - |Function|that|prints|an|error|message
* @riinfovi:|the|parameter|&|return|info|struct
* @riestrvi:|string|containing|specified|error|type
* Return: |-1|on|error|else|0|if|no|converted|numbers|in|string
*
*/

void print_error(riinfo_tvi *riinfovi, char *riestrvi)
{
_eputs(riinfovi->rifnamevi);
_eputs(": ");
print_d(riinfovi->riline_countvi, STDERR_FILENO);
_eputs(": ");
_eputs(riinfovi->riargvvi[0]);
_eputs(": ");
_eputs(riestrvi);
}

/**
* print_d - |function|that|prints|a|decimal|(integer)|number|(base 10)
* @riinputvi: Represents|the|input
* @rifdvi: |Represents|the|filedescriptor|to|write|to
*
* Return:|number|of|characters|printed
*/

int print_d(int riinputvi, int rifdvi)
{
int (*__putchar)(char) = _putchar;
int riivi, ricountvi = 0;
unsigned int _riabsvi_, ricurrentvi;

if (rifdvi == STDERR_FILENO)
__putchar = _eputchar;
if (riinputvi < 0)
{
_riabsvi_ = -riinputvi;
__putchar('-');
ricountvi++;
}
else
_riabsvi_ = riinputvi;
ricurrentvi = _riabsvi_;
for (riivi = 1000000000; riivi > 1; riivi /= 10)
{
if (_riabsvi_ / riivi)
{
__putchar('0' + ricurrentvi / riivi);
ricountvi++;
}
ricurrentvi %= riivi;
}
__putchar('0' + ricurrentvi);
ricountvi++;

return (ricountvi);
}

/**
* convert_number - |a|clone|of|itoa|converter|function
* @rinumvi: Represnets|number
* @ribasevi: Represents|base
* @riflagsvi: Represents|argument|flags
*
* Return:|string
*/

char *convert_number(long int rinumvi, int ribasevi, int riflagsvi)
{
static char *riarrayvi;
static char ribuffervi[50];
char risignvi = 0;
char *riptrvi;
unsigned long rinvi = rinumvi;

if (!(riflagsvi & RICONVERT_UNSIGNEDVI) && rinumvi < 0)
{
rinvi = -rinumvi;
risignvi = '-';

}
riarrayvi = riflagsvi & RICONVERT_LOWERCASEVI ?
"0123456789abcdef" : "0123456789ABCDEF";
riptrvi = &ribuffervi[49];
*riptrvi = '\0';

do {
*--riptrvi = riarrayvi[rinvi % ribasevi];
rinvi /= ribasevi;
} while (rinvi != 0);

if (risignvi)
*--riptrvi = risignvi;
return (riptrvi);
}

/**
* remove_comments -|function|that|replaces|first|instance|of|'#'|with|'\0'
* @ribufvi: RepResnents|the|address|of|the|string|to|modify
*
* Return:|always||when|successful;
*/

void remove_comments(char *ribufvi)
{
int riivi;

for (riivi = 0; ribufvi[riivi] != '\0'; riivi++)
if (ribufvi[riivi] == '#' && (!riivi || ribufvi[riivi - 1] == ' '))
{
ribufvi[riivi] = '\0';
break;
}
}
77 changes: 77 additions & 0 deletions exits.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "shell.h"

/**
**_strncpy - |Function|that|copies|a|string
*@ridestvi: |Represents|the|destination|string|to|be|copied|to
*@risrcvi: |Represents|the|source|string
*@rinvi: |Represents|the|amount|of|characters|to|be|copied
*Return: |Returns|the|concatenated|string
*/

char *_strncpy(char *ridestvi, char *risrcvi, int rinvi)
{
int riivi, rijvi;
char *risvi = ridestvi;

riivi = 0;
while (risrcvi[riivi] != '\0' && riivi < rinvi - 1)
{
ridestvi[riivi] = risrcvi[riivi];
riivi++;
}
if (riivi < rinvi)
{
rijvi = riivi;
while (rijvi < rinvi)
{
ridestvi[rijvi] = '\0';
rijvi++;
}
}
return (risvi);
}

/**
**_strncat - |Function|that|concatenates|two|strings
*@ridestvi: |Represents|the|first|string
*@risrcvi: |Represnents|the|second|string
*@rinvi: |Represents|the|amount|of|bytes|to|be|maximally|used
*Return: |Returns|the|concatenated|string
*/

char *_strncat(char *ridestvi, char *risrcvi, int rinvi)
{
int riivi, rijvi;
char *risvi = ridestvi;

riivi = 0;
rijvi = 0;
while (ridestvi[riivi] != '\0')
riivi++;
while (risrcvi[rijvi] != '\0' && rijvi < rinvi)
{
ridestvi[riivi] = risrcvi[rijvi];
riivi++;
rijvi++;
}
if (rijvi < rinvi)
ridestvi[riivi] = '\0';
return (risvi);
}

/**
**_strchr - |Function|locates|a|character|in|a|string
*@risvi: |Represents|the|string|to|be|parsed
*@ricvi: |Represents|the|character|to|look|for
*Return: |'s'|a|pointer|to|the|memory|area|s
*/

char *_strchr(char *risvi, char ricvi)
{
do {
if (*risvi == ricvi)
return (risvi);
} while (*risvi++ != '\0');

return (NULL);
}
17 changes: 17 additions & 0 deletions generate-authors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOTDIR="$(git -C "$SCRIPTDIR" rev-parse --show-toplevel)"

set -x

# see also ".mailmap" for how email addresses and names are deduplicated
cat > "${ROOTDIR}/AUTHORS" <<- EOF
# File @generated by hack/generate-authors.sh. DO NOT EDIT.
# This file lists all contributors to the repository.
# See hack/generate-authors.sh to make modifications.
$(git -C "$ROOTDIR" log --format='%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf)
EOF
Loading

0 comments on commit 1254bc6

Please sign in to comment.