- Timestamp:
- Jun 28, 2007 3:20:17 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r1394 r1399 265 265 /* Scan tokens in the file. */ 266 266 while (argc < MAX_ARGS && !feof(fhnd)) { 267 char *token, *p = line; 268 267 char *token; 268 char *p; 269 const char *whitespace = " \t\r\n"; 270 char cDelimiter; 271 int len, token_len; 272 269 273 if (fgets(line, sizeof(line), fhnd) == NULL) break; 270 271 for (token = strtok(p, " \t\r\n"); argc < MAX_ARGS; 272 token = strtok(NULL, " \t\r\n")) 273 { 274 int token_len; 274 275 // Trim ending newlines 276 len = strlen(line); 277 if (line[len-1]=='\n') 278 line[--len] = '\0'; 279 if (line[len-1]=='\r') 280 line[--len] = '\0'; 281 282 if (len==0) continue; 283 284 for (p = line; *p != '\0' && argc < MAX_ARGS; p++) { 285 // first, scan whitespaces 286 while (*p != '\0' && strchr(whitespace, *p) != NULL) p++; 287 288 if (*p == '\0') // are we done yet? 289 break; 275 290 276 if (!token) break; 277 if (*token == '#') break; 278 279 token_len = strlen(token); 280 if (!token_len) 281 continue; 282 argv[argc] = pj_pool_alloc(pool, token_len+1); 283 pj_memcpy(argv[argc], token, token_len+1); 284 ++argc; 291 if (*p == '"' || *p == '\'') { // is token a quoted string 292 cDelimiter = *p++; // save quote delimiter 293 token = p; 294 295 while (*p != '\0' && *p != cDelimiter) p++; 296 297 if (*p == '\0') // found end of the line, but, 298 cDelimiter = '\0'; // didn't find a matching quote 299 300 } else { // token's not a quoted string 301 token = p; 302 303 while (*p != '\0' && strchr(whitespace, *p) == NULL) p++; 304 305 cDelimiter = *p; 306 } 307 308 *p = '\0'; 309 token_len = p-token; 310 311 if (token_len > 0) { 312 if (*token == '#') 313 break; // ignore remainder of line 314 315 argv[argc] = pj_pool_alloc(pool, token_len + 1); 316 pj_memcpy(argv[argc], token, token_len + 1); 317 ++argc; 318 } 319 320 *p = cDelimiter; 285 321 } 286 322 }
Note: See TracChangeset
for help on using the changeset viewer.