Home
       initial commit - bsleep - Unnamed repository; edit this file 'description' to name the repository.
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit a3d47929ad00f036aabe8bd131d65f612260861d
  HTML Author: kroovy <me@kroovy.de>
       Date:   Sun, 30 Jun 2024 18:49:18 +0200
       
       initial commit
       
       Diffstat:
         A .gitignore                          |       2 ++
         A LICENSE                             |      15 +++++++++++++++
         A Makefile                            |      16 ++++++++++++++++
         A README                              |      19 +++++++++++++++++++
         A bsleep.c                            |      35 +++++++++++++++++++++++++++++++
       
       5 files changed, 87 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/.gitignore b/.gitignore
       @@ -0,0 +1,2 @@
       +gopherproxy
       +*.o
   DIR diff --git a/LICENSE b/LICENSE
       @@ -0,0 +1,15 @@
       +ISC License
       +
       +Copyright (c) 2024 kroovy <me@kroovy.de>
       +
       +Permission to use, copy, modify, and/or distribute this software for any
       +purpose with or without fee is hereby granted, provided that the above
       +copyright notice and this permission notice appear in all copies.
       +
       +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
       +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
       +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
       +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
       +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
       +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
       +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   DIR diff --git a/Makefile b/Makefile
       @@ -0,0 +1,16 @@
       +.POSIX:
       +
       +BIN = bsleep
       +OBJ = $(BIN:=.o)
       +
       +LDFLAGS += -static -Wall -Wextra -pedantic
       +
       +all: $(BIN)
       +
       +$(BIN): $(OBJ)
       +        $(CC) $(OBJ) $(LDFLAGS) -o $@
       +
       +$(OBJ): Makefile
       +
       +clean:
       +        rm -f $(BIN) $(OBJ)
   DIR diff --git a/README b/README
       @@ -0,0 +1,19 @@
       +bsleep
       +
       +Breakable sleep. The button 'b' breaks the sleep. This can be used to
       +chain two tasks on the commandline, with the second task only waiting for
       +you to press 'b'.
       +
       +Build dependencies
       +- C compiler
       +- libc
       +
       +This program is meant to help people complete tasks on the commandline.
       +Also the source code can be studied as a simple approach to forking a
       +process.
       +
       +The invocation of the operating system command "/bin/stty" via system()
       +is not the most elegant. At the moment this needed to read the character
       +without the need to press Enter.
       +If possible I will try to replace the call system("/bin/stty ...") in the
       +future.
   DIR diff --git a/bsleep.c b/bsleep.c
       @@ -0,0 +1,35 @@
       +#include <signal.h>
       +#include <stdio.h>
       +#include <stdlib.h>
       +#include <unistd.h>
       +
       +int
       +main(void)
       +{
       +        int i,in,pid;
       +        pid = fork();
       +
       +        if (pid == 0) {
       +                /* child */
       +                for (i=1;;i++) {
       +                        printf("%d ", i); fflush(stdout); /* comment out if you prefer silent */
       +                        sleep(1);
       +                }
       +                return 0;
       +
       +        } else if (pid > 0) {
       +                /* parent */
       +                system ("/bin/stty raw");
       +                while ((in = getchar()) != 'b') {
       +                        printf("%c ", in);
       +                }
       +                system ("/bin/stty cooked");
       +                printf("\n");
       +                kill(pid, SIGKILL); /* kill child */
       +                return 0;
       +
       +        } else {
       +                return -1;
       +        }
       +        return 0;
       +}