Skip to content
Snippets Groups Projects
Commit f92b03e1 authored by deuce's avatar deuce
Browse files

Replace binary syncterm.lst with an .ini style one.

This is absolutely guarantted to be the very last time you'll need to
delete your syncterm.lst, honest, I promise.
parent 0cababf7
Branches
Tags
No related merge requests found
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <dirwrap.h>
#include <ini_file.h>
#include <uifc.h>
#include "bbslist.h"
......@@ -12,20 +13,6 @@ enum {
,SYSTEM_BBSLIST
};
struct bbslist_file {
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];
int dumb;
int reversed;
char padding[256];
};
void sort_list(struct bbslist **list) {
struct bbslist *tmp;
unsigned int i,swapped=1;
......@@ -44,49 +31,6 @@ void sort_list(struct bbslist **list) {
}
}
void write_list(struct bbslist **list)
{
char *home;
char listpath[MAX_PATH+1];
FILE *listfile;
int i;
struct bbslist_file bbs;
char str[MAX_PATH+1];
home=getenv("HOME");
if(home==NULL)
getcwd(listpath,sizeof(listpath));
else
strcpy(listpath,home);
strncat(listpath,"/",sizeof(listpath));
strncat(listpath,"syncterm.lst",sizeof(listpath));
if(strlen(listpath)>MAX_PATH) {
fprintf(stderr,"Path to syncterm.lst too long");
return;
}
if((listfile=fopen(listpath,"wb"))!=NULL) {
for(i=0;list[i]->name[0];i++) {
strcpy(bbs.name,list[i]->name);
strcpy(bbs.addr,list[i]->addr);
bbs.port=list[i]->port;
bbs.added=list[i]->added;
bbs.connected=list[i]->connected;
bbs.calls=list[i]->calls;
bbs.dumb=list[i]->dumb;
strcpy(bbs.user,list[i]->user);
strcpy(bbs.password,list[i]->password);
fwrite(&bbs,sizeof(bbs),1,listfile);
}
fclose(listfile);
}
else {
uifc.helpbuf= "`Can't save list`\n\n"
"The system is unable to save your dialing list\n";
sprintf(str,"Can't save list to %.*s",MAX_PATH-20,listpath);
uifc.msg(str);
}
}
/*
* Reads in a BBS list from listpath using *i as the counter into bbslist
* first BBS read goes into list[i]
......@@ -94,37 +38,45 @@ void write_list(struct bbslist **list)
void read_list(char *listpath, struct bbslist **list, int *i, int type)
{
FILE *listfile;
struct bbslist_file bbs;
char *bbsname;
str_list_t bbses;
if((listfile=fopen(listpath,"r"))!=NULL) {
while(*i<MAX_OPTS && fread(&bbs,sizeof(bbs),1,listfile)) {
bbses=iniGetSectionList(listfile,NULL);
while((bbsname=strListPop(&bbses))!=NULL) {
if((list[*i]=(struct bbslist *)malloc(sizeof(struct bbslist)))==NULL)
break;
strcpy(list[*i]->name,bbs.name);
strcpy(list[*i]->addr,bbs.addr);
list[*i]->port=bbs.port;
list[*i]->added=bbs.added;
list[*i]->connected=bbs.connected;
list[*i]->calls=bbs.calls;
strcpy(list[*i]->user,bbs.user);
strcpy(list[*i]->password,bbs.password);
list[*i]->dumb=bbs.dumb;
strcpy(list[*i]->name,bbsname);
iniGetString(listfile,bbsname,"Address","",list[*i]->addr);
list[*i]->port=iniGetShortInt(listfile,bbsname,"Port",513);
list[*i]->added=iniGetInteger(listfile,bbsname,"Added",0);
list[*i]->connected=iniGetInteger(listfile,bbsname,"LastConnected",0);
list[*i]->calls=iniGetInteger(listfile,bbsname,"TotalCalls",0);
iniGetString(listfile,bbsname,"UserName","",list[*i]->user);
iniGetString(listfile,bbsname,"Password","",list[*i]->password);
list[*i]->dumb=iniGetBool(listfile,bbsname,"BeDumb",0);
list[*i]->reversed=iniGetBool(listfile,bbsname,"Reversed",0);
list[*i]->type=type;
list[*i]->id=(*i)++;
}
fclose(listfile);
strListFreeStrings(bbses);
}
/* Add terminator */
list[*i]=(struct bbslist *)"";
}
int edit_list(struct bbslist *item)
int edit_list(struct bbslist *item,char *listpath)
{
char opt[8][80];
char *opts[8];
int changed=0;
int copt=0,i,j;
char str[6];
FILE *listfile;
str_list_t inifile;
char tmp[LIST_NAME_MAX+1];
for(i=0;i<8;i++)
opts[i]=opt[i];
......@@ -138,6 +90,12 @@ int edit_list(struct bbslist *item)
return(0);
}
opt[7][0]=0;
if((listfile=fopen(listpath,"r"))!=NULL) {
inifile=iniReadFile(listfile);
fclose(listfile);
}
else
return(0);
for(;;) {
sprintf(opt[0],"BBS Name: %s",item->name);
sprintf(opt[1],"RLogin Address: %s",item->addr);
......@@ -152,17 +110,25 @@ int edit_list(struct bbslist *item)
"Select item to edit.";
switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&copt,NULL,"Edit Entry",opts)) {
case -1:
if((listfile=fopen(listpath,"w"))!=NULL) {
iniWriteFile(listfile,inifile);
fclose(listfile);
}
strListFreeStrings(inifile);
return(changed);
case 0:
uifc.helpbuf= "`BBS Name`\n\n"
"Enter the BBS name as it is to appear in the list.";
strcpy(tmp,item->name);
uifc.input(WIN_MID|WIN_SAV,0,0,"BBS Name",item->name,LIST_NAME_MAX,K_EDIT);
iniRenameSection(&inifile,tmp,item->name);
break;
case 1:
uifc.helpbuf= "`RLogin address`\n\n"
"Enter the domain name of the system to connect to ie:\n"
"nix.synchro.net";
uifc.input(WIN_MID|WIN_SAV,0,0,"RLogin Address",item->addr,LIST_ADDR_MAX,K_EDIT);
iniSetString(&inifile,item->name,"Address",item->addr,NULL);
break;
case 2:
i=item->port;
......@@ -179,6 +145,7 @@ int edit_list(struct bbslist *item)
if(j<1 || j>65535)
j=513;
item->port=j;
iniSetShortInt(&inifile,item->name,"Port",item->port,NULL);
if(i!=j)
uifc.changes=1;
else
......@@ -188,19 +155,23 @@ int edit_list(struct bbslist *item)
uifc.helpbuf= "`Username`\n\n"
"Enter the username to attempt auto-login to the remote with.";
uifc.input(WIN_MID|WIN_SAV,0,0,"Username",item->user,MAX_USER_LEN,K_EDIT);
iniSetString(&inifile,item->name,"UserName",item->user,NULL);
break;
case 4:
uifc.helpbuf= "`Password`\n\n"
"Enter your password for auto-login.";
uifc.input(WIN_MID|WIN_SAV,0,0,"Password",item->password,MAX_PASSWD_LEN,K_EDIT);
iniSetString(&inifile,item->name,"Password",item->password,NULL);
break;
case 5:
item->dumb=!item->dumb;
changed=1;
iniSetBool(&inifile,item->name,"BeDumb",item->dumb,NULL);
break;
case 6:
item->reversed=!item->reversed;
changed=1;
iniSetBool(&inifile,item->name,"Reversed",item->reversed,NULL);
break;
}
if(uifc.changes)
......@@ -208,11 +179,60 @@ int edit_list(struct bbslist *item)
}
}
void add_bbs(char *listpath, struct bbslist *bbs)
{
FILE *listfile;
str_list_t inifile;
if((listfile=fopen(listpath,"r"))!=NULL) {
inifile=iniReadFile(listfile);
fclose(listfile);
}
else {
inifile=strListInit();
}
/*
* Redundant:
* iniAddSection(&inifile,bbs->name,NULL);
*/
iniSetString(&inifile,bbs->name,"Address",bbs->addr,NULL);
iniSetShortInt(&inifile,bbs->name,"Port",bbs->port,NULL);
iniSetInteger(&inifile,bbs->name,"Added",bbs->added,NULL);
iniSetInteger(&inifile,bbs->name,"LastConnected",bbs->connected,NULL);
iniSetInteger(&inifile,bbs->name,"TotalCalls",bbs->calls,NULL);
iniSetString(&inifile,bbs->name,"UserName",bbs->user,NULL);
iniSetString(&inifile,bbs->name,"Password",bbs->password,NULL);
iniSetBool(&inifile,bbs->name,"BeDumb",bbs->dumb,NULL);
iniSetBool(&inifile,bbs->name,"Reversed",bbs->reversed,NULL);
if((listfile=fopen(listpath,"w"))!=NULL) {
iniWriteFile(listfile,inifile);
fclose(listfile);
}
strListFreeStrings(inifile);
}
void del_bbs(char *listpath, struct bbslist *bbs)
{
FILE *listfile;
str_list_t inifile;
if((listfile=fopen(listpath,"r"))!=NULL) {
inifile=iniReadFile(listfile);
fclose(listfile);
iniRemoveSection(&inifile,bbs->name);
if((listfile=fopen(listpath,"w"))!=NULL) {
iniWriteFile(listfile,inifile);
fclose(listfile);
}
strListFreeStrings(inifile);
}
}
/*
* Displays the BBS list and allows edits to user BBS list
* Mode is one of BBSLIST_SELECT or BBSLIST_EDIT
*/
struct bbslist *show_bbslist(int mode)
struct bbslist *show_bbslist(int mode, char *path)
{
char *home;
char listpath[MAX_PATH+1];
......@@ -231,11 +251,12 @@ struct bbslist *show_bbslist(int mode)
/* User BBS list */
home=getenv("HOME");
if(home==NULL)
getcwd(listpath,sizeof(listpath));
home=getenv("USERPROFILE");
if(home==NULL)
strcpy(listpath,path);
else
strcpy(listpath,home);
strncat(listpath,"/",sizeof(listpath));
strncat(listpath,"syncterm.lst",sizeof(listpath));
strncat(listpath,"/syncterm.lst",sizeof(listpath));
if(strlen(listpath)>MAX_PATH) {
fprintf(stderr,"Path to syncterm.lst too long");
return(NULL);
......@@ -351,7 +372,7 @@ struct bbslist *show_bbslist(int mode)
if(list[j]->id==listcount-1)
opt=j;
}
write_list(list);
add_bbs(listpath,list[listcount-1]);
}
break;
case MSK_DEL:
......@@ -371,6 +392,7 @@ struct bbslist *show_bbslist(int mode)
uifc.msg("It's gone, calm down man!");
break;
}
del_bbs(listpath,list[opt]);
free(list[opt]);
for(i=opt;list[i]->name[0];i++) {
list[i]=list[i+1];
......@@ -378,7 +400,6 @@ struct bbslist *show_bbslist(int mode)
for(i=0;list[i]->name[0];i++) {
list[i]->id=i;
}
write_list(list);
listcount--;
break;
}
......@@ -386,9 +407,8 @@ struct bbslist *show_bbslist(int mode)
else {
if(mode==BBSLIST_EDIT) {
i=list[opt]->id;
if(edit_list(list[opt])) {
if(edit_list(list[opt],listpath)) {
sort_list(list);
write_list(list);
for(j=0;list[j]->name[0];j++) {
if(list[j]->id==i)
opt=j;
......
......@@ -28,6 +28,6 @@ struct bbslist {
int reversed;
};
struct bbslist *show_bbslist(int mode);
struct bbslist *show_bbslist(int mode,char *path);
#endif
......@@ -3,8 +3,11 @@ OBJS := ${LIBODIR}/syncterm.${OFILE} \
${LIBODIR}/uifcinit.${OFILE} \
${LIBODIR}/rlogin.${OFILE} \
${LIBODIR}/sockwrap.${OFILE} \
${LIBODIR}/dirwrap.${OFILE} \
${LIBODIR}/filewrap.${OFILE} \
${LIBODIR}/term.${OFILE} \
${LIBODIR}/genwrap.${OFILE} \
${LIBODIR}/ini_file.${OFILE} \
${LIBODIR}/str_list.${OFILE} \
${LIBODIR}/window.${OFILE} \
${LIBODIR}/menu.${OFILE}
#include <stdlib.h>
#include <ciolib.h>
#include <dirwrap.h>
#include "bbslist.h"
#include "rlogin.h"
#include "uifcinit.h"
......@@ -36,18 +38,24 @@ int main(int argc, char **argv)
{
struct bbslist *bbs;
struct text_info txtinfo;
char drive[MAX_PATH];
char path[MAX_PATH];
char fname[MAX_PATH];
char ext[MAX_PATH];
if(!winsock_startup())
return(1);
gettextinfo(&txtinfo);
if((txtinfo.screenwidth<40) || txtinfo.screenheight<24) {
fputs("Window too small, must be at lest 80x24\n",stderr);
fputs("Window too small, must be at least 80x24\n",stderr);
return(1);
}
_splitpath(argv[0],drive,path,fname,ext);
strcat(drive,path);
FULLPATH(path,drive,sizeof(path));
atexit(uifcbail);
while((bbs=show_bbslist(BBSLIST_SELECT))!=NULL) {
while((bbs=show_bbslist(BBSLIST_SELECT,path))!=NULL) {
if(!rlogin_connect(bbs->addr,bbs->port,bbs->reversed?bbs->password:bbs->user,bbs->reversed?bbs->user:bbs->password,bbs->dumb)) {
/* ToDo: Update the entry with new lastconnected */
/* ToDo: Disallow duplicate entries */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment