Article View: es.comp.os.linux.programacion
Article #12803Parsear l�nea de comandos en C
From: crisp
Date: Thu, 10 May 2001 10:59
Date: Thu, 10 May 2001 10:59
43 lines
2560 bytes
2560 bytes
Hola a todos.
Estoy haciendo un peque�o programita en GNU/Linux en C, y quiero que
los par�metros que se le pasen puedan ser del tipo corto y largo:
Ej: miprograma -i eth0 == miprograma --interface eth0
miprograma -h == miprograma --help
etc....
Hasta ahora s�lo utilizaba par�metros cortos, gracias a la funci�n
getopt(). He visto que existe la funci�n getopt_long(); pero el
problema es que como bien dice la p�gina del manual (man 3 getopt), no
hay qui�n la entienda ;-) La verdad es que la sintaxis de esas
funciones es bastante liosa.
Esto es lo que tengo ahora (lo copi� de otro programa parecido, aunque
sin saber exactamente c�mo funciona):
while((i = getopt(argc, argv, "d,i:s")) != -1)
{
switch(i)
{
case 'd': { show_download = 1; break; }
case 'i': { carg++;
strncpy(miface,argv[carg],sizeof(miface)); break; }
default: { usage(argv); } // shows options
}
Y quiero ponerlo tambi�n con la opci�n larga y otras opciones m�s.
Si alguien conoce alguna direcci�n/tutorial que me pueda servir de
ayuda, le estar� muy agradecido.
Saludos para todos y gracias por adelantado.
-
crispNOSPAM@softhomeNOSPAM.net
Quita NOSPAM si quieres contactar conmigo
================================================================
�� Tarifa plana YA !! YA hace tiempo que deber�amos tenerla....
================================================================
Technical Details
Message-ID:
<shskftg73jas41fjg68rivble3d5mi95g4@4ax.com>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!194.25.134.62!newsfeed00.sul.t-online.de!t-online.de!news-ge.switch.ch!news.rediris.es!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!news.bt.es!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,81a5aeecbc4fa4c2,start X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2001-05-10 04:01:58 PST From: crisp <esta@no.es.mi.direccion.verdadera> Newsgroups: es.comp.os.linux.programacion Subject: Parsear l�nea de comandos en C Date: Thu, 10 May 2001 12:59:51 +0200 Organization: Tarifa Plana....YA!!! Lines: 43 Message-ID: <shskftg73jas41fjg68rivble3d5mi95g4@4ax.com> NNTP-Posting-Host: cable231a161.usuarios.retecal.es Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: titan.bt.es 989492280 21026 212.183.231.161 (10 May 2001 10:58:00 GMT) X-Complaints-To: abuse@bt.es NNTP-Posting-Date: 10 May 2001 10:58:00 GMT X-Newsreader: Forte Agent 1.8/32.548 Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!194.25.134.62!newsfeed00.sul.t-online.de!t-online.de!news-ge.switch.ch!news.rediris.es!newsfeed.bt.es!195.5.65.34.MISMATCH!caladan.arrakis.es!news.bt.es!not-for-mail