From 406bea6099ea08fdd24990d98cb6563c436f38d0 Mon Sep 17 00:00:00 2001 From: "HIGUCHI Daisuke (VDR dai)" Date: Wed, 13 Sep 2023 23:02:28 +0900 Subject: [PATCH] initial import --- AUTHORS | 0 COPYING | 481 +++++++++++++++++++++++++++++++++++++++ ChangeLog | 1 + LICENSE | 12 + Makefile.am | 1 + NEWS | 0 README | 1 + configure.in | 79 +++++++ doc/HISTORY | 68 ++++++ doc/INSTALL.en | 42 ++++ doc/INSTALL.ja | 40 ++++ doc/README.en | 134 +++++++++++ doc/README.ja | 144 ++++++++++++ doc/longbeep-linux.patch | 11 + man/Makefile.am | 1 + man/en/Makefile.am | 1 + man/en/beep2.1 | 86 +++++++ man/ja/Makefile.am | 2 + man/ja/beep2.1 | 91 ++++++++ sample/abc-score.bps | 122 ++++++++++ sample/ring.bpf | 18 ++ sample/ring.bps | 18 ++ src/Makefile.am | 6 + src/beep.c | 69 ++++++ src/beep.h | 45 ++++ src/log.c | 67 ++++++ src/main.c | 154 +++++++++++++ src/parse_f.c | 88 +++++++ src/parse_s.c | 155 +++++++++++++ src/s2f.c | 64 ++++++ src/usage.c | 25 ++ src/version.c | 42 ++++ 32 files changed, 2068 insertions(+) create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 ChangeLog create mode 100644 LICENSE create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100644 configure.in create mode 100644 doc/HISTORY create mode 100644 doc/INSTALL.en create mode 100644 doc/INSTALL.ja create mode 100644 doc/README.en create mode 100644 doc/README.ja create mode 100644 doc/longbeep-linux.patch create mode 100644 man/Makefile.am create mode 100644 man/en/Makefile.am create mode 100644 man/en/beep2.1 create mode 100644 man/ja/Makefile.am create mode 100644 man/ja/beep2.1 create mode 100755 sample/abc-score.bps create mode 100755 sample/ring.bpf create mode 100755 sample/ring.bps create mode 100644 src/Makefile.am create mode 100644 src/beep.c create mode 100644 src/beep.h create mode 100644 src/log.c create mode 100644 src/main.c create mode 100644 src/parse_f.c create mode 100644 src/parse_s.c create mode 100644 src/s2f.c create mode 100644 src/usage.c create mode 100644 src/version.c diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..eb685a5 --- /dev/null +++ b/COPYING @@ -0,0 +1,481 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..92d5cbe --- /dev/null +++ b/ChangeLog @@ -0,0 +1 @@ +see doc/HISTORY diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..334a1ae --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +beep2 license description. +Copyright (C) 2002 YAMAGUCHI Shingo + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..7c1d8f4 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS=src man diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..bcbcc3f --- /dev/null +++ b/README @@ -0,0 +1 @@ +see doc/ diff --git a/configure.in b/configure.in new file mode 100644 index 0000000..ff51896 --- /dev/null +++ b/configure.in @@ -0,0 +1,79 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([beep2], 1.3, [shingo@kip.iis.toyama-u.ac.jp]) + +# OSTYPE +AC_CANONICAL_SYSTEM + +# automake +AM_INIT_AUTOMAKE($PACKAGE_NAME, $PACKAGE_VERSION, no-define) + +AC_CONFIG_SRCDIR([src/beep.c]) +AC_CONFIG_HEADER([config.h]) + +# Checks for programs. +AC_PROG_CXX +AC_PROG_CC +AC_PROG_INSTALL + +# Checks for libraries. + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([stdlib.h string.h syslog.h unistd.h]) +# +#AC_CHECK_HEADERS([stdio.h stdlib.h unistd.h]) +#AC_CHECK_HEADERS([stdio.h stdlib.h unistd.h pwd.h sys/types.h syslog.h]) +#AC_CHECK_HEADERS([stdio.h stdlib.h unistd.h ctype.h]) +#AC_CHECK_HEADERS([stdio.h ctype.h]) +#AC_CHECK_HEADERS([stdio.h ctype.h]) +#AC_CHECK_HEADERS([string.h]) +#AC_CHECK_HEADERS([stdio.h]) +#AC_CHECK_HEADERS([stdio.h]) +AC_CHECK_HEADERS([stdio.h pwd.h sys/types.h syslog.h ctype.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_UID_T + +# Checks for library functions. +AC_FUNC_MALLOC + +# output device +AC_ARG_WITH(output-device, + [[ --with-output-device=/foo output device /foo [/dev/console]]]) + +if test "x$with_output_device" = "x" ; then + OUTPUT_DEVICE=/dev/console +else + OUTPUT_DEVICE="$with_output_device" +fi +AC_SUBST(OUTPUT_DEVICE) +AC_DEFINE_UNQUOTED(OUTPUT_DEVICE, "$OUTPUT_DEVICE",[Output device]) + +# syslog +AC_MSG_CHECKING([whether to build support for the system logging]) +AC_ARG_ENABLE([syslog], + [ --disable-syslog disable system logging], + [SYSTEM_LOGGING=no], [SYSTEM_LOGGING=yes]) +AC_MSG_RESULT([$SYSTEM_LOGGING]) +if test "x$SYSTEM_LOGGING" = "xyes"; then + SYSTEM_LOGGING="-DSYSTEM_LOGGING" +else + SYSTEM_LOGGING= +fi +AC_SUBST([SYSTEM_LOGGING]) + +# FreeBSD +case $target_os in + *bsd*) OSTYPE_BSD="-DOSTYPE_BSD" ;; +esac +AC_SUBST([OSTYPE_BSD]) + +AC_CONFIG_FILES([Makefile + src/Makefile + man/Makefile + man/en/Makefile + man/ja/Makefile]) +AC_OUTPUT diff --git a/doc/HISTORY b/doc/HISTORY new file mode 100644 index 0000000..987854a --- /dev/null +++ b/doc/HISTORY @@ -0,0 +1,68 @@ +beep2 version +Original Copyright (C) 1997 Josef Pavlik +Copyright (C) 2002 YAMAGUCHI Shingo + +2004/09/25 +version 1.3 - dai@kip + * autoconficate + * expansion OUTPUT_DEVICE + +2002/01/10 +version 1.2a + + * security hole (local users read all files when beep2 is installed on + setuid-root) fixed. + +2000/10/17 +version 1.2 + + * add logging function(use syslog). + * add information of included function to "-v" option. + * fix usage-output missmatch. + * fix argv[i] debug message ("(null)" included bug). + + +2000/10/02 +version 1.1 + + * add "tempo control" option "-t". + * add "show version" option "-v". + * fixing score => frequency table (12-average). + + +2000/09/25 +version 1.0a + + * include the patch which releases Linux kernel limitation. + * change manual and documentation. + + +2000/09/22 +beep2 version 1.0 (by YAMAGUCHI Shingo) + + Initial public release. + + append + + * debug option. + * stdin frequency/score input. + * score input mode. + * FreeBSD support. + * manual page. + * documentation (include Japanese). + + delete + + * commandline frequency input. + * commandline selection of output device. + * direct I/O access source. + + +1997/10/04 +console beep version 0.1 (by Josef Pavlik) + + * frequency input mode. + * commandline frequency input. + * output device selectable. + * Linux support. + * documentation. diff --git a/doc/INSTALL.en b/doc/INSTALL.en new file mode 100644 index 0000000..8abe28a --- /dev/null +++ b/doc/INSTALL.en @@ -0,0 +1,42 @@ +beep2 version 1.2a install instruction. +Copyright (C) 2002 YAMAGUCHI Shingo + +Quick install + + 1. Edit "Makefile" and set install path (binary and manual). If you + do not use Japanese manual, Please comment out these lines. + + install.man: + gzip -c9 man/en/beep2.1 > man/en/beep2.1.gz + install -m 0644 man/en/beep2.1.gz $(MANDIR) + // gzip -c9 man/ja/beep2.1 > man/ja/beep2.1.gz <= comment out + // install -m 0644 man/ja/beep2.1.gz $(JMANDIR) <= comment out + + 2. Edit "config.h" and set output device. + + If you need not to use logging function, disable "SYSTEM_LOGGING" + option. The default is enabled. + + If you use FreeBSD or any other BSD-like OS, enable "OSTYPE_BSD" + option. The default is impremented for Linux. + + 3. Run "make". + + 4. Run "make install" as root. + + 5. (Optional) Config syslog. + + +Caution + + This program runs on below platforms: + + Linux 2.2 (ix86, glibc 2.1) + Linux 2.2 (ix86, libc 5.4.46) + Linux 2.2 (PowerPC, linuxPPC, glibc 2.0.7) + FreeBSD 4.0 release (ix86) + FreeBSD 4.1 release (ix86) + + If you run it any other platform, please tell author. + + It does not run on "HARDWARE LIMITED" beep systems like Sun WS. diff --git a/doc/INSTALL.ja b/doc/INSTALL.ja new file mode 100644 index 0000000..3952582 --- /dev/null +++ b/doc/INSTALL.ja @@ -0,0 +1,40 @@ +beep2 version 1.2a $B%$%s%9%H!<%k2r@b(B +Copyright (C) 2002 YAMAGUCHI Shingo + +Quick install + + 1. Makefile $B$rJT=8$7$Fo$O%G%U%)%k%H(B + $B$N$^$^$G9=$$$^$;$s!#(B + + $B%G%U%)%k%H$G$O%m%05!G=$,M-8z$K$J$C$F$$$^$9$,!"$b$7L58z$K$7$?$$>l9g$O(B + SYSTEM_LOGGING $B$rL58z$K$7$F$/$@$5$$!#(B + + $B$b$7(B FreeBSD $B$J$I$N(B BSD $B7O(B OS $B$r$*;H$$$J$i(B OSTYPE_BSD $B%*%W%7%g%s$r(B + $BM-8z$K$7$F$/$@$5$$!#%G%U%)%k%H$G$O(B Linux $BMQ$N +Copyright (C) 2002 YAMAGUCHI Shingo + +1. Usage + + beep2 [-dfs] [-t tempo] [file] + beep2 -v + +'-d' option is "debug mode". +'-f' option is "frequency input mode". This is the same as console +beep V0.1. +'-s' option is "score mode". +'-t' option is "tempo change". tempo change into "tempo" %. +'-v' option is "show version and included function". + + +2. Frequency input mode +If frequency is 0, then delay(rest). +Frequency is in Hz, length is in milliseconds. + +2.1 Input format +Please see sample file "ring.bpf" to more detail. + +freq duration +freq duration +freq duration # comment +# comment +... + +2.2 Execution example + +(1) sound 1 kHz for 0.5 sec. + + % beep2[Enter] + 1000 500[Enter] + [Ctrl+d] + +(2) ring the file "ring.bpf" + + % beep2 ./ring.bpf[Enter] + +(3) 750ms delay + + % beep2[Enter] + 0 750[Enter] + [Ctrl+d] + +If first line of file is + + #!/usr/bin/beep2 + +and file has attribute x, you may run it immediately. + + +3. Score input mode +If the score field is "-", then delay(rest). +The score input is in below: + + C4 - base score + C5# - "C5" + sharp + --- - rest + +You can set octave from 1 to 9, and set score from C1 to B9. + +3.1 Input format +Please see sample file "ring.bps" to more detail. + +score length +score length +score length # comment +# comment +... + +3.2 Execution example +(1) sound C5 for 0.5 sec. + + % beep2 -s[Enter] + C5 500[Enter] + [Ctrl+d] + +(2) ring the file "ring.bps" + + % beep2 -s ./ring.bps[Enter] + +(3) 750ms delay + + % beep2 -s[Enter] + --- 750[Enter] + [Ctrl+d] + +If first line of file is + + #!/usr/bin/beep2 -s + +and file has attribute x, you may run it immediately. + + +4. About logging function +beep2 is added logging function since version 1.2. You can use this +function if you enable it when you compile this program. + +The log is sent to syslog at user.info priority. Generally, it is +written to /var/log/messages. It includes the information of executed +real user name and executed command string. + +If you want to change log file, you need to edit syslog.conf (generally +placed at /etc) and configure. The detail is in syslog documents. + + +5. About "longbeep-linux.patch" +Because of the Linux console driver limitation, beep2 can not ring +over 2000 ms. This patch releases this limitation and expands length +to 9999 ms. + +If you want to use this patch, go to drivers/char on the Linux kernel +directory and run patch command. That is: + + # cd /usr/src/linux/drivers/char + # patch < /foo/bar/longbeep-linux.patch + +This patch is NO WARRANTY and is used at your own risk. +If you use non-Linux OS, you need not use this patch. + + +6. Warning +This program installs as root setuid-ed. Please consider with +seculity policy and set execute attribute for trasted users only. + + +7. Newest release + + http://www.kip.iis.toyama-u.ac.jp/~shingo/beep/index.html (English) + http://www.kip.iis.toyama-u.ac.jp/~shingo/beep/index-j.html (Japanese) diff --git a/doc/README.ja b/doc/README.ja new file mode 100644 index 0000000..c3572d2 --- /dev/null +++ b/doc/README.ja @@ -0,0 +1,144 @@ +beep2 version 1.2a +Original Copyright (C) 1997 Josef Pavlik +Copyright (C) 2002 YAMAGUCHI Shingo + +1. 使用法 + + beep2 [-dfs] [-t tempo] [file] + beep2 -v + +-d オプションがつくとデバッグモードで動作します。 +-f オプションがつくと周波数入力モードで動作します。これは console +beep V0.1 と同じ動作です。-s オプションがつかないときは自動的にこの +モードで動作します。 +-s オプションがつくと音階入力モードで動作します。 +-t オプションがつくと演奏の早さが整数値 tempo % になります。 +-v オプションがつくとこのプログラムのバージョンと組み込み機能を表示して +終了します。 + + +2. 周波数入力モード +周波数が 0 のときは音が鳴らない(休符)となります。 +周波数は Hz 単位で指定し、長さは ms 単位で指定します。 + +2.1 入力フォーマット +詳しくはサンプルファイル ring.bpf を参照してください。 + +{周波数} {長さ} +{周波数} {長さ} +{周波数} {長さ} # コメント +# コメント +... + +2.2 実行例 + +(1) 1kHz で 0.5 秒間鳴ります + + % beep2[Enter] + 1000 500[Enter] + [Ctrl+d] + +(2) ファイル ring を演奏します + + % beep2 ./ring[Enter] + +(3) 750 ms の間音を出しません + + % beep2[Enter] + 0 750[Enter] + [Ctrl+d] + +ファイルの 1 行目に、 + + #!/usr/bin/beep2 + +などと記述して実行属性を付けるとファイルを直接実行できます。 + + +3. 音階入力モード +音階が - のときは音が鳴らない(休符)となります。 +音階は次のように入力します。 + + C4 - ド (ト音記号下第 1 線) + C5# - ド# (ト音記号第 2 間) + --- - 休符 + +音階の ド,レ,ミ,ファ,ソ,ラ,シ はそれぞれ C,D,E,F,G,A,B に対応して +います。オクターブは 1 〜 9 まで指定できます。 + +3.1 入力フォーマット +詳しくはサンプルファイル ring.bpf を参照してください。 + +{周波数} {長さ} +{周波数} {長さ} +{周波数} {長さ} # コメント +# コメント +... + +3.2 実行例 + +(1) 音階 C5 で 0.5 秒間鳴ります + + % beep2 -s[Enter] + C5 500[Enter] + [Ctrl+d] + +(2) ファイル ring.bps を演奏します + + % beep2 -s ./ring.bps[Enter] + +(3) 750 ms の間音を出しません + + % beep2 -s[Enter] + --- 750[Enter] + [Ctrl+d] + +ファイルの 1 行目に、 + + #!/usr/bin/beep2 -s + +などと記述して実行属性を付けるとファイルを直接実行できます。 + + +4. ログ機能について +beep2 version 1.2 から、syslog を使ったログ機能が追加されており、 +コンパイル時に有効にすることで使用することができます。 + +このログは user.info の優先度で syslog に送られるため、一般的なシス +テムの場合 /var/log/messages に書き出されます。ログにはコマンドを +使用した実ユーザ名とそのときのコマンドライン文字列が記録されます。 + +syslog.conf (一般的には /etc にある)を編集することによってログの +出力先を変更することができます。詳しくは syslog のドキュメントを +参照してください。 + + +5. longbeep-linux.patch について +Linux のコンソールドライバの制限により、2000 ms 以上の beep 音は +鳴らないようになっていますが、このパッチをカーネルに対して適用する +ことで最大 9999 ms まで鳴らすことができるようになります。 + +パッチを当てるには、Linux ソースディレクトリの drivers/char に移動して +patch コマンドで当てます。すなわち、 + + # cd /usr/src/linux/drivers/char + # patch < /hoge/hoga/longbeep-linux.patch + +とします。 + +なお、このパッチは無保証なので御自分の責任においてご利用ください。 +Linux 以外のプラットフォームについてはこのパッチを適用する必要は +ありません。 + + +6. 警告 +このプログラムはエスケープシーケンスコードを用いて実装されているので +任意のユーザに /dev/console への書き込み属性を持たせるために root に +setuid されてインストールされます。あなたのサイトのセキュリティポリシー +と照らし合わせて実行権限を調整してください。 + + +7. 最新版の入手先 + + http://www.kip.iis.toyama-u.ac.jp/~shingo/beep/index.html (英語) + http://www.kip.iis.toyama-u.ac.jp/~shingo/beep/index-j.html (日本語) diff --git a/doc/longbeep-linux.patch b/doc/longbeep-linux.patch new file mode 100644 index 0000000..ae35412 --- /dev/null +++ b/doc/longbeep-linux.patch @@ -0,0 +1,11 @@ +--- console.c.orig Sun Sep 24 15:26:43 2000 ++++ console.c Sun Sep 24 15:27:59 2000 +@@ -1268,7 +1268,7 @@ + break; + case 11: /* set bell duration in msec */ + if (npar >= 1) +- bell_duration = (par[1] < 2000) ? ++ bell_duration = (par[1] < 10000) ? + par[1]*HZ/1000 : 0; + else + bell_duration = DEFAULT_BELL_DURATION; diff --git a/man/Makefile.am b/man/Makefile.am new file mode 100644 index 0000000..f8d8741 --- /dev/null +++ b/man/Makefile.am @@ -0,0 +1 @@ +SUBDIRS=en ja diff --git a/man/en/Makefile.am b/man/en/Makefile.am new file mode 100644 index 0000000..12d5715 --- /dev/null +++ b/man/en/Makefile.am @@ -0,0 +1 @@ +man_MANS=beep2.1 diff --git a/man/en/beep2.1 b/man/en/beep2.1 new file mode 100644 index 0000000..3d447ec --- /dev/null +++ b/man/en/beep2.1 @@ -0,0 +1,86 @@ +.\" beep2 Manual (English version) +.\" Author: YAMAGUCHI Shingo +.TH BEEP2 1 beep2-1.2 +.SH NAME +beep2 \- ring beep sounds with various frequency/length. +.SH SYNOPSIS +.in +.5i +.ti -.5i +.B beep2 +\%[-dfs] +\%[-t tempo] +\%[file] +.LP +.B beep2 +\%-v +.in -.5i +.SH DESCRIPTION +This manual page is for \fIbeep2\fR from \fIbeep\fR by Josef Pavlik (jetset@ibm.net). +.LP +\fIbeep2\fR accepts frequency (or score) and length from stdin or text file, and translates to beep sounds. The input format is descripted at +.B INPUT FORMAT +section. +.SS OPTION +.TP +.I "\-d" +Debug mode. \fIbeep2\fR outputs various messages. +.TP +.I "\-f" +Frequency input mode(default). \fIbeep2\fR uses frequency as input. This fuction is the same as \fIconsole beep V0.1\fR. +.TP +.I "\-s" +Score input mode. \fIbeep2\fR uses score as input. Score is constructed with set of alphabet and number (includes #). +.TP +.I "\-t tempo" +Tempo change. \fIbeep2\fR changes tempo into \fItempo\fR %. The default \fItempo\fR value is 100. +.TP +.I "\-v" +Show the version of this program and the infomation of included functions, then exit. +.SH INPUT FORMAT +\fIbeep2\fR parses line to line. A line begins with # or empty is parsed as a comment and ignored. A string after length block is parsed as a comment and ignored too. Other line is composed as 2 fields separated with space or tab. A line does not match this format is ignored. A 0 frequency input line is parsed as no sound (rest). +.SS FREQUENCY INPUT MODE +At this mode, the first field is frequency in Hz, and the second field is length in milliseconds. For example: +.nf +.in +.5i +#!/usr/bin/beep2 -d + +1046 200 # C6 +1046 100 # C6 +0 100 # rest +.in -.5i +.fi +.SS SCORE INPUT MODE +At this mode, the first field is score which constructed with alphabet and number (and #), and the second field is length in milliseconds. For example: +.nf +.in +.5i +#!/usr/bin/beep2 -ds + +C6 200 # C6 +C6 100 # C6 +C6# 100 # C6# +--- 100 # rest +.in -.5i +.fi +\fIbeep2\fR can parse octaves from 1 to 9, and parse score from C1 to B9. The rest syntax is \*(lq\-\*(rq. +.SH LIMITATION +\fIbeep2\fR makes beep sound with escape sequence code. So, \fIbeep2\fR has limitation below. +.SS I cannot hear under about 20 Hz and over about 20000 Hz sound. +This is human limitation. Some animals hear sound. +.SS I cannot set under C1 or over B9. +This is program and human limitation. +.SS I cannot hear under about 10 ms sound. +The program spends about 10 ms to change frequency. +.SS I cannot hear over 2000 ms on Linux. +This is the limitation of Linux kernel console driver. If you get source package, please use "longbeep-linux.patch" kernel patch. If you use this patch, the limitation is released and the kernel is expanded to deal length to 9999 ms. +.SH LOGGING FUNCTION +\fIbeep2\fR is added logging function since version 1.2. You can use this function if you enable it when you compile this program. +.LP +The log is sent to syslog at user.info priority. Generally, it is written to /var/log/messages. It includes the information of executed real user name and executed command string. +.LP +If you want to change log file, you need to edit syslog.conf (generally placed at /etc) and configure. The detail is in syslog documents. +.SH WARNING +\fIbeep2\fR installs as root setuid-ed. Please consider with seculity policy and set execute attribute for trasted users only. +.SH BUG +This program is not tested enoughly. I seem to be contained many bugs. If you see buggy behavior, please tell the author of \fIbeep2\fR. +.SH AUTHOR +YAMAGUCHI Shingo(shingo@kip.iis.toyama-u.ac.jp) diff --git a/man/ja/Makefile.am b/man/ja/Makefile.am new file mode 100644 index 0000000..f44ab0a --- /dev/null +++ b/man/ja/Makefile.am @@ -0,0 +1,2 @@ +man_MANS=beep2.1 +mandir=@mandir@/ja/ diff --git a/man/ja/beep2.1 b/man/ja/beep2.1 new file mode 100644 index 0000000..8fd2d06 --- /dev/null +++ b/man/ja/beep2.1 @@ -0,0 +1,91 @@ +.\" beep2 マニュアル +.\" 作成者: 山口 真悟 +.TH BEEP2 1 beep2-1.2 +.SH 名前 +beep2 \- いろいろな長さと音程のビープ音を鳴らす +.SH 書式 +.in +.5i +.ti -.5i +.B beep2 +\%[-dfs] +\%[-t tempo] +\%[file] +.LP +.B beep2 +\%-v +.in -.5i +.SH 説明 +このマニュアルページは Josef Pavlik (jetset@ibm.net) によって開発された \fIbeep\fR から派生した \fIbeep2\fR について書いている。 +.LP +\fIbeep2\fR は、標準入力又はテキストファイルから音の周波数又は音階と長さを受け取り、それをビープとして発音する。入力のフォーマットは +.B 入力フォーマット +節で説明している。 +.SS オプション +.TP +.I "\-d" +デバッグモード。プログラムで処理中の情報を逐次表示する。 +.TP +.I "\-f" +周波数入力モード(デフォルト)。音程を周波数の高低で与える。これは console beep V0.1 と同じ動作である。 +.TP +.I "\-s" +音階入力モード。音程をアルファベットと数字(# を含む)の組み合せで与える。 +.TP +.I "\-t tempo" +テンポ変換。テンポを \fItempo\fR % に変換する。デフォルトの値は 100 。 +.TP +.I "\-v" +プログラムのバージョンと組み込み機能を表示して終了する。 +.SH 入力フォーマット +\fIbeep2\fR はテキストを行単位で処理する。# から始まる行又は空行はコメント行として無視される。また、長さの指定後の文字列はコメント行として無視される。通常の音指定行は空白又はタブ文字で区切られた 2 個のフィールドから成る。このフォーマットに合わない行は解析エラー行として無視される。周波数が 0 のときは音が鳴らない(休符)となる。 +.SS 周波数入力モード +このモードでは第 1 フィールドに音の周波数を Hz 単位で指定し、第 2 フィールドに音の長さをミリ秒単位で指定する。例えば以下のようになる。 +.nf +.in +.5i +#!/usr/bin/beep2 -d + +1046 200 # C6 +1046 100 # C6 +0 100 # rest +.in -.5i +.fi +.SS 音階入力モード +このモードでは第 1 フィールドに音程をアルファベットと数字(と # 記号)で指定し、第 2 フィールドに音の長さをミリ秒単位で指定する。例えば以下のようになる。 +.nf +.in +.5i +#!/usr/bin/beep2 -ds + +C6 200 # C6 +C6 100 # C6 +C6# 100 # C6# +--- 100 # rest +.in -.5i +.fi +音階の ド,レ,ミ,ファ,ソ,ラ,シ はそれぞれ C,D,E,F,G,A,B に対応しており、オクターブは 1 〜 9 まで指定できる。 +.LP +なお、指定できる音階は C1 から B9 までであり、C4 がト音記号における下第1線の\*(lqド\*(rq となる。また、休符は - に対応する。 +.SH 制限 +\fIbeep2\fR はエスケープシーケンスコードを利用して音程を作っているので以下のような制限がある。 +.SS 約 20 Hz 以下又は約 20000 Hz 以上の音が聞こえない +人間の可聴領域を越えているためであり、聞こえる動物には聞こえているはずである。 +.SS C1 より低い音又は B9 より高い音の指定ができない +実用的な音程は上記の範囲で収まっているはずであるし、人間の可聴領域を越えて +しまうため。 +.SS 約 10 ms 以下の音程の切り替えができない +音程の切り替えに約 10 ms かかるのでこれ以下の長さを指定すると音が鳴らない。 +.SS Linux において 2000 ms 以上の長さの音が鳴らない +これは Linux カーネルのコンソールドライバの制限によるもので、ソースパッケージ付属の longbeep-linux.patch をカーネルに対して適用することでこの制限を 9999 ms まで拡張することができる。 +.LP +もしソースパッケージではなくてバイナリパッケージで入手した場合は beep2 作者の Web ページでこのパッチを入手する必要がある。 +.SH ログ機能 +\fIbeep2\fR version 1.2 から、syslog を使ったログ機能が追加されており、コンパイル時に有効にすることで使用することができる。もしバイナリパッケージを手に入れたなら -v オプションをつけて起動し、ログ機能が有効になっているか確かめることができる。もしログ機能が必要ないなら \fIbeep2\fR 作者のページでログ機能を無効にしたバイナリパッケージを用意しているのでそちらを使って欲しい。 +.LP +ログは user.info の優先度で syslog に送られるため、一般的なシステムの場合 /var/log/messages に書き出される。ログにはコマンドを使用した実ユーザ名とそのときのコマンドライン文字列が記録される。 +.LP +syslog.conf (一般的には /etc にある)を編集することでログの出力先を変更することができる。詳しくは syslog のドキュメントを参照すること。 +.SH セキュリティ上の警告 +\fIbeep2\fR は root に setuid されてインストールされる。このためバッファオーバーフローなどのセキュリティホールを突くために利用される恐れがある。各サイトのセキュリティーポリシーと照らし合わせて、プログラムの実行権限を適切に設定する必要がある。 +.SH バグ +このソフトはまだ十分にテストされていないのでまだ多くのバグが潜んでいると思われる。もしバグと思われる現象を発見したなら \fIbeep2\fR の作者まで知らせて欲しい。 +.SH 著者 +山口 真悟(shingo@kip.iis.toyama-u.ac.jp) diff --git a/sample/abc-score.bps b/sample/abc-score.bps new file mode 100755 index 0000000..6586fcc --- /dev/null +++ b/sample/abc-score.bps @@ -0,0 +1,122 @@ +#!/usr/bin/beep2 -s +# +# abc-score.bps - beep sound CDEFGAH +# 2000/09/29 Shingo YAMAGUCHI +# + +C1 200 +C1# 200 +D1 200 +D1# 200 +E1 200 +F1 200 +F1# 200 +G1 200 +G1# 200 +A1 200 +A1# 200 +B1 200 +--- 1000 +C2 200 +C2# 200 +D2 200 +D2# 200 +E2 200 +F2 200 +F2# 200 +G2 200 +G2# 200 +A2 200 +A2# 200 +B2 200 +--- 1000 +C3 200 +C3# 200 +D3 200 +D3# 200 +E3 200 +F3 200 +F3# 200 +G3 200 +G3# 200 +A3 200 +A3# 200 +B3 200 +--- 1000 +C4 200 +C4# 200 +D4 200 +D4# 200 +E4 200 +F4 200 +F4# 200 +G4 200 +G4# 200 +A4 200 +A4# 200 +B4 200 +--- 1000 +C5 200 +C5# 200 +D5 200 +D5# 200 +E5 200 +F5 200 +F5# 200 +G5 200 +G5# 200 +A5 200 +A5# 200 +B5 200 +--- 1000 +C6 200 +C6# 200 +D6 200 +D6# 200 +E6 200 +F6 200 +F6# 200 +G6 200 +G6# 200 +A6 200 +A6# 200 +B6 200 +--- 1000 +C7 200 +C7# 200 +D7 200 +D7# 200 +E7 200 +F7 200 +F7# 200 +G7 200 +G7# 200 +A7 200 +A7# 200 +B7 200 +--- 1000 +C8 200 +C8# 200 +D8 200 +D8# 200 +E8 200 +F8 200 +F8# 200 +G8 200 +G8# 200 +A8 200 +A8# 200 +B8 200 +--- 1000 +C9 200 +C9# 200 +D9 200 +D9# 200 +E9 200 +F9 200 +F9# 200 +G9 200 +G9# 200 +A9 200 +A9# 200 +B9 200 diff --git a/sample/ring.bpf b/sample/ring.bpf new file mode 100755 index 0000000..7c6633b --- /dev/null +++ b/sample/ring.bpf @@ -0,0 +1,18 @@ +#!/usr/bin/beep2 +770 40 +880 40 +770 40 +880 40 +770 40 +880 40 +770 40 +880 40 +0 200 +770 40 +880 40 +770 40 +880 40 +770 40 +880 40 +770 40 +880 40 diff --git a/sample/ring.bps b/sample/ring.bps new file mode 100755 index 0000000..829964f --- /dev/null +++ b/sample/ring.bps @@ -0,0 +1,18 @@ +#!/usr/bin/beep2 -s +G5 40 +A5 40 +G5 40 +A5 40 +G5 40 +A5 40 +G5 40 +A5 40 +--- 200 +G5 40 +A5 40 +G5 40 +A5 40 +G5 40 +A5 40 +G5 40 +A5 40 diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..2aa2cd8 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,6 @@ +CFLAGS = @CFLAGS@ @SYSTEM_LOGGING@ @OSTYPE_BSD@ + +INSTALL_PROGRAM = $(install_sh) -c -m 4755 + +bin_PROGRAMS = beep2 +beep2_SOURCES = beep.c beep.h log.c main.c parse_f.c parse_s.c s2f.c usage.c version.c diff --git a/src/beep.c b/src/beep.c new file mode 100644 index 0000000..c1c2131 --- /dev/null +++ b/src/beep.c @@ -0,0 +1,69 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#include "beep.h" + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STDlIB_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif + +void output_beep_sound(param_t *beepbuf) +{ + FILE *dest; + int parsedline; + + dest = fopen(OUTPUT_DEVICE, "w"); + if (!dest) { + fprintf(stderr, "beep2: Can't open "OUTPUT_DEVICE"\n"); + exit(1); + } + + for (parsedline = 0; + beepbuf[parsedline].status != PARSE_TERMINATE; + parsedline++) { +#ifdef OSTYPE_BSD + int pitch; + int dulation; + if (beepbuf[parsedline].freq != 0 ) { + pitch = 1193182 / beepbuf[parsedline].freq; + } else { + pitch = 0; + } + dulation = beepbuf[parsedline].length / 10; + + if (debug == ON) { + fprintf(stderr, + "beep2: pitch: %d dulation: %d\n", + pitch, + dulation); + } + + fprintf(dest, "\033[=%d;%dB\a\033[=800;1B", + pitch, dulation); +#else + if (debug == ON) { + fprintf(stderr, + "beep2: freq: %d, length: %d\n", + beepbuf[parsedline].freq, + beepbuf[parsedline].length); + } + fprintf(dest,"\033[10;%d]\033[11;%d]\a\033[10]\033[11]", + beepbuf[parsedline].freq, beepbuf[parsedline].length); +#endif /* OSTYPE_BSD */ + fflush(dest); + + if (beepbuf[parsedline].length) { + usleep(beepbuf[parsedline].length*1000L); + } + } + fclose(dest); +} diff --git a/src/beep.h b/src/beep.h new file mode 100644 index 0000000..3d78f22 --- /dev/null +++ b/src/beep.h @@ -0,0 +1,45 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#ifndef __BEEP_H_INCLUDED__ +#define __BEEP_H_INCLUDED__ + +#include "config.h" + +#define BUFFER 65535 + +#define ON 1 +#define OFF 0 + +#define SOURCE_FREQ 1 +#define SOURCE_SEQUENCE 2 + +#define PARSE_OK 1 +#define PARSE_ERROR 2 +#define PARSE_COMMENT 4 +#define PARSE_TERMINATE 8 + +#define NOW_START 1 +#define NOW_BLANK 2 +#define NOW_FREQ 4 +#define NOW_REST 8 +#define NOW_SEQCHR 16 +#define NOW_SEQNUM 32 +#define NOW_SEQSHP 64 +#define NOW_LENG 128 +#define NOW_END 256 + +typedef struct param { + int status; /* parse line status */ + int freq; /* frequency */ + int length; /* length(milliseconds) */ +} param_t; + +int debug; +int source; +int tempo; + +#endif /* __BEEP_H_INCLUDED__ */ diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..8ffaa84 --- /dev/null +++ b/src/log.c @@ -0,0 +1,67 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#include "beep.h" + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_PWD_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYSLOG_H +#include +#endif + +#ifdef SYSTEM_LOGGING + +void write_log(int argc, char **argv) +{ + uid_t execuid; + struct passwd *execpwuid; + char *execuname; + + int i; + char *execstr; + + execuname = (char*)malloc(BUFFER); + execstr = (char*)malloc(BUFFER); + + /* + * get execute user ID + */ + execuid = getuid(); + execpwuid = getpwuid(execuid); + strcpy(execuname, execpwuid->pw_name); + + /* + * get execute string + */ + for (i = 0; i <= argc - 1; i++) { + sprintf(execstr, "%s %s", execstr, argv[i]); + } + + /* + * send log message to syslog + */ + syslog(LOG_INFO, "user = %s, exec =%s\n", execuname, execstr); + + free(execuname); + free(execstr); +} +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..fd9e573 --- /dev/null +++ b/src/main.c @@ -0,0 +1,154 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#include "beep.h" + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_CTYPE_H +#include +#endif + +param_t get_parameter_from_sequence_source(char *instr); +param_t get_parameter_from_freqency_source(char *instr); +void output_beep_sound(param_t *beepbuf); +void output_usage(); +void output_version(); +#ifdef SYSTEM_LOGGING +void write_log(int argc, char **argv); +#endif + +int main (int argc, char **argv) { + FILE *in = NULL; + int i; + int arg; + int line; + int parsedline; + param_t parameter; + param_t beepbuf[BUFFER]; + char instr[BUFFER] = ""; + + debug = OFF; + source = SOURCE_FREQ; + tempo = 100; + +#ifdef SYSTEM_LOGGING + write_log(argc, argv); +#endif + + while ((arg = getopt(argc, argv, "dfst:v")) != -1) { + switch (arg) { + case 'd': + debug = ON; + break; + case 'f': + source = SOURCE_FREQ; + break; + case 's': + source = SOURCE_SEQUENCE; + break; + case 't': + if (isdigit(*optarg)) { + tempo = atoi(optarg); + } else { + output_usage(); + exit(1); + } + break; + case 'v': + output_version(); + exit(0); + break; + case ':': + case '?': + output_usage(); + exit(1); + break; + default: + break; + } + } + + if (debug == ON) { + fprintf(stderr, "beep2: optind=%d\n", optind); + fprintf(stderr, "beep2: source=%d\n", source); + fprintf(stderr, "beep2: tempo=%d%%\n", tempo); + fprintf(stderr, "beep2: argc=%d\n", argc); + for (i = 0; i <= argc; i++) { + fprintf(stderr, "beep2: argv[%d]=%s\n", i, argv[i]); + } + } + + if (optind == argc) { + in = stdin; + } else if (optind == argc - 1) { + in = fopen(argv[optind], "r"); + if (!in) { + fprintf(stderr,"beep2: Can't open file %s.\n", argv[optind]); + output_usage(); + exit(1); + } + } else { + output_usage(); + exit(1); + } + + line = 0; + parsedline = 0; + + if (debug == ON) { + fprintf(stderr, "beep2: Parsing"); + } + + while (1) { + *instr = '\0'; + fgets(instr, sizeof(instr), in); + if ((*instr == '\n' || *instr == '\0') && feof(in)) { + break; + } + + if (source == SOURCE_SEQUENCE) { + parameter = get_parameter_from_sequence_source(instr); + } else { + parameter = get_parameter_from_freqency_source(instr); + } + + if (parameter.status == PARSE_OK) { + beepbuf[parsedline] = parameter; + parsedline++; + } else if (parameter.status == PARSE_ERROR) { + fprintf(stderr, "beep2: Parse error at line %d\n", line+1); + } + parameter.status = PARSE_COMMENT; + parameter.freq = 0; + parameter.length = 0; + + if (debug == ON) { + if (line % 10 == 0) { + fprintf(stderr, "."); + } + } + line++; + } + fclose(in); + + beepbuf[parsedline].status = PARSE_TERMINATE; + + if (debug == ON) { + fprintf(stderr, "done.\n"); + } + + output_beep_sound(beepbuf); + + exit(0); +} diff --git a/src/parse_f.c b/src/parse_f.c new file mode 100644 index 0000000..87c6987 --- /dev/null +++ b/src/parse_f.c @@ -0,0 +1,88 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#include "beep.h" + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_CTYPE_H +#include +#endif + +param_t get_parameter_from_freqency_source(char *instr) +{ + int num; + int status; + int value; + param_t parameter; + + parameter.status = PARSE_COMMENT; + parameter.freq = 0; + parameter.length = 0; + + if (instr[0] != '\n' && instr[0] != '#') { + status = NOW_START; + value = 0; + for (num = 0; instr[num] != '\0'; num++) { + if (isdigit(instr[num])) { + switch (status) { + case NOW_START: + case NOW_FREQ: + status = NOW_FREQ; + value *= 10; + value += instr[num] - '0'; + break; + case NOW_BLANK: + case NOW_LENG: + status = NOW_LENG; + value *= 10; + value += instr[num] - '0'; + break; + default: + break; + } + } else if (instr[num] == ' ' || instr[num] == '\t') { + switch (status) { + case NOW_FREQ: + status = NOW_BLANK; + parameter.freq = value; + value = 0; + break; + case NOW_LENG: + status = NOW_END; + parameter.status = PARSE_OK; + parameter.length = value * (double)(100.0 / tempo); + value = 0; + break; + default: + break; + } + } else if (instr[num] == '\n') { + switch (status) { + case NOW_START: + status = NOW_END; + parameter.status = PARSE_COMMENT; + break; + case NOW_FREQ: + case NOW_BLANK: + status = NOW_END; + parameter.status = PARSE_ERROR; + break; + case NOW_LENG: + status = NOW_END; + parameter.status = PARSE_OK; + parameter.length = value * (double)(100.0 / tempo); + value = 0; + break; + default: + break; + } + } + } + } + return parameter; +} diff --git a/src/parse_s.c b/src/parse_s.c new file mode 100644 index 0000000..83243a2 --- /dev/null +++ b/src/parse_s.c @@ -0,0 +1,155 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#include "beep.h" + +#ifdef HAVE_STDIO_H +#include +#endif +#ifdef HAVE_CTYPE_H +#include +#endif + +int get_frequency_from_sequence(char *scale); + +param_t get_parameter_from_sequence_source(char *instr) +{ + int num; + int status; + int value; + char scale[3]; + param_t parameter; + + parameter.status = PARSE_COMMENT; + parameter.freq = 0; + parameter.length = 0; + + if (instr[0] != '\n' && instr[0] != '#') { + status = NOW_START; + value = 0; + for (num = 0; instr[num] != '\0'; num++) { + if (instr[num] == '-') { + switch (status) { + case NOW_START: + status = NOW_REST; + break; + case NOW_SEQCHR: + case NOW_SEQNUM: + case NOW_SEQSHP: + case NOW_BLANK: + status = NOW_END; + parameter.status = PARSE_ERROR; + break; + default: + break; + } + } else if (instr[num] == 'A' || + instr[num] == 'B' || + instr[num] == 'C' || + instr[num] == 'D' || + instr[num] == 'E' || + instr[num] == 'F' || + instr[num] == 'G') { + switch (status) { + case NOW_START: + status = NOW_SEQCHR; + sprintf(scale, "%c", instr[num]); + break; + case NOW_SEQNUM: + case NOW_SEQSHP: + case NOW_BLANK: + status = NOW_END; + parameter.status = PARSE_ERROR; + break; + default: + break; + } + } else if (isdigit(instr[num])) { + switch (status) { + case NOW_START: + case NOW_SEQNUM: + status = NOW_END; + parameter.status = PARSE_ERROR; + break; + case NOW_SEQCHR: + status = NOW_SEQNUM; + sprintf(scale, "%s%c", scale, instr[num]); + break; + case NOW_BLANK: + case NOW_LENG: + status = NOW_LENG; + value *= 10; + value += instr[num] - '0'; + break; + default: + break; + } + } else if (instr[num] == '#') { + switch (status) { + case NOW_START: + status = NOW_END; + break; + case NOW_SEQCHR: + case NOW_SEQSHP: + case NOW_LENG: + status = NOW_END; + parameter.status = PARSE_ERROR; + break; + case NOW_SEQNUM: + status = NOW_SEQSHP; + sprintf(scale, "%s%c", scale, instr[num]); + break; + default: + break; + } + } else if (instr[num] == ' ' || instr[num] == '\t') { + switch (status) { + case NOW_SEQCHR: + status = NOW_END; + parameter.status = PARSE_ERROR; + break; + case NOW_SEQNUM: + case NOW_SEQSHP: + status = NOW_BLANK; + parameter.freq = get_frequency_from_sequence(scale); + break; + case NOW_REST: + status = NOW_BLANK; + parameter.freq = 0; + break; + case NOW_LENG: + status = NOW_END; + parameter.status = PARSE_OK; + parameter.length = value * (double)(100.0 / tempo); + value = 0; + break; + default: + break; + } + } else if (instr[num] == '\n') { + switch (status) { + case NOW_SEQCHR: + case NOW_SEQNUM: + case NOW_SEQSHP: + case NOW_REST: + case NOW_BLANK: + status = NOW_END; + parameter.status = PARSE_ERROR; + break; + case NOW_LENG: + status = NOW_END; + parameter.status = PARSE_OK; + parameter.length = value * (double)(100.0 / tempo); + value = 0; + break; + default: + break; + } + } + } + } + return parameter; +} diff --git a/src/s2f.c b/src/s2f.c new file mode 100644 index 0000000..9f1ddd6 --- /dev/null +++ b/src/s2f.c @@ -0,0 +1,64 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#include "beep.h" + +#ifdef HAVE_STRING_H +#include +#endif + +int get_frequency_from_sequence(char *scale) +{ + int i; + char *def_scale[108] = { + "C1", "C1#", "D1", "D1#", "E1", "F1", + "F1#", "G1", "G1#", "A1", "A1#", "B1", + "C2", "C2#", "D2", "D2#", "E2", "F2", + "F2#", "G2", "G2#", "A2", "A2#", "B2", + "C3", "C3#", "D3", "D3#", "E3", "F3", + "F3#", "G3", "G3#", "A3", "A3#", "B3", + "C4", "C4#", "D4", "D4#", "E4", "F4", + "F4#", "G4", "G4#", "A4", "A4#", "B4", + "C5", "C5#", "D5", "D5#", "E5", "F5", + "F5#", "G5", "G5#", "A5", "A5#", "B5", + "C6", "C6#", "D6", "D6#", "E6", "F6", + "F6#", "G6", "G6#", "A6", "A6#", "B6", + "C7", "C7#", "D7", "D7#", "E7", "F7", + "F7#", "G7", "G7#", "A7", "A7#", "B7", + "C8", "C8#", "D8", "D8#", "E8", "F8", + "F8#", "G8", "G8#", "A8", "A8#", "B8", + "C9", "C9#", "D9", "D9#", "E9", "F9", + "F9#", "G9", "G9#", "A9", "A9#", "B9", + }; + + int def_freq[108] = { + 33, 35, 37, 39, 41, 44, + 46, 49, 52, 55, 58, 62, + 65, 69, 73, 78, 82, 87, + 92, 98, 104, 110, 117, 123, + 131, 139, 147, 156, 165, 175, + 185, 196, 208, 220, 233, 247, + 262, 277, 294, 311, 330, 349, + 370, 392, 415, 440, 466, 494, + 523, 554, 587, 622, 659, 698, + 740, 784, 831, 880, 932, 988, + 1047, 1109, 1175, 1245, 1319, 1397, + 1480, 1568, 1661, 1760, 1865, 1976, + 2093, 2217, 2349, 2489, 2637, 2794, + 2960, 3136, 3322, 3520, 3729, 3951, + 4186, 4435, 4699, 4978, 5274, 5588, + 5920, 6272, 6645, 7040, 7459, 7902, + 8372, 8870, 9397, 9956, 10548, 11175, + 11840, 12544, 13290, 14080, 14917, 15804 + }; + + for (i = 0; i < 108; i++) { + if (!strcmp(def_scale[i], scale)) { + return def_freq[i]; + } + } + return 0; +} diff --git a/src/usage.c b/src/usage.c new file mode 100644 index 0000000..b061afe --- /dev/null +++ b/src/usage.c @@ -0,0 +1,25 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#include "beep.h" + +#ifdef HAVE_STDIO_H +#include +#endif + +void output_usage() +{ + fprintf(stderr, "beep2: Usage:\n"); + fprintf(stderr, "beep2: \t\tbeep2 [-dfs] [file]\n"); + fprintf(stderr, "beep2: \t\tbeep2 -v\n"); + fprintf(stderr, "beep2: \n"); + fprintf(stderr, "beep2: Options:\n"); + fprintf(stderr, "beep2: \t\t-d\tdebug mode\n"); + fprintf(stderr, "beep2: \t\t-f\tfrequency input mode(default)\n"); + fprintf(stderr, "beep2: \t\t-s\tscore input mode\n"); + fprintf(stderr, "beep2: \t\t-t tempo\tchange tempo\n"); + fprintf(stderr, "beep2: \t\t-v\tshow version and included functions\n"); +} diff --git a/src/version.c b/src/version.c new file mode 100644 index 0000000..0a40ab8 --- /dev/null +++ b/src/version.c @@ -0,0 +1,42 @@ +/* + * beep2 + * Original Copyright (C) 1997 Josef Pavlik + * Copyright (C) 2002 YAMAGUCHI Shingo + */ + +#include "beep.h" + +#ifdef HAVE_STDIO_H +#include +#endif + +#include "beep.h" + +void output_version() +{ + fprintf(stderr, "\nbeep2 version "PACKAGE_VERSION"\n\n"); + fprintf(stderr, " Original Copyright (C) 1997 Josef Pavlik "); + fprintf(stderr, "(jetset@ibm.net)\n"); + fprintf(stderr, " Copyright (C) 2002 YAMAGUCHI Shingo "); + fprintf(stderr, "\n\n"); + + fprintf(stderr, "Function information:\n\n"); + fprintf(stderr, " Supported OS type: "); +#ifdef OSTYPE_BSD + fprintf(stderr, "BSD (FreeBSD etc...)\n"); +#else + fprintf(stderr, "Linux\n"); +#endif + fprintf(stderr, " Logging: "); +#ifdef SYSTEM_LOGGING + fprintf(stderr, "enabled\n\n"); +#else + fprintf(stderr, "disabled\n\n"); +#endif + + fprintf(stderr, "The latest release is here:\n\n"); + fprintf(stderr, " http://www.kip.iis.toyama-u.ac.jp"); + fprintf(stderr, "/~shingo/beep/index.html (English)\n"); + fprintf(stderr, " http://www.kip.iis.toyama-u.ac.jp"); + fprintf(stderr, "/~shingo/beep/index-j.html (Japanese)\n\n"); +}