00001 /* 00002 * This file is part of testrunner-lite 00003 * 00004 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00005 * 00006 * Contact: Raimo Gratseff <ext-raimo.gratseff@nokia.com> 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public License 00010 * version 2.1 as published by the Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00020 * 02110-1301 USA 00021 * 00022 */ 00023 00024 /* ------------------------------------------------------------------------- */ 00025 /* INCLUDE FILES */ 00026 #include <stdio.h> 00027 #include <stdlib.h> 00028 #include <errno.h> 00029 #include <string.h> 00030 #include <ctype.h> 00031 00032 /* ------------------------------------------------------------------------- */ 00033 /* EXTERNAL DATA STRUCTURES */ 00034 /* None */ 00035 00036 /* ------------------------------------------------------------------------- */ 00037 /* EXTERNAL GLOBAL VARIABLES */ 00038 /* None */ 00039 00040 /* ------------------------------------------------------------------------- */ 00041 /* EXTERNAL FUNCTION PROTOTYPES */ 00042 /* None */ 00043 00044 /* ------------------------------------------------------------------------- */ 00045 /* GLOBAL VARIABLES */ 00046 /* None */ 00047 00048 /* ------------------------------------------------------------------------- */ 00049 /* CONSTANTS */ 00050 /* None */ 00051 00052 /* ------------------------------------------------------------------------- */ 00053 /* MACROS */ 00054 /* None */ 00055 00056 /* ------------------------------------------------------------------------- */ 00057 /* LOCAL GLOBAL VARIABLES */ 00058 /* None */ 00059 00060 /* ------------------------------------------------------------------------- */ 00061 /* LOCAL CONSTANTS AND MACROS */ 00062 00063 /* Match these to log.h log_message_types */ 00064 /* None */ 00065 00066 /* ------------------------------------------------------------------------- */ 00067 /* MODULE DATA STRUCTURES */ 00068 /* None */ 00069 00070 00071 /* ------------------------------------------------------------------------- */ 00072 /* LOCAL FUNCTION PROTOTYPES */ 00073 /* ------------------------------------------------------------------------- */ 00074 /* None */ 00075 00076 /* FORWARD DECLARATIONS */ 00077 /* None */ 00078 00079 /* ------------------------------------------------------------------------- */ 00080 /* ==================== LOCAL FUNCTIONS ==================================== */ 00081 /* ------------------------------------------------------------------------- */ 00082 /* None */ 00083 00084 /* ------------------------------------------------------------------------- */ 00085 /* ======================== FUNCTIONS ====================================== */ 00086 /* ------------------------------------------------------------------------- */ 00096 unsigned int trim_string (char *ins, char *outs) 00097 { 00098 unsigned int ins_i = 0; 00099 unsigned int ins_end = 0; 00100 unsigned int outs_i = 0; 00101 00102 /* make sure input and output strings exist */ 00103 if (ins == 0 || outs == 0) { 00104 return 0; 00105 } 00106 00107 ins_end = strlen(ins); 00108 00109 /* test if the string is empty */ 00110 if (ins_end == 0) { 00111 return 0; 00112 } 00113 00114 /* find the first non-whitespace character */ 00115 while (1) { 00116 if (ins_i >= ins_end) 00117 break; 00118 if (isspace(ins[ins_i])) 00119 ins_i += 1; 00120 else 00121 break; 00122 } 00123 00124 /* find the last non-whitespace character */ 00125 while (1) { 00126 if (ins_end <= ins_i) 00127 break; 00128 if (isspace(ins[ins_end - 1])) 00129 ins_end -= 1; 00130 else 00131 break; 00132 } 00133 00134 /* Copy trimmed string to output */ 00135 while (ins_i < ins_end) { 00136 /* check and skip control characters */ 00137 if (!iscntrl(ins[ins_i])) { 00138 outs[outs_i] = ins[ins_i]; 00139 outs_i += 1; 00140 } 00141 ins_i += 1; 00142 } 00143 /* add null termination */ 00144 outs[outs_i] = 0; 00145 00146 return outs_i; 00147 } 00148 00155 int list_contains(const char *list, const char *value, const char* delim) 00156 { 00157 int ret = 0; 00158 char *str = strdup(list); 00159 char *c = strtok(str, delim); 00160 00161 while (c != NULL) { 00162 if (strcmp(value, c) == 0) { 00163 ret = 1; 00164 break; 00165 } 00166 c = strtok(NULL, delim); 00167 } 00168 00169 free(str); 00170 return ret; 00171 } 00172 00173 00174 /* ================= OTHER EXPORTED FUNCTIONS ============================== */ 00175 /* None */ 00176 00177 /* ------------------------------------------------------------------------- */ 00178 /* End of file */ 00179
1.6.3