Date: Wed, 1 Sep 1999 10:15:07 +0200 (CEST) From: johan@bricsnet.com To: FreeBSD-gnats-submit@freebsd.org Subject: ports/13516: ported picprog-1.0 from LinuX to FreeBSD Message-ID: <199909010815.KAA21934@mail.bricsnet.com>
next in thread | raw e-mail | index | archive | help
>Number: 13516 >Category: ports >Synopsis: ported picprog-1.0 from LinuX to FreeBSD >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Sep 1 01:20:01 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Johan Kerckaert >Release: FreeBSD 3.2-STABLE i386 >Organization: BricsNet >Environment: >Description: Serial port pic16c84 programmer. >How-To-Repeat: >Fix: # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # picprog # picprog/pkg # picprog/pkg/COMMENT # picprog/pkg/DESCR # picprog/pkg/PLIST # picprog/patches # picprog/patches/patch-ae # picprog/patches/patch-ac # picprog/patches/patch-ad # picprog/patches/patch-ab # picprog/patches/getopt1.c # picprog/patches/getopt.h # picprog/patches/getopt.c # picprog/patches/patch-aa # picprog/files # picprog/files/md5 # picprog/Makefile # echo c - picprog mkdir -p picprog > /dev/null 2>&1 echo c - picprog/pkg mkdir -p picprog/pkg > /dev/null 2>&1 echo x - picprog/pkg/COMMENT sed 's/^X//' >picprog/pkg/COMMENT << 'END-of-picprog/pkg/COMMENT' XSerial port pic16c84 programmer. END-of-picprog/pkg/COMMENT echo x - picprog/pkg/DESCR sed 's/^X//' >picprog/pkg/DESCR << 'END-of-picprog/pkg/DESCR' XThis is Picprog, pic16c84 programmer software for the serial port device. XCopyright 1997 Jaakko Hyvatti X XTo program a pic16c84 chip: X X picprog --burn --input something.hex --pic /dev/cuaa1 X XFull manual: X X see file /usr/local/share/doc/picprog/picprog.html X or <URL:http://www.iki.fi/hyvatti/pic/picprog.html> X XThe author may be contacted at: X X Email: Jaakko.Hyvatti@iki.fi X URL: http://www.iki.fi/hyvatti/ X Phone: +358 40 5011222 X XRemember: this is not a production quality programmer! See PIC16C84 Xdata sheet for more information. END-of-picprog/pkg/DESCR echo x - picprog/pkg/PLIST sed 's/^X//' >picprog/pkg/PLIST << 'END-of-picprog/pkg/PLIST' Xbin/picprog Xshare/doc/picprog/anybrowser3.gif Xshare/doc/picprog/jdm84pcb3.gif Xshare/doc/picprog/jdm84new.gif Xshare/doc/picprog/picprog.html X@dirrm share/doc/picprog END-of-picprog/pkg/PLIST echo c - picprog/patches mkdir -p picprog/patches > /dev/null 2>&1 echo x - picprog/patches/patch-ae sed 's/^X//' >picprog/patches/patch-ae << 'END-of-picprog/patches/patch-ae' X--- program.h.orig Sun Nov 29 16:03:30 1998 X+++ program.h Sun Nov 29 16:04:01 1998 X@@ -31,7 +31,7 @@ X #ifndef H_PROGRAM X #define H_PROGRAM X X-#include <getopt.h> X+#include "getopt.h" X X class program { X static const char warranty_t []; END-of-picprog/patches/patch-ae echo x - picprog/patches/patch-ac sed 's/^X//' >picprog/patches/patch-ac << 'END-of-picprog/patches/patch-ac' X--- main.cc.orig Sun Nov 29 16:02:59 1998 X+++ main.cc Sun Nov 29 16:04:10 1998 X@@ -31,11 +31,10 @@ X #include <iostream.h> X #include <sysexits.h> X #include <unistd.h> X-#include <getopt.h> X X #include "hexfile.h" X #include "program.h" X- X+#include "getopt.h" X X program prog; X END-of-picprog/patches/patch-ac echo x - picprog/patches/patch-ad sed 's/^X//' >picprog/patches/patch-ad << 'END-of-picprog/patches/patch-ad' X--- picprog.1.orig Sun Nov 29 16:03:13 1998 X+++ picprog.1 Sun Nov 29 16:04:06 1998 X@@ -31,9 +31,9 @@ X .B \-\-burn X .B \-q \-h \-? X .SH DESCRIPTION X-See <URL:http://www.iki.fi/hyvatti/pic/picprog.html>. X+See <URL:http://www.iki.fi/hyvatti/pic/picprog.html>, or /usr/local/share/doc/picprog/picprog.html. X .SH OPTIONS X-See <URL:http://www.iki.fi/hyvatti/pic/picprog.html>. X+See <URL:http://www.iki.fi/hyvatti/pic/picprog.html>, or /usr/local/share/doc/picprog/picprog.html. X .SH AUTHOR X Jaakko Hyvätti X .LP END-of-picprog/patches/patch-ad echo x - picprog/patches/patch-ab sed 's/^X//' >picprog/patches/patch-ab << 'END-of-picprog/patches/patch-ab' X--- Makefile.orig Mon Jun 2 13:37:54 1997 X+++ Makefile Wed Dec 2 22:14:54 1998 X@@ -32,7 +32,10 @@ X CXXFLAGS=-O2 -Wall -Wmissing-prototypes X LDFLAGS= X X-OBJS=main.o picport.o hexfile.o program.o stringc.o X+CC=gcc X+CFLAGS=-O2 -Wall X+ X+OBJS=main.o picport.o hexfile.o program.o stringc.o getopt.o getopt1.o X PROG=picprog X X all: $(PROG) X@@ -53,12 +56,5 @@ X $(PROG)-$(VERSION)/*.{html,gif,diff,1,h,cc} X X install: all X- install -c -o 0 -g 0 -m 755 -s $(PROG) /usr/local/bin/ X- install -c -o 0 -g 0 -m 644 *.1 /usr/local/man/man1/ X- X-# X-# include a dependency file if one exists X-# X-ifeq (.depend,$(wildcard .depend)) X-include .depend X-endif X+ install -c -o 0 -g 0 -m 755 -s $(PROG) /usr/local/bin X+ install -c -o 0 -g 0 -m 444 *.1 /usr/local/man/man1 END-of-picprog/patches/patch-ab echo x - picprog/patches/getopt1.c sed 's/^X//' >picprog/patches/getopt1.c << 'END-of-picprog/patches/getopt1.c' X/* getopt_long and getopt_long_only entry points for GNU getopt. X Copyright (C) 1987, 88, 89, 90, 91, 92, 1993 X Free Software Foundation, Inc. X X This program is free software; you can redistribute it and/or X modify it under the terms of the GNU Library General Public License X as published by the Free Software Foundation; either version 2, or X (at your option) any later version. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU Library General Public License for more details. X X You should have received a copy of the GNU Library General Public License X along with this program; if not, write to the Free Software X Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ X X#ifdef HAVE_CONFIG_H X#if defined (emacs) || defined (CONFIG_BROKETS) X/* We use <config.h> instead of "config.h" so that a compilation X using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h X (which it would do because it found this file in $srcdir). */ X#include <config.h> X#else X#include "config.h" X#endif X#endif X X#include "getopt.h" X X#ifndef __STDC__ X/* This is a separate conditional since some stdc systems X reject `defined (const)'. */ X#ifndef const X#define const X#endif X#endif X X#include <stdio.h> X X/* Comment out all this code if we are using the GNU C Library, and are not X actually compiling the library itself. This code is part of the GNU C X Library, but also included in many other GNU distributions. Compiling X and linking in this code is a waste when using the GNU C library X (especially if it is a shared library). Rather than having every GNU X program understand `configure --with-gnu-libc' and omit the object files, X it is simpler to just do this in the source for each such file. */ X X#if defined (_LIBC) || !defined (__GNU_LIBRARY__) X X X/* This needs to come after some library #include X to get __GNU_LIBRARY__ defined. */ X#ifdef __GNU_LIBRARY__ X#include <stdlib.h> X#else Xchar *getenv (); X#endif X X#ifndef NULL X#define NULL 0 X#endif X Xint Xgetopt_long (argc, argv, options, long_options, opt_index) X int argc; X char *const *argv; X const char *options; X const struct option *long_options; X int *opt_index; X{ X return _getopt_internal (argc, argv, options, long_options, opt_index, 0); X} X X/* Like getopt_long, but '-' as well as '--' can indicate a long option. X If an option that starts with '-' (not '--') doesn't match a long option, X but does match a short option, it is parsed as a short option X instead. */ X Xint Xgetopt_long_only (argc, argv, options, long_options, opt_index) X int argc; X char *const *argv; X const char *options; X const struct option *long_options; X int *opt_index; X{ X return _getopt_internal (argc, argv, options, long_options, opt_index, 1); X} X X X#endif /* _LIBC or not __GNU_LIBRARY__. */ X X#ifdef TEST X X#include <stdio.h> X Xint Xmain (argc, argv) X int argc; X char **argv; X{ X int c; X int digit_optind = 0; X X while (1) X { X int this_option_optind = optind ? optind : 1; X int option_index = 0; X static struct option long_options[] = X { X {"add", 1, 0, 0}, X {"append", 0, 0, 0}, X {"delete", 1, 0, 0}, X {"verbose", 0, 0, 0}, X {"create", 0, 0, 0}, X {"file", 1, 0, 0}, X {0, 0, 0, 0} X }; X X c = getopt_long (argc, argv, "abc:d:0123456789", X long_options, &option_index); X if (c == EOF) X break; X X switch (c) X { X case 0: X printf ("option %s", long_options[option_index].name); X if (optarg) X printf (" with arg %s", optarg); X printf ("\n"); X break; X X case '0': X case '1': X case '2': X case '3': X case '4': X case '5': X case '6': X case '7': X case '8': X case '9': X if (digit_optind != 0 && digit_optind != this_option_optind) X printf ("digits occur in two different argv-elements.\n"); X digit_optind = this_option_optind; X printf ("option %c\n", c); X break; X X case 'a': X printf ("option a\n"); X break; X X case 'b': X printf ("option b\n"); X break; X X case 'c': X printf ("option c with value `%s'\n", optarg); X break; X X case 'd': X printf ("option d with value `%s'\n", optarg); X break; X X case '?': X break; X X default: X printf ("?? getopt returned character code 0%o ??\n", c); X } X } X X if (optind < argc) X { X printf ("non-option ARGV-elements: "); X while (optind < argc) X printf ("%s ", argv[optind++]); X printf ("\n"); X } X X exit (0); X} X X#endif /* TEST */ END-of-picprog/patches/getopt1.c echo x - picprog/patches/getopt.h sed 's/^X//' >picprog/patches/getopt.h << 'END-of-picprog/patches/getopt.h' X/* Declarations for getopt. X Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. X X This program is free software; you can redistribute it and/or modify it X under the terms of the GNU General Public License as published by the X Free Software Foundation; either version 2, or (at your option) any X later version. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with this program; if not, write to the Free Software X Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ X X#ifndef _GETOPT_H X#define _GETOPT_H 1 X X#ifdef __cplusplus Xextern "C" { X#endif X X/* For communication from `getopt' to the caller. X When `getopt' finds an option that takes an argument, X the argument value is returned here. X Also, when `ordering' is RETURN_IN_ORDER, X each non-option ARGV-element is returned here. */ X Xextern char *optarg; X X/* Index in ARGV of the next element to be scanned. X This is used for communication to and from the caller X and for communication between successive calls to `getopt'. X X On entry to `getopt', zero means this is the first call; initialize. X X When `getopt' returns EOF, this is the index of the first of the X non-option elements that the caller should itself scan. X X Otherwise, `optind' communicates from one call to the next X how much of ARGV has been scanned so far. */ X Xextern int optind; X X/* Callers store zero here to inhibit the error message `getopt' prints X for unrecognized options. */ X Xextern int opterr; X X/* Set to an option character which was unrecognized. */ X Xextern int optopt; X X/* Describe the long-named options requested by the application. X The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector X of `struct option' terminated by an element containing a name which is X zero. X X The field `has_arg' is: X no_argument (or 0) if the option does not take an argument, X required_argument (or 1) if the option requires an argument, X optional_argument (or 2) if the option takes an optional argument. X X If the field `flag' is not NULL, it points to a variable that is set X to the value given in the field `val' when the option is found, but X left unchanged if the option is not found. X X To have a long-named option do something other than set an `int' to X a compiled-in constant, such as set a value from `optarg', set the X option's `flag' field to zero and its `val' field to a nonzero X value (the equivalent single-letter option character, if there is X one). For long options that have a zero `flag' field, `getopt' X returns the contents of the `val' field. */ X Xstruct option X{ X#if __STDC__ X const char *name; X#else X char *name; X#endif X /* has_arg can't be an enum because some compilers complain about X type mismatches in all the code that assumes it is an int. */ X int has_arg; X int *flag; X int val; X}; X X/* Names for the values of the `has_arg' field of `struct option'. */ X X#define no_argument 0 X#define required_argument 1 X#define optional_argument 2 X X#if __STDC__ X#if defined(__GNU_LIBRARY__) X/* Many other libraries have conflicting prototypes for getopt, with X differences in the consts, in stdlib.h. To avoid compilation X errors, only prototype getopt for the GNU C library. */ Xextern int getopt (int argc, char *const *argv, const char *shortopts); X#else /* not __GNU_LIBRARY__ */ Xextern int getopt (); X#endif /* not __GNU_LIBRARY__ */ Xextern int getopt_long (int argc, char *const *argv, const char *shortopts, X const struct option *longopts, int *longind); Xextern int getopt_long_only (int argc, char *const *argv, X const char *shortopts, X const struct option *longopts, int *longind); X X/* Internal only. Users should not call this directly. */ Xextern int _getopt_internal (int argc, char *const *argv, X const char *shortopts, X const struct option *longopts, int *longind, X int long_only); X#else /* not __STDC__ */ Xextern int getopt (); Xextern int getopt_long (); Xextern int getopt_long_only (); X Xextern int _getopt_internal (); X#endif /* not __STDC__ */ X X#ifdef __cplusplus X} X#endif X X#endif /* _GETOPT_H */ END-of-picprog/patches/getopt.h echo x - picprog/patches/getopt.c sed 's/^X//' >picprog/patches/getopt.c << 'END-of-picprog/patches/getopt.c' X/* Getopt for GNU. X NOTE: getopt is now part of the C library, so if you don't know what X "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu X before changing it! X X Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94 X Free Software Foundation, Inc. X X This program is free software; you can redistribute it and/or X modify it under the terms of the GNU Library General Public License X as published by the Free Software Foundation; either version 2, or X (at your option) any later version. X X This program is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU Library General Public License for more details. X X You should have received a copy of the GNU Library General Public License X along with this program; if not, write to the Free Software X Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ X X/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. X Ditto for AIX 3.2 and <stdlib.h>. */ X#ifndef _NO_PROTO X#define _NO_PROTO X#endif X X#ifdef HAVE_CONFIG_H X#if defined (emacs) || defined (CONFIG_BROKETS) X/* We use <config.h> instead of "config.h" so that a compilation X using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h X (which it would do because it found this file in $srcdir). */ X#include <config.h> X#else X#include "config.h" X#endif X#endif X X#ifndef __STDC__ X/* This is a separate conditional since some stdc systems X reject `defined (const)'. */ X#ifndef const X#define const X#endif X#endif X X#include <strings.h> X#include <stdio.h> X X/* Comment out all this code if we are using the GNU C Library, and are not X actually compiling the library itself. This code is part of the GNU C X Library, but also included in many other GNU distributions. Compiling X and linking in this code is a waste when using the GNU C library X (especially if it is a shared library). Rather than having every GNU X program understand `configure --with-gnu-libc' and omit the object files, X it is simpler to just do this in the source for each such file. */ X X#if defined (_LIBC) || !defined (__GNU_LIBRARY__) X X X/* This needs to come after some library #include X to get __GNU_LIBRARY__ defined. */ X#ifdef __GNU_LIBRARY__ X/* Don't include stdlib.h for non-GNU C libraries because some of them X contain conflicting prototypes for getopt. */ X#include <stdlib.h> X#endif /* GNU C library. */ X X/* This version of `getopt' appears to the caller like standard Unix `getopt' X but it behaves differently for the user, since it allows the user X to intersperse the options with the other arguments. X X As `getopt' works, it permutes the elements of ARGV so that, X when it is done, all the options precede everything else. Thus X all application programs are extended to handle flexible argument order. X X Setting the environment variable POSIXLY_CORRECT disables permutation. X Then the behavior is completely standard. X X GNU application programs can use a third alternative mode in which X they can distinguish the relative order of options and other arguments. */ X X#include "getopt.h" X X/* For communication from `getopt' to the caller. X When `getopt' finds an option that takes an argument, X the argument value is returned here. X Also, when `ordering' is RETURN_IN_ORDER, X each non-option ARGV-element is returned here. */ X Xchar *optarg = NULL; X X/* Index in ARGV of the next element to be scanned. X This is used for communication to and from the caller X and for communication between successive calls to `getopt'. X X On entry to `getopt', zero means this is the first call; initialize. X X When `getopt' returns EOF, this is the index of the first of the X non-option elements that the caller should itself scan. X X Otherwise, `optind' communicates from one call to the next X how much of ARGV has been scanned so far. */ X X/* XXX 1003.2 says this must be 1 before any call. */ Xint optind = 0; X X/* The next char to be scanned in the option-element X in which the last option character we returned was found. X This allows us to pick up the scan where we left off. X X If this is zero, or a null string, it means resume the scan X by advancing to the next ARGV-element. */ X Xstatic char *nextchar; X X/* Callers store zero here to inhibit the error message X for unrecognized options. */ X Xint opterr = 1; X X/* Set to an option character which was unrecognized. X This must be initialized on some systems to avoid linking in the X system's own getopt implementation. */ X Xint optopt = '?'; X X/* Describe how to deal with options that follow non-option ARGV-elements. X X If the caller did not specify anything, X the default is REQUIRE_ORDER if the environment variable X POSIXLY_CORRECT is defined, PERMUTE otherwise. X X REQUIRE_ORDER means don't recognize them as options; X stop option processing when the first non-option is seen. X This is what Unix does. X This mode of operation is selected by either setting the environment X variable POSIXLY_CORRECT, or using `+' as the first character X of the list of option characters. X X PERMUTE is the default. We permute the contents of ARGV as we scan, X so that eventually all the non-options are at the end. This allows options X to be given in any order, even with programs that were not written to X expect this. X X RETURN_IN_ORDER is an option available to programs that were written X to expect options and other ARGV-elements in any order and that care about X the ordering of the two. We describe each non-option ARGV-element X as if it were the argument of an option with character code 1. X Using `-' as the first character of the list of option characters X selects this mode of operation. X X The special argument `--' forces an end of option-scanning regardless X of the value of `ordering'. In the case of RETURN_IN_ORDER, only X `--' can cause `getopt' to return EOF with `optind' != ARGC. */ X Xstatic enum X{ X REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER X} ordering; X X#ifdef __GNU_LIBRARY__ X/* We want to avoid inclusion of string.h with non-GNU libraries X because there are many ways it can cause trouble. X On some systems, it contains special magic macros that don't work X in GCC. */ X#include <string.h> X#define my_index strchr X#else X X/* Avoid depending on library functions or files X whose names are inconsistent. */ X Xchar *getenv (); X Xstatic char * Xmy_index (str, chr) X const char *str; X int chr; X{ X while (*str) X { X if (*str == chr) X return (char *) str; X str++; X } X return 0; X} X X/* If using GCC, we can safely declare strlen this way. X If not using GCC, it is ok not to declare it. */ X#ifdef __GNUC__ X/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. X That was relevant to code that was here before. */ X#ifndef __STDC__ X/* gcc with -traditional declares the built-in strlen to return int, X and has done so at least since version 2.4.5. -- rms. */ Xextern int strlen (const char *); X#endif /* not __STDC__ */ X#endif /* __GNUC__ */ X X#endif /* not __GNU_LIBRARY__ */ X X/* Handle permutation of arguments. */ X X/* Describe the part of ARGV that contains non-options that have X been skipped. `first_nonopt' is the index in ARGV of the first of them; X `last_nonopt' is the index after the last of them. */ X Xstatic int first_nonopt; Xstatic int last_nonopt; X X/* Exchange two adjacent subsequences of ARGV. X One subsequence is elements [first_nonopt,last_nonopt) X which contains all the non-options that have been skipped so far. X The other is elements [last_nonopt,optind), which contains all X the options processed since those non-options were skipped. X X `first_nonopt' and `last_nonopt' are relocated so that they describe X the new indices of the non-options in ARGV after they are moved. */ X Xstatic void Xexchange (argv) X char **argv; X{ X int bottom = first_nonopt; X int middle = last_nonopt; X int top = optind; X char *tem; X X /* Exchange the shorter segment with the far end of the longer segment. X That puts the shorter segment into the right place. X It leaves the longer segment in the right place overall, X but it consists of two parts that need to be swapped next. */ X X while (top > middle && middle > bottom) X { X if (top - middle > middle - bottom) X { X /* Bottom segment is the short one. */ X int len = middle - bottom; X register int i; X X /* Swap it with the top part of the top segment. */ X for (i = 0; i < len; i++) X { X tem = argv[bottom + i]; X argv[bottom + i] = argv[top - (middle - bottom) + i]; X argv[top - (middle - bottom) + i] = tem; X } X /* Exclude the moved bottom segment from further swapping. */ X top -= len; X } X else X { X /* Top segment is the short one. */ X int len = top - middle; X register int i; X X /* Swap it with the bottom part of the bottom segment. */ X for (i = 0; i < len; i++) X { X tem = argv[bottom + i]; X argv[bottom + i] = argv[middle + i]; X argv[middle + i] = tem; X } X /* Exclude the moved top segment from further swapping. */ X bottom += len; X } X } X X /* Update records for the slots the non-options now occupy. */ X X first_nonopt += (optind - last_nonopt); X last_nonopt = optind; X} X X/* Initialize the internal data when the first call is made. */ X Xstatic const char * X_getopt_initialize (optstring) X const char *optstring; X{ X /* Start processing options with ARGV-element 1 (since ARGV-element 0 X is the program name); the sequence of previously skipped X non-option ARGV-elements is empty. */ X X first_nonopt = last_nonopt = optind = 1; X X nextchar = NULL; X X /* Determine how to handle the ordering of options and nonoptions. */ X X if (optstring[0] == '-') X { X ordering = RETURN_IN_ORDER; X ++optstring; X } X else if (optstring[0] == '+') X { X ordering = REQUIRE_ORDER; X ++optstring; X } X else if (getenv ("POSIXLY_CORRECT") != NULL) X ordering = REQUIRE_ORDER; X else X ordering = PERMUTE; X X return optstring; X} X X/* Scan elements of ARGV (whose length is ARGC) for option characters X given in OPTSTRING. X X If an element of ARGV starts with '-', and is not exactly "-" or "--", X then it is an option element. The characters of this element X (aside from the initial '-') are option characters. If `getopt' X is called repeatedly, it returns successively each of the option characters X from each of the option elements. X X If `getopt' finds another option character, it returns that character, X updating `optind' and `nextchar' so that the next call to `getopt' can X resume the scan with the following option character or ARGV-element. X X If there are no more option characters, `getopt' returns `EOF'. X Then `optind' is the index in ARGV of the first ARGV-element X that is not an option. (The ARGV-elements have been permuted X so that those that are not options now come last.) X X OPTSTRING is a string containing the legitimate option characters. X If an option character is seen that is not listed in OPTSTRING, X return '?' after printing an error message. If you set `opterr' to X zero, the error message is suppressed but we still return '?'. X X If a char in OPTSTRING is followed by a colon, that means it wants an arg, X so the following text in the same ARGV-element, or the text of the following X ARGV-element, is returned in `optarg'. Two colons mean an option that X wants an optional arg; if there is text in the current ARGV-element, X it is returned in `optarg', otherwise `optarg' is set to zero. X X If OPTSTRING starts with `-' or `+', it requests different methods of X handling the non-option ARGV-elements. X See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. X X Long-named options begin with `--' instead of `-'. X Their names may be abbreviated as long as the abbreviation is unique X or is an exact match for some defined option. If they have an X argument, it follows the option name in the same ARGV-element, separated X from the option name by a `=', or else the in next ARGV-element. X When `getopt' finds a long-named option, it returns 0 if that option's X `flag' field is nonzero, the value of the option's `val' field X if the `flag' field is zero. X X The elements of ARGV aren't really const, because we permute them. X But we pretend they're const in the prototype to be compatible X with other systems. X X LONGOPTS is a vector of `struct option' terminated by an X element containing a name which is zero. X X LONGIND returns the index in LONGOPT of the long-named option found. X It is only valid when a long-named option has been found by the most X recent call. X X If LONG_ONLY is nonzero, '-' as well as '--' can introduce X long-named options. */ X X#if NLS X#include "nl_types.h" X#endif X Xint X_getopt_internal (argc, argv, optstring, longopts, longind, long_only) X int argc; X char *const *argv; X const char *optstring; X const struct option *longopts; X int *longind; X int long_only; X{ X optarg = NULL; X X#if NLS X libc_nls_init(); X#endif X X if (optind == 0) X optstring = _getopt_initialize (optstring); X X if (nextchar == NULL || *nextchar == '\0') X { X /* Advance to the next ARGV-element. */ X X if (ordering == PERMUTE) X { X /* If we have just processed some options following some non-options, X exchange them so that the options come first. */ X X if (first_nonopt != last_nonopt && last_nonopt != optind) X exchange ((char **) argv); X else if (last_nonopt != optind) X first_nonopt = optind; X X /* Skip any additional non-options X and extend the range of non-options previously skipped. */ X X while (optind < argc X && (argv[optind][0] != '-' || argv[optind][1] == '\0')) X optind++; X last_nonopt = optind; X } X X /* The special ARGV-element `--' means premature end of options. X Skip it like a null option, X then exchange with previous non-options as if it were an option, X then skip everything else like a non-option. */ X X if (optind != argc && !strcmp (argv[optind], "--")) X { X optind++; X X if (first_nonopt != last_nonopt && last_nonopt != optind) X exchange ((char **) argv); X else if (first_nonopt == last_nonopt) X first_nonopt = optind; X last_nonopt = argc; X X optind = argc; X } X X /* If we have done all the ARGV-elements, stop the scan X and back over any non-options that we skipped and permuted. */ X X if (optind == argc) X { X /* Set the next-arg-index to point at the non-options X that we previously skipped, so the caller will digest them. */ X if (first_nonopt != last_nonopt) X optind = first_nonopt; X return EOF; X } X X /* If we have come to a non-option and did not permute it, X either stop the scan or describe it to the caller and pass it by. */ X X if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) X { X if (ordering == REQUIRE_ORDER) X return EOF; X optarg = argv[optind++]; X return 1; X } X X /* We have found another option-ARGV-element. X Skip the initial punctuation. */ X X nextchar = (argv[optind] + 1 X + (longopts != NULL && argv[optind][1] == '-')); X } X X /* Decode the current option-ARGV-element. */ X X /* Check whether the ARGV-element is a long option. X X If long_only and the ARGV-element has the form "-f", where f is X a valid short option, don't consider it an abbreviated form of X a long option that starts with f. Otherwise there would be no X way to give the -f short option. X X On the other hand, if there's a long option "fubar" and X the ARGV-element is "-fu", do consider that an abbreviation of X the long option, just like "--fu", and not "-f" with arg "u". X X This distinction seems to be the most useful approach. */ X X if (longopts != NULL X && (argv[optind][1] == '-' X || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) X { X char *nameend; X const struct option *p; X const struct option *pfound = NULL; X int exact = 0; X int ambig = 0; X int indfound = -1; X int option_index; X X for (nameend = nextchar; *nameend && *nameend != '='; nameend++) X /* Do nothing. */ ; X X /* Test all long options for either exact match X or abbreviated matches. */ X for (p = longopts, option_index = 0; p->name; p++, option_index++) X if (!strncmp (p->name, nextchar, nameend - nextchar)) X { X if (nameend - nextchar == strlen (p->name)) X { X /* Exact match found. */ X pfound = p; X indfound = option_index; X exact = 1; X break; X } X else if (pfound == NULL) X { X /* First nonexact match found. */ X pfound = p; X indfound = option_index; X } X else X /* Second or later nonexact match found. */ X ambig = 1; X } X X if (ambig && !exact) X { X if (opterr) X#if NLS X fprintf (stderr, X catgets(_libc_cat, GetoptSet, GetoptAmbiguous, X "%s: option `%s' is ambiguous\n"), X argv[0], argv[optind]); X#else X fprintf (stderr, "%s: option `%s' is ambiguous\n", X argv[0], argv[optind]); X#endif X nextchar += strlen (nextchar); X optind++; X return '?'; X } X X if (pfound != NULL) X { X option_index = indfound; X optind++; X if (*nameend) X { X /* Don't test has_arg with >, because some C compilers don't X allow it to be used on enums. */ X if (pfound->has_arg) X optarg = nameend + 1; X else X { X if (opterr) X { X if (argv[optind - 1][1] == '-') X /* --option */ X#if NLS X fprintf (stderr, X catgets(_libc_cat, GetoptSet, GetoptNoArgumentsAllowed1, X "%s: option `--%s' doesn't allow an argument\n"), X argv[0], pfound->name); X#else X fprintf (stderr, X "%s: option `--%s' doesn't allow an argument\n", X argv[0], pfound->name); X#endif X else X /* +option or -option */ X#if NLS X fprintf (stderr, X catgets(_libc_cat, GetoptSet, GetoptNoArgumentsAllowed2, X "%s: option `%c%s' doesn't allow an argument\n"), X argv[0], argv[optind - 1][0], pfound->name); X#else X fprintf (stderr, X "%s: option `%c%s' doesn't allow an argument\n", X argv[0], argv[optind - 1][0], pfound->name); X#endif X } X nextchar += strlen (nextchar); X return '?'; X } X } X else if (pfound->has_arg == 1) X { X if (optind < argc) X optarg = argv[optind++]; X else X { X if (opterr) X#if NLS X fprintf (stderr, X catgets(_libc_cat, GetoptSet, GetoptRequiresArgument1, X "%s: option `%s' requires an argument\n"), X argv[0], argv[optind - 1]); X#else X fprintf (stderr, "%s: option `%s' requires an argument\n", X argv[0], argv[optind - 1]); X#endif X nextchar += strlen (nextchar); X return optstring[0] == ':' ? ':' : '?'; X } X } X nextchar += strlen (nextchar); X if (longind != NULL) X *longind = option_index; X if (pfound->flag) X { X *(pfound->flag) = pfound->val; X return 0; X } X return pfound->val; X } X X /* Can't find it as a long option. If this is not getopt_long_only, X or the option starts with '--' or is not a valid short X option, then it's an error. X Otherwise interpret it as a short option. */ X if (!long_only || argv[optind][1] == '-' X || my_index (optstring, *nextchar) == NULL) X { X if (opterr) X { X if (argv[optind][1] == '-') X /* --option */ X#if NLS X fprintf (stderr, X catgets(_libc_cat, GetoptSet, GetoptUnrecognized1, X "%s: unrecognized option `--%s'\n"), X argv[0], nextchar); X#else X fprintf (stderr, "%s: unrecognized option `--%s'\n", X argv[0], nextchar); X#endif X else X /* +option or -option */ X#if NLS X fprintf (stderr, X catgets(_libc_cat, GetoptSet, GetoptUnrecognized2, X "%s: unrecognized option `%c%s'\n"), X argv[0], argv[optind][0], nextchar); X#else X fprintf (stderr, "%s: unrecognized option `%c%s'\n", X argv[0], argv[optind][0], nextchar); X#endif X } X nextchar = (char *) ""; X optind++; X return '?'; X } X } X X /* Look at and handle the next short option-character. */ X X { X char c = *nextchar++; X char *temp = my_index (optstring, c); X X /* Increment `optind' when we start to process its last character. */ X if (*nextchar == '\0') X ++optind; X X if (temp == NULL || c == ':') X { X if (opterr) X { X /* 1003.2 specifies the format of this message. */ X#if NLS X fprintf (stderr, X catgets(_libc_cat, GetoptSet, GetoptIllegal, X "%s: illegal option -- %c\n"), X argv[0], c); X#else X fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); X#endif X } X optopt = c; X return '?'; X } X if (temp[1] == ':') X { X if (temp[2] == ':') X { X /* This is an option that accepts an argument optionally. */ X if (*nextchar != '\0') X { X optarg = nextchar; X optind++; X } X else X optarg = NULL; X nextchar = NULL; X } X else X { X /* This is an option that requires an argument. */ X if (*nextchar != '\0') X { X optarg = nextchar; X /* If we end this ARGV-element by taking the rest as an arg, X we must advance to the next element now. */ X optind++; X } X else if (optind == argc) X { X if (opterr) X { X /* 1003.2 specifies the format of this message. */ X#if NLS X fprintf (stderr, X catgets(_libc_cat, GetoptSet, X GetoptRequiresArgument2, X "%s: option requires an argument -- %c\n"), X argv[0], c); X#else X fprintf (stderr, "%s: option requires an argument -- %c\n", X argv[0], c); X#endif X } X optopt = c; X if (optstring[0] == ':') X c = ':'; X else X c = '?'; X } X else X /* We already incremented `optind' once; X increment it again when taking next ARGV-elt as argument. */ X optarg = argv[optind++]; X nextchar = NULL; X } X } X return c; X } X} X Xint Xgetopt (argc, argv, optstring) X int argc; X char *const *argv; X const char *optstring; X{ X return _getopt_internal (argc, argv, optstring, X (const struct option *) 0, X (int *) 0, X 0); X} X X#endif /* _LIBC or not __GNU_LIBRARY__. */ X X#ifdef TEST X X/* Compile with -DTEST to make an executable for use in testing X the above definition of `getopt'. */ X Xint Xmain (argc, argv) X int argc; X char **argv; X{ X int c; X int digit_optind = 0; X X while (1) X { X int this_option_optind = optind ? optind : 1; X X c = getopt (argc, argv, "abc:d:0123456789"); X if (c == EOF) X break; X X switch (c) X { X case '0': X case '1': X case '2': X case '3': X case '4': X case '5': X case '6': X case '7': X case '8': X case '9': X if (digit_optind != 0 && digit_optind != this_option_optind) X printf ("digits occur in two different argv-elements.\n"); X digit_optind = this_option_optind; X printf ("option %c\n", c); X break; X X case 'a': X printf ("option a\n"); X break; X X case 'b': X printf ("option b\n"); X break; X X case 'c': X printf ("option c with value `%s'\n", optarg); X break; X X case '?': X break; X X default: X printf ("?? getopt returned character code 0%o ??\n", c); X } X } X X if (optind < argc) X { X printf ("non-option ARGV-elements: "); X while (optind < argc) X printf ("%s ", argv[optind++]); X printf ("\n"); X } X X exit (0); X} X X#endif /* TEST */ END-of-picprog/patches/getopt.c echo x - picprog/patches/patch-aa sed 's/^X//' >picprog/patches/patch-aa << 'END-of-picprog/patches/patch-aa' X--- hexfile.h.orig Tue Aug 31 11:51:09 1999 X+++ hexfile.h Tue Aug 31 11:53:58 1999 X@@ -48,7 +48,7 @@ X #include "picport.h" X X class hexfile { X- const int size = 0x4000; X+ static const int size = 0x4000; X short pgm [size]; X X int program_location (picport& pic, int addr, bool data) const; END-of-picprog/patches/patch-aa echo c - picprog/files mkdir -p picprog/files > /dev/null 2>&1 echo x - picprog/files/md5 sed 's/^X//' >picprog/files/md5 << 'END-of-picprog/files/md5' XMD5 (picprog-1.0.tar.gz) = 8ef1c0df63170626d4d497b199c2f830 END-of-picprog/files/md5 echo x - picprog/Makefile sed 's/^X//' >picprog/Makefile << 'END-of-picprog/Makefile' X# New ports collection makefile for: picprog X# Version required: 1.0 X# Date created: 31 August 1999 X# Whom: Johan Kerckaert <kirk@bricsnet.com> X# X# $Id$ X# X XDISTNAME= picprog-1.0 XCATEGORIES= devel XMASTER_SITES= http://hyvatti.iki.fi/~jaakko/pic/ X XMAINTAINER= ports@FreeBSD.org X XMAN1= picprog.1 X Xpost-patch: X $(CP) ${PATCHDIR}/getopt* ${WRKSRC} X Xpost-install: X.if !defined(NOPORTDOCS) X ${MKDIR} ${PREFIX}/share/doc/picprog X ${INSTALL_MAN} ${WRKSRC}/picprog.html ${PREFIX}/share/doc/picprog X ${INSTALL_MAN} ${WRKSRC}/*.gif ${PREFIX}/share/doc/picprog X.endif X X.include <bsd.port.mk> END-of-picprog/Makefile exit >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909010815.KAA21934>