Merge branch '2636_configs_placement'

* 2636_configs_placement:
  Show error and don't start if config directory is a regular file
  Fixed migration rules
  Added unit test for mc_config_get_full_path() function
  Updated MAN-pages for describe new paths to configs
  Ticket #2675: man pages fixes.
  Fixed comment about location of mc.keymap file.
  fixup! Ticket #2636: The various MC config placements.
  Added function mc_config_get_full_path() for search user's config files by short names.
  Some config files moved to more appropriate places.
  Changed source code for respect '--enable-homedir' configure option.
  Ticket #2636: The various MC config placements.
  Ticket #1730 (troubles in mcviewer with utf8)
This commit is contained in:
Slava Zanko 2011-12-06 16:27:59 +03:00
commit 5975ec9f66
32 changed files with 485 additions and 152 deletions

View File

@ -405,6 +405,30 @@ linux*)
esac esac
dnl
dnl Where config files should be placed
dnl
AC_ARG_WITH([homedir],
AS_HELP_STRING([--with-homedir], [Choose any place of user settings relative to home dir, or XDG for respect XDG standards @<:@XDG@:>@]),
[
if test "x$withval" = "xXDG"; then
with_homedir=XDG
else
with_homedir=$withval
fi
],
[with_homedir=XDG])
if test x$with_homedir = xXDG; then
AC_DEFINE(MC_HOMEDIR_XDG, 1,
[Define to enable XDG standard support])
else
AC_DEFINE_UNQUOTED([MC_USERCONF_DIR], ["$with_homedir"], [Where configs will be placed relative to $HOME])
fi
dnl Support for background operations dnl Support for background operations
AC_ARG_ENABLE([background], AC_ARG_ENABLE([background],
[ --enable-background Support for background file operations [[yes]]]) [ --enable-background Support for background file operations [[yes]]])

View File

@ -138,6 +138,11 @@ incomplete, use `configure --help' to get the full list):
default. Background code is known to be less stable than the rest default. Background code is known to be less stable than the rest
of the code, so you may want to disable it at the compile time. of the code, so you may want to disable it at the compile time.
`--with-homedir'
This option allow users to place user config directories in any
place. By default value is 'XDG', this mean, mc will respect XDG
standards. If other value will specified, this will used as directory
name (relative to $HOME).
VFS options: VFS options:
- - - - - - - - - - - -

View File

@ -1361,7 +1361,7 @@ comando cd interno\&.
.\"NODE " Extension File Edit" .\"NODE " Extension File Edit"
.SH " Editar el Archivo de Extensiones" .SH " Editar el Archivo de Extensiones"
Abre el archivo Abre el archivo
.I ~/.local/share/mc/mc.ext .I ~/.config/mc/mc.ext
en nuestro editor. El administrador puede optar por editar, en su lugar, en nuestro editor. El administrador puede optar por editar, en su lugar,
el archivo de extensiones del sistema el archivo de extensiones del sistema
.IR @prefix@/share/mc/mc.ext . .IR @prefix@/share/mc/mc.ext .
@ -1434,7 +1434,7 @@ El menú de usuario es un menú de acciones útiles que puede ser personalizado
por el usuario. Cuando accedemos al menú de usuario se utiliza, si existe, por el usuario. Cuando accedemos al menú de usuario se utiliza, si existe,
el archivo .mc.menu del directorio actual, pero sólo si es propiedad del el archivo .mc.menu del directorio actual, pero sólo si es propiedad del
usuario o del superusuario y no es modificable por todos. usuario o del superusuario y no es modificable por todos.
Si no se encuentra allí el archivo, se intenta de la misma manera con ~/.local/share/mc/menu, Si no se encuentra allí el archivo, se intenta de la misma manera con ~/.config/mc/menu,
y si no, mc utiliza el menú por defecto para todo el sistema y si no, mc utiliza el menú por defecto para todo el sistema
@prefix@/share/mc/mc.menu. @prefix@/share/mc/mc.menu.
.PP .PP
@ -3672,7 +3672,7 @@ Archivo de ayuda.
.IP .IP
Archivo de extensiones por defecto del sistema. Archivo de extensiones por defecto del sistema.
.PP .PP
.I ~/.local/share/mc/mc.ext .I ~/.config/mc/mc.ext
.IP .IP
Archivo de usuario de extensiones y configuración de visor y editor. Si Archivo de usuario de extensiones y configuración de visor y editor. Si
está presente prevalece sobre el contenido de los archivos del sistema. está presente prevalece sobre el contenido de los archivos del sistema.
@ -3705,7 +3705,7 @@ programa.
.IP .IP
Este archivo contiene el menú de aplicaciones por defecto para el sistema. Este archivo contiene el menú de aplicaciones por defecto para el sistema.
.PP .PP
.I ~/.local/share/mc/menu .I ~/.config/mc/menu
.IP .IP
Menú de aplicaciones personal del usuario. Si está presente será utilizado Menú de aplicaciones personal del usuario. Si está presente será utilizado
en lugar del menú por defecto del sistema. en lugar del menú por defecto del sistema.

View File

