static gboolean cover_name_filter(const gchar *name, const gchar *filter, const gboolean ret_on_empty) { gboolean result = FALSE; gchar **splitted; gchar *current; gchar *lname; gint i; if (!filter || strlen(filter) == 0) { return ret_on_empty; } splitted = g_strsplit(filter, ",", 0); lname = g_strdup(name); g_strdown(lname); for (i = 0; !result && (current = splitted[i]); i++) { gchar *stripped = g_strstrip(g_strdup(current)); g_strdown(stripped); result = result || strstr(lname, stripped); g_free(stripped); } g_free(lname); g_strfreev(splitted); return result; }
static void complete_from_nicklist(GList **outlist, CHANNEL_REC *channel, const char *nick, const char *suffix) { MODULE_CHANNEL_REC *mchannel; GSList *tmp; GList *ownlist; char *str; int len; /* go through the last x nicks who have said something in the channel. nicks of all the "own messages" are placed before others */ ownlist = NULL; len = strlen(nick); mchannel = MODULE_DATA(channel); for (tmp = mchannel->lastmsgs; tmp != NULL; tmp = tmp->next) { LAST_MSG_REC *rec = tmp->data; if (g_strncasecmp(rec->nick, nick, len) == 0 && glist_find_icase_string(*outlist, rec->nick) == NULL) { str = g_strconcat(rec->nick, suffix, NULL); if (completion_lowercase) g_strdown(str); if (rec->own) ownlist = g_list_append(ownlist, str); else *outlist = g_list_append(*outlist, str); } } *outlist = g_list_concat(ownlist, *outlist); }
// return the number of files that match int vfsGetFileCount (const char *filename) { int i, count = 0; char fixed[NAME_MAX], tmp[NAME_MAX]; GSList *lst; strcpy (fixed, filename); vfsFixDOSName (fixed); g_strdown (fixed); for (lst = g_pakFiles; lst != NULL; lst = g_slist_next (lst)) { VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data; if (strcmp (file->name, fixed) == 0) count++; } for (i = 0; i < g_numDirs; i++) { strcpy (tmp, g_strDirs[i]); strcat (tmp, fixed); if (access (tmp, R_OK) == 0) count++; } return count; }
int mode_util_accept_on_request (char *line, int case_sensitive, int cnt, ...) { va_list modelist; char *c_mode; char *cs_line; int i; if (!line || (line && strlen (line) == 0)) return 0; cs_line = g_strdup (line); if (!case_sensitive) g_strdown (cs_line); va_start (modelist, cnt); for (i = 0; i < cnt; i++) { c_mode = va_arg (modelist, char *); if (_mode_util_accept_one (cs_line, c_mode)) { free (cs_line); va_end (modelist); return 1; } } va_end (modelist); free (cs_line); return 0; }
static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char *nick, const char *address) { char *params, *target, *msg, *args, *str; g_return_if_fail(data != NULL); params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg); if (ischannel(*target)) { g_free(params); return; } /* private message for us */ str = g_strconcat("bot command ", msg, NULL); args = strchr(str+12, ' '); if (args != NULL) *args++ = '\0'; else args = ""; g_strdown(str); if (signal_emit(str, 4, args, server, nick, address)) { /* msg was a command - the msg event. */ signal_stop(); } g_free(str); g_free(params); }
void on_find_clicked ( ) { GtkTextBuffer *buffer; buffer = gtk_text_view_get_buffer ( mydata.meaning_text_view ); gtk_text_buffer_set_text ( buffer, "",-1); char *word, *entry_word; entry_word = gtk_entry_get_text ( mydata.input_word ); word = g_strchomp( g_strchug( g_strdown( entry_word ) ) ); //g_string_ascii_down () instead for comp /* ********** convert data. to mydata. ************** gchar *message = g_strdup_printf("Finding word %s", word); gtk_statusbar_pop( mydata.statusbar, mydata.statusbar_context_id ); // data.statusbar_context_id = gtk_statusbar_get_context_id ( data.statusbar,"on_find_clicked"); gtk_statusbar_push( data.statusbar, data.statusbar_context_id, message); */ if( strlen(word) != 0 ) find_meaning_put_gui( word ); //gtk_widget_show( data.window ); //gtk_statusbar_pop( data.statusbar, data.statusbar_context_id ); //gtk_statusbar_push( data.statusbar, data.statusbar_context_id,"Fill or choose a word" ); }
void on_input_word_changed (GtkEditable *editable, gpointer user_data) { // g_print("on_input_word_changed called\n"); char *word = NULL, *entry_word = NULL; entry_word = gtk_entry_get_text ( mydata.input_word ); // word = g_strchomp( g_strchug( g_strdown( entry_word ) ) ); // it has caused a Pango: index out of bound bug so use instead word = g_strdown( entry_word ); if( strlen( word ) == 0 ){ //g_print("on_input_word_changed():word is NULL\n"); //avoid some latency by commenting below //remove_all_from_list(); return ; //return as word is NULL and nothing to do } if( strlen( word ) == 1 ){ // // g_print("on_input_word_changed():word= %s\n", word ); load_hashtable_list(); // //list is loaded use it for auto completion GtkEntryCompletion *completion; completion = gtk_entry_completion_new(); gtk_entry_completion_set_text_column(completion, LIST_ITEM ); gtk_entry_set_completion(GTK_ENTRY(mydata.input_word), completion); g_signal_connect(G_OBJECT (completion), "match-selected",G_CALLBACK (on_match_select), NULL); gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(mydata.list_store)); // } }
static void player_pattern_compile (struct player_pattern *pp) { int res; free_player_pattern_compiled_data (pp); if (pp->pattern && pp->pattern[0]) { switch (pp->mode) { case PATTERN_MODE_REGEXP: pp->data = g_malloc (sizeof (regex_t)); res = regcomp ((regex_t *) pp->data, pp->pattern, REGCOMP_FLAGS); if (res) { pp->error = get_regerror (res, (regex_t *) pp->data); regfree ((regex_t *) pp->data); g_free (pp->data); pp->data = NULL; } break; case PATTERN_MODE_STRING: case PATTERN_MODE_SUBSTR: default: pp->data = g_strdup (pp->pattern); g_strdown (pp->data); break; } } }
/* Returns a string which can be used as key for case-insensitive sort; * input string is in locale encoding in GTK+1, in UTF-8 in GTK+2 */ static char *isort_key(char *src) { char *s; s = g_strdup(src); g_strdown(s); // !!! Consider replicating g_utf8_collate_key(), based on strxfrm() return (s); }
void load_hashtable_list( ){ char *word = NULL, *entry_word = NULL; entry_word = gtk_entry_get_text ( mydata.input_word ); // word = g_strchomp( g_strchug( g_strdown( entry_word ) ) ); // it has caused a Pango: index out of bound bug so use instead word = g_strdown( entry_word ); // if( ! isalpha( word[0] ) ){ //g_print("on_input_word_changed(): enter proper word\n"); // ************** show proper warning to enter proper word ***************** // gtk_statusbar_pop ( mydata.statusbar, mydata.statusbar_context_id ); gtk_statusbar_push (GTK_STATUSBAR (mydata.statusbar), mydata.statusbar_context_id, "Please enter/select proper english word"); // return; } //check if hash table is created for word[0] of not g_sprintf( file_loaded_name, APP_DBS"%c.db", g_ascii_tolower( word[0] ) ); //g_print("on_input_word_changed(): filename = %s\n",file_loaded_name); if( mydata.hash_tab[ g_ascii_toupper(word[0]) - 'A' ] == NULL ){ //remove the prev word entries //remove_all_from_list (); //g_print("on_input_word_changed(): generating hash table\n"); mydata.hash_tab[ g_ascii_toupper(word[0]) - 'A' ] = generate_hash_table( file_loaded_name ); mydata.list_store_arr[ g_ascii_toupper(word[0]) - 'A' ] = mydata.list_store; list_loaded = g_ascii_toupper(word[0]) - 'A'; //check if hash table is created or not by generate_hash_table() func call if( mydata.hash_tab[ g_ascii_toupper(word[0]) - 'A' ] == NULL ){ g_print("on_input_word_changed():\nafter trying to generate_hash_table\nfile: %s could not be located and loaded\n", file_loaded_name ); } }else{ //g_print("on_input_word_changed(): %d", list_loaded ); if( list_loaded != (g_ascii_toupper(word[0]) - 'A') ){ //remove_all_from_list (); //************ we have change here to fasten************ -------------->>>>>>>>> //load list from pointer else populate it if( mydata.list_store_arr[ g_ascii_toupper(word[0]) - 'A' ] == NULL ){ populate_list_only( file_loaded_name ); //g_print("on_input_word_changed(): list populated from file\n" ); }else{ mydata.list_store = mydata.list_store_arr[ g_ascii_toupper(word[0]) - 'A' ]; // following may be necessary gtk_tree_view_set_model ( mydata.treeview, GTK_TREE_MODEL(mydata.list_store) ); //g_print("on_input_word_changed(): list used from previous list\n" ); } list_loaded = (g_ascii_toupper(word[0]) - 'A'); } } // }
/* * Insert address into cache. * Enter: harvester Harvester object. * entry Header object. * cache Address cache to load. * name Name. * address eMail address. */ static void addrharvest_insert_cache( AddressHarvester *harvester, HeaderEntry *entry, AddressCache *cache, const gchar *name, const gchar *address ) { ItemPerson *person; ItemFolder *folder; gchar *folderName; gboolean newFolder; gint cnt; gchar *key, *value; newFolder = FALSE; folder = entry->folder; if( folder == NULL ) { newFolder = TRUE; /* No folder yet */ } if( entry->count % harvester->folderSize == 0 ) { newFolder = TRUE; /* Folder is full */ } /* Insert address */ key = g_strdup( address ); g_strdown( key ); person = g_hash_table_lookup( harvester->dupTable, key ); if( person ) { /* Update existing person to use longest name */ value = ADDRITEM_NAME(person); if( strlen( name ) > strlen( value ) ) { addritem_person_set_common_name( person, name ); } g_free( key ); } else { /* Folder if required */ if( newFolder ) { cnt = 1 + ( entry->count / harvester->folderSize ); folderName =g_strdup_printf( "%s (%d)", entry->header, cnt ); folder = addritem_create_item_folder(); addritem_folder_set_name( folder, folderName ); addritem_folder_set_remarks( folder, "" ); addrcache_id_folder( cache, folder ); addrcache_add_folder( cache, folder ); entry->folder = folder; g_free( folderName ); } /* Insert entry */ person = addrcache_add_contact( cache, folder, name, address, "" ); g_hash_table_insert( harvester->dupTable, key, person ); entry->count++; } addritem_parse_first_last( person ); }
static GList *completion_nicks_nonstrict(CHANNEL_REC *channel, const char *nick, const char *suffix) { GSList *nicks, *tmp; GList *list; char *tnick, *str, *in, *out; int len, str_len, tmplen; g_return_val_if_fail(channel != NULL, NULL); list = NULL; /* get all nicks from current channel, strip non alnum chars, compare again and add to completion list on matching */ len = strlen(nick); nicks = nicklist_getnicks(channel); str_len = 80; str = g_malloc(str_len+1); for (tmp = nicks; tmp != NULL; tmp = tmp->next) { NICK_REC *rec = tmp->data; tmplen = strlen(rec->nick); if (tmplen > str_len) { str_len = tmplen*2; str = g_realloc(str, str_len+1); } /* remove non alnum chars from nick */ in = rec->nick; out = str; while (*in != '\0') { if (i_isalnum(*in)) *out++ = *in; in++; } *out = '\0'; /* add to list if 'cleaned' nick matches */ if (g_strncasecmp(str, nick, len) == 0) { tnick = g_strconcat(rec->nick, suffix, NULL); if (completion_lowercase) g_strdown(tnick); if (glist_find_icase_string(list, tnick) == NULL) list = g_list_append(list, tnick); else g_free(tnick); } } g_free(str); g_slist_free(nicks); return list; }
// HYDRA: this now searches VFS/PAK files in addition to the filesystem // if FLAG is unspecified then ONLY dirs are searched. // PAK's are searched before DIRs to mimic engine behaviour // index is ignored when searching PAK files. // see ifilesystem.h char* vfsGetFullPath(const char *in, int index, int flag) { int count = 0; static char out[PATH_MAX]; char tmp[NAME_MAX]; int i; if (flag & VFS_SEARCH_PAK) { char fixed[NAME_MAX]; GSList *lst; strcpy (fixed, in); vfsFixDOSName (fixed); g_strdown (fixed); for (lst = g_pakFiles; lst != NULL; lst = g_slist_next (lst)) { VFS_PAKFILE* file = (VFS_PAKFILE*)lst->data; char *ptr,*lastptr; lastptr = file->name; while ((ptr = strchr(lastptr,'/')) != NULL) lastptr = ptr+1; if (strcmp (lastptr, fixed) == 0) { strncpy(out,file->name,PATH_MAX); return out; } } } if (!flag || (flag & VFS_SEARCH_DIR)) { for (i = 0; i < g_numDirs; i++) { strcpy (tmp, g_strDirs[i]); strcat (tmp, in); if (access (tmp, R_OK) == 0) { if (count == index) { strcpy (out, tmp); return out; } count++; } } } return NULL; }
static void sig_nickchange_over(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr) { char *signal; server->nick_changing = FALSE; signal = g_strconcat("event ", current_server_event, NULL); g_strdown(signal+6); signal_emit(signal, 4, data, server, nick, addr); g_free(signal); }
static void vfsInitPakFile (const char *filename) { pakheader_t header; FILE *f; long i; f = fopen (filename, "rb"); if (f == NULL) return; // read header fread (header.magic, 1, 4, f); fread (&header.diroffset, 1, 4, f); fread (&header.dirsize, 1, 4, f); // fix endianess header.diroffset = GINT32_FROM_LE (header.diroffset); header.dirsize = GINT32_FROM_LE (header.dirsize); // check that the magic header if (strncmp (header.magic, "PACK", 4)) { fclose (f); return; } g_FuncTable.m_pfnSysPrintf(" pak file: %s\n", filename); g_unzFiles = g_slist_append (g_unzFiles, f); fseek (f, header.diroffset, SEEK_SET); for (i = 0; i < (long)(header.dirsize/sizeof (pakentry_t)); i++) { VFS_PAKFILE* file; file = (VFS_PAKFILE*)g_malloc (sizeof (VFS_PAKFILE)); g_pakFiles = g_slist_append (g_pakFiles, file); fread (file->entry.filename, 1, sizeof (file->entry.filename), f); fread (&file->entry.offset, 1, sizeof (file->entry.offset), f); fread (&file->entry.size, 1, sizeof (file->entry.size), f); file->pak = f; // fix endianess file->entry.offset = GINT32_FROM_LE (file->entry.offset); file->entry.size = GINT32_FROM_LE (file->entry.size); // fix filename vfsFixDOSName (file->entry.filename); g_strdown (file->entry.filename); //g_FuncTable.m_pfnSysPrintf("vfs file from pak: %s\n", file->entry.filename); } }
void change_case (gint UpDown) { gint CurrentPage, l_min, l_max; gchar *buffer ; CurrentPage = gtk_notebook_get_current_page (GTK_NOTEBOOK(MainNotebook)); l_min = min_from_selection (GTK_EDITABLE(FPROPS(CurrentPage, Text))); l_max = max_from_selection (GTK_EDITABLE(FPROPS(CurrentPage, Text))); buffer = gtk_editable_get_chars (GTK_EDITABLE(FPROPS(CurrentPage, Text)), l_min, l_max); if (UpDown == 1) g_strup (buffer); else if (UpDown == 2) g_strdown (buffer); else if (UpDown == 3) { gint l_len, i, j; gchar *Delimiters = " \t\b\n\f\'\"{}()[]<>%^&*~-+=_@#$\\|/:;,.?!"; l_len = l_max - l_min; if ((buffer[0] >= 'a') && (buffer[0] <= 'z')) buffer[0] = buffer[0] - 'a' + 'A'; for (i = 1; i < l_len; i++) { for (j = 0; j <= (gint)strlen (Delimiters); j++) { if (buffer [i] == Delimiters[j]) { if ((buffer[i+1] >= 'a') && (buffer[i+1] <= 'z')) buffer[i+1] = buffer[i+1] - 'a' + 'A'; break; } } } } else if (UpDown == 4) { gint l_len, change_case, i; l_len = l_max - l_min; change_case = 'a' - 'A'; for (i = 0; i <= l_len; i++) { if ((buffer[i] >= 'A') && (buffer[i] <= 'Z')) buffer[i] = buffer[i] + change_case; else if ((buffer[i] >= 'a') && (buffer[i] <= 'z')) buffer[i] = buffer[i] - change_case; } } gtk_editable_delete_selection (GTK_EDITABLE(FPROPS(CurrentPage, Text))); gtk_editable_insert_text (GTK_EDITABLE(FPROPS(CurrentPage, Text)), buffer, strlen(buffer), &l_min); g_free (buffer); }
static void vfsInitPakFile(const char *filename) { unz_global_info gi; unzFile uf; guint32 i; int err; uf = unzOpen(filename); if(uf == NULL) return; g_unzFiles = g_slist_append(g_unzFiles, uf); err = unzGetGlobalInfo(uf, &gi); if(err != UNZ_OK) return; unzGoToFirstFile(uf); Sys_Printf("VFS Init: %s (pk3)\n", filename); for(i = 0; i < gi.number_entry; i++) { char filename_inzip[NAME_MAX]; unz_file_info file_info; VFS_PAKFILE *file; err = unzGetCurrentFileInfo(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); if(err != UNZ_OK) break; file = (VFS_PAKFILE *) safe_malloc(sizeof(VFS_PAKFILE)); g_pakFiles = g_slist_append(g_pakFiles, file); vfsFixDOSName(filename_inzip); g_strdown(filename_inzip); file->name = strdup(filename_inzip); file->size = file_info.uncompressed_size; file->zipfile = uf; memcpy(&file->zipinfo, uf, sizeof(unz_s)); if((i + 1) < gi.number_entry) { err = unzGoToNextFile(uf); if(err != UNZ_OK) break; } } }
static MimeViewer *get_viewer_for_content_type(MimeView *mimeview, const gchar *content_type) { GSList *cur; MimeViewerFactory *factory = NULL; MimeViewer *viewer = NULL; /* * FNM_CASEFOLD is a GNU extension * if its not defined copy the string to the stack and * convert the copy to lower case */ #ifndef FNM_CASEFOLD #define FNM_CASEFOLD 0 Xstrdup_a(content_type, content_type, return NULL); g_strdown((gchar *)content_type); #endif for (cur = mimeviewer_factories; cur != NULL; cur = g_slist_next(cur)) { MimeViewerFactory *curfactory = cur->data; gint i = 0; while (curfactory->content_types[i] != NULL) { if(!fnmatch(curfactory->content_types[i], content_type, FNM_CASEFOLD)) { debug_print("%s\n", curfactory->content_types[i]); factory = curfactory; break; } i++; } if (factory != NULL) break; } if (factory == NULL) return NULL; for (cur = mimeview->viewers; cur != NULL; cur = g_slist_next(cur)) { MimeViewer *curviewer = cur->data; if (curviewer->factory == factory) return curviewer; } viewer = factory->create_viewer(); gtk_container_add(GTK_CONTAINER(mimeview->mime_notebook), GTK_WIDGET(viewer->get_widget(viewer))); mimeview->viewers = g_slist_append(mimeview->viewers, viewer); return viewer; }
/* * ============================================================================ * Read all files in specified directory into address book. * Enter: harvester Harvester object. * cache Address cache to load. * msgList List of message numbers, or NULL to process folder. * Return: Status. * ============================================================================ */ gint addrharvest_harvest( AddressHarvester *harvester, AddressCache *cache, GList *msgList ) { gint retVal; GList *node; GList *listHdr; retVal = MGU_BAD_ARGS; g_return_val_if_fail( harvester != NULL, retVal ); g_return_val_if_fail( cache != NULL, retVal ); g_return_val_if_fail( harvester->path != NULL, retVal ); /* Clear cache */ addrcache_clear( cache ); cache->dataRead = FALSE; /* Build list of headers of interest */ listHdr = NULL; node = harvester->headerTable; while( node ) { HeaderEntry *entry; entry = node->data; if( entry->selected ) { gchar *p; p = g_strdup( entry->header ); g_strdown( p ); listHdr = g_list_append( listHdr, p ); } node = g_list_next( node ); } /* Process directory/files */ if( msgList == NULL ) { addrharvest_harvest_dir( harvester, cache, listHdr, harvester->path ); } else { addrharvest_harvest_list( harvester, cache, listHdr, msgList ); } mgu_free_dlist( listHdr ); /* Mark cache */ cache->modified = FALSE; cache->dataRead = TRUE; return retVal; }
/* * Parse tag name from line buffer. * Return: Buffer containing the tag name, or NULL if no delimiter char found. */ static gchar *vcard_get_tagname( char* line, gchar dlm ) { gint len = 0; gchar *tag = NULL; gchar *lptr = line; while( *lptr++ ) { if( *lptr == dlm ) { len = lptr - line; tag = g_strndup( line, len+1 ); tag[ len ] = '\0'; g_strdown( tag ); return tag; } } return tag; }
void on_text_selection_changed(GtkClipboard *clipboard, GdkEvent *event, gpointer data) { char* text = gtk_clipboard_wait_for_text(clipboard), *word = NULL; if(text) { //printf("%s\n", text); //gtk_clipboard_clear(clipboard); //gtk_clipboard_set_text( clipboard, "", 0 ); word = g_strdup( g_strchomp ( g_strchug ( g_strdown( text ) ) ) ); gtk_entry_set_text ( mydata.input_word, word ); load_hashtable_list( ); on_find_clicked(); } free( text ); free( word ); }
static void ctcp_reply(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr, const char *target) { char *args, *str; if (ignore_check(server, nick, addr, target, data, MSGLEVEL_CTCPS)) return; str = g_strconcat("ctcp reply ", data, NULL); args = strchr(str+11, ' '); if (args != NULL) *args++ = '\0'; else args = ""; g_strdown(str+11); if (!signal_emit(str, 5, args, server, nick, addr, target)) signal_emit("default ctcp reply", 5, data, server, nick, addr, target); g_free(str); }
static void autolog_open(SERVER_REC *server, const char *server_tag, const char *target) { LOG_REC *log; char *fname, *dir, *fixed_target, *params; log = logs_find_item(LOG_ITEM_TARGET, target, server_tag, NULL); if (log != NULL && !log->failed) { log_start_logging(log); return; } /* '/' -> '_' - don't even accidentally try to log to #../../../file if you happen to join to such channel.. similar for some characters that are metacharacters and/or illegal in Windows filenames. '%' -> '%%' - so strftime() won't mess with them */ fixed_target = escape_target(target); if (CHAT_PROTOCOL(server)->case_insensitive) g_strdown(fixed_target); /* $0 = target, $1 = server tag */ params = g_strconcat(fixed_target, " ", server_tag, NULL); g_free(fixed_target); fname = parse_special_string(autolog_path, server, NULL, params, NULL, 0); g_free(params); if (log_find(fname) == NULL) { log = log_create_rec(fname, autolog_level); if (!settings_get_bool("autolog_colors")) log->colorizer = log_colorizer_strip; log_item_add(log, LOG_ITEM_TARGET, target, server_tag); dir = g_path_get_dirname(log->real_fname); mkpath(dir, log_dir_create_mode); g_free(dir); log->temp = TRUE; log_update(log); log_start_logging(log); } g_free(fname); }
/* split the line to command and arguments */ static char *line_get_command(const char *line, char **args, int aliases) { const char *ptr, *cmdargs; char *cmd, *checkcmd; g_return_val_if_fail(line != NULL, NULL); g_return_val_if_fail(args != NULL, NULL); cmd = checkcmd = NULL; *args = ""; cmdargs = NULL; ptr = line; do { ptr = strchr(ptr, ' '); if (ptr == NULL) { checkcmd = g_strdup(line); cmdargs = ""; } else { checkcmd = g_strndup(line, (int) (ptr-line)); while (*ptr == ' ') ptr++; cmdargs = ptr; } if (aliases ? !alias_find(checkcmd) : !command_find(checkcmd)) { /* not found, use the previous */ g_free(checkcmd); break; } /* found, check if it has subcommands */ g_free_not_null(cmd); if (!aliases) cmd = checkcmd; else { cmd = g_strdup(alias_find(checkcmd)); g_free(checkcmd); } *args = (char *) cmdargs; } while (ptr != NULL); if (cmd != NULL) g_strdown(cmd); return cmd; }
static GList *completion_channel_nicks(CHANNEL_REC *channel, const char *nick, const char *suffix) { GSList *nicks, *tmp; GList *list; char *str; int len; g_return_val_if_fail(channel != NULL, NULL); g_return_val_if_fail(nick != NULL, NULL); if (*nick == '\0') return NULL; if (suffix != NULL && *suffix == '\0') suffix = NULL; /* put first the nicks who have recently said something */ list = NULL; complete_from_nicklist(&list, channel, nick, suffix); /* and add the rest of the nicks too */ len = strlen(nick); nicks = nicklist_getnicks(channel); for (tmp = nicks; tmp != NULL; tmp = tmp->next) { NICK_REC *rec = tmp->data; if (g_strncasecmp(rec->nick, nick, len) == 0 && rec != channel->ownnick) { str = g_strconcat(rec->nick, suffix, NULL); if (completion_lowercase) g_strdown(str); if (glist_find_icase_string(list, str) == NULL) list = g_list_append(list, str); else g_free(str); } } g_slist_free(nicks); /* remove non alphanum chars from nick and search again in case list is still NULL ("foo<tab>" would match "_foo_" f.e.) */ if (!completion_strict) list = g_list_concat(list, completion_nicks_nonstrict(channel, nick, suffix)); return list; }
static void ctcp_msg(IRC_SERVER_REC *server, const char *data, const char *nick, const char *addr, const char *target) { char *args, *str; if (ignore_check(SERVER(server), nick, addr, target, data, MSGLEVEL_CTCPS)) return; str = g_strconcat("ctcp msg ", data, NULL); args = strchr(str+9, ' '); if (args != NULL) *args++ = '\0'; else args = ""; g_strdown(str+9); if (!signal_emit(str, 5, server, args, nick, addr, target)) { signal_emit("default ctcp msg", 5, server, data, nick, addr, target); } g_free(str); }
static void cmd_statusbar(const char *data) { CONFIG_NODE *node; char *name, *cmd, *params, *signal; void *free_arg; if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &name, &cmd, ¶ms)) return; if (*name == '\0') { /* list all statusbars */ cmd_statusbar_list(); cmd_params_free(free_arg); return; } if (*cmd == '\0') { /* print statusbar info */ cmd_statusbar_print_info(name); cmd_params_free(free_arg); return; } /* lookup/create the statusbar node */ node = iconfig_node_traverse("statusbar", TRUE); node = config_node_section(node, active_statusbar_group->name, NODE_TYPE_BLOCK); node = config_node_section(node, name, NODE_TYPE_BLOCK); /* call the subcommand */ signal = g_strconcat("command statusbar ", cmd, NULL); g_strdown(signal); if (!signal_emit(signal, 4, params, NULL, NULL, node)) { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_STATUSBAR_UNKNOWN_COMMAND, cmd); } else { read_statusbar_config(); } g_free(signal); cmd_params_free(free_arg); }
/* * Insert person and address into address cache. * Enter: muttFile MUTT control data. * cache Address cache. * address E-Mail address. * name Name. * Return: E-Mail object, either inserted or found in hash table. */ static ItemEMail *mutt_insert_table( MuttFile *muttFile, AddressCache *cache, gchar *address, gchar *name ) { ItemPerson *person; ItemEMail *email; gchar *key; /* Test whether address already in hash table */ key = g_strdup( address ); g_strdown( key ); email = g_hash_table_lookup( muttFile->uniqTable, key ); if( email == NULL ) { /* No - create person */ person = addritem_create_item_person(); addritem_person_set_common_name( person, name ); addrcache_id_person( cache, person ); addrcache_add_person( cache, person ); /* Add email for person */ email = addritem_create_item_email(); addritem_email_set_address( email, address ); addrcache_id_email( cache, email ); addrcache_person_add_email( cache, person, email ); /* Insert entry */ g_hash_table_insert( muttFile->uniqTable, key, email ); } else { /* Yes - update person with longest name */ person = ( ItemPerson * ) ADDRITEM_PARENT(email); if( strlen( name ) > strlen( ADDRITEM_NAME(person) ) ) { addritem_person_set_common_name( person, name ); } /* Free up */ g_free( key ); } return email; }
static void botnet_event(BOT_REC *bot, const char *data) { char *params, *source, *target, *command, *args, *event; if (!bot->connected) return; params = cmd_get_params(data, 4 | PARAM_FLAG_GETREST, &source, &target, &command, &args); if (*target == '-' && target[1] == '\0') target = NULL; g_strdown(command); event = g_strconcat("botnet event ", command, NULL); signal_emit(event, 4, bot, args, source, target); g_free(event); g_free(params); }
/* DCC CHAT: text received */ static void dcc_chat_msg(DCC_REC *dcc, const char *msg) { char *cmd, *ptr; int reply; g_return_if_fail(dcc != NULL); g_return_if_fail(msg != NULL); reply = FALSE; if (g_strncasecmp(msg, "CTCP_MESSAGE ", 13) == 0) { /* bitchx (and ircii?) sends this */ msg += 13; dcc->mirc_ctcp = FALSE; } else if (g_strncasecmp(msg, "CTCP_REPLY ", 11) == 0) { /* bitchx (and ircii?) sends this */ msg += 11; reply = TRUE; dcc->mirc_ctcp = FALSE; } else if (*msg == 1) { /* Use the mirc style CTCPs from now on.. */ dcc->mirc_ctcp = TRUE; } /* Handle only DCC CTCPs */ if (*msg != 1) return; /* get ctcp command, remove \001 chars */ cmd = g_strconcat(reply ? "dcc reply " : "dcc ctcp ", msg+1, NULL); if (cmd[strlen(cmd)-1] == 1) cmd[strlen(cmd)-1] = '\0'; ptr = strchr(cmd+9, ' '); if (ptr != NULL) *ptr++ = '\0'; else ptr = ""; g_strdown(cmd+9); if (!signal_emit(cmd, 2, ptr, dcc)) signal_emit(reply ? "default dcc reply" : "default dcc ctcp", 2, msg, dcc); g_free(cmd); signal_stop(); }