<commit_before>#include "NiKomStr.h"
#include "NiKomLib.h"
#include "NiKomBase.h"

#include "UnreadTexts.h"
#include "ConferenceTexts.h"
#include "Util.h"
#include "Funcs.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/dos.h>

/* ******* Local functions ******** */

void shiftBitmap(struct UnreadTexts *unreadTexts, int textNumberToAccomodate);
void trimLowestPossibleUnreadText(struct UnreadTexts *unreadTexts, int conf,
  struct System *Servermem);
int maybeConvertUnreadTextsData(int userId, struct UnreadTexts *unreadTexts,
  struct NiKomBase *NiKomBase);

/* ******* Library functions ******** */

/****** nikom.library/ChangeUnreadTextStatus *************************

    NAME
        ChangeUnreadTextStatus -- Marks a text as read or unread.

    SYNOPSIS
        ChangeUnreadTextStatus(textNumber, markAsUnread, unreadTexts)
                               D0          D1            A0
        void ChangeUnreadTextStatus(int, int, struct UnreadTexts *);

    FUNCTION
        Marks the given text number as either read or unread in the
        given unreadTexts struct.

    INPUTS
        textNumber   - the text number to mark.
        markAsUnread - 0 to mark as read, non-zero to mark as unread.
        unreadTexts  - the UnreadTexts structure to make changes to.

**********************************************************************/

void __saveds AASM LIBChangeUnreadTextStatus(
   register __d0 int textNumber AREG(d0),
   register __d1 int markAsUnread AREG(d1),
   register __a0 struct UnreadTexts *unreadTexts AREG(a0),
   register __a6 struct NiKomBase *NiKomBase AREG(a6)) {

   if(textNumber < unreadTexts->bitmapStartText) {
      return;
   }
   if(textNumber >= (unreadTexts->bitmapStartText + UNREADTEXTS_BITMAPSIZE)) {
     if(markAsUnread) {
       return;
     }
     shiftBitmap(unreadTexts, textNumber);
   }

   if(markAsUnread) {
      BAMSET(unreadTexts->bitmap, textNumber % UNREADTEXTS_BITMAPSIZE);
   } else {
      BAMCLEAR(unreadTexts->bitmap, textNumber % UNREADTEXTS_BITMAPSIZE);
   }
}

/****** nikom.library/IsTextUnread ***********************************

    NAME
        IsTextUnread -- Checks if a text is unread or not

    SYNOPSIS
        status = IsTextUnread(textNumber, unreadTexts)
        D0                    D0          A0
        int IsTextUnread(int, struct UnreadTexts *);

    FUNCTION
        Checks if the given text number is unread or not. Texts lower
        than the range of the internal bitmap are always considered to
        be read. Texts higher than the range are always considered to<commit_msg>Fixing so that when you mark a text as unread that is below the "lowestPossibleUnreadText" pointer the pointer is set to that textId so that it doesn't get missed by the KOM engine.<commit_after>#include "NiKomStr.h"
#include "NiKomLib.h"
#include "NiKomBase.h"

#include "UnreadTexts.h"
#include "ConferenceTexts.h"
#include "Util.h"
#include "Funcs.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/dos.h>

/* ******* Local functions ******** */

void shiftBitmap(struct UnreadTexts *unreadTexts, int textNumberToAccomodate);
void trimLowestPossibleUnreadText(struct UnreadTexts *unreadTexts, int conf,
  struct System *Servermem);
int maybeConvertUnreadTextsData(int userId, struct UnreadTexts *unreadTexts,
  struct NiKomBase *NiKomBase);

/* ******* Library functions ******** */

/****** nikom.library/ChangeUnreadTextStatus *************************

    NAME
        ChangeUnreadTextStatus -- Marks a text as read or unread.

    SYNOPSIS
        ChangeUnreadTextStatus(textId, markAsUnread, unreadTexts)
                               D0          D1            A0
        void ChangeUnreadTextStatus(int, int, struct UnreadTexts *);

    FUNCTION
        Marks the given text number as either read or unread in the
        given unreadTexts struct.

    INPUTS
        textId   - the text number to mark.
        markAsUnread - 0 to mark as read, non-zero to mark as unread.
        unreadTexts  - the UnreadTexts structure to make changes to.

**********************************************************************/

void __saveds AASM LIBChangeUnreadTextStatus(
   register __d0 int textId AREG(d0),
   register __d1 int markAsUnread AREG(d1),
   register __a0 struct UnreadTexts *unreadTexts AREG(a0),
   register __a6 struct NiKomBase *NiKomBase AREG(a6)) {
  int confId;

   if(textId < unreadTexts->bitmapStartText) {
      return;
   }
   confId = GetConferenceForText(textId);
   if(confId == -1) {
     return;
   }
   if(textId >= (unreadTexts->bitmapStartText + UNREADTEXTS_BITMAPSIZE)) {
     if(markAsUnread) {
       return;
     }
     shiftBitmap(unreadTexts, textId);
   }

   if(markAsUnread) {
      BAMSET(unreadTexts->bitmap, textId % UNREADTEXTS_BITMAPSIZE);
      if(unreadTexts->lowestPossibleUnreadText[confId] > textId) {
        unreadTexts->lowestPossibleUnreadText[confId] = textId;
      }
   } else {
      BAMCLEAR(unreadTexts->bitmap, textId % UNREADTEXTS_BITMAPSIZE);
   }
}

/****** nikom.library/IsTextUnread ***********************************

    NAME
        IsTextUnread -- Checks if a text is unread or not

    SYNOPSIS
        status = IsTextUnread(textNumber, unreadTexts)
        D0                    D0          A0
        int IsTextUnread(int, struct UnreadTexts *);

    FUNCTION
        Checks if the given text number is unread or not. Texts lower
        than the range of the internal bitmap are always considered to
        be read. Texts higher than the range are always considered to
{'fraction_non_alphanumeric': 0.1337321837057892, 'fraction_numerical': 0.0054548653879992965, 'mean_word_length': 3.222882615156018, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3476395', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1783, 'n_words': 480}