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

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

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