Пример #1
0
size_t AccumulativeWordCounter::GetWordCount()
{
	size_t cnt = 0;
	size_t ctrl_cnt = 0;
	size_t sp_cnt = 0;
	CountWords(m_ustr, cnt, ctrl_cnt, sp_cnt);
	return m_cnt + cnt;
}
Пример #2
0
size_t AccumulativeWordCounter::GetWordCountNoCtrlNoSP()
{
	size_t cnt = 0;
	size_t ctrl_cnt = 0;
	size_t sp_cnt = 0;
	CountWords(m_ustr, cnt, ctrl_cnt, sp_cnt);
	return m_cnt + cnt - m_ctrl_cnt - ctrl_cnt - m_sp_cnt - sp_cnt;
}
Пример #3
0
size_t SimpleWordCounter::GetWordCountNoCtrlNoSP()
{
	size_t cnt = 0;
	size_t ctrl_cnt = 0;
	size_t sp_cnt = 0;
	CountWords(m_ustr, cnt, ctrl_cnt, sp_cnt);
	return cnt - ctrl_cnt - sp_cnt;
}
Пример #4
0
int populateLangCommand(struct LangCommand *langCmd, char *str) {
  if(!GetStringCfgValue(str, langCmd->name, 30)) {
    return 0;
  }
  if(langCmd->name[0] == '-') {
    langCmd->name[0] = '\0';
  } else {
    langCmd->words = CountWords(langCmd->name);
  }
  return 1;
}
Пример #5
0
void AccumulativeWordCounter::PiecewiseCount(UChar32 ch)
{
	// count last part
	CountWords(m_ustr, m_cnt, m_ctrl_cnt, m_sp_cnt);

	// joint: last char of last part + first char of new part
	int32_t last_idx = m_ustr.moveIndex32(m_ustr.length(), -1);
	UnicodeString joint = m_ustr.char32At(last_idx);
	joint += ch;

	// count the joint
	size_t cnt = 0;
	size_t ctrl_cnt = 0;
	size_t sp_cnt = 0;
	CountWords(joint, cnt, ctrl_cnt, sp_cnt);

	// if joint is one word, should take off the last word from last part
	if (cnt == 1)
	{
		m_cnt -= cnt;
		m_ctrl_cnt -= ctrl_cnt;
		m_sp_cnt -= sp_cnt;
	}
}
Пример #6
0
FX_BOOL Document::getPageNumWords(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
	ASSERT(m_pDocument != NULL);

	if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;

	int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;

	CPDF_Document* pDocument = m_pDocument->GetDocument();
	ASSERT(pDocument != NULL);

	CJS_Context* pContext = static_cast<CJS_Context*>(cc);
	if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
	{
		sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
		return FALSE;
	}

	CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
	if (!pPageDict) return FALSE;

	CPDF_Page page;
	page.Load(pDocument, pPageDict);
	page.StartParse();
	page.ParseContent();

	FX_POSITION pos = page.GetFirstObjectPosition();

	int nWords = 0;

	while (pos)
	{
		if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
		{
			if (pPageObj->m_Type == PDFPAGE_TEXT)
			{
				CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;
				nWords += CountWords(pTextObj);
			}
		}
	}

	vRet = nWords;

	return TRUE;
}
Пример #7
0
int main (int argc, const char * argv[]) {
	char	line[ kMaxLineLength ];
	int		numWords;
	
	printf( "Type a line of text, please:\n" );
	
	ReadLine( line );
	numWords = CountWords( line );
	
	printf( "\n---- This line has %d word", numWords );
	
	if ( numWords != 1 )
		printf( "s" );
	
	printf( " ----\n%s\n", line );
	
	return 0;
}
Пример #8
0
/* Save the dictionary
*/
void Niall_SaveDictionary(char *FileName)
{
	FILE *fHandle;
	int nWords;
	WORD *Word;
	ASCN *Assoc;
	int i;

	nWords=CountWords();
	if(nWords<2)
	{
		Niall_Warning("No words to save.");
		return;
	}

	fHandle=fopen(FileName,"w");
	if(!fHandle)
	{
		Niall_Warning("Can't open file %s.",FileName);
		return;
	}
	fprintf(fHandle,"%s %d\n",FILE_ID,nWords);

	for(i=0,Word=WordList;Word;Word=Word->Next,i++)
	{
		if(strlen(Word->Data)==0)
			fprintf(fHandle,"%4d: > %d|",i,CountProbs(Word));
		else
			fprintf(fHandle,"%4d: %s %d|",i,Word->Data,CountProbs(Word));
		for(Assoc=Word->Associations;Assoc;Assoc=Assoc->Next)
		{
			fprintf(fHandle," %d(%d)",Assoc->Word,Assoc->Probability);
		}
		fprintf(fHandle,"\n");
		if(ferror(fHandle))
		{
			Niall_Warning("File %s not saved correctly.",FileName);
			fclose(fHandle);
			return;
		}
	}
	fclose(fHandle);
}
Пример #9
0
int main (int argc, const char * argv[])
{
    char line[ kMaxLineLength+1 ];  // room for kMaxLineLength chars + one NUL
    int	 numWords;
    
    // Chapter 9 exercise:
    //  Removed the code that prompts for a line.
    
    // Chapter 9 exercise:
    //  Run ReadLine() and CountWords() in a while loop that continues, indefinately,
    //  until ReadLine() returns false (meaning there are no more characters to read).
    //  Note: Becuase of this, the program will now run in the Xcode console until you
    //        stop it with the Stop button, or type Control+D in the console pane.
    //        ^D is the ASCII end-of-file control character and will cause standard in
    //        to return an EOF.
    while ( ReadLine( line ) != false ) {
        numWords = CountWords( line );
        printf( "\n---- This line has %d word%s. ---\n", numWords, ( numWords!=1 ? "s" : "" ) );
        printf( "%s\n", line );
    }
    
    return 0;
}
Пример #10
0
int main (void) 
{
	int Alpha=0;		/* letter of alphabeth variable 	*/
	int SentChk=0;		/* end of sentence identifier 		*/
	int punct=0;		/* punctuation counter 			*/
	int Words=0;		/* words ended by whitespace counter 	*/
	int totalSents=0;	/* total amount of sentences 		*/
	int onlyVowel_e=0;	/* only the vowel 'e' counter 		*/
	int isVowel=0;		/* vowel identifier 			*/
	int vowelChk=0;		/* number of vowels in a word 		*/
	int syllables=0;	/* number of syllables 			*/
	int Vowel_e=0;		/* number of vowels 'e' 		*/
	int endVowel_e=0;	/* word that ends in the vowel 'e' 	*/
	int totalSylls=0;	/* total number of syllables 		*/
	int totalWords=0;	/* total number of words 		*/
	int index;		/* legibility index 			*/
	char ch;		/* a character read from stdin 		*/
	
	while ((ch = getchar()) != EOF)	/* loop that reads each character from stdin until the end of file is reached */
	{			
		CountWords(ch, &Alpha, &SentChk, &punct, &Words, &totalSents, &onlyVowel_e);			/* Calls function to count words 	*/
		isVowel=vowel(ch);										/* Calls function to check vowels 	*/
		CountSyllables(ch, &isVowel, &vowelChk, &syllables, &Vowel_e, &onlyVowel_e, &endVowel_e);	/* Calls function to count syllables	*/
	}
	
	totalWords=Words+totalSents;													/* Calculates total words */
	totalSylls=syllables-endVowel_e;												/* Calculates total syllables */
	index= floor(206.835 - 84.6 * ((float)totalSylls/(float)totalWords) - 1.015 * ((float)totalWords/(float)totalSents)+0.5);	/* Calculates legibility index */
	
	/* Output of calculated data */
	printf("\nLegibility Index = %d", index);
	printf("\nSyllable count   = %d", totalSylls);
	printf("\nWord count       = %d", totalWords);
	printf("\nSentence count   = %d\n", totalSents);
	
    return 0;	
}
Пример #11
0
int TStrUtil::CountWords(const TChA& ChA) {
  return CountWords(ChA.CStr());
}
Пример #12
0
long
SearchWordList( WORD word , WORD *word_info[], BOOL keep_text )
{
   extern FILE *TLGwlist;
   extern char diacrit[];
   int match_len=0,ncb=0,block_cnt=0;
   long words_fnd=0;
   BYTE *block,*block_index,*word_beg,*last_pos;
   BOOL srch_abort = FALSE;

   block     = (BYTE *) TLGmalloc( TLGBLOCKSIZE );
   block_cnt = word.word_loc.end_wlblock - word.word_loc.start_wlblock;

   do  /* Loop over all necessary blocks */
   {
      if(srch_abort = CheckForEscape())
        goto short_exit;

      CHECKREAD( block, TLGBLOCKSIZE, 1, TLGwlist);
      block_index = block;
      last_pos = block;

      while( (word_beg = MatchPattern( (BYTE *) word.word_text->m_text,last_pos,
                                 TLGBLOCKSIZE - ( last_pos - block ) ))  &&
              ((last_pos-block) < TLGBLOCKSIZE) )
      {
        if(srch_abort=CheckForEscape())
                goto short_exit;

        /*   Bail out if we need the full word and this ain't it
         */
         if( LetterVal(word.word_text->m_text[0]) && !HIBITSET(word_beg[-1]) )
         {
                last_pos = (BYTE *) end_of_patt;
                continue;
         }
         if( !HIBITSET(*end_of_patt) )
         {
                last_pos = (BYTE *) end_of_patt;
                continue;
         }

         if( words_fnd >= WORDARRAYSIZE )
                goto short_exit;

         /*
          *  Get whole word and character count
          */
         CURRWORD = (WORD *) TLGmalloc(sizeof(WORD));
         while(!HIBITSET(word_beg[-1])) word_beg--;
         block_index = word_beg;
         match_len=0;

         if(keep_text)
         {
           CURRWORD->word_text = (WORDTEXT *) TLGmalloc( sizeof(WORDTEXT) );

           while( !HIBITSET(*block_index) )
                 CURRWORD->word_text->text[match_len++] = *block_index++;

           CURRWORD->word_text->text[match_len] = '\0';
           MassageWord( CURRWORD->word_text->text,CURRWORD->word_text->m_text);
        }

        block_index = word_beg-1;

        /*
         *  Find the number of word occurences from count bytes.
         */
         ncb = 0;
         while( HIBITSET(*block_index) )
         {
                ncb++;
                block_index--;
         }
         CURRWORD->total = BitVal7xN((BYTE *)block_index+1,ncb);

         CURRWORD->word_loc.start_wlblock = word.word_loc.start_wlblock;
         CURRWORD->word_loc.WordNum = CountWords((BYTE *)block,
                                                 (BYTE *)word_beg);

         words_fnd++;
         word_beg+=match_len;

         last_pos = word_beg;
         while(!HIBITSET(*last_pos) && ((*last_pos) != 0) )
                last_pos++;;

      }/*END WHILE Strsrch finds match*/
      word.word_loc.start_wlblock++;

   } while( block_cnt-- );

short_exit:
   match_count = words_fnd;

   if(srch_abort)
   {
      FreeWordList();
      words_fnd = -1;
   }

   TLGfree(block);
   return(words_fnd);
}/*
Пример #13
0
FX_BOOL Document::getPageNthWord(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
{
	ASSERT(m_pDocument != NULL);

	if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;

	int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
	int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0;
	bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true;

	CPDF_Document* pDocument = m_pDocument->GetDocument();
	if (!pDocument) return FALSE;

	CJS_Context* pContext = static_cast<CJS_Context*>(cc);
	if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
	{
		sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
		return FALSE;
	}

	CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
	if (!pPageDict) return FALSE;

	CPDF_Page page;
	page.Load(pDocument, pPageDict);
	page.StartParse();
	page.ParseContent();

	FX_POSITION pos = page.GetFirstObjectPosition();

	int nWords = 0;

	CFX_WideString swRet;

	while (pos)
	{
		if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
		{
			if (pPageObj->m_Type == PDFPAGE_TEXT)
			{
				int nObjWords = CountWords((CPDF_TextObject*)pPageObj);

				if (nWords + nObjWords >= nWordNo)
				{
					swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);
					break;
				}

				nWords += nObjWords;
			}
		}
	}

	if (bStrip)
	{
		swRet.TrimLeft();
		swRet.TrimRight();
	}

	vRet = swRet.c_str();
	return TRUE;
}
Пример #14
0
 printf("ReadSet introuvable:%s:\n",ptr);
 free(ptr);

 ptr=CopieAt("LIGNE DE TEXTE","DE","\0");
 printf("CopieAt:%s:\n",ptr);
 free(ptr);
 
 ptr=CopieAt("LIGNE DE TEXTE","de","\0");
 printf("CopieAt MAJ/MIN:%s:\n",ptr);
 free(ptr);
 
 ptr=CopieAt("LIGNE DE TEXTE","deu","\0");
 printf("CopieAt delimiteur inexistant:%s:\n",ptr);
 free(ptr);

 ptr=CountWords("LIGNE   DE TEXTE FIN dede dede  de","\0");
 printf(":%s:\n",ptr);
 free(ptr);

 ptr=CountWords("  LIGNE   DE TEXTE FIN dede dede  de ","\0");
 printf(":%s:\n",ptr);
 free(ptr);
 
 ptr=CountWords(" ","\0");
 printf("CountWords:%s:\n",ptr);
 free(ptr);

 ptr=CountWords("H","\0");
 printf("CountWords:%s:\n",ptr);
 free(ptr);
Пример #15
0
/* ver.3.20:Use combo (item list) */
int ShowMediaSizeIllegalSelectDialog(UIMediaSizeDialog* dialog, gchar* applied)
{
	GtkWidget* current_label;
	GtkWidget* message_label;
	char *data;
	short change_id;
	char* change_msg;
	int i;
	gchar* alert_msg2_1;
	gchar* alert_msg2_2;
	gchar* message;
	gchar* tmp_message;
	gint message_len, tmp_message_len;

	if( dialog->change == UI_MEDIASIZE_CHANGE_SIZE ){
		/* show  media -> size */
		/* show media */
		current_label = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_select_label001");
		gtk_label_set_text( GTK_LABEL(current_label), LookupText(g_keytext_list, "LUM_IDD_PAG_MAIN_IDC_STT_MEDIATYPE") );

		current_label = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_select_label002");
		data = ValueToName(CNCL_MEDIATYPE, KeyToValue(CNCL_MEDIATYPE, dialog->media));
		gtk_label_set_text( GTK_LABEL(current_label), data );

		/* show size */
		current_label = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_select_label003");
		gtk_label_set_text( GTK_LABEL(current_label), LookupText(g_keytext_list, "LUM_IDD_PAG_PAGESET_XP_IDC_STT_PAGESIZE") );

		current_label = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_select_label004");
		data = ValueToName(CNCL_PAPERSIZE, KeyToValue(CNCL_PAPERSIZE, dialog->size));
		gtk_label_set_text( GTK_LABEL(current_label), data );
	}
	else {
		/* show  size -> media */
		/* show size */
		current_label = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_select_label001");
		gtk_label_set_text( GTK_LABEL(current_label), LookupText(g_keytext_list, "LUM_IDD_PAG_PAGESET_XP_IDC_STT_PAGESIZE") );

		current_label = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_select_label002");
		data = ValueToName(CNCL_PAPERSIZE, KeyToValue(CNCL_PAPERSIZE, dialog->size));
		gtk_label_set_text( GTK_LABEL(current_label), data );

		/* show media */
		current_label = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_select_label003");
		gtk_label_set_text( GTK_LABEL(current_label), LookupText(g_keytext_list, "LUM_IDD_PAG_MAIN_IDC_STT_MEDIATYPE") );

		current_label = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_select_label004");
		data = ValueToName(CNCL_MEDIATYPE, KeyToValue(CNCL_MEDIATYPE, dialog->media));
		gtk_label_set_text( GTK_LABEL(current_label), data );
	}
	dialog->item_count = CountWords(applied);

	message_label = LookupWidget(UI_DIALOG(dialog)->window,
									"mediasize_illegal_select_message_label");
	if( dialog->change == UI_MEDIASIZE_CHANGE_SIZE )
	{
		change_id = CNCL_PAPERSIZE;
		change_msg = LookupText(g_keytext_list, "mediasize_change_size");
	}
	else
	{
		change_id = CNCL_MEDIATYPE;
		change_msg = LookupText(g_keytext_list, "mediasize_change_media");
	}

	// In case of changing more than 1 recommended items.
	alert_msg2_1
		= LookupText(g_keytext_list, "mediasize_illegal_select_message2_1");
	alert_msg2_2
		= LookupText(g_keytext_list, "mediasize_illegal_select_message2_2");
	message_len = strlen(change_msg) + strlen(alert_msg2_1) + strlen(alert_msg2_2) + 2;	/* Ver.2.80 "2":\n+\0 */
	message = (gchar*)g_malloc( message_len );
	tmp_message_len = strlen(change_msg) + strlen(alert_msg2_1) + 1;	/* Ver.2.80 "1":\0 */
	tmp_message = (gchar*)g_malloc( tmp_message_len );

	snprintf(tmp_message, tmp_message_len, alert_msg2_1, change_msg ); /* Ver.3.60 */
	snprintf(message, message_len, "%s\n%s", tmp_message, alert_msg2_2);
	gtk_label_set_text(GTK_LABEL(message_label), message);

	g_free(tmp_message);
	g_free(message);

	{
		gchar* words = applied;
		gchar* word = (gchar*)g_malloc(strlen(words));
		gchar* next;
		gchar* change_to;
		int len;

		/* Ver.3.20: make combo */
		GtkWidget* combo = LookupWidget(UI_DIALOG(dialog)->window, "mediasize_illegal_combo" );
	
		/* Remove all items in current list */
		if(gtk_combo_box_get_active_text( GTK_COMBO_BOX( combo )) ){
			while( 1 ){
				gtk_combo_box_set_active( GTK_COMBO_BOX( combo ), 0 );
				if( ! gtk_combo_box_get_active_text( GTK_COMBO_BOX( combo )) ) break;
				gtk_combo_box_remove_text( GTK_COMBO_BOX( combo ), 0 );
			}
		}
		/* Add available list (not disable items from UIDB ) */
		for( i = 0 ; i < dialog->item_count ; i++ )
		{
			next = GetWord(words, &len);
			strncpy(word, words, len);
			word[len] = '\0';
			change_to = LookupText(g_keytext_list, word);
			
			if( change_to != NULL )
			{
				if( *change_to != '\0' ){
					/* append one item */
					gtk_combo_box_append_text( GTK_COMBO_BOX( combo ), change_to );
				}
			}
			
			if( i == 0) dialog->current_change_to_id = KeyToValue(change_id, word);		/* default current...set top item */
			
			words = next;
			
		}
		/* Set active item to top */
		gtk_combo_box_set_active( GTK_COMBO_BOX( combo ), 0 );
		gtk_widget_show( combo );

		g_free(word);
	}

	gtk_window_set_title(
		GTK_WINDOW(UI_DIALOG(dialog)->window), g_window_title);	
	gtk_window_set_position(
		GTK_WINDOW(UI_DIALOG(dialog)->window), GTK_WIN_POS_CENTER);	

	ShowDialog((UIDialog*)dialog, "mediasize_illegal_select_apply_button");
	return dialog->exec;
}
Пример #16
0
void TextEditor::UpdateDocumentStatus() {
    QString LengthString    = Shared::Length + ": " + CalculateSize();
    QString LineCountString = Shared::Lines  + ": " + QString::number(document()->blockCount());
    QString WordCountString = Shared::Words  + ": " + QString::number(CountWords());
}
/*
 * Name        : lab_3_unit_test.cpp
 * Author      : Luke Sathrum
 * Description : Unit test to test Lab #3 Functionality
 * Sources     :
 */
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include "assignment_1.h"

