tape-kernel 1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
utils.h File Reference
#include "types.h"
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_ARGS   12

Functions

int abs (int x)
int strlen (const char *s)
int strcmp (const char *a, const char *b)
void strcpy (char *dest, const char *src)
void strcat (char *dest, const char *src)
void itoa (int num, char *str)
 itoa converts an integer to a decimal string
int atoi (const char *str)
 atoi converts a decimal string to an integer
void srand (uint32_t seed)
 srand seeds the random number generator
uint32_t rand (void)
 rand returns a pseudo-random 32 bit integer
int pargs (char *line, char *args[])
 pargs parses a command line into an argument array

Macro Definition Documentation

◆ MAX_ARGS

#define MAX_ARGS   12

Definition at line 5 of file utils.h.

Referenced by __shell(), and pargs().

Function Documentation

◆ abs()

int abs ( int x)

Definition at line 5 of file utils.c.

Referenced by __drw().

◆ atoi()

int atoi ( const char * str)

atoi converts a decimal string to an integer

atoi is a function that parses a string of digit characters and returns the corresponding integer value

Parameters
str,thenull-terminated decimal string to parse

using atoi is done with

#include "../lib/utils.h" //or just utils.h
int value = atoi("42");
int atoi(const char *str)
atoi converts a decimal string to an integer
Definition utils.c:118
See also
itoa()

Definition at line 118 of file utils.c.

Referenced by __shell().

◆ itoa()

void itoa ( int num,
char * str )

itoa converts an integer to a decimal string

itoa is a function that converts a signed integer into a null-terminated decimal string representation

Parameters
num,theinteger to convert
str,theoutput buffer for the resulting string

using itoa is done with

#include "../lib/utils.h" //or just utils.h
char buff[12];
itoa(-42, buff);
void itoa(int num, char *str)
itoa converts an integer to a decimal string
Definition utils.c:49
See also
atoi(), prtd()

Definition at line 49 of file utils.c.

Referenced by __getcpu(), and __prtd().

◆ pargs()

int pargs ( char * line,
char * args[] )

pargs parses a command line into an argument array

pargs is a function that splits a string into an argv-style array of null-terminated arguments, supporting quoted strings and skipping leading '/' characters

Parameters
line,theinput line to parse (modified in-place)
args,theoutput array of string pointers

using pargs is done with

#include "../lib/utils.h" //or just utils.h
char input[100];
char *args[MAX_ARGS];
rdln(input, 100);
int argc = pargs(input, args);
int pargs(char *line, char *args[])
pargs parses a command line into an argument array
Definition utils.c:189
#define MAX_ARGS
Definition utils.h:5
#define rdln
Definition vga.h:9
See also
shell(), MAX_ARGS

Definition at line 189 of file utils.c.

References MAX_ARGS.

Referenced by __shell().

◆ rand()

uint32_t rand ( void )

rand returns a pseudo-random 32 bit integer

rand is a function that generates a random number using a xor-shift algorithm on the internal rng state

using rand is done with

#include "../lib/utils.h" //or just utils.h
uint32_t rnd = rand();
unsigned int uint32_t
Definition types.h:30
uint32_t rand(void)
rand returns a pseudo-random 32 bit integer
Definition utils.c:162
See also
srand()

Definition at line 162 of file utils.c.

References rng_state.

◆ srand()

void srand ( uint32_t seed)

srand seeds the random number generator

srand is a function that initializes the xor-shift rng state with a given seed value

Parameters
seed,theinitial seed value for the rng

using srand is done with

#include "../lib/utils.h" //or just utils.h
srand(12345);
void srand(uint32_t seed)
srand seeds the random number generator
Definition utils.c:144
See also
rand()

Definition at line 144 of file utils.c.

References rng_state.

◆ strcat()

void strcat ( char * dest,
const char * src )

Definition at line 26 of file utils.c.

Referenced by __getcpu().

◆ strcmp()

int strcmp ( const char * a,
const char * b )

Definition at line 15 of file utils.c.

Referenced by ___init(), __fsdelete(), __fsfind(), and __shell().

◆ strcpy()

void strcpy ( char * dest,
const char * src )

Definition at line 21 of file utils.c.

Referenced by __fsadd(), and __getcpu().

◆ strlen()

int strlen ( const char * s)

Definition at line 9 of file utils.c.

Referenced by __shell().