Exemplo n.º 1
0
int main()
{
    char str[16];

    strip_leading_spaces(str, "", 0); /* ten spaces in 'src' */
    assert(strlen(str) == 0);

    strip_leading_spaces(str, "     ", 5); /* ten spaces in 'src' */
    assert(strlen(str) == 0);

    strip_leading_spaces(str, " H", 2);
    assert(!strcmp(str, "H"));

    strip_leading_spaces(str, "    Hello, ", 11);
    assert(!strcmp(str, "Hello, "));

    strip_leading_spaces(str, "Hello,  ", 8);
    assert(!strcmp(str, "Hello,  "));

    strip_leading_spaces(str, "Hello, Text", 11);
    assert(!strcmp(str, "Hello, Text"));

    return 0;   
}
Exemplo n.º 2
0
//********************************************************************
void find_anagrams(HWND hwnd)
{
   char msgstr[81] ;
   //  read data out of hwnd:IDC_PHRASE
   char input_bfr[MAX_PKT_CHARS+1] ;
   uint input_bfr_len = GetWindowTextA (GetDlgItem(hwnd,IDC_PHRASE) , input_bfr, MAX_PKT_CHARS);
   if (input_bfr_len > MAX_PKT_CHARS) 
       input_bfr_len = MAX_PKT_CHARS ;
   input_bfr[MAX_PKT_CHARS] = 0 ;
   if (vflag)  //lint !e506 !e774
      syslog("find_anagrams: [%u] [%s]\n", input_bfr_len, input_bfr) ;

   //  scan for separator char
   excl_idx = 0 ; //  reset exclusions list
   char *hd ;
   char *tl = strchr(input_bfr, '!');
   if (tl != NULL) {
      *tl++ = 0 ; //  NULL-term word list, point to exclusions list
      while (LOOP_FOREVER) {
         tl = strip_leading_spaces(tl);
         if (*tl != 0) {
            hd = tl ;
            tl = strchr(hd, ' ');
            if (tl != NULL) {
               *tl++ = 0 ;
               //  hd points to one exclusion arg
            }
            add_to_excl_list(hd);
            if (tl == NULL) {
               break;
            }
         }
      }
   }

   status_message("Begin new anagram search") ;

   // clear_message_area(&this_term);
   clear_message_area();
   if (excl_idx == 0) {
      status_message("excl: <none>", 1);
   }
   else
   {
      uint slen = sprintf(msgstr, "excl: ");
      for (uint idx=0; idx<excl_idx; idx++) {
         slen += (uint) sprintf(msgstr+slen, "%s ", excl_list[idx]);
      }
      status_message(msgstr, 1);
   }
   delete_wordlist() ;

   ZeroMemory((char *) &freq[0], sizeof(freq)) ;
   nletters = 0 ;
   for (char *p = input_bfr; *p != 0; p++) {
      if (*p != ' ') {
         freq[(uint) (u8) *p]++ ;
         nletters++;
      }
   }
   if (maxgen == 0)
       maxgen = nletters;
   
   wordlist = buildwordlist ();
   if (wordlist == NULL) {
      syslog("Empty dictionary or no suitable words.\n");
      return ;
   }

   wordlist = sort (wordlist);
   initfind (wordlist);

   solutions_found = 0 ;
   findanags (0, forgelinks (wordlist), nletters);
   if (solutions_found == 0) {
      status_message("no anagrams found for input string !") ;
   } else {
      // reverse_list_entries() ;
      // InsertListViewItems(solutions_found);  //  This triggers drawing of listview
      myTerminal->reverse_list_entries() ;
      update_listview();

      wsprintf(msgstr, "%u anagrams found", solutions_found) ;
      status_message(msgstr) ;
   }
}