summaryrefslogtreecommitdiff
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c126
1 files changed, 3 insertions, 123 deletions
diff --git a/src/common.c b/src/common.c
index c8b8d9a..2a9232b 100644
--- a/src/common.c
+++ b/src/common.c
@@ -77,28 +77,6 @@ int file_edit(char* path, char* editor) {
return system(cmd);
}
-
-/**
- * Yup, wrote my own.
- * TODO: Make this work with escaped path delimiters
- * TODO: Write this function description
- *
- * @return int Basename path length
- */
-int basename(char* path, char* out) {
- int path_len = strlen(path);
- // Start from the right and move left
- for(int i = path_len; i > 0; i--) {
- // Copy if an extension delimiter (a period) is found
- if(path[i] == '/') {
- strcpy(out, &path[i + 1]);
- return i;
- }
- }
- return -1;
-}
-
-
/**
* Just a wrapper function to call the specified line search function for case
* insensitive or case sensitive matching.
@@ -110,113 +88,15 @@ int basename(char* path, char* out) {
*/
int str_contains(char* line, char* term, int case_insensitive) {
if(case_insensitive == 1) {
- return str_contains_case_insensitive(line, term);
+ if(strcasestr(line, term) != NULL)
+ return 1;
} else {
- return str_contains_case_sensitive(line, term);
- }
-}
-
-
-/**
- * Performs a case insensitive search in the given line for the specified term.
- *
- * Note that for the sake of efficiency, this function is fairly confusing
- * (sorry). Learning how chars and ints relate in c will help tremendously
- * to understand this function.
- *
- * @param str String to check for the search term
- * @param term Search term to find in line
- *
- * @return int Search term found (1) or not (0)
- */
-int str_contains_case_insensitive(char* str, char* term) {
- // String char index
- int si = 0;
- // Term char index
- int ti = 0;
- int term_len = strlen(term);
-
- // Compare one char at a time
- while(str[si] != '\0') {
- // Current str char
- char lc;
- // Current term char
- char tc;
-
- // Welcome to the confusing part (see function description)
-
- // Convert current term char to lowercase
- if(term[ti] >= 97 && term[ti] <= 122) {
- // Already lower case
- tc = term[ti];
- } else if(term[ti] >= 65 && term[ti] <= 90) {
- // Uppercase. Add 32 to get lowercase equivelant.
- tc = term[ti] + 32;
- } else {
- // Term char isn't a letter. Must be a symbol or something ELSE...
- // Take it as it is.
- tc = term[ti];
- }
-
- // Convert current str char to lowercase
- if(str[si] >= 97 && str[si] <= 122) {
- // Already lower case
- lc = str[si];
- } else if(str[si] >= 65 && str[si] <= 90) {
- // Uppercase. Add 32 to get lowercase equivelant.
- lc = str[si] + 32;
- } else {
- // Term char isn't a letter. Must be a symbol or something ELSE...
- // Take it as it is.
- lc = str[si];
- }
-
- // Compare the temp lowercase version of the current str and term chars
- if(lc == tc) {
- ti++;
- } else {
- ti = 0;
- }
-
- // Return if we've matched the entire search term
- if(ti == term_len) { return 1; }
-
- si++;
- }
- return 0;
-}
-
-
-/**
- * Performs a case sensitive search in the given string for the specified term.
- *
- * @param str String to check for the search term
- * @param term Search term to find in str
- *
- * @return int Search term found (1) or not (0)
- */
-int str_contains_case_sensitive(char* str, char* term) {
- int s = 0;
- int t = 0;
- int term_len = strlen(term);
-
- // Compare one char at a time
- while(str[s] != '\0') {
- if(t == term_len) {
+ if(strstr(line, term) != NULL)
return 1;
- } else if(term[t] == str[s]) {
- // Found a single char match. Increment to the next term char
- t++;
- } else {
- // Reset the match counter if a partial or no match was made
- t = 0;
- }
- s++;
}
return 0;
}
-
/**
* Removes the extension from the given string filename
*

Generated by cgit