Article View: es.comp.os.linux.programacion
Article #11123Re: Actualizar el XF86Config desde un script
From: Ignacio Arenaza
Date: Sat, 29 Dec 2001 23:06
Date: Sat, 29 Dec 2001 23:06
113 lines
4181 bytes
4181 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
>>>>> "tas" == tas <tas@subdimension.com> writes:
tas> Hola. Estoy intentando actualizar la entrada "FontPath" del
tas> fichero XF86Config desde un script. Se trata de comprobar si
tas> una ruta dada est� ya en el "FontPath", y en caso negativo
tas> a�adirla al final.
tas> Si alguien me pudiera orientar sobre (a) c�mo solucionar todo
tas> esto, (b) alguna otra forma de afrontar la tarea, o (c) qu�
tas> otros problemas podr�an surgir, le estar�a muy agradecido.
El churro (bastante poco optimizado y limpio, la verdad) que adjunto a
continuacion permite verificar si el path que se le indica como
argumento esta o no en el fichero que se le envia por la entrada
estandar (como un valor del tipo FontPath). Genera el codigo de
retorno 0 (cero) si el path se ha encontrado en el fichero y 1 (uno)
en caso contrario. Por ejemplo, si tengo en el fichero
/etc/X11/XF86Config algo como:
...
Section "Files"
RgbPath "/usr/X11R6/lib/X11/rgb"
FontPath "/usr/X11R6/lib/X11/fonts/misc:unscaled"
FontPath "/usr/X11R6/lib/X11/fonts/75dpi:unscaled"
FontPath "/usr/X11R6/lib/X11/fonts/100dpi:unscaled"
FontPath "/usr/X11R6/lib/X11/fonts/URW",\
"/usr/X11R6/lib/X11/fonts/75dpi", "/usr/X11R6/lib/X11/fonts/100dpi",\
"/usr/X11R6/lib/X11/fonts/freefont/"
FONTPath "/usr/X11R6/lib/X11/fonts/sharefont/"
EndSection
...
Con la orden:
$ busca_fontpath.pl /usr/X11R6/lib/X11/fonts/misc:unscale <
/etc/X11/XF86Config
$ echo $?
0
$ busca_fontpath.pl /usr/X11R6/lib/X11/fonts/no-esta <
/etc/X11/XF86Config
$ echo $?
1
<-----> <-----> <-----> <-----> <-----> <-----> <-----> <-----> <----->
#!/usr/bin/perl -w
#
# fichero busca_fontpath.pl
#
# Copyright (C) 2001 Ignacio Arenaza. Distribuible bajo licencia GPL.
#
use strict;
my $IN;
my $OUT;
my $continue;
my $last;
my @paths;
my %fontpaths;
my $i;
$continue = 0;
print "$ARGV[1]\n";
while (<STDIN>) {
chomp;
next unless (/^ *FontPath/i or $continue);
if (! $continue) {
/^ *FontPath (.*)$/io;
$_ = $1;
}
/^ *(.*)$/o;
$_ = $1;
$last = substr ($_, -1);
if ($last eq "\\") {
$continue = 1;
$_ = substr ($_, 0, length ($_)-1);
}
else {
$continue = 0;
}
@paths = split /,/;
foreach $i (@paths) {
$i =~ /^[^\"]*\"([^\"]*)\"/o;
$_ = $1;
$fontpaths{$_} = 1;
}
}
if (defined ($fontpaths {$ARGV[0]})) {
exit 0;
}
else {
exit 1;
}
<-----> <-----> <-----> <-----> <-----> <-----> <-----> <-----> <----->
Saludos. I�aki.
- --
Get PGP/GPG Keys at http://www.escomposlinux.org/iarenaza/pgpkey.html
I use free software / Yo uso software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt and GPG
iD8DBQE8LkyPZXLnGT1HLgcRApmVAJ9uJL2U0wbugxC6V9QQgTibLeqJLgCeIHrN
CfuWIiiceJgfqEQzDBidDBc=
=+WoD
-----END PGP SIGNATURE-----
Technical Details
Message-ID:
<871yhdzkvi.fsf@eb2ebu.ampr.org>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!213-98-91-117.uc.nombres.ttd.ES!not-for-mailReferences:
<rvhi0a.9aj.ln@127.0.0.1>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,3ab78fa791df1f1e X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2001-12-29 15:20:24 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!213-98-91-117.uc.nombres.ttd.ES!not-for-mail From: Ignacio Arenaza <iarenaza@eb2ebu.ampr.org> Newsgroups: es.comp.os.linux.programacion Subject: Re: Actualizar el XF86Config desde un script Date: 30 Dec 2001 00:06:57 +0100 Organization: Servidor NNTP de eb2ebu.ampr.org Lines: 113 Message-ID: <871yhdzkvi.fsf@eb2ebu.ampr.org> References: <rvhi0a.9aj.ln@127.0.0.1> NNTP-Posting-Host: 213-98-91-117.uc.nombres.ttd.es (213.98.91.117) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: fu-berlin.de 1009668023 22914601 213.98.91.117 (16 [63420]) X-Orig-Path: julieta.escomposlinux.org!eriador.escomposlinux.net!eb2ebu.ampr.org!not-for-mail User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7