Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parseconf.c 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * core/parseconf.c
  3. */
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "config.h"
  7. extern int verbosity;
  8. extern Configuration config;
  9. #define CMP(a) (!strcmp(cptr, a))
  10. /* ---------------------------------------------------------------- */
  11. int parse_config(char *fname, int flags)
  12. {
  13. FILE *fp;
  14. char line[SZ_STRINGS+1], *cptr;
  15. int numligne;
  16. #if DEBUG_LEVEL
  17. fprintf(stderr, ">>> %s ( '%s' $%x )\n", fname, flags);
  18. #endif
  19. config.valid = 49;
  20. if (NULL==(fp=fopen(fname, "r"))) {
  21. perror(fname);
  22. return -2;
  23. }
  24. numligne = 0;
  25. while (fgets(line, SZ_STRINGS, fp))
  26. {
  27. numligne++;
  28. if ('\0'==line[0]) {
  29. fprintf(stderr, "%s : short read line %d\n",
  30. fname, numligne);
  31. fclose(fp);
  32. return -1;
  33. }
  34. /* massage the end of line */
  35. line[strlen(line)-1] = '\0'; /* kill EOL */
  36. if (verbosity) {
  37. fprintf(stderr, "%3d :\t%s\n", numligne, line);
  38. }
  39. /* seek for the first token in this line */
  40. if (NULL==(cptr = strtok(line, " \t"))) {
  41. /* Got an empty line */
  42. continue;
  43. }
  44. /* skip comments */
  45. if ('#'==*cptr) continue;
  46. if(verbosity) fprintf(stderr, "[%s]\n", cptr);
  47. }
  48. fclose(fp);
  49. return -1;
  50. }
  51. /* ---------------------------------------------------------------- */
  52. int show_config(char *title)
  53. {
  54. if (verbosity) {
  55. printf("********** %s **********\n", title);
  56. }
  57. printf("valid %d\n", config.valid);
  58. puts("");
  59. return 0;
  60. }
  61. /* ---------------------------------------------------------------- */