This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // file_count will add one to the count because zero is reserved for errors | |
| size_t file_count(const char* dir_nm){ | |
| DIR* dir=opendir(dir_nm); | |
| if(!dir)return 0; | |
| struct dirent* entity=readdir(dir); | |
| size_t count=0; | |
| for(;readdir(dir);count++); | |
| closedir(dir); | |
| return count; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _Bool strcmp_until(const char* s1,const char* s2,const char until){ | |
| for(size_t i=0;s1[i]!=until;i++) | |
| if(s1[i]!=s2[i])return 1; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _Bool starts_with_word(const char* str, const char* word){ | |
| for(size_t i=0;;i++){ | |
| if(!((str[i]>='A'&&str[i]<='Z')||(str[i]>='a'&&str[i]<='z')||str[i]=='_')){ | |
| if(word[i])return 1; | |
| break; | |
| } | |
| if(str[i]!=word[i]){ | |
| return 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _Bool starts_with(const char* in, const char* sw){ | |
| for(size_t i=0;sw[i];i++) | |
| if(in[i]!=sw[i]) | |
| return 1; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // returns position of the last byte in an array or string whose length is known. | |
| size_t get_last_byte_ex(const char* const bytes, const char byte,size_t len, _Bool* const exists){ | |
| while(bytes[len]!=byte){ | |
| if(!len){ | |
| *exists=0; | |
| return 0; | |
| } | |
| len--; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // returns position of the last byte in an array or string whose length is known. | |
| size_t get_last_byte(const char* const bytes, const char byte,size_t len){ | |
| while(bytes[len]!=byte&&len)len--; | |
| return len; | |
| } | |
| // returns position of the last character of a string whose length is not known. | |
| size_t get_last_char(const char* const str, const char byte){ | |
| size_t pos=0; | |
| for(size_t i=0;str[i];i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| char** atokl(const char* const InC, const char* const delim, long unsigned int* len){ | |
| // eight as that provides room for small splitting operations | |
| long unsigned int capacity=8; | |
| char** tok=(char**)malloc(capacity*sizeof(char**)); | |
| if(!tok)return 0x0; | |
| tok[0]=strtok(strdup(InC), delim); | |
| { | |
| long unsigned int i=1; | |
| while(tok[i-1]!=NULL){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void print_str_esc(const char* str, FILE* stream){ | |
| for(size_t i=0;str[i];i++){ | |
| switch(str[i]){ | |
| case '\n': | |
| { | |
| putc('\\', stream); | |
| putc('n', stream); | |
| break; | |
| } | |
| case '\t': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| char* read_text_file(const char* const filenm){ | |
| char* buf; | |
| long unsigned int len; | |
| FILE* const f=fopen(filenm, "r"); | |
| if(f){ | |
| fseek(f, 0, SEEK_END); | |
| len=ftell(f); | |
| fseek(f, 0, SEEK_SET); | |
| buf=(char*)malloc(len+1); | |
| if(buf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| char* char_instance(char* src, char ch,size_t instance){ | |
| for(size_t c=0;*src&&c<instance;src++) | |
| if(*src==ch)c++; | |
| return src; | |
| } |