GSList *server_redirect_getqueue(SERVER_REC *server, const char *event, const char *args) { REDIRECT_REC *rec; GSList *list; char **arglist; int found; list = g_hash_table_lookup(server->eventtable, event); for (; list != NULL; list = list->next) { rec = list->data; if (rec->argpos == -1) break; if (rec->arg == NULL) continue; /* we need to check that the argument is right.. */ arglist = g_strsplit(args, " ", -1); found = (strarray_length(arglist) > rec->argpos && find_substr(rec->arg, arglist[rec->argpos])); g_strfreev(arglist); if (found) break; } return list; }
static bool search (Point pt, const char *s, int forward, int regexp) { Line *lp = pt.p; astr as = get_line_text (lp); size_t ssize = strlen (s), from = 0, to = astr_len (as); bool downcase = get_variable_bool ("case-fold-search") && no_upper (s, ssize, regexp); bool notbol = false, noteol = false; int pos; if (ssize < 1) return false; /* Match first line. */ if (forward) { notbol = pt.o > from; from = pt.o; } else { noteol = pt.o < to; to = pt.o; } pos = find_substr (as, s, ssize, from, to, forward, notbol, noteol, regexp, downcase); /* Match following lines. */ while (pos < 0) { lp = (forward ? get_line_next : get_line_prev) (lp); if (lp == get_buffer_lines (cur_bp)) break; as = get_line_text (lp); pos = find_substr (as, s, ssize, 0, astr_len (as), forward, false, false, regexp, downcase); } if (pos < 0) return false; while (get_buffer_pt (cur_bp).p != lp) (forward ? next_line : previous_line) (); pt = get_buffer_pt (cur_bp); pt.o = pos; set_buffer_pt (cur_bp, pt); thisflag |= FLAG_NEED_RESYNC; return true; }
static char * find_automount() { char *ps_command, *ps_output_line, *retaddr, *taddr; int qlen; FILE *ps_output_pipe; ps_output_line = (char *) malloc( PS_OUTPUT_LINE_SIZE ); if (ps_output_line == NULL) { return( NULL ); } #ifdef LINUX ps_command = "ps ax"; #else ps_command = "ps -ef"; #endif ps_output_pipe = popen_call( ps_command, "r" ); if (ps_output_pipe == NULL) { free( ps_output_line ); return( NULL ); } taddr = NULL; while (fgets( ps_output_line, PS_OUTPUT_LINE_SIZE - 1, ps_output_pipe ) != NULL) { qlen = strlen( ps_output_line ); if (qlen > 0) if (ps_output_line[ qlen-1 ] == '\n') ps_output_line[ qlen-1 ] = '\0'; taddr = find_substr( ps_output_line, "automount" ); if (taddr != NULL) { break; } } pclose_call( ps_output_pipe ); /* If you want to return the entire line, skip this bit and return ps_output_line */ if (taddr != NULL) { qlen = strlen( taddr ); retaddr = (char *) malloc( qlen+1 ); if (retaddr == NULL) { free( ps_output_line ); return( NULL ); } strcpy( retaddr, taddr ); free( ps_output_line ); return( retaddr ); } else return( NULL ); }
static int ps_to_automount_dir() { char *automount_cmd, *switch_automount, *qaddr; int qlen; /* If there is no automount process, then there is no automount directory */ automount_cmd = find_automount(); if (automount_cmd == NULL) { automount_dir[ 0 ] = '\0'; automount_len = 0; return( 0 ); } /* If there is an automount process, but it doesn't call out an automount directory, then the default automount directory is the automount directory */ switch_automount = find_substr( automount_cmd, "-M" ); if (switch_automount == NULL) { strcpy( &automount_dir[ 0 ], DEFAULT_AUTOMOUNT ); automount_len = strlen( DEFAULT_AUTOMOUNT ); free( automount_cmd ); return( 0 ); } switch_automount += 2; /* skip past "-M" */ qaddr = next_non_blank( switch_automount ); /* start of automount dir */ if (qaddr == NULL) { strcpy( &automount_dir[ 0 ], DEFAULT_AUTOMOUNT ); automount_len = strlen( DEFAULT_AUTOMOUNT ); free( automount_cmd ); return( 0 ); } else switch_automount = qaddr; qaddr = strchr( switch_automount, ' ' ); /* end of automount dir */ if (qaddr == NULL) qlen = strlen( switch_automount ); else qlen = qaddr - switch_automount; strncpy( &automount_dir[ 0 ], switch_automount, qlen ); automount_dir[ qlen ] = '\0'; automount_len = qlen; free( automount_cmd ); return( 0 ); }
static void read_settings(void) { #ifndef WIN32 static int signals[] = { SIGINT, SIGQUIT, SIGTERM, SIGALRM, SIGUSR1, SIGUSR2 }; static char *signames[] = { "int", "quit", "term", "alrm", "usr1", "usr2" }; const char *ignores; struct sigaction act; int n; ignores = settings_get_str("ignore_signals"); sigemptyset (&act.sa_mask); act.sa_flags = 0; /* reload config on SIGHUP */ act.sa_handler = sig_reload_config; sigaction(SIGHUP, &act, NULL); for (n = 0; n < sizeof(signals)/sizeof(signals[0]); n++) { act.sa_handler = find_substr(ignores, signames[n]) ? SIG_IGN : SIG_DFL; sigaction(signals[n], &act, NULL); } #ifdef HAVE_SYS_RESOURCE_H if (!settings_get_bool("override_coredump_limit")) setrlimit(RLIMIT_CORE, &orig_core_rlimit); else { struct rlimit rlimit; rlimit.rlim_cur = RLIM_INFINITY; rlimit.rlim_max = RLIM_INFINITY; if (setrlimit(RLIMIT_CORE, &rlimit) == -1) settings_set_bool("override_coredump_limit", FALSE); } #endif #endif }
int main(int argc, char const *argv[]) { char string[256]; char string1[256]; printf("Input test string0: "); fgets(string, 256, stdin); printf("Input test string1: "); fgets(string1, 256, stdin); char *ptr = find_substr(string, string1); if (ptr) { printf("%s\n", ptr); } else { printf("not found\n"); } return 0; }
void main() { if(find_substr("C is fun", "is") != -1) printf("Substring is found.\n"); }
// read "count" lines from the end starting from "startline" extern std::map<long, char*> userlog_read(const char * username, long startline, const char * search_substr) { std::map<long, char*> lines; long linecount = 0; char line[MAX_MESSAGE_LEN+1]; int linepos = 0; char c, prev_c = 0; long pos; char * filename = userlog_filename(username); if (FILE *fp = fopen(filename, "r")) { // set position to the end of file fseek(fp, 0, SEEK_END); pos = ftell(fp); // read file reversely by byte do { pos--; fseek(fp, pos, SEEK_SET); c = fgetc(fp); // add char into line array if (c != '\n') line[linepos] = c; // end of line (or start of file) if ((c == '\n' && c != prev_c) || pos == -1) { // hack for large lines (instead we will receive cut line without start symbols) if (linepos == MAX_MESSAGE_LEN) { // return carriage to read whole line to(from) start pos = pos + MAX_MESSAGE_LEN; linepos = 0; } if (linepos > 0) { line[linepos] = '\0'; // set end of string strreverse(line); linepos = 0; // reset position inside line linecount++; if (linecount >= startline) { if (search_substr && strlen(search_substr) > 0) { if (find_substr(line, search_substr)) lines[linecount] = xstrdup(line); } else { lines[linecount] = xstrdup(line); } } // limitation of results if (lines.size() >= userlog_max_output_lines) break; } } prev_c = c; if (c != '\n' && linepos < MAX_MESSAGE_LEN) linepos++; } while (c != EOF); fclose(fp); } return lines; }
int main(int argc, char **argv) { if (find_substr("C is fun", "fun") != -1) { printf("Substring is found.\n"); } }