--- /dev/null
+/*
+ process command line, GNU style.
+
+ this is (Copyleft) 1996, Han-Wen Nienhuys, <hanwen@cs.uu.nl>
+ */
+
+#include <stdio.h>
+#include <iostream.h>
+#include <assert.h>
+#include "getopt-long.hh"
+#include "international.hh"
+
+long
+Getopt_long::argument_to_i()
+{
+ long l;
+ if (!optional_argument_ch_C_
+ || sscanf (optional_argument_ch_C_, "%ld", &l) != 1)
+ report (E_ILLEGALARG);
+
+ return l;
+}
+
+const Long_option_init *
+Getopt_long::parselong()
+{
+ char const *optnm = arg_value_ch_a_a_[array_index_i_] + 2 ;
+ assert (*optnm);
+
+ char const *endopt = strchr (optnm, '=');
+ int searchlen = (endopt) ? endopt - optnm : strlen (optnm);
+
+ found_option_l_=0;
+ for (int i=0; i< table_len_i_; i++)
+ {
+ char const *ln = option_a_[i].longname;
+
+ if (ln && !strncmp (ln, optnm, searchlen))
+ {
+ found_option_l_ = option_a_+i;
+ break;
+ }
+ }
+
+ if (!found_option_l_)
+ {
+ report (E_UNKNOWNOPTION);
+ return 0;
+ }
+ array_index_i_++;
+ argument_index_i_ = 0;
+
+
+ if (found_option_l_->take_arg)
+ {
+ if (endopt)
+ optional_argument_ch_C_ = endopt +1; // a '='
+ else
+ {
+ optional_argument_ch_C_ = arg_value_ch_a_a_[array_index_i_];
+ array_index_i_++;
+ }
+ if (!optional_argument_ch_C_)
+ report (E_ARGEXPECT);
+
+ }
+ else
+ {
+ optional_argument_ch_C_ = 0;
+ if (endopt)
+ report (E_NOARGEXPECT);
+ }
+
+ return found_option_l_;
+}
+
+String
+Long_option_init::str () const
+{
+ String str;
+ if (shortname)
+ str += "-" + shortname;
+ if (shortname && longname)
+ str += ", ";
+ if (longname)
+ str += String ("`--") + longname + "'";
+ return str;
+}
+
+// report an error, GNU style.
+void
+Getopt_long::report (Errorcod c)
+{
+ error_ = c;
+ if (!error_ostream_l_)
+ return;
+
+ String str = arg_value_ch_a_a_[0];
+ str += ": ";
+ switch (c)
+ {
+ case E_ARGEXPECT:
+ str += _f ("option `%s\' requires an argument",
+ found_option_l_->str ());
+ break;
+ case E_NOARGEXPECT:
+ str += _f ("option `%s\' doesn't allow an argument",
+ found_option_l_->str ());
+ break;
+ case E_UNKNOWNOPTION:
+ str += _f ("unrecognized option: `%s\'",
+ String (argument_index_i_
+ ? String ("-" + _f("%c",arg_value_ch_a_a_[array_index_i_][argument_index_i_]))
+ : String (arg_value_ch_a_a_[array_index_i_])));
+ break;
+ case E_ILLEGALARG:
+ str += _f ("invalid argument `%s\' to option `%s'",
+ optional_argument_ch_C_, found_option_l_->str ());
+ default:
+ assert (false);
+ }
+ *error_ostream_l_ << str << endl;
+ exit (2);
+}
+
+const Long_option_init *
+Getopt_long::parseshort()
+{
+ char c=arg_value_ch_a_a_[array_index_i_][argument_index_i_];
+ found_option_l_=0;
+ assert (c);
+
+ for (int i=0; i < table_len_i_; i++)
+ if (option_a_[i].shortname == c)
+ {
+ found_option_l_ = option_a_+i;
+ break;
+ }
+
+ if (!found_option_l_)
+ {
+ report (E_UNKNOWNOPTION);
+ return 0;
+ }
+
+ argument_index_i_++;
+ if (!found_option_l_->take_arg)
+ {
+ optional_argument_ch_C_ = 0;
+ return found_option_l_;
+ }
+ optional_argument_ch_C_ = arg_value_ch_a_a_[array_index_i_] + argument_index_i_;
+
+ array_index_i_ ++;
+ argument_index_i_ = 0;
+
+ if (!optional_argument_ch_C_[0])
+ {
+ optional_argument_ch_C_ = arg_value_ch_a_a_[array_index_i_];
+ array_index_i_ ++;
+ }
+ if (!optional_argument_ch_C_)
+ {
+ report (E_ARGEXPECT);
+ }
+
+ return found_option_l_;
+}
+
+const Long_option_init *
+Getopt_long::operator()()
+{
+ if (!ok())
+ return 0;
+
+ next();
+ if (!ok ())
+ return 0;
+
+ if (argument_index_i_)
+ return parseshort();
+
+ const char * argument_C = arg_value_ch_a_a_[array_index_i_];
+
+ if (argument_C[0] != '-')
+ return 0;
+
+ if (argument_C[1] == '-') {// what to do with "command -- bla"
+ if (argument_C[2])
+ return parselong();
+ else
+ return 0;
+ }
+ else
+ {
+ if (argument_C[ 1 ])
+ {
+ argument_index_i_ = 1;
+ return parseshort();
+ }
+ else
+ {
+ return 0;
+ }
+ }
+}
+
+Getopt_long::Getopt_long (int c, char **v, Long_option_init *lo)
+{
+ option_a_ = lo;
+ error_ostream_l_ = &cerr;
+ arg_value_ch_a_a_ = v;
+ argument_count_i_ = c;
+ array_index_i_ = 1;
+ argument_index_i_ = 0;
+
+ // reached end of option table?
+ table_len_i_ =0;
+ for (int i = 0; option_a_[i].longname ||option_a_[i].shortname; i++)
+ table_len_i_ ++;
+}
+
+bool
+Getopt_long::ok() const
+{
+ return array_index_i_ < argument_count_i_;
+}
+
+void
+Getopt_long::next()
+{
+ error_ = E_NOERROR;
+ while (array_index_i_ < argument_count_i_
+ && !arg_value_ch_a_a_[array_index_i_][argument_index_i_])
+ {
+ array_index_i_++;
+ argument_index_i_ = 0;
+ }
+}
+
+char const *
+Getopt_long::current_arg()
+{
+ if (array_index_i_ >= argument_count_i_)
+ return 0;
+ char const * a = arg_value_ch_a_a_[array_index_i_];
+ return a + argument_index_i_;
+}
+
+char const *
+Getopt_long::get_next_arg()
+{
+ char const * a = current_arg();
+ if (a)
+ {
+ array_index_i_ ++;
+ argument_index_i_= 0;
+ }
+ return a;
+}
--- /dev/null
+#ifndef GETOPT_LONG_HH
+#define GETOPT_LONG_HH
+
+#include "string.hh"
+
+class ostream;
+
+/**
+ a struct this for initialising the commandline options.
+ */
+struct Long_option_init {
+ bool take_arg;
+ char const * longname;
+ char shortname;
+
+ String str () const;
+};
+
+
+/** C++ for version of long_getopt. For processing GNU style command
+ line arguments. No pointer (return values, arguments) contents are
+ copied.
+
+ TODO: handle
+ command - , and command --
+
+ argument reordering
+ */
+class Getopt_long {
+
+ /// the option info.
+ const Long_option_init *option_a_;
+ int table_len_i_;
+
+ /// if doing short option, arg_value_ch_a_a_[optind][optindind] is processed next.
+ int argument_index_i_;
+
+ /// the option found
+ const Long_option_init *found_option_l_;
+
+
+public:
+ /** errorcodes: no error, argument expected, no argument expected,
+ unknown option, illegal argument (eg. int expected). */
+ enum Errorcod { E_NOERROR = 0, E_ARGEXPECT, E_NOARGEXPECT, E_UNKNOWNOPTION,
+ E_ILLEGALARG } ;
+
+ /// argument. Set to 0 if not present
+ char const * optional_argument_ch_C_;
+
+ /// current error status
+ Errorcod error_;
+
+ /// arg_value_ch_a_a_[array_index_i_] will be processed next.
+ int array_index_i_;
+
+ /// the arguments
+ char **arg_value_ch_a_a_;
+
+ /// the arg. count
+ int argument_count_i_;
+
+ ostream *error_ostream_l_;
+
+public:
+ /// get ready for processing next error.
+ void next();
+ const Long_option_init *parselong();
+ const Long_option_init *parseshort();
+ void OK() const;
+ bool ok() const;
+
+ /// report an error and abort
+ void report (Errorcod c);
+
+
+ /// return an integer (with err. detect)
+ long argument_to_i();
+
+
+ /**
+ What to do with errors.
+ report messages on #*os#, and abort.
+ if #os# is null, then do not report nor abort, just set #error#
+ */
+
+ void seterror (ostream *os);
+
+ /// construct: pass arguments and option info.
+ Getopt_long (int c, char **v, Long_option_init *lo);
+
+ /** get the next option.
+ @return pointer to next option found.
+ 0 if error occurred, or next argument is no option.
+ */
+ const Long_option_init *operator()();
+
+ char const *current_arg();
+ char const * get_next_arg();
+};
+
+#endif // GETOPT_LONG_HH
--- /dev/null
+#!@PYTHON@
+
+"""
+Print a nice footer. add the top of the NEWS file (up to the ********)
+"""
+
+program_name = 'add-html-footer'
+version = '0.1'
+
+import sys
+import os
+from string import *
+import getopt
+import __main__
+
+fullname = "unknown"
+news_file = ''
+
+index_file=''
+banner_file = ''
+news_file=''
+news =''
+(options, files) = getopt.getopt(sys.argv[1:], 'hp:', ['help', 'news=', 'index=', 'package='])
+
+def help ():
+ sys.stdout.write ("Usage: add-html-footer [OPTION]... HTML-FILE\n"
+ "Add a nice footer, add the top of the NEWS file (up to the ********)\n\n"
+ + "Options:\n"
+ + " -h, --help print this help\n"
+ + " -p, --package=DIR specify package\n"
+ )
+ sys.exit (0)
+
+for opt in options:
+ o = opt[0]
+ a = opt[1]
+ if o == '--news':
+ news_file = a
+ elif o == '--index':
+ index_file = a
+ elif o == '-h' or o == '--help':
+ help ()
+ elif o == '-p' or o == '--package':
+ topdir = a
+
+sys.path.append (topdir + '/stepmake/bin')
+from packagepython import *
+package = Package (topdir)
+packager = Packager ()
+
+def set_vars():
+ os.environ["CONFIGSUFFIX"] = 'www';
+ if os.name == 'nt':
+ import ntpwd
+ pw = ntpwd.getpwname(os.environ['USERNAME'])
+ else:
+ import pwd
+ pw = pwd.getpwuid (os.getuid());
+
+ __main__.fullname=pw[4]
+
+set_vars ()
+
+backstr = '\n<hr>Please take me <a href=%s>back to the index</a>\n\
+of ' + package.Name + '\n'
+builtstr = '\n<hr><font size=-1>\n\
+This page was built from ' + package.name + '-%s by <p>\n\
+<address><br>%s <<a href=mailto:%s>%s</a>></address>\n\
+<p></font>'
+
+def footstr(index):
+ s = backstr % index
+ s = s + builtstr % (version_tuple_to_str (package.version), fullname,
+ packager.mail, packager.mail)
+ return s
+
+banner = footstr (index_file)
+banner_id = '<! banner_id >'
+
+
+if news_file:
+ news = gulp_file (news_file)
+ i = regex.search ('^\*\*', news)
+ news = news[:i]
+
+def check_tag (tag, sub, s, bottom):
+ tag = lower (tag)
+ TAG = upper (tag)
+ s = regsub.sub (tag, TAG, s)
+ i = regex.search (TAG, s)
+ if i < 0:
+ if bottom:
+ s = s + sub + '\n'
+ else:
+ s = sub + '\n' + s
+ return s
+
+for f in files:
+ s = gulp_file (f)
+
+ if news_file:
+ s = regsub.sub ('top_of_NEWS', '<XMP>\n'+ news + '\n</XMP>\n', s)
+
+ s = check_tag ('<body', '', s, 0)
+ if regex.search ('<BODY', s) == -1:
+ s = '<BODY>\n' + s
+ s = regsub.sub ('<BODY>', '<BODY BGCOLOR=WHITE><FONT COLOR=BLACK>', s)
+ if regex.search (banner_id, s) == -1:
+ s = regsub.sub ('</body>', '</BODY>', s)
+ s = regsub.sub ('</BODY>', banner_id + banner + '</BODY>', s)
+ else:
+ s = check_tag ('</body>', '</BODY>', s, 1)
+
+ title = '<HEAD><TITLE>' \
+ + package.Name + ' -- ' + os.path.basename (os.path.splitext(f)[0]) \
+ + '</TITLE></HEAD>'
+ s = check_tag ('<title>', title, s, 0)
+
+ s = check_tag ('<html>', '<HTML>', s, 0)
+ s = check_tag ('</html>', '</HTML>', s, 1)
+
+ #urg
+ if regex.search ('@COUNTER_REF@', s) != -1:
+ counter = ''
+ try:
+ counter = os.environ[package.NAME + '_COUNTERPATH']
+ counter = '<hr><img src="' + counter + '">\n'
+ except:
+ pass
+ s = regsub.gsub ('@COUNTER_REF@', counter, s)
+
+ dump_file (f, s)
+
+