@ -1295,7 +1295,7 @@ A cd belső parancs
leírásánál. leírásánál.
.\"NODE " Extension File Edit" .\"NODE " Extension File Edit"
.SH " Társítások" .SH " Társítások"
Ez az ~/.local/share/mc/mc.ext szerkesztéséhez segítségül fogja hívni a Ez az ~/.config/mc/mc.ext szerkesztéséhez segítségül fogja hívni a
szövegszerkesztődet. A fájl formátuma a következő (a formátum a 3.0\-ás szövegszerkesztődet. A fájl formátuma a következő (a formátum a 3.0\-ás
verzióval megváltozott): verzióval megváltozott):
.PP .PP
@ -1367,7 +1367,7 @@ A felhasználói menüt a felhasználó testre szabhatja. Ez az aktulis
könyvtár .mc.menu fájlja, ha az létezik, de csak, ha az a felhasználó könyvtár .mc.menu fájlja, ha az létezik, de csak, ha az a felhasználó
(illetve a root) a tulajdonosa, és nem lehet bárki számára írható. Ha (illetve a root) a tulajdonosa, és nem lehet bárki számára írható. Ha
nem talál ilyen fájlt, az nem talál ilyen fájlt, az
.I ~/.local/share/mc/menu .I ~/.config/mc/menu
keresése a következő lépés, egyébként pedig az mc az alapértelmezett keresése a következő lépés, egyébként pedig az mc az alapértelmezett
rendszerszintű menüt használja, pl.: rendszerszintű menüt használja, pl.:
.IR @prefix@/share/mc/mc.menu , .IR @prefix@/share/mc/mc.menu ,
@ -2499,7 +2499,7 @@ formázza a szöveget
vagy más kódra) amikor ez a rész vagy más kódra) amikor ez a rész
.BR kijelölt . .BR kijelölt .
Ennek használatához elöször egy futtatható fájlt kell készítened Ennek használatához elöször egy futtatható fájlt kell készítened
.B ~/.cedit/edit.indent.rc .B ~/.local/share/mc/mcedit/edit.indent.rc
néven. Szerkeszd ezt szkriptet, ha szükséges. néven. Szerkeszd ezt szkriptet, ha szükséges.
.PP .PP
A szerkesztő megjeleníti még a nem\-amerikai karaktereket is (160 A szerkesztő megjeleníti még a nem\-amerikai karaktereket is (160
@ -3181,7 +3181,7 @@ A program súgó fájlja.
.IP .IP
Az alapértelmezett rendszerszintű kiterjesztés fájl. Az alapértelmezett rendszerszintű kiterjesztés fájl.
.PP .PP
.I ~/.local/share/mc/mc.ext .I ~/.config/mc/mc.ext
.IP .IP
A felhasználó saját kiterjesztései, nézet beállítások és szerkesztési A felhasználó saját kiterjesztései, nézet beállítások és szerkesztési
beállítások. Ezek felülbírálják a rendszerszintű fájl bejegyzéseit, ha beállítások. Ezek felülbírálják a rendszerszintű fájl bejegyzéseit, ha
@ -3213,7 +3213,7 @@ Ez a fájl tartalmazza a program által megjelenített útmutattásokat
.IP .IP
Ez a fájl azonos a rendszerszintű alkalmazás menüvel. Ez a fájl azonos a rendszerszintű alkalmazás menüvel.
.PP .PP
.I ~/.local/share/mc/menu .I ~/.config/mc/menu
.IP .IP
A falhasználó saját alkalmazás menüje. Ha ez a fájl elérhető a A falhasználó saját alkalmazás menüje. Ha ez a fájl elérhető a
rendszerszintű alkalmazás menü helyett ezt fogja használni. rendszerszintű alkalmazás menü helyett ezt fogja használni.

View File

@ -1310,7 +1310,7 @@ comando cd interno\&.
.\"NODE " Extension File Edit" .\"NODE " Extension File Edit"
.SH " Modifica file estensioni" .SH " Modifica file estensioni"
Questo comando invocherà l'editor sul file Questo comando invocherà l'editor sul file
.IR ~/.local/share/mc/mc.ext . .IR ~/.config/mc/mc.ext .
Il fomato di questo file è il seguente (il formato è cambiato dalla Il fomato di questo file è il seguente (il formato è cambiato dalla
versione 3.0): versione 3.0):
.PP .PP
@ -1377,7 +1377,7 @@ personalizzati dall'utente. Quando si accede al menu utente, viene
utilizzato, se esiste, il file .mc.menu dalla directory corrente, utilizzato, se esiste, il file .mc.menu dalla directory corrente,
ma solo se è di proprietà dell'utente o di root e se non è scrivibile ma solo se è di proprietà dell'utente o di root e se non è scrivibile
a tutti. Se tale file non viene trovato, mc alla stessa maniera a tutti. Se tale file non viene trovato, mc alla stessa maniera
prova con ~/.local/share/mc/menu altrimenti usa il menu di sistema prova con ~/.config/mc/menu altrimenti usa il menu di sistema
@prefix@/share/mc/mc.menu. @prefix@/share/mc/mc.menu.
.PP .PP
Il formato del file menu è molto semplice. Le righe che cominciano Il formato del file menu è molto semplice. Le righe che cominciano
@ -3176,7 +3176,7 @@ Il file di aiuto per il programma.
.IP .IP
Il file delle estensioni di sistema predefinito. Il file delle estensioni di sistema predefinito.
.PP .PP
.I ~/.local/share/mc/mc.ext .I ~/.config/mc/mc.ext
.IP .IP
Le estensioni dell'utente, la configurazione del visualizzatore e Le estensioni dell'utente, la configurazione del visualizzatore e
dell'editor di file. Se presenti, questi file si sovrappongono ai file di dell'editor di file. Se presenti, questi file si sovrappongono ai file di
@ -3210,7 +3210,7 @@ Questo file contiene i suggerimenti (dritte) mostrate dal programma.
.IP .IP
Questo file contiene il menu di sistema per le applicazioni. Questo file contiene il menu di sistema per le applicazioni.
.PP .PP
.I ~/.local/share/mc/menu .I ~/.config/mc/menu
.IP .IP
Il menu utente per le applicazioni. Se presente viene usato al posto Il menu utente per le applicazioni. Se presente viene usato al posto
del menu delle applicazioni di sistema. del menu delle applicazioni di sistema.

View File

@ -340,7 +340,7 @@ in section
of config file. of config file.
.br .br
4) File 4) File
.B ~/.local/share/mc/mc.keymap .B ~/.config/mc/mc.keymap
.br .br
5) File 5) File
.B @sysconfdir@/mc/mc.keymap .B @sysconfdir@/mc/mc.keymap
@ -354,7 +354,7 @@ or without it). Search of keymap\-file will occur in (to the first one found):
.IP .IP
.br .br
1) 1)
.B ~/.local/share/mc .B ~/.config/mc
.br .br
2) 2)
.B @sysconfdir@/mc/ .B @sysconfdir@/mc/
@ -1473,7 +1473,7 @@ description.
.\"NODE " Extension File Edit" .\"NODE " Extension File Edit"
.SH " Extension File Edit" .SH " Extension File Edit"
This will invoke your editor on the file This will invoke your editor on the file
.IR ~/.local/share/mc/mc.ext . .IR ~/.config/mc/mc.ext .
The format of this file following: The format of this file following:
.PP .PP
All lines starting with # or empty lines are thrown away. All lines starting with # or empty lines are thrown away.
@ -1566,7 +1566,7 @@ The user menu is a menu of useful actions that can be customized by
the user. When you access the user menu, the the user. When you access the user menu, the
file .mc.menu from the current directory is used if it exists, file .mc.menu from the current directory is used if it exists,
but only if it is owned by user or root and is not world\-writable. but only if it is owned by user or root and is not world\-writable.
If no such file found, ~/.local/share/mc/menu is tried in the same way, If no such file found, ~/.config/mc/menu is tried in the same way,
and otherwise mc uses the default system\-wide menu and otherwise mc uses the default system\-wide menu
@prefix@/share/mc/mc.menu. @prefix@/share/mc/mc.menu.
.PP .PP
@ -2025,7 +2025,7 @@ format and sort options. Unchecked by default.
.PP .PP
.I Auto save panels setup. .I Auto save panels setup.
If this option is enabled, when you exit the Midnight Commander the If this option is enabled, when you exit the Midnight Commander the
current settings of panels are saved in the ~/.cache/mc/panels.ini file. current settings of panels are saved in the ~/.config/mc/panels.ini file.
Disabled by default. Disabled by default.
.PP .PP
.B Navigation .B Navigation
@ -4102,7 +4102,7 @@ The help file for the program.
.IP .IP
The default system\-wide extensions file. The default system\-wide extensions file.
.PP .PP
.I ~/.local/share/mc/mc.ext .I ~/.config/mc/mc.ext
.IP .IP
User's own extension, view configuration and edit configuration User's own extension, view configuration and edit configuration
file. They override the contents of the system wide files if present. file. They override the contents of the system wide files if present.
@ -4134,7 +4134,7 @@ This file contains the hints displayed by the program.
.IP .IP
This file contains the default system\-wide applications menu. This file contains the default system\-wide applications menu.
.PP .PP
.I ~/.local/share/mc/menu .I ~/.config/mc/menu
.IP .IP
User's own application menu. If this file is present it is used instead User's own application menu. If this file is present it is used instead
of the system\-wide applications menu. of the system\-wide applications menu.

View File

@ -238,12 +238,12 @@ Forward).
supports syntax highlighting. This means that keywords and contexts supports syntax highlighting. This means that keywords and contexts
(like C comments, string constants, etc) are highlighted in different (like C comments, string constants, etc) are highlighted in different
colors. The following section explains the format of the file colors. The following section explains the format of the file
.BR ~/.local/share/mc/mcedit/Syntax . .BR ~/.config/mc/mcedit/Syntax .
If this file is missing, system\-wide If this file is missing, system\-wide
.B @prefix@/share/mc/syntax/Syntax .B @prefix@/share/mc/syntax/Syntax
is used. is used.
The file The file
.B ~/.local/share/mc/mcedit/Syntax .B ~/.config/mc/mcedit/Syntax
is rescanned on opening of a any new editor file. The file contains is rescanned on opening of a any new editor file. The file contains
rules for highlighting, each of which is given on a separate line, and rules for highlighting, each of which is given on a separate line, and
define which keywords will be highlighted to what color. define which keywords will be highlighted to what color.

View File

@ -1091,7 +1091,7 @@ przemieszczanie.
.PP .PP
.\"NODE " Extension File Edit" .\"NODE " Extension File Edit"
.SH " Edycja rozszerzeń pliów (Extension File Edit)" .SH " Edycja rozszerzeń pliów (Extension File Edit)"
Ta komenda wywoła twój edytor na plik ~/.local/share/mc/mc.ext. Format tego pliku jest Ta komenda wywoła twój edytor na plik ~/.config/mc/mc.ext. Format tego pliku jest
następujący (zmienił się on począwszy od wersji 3.0): następujący (zmienił się on począwszy od wersji 3.0):
.PP .PP
Wszystkie linie zaczynające się od #, lub puste, nie są brane pod uwagę. Wszystkie linie zaczynające się od #, lub puste, nie są brane pod uwagę.
@ -1164,7 +1164,7 @@ Menu użytkownika jest bardzo użytecznym menu, które może być tworzone
w sposób dowolny, przez użytkownika. Kiedy tylko próbujesz coś zrobić w sposób dowolny, przez użytkownika. Kiedy tylko próbujesz coś zrobić
przy użyciu tego menu, ładowany jest plik .mc.menu z aktualnego katalogu, ale przy użyciu tego menu, ładowany jest plik .mc.menu z aktualnego katalogu, ale
tylko wtedy kiedy jest on w posiadaniu użytkownika lub roota i mamy do niego tylko wtedy kiedy jest on w posiadaniu użytkownika lub roota i mamy do niego
prawa zapisu. Jeśli takiego nie ma próbuje się z plikiem ~/.local/share/mc/menu z tymi prawa zapisu. Jeśli takiego nie ma próbuje się z plikiem ~/.config/mc/menu z tymi
samymi założeniami, jeśli jego też nie ma \- używa się standardowego pliku samymi założeniami, jeśli jego też nie ma \- używa się standardowego pliku
systemowego, który znajduje się w @prefix@/share/mc/mc.menu. systemowego, który znajduje się w @prefix@/share/mc/mc.menu.
.PP .PP
@ -2882,7 +2882,7 @@ Plik pomocy dla programu.
.IP .IP
Standardowy plik rozszerzeń plików. Standardowy plik rozszerzeń plików.
.PP .PP
~/.local/share/mc/mc.ext ~/.config/mc/mc.ext
.IP .IP
Własny plik użytkownika, konfiguruje podgląd i edycje plików. Ma wyższy Własny plik użytkownika, konfiguruje podgląd i edycje plików. Ma wyższy
priorytet niż plik systemowy. priorytet niż plik systemowy.
@ -2911,7 +2911,7 @@ Plik zawierający podpowiedzi (hints) wyświetlane przez program.
.IP .IP
Ten plik zawiera informacje o ogólnosystemowych aplikacjach w menu. Ten plik zawiera informacje o ogólnosystemowych aplikacjach w menu.
.PP .PP
~/.local/share/mc/menu ~/.config/mc/menu
.IP .IP
Własny plik menu użytkownika. Jeśli ten plik jest obecny jest używany Własny plik menu użytkownika. Jeśli ten plik jest obecny jest używany
zamiast pliku globalnego. zamiast pliku globalnego.

