1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
* prefs.c -- preferences and global variable mangement of hnb
*
* Copyright (C) 2001,2003 yvind Kols <pippin@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define PREFS_C
#include <stdlib.h>
#include <string.h>
#include "tree.h"
#include "ui.h"
#include "path.h"
#include "prefs.h"
#include "cli.h"
#include "ui_cli.h"
#include "file.h"
Tprefs prefs = {
"hnb", /*format; */
0, /*tutorial; */
"", /*rc_file[100]; */
"", /*db_file[100]; */
"", /*default_db_file[100]; */
1, /*showpercent */
0, /*fixed focusbar */
0, /*save position */
0 /*readonly */
};
typedef struct {
char name[4];
int color;
} ColornameT;
/*
!init_prefs();
*/
void init_prefs ()
{
#ifndef WIN32
if (!getenv ("HOME")) {
fprintf(stderr, "$HOME is not set. Exiting.\n");
exit(1);
}
sprintf (prefs.rc_file, "%s/.hnbrc", getenv ("HOME"));
sprintf (prefs.default_db_file, "%s/.hnb", getenv ("HOME"));
#endif
#ifdef WIN32
sprintf (prefs.rc_file, "C:\\hnb.rc");
sprintf (prefs.default_db_file, "C:\\hnb_data");
#endif
cli_add_string ("format", prefs.format, "the format of the current file");
cli_add_string ("rc_file", prefs.rc_file, "");
cli_add_string ("db_file", prefs.db_file, "");
cli_add_string ("default_db_file", prefs.default_db_file, "");
cli_add_int ("showpercent", &prefs.showpercent, "");
cli_add_int ("fixedfocus", &prefs.fixedfocus, "");
cli_add_int ("savepos", &prefs.savepos, "");
cli_add_int ("readonly", &prefs.readonly, "");
#ifdef NCURSES_VERSION
cli_add_int ("escdelay", &ESCDELAY,
"how long does curses wait before it decides ESC is ESC and not a coded key sequence");
#endif
}
void write_default_prefs ()
{
FILE *file;
file = fopen (prefs.rc_file, "w");
fprintf (file,
#include "hnbrc.inc"
);
fclose (file);
}
void load_prefs (void)
{
if (xml_check (prefs.rc_file)) {
printf
("seems like your current ~/.hnbrc is outdated (it's xml the new format\n\
is plain text,.. remove it and let hnb make a new default\n");
exit (0);
}
cli_load_file (prefs.rc_file);
}
|