Commit 6de4bf9e authored by rswindell's avatar rswindell
Browse files

When cutting and pasting a single sub-board, restore the QWKnet hub

sub-board (if there was one) which pointed to the cut-sub.
parent 25d190c9
......@@ -142,9 +142,9 @@ int export_mdm(char *fname);
int code_ok(char *str);
int bits(long l);
void getar(char *desc, char *ar);
bool new_sub(unsigned new_subnum, unsigned group_num);
bool new_sub(unsigned new_subnum, unsigned group_num, sub_t* pasted_sub);
bool new_qhub_sub(qhub_t*, unsigned qsubnum, sub_t*, unsigned confnum);
void remove_sub(scfg_t*, unsigned subnum);
void remove_sub(scfg_t*, unsigned subnum, bool cut);
void sort_subs(int grpnum);
void sort_dirs(int libnum);
unsigned subs_in_group(unsigned grpnum);
......
......@@ -329,7 +329,7 @@ long import_msg_areas(enum import_list_type type, FILE* stream, unsigned grpnum
return -2;
if(j==cfg.total_subs) {
if(!new_sub(j, grpnum))
if(!new_sub(j, grpnum, /* pasted_sub: */NULL))
return -3;
if(added != NULL)
(*added)++;
......@@ -379,7 +379,7 @@ void msgs_cfg()
static int export_list_type;
char str[256],str2[256],done=0;
char tmp[128];
int j,k,q,s;
int j,k,q;
int i,file;
long ported;
static grp_t savgrp;
......@@ -526,7 +526,7 @@ void msgs_cfg()
if (msk == MSK_DEL) {
for (j = 0; j < cfg.total_subs;) {
if (cfg.sub[j]->grp == grpnum) { /* delete subs of this group */
remove_sub(&cfg, j);
remove_sub(&cfg, j, /* cut: */false);
}
else j++;
}
......
......@@ -33,7 +33,9 @@
#include "scfg.h"
bool new_sub(unsigned new_subnum, unsigned group_num)
static sub_t** cut_qhub_sub;
bool new_sub(unsigned new_subnum, unsigned group_num, sub_t* pasted_sub)
{
sub_t* new_subboard;
if ((new_subboard = (sub_t *)malloc(sizeof(*new_subboard))) == NULL) {
......@@ -41,7 +43,6 @@ bool new_sub(unsigned new_subnum, unsigned group_num)
return false;
}
memset(new_subboard, 0, sizeof(*new_subboard));
new_subboard->grp = group_num;
if (cfg.total_faddrs)
new_subboard->faddr = cfg.faddr[0];
/* ToDo: Define these defaults somewhere else: */
......@@ -58,6 +59,14 @@ bool new_sub(unsigned new_subnum, unsigned group_num)
}
}
new_subboard->misc |= SUB_HDRMOD;
if (pasted_sub != NULL) {
*new_subboard = *pasted_sub;
if (cut_qhub_sub != NULL && (*cut_qhub_sub) == NULL) {
*cut_qhub_sub = new_subboard;
cut_qhub_sub = NULL;
}
}
new_subboard->grp = group_num;
/* Allocate a new (unused) pointer index (deprecated!) */
for (; new_subboard->ptridx < USHRT_MAX; new_subboard->ptridx++) {
......@@ -81,28 +90,27 @@ bool new_sub(unsigned new_subnum, unsigned group_num)
for (unsigned u = cfg.total_subs; u > new_subnum; u--)
cfg.sub[u] = cfg.sub[u - 1];
#if 0 /* no longer necessary */
/* Subs are re-numbered, so adjust QWKnet hub sub lists */
for (unsigned q = 0; q < cfg.total_qhubs; q++)
for (unsigned s = 0; s < cfg.qhub[q]->subs; s++)
if (cfg.qhub[q]->sub[s] >= new_subnum)
cfg.qhub[q]->sub[s]++;
#endif
new_subboard->subnum = new_subnum;
cfg.sub[new_subnum] = new_subboard;
cfg.total_subs++;
return true;
}
void remove_sub(scfg_t* cfg, unsigned subnum)
void remove_sub(scfg_t* cfg, unsigned subnum, bool cut)
{
sub_t* sub = cfg->sub[subnum];
if(cut)
cut_qhub_sub = NULL;
// Remove the sub-board from any QWKnet hub sub-boards
for (unsigned q = 0; q < cfg->total_qhubs; q++) {
for (unsigned s = 0; s < cfg->qhub[q]->subs; s++) {
if (cfg->qhub[q]->sub[s] == sub)
if (cfg->qhub[q]->sub[s] == sub) {
if(cut && cut_qhub_sub == NULL)
cut_qhub_sub = &cfg->qhub[q]->sub[s];
cfg->qhub[q]->sub[s] = NULL;
}
}
}
FREE_AND_NULL(cfg->sub[subnum]);
......@@ -117,7 +125,7 @@ void sub_cfg(uint grpnum)
char str[128],str2[128],done=0,code[128];
char path[MAX_PATH+1];
char data_dir[MAX_PATH+1];
int j,m,n,ptridx;
int j,m,n;
uint i,subnum[MAX_OPTS+1];
static sub_t savsub;
......@@ -265,7 +273,7 @@ void sub_cfg(uint grpnum)
continue;
}
if (!new_sub(subnum[i], grpnum))
if (!new_sub(subnum[i], grpnum, /* pasted_sub: */NULL))
continue;
SAFECOPY(cfg.sub[subnum[i]]->code_suffix,code);
......@@ -307,37 +315,21 @@ void sub_cfg(uint grpnum)
}
if(msk == MSK_CUT)
savsub = *cfg.sub[subnum[i]];
remove_sub(&cfg, subnum[i]);
remove_sub(&cfg, subnum[i], msk == MSK_CUT);
uifc.changes = TRUE;
continue;
}
if(msk==MSK_COPY) {
savsub=*cfg.sub[subnum[i]];
cut_qhub_sub = NULL;
continue;
}
if(msk == MSK_PASTE) {
if (!new_sub(subnum[i], grpnum))
if (!new_sub(subnum[i], grpnum, &savsub))
continue;
ptridx=cfg.sub[subnum[i]]->ptridx;
*cfg.sub[subnum[i]]=savsub;
cfg.sub[subnum[i]]->ptridx=ptridx;
cfg.sub[subnum[i]]->grp=grpnum;
uifc.changes = TRUE;
continue;
}
#if 0
if(msk == MSK_SORT) {
sort_min = subnum[i];
sort_group = grpnum;
qsort(cfg.sub, cfg.total_subs, sizeof(sub_t*), sub_compare);
last_sort_field = sort_field;
sort_field++;
if(sort_field >= SORT_NONE)
sort_field = 0;
uifc.changes = TRUE;
continue;
}
#endif
i=subnum[i];
j=0;
done=0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment