From owner-freebsd-hackers Wed Oct 20 13:11: 8 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from smtp02.wxs.nl (smtp02.wxs.nl [195.121.6.60]) by hub.freebsd.org (Postfix) with ESMTP id 551C614D60; Wed, 20 Oct 1999 13:10:58 -0700 (PDT) (envelope-from asmodai@wxs.nl) Received: from daemon.ninth-circle.org ([195.121.197.195]) by smtp02.wxs.nl (Netscape Messaging Server 3.61) with ESMTP id AAB16BC; Wed, 20 Oct 1999 22:10:56 +0200 Received: (from asmodai@localhost) by daemon.ninth-circle.org (8.9.3/8.9.3) id WAA90771; Wed, 20 Oct 1999 22:10:08 +0200 (CEST) (envelope-from asmodai) Date: Wed, 20 Oct 1999 22:10:08 +0200 From: Jeroen Ruigrok/Asmodai To: hackers@freebsd.org Cc: Bill Fumerola , Bruce Evans Subject: getopt.h Message-ID: <19991020221007.A90211@daemon.ninth-circle.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre3i Organisation: Ninth-Circle Enterprises Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Well I searched the mailinglists and didn't really got further than discovering that unistd.h goes a little way to provide functionality which getopt.h from glibc provides. And seeing that a question of Bill early 1999 never got answered correctly. I cc:'d Bruce on this since I value his stylistic mindset on this issue. I am starting on this topic since I need to port the source of an application and I found the support of some part of getopt.h and lack of support for the other part a kind of an oddity in the source tree. That, plus a lot of our ports depend on it. And it would be a waste for using ports/devel/libgnugetopt when the solution is pretty small. In unistd.h we have definitions for getopt, optarg, optind, opterr, and optopt. However this means we still have this to worry about: [hacked up version of linux/glibc/posix/getopt.h] #if !defined __GNU_LIBRARY__ #include #endif struct option { #if defined __STDC__ && __STDC__ const char *name; #else char *name; #endif int has_arg; int *flag; int val; }; #define no_argument 0 #define required_argument 1 #define optional_argument 2 #if defined __STDC__ && __STDC__ extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind); extern int getopt_long_only (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind); extern int _getopt_internal (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind, int __long_only); #endif /* __STDC__ */ I think the above inclusion of ctype.h can be forgotten about when we include sys/types.h and sys/cdefs.h such as unistd.h does. So that effectively leaves us with one struct, three defines and three functions. The things I propose to add to unistd.h are the following: struct option { char *name; int has_arg; int *flag; int val; }; #define no_argument 0 #define required_argument 1 #define optional_argument 2 extern int getopt_long (int, char *const [], const char *, const struct option *, int *); extern int getopt_long_only (int, char *const [], const char *, const struct option *, int *); extern int _getopt_internal (int, char *const [], const char *, const struct option *, int *, int ); This should enable us to compile programs which require getopt.h by simply including unistd.h. I would like to hear any constructive comments on this. Mostly on the three #define's. regards, -- Jeroen Ruigrok van der Werven/Asmodai asmodai(at)wxs.nl The BSD Programmer's Documentation Project Network/Security Specialist BSD: Technical excellence at its best For country, children, hearth, and home. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message