First commit to this server

This commit is contained in:
Tim O\'Neil committed 2025-08-19 07:49:22 -07:00
1 parent ec05d3601a
commit cce6f6b9c6
44 files changed
+5529 -296

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
#ifndef _TCONFIG_H_
#define _TCONFIG_H_
#include <stdbool.h>
typedef struct ini_entry_s {
char* key;
char* value;
} ini_entry_s;
typedef struct ini_section_s {
char* name;
ini_entry_s* entry;
int size;
} ini_section_s;
typedef struct ini_table_s {
ini_section_s* section;
int size;
} ini_table_s;
/**
* @brief Creates an empty ini_table_s struct for writing new entries to.
* @return ini_table_s*
*/
ini_table_s* ini_table_create();
/**
* @brief Free up all the allocated resources in the ini_table_s struct.
* @param table
*/
void ini_table_destroy(ini_table_s* table);
/**
* @brief Creates an ini_table_s struct filled with data from the specified
* `file'. Returns NULL if the file can not be read.
* @param table
* @param file
* @return ini_table_s*
*/
bool ini_table_read_from_file(ini_table_s* table, const char* file);
/**
* @brief Writes the specified ini_table_s struct to the specified `file'.
* Returns false if the file could not be opened for writing, otherwise
* true.
* @param table
* @param file
* @return bool
*/
bool ini_table_write_to_file(ini_table_s* table, const char* file);
/**
* @brief Creates a new entry in the `table' containing the `key' and `value'
* provided if it does not exist. Otherwise, modifies an exsiting `key'
* with the new `value'
* @param table
* @param section_name
* @param key
* @param value
*/
void ini_table_create_entry(ini_table_s* table, const char* section_name,
const char* key, const char* value);
/**
* @brief Checks for the existance of an entry in the specified `table'. Returns
* false if the entry does not exist, otherwise true.
* @param table
* @param section_name
* @param key
* @return bool
*/
bool ini_table_check_entry(ini_table_s* table, const char* section_name,
const char* key);
/**
* @brief Retrieves the unmodified value of the specified `key' in `section_name'.
* Returns NULL if the entry does not exist, otherwise a pointer to the
* entry value data.
* @param table
* @param section_name
* @param key
* @return const char*
*/
const char* ini_table_get_entry(ini_table_s* table, const char* section_name,
const char* key);
/**
* @brief Retrieves the value of the specified `key' in `section_name', converted
* to int. Returns false on failure, otherwise true.
* @param table
* @param section_name
* @param key
* @param [out]value
* @return int
*/
bool ini_table_get_entry_as_int(ini_table_s* table, const char* section_name,
const char* key, int* value);
/**
* @brief Retrieves the value of the specified `key' in `section_name', converted
* to bool. Returns false on failure, true otherwise.
* @param table
* @param section_name
* @param key
* @param [out]value
* @return bool
*/
bool ini_table_get_entry_as_bool(ini_table_s* table, const char* section_name,
const char* key, bool* value);
#endif//_TCONFIG_H_
+51
View File
@@ -0,0 +1,51 @@
#pragma once
#include <sys/types.h>
#include <stdlib.h>
#include <utils/filesys.h>
#include <sys/stat.h>
#include <stdbool.h>
#include <stdio.h>
#ifndef _MSC_VER
#include <pwd.h>
#include <unistd.h>
#else
#include <io.h>
#include <Shlobj.h>
#endif
#include "support.h"
#include "simple_strlib.h"
#include "error_info.h"
#define MAXSIZE 256
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file filesys.h
* @author Tim O'Neil
* @date 3/9/2018
*
* @brief System-specific & near system-specific utilities
*
* @section DESCRIPTION
*
* Collection of functions that will be more system specific
* and non-portable (mostly file systems utils and such).
*/
int find_cfgfile(const char*, char*, bool);
int create_cfgfile(const char*);
void get_userdir(char*);
int write_motd(char*, const char*);
int read_motd(const char*);
const char* get_keyvalue(const char*, const char*);
int set_keyvalue(const char*, const char*);
bool file_exists(const char*);
#ifdef __cplusplus
}
#endif
+84
View File
@@ -0,0 +1,84 @@
/* A minimal POSIX getopt() implementation in ANSI C
*
* This is free and unencumbered software released into the public domain.
*
* This implementation supports the convention of resetting the option
* parser by assigning optind to 0. This resets the internal state
* appropriately.
*
* Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html
*/
#ifndef GETOPT_H
#define GETOPT_H
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int optind;
int opterr = 1;
int optopt;
char *optarg;
int
getopt(int argc, char * const argv[], const char *optstring)
{
static int optpos = 1;
const char *arg;
/* Reset? */
if (optind == 0) {
optind = !!argc;
optpos = 1;
}
arg = argv[optind];
if (arg && strcmp(arg, "--") == 0) {
optind++;
return -1;
} else if (!arg || arg[0] != '-' || !isalnum(arg[1])) {
return -1;
} else {
const char *opt = strchr(optstring, arg[optpos]);
optopt = arg[optpos];
if (!opt) {
if (opterr && *optstring != ':')
fprintf(stderr, "%s: illegal option: %c\n", argv[0], optopt);
if (!arg[++optpos]) {
optind++;
optpos = 1;
}
return '?';
} else if (opt[1] == ':') {
if (arg[optpos + 1]) {
optarg = (char *)arg + optpos + 1;
optind++;
optpos = 1;
return optopt;
} else if (argv[optind + 1]) {
optarg = (char *)argv[optind + 1];
optind += 2;
optpos = 1;
return optopt;
} else {
if (opterr && *optstring != ':')
fprintf(stderr,
"%s: option requires an argument: %c\n",
argv[0], optopt);
if (!arg[++optpos]) {
optind++;
optpos = 1;
}
return *optstring == ':' ? ':' : '?';
}
} else {
if (!arg[++optpos]) {
optind++;
optpos = 1;
}
return optopt;
}
}
}
#endif
+66
View File
@@ -0,0 +1,66 @@
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/**
* @file huff.h
* @author Tim O'Neil
* @date 3/9/2018
*
* @brief Probably pretty portable Huffman coder
*
* @section DESCRIPTION
*
* Huffman ecoder to compress large blobs of text and anything
* meant to be read only through an application UI. This file
* defines some necessary structs and such. See the implementation
* file for more details.
*/
typedef struct node
{
char c;
int freq;
struct node *link;
struct node *rlink;
struct node *llink;
} node_t;
typedef struct List
{
node_t *head;
} List_t;
typedef struct
{
unsigned char c : 8;
} code_generated;
typedef struct
{
int freq;
unsigned char ch;
} info;
void decode(const char*);
void encode(const char*, char*);
void insert_in_list(List_t*, node_t*);
void init_list(List_t *ptr);
void disp_list(const List_t*);
void make_node(List_t*, int, char);
void make_list(List_t*, int*);
void find_freq(char*, int*);
void make_tree(List_t*, int*);
void find_code(node_t*, char*, char codes[256][40]);
void compress(char*, FILE*, char codes[256][40], int, info*, int*, int num);
unsigned char convert_string_char(char string[8]);
int find_no_of_chars(int*);
void strre(char*, int);
node_t* decode_char(FILE*, node_t*, int, int, node_t*, int*, int);
int create_header(int*, int, info*);