From: fred
Date: Mon, 27 Jul 1998 14:14:16 +0000 (+0000)
Subject: lilypond-1.0.1
X-Git-Tag: release/1.5.59~5873
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=04ca3104684f4c5d07fe5939c21b78a5055691eb;p=lilypond.git
lilypond-1.0.1
---
diff --git a/flower/getopt-long.cc b/flower/getopt-long.cc
new file mode 100644
index 0000000000..e3a3176b27
--- /dev/null
+++ b/flower/getopt-long.cc
@@ -0,0 +1,260 @@
+/*
+ process command line, GNU style.
+
+ this is (Copyleft) 1996, Han-Wen Nienhuys,
+ */
+
+#include
+#include
+#include
+#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;
+}
diff --git a/flower/include/getopt-long.hh b/flower/include/getopt-long.hh
new file mode 100644
index 0000000000..a069e28422
--- /dev/null
+++ b/flower/include/getopt-long.hh
@@ -0,0 +1,102 @@
+#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
diff --git a/stepmake/bin/add-html-footer.py b/stepmake/bin/add-html-footer.py
new file mode 100644
index 0000000000..e8a858a0c9
--- /dev/null
+++ b/stepmake/bin/add-html-footer.py
@@ -0,0 +1,134 @@
+#!@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
Please take me back to the index\n\
+of ' + package.Name + '\n'
+builtstr = '\n
\n\
+This page was built from ' + package.name + '-%s by \n\
+
%s <%s>\n\
+'
+
+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 = ''
+
+
+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', '\n'+ news + '\n\n', s)
+
+ s = check_tag ('', '', s)
+ if regex.search (banner_id, s) == -1:
+ s = regsub.sub ('', '', s)
+ s = regsub.sub ('
', banner_id + banner + '', s)
+ else:
+ s = check_tag ('', '', s, 1)
+
+ title = '