From 3cd5ef65476daf64b0dc0b5369a7d88f9eff9033 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 1 Apr 2022 17:06:48 +0200 Subject: New file, still progressing --- Makefile | 6 ++++-- src/c_go2work.go | 22 ++++++++++++---------- src/p_options.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 src/p_options.go diff --git a/Makefile b/Makefile index 9842d3f..15f22b5 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ # ======================== # # go2work: Makefile -# Wed Mar 30 13:26:48 CEST 2022 +# Fri Apr 1 17:04:04 CEST 2022 # Joe # # GNU Makefile @@ -28,6 +28,7 @@ TRGT_DIR = ./ SRCS_NAME = c_defs SRCS_NAME += c_go2work SRCS_NAME += c_player +SRCS_NAME += p_options SRCS_NAME += u_checks SRCS_NAME += u_prints SRCS_NAME += u_utils @@ -55,4 +56,5 @@ run: # File prefixes info # ------------------ # c_ -> core program -# u_ -> utils related +# p_ -> parsing +# u_ -> utils diff --git a/src/c_go2work.go b/src/c_go2work.go index 5dc460c..920c9bf 100644 --- a/src/c_go2work.go +++ b/src/c_go2work.go @@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * go2work: src/c_go2work.go - * Wed Mar 30 13:20:26 CEST 2022 + * Fri Apr 1 17:03:18 CEST 2022 * Joe * * The main. @@ -60,6 +60,7 @@ func main() { var curr_t [3]byte var dest_t [3]byte var tmp int + var options options log.SetPrefix(PROGNAME + ": ") log.SetFlags(0) if len(os.Args[0:]) == 1 { @@ -89,17 +90,18 @@ func main() { dest_t[MINS] = byte(tmp) dest_t[SECS] = 0 } - if check_media_player(DEF_MEDIA_PLAYER) == false { - log.Fatal("media player (" + DEF_MEDIA_PLAYER + ") not found") - return - } - if DEF_USE_FORTUNE == true && check_fortune() == false { - fmt.Println("Beware, fortune is set on but was not found") - } + options = parse_options() if check_time_format(dest_t) == false { log.Fatal(LOG_FORMAT) return } + if check_media_player(options.media_player) == false { + log.Fatal("media player (" + options.media_player + ") not found") + return + } + if options.use_fortune == true && check_fortune() == false { + fmt.Println("Beware, fortune is set on but was not found") + } curr_t = get_time() print_time_left(curr_t, dest_t) ticker := time.NewTicker(INTERVAL * time.Millisecond) @@ -114,8 +116,8 @@ func main() { curr_t[SECS] == dest_t[SECS] { args := append(DEF_PLAYER_OPTIONS(), DEF_FILES()[0]) exec_player( - DEF_USE_FORTUNE, - DEF_MEDIA_PLAYER, + options.use_fortune, + options.media_player, args..., ) return diff --git a/src/p_options.go b/src/p_options.go new file mode 100644 index 0000000..44b67e9 --- /dev/null +++ b/src/p_options.go @@ -0,0 +1,53 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * 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/p_options.go + * Fri Apr 1 17:03:22 CEST 2022 + * Joe + * + * Options parsing. + */ + +package main + +func parse_options() options { + var options options + return options +} -- cgit v1.2.3