~ubuntu-branches/ubuntu/karmic/htop/karmic

« back to all changes in this revision

Viewing changes to String.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2008-11-11 04:15:57 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20081111041557-jwylxzcj2p11rcfo
Tags: 0.8.1-0ubuntu1
New upstream release (LP: #273943)

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
   }
104
104
   return 0;
105
105
}
 
106
 
 
107
char* String_getToken(const char* line, const unsigned short int numMatch) {
 
108
   const unsigned short int len = strlen(line);
 
109
   char inWord = 0;
 
110
   unsigned short int count = 0;
 
111
   char match[50];
 
112
 
 
113
   unsigned short int foundCount = 0;
 
114
 
 
115
   for (unsigned short int i = 0; i < len; i++) {
 
116
      char lastState = inWord;
 
117
      inWord = line[i] == ' ' ? 0:1;
 
118
 
 
119
      if (lastState == 0 && inWord == 1)
 
120
         count++;
 
121
    
 
122
      if(inWord == 1){
 
123
         if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != EOF) {
 
124
            match[foundCount] = line[i];
 
125
            foundCount++;
 
126
         }
 
127
      }
 
128
   }
 
129
 
 
130
   match[foundCount] = '\0';
 
131
   return((char*)strdup(match));
 
132
}