コード例 #1
0
ファイル: KOM.c プロジェクト: punktniklas/NiKom
struct Kommando *getCommandToExecute(int defaultCmd) {
  int parseRes, cmdId;
  struct Alias *alias;
  static badCommandCnt = 0;
  static char aliasbuf[1081];

  if(GetString(999, NULL)) {
    return NULL;
  }
  if(inmat[0]=='.' || inmat[0]==' ') {
    return NULL;
  }
  if(inmat[0] && (alias = parsealias(inmat))) {
    strcpy(aliasbuf, alias->blirtill);
    strcat(aliasbuf, " ");
    strncat(aliasbuf, FindNextWord(inmat),980);
    strcpy(inmat,aliasbuf);
  }
  
  parseRes = parse(inmat);
  switch(parseRes) {
  case -1:
    SendString("\r\n\n%s\r\n", CATSTR(MSG_KOM_INVALID_COMMAND));
    if(++badCommandCnt >= 2 && !(Servermem->inne[nodnr].flaggor & INGENHELP)) {
      sendfile("NiKom:Texter/2fel.txt");
    }
    return NULL;

  case -2:
    return NULL; // Ambigous command

  case -3:
    cmdId = defaultCmd;
    break;

  case -4:
    SendString("\r\n\n%s\r\n", CATSTR(MSG_KOM_NO_PERMISSION));
    if(Servermem->cfg.ar.noright) {
      sendautorexx(Servermem->cfg.ar.noright);
    }
    return NULL;

  case -5:
    SendString("\r\n\n%s\r\n", CATSTR(MSG_KOM_INVALID_PASSWORD));
    return NULL;

  default:
    cmdId = parseRes;
    badCommandCnt = 0;
    break;
  }
  if(cmdId == CMD_GOMAIL) {
    return &internalGoMailCommand;
  }
  return getkmdpek(cmdId);
}
コード例 #2
0
ファイル: mozSpellChecker.cpp プロジェクト: amyvmiwei/firefox
NS_IMETHODIMP 
mozSpellChecker::NextMisspelledWord(nsAString &aWord, nsTArray<nsString> *aSuggestions)
{
  if(!aSuggestions||!mConverter)
    return NS_ERROR_NULL_POINTER;

  PRUint32 selOffset;
  PRInt32 begin,end;
  nsresult result;
  result = SetupDoc(&selOffset);
  PRBool isMisspelled,done;
  if (NS_FAILED(result))
    return result;

  while( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done )
    {
      nsString str;
      result = mTsDoc->GetCurrentTextBlock(&str);
  
      if (NS_FAILED(result))
        return result;
      do{
        result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end);
        if(NS_SUCCEEDED(result)&&(begin != -1)){
          const nsAString &currWord = Substring(str, begin, end - begin);
          result = CheckWord(currWord, &isMisspelled, aSuggestions);
          if(isMisspelled){
            aWord = currWord;
            mTsDoc->SetSelection(begin, end-begin);
            // After ScrollSelectionIntoView(), the pending notifications might
            // be flushed and PresShell/PresContext/Frames may be dead.
            // See bug 418470.
            mTsDoc->ScrollSelectionIntoView();
            return NS_OK;
          }
        }
        selOffset = end;
      }while(end != -1);
      mTsDoc->NextBlock();
      selOffset=0;
    }
  return NS_OK;
}
コード例 #3
0
ファイル: ConfigUtils.c プロジェクト: punktniklas/NiKom
char *findStringCfgValue(char *str) {
  char *tmp;
  int lastpos;

  tmp = strchr(str, '=');
  if(tmp == NULL) {
    printf("Invalid config line, no '=' sign found: %s\n", str);
    return NULL;
  }
  tmp++;
  if(IzSpace(tmp[0])) {
    tmp = FindNextWord(tmp);
  }
  if(IzSpace(tmp[0]) || tmp[0] == '\0') {
    printf("Invalid config line, no value after '=': %s\n", str);
    return NULL;
  }

  lastpos = strlen(tmp) - 1;
  while(IzSpace(tmp[lastpos])) {
    tmp[lastpos--] = '\0';
  }
  return tmp;
}
コード例 #4
0
ファイル: mozSpellChecker.cpp プロジェクト: amyvmiwei/firefox
NS_IMETHODIMP 
mozSpellChecker::Replace(const nsAString &aOldWord, const nsAString &aNewWord, PRBool aAllOccurrences)
{
  if(!mConverter)
    return NS_ERROR_NULL_POINTER;

  nsAutoString newWord(aNewWord); // sigh

  if(aAllOccurrences){
    PRUint32 selOffset;
    PRInt32 startBlock,currentBlock,currOffset;
    PRInt32 begin,end;
    PRBool done;
    nsresult result;
    nsAutoString str;

    // find out where we are
    result = SetupDoc(&selOffset);
    if(NS_FAILED(result))
      return result;
    result = GetCurrentBlockIndex(mTsDoc,&startBlock);
    if(NS_FAILED(result))
      return result;

    //start at the beginning
    result = mTsDoc->FirstBlock();
    currOffset=0;
    currentBlock = 0;
    while( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done )
      {
        result = mTsDoc->GetCurrentTextBlock(&str);
        do{
          result = mConverter->FindNextWord(str.get(),str.Length(),currOffset,&begin,&end);
          if(NS_SUCCEEDED(result)&&(begin != -1)){
            if (aOldWord.Equals(Substring(str, begin, end-begin))) {
              // if we are before the current selection point but in the same block
              // move the selection point forwards
              if((currentBlock == startBlock)&&(begin < (PRInt32) selOffset)){
                selOffset += (aNewWord.Length() - aOldWord.Length());
                if(selOffset < 0) selOffset=0;
              }
              mTsDoc->SetSelection(begin, end-begin);
              mTsDoc->InsertText(&newWord);
              mTsDoc->GetCurrentTextBlock(&str);
              end += (aNewWord.Length() - aOldWord.Length());  // recursion was cute in GEB, not here.
            }
          }
          currOffset = end;
        }while(currOffset != -1);
        mTsDoc->NextBlock();
        currentBlock++;
        currOffset=0;          
      }

    // We are done replacing.  Put the selection point back where we found  it (or equivalent);
    result = mTsDoc->FirstBlock();
    currentBlock = 0;
    while(( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ) &&(currentBlock < startBlock)){
      mTsDoc->NextBlock();
    }

//After we have moved to the block where the first occurrence of replace was done, put the 
//selection to the next word following it. In case there is no word following it i.e if it happens
//to be the last word in that block, then move to the next block and put the selection to the 
//first word in that block, otherwise when the Setupdoc() is called, it queries the LastSelectedBlock()
//and the selection offset of the last occurrence of the replaced word is taken instead of the first 
//occurrence and things get messed up as reported in the bug 244969

    if( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ){
      nsString str;                                
      result = mTsDoc->GetCurrentTextBlock(&str);  
      result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end);
            if(end == -1)
             {
                mTsDoc->NextBlock();
                selOffset=0;
                result = mTsDoc->GetCurrentTextBlock(&str); 
                result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end);
                mTsDoc->SetSelection(begin, 0);
             }
         else
                mTsDoc->SetSelection(begin, 0);
    }
 }
  else{
    mTsDoc->InsertText(&newWord);
  }
  return NS_OK;
}
コード例 #5
0
NS_IMETHODIMP mozEnglishWordUtils::FindNextWord(const char16_t *word, uint32_t length, uint32_t offset, int32_t *begin, int32_t *end)
{
  const char16_t *p = word + offset;
  const char16_t *endbuf = word + length;
  const char16_t *startWord=p;
  if(p<endbuf){
    // XXX These loops should be modified to handle non-BMP characters.
    // if previous character is a word character, need to advance out of the word
    if (offset > 0 && ucIsAlpha(*(p-1))) {
      while (p < endbuf && ucIsAlpha(*p))
        p++;
    }
    while((p < endbuf) && (!ucIsAlpha(*p)))
      {
        p++;
      }
    startWord=p;
    while((p < endbuf) && ((ucIsAlpha(*p))||(*p=='\'')))
      {
        p++;
      }

    // we could be trying to break down a url, we don't want to break a url into parts,
    // instead we want to find out if it really is a url and if so, skip it, advancing startWord
    // to a point after the url.

    // before we spend more time looking to see if the word is a url, look for a url identifer
    // and make sure that identifer isn't the last character in the word fragment.
    if ( (*p == ':' || *p == '@' || *p == '.') &&  p < endbuf - 1) {

        // ok, we have a possible url...do more research to find out if we really have one
        // and determine the length of the url so we can skip over it.

        if (mURLDetector)
        {
          int32_t startPos = -1;
          int32_t endPos = -1;

          mURLDetector->FindURLInPlaintext(startWord, endbuf - startWord, p - startWord, &startPos, &endPos);

          // ok, if we got a url, adjust the array bounds, skip the current url text and find the next word again
          if (startPos != -1 && endPos != -1) {
            startWord = p + endPos + 1; // skip over the url
            p = startWord; // reset p

            // now recursively call FindNextWord to search for the next word now that we have skipped the url
            return FindNextWord(word, length, startWord - word, begin, end);
          }
        }
    }

    while((p > startWord)&&(*(p-1) == '\'')){  // trim trailing apostrophes
      p--;
    }
  }
  else{
    startWord = endbuf;
  }
  if(startWord == endbuf){
    *begin = -1;
    *end = -1;
  }
  else{
    *begin = startWord-word;
    *end = p-word;
  }
  return NS_OK;
}
コード例 #6
0
ファイル: Config.c プロジェクト: punktniklas/NiKom
int handleFidoConfigLine(char *line, BPTR fh) {
  int i, address[4], group;
  char *tmp1, *tmp2, tmpbuf[50];

  if(isMatchingConfigLine(line,"DOMAIN")) {
    for(i = 0; i < 10; i++) {
      if(!Servermem->fidodata.fd[i].domain[0]) {
        break;
      }
    }
    if(i == 10) {
      printf("Too many FidoNet domains defined.\n");
      return 0;
    }
    tmp1 = FindNextWord(line);
    Servermem->fidodata.fd[i].nummer = atoi(tmp1);
    if(Servermem->fidodata.fd[i].nummer <= 0) {
      printf("The domain number must be a positive integer: %s\n", line);
      return 0;
    }
    tmp1 = FindNextWord(tmp1);
    tmp2 = FindNextWord(tmp1);
    tmp2[-1] = '\0';
    strncpy(Servermem->fidodata.fd[i].domain, tmp1, 19);
    if(!ParseFidoAddress(tmp2, address)) {
      printf("Invalid FidoNet address '%s'\n", tmp2);
      return 0;
    }
    Servermem->fidodata.fd[i].zone = address[0];
    Servermem->fidodata.fd[i].net = address[1];
    Servermem->fidodata.fd[i].node = address[2];
    Servermem->fidodata.fd[i].point = address[3];

    tmp1 = FindNextWord(tmp2);
    strncpy(Servermem->fidodata.fd[i].zones, tmp1, 49);
  }
  else if(isMatchingConfigLine(line, "ALIAS")) {
    for(i = 0; i < 20; i++) {
      if(!Servermem->fidodata.fa[i].namn[0]) {
        break;
      }
    }
    if(i == 20) {
      printf("Too many FidoNet aliases defined.\n");
      return 0;
    }
    tmp1 = FindNextWord(line);
    Servermem->fidodata.fa[i].nummer = atoi(tmp1);
    tmp1 = FindNextWord(tmp1);
    strncpy(Servermem->fidodata.fa[i].namn, tmp1, 35);
  }
  else if(isMatchingConfigLine(line, "BOUNCE")) {
    if(!GetStringCfgValue(line, tmpbuf, 10)) {
      return 0;
    }
    if(tmpbuf[0] == 'Y' || tmpbuf[0] == 'y') {
      Servermem->fidodata.bounce = TRUE;
    }
  } else if(isMatchingConfigLine(line, "MATRIXDIR")) {
    if(!GetStringCfgValue(line, Servermem->fidodata.matrixdir, 99)) {
      return 0;
    }
  } else if(isMatchingConfigLine(line, "MAILGROUP")) {
    if(!GetStringCfgValue(line, tmpbuf, 49)) {
      return 0;
    }
    group = parsegrupp(tmpbuf);
    if(group == -1) {
      printf("Unknown user group '%s'\n", tmpbuf);
      return 0;
    }
    BAMSET((char *)&Servermem->fidodata.mailgroups, group);
  }
  else if(isMatchingConfigLine(line, "MAILSTATUS")) {
    if(!GetCharCfgValue(line, &Servermem->fidodata.mailstatus)) {
      return 0;
    }
  } else if(isMatchingConfigLine(line, "DEFAULTORIGIN")) {
    if(!GetStringCfgValue(line, Servermem->fidodata.defaultorigin, 69)) {
      return 0;
    }
  } else if(isMatchingConfigLine(line, "CRASHSTATUS")) {
    if(!GetCharCfgValue(line, &Servermem->fidodata.crashstatus)) {
      return 0;
    }
  } else if(isMatchingConfigLine(line, "MESSAGE_BYTE_ORDER")) {
    if(!GetStringCfgValue(line, tmpbuf, 49)) {
      return 0;
    }
    if(strcmp(tmpbuf, "BIG_ENDIAN") == 0) {
      Servermem->fidodata.littleEndianByteOrder = 0;
    } else if(strcmp(tmpbuf, "LITTLE_ENDIAN") == 0) {
      Servermem->fidodata.littleEndianByteOrder = 1;
    } else {
      printf("Invalid byte order '%s'\n", tmpbuf);
    }
  } else {
    printf("Invalid config line: %s\n", line);
    return 0;
  }
  return 1;
}
コード例 #7
0
ファイル: NiKFuncs.c プロジェクト: punktniklas/NiKom
int parse(char *str) {
    int argType, timeSinceFirstLogin;
    char *arg2 = NULL, *word2;
    struct Kommando *cmd, *foundCmd = NULL;
    struct LangCommand *langCmd;

    timeSinceFirstLogin = time(NULL) - Servermem->inne[nodnr].forst_in;
    if(str[0] == 0) {
        return -3;
    }
    if(str[0] >= '0' && str[0] <= '9') {
        argument = str;
        return 212;
    }

    arg2 = FindNextWord(str);
    if(IzDigit(arg2[0])) {
        argType = KOMARGNUM;
    } else if(!arg2[0]) {
        argType = KOMARGINGET;
    } else {
        argType = KOMARGCHAR;
    }

    ITER_EL(cmd, Servermem->kom_list, kom_node, struct Kommando *) {
        if(cmd->secret) {
            if(cmd->status > Servermem->inne[nodnr].status) continue;
            if(cmd->minlogg > Servermem->inne[nodnr].loggin) continue;
            if(cmd->mindays * 86400 > timeSinceFirstLogin) continue;
            if(cmd->grupper && !(cmd->grupper & Servermem->inne[nodnr].grupper)) continue;
        }
        langCmd = chooseLangCommand(cmd);
        if(langCmd->name[0] && matchar(str, langCmd->name)) {
            word2 = FindNextWord(langCmd->name);
            if((langCmd->words == 2 && matchar(arg2, word2) && arg2[0]) || langCmd->words == 1) {
                if(langCmd->words == 1) {
                    if(cmd->argument == KOMARGNUM && argType == KOMARGCHAR) continue;
                    if(cmd->argument == KOMARGINGET && argType != KOMARGINGET) continue;
                }
                if(foundCmd == NULL) {
                    foundCmd = cmd;
                }
                else if(foundCmd == (struct Kommando *)1L) {
                    SendString("%s\n\r", chooseLangCommand(cmd)->name);
                } else {
                    SendString("\r\n\n%s\r\n\n", CATSTR(MSG_KOM_AMBIGOUS_COMMAND));
                    SendString("%s\n\r", chooseLangCommand(foundCmd)->name);
                    SendString("%s\n\r", chooseLangCommand(cmd)->name);
                    foundCmd = (struct Kommando *)1L;
                }
            }
        }
    }
    if(foundCmd != NULL && foundCmd != (struct Kommando *)1L) {
        argument = FindNextWord(str);
        if(chooseLangCommand(foundCmd)->words == 2) {
            argument = FindNextWord(argument);
        }
        memset(argbuf, 0, 1080);
        strncpy(argbuf, argument, 1080);
        argbuf[strlen(argument)] = 0;
        argument = argbuf;
    }
    if(foundCmd == NULL) {
        return -1;
    }
    else if(foundCmd == (struct Kommando *)1L) {
        return -2;
    } else {
        if(foundCmd->status > Servermem->inne[nodnr].status || foundCmd->minlogg > Servermem->inne[nodnr].loggin) {
            return -4;
        }
        if(foundCmd->mindays * 86400 > timeSinceFirstLogin) {
            return -4;
        }
        if(foundCmd->grupper && !(foundCmd->grupper & Servermem->inne[nodnr].grupper)) {
            return -4;
        }
    }
    if(foundCmd->losen[0]) {
        SendString("\r\n\n%s: ", CATSTR(MSG_KOM_COMMAND_PASSWORD));
        if(Servermem->inne[nodnr].flaggor & STAREKOFLAG) {
            getstring(STAREKO,20,NULL);
        } else {
            getstring(EJEKO,20,NULL);
        }
        if(strcmp(foundCmd->losen, inmat)) {
            return -5;
        }
    }
    return foundCmd->nummer;
}