View File

@ -336,7 +336,7 @@ S\-<символ> означает, что нужно держать в нажа
конфигурационного файла. конфигурационного файла.
.br .br
4) файл 4) файл
.B ~/.local/share/mc/mc.keymap .B ~/.config/mc/mc.keymap
.br .br
5) файл 5) файл
.B @sysconfdir@/mc/mc.keymap .B @sysconfdir@/mc/mc.keymap
@ -352,7 +352,7 @@ S\-<символ> означает, что нужно держать в нажа
.IP .IP
.br .br
1) 1)
.B ~/.local/share/mc/ .B ~/.config/mc/
.br .br
2) 2)
.B @sysconfdir@/mc/ .B @sysconfdir@/mc/
@ -1565,7 +1565,7 @@ CDPATH (смотрите описание
.SH " Файл расширений" .SH " Файл расширений"
Этот пункт меню "Команда" служит для вызова редактора и редактирования Этот пункт меню "Команда" служит для вызова редактора и редактирования
файла файла
.BR ~/.local/share/mc/mc.ext . .BR ~/.config/mc/mc.ext .
Этот файл имеет следующий формат (формат был изменен в версии 3.0): Этот файл имеет следующий формат (формат был изменен в версии 3.0):
.PP .PP
Все строки, начинающиеся с # или пустые строки игнорируются. Все строки, начинающиеся с # или пустые строки игнорируются.
@ -1657,7 +1657,7 @@ View из второй секции. default должно описывать в
если владельцем этого файла является данный пользователь или root и этот если владельцем этого файла является данный пользователь или root и этот
файл не доступен на запись всем). Если такого файла не найдено, таким же файл не доступен на запись всем). Если такого файла не найдено, таким же
образом ищется файл образом ищется файл
.BR ~/.local/share/mc/menu , .BR ~/.config/mc/menu ,
и в последнюю очередь mc использует общесистемное меню и в последнюю очередь mc использует общесистемное меню
.BR @prefix@/share/mc/mc.menu . .BR @prefix@/share/mc/mc.menu .
.PP .PP
@ -2165,7 +2165,7 @@ Commander будет использовать для вывода содержи
.I Автосохранение настроек панелей. .I Автосохранение настроек панелей.
Если опция включена (по умолчанию она выключена), то при выходе из Если опция включена (по умолчанию она выключена), то при выходе из
Midnight Commander'а текущие настройки панелей соханяются в файле Midnight Commander'а текущие настройки панелей соханяются в файле
~/.cache/mc/panels.ini. ~/.config/mc/panels.ini.
.PP .PP
.B Навигация .B Навигация
.PP .PP
@ -4476,7 +4476,7 @@ insert=\\e[Op
.IP .IP
Используемый по умолчанию общесистемный файл расширений. Используемый по умолчанию общесистемный файл расширений.
.PP .PP
.I ~/.local/share/mc/mc.ext .I ~/.config/mc/mc.ext
.IP .IP
Файл расширений пользователя. Если этот файл существует, он используется Файл расширений пользователя. Если этот файл существует, он используется
вместо общесистемного файла расширений. вместо общесистемного файла расширений.
@ -4513,7 +4513,7 @@ Commander; используется только в тех случаях, ко
.IP .IP
Этот файл содержит общесистемное меню приложений. Этот файл содержит общесистемное меню приложений.
.PP .PP
.I ~/.local/share/mc/menu .I ~/.config/mc/menu
.IP .IP
Собственное меню пользователя. Если этот файл существует, он Собственное меню пользователя. Если этот файл существует, он
используется вместо общесистемного меню. используется вместо общесистемного меню.

View File

@ -1278,7 +1278,7 @@ awk '$9 ~! /incoming/ { print $9 }' < /var/log/xferlog
.\"NODE " Extension File Edit" .\"NODE " Extension File Edit"
.SH " Уреди датотеку врста" .SH " Уреди датотеку врста"
Ово покреће ваш уређивач над датотеком Ово покреће ваш уређивач над датотеком
.IR ~/.local/share/mc/mc.ext . .IR ~/.config/mc/mc.ext .
Формат ове датотеке је следећи: Формат ове датотеке је следећи:
.PP .PP
Сви редови који почињу на # или празни редови се одбацују. Сви редови који почињу на # или празни редови се одбацују.
@ -1369,7 +1369,7 @@ awk '$9 ~! /incoming/ { print $9 }' < /var/log/xferlog
датотека .mc.menu из текућег директоријума, уколико она постоји, али само датотека .mc.menu из текућег директоријума, уколико она постоји, али само
уколико је њен власник корисник или администратор (root) и није уколико је њен власник корисник или администратор (root) и није
дозвољен упис у њу од стране других (света). Ако таква датотека није дозвољен упис у њу од стране других (света). Ако таква датотека није
нађена, на исти начин се покушава са датотеком ~/.local/share/mc/menu, а иначе ПН нађена, на исти начин се покушава са датотеком ~/.config/mc/menu, а иначе ПН
користи подразумевану датотеку менија за цео систем користи подразумевану датотеку менија за цео систем
@prefix@/share/mc/mc.menu. @prefix@/share/mc/mc.menu.
.PP .PP
@ -3188,7 +3188,7 @@ MC_DATADIR. Ако ова променљива није постављена, б
.IP .IP
Подразумевана системска датотека врста. Подразумевана системска датотека врста.
.PP .PP
.I ~/.local/share/mc/mc.ext .I ~/.config/mc/mc.ext
.IP .IP
Корисничке датотеке врста, подешавања прегледача и уређивача. Уколико Корисничке датотеке врста, подешавања прегледача и уређивача. Уколико
постоје, оне заобилазе системске датотеке. постоје, оне заобилазе системске датотеке.
@ -3221,7 +3221,7 @@ MC_DATADIR. Ако ова променљива није постављена, б
.IP .IP
Ова датотека садржи подразумевани мени програма за цео систем. Ова датотека садржи подразумевани мени програма за цео систем.
.PP .PP
.I ~/.local/share/mc/menu .I ~/.config/mc/menu
.IP .IP
Кориснички мени програма. Ако је ова датотека присутна, онда се она Кориснички мени програма. Ако је ова датотека присутна, онда се она
користи уместо менија програма система. користи уместо менија програма система.

View File

@ -199,7 +199,7 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
gboolean ok; gboolean ok;
/* ${XDG_CONFIG_HOME}/mc/filehighlight.ini */ /* ${XDG_CONFIG_HOME}/mc/filehighlight.ini */
name = g_build_filename (mc_config_get_data_path (), MC_FHL_INI_FILE, (char *) NULL); name = mc_config_get_full_path (MC_FHL_INI_FILE);
ok = mc_fhl_read_ini_file (fhl, name); ok = mc_fhl_read_ini_file (fhl, name);
g_free (name); g_free (name);
if (ok) if (ok)

View File

@ -104,7 +104,7 @@ get_log_filename (void)
if (mc_config_has_param (mc_main_config, CONFIG_GROUP_NAME, CONFIG_KEY_NAME_FILE)) if (mc_config_has_param (mc_main_config, CONFIG_GROUP_NAME, CONFIG_KEY_NAME_FILE))
return mc_config_get_string (mc_main_config, CONFIG_GROUP_NAME, CONFIG_KEY_NAME_FILE, NULL); return mc_config_get_string (mc_main_config, CONFIG_GROUP_NAME, CONFIG_KEY_NAME_FILE, NULL);
return g_build_filename (mc_config_get_cache_path (), "mc.log", NULL); return mc_config_get_full_path ("mc.log");
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -108,6 +108,8 @@ const char *mc_config_get_path (void);
const char *mc_config_get_home_dir (void); const char *mc_config_get_home_dir (void);
char *mc_config_get_full_path (const char *config_name);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/

View File

@ -26,6 +26,7 @@
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <errno.h> #include <errno.h>
#include "lib/global.h" #include "lib/global.h"
@ -39,14 +40,16 @@
/*** file scope macro definitions ****************************************************************/ /*** file scope macro definitions ****************************************************************/
#define MC_OLD_USERCONF_DIR ".mc"
/*** file scope type declarations ****************************************************************/ /*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/ /*** file scope variables ************************************************************************/
static gboolean xdg_vars_initialized = FALSE; static gboolean xdg_vars_initialized = FALSE;
static char *xdg_config = NULL; static char *mc_config_str = NULL;
static char *xdg_cache = NULL; static char *mc_cache_str = NULL;
static char *xdg_data = NULL; static char *mc_data_str = NULL;
static const char *homedir = NULL; static const char *homedir = NULL;
@ -58,42 +61,73 @@ static const struct
char **new_basedir; char **new_basedir;
const char *new_filename; const char *new_filename;
} mc_config_migrate_rules[] = } mc_config_files_reference[] =
{ {
/* *INDENT-OFF* */ /* *INDENT-OFF* */
/* config */ /* config */
{ "ini", &xdg_config, MC_CONFIG_FILE}, { "ini", &mc_config_str, MC_CONFIG_FILE},
{ "filehighlight.ini", &xdg_config, MC_FHL_INI_FILE}, { "filehighlight.ini", &mc_config_str, MC_FHL_INI_FILE},
{ "hotlist", &xdg_config, MC_HOTLIST_FILE}, { "hotlist", &mc_config_str, MC_HOTLIST_FILE},
{ "mc.keymap", &xdg_config, GLOBAL_KEYMAP_FILE}, { "mc.keymap", &mc_config_str, GLOBAL_KEYMAP_FILE},
{ "menu", &mc_config_str, MC_USERMENU_FILE},
{ "cedit" PATH_SEP_STR "Syntax", &mc_config_str, EDIT_SYNTAX_FILE},
{ "cedit" PATH_SEP_STR "menu", &mc_config_str, EDIT_HOME_MENU},
{ "cedit" PATH_SEP_STR "edit.indent.rc", &mc_config_str, EDIT_DIR PATH_SEP_STR "edit.indent.rc"},
{ "cedit" PATH_SEP_STR "edit.spell.rc", &mc_config_str, EDIT_DIR PATH_SEP_STR "edit.spell.rc"},
{ "panels.ini", &mc_config_str, MC_PANELS_FILE},
/* User should move this file with applying some changes in file */
{ "", &mc_config_str, MC_FILEBIND_FILE},
/* data */ /* data */
{ "skins", &xdg_data, MC_SKINS_SUBDIR}, { "skins", &mc_data_str, MC_SKINS_SUBDIR},
{ "fish", &xdg_data, FISH_PREFIX}, { "fish", &mc_data_str, FISH_PREFIX},
{ "bindings", &xdg_data, MC_FILEBIND_FILE}, { "bashrc", &mc_data_str, "bashrc"},
{ "menu", &xdg_data, MC_USERMENU_FILE}, { "inputrc", &mc_data_str, "inputrc"},
{ "bashrc", &xdg_data, "bashrc"}, { "extfs.d", &mc_data_str, MC_EXTFS_DIR},
{ "inputrc", &xdg_data, "inputrc"}, { "history", &mc_data_str, MC_HISTORY_FILE},
{ "extfs.d", &xdg_data, MC_EXTFS_DIR}, { "filepos", &mc_data_str, MC_FILEPOS_FILE},
{ "cedit" PATH_SEP_STR "Syntax", &xdg_data, EDIT_SYNTAX_FILE}, { "cedit" PATH_SEP_STR "cooledit.clip", &mc_data_str, EDIT_CLIP_FILE},
{ "cedit" PATH_SEP_STR "menu", &xdg_data, EDIT_HOME_MENU}, { "", &mc_data_str, MC_MACRO_FILE},
{ "cedit" PATH_SEP_STR "edit.indent.rc", &xdg_data, EDIT_DIR PATH_SEP_STR "edit.indent.rc"},
{ "cedit" PATH_SEP_STR "edit.spell.rc", &xdg_data, EDIT_DIR PATH_SEP_STR "edit.spell.rc"},
/* cache */ /* cache */
{ "history", &xdg_cache, MC_HISTORY_FILE}, { "log", &mc_cache_str, "mc.log"},
{ "panels.ini", &xdg_cache, MC_PANELS_FILE}, { "Tree", &mc_cache_str, MC_TREESTORE_FILE},
{ "log", &xdg_cache, "mc.log"}, { "cedit" PATH_SEP_STR "cooledit.temp", &mc_cache_str, EDIT_TEMP_FILE},
{ "filepos", &xdg_cache, MC_FILEPOS_FILE}, { "cedit" PATH_SEP_STR "cooledit.block", &mc_cache_str, EDIT_BLOCK_FILE},
{ "Tree", &xdg_cache, MC_TREESTORE_FILE},
{ "cedit" PATH_SEP_STR "cooledit.clip", &xdg_cache, EDIT_CLIP_FILE},
{ "cedit" PATH_SEP_STR "cooledit.temp", &xdg_cache, EDIT_TEMP_FILE},
{ "cedit" PATH_SEP_STR "cooledit.block", &xdg_cache, EDIT_BLOCK_FILE},
{NULL, NULL, NULL} {NULL, NULL, NULL}
/* *INDENT-ON* */ /* *INDENT-ON* */
}; };
#ifdef MC_HOMEDIR_XDG
static const struct
{
char **old_basedir;
const char *filename;
char **new_basedir;
} mc_config_migrate_rules_fix[] =
{
/* *INDENT-OFF* */
{ &mc_data_str, MC_USERMENU_FILE, &mc_config_str},
{ &mc_data_str, EDIT_SYNTAX_FILE, &mc_config_str},
{ &mc_data_str, EDIT_HOME_MENU, &mc_config_str},
{ &mc_data_str, EDIT_DIR PATH_SEP_STR "edit.indent.rc", &mc_config_str},
{ &mc_data_str, EDIT_DIR PATH_SEP_STR "edit.spell.rc", &mc_config_str},
{ &mc_data_str, MC_FILEBIND_FILE, &mc_config_str},
{ &mc_cache_str, MC_HISTORY_FILE, &mc_data_str},
{ &mc_cache_str, MC_FILEPOS_FILE, &mc_data_str},
{ &mc_cache_str, EDIT_CLIP_FILE, &mc_data_str},
{ &mc_cache_str, MC_PANELS_FILE, &mc_config_str},
{NULL, NULL, NULL}
/* *INDENT-ON* */
};
#endif /* MC_HOMEDIR_XDG */
/*** file scope functions *********************************************************************** */ /*** file scope functions *********************************************************************** */
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -118,8 +152,18 @@ mc_config_init_one_config_path (const char *path_base, const char *subdir, GErro
full_path = g_build_filename (path_base, subdir, NULL); full_path = g_build_filename (path_base, subdir, NULL);
if (g_file_test (full_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) if (g_file_test (full_path, G_FILE_TEST_EXISTS))
config_dir_present = TRUE; {
if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
{
config_dir_present = TRUE;
}
else
{
fprintf (stderr, "%s %s\n", _("FATAL: not a directory:"), full_path);
exit (EXIT_FAILURE);
}
}
mc_config_mkdir (full_path, error); mc_config_mkdir (full_path, error);
if (error != NULL && *error != NULL) if (error != NULL && *error != NULL)
@ -135,7 +179,7 @@ mc_config_init_one_config_path (const char *path_base, const char *subdir, GErro
static char * static char *
mc_config_get_deprecated_path (void) mc_config_get_deprecated_path (void)
{ {
return g_build_filename (mc_config_get_home_dir (), "." MC_USERCONF_DIR, NULL); return g_build_filename (mc_config_get_home_dir (), MC_OLD_USERCONF_DIR, NULL);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -189,6 +233,37 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error)
} }
} }
/* --------------------------------------------------------------------------------------------- */
#if MC_HOMEDIR_XDG
static void
mc_config_fix_migrated_rules (void)
{
size_t rule_index;
for (rule_index = 0; mc_config_migrate_rules_fix[rule_index].old_basedir != NULL; rule_index++)
{
char *old_name;
old_name =
g_build_filename (*mc_config_migrate_rules_fix[rule_index].old_basedir,
mc_config_migrate_rules_fix[rule_index].filename, NULL);
if (g_file_test (old_name, G_FILE_TEST_EXISTS))
{
char *new_name;
const char *basedir = *mc_config_migrate_rules_fix[rule_index].new_basedir;
const char *filename = mc_config_migrate_rules_fix[rule_index].filename;
new_name = g_build_filename (basedir, filename, NULL);
rename (old_name, new_name);
g_free (new_name);
}
g_free (old_name);
}
}
#endif /* MC_HOMEDIR_XDG */
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/ /*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -198,6 +273,7 @@ mc_config_init_config_paths (GError ** error)
{ {
const char *mc_datadir; const char *mc_datadir;
#ifdef MC_HOMEDIR_XDG
char *u_config_dir = (char *) g_get_user_config_dir (); char *u_config_dir = (char *) g_get_user_config_dir ();
char *u_data_dir = (char *) g_get_user_data_dir (); char *u_data_dir = (char *) g_get_user_data_dir ();
char *u_cache_dir = (char *) g_get_user_cache_dir (); char *u_cache_dir = (char *) g_get_user_cache_dir ();
@ -215,14 +291,28 @@ mc_config_init_config_paths (GError ** error)
? g_build_filename (mc_config_get_home_dir (), ".local", "share", NULL) ? g_build_filename (mc_config_get_home_dir (), ".local", "share", NULL)
: g_strdup (u_data_dir); : g_strdup (u_data_dir);
xdg_config = mc_config_init_one_config_path (u_config_dir, MC_USERCONF_DIR, error); mc_config_str = mc_config_init_one_config_path (u_config_dir, MC_USERCONF_DIR, error);
xdg_cache = mc_config_init_one_config_path (u_cache_dir, MC_USERCONF_DIR, error); mc_cache_str = mc_config_init_one_config_path (u_cache_dir, MC_USERCONF_DIR, error);
xdg_data = mc_config_init_one_config_path (u_data_dir, MC_USERCONF_DIR, error); mc_data_str = mc_config_init_one_config_path (u_data_dir, MC_USERCONF_DIR, error);
g_free (u_data_dir); g_free (u_data_dir);
g_free (u_cache_dir); g_free (u_cache_dir);
g_free (u_config_dir); g_free (u_config_dir);
mc_config_fix_migrated_rules ();
#else /* MC_HOMEDIR_XDG */
char *u_config_dir = g_build_filename (mc_config_get_home_dir (), MC_USERCONF_DIR, NULL);
u_config_dir = (u_config_dir == NULL)
? g_build_filename (mc_config_get_home_dir (), MC_OLD_USERCONF_DIR,
NULL) : g_strdup (u_config_dir);
mc_data_str = mc_cache_str = mc_config_str =
mc_config_init_one_config_path (u_config_dir, "", error);
g_free (u_config_dir);
#endif /* MC_HOMEDIR_XDG */
/* This is the directory, where MC was installed, on Unix this is DATADIR */ /* This is the directory, where MC was installed, on Unix this is DATADIR */
/* and can be overriden by the MC_DATADIR environment variable */ /* and can be overriden by the MC_DATADIR environment variable */
mc_datadir = g_getenv ("MC_DATADIR"); mc_datadir = g_getenv ("MC_DATADIR");
@ -244,9 +334,11 @@ mc_config_deinit_config_paths (void)
if (!xdg_vars_initialized) if (!xdg_vars_initialized)
return; return;
g_free (xdg_config); g_free (mc_config_str);
g_free (xdg_cache); #ifdef MC_HOMEDIR_XDG
g_free (xdg_data); g_free (mc_cache_str);
g_free (mc_data_str);
#endif /* MC_HOMEDIR_XDG */
g_free (mc_global.share_data_dir); g_free (mc_global.share_data_dir);
g_free (mc_global.sysconfig_dir); g_free (mc_global.sysconfig_dir);
@ -262,7 +354,7 @@ mc_config_get_data_path (void)
if (!xdg_vars_initialized) if (!xdg_vars_initialized)
mc_config_init_config_paths (NULL); mc_config_init_config_paths (NULL);
return (const char *) xdg_data; return (const char *) mc_data_str;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -273,7 +365,7 @@ mc_config_get_cache_path (void)
if (!xdg_vars_initialized) if (!xdg_vars_initialized)
mc_config_init_config_paths (NULL); mc_config_init_config_paths (NULL);
return (const char *) xdg_cache; return (const char *) mc_cache_str;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -298,7 +390,7 @@ mc_config_get_path (void)
if (!xdg_vars_initialized) if (!xdg_vars_initialized)
mc_config_init_config_paths (NULL); mc_config_init_config_paths (NULL);
return (const char *) xdg_config; return (const char *) mc_config_str;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -311,31 +403,35 @@ mc_config_migrate_from_old_place (GError ** error)
old_dir = mc_config_get_deprecated_path (); old_dir = mc_config_get_deprecated_path ();
g_free (mc_config_init_one_config_path (xdg_config, EDIT_DIR, error)); g_free (mc_config_init_one_config_path (mc_config_str, EDIT_DIR, error));
g_free (mc_config_init_one_config_path (xdg_cache, EDIT_DIR, error)); #ifdef MC_HOMEDIR_XDG
g_free (mc_config_init_one_config_path (xdg_data, EDIT_DIR, error)); g_free (mc_config_init_one_config_path (mc_cache_str, EDIT_DIR, error));
g_free (mc_config_init_one_config_path (mc_data_str, EDIT_DIR, error));
#endif /* MC_HOMEDIR_XDG */
for (rule_index = 0; mc_config_migrate_rules[rule_index].old_filename != NULL; rule_index++) for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
{ {
char *old_name; char *old_name;
if (*mc_config_files_reference[rule_index].old_filename == '\0')
continue;
old_name = old_name =
g_build_filename (old_dir, mc_config_migrate_rules[rule_index].old_filename, NULL); g_build_filename (old_dir, mc_config_files_reference[rule_index].old_filename, NULL);
if (g_file_test (old_name, G_FILE_TEST_EXISTS)) if (g_file_test (old_name, G_FILE_TEST_EXISTS))
{ {
char *new_name; char *new_name;
const char *basedir = *mc_config_files_reference[rule_index].new_basedir;
const char *filename = mc_config_files_reference[rule_index].new_filename;
new_name = g_build_filename (*mc_config_migrate_rules[rule_index].new_basedir, new_name = g_build_filename (basedir, filename, NULL);
mc_config_migrate_rules[rule_index].new_filename, NULL);
mc_config_copy (old_name, new_name, error); mc_config_copy (old_name, new_name, error);
g_free (new_name); g_free (new_name);
} }
g_free (old_name); g_free (old_name);
} }
#ifdef MC_HOMEDIR_XDG
g_propagate_error (error, g_propagate_error (error,
g_error_new (MC_ERROR, 0, g_error_new (MC_ERROR, 0,
_ _
@ -344,6 +440,13 @@ mc_config_migrate_from_old_place (GError ** error)
"To get more info, please visit\n" "To get more info, please visit\n"
"http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html"), "http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html"),
old_dir)); old_dir));
#else /* MC_HOMEDIR_XDG */
g_propagate_error (error,
g_error_new (MC_ERROR, 0,
_
("Your old settings were migrated from %s\n"
"to %s\n"), old_dir, mc_config_str));
#endif /* MC_HOMEDIR_XDG */
g_free (old_dir); g_free (old_dir);
} }
@ -364,3 +467,33 @@ mc_config_deprecated_dir_present (void)
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/**
* Get full path to config file by short name.
*
* @param config_name short name
* @return full path to config file
*/
char *
mc_config_get_full_path (const char *config_name)
{
size_t rule_index;
if (config_name == NULL)
return NULL;
if (!xdg_vars_initialized)
mc_config_init_config_paths (NULL);
for (rule_index = 0; mc_config_files_reference[rule_index].old_filename != NULL; rule_index++)
{
if (strcmp (config_name, mc_config_files_reference[rule_index].new_filename) == 0)
{
return g_build_filename (*mc_config_files_reference[rule_index].new_basedir,
mc_config_files_reference[rule_index].new_filename, NULL);
}
}
return NULL;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -1277,7 +1277,7 @@ load_file_position (const char *filename, long *line, long *column, off_t * offs
*offset = 0; *offset = 0;
/* open file with positions */ /* open file with positions */
fn = g_build_filename (mc_config_get_cache_path (), MC_FILEPOS_FILE, NULL); fn = mc_config_get_full_path (MC_FILEPOS_FILE);
f = fopen (fn, "r"); f = fopen (fn, "r");
g_free (fn); g_free (fn);
if (f == NULL) if (f == NULL)
@ -1367,7 +1367,7 @@ save_file_position (const char *filename, long line, long column, off_t offset,
filepos_max_saved_entries = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION, filepos_max_saved_entries = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
"filepos_max_saved_entries", 1024); "filepos_max_saved_entries", 1024);
fn = g_build_filename (mc_config_get_cache_path (), MC_FILEPOS_FILE, NULL); fn = mc_config_get_full_path (MC_FILEPOS_FILE);
if (fn == NULL) if (fn == NULL)
goto early_error; goto early_error;

View File

@ -165,7 +165,7 @@ dlg_read_history (Dlg_head * h)
if (num_history_items_recorded == 0) /* this is how to disable */ if (num_history_items_recorded == 0) /* this is how to disable */
return; return;
profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, NULL); profile = mc_config_get_full_path (MC_HISTORY_FILE);
event_data.cfg = mc_config_init (profile); event_data.cfg = mc_config_init (profile);
event_data.receiver = NULL; event_data.receiver = NULL;
@ -1192,7 +1192,7 @@ dlg_save_history (Dlg_head * h)
if (num_history_items_recorded == 0) /* this is how to disable */ if (num_history_items_recorded == 0) /* this is how to disable */
return; return;
profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, (char *) NULL); profile = mc_config_get_full_path (MC_HISTORY_FILE);
i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
if (i != -1) if (i != -1)
close (i); close (i);

