diff --git a/src/syncterm/bbslist.c b/src/syncterm/bbslist.c index fc5b0e9fc52693473567f8f504f08f05d31fc057..e2eecf7363b19a1c20324992f06b4a7a0962bf49 100644 --- a/src/syncterm/bbslist.c +++ b/src/syncterm/bbslist.c @@ -9,11 +9,6 @@ #include "uifcinit.h" #include "conn.h" -enum { - USER_BBSLIST - ,SYSTEM_BBSLIST -}; - char *screen_modes[]={"Current", "80x25", "80x28", "80x43", "80x50", "80x60", ""}; void sort_list(struct bbslist **list) { @@ -34,6 +29,15 @@ void sort_list(struct bbslist **list) { } } +void free_list(struct bbslist **list, int listcount) +{ + int i; + + for(i=0;i<listcount;i++) { + free(list[i]); + } +} + /* * Reads in a BBS list from listpath using *i as the counter into bbslist * first BBS read goes into list[i] @@ -303,6 +307,7 @@ struct bbslist *show_bbslist(int mode, char *path) mode=BBSLIST_SELECT; break; case -1: /* ESC */ + free_list(&list[0],listcount); return(NULL); } } @@ -436,6 +441,7 @@ struct bbslist *show_bbslist(int mode, char *path) } else { memcpy(&retlist,list[val],sizeof(struct bbslist)); + free_list(&list[0],listcount); return(&retlist); } } diff --git a/src/syncterm/bbslist.h b/src/syncterm/bbslist.h index b7a7351a0a64428219b22b1bc91ad7078d191337..fbc72245f70aca24aa037be2a04aa62467bc5371 100644 --- a/src/syncterm/bbslist.h +++ b/src/syncterm/bbslist.h @@ -8,6 +8,11 @@ #define MAX_USER_LEN 16 #define MAX_PASSWD_LEN 16 +enum { + USER_BBSLIST + ,SYSTEM_BBSLIST +}; + enum { BBSLIST_SELECT ,BBSLIST_EDIT diff --git a/src/syncterm/syncterm.c b/src/syncterm/syncterm.c index c648d4460668205b2fd57a337814ecd9bd049ff9..95537a2eba9dd8a615b4a70fc9371b2fa7bc346f 100644 --- a/src/syncterm/syncterm.c +++ b/src/syncterm/syncterm.c @@ -52,6 +52,12 @@ int main(int argc, char **argv) char *p3; int i; int ciolib_mode=CIOLIB_MODE_AUTO; + struct bbslist *list[MAX_OPTS+1]; + int listcount=0; + str_list_t inifile; + FILE *listfile; + char listpath[MAX_PATH+1]; + char *home; /* UIFC initialization */ memset(&uifc,0,sizeof(uifc)); @@ -125,12 +131,34 @@ int main(int argc, char **argv) FULLPATH(path,drive,sizeof(path)); atexit(uifcbail); + /* User BBS list path */ + home=getenv("HOME"); + if(home==NULL) + home=getenv("USERPROFILE"); + if(home==NULL) + strcpy(listpath,path); + else + strcpy(listpath,home); + strncat(listpath,"/syncterm.lst",sizeof(listpath)); + if(strlen(listpath)>MAX_PATH) { + fprintf(stderr,"Path to syncterm.lst too long"); + return(0); + } + /* Auto-connect URL */ if(url[0]) { if((bbs=(struct bbslist *)malloc(sizeof(struct bbslist)))==NULL) { uifcmsg("Unable to allocate memory","The system was unable to allocate memory."); return(1); } + bbs->id=-1; + bbs->added=time(NULL); + bbs->calls=0; + bbs->user[0]=0; + bbs->password[0]=0; + bbs->type=USER_BBSLIST; + bbs->reversed=FALSE; + bbs->screen_mode=SCREEN_MODE_CURRENT; if(!strnicmp("rlogin://",url,9)) { bbs->conn_type=CONN_TYPE_RLOGIN; bbs->port=513; @@ -141,12 +169,10 @@ int main(int argc, char **argv) } else goto USAGE; - bbs->user[0]=0; - bbs->password[0]=0; p1=url+9; /* Remove trailing / (Win32 adds one 'cause it hates me) */ p2=strchr(p1,'/'); - if(p2!=NULL); + if(p2!=NULL) *p2=0; p3=strchr(p1,'@'); if(p3!=NULL) { @@ -170,6 +196,20 @@ int main(int argc, char **argv) goto USAGE; } SAFECOPY(bbs->addr,p1); + + /* Find BBS listing in users phone book */ + read_list(listpath, &list[0], &listcount, USER_BBSLIST); + for(i=0;i<listcount;i++) { + if((stricmp(bbs->addr,list[i]->addr)==0) + && (bbs->port==list[i]->port) + && (bbs->conn_type==list[i]->conn_type) + && (bbs->user[0]==0 || (stricmp(bbs->name,list[i]->name)==0)) + && (bbs->password[0]==0 || (stricmp(bbs->password,list[i]->password)==0))) { + memcpy(bbs,list[i],sizeof(struct bbslist)); + break; + } + } + free_list(&list[0],listcount); } if(!winsock_startup()) @@ -179,27 +219,10 @@ int main(int argc, char **argv) if(!conn_connect(bbs->addr,bbs->port,bbs->reversed?bbs->password:bbs->user,bbs->reversed?bbs->user:bbs->password,bbs->conn_type)) { /* ToDo: Update the entry with new lastconnected */ /* ToDo: Disallow duplicate entries */ - str_list_t inifile; - FILE *listfile; - char listpath[MAX_PATH+1]; - char *home; - /* User BBS list */ - home=getenv("HOME"); - if(home==NULL) - home=getenv("USERPROFILE"); - if(home==NULL) - strcpy(listpath,path); - else - strcpy(listpath,home); - strncat(listpath,"/syncterm.lst",sizeof(listpath)); - if(strlen(listpath)>MAX_PATH) { - fprintf(stderr,"Path to syncterm.lst too long"); - return(0); - } bbs->connected=time(NULL); bbs->calls++; - if(!url[0]) { + if(bbs->id != -1) { if((listfile=fopen(listpath,"r"))!=NULL) { inifile=iniReadFile(listfile); fclose(listfile); @@ -239,15 +262,17 @@ int main(int argc, char **argv) settitle("SyncTERM"); } if(url[0]) { - char *YesNo[3]={"Yes","No",""}; - /* Started from the command-line with a URL */ - init_uifc(); - switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Save this BBS in directory?",YesNo)) { - case 0: /* Yes */ - add_bbs(path,bbs); - break; - default: /* ESC/No */ - break; + if(bbs->id==-1) { + char *YesNo[3]={"Yes","No",""}; + /* Started from the command-line with a URL */ + init_uifc(); + switch(uifc.list(WIN_MID|WIN_SAV,0,0,0,&i,NULL,"Save this BBS in directory?",YesNo)) { + case 0: /* Yes */ + add_bbs(path,bbs); + break; + default: /* ESC/No */ + break; + } } free(bbs); bbs=NULL;