Remove input C code

This commit is contained in:
Greg Shuflin 2023-08-12 02:35:26 -07:00
parent ed640548a6
commit ea5efdcf69
3 changed files with 2 additions and 98 deletions

View File

@ -17,7 +17,7 @@ CFLAGS ?= -Wextra -Wall -O2
.PHONY: all install uninstall clean .PHONY: all install uninstall clean
nms: $(OBJ)/input.o $(OBJ)/error.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN) nms: $(OBJ)/error.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
$(CC) $(CFLAGS) -o $(BIN)/$@ $^ target/release/libnmsrust.a $(CC) $(CFLAGS) -o $(BIN)/$@ $^ target/release/libnmsrust.a
sneakers: $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN) sneakers: $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)
@ -27,7 +27,7 @@ all: nms sneakers
all-ncurses: nms-ncurses sneakers-ncurses all-ncurses: nms-ncurses sneakers-ncurses
nms-ncurses: $(OBJ)/input.o $(OBJ)/error.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN) nms-ncurses: $(OBJ)/error.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
$(CC) $(CFLAGS) -o $(BIN)/nms $^ -lncursesw target/release/libnmsrust.a $(CC) $(CFLAGS) -o $(BIN)/nms $^ -lncursesw target/release/libnmsrust.a
sneakers-ncurses: $(OBJ)/nmscharset.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN) sneakers-ncurses: $(OBJ)/nmscharset.o $(OBJ)/nmstermio_ncurses.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)

View File

@ -1,83 +0,0 @@
/*
* Copyright (c) 2017 Brian Barto
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GPL License. See LICENSE for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <time.h>
#include <errno.h>
#include "input.h"
#include "error.h"
int input_get(unsigned char** dest, char *prompt)
{
int r, input_len;
fd_set input_stream;
struct timeval timeout;
void *timeout_p;
FD_ZERO(&input_stream);
input_len = 0;
timeout.tv_sec = 10;
timeout.tv_usec = 0;
if (isatty(STDIN_FILENO))
{
timeout_p = NULL;
if (prompt != NULL)
{
printf("%s", prompt);
fflush(stdout);
}
}
else
{
timeout_p = &timeout;
}
FD_SET(STDIN_FILENO, &input_stream);
r = select(FD_SETSIZE, &input_stream, NULL, NULL, timeout_p);
if (r < 0)
{
error_log("Error while waiting for input data. Errno: %i", errno);
return -1;
}
if (r > 0)
{
r = ioctl(STDIN_FILENO, FIONREAD, &input_len);
if (r < 0)
{
error_log("Could not determine length of input. Errno: %i", errno);
return -1;
}
if (input_len > 0)
{
*dest = malloc(input_len);
if (*dest == NULL)
{
error_log("Memory allocation error.");
return -1;
}
r = read(STDIN_FILENO, *dest, input_len);
if (r < 0)
{
error_log("Input read error. Errno: %i", errno);
return -1;
}
}
}
FD_CLR(STDIN_FILENO, &input_stream);
return input_len;
}

View File

@ -1,13 +0,0 @@
/*
* Copyright (c) 2017 Brian Barto
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GPL License. See LICENSE for more details.
*/
#ifndef INPUT_H
#define INPUT_H 1
int input_get(unsigned char** dest, char *prompt);
#endif