View File

@ -150,7 +150,7 @@ history_get (const char *input_name)
if ((input_name == NULL) || (*input_name == '\0')) if ((input_name == NULL) || (*input_name == '\0'))
return NULL; return NULL;
profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, NULL); profile = mc_config_get_full_path (MC_HISTORY_FILE);
cfg = mc_config_init (profile); cfg = mc_config_init (profile);
hist = history_load (cfg, input_name); hist = history_load (cfg, input_name);
@ -303,7 +303,7 @@ history_put (const char *input_name, GList * h)
if (h == NULL) if (h == NULL)
return; return;
profile = g_build_filename (mc_config_get_cache_path (), MC_HISTORY_FILE, (char *) NULL); profile = mc_config_get_full_path (MC_HISTORY_FILE);
i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
if (i != -1) if (i != -1)

View File

@ -77,7 +77,7 @@ clipboard_file_to_ext_clip (const gchar * event_group_name, const gchar * event_
if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] == '\0') if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] == '\0')
return TRUE; return TRUE;
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
cmd = g_strconcat (clipboard_store_path, " ", tmp, " 2>/dev/null", (char *) NULL); cmd = g_strconcat (clipboard_store_path, " ", tmp, " 2>/dev/null", (char *) NULL);
if (cmd != NULL) if (cmd != NULL)
@ -107,7 +107,7 @@ clipboard_file_from_ext_clip (const gchar * event_group_name, const gchar * even
if (d == NULL || clipboard_paste_path == NULL || clipboard_paste_path[0] == '\0') if (d == NULL || clipboard_paste_path == NULL || clipboard_paste_path[0] == '\0')
return TRUE; return TRUE;
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
cmd = g_strconcat (clipboard_paste_path, " > ", tmp, " 2>/dev/null", (char *) NULL); cmd = g_strconcat (clipboard_paste_path, " > ", tmp, " 2>/dev/null", (char *) NULL);
if (cmd != NULL) if (cmd != NULL)
@ -138,7 +138,7 @@ clipboard_text_to_file (const gchar * event_group_name, const gchar * event_name
if (text == NULL) if (text == NULL)
return FALSE; return FALSE;
fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL); fname = mc_config_get_full_path (EDIT_CLIP_FILE);
file = mc_open (fname, O_CREAT | O_WRONLY | O_TRUNC, file = mc_open (fname, O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY); S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY);
g_free (fname); g_free (fname);
@ -169,7 +169,7 @@ clipboard_text_from_file (const gchar * event_group_name, const gchar * event_na
(void) event_name; (void) event_name;
(void) init_data; (void) init_data;
fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL); fname = mc_config_get_full_path (EDIT_CLIP_FILE);
f = fopen (fname, "r"); f = fopen (fname, "r");
g_free (fname); g_free (fname);

View File

@ -714,10 +714,10 @@ edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width)
cursor_buf_ptr = utf8_buf + (2 * UTF8_CHAR_LEN); cursor_buf_ptr = utf8_buf + (2 * UTF8_CHAR_LEN);
str = g_utf8_find_prev_char (utf8_buf, cursor_buf_ptr); str = g_utf8_find_prev_char (utf8_buf, cursor_buf_ptr);
if (str == NULL || g_utf8_next_char(str) != cursor_buf_ptr) if (str == NULL || g_utf8_next_char (str) != cursor_buf_ptr)
{ {
*char_width = 1; *char_width = 1;
return *(cursor_buf_ptr-1); return *(cursor_buf_ptr - 1);
} }
else else
{ {
@ -726,7 +726,7 @@ edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width)
if (res < 0) if (res < 0)
{ {
*char_width = 1; *char_width = 1;
return *(cursor_buf_ptr-1); return *(cursor_buf_ptr - 1);
} }
else else
{ {
@ -1833,7 +1833,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
long start_mark, end_mark; long start_mark, end_mark;
struct stat status; struct stat status;
block_file = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE); block_file = mc_config_get_full_path (EDIT_BLOCK_FILE);
curs = edit->curs1; curs = edit->curs1;
nomark = eval_marks (edit, &start_mark, &end_mark); nomark = eval_marks (edit, &start_mark, &end_mark);
if (nomark == 0) if (nomark == 0)

View File

@ -525,7 +525,7 @@ edit_load_syntax_file (WEdit * edit)
{ {
char *buffer; char *buffer;
buffer = concat_dir_and_file (mc_config_get_data_path (), EDIT_SYNTAX_FILE); buffer = mc_config_get_full_path (EDIT_SYNTAX_FILE);
check_for_default (extdir, buffer); check_for_default (extdir, buffer);
edit_load_file_from_filename (edit, buffer); edit_load_file_from_filename (edit, buffer);
g_free (buffer); g_free (buffer);
@ -566,7 +566,7 @@ edit_load_menu_file (WEdit * edit)
break; break;
case 1: case 1:
buffer = concat_dir_and_file (mc_config_get_data_path (), EDIT_HOME_MENU); buffer = mc_config_get_full_path (EDIT_HOME_MENU);
check_for_default (menufile, buffer); check_for_default (menufile, buffer);
break; break;
@ -937,7 +937,7 @@ edit_save_block_to_clip_file (WEdit * edit, long start, long finish)
{ {
int ret; int ret;
gchar *tmp; gchar *tmp;
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
ret = edit_save_block (edit, tmp, start, finish); ret = edit_save_block (edit, tmp, start, finish);
g_free (tmp); g_free (tmp);
return ret; return ret;
@ -1311,7 +1311,7 @@ edit_delete_macro (WEdit * edit, int hotkey)
edit_macro_sort_by_hotkey (); edit_macro_sort_by_hotkey ();
} }
macros_fname = g_build_filename (mc_config_get_data_path (), MC_MACRO_FILE, (char *) NULL); macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
macros_config = mc_config_init (macros_fname); macros_config = mc_config_init (macros_fname);
g_free (macros_fname); g_free (macros_fname);
@ -1645,7 +1645,7 @@ edit_store_macro_cmd (WEdit * edit)
edit_delete_macro (edit, hotkey); edit_delete_macro (edit, hotkey);
macros_fname = g_build_filename (mc_config_get_data_path (), MC_MACRO_FILE, (char *) NULL); macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
macros_config = mc_config_init (macros_fname); macros_config = mc_config_init (macros_fname);
g_free (macros_fname); g_free (macros_fname);
@ -1749,7 +1749,7 @@ edit_load_macro_cmd (WEdit * edit)
(void) edit; (void) edit;
macros_fname = g_build_filename (mc_config_get_data_path (), MC_MACRO_FILE, (char *) NULL); macros_fname = mc_config_get_full_path (MC_MACRO_FILE);
macros_config = mc_config_init (macros_fname); macros_config = mc_config_init (macros_fname);
g_free (macros_fname); g_free (macros_fname);
@ -2683,7 +2683,7 @@ edit_paste_from_X_buf_cmd (WEdit * edit)
gchar *tmp; gchar *tmp;
/* try use external clipboard utility */ /* try use external clipboard utility */
mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", NULL); mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", NULL);
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
edit_insert_file (edit, tmp); edit_insert_file (edit, tmp);
g_free (tmp); g_free (tmp);
} }
@ -2744,7 +2744,7 @@ edit_save_block_cmd (WEdit * edit)
if (eval_marks (edit, &start_mark, &end_mark)) if (eval_marks (edit, &start_mark, &end_mark))
return 1; return 1;
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
exp = exp =
input_expand_dialog (_("Save block"), _("Enter file name:"), input_expand_dialog (_("Save block"), _("Enter file name:"),
MC_HISTORY_EDIT_SAVE_BLOCK, tmp); MC_HISTORY_EDIT_SAVE_BLOCK, tmp);
@ -2786,7 +2786,7 @@ edit_insert_file_cmd (WEdit * edit)
gchar *tmp; gchar *tmp;
char *exp; char *exp;
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); tmp = mc_config_get_full_path (EDIT_CLIP_FILE);
exp = input_expand_dialog (_("Insert file"), _("Enter file name:"), exp = input_expand_dialog (_("Insert file"), _("Enter file name:"),
MC_HISTORY_EDIT_INSERT_FILE, tmp); MC_HISTORY_EDIT_INSERT_FILE, tmp);
g_free (tmp); g_free (tmp);
@ -2824,7 +2824,7 @@ int
edit_sort_cmd (WEdit * edit) edit_sort_cmd (WEdit * edit)
{ {
static char *old = 0; static char *old = 0;
char *exp, *tmp; char *exp, *tmp, *tmp_edit_block_name, *tmp_edit_temp_name;
long start_mark, end_mark; long start_mark, end_mark;
int e; int e;
@ -2834,7 +2834,7 @@ edit_sort_cmd (WEdit * edit)
return 0; return 0;
} }
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE); tmp = mc_config_get_full_path (EDIT_BLOCK_FILE);
edit_save_block (edit, tmp, start_mark, end_mark); edit_save_block (edit, tmp, start_mark, end_mark);
g_free (tmp); g_free (tmp);
@ -2846,10 +2846,14 @@ edit_sort_cmd (WEdit * edit)
return 1; return 1;
g_free (old); g_free (old);
old = exp; old = exp;
tmp_edit_block_name = mc_config_get_full_path (EDIT_BLOCK_FILE);
tmp_edit_temp_name = mc_config_get_full_path (EDIT_TEMP_FILE);
tmp = tmp =
g_strconcat (" sort ", exp, " ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_BLOCK_FILE, g_strconcat (" sort ", exp, " ", tmp_edit_block_name,
" > ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_TEMP_FILE, " > ", tmp_edit_temp_name, (char *) NULL);
(char *) NULL); g_free (tmp_edit_temp_name);
g_free (tmp_edit_block_name);
e = system (tmp); e = system (tmp);
g_free (tmp); g_free (tmp);
if (e) if (e)
@ -2873,7 +2877,7 @@ edit_sort_cmd (WEdit * edit)
if (edit_block_delete_cmd (edit)) if (edit_block_delete_cmd (edit))
return 1; return 1;
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_TEMP_FILE); tmp = mc_config_get_full_path (EDIT_TEMP_FILE);
edit_insert_file (edit, tmp); edit_insert_file (edit, tmp);
g_free (tmp); g_free (tmp);
return 0; return 0;
@ -2888,7 +2892,7 @@ edit_sort_cmd (WEdit * edit)
int int
edit_ext_cmd (WEdit * edit) edit_ext_cmd (WEdit * edit)
{ {
char *exp, *tmp; char *exp, *tmp, *tmp_edit_temp_file;
int e; int e;
exp = exp =
@ -2898,9 +2902,9 @@ edit_ext_cmd (WEdit * edit)
if (!exp) if (!exp)
return 1; return 1;
tmp = tmp_edit_temp_file = mc_config_get_full_path (EDIT_TEMP_FILE);
g_strconcat (exp, " > ", mc_config_get_cache_path (), PATH_SEP_STR EDIT_TEMP_FILE, tmp = g_strconcat (exp, " > ", tmp_edit_temp_file, (char *) NULL);
(char *) NULL); g_free (tmp_edit_temp_file);
e = system (tmp); e = system (tmp);
g_free (tmp); g_free (tmp);
g_free (exp); g_free (exp);
@ -2912,7 +2916,7 @@ edit_ext_cmd (WEdit * edit)
} }
edit->force |= REDRAW_COMPLETELY; edit->force |= REDRAW_COMPLETELY;
tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_TEMP_FILE); tmp = mc_config_get_full_path (EDIT_TEMP_FILE);
edit_insert_file (edit, tmp); edit_insert_file (edit, tmp);
g_free (tmp); g_free (tmp);
return 0; return 0;

