/* Process a line of text */ void Niall_Learn(char *Buffer) { char c; int i,j; /* Remove trailing spaces */ for(i=strlen(Buffer)-1;i>=0;i--) { if(!isspace(Buffer[i])) break; Buffer[i]=0; } /* Strip punctuation and break sentence if necessary */ for(i=0;i<strlen(Buffer);i++) { c=Buffer[i]; if(( c=='.' )||( c==',' )) { if( i+1 < strlen(Buffer)) { Buffer[i]=0; Niall_Learn(&Buffer[i+1]); } Buffer[i]=0; break; } else if(isspace(c)) { Buffer[i]=' '; } else if(!isalnum(c)) { for(j=i+1;j<=strlen(Buffer);j++) Buffer[j-1]=Buffer[j]; i--; } else Buffer[i]=tolower(c); } AddWords(Buffer); }
static void BuildLists( void ) //================================ { int index; group_list *curr_group; int group; msg_list *prev_msg; msg_list *msg_ptr; msg_list *last_non_null_msg; msg_list **p_null_msg; msg_word *word; int caret; char rec[BUFF_LEN+1]; char msg_used_at; char msg_compiler; char msg_target; char delim; fprintf( ErrCod, "#define NO_CARROT 0\n" ); fprintf( ErrCod, "#define OPR_CARROT 1\n" ); fprintf( ErrCod, "#define OPN_CARROT 2\n" ); fprintf( RCFile, "#include \"errcod.h\"\n\n" ); fprintf( RCFile, "STRINGTABLE\nBEGIN\n\n" ); group = 0; curr_group = NULL; ReadInFile( rec ); prev_msg = NULL; last_non_null_msg = NULL; for( ;; ) { if( HeadGroup == NULL ) { HeadGroup = malloc( sizeof( group_list ) ); curr_group = HeadGroup; } else { curr_group->link = malloc( sizeof( group_list ) ); curr_group = curr_group->link; } curr_group->link = NULL; curr_group->start_msg_num = group * 256; curr_group->end_msg_num = curr_group->start_msg_num; curr_group->name[0] = rec[0]; curr_group->name[1] = rec[1]; curr_group->name[2] = NULLCHAR; for( ;; ) { if( ReadInFile( rec ) != 0 ) { fprintf( RCFile, "\nEND\n" ); return; } ++RecNum; if( ( strlen( rec ) > 2 ) && ( rec[2] == ' ' ) ) // Group record break; index = 3; while( rec[index] != ' ' ) { ++index; } // End of message ID rec[index] = '\0'; ++index; ++index; // skip [ if( rec[index] != sw_language ) continue; ++index; msg_compiler = rec[index]; ++index; msg_target = rec[index]; ++index; msg_used_at = rec[index]; ++index; caret = rec[index] - '0'; ++index; ++index; // skip ] msg_ptr = InitMsg(); if( UseMessage( msg_compiler, msg_target, msg_used_at ) ) { // proccess message text AddWords( msg_ptr, &rec[index] ); } msg_ptr->caret = caret; if( msg_ptr->msg != NULL ) { fprintf( ErrCod, "#define %s %d\n", rec, curr_group->end_msg_num ); fprintf( RCFile, " %s+MSG_LANG_BASE \"", rec ); delim = ' '; for( word = msg_ptr->msg; word != NULL; word = word->link ) { if( word->link == NULL ) { delim = '"'; } fprintf( RCFile, "%s%c", word->word->word, delim ); } fprintf( RCFile, "\n" ); last_non_null_msg = msg_ptr; } curr_group->end_msg_num++; if( HeadMsg == NULL ) { HeadMsg = msg_ptr; } else { prev_msg->link = msg_ptr; } prev_msg = msg_ptr; } prev_msg = last_non_null_msg; if( last_non_null_msg == NULL ) { p_null_msg = &HeadMsg; } else { p_null_msg = &last_non_null_msg->link; } while( *p_null_msg != NULL ) { msg_ptr = (*p_null_msg)->link; free( *p_null_msg ); curr_group->end_msg_num--; *p_null_msg = msg_ptr; } ++group; } }
/** \brief Add a new words. * * Replace the existing words with the newly specified words. * * \exception bad_alloc() is generated if a string cannot be allocated. * * \param[in] words The new words to save in this moWords object. * * \return The number of words found in \p words. * * \sa Empty(), Quotes(), AutoClip(), CharSeparators(), StringSeparators() */ unsigned long moWords::SetWords(const moWCString& words) { Empty(); f_words.Empty(); return AddWords(words); }