/* * Split a headline into its useful components. * Copy the line into dynamic string space, then set * pointers into the copied line in the passed headline * structure. Actually, it scans. */ void parse(char *line, struct headline *hl, char *pbuf) { char *cp, *sp; char word[LINESIZE]; hl->l_from = NULL; hl->l_tty = NULL; hl->l_date = NULL; cp = line; sp = pbuf; /* * Skip over "From" first. */ cp = nextword(cp, word); cp = nextword(cp, word); if (*word) hl->l_from = copyin(word, &sp); if (cp != NULL && strncmp(cp, "tty", 3) == 0) { cp = nextword(cp, word); hl->l_tty = copyin(word, &sp); } if (cp != NULL) hl->l_date = copyin(cp, &sp); }
/* * Split a headline into its useful components. * Copy the line into dynamic string space, then set * pointers into the copied line in the passed headline * structure. Actually, it scans. */ void parse(char line[], struct headline *hl, char pbuf[]) { char *cp, *sp; char word[LINESIZE]; hl->l_from = NULL; hl->l_tty = NULL; hl->l_date = NULL; cp = line; sp = pbuf; /* * Skip over "From" first. */ cp = nextword(cp, word); /* * Check for missing return-path. */ if (isdate(cp)) { hl->l_date = copyin(cp, &sp); return; } cp = nextword(cp, word); if (strlen(word) > 0) hl->l_from = copyin(word, &sp); if (cp != NULL && strncmp(cp, "tty", 3) == 0) { cp = nextword(cp, word); hl->l_tty = copyin(word, &sp); } if (cp != NULL) hl->l_date = copyin(cp, &sp); }
static void ccf_search(adns_state ads, const char *fn, int lno, const char *buf) { const char *bufp, *word; char *newchars, **newptrs, **pp; int count, tl, l; if (!buf) return; bufp= buf; count= 0; tl= 0; while (nextword(&bufp,&word,&l)) { count++; tl += l+1; } newptrs= malloc(sizeof(char*)*count); if (!newptrs) { saveerr(ads,errno); return; } newchars= malloc(tl); if (!newchars) { saveerr(ads,errno); free(newptrs); return; } bufp= buf; pp= newptrs; while (nextword(&bufp,&word,&l)) { *pp++= newchars; memcpy(newchars,word,l); newchars += l; *newchars++ = 0; } freesearchlist(ads); ads->nsearchlist= count; ads->searchlist= newptrs; }
int uue_download(unsigned address) { char *buffer = (char *)address; char *s; int errs = 0; int i; unsigned c, w; int offset = 0; int len; unsigned led_status = 3; char command_line[256]; char gpbuff[256]; printf("Ready to download. Use 'transmit' option on terminal emulator to download file. \n"); s = command_line; do { if (ReadLineZ(s, sizeof(command_line)-1) == -1) return -1; } while (!cistreq(s, BEGIN, ' ')); s = nextword(s); s = nextword(s); strcpy(gpbuff, s); do { s = command_line; len = ReadLineZ(s, sizeof(command_line)-1); led_status ^= 0x04; SetLEDs(led_status); if (len == -1 || cistreq(s, END, ' ')) break; c = *s++; if (!c) continue; len = c - 0x20; if (len == 0) continue; if (len > 45) { errs++; continue; } i = 0; while (1) { c = *s; if (c) { c -= 0x20; if (c >= 0x40) { errs++; break; } s++; } w = (w << 6) + c; if ((++i & 3) == 0) { buffer[offset++] = w >> 16; if (--len == 0) break; buffer[offset++] = w >> 8; if (--len == 0) break; buffer[offset++] = w; if (--len == 0) break; } } } while (1); SetLEDs(3); if (errs) printf("Error: %d errors encountered during download. \n", errs); printf("Loaded file %s at address %x, size = %d \n", gpbuff, buffer, offset); return 0; }
static int32 parse_tmat_senmap(mdef_t * m, char *line, int32 lineno, s3pid_t p) { int32 wlen, n, s; char *word; char tmp; /* Read transition matrix id */ if ((sscanf(line, "%d%n", &n, &wlen) != 1) || (n < 0)) E_FATAL("Line %d: Missing or bad transition matrix id\n", lineno); m->phone[p].tmat = n; if (mdef->n_tmat <= n) E_FATAL("Line %d: tmat-id(%d) > #tmat in header(%d)\n", lineno, n, mdef->n_tmat); line += wlen; /* Read senone mappings for each emitting state */ for (n = 0; n < mdef->n_emit_state; n++) { if ((sscanf(line, "%d%n", &s, &wlen) != 1) || (s < 0)) E_FATAL ("Line %d: Missing or bad state[%d]->senone mapping\n", lineno, n); m->phone[p].state[n] = s; if (p < max_ciphone) { if (mdef->n_ci_sen <= s) E_FATAL ("Line %d: CI-senone-id(%d) > #CI-senone in header(%d)\n", lineno, s, mdef->n_ci_sen); } if (mdef->n_sen <= s) E_FATAL ("Line %d: Senone-id(%d) > #senone in header(%d)\n", lineno, s, mdef->n_sen); line += wlen; } /* Check for the last non-emitting state N */ if (((wlen = nextword(line, delim, &word, &tmp)) < 0) || (strcmp(word, "N") != 0)) E_FATAL("Line %d: Missing non-emitting state spec\n", lineno); line = word + wlen; word[wlen] = tmp; /* Check for end of line */ if ((wlen = nextword(line, delim, &word, &tmp)) >= 0) E_FATAL ("Line %d: Non-empty beyond non-emitting final state\n", lineno); return 0; }
static int32 parse_base_line (mdef_t *m, char *line, int32 lineno, s3pid_t p) { int32 wlen, n; char *word; s3cipid_t ci; char tmp; /* Read base phone name */ if ((wlen = nextword (line, delim, &word, &tmp)) < 0) /* Empty line */ E_FATAL("Line %d: Incomplete base phone line\n", lineno); /* Make sure it's not a duplicate */ ci = mdef_ciphone_id (m, word); if (IS_CIPID(ci)) E_FATAL("Line %d: Duplicate base phone: %s\n", lineno, word); /* Add ciphone to ciphone table with id p */ ciphone_add (m, word, p); ci = p; /* Restore original delimiter to word */ line = word+wlen; word[wlen] = tmp; /* Read and skip "-" for lc, rc, wpos */ for (n = 0; n < 3; n++) { if ((wlen = nextword (line, delim, &word, &tmp)) < 0) E_FATAL("Line %d: Incomplete base phone line\n", lineno); if ((wlen != 1) || (word[0] != '-')) E_FATAL("Line %d: %s instead of '-' in base phone line\n", word, lineno); line = word+wlen; word[wlen] = tmp; } /* Read filler attribute, if present */ if ((wlen = nextword (line, delim, &word, &tmp)) < 0) E_FATAL("Line %d: Incomplete base phone line\n", lineno); if (strcmp (word, "filler") == 0) m->ciphone[ci].filler = 1; else if (strcmp (word, "n/a") == 0) m->ciphone[ci].filler = 0; else E_FATAL("Line %d: Illegal attribute string: %s\n", lineno, word); line = word+wlen; word[wlen] = tmp; if (triphone_add (m, ci, BAD_CIPID, BAD_CIPID, WORD_POSN_UNDEFINED, p) < 0) E_FATAL("Line %d: Duplicate/Bad triphone\n", lineno); /* Parse remainder of line: transition matrix and state->senone mappings */ parse_tmat_senmap (m, line, lineno, p); return 0; }
int chat_kick( int unum, char *msg ) { char *twit = nextword(&msg); int rnum = users[unum].room; int recunum; if (!OPERATOR(unum) && !MANAGER(unum)) { send_to_unum(unum, "*** You're not operator\n", -1); return 0; } if ((recunum = chatid_to_indx(twit)) == -1) { /* no such user */ sprintf(genbuf, "*** No such chatid '%s'\n", twit); send_to_unum(unum, genbuf, -1); return 0; } if (rnum != users[recunum].room) { sprintf(genbuf, "*** '%s' is not in this room\n", users[recunum].chatid); send_to_unum(unum, genbuf, -1); return 0; } exit_room(recunum, EXIT_KICK, msg); if (rnum == 0) logout_user(recunum); else enter_room(recunum, mainroom, (char *)NULL); return 0; }
int chat_invite( int unum, char *msg ) { char *invitee = nextword(&msg); int rnum = users[unum].room; int recunum; if (!OPERATOR(unum)) { send_to_unum(unum, "*** You're not operator\n", -1); return 0; } if ((recunum = chatid_to_indx(invitee)) == -1) { /* no such user */ sprintf(genbuf, "*** No such chatid '%s'\n", invitee); send_to_unum(unum, genbuf, -1); return 0; } if (rooms[rnum].invites[recunum] == 1) { sprintf(genbuf, "*** %s already has a key\n", users[recunum].chatid); send_to_unum(unum, genbuf, -1); return 0; } rooms[rnum].invites[recunum] = 1; sprintf(genbuf, "*** %s gave you a key to room '%s'\n", users[unum].chatid, rooms[rnum].name); send_to_unum(recunum, genbuf, unum); sprintf(genbuf, "*** Key given to %s\n", users[recunum].chatid); send_to_unum(unum, genbuf, -1); return 0; }
void lastview( /* return to a previous view */ char *s ) { char buf[128]; char *fname; int success; VIEW nv; /* get parameters from a file */ if (nextword(buf, sizeof(buf), s) != NULL) { nv = stdview; if ((fname = getpath(buf, "", R_OK)) == NULL || (success = viewfile(fname, &nv, NULL)) == -1) { sprintf(errmsg, "cannot open \"%s\"", buf); error(COMMAND, errmsg); return; } if (!success) error(COMMAND, "wrong file format"); else newview(&nv); return; } if (oldview.type == 0) { /* no old view! */ error(COMMAND, "no previous view"); return; } nv = ourview; ourview = oldview; oldview = nv; newimage(NULL); }
void saveview( /* save view to rad file */ char *s ) { char view[64]; char *fname; FILE *fp; if (*atos(view, sizeof(view), s)) { if (isint(view)) { error(COMMAND, "cannot write view by number"); return; } s = sskip(s); } if (nextword(rifname, sizeof(rifname), s) == NULL && !rifname[0]) { error(COMMAND, "no previous rad file"); return; } if ((fname = getpath(rifname, NULL, 0)) == NULL || (fp = fopen(fname, "a")) == NULL) { sprintf(errmsg, "cannot open \"%s\"", rifname); error(COMMAND, errmsg); return; } fputs("view= ", fp); fputs(view, fp); fprintview(&ourview, fp); putc('\n', fp); fclose(fp); }
int chat_makeop( int unum, char *msg ) { char *newop = nextword(&msg); int rnum = users[unum].room; int recunum; if (!OPERATOR(unum)) { send_to_unum(unum, "*** You're not operator\n", -1); return 0; } if ((recunum = chatid_to_indx(newop)) == -1) { /* no such user */ sprintf(genbuf, "*** No such chatid '%s'\n", newop); send_to_unum(unum, genbuf, -1); return 0; } if (unum == recunum) { sprintf(genbuf, "*** You're already op\n"); send_to_unum(unum, genbuf, -1); return 0; } if (rnum != users[recunum].room) { sprintf(genbuf, "*** '%s' is not in this room\n", users[recunum].chatid); send_to_unum(unum, genbuf, -1); return 0; } users[unum].flags &= ~FLG_CHATOP; users[recunum].flags |= FLG_CHATOP; sprintf(genbuf, "*** %s gave Op to %s\n", users[unum].chatid, users[recunum].chatid); send_to_room(rnum, genbuf, -1); return 0; }
int chat_private( int unum, char *msg ) { char *recipient = nextword(&msg); int recunum = fuzzy_chatid_to_indx(recipient); if (recunum < 0) { /* no such user, or ambiguous */ if (recunum == -1) sprintf(genbuf, "*** No such chatid '%s'\n", recipient); else sprintf(genbuf, "*** '%s' is ambiguous: try more letters", recipient); send_to_unum(unum, genbuf, -1); return 0; } if (*msg) { sprintf(genbuf, "*%s* ", users[unum].chatid); strncat(genbuf, msg, CHATLINE_TEXT_MAX); strcat(genbuf, "\n"); if (send_to_unum(recunum, genbuf, unum)) { sprintf(genbuf, "%s> ", users[recunum].chatid); strncat(genbuf, msg, CHATLINE_TEXT_MAX); strcat(genbuf, "\n"); } else sprintf(genbuf, "*** You are being ignored by '%s'\n", users[recunum].chatid); send_to_unum(unum, genbuf, -1); } return 0; }
/* * A word is invalid if it is not in the dictionary * At this point it is already known that the word can be formed from * the current board */ int validword(char *word) { int j; char *q, *w; j = word[0] - 'a'; if (dictseek(dictfp, dictindex[j].start, SEEK_SET) < 0) { cleanup(); errx(1, "seek error in validword()"); } while ((w = nextword(dictfp)) != NULL) { int ch; if (*w != word[0]) /* end of words starting with word[0] */ break; q = word; while ((ch = *w++) == *q++ && ch != '\0') ; if (*(w - 1) == '\0' && *(q - 1) == '\0') return (1); } if (dictfp != NULL && feof(dictfp)) /* Special case for z's */ clearerr(dictfp); return (0); }
int chat_query_chatid( int unum, char *msg ) { USERDATA udata; int recunum; char *recipient = nextword(&msg); send_to_unum(unum, "***\n", -1); if (*recipient == '\0') { /* map all chatids to userids */ return (chat_map_chatids(unum)); } recunum = fuzzy_chatid_to_indx(recipient); if (recunum < 0) { /* no such user, or ambiguous */ if (recunum == -1) sprintf(genbuf, "*** No such chatid '%s'\n", recipient); else sprintf(genbuf, "*** '%s' is ambiguous: try more letters", recipient); send_to_unum(unum, genbuf, -1); return 0; } if (utable_get_record(users[recunum].utent, &udata) != S_OK || strcmp(users[recunum].userid, udata.u.userid) || udata.u.mode != M_CHAT) { sprintf(genbuf, "*** '%s' is apparently no longer here\n", users[recunum].userid); send_to_unum(unum, genbuf, -1); exit_room(recunum, EXIT_LOSTCONN, (char *)NULL); logout_user(recunum); return 0; } sprintf(genbuf, "*** %s is %s (%s)\n", users[recunum].chatid, udata.u.userid, udata.u.username); send_to_unum(unum, genbuf, -1); sprintf(genbuf, "*** Logged in from %s\n", udata.u.fromhost); send_to_unum(unum, genbuf, -1); return 0; }
void writepict( /* write the picture to a file */ char *s ) { static char buf[128]; char *fname; FILE *fp; COLR *scanline; int y; /* XXX relies on words.c 2.11 behavior */ if (nextword(buf, sizeof(buf), s) == NULL && !buf[0]) { error(COMMAND, "no file"); return; } if ((fname = getpath(buf, NULL, 0)) == NULL || (fp = fopen(fname, "w")) == NULL) { sprintf(errmsg, "cannot open \"%s\"", buf); error(COMMAND, errmsg); return; } SET_FILE_BINARY(fp); (*dev->comout)("writing \""); (*dev->comout)(fname); (*dev->comout)("\"...\n"); /* write header */ newheader("RADIANCE", fp); fputs(progname, fp); fprintview(&ourview, fp); if (octname != NULL) fprintf(fp, " %s\n", octname); else putc('\n', fp); fprintf(fp, "SOFTWARE= %s\n", VersionID); fputnow(fp); if (exposure != 1.0) fputexpos(exposure, fp); if (dev->pixaspect != 1.0) fputaspect(dev->pixaspect, fp); fputformat(COLRFMT, fp); putc('\n', fp); fprtresolu(hresolu, vresolu, fp); scanline = (COLR *)malloc(hresolu*sizeof(COLR)); if (scanline == NULL) { error(COMMAND, "not enough memory!"); fclose(fp); unlink(fname); return; } for (y = vresolu-1; y >= 0; y--) { getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); if (fwritecolrs(scanline, hresolu, fp) < 0) break; } free((void *)scanline); if (fclose(fp) < 0) error(COMMAND, "write error"); }
int docmd(void) { char *p = NULL; const struct cmd_table *ct = cmd_table, *cs; cmd.argc = 1; if (cmd.cmd == NULL) { /* command */ for (p = cmd_buf; *p == ' ' || *p == '\t'; p++) ; if (*p == '#' || *p == '\0') { /* comment or empty string */ #ifdef DEBUG printf("rem\n"); #endif return 0; } ct = cmd_table; cs = NULL; cmd.argv[cmd.argc] = p; /* in case it's shortcut boot */ p = whatcmd(&ct, p); if (ct == NULL) { cmd.argc++; ct = cmd_table; } else if (ct->cmd_type == CMDT_SET && p != NULL) { cs = cmd_set; #ifdef MACHINE_CMD } else if (ct->cmd_type == CMDT_MDC && p != NULL) { cs = MACHINE_CMD; #endif } if (cs != NULL) { p = whatcmd(&cs, p); if (cs == NULL) { printf("%s: syntax error\n", ct->cmd_name); return 0; } ct = cs; } cmd.cmd = ct; } cmd.argv[0] = ct->cmd_name; while (p && cmd.argc+1 < sizeof(cmd.argv) / sizeof(cmd.argv[0])) { cmd.argv[cmd.argc++] = p; p = nextword(p); } cmd.argv[cmd.argc] = NULL; #ifdef REGRESS printf("%s %s\n", cmd.argv[0], (cmd.argv[1] == NULL) ? "(null)" : cmd.argv[1]); #else return (*cmd.cmd->cmd_exec)(); #endif }
int countword(char *s) { int i=0; if( *(s=firstword(s)) ) i++; while( *(s=nextword(s)) ) i++; return(i); }
void chat_sendmsg(chatcontext * pthis, const char *arg) { /* send msg in chatroom , by alex, 96.9.5 */ char userid[IDLEN + 1]; char msg[STRLEN * 2]; struct user_info *uin; int state; nextword(&arg, userid, sizeof(userid)); if (!userid[0]) { printchatline(pthis, "\x1b[37m*** \x1b[32m请输入你要发消息的 ID\x1b[37m ***\x1b[m"); return; } else if (!*arg) { printchatline(pthis, "\x1b[37m*** \x1b[32m请输入你要发的消息\x1b[37m ***\x1b[m"); return; } else if (!HAS_PERM(getCurrentUser(), PERM_PAGE)) { /* Leeward 98.07.30 */ sprintf(msg, "\x1b[32m你没有发信息的权限\x1b[m"); } else { uin = t_search(userid, false); if (uin == NULL) { sprintf(msg, "\x1b[32m%s\x1b[37m 并没有上站\x1b[m", userid); } else if (LOCKSCREEN == uin->mode) /* Leeward 98.02.28 */ sprintf(msg, "\x1b[32m%s\x1b[37m已经锁定屏幕,请稍候再发或给他(她)写信.\n", uin->userid); else { if (!canmsg(getCurrentUser(), uin)) sprintf(msg, "\x1b[32m%s\x1b[37m已经关闭接受讯息的呼叫器.\n", uin->userid); else if (false == canIsend2(getCurrentUser(),uin->userid)) sprintf(msg, "\x1b[32m%s\x1b[37m拒绝接受你的讯息.\n", uin->userid); /*Haohmaru.99.6.6,检查是否被ignore */ else { if (get_unreadcount(uin->userid) > MAXMESSAGE) sprintf(msg, "对方尚有一些讯息未处理,请稍候再发或给他(她)写信...\n"); else { /* 保存所发msg的目的uid 1998.7.5 by dong */ strcpy(getSession()->MsgDesUid, uin->userid); state = do_sendmsg(uin, arg, 2); if (state == 1) sprintf(msg, "\x1b[37m已经发消息给 \x1b[32m%s\x1b[37m 了\x1b[m", uin->userid); else if (state == -2) sprintf(msg, "\x1b[37m对方已经离线了...\x1b[m"); else sprintf(msg, "\033[37对方不接受你的消息...\033[m"); } } } } printchatline(pthis, msg); }
void test_function_md5(param_test_thread* p) { /**********************/ /** Define variables **/ /**********************/ long count = 0; mpz_t nb; char word[100]; int i = 0; unsigned char hash[16]; char tmp[2]; char test[] = "05b28d17a7b6e7024b6e5d8cc43a8bf7"; /**************************/ /** Initialize variables **/ /**************************/ mpz_init_set_ui(nb, 540504354034); int2word(nb, "abcdefghijklmnopqrstuvwxyz", 26, word); /** Transfor hash (to externalize **/ for(i = 0; i < 16; i++) { tmp[0] = test[i*2]; tmp[1] = test[i*2+1]; sscanf(tmp, "%02x", (unsigned int *)&hash[i]); } /** Calculate while time is not over **/ while(*p->time_over == 0) { count++; nextword("abcdefghijklmnopqrstuvwxyz", 26, word); // comp(hash, (unsigned char*)md5(word)); module_md5_comp(hash, word); } /** When finish, block to avoid conflict on idp and mutex_running**/ test_finish_thread(p, count); /*pthread_mutex_lock(p->mutex_idp); *p->mutex_running -= 1; *p->idp += count; If mutex_runing reach 0, all thread are terminated. End program if(*p->mutex_running <= 0) { pthread_mutex_unlock(p->mutex_finish_test); } pthread_mutex_unlock(p->mutex_idp); */ }
void Vertex::parsestr(const std::string& pstr) { std::string str = trim(pstr, " \t\r\n()"); size_t fspos = str.find_first_of(' '), espos = str.find_last_of(' '); if (fspos == std::string::npos || espos == std::string::npos || fspos == espos) { vertex_[0] = std::numeric_limits<double>::quiet_NaN(); vertex_[1] = std::numeric_limits<double>::quiet_NaN(); vertex_[2] = std::numeric_limits<double>::quiet_NaN(); return; } size_t pos = 0; std::string xstr = nextword(pos, str); std::string ystr = nextword(pos, str); std::string zstr = nextword(pos, str); vertex_[0] = atof(xstr.c_str()); vertex_[1] = atof(ystr.c_str()); vertex_[2] = atof(zstr.c_str()); }
int main(int argc, char **argv) { if (argc < 2) { printf("Usage: countwords filename\n"); exit(1); } char * filename = argv[1]; fd = fopen(filename, "r"); fgets(word,1000,stdin); int count = 0; char w[100]; nWords = 0; maxWords = 100; wordArray = (WordInfo*) malloc(sizeof(WordInfo) maxWords); while(*(w=nextword())!=NULL) { int jud = -1; int i; for(i =0; i < nWords; i++) { if(strcmp(wordArray[i].word,w) == 0) jud = i; } if(jud != -1) wordArray[i].count ++; else if(nWords < maxWords) { wordArray[nWords].word = w; wordArray[nWords++].count = 1; } else{ wordArray = (WordInfo*) realloc(wordArray,sizeof(WordInfo)*(++maxWords)); wordArray[nWords].word = w; wordArray[nWords++].count = 1; } WordInfo temp; int j; for(i = 0; i < nWords-1; i++) { for(j = i; j < nWords; j++) { if(strcmp(wordArray[i].word, wordArray[j].word) > 0){ temp = wordArray[i]; wordArray[j] = wordArray[i]; wordArray[j] = temp; } } } for( i = 0; i < nWords; i++) { printf("%s %d\n",wordArray[i].word,wordArray[i].count); } } }
double rpn_eval(char * fileName, double x) { double a,b,c; int i = 0; char *word; FILE * fd = fopen(fileName, "r"); if (fd == NULL) { printf("Could not open file %s\n", fileName); exit(1); } while((word = nextword(fd)) != NULL) { if (strcmp(word, "x")==0) { stack_push(x); continue; } else if (strcmp(word, "+")==0) { stack_push(stack_pop() + stack_pop()); } else if (strcmp(word, "-")==0) { a = stack_pop(); b = stack_pop(); stack_push(b - a); } else if (strcmp(word, "*")==0) { a = stack_pop(); b = stack_pop(); stack_push(a * b); } else if (strcmp(word, "/")==0) { a = stack_pop(); b = stack_pop(); stack_push(b / a); } else if (strcmp(word, "sin")==0) stack_push(sin(stack_pop())); else if (strcmp(word, "cos")==0) stack_push(cos(stack_pop())); else if (strcmp(word, "log")==0) stack_push(log(stack_pop())); else if (strcmp(word, "exp")==0) stack_push(exp(stack_pop())); else if (strcmp(word, "pow")==0) { a = stack_pop(); b = stack_pop(); stack_push(pow(b,a)); } else { stack_push(atof(word)); } // stack_print();printf("\nWord: %s\n",word); } //printf("%s\n",word); if (stack_top() > 1) { printf("Elements remain in the stack\n"); exit(1); } //else if (stac // printf("Stack Underflow\n"); exit(1); //} if (stack_top() == 1) return stack_pop(); //else { printf("Stack Underflow\n"); exit(1); } }
int compare(char *str1, char *str2, int i, int j) { int i2 = nextword(str1, i); if (str1[i2] == '\0') i2--; if (str1[i2 - 1] == 32) i2 = i2 - 2; int k = i2 - i; int j2 = nextword(str2, j); if (str2[j2] == '\0') j2--; if (str2[j2 - 1] == 32) j2 = j2 - 2; while (i<i2 && j<j2) { if (str1[i] != str2[j]) break; else { i++; j++; } } if (i<i2) return 0; return k + 1; }
void say(char* txt) { int line = 0; while (*txt) { putchar(*txt); txt++; line++; if (line+nextword(txt) >= 79) { putchar('\n'); line = 0; } } putchar('\n'); }
int main() { int buf_len = BUFLEN; //char buf[buf_len], *wordptr; char *wordptr; //buf[0] = '\0'; char * buffer = calloc(BUFLEN, sizeof(char)); /* ... set up word filing module ... */ init_table(); /* ... read words and store them ... */ /* was: scanf("%s", buf) */ while ( (buffer = read_word(buffer, &buf_len)) != NULL ){ if (DEBUG) printf("buf = %s, buf_len: %d\n", buffer, buf_len); convert_to_lower_case( buffer ); if ( in_table( buffer ) == YES ) { if (DEBUG) printf("main: found %s in table with a value of %d ", buffer, lookup( buffer )); update( buffer, 1 + lookup( buffer ) ); } else if ( insert( buffer, 1 ) == NO ){ fprintf(stderr,"wordfreq: out of memory\n"); exit(1); } } /* ... move cursor down the table printing out results */ if (DEBUG) printf("printing the results starting with %s \n", firstword()); for( wordptr = firstword() ; wordptr != NULL; wordptr = nextword() ) printf("%5d\t%s\n", lookup( wordptr ), wordptr ); //char hello[] = "hello"; //word_delete(hello); return 0; }
int chat_roll_dice( int unum, char *msg ) { static int seeded; int ndice = 2; int die = 6; int total = 0; int i, roll; char diebuf[8]; char *rollspec = nextword(&msg); char *d; if (!seeded) { srand((int)time(NULL)); seeded++; } if ((d = strchr(rollspec, 'd')) != NULL) { *d = '\0'; die = atoi(d+1); } if (*rollspec != '\0') { ndice = atoi(rollspec); } if (ndice < 0 || ndice > 10) { send_to_unum(unum, "*** May only roll from 1 to 10 dice\n", -1); return 0; } if (die < 2 || die > 100) { send_to_unum(unum, "*** Die must have from 2 to 100 sides\n", -1); return 0; } strcpy(genbuf, "*** "); strcat(genbuf, users[unum].chatid); strcat(genbuf, " rolled ("); for (i=0; i<ndice; i++) { roll = diceroll(die); if (i > 0) strcat(genbuf, ", "); sprintf(diebuf, "%d", roll); strcat(genbuf, diebuf); total += roll; } strcat(genbuf, ") = "); sprintf(diebuf, "%d", total); strcat(genbuf, diebuf); strcat(genbuf, " on "); sprintf(diebuf, "%dd%d", ndice, die); strcat(genbuf, diebuf); strcat(genbuf, "\n"); send_to_room(users[unum].room, genbuf, unum); return 0; }
int chat_setroom( int unum, char *msg ) { char *modestr = nextword(&msg); int rnum = users[unum].room; int sign = 1; int flag; char *fstr; if (!OPERATOR(unum)) { send_to_unum(unum, "*** You're not operator\n", -1); return 0; } if (*modestr == '+') modestr++; else if (*modestr == '-') { modestr++; sign = 0; } if (*modestr == '\0') { send_to_unum(unum, "*** No flags specified\n", -1); return 0; } while (*modestr) { flag = 0; switch (*modestr) { case 'l': case 'L': flag = ROOM_LOCKED; fstr = "Locked"; break; case 's': case 'S': flag = ROOM_SECRET; fstr = "Secret"; break; default: sprintf(genbuf, "*** Unknown flag '%c'\n", *modestr); send_to_unum(unum, genbuf, -1); } if (flag && ((rooms[rnum].flags & flag) != sign*flag)) { rooms[rnum].flags ^= flag; sprintf(genbuf, "*** Mode change by %s to%s%s\n", users[unum].chatid, sign ? " " : " NOT ", fstr); send_to_room(rnum, genbuf, -1); } modestr++; } return 0; }
chat_list_by_room( int unum, char *msg ) { int whichroom; char *roomstr = nextword(&msg); if (*roomstr == '\0') whichroom = users[unum].room; else { if ((whichroom = roomid_to_indx(roomstr)) == -1) { sprintf(genbuf, "*** No such room '%s'\n", roomstr); send_to_unum(unum, genbuf, -1); return 0; } if ((rooms[whichroom].flags & ROOM_SECRET) && !MANAGER(unum)) { send_to_unum(unum, "*** Cannot list users in secret rooms\n", -1); return 0; } } return (chat_do_user_list(unum, msg, whichroom)); }
static char * whatcmd(const struct cmd_table **ct, char *p) { char *q; int l; q = nextword(p); for (l = 0; p[l]; l++) ; while ((*ct)->cmd_name != NULL && strncmp(p, (*ct)->cmd_name, l)) (*ct)++; if ((*ct)->cmd_name == NULL) *ct = NULL; return q; }
int chat_join( int unum, char *msg ) { char *roomid = nextword(&msg); if (RESTRICTED(unum)) { send_to_unum(unum, "*** You do not have permission to join other rooms\n", -1); return 0; } if (*roomid == '\0') { send_to_unum(unum, "*** You must specify a room\n", -1); return 0; } if (!is_valid_roomname(roomid)) { send_to_unum(unum, "*** Invalid room name\n", -1); return 0; } enter_room(unum, roomid, msg); return 0; }