Commits (1)
  • Deucе's avatar
    I can't stand it anymore. · 030c7cf9
    Deucе authored
    Run uncrustify on this mess.
    There's a few small oddities (especially in enums), but this is
    much better.
    030c7cf9
......@@ -9,27 +9,28 @@ enum fonttype {
};
struct StandardFontEntry {
char name[256];
uint16_t height;
uint8_t style;
uint8_t flags;
char name[256];
uint16_t height;
uint8_t style;
uint8_t flags;
};
struct TaggedFontEntry {
char name[254];
uint16_t tags;
uint16_t height;
uint8_t style;
uint8_t flags;
char name[254];
uint16_t tags;
uint16_t height;
uint8_t style;
uint8_t flags;
};
struct FontContentsHeader {
uint16_t type;
uint16_t count;
uint16_t type;
uint16_t count;
};
struct FontList {
struct FontContentsHeader header;
union {
struct StandardFontEntry std;
struct StandardFontEntry tag;
......@@ -37,39 +38,39 @@ struct FontList {
};
#if defined(_WIN32) || defined(__BORLANDC__)
#define PRAGMA_PACK
#define PRAGMA_PACK
#endif
#if defined(PRAGMA_PACK) || defined(__WATCOMC__)
#define _PACK
#define _PACK
#else
#define _PACK __attribute__ ((packed))
#define _PACK __attribute__((packed))
#endif
#if defined(PRAGMA_PACK)
#pragma pack(push,1) /* Disk image structures must be packed */
#pragma pack(push,1) /* Disk image structures must be packed */
#endif
struct _PACK FontHeader {
uint8_t ignore[0x6E];
uint16_t height;
uint8_t style;
uint8_t flags;
uint16_t xsize;
uint16_t baseline; // Distance from top to baseline
uint16_t boldsmear;
uint16_t rc; // Literally a reference count on disk.
uint8_t first;
uint8_t last;
uint32_t dataOffset;
uint16_t modulo;
uint32_t charlocOffset;
uint32_t fontSpaceOffset;
uint32_t kernOffset;
uint8_t ignore[0x6E];
uint16_t height;
uint8_t style;
uint8_t flags;
uint16_t xsize;
uint16_t baseline; // Distance from top to baseline
uint16_t boldsmear;
uint16_t rc; // Literally a reference count on disk.
uint8_t first;
uint8_t last;
uint32_t dataOffset;
uint16_t modulo;
uint32_t charlocOffset;
uint32_t fontSpaceOffset;
uint32_t kernOffset;
};
#if defined(PRAGMA_PACK)
#pragma pack(pop) /* original packing */
#pragma pack(pop) /* original packing */
#endif
#endif
#endif // ifndef AMIGAFONT_H
This diff is collapsed.
......@@ -6,126 +6,159 @@
#define _BBSLIST_H_
#include <stdbool.h>
#include <stdio.h> /* FILE * */
#include <stdio.h> /* FILE * */
#include <time.h>
#include "dirwrap.h" /* MAX_PATH */
#include "gen_defs.h"
#include "dirwrap.h" /* MAX_PATH */
#include "ini_file.h"
#include <time.h>
#if defined(_WIN32)
#include <malloc.h> /* alloca() on Win32 */
#include <malloc.h> /* alloca() on Win32 */
#endif
#include <cterm.h>
#define LIST_NAME_MAX 30
#define LIST_ADDR_MAX 64
#define MAX_USER_LEN 30
#define MAX_PASSWD_LEN 128
#define LIST_NAME_MAX 30
#define LIST_ADDR_MAX 64
#define MAX_USER_LEN 30
#define MAX_PASSWD_LEN 128
#define MAX_SYSPASS_LEN 128
enum {
USER_BBSLIST
,SYSTEM_BBSLIST
USER_BBSLIST
,
SYSTEM_BBSLIST
};
enum {
BBSLIST_SELECT
,BBSLIST_EDIT
BBSLIST_SELECT
,
BBSLIST_EDIT
};
enum {
SCREEN_MODE_CURRENT
,SCREEN_MODE_80X25
,SCREEN_MODE_LCD80X25
,SCREEN_MODE_80X28
,SCREEN_MODE_80X30
,SCREEN_MODE_80X43
,SCREEN_MODE_80X50
,SCREEN_MODE_80X60
,SCREEN_MODE_132X37
,SCREEN_MODE_132x52
,SCREEN_MODE_132X25
,SCREEN_MODE_132X28
,SCREEN_MODE_132X30
,SCREEN_MODE_132X34
,SCREEN_MODE_132X43
,SCREEN_MODE_132X50
,SCREEN_MODE_132X60
,SCREEN_MODE_C64
,SCREEN_MODE_C128_40
,SCREEN_MODE_C128_80
,SCREEN_MODE_ATARI
,SCREEN_MODE_ATARI_XEP80
,SCREEN_MODE_CUSTOM
,SCREEN_MODE_EGA_80X25
,SCREEN_MODE_VGA_80X25
,SCREEN_MODE_TERMINATOR
SCREEN_MODE_CURRENT
,
SCREEN_MODE_80X25
,
SCREEN_MODE_LCD80X25
,
SCREEN_MODE_80X28
,
SCREEN_MODE_80X30
,
SCREEN_MODE_80X43
,
SCREEN_MODE_80X50
,
SCREEN_MODE_80X60
,
SCREEN_MODE_132X37
,
SCREEN_MODE_132x52
,
SCREEN_MODE_132X25
,
SCREEN_MODE_132X28
,
SCREEN_MODE_132X30
,
SCREEN_MODE_132X34
,
SCREEN_MODE_132X43
,
SCREEN_MODE_132X50
,
SCREEN_MODE_132X60
,
SCREEN_MODE_C64
,
SCREEN_MODE_C128_40
,
SCREEN_MODE_C128_80
,
SCREEN_MODE_ATARI
,
SCREEN_MODE_ATARI_XEP80
,
SCREEN_MODE_CUSTOM
,
SCREEN_MODE_EGA_80X25
,
SCREEN_MODE_VGA_80X25
,
SCREEN_MODE_TERMINATOR
};
enum {
ADDRESS_FAMILY_UNSPEC
,ADDRESS_FAMILY_INET
,ADDRESS_FAMILY_INET6
ADDRESS_FAMILY_UNSPEC
,
ADDRESS_FAMILY_INET
,
ADDRESS_FAMILY_INET6
};
enum {
RIP_VERSION_NONE
,RIP_VERSION_1
,RIP_VERSION_3
RIP_VERSION_NONE
,
RIP_VERSION_1
,
RIP_VERSION_3
};
/* NOTE: changing this may require updating sort_order in bbslist.c */
struct bbslist {
char name[LIST_NAME_MAX+1];
char addr[LIST_ADDR_MAX+1];
short unsigned int port;
time_t added;
time_t connected;
unsigned int calls;
char user[MAX_USER_LEN+1];
char password[MAX_PASSWD_LEN+1];
char syspass[MAX_SYSPASS_LEN+1];
int type;
int conn_type;
int id;
int screen_mode;
int nostatus;
char dldir[MAX_PATH+1];
char uldir[MAX_PATH+1];
char logfile[MAX_PATH+1];
bool append_logfile;
int xfer_loglevel;
int telnet_loglevel;
int bpsrate;
int music;
int address_family;
char font[80];
int hidepopups;
char ghost_program[9]; /* GHost program can only be 8 chars max. */
int rip;
int flow_control;
char comment[1024];
char name[LIST_NAME_MAX + 1];
char addr[LIST_ADDR_MAX + 1];
short unsigned int port;
time_t added;
time_t connected;
unsigned int calls;
char user[MAX_USER_LEN + 1];
char password[MAX_PASSWD_LEN + 1];
char syspass[MAX_SYSPASS_LEN + 1];
int type;
int conn_type;
int id;
int screen_mode;
int nostatus;
char dldir[MAX_PATH + 1];
char uldir[MAX_PATH + 1];
char logfile[MAX_PATH + 1];
bool append_logfile;
int xfer_loglevel;
int telnet_loglevel;
int bpsrate;
int music;
int address_family;
char font[80];
int hidepopups;
char ghost_program[9]; /* GHost program can only be 8 chars max. */
int rip;
int flow_control;
char comment[1024];
};
extern char *music_names[];
extern char*music_names[];
extern char music_helpbuf[];
struct bbslist *show_bbslist(char *current, int connected);
extern char *log_levels[];
extern char *rate_names[];
extern int rates[];
extern int sortorder[];
struct bbslist *show_bbslist(char*current, int connected);
extern char *log_levels[];
extern char *rate_names[];
extern int rates[];
extern int sortorder[];
extern ini_style_t ini_style;
extern char *screen_modes_enum[];
void read_item(str_list_t listfile, struct bbslist *entry, char *bbsname, int id, int type);
void read_list(char *listpath, struct bbslist **list, struct bbslist *defaults, int *i, int type);
void free_list(struct bbslist **list, int listcount);
void add_bbs(char *listpath, struct bbslist *bbs);
int edit_list(struct bbslist **list, struct bbslist *item,char *listpath,int isdefault);
int get_rate_num(int rate);
cterm_emulation_t get_emulation(struct bbslist *bbs);
extern char *screen_modes_enum[];
void read_item(str_list_t listfile, struct bbslist*entry, char*bbsname, int id, int type);
void read_list(char*listpath, struct bbslist**list, struct bbslist*defaults, int*i, int type);
void free_list(struct bbslist**list, int listcount);
void add_bbs(char*listpath, struct bbslist*bbs);
int edit_list(struct bbslist**list, struct bbslist*item, char*listpath, int isdefault);
int get_rate_num(int rate);
cterm_emulation_t get_emulation(struct bbslist*bbs);
const char *get_emulation_str(cterm_emulation_t emu);
void get_term_size(struct bbslist *bbs, int *cols, int *rows);
void get_term_size(struct bbslist*bbs, int*cols, int*rows);
#endif
#endif // ifndef _BBSLIST_H_
This diff is collapsed.
......@@ -7,71 +7,86 @@
#include <stdbool.h>
#include "bbslist.h"
#include "sockwrap.h"
#include "threadwrap.h"
#include "bbslist.h"
extern char *conn_types[];
extern char *conn_types_enum[];
extern char *conn_types[];
extern char *conn_types_enum[];
extern short unsigned int conn_ports[];
enum {
CONN_TYPE_UNKNOWN
,CONN_TYPE_RLOGIN
,CONN_TYPE_RLOGIN_REVERSED
,CONN_TYPE_TELNET
,CONN_TYPE_RAW
,CONN_TYPE_SSH
,CONN_TYPE_SSHNA
,CONN_TYPE_MODEM
,CONN_TYPE_SERIAL
,CONN_TYPE_SERIAL_NORTS
,CONN_TYPE_SHELL
,CONN_TYPE_MBBS_GHOST
,CONN_TYPE_TELNETS
,CONN_TYPE_TERMINATOR
CONN_TYPE_UNKNOWN
,
CONN_TYPE_RLOGIN
,
CONN_TYPE_RLOGIN_REVERSED
,
CONN_TYPE_TELNET
,
CONN_TYPE_RAW
,
CONN_TYPE_SSH
,
CONN_TYPE_SSHNA
,
CONN_TYPE_MODEM
,
CONN_TYPE_SERIAL
,
CONN_TYPE_SERIAL_NORTS
,
CONN_TYPE_SHELL
,
CONN_TYPE_MBBS_GHOST
,
CONN_TYPE_TELNETS
,
CONN_TYPE_TERMINATOR
};
struct conn_api {
int (*connect)(struct bbslist *bbs);
int (*close)(void);
void (*binary_mode_on)(void);
void (*binary_mode_off)(void);
bool binary_mode;
void *(*rx_parse_cb)(const void* inbuf, size_t inlen, size_t *olen);
void *(*tx_parse_cb)(const void* inbuf, size_t inlen, size_t *olen);
int log_level;
int type;
int nostatus;
int (*connect)(struct bbslist*bbs);
int (*close)(void);
void (*binary_mode_on)(void);
void (*binary_mode_off)(void);
bool binary_mode;
void * (*rx_parse_cb)(const void*inbuf, size_t inlen, size_t*olen);
void * (*tx_parse_cb)(const void*inbuf, size_t inlen, size_t*olen);
int log_level;
int type;
int nostatus;
cterm_emulation_t emulation;
volatile int input_thread_running;
volatile int output_thread_running;
volatile int terminate;
unsigned char *rd_buf;
size_t rd_buf_size;
unsigned char *wr_buf;
size_t wr_buf_size;
volatile int input_thread_running;
volatile int output_thread_running;
volatile int terminate;
unsigned char *rd_buf;
size_t rd_buf_size;
unsigned char *wr_buf;
size_t wr_buf_size;
};
struct conn_buffer {
unsigned char *buf;
size_t bufsize;
size_t buftop;
size_t bufbot;
int isempty;
pthread_mutex_t mutex;
sem_t in_sem;
sem_t out_sem;
unsigned char *buf;
size_t bufsize;
size_t buftop;
size_t bufbot;
int isempty;
pthread_mutex_t mutex;
sem_t in_sem;
sem_t out_sem;
};
/*
* Functions for stuff using connections
*/
int conn_recv_upto(void *buffer, size_t buflen, unsigned int timeout);
int conn_send(const void *buffer, size_t buflen, unsigned int timeout);
int conn_send_raw(const void *buffer, size_t buflen, unsigned int timeout);
int conn_connect(struct bbslist *bbs);
int conn_recv_upto(void*buffer, size_t buflen, unsigned int timeout);
int conn_send(const void*buffer, size_t buflen, unsigned int timeout);
int conn_send_raw(const void*buffer, size_t buflen, unsigned int timeout);
int conn_connect(struct bbslist*bbs);
int conn_close(void);
bool conn_connected(void);
size_t conn_data_waiting(void);
......@@ -82,21 +97,22 @@ void conn_binary_mode_off(void);
* For connection providers
*/
#define BUFFER_SIZE 16384
#define BUFFER_SIZE 16384
extern struct conn_buffer conn_inbuf;
extern struct conn_buffer conn_outbuf;
extern struct conn_api conn_api;
struct conn_buffer *create_conn_buf(struct conn_buffer *buf, size_t size);
void destroy_conn_buf(struct conn_buffer *buf);
size_t conn_buf_bytes(struct conn_buffer *buf);
size_t conn_buf_peek(struct conn_buffer *buf, void *voutbuf, size_t outlen);
size_t conn_buf_get(struct conn_buffer *buf, void *outbuf, size_t outlen);
size_t conn_buf_put(struct conn_buffer *buf, const void *outbuf, size_t outlen);
size_t conn_buf_wait_cond(struct conn_buffer *buf, size_t bcount, unsigned long timeout, int do_free);
#define conn_buf_wait_bytes(buf, count, timeout) conn_buf_wait_cond(buf, count, timeout, 0)
#define conn_buf_wait_free(buf, count, timeout) conn_buf_wait_cond(buf, count, timeout, 1)
int conn_socket_connect(struct bbslist *bbs);
#endif
extern struct conn_api conn_api;
struct conn_buffer *create_conn_buf(struct conn_buffer*buf, size_t size);
void destroy_conn_buf(struct conn_buffer*buf);
size_t conn_buf_bytes(struct conn_buffer*buf);
size_t conn_buf_peek(struct conn_buffer*buf, void*voutbuf, size_t outlen);
size_t conn_buf_get(struct conn_buffer*buf, void*outbuf, size_t outlen);
size_t conn_buf_put(struct conn_buffer*buf, const void*outbuf, size_t outlen);
size_t conn_buf_wait_cond(struct conn_buffer*buf, size_t bcount, unsigned long timeout, int do_free);
#define conn_buf_wait_bytes(buf, count, timeout) conn_buf_wait_cond(buf, count, timeout, 0)
#define conn_buf_wait_free(buf, count, timeout) conn_buf_wait_cond(buf, count, timeout, 1)
int conn_socket_connect(struct bbslist*bbs);
#endif // ifndef _CONN_H_
This diff is collapsed.
......@@ -2,8 +2,7 @@
#ifndef _CONN_PTY_H_
#define _CONN_PTY_H_
int pty_connect(struct bbslist *bbs);
int pty_connect(struct bbslist*bbs);
int pty_close(void);
#endif
......@@ -5,38 +5,39 @@
#include <stdbool.h>
#include <stdlib.h>
#include "bbslist.h"
#include "conn.h"
#include "gen_defs.h"
#include "genwrap.h"
#include "rlogin.h"
#include "sockwrap.h"
#include "threadwrap.h"
#include "bbslist.h"
#include "conn.h"
#include "telnet_io.h"
#include "term.h"
#include "threadwrap.h"
#include "uifcinit.h"
#include "telnet_io.h"
#include "rlogin.h"
extern int telnet_log_level;
extern int telnet_log_level;
/*****************************************************************************/
// Escapes Telnet IACs in 'inbuf' by doubling the IAC char
// 'result' may point to either inbuf (if there were no IACs) or outbuf
// Returns the final byte count of the result
/*****************************************************************************/
static size_t st_telnet_expand(const uchar* inbuf, size_t inlen, uchar* outbuf, size_t outlen, bool expand_cr, uchar** result)
static size_t
st_telnet_expand(const uchar*inbuf, size_t inlen, uchar*outbuf, size_t outlen, bool expand_cr, uchar**result)
{
static bool last_was_lf = false;
BYTE* first_iac = (BYTE*)memchr(inbuf, TELNET_IAC, inlen);
BYTE* first_cr=NULL;
BYTE *first_iac = (BYTE*)memchr(inbuf, TELNET_IAC, inlen);
BYTE *first_cr = NULL;
if (inlen == 0) {
if (result != NULL)
*result = (uchar *)inbuf;
*result = (uchar*)inbuf;
return 0;
}
if (last_was_lf && inbuf[0] == '\n') {
if (last_was_lf && (inbuf[0] == '\n')) {
inbuf++;
inlen--;
}
......@@ -46,7 +47,7 @@ static size_t st_telnet_expand(const uchar* inbuf, size_t inlen, uchar* outbuf,
else
last_was_lf = false;
if (first_iac == NULL && first_cr == NULL) { /* Nothing to expand */
if ((first_iac == NULL) && (first_cr == NULL)) { /* Nothing to expand */
if (result != NULL)
*result = (uchar*)inbuf;
return inlen;
......@@ -54,50 +55,52 @@ static size_t st_telnet_expand(const uchar* inbuf, size_t inlen, uchar* outbuf,
size_t o;
if(first_iac != NULL && (first_cr == NULL || first_iac < first_cr))
if ((first_iac != NULL) && ((first_cr == NULL) || (first_iac < first_cr)))
o = first_iac - inbuf;
else
o = first_cr - inbuf;
memcpy(outbuf, inbuf, o);
for (size_t i = o; i < inlen && o < outlen; i++) {
if (inbuf[i] == '\n' && last_was_lf)
if ((inbuf[i] == '\n') && last_was_lf)
continue;
last_was_lf = false;
if(inbuf[i] == TELNET_IAC)
if (inbuf[i] == TELNET_IAC)
outbuf[o++] = TELNET_IAC;
if(o >= outlen)
if (o >= outlen)
break;
outbuf[o++] = inbuf[i];
if(expand_cr && inbuf[i] == '\r' && o < outlen) {
if (expand_cr && (inbuf[i] == '\r') && (o < outlen)) {
last_was_lf = true;
outbuf[o++] = '\n'; // See RFC5198
}
}
if(result != NULL)
if (result != NULL)
*result = outbuf;
return o;
}
void *telnet_rx_parse_cb(const void *buf, size_t inlen, size_t *olen)
void*
telnet_rx_parse_cb(const void*buf, size_t inlen, size_t*olen)
{
// telnet_interpret() can add up to one byte to inbuf ('\r')
void *ret = malloc(inlen + 1);
// telnet_interpret() can add up to one byte to inbuf ('\r')
void*ret = malloc(inlen + 1);
if (ret == NULL)
return ret;
if (telnet_interpret((BYTE *)buf, inlen, ret, olen) != ret)
if (telnet_interpret((BYTE*)buf, inlen, ret, olen) != ret)
memcpy(ret, buf, *olen);
return ret;
}
void *telnet_tx_parse_cb(const void *buf, size_t len, size_t *olen)
void*
telnet_tx_parse_cb(const void*buf, size_t len, size_t*olen)
{
void *ret = malloc(len * 2);
void *parsed;
void*ret = malloc(len * 2);
void*parsed;
*olen = st_telnet_expand(buf, len, ret, len * 2
,telnet_local_option[TELNET_BINARY_TX]!=TELNET_DO, (BYTE **)&parsed);
, telnet_local_option[TELNET_BINARY_TX] != TELNET_DO, (BYTE**)&parsed);
if (parsed != ret)
memcpy(ret, parsed, *olen);
......@@ -105,41 +108,42 @@ void *telnet_tx_parse_cb(const void *buf, size_t len, size_t *olen)
return ret;
}
int telnet_connect(struct bbslist *bbs)
int
telnet_connect(struct bbslist*bbs)
{
if (!bbs->hidepopups)
init_uifc(true, true);
telnet_log_level = bbs->telnet_loglevel;
rlogin_sock=conn_socket_connect(bbs);
if(rlogin_sock==INVALID_SOCKET)
return(-1);
rlogin_sock = conn_socket_connect(bbs);
if (rlogin_sock == INVALID_SOCKET)
return -1;
if(!create_conn_buf(&conn_inbuf, BUFFER_SIZE))
return(-1);
if(!create_conn_buf(&conn_outbuf, BUFFER_SIZE)) {
if (!create_conn_buf(&conn_inbuf, BUFFER_SIZE))
return -1;
if (!create_conn_buf(&conn_outbuf, BUFFER_SIZE)) {
destroy_conn_buf(&conn_inbuf);
return(-1);
return -1;
}
conn_api.rd_buf=(unsigned char *)malloc(BUFFER_SIZE);
if(!conn_api.rd_buf) {
conn_api.rd_buf = (unsigned char*)malloc(BUFFER_SIZE);
if (!conn_api.rd_buf) {
destroy_conn_buf(&conn_inbuf);
destroy_conn_buf(&conn_outbuf);
return(-1);
return -1;
}
conn_api.rd_buf_size=BUFFER_SIZE;
conn_api.wr_buf=(unsigned char *)malloc(BUFFER_SIZE);
if(!conn_api.wr_buf) {
conn_api.rd_buf_size = BUFFER_SIZE;
conn_api.wr_buf = (unsigned char*)malloc(BUFFER_SIZE);
if (!conn_api.wr_buf) {
FREE_AND_NULL(conn_api.rd_buf);
destroy_conn_buf(&conn_inbuf);
destroy_conn_buf(&conn_outbuf);
return(-1);
return -1;
}
conn_api.wr_buf_size=BUFFER_SIZE;
conn_api.wr_buf_size = BUFFER_SIZE;
memset(telnet_local_option,0,sizeof(telnet_local_option));
memset(telnet_remote_option,0,sizeof(telnet_remote_option));
memset(telnet_local_option, 0, sizeof(telnet_local_option));
memset(telnet_remote_option, 0, sizeof(telnet_remote_option));
conn_api.rx_parse_cb = telnet_rx_parse_cb;
conn_api.tx_parse_cb = telnet_tx_parse_cb;
......@@ -149,17 +153,19 @@ int telnet_connect(struct bbslist *bbs)
if (!bbs->hidepopups)
uifc.pop(NULL);
return(0);
return 0;
}
void telnet_binary_mode_on(void)
void
telnet_binary_mode_on(void)
{
request_telnet_opt(TELNET_DO,TELNET_BINARY_TX);
request_telnet_opt(TELNET_WILL,TELNET_BINARY_TX);
request_telnet_opt(TELNET_DO, TELNET_BINARY_TX);
request_telnet_opt(TELNET_WILL, TELNET_BINARY_TX);
}
void telnet_binary_mode_off(void)
void
telnet_binary_mode_off(void)
{
request_telnet_opt(TELNET_DONT,TELNET_BINARY_TX);
request_telnet_opt(TELNET_WONT,TELNET_BINARY_TX);
request_telnet_opt(TELNET_DONT, TELNET_BINARY_TX);
request_telnet_opt(TELNET_WONT, TELNET_BINARY_TX);
}
......@@ -8,9 +8,10 @@
extern SOCKET telnet_sock;
void telnet_binary_mode_on(void);
void telnet_binary_mode_off(void);
int telnet_connect(struct bbslist *bbs);
void *telnet_rx_parse_cb(const void *buf, size_t inlen, size_t *olen);
void *telnet_tx_parse_cb(const void *buf, size_t len, size_t *olen);
int telnet_connect(struct bbslist*bbs);
void *telnet_rx_parse_cb(const void*buf, size_t inlen, size_t*olen);
void *telnet_tx_parse_cb(const void*buf, size_t len, size_t*olen);
#define telnet_close rlogin_close
#endif
......@@ -3,26 +3,23 @@
#include <stdio.h>
#include <string.h>
#include "gen_defs.h"
#include "ini_file.h"
#include "bbslist.h"
#include "ciolib.h"
#include "uifc.h"
#include "filepick.h"
#include "bbslist.h"
#include "fonts.h"
#include "gen_defs.h"
#include "ini_file.h"
#include "syncterm.h"
#include "uifc.h"
#include "uifcinit.h"
void free_font_files(struct font_files *ff)
void
free_font_files(struct font_files*ff)
{
int i;
int i;
if(ff==NULL)
if (ff == NULL)
return;
for(i=0; ff[i].name != NULL; i++) {
for (i = 0; ff[i].name != NULL; i++) {
FREE_AND_NULL(ff[i].name);
FREE_AND_NULL(ff[i].path8x8);
FREE_AND_NULL(ff[i].path8x14);
......@@ -30,53 +27,53 @@ void free_font_files(struct font_files *ff)
}
free(ff);
}
void save_font_files(struct font_files *fonts)
void
save_font_files(struct font_files*fonts)
{
FILE *inifile;
char inipath[MAX_PATH+1];
char newfont[MAX_PATH+1];
char *fontid;
str_list_t ini_file;
str_list_t fontnames;
int i;
FILE *inifile;
char inipath[MAX_PATH + 1];
char newfont[MAX_PATH + 1];
char *fontid;
str_list_t ini_file;
str_list_t fontnames;
int i;
if(safe_mode)
if (safe_mode)
return;
get_syncterm_filename(inipath, sizeof(inipath), SYNCTERM_PATH_INI, false);
if((inifile=fopen(inipath,"r"))!=NULL) {
ini_file=iniReadFile(inifile);
if ((inifile = fopen(inipath, "r")) != NULL) {
ini_file = iniReadFile(inifile);
fclose(inifile);
}
else {
ini_file=strListInit();
ini_file = strListInit();
}
fontnames=iniGetSectionList(ini_file, "Font:");
fontnames = iniGetSectionList(ini_file, "Font:");
/* TODO: Remove all sections... we don't *NEED* to do this */
while((fontid=strListPop(&fontnames))!=NULL) {
/* TODO: Remove all sections... we don't *NEED* to do this */
while ((fontid = strListPop(&fontnames)) != NULL) {
iniRemoveSection(&ini_file, fontid);
free(fontid);
}
if(fonts != NULL) {
for(i=0; fonts[i].name && fonts[i].name[0]; i++) {
sprintf(newfont,"Font:%s",fonts[i].name);
if(fonts[i].path8x8)
if (fonts != NULL) {
for (i = 0; fonts[i].name && fonts[i].name[0]; i++) {
sprintf(newfont, "Font:%s", fonts[i].name);
if (fonts[i].path8x8)
iniSetString(&ini_file, newfont, "Path8x8", fonts[i].path8x8, &ini_style);
if(fonts[i].path8x14)
if (fonts[i].path8x14)
iniSetString(&ini_file, newfont, "Path8x14", fonts[i].path8x14, &ini_style);
if(fonts[i].path8x16)
if (fonts[i].path8x16)
iniSetString(&ini_file, newfont, "Path8x16", fonts[i].path8x16, &ini_style);
}
}
if((inifile=fopen(inipath,"w"))!=NULL) {
iniWriteFile(inifile,ini_file);
if ((inifile = fopen(inipath, "w")) != NULL) {
iniWriteFile(inifile, ini_file);
fclose(inifile);
}
else {
uifc.helpbuf="There was an error writing the INI file.\nCheck permissions and try again.\n";
uifc.helpbuf = "There was an error writing the INI file.\nCheck permissions and try again.\n";
uifc.msg("Cannot write to the .ini file!");
check_exit(false);
}
......@@ -85,108 +82,102 @@ void save_font_files(struct font_files *fonts)
strListFree(&ini_file);
}
struct font_files *read_font_files(int *count)
struct font_files*
read_font_files(int*count)
{
FILE *inifile;
char inipath[MAX_PATH+1];
char fontpath[MAX_PATH+1];
char *fontid;
str_list_t fonts;
struct font_files *ret=NULL;
struct font_files *tmp;
FILE *inifile;
char inipath[MAX_PATH + 1];
char fontpath[MAX_PATH + 1];
char *fontid;
str_list_t fonts;
struct font_files*ret = NULL;
struct font_files*tmp;
*count=0;
*count = 0;
get_syncterm_filename(inipath, sizeof(inipath), SYNCTERM_PATH_INI, false);
if((inifile=fopen(inipath, "r"))==NULL) {
return(ret);
}
fonts=iniReadSectionList(inifile, "Font:");
while((fontid=strListRemove(&fonts, 0))!=NULL) {
if(!fontid[5]) {
if ((inifile = fopen(inipath, "r")) == NULL)
return ret;
fonts = iniReadSectionList(inifile, "Font:");
while ((fontid = strListRemove(&fonts, 0)) != NULL) {
if (!fontid[5]) {
free(fontid);
continue;
}
(*count)++;
tmp=(struct font_files *)realloc(ret, sizeof(struct font_files)*(*count+1));
if(tmp==NULL) {
tmp = (struct font_files*)realloc(ret, sizeof(struct font_files) * (*count + 1));
if (tmp == NULL) {
count--;
free(fontid);
continue;
}
ret=tmp;
ret[*count].name=NULL;
ret[*count-1].name=strdup(fontid+5);
if((ret[*count-1].path8x8=iniReadString(inifile,fontid,"Path8x8",NULL,fontpath))!=NULL)
ret[*count-1].path8x8=strdup(fontpath);
if((ret[*count-1].path8x14=iniReadString(inifile,fontid,"Path8x14",NULL,fontpath))!=NULL)
ret[*count-1].path8x14=strdup(fontpath);
if((ret[*count-1].path8x16=iniReadString(inifile,fontid,"Path8x16",NULL,fontpath))!=NULL)
ret[*count-1].path8x16=strdup(fontpath);
ret = tmp;
ret[*count].name = NULL;
ret[*count - 1].name = strdup(fontid + 5);
if ((ret[*count - 1].path8x8 = iniReadString(inifile, fontid, "Path8x8", NULL, fontpath)) != NULL)
ret[*count - 1].path8x8 = strdup(fontpath);
if ((ret[*count - 1].path8x14 = iniReadString(inifile, fontid, "Path8x14", NULL, fontpath)) != NULL)
ret[*count - 1].path8x14 = strdup(fontpath);
if ((ret[*count - 1].path8x16 = iniReadString(inifile, fontid, "Path8x16", NULL, fontpath)) != NULL)
ret[*count - 1].path8x16 = strdup(fontpath);
free(fontid);
}
fclose(inifile);
strListFree(&fonts);
return(ret);
return ret;
}
void load_font_files(void)
void
load_font_files(void)
{
int count=0;
int i;
int nextfont=CONIO_FIRST_FREE_FONT;
struct font_files *ff;
FILE *fontfile;
char *fontdata;
int count = 0;
int i;
int nextfont = CONIO_FIRST_FREE_FONT;
struct font_files*ff;
FILE *fontfile;
char *fontdata;
ff=read_font_files(&count);
for(i=0; i<count; i++) {
if(conio_fontdata[nextfont].eight_by_sixteen)
ff = read_font_files(&count);
for (i = 0; i < count; i++) {
if (conio_fontdata[nextfont].eight_by_sixteen)
FREE_AND_NULL(conio_fontdata[nextfont].eight_by_sixteen);
if(conio_fontdata[nextfont].eight_by_fourteen)
if (conio_fontdata[nextfont].eight_by_fourteen)
FREE_AND_NULL(conio_fontdata[nextfont].eight_by_fourteen);
if(conio_fontdata[nextfont].eight_by_eight)
if (conio_fontdata[nextfont].eight_by_eight)
FREE_AND_NULL(conio_fontdata[nextfont].eight_by_eight);
if(conio_fontdata[nextfont].desc)
if (conio_fontdata[nextfont].desc)
FREE_AND_NULL(conio_fontdata[nextfont].desc);
if(ff[i].name)
conio_fontdata[nextfont].desc=strdup(ff[i].name);
if (ff[i].name)
conio_fontdata[nextfont].desc = strdup(ff[i].name);
else
continue;
if(ff[i].path8x8 && ff[i].path8x8[0]) {
if((fontfile=fopen(ff[i].path8x8,"rb"))!=NULL) {
if((fontdata=(char *)malloc(2048))!=NULL) {
if(fread(fontdata, 1, 2048, fontfile)==2048) {
conio_fontdata[nextfont].eight_by_eight=fontdata;
}
else {
if (ff[i].path8x8 && ff[i].path8x8[0]) {
if ((fontfile = fopen(ff[i].path8x8, "rb")) != NULL) {
if ((fontdata = (char*)malloc(2048)) != NULL) {
if (fread(fontdata, 1, 2048, fontfile) == 2048)
conio_fontdata[nextfont].eight_by_eight = fontdata;
else
free(fontdata);
}
}
fclose(fontfile);
}
}
if(ff[i].path8x14 && ff[i].path8x14[0]) {
if((fontfile=fopen(ff[i].path8x14,"rb"))!=NULL) {
if((fontdata=(char *)malloc(3584))!=NULL) {
if(fread(fontdata, 1, 3584, fontfile)==3584) {
conio_fontdata[nextfont].eight_by_fourteen=fontdata;
}
else {
if (ff[i].path8x14 && ff[i].path8x14[0]) {
if ((fontfile = fopen(ff[i].path8x14, "rb")) != NULL) {
if ((fontdata = (char*)malloc(3584)) != NULL) {
if (fread(fontdata, 1, 3584, fontfile) == 3584)
conio_fontdata[nextfont].eight_by_fourteen = fontdata;
else
free(fontdata);
}
}
fclose(fontfile);
}
}
if(ff[i].path8x16 && ff[i].path8x16[0]) {
if((fontfile=fopen(ff[i].path8x16,"rb"))!=NULL) {
if((fontdata=(char *)malloc(4096))!=NULL) {
if(fread(fontdata, 1, 4096, fontfile)==4096) {
conio_fontdata[nextfont].eight_by_sixteen=fontdata;
}
else {
if (ff[i].path8x16 && ff[i].path8x16[0]) {
if ((fontfile = fopen(ff[i].path8x16, "rb")) != NULL) {
if ((fontdata = (char*)malloc(4096)) != NULL) {
if (fread(fontdata, 1, 4096, fontfile) == 4096)
conio_fontdata[nextfont].eight_by_sixteen = fontdata;
else
free(fontdata);
}
}
fclose(fontfile);
}
......@@ -195,185 +186,202 @@ void load_font_files(void)
}
free_font_files(ff);
for(i=0; conio_fontdata[i].desc != NULL; i++) {
font_names[i]=conio_fontdata[i].desc;
if(!strcmp(conio_fontdata[i].desc,"Codepage 437 English")) {
default_font=i;
}
for (i = 0; conio_fontdata[i].desc != NULL; i++) {
font_names[i] = conio_fontdata[i].desc;
if (!strcmp(conio_fontdata[i].desc, "Codepage 437 English"))
default_font = i;
}
/* Set default font */
/* Set default font */
setfont(default_font, false, 0);
font_names[i]="";
font_names[i] = "";
}
int find_font_id(char *name)
int
find_font_id(char*name)
{
int ret=0;
int ret = 0;
int i;
for(i=0; i<256; i++) {
if(!conio_fontdata[i].desc)
for (i = 0; i < 256; i++) {
if (!conio_fontdata[i].desc)
continue;
if(!strcmp(conio_fontdata[i].desc,name)) {
ret=i;
if (!strcmp(conio_fontdata[i].desc, name)) {
ret = i;
break;
}
}
return(ret);
return ret;
}
void font_management(void)
void
font_management(void)
{
int i,j;
int cur=0;
int bar=0;
int fcur=0;
int fbar=0;
int count=0;
struct font_files *fonts;
char *opt[256];
char opts[5][80];
struct font_files *tmp;
char str[128];
int i, j;
int cur = 0;
int bar = 0;
int fcur = 0;
int fbar = 0;
int count = 0;
struct font_files*fonts;
char *opt[256];
char opts[5][80];
struct font_files*tmp;
char str[128];
fonts=read_font_files(&count);
opts[4][0]=0;
fonts = read_font_files(&count);
opts[4][0] = 0;
for(;!quitting;) {
uifc.helpbuf= "`Font Management`\n\n"
"Allows you to add and remove font files to/from the default font set.\n\n"
"`INS` Adds a new font.\n"
"`DEL` Removes an existing font.\n\n"
"Selecting a font allows you to set the files for all three font sizes:\n\n"
"`8x8` Used for screen modes with 35 or more lines and all C64/C128 modes\n"
"`8x14` Used for screen modes with 28 and 34 lines\n"
"`8x16` Used for screen modes with 30 lines or fewer than 28 lines.";
if(fonts) {
for(j=0;fonts[j].name && fonts[j].name[0]; j++)
opt[j]=fonts[j].name;
opt[j]="";
for (; !quitting;) {
uifc.helpbuf = "`Font Management`\n\n"
"Allows you to add and remove font files to/from the default font set.\n\n"
"`INS` Adds a new font.\n"
"`DEL` Removes an existing font.\n\n"
"Selecting a font allows you to set the files for all three font sizes:\n\n"
"`8x8` Used for screen modes with 35 or more lines and all C64/C128 modes\n"
"`8x14` Used for screen modes with 28 and 34 lines\n"
"`8x16` Used for screen modes with 30 lines or fewer than 28 lines.";
if (fonts) {
for (j = 0; fonts[j].name && fonts[j].name[0]; j++)
opt[j] = fonts[j].name;
opt[j] = "";
}
else {
opts[0][0]=0;
opt[0]=opts[0];
opts[0][0] = 0;
opt[0] = opts[0];
}
i=uifc.list(WIN_SAV|WIN_INS|WIN_INSACT|WIN_DEL|WIN_XTR|WIN_ACT,0,0,0,&cur,&bar,"Font Management",opt);
if(i==-1) {
i = uifc.list(WIN_SAV | WIN_INS | WIN_INSACT | WIN_DEL | WIN_XTR | WIN_ACT,
0,
0,
0,
&cur,
&bar,
"Font Management",
opt);
if (i == -1) {
check_exit(false);
save_font_files(fonts);
free_font_files(fonts);
return;
}
for(;!quitting;) {
char *fontmask;
int show_filepick=0;
char **path;
for (; !quitting;) {
char *fontmask;
int show_filepick = 0;
char**path;
if(i&MSK_DEL) {
if (i & MSK_DEL) {
if (fonts) {
FREE_AND_NULL(fonts[cur].name);
FREE_AND_NULL(fonts[cur].path8x8);
FREE_AND_NULL(fonts[cur].path8x14);
FREE_AND_NULL(fonts[cur].path8x16);
memmove(&(fonts[cur]),&(fonts[cur+1]),sizeof(struct font_files)*(count-cur));
memmove(&(fonts[cur]), &(fonts[cur + 1]),
sizeof(struct font_files) * (count - cur));
count--;
}
break;
}
if(i&MSK_INS) {
str[0]=0;
uifc.helpbuf="Enter the name of the font as you want it to appear in menus.";
if(uifc.input(WIN_SAV|WIN_MID,0,0,"Font Name",str,50,0)==-1) {
if (i & MSK_INS) {
str[0] = 0;
uifc.helpbuf = "Enter the name of the font as you want it to appear in menus.";
if (uifc.input(WIN_SAV | WIN_MID, 0, 0, "Font Name", str, 50, 0) == -1) {
check_exit(false);
break;
}
count++;
tmp=(struct font_files *)realloc(fonts, sizeof(struct font_files)*(count+1));
if(tmp==NULL) {
tmp = (struct font_files*)realloc(fonts, sizeof(struct font_files) * (count + 1));
if (tmp == NULL) {
uifc.msg("realloc() failure, cannot add font.");
check_exit(false);
count--;
break;
}
fonts=tmp;
memmove(fonts+cur+1,fonts+cur,sizeof(struct font_files)*(count-cur));
memset(&(fonts[count]),0,sizeof(fonts[count]));
fonts[cur].name=strdup(str);
fonts[cur].path8x8=NULL;
fonts[cur].path8x14=NULL;
fonts[cur].path8x16=NULL;
fonts = tmp;
memmove(fonts + cur + 1, fonts + cur, sizeof(struct font_files) * (count - cur));
memset(&(fonts[count]), 0, sizeof(fonts[count]));
fonts[cur].name = strdup(str);
fonts[cur].path8x8 = NULL;
fonts[cur].path8x14 = NULL;
fonts[cur].path8x16 = NULL;
}
for(i=0; i<5; i++)
opt[i]=opts[i];
uifc.helpbuf="`Font Details`\n\n"
"`8x8` Used for screen modes with 35 or more lines and all C64/C128 modes\n"
"`8x14` Used for screen modes with 28 and 34 lines\n"
"`8x16` Used for screen modes with 30 lines or fewer than 28 lines.";
sprintf(opts[0],"Name: %.50s",fonts[cur].name?fonts[cur].name:"<undefined>");
sprintf(opts[1],"8x8 %.50s",fonts[cur].path8x8?fonts[cur].path8x8:"<undefined>");
sprintf(opts[2],"8x14 %.50s",fonts[cur].path8x14?fonts[cur].path8x14:"<undefined>");
sprintf(opts[3],"8x16 %.50s",fonts[cur].path8x16?fonts[cur].path8x16:"<undefined>");
opts[4][0]=0;
i=uifc.list(WIN_SAV|WIN_ACT|WIN_INS|WIN_INSACT|WIN_DEL|WIN_RHT|WIN_BOT,0,0,0,&fcur,&fbar,"Font Details",opt);
if(i==-1) {
for (i = 0; i < 5; i++)
opt[i] = opts[i];
uifc.helpbuf = "`Font Details`\n\n"
"`8x8` Used for screen modes with 35 or more lines and all C64/C128 modes\n"
"`8x14` Used for screen modes with 28 and 34 lines\n"
"`8x16` Used for screen modes with 30 lines or fewer than 28 lines.";
sprintf(opts[0], "Name: %.50s", fonts[cur].name ? fonts[cur].name : "<undefined>");
sprintf(opts[1], "8x8 %.50s", fonts[cur].path8x8 ? fonts[cur].path8x8 : "<undefined>");
sprintf(opts[2], "8x14 %.50s", fonts[cur].path8x14 ? fonts[cur].path8x14 : "<undefined>");
sprintf(opts[3], "8x16 %.50s", fonts[cur].path8x16 ? fonts[cur].path8x16 : "<undefined>");
opts[4][0] = 0;
i = uifc.list(WIN_SAV | WIN_ACT | WIN_INS | WIN_INSACT | WIN_DEL | WIN_RHT | WIN_BOT,
0,
0,
0,
&fcur,
&fbar,
"Font Details",
opt);
if (i == -1) {
check_exit(false);
break;
}
switch(i) {
switch (i) {
case 0:
SAFECOPY(str,fonts[cur].name);
uifc.helpbuf="Enter the name of the font as you want it to appear\nin menus.";
if (uifc.input(WIN_SAV|WIN_MID,0,0,"Font Name",str,50,K_EDIT)==-1)
SAFECOPY(str, fonts[cur].name);
uifc.helpbuf = "Enter the name of the font as you want it to appear\nin menus.";
if (uifc.input(WIN_SAV | WIN_MID, 0, 0, "Font Name", str, 50, K_EDIT) == -1) {
check_exit(false);
}
else {
FREE_AND_NULL(fonts[cur].name);
fonts[cur].name=strdup(str);
show_filepick=0;
fonts[cur].name = strdup(str);
show_filepick = 0;
}
break;
case 1:
sprintf(str,"8x8 %.50s",fonts[cur].name);
path=&(fonts[cur].path8x8);
fontmask="*.f8";
show_filepick=1;
sprintf(str, "8x8 %.50s", fonts[cur].name);
path = &(fonts[cur].path8x8);
fontmask = "*.f8";
show_filepick = 1;
break;
case 2:
sprintf(str,"8x14 %.50s",fonts[cur].name);
path=&(fonts[cur].path8x14);
fontmask="*.f14";
show_filepick=1;
sprintf(str, "8x14 %.50s", fonts[cur].name);
path = &(fonts[cur].path8x14);
fontmask = "*.f14";
show_filepick = 1;
break;
case 3:
sprintf(str,"8x16 %.50s",fonts[cur].name);
path=&(fonts[cur].path8x16);
fontmask="*.f16";
show_filepick=1;
sprintf(str, "8x16 %.50s", fonts[cur].name);
path = &(fonts[cur].path8x16);
fontmask = "*.f16";
show_filepick = 1;
break;
}
if(show_filepick && !safe_mode) {
int result;
if (show_filepick && !safe_mode) {
int result;
struct file_pick fpick;
struct vmem_cell *savbuf;
struct text_info ti;
struct vmem_cell*savbuf;
struct text_info ti;
gettextinfo(&ti);
savbuf=alloca((ti.screenheight-2)*ti.screenwidth*sizeof(*savbuf));
if(savbuf==NULL) {
uifc.helpbuf="malloc() has failed. Available Memory is dangerously low.";
savbuf = alloca((ti.screenheight - 2) * ti.screenwidth * sizeof(*savbuf));
if (savbuf == NULL) {
uifc.helpbuf = "malloc() has failed. Available Memory is dangerously low.";
uifc.msg("malloc() failure.");
check_exit(false);
continue;
}
vmem_gettext(1,2,ti.screenwidth,ti.screenheight-1,savbuf);
result=filepick(&uifc, str, &fpick, ".", fontmask, UIFC_FP_ALLOWENTRY);
if(result!=-1 && fpick.files>0) {
vmem_gettext(1, 2, ti.screenwidth, ti.screenheight - 1, savbuf);
result = filepick(&uifc, str, &fpick, ".", fontmask, UIFC_FP_ALLOWENTRY);
if ((result != -1) && (fpick.files > 0)) {
FREE_AND_NULL(*path);
*(path)=strdup(fpick.selected[0]);
*(path) = strdup(fpick.selected[0]);
}
else
else {
check_exit(false);
}
filepick_free(&fpick);
vmem_puttext(1,2,ti.screenwidth,ti.screenheight-1,savbuf);
vmem_puttext(1, 2, ti.screenwidth, ti.screenheight - 1, savbuf);
}
}
}
......
......@@ -4,17 +4,17 @@
#define _SYNCTERM_FONTS_H
struct font_files {
char *name;
char *path8x8;
char *path8x14;
char *path8x16;
char*name;
char*path8x8;
char*path8x14;
char*path8x16;
};
void free_font_files(struct font_files *ff);
void save_font_files(struct font_files *fonts);
struct font_files *read_font_files(int *count);
void free_font_files(struct font_files*ff);
void save_font_files(struct font_files*fonts);
struct font_files *read_font_files(int*count);
void load_font_files(void);
int find_font_id(char *name);
int find_font_id(char*name);
void font_management(void);
#endif
#endif // ifndef _SYNCTERM_FONTS_H