commit before cleaning

This commit is contained in:
viandoxdev 2022-08-30 18:45:53 +02:00
parent fd719fc1b1
commit 2297685cd6
No known key found for this signature in database
GPG Key ID: AF1410C5BC10AA25
4 changed files with 39 additions and 30 deletions

View File

@ -1,6 +1,6 @@
Q=@ Q=@
CC=gcc CC=gcc
CFLAGS=-g -Wall -Wno-format-truncation CFLAGS=-g -Wall -Wno-format-truncation -pthread
LDFLAGS= LDFLAGS=
BUILD_DIR=./objects BUILD_DIR=./objects
BIN=jsfw BIN=jsfw

View File

@ -0,0 +1,6 @@
#include<stdint.h>
#include "client.h"
void client_run(char * address, uint16_t port) {
}

View File

@ -1,7 +1,8 @@
// vi: set ft=c // vi: set ft=c
#ifndef CLIENT_H #ifndef CLIENT_H
#define CLIENT_H #define CLIENT_H
#include <stdint.h>
void client_run(char * address, uint16_t port);
#endif #endif

58
main.c
View File

@ -1,68 +1,70 @@
#include<stdio.h> #include <fcntl.h>
#include<sys/ioctl.h> #include <linux/joystick.h>
#include<linux/joystick.h> #include <pthread.h>
#include<stdint.h> #include <stdarg.h>
#include<fcntl.h> #include <stdint.h>
#include<stdlib.h> #include <stdio.h>
#include<string.h> #include <stdlib.h>
#include<stdarg.h> #include <string.h>
#include<unistd.h> #include <sys/ioctl.h>
#include<pthread.h> #include <unistd.h>
#include "main.h" #include "client.h"
#include "hid.h" #include "hid.h"
#include "main.h"
#include "server.h" #include "server.h"
#include "util.h" #include "util.h"
const char* USAGE[] = { const char *USAGE[] = {
"jsfw client [address] [port]\n", "jsfw client [address] [port]\n",
"jsfw server [port]\n", "jsfw server [port]\n",
}; };
const size_t EVENT_SIZE = sizeof(struct js_event); const size_t EVENT_SIZE = sizeof(struct js_event);
uint16_t parse_port(const char * str) { uint16_t parse_port(const char *str) {
long long n = atoll(str); long long n = atoll(str);
if(n <= 0 || n > UINT16_MAX) if (n <= 0 || n > UINT16_MAX)
panicf("Invalid port: Expected a number in the range 1..%d, got '%s'\n", UINT16_MAX, str); panicf("Invalid port: Expected a number in the range 1..%d, got '%s'\n", UINT16_MAX, str);
return n; return n;
} }
void server(uint16_t port) { void server(uint16_t port) {
printf("Server (port: %u).\n", port); printf("Server (port: %u).\n\n", port);
pthread_t thread; pthread_t thread;
pthread_create(&thread, NULL, hid_thread, NULL); pthread_create(&thread, NULL, hid_thread, NULL);
server_run(port); server_run(port);
} }
void client(char * address, uint16_t port) { void client(char *address, uint16_t port) {
printf("JSFW Client (%s:%d)\n", address, port); printf("Client (%s:%d)\n\n", address, port);
client_run(address, port);
} }
int main(int argc, char* argv[]) { int main(int argc, char *argv[]) {
if(argc < 2) { if (argc < 2) {
printf("Usage: %s", USAGE[0]); printf("Usage: %s", USAGE[0]);
printf(" %s", USAGE[1]); printf(" %s", USAGE[1]);
return 1; return 1;
} }
char* mode = argv[1]; char *mode = argv[1];
if(strcmp(mode, "server") == 0) { if (strcmp(mode, "server") == 0) {
if(argc < 3) if (argc < 3)
panicf("Usage: %s", USAGE[1]); panicf("Usage: %s", USAGE[1]);
uint16_t port = parse_port(argv[2]); uint16_t port = parse_port(argv[2]);
server(port); server(port);
} else if(strcmp(mode, "client") == 0) { } else if (strcmp(mode, "client") == 0) {
if(argc < 4) if (argc < 4)
panicf("Usage: %s", USAGE[0]); panicf("Usage: %s", USAGE[0]);
char * address = argv[2]; char *address = argv[2];
uint16_t port = parse_port(argv[3]); uint16_t port = parse_port(argv[3]);
client(address, port); client(address, port);
} else { } else {