/* CaseInsensitive ucache_hash */ static unsigned int ucache_hash_deep(const char *userid) { int n1, n2, n; struct ucache_hashtable *hash; if (!*userid) return 0; hash = &(binfo->ucachehashshm->hashtable); n1 = mytoupper(*userid++); n1 -= 'A'; n1 = hash->hash[0][n1]; n = 1; while (n1 < 0) { n1 = -n1 - 1; if (!*userid) { n1 = hash->hash[n1][0]; } else { n2 = mytoupper(*userid++); n2 -= 'A'; n1 = hash->hash[n1][n2]; } n++; } return n; }
// username�û���֤ʧ�ܵĴ�����������û�������Ŀǰ��δʹ������������� added by interma@BMY 2005.5.16 void register_fail(char *userid) { int id; strcpy(genbuf, userid); id = getuser(genbuf); if (lookupuser.userid[0] == '\0' || !strcmp(lookupuser.userid, "SYSOP")) { return; } sprintf(genbuf, "mail/%c/%s", mytoupper(lookupuser.userid[0]), lookupuser.userid); deltree(genbuf); sprintf(genbuf, "home/%c/%s", mytoupper(lookupuser.userid[0]), lookupuser.userid); deltree(genbuf); lookupuser.userlevel = 0; strcpy(lookupuser.address, ""); strcpy(lookupuser.username, ""); strcpy(lookupuser.realname, ""); strcpy(lookupuser.ip, ""); strcpy(lookupuser.realmail, ""); lookupuser.userid[0] = '\0'; substitute_record(PASSFILE, &lookupuser, sizeof (lookupuser), id); setuserid(id, lookupuser.userid); }
int stringbeg(char *s,char *t) /* Return nonzero iff string t begins with non-empty string s */ { size_t i=0; size_t l=strlen(s); if(l>0) { while((i<l) && (mytoupper(s[i])==mytoupper(t[i]))) i++; if(i==l) return true; } return false; }
static Word eval_ar_expression(char *asc, Boolean *ok) { *ok = True; if ((mytoupper(asc[0]) == 'A') && (mytoupper(asc[1]) == 'R') && (asc[2] >= '0') && (asc[2] <= '7') && (asc[3] <= '\0')) return asc[2] - '0'; return EvalIntExpression(asc, UInt3, ok); }
char * u_namearray(char buf[][IDLEN + 1], int max, int *pnum, char *tag, char *atag, int *full) /* 根据tag ,生成 匹配的user id 列表 (针对所有注册用户)*/ { struct UCACHEHASH *reg_ushm = binfo->ucachehashshm; int n, num, i; int hash, len, ksz, alen; char tagv[IDLEN + 1]; len = strlen(tag); alen = strlen(atag); if (len > IDLEN) return NULL; if (!len) { return NULL; } ksz = ucache_hash_deep(tag); strcpy(tagv, tag); if (len >= ksz || len == IDLEN) { tagv[ksz] = 0; hash = ucache_hash(tagv) - 1; for (n = 0; n < UCACHE_HASHBSIZE; n++) { num = reg_ushm->hash_head[(hash + n % UCACHE_HASHBSIZE) % UCACHE_HASHSIZE + 1]; while (num) { if (!strncasecmp (passwdptr[num - 1].userid, atag, alen) && (passwdptr[num - 1].kickout == 0)) { strcpy(buf[(*pnum)++], passwdptr[num - 1].userid); /*如果匹配, add into buf */ if (*pnum >= max) { *full = 1; return buf[0]; } } num = reg_ushm->next[num]; } } } else { for (i = 'A'; i <= 'Z'; i++) { tagv[len] = i; tagv[len + 1] = 0; u_namearray(buf, max, pnum, tagv, atag, full); if (*full == 1) return buf[0]; if (mytoupper(tagv[len]) == 'Z') { tagv[len] = 'A'; return buf[0]; } else { tagv[len]++; } } } return buf[0]; }
int main(int argc, char *argv[]) { unsigned int weights[0x100]; unsigned int i, j; unsigned char c; for (i = 0; i < 0x100; i++) weights[i] = 0; while (scanf("%c %u\n", &c, &j) == 2) weights[c] = j; puts("/* THIS IS A GENERATED TABLE, see data/basetoc.c. */"); printf("static const unsigned short int RAW_"); for (i = 0; argv[1][i]; i++) printf("%c", mytoupper(argv[1][i])); puts("[] = {"); for (i = 0; i < 0x100; i++) { if (i % 8 == 0) printf(" "); printf("%4u", weights[i]); if (i % 8 == 7) printf(", /* 0x%02x */\n", i-7); else printf(", "); } puts("};\n"); return 0; }
int bbsnewmail_main() { FILE *fp; struct fileheader x; int total = 0, total2 = 0; char dir[80]; if (!loginok || isguest) http_fatal("您尚未登录, 请先登录"); sprintf(dir, "mail/%c/%s/.DIR", mytoupper(currentuser->userid[0]), currentuser->userid); if (cache_header(file_time(dir), 1)) return 0; html_header(1); //check_msg(); changemode(RMAIL); //去掉了框架 printf("<body topmargin=0 leftMargin=1 MARGINWIDTH=1 MARGINHEIGHT=0>" WWWLEFT_DIV); printf("<center>\n"); printf ("%s -- 未读邮件列表 [使用者: %s] [信箱容量: %dk, 已用空间: %dk]<hr>\n", BBSNAME, currentuser->userid, max_mailsize(currentuser), get_mailsize(currentuser)); fp = fopen(dir, "r"); if (fp == 0) http_fatal("目前您的信箱没有任何信件"); printf("<table border=1>\n"); printf ("<tr><td>序号</td><td>状态</td><td>发信人</td><td>日期</td><td>信件标题</td></tr>\n"); while (1) { if (fread(&x, sizeof (x), 1, fp) <= 0) break; total++; if (x.accessed & FH_READ) continue; printf("<tr><td>%d</td><td>N</td>", total); printf("<td>%s</td>", userid_str(fh2owner(&x))); printf("<td>%6.6s</td>", Ctime(x.filetime) + 4); printf("<td><a href=bbsmailcon?file=%s&num=%d>", fh2fname(&x), total - 1); if (strncmp("Re: ", x.title, 4)) printf("★ "); hprintf("%42.42s", void1(x.title)); printf(" </a></td></tr>\n"); total2++; } fclose(fp); printf("</table><hr>\n"); printf("您的信箱共有%d封信件, 其中新信%d封.", total, total2); printf("</center>"); showfile(MY_BBS_HOME "/wwwtmp/googleanalytics"); // printf("</body>"); //修改框架,页面底部 printf(WWWFOOT_DIV "</body></html>\n"); http_quit(); return 0; }
/* * \param s */ void ISpellChecker::upcase(ichar_t *s) { while(*s) { *s = mytoupper(*s); s++; } }
int mails_time(char *id) { char path[80]; if (!loginok || isguest) return 0; sprintf(path, "mail/%c/%s/.DIR", mytoupper(id[0]), id); return file_time(path); }
int mk_upper(ichar_t *w, ichar_t *nword) { register ichar_t *p, *q; /* Make an uppercase copy of the word we are checking. */ for (p = w, q = nword; *p; ) *q++ = mytoupper(*p++); *q = 0; /* put end of string */ return q - nword; /* word length */ }
static size_t findNoodFragOffset(const u8 *lit, size_t len, bool nocase) { size_t offset = 0; for (size_t i = 0; i + 1 < len; i++) { int diff = 0; const char c = lit[i]; const char d = lit[i + 1]; if (nocase && ourisalpha(c)) { diff = (mytoupper(c) != mytoupper(d)); } else { diff = (c != d); } offset = i; if (diff) { break; } } return offset; }
int main( int argc, char **argv ) { char ch; if ( strcmp( *argv, "ex0701" ) == 0 ) { while ( (ch = getchar()) != EOF ) { putchar( mytolower( ch ) ); } } else { while ( (ch = getchar()) != EOF ) { putchar( mytoupper( ch ) ); } } return 0; }
static size_t findNoodFragOffset(const hwlmLiteral &lit) { const auto &s = lit.s; const size_t len = lit.s.length(); size_t offset = 0; for (size_t i = 0; i + 1 < len; i++) { int diff = 0; const char c = s[i]; const char d = s[i + 1]; if (lit.nocase && ourisalpha(c)) { diff = (mytoupper(c) != mytoupper(d)); } else { diff = (c != d); } offset = i; if (diff) { break; } } return offset; }
/* CaseInsensitive ucache_hash */ unsigned int ucache_hash(const char *userid) { int n1, n2, n, len; struct ucache_hashtable *hash; if (!*userid) return 0; hash = &(binfo->ucachehashshm->hashtable); n1 = mytoupper(*userid++); n1 -= 'A'; n1 = hash->hash[0][n1]; while (n1 < 0) { n1 = -n1 - 1; if (!*userid) { n1 = hash->hash[n1][0]; } else { n2 = mytoupper(*userid++); n2 -= 'A'; n1 = hash->hash[n1][n2]; } } n1 = (n1 * UCACHE_HASHBSIZE) % UCACHE_HASHSIZE + 1; if (!*userid) return n1; n2 = 0; len = strlen(userid); while (*userid) { n = mytoupper(*userid++); n2 += (n - 'A') * len; len--; } n1 = (n1 + n2 % UCACHE_HASHBSIZE) % UCACHE_HASHSIZE + 1; return n1; }
int bbsnewmail_main() { //modify by mintbaggio 20040829 for new www FILE *fp; struct fileheader x; int total = 0, total2 = 0; char dir[80]; if (!loginok || isguest) http_fatal("您尚未登录, 请先登录"); sprintf(dir, "mail/%c/%s/.DIR", mytoupper(currentuser.userid[0]), currentuser.userid); if(cache_header(file_time(dir),1)) return 0; html_header(1); check_msg(); changemode(RMAIL); printf("<body><center>\n"); printf ("<div class=rhead>%s -- 新邮件列表 [使用者: <span class=h11>%s</span>]<br>[信箱容量: <span class=h11>%d</span>k, 已用空间: <span class=h11>%dk</span>]</div><hr>\n", BBSNAME, currentuser.userid, max_mail_size(), get_mail_size()); fp = fopen(dir, "r"); if (fp == 0) http_fatal("目前您的信箱没有任何信件"); printf("<table border=1>\n"); printf ("<tr><td>序号</td><td>状态</td><td>发信人</td><td>日期</td><td>信件标题</td></tr>\n"); while (1) { if (fread(&x, sizeof (x), 1, fp) <= 0) break; total++; if (x.accessed & FH_READ) continue; printf("<tr><td>%d</td><td>N</td>", total); printf("<td>%s</td>", userid_str(fh2owner(&x))); printf("<td>%6.6s</td>", Ctime(x.filetime) + 4); printf("<td><a href=bbsmailcon?file=%s&num=%d>", fh2fname(&x), total - 1); if (strncmp("Re: ", x.title, 4)) printf("★ "); hprintf("%42.42s", void1(x.title)); printf(" </a></td></tr>\n"); total2++; } fclose(fp); printf("</table><hr>\n"); printf("您的信箱共有%d封信件, 其中新信%d封.", total, total2); printf("</center></body>"); http_quit(); return 0; }
/* * \param a * \param b * \param canonical NZ for canonical string chars * * \return */ int ISpellChecker::casecmp (char *a, char *b, int canonical) { register ichar_t * ap; register ichar_t * bp; ichar_t inta[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4]; ichar_t intb[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4]; strtoichar (inta, a, sizeof inta, canonical); strtoichar (intb, b, sizeof intb, canonical); for (ap = inta, bp = intb; *ap != 0; ap++, bp++) { if (*ap != *bp) { if (*bp == '\0') return m_hashheader.sortorder[*ap]; else if (mylower (*ap)) { if (mylower (*bp) || mytoupper (*ap) != *bp) return static_cast<int>(m_hashheader.sortorder[*ap]) - static_cast<int>(m_hashheader.sortorder[*bp]); } else { if (myupper (*bp) || mytolower (*ap) != *bp) return static_cast<int>(m_hashheader.sortorder[*ap]) - static_cast<int>(m_hashheader.sortorder[*bp]); } } } if (*bp != '\0') return -static_cast<int>(m_hashheader.sortorder[*bp]); for (ap = inta, bp = intb; *ap; ap++, bp++) { if (*ap != *bp) { return static_cast<int>(m_hashheader.sortorder[*ap]) - static_cast<int>(m_hashheader.sortorder[*bp]); } } return 0; }
/* ARGSUSED */ int ISpellChecker::good(ichar_t *w, int ignoreflagbits, int dummy, int pfxopts, int sfxopts) #endif { ichar_t nword[INPUTWORDLEN + MAXAFFIXLEN]; register ichar_t *p; register ichar_t *q; register int n; register struct dent *dp; /* ** Make an uppercase copy of the word we are checking. */ for(p = w, q = nword; *p;) *q++ = mytoupper(*p++); *q = 0; n = q - nword; m_numhits = 0; if((dp = ispell_lookup(nword, 1)) != NULL) { m_hits[0].dictent = dp; m_hits[0].prefix = NULL; m_hits[0].suffix = NULL; #ifndef NO_CAPITALIZATION_SUPPORT if(allhits || cap_ok(w, &m_hits[0], n)) m_numhits = 1; #else m_numhits = 1; #endif } if(m_numhits && !allhits) return 1; /* try stripping off affixes */ chk_aff(w, nword, n, ignoreflagbits, allhits, pfxopts, sfxopts); return m_numhits; }
int htoi(char *c) { int res=0,i=0,num; int len = strlen(c); //printf("%d\n",len); if(c[0]=='0' && (c[1] == 'x' || c[1] == 'X') ) { while(--len > 1) { if(isdigit((int)c[len])) { res = res + (c[len]-48)* pow(16,i++); } else { c[len] = mytoupper(c[len]); switch(c[len]) { case 'A': num = 10;break; case 'B': num = 11;break; case 'C': num = 12;break; case 'D': num = 13;break; case 'E': num = 14;break; case 'F': num = 15;break; default : printf("Enter the valid HEX number\n"); exit(0); } // printf("%d\n",num); res = res + num * pow(16,i++); } } return res; } else { puts("Enter the valid HEX numb\n"); return -1; } }
/*! * Print a suffix expansion * * \param croot Char version of rootword * \param rootword Root word to expand * \param flent Current table entry * \param option Option, see expandmode * \param extra Extra info to add to line * * \return */ int ISpellChecker::pr_suf_expansion (char *croot, ichar_t *rootword, struct flagent *flent, int option, char *extra) { int cond; /* Current condition number */ register ichar_t * nextc; /* Next case choice */ int tlen; /* Length of tword */ ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN]; /* Temp */ tlen = icharlen (rootword); cond = flent->numconds; if (cond > tlen) return 0; if (tlen - flent->stripl <= 0) return 0; for (nextc = rootword + tlen; --cond >= 0; ) { if ((flent->conds[mytoupper (*--nextc)] & (1 << cond)) == 0) return 0; } /* * The conditions are satisfied. Copy the word, add the suffix, * and make it match the case of the last remaining character of the * root. Again, this code carefully matches ins_cap and cap_ok. */ icharcpy (tword, rootword); nextc = tword + tlen - flent->stripl; if (flent->affl) { icharcpy (nextc, flent->affix); if (!myupper (nextc[-1])) forcelc (nextc, flent->affl); } else *nextc = 0; if (option == 3) printf ("\n%s", croot); if (option != 4) printf (" %s%s", ichartosstr (tword, 1), extra); return tlen + flent->affl - flent->stripl; }
static int get_user_mail_size(char * userid) { int currsize = 0; char currmaildir[STRLEN], tmpmail[STRLEN]; struct fileheader tmpfh; FILE *fp; time_t t; sethomefile(tmpmail, userid, "msgindex"); if(file_time(tmpmail)) currsize += file_size_s(tmpmail); sethomefile(tmpmail, userid, "msgindex2"); if(file_time(tmpmail)) currsize += file_size_s(tmpmail); sethomefile(tmpmail, userid, "msgcontent"); if(file_time(tmpmail)) currsize += file_size_s(tmpmail); sprintf(currmaildir, "mail/%c/%s/%s", mytoupper(userid[0]), userid, DOT_DIR); t = file_time(currmaildir); if(!t) return (currsize/1024); fp = fopen(currmaildir, "r"); if(!fp) return (currsize/1024); while(fread(&tmpfh, 1, sizeof(tmpfh), fp) == sizeof(tmpfh)) { setmailfile(tmpmail, userid, fh2fname(&tmpfh)); currsize += file_size_s(tmpmail); } fclose(fp); return (currsize/1024); }
int bbsqry_main() { FILE *fp; char userid[14], filename[80], buf[512]; struct userec *x; int tmp2; struct in_addr in; html_header(1); check_msg(); changemode(QUERY); strsncpy(userid, getparm("U"), 13); if (!userid[0]) strsncpy(userid, getparm("userid"), 13); printf("<body><center>"); printf("%s -- 查询网友<hr>\n", BBSNAME); if (userid[0] == 0) { printf("<form name=qry action=bbsqry>\n"); printf ("请输入用户名: <input name=userid maxlength=12 size=12>\n"); printf("<input type=submit value=查询用户>\n"); printf("</form><hr>\n"); printf("<script>document.qry.userid.focus();</script>"); http_quit(); } if (getuser(userid, &x) <= 0) { printf("不可能,肯定是你敲错了,根本没这人啊"); printf("<p><a href=javascript:history.go(-1)>快速返回</a>"); http_quit(); } printf("</center><pre>\n"); if (x->mypic) { printf("<table align=left><tr><td><center>"); printmypic(x->userid); printf("</center></td></tr></table>"); } printf("<b><font size=+1>%s</font></b> (<font class=gre>%s</font>) " "共上站 <font class=gre>%d</font> 次," "发表文章 <font class=gre>%d</font> 篇\n", x->userid, x->username, x->numlogins, x->numposts); // show_special(x->userid); in.s_addr = x->lasthost & 0x0000ffff; printf ("上次在 <font color=green>%s</font> 从 <font color=green>%s</font> 到本站一游。<br>", Ctime(x->lastlogin), inet_ntoa(in)); mails(userid, &tmp2); printf("信箱:[<font color=green>%s</font>],", tmp2 ? "⊙" : " "); if (!strcasecmp(x->userid, currentuser->userid)) { printf ("经验值:[<font color=green>%d</font>](<font color=olive>%s</font>) ", countexp(x), cuserexp(countexp(x))); printf ("表现值:[<font color=green>%d</font>](<font color=olive>%s</font>) ", countperf(x), cperf(countperf(x))); } if (x->dieday) { printf ("<br>已经离开了人世,呜呜...<br>还有 [<b>%d</b>] 天就要转世投胎了<br>", countlife(x)); } else { printf("生命力:[<font color=red>%d</font>]。<br>", countlife(x)); if (x->userlevel & PERM_BOARDS) { int i; printf("担任版务:"); for (i = 0; i < MAXBOARD && i < shm_bcache->number; i++) bm_printboard(&shm_bcache->bcache[i], x->userid); printf("<br>"); } if (!show_onlinestate(userid)) { printf ("目前不在站上, 上次离站时间 [<font color=blue>%s</font>]\n\n", (x->lastlogout >= x->lastlogin) ? Ctime(x-> lastlogout) : "因在线上或不正常断线不详"); } } printf("\n"); printf("</pre><table width=100%%><tr><td>"); sethomefile(filename, x->userid, "plans"); fp = fopen(filename, "r"); sprintf(filename, "00%s-plan", x->userid); fdisplay_attach(NULL, NULL, NULL, NULL); if (fp) { while (1) { if (fgets(buf, 256, fp) == 0) break; if (!strncmp(buf, "begin 644 ", 10)) { errlog("old attach %s", filename); fdisplay_attach(stdout, fp, buf, filename); continue; } fhhprintf(stdout, "%s", buf); } fclose(fp); } else { printf("<font color=teal>没有个人说明档</font><br>"); } printf("</td></tr></table>"); printf ("<br><br><a href=bbspstmail?userid=%s&title=没主题>[书灯絮语]</a> ", x->userid); printf("<a href=bbssendmsg?destid=%s>[发送讯息]</a> ", x->userid); printf("<a href=bbsfadd?userid=%s>[加入好友]</a> ", x->userid); printf("<a href=bbsfdel?userid=%s>[删除好友]</a> ", x->userid); if (x->userlevel & PERM_SPECIAL8) { printf ("<a href=bbs0an?path=/groups/GROUP_0/Personal_Corpus/%c/%s>[个人文集]</a> ", mytoupper(x->userid[0]), x->userid); } sethomefile(filename, x->userid, "B/config"); if (file_isfile(filename)) { printf ("<a href=blog?U=%s>[Blog]</a>", x->userid); } printf("<hr>"); printf("<center><form name=qry action=bbsqry>\n"); printf("请输入用户名: <input name=userid maxlength=12 size=12>\n"); printf("<input type=submit value=查询用户>\n"); printf("</form><hr>\n"); printf("</body>\n"); http_quit(); return 0; }
static char * parse_mail(char * userid, int filetime, int mode, struct attach_link **attach_link_list) { if(mode != ARTICLE_PARSE_WITHOUT_ANSICOLOR && mode != ARTICLE_PARSE_WITH_ANSICOLOR) return NULL; if(!userid || filetime<=0) return NULL; char path[STRLEN]; snprintf(path, STRLEN, "mail/%c/%s/M.%d.A", mytoupper(userid[0]), userid, filetime); FILE *article_stream = fopen(path, "r"); if(!article_stream) return NULL; FILE *mem_stream, *html_stream; char *mem_buf, *html_buf, buf[512], attach_link[256], *tmp_buf, *attach_filename; size_t mem_buf_len, html_buf_len, attach_file_size; int attach_no = 0; mem_stream = open_memstream(&mem_buf, &mem_buf_len); fseek(article_stream, 0, SEEK_SET); keepoldheader(article_stream, SKIPHEADER); while(1) { if(fgets(buf, 500, article_stream) == 0) break; // RAW 模式下跳过 qmd if(mode == ARTICLE_PARSE_WITHOUT_ANSICOLOR && (strncmp(buf, "--\n", 3)==0)) break; // 附件处理 if(!strncmp(buf, "begin 644", 10)) { // TODO 老方式暂不实现 fflush(mem_stream); fclose(mem_stream); free(mem_buf); return NULL; } else if(checkbinaryattach(buf, article_stream, &attach_file_size)) { attach_no++; attach_filename = buf + 18; fprintf(mem_stream, "#attach %s\n", attach_filename); memset(attach_link, 0, 256); snprintf(attach_link, 256, "/api/attach/get?mid=%d&pos=%d&attname=%s", filetime, -4+(int)ftell(article_stream), attach_filename); add_attach_link(attach_link_list, attach_link, attach_file_size); fseek(article_stream, attach_file_size, SEEK_CUR); continue; } // 常规字符处理 if(mode == ARTICLE_PARSE_WITHOUT_ANSICOLOR && strchr(buf, '\033')!=NULL) { tmp_buf = strdup(buf); while(strchr(tmp_buf, '\033') != NULL) tmp_buf = string_replace(tmp_buf, "\033", "[ESC]"); fprintf(mem_stream, "%s", tmp_buf); free(tmp_buf); tmp_buf = NULL; } else { fprintf(mem_stream, "%s", buf[0]==0 ? "" : buf); } } fflush(mem_stream); fclose(article_stream); char *utf_content; if(mode == ARTICLE_PARSE_WITHOUT_ANSICOLOR) { if(strlen(mem_buf)==0) { utf_content = strdup(""); } else { utf_content = (char *)malloc(3*mem_buf_len); memset(utf_content, 0, 3*mem_buf_len); g2u(mem_buf, mem_buf_len, utf_content, 3*mem_buf_len); } } else { html_stream = open_memstream(&html_buf, &html_buf_len); fseek(mem_stream, 0, SEEK_SET); fprintf(html_stream, "<article>\n"); aha_convert(mem_stream, html_stream); fprintf(html_stream, "</article>"); fflush(html_stream); fclose(html_stream); utf_content = (char*)malloc(3*html_buf_len); memset(utf_content, 0, 3*html_buf_len); g2u(html_buf, html_buf_len, utf_content, 3*html_buf_len); free(html_buf); } // 释放资源 fclose(mem_stream); free(mem_buf); return utf_content; }
/*! * \param word Word to be saved * \param pattern Capitalization pattern * \param prestrip No. chars stripped from front * \param preadd No. chars added to front of root * \param sufstrip No. chars stripped from back * \param sufadd No. chars added to back of root * \param firstdent First dent for root * \param pfxent Pfx-flag entry for word * \param sufent Sfx-flag entry for word * \param savearea Room to save words * \param nsaved Number saved so far (updated) */ void ISpellChecker::save_root_cap (ichar_t *word, ichar_t *pattern, int prestrip, int preadd, int sufstrip, int sufadd, struct dent *firstdent, struct flagent *pfxent, struct flagent *sufent, ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN], int * nsaved) { #ifndef NO_CAPITALIZATION_SUPPORT register struct dent * dent; #endif /* NO_CAPITALIZATION_SUPPORT */ int firstisupper; ichar_t newword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4]; #ifndef NO_CAPITALIZATION_SUPPORT register ichar_t * p; int len; int i; int limit; #endif /* NO_CAPITALIZATION_SUPPORT */ if (*nsaved >= MAX_CAPS) return; icharcpy (newword, word); firstisupper = myupper (pattern[0]); #ifdef NO_CAPITALIZATION_SUPPORT /* ** Apply the old, simple-minded capitalization rules. */ if (firstisupper) { if (myupper (pattern[1])) upcase (newword); else { lowcase (newword); newword[0] = mytoupper (newword[0]); } } else lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; #else /* NO_CAPITALIZATION_SUPPORT */ #define flagsareok(dent) \ ((pfxent == NULL \ || TSTMASKBIT (dent->mask, pfxent->flagbit)) \ && (sufent == NULL \ || TSTMASKBIT (dent->mask, sufent->flagbit))) dent = firstdent; if ((dent->flagfield & (CAPTYPEMASK | MOREVARIANTS)) == ALLCAPS) { upcase (newword); /* Uppercase required */ icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } for (p = pattern; *p; p++) { if (mylower (*p)) break; } if (*p == 0) { upcase (newword); /* Pattern was all caps */ icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } for (p = pattern + 1; *p; p++) { if (myupper (*p)) break; } if (*p == 0) { /* ** The pattern was all-lower or capitalized. If that's ** legal, insert only that version. */ if (firstisupper) { if (captype (dent->flagfield) == CAPITALIZED || captype (dent->flagfield) == ANYCASE) { lowcase (newword); newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } else { if (captype (dent->flagfield) == ANYCASE) { lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } while (dent->flagfield & MOREVARIANTS) { dent = dent->next; if (captype (dent->flagfield) == FOLLOWCASE || !flagsareok (dent)) continue; if (firstisupper) { if (captype (dent->flagfield) == CAPITALIZED) { lowcase (newword); newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } else { if (captype (dent->flagfield) == ANYCASE) { lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } } } /* ** Either the sample had complex capitalization, or the simple ** capitalizations (all-lower or capitalized) are illegal. ** Insert all legal capitalizations, including those that are ** all-lower or capitalized. If the prototype is capitalized, ** capitalized all-lower samples. Watch out for affixes. */ dent = firstdent; p = strtosichar (dent->word, 1); len = icharlen (p); if (dent->flagfield & MOREVARIANTS) dent = dent->next; /* Skip place-holder entry */ for ( ; ; ) { if (flagsareok (dent)) { if (captype (dent->flagfield) != FOLLOWCASE) { lowcase (newword); if (firstisupper || captype (dent->flagfield) == CAPITALIZED) newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; if (*nsaved >= MAX_CAPS) return; } else { /* Followcase is the tough one. */ p = strtosichar (dent->word, 1); memmove ( reinterpret_cast<char *>(newword + preadd), reinterpret_cast<char *>(p + prestrip), (len - prestrip - sufstrip) * sizeof (ichar_t)); if (myupper (p[prestrip])) { for (i = 0; i < preadd; i++) newword[i] = mytoupper (newword[i]); } else { for (i = 0; i < preadd; i++) newword[i] = mytolower (newword[i]); } limit = len + preadd + sufadd - prestrip - sufstrip; i = len + preadd - prestrip - sufstrip; p += len - sufstrip - 1; if (myupper (*p)) { for (p = newword + i; i < limit; i++, p++) *p = mytoupper (*p); } else { for (p = newword + i; i < limit; i++, p++) *p = mytolower (*p); } icharcpy (savearea[*nsaved], newword); (*nsaved)++; if (*nsaved >= MAX_CAPS) return; } } if ((dent->flagfield & MOREVARIANTS) == 0) break; /* End of the line */ dent = dent->next; } return; #endif /* NO_CAPITALIZATION_SUPPORT */ }
/*! * Print a prefix expansion * * \param croot Char version of rootword * \param rootword Root word to expand * \param flent Current table entry * \param mask Mask bits to expand on * \param option Option, see expandmode * \param extra Extra info to add to line * * \return */ int ISpellChecker::pr_pre_expansion ( char *croot, ichar_t *rootword, struct flagent *flent, MASKTYPE mask[], int option, char *extra) { int cond; /* Current condition number */ register ichar_t * nextc; /* Next case choice */ int tlen; /* Length of tword */ ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN]; /* Temp */ tlen = icharlen (rootword); if (flent->numconds > tlen) return 0; tlen -= flent->stripl; if (tlen <= 0) return 0; tlen += flent->affl; for (cond = 0, nextc = rootword; cond < flent->numconds; cond++) { if ((flent->conds[mytoupper (*nextc++)] & (1 << cond)) == 0) return 0; } /* * The conditions are satisfied. Copy the word, add the prefix, * and make it the proper case. This code is carefully written * to match that ins_cap and cap_ok. Note that the affix, as * inserted, is uppercase. * * There is a tricky bit here: if the root is capitalized, we * want a capitalized result. If the root is followcase, however, * we want to duplicate the case of the first remaining letter * of the root. In other words, "Loved/U" should generate "Unloved", * but "LOved/U" should generate "UNLOved" and "lOved/U" should * produce "unlOved". */ if (flent->affl) { icharcpy (tword, flent->affix); nextc = tword + flent->affl; } icharcpy (nextc, rootword + flent->stripl); if (myupper (rootword[0])) { /* We must distinguish followcase from capitalized and all-upper */ for (nextc = rootword + 1; *nextc; nextc++) { if (!myupper (*nextc)) break; } if (*nextc) { /* It's a followcase or capitalized word. Figure out which. */ for ( ; *nextc; nextc++) { if (myupper (*nextc)) break; } if (*nextc) { /* It's followcase. */ if (!myupper (tword[flent->affl])) forcelc (tword, flent->affl); } else { /* It's capitalized */ forcelc (tword + 1, tlen - 1); } } } else { /* Followcase or all-lower, we don't care which */ if (!myupper (*nextc)) forcelc (tword, flent->affl); } if (option == 3) printf ("\n%s", croot); if (option != 4) printf (" %s%s", ichartosstr (tword, 1), extra); if (flent->flagflags & FF_CROSSPRODUCT) return tlen + expand_suf (croot, tword, mask, FF_CROSSPRODUCT, option, extra); else return tlen; }
pair<u8 *, size_t> setupFDRFloodControl(const vector<hwlmLiteral> &lits, const EngineDescription &eng) { vector<FDRFlood> tmpFlood(N_CHARS); u32 default_suffix = eng.getDefaultFloodSuffixLength(); // zero everything to avoid spurious distinctions in the compares memset(&tmpFlood[0], 0, N_CHARS * sizeof(FDRFlood)); for (u32 c = 0; c < N_CHARS; c++) { tmpFlood[c].suffix = default_suffix; } for (const auto &lit : lits) { DEBUG_PRINTF("lit: '%s'%s\n", escapeString(lit.s).c_str(), lit.nocase ? " (nocase)" : ""); u32 litSize = verify_u32(lit.s.size()); u32 maskSize = (u32)lit.msk.size(); u8 c = lit.s[litSize - 1]; bool nocase = ourisalpha(c) ? lit.nocase : false; if (nocase && maskSize && (lit.msk[maskSize - 1] & CASE_BIT)) { c = (lit.cmp[maskSize - 1] & CASE_BIT) ? mytolower(c) : mytoupper(c); nocase = false; } u32 iEnd = MAX(litSize, maskSize); u32 upSuffix = iEnd; // upSuffix is used as an upper case suffix length // for case-less, or as a suffix length for case-sensitive; u32 loSuffix = iEnd; // loSuffix used only for case-less as a lower case suffix // length; for (u32 i = 0; i < iEnd; i++) { if (i < litSize) { if (isDifferent(c, lit.s[litSize - i - 1], lit.nocase)) { DEBUG_PRINTF("non-flood char in literal[%u] %c != %c\n", i, c, lit.s[litSize - i - 1]); upSuffix = MIN(upSuffix, i); loSuffix = MIN(loSuffix, i); // makes sense only for case-less break; } } if (i < maskSize) { u8 m = lit.msk[maskSize - i - 1]; u8 cm = lit.cmp[maskSize - i - 1] & m; if(nocase) { if ((mytoupper(c) & m) != cm) { DEBUG_PRINTF("non-flood char in mask[%u] %c != %c\n", i, mytoupper(c), cm); upSuffix = MIN(upSuffix, i); } if ((mytolower(c) & m) != cm) { DEBUG_PRINTF("non-flood char in mask[%u] %c != %c\n", i, mytolower(c), cm); loSuffix = MIN(loSuffix, i); } if (loSuffix != iEnd && upSuffix != iEnd) { break; } } else if ((c & m) != cm) { DEBUG_PRINTF("non-flood char in mask[%u] %c != %c\n", i, c, cm); upSuffix = MIN(upSuffix, i); break; } } } if(upSuffix != iEnd) { updateFloodSuffix(tmpFlood, nocase ? mytoupper(c) : c, upSuffix); } else { addFlood(tmpFlood, nocase ? mytoupper(c) : c, lit, upSuffix); } if (nocase) { if(loSuffix != iEnd) { updateFloodSuffix(tmpFlood, mytolower(c), loSuffix); } else { addFlood(tmpFlood, mytolower(c), lit, loSuffix); } } } #ifdef DEBUG for (u32 i = 0; i < N_CHARS; i++) { FDRFlood &fl = tmpFlood[i]; if (!fl.idCount) { continue; } printf("i is %02x fl->idCount is %hd fl->suffix is %d fl->allGroups is " "%016llx\n", i, fl.idCount, fl.suffix, fl.allGroups); for (u32 j = 0; j < fl.idCount; j++) { printf("j is %d fl.groups[j] %016llx fl.len[j] %d \n", j, fl.groups[j], fl.len[j]); } } #endif map<FDRFlood, CharReach, FloodComparator> flood2chars; for (u32 i = 0; i < N_CHARS; i++) { FDRFlood fl = tmpFlood[i]; flood2chars[fl].set(i); } u32 nDistinctFloods = flood2chars.size(); size_t floodHeaderSize = sizeof(u32) * N_CHARS; size_t floodStructSize = sizeof(FDRFlood) * nDistinctFloods; size_t totalSize = ROUNDUP_16(floodHeaderSize + floodStructSize); u8 *buf = (u8 *)aligned_zmalloc(totalSize); assert(buf); // otherwise would have thrown std::bad_alloc u32 *floodHeader = (u32 *)buf; FDRFlood *layoutFlood = (FDRFlood * )(buf + floodHeaderSize); u32 currentFloodIndex = 0; for (const auto &m : flood2chars) { const FDRFlood &fl = m.first; const CharReach &cr = m.second; layoutFlood[currentFloodIndex] = fl; for (size_t c = cr.find_first(); c != cr.npos; c = cr.find_next(c)) { floodHeader[c] = currentFloodIndex; } currentFloodIndex++; } DEBUG_PRINTF("made a flood structure with %zu + %zu = %zu\n", floodHeaderSize, floodStructSize, totalSize); return make_pair((u8 *)buf, totalSize); }
static void findForwardAccelScheme(const vector<hwlmLiteral> &lits, hwlm_group_t expected_groups, AccelAux *aux) { DEBUG_PRINTF("building accel expected=%016llx\n", expected_groups); u32 min_len = MAX_ACCEL_OFFSET; vector<const hwlmLiteral *> filtered_lits; filterLits(lits, expected_groups, &filtered_lits, &min_len); if (filtered_lits.empty()) { return; } if (findDVerm(filtered_lits, aux) || findSVerm(filtered_lits, aux)) { return; } vector<CharReach> reach(MAX_ACCEL_OFFSET, CharReach()); for (const auto &lit : lits) { if (!(lit.groups & expected_groups)) { continue; } for (u32 i = 0; i < MAX_ACCEL_OFFSET && i < lit.s.length(); i++) { unsigned char c = lit.s[i]; if (lit.nocase) { DEBUG_PRINTF("adding %02hhx to %u\n", mytoupper(c), i); DEBUG_PRINTF("adding %02hhx to %u\n", mytolower(c), i); reach[i].set(mytoupper(c)); reach[i].set(mytolower(c)); } else { DEBUG_PRINTF("adding %02hhx to %u\n", c, i); reach[i].set(c); } } } u32 min_count = ~0U; u32 min_offset = ~0U; for (u32 i = 0; i < min_len; i++) { size_t count = reach[i].count(); DEBUG_PRINTF("offset %u is %s (reach %zu)\n", i, describeClass(reach[i]).c_str(), count); if (count < min_count) { min_count = (u32)count; min_offset = i; } } assert(min_offset <= min_len); if (min_count > MAX_SHUFTI_WIDTH) { DEBUG_PRINTF("min shufti with %u chars is too wide\n", min_count); return; } const CharReach &cr = reach[min_offset]; if (shuftiBuildMasks(cr, &aux->shufti.lo, &aux->shufti.hi) != -1) { DEBUG_PRINTF("built shufti for %s (%zu chars, offset %u)\n", describeClass(cr).c_str(), cr.count(), min_offset); aux->shufti.accel_type = ACCEL_SHUFTI; aux->shufti.offset = verify_u8(min_offset); return; } DEBUG_PRINTF("fail\n"); }
/* How to print: * 1 = expansions only * 2 = original line + expansions * 3 = original paired w/ expansions * 4 = add length ratio */ static void expandmode(int option) { char buf[BUFSIZ]; int explength; /* Total length of all expansions */ register char *flagp; /* Pointer to next flag char */ ichar_t ibuf[BUFSIZ]; MASKTYPE mask[MASKSIZE]; char origbuf[BUFSIZ]; /* Original contents of buf */ char ratiobuf[20]; /* Expansion/root length ratio */ int rootlength; /* Length of root word */ register int temp; /* char strg_out[MAXSOLLEN]; */ while (xgets(buf, sizeof buf, stdin) != NULL) { rootlength = strlen(buf); if (buf[rootlength - 1] == '\n') buf[--rootlength] = '\0'; strcpy(origbuf, buf); if ((flagp = index(buf, hashheader.flagmarker)) != NULL) { rootlength = flagp - buf; *flagp++ = '\0'; } if (option == 2 || option == 3 || option == 4) printf("%s ", origbuf); if (flagp != NULL) { if (flagp - buf > INPUTWORDLEN) buf[INPUTWORDLEN] = '\0'; } else { if ((int) strlen(buf) > INPUTWORDLEN - 1) buf[INPUTWORDLEN] = '\0'; } fputs(buf, stdout); fputc(' ', stdout); /* strtoichar(ibuf, buf, sizeof ibuf, 1); if (good(ibuf, 0, 0, 0)) { get_info(hits[0]); sprintf(strg_out, o_form, root, macro(root_class), pre_class, macro(suf_class), suf2_class); printf("%s ", strg_out); } */ if (flagp != NULL) { bzero((char *) mask, sizeof(mask)); while (*flagp != '\0' && *flagp != '\n') { #if MASKBITS <= 32 temp = CHARTOBIT(mytoupper(chartoichar(*flagp))); #else temp = CHARTOBIT((unsigned char) *flagp); #endif if (temp >= 0 && temp <= LARGESTFLAG) SETMASKBIT (mask, temp); flagp++; /* Accept old-format dicts with extra slashes */ if (*flagp == hashheader.flagmarker) flagp++; } if (strtoichar(ibuf, buf, sizeof ibuf, 1)) fprintf(stderr, WORD_TOO_LONG(buf)); explength = expand_pre(origbuf, ibuf, mask, option, ""); explength += expand_suf(origbuf, ibuf, mask, 0, option, "", ""); explength += rootlength; if (option == 4) { sprintf(ratiobuf, " %f", (double) explength / (double) rootlength); fputs(ratiobuf, stdout); expand_pre(origbuf, ibuf, mask, 3, ratiobuf); expand_suf(origbuf, ibuf, mask, 0, 3, ratiobuf, ""); } } printf(SEP4); } }
int bbssndmail_main() { char mymaildir[80], userid[80], filename[80], filename2[80], title[80], title2[80], *content; char *ptr; int i, sig, backup, allfriend, mark = 0, reply = 0, num = 0, use_ubb; struct userec *u; struct fileheader fh; html_header(1); strsncpy(userid, getparm("userid"), 40); if (!loginok || (isguest && strcmp(userid, "SYSOP"))) http_fatal("匆匆过客不能写信,请先登录"); sprintf(mymaildir, "mail/%c/%s/.DIR", mytoupper(currentuser->userid[0]), currentuser->userid); if ((ptr=check_mailperm(currentuser))) http_fatal(ptr); changemode(SMAIL); strsncpy(title, getparm("title"), 50); backup = strlen(getparm("backup")); allfriend = strlen(getparm("allfriend")); reply = atoi(getparm("reply")); num = atoi(getparm("num")); use_ubb = strlen(getparm("useubb")); if (!strstr(userid, "@") && !allfriend) { if (getuser(userid, &u) <= 0) http_fatal("错误的收信人帐号 %s", userid); strcpy(userid, u->userid); if (inoverride(currentuser->userid, userid, "rejects")) http_fatal("无法发信给这个人"); } if (!USERPERM(currentuser, PERM_LOGINOK) && strcmp(userid, "SYSOP")) http_fatal("未通过注册用户只能给SYSOP写信!"); for (i = 0; i < strlen(title); i++) if (title[i] <= 27 && title[i] >= -1) title[i] = ' '; sig = atoi(getparm("signature")); content = getparm("text"); if (title[0] == 0) strcpy(title, "没主题"); sprintf(filename, "bbstmpfs/tmp/%d.tmp", thispid); sprintf(filename2, "bbstmpfs/tmp/%d.tmp2", thispid); if (use_ubb) ubb2ansi(content, filename2); else f_write(filename2, content); if (insertattachments_byfile(filename, filename2, currentuser->userid) > 0) mark |= FH_ATTACHED; unlink(filename2); if (!allfriend) { snprintf(title2, sizeof (title2), "{%s} %s", userid, title); post_mail(userid, title, filename, currentuser->userid, currentuser->username, fromhost, sig - 1, mark); } else { loadfriend(currentuser->userid); snprintf(title2, sizeof (title2), "[群体信件] %.60s", title); for (i = 0; i < friendnum; i++) { if (getuser(fff[i].id, &u) <= 0) { u = NULL; continue; } if (inoverride (currentuser->userid, fff[i].id, "rejects")) continue; post_mail(fff[i].id, title2, filename, currentuser->userid, currentuser->username, fromhost, sig - 1, mark); } } if (backup) post_mail(currentuser->userid, title2, filename, currentuser->userid, currentuser->username, fromhost, sig - 1, mark); unlink(filename); if (reply > 0) { /* churinga - add reply mark 'R' */ if (get_record(&fh, sizeof(struct fileheader), num, mymaildir) > 0) { fh.accessed |= FH_REPLIED; put_record(&fh, sizeof (struct fileheader), num, mymaildir); } } if(!(u->userdefine & DEF_SEEWELC1)) printf("发送失败,此用户已经关闭信箱。"); else printf("信件已寄给%s.<br>\n", allfriend ? "所有好友" : userid); if (backup) printf("信件已经备份.<br>\n"); printf("<a href='javascript:history.go(-2)'>返回</a>"); http_quit(); return 0; }
int main(int argc, char *argv[]) { unsigned int letters[0x100]; unsigned int order[0x100]; unsigned char *pairs[0x100]; FILE *f; unsigned int i, j, k; int first, second; /* read letters */ for (i = 0; i < 0x100; i++) { letters[i] = 0; pairs[i] = NULL; } f = fopen(argv[2], "r"); while (fscanf(f, "%lx", &j) == 1) letters[j] = 0xff; fclose(f); /* read stuff */ j = 0; while ((first = getchar()) != EOF) { pairs[first] = (unsigned char*)malloc(0x101); order[j] = first; letters[first] = j++; getchar(); /* : */ i = 0; while ((second = getchar()) != '\n') pairs[first][i++] = (unsigned char*)second; pairs[first][i] = '\0'; } assert(order[0] == FILL_CHARACTER); puts("/* THIS IS A GENERATED TABLE, see data/pairtoc.c. */"); printf("static const unsigned char LETTER_"); for (i = 0; argv[1][i]; i++) printf("%c", mytoupper(argv[1][i])); puts("[] = {"); for (i = 0; i < 0x100; i++) { if (i % 8 == 0) printf(" "); printf("%3u", letters[i]); if (i % 8 == 7) printf(", /* 0x%02x */\n", i-7); else printf(", "); } puts("};\n"); puts("/* THIS IS A GENERATED TABLE, see data/pairtoc.c. */"); printf("static const unsigned char *PAIR_"); for (i = 0; argv[1][i]; i++) printf("%c", mytoupper(argv[1][i])); puts("[] = {\n"); printf(" (unsigned char*)\""); for (k = 0; pairs[FILL_CHARACTER][k]; k++) { printf("\\x%02x", pairs[FILL_CHARACTER][k]); } printf("\", /* FILLCHAR */\n"); for (i = 1; i < j; i++) { printf(" (unsigned char*)\""); for (k = 0; pairs[order[i]][k]; k++) { if (pairs[order[i]][k] == FILL_CHARACTER) printf("."); else printf("\\x%02x", pairs[order[i]][k]); } printf("\", /* 0x%02x */\n", order[i]); } puts("};\n"); return 0; }