Fixed noninteractive exiting on NULL input to return the last exit
[simpleshell.git] / mystring.h
blob8932573fd729c51223d014c8a14e6f1b474274bf
1 #ifndef _MYSTRING_H
2 #define _MYSTRING_H
4 /**
5 * Arbitrary size string struct
6 * Note: only use with the functions defined herein,
7 * unless you want to just *READ* from the string
8 */
9 typedef struct mystring {
10 char *str;
11 int len;
12 int maxlen;
13 int incr;
14 } *MString;
16 /**
17 * Creates a string
18 * Note: use mystring_unset() on the return value once you're done with it
19 * Arguments:
20 * initial_size: initial available size for the string
21 * size_increment: by how much the allocated size should grow when needed
22 * Returns: a pointer to an initialized mystring struct
24 MString mystring_new(int, int);
26 /**
27 * Resets a string
28 * Note: this only sets the first character to '\0', as well as mystring->cursize to 0
29 * Arguments:
30 * string: string to be reset
32 void mystring_clear(MString);
34 /**
35 * Enlarges the allocated memory for the string by exactly mystring->incr
36 * Arguments:
37 * string: string to be enlarged
39 void mystring_enlarge(MString);
41 /**
42 * Appends a string to the mystring struct
43 * Note: it actually copies toinsert, so you can free it afterwards if appropriate
44 * Arguments:
45 * string: string to append toinsert to
46 * toinsert: the string to be appended to string
48 void mystring_str_append(MString, char *);
50 /**
51 * Appends a single character to the mystring struct
52 * Arguments:
53 * string: string to append toinsert to
54 * toinsert: character to append to string
56 void mystring_char_append(MString, char);
58 /**
59 * Frees a mystring struct
60 * Note: also frees the string held in the struct, so it can't be used anymore either
61 * Arguments:
62 * string: string to be freed
64 void mystring_free(MString);
66 /**
67 * Gets a line from a file (everything up to a '\n' or EOF) and appends it to a mystring struct
68 * Note: this may not work on \r\n newlines
69 * Arguments:
70 * string: string to append to
71 * file: filehandle to read from
73 int mystring_getline(MString, FILE *);
75 void mystring_truncate(MString, int);
77 void mystring_erase(MString, int, int);
79 int mystring_has_prefix(MString, char *);
81 int mystring_has_suffix(MString, char *);
83 int mystring_strip(MString);
84 #endif