2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 #include <sys/types.h>
34 #define XCHAT_DIR ".xchat2"
35 #define DEF_FONT "Monospace 9"
38 list_addentry (GSList
** list
, char *cmd
, char *name
)
41 int cmd_len
= 1, name_len
;
43 /* remove <2.8.0 stuff */
44 if (!strcmp (cmd
, "away") && !strcmp (name
, "BACK"))
48 cmd_len
= strlen (cmd
) + 1;
49 name_len
= strlen (name
) + 1;
51 pop
= malloc (sizeof (struct popup
) + cmd_len
+ name_len
);
52 pop
->name
= (char *) pop
+ sizeof (struct popup
);
53 pop
->cmd
= pop
->name
+ name_len
;
55 memcpy (pop
->name
, name
, name_len
);
57 memcpy (pop
->cmd
, cmd
, cmd_len
);
61 *list
= g_slist_append (*list
, pop
);
64 /* read it in from a buffer to our linked list */
67 list_load_from_data (GSList
** list
, char *ibuf
, int size
)
77 while (buf_get_line (ibuf
, &buf
, &pnt
, size
))
81 if (!strncasecmp (buf
, "NAME ", 5))
83 safe_strcpy (name
, buf
+ 5, sizeof (name
));
85 else if (!strncasecmp (buf
, "CMD ", 4))
87 safe_strcpy (cmd
, buf
+ 4, sizeof (cmd
));
90 list_addentry (list
, cmd
, name
);
100 list_loadconf (char *file
, GSList
** list
, char *defaultconf
)
107 snprintf (filebuf
, sizeof (filebuf
), "%s/%s", get_xdir_fs (), file
);
108 fh
= open (filebuf
, O_RDONLY
| OFLAGS
);
112 list_load_from_data (list
, defaultconf
, strlen (defaultconf
));
115 if (fstat (fh
, &st
) != 0)
121 ibuf
= malloc (st
.st_size
);
122 read (fh
, ibuf
, st
.st_size
);
125 list_load_from_data (list
, ibuf
, st
.st_size
);
131 list_free (GSList
** list
)
136 data
= (void *) (*list
)->data
;
138 *list
= g_slist_remove (*list
, data
);
143 list_delentry (GSList
** list
, char *name
)
146 GSList
*alist
= *list
;
150 pop
= (struct popup
*) alist
->data
;
151 if (!strcasecmp (name
, pop
->name
))
153 *list
= g_slist_remove (*list
, pop
);
163 cfg_get_str (char *cfg
, char *var
, char *dest
, int dest_len
)
167 if (!strncasecmp (var
, cfg
, strlen (var
)))
177 /*while (*cfg == ' ' || *cfg == '=')
180 while (*cfg
!= 0 && *cfg
!= '\n')
184 safe_strcpy (dest
, value
, dest_len
);
188 while (*cfg
!= 0 && *cfg
!= '\n')
199 cfg_put_str (int fh
, char *var
, char *value
)
204 snprintf (buf
, sizeof buf
, "%s = %s\n", var
, value
);
206 return (write (fh
, buf
, len
) == len
);
210 cfg_put_color (int fh
, int r
, int g
, int b
, char *var
)
215 snprintf (buf
, sizeof buf
, "%s = %04x %04x %04x\n", var
, r
, g
, b
);
217 return (write (fh
, buf
, len
) == len
);
221 cfg_put_int (int fh
, int value
, char *var
)
229 snprintf (buf
, sizeof buf
, "%s = %d\n", var
, value
);
231 return (write (fh
, buf
, len
) == len
);
235 cfg_get_color (char *cfg
, char *var
, int *r
, int *g
, int *b
)
239 if (!cfg_get_str (cfg
, var
, str
, sizeof (str
)))
242 sscanf (str
, "%04x %04x %04x", r
, g
, b
);
247 cfg_get_int_with_result (char *cfg
, char *var
, int *result
)
251 if (!cfg_get_str (cfg
, var
, str
, sizeof (str
)))
262 cfg_get_int (char *cfg
, char *var
)
266 if (!cfg_get_str (cfg
, var
, str
, sizeof (str
)))
272 char *xdir_fs
= NULL
; /* file system encoding */
273 char *xdir_utf
= NULL
; /* utf-8 encoding */
279 xdir_fs
= g_strdup_printf ("%s/" XCHAT_DIR
, g_get_home_dir ());
287 if (!xdir_utf
) /* never free this, keep it for program life time */
288 xdir_utf
= xchat_filename_to_utf8 (get_xdir_fs (), -1, 0, 0, 0);
294 check_prefs_dir (void)
296 char *dir
= get_xdir_fs ();
297 if (access (dir
, F_OK
) != 0)
299 if (mkdir (dir
, S_IRUSR
| S_IWUSR
| S_IXUSR
) != 0)
300 fe_message (_("Cannot create ~/.xchat2"), FE_MSG_ERROR
);
307 static char *dfile
= 0;
311 dfile
= malloc (strlen (get_xdir_fs ()) + 12);
312 sprintf (dfile
, "%s/xchat.conf", get_xdir_fs ());
317 /* Keep these sorted!! */
319 const struct prefs vars
[] = {
320 {"auto_save", P_OFFINT (autosave
), TYPE_BOOL
},
321 {"auto_save_url", P_OFFINT (autosave_url
), TYPE_BOOL
},
323 {"away_auto_unmark", P_OFFINT (auto_unmark_away
), TYPE_BOOL
},
324 {"away_reason", P_OFFSET (awayreason
), TYPE_STR
},
325 {"away_show_message", P_OFFINT (show_away_message
), TYPE_BOOL
},
326 {"away_show_once", P_OFFINT (show_away_once
), TYPE_BOOL
},
327 {"away_size_max", P_OFFINT (away_size_max
), TYPE_INT
},
328 {"away_timeout", P_OFFINT (away_timeout
), TYPE_INT
},
329 {"away_track", P_OFFINT (away_track
), TYPE_BOOL
},
331 {"completion_amount", P_OFFINT (completion_amount
), TYPE_INT
},
332 {"completion_auto", P_OFFINT (nickcompletion
), TYPE_BOOL
},
333 {"completion_sort", P_OFFINT (completion_sort
), TYPE_INT
},
334 {"completion_suffix", P_OFFSET (nick_suffix
), TYPE_STR
},
336 {"dcc_auto_chat", P_OFFINT (autodccchat
), TYPE_INT
},
337 {"dcc_auto_resume", P_OFFINT (autoresume
), TYPE_BOOL
},
338 {"dcc_auto_send", P_OFFINT (autodccsend
), TYPE_INT
},
339 {"dcc_blocksize", P_OFFINT (dcc_blocksize
), TYPE_INT
},
340 {"dcc_completed_dir", P_OFFSET (dcc_completed_dir
), TYPE_STR
},
341 {"dcc_dir", P_OFFSET (dccdir
), TYPE_STR
},
342 {"dcc_fast_send", P_OFFINT (fastdccsend
), TYPE_BOOL
},
343 {"dcc_global_max_get_cps", P_OFFINT (dcc_global_max_get_cps
), TYPE_INT
},
344 {"dcc_global_max_send_cps", P_OFFINT (dcc_global_max_send_cps
), TYPE_INT
},
345 {"dcc_ip", P_OFFSET (dcc_ip_str
), TYPE_STR
},
346 {"dcc_ip_from_server", P_OFFINT (ip_from_server
), TYPE_BOOL
},
347 {"dcc_max_get_cps", P_OFFINT (dcc_max_get_cps
), TYPE_INT
},
348 {"dcc_max_send_cps", P_OFFINT (dcc_max_send_cps
), TYPE_INT
},
349 {"dcc_permissions", P_OFFINT (dccpermissions
), TYPE_INT
},
350 {"dcc_port_first", P_OFFINT (first_dcc_send_port
), TYPE_INT
},
351 {"dcc_port_last", P_OFFINT (last_dcc_send_port
), TYPE_INT
},
352 {"dcc_remove", P_OFFINT (dcc_remove
), TYPE_BOOL
},
353 {"dcc_save_nick", P_OFFINT (dccwithnick
), TYPE_BOOL
},
354 {"dcc_send_fillspaces", P_OFFINT (dcc_send_fillspaces
), TYPE_BOOL
},
355 {"dcc_stall_timeout", P_OFFINT (dccstalltimeout
), TYPE_INT
},
356 {"dcc_timeout", P_OFFINT (dcctimeout
), TYPE_INT
},
358 {"dnsprogram", P_OFFSET (dnsprogram
), TYPE_STR
},
360 {"flood_ctcp_num", P_OFFINT (ctcp_number_limit
), TYPE_INT
},
361 {"flood_ctcp_time", P_OFFINT (ctcp_time_limit
), TYPE_INT
},
362 {"flood_msg_num", P_OFFINT (msg_number_limit
), TYPE_INT
},
363 {"flood_msg_time", P_OFFINT (msg_time_limit
), TYPE_INT
},
365 {"gui_auto_open_chat", P_OFFINT (autoopendccchatwindow
), TYPE_BOOL
},
366 {"gui_auto_open_dialog", P_OFFINT (autodialog
), TYPE_BOOL
},
367 {"gui_auto_open_recv", P_OFFINT (autoopendccrecvwindow
), TYPE_BOOL
},
368 {"gui_auto_open_send", P_OFFINT (autoopendccsendwindow
), TYPE_BOOL
},
369 {"gui_dialog_height", P_OFFINT (dialog_height
), TYPE_INT
},
370 {"gui_dialog_left", P_OFFINT (dialog_left
), TYPE_INT
},
371 {"gui_dialog_top", P_OFFINT (dialog_top
), TYPE_INT
},
372 {"gui_dialog_width", P_OFFINT (dialog_width
), TYPE_INT
},
373 {"gui_hide_menu", P_OFFINT (hidemenu
), TYPE_BOOL
},
374 {"gui_input_spell", P_OFFINT (gui_input_spell
), TYPE_BOOL
},
375 {"gui_input_style", P_OFFINT (style_inputbox
), TYPE_BOOL
},
376 {"gui_join_dialog", P_OFFINT (gui_join_dialog
), TYPE_BOOL
},
377 {"gui_lagometer", P_OFFINT (lagometer
), TYPE_INT
},
378 {"gui_mode_buttons", P_OFFINT (chanmodebuttons
), TYPE_BOOL
},
379 {"gui_pane_left_size", P_OFFINT (gui_pane_left_size
), TYPE_INT
},
380 {"gui_pane_right_size", P_OFFINT (gui_pane_right_size
), TYPE_INT
},
381 {"gui_quit_dialog", P_OFFINT (gui_quit_dialog
), TYPE_BOOL
},
382 {"gui_slist_fav", P_OFFINT (slist_fav
), TYPE_INT
},
383 {"gui_slist_select", P_OFFINT (slist_select
), TYPE_INT
},
384 {"gui_slist_skip", P_OFFINT (slist_skip
), TYPE_BOOL
},
385 {"gui_throttlemeter", P_OFFINT (throttlemeter
), TYPE_INT
},
386 {"gui_topicbar", P_OFFINT (topicbar
), TYPE_BOOL
},
387 {"gui_tray", P_OFFINT (gui_tray
), TYPE_BOOL
},
388 {"gui_tray_flags", P_OFFINT (gui_tray_flags
), TYPE_INT
},
389 {"gui_tweaks", P_OFFINT (gui_tweaks
), TYPE_INT
},
390 {"gui_ulist_buttons", P_OFFINT (userlistbuttons
), TYPE_BOOL
},
391 {"gui_ulist_doubleclick", P_OFFSET (doubleclickuser
), TYPE_STR
},
392 {"gui_ulist_hide", P_OFFINT (hideuserlist
), TYPE_BOOL
},
393 {"gui_ulist_left", P_OFFINT (_gui_ulist_left
), TYPE_BOOL
}, /* obsolete */
394 {"gui_ulist_pos", P_OFFINT (gui_ulist_pos
), TYPE_INT
},
395 {"gui_ulist_resizable", P_OFFINT (paned_userlist
), TYPE_BOOL
},
396 {"gui_ulist_show_hosts", P_OFFINT(showhostname_in_userlist
), TYPE_BOOL
},
397 {"gui_ulist_sort", P_OFFINT (userlist_sort
), TYPE_INT
},
398 {"gui_ulist_style", P_OFFINT (style_namelistgad
), TYPE_BOOL
},
399 {"gui_url_mod", P_OFFINT (gui_url_mod
), TYPE_INT
},
400 {"gui_usermenu", P_OFFINT (gui_usermenu
), TYPE_BOOL
},
401 {"gui_win_height", P_OFFINT (mainwindow_height
), TYPE_INT
},
402 {"gui_win_left", P_OFFINT (mainwindow_left
), TYPE_INT
},
403 {"gui_win_save", P_OFFINT (mainwindow_save
), TYPE_BOOL
},
404 {"gui_win_state", P_OFFINT (gui_win_state
), TYPE_INT
},
405 {"gui_win_top", P_OFFINT (mainwindow_top
), TYPE_INT
},
406 {"gui_win_width", P_OFFINT (mainwindow_width
), TYPE_INT
},
408 {"input_balloon_chans", P_OFFINT (input_balloon_chans
), TYPE_BOOL
},
409 {"input_balloon_hilight", P_OFFINT (input_balloon_hilight
), TYPE_BOOL
},
410 {"input_balloon_priv", P_OFFINT (input_balloon_priv
), TYPE_BOOL
},
411 {"input_balloon_time", P_OFFINT (input_balloon_time
), TYPE_INT
},
412 {"input_beep_chans", P_OFFINT (input_beep_chans
), TYPE_BOOL
},
413 {"input_beep_hilight", P_OFFINT (input_beep_hilight
), TYPE_BOOL
},
414 {"input_beep_msg", P_OFFINT (input_beep_priv
), TYPE_BOOL
},
415 {"input_command_char", P_OFFSET (cmdchar
), TYPE_STR
},
416 {"input_filter_beep", P_OFFINT (filterbeep
), TYPE_BOOL
},
417 {"input_flash_chans", P_OFFINT (input_flash_chans
), TYPE_BOOL
},
418 {"input_flash_hilight", P_OFFINT (input_flash_hilight
), TYPE_BOOL
},
419 {"input_flash_priv", P_OFFINT (input_flash_priv
), TYPE_BOOL
},
420 {"input_perc_ascii", P_OFFINT (perc_ascii
), TYPE_BOOL
},
421 {"input_perc_color", P_OFFINT (perc_color
), TYPE_BOOL
},
422 {"input_tray_chans", P_OFFINT (input_tray_chans
), TYPE_BOOL
},
423 {"input_tray_hilight", P_OFFINT (input_tray_hilight
), TYPE_BOOL
},
424 {"input_tray_priv", P_OFFINT (input_tray_priv
), TYPE_BOOL
},
426 {"irc_auto_rejoin", P_OFFINT (autorejoin
), TYPE_BOOL
},
427 {"irc_ban_type", P_OFFINT (bantype
), TYPE_INT
},
428 {"irc_conf_mode", P_OFFINT (confmode
), TYPE_BOOL
},
429 {"irc_extra_hilight", P_OFFSET (irc_extra_hilight
), TYPE_STR
},
430 {"irc_hide_version", P_OFFINT (hidever
), TYPE_BOOL
},
431 {"irc_id_ntext", P_OFFSET (irc_id_ntext
), TYPE_STR
},
432 {"irc_id_ytext", P_OFFSET (irc_id_ytext
), TYPE_STR
},
433 {"irc_invisible", P_OFFINT (invisible
), TYPE_BOOL
},
434 {"irc_join_delay", P_OFFINT (irc_join_delay
), TYPE_INT
},
435 {"irc_logging", P_OFFINT (logging
), TYPE_BOOL
},
436 {"irc_logmask", P_OFFSET (logmask
), TYPE_STR
},
437 {"irc_nick1", P_OFFSET (nick1
), TYPE_STR
},
438 {"irc_nick2", P_OFFSET (nick2
), TYPE_STR
},
439 {"irc_nick3", P_OFFSET (nick3
), TYPE_STR
},
440 {"irc_nick_hilight", P_OFFSET (irc_nick_hilight
), TYPE_STR
},
441 {"irc_no_hilight", P_OFFSET (irc_no_hilight
), TYPE_STR
},
442 {"irc_part_reason", P_OFFSET (partreason
), TYPE_STR
},
443 {"irc_quit_reason", P_OFFSET (quitreason
), TYPE_STR
},
444 {"irc_raw_modes", P_OFFINT (raw_modes
), TYPE_BOOL
},
445 {"irc_real_name", P_OFFSET (realname
), TYPE_STR
},
446 {"irc_servernotice", P_OFFINT (servernotice
), TYPE_BOOL
},
447 {"irc_skip_motd", P_OFFINT (skipmotd
), TYPE_BOOL
},
448 {"irc_user_name", P_OFFSET (username
), TYPE_STR
},
449 {"irc_wallops", P_OFFINT (wallops
), TYPE_BOOL
},
450 {"irc_who_join", P_OFFINT (userhost
), TYPE_BOOL
},
451 {"irc_whois_front", P_OFFINT (irc_whois_front
), TYPE_BOOL
},
453 {"net_auto_reconnect", P_OFFINT (autoreconnect
), TYPE_BOOL
},
454 {"net_bind_host", P_OFFSET (hostname
), TYPE_STR
},
455 {"net_ping_timeout", P_OFFINT (pingtimeout
), TYPE_INT
},
456 {"net_proxy_auth", P_OFFINT (proxy_auth
), TYPE_BOOL
},
457 {"net_proxy_host", P_OFFSET (proxy_host
), TYPE_STR
},
458 {"net_proxy_pass", P_OFFSET (proxy_pass
), TYPE_STR
},
459 {"net_proxy_port", P_OFFINT (proxy_port
), TYPE_INT
},
460 {"net_proxy_type", P_OFFINT (proxy_type
), TYPE_INT
},
461 {"net_proxy_use", P_OFFINT (proxy_use
), TYPE_INT
},
462 {"net_proxy_user", P_OFFSET (proxy_user
), TYPE_STR
},
464 {"net_reconnect_delay", P_OFFINT (recon_delay
), TYPE_INT
},
465 {"net_throttle", P_OFFINT (throttle
), TYPE_BOOL
},
467 {"notify_timeout", P_OFFINT (notify_timeout
), TYPE_INT
},
468 {"notify_whois_online", P_OFFINT (whois_on_notifyonline
), TYPE_BOOL
},
470 {"perl_warnings", P_OFFINT (perlwarnings
), TYPE_BOOL
},
472 {"sound_command", P_OFFSET (soundcmd
), TYPE_STR
},
473 {"sound_dir", P_OFFSET (sounddir
), TYPE_STR
},
474 {"stamp_log", P_OFFINT (timestamp_logs
), TYPE_BOOL
},
475 {"stamp_log_format", P_OFFSET (timestamp_log_format
), TYPE_STR
},
476 {"stamp_text", P_OFFINT (timestamp
), TYPE_BOOL
},
477 {"stamp_text_format", P_OFFSET (stamp_format
), TYPE_STR
},
479 {"tab_chans", P_OFFINT (tabchannels
), TYPE_BOOL
},
480 {"tab_dialogs", P_OFFINT (privmsgtab
), TYPE_BOOL
},
481 {"tab_layout", P_OFFINT (tab_layout
), TYPE_INT
},
482 {"tab_new_to_front", P_OFFINT (newtabstofront
), TYPE_INT
},
483 {"tab_notices", P_OFFINT (notices_tabs
), TYPE_BOOL
},
484 {"tab_pos", P_OFFINT (tab_pos
), TYPE_INT
},
485 {"tab_position", P_OFFINT (_tabs_position
), TYPE_INT
}, /* obsolete */
486 {"tab_server", P_OFFINT (use_server_tab
), TYPE_BOOL
},
487 {"tab_small", P_OFFINT (tab_small
), TYPE_INT
},
488 {"tab_sort", P_OFFINT (tab_sort
), TYPE_BOOL
},
489 {"tab_trunc", P_OFFINT (truncchans
), TYPE_INT
},
490 {"tab_utils", P_OFFINT (windows_as_tabs
), TYPE_BOOL
},
492 {"text_background", P_OFFSET (background
), TYPE_STR
},
493 {"text_color_nicks", P_OFFINT (colorednicks
), TYPE_BOOL
},
494 {"text_font", P_OFFSET (font_normal
), TYPE_STR
},
495 {"text_indent", P_OFFINT (indent_nicks
), TYPE_BOOL
},
496 {"text_max_indent", P_OFFINT (max_auto_indent
), TYPE_INT
},
497 {"text_max_lines", P_OFFINT (max_lines
), TYPE_INT
},
498 {"text_replay", P_OFFINT (text_replay
), TYPE_BOOL
},
499 {"text_show_marker", P_OFFINT (show_marker
), TYPE_BOOL
},
500 {"text_show_sep", P_OFFINT (show_separator
), TYPE_BOOL
},
501 {"text_stripcolor", P_OFFINT (stripcolor
), TYPE_BOOL
},
502 {"text_thin_sep", P_OFFINT (thin_separator
), TYPE_BOOL
},
503 {"text_tint_blue", P_OFFINT (tint_blue
), TYPE_INT
},
504 {"text_tint_green", P_OFFINT (tint_green
), TYPE_INT
},
505 {"text_tint_red", P_OFFINT (tint_red
), TYPE_INT
},
506 {"text_transparent", P_OFFINT (transparent
), TYPE_BOOL
},
507 {"text_wordwrap", P_OFFINT (wordwrap
), TYPE_BOOL
},
509 {"url_grabber", P_OFFINT (url_grabber
), TYPE_BOOL
},
510 {"url_grabber_limit", P_OFFINT (url_grabber_limit
), TYPE_INT
},
515 convert_with_fallback (const char *str
, const char *fallback
)
519 utf
= g_locale_to_utf8 (str
, -1, 0, 0, 0);
522 /* this can happen if CHARSET envvar is set wrong */
523 /* maybe it's already utf8 (breakage!) */
524 if (!g_utf8_validate (str
, -1, NULL
))
525 utf
= g_strdup (fallback
);
527 utf
= g_strdup (str
);
538 const char *username
, *realname
;
542 username
= g_get_user_name ();
546 realname
= g_get_real_name ();
547 if ((realname
&& realname
[0] == 0) || !realname
)
550 username
= convert_with_fallback (username
, "username");
551 realname
= convert_with_fallback (realname
, "realname");
553 memset (&prefs
, 0, sizeof (struct xchatprefs
));
555 /* put in default values, anything left out is automatically zero */
556 prefs
.local_ip
= 0xffffffff;
557 prefs
.irc_join_delay
= 3;
558 prefs
.show_marker
= 1;
559 prefs
.newtabstofront
= 0;
560 prefs
.completion_amount
= 5;
561 prefs
.away_timeout
= 60;
562 prefs
.away_size_max
= 300;
563 prefs
.away_track
= 1;
564 prefs
.timestamp_logs
= 1;
565 prefs
.truncchans
= 20;
566 prefs
.autoresume
= 1;
567 prefs
.show_away_once
= 1;
568 prefs
.indent_nicks
= 1;
569 prefs
.thin_separator
= 1;
570 prefs
._tabs_position
= 2; /* 2 = left */
571 prefs
.fastdccsend
= 1;
574 prefs
.autodialog
= 1;
575 prefs
.gui_input_spell
= 1;
576 prefs
.autoreconnect
= 1;
577 prefs
.recon_delay
= 10;
578 prefs
.text_replay
= 1;
579 prefs
.tabchannels
= 1;
580 prefs
.tab_layout
= 2; /* 0=Tabs 1=Reserved 2=Tree */
582 prefs
.paned_userlist
= 1;
583 prefs
.newtabstofront
= 2;
584 prefs
.use_server_tab
= 1;
585 prefs
.privmsgtab
= 1;
586 /*prefs.style_inputbox = 1;*/
587 prefs
.dccpermissions
= 0600;
588 prefs
.max_lines
= 500;
589 prefs
.mainwindow_width
= 640;
590 prefs
.mainwindow_height
= 400;
591 prefs
.dialog_width
= 500;
592 prefs
.dialog_height
= 256;
593 prefs
.gui_join_dialog
= 1;
594 prefs
.gui_quit_dialog
= 1;
595 prefs
.dcctimeout
= 180;
596 prefs
.dccstalltimeout
= 60;
597 prefs
.notify_timeout
= 15;
600 prefs
.tint_blue
= 195;
601 prefs
.auto_indent
= 1;
602 prefs
.max_auto_indent
= 256;
603 prefs
.show_separator
= 1;
604 prefs
.dcc_blocksize
= 1024;
606 /*FIXME*/ prefs
.msg_time_limit
= 30;
607 prefs
.msg_number_limit
= 5;
608 prefs
.ctcp_time_limit
= 30;
609 prefs
.ctcp_number_limit
= 5;
612 prefs
.throttlemeter
= 1;
613 prefs
.autoopendccrecvwindow
= 1;
614 prefs
.autoopendccsendwindow
= 1;
615 prefs
.autoopendccchatwindow
= 1;
617 prefs
.gui_url_mod
= 4; /* ctrl */
619 prefs
.gui_pane_left_size
= 100;
620 prefs
.gui_pane_right_size
= 100;
621 prefs
.mainwindow_save
= 1;
623 prefs
.input_balloon_time
= 20;
624 prefs
.input_flash_priv
= prefs
.input_flash_hilight
= 1;
625 prefs
.input_tray_priv
= prefs
.input_tray_hilight
= 1;
626 prefs
.autodccsend
= 2; /* browse mode */
627 prefs
.url_grabber
= 1;
628 prefs
.url_grabber_limit
= 0; /* 0 means unlimited for backcompat */
629 strcpy (prefs
.stamp_format
, "[%H:%M] ");
630 strcpy (prefs
.timestamp_log_format
, "%b %d %H:%M:%S ");
631 strcpy (prefs
.logmask
, "%n-%c.log");
632 strcpy (prefs
.nick_suffix
, ",");
633 strcpy (prefs
.cmdchar
, "/");
634 strcpy (prefs
.nick1
, username
);
635 strcpy (prefs
.nick2
, username
);
636 strcat (prefs
.nick2
, "_");
637 strcpy (prefs
.nick3
, username
);
638 strcat (prefs
.nick3
, "__");
639 strcpy (prefs
.realname
, realname
);
640 strcpy (prefs
.username
, username
);
641 snprintf (prefs
.sounddir
, sizeof (prefs
.sounddir
), "%s/sounds", get_xdir_utf8 ());
642 snprintf (prefs
.dccdir
, sizeof (prefs
.dccdir
), "%s/downloads", get_xdir_utf8 ());
643 strcpy (prefs
.doubleclickuser
, "QUERY %s");
644 strcpy (prefs
.awayreason
, _("I'm busy"));
645 strcpy (prefs
.quitreason
, _("Leaving"));
646 strcpy (prefs
.partreason
, prefs
.quitreason
);
647 strcpy (prefs
.font_normal
, DEF_FONT
);
648 strcpy (prefs
.dnsprogram
, "host");
649 strcpy (prefs
.irc_no_hilight
, "NickServ,ChanServ");
651 g_free ((char *)username
);
652 g_free ((char *)realname
);
654 fh
= open (default_file (), OFLAGS
| O_RDONLY
);
658 cfg
= malloc (st
.st_size
+ 1);
660 i
= read (fh
, cfg
, st
.st_size
);
662 cfg
[i
] = '\0'; /* make sure cfg is NULL terminated */
667 switch (vars
[i
].type
)
670 cfg_get_str (cfg
, vars
[i
].name
, (char *) &prefs
+ vars
[i
].offset
,
675 val
= cfg_get_int_with_result (cfg
, vars
[i
].name
, &res
);
677 *((int *) &prefs
+ vars
[i
].offset
) = val
;
682 while (vars
[i
].name
);
688 /* OS/2 uses UID 0 all the time */
690 fe_message (_("* Running IRC as root is stupid! You should\n"
691 " create a User Account and use that to login.\n"), FE_MSG_WARN
|FE_MSG_WAIT
);
693 mkdir_utf8 (prefs
.dccdir
);
694 mkdir_utf8 (prefs
.dcc_completed_dir
);
696 if (prefs
.mainwindow_height
< 138)
697 prefs
.mainwindow_height
= 138;
698 if (prefs
.mainwindow_width
< 106)
699 prefs
.mainwindow_width
= 106;
701 sp
= strchr (prefs
.username
, ' ');
703 sp
[0] = 0; /* spaces in username would break the login */
705 /* try to make sense of old ulist/tree position settings */
706 if (prefs
.gui_ulist_pos
== 0)
708 prefs
.gui_ulist_pos
= 3; /* top right */
709 if (prefs
._gui_ulist_left
)
710 prefs
.gui_ulist_pos
= 2; /* bottom left */
712 switch (prefs
._tabs_position
)
715 prefs
.tab_pos
= 6; /* bottom */
718 prefs
.tab_pos
= 5; /* top */
721 prefs
.tab_pos
= 1; /* left */
724 prefs
.tab_pos
= 4; /* right */
727 prefs
.tab_pos
= 1; /* (hidden)left */
730 if (prefs
._gui_ulist_left
)
732 prefs
.tab_pos
= 1; /* above ulist left */
733 prefs
.gui_ulist_pos
= 2;
737 prefs
.tab_pos
= 3; /* above ulist right */
738 prefs
.gui_ulist_pos
= 4;
749 char *new_config
, *config
;
753 config
= default_file ();
754 new_config
= malloc (strlen (config
) + 5);
755 strcpy (new_config
, config
);
756 strcat (new_config
, ".new");
758 fh
= open (new_config
, OFLAGS
| O_TRUNC
| O_WRONLY
| O_CREAT
, 0600);
765 if (!cfg_put_str (fh
, "version", PACKAGE_VERSION
))
774 switch (vars
[i
].type
)
777 if (!cfg_put_str (fh
, vars
[i
].name
, (char *) &prefs
+ vars
[i
].offset
))
785 if (!cfg_put_int (fh
, *((int *) &prefs
+ vars
[i
].offset
), vars
[i
].name
))
793 while (vars
[i
].name
);
795 if (close (fh
) == -1)
801 if (rename (new_config
, config
) == -1)
812 set_showval (session
*sess
, const struct prefs
*var
, char *tbuf
)
816 len
= strlen (var
->name
);
817 memcpy (tbuf
, var
->name
, len
);
821 tbuf
[len
++] = '\003';
829 sprintf (tbuf
+ len
, "\0033:\017 %s\n",
830 (char *) &prefs
+ var
->offset
);
833 sprintf (tbuf
+ len
, "\0033:\017 %d\n",
834 *((int *) &prefs
+ var
->offset
));
837 if (*((int *) &prefs
+ var
->offset
))
838 sprintf (tbuf
+ len
, "\0033:\017 %s\n", "ON");
840 sprintf (tbuf
+ len
, "\0033:\017 %s\n", "OFF");
843 PrintText (sess
, tbuf
);
847 set_list (session
* sess
, char *tbuf
)
854 set_showval (sess
, &vars
[i
], tbuf
);
857 while (vars
[i
].name
);
861 cfg_get_bool (char *var
)
867 if (!strcasecmp (var
, vars
[i
].name
))
869 return *((int *) &prefs
+ vars
[i
].offset
);
873 while (vars
[i
].name
);
879 cmd_set (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
886 int i
= 0, finds
= 0, found
;
890 if (strcasecmp (word
[2], "-e") == 0)
897 if (strcasecmp (word
[idx
], "-off") == 0)
904 if (strcasecmp (word
[idx
], "-or") == 0 || strcasecmp (word
[idx
], "-on") == 0)
910 if (strcasecmp (word
[idx
], "-quiet") == 0)
917 val
= word_eol
[idx
+1];
921 set_list (sess
, tbuf
);
925 if ((strchr (var
, '*') || strchr (var
, '?')) && !*val
)
934 found
= !match (var
, vars
[i
].name
);
936 found
= strcasecmp (var
, vars
[i
].name
);
941 switch (vars
[i
].type
)
946 strncpy ((char *) &prefs
+ vars
[i
].offset
, val
, vars
[i
].len
);
947 ((char *) &prefs
)[vars
[i
].offset
+ vars
[i
].len
- 1] = 0;
949 PrintTextf (sess
, "%s set to: %s\n", var
, (char *) &prefs
+ vars
[i
].offset
);
952 set_showval (sess
, &vars
[i
], tbuf
);
959 if (vars
[i
].type
== TYPE_BOOL
)
962 *((int *) &prefs
+ vars
[i
].offset
) = 1;
964 *((int *) &prefs
+ vars
[i
].offset
) = 0;
965 if (!strcasecmp (val
, "YES") || !strcasecmp (val
, "ON"))
966 *((int *) &prefs
+ vars
[i
].offset
) = 1;
967 if (!strcasecmp (val
, "NO") || !strcasecmp (val
, "OFF"))
968 *((int *) &prefs
+ vars
[i
].offset
) = 0;
972 *((int *) &prefs
+ vars
[i
].offset
) |= atoi (val
);
974 *((int *) &prefs
+ vars
[i
].offset
) &= ~(atoi (val
));
976 *((int *) &prefs
+ vars
[i
].offset
) = atoi (val
);
979 PrintTextf (sess
, "%s set to: %d\n", var
,
980 *((int *) &prefs
+ vars
[i
].offset
));
983 set_showval (sess
, &vars
[i
], tbuf
);
990 while (vars
[i
].name
);
992 if (!finds
&& !quiet
)
993 PrintText (sess
, "No such variable.\n");
999 xchat_open_file (char *file
, int flags
, int mode
, int xof_flags
)
1003 if (xof_flags
& XOF_FULLPATH
)
1005 if (xof_flags
& XOF_DOMODE
)
1006 return open (file
, flags
| OFLAGS
, mode
);
1008 return open (file
, flags
| OFLAGS
);
1011 snprintf (buf
, sizeof (buf
), "%s/%s", get_xdir_fs (), file
);
1012 if (xof_flags
& XOF_DOMODE
)
1013 return open (buf
, flags
| OFLAGS
, mode
);
1015 return open (buf
, flags
| OFLAGS
);
1019 xchat_fopen_file (const char *file
, const char *mode
, int xof_flags
)
1023 if (xof_flags
& XOF_FULLPATH
)
1024 return fopen (file
, mode
);
1026 snprintf (buf
, sizeof (buf
), "%s/%s", get_xdir_fs (), file
);
1027 return fopen (buf
, mode
);