Mercurial > hg > octave-jordi
comparison src/variables.cc @ 279:c64f870ac8d9
[project @ 1994-01-08 22:51:53 by jwe]
author | jwe |
---|---|
date | Sat, 08 Jan 1994 22:51:53 +0000 |
parents | d66cc97f77a9 |
children | 3c23b8ea9099 |
comparison
equal
deleted
inserted
replaced
278:c2189d67a05c | 279:c64f870ac8d9 |
---|---|
29 #ifdef HAVE_UNISTD_H | 29 #ifdef HAVE_UNISTD_H |
30 #include <unistd.h> | 30 #include <unistd.h> |
31 #endif | 31 #endif |
32 #include <ctype.h> | 32 #include <ctype.h> |
33 #include <iostream.h> | 33 #include <iostream.h> |
34 #include <strstream.h> | |
34 | 35 |
35 #include "statdefs.h" | 36 #include "statdefs.h" |
36 #include "tree-const.h" | 37 #include "tree-const.h" |
37 #include "variables.h" | 38 #include "variables.h" |
38 #include "user-prefs.h" | 39 #include "user-prefs.h" |
445 /* | 446 /* |
446 * Extract a keyword and its value from a file. Input should look | 447 * Extract a keyword and its value from a file. Input should look |
447 * something like: | 448 * something like: |
448 * | 449 * |
449 * #[ \t]*keyword[ \t]*:[ \t]*string-value\n | 450 * #[ \t]*keyword[ \t]*:[ \t]*string-value\n |
450 */ | 451 * |
451 int | 452 * Returns a pointer to a static variable which is only valid until |
452 extract_keyword (istream& is, char *keyword, char *value) | 453 * the next time this function is called. |
453 { | 454 */ |
454 char *ptr = value; | 455 char * |
455 | 456 extract_keyword (istream& is, char *keyword) |
456 int status = 0; | 457 { |
458 ostrstream buf; | |
459 | |
460 static char *retval = (char *) NULL; | |
461 | |
462 delete [] retval; | |
463 retval = (char *) NULL; | |
457 | 464 |
458 char c; | 465 char c; |
459 while (is.get (c)) | 466 while (is.get (c)) |
460 { | 467 { |
461 if (c == '#') | 468 if (c == '#') |
462 { | 469 { |
463 while (is.get (c) && (c == ' ' || c == '\t' || c == '#')) | 470 while (is.get (c) && (c == ' ' || c == '\t' || c == '#')) |
464 ; // Skip whitespace and comment characters. | 471 ; // Skip whitespace and comment characters. |
465 | 472 |
466 if (isalpha (c)) | 473 if (isalpha (c)) |
467 *ptr++ = c; | 474 buf << c; |
468 | 475 |
469 while (is.get (c) && isalpha (c)) | 476 while (is.get (c) && isalpha (c)) |
470 *ptr++ = c; | 477 buf << c; |
471 | 478 |
472 if (strncmp (value, keyword, strlen (keyword)) == 0) | 479 buf << ends; |
480 char *tmp = buf.str (); | |
481 int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); | |
482 delete [] tmp; | |
483 | |
484 if (match) | |
473 { | 485 { |
474 ptr = value; | 486 ostrstream value; |
475 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) | 487 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) |
476 ; // Skip whitespace and the colon. | 488 ; // Skip whitespace and the colon. |
477 | 489 |
478 if (c != '\n') | 490 if (c != '\n') |
479 { | 491 { |
480 *ptr++ = c; | 492 value << c; |
481 while (is.get (c) && c != '\n') | 493 while (is.get (c) && c != '\n') |
482 *ptr++ = c; | 494 value << c; |
483 } | 495 } |
484 *ptr = '\0'; | 496 value << ends; |
485 status = 1; | 497 retval = value.str (); |
486 break; | 498 break; |
487 } | 499 } |
488 } | 500 } |
489 } | 501 } |
490 return status; | 502 return retval; |
491 } | 503 } |
492 | 504 |
493 int | 505 int |
494 extract_keyword (istream& is, char *keyword, int& value) | 506 extract_keyword (istream& is, char *keyword, int& value) |
495 { | 507 { |
496 char buf [128]; | 508 ostrstream buf; |
497 char *ptr = buf; | |
498 | 509 |
499 int status = 0; | 510 int status = 0; |
500 value = 0; | 511 value = 0; |
501 | 512 |
502 char c; | 513 char c; |
506 { | 517 { |
507 while (is.get (c) && (c == ' ' || c == '\t' || c == '#')) | 518 while (is.get (c) && (c == ' ' || c == '\t' || c == '#')) |
508 ; // Skip whitespace and comment characters. | 519 ; // Skip whitespace and comment characters. |
509 | 520 |
510 if (isalpha (c)) | 521 if (isalpha (c)) |
511 *ptr++ = c; | 522 buf << c; |
512 | 523 |
513 while (is.get (c) && isalpha (c)) | 524 while (is.get (c) && isalpha (c)) |
514 *ptr++ = c; | 525 buf << c; |
515 | 526 |
516 if (strncmp (buf, keyword, strlen (keyword)) == 0) | 527 buf << ends; |
528 char *tmp = buf.str (); | |
529 int match = (strncmp (tmp, keyword, strlen (keyword)) == 0); | |
530 delete [] tmp; | |
531 | |
532 if (match) | |
517 { | 533 { |
518 ptr = buf; | |
519 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) | 534 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) |
520 ; // Skip whitespace and the colon. | 535 ; // Skip whitespace and the colon. |
521 | 536 |
522 is.putback (c); | 537 is.putback (c); |
523 if (c != '\n') | 538 if (c != '\n') |