/** * The /ms read command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int do_read(User * u) { MemoInfo *mi; ChannelInfo *ci; char *numstr = strtok(NULL, " "), *chan = NULL; int num, count; if (numstr && *numstr == '#') { chan = numstr; numstr = strtok(NULL, " "); if (!(ci = cs_findchan(chan))) { notice_lang(s_MemoServ, u, CHAN_X_NOT_REGISTERED, chan); return MOD_CONT; } else if (ci->flags & CI_VERBOTEN) { notice_lang(s_MemoServ, u, CHAN_X_FORBIDDEN, chan); return MOD_CONT; } else if (!check_access(u, ci, CA_MEMO)) { notice_lang(s_MemoServ, u, ACCESS_DENIED); return MOD_CONT; } mi = &ci->memos; } else { if (!nick_identified(u)) { notice_lang(s_MemoServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ); return MOD_CONT; } mi = &u->na->nc->memos; } num = numstr ? atoi(numstr) : -1; if (!numstr || (stricmp(numstr, "LAST") != 0 && stricmp(numstr, "NEW") != 0 && num <= 0)) { syntax_error(s_MemoServ, u, "READ", MEMO_READ_SYNTAX); } else if (mi->memocount == 0) { if (chan) notice_lang(s_MemoServ, u, MEMO_X_HAS_NO_MEMOS, chan); else notice_lang(s_MemoServ, u, MEMO_HAVE_NO_MEMOS); } else { int i; if (stricmp(numstr, "NEW") == 0) { int readcount = 0; for (i = 0; i < mi->memocount; i++) { if (mi->memos[i].flags & MF_UNREAD) { read_memo(u, i, mi, chan); readcount++; } } if (!readcount) { if (chan) notice_lang(s_MemoServ, u, MEMO_X_HAS_NO_NEW_MEMOS, chan); else notice_lang(s_MemoServ, u, MEMO_HAVE_NO_NEW_MEMOS); } } else if (stricmp(numstr, "LAST") == 0) { for (i = 0; i < mi->memocount - 1; i++); read_memo(u, i, mi, chan); } else { /* number[s] */ if (!process_numlist(numstr, &count, read_memo_callback, u, mi, chan)) { if (count == 1) notice_lang(s_MemoServ, u, MEMO_DOES_NOT_EXIST, num); else notice_lang(s_MemoServ, u, MEMO_LIST_NOT_FOUND, numstr); } } } return MOD_CONT; }
void main(void) { int offset; int ret; int i; DsDisplayBlockClear(0, 0, 240, 120); DsPrintf(20,0,16,"Looking up memo..."); /* Read each chunk of data from the memo */ offset = 0; for (i=0; i<NR_CHUNKS; i++) { int len = strlen(pp_file_data[i]); char buf[512]; memset(buf, 0, 512); if ( (ret = read_memo(FILENAME, buf, offset, len)) >= 0) { char str[NAME_SIZE]; int j; /* Success! Display the data and the length of the memo */ DsDisplayBlockClear(0, 40, 240, 11); DsPrintf(10,40,32,"Read OK, length: "); itoa(str, offset+len); DsPrintf(100,40,32, str); DsDisplayBlockClear(0, 110, 240, 11); DsPrintf(10,110,32, buf); /* Verify that the data matches the input */ for (j=0; j<len; j++) { if (buf[j] != *(pp_file_data[i]+j)) { DsDisplayBlockClear(0, 40, 240, 11); DsPrintf(10,40,32,"Data not consistent:"); goto out; } } } else { /* Failure! */ DsDisplayBlockClear(0, 40, 240, 11); switch (ret) { case -1: DsPrintf(10,40,32,"Read error DbOpen"); break; case -2: DsPrintf(10,40,32,"Read error DbReadText"); break; case -3: DsPrintf(10,40,32,"Read error DbReadField"); break; case -4: DsPrintf(10,40,32,"Read error DbFindRecord"); break; case -5: DsPrintf(10,40,32,"Read error strcmp"); break; default: break; } } offset+=len; } out: /* Cleanup after the app */ wait_anykey(); DsEventClear(); DsDisplayBlockClear(0, 0, 240, 120); DsAddinTerminate(); }