/[cvs]/joko/Uni/BSArch/03/win32/utils_misc.c
ViewVC logotype

Diff of /joko/Uni/BSArch/03/win32/utils_misc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by joko, Fri Jun 16 00:06:11 2006 UTC revision 1.3 by joko, Fri Jun 16 19:39:07 2006 UTC
# Line 11  void chomp(char * string) { Line 11  void chomp(char * string) {
11    }    }
12  }  }
13    
14    void trim(char ** string) {
15      
16      // string length and loop variable
17      int string_length, i;
18      
19      // contains current character at string position i
20      char current_char[2];
21      
22      // pointers to begin end tail of new (stripped) string
23      char * begin;
24      char * tail;
25      
26      // prepare to be used with "strcmp" (comparison string should be terminated properly)
27      current_char[1] = '\0';
28      
29      
30      /*****************************
31       *  1. strip leading spaces
32       **/
33      begin = *string;
34      string_length = strlen(*string);
35      
36      // loop through all string characters (from left to right)
37      for (i = 0; i < string_length; i++) {
38        
39        // get character at position i
40        current_char[0] = *(*string + i);
41        
42        // is it a space? then increase pointer to begin of "new" string
43        if (strcmp(current_char, " ") == 0) {
44          begin++;
45        } else {
46          break;
47        }
48      }
49      *string = begin;
50      
51      
52      /*****************************
53       *  2. strip trailing spaces
54       **/
55      
56      // calculate new string length
57      string_length = strlen(*string);
58      
59      // loop through all string characters (from right to left)
60      for (i = 0; i < string_length - 1; i++) {
61        
62        // get character at position string_length - i
63        tail = *string + string_length - 1 - i;
64        current_char[0] = *tail;
65        
66        // is it a space? then set null-byte to indicate end of "new" string at current position
67        if (strcmp(current_char, " ") == 0) {
68          *tail = '\0';
69        } else {
70          break;
71        }
72      }
73      
74    }
75    
76    
77  // checks for errors and writes its message to stderr  // checks for errors and writes its message to stderr
78  BOOL check_alert_error(const char * error_source) {  BOOL check_alert_error(const char * error_source) {
79    DWORD dwError = GetLastError();    DWORD dwError = GetLastError();

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed