From 4f77685d24fdc3b49a6459b77dc2a23a68aaf30d Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 4 Apr 2022 18:09:53 +0200 Subject: v1.0.0 incoming --- Makefile | 55 ++++++++++++++++++++++++-------- man/go2work.1 | 0 share/ring01.wav | Bin 0 -> 1552750 bytes share/ring02.wav | Bin 0 -> 1704684 bytes src/c_defs.go | 6 ++-- src/c_go2work.go | 44 -------------------------- src/c_loop.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 139 insertions(+), 61 deletions(-) create mode 100644 man/go2work.1 create mode 100644 share/ring01.wav create mode 100644 share/ring02.wav create mode 100644 src/c_loop.go diff --git a/Makefile b/Makefile index 68ae630..3ff7fd0 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ # ======================== # # go2work: Makefile -# Mon Apr 4 17:06:10 CEST 2022 +# Mon Apr 4 18:03:35 CEST 2022 # Joe # # GNU Makefile @@ -19,40 +19,67 @@ default: build SHELL := /bin/sh -OS = $(shell uname) +OS := $(shell uname) -SRCS_DIR = src/ -DATA_DIR = share/ -TRGT_DIR = ./ +DESTDIR := /usr/local/ +SRCS_DIR := src/ +DATA_DIR := share/ +MAN_DIR := man/ -SRCS_NAME = c_defs +SRCS_NAME := c_defs SRCS_NAME += c_go2work +SRCS_NAME += c_loop SRCS_NAME += c_player SRCS_NAME += p_options SRCS_NAME += u_checks SRCS_NAME += u_prints SRCS_NAME += u_utils -SRCS = $(addprefix ${SRCS_DIR}, $(addsuffix .go, ${SRCS_NAME})) +SRCS := $(addprefix ${SRCS_DIR}, $(addsuffix .go, ${SRCS_NAME})) -TRGT_NAME = go2work -TARGET = $(addprefix ${TRGT_DIR}, ${TRGT_NAME}) +TARGET := go2work +MAN := $(addsuffix .1, ${TARGET}) -MKDIR = mkdir -p -RMDIR = rmdir -RM = rm -rf +MKDIR := mkdir -p +RMDIR := rmdir +RM := rm -rf +GZIP := gzip +GUNZIP := gunzip +INSTALL := install deps: go get github.com/BurntSushi/toml@latest -build: deps +build: ${TARGET} + +${TARGET}: deps go build -o ${TARGET} ${SRCS} +install-bin: ${TARGET} + ${MKDIR} ${DESTDIR}bin + ${INSTALL} -m0555 ${TARGET} ${DESTDIR}bin/${TARGET} + +install-data: + ${MKDIR} ${DESTDIR}share/${TARGET} + ${INSTALL} -m0644 ${DATA_DIR}ring01.wav ${DESTDIR}share/${TARGET}/ring01.wav + ${INSTALL} -m0644 ${DATA_DIR}ring02.wav ${DESTDIR}share/${TARGET}/ring02.wav + +install-doc: + ${MKDIR} ${DESTDIR}man/man1 + ${GZIP} ${MAN_DIR}${MAN} + ${INSTALL} -m0444 ${MAN_DIR}${MAN}.gz ${DESTDIR}man/man1/${MAN}.gz + ${GUNZIP} ${MAN_DIR}${MAN} + +install: install-bin install-doc + false + +# ifeq(${OS} == "FreeBSD") + clean: go clean ${RM} ${TARGET} -.PHONY: build clean deps +.PHONY: deps build install clean # File prefixes info # ------------------ diff --git a/man/go2work.1 b/man/go2work.1 new file mode 100644 index 0000000..e69de29 diff --git a/share/ring01.wav b/share/ring01.wav new file mode 100644 index 0000000..8509f0b Binary files /dev/null and b/share/ring01.wav differ diff --git a/share/ring02.wav b/share/ring02.wav new file mode 100644 index 0000000..d76005a Binary files /dev/null and b/share/ring02.wav differ diff --git a/src/c_defs.go b/src/c_defs.go index 9c57b66..eb211c6 100644 --- a/src/c_defs.go +++ b/src/c_defs.go @@ -49,7 +49,7 @@ package main const ( PROGNAME = "go2work" - VERSION = "0.1.0" + VERSION = "1.0.0" HOURS = 0 MINS = 1 SECS = 2 @@ -63,8 +63,8 @@ const ( func DEF_FILES() []string { return []string{ - "/usr/home/jozan/mu/progressive/progressive_black_metal/deathspell_omega/2010_paracletus/02_wings_of_predation.flac", - "/usr/home/jozan/docs/dr2_art/sounds/sfx/broking_cursed_object.wav", + "/usr/local/share/go2work/ring01.wav", + "/usr/local/share/go2work/ring02.wav", } } diff --git a/src/c_go2work.go b/src/c_go2work.go index e11dab4..5a42160 100644 --- a/src/c_go2work.go +++ b/src/c_go2work.go @@ -52,7 +52,6 @@ import ( "os" "strconv" "strings" - "time" ) func main() { @@ -105,46 +104,3 @@ func main() { print_time_left(curr_t, dest_t) main_loop(dest_t, options) } - -func main_loop(dest_t [3]byte, options Options) { - var curr_t [3]byte - ticker := time.NewTicker(INTERVAL * time.Millisecond) - quit := make(chan struct{}) - for { - select { - case <- ticker.C: - curr_t = get_time() - print_time_left(curr_t, dest_t) - if curr_t[HOURS] == dest_t[HOURS] && - curr_t[MINS] == dest_t[MINS] && - curr_t[SECS] == dest_t[SECS] { - file_id := choose_file(options) - var args []string - if file_id >= 0 { - args = append( - options.Player_options, - options.Files[file_id], - ) - } else { - args = append( - options.Player_options, - DEF_FILES()[0], - ) - } - has_rang := false - for { - exec_player( - options.Fortune, - has_rang, - options.Media_player, - args..., - ) - has_rang = true - } - } - case <- quit: - ticker.Stop() - return - } - } -} diff --git a/src/c_loop.go b/src/c_loop.go new file mode 100644 index 0000000..8a5e9c7 --- /dev/null +++ b/src/c_loop.go @@ -0,0 +1,95 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2022 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * go2work: src/c_loop.go + * Mon Apr 4 17:28:38 CEST 2022 + * Joe + * + * The main loop + */ + +package main + +import( + "time" +) + +func main_loop(dest_t [3]byte, options Options) { + var curr_t [3]byte + ticker := time.NewTicker(INTERVAL * time.Millisecond) + quit := make(chan struct{}) + for { + select { + case <- ticker.C: + curr_t = get_time() + print_time_left(curr_t, dest_t) + if curr_t[HOURS] == dest_t[HOURS] && + curr_t[MINS] == dest_t[MINS] && + curr_t[SECS] == dest_t[SECS] { + file_id := choose_file(options) + var args []string + if file_id >= 0 { + args = append( + options.Player_options, + options.Files[file_id], + ) + } else { + args = append( + options.Player_options, + DEF_FILES()[0], + ) + } + has_rang := false + for { + exec_player( + options.Fortune, + has_rang, + options.Media_player, + args..., + ) + has_rang = true + } + } + case <- quit: + ticker.Stop() + return + } + } +} -- cgit v1.2.3