diff options
Diffstat (limited to 'mbbsd/announce.c')
-rw-r--r-- | mbbsd/announce.c | 226 |
1 files changed, 167 insertions, 59 deletions
diff --git a/mbbsd/announce.c b/mbbsd/announce.c index 950a907d..7d7aaba9 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -1,33 +1,100 @@ /* $Id$ */ #include "bbs.h" -struct CopyTmp { +/* copy temp queue operation -------------------------------------- */ +typedef struct { char copyfile[PATHLEN]; char copytitle[TTLEN + 1]; char copyowner[IDLEN + 2]; -}; -static struct CopyTmp *copytmp; +} CopyQueue ; -void -a_copyitem(const char *fpath, const char *title, const char *owner, int mode) +static CopyQueue *copyqueue; +static int allocated_copyqueue = 0, used_copyqueue = 0, head_copyqueue = 0; + +int copyqueue_testin(CopyQueue *pcq) { - if(copytmp == NULL) { - copytmp = (struct CopyTmp*)malloc(sizeof(struct CopyTmp)); - if(copytmp == NULL) { - if(mode) vmsg("��������"); - return; + int i = 0; + for (i = 0; i < used_copyqueue; i++) + if (strcmp(pcq->copyfile, copyqueue[i].copyfile) == 0) + return 1; + return 0; +} + +void copyqueue_reset() +{ + allocated_copyqueue = 0; + used_copyqueue = 0; + head_copyqueue = 0; +} + +int copyqueue_append(CopyQueue *pcq) +{ + if(copyqueue_testin(pcq)) + return 0; + if(head_copyqueue == used_copyqueue) + { + // empty queue, happy happy reset + head_copyqueue = used_copyqueue = 0; + } + used_copyqueue ++; + + if(used_copyqueue > allocated_copyqueue) + { + allocated_copyqueue = used_copyqueue + 10; // half page + copyqueue = (CopyQueue*) realloc (copyqueue, + sizeof(CopyQueue) * allocated_copyqueue); + if(!copyqueue) + { + vmsg("�O���餣���A��������"); + // try to reset + copyqueue_reset(); + if(copyqueue) free(copyqueue); + copyqueue = NULL; + return 0; } } - memset(copytmp, 0, sizeof(struct CopyTmp)); + memcpy(&(copyqueue[used_copyqueue-1]), pcq, sizeof(CopyQueue)); + return 1; +} - strcpy(copytmp->copyfile, fpath); - strcpy(copytmp->copytitle, title); +CopyQueue *copyqueue_gethead() +{ + if( used_copyqueue <= 0 || + head_copyqueue >= used_copyqueue) + return NULL; + return &(copyqueue[head_copyqueue++]); +} + +int copyqueue_querysize() +{ + if( used_copyqueue <= 0 || + head_copyqueue >= used_copyqueue) + return 0; + return (used_copyqueue - head_copyqueue); +} + +/* end copy temp queue operation ----------------------------------- */ + +void +a_copyitem(const char *fpath, const char *title, const char *owner, int mode) +{ + CopyQueue cq; + memset(&cq, 0, sizeof(CopyQueue)); + strcpy(cq.copyfile, fpath); + strcpy(cq.copytitle, title); if (owner) - strcpy(copytmp->copyowner, owner); - else - *copytmp->copyowner = 0; + strcpy(cq.copyowner, owner); + + copyqueue_append(&cq); if (mode) { - vmsg("�ɮаO�����C[�`�N] ������~��R�����!"); +#if 0 + move(b_lines-2, 0); clrtoeol(); + prints("�ثe�w�аO %d ���ɮסC[�`�N] ������~��R�����!", + copyqueue_querysize()); +#else + vmsg("�ثe�w�ƻs %d �Ӷ��ءC [�`�N] �K�W(p)�Ϊ��[(a)��~��R�����!", + copyqueue_querysize()); +#endif } } @@ -159,7 +226,7 @@ a_showhelp(int level) "[n/g/G] ������ؤ峹/�}�P�ؿ�/�إ߳s�u\n" "[m/d/D] ����/�R���峹/�R���@�ӽd�峹\n" "[f/T/e] �s����D�Ÿ�/�ק�峹���D/���e\n" - "[c/p/a] ����/�߶K/���[�峹\n" + "[c/p/a] ����/�K�W(�i�h�g)/���[��g�峹\n" "[^P/^A] �߶K/���[�w��'t'�аO�峹\n"); } if (level >= SYSOP) { @@ -324,30 +391,70 @@ a_pasteitem(menu_t * pm, int mode) { char newpath[PATHLEN]; char buf[PATHLEN]; - char ans[2]; - int i; + char ans[2], skipAll = 0, multiple = 0; + int i, copied = 0; fileheader_t item; - move(b_lines - 1, 1); - if (copytmp && copytmp->copyfile[0]) { - if (dashd(copytmp->copyfile)) { - for (i = 0; copytmp->copyfile[i] && copytmp->copyfile[i] == pm->path[i]; i++); - if (!copytmp->copyfile[i]) { + CopyQueue *cq; + + move(b_lines - 1, 0); + if(copyqueue_querysize() <= 0) + { + vmsg("�Х�����ƻs(copy)�R�O��A�K�W(paste)"); + return; + } + if(mode && copyqueue_querysize() > 1) + { + multiple = 1; + move(b_lines-2, 0); clrtobot(); + outs("c: ��U���حӧO�T�{�O�_�n�K�W, z: �������K�A�P�ɭ��]�è��������аO\n"); + snprintf(buf, sizeof(buf), + "�T�w�n�K�W�����@ %d �Ӷ��ض� (c/z/y/N)�H ", + copyqueue_querysize()); + getdata(b_lines - 1, 0, buf, ans, sizeof(ans), LCECHO); + if(ans[0] == 'y') + skipAll = 1; + else if(ans[0] == 'z') + { + copyqueue_reset(); + vmsg("�w���]�ƻs�O���C"); + return; + } + else if (ans[0] != 'c') + return; + clear(); + } + while (copyqueue_querysize() > 0) + { + cq = copyqueue_gethead(); + if(!cq->copyfile[0]) + continue; + if(mode && multiple) + { + scroll(); + move(b_lines-2, 0); clrtobot(); + prints("%d. %s\n", ++copied,cq->copytitle); + + } + + if (dashd(cq->copyfile)) { + for (i = 0; cq->copyfile[i] && cq->copyfile[i] == pm->path[i]; i++); + if (!cq->copyfile[i]) { vmsg("�N�ؿ����i�ۤv���l�ؿ����A�|�y���L�a�j��I"); - return; + continue; } } - if (mode) { + if (mode && !skipAll) { snprintf(buf, sizeof(buf), - "�T�w�n����[%s]��(Y/N)�H[N] ", copytmp->copytitle); - getdata(b_lines - 1, 1, buf, ans, sizeof(ans), LCECHO); + "�T�w�n����[%s]��(Y/N)�H[N] ", cq->copytitle); + getdata(b_lines - 1, 0, buf, ans, sizeof(ans), LCECHO); } else ans[0] = 'y'; if (ans[0] == 'y') { strlcpy(newpath, pm->path, sizeof(newpath)); - if (*copytmp->copyowner) { - char *fname = strrchr(copytmp->copyfile, '/'); + if (*cq->copyowner) { + char *fname = strrchr(cq->copyfile, '/'); if (fname) strcat(newpath, fname); @@ -357,30 +464,27 @@ a_pasteitem(menu_t * pm, int mode) mkdir(pm->path, 0755); memset(&item, 0, sizeof(fileheader_t)); strlcpy(item.filename, fname + 1, sizeof(item.filename)); - memcpy(copytmp->copytitle, "��", 2); - Copy(copytmp->copyfile, newpath); - } else if (dashf(copytmp->copyfile)) { + memcpy(cq->copytitle, "��", 2); + Copy(cq->copyfile, newpath); + } else if (dashf(cq->copyfile)) { stampfile(newpath, &item); - memcpy(copytmp->copytitle, "��", 2); - Copy(copytmp->copyfile, newpath); - } else if (dashd(copytmp->copyfile)) { + memcpy(cq->copytitle, "��", 2); + Copy(cq->copyfile, newpath); + } else if (dashd(cq->copyfile)) { stampdir(newpath, &item); - memcpy(copytmp->copytitle, "��", 2); - copy_file(copytmp->copyfile, newpath); + memcpy(cq->copytitle, "��", 2); + copy_file(cq->copyfile, newpath); } else { - outs("�L�k�����I"); - igetch(); + copyqueue_reset(); + vmsg("�L�k�����I"); return; } - strlcpy(item.owner, *copytmp->copyowner ? copytmp->copyowner : cuser.userid, + strlcpy(item.owner, *cq->copyowner ? cq->copyowner : cuser.userid, sizeof(item.owner)); - strlcpy(item.title, copytmp->copytitle, sizeof(item.title)); + strlcpy(item.title, cq->copytitle, sizeof(item.title)); a_additem(pm, &item); - copytmp->copyfile[0] = '\0'; + cq->copyfile[0] = '\0'; } - } else { - outs("�Х����� copy �R�O��A paste"); - igetch(); } } @@ -393,19 +497,28 @@ a_appenditem(const menu_t * pm, int isask) FILE *fp, *fin; move(b_lines - 1, 1); - if (copytmp && copytmp->copyfile[0]) { - if (dashf(copytmp->copyfile)) { + if(copyqueue_querysize() <= 0) + { + vmsg("�Х����� copy �R�O��A append"); + copyqueue_reset(); + return; + } + else + { + CopyQueue *cq = copyqueue_gethead(); + + if (dashf(cq->copyfile)) { snprintf(fname, sizeof(fname), "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); if (dashf(fname)) { if (isask) { snprintf(buf, sizeof(buf), - "�T�w�n�N[%s]���[��(Y/N)�H[N] ", copytmp->copytitle); + "�T�w�n�N[%s]���[��(Y/N)�H[N] ", cq->copytitle); getdata(b_lines - 2, 1, buf, ans, sizeof(ans), LCECHO); } if (ans[0] == 'y') { if ((fp = fopen(fname, "a+"))) { - if ((fin = fopen(copytmp->copyfile, "r"))) { + if ((fin = fopen(cq->copyfile, "r"))) { memset(buf, '-', 74); buf[74] = '\0'; fprintf(fp, "\n> %s <\n\n", buf); @@ -420,22 +533,17 @@ a_appenditem(const menu_t * pm, int isask) fputs(buf, fp); } fclose(fin); - copytmp->copyfile[0] = '\0'; + cq->copyfile[0] = '\0'; } fclose(fp); } } } else { - outs("�ɮפ��o���[�I"); - igetch(); + vmsg("�ɮפ��o���[�I"); } } else { - outs("���o���[��ӥؿ����ɮ�I"); - igetch(); + vmsg("�ؿ����o���[���ɮ�I"); } - } else { - outs("�Х����� copy �R�O��A append"); - igetch(); } } |