TEST_CASE("CountWords(\"\")") {
  SECTION("CountWords(\"\")") {
    CHECK(CountWords("") == 0);
  }

  SECTION("CountWords(\"hello\")") {
    CHECK(CountWords("hello") == 1);
  }
  
 SECTION("CountWords(\"hello,world\")") {
    CHECK(CountWords("hello,world") == 1);
  }
  
  SECTION("CountWords(\"hello world\")") {
    CHECK(CountWords("hello world") == 2);
  }
  
  SECTION("CountWords(\"hello, world\")") {
    CHECK(CountWords("hello, world") == 2);
  }
Пример #18
0
void CSentence::CreateEventWordDistribution( char const *pszText, float flSentenceDuration )
{
	Assert( pszText );
	if ( !pszText )
		return;

	int wordCount = CountWords( pszText );
	if ( wordCount <= 0 )
		return;

	float wordLength = ( flSentenceDuration - 2 * STARTEND_TIMEGAP) / (float)wordCount;
	float wordStart = STARTEND_TIMEGAP;

	Reset();

	char word[ 256 ];
	unsigned char const *in = (unsigned char *)pszText;
	char *out = word;
	
	while ( *in )
	{
		if ( !ShouldSplitWord( *in ) )
		{
			*out++ = *in++;
		}
		else
		{
			*out = 0;

			// Skip over splitters
			while ( *in && ( ShouldSplitWord( *in ) ) )
			{
				in++;
			}
			
			if ( strlen( word ) > 0 )
			{
				CWordTag *w = new CWordTag();
				Assert( w );
				w->SetWord( word );
				w->m_flStartTime = wordStart;
				w->m_flEndTime = wordStart + wordLength;
				
				AddWordTag( w );
				
				wordStart += wordLength;
			}
			
			out = word;
		}
	}
	
	*out = 0;

	if ( strlen( word ) > 0 )
	{
		CWordTag *w = new CWordTag();
		Assert( w );
		w->SetWord( word );
		w->m_flStartTime = wordStart;
		w->m_flEndTime = wordStart + wordLength;
		
		AddWordTag( w );
		
		wordStart += wordLength;
	}
}
Пример #19
0
/** 
* Gets the number of words required to represent this RInteger.
* 
* @return	The size of the integer in words.
*
*/
EXPORT_C TUint TInteger::WordCount() const
	{
	return CountWords(Ptr(), Size());
	}
Пример #20
0
gboolean CheckMediaSizeCombination(LPBJFLTDEVICE bjdev, gboolean* change_item)
{
	MediaSizeTable* table = GetMediaSizeTable(bjdev->bjfltModelID);
	char* media = ValueToKey(CNCL_MEDIATYPE, bjdev->bjfltMediaType);
	char* size = ValueToKey(CNCL_PAPERSIZE, bjdev->bjfltPaperSize);
	int change;
	gboolean exec_print;
	int result = TRUE;
	gchar* applied = NULL;
	gchar* applied_title = NULL;
	GtkWidget *window = UI_DIALOG(g_main_window)->window;

	*change_item = FALSE;

	if( table == NULL )
		return TRUE;


	while( table->base != NULL )
	{
		if( !strcmp(media, table->base) )
		{
			// Get available media size.
			applied = GetAvailableSize(table->applied);

			if( SearchWord(size, applied) == NULL )
			{
				applied_title = GetAvailableSize(table->applied_title);
				change = UI_MEDIASIZE_CHANGE_SIZE;
				break;
			}
		}
		else if( !strcmp(size, table->base) )
		{
			// Get available media type.
			applied = GetAvailableMedia(table->applied);

			if( SearchWord(media, applied) == NULL )
			{
				applied_title = GetAvailableMedia(table->applied_title);
				change = UI_MEDIASIZE_CHANGE_MEDIA;
				break;
			}
		}
		table++;
	}


	if( table->base )
	{
		UIMediaSizeDialog* dialog = NULL;
		int (*show_dialog)(UIMediaSizeDialog*, gchar*) = NULL;

		switch( table->type )
		{
			case UI_MEDIASIZE_ILLEGAL:
				if( 1 >= CountWords(applied) )
				{
					dialog = g_mediasize_illegal_dialog;
					show_dialog = ShowMediaSizeIllegalDialog;
				}
				else
				{
					dialog = g_mediasize_illegal_select_dialog;
					show_dialog = ShowMediaSizeIllegalSelectDialog;
				}
				break;

			case UI_MEDIASIZE_RECOMMEND:
				dialog = g_mediasize_recommend_dialog;
				show_dialog = ShowMediaSizeRecommendDialog;
				break;
		}

		// Show the dialog when the number of applied item is more than 1.
		if( dialog && strlen(applied) > 0 )
		{
			dialog->media = media;
			dialog->size = size;
			dialog->table = (void*)table;
			dialog->change = change;

			// Show dialog.
			exec_print = show_dialog(dialog, applied_title);

			if( dialog->apply )
			{
				GtkWidget*	analyzer_combo = NULL;
				char 		*change_to_value_str = NULL;
				short		change_to_id;

				if( dialog->item_count > 1 )		/* multiple items -> get value id of chenge item */
				{
					/* Ver.3.20 */
					if( table->type == UI_MEDIASIZE_RECOMMEND )			/* recommend */
						analyzer_combo = LookupWidget(UI_DIALOG(dialog)->window,  "mediasize_recommend_combo");
					else												/* illegal   */
						analyzer_combo = LookupWidget(UI_DIALOG(dialog)->window,  "mediasize_illegal_combo");

					change_to_value_str = (char*)gtk_combo_box_get_active_text(GTK_COMBO_BOX(analyzer_combo));
					
					if( dialog->change == UI_MEDIASIZE_CHANGE_SIZE )	/* change size */
						change_to_id = NameToValue( CNCL_PAPERSIZE , change_to_value_str );
					else												/* change media */
						change_to_id = NameToValue( CNCL_MEDIATYPE , change_to_value_str );
					
					dialog->current_change_to_id = change_to_id;
					
					if(change_to_value_str){
						free(change_to_value_str);
						change_to_value_str = NULL;
					}
				}

				if( dialog->change == UI_MEDIASIZE_CHANGE_SIZE )
				{
					UpdateMenuLink(CNCL_PAPERSIZE, dialog->current_change_to_id);
					DisableSignal();
					UpdateWidgets(window, NULL);
					EnableSignal();
				}
				else
				{
					// Save current supply value.
					short supply_value = GetCurrentnValue(CNCL_MEDIASUPPLY);

					// Change the media type.
					UpdateMenuLink(CNCL_MEDIATYPE, dialog->current_change_to_id);
					DisableSignal();
					UpdateWidgets(window, NULL);
					EnableSignal();

					if( supply_value != GetCurrentnValue(CNCL_MEDIASUPPLY) )
					{
						// If no supply value for the current media type,
						// Some alert should be shown.

						// Only restore the saved supply value in this version.
						//UpdateMenuLink(CNCL_MEDIASUPPLY, supply_value);
					}
				}

				*change_item = TRUE;
			}
			result = exec_print;
		}
	}

	if( applied )
		g_free(applied);

	if( applied_title )
		g_free(applied_title);	/* Ver.3.00 */

	return result;
}
Пример #21
0
unsigned int PolynomialMod2::WordCount() const
{
	return (unsigned int)CountWords(reg, reg.size());
}
Пример #22
0
Файл: 1.c Проект: AJBull/CStudy
         main()
         {
            printf("Enter a string\n");
            CountWords();

         }