//
// Name: INTERSTELLAR CONSOLE
// Author: Misato Observatory, Wakayama, Japan
// License: GPL (General Public License)
//

#include <stdio.h>

//
//  Reads tcl-path.txt in current directory, and returns path string to set.
//
static inline int get_tcl_path( char *buf_path, int len_buf_path )
{
    int flag_found;
    FILE *fp;

    flag_found = 0;
    fp = fopen("tcl-path.txt", "r");
    if ( fp != NULL ) {
      char line[len_buf_path];
      while ( fgets(line, len_buf_path, fp) != NULL ) {
        int i,j,last_delim;
        for ( i=0 ; i < len_buf_path ; i++ ) {
          if ( line[i] == '\0' || ' ' < line[i] ) break;
        }
        j=0;
        last_delim=0;
        for ( ; i < len_buf_path ; i++ ) {
          if ( line[i] < ' ' ) {
            if ( 0 < last_delim ) {
              buf_path[last_delim] = '\0';
            } else {
              buf_path[j] = '\0';
            }
            break;
          } else {
            buf_path[j] = line[i];
            if ( ' ' < line[i] ) {
              last_delim = j + 1;
            }
            j++;
          }
        }
        if ( 0 < j ) {
          flag_found = 1;
          break;
        }
      }
      fclose(fp);
    }

    return flag_found;
}