View File

@ -1512,7 +1512,7 @@ edit_load_syntax (WEdit * edit, char ***pnames, const char *type)
if (!*edit->filename && !type) if (!*edit->filename && !type)
return; return;
} }
f = g_build_filename (mc_config_get_data_path (), EDIT_SYNTAX_FILE, (char *) NULL); f = mc_config_get_full_path (EDIT_SYNTAX_FILE);
if (edit != NULL) if (edit != NULL)
r = edit_read_syntax_file (edit, pnames, f, edit->filename, r = edit_read_syntax_file (edit, pnames, f, edit->filename,
get_first_editor_line (edit), get_first_editor_line (edit),

View File

@ -1069,7 +1069,7 @@ ext_cmd (void)
if (dir == 0) if (dir == 0)
{ {
buffer = g_build_filename (mc_config_get_data_path (), MC_FILEBIND_FILE, NULL); buffer = mc_config_get_full_path (MC_FILEBIND_FILE);
check_for_default (extdir, buffer); check_for_default (extdir, buffer);
do_edit (buffer); do_edit (buffer);
g_free (buffer); g_free (buffer);
@ -1118,7 +1118,7 @@ edit_mc_menu_cmd (void)
break; break;
case 1: case 1:
buffer = g_build_filename (mc_config_get_data_path (), MC_USERMENU_FILE, NULL); buffer = mc_config_get_full_path (MC_USERMENU_FILE);
check_for_default (menufile, buffer); check_for_default (menufile, buffer);
break; break;
@ -1163,7 +1163,7 @@ edit_fhl_cmd (void)
if (dir == 0) if (dir == 0)
{ {
buffer = g_build_filename (mc_config_get_path (), MC_FHL_INI_FILE, NULL); buffer = mc_config_get_full_path (MC_FHL_INI_FILE);
check_for_default (fhlfile, buffer); check_for_default (fhlfile, buffer);
do_edit (buffer); do_edit (buffer);
g_free (buffer); g_free (buffer);
@ -1615,7 +1615,7 @@ save_setup_cmd (void)
char *d1; char *d1;
const char *d2; const char *d2;
d1 = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, (char *) NULL); d1 = mc_config_get_full_path (MC_CONFIG_FILE);
d2 = strip_home_and_password (d1); d2 = strip_home_and_password (d1);
g_free (d1); g_free (d1);

View File

@ -641,7 +641,7 @@ regex_command (const char *filename, const char *action, int *move_dir)
int mc_user_ext = 1; int mc_user_ext = 1;
int home_error = 0; int home_error = 0;
extension_file = g_build_filename (mc_config_get_data_path (), MC_FILEBIND_FILE, NULL); extension_file = mc_config_get_full_path (MC_FILEBIND_FILE);
if (!exist_file (extension_file)) if (!exist_file (extension_file))
{ {
g_free (extension_file); g_free (extension_file);
@ -687,15 +687,14 @@ regex_command (const char *filename, const char *action, int *move_dir)
} }
if (home_error) if (home_error)
{ {
char *title = g_strdup_printf (_("%s%s%s file error"), char *filebind_filename = mc_config_get_full_path (MC_FILEBIND_FILE);
mc_config_get_data_path (), PATH_SEP_STR, char *title = g_strdup_printf (_("%s file error"), filebind_filename);
MC_FILEBIND_FILE);
message (D_ERROR, title, message (D_ERROR, title,
_("The format of the %s%s%s file has " _("The format of the %s file has "
"changed with version 3.0. You may either want to copy " "changed with version 3.0. You may either want to copy "
"it from %smc.ext or use that file as an example of how to write it."), "it from %smc.ext or use that file as an example of how to write it."),
mc_config_get_data_path (), PATH_SEP_STR, MC_FILEBIND_FILE, filebind_filename, mc_global.sysconfig_dir);
mc_global.sysconfig_dir); g_free (filebind_filename);
g_free (title); g_free (title);
} }
} }

View File

@ -1564,7 +1564,7 @@ load_hotlist (void)
} }
if (!hotlist_file_name) if (!hotlist_file_name)
hotlist_file_name = g_build_filename (mc_config_get_path (), MC_HOTLIST_FILE, NULL); hotlist_file_name = mc_config_get_full_path (MC_HOTLIST_FILE);
hotlist = new_hotlist (); hotlist = new_hotlist ();
hotlist->type = HL_TYPE_GROUP; hotlist->type = HL_TYPE_GROUP;

View File

@ -178,8 +178,7 @@ save_tree (WTree * tree)
if (error) if (error)
{ {
tree_name = tree_name = mc_config_get_full_path (MC_TREESTORE_FILE);
g_build_filename (mc_config_get_cache_path (), MC_TREESTORE_FILE, (char *) NULL);
fprintf (stderr, _("Cannot open the %s file for writing:\n%s\n"), tree_name, fprintf (stderr, _("Cannot open the %s file for writing:\n%s\n"), tree_name,
unix_error_string (error)); unix_error_string (error));
g_free (tree_name); g_free (tree_name);

View File

@ -647,7 +647,7 @@ tree_store_load (void)
char *name; char *name;
int retval; int retval;
name = g_build_filename (mc_config_get_cache_path (), MC_TREESTORE_FILE, NULL); name = mc_config_get_full_path (MC_TREESTORE_FILE);
retval = tree_store_load_from (name); retval = tree_store_load_from (name);
g_free (name); g_free (name);
@ -667,7 +667,7 @@ tree_store_save (void)
char *name; char *name;
int retval; int retval;
name = g_build_filename (mc_config_get_cache_path (), MC_TREESTORE_FILE, NULL); name = mc_config_get_full_path (MC_TREESTORE_FILE);
mc_util_make_backup_if_possible (name, ".tmp"); mc_util_make_backup_if_possible (name, ".tmp");
retval = tree_store_save_to (name); retval = tree_store_save_to (name);

View File

@ -798,7 +798,7 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
#ifdef USE_INTERNAL_EDIT #ifdef USE_INTERNAL_EDIT
if (edit_widget) if (edit_widget)
{ {
char *file = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE); char *file = mc_config_get_full_path (EDIT_BLOCK_FILE);
fname = (*quote_func) (file, 0); fname = (*quote_func) (file, 0);
g_free (file); g_free (file);
return fname; return fname;
@ -897,9 +897,9 @@ user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_e
g_free (menu); g_free (menu);
if (edit_widget) if (edit_widget)
menu = concat_dir_and_file (mc_config_get_data_path (), EDIT_HOME_MENU); menu = mc_config_get_full_path (EDIT_HOME_MENU);
else else
menu = g_build_filename (mc_config_get_data_path (), MC_USERMENU_FILE, NULL); menu = mc_config_get_full_path (MC_USERMENU_FILE);
if (!exist_file (menu)) if (!exist_file (menu))

View File

@ -621,8 +621,7 @@ load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t
{ {
gchar **values, **curr_values; gchar **values, **curr_values;
curr_values = values = curr_values = values = mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
mc_config_get_string_list (cfg, section_name, *profile_keys, &len);
if (curr_values != NULL) if (curr_values != NULL)
{ {
@ -672,7 +671,7 @@ load_setup_get_keymap_profile_config (gboolean load_from_file)
g_free (fname); g_free (fname);
/* 3) ${XDG_CONFIG_HOME}/mc */ /* 3) ${XDG_CONFIG_HOME}/mc */
fname = g_build_filename (mc_config_get_path (), GLOBAL_KEYMAP_FILE, NULL); fname = mc_config_get_full_path (GLOBAL_KEYMAP_FILE);
load_setup_init_config_from_file (&keymap_config, fname); load_setup_init_config_from_file (&keymap_config, fname);
g_free (fname); g_free (fname);
@ -793,7 +792,7 @@ setup_init (void)
if (profile_name != NULL) if (profile_name != NULL)
return profile_name; return profile_name;
profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL); profile = mc_config_get_full_path (MC_CONFIG_FILE);
if (!exist_file (profile)) if (!exist_file (profile))
{ {
inifile = concat_dir_and_file (mc_global.sysconfig_dir, "mc.ini"); inifile = concat_dir_and_file (mc_global.sysconfig_dir, "mc.ini");
@ -848,7 +847,7 @@ load_setup (void)
g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL); g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL);
} }
panels_profile_name = g_build_filename (mc_config_get_cache_path (), MC_PANELS_FILE, NULL); panels_profile_name = mc_config_get_full_path (MC_PANELS_FILE);
mc_main_config = mc_config_init (profile); mc_main_config = mc_config_init (profile);
@ -1005,7 +1004,7 @@ save_setup (gboolean save_options, gboolean save_panel_options)
mc_config_set_string (mc_main_config, "Misc", "clipboard_store", clipboard_store_path); mc_config_set_string (mc_main_config, "Misc", "clipboard_store", clipboard_store_path);
mc_config_set_string (mc_main_config, "Misc", "clipboard_paste", clipboard_paste_path); mc_config_set_string (mc_main_config, "Misc", "clipboard_paste", clipboard_paste_path);
tmp_profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL); tmp_profile = mc_config_get_full_path (MC_CONFIG_FILE);
ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL); ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
g_free (tmp_profile); g_free (tmp_profile);
} }
@ -1139,7 +1138,7 @@ void
load_keymap_defs (gboolean load_from_file) load_keymap_defs (gboolean load_from_file)
{ {
/* /*
* Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_DATA_HOME}/mc/keymap, so that the user * Load keymap from GLOBAL_KEYMAP_FILE before ${XDG_CONFIG_HOME}/mc/mc.keymap, so that the user
* definitions override global settings. * definitions override global settings.
*/ */
mc_config_t *mc_global_keymap; mc_config_t *mc_global_keymap;

View File

@ -269,7 +269,7 @@ init_subshell_child (const char *pty_name)
switch (subshell_type) switch (subshell_type)
{ {
case BASH: case BASH:
init_file = g_build_filename (mc_config_get_path (), "bashrc", NULL); init_file = mc_config_get_full_path ("bashrc");
if (access (init_file, R_OK) == -1) if (access (init_file, R_OK) == -1)
{ {
@ -282,7 +282,7 @@ init_subshell_child (const char *pty_name)
/* Allow alternative readline settings for MC */ /* Allow alternative readline settings for MC */
{ {
char *input_file = g_build_filename (mc_config_get_path (), "inputrc", NULL); char *input_file = mc_config_get_full_path ("inputrc");
if (access (input_file, R_OK) == 0) if (access (input_file, R_OK) == 0)
{ {
char *putenv_str = g_strconcat ("INPUTRC=", input_file, NULL); char *putenv_str = g_strconcat ("INPUTRC=", input_file, NULL);

View File

@ -163,6 +163,7 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
int res = -1; int res = -1;
gunichar ch; gunichar ch;
gchar *next_ch = NULL; gchar *next_ch = NULL;
gchar utf8buf[UTF8_CHAR_LEN + 1];
*char_width = 0; *char_width = 0;
*result = FALSE; *result = FALSE;
@ -188,6 +189,25 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
res = g_utf8_get_char_validated (str, -1); res = g_utf8_get_char_validated (str, -1);
if (res < 0)
{
/* Retry with explicit bytes to make sure it's not a buffer boundary */
int i;
for (i = 0; i < UTF8_CHAR_LEN; i++)
{
if (mcview_get_byte (view, byte_index + i, &res))
utf8buf[i] = res;
else
{
utf8buf[i] = '\0';
break;
}
}
utf8buf[UTF8_CHAR_LEN] = '\0';
str = utf8buf;
res = g_utf8_get_char_validated (str, -1);
}
if (res < 0) if (res < 0)
{ {
ch = *str; ch = *str;

View File

@ -1,12 +1,18 @@
AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFLAGS@ \ AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFLAGS@ \
-DWORKDIR=\"$(abs_builddir)\" -DWORKDIR=\"$(abs_builddir)\" -z muldefs
AM_LDFLAGS = -z muldefs
LIBS=@CHECK_LIBS@ $(top_builddir)/lib/libmc.la LIBS=@CHECK_LIBS@ $(top_builddir)/lib/libmc.la
TESTS = \ TESTS = \
config_string config_string \
user_configs_path
check_PROGRAMS = $(TESTS) check_PROGRAMS = $(TESTS)
config_string_SOURCES = \ config_string_SOURCES = \
config_string.c config_string.c
user_configs_path_SOURCES = \
user_configs_path.c

View File

@ -0,0 +1,142 @@
/*
libmc - check mcconfig submodule. Get full paths to user's config files.
Copyright (C) 2011
The Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2011
This file is part of the Midnight Commander.
The Midnight Commander 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 3 of the License,
or (at your option) any later version.
The Midnight Commander 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, see <http://www.gnu.org/licenses/>.
*/
#define TEST_SUITE_NAME "lib/mcconfig"
#include <config.h>
#include <check.h>
#include "lib/global.h"
#include "lib/strutil.h"
#include "lib/strescape.h"
#include "lib/vfs/vfs.h"
#include "lib/fileloc.h"
#include "lib/mcconfig.h"
#include "src/vfs/local/local.c"
#define HOME_DIR "/home/testuser"
#ifdef MC_HOMEDIR_XDG
# define CONF_MAIN HOME_DIR PATH_SEP_STR ".config"
# define CONF_DATA HOME_DIR PATH_SEP_STR ".local" PATH_SEP_STR "share"
# define CONF_CACHE HOME_DIR PATH_SEP_STR ".cache"
#else
# define CONF_MAIN HOME_DIR
# define CONF_DATA CONF_MAIN
# define CONF_CACHE CONF_MAIN
#endif
static void
setup (void)
{
g_setenv ("HOME", HOME_DIR, TRUE);
#ifdef MC_HOMEDIR_XDG
g_setenv ("XDG_CONFIG_HOME", CONF_MAIN, TRUE);
g_setenv ("XDG_DATA_HOME", CONF_DATA, TRUE);
g_setenv ("XDG_CACHE_HOME", CONF_CACHE, TRUE);
#endif
str_init_strings("UTF-8");
vfs_init ();
init_localfs ();
}
static void
teardown (void)
{
vfs_shut ();
str_uninit_strings();
}
#define path_fail_unless(conf_dir, conf_name) {\
result = mc_config_get_full_path (conf_name); \
fail_unless (strcmp( conf_dir PATH_SEP_STR MC_USERCONF_DIR PATH_SEP_STR conf_name, result) == 0); \
g_free (result); \
}
/* --------------------------------------------------------------------------------------------- */
START_TEST (user_configs_path_test)
{
char *result;
path_fail_unless (CONF_MAIN, MC_CONFIG_FILE);
path_fail_unless (CONF_MAIN, MC_FHL_INI_FILE);
path_fail_unless (CONF_MAIN, MC_HOTLIST_FILE);
path_fail_unless (CONF_MAIN, GLOBAL_KEYMAP_FILE);
path_fail_unless (CONF_MAIN, MC_USERMENU_FILE);
path_fail_unless (CONF_MAIN, EDIT_SYNTAX_FILE);
path_fail_unless (CONF_MAIN, EDIT_HOME_MENU);
path_fail_unless (CONF_MAIN, EDIT_DIR PATH_SEP_STR "edit.indent.rc");
path_fail_unless (CONF_MAIN, EDIT_DIR PATH_SEP_STR "edit.spell.rc");
path_fail_unless (CONF_MAIN, MC_PANELS_FILE);
path_fail_unless (CONF_MAIN, MC_FILEBIND_FILE);
path_fail_unless (CONF_DATA, MC_SKINS_SUBDIR);
path_fail_unless (CONF_DATA, FISH_PREFIX);
path_fail_unless (CONF_DATA, "bashrc");
path_fail_unless (CONF_DATA, "inputrc");
path_fail_unless (CONF_DATA, MC_EXTFS_DIR);
path_fail_unless (CONF_DATA, MC_HISTORY_FILE);
path_fail_unless (CONF_DATA, MC_FILEPOS_FILE);
path_fail_unless (CONF_DATA, EDIT_CLIP_FILE);
path_fail_unless (CONF_DATA, MC_MACRO_FILE);
path_fail_unless (CONF_CACHE, "mc.log");
path_fail_unless (CONF_CACHE, MC_TREESTORE_FILE);
path_fail_unless (CONF_CACHE, EDIT_TEMP_FILE);
path_fail_unless (CONF_CACHE, EDIT_BLOCK_FILE);
}
END_TEST
/* --------------------------------------------------------------------------------------------- */
int
main (void)
{
int number_failed;
Suite *s = suite_create (TEST_SUITE_NAME);
TCase *tc_core = tcase_create ("Core");
SRunner *sr;
tcase_add_checked_fixture (tc_core, setup, teardown);
/* Add new tests here: *************** */
tcase_add_test (tc_core, user_configs_path_test);
/* *********************************** */
suite_add_tcase (s, tc_core);
sr = srunner_create (s);
srunner_set_log (sr, "user_configs_path.log");
// srunner_set_fork_status (sr, CK_NOFORK);
srunner_run_all (sr, CK_NORMAL);
number_failed = srunner_ntests_failed (sr);
srunner_free (sr);
return (number_failed == 0) ? 0 : 1;
}
/* --------------------------------------------------------------------------------------------- */