⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 respond.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
		mailbox = FALSE;	    else {		if (read(tmpfd,buf,LBUFLEN)) {		    c = buf;		    if (!isspace(MBOXCHAR))   /* if non-zero, */			while (isspace(*c))   /* check the first character */			    c++;		    mailbox = (*c == MBOXCHAR);		} else {		    mailbox = mbox_always;    /* if zero length, recheck -M */		}		close(tmpfd);	    }	}	safecpy(cmd_buf, filexp(mailbox ?	    getval("MBOXSAVER",MBOXSAVER) :	    getval("NORMSAVER",NORMSAVER) ), sizeof cmd_buf);				/* format the command */	termlib_reset();	resetty();		/* make terminal behave */	if (doshell(use_pref?Nullch:SH,cmd_buf)) {	    termlib_init();	    fputs("Not saved",stdout);	} else {	    termlib_init();	    printf("%s to %s %s",	      there?"Appended":"Saved",	      mailbox?"mailbox":"file",	      s);	}	if (interactive)	    putchar('\n') FLUSH;	noecho();		/* make terminal do what we want */	crmode();    }s_bomb:#ifdef USE_NNTP    if (chdir(spool)) {#else    if (chdir(spool) || chdir(ngdir)) {#endif	printf(nocd,ngdir) FLUSH;	sig_catcher(0);    }    return SAVE_DONE;}intcancel_article(){    char *ngs_buf;    char *from_buf;    char *reply_buf;    int myuid = getuid();    int r = -1;    if (artopen(art) == Nullfp) {#ifdef VERBOSE	IF(verbose)	    fputs("\n\Cancelling null articles is your idea of fun?  :-)\n\",stdout) FLUSH;	ELSE#endif#ifdef TERSE	    fputs(nullart,stdout) FLUSH;#endif	return r;    }    reply_buf = fetchlines(art,REPLY_LINE);    from_buf = fetchlines(art,FROM_LINE);    ngs_buf = fetchlines(art,NGS_LINE);    if (!instr(from_buf,phostname,FALSE) ||	(!instr(from_buf,logname,TRUE) &&	 !instr(reply_buf,logname,TRUE) &&#ifdef NEWS_ADMIN	 myuid != newsuid &&#endif	 myuid != ROOTID ) ) {#ifdef DEBUG	    if (debug)		printf("\n%s@%s != %s\n",logname,phostname,from_buf) FLUSH;#endif#ifdef VERBOSE	    IF(verbose)		fputs("\nYou can't cancel someone else's article\n",stdout)		  FLUSH;	    ELSE#endif#ifdef TERSE		fputs("\nNot your article\n",stdout) FLUSH;#endif    }    else {	tmpfp = fopen(headname,"w");	/* open header file */	if (tmpfp == Nullfp) {	    printf(cantcreate,headname) FLUSH;	    goto no_cancel;	}	interp(buf, (sizeof buf), getval("CANCELHEADER",CANCELHEADER));	fputs(buf,tmpfp);	fclose(tmpfp);	fputs("\nCanceling...\n",stdout) FLUSH;	r = doshell(sh,filexp(getval("CANCEL",CANCEL)));    }no_cancel:    free(ngs_buf);    free(from_buf);    free(reply_buf);    return r;}intsupersede_article()		/* Supersedes: */{    char *ngs_buf;    char *from_buf;    char *reply_buf;    int myuid = getuid();    int r = -1;    bool incl_body = (*buf == 'Z');    if (artopen(art) == Nullfp) {#ifdef VERBOSE	IF(verbose)	    fputs("\n\Superceding null articles is your idea of fun?  :-)\n\",stdout) FLUSH;	ELSE#endif#ifdef TERSE	    fputs(nullart,stdout) FLUSH;#endif	return r;    }    reply_buf = fetchlines(art,REPLY_LINE);    from_buf = fetchlines(art,FROM_LINE);    ngs_buf = fetchlines(art,NGS_LINE);    if (!instr(from_buf,phostname,FALSE) ||	(!instr(from_buf,logname,TRUE) &&	 !instr(reply_buf,logname,TRUE) &&#ifdef NEWS_ADMIN	 myuid != newsuid &&#endif	 myuid != ROOTID ) ) {#ifdef DEBUG	    if (debug)		printf("\n%s@%s != %s\n",logname,phostname,from_buf) FLUSH;#endif#ifdef VERBOSE	    IF(verbose)		fputs("\nYou can't supersede someone else's article\n",stdout)		  FLUSH;	    ELSE#endif#ifdef TERSE		fputs("\nNot your article\n",stdout) FLUSH;#endif    }    else {	tmpfp = fopen(headname,"w");	/* open header file */	if (tmpfp == Nullfp) {	    printf(cantcreate,headname) FLUSH;	    goto no_commute;	}	interp(buf, (sizeof buf), getval("SUPERSEDEHEADER",SUPERSEDEHEADER));	fputs(buf,tmpfp);	if (incl_body && artfp != Nullfp) {	    parseheader(art);	    fseek(artfp,(long)htype[PAST_HEADER].ht_minpos,0);	    while (fgets(buf,LBUFLEN,artfp) != Nullch) {		fputs(buf,tmpfp);	    }	}	fclose(tmpfp);    	safecpy(cmd_buf,filexp(getval("NEWSPOSTER",NEWSPOSTER)),		sizeof cmd_buf);    	invoke(cmd_buf,origdir);	r = 0;    }no_commute:    free(ngs_buf);    free(from_buf);    free(reply_buf);    return r;}voidreply(){    bool incl_body = (*buf == 'R');    char *maildoer = savestr(filexp(getval("MAILPOSTER",MAILPOSTER)));    artopen(art);    tmpfp = fopen(headname,"w");	/* open header file */    if (tmpfp == Nullfp) {	printf(cantcreate,headname) FLUSH;	goto no_reply;    }    interp(buf, (sizeof buf), getval("MAILHEADER",MAILHEADER));    fputs(buf,tmpfp);    if (!instr(maildoer,"%h",TRUE))#ifdef VERBOSE	IF(verbose)	    printf("\n%s\n(Above lines saved in file %s)\n",buf,headname)	      FLUSH;	ELSE#endif#ifdef TERSE	    printf("\n%s\n(Header in %s)\n",buf,headname) FLUSH;#endif    if (incl_body && artfp != Nullfp) {	interp(buf, (sizeof buf), getval("YOUSAID",YOUSAID));	fprintf(tmpfp,"%s\n",buf);	parseheader(art);	fseek(artfp,(long)htype[PAST_HEADER].ht_minpos,0);	while (fgets(buf,LBUFLEN,artfp) != Nullch) {	    fprintf(tmpfp,"%s%s",indstr,buf);	}	fprintf(tmpfp,"\n");    }    fclose(tmpfp);    interp(cmd_buf, (sizeof cmd_buf), maildoer);    invoke(cmd_buf,origdir);    UNLINK(headname);		/* kill the header file */no_reply:    free(maildoer);}voidfollowup(){    bool incl_body = (*buf == 'F');    char hbuf[4*LBUFLEN];	/* four times the old size */    ART_NUM oldart = art;    if (!incl_body && art <= lastart) {	in_answer("\n\nAre you starting an unrelated topic? [ynq] ", 'F');	setdef(buf,"y");	if (*buf == 'q')  /*TODO: need to add 'h' also */	    return;	if (*buf != 'n')	    art = lastart + 1;    }    artopen(art);    tmpfp = fopen(headname,"w");    if (tmpfp == Nullfp) {	printf(cantcreate,headname) FLUSH;	art = oldart;	return;    }    interp(hbuf, (sizeof hbuf), getval("NEWSHEADER",NEWSHEADER));    fprintf(tmpfp,"%s",hbuf);    if (incl_body && artfp != Nullfp) {#ifdef VERBOSE	if (verbose)	    fputs("\n\(Be sure to double-check the attribution against the signature, and\n\trim the quoted article down as much as possible.)\n\",stdout) FLUSH;#endif	interp(buf, (sizeof buf), getval("ATTRIBUTION",ATTRIBUTION));	fprintf(tmpfp,"%s\n",buf);	parseheader(art);	fseek(artfp,(long)htype[PAST_HEADER].ht_minpos,0);	while (fgets(buf,LBUFLEN,artfp) != Nullch) {	    fprintf(tmpfp,"%s%s",indstr,buf);	}	fprintf(tmpfp,"\n");    }    fclose(tmpfp);    safecpy(cmd_buf,filexp(getval("NEWSPOSTER",NEWSPOSTER)),sizeof cmd_buf);    invoke(cmd_buf,origdir);    UNLINK(headname);    art = oldart;}voidinvoke(cmd,dir)char *cmd,*dir;{    if (chdir(dir)) {	printf(nocd,dir) FLUSH;	return;    }    termlib_reset();#ifdef VERBOSE    IF(verbose)	printf("\n(leaving cbreak mode; cwd=%s)\nInvoking command: %s\n\n",	    dir,cmd) FLUSH;    ELSE#endif#ifdef TERSE	printf("\n(-cbreak; cwd=%s)\nInvoking: %s\n\n",dir,cmd) FLUSH;#endif    resetty();			/* make terminal well-behaved */    doshell(sh,cmd);		/* do the command */    noecho();			/* set no echo */    crmode();			/* and cbreak mode */#ifdef VERBOSE    IF(verbose)	fputs("\n(re-entering cbreak mode)\n",stdout) FLUSH;    ELSE#endif#ifdef TERSE	fputs("\n(+cbreak)\n",stdout) FLUSH;#endif    termlib_init();#ifdef USE_NNTP    if (chdir(spool)) {#else    if (chdir(spool) || chdir(ngdir)) {#endif	printf(nocd,ngdir) FLUSH;	sig_catcher(0);    }}/*** cut_line() determines if a line is meant as a "cut here" marker.** Some examples that we understand:****  BEGIN--cut here--cut here****  ------------------ tear at this line ------------------****  #----cut here-----cut here-----cut here-----cut here----#*/boolcut_line(str)char *str;{    char *cp, got_flag;    char word[80];    int  dash_cnt, equal_cnt, other_cnt;    /* Disallow any single-/double-quoted, parenthetical or c-commented    ** string lines.  Make sure it has the cut-phrase and at least six    ** '-'s or '='s.  If only four '-'s are present, check for a duplicate    ** of the cut phrase.  If over 20 unknown characters are encountered,    ** assume it isn't a cut line.  If we succeed, return TRUE.    */    for (cp = str, dash_cnt = equal_cnt = other_cnt = 0; *cp; cp++) {	switch (*cp) {	case '-':	    dash_cnt++;	    break;	case '=':	    equal_cnt++;	    break;	case '/':	    if(*(cp+1) != '*') {		break;	    }	case '"':	case '\'':	case '(':	case ')':	case '[':	case ']':	case '{':	case '}':	    return FALSE;	default:	    other_cnt++;	    break;	}    }    if (dash_cnt < 4 && equal_cnt < 6)	return FALSE;    got_flag = 0;    for (*(cp = word) = '\0'; *str; str++) {	if (islower(*str))	    *cp++ = *str;	else if (isupper(*str))	    *cp++ = tolower(*str);	else {	    if (*word) {		*cp = '\0';		switch (got_flag) {		case 2:		    if (!strcmp(word, "line")		     || !strcmp(word, "here"))			if ((other_cnt -= 4) <= 20)			    return TRUE;		    break;		case 1:		    if (!strcmp(word, "this")) {			got_flag = 2;			other_cnt -= 4;		    }		    else if (!strcmp(word, "here")) {			other_cnt -= 4;			if ((dash_cnt >= 6 || equal_cnt >= 6)			 && other_cnt <= 20)			    return TRUE;			dash_cnt = 6;			got_flag = 0;		    }		    break;		case 0:		    if (!strcmp(word, "cut")		     || !strcmp(word, "snip")		     || !strcmp(word, "tear")) {			got_flag = 1;			other_cnt -= strlen(word);		    }		    break;		}		*(cp = word) = '\0';	    }	}    } /* for *str */    return FALSE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -