static MEMO_EL * DoActions( MEMO_EL * el, ACTION act ) /****************************************************/ /* Perform one action on the memos. */ { MEMO_EL * new_el; MEMO_EL * prev_el; switch( act ) { case HELP: Help(); break; case ADD: new_el = AddMemo( el ); if( new_el != NULL ) { el = new_el; MemosModified = TRUE; } break; case DELETE: el = DeleteMemo( el ); MemosModified = TRUE; break; case REPLACE: prev_el = el; new_el = AddMemo( el ); if( new_el != NULL ) { DeleteMemo( prev_el ); MemosModified = TRUE; } break; case SHOW: DisplayMemo( el ); break; case UP: el = DoUpAction( el ); break; case DOWN: el = DoDownAction( el ); break; case TOP: el = NULL; break; case TODAY: el = ShowTodaysMemos(); break; case SAVE: if( SaveMemos() ) { MemosModified = FALSE; } break; case QUIT: if( WantToQuit() ) { QuitFlag = TRUE; el = NULL; } } return( el ); }
int PurgeMemos(struct MemoInfo *mptr) { int ret; struct Memo *memoptr, *next; if (!mptr) return 0; ret = 0; for (memoptr = mptr->memos; memoptr; memoptr = next) { next = memoptr->next; if (memoptr->flags & MS_DELETE) { ++ret; DeleteMemo(mptr, memoptr); } } mptr->memocnt -= ret; if (!mptr->memocnt) { /* * mptr has no more memos - delete it from the memolist[] * array */ DeleteMemoList(mptr); return (ret); } else if (ret) { int cnt; /* * its possible that the indices of the memos are now * messed up - if you have 3 memos, and you delete the 2nd one, * you'll have 2 memos, one with an index of 1, and the other * with an index of 3 - check if consecutive indices are * one higher than the previous - if not, fix it */ cnt = 0; for (memoptr = mptr->memos; memoptr; memoptr = memoptr->next) { if (memoptr->index != (cnt + 1)) memoptr->index = cnt + 1; ++cnt; } } return (ret); } /* PurgeMemos() */