Commit d335eac9 authored by deuce's avatar deuce
Browse files

Move font functions into separate file, Add program settings menu.

parent 19f5b5fb
......@@ -162,11 +162,7 @@ int edit_list(struct bbslist *item,char *listpath,int isdefault)
fclose(listfile);
}
else {
if((listfile=fopen(listpath,"w"))==NULL)
return(0);
fclose(listfile);
if((listfile=fopen(listpath,"r"))==NULL)
return(0);
inifile=strListInit();
}
if(isdefault)
......@@ -490,331 +486,58 @@ void del_bbs(char *listpath, struct bbslist *bbs)
}
}
void free_font_files(struct font_files *ff)
{
int i;
if(ff==NULL)
return;
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);
FREE_AND_NULL(ff[i].path8x16);
}
FREE_AND_NULL(ff);
}
void save_font_files(struct font_files *fonts)
void change_settings(void)
{
FILE *inifile;
char inipath[MAX_PATH];
char newfont[MAX_PATH];
char *fontid;
str_list_t ini_file;
str_list_t fontnames;
int i;
FILE *inifile;
str_list_t inicontents;
char opts[3][80];
char *opt[3];
int i,j;
get_syncterm_filename(inipath, sizeof(inipath), SYNCTERM_PATH_INI, FALSE);
if((inifile=fopen(inipath,"r"))!=NULL) {
ini_file=iniReadFile(inifile);
inicontents=iniReadFile(inifile);
fclose(inifile);
}
else {
ini_file=strListInit();
}
fontnames=iniGetSectionList(ini_file, "Font:");
/* TODO: Remove all sections... we don't *NEED* to do this */
while((fontid=strListPop(&fontnames))!=NULL) {
iniRemoveSection(&ini_file, 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)
iniSetString(&ini_file, newfont, "Path8x8", fonts[i].path8x8, &ini_style);
if(fonts[i].path8x14)
iniSetString(&ini_file, newfont, "Path8x14", fonts[i].path8x14, &ini_style);
if(fonts[i].path8x16)
iniSetString(&ini_file, newfont, "Path8x16", fonts[i].path8x16, &ini_style);
}
}
if((inifile=fopen(inipath,"w"))!=NULL) {
iniWriteFile(inifile,ini_file);
fclose(inifile);
}
else {
uifc.msg("Cannot write to the .ini file!");
}
strListFreeStrings(fontnames);
strListFreeStrings(ini_file);
}
struct font_files *read_font_files(int *count)
{
FILE *inifile;
char inipath[MAX_PATH];
char fontpath[MAX_PATH];
char *fontid;
str_list_t fonts;
struct font_files *ret=NULL;
struct font_files *tmp=NULL;
*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=strListPop(&fonts))!=NULL) {
if(!fontid[5])
continue;
(*count)++;
tmp=(struct font_files *)realloc(ret, sizeof(struct font_files)*(*count+1));
if(tmp==NULL) {
count--;
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","",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);
}
fclose(inifile);
strListFreeStrings(fonts);
return(ret);
}
void load_font_files(void)
{
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)
FREE_AND_NULL(conio_fontdata[nextfont].eight_by_sixteen);
if(conio_fontdata[nextfont].eight_by_fourteen)
FREE_AND_NULL(conio_fontdata[nextfont].eight_by_fourteen);
if(conio_fontdata[nextfont].eight_by_sixteen)
FREE_AND_NULL(conio_fontdata[nextfont].eight_by_eight);
if(conio_fontdata[nextfont].desc)
FREE_AND_NULL(conio_fontdata[nextfont].desc);
if(ff[i].name)
conio_fontdata[nextfont].desc=strdup(ff[i].name);
else
continue;
if(ff[i].path8x8) {
if((fontfile=fopen(ff[i].path8x8,"r"))!=NULL) {
if((fontdata=(char *)malloc(2048))!=NULL) {
if(fread(fontdata, 1, 2048, fontfile)==2048) {
conio_fontdata[nextfont].eight_by_eight=fontdata;
}
else {
free(fontdata);
}
}
}
}
if(ff[i].path8x14) {
if((fontfile=fopen(ff[i].path8x14,"r"))!=NULL) {
if((fontdata=(char *)malloc(3584))!=NULL) {
if(fread(fontdata, 1, 3584, fontfile)==3584) {
conio_fontdata[nextfont].eight_by_fourteen=fontdata;
}
else {
free(fontdata);
}
}
}
}
if(ff[i].path8x16) {
if((fontfile=fopen(ff[i].path8x16,"r"))!=NULL) {
if((fontdata=(char *)malloc(4096))!=NULL) {
if(fread(fontdata, 1, 4096, fontfile)==4096) {
conio_fontdata[nextfont].eight_by_sixteen=fontdata;
}
else {
free(fontdata);
}
}
}
}
nextfont++;
inicontents=strListInit();
}
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;
}
}
font_names[i]="";
}
int find_font_id(char *name)
{
int ret=0;
int i;
for(i=0; i<256; i++) {
if(!conio_fontdata[i].desc)
continue;
if(!strcmp(conio_fontdata[i].desc,name)) {
ret=i;
break;
}
}
}
void font_management(void)
{
int i,j;
int cur=0;
int bar=0;
int fcur=0;
int fbar=0;
int count=0;
int size=0;
struct font_files *fonts;
char *opt[256];
char opts[5][80];
struct font_files *tmp=NULL;
char str[128];
fonts=read_font_files(&count);
opts[4][0]=0;
for(i=0; i<3; i++)
opt[i]=opts[i];
i=0;
opts[2][0]=0;
for(;;) {
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"
"8x8, 8x14, and 8x16.";
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];
}
i=uifc.list(WIN_SAV|WIN_INS|WIN_INSACT|WIN_DEL|WIN_XTR,0,0,0,&cur,&bar,"Font",opt);
if(i==-1) {
save_font_files(fonts);
free_font_files(fonts);
return;
}
for(;;) {
char *fontmask;
int show_filepick=0;
char **path;
if(i&MSK_DEL) {
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-1));
count--;
break;
}
if(i&MSK_INS) {
str[0]=0;
if(uifc.input(WIN_SAV|WIN_MID,0,0,"Font Name",str,50,0)==-1)
break;
count++;
tmp=(struct font_files *)realloc(fonts, sizeof(struct font_files)*(count+1));
if(tmp==NULL) {
uifc.msg("realloc() failure, cannot add font.");
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;
}
for(i=0; i<5; i++)
opt[i]=opts[i];
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_INS|WIN_DEL,0,0,0,&fcur,&fbar,"Font",opt);
if(i==-1)
sprintf(opts[0],"Confirm Program Exit: %s",settings.confirm_close?"Yes":"No");
sprintf(opts[1],"Startup Video Mode: %s",screen_modes[settings.startup_mode]);
switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Program Settings",opt)) {
case -1:
goto write_ini;
case 0:
settings.confirm_close=!settings.confirm_close;
iniSetBool(&inicontents,"SyncTERM","ConfirmClose",settings.confirm_close,&ini_style);
break;
switch(i) {
case 0:
SAFECOPY(str,fonts[cur].name);
free(fonts[cur].name);
uifc.input(WIN_SAV|WIN_MID,0,0,"Font Name",str,50,K_EDIT);
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;
break;
case 2:
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;
break;
}
if(show_filepick) {
int result;
struct file_pick fpick;
char *savbuf;
struct text_info ti;
gettextinfo(&ti);
savbuf=(char *)malloc((ti.screenheight-2)*ti.screenwidth*2);
if(savbuf==NULL) {
uifc.msg("malloc() failure.");
continue;
}
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(*path);
*(path)=strdup(fpick.selected[0]);
case 1:
j=settings.startup_mode;
for(;;) {
switch(uifc.list(WIN_SAV,0,0,0,&j,NULL,"Startup Video Mode",screen_modes)) {
case -1:
continue;
default:
settings.startup_mode=j;
iniSetInteger(&inicontents,"SyncTERM","VideoMode",settings.startup_mode,&ini_style);
break;
}
}
filepick_free(&fpick);
puttext(1,2,ti.screenwidth,ti.screenheight-1,savbuf);
free(savbuf);
}
}
}
write_ini:
if((inifile=fopen(inipath,"w"))!=NULL) {
iniWriteFile(inifile,inicontents);
fclose(inifile);
}
}
/*
......@@ -844,7 +567,7 @@ struct bbslist *show_bbslist(int mode)
,"Program Settings"
,""
};
int settings=0;
int at_settings=0;
struct mouse_event mevent;
struct bbslist defaults;
char shared_list[MAX_PATH];
......@@ -865,8 +588,8 @@ struct bbslist *show_bbslist(int mode)
uifc.list(WIN_T2B|WIN_RHT|WIN_IMM|WIN_INACT
,0,0,0,&sopt,&sbar,"SyncTERM Settings",settings_menu);
for(;;) {
if (!settings) {
for(;!settings;) {
if (!at_settings) {
for(;!at_settings;) {
uifc.helpbuf= "`SyncTERM Dialing Directory`\n\n"
"Commands:\n\n"
"~ CTRL-D ~ Quick-dial a URL\n"
......@@ -898,7 +621,7 @@ struct bbslist *show_bbslist(int mode)
uifc.list((listcount<MAX_OPTS?WIN_XTR:0)
|WIN_T2B|WIN_IMM|WIN_INACT
,0,0,0,&opt,&bar,mode==BBSLIST_SELECT?"Directory":"Edit",(char **)list);
settings=!settings;
at_settings=!at_settings;
break;
case -7: /* CTRL-E */
#ifdef PCM
......@@ -932,10 +655,8 @@ struct bbslist *show_bbslist(int mode)
}
break;
case -1: /* ESC */
#ifdef PCM
if(!confirm("Are you sure you want to exit?",NULL))
if(settings.confirm_close && !confirm("Are you sure you want to exit?",NULL))
continue;
#endif
free_list(&list[0],listcount);
return(NULL);
}
......@@ -1062,7 +783,7 @@ struct bbslist *show_bbslist(int mode)
}
}
else {
for(;settings;) {
for(;at_settings;) {
uifc.helpbuf= "`SyncTERM Settings Menu`\n\n";
if(oldopt != -2)
settitle(syncterm_version);
......@@ -1075,13 +796,11 @@ struct bbslist *show_bbslist(int mode)
case -11: /* TAB */
uifc.list(WIN_T2B|WIN_RHT|WIN_IMM|WIN_INACT
,0,0,0,&sopt,&sbar,"SyncTERM Settings",settings_menu);
settings=!settings;
at_settings=!at_settings;
break;
case -1: /* ESC */
#ifdef PCM
if(!confirm("Are you sure you want to exit?",NULL))
if(settings.confirm_close && !confirm("Are you sure you want to exit?",NULL))
continue;
#endif
free_list(&list[0],listcount);
return(NULL);
case 0: /* Edit default connection settings */
......@@ -1145,7 +864,7 @@ struct bbslist *show_bbslist(int mode)
font_management();
break;
case 4: /* Program settings */
uifc.msg("This section not yet functional");
change_settings();
break;
}
}
......
......@@ -6,6 +6,7 @@
#include <stdio.h> /* FILE * */
#include "gen_defs.h"
#include "dirwrap.h" /* MAX_PATH */
#include "ini_file.h"
#include <time.h>
#define LIST_NAME_MAX 30
......@@ -58,26 +59,15 @@ struct bbslist {
char font[80];
};
struct font_files {
char *name;
char *path8x8;
char *path8x14;
char *path8x16;
};
struct bbslist *show_bbslist(int mode);
extern char *log_levels[];
extern char *rate_names[];
extern int rates[];
extern ini_style_t ini_style;
void read_item(FILE *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 get_rate_num(int rate);
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);
#endif
#include <stdio.h>
#include <string.h>
#include "gen_defs.h"
#include "ini_file.h"
#include "ciolib.h"
#include "allfonts.h"
#include "uifc.h"
#include "filepick.h"
#include "bbslist.h"
#include "fonts.h"
#include "syncterm.h"
#include "uifcinit.h"
void free_font_files(struct font_files *ff)
{
int i;
if(ff==NULL)
return;
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);
FREE_AND_NULL(ff[i].path8x16);
}
FREE_AND_NULL(ff);
}
void save_font_files(struct font_files *fonts)
{
FILE *inifile;
char inipath[MAX_PATH];
char newfont[MAX_PATH];
char *fontid;
str_list_t ini_file;
str_list_t fontnames;
int i;
get_syncterm_filename(inipath, sizeof(inipath), SYNCTERM_PATH_INI, FALSE);
if((inifile=fopen(inipath,"r"))!=NULL) {
ini_file=iniReadFile(inifile);
fclose(inifile);
}
else {
ini_file=strListInit();
}
fontnames=iniGetSectionList(ini_file, "Font:");
/* TODO: Remove all sections... we don't *NEED* to do this */
while((fontid=strListPop(&fontnames))!=NULL) {
iniRemoveSection(&ini_file, 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)
iniSetString(&ini_file, newfont, "Path8x8", fonts[i].path8x8, &ini_style);
if(fonts[i].path8x14)
iniSetString(&ini_file, newfont, "Path8x14", fonts[i].path8x14, &ini_style);
if(fonts[i].path8x16)
iniSetString(&ini_file, newfont, "Path8x16", fonts[i].path8x16, &ini_style);
}
}
if((inifile=fopen(inipath,"w"))!=NULL) {
iniWriteFile(inifile,ini_file);
fclose(inifile);
}
else {
uifc.msg("Cannot write to the .ini file!");
}
strListFreeStrings(fontnames);
strListFreeStrings(ini_file);
}
struct font_files *read_font_files(int *count)
{
FILE *inifile;
char inipath[MAX_PATH];
char fontpath[MAX_PATH];
char *fontid;
str_list_t fonts;
struct font_files *ret=NULL;
struct font_files *tmp=NULL;
*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=strListPop(&fonts))!=NULL) {
if(!fontid[5])
continue;
(*count)++;
tmp=(struct font_files *)realloc(ret, sizeof(struct font_files)*(*count+1));
if(tmp==NULL) {
count--;
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","",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);
}
fclose(inifile);