Blame


1 0f3e84f4 2003-01-13 alex /*
2 0f3e84f4 2003-01-13 alex * ngIRCd -- The Next Generation IRC Daemon
3 39f1ddd9 2005-01-25 alex * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
4 0f3e84f4 2003-01-13 alex *
5 0f3e84f4 2003-01-13 alex * This program is free software; you can redistribute it and/or modify
6 0f3e84f4 2003-01-13 alex * it under the terms of the GNU General Public License as published by
7 0f3e84f4 2003-01-13 alex * the Free Software Foundation; either version 2 of the License, or
8 0f3e84f4 2003-01-13 alex * (at your option) any later version.
9 0f3e84f4 2003-01-13 alex * Please read the file COPYING, README and AUTHORS for more information.
10 0f3e84f4 2003-01-13 alex *
11 0f3e84f4 2003-01-13 alex * Tool functions
12 0f3e84f4 2003-01-13 alex */
13 0f3e84f4 2003-01-13 alex
14 0f3e84f4 2003-01-13 alex
15 0f3e84f4 2003-01-13 alex #include "portab.h"
16 0f3e84f4 2003-01-13 alex
17 8adff592 2005-03-19 fw static char UNUSED id[] = "$Id: tool.c,v 1.3 2005/03/19 18:43:52 fw Exp $";
18 0f3e84f4 2003-01-13 alex
19 0f3e84f4 2003-01-13 alex #include "imp.h"
20 0f3e84f4 2003-01-13 alex #include <assert.h>
21 0f3e84f4 2003-01-13 alex #include <ctype.h>
22 0f3e84f4 2003-01-13 alex #include <stdio.h>
23 0f3e84f4 2003-01-13 alex #include <string.h>
24 0f3e84f4 2003-01-13 alex
25 0f3e84f4 2003-01-13 alex #include "exp.h"
26 0f3e84f4 2003-01-13 alex #include "tool.h"
27 0f3e84f4 2003-01-13 alex
28 0f3e84f4 2003-01-13 alex
29 8adff592 2005-03-19 fw GLOBAL void
30 8adff592 2005-03-19 fw ngt_TrimStr( char *String )
31 0f3e84f4 2003-01-13 alex {
32 0f3e84f4 2003-01-13 alex /* Mit ngt_TrimStr() werden fuehrende und folgende Leerzeichen,
33 0f3e84f4 2003-01-13 alex * Tabulatoren und Zeilenumbrueche (ASCII 10 und ASCII 13) aus
34 0f3e84f4 2003-01-13 alex * dem String entfernt. */
35 0f3e84f4 2003-01-13 alex
36 8adff592 2005-03-19 fw char *start, *ptr;
37 0f3e84f4 2003-01-13 alex
38 0f3e84f4 2003-01-13 alex assert( String != NULL );
39 0f3e84f4 2003-01-13 alex
40 0f3e84f4 2003-01-13 alex start = String;
41 0f3e84f4 2003-01-13 alex
42 0f3e84f4 2003-01-13 alex /* Zeichen am Anfang pruefen ... */
43 0f3e84f4 2003-01-13 alex while(( *start == ' ' ) || ( *start == 9 )) start++;
44 0f3e84f4 2003-01-13 alex
45 0f3e84f4 2003-01-13 alex /* Zeichen am Ende pruefen ... */
46 0f3e84f4 2003-01-13 alex ptr = strchr( start, '\0' ) - 1;
47 0f3e84f4 2003-01-13 alex while((( *ptr == ' ' ) || ( *ptr == 9 ) || ( *ptr == 10 ) || ( *ptr == 13 )) && ptr >= start ) ptr--;
48 0f3e84f4 2003-01-13 alex *(++ptr) = '\0';
49 0f3e84f4 2003-01-13 alex
50 0f3e84f4 2003-01-13 alex memmove( String, start, strlen( start ) + 1 );
51 0f3e84f4 2003-01-13 alex } /* ngt_TrimStr */
52 0f3e84f4 2003-01-13 alex
53 0f3e84f4 2003-01-13 alex
54 8adff592 2005-03-19 fw GLOBAL char *
55 8adff592 2005-03-19 fw ngt_LowerStr( char *String )
56 0f3e84f4 2003-01-13 alex {
57 0f3e84f4 2003-01-13 alex /* String in Kleinbuchstaben konvertieren. Der uebergebene
58 0f3e84f4 2003-01-13 alex * Speicherbereich wird durch das Ergebnis ersetzt, zusaetzlich
59 0f3e84f4 2003-01-13 alex * wird dieser auch als Pointer geliefert. */
60 0f3e84f4 2003-01-13 alex
61 8adff592 2005-03-19 fw char *ptr;
62 0f3e84f4 2003-01-13 alex
63 0f3e84f4 2003-01-13 alex assert( String != NULL );
64 0f3e84f4 2003-01-13 alex
65 0f3e84f4 2003-01-13 alex /* Zeichen konvertieren */
66 0f3e84f4 2003-01-13 alex ptr = String;
67 0f3e84f4 2003-01-13 alex while( *ptr )
68 0f3e84f4 2003-01-13 alex {
69 0f3e84f4 2003-01-13 alex *ptr = tolower( *ptr );
70 0f3e84f4 2003-01-13 alex ptr++;
71 0f3e84f4 2003-01-13 alex }
72 0f3e84f4 2003-01-13 alex
73 0f3e84f4 2003-01-13 alex return String;
74 0f3e84f4 2003-01-13 alex } /* ngt_LowerStr */
75 0f3e84f4 2003-01-13 alex
76 0f3e84f4 2003-01-13 alex
77 8adff592 2005-03-19 fw GLOBAL void
78 8adff592 2005-03-19 fw ngt_TrimLastChr( char *String, const char Chr)
79 39f1ddd9 2005-01-25 alex {
80 39f1ddd9 2005-01-25 alex /* If last character in the string matches Chr, remove it.
81 39f1ddd9 2005-01-25 alex * Empty strings are handled correctly. */
82 39f1ddd9 2005-01-25 alex
83 8adff592 2005-03-19 fw unsigned int len;
84 39f1ddd9 2005-01-25 alex
85 39f1ddd9 2005-01-25 alex assert( String != NULL );
86 39f1ddd9 2005-01-25 alex
87 39f1ddd9 2005-01-25 alex len = strlen( String );
88 39f1ddd9 2005-01-25 alex if( len == 0 ) return;
89 39f1ddd9 2005-01-25 alex
90 39f1ddd9 2005-01-25 alex len--;
91 39f1ddd9 2005-01-25 alex
92 39f1ddd9 2005-01-25 alex if( String[len] == Chr ) String[len] = '\0';
93 39f1ddd9 2005-01-25 alex } /* ngt_TrimLastChr */
94 39f1ddd9 2005-01-25 alex
95 39f1ddd9 2005-01-25 alex
96 0f3e84f4 2003-01-13 alex /* -eof- */