Beispiel #1
0
void IniConfig::read ()
{
    char *path = NULL;
    ini_fd_t ini  = 0;
    char   *configPath;
    size_t  length;

#ifdef _WIN32
    path = (char *) getenv("USERPROFILE");
#endif
#ifdef HAVE_UNIX
    path = (char *) getenv("HOME");
#endif

    if (!path)
        goto IniConfig_read_error;

    length = strlen(path) + strlen(DIR_NAME) + strlen(FILE_NAME) + 3;
    configPath = (char *) malloc(length);
    if (! configPath)
        goto IniConfig_read_error;

    sprintf(configPath, "%s/%s", path, DIR_NAME);

#ifdef HAVE_UNIX
    // Make sure the config path exists
    if (!opendir(configPath))
        mkdir(configPath, 0755);
#endif
#ifdef _WIN32
    CreateDirectory(configPath, NULL);
#endif

    /* sprintf on top of itself fails nowadays. */
    strcat(configPath, "/");
    strcat(configPath, FILE_NAME);

    // Opens an existing file or creates a new one
    ini = ini_open (configPath, "w", ";");

    // Unable to open file?
    if (!ini)
        goto IniConfig_read_error;

    clear ();

    // This may not exist here...
    status &= readSidplay2  (ini);
    status &= readConsole   (ini);
    status &= readAudio     (ini);
    status &= readEmulation (ini);
    ini_close (ini);
return;

IniConfig_read_error:
    if (ini)
        ini_close (ini);
    clear ();
    status = false;
}
Beispiel #2
0
/**
 * 
 * 
 * @author chenxb (10/2/2010)
 * 
 * @return int 
 */
int load_cfg()
{
    INI  *inidev, *iniplan, *iniaction;
    inidev = ini_open(DEV_INI);
    if( !inidev)  {
        config_debug("(load_cfg) err: open %s\n", DEV_INI);
        return -1;
    }
    dev_cfg(inidev);
    ini_close(inidev);

    iniplan = ini_open(PLAN_INI);
    if( !iniplan) {
        config_debug("(load_cfg): err, open %s\n", PLAN_INI);
        return -1;
    }
    plan_cfg(iniplan);
	ini_close(iniplan);
	
    iniaction = ini_open(AC_INI);
    if(!iniaction) {
        config_debug("(load_cfg): err, open %s\n", AC_INI);
        return -1;
    }
    ac_cfg(iniaction);
	ini_close(iniaction);
	
    printf("load_cfg ok !\n");
    return 0;

}
Beispiel #3
0
static int close_rename(INI_FILETYPE *rfp, INI_FILETYPE *wfp, const TCHAR *filename, TCHAR *buffer)
{
  (void)ini_close(rfp);
  (void)ini_close(wfp);
  (void)ini_remove(filename);
  (void)ini_tempname(buffer, filename, INI_BUFFERSIZE);
  (void)ini_rename(buffer, filename);
  return 1;
}
Beispiel #4
0
/* -------------------------------------------------------------------------- *
 * Client Shutdown                                                            *
 * -------------------------------------------------------------------------- */
void client_shutdown(void)
{
  if(client_ini)
    ini_close(client_ini);
  
  /* Bilder freigeben */
  client_free(client_buffer);  
/*  client_free_image(client_background);*/
  
  /* Client-Module herunterfahren */
  sound_shutdown();
  card_shutdown();
  net_shutdown();
  
  /* Bibliotheken herunterfahren */
  SDL_Quit();
  sgQuit();
  
#if MDEBUG_ENABLE
  mdebug_shutdown();
#endif /* MDEBUG_ENABLE */
  
  client_log(STATUS, "Baba! *Winke-Wink*");
  exit(0);
}
Beispiel #5
0
ini_t *ini_open( char *file )
{
	int fd;
	ini_t *ini = NULL;
	struct stat fi;
	
	if( ( fd = open( file, O_RDONLY ) ) != -1 &&
	    fstat( fd, &fi ) == 0 &&
	    fi.st_size <= 16384 &&
	    ( ini = g_malloc( sizeof( ini_t ) + fi.st_size + 1 ) ) &&
	    read( fd, ini->file, fi.st_size ) == fi.st_size )
	{
		memset( ini, 0, sizeof( ini_t ) );
		ini->size = fi.st_size;
		ini->file[ini->size] = 0;
		ini->cur = ini->file;
		ini->c_section = "";
		
		close( fd );
		
		return ini;
	}

	if( fd >= 0 )
		close( fd );
	
	ini_close( ini );

	return NULL;
}
Beispiel #6
0
static void gqi_ini_close(void* _self) {
  GQI_INI* self = _self;
  if (self->owns) {
    ini_close(self->ini);
    free(self->ini);
  }
  free(self);
}
Beispiel #7
0
void appini_t::ini_destroy (
                             ini_t * This
                             )
{
    if ( This )
    {
        ini_close ( This );
        free ( This );
    }
}
Beispiel #8
0
/** ini_browse()
 * \param Callback    a pointer to a function that will be called for every
 *                    setting in the INI file.
 * \param UserData    arbitrary data, which the function passes on the the
 *                    \c Callback function
 * \param Filename    the name and full path of the .ini file to read from
 *
 * \return            1 on success, 0 on failure (INI file not found)
 *
 * \note              The \c Callback function must return 1 to continue
 *                    browsing through the INI file, or 0 to stop. Even when the
 *                    callback stops the browsing, this function will return 1
 *                    (for success).
 */
int  ini_browse(INI_CALLBACK Callback, const void *UserData, const TCHAR *Filename)
{
  TCHAR LocalBuffer[INI_BUFFERSIZE];
  TCHAR *sp, *ep;
  int lenSec, lenKey;
  enum quote_option quotes;
  INI_FILETYPE fp;

  if (Callback == NULL)
    return 0;
  if (!ini_openread(Filename, &fp))
    return 0;

  LocalBuffer[0] = '\0';   /* copy an empty section in the buffer */
  lenSec = _tcslen(LocalBuffer) + 1;
  for ( ;; ) {
    if (!ini_read(LocalBuffer + lenSec, INI_BUFFERSIZE - lenSec, &fp))
      break;
    sp = skipleading(LocalBuffer + lenSec);
    /* ignore empty strings and comments */
    if (*sp == '\0' || *sp == ';' || *sp == '#')
      continue;
    /* see whether we reached a new section */
    ep = _tcschr(sp, ']');
    if (*sp == '[' && ep != NULL) {
      *ep = '\0';
      save_strncpy(LocalBuffer, sp + 1, INI_BUFFERSIZE, QUOTE_NONE);
      lenSec = _tcslen(LocalBuffer) + 1;
      continue;
    } /* if */
    /* not a new section, test for a key/value pair */
    ep = _tcschr(sp, '=');    /* test for the equal sign or colon */
    if (ep == NULL)
      ep = _tcschr(sp, ':');
    if (ep == NULL)
      continue;               /* invalid line, ignore */
    *ep++ = '\0';             /* split the key from the value */
    striptrailing(sp);
    save_strncpy(LocalBuffer + lenSec, sp, INI_BUFFERSIZE - lenSec, QUOTE_NONE);
    lenKey = _tcslen(LocalBuffer + lenSec) + 1;
    /* clean up the value */
    sp = skipleading(ep);
    sp = cleanstring(sp, &quotes);  /* Remove a trailing comment */
    save_strncpy(LocalBuffer + lenSec + lenKey, sp, INI_BUFFERSIZE - lenSec - lenKey, quotes);
    /* call the callback */
    if (!Callback(LocalBuffer, LocalBuffer + lenSec, LocalBuffer + lenSec + lenKey, UserData))
      break;
  } /* for */

  (void)ini_close(&fp);
  return 1;
}
bool LauncherSettings::save()
{
	FILE *fp = ini_open_for_write(const_cast<char*>(INI_MAIN), false, "DO NOT EDIT THIS FILE");
	if (fp == NULL)
		return false;

	ini_write_type(fp, "[launcher]");
	ini_write_data(fp, "exe_filepath", m_exe_filepath);
	ini_write_data(fp, "active_mod", m_active_mod);
	ini_write_data(fp, "showed_pilot_warning", m_showed_pilot_warning);

	ini_close(fp);
	return true;
}
Beispiel #10
0
void SidFilter::read (const char *filename)
{
    ini_fd_t ini = ini_open (filename, "r", ";");

    // Illegal ini fd
    if (!ini)
    {
        m_status      = false;
        m_errorString = "SID Filter: Unable to open filter file";
        return;
    }

    read (ini, "Filter");
    ini_close (ini);
}
Beispiel #11
0
/** ini_getkey()
 * \param Section     the name of the section to browse through, or NULL to
 *                    browse through the keys outside any section
 * \param idx         the zero-based sequence number of the key to return
 * \param Buffer      a pointer to the buffer to copy into
 * \param BufferSize  the maximum number of characters to copy
 * \param Filename    the name and full path of the .ini file to read from
 *
 * \return            the number of characters copied into the supplied buffer
 */
int  ini_getkey(const TCHAR *Section, int idx, TCHAR *Buffer, int BufferSize, const TCHAR *Filename)
{
  INI_FILETYPE fp;
  int ok = 0;

  if (Buffer == NULL || BufferSize <= 0 || idx < 0)
    return 0;
  if (ini_openread(Filename, &fp)) {
    ok = getkeystring(&fp, Section, NULL, -1, idx, Buffer, BufferSize);
    (void)ini_close(&fp);
  } /* if */
  if (!ok)
    *Buffer = '\0';
  return _tcslen(Buffer);
}
Beispiel #12
0
int ini_gets(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *DefValue, mTCHAR *Buffer, int BufferSize, const TCHAR *Filename)
{
	INI_FILETYPE fp;
	int nb = 0;

	if (Buffer == NULL || BufferSize <= 0 || Key == NULL)
	    return 0;

	if(ini_openread(Filename, &fp))
	{
		nb = ini_gets_OpenedFile(Section, Key, DefValue, Buffer, BufferSize, &fp);
		(void) ini_close(&fp);
	}

	return nb;
}
Beispiel #13
0
/** ini_getkey()
 * \param Section     the name of the section to browse through, or NULL to
 *                    browse through the keys outside any section
 * \param idx         the zero-based sequence number of the key to return
 * \param Buffer      a pointer to the buffer to copy into
 * \param BufferSize  the maximum number of characters to copy
 * \param Filename    the name and full path of the .ini file to read from
 *
 * \return            the number of characters copied into the supplied buffer
 */
int  ini_getkey(const TCHAR *Section, int idx, TCHAR *Buffer, int BufferSize, const TCHAR *Filename)
{
	INI_FILETYPE fp;
	int nb = 0;

	if (Buffer == NULL || BufferSize <= 0 || idx < 0)
		return 0;

	if (ini_openread(Filename, &fp))
	{
		nb = ini_getkey_OpenedFile(Section, idx, Buffer, BufferSize, &fp);
		(void) ini_close(&fp);
	}

	return nb;
}
Beispiel #14
0
/** ini_gets()
 * \param Section     the name of the section to search for
 * \param Key         the name of the entry to find the value of
 * \param DefValue    default string in the event of a failed read
 * \param Buffer      a pointer to the buffer to copy into
 * \param BufferSize  the maximum number of characters to copy
 * \param Filename    the name and full path of the .ini file to read from
 *
 * \return            the number of characters copied into the supplied buffer
 */
int ini_gets(const TCHAR *Section, const TCHAR *Key, const TCHAR *DefValue,
             TCHAR *Buffer, int BufferSize, const TCHAR *Filename)
{
  INI_FILETYPE fp;
  int ok = 0;

  if (Buffer == NULL || BufferSize <= 0 || Key == NULL)
    return 0;
  if (ini_openread(Filename, &fp)) {
    ok = getkeystring(&fp, Section, Key, -1, -1, Buffer, BufferSize);
    (void)ini_close(&fp);
  } /* if */
  if (!ok)
    save_strncpy(Buffer, DefValue, BufferSize, QUOTE_NONE);
  return _tcslen(Buffer);
}
bool ModSettings::save_user()
{
	char path_buffer[MAX_PATH];
	char all_params[3000] = { 0 };
	FILE *fp;

	// build command line (sans exe)
	if (*m_mod_params)
	{
		strcat(all_params, m_mod_params);
		strcat(all_params, " ");
	}
	if (*m_standard_params)
	{
		strcat(all_params, m_standard_params);
		strcat(all_params, " ");
	}
	if (*m_custom_params)
	{
		strcat(all_params, m_custom_params);
		strcat(all_params, " ");
	}
	trim(all_params);

	// write to config file
	check_cfg_file(path_buffer, true);
	fp = fopen(path_buffer, "wt");
	if (fp)
	{
		fwrite(all_params, len * sizeof(char), 1, fp);
		fclose(fp);
	}

	// write standard params to ini file
	char ini_name[MAX_PATH];
	sprintf(ini_name, "%s\\%s\\%s", LauncherSettings::get_exe_pathonly(), LauncherSettings::get_active_mod(), const_cast<char*>(INI_MOD_CUSTOM));

	fp = ini_open_for_write(ini_name, false, "These are the user's custom settings; don't distribute them with the mod because he'll want to choose his own");
	if (fp == NULL)
		return false;

	ini_write_type(fp, "[settings]");
	ini_write_data(fp, "flags", m_standard_params);

	ini_close(fp);
	return true;
}
Beispiel #16
0
static int load_theme_config(void)
{
	char buffer[300], *p = buffer;
	int ret;

	if (!theme_config_fd) {
		/*Theme config is not loaded yet*/
		memset(theme_font_sizes_cache, 0, sizeof(theme_font_sizes_cache));
		/* Open config file */
		char *filename = cfg_findfile ("etc/nanowm.cfg");
		if (!filename)
			return -1;

		ini_fd_t fd = ini_open (filename, "r", "#;");
		free (filename);

		if (fd == NULL) {
			fprintf (stderr, "theme_get: Unable to open nanowm.cfg file\n");
			return -1;
		} else {
			ret = ini_locateHeading (fd, "Main");
			ret = ini_locateKey (fd, "Theme");
			ret = ini_readString (fd, p, sizeof (buffer));
		}
		ini_close(fd);
		if (ret < 0)
			p = "theme";
		/* open theme config file */
		char path[256] =  ACTIVETHEME_PATH;

		strncat(path, p, 255);
		strncat(path, ".cfg", 255);
		filename = cfg_findfile (path);
		theme_config_fd = ini_open (filename, "r", "#;");
		free (filename);
		if (theme_config_fd == NULL) {
			fprintf (stderr, "theme_get: Unable to open theme config file\n");
			return -1;
		}

	}
	return 0;
}
Beispiel #17
0
/** ini_gets()
 * \param Section     the name of the section to search for
 * \param Key         the name of the entry to find the value of
 * \param DefValue    default string in the event of a failed read
 * \param Buffer      a pointer to the buffer to copy into
 * \param BufferSize  the maximum number of characters to copy
 * \param Filename    the name and full path of the .ini file to read from
 *
 * \return            the number of characters copied into the supplied buffer
 */
int ini_gets(const TCHAR *Section, const TCHAR *Key, const TCHAR *DefValue,
             TCHAR *Buffer, int BufferSize, const TCHAR *Filename)
{
  INI_FILETYPE fp;

//FILE* fp = fopen("./config.txt","rb");


  int ok = 0;

/*int i;
printf("file pointer, %p\n", fp);

  u_char* data;
  data = (u_char*) &fp;

  printf("fopen:::");

	    for (i=0; i<=(20); i++)	//-1 to account for not starting at 1
	    {
		printf("%s:", data[i]);
	    }
		printf("\n"); 
*/


  if (Buffer == NULL || BufferSize <= 0 || Key == NULL)
    return 0;
  if (ini_openread(Filename, &fp)) {
    ok = getkeystring(&fp, Section, Key, -1, -1, Buffer, BufferSize);
    (void)ini_close(&fp);
  } /* if */
  if (!ok)
    save_strncpy(Buffer, DefValue, BufferSize, QUOTE_NONE);
  return _tcslen(Buffer);
}
Beispiel #18
0
/** ini_puts()
 * \param Section     the name of the section to write the string in
 * \param Key         the name of the entry to write, or NULL to erase all keys in the section
 * \param Value       a pointer to the buffer the string, or NULL to erase the key
 * \param Filename    the name and full path of the .ini file to write to
 *
 * \return            1 if successful, otherwise 0
 */
int ini_puts(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value, const TCHAR *Filename)
{
  INI_FILETYPE rfp;
  INI_FILETYPE wfp;
  INI_FILEPOS mark;
  TCHAR *sp, *ep;
  TCHAR LocalBuffer[INI_BUFFERSIZE];
  int len, match, flag, cachelen;

  assert(Filename != NULL);
  if (!ini_openread(Filename, &rfp)) {
    /* If the .ini file doesn't exist, make a new file */
    if (Key != NULL && Value != NULL) {
      if (!ini_openwrite(Filename, &wfp))
        return 0;
      writesection(LocalBuffer, Section, &wfp);
      writekey(LocalBuffer, Key, Value, &wfp);
      (void)ini_close(&wfp);
    } /* if */
    return 1;
  } /* if */

  /* If parameters Key and Value are valid (so this is not an "erase" request)
   * and the setting already exists and it already has the correct value, do
   * nothing. This early bail-out avoids rewriting the INI file for no reason.
   */
  if (Key != NULL && Value != NULL) {
    (void)ini_tell(&rfp, &mark);
    match = getkeystring(&rfp, Section, Key, -1, -1, LocalBuffer, sizearray(LocalBuffer));
    if (match && _tcscmp(LocalBuffer,Value) == 0) {
      (void)ini_close(&rfp);
      return 1;
    } /* if */
    /* key not found, or different value -> proceed (but rewind the input file first) */
    (void)ini_seek(&rfp, &mark);
  } /* if */

  /* Get a temporary file name to copy to. Use the existing name, but with
   * the last character set to a '~'.
   */
  ini_tempname(LocalBuffer, Filename, INI_BUFFERSIZE);
  if (!ini_openwrite(LocalBuffer, &wfp)) {
    (void)ini_close(&rfp);
    return 0;
  } /* if */
  (void)ini_tell(&rfp, &mark);
  cachelen = 0;

  /* Move through the file one line at a time until a section is
   * matched or until EOF. Copy to temp file as it is read.
   */
  len = (Section != NULL) ? _tcslen(Section) : 0;
  if (len > 0) {
    do {
      if (!ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
        /* Failed to find section, so add one to the end */
        flag = cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
        if (Key!=NULL && Value!=NULL) {
          if (!flag)
            (void)ini_write(INI_LINETERM, &wfp);  /* force a new line behind the last line of the INI file */
          writesection(LocalBuffer, Section, &wfp);
          writekey(LocalBuffer, Key, Value, &wfp);
        } /* if */
        return close_rename(&rfp, &wfp, Filename, LocalBuffer);  /* clean up and rename */
      } /* if */
      /* Copy the line from source to dest, but not if this is the section that
       * we are looking for and this section must be removed
       */
      sp = skipleading(LocalBuffer);
      ep = _tcschr(sp, ']');
      match = (*sp == '[' && ep != NULL && (int)(ep-sp-1) == len && _tcsnicmp(sp + 1,Section,len) == 0);
      if (!match || Key != NULL) {
        if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
          cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
          (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
          cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
        } /* if */
      } /* if */
    } while (!match);
  } /* if */
  cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
  /* when deleting a section, the section head that was just found has not been
   * copied to the output file, but because this line was not "accumulated" in
   * the cache, the position in the input file was reset to the point just
   * before the section; this must now be skipped (again)
   */
  if (Key == NULL) {
    (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
    (void)ini_tell(&rfp, &mark);
  } /* if */

  /* Now that the section has been found, find the entry. Stop searching
   * upon leaving the section's area. Copy the file as it is read
   * and create an entry if one is not found.
   */
  len = (Key!=NULL) ? _tcslen(Key) : 0;
  for( ;; ) {
    if (!ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
      /* EOF without an entry so make one */
      flag = cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
      if (Key!=NULL && Value!=NULL) {
        if (!flag)
          (void)ini_write(INI_LINETERM, &wfp);  /* force a new line behind the last line of the INI file */
        writekey(LocalBuffer, Key, Value, &wfp);
      } /* if */
      return close_rename(&rfp, &wfp, Filename, LocalBuffer);  /* clean up and rename */
    } /* if */
    sp = skipleading(LocalBuffer);
    ep = _tcschr(sp, '='); /* Parse out the equal sign */
    if (ep == NULL)
      ep = _tcschr(sp, ':');
    match = (ep != NULL && (int)(skiptrailing(ep,sp)-sp) == len && _tcsnicmp(sp,Key,len) == 0);
    if ((Key != NULL && match) || *sp == '[')
      break;  /* found the key, or found a new section */
    /* copy other keys in the section */
    if (Key == NULL) {
      (void)ini_tell(&rfp, &mark);  /* we are deleting the entire section, so update the read position */
    } else {
      if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
        cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
        (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
        cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
      } /* if */
    } /* if */
  } /* for */
  /* the key was found, or we just dropped on the next section (meaning that it
   * wasn't found); in both cases we need to write the key, but in the latter
   * case, we also need to write the line starting the new section after writing
   * the key
   */
  flag = (*sp == '[');
  cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
  if (Key != NULL && Value != NULL)
    writekey(LocalBuffer, Key, Value, &wfp);
  /* cache_flush() reset the "read pointer" to the start of the line with the
   * previous key or the new section; read it again (because writekey() destroyed
   * the buffer)
   */
  (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
  if (flag) {
    /* the new section heading needs to be copied to the output file */
    cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
  } else {
    /* forget the old key line */
    (void)ini_tell(&rfp, &mark);
  } /* if */
  /* Copy the rest of the INI file */
  while (ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
    if (!cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE)) {
      cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
      (void)ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp);
      cache_accum(LocalBuffer, &cachelen, INI_BUFFERSIZE);
    } /* if */
  } /* while */
  cache_flush(LocalBuffer, &cachelen, &rfp, &wfp, &mark);
  return close_rename(&rfp, &wfp, Filename, LocalBuffer);  /* clean up and rename */
}
Beispiel #19
0
MYBOOL __WINAPI write_params(lprec *lp, char *filename, char *options)
{
    int k, ret, params_written;
    FILE *fp, *fp0;
    int state = 0, looping, newline;
    char buf[4096], *filename0, *ptr1, *ptr2, *header = NULL;

    readoptions(options, &header);

    k = strlen(filename);
    filename0 = (char *) malloc(k + 1 + 1);
    strcpy(filename0, filename);
    ptr1 = strrchr(filename0, '.');
    ptr2 = strrchr(filename0, '\\');
    if((ptr1 == NULL) || ((ptr2 != NULL) && (ptr1 < ptr2)))
        ptr1 = filename0 + k;
    memmove(ptr1 + 1, ptr1, k + 1 - (int) (ptr1 - filename0));
    ptr1[0] = '_';
    if(rename(filename, filename0)) {
        switch(errno) {
        case ENOENT: /* File or path specified by oldname not found */
            FREE(filename0);
            filename0 = NULL;
            break;
        case EACCES: /* File or directory specified by newname already exists or could not be created (invalid path); or oldname is a directory and newname specifies a different path. */
            FREE(filename0);
            FREE(header);
            return(FALSE);
            break;
        }
    }

    if((fp = ini_create(filename)) == NULL)
        ret = FALSE;
    else {
        params_written = FALSE;
        newline = TRUE;
        if(filename0 != NULL) {
            fp0 = ini_open(filename0);
            if(fp0 == NULL) {
                rename(filename0, filename);
                FREE(filename0);
                FREE(header);
                return(FALSE);
            }
            looping = TRUE;
            while(looping) {
                switch(ini_readdata(fp0, buf, sizeof(buf), TRUE)) {
                case 0: /* End of file */
                    looping = FALSE;
                    break;
                case 1: /* header */
                    ptr1 = strdup(buf);
                    STRUPR(buf);
                    ptr2 = strdup(header);
                    STRUPR(ptr2);
                    if(strcmp(buf, ptr2) == 0) {
                        write_params1(lp, fp, ptr1, newline);
                        params_written = TRUE;
                        newline = TRUE;
                        state = 1;
                    }
                    else {
                        state = 0;
                        ini_writeheader(fp, ptr1, newline);
                        newline = TRUE;
                    }
                    FREE(ptr2);
                    FREE(ptr1);
                    break;
                case 2: /* data */
                    if(state == 0) {
                        ini_writedata(fp, NULL, buf);
                        newline = (*buf != 0);
                    }
                    break;
                }
            }
            ini_close(fp0);
        }

        if(!params_written)
            write_params1(lp, fp, header, newline);

        ini_close(fp);
        ret = TRUE;
    }

    if(filename0 != NULL) {
        remove(filename0);
        FREE(filename0);
    }

    FREE(header);

    return( (MYBOOL) ret );
}
Beispiel #20
0
MYBOOL __WINAPI read_params(lprec *lp, char *filename, char *options)
{
    int ret, looping, line;
    FILE *fp;
    hashtable *hashfunctions, *hashparameters;
    hashelem *hp;
    int i, j, elements, n, intvalue, state = 0;
    REAL REALvalue;
    char buf[4096], *header = NULL, *ptr, *ptr1, *ptr2;

    if((fp = ini_open(filename)) == NULL)
        ret = FALSE;
    else {
        /* create hashtable of all callable commands to find them quickly */
        hashfunctions = create_hash_table(sizeof(functions) / sizeof(*functions), 0);
        for (n = 0, i = 0; i < (int) (sizeof(functions)/sizeof(*functions)); i++) {
            puthash(functions[i].par, i, NULL, hashfunctions);
            if(functions[i].values != NULL)
                n += functions[i].elements;
        }
        /* create hashtable of all arguments to find them quickly */
        hashparameters = create_hash_table(n, 0);
        for (n = 0, i = 0; i < (int) (sizeof(functions)/sizeof(*functions)); i++) {
            if(functions[i].values != NULL) {
                elements = functions[i].elements;
                for(j = 0; j < elements; j++)
                    if((strcmp(functions[i].values[j].svalue, "0") != 0) &&
                            (strcmp(functions[i].values[j].svalue, "1") != 0))
                        puthash(functions[i].values[j].svalue, j, NULL, hashparameters);
            }
        }

        readoptions(options, &header);

        STRUPR(header);
        ret = looping = TRUE;
        line = 0;
        while((ret) && (looping)) {
            line++;
            switch(ini_readdata(fp, buf, sizeof(buf), FALSE)) {
            case 0: /* End of file */
                looping = FALSE;
                break;
            case 1: /* header */
                switch(state) {
                case 0:
                    STRUPR(buf);
                    if(strcmp(buf, header) == 0)
                        state = 1;
                    break;
                case 1:
                    looping = FALSE;
                    break;
                }
                break;
            case 2: /* data */
                if(state == 1) {
                    for(ptr = buf; (*ptr) && (isspace(*ptr)); ptr++);
                }
                else
                    ptr = NULL;
                if((ptr != NULL) && (*ptr)) {
                    STRUPR(buf);
                    ptr = strchr(buf, '=');
                    if(ptr == NULL) {
                        report(lp, IMPORTANT, "read_params: No equal sign on line %d\n", line);
                        ret = FALSE;
                    }
                    else {
                        *ptr = 0;
                        for(ptr1 = buf; isspace(*ptr1); ptr1++);
                        for(ptr2 = ptr - 1; (ptr2 >= ptr1) && (isspace(*ptr2)); ptr2--);
                        if(ptr2 <= ptr1) {
                            report(lp, IMPORTANT, "read_params: No parameter name before equal sign on line %d\n", line);
                            ret = FALSE;
                        }
                        else {
                            ptr2[1] = 0;
                            hp = findhash(ptr1, hashfunctions);
                            if(hp == NULL) {
                                report(lp, IMPORTANT, "read_params: Unknown parameter name (%s) before equal sign on line %d\n", ptr1, line);
                                ret = FALSE;
                            }
                            else {
                                i = hp->index;
                                ptr1 = ++ptr;
                                intvalue = 0;
                                REALvalue = 0;
                                if(functions[i].values == NULL) {
                                    switch(functions[i].type) {
                                    case intfunction:
                                    case longfunction:
                                    case MYBOOLfunction:
                                        intvalue = strtol(ptr1, &ptr2, 10);
                                        while((*ptr2) && (isspace(*ptr2)))
                                            ptr2++;
                                        if(*ptr2) {
                                            report(lp, IMPORTANT, "read_params: Invalid integer value on line %d\n", line);
                                            ret = FALSE;
                                        }
                                        break;
                                    case REALfunction:
                                        REALvalue = strtod(ptr1, &ptr2);
                                        while((*ptr2) && (isspace(*ptr2)))
                                            ptr2++;
                                        if(*ptr2) {
                                            report(lp, IMPORTANT, "read_params: Invalid real value on line %d\n", line);
                                            ret = FALSE;
                                        }
                                        break;
                                    }
                                }
                                else {
                                    while(ret) {
                                        ptr = strchr(ptr1, '+');
                                        if(ptr == NULL)
                                            ptr = ptr1 + strlen(ptr1);
                                        for(; isspace(*ptr1); ptr1++);
                                        for(ptr2 = ptr - 1; (ptr2 >= ptr1) && (isspace(*ptr2)); ptr2--);
                                        if(ptr2 <= ptr1)
                                            break;
                                        else {
                                            ptr2[1] = 0;
                                            hp = findhash(ptr1, hashparameters);
                                            if (hp == NULL) {
                                                report(lp, IMPORTANT, "read_params: Invalid parameter name (%s) on line %d\n", ptr1, line);
                                                ret = FALSE;
                                            }
                                            else {
                                                j = hp->index;
                                                if((j >= functions[i].elements) ||
                                                        (strcmp(functions[i].values[j].svalue, ptr1))) {
                                                    report(lp, IMPORTANT, "read_params: Inappropriate parameter name (%s) on line %d\n", ptr1, line);
                                                    ret = FALSE;
                                                }
                                                else {
                                                    intvalue += functions[i].values[j].value;
                                                }
                                            }
                                            ptr1 = ptr + 1;
                                        }
                                    }
                                }
                                if(ret) {
                                    switch(functions[i].type) {
                                    case intfunction:
                                        functions[i].set_function.int_set_function(lp, intvalue);
                                        break;
                                    case longfunction:
                                        functions[i].set_function.long_set_function(lp, intvalue);
                                        break;
                                    case MYBOOLfunction:
                                        functions[i].set_function.MYBOOL_set_function(lp, (MYBOOL) intvalue);
                                        break;
                                    case REALfunction:
                                        functions[i].set_function.REAL_set_function(lp, REALvalue);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            }
        }

        FREE(header);
        free_hash_table(hashfunctions);
        free_hash_table(hashparameters);

        ini_close(fp);
    }

    return( (MYBOOL) ret );
}
Beispiel #21
0
 ~Rule () { ini_close (m_inifd); }
Beispiel #22
0
void ini_clear(INI* self) {
  ini_close(self);
  ini_init(self);
}
Beispiel #23
0
void update_from_ini(const char *ini_file,
		const char *driver_name, struct iio_device *dev,
		const char * const *whitelist, size_t list_len)
{
	bool found = false;
	const char *name;
	size_t nlen;
	unsigned int i;
	struct INI *ini = ini_open(ini_file);
	struct load_store_params params = {
		.dev = dev,
		.whitelist = whitelist,
		.list_len = list_len,
		.is_debug = false,
		.ini = ini,
	};

	if (!ini) {
		fprintf(stderr, "ERROR: Cannot open INI file %s\n", ini_file);
		return;
	}

	while (!found && ini_next_section(ini, &name, &nlen) > 0)
		found = !strncmp(name, driver_name, nlen);
	if (!found) {
		fprintf(stderr, "error parsing %s file: Could not find %s\n",
				ini_file, driver_name);
		ini_close(ini);
		return;
	}

	params.section_top = name + nlen + 1;

	for (i = 0; i < iio_device_get_channels_count(dev); i++)
		iio_channel_attr_write_all(iio_device_get_channel(dev, i),
				update_from_ini_chn_cb, &params);
	if (iio_device_get_attrs_count(dev))
		iio_device_attr_write_all(dev, update_from_ini_dev_cb, &params);

	params.is_debug = true;
	iio_device_debug_attr_write_all(dev, update_from_ini_dev_cb, &params);

	ini_close(ini);
}

char * read_token_from_ini(const char *ini_file,
		const char *driver_name, const char *token)
{
	char *dup;
	const char *name, *key, *value;
	size_t nlen, klen, vlen, tlen = strlen(token);
	bool found = false;
	struct INI *ini = ini_open(ini_file);
	if (!ini)
		return NULL;

	while (!found && ini_next_section(ini, &name, &nlen) > 0)
		found = !strncmp(name, driver_name, nlen);
	if (!found)
		return NULL;

	found = false;
	while (!found && ini_read_pair(ini, &key, &klen, &value, &vlen) > 0)
		found = (tlen == klen) && !strncmp(token, key, klen);
	if (!found)
		return NULL;

	dup = malloc(vlen + 1);
	snprintf(dup, vlen + 1, "%.*s", (int) vlen, value);

	ini_close(ini);
	return dup;
}
Beispiel #24
0
void save_to_ini(FILE *f, const char *driver_name, struct iio_device *dev,
		const char * const *whitelist, size_t list_len)
{
	unsigned int i;
	struct load_store_params params = {
		.dev = dev,
		.whitelist = whitelist,
		.list_len = list_len,
		.is_debug = false,
		.f = f,
	};

	if (driver_name) {
		fwrite("\n[", 1, 2, f);
		fwrite(driver_name, 1, strlen(driver_name), f);
		fwrite("]\n", 1, 2, f);
	}

	for (i = 0; i < iio_device_get_channels_count(dev); i++)
		iio_channel_attr_read_all(iio_device_get_channel(dev, i),
				save_to_ini_chn_cb, &params);
	iio_device_attr_read_all(dev, save_to_ini_dev_cb, &params);

	params.is_debug = true;
	iio_device_debug_attr_read_all(dev, save_to_ini_dev_cb, &params);
}

int foreach_in_ini(const char *ini_file,
		int (*cb)(int, const char *, const char *, const char *))
{
	int ret = 0;
	const char *name, *key, *value;
	size_t nlen, klen, vlen;
	struct INI *ini = ini_open(ini_file);
	if (!ini)
		return -1;

	while (ini_next_section(ini, &name, &nlen) > 0) {
		char *n = malloc(nlen + 1);
		if (!n)
			goto err_ini_close;

		snprintf(n, nlen + 1, "%.*s", (int) nlen, name);

		while (ini_read_pair(ini, &key, &klen, &value, &vlen) > 0) {
			int line = ini_get_line_number(ini, key);
			char *v, *k = malloc(klen + 1);
			if (!k) {
				free(n);
				goto err_ini_close;
			}

			v = malloc(vlen + 1);
			if (!v) {
				free(k);
				free(n);
				goto err_ini_close;
			}

			snprintf(k, klen + 1, "%.*s", (int) klen, key);
			snprintf(v, vlen + 1, "%.*s", (int) vlen, value);

			ret = cb(line, n, k, v);

			/* only needed when debugging - this should be done in each section
			if (ret < 0) {
				fprintf(stderr, "issue in '%s' file: Section:'%s' key:'%s' value:'%s'\n",
						ini_file, n, k, v);
			}
			*/

			free(k);
			free(v);

			if (ret < 0) {
				free(n);
				goto err_ini_close;
			}

			if (ret > 0) {
				ret = 0;
				break;
			}
		}

		free(n);
	}

err_ini_close:
	ini_close(ini);
	return ret;
}
Beispiel #25
0
/** ini_puts()
 * \param Section     the name of the section to write the string in
 * \param Key         the name of the entry to write, or NULL to erase all keys in the section
 * \param Value       a pointer to the buffer the string, or NULL to erase the key
 * \param Filename    the name and full path of the .ini file to write to
 *
 * \return            1 if successful, otherwise 0
 */
int ini_puts(const TCHAR *Section, const TCHAR *Key, const TCHAR *Value, const TCHAR *Filename)
{
  INI_FILETYPE rfp;
  INI_FILETYPE wfp;
  TCHAR *sp, *ep;
  TCHAR LocalBuffer[INI_BUFFERSIZE];
  int len, match, count;

  assert(Filename!=NULL);
  if (!ini_openread(Filename, &rfp)) {
    /* If the .ini file doesn't exist, make a new file */
    if (Key!=NULL && Value!=NULL) {
      if (!ini_openwrite(Filename, &wfp))
        return 0;
      writesection(LocalBuffer, Section, &wfp);
      writekey(LocalBuffer, Key, Value, &wfp);
      ini_close(&wfp);
    } /* if */
    return 1;
  } /* if */

  /* If parameters Key and Value are valid (so this is not an "erase" request)
   * and the setting already exists and it already has the correct value, do
   * nothing. This early bail-out avoids rewriting the INI file for no reason.
   */
  if (Key!=NULL && Value!=NULL) {
    match = getkeystring(&rfp, Section, Key, -1, -1, LocalBuffer, sizearray(LocalBuffer));
    if (match && _tcscmp(LocalBuffer,Value)==0) {
      ini_close(&rfp);
      return 1;
    } /* if */
    /* key not found, or different value -> proceed (but rewind the input file first) */
    ini_rewind(&rfp);
  } /* if */

  /* Get a temporary file name to copy to. Use the existing name, but with
   * the last character set to a '~'.
   */
  ini_tempname(LocalBuffer, Filename, INI_BUFFERSIZE);
  if (!ini_openwrite(LocalBuffer, &wfp)) {
    ini_close(&rfp);
    return 0;
  } /* if */

  /* Move through the file one line at a time until a section is
   * matched or until EOF. Copy to temp file as it is read.
   */
  count = 0;
  len = (Section != NULL) ? _tcslen(Section) : 0;
  if (len > 0) {
    do {
      if (!ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
        /* Failed to find section, so add one to the end */
        if (Key!=NULL && Value!=NULL) {
            ini_write(INI_LINETERM, &wfp);  /* force a new line (there may not have been one) behind the last line of the INI file */
            writesection(LocalBuffer, Section, &wfp);
            writekey(LocalBuffer, Key, Value, &wfp);
        } /* if */
        /* Clean up and rename */
        ini_close(&rfp);
        ini_close(&wfp);
        ini_remove(Filename);
        ini_tempname(LocalBuffer, Filename, INI_BUFFERSIZE);
        ini_rename(LocalBuffer, Filename);
        return 1;
      } /* if */
      /* Copy the line from source to dest, but not if this is the section that
       * we are looking for and this section must be removed
       */
      sp = skipleading(LocalBuffer);
      ep = _tcschr(sp, ']');
      match = (*sp == '[' && ep != NULL && (int)(ep-sp-1) == len && _tcsnicmp(sp + 1,Section,len) == 0);
      if (!match || Key!=NULL) {
        /* Remove blank lines, but insert a blank line (possibly one that was
         * removed on the previous iteration) before a new section. This creates
         * "neat" INI files.
         */
        if (_tcslen(sp) > 0) {
          if (*sp == '[' && count > 0)
            ini_write(INI_LINETERM, &wfp);
          ini_write(sp, &wfp);
          count++;
        } /* if */
      } /* if */
    } while (!match);
  } /* if */

  /* Now that the section has been found, find the entry. Stop searching
   * upon leaving the section's area. Copy the file as it is read
   * and create an entry if one is not found.
   */
  len = (Key!=NULL) ? _tcslen(Key) : 0;
  for( ;; ) {
    if (!ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
      /* EOF without an entry so make one */
      if (Key!=NULL && Value!=NULL) {
          ini_write(INI_LINETERM, &wfp);  /* force a new line (there may not have been one) behind the last line of the INI file */
          writekey(LocalBuffer, Key, Value, &wfp);
      } /* if */
      /* Clean up and rename */
      ini_close(&rfp);
      ini_close(&wfp);
      ini_remove(Filename);
      ini_tempname(LocalBuffer, Filename, INI_BUFFERSIZE);
      ini_rename(LocalBuffer, Filename);
      return 1;
    } /* if */
    sp = skipleading(LocalBuffer);
    ep = _tcschr(sp, '='); /* Parse out the equal sign */
    if (ep == NULL)
      ep = _tcschr(sp, ':');
    match = (ep != NULL && (int)(ep-sp) == len && _tcsnicmp(sp,Key,len) == 0);
    if ((Key!=NULL && match) || *sp == '[')
      break;  /* found the key, or found a new section */
    /* in the section that we re-write, do not copy empty lines */
    if (Key!=NULL && _tcslen(sp) > 0)
      ini_write(sp, &wfp);
  } /* for */
  if (*sp == '[') {
    /* found start of new section, the key was not in the specified
     * section, so we add it just before the new section
     */
    if (Key!=NULL && Value!=NULL) {
      /* We cannot use "writekey()" here, because we need to preserve the
       * contents of LocalBuffer.
       */
      ini_write(Key, &wfp);
      ini_write("=", &wfp);
      ini_write(Value, &wfp);
      ini_write(INI_LINETERM INI_LINETERM, &wfp); /* put a blank line between the current and the next section */
    } /* if */
    /* write the new section header that we read previously */
    ini_write(sp, &wfp);
  } else {
    /* We found the key; ignore the line just read (with the key and
     * the current value) and write the key with the new value.
     */
    if (Key!=NULL && Value!=NULL)
      writekey(LocalBuffer, Key, Value, &wfp);
  } /* if */
  /* Copy the rest of the INI file (removing empty lines, except before a section) */
  while (ini_read(LocalBuffer, INI_BUFFERSIZE, &rfp)) {
    sp = skipleading(LocalBuffer);
    if (_tcslen(sp) > 0) {
      if (*sp == '[')
        ini_write(INI_LINETERM, &wfp);
      ini_write(sp, &wfp);
    } /* if */
  } /* while */
  /* Clean up and rename */
  ini_close(&rfp);
  ini_close(&wfp);
  ini_remove(Filename);
  ini_tempname(LocalBuffer, Filename, INI_BUFFERSIZE);
  ini_rename(LocalBuffer, Filename);
  return 1;
}
Beispiel #26
0
int init_setting(void) {
//
	double data;
	char temp[128] = {'\0'};
	INI_HANDLE handle = ini_open("setting.ini");
	if(handle == INI_FAIL){
		print_errmsg("%s\n", ini_geterrmsg());
		return -1;
	}
//
	if(mem_set() != 0) {
		print_errmsg("memory alloc fail!\n");
		return -1;
	}

	load_default();
	
	ini_get_key_ulong(handle, "system", "CMD_BUFFER_SIZE", &sys->cmd_buffer_size);
	ini_get_key_ulong(handle, "system", "CMD_BUFFER_NEAR_FULL", &sys->cmd_buffer_near_full);
	ini_get_key_ulong(handle, "system", "BLOCK_BUFFER_SIZE", &sys->block_buffer_size);
	ini_get_key_ulong(handle, "system", "BLOCK_BUFFER_BOUND", &sys->block_buffer_bound);
	ini_get_key_ulong(handle, "system", "MAX_CMD_SIZE", &sys->max_cmd_size);
	ini_get_key_ulong(handle, "system", "STEPPER_BUFFER_SIZE", &sys->stepper_buffer_size);
	ini_get_key_ulong(handle, "system", "STEPPER_BUFFER_BOUND", &sys->stepper_buffer_bound);
	ini_get_key_ulong(handle, "system", "MIN_STEP_PULSE_DUTY", &sys->min_step_pulse_duty);
	ini_get_key_ulong(handle, "system", "DEFAULT_PULSE_PERIOD", &sys->default_pulse_period);
	ini_get_key_ulong(handle, "system", "DEFAULT_PULSE_DUTY", &sys->default_pulse_duty);
	ini_get_key_ulong(handle, "system", "HIT_PULSE_PERIOD", &sys->hit_pulse_period);
	ini_get_key_ulong(handle, "system", "HIT_PULSE_DUTY", &sys->hit_pulse_duty);

	ini_get_key_int(handle, "machine", "MIN_SOFTWARE_LIMIT", &machine->min_software_limit);
	ini_get_key_int(handle, "machine", "MAX_SOFTWARE_LIMIT", &machine->max_software_limit);
	//TODO:改不管大小寫
	ini_get_key(handle, "machine", "TYPE", &temp[0]);
	if(strcmp(temp, "H_BOT") == 0) 
		machine->type = H_BOT;
	else if(strcmp(temp, "DELTA") == 0)
		machine->type = DELTA;
	else
		machine->type = NORMAL;
	
	ini_get_key_int(handle, "machine", "NUM_AXIS", &machine->num_axis);
	ini_get_key_double(handle, "machine", "X_MAX_POS_MM", &machine->x_max_pos_mm);
	ini_get_key_double(handle, "machine", "X_MIN_POS_MM", &machine->x_min_pos_mm);
	ini_get_key_double(handle, "machine", "X_HOME_POS_MM", &machine->x_home_pos_mm);
	ini_get_key_double(handle, "machine", "Y_MAX_POS_MM", &machine->y_max_pos_mm);
	ini_get_key_double(handle, "machine", "Y_MIN_POS_MM", &machine->y_min_pos_mm);
	ini_get_key_double(handle, "machine", "Y_HOME_POS_MM", &machine->y_home_pos_mm);
	ini_get_key_double(handle, "machine", "Z_MAX_POS_MM", &machine->z_max_pos_mm);
	ini_get_key_double(handle, "machine", "Z_MIN_POS_MM", &machine->z_min_pos_mm);
	ini_get_key_double(handle, "machine", "Z_HOME_POS_MM", &machine->z_home_pos_mm);
	ini_get_key_double(handle, "machine", "X_HOME_RETRACT_MM", &machine->x_home_retract_mm);
	ini_get_key_double(handle, "machine", "Y_HOME_RETRACT_MM", &machine->y_home_retract_mm);
	ini_get_key_double(handle, "machine", "Z_HOME_RETRACT_MM", &machine->z_home_retract_mm);
	ini_get_key_int(handle, "machine", "X_HOME_DIR", &machine->x_home_dir);;
	ini_get_key_int(handle, "machine", "Y_HOME_DIR", &machine->y_home_dir);
	ini_get_key_int(handle, "machine", "Z_HOME_DIR", &machine->z_home_dir);
	ini_get_key_double(handle, "machine", "QX_STEPS_PER_MM", &machine->qx_steps_per_mm);
	ini_get_key_double(handle, "machine", "QY_STEPS_PER_MM", &machine->qy_steps_per_mm);
	ini_get_key_double(handle, "machine", "QZ_STEPS_PER_MM", &machine->qz_steps_per_mm);
	ini_get_key_double(handle, "machine", "QE_STEPS_PER_MM", &machine->qe_steps_per_mm);	
	ini_get_key_double(handle, "machine", "X_MAX_FEEDRATE", &machine->x_max_feedrate_mps);
	ini_get_key_double(handle, "machine", "Y_MAX_FEEDRATE", &machine->y_max_feedrate_mps);
	ini_get_key_double(handle, "machine", "Z_MAX_FEEDRATE", &machine->z_max_feedrate_mps);
	ini_get_key_double(handle, "machine", "E_MAX_FEEDRATE", &machine->e_max_feedrate_mps);	
	ini_get_key_double(handle, "machine", "X_HOMING_FEEDRATE", &machine->x_homing_feedrate_mpm);
	ini_get_key_double(handle, "machine", "Y_HOMING_FEEDRATE", &machine->y_homing_feedrate_mpm);
	ini_get_key_double(handle, "machine", "Z_HOMING_FEEDRATE", &machine->z_homing_feedrate_mpm);	
	ini_get_key_double(handle, "machine", "QX_MAX_ACCELERATION", &machine->qx_max_acceleration);
	ini_get_key_double(handle, "machine", "QY_MAX_ACCELERATION", &machine->qy_max_acceleration);
	ini_get_key_double(handle, "machine", "QZ_MAX_ACCELERATION", &machine->qz_max_acceleration);
	ini_get_key_double(handle, "machine", "QE_MAX_ACCELERATION", &machine->qe_max_acceleration);	
	ini_get_key_double(handle, "machine", "DEFAULT_ACCELERATION", &machine->default_acceleration);
	ini_get_key_double(handle, "machine", "DEFAULT_RETRACT_ACCELERATION", &machine->default_retract_acceleration);
	ini_get_key_double(handle, "machine", "DEFAULT_MINIMUMFEEDRATE", &machine->default_minimumfeedrate);
	ini_get_key_double(handle, "machine", "DEFAULT_MINTRAVELFEEDRATE", &machine->default_mintravelfeedrate);
	ini_get_key_double(handle, "machine", "DEFAULT_XYJERK", &machine->default_xyjerk);
	ini_get_key_double(handle, "machine", "DEFAULT_EJERK", &machine->default_ejerk);
	ini_get_key_double(handle, "machine", "DEFAULT_ZJERK", &machine->default_zjerk);
	ini_get_key_double(handle, "machine", "MINIMUM_PLANNER_SPEED", &machine->minimum_planner_speed);
	
	//這裡必須檔0.5 跟 DUTY_MIN
	ini_get_key_double(handle, "machine", "STEP_PULSE_DUTY_RATE", &data);
	if(data < 0.5)
		machine->step_pulse_duty_ratio = 0.5;
	else if(data > 1 && data < (double)sys->min_step_pulse_duty)
		machine->step_pulse_duty_ratio = (double)sys->min_step_pulse_duty;
	else
		machine->step_pulse_duty_ratio = data;
	
	//TODO:改不管大小寫
	ini_get_key(handle, "machine", "LIMIT_SPEED", &temp[0]);
	if(strcmp(temp, "250k") == 0)
		machine->mcm_samplecycle = 25;
	else if(strcmp(temp, "200k") == 0)
		machine->mcm_samplecycle = 20;
	else if(strcmp(temp, "100k") == 0)
		machine->mcm_samplecycle = 10;
	else if(strcmp(temp, "50k") == 0)
		machine->mcm_samplecycle = 5;
	else if(strcmp(temp, "40k") == 0)
		machine->mcm_samplecycle = 4;
	else
		machine->mcm_samplecycle = 1;
	
	ini_get_key_int(handle, "machine", "MM_PER_ARC_SEGMENT", &machine->mm_per_arc_segment);
	ini_get_key_int(handle, "machine", "N_ARC_CORRECTION", &machine->n_arc_correction);	
	ini_get_key_double(handle, "machine", "X_HOME_OFFSET", &machine->home_offset[0]);
	ini_get_key_double(handle, "machine", "Y_HOME_OFFSET", &machine->home_offset[1]);
	ini_get_key_double(handle, "machine", "Z_HOME_OFFSET", &machine->home_offset[2]);

	ini_get_key_int(handle, "pins", "mc_qx", &pins->mc_qx);
	ini_get_key_int(handle, "pins", "md_qx", &pins->md_qx);
	ini_get_key_int(handle, "pins", "mc_qy", &pins->mc_qy);
	ini_get_key_int(handle, "pins", "md_qy", &pins->md_qy);
	ini_get_key_int(handle, "pins", "mc_qz", &pins->mc_qz);
	ini_get_key_int(handle, "pins", "md_qz", &pins->md_qz);
	ini_get_key_int(handle, "pins", "mc_qe", &pins->mc_qe);
	ini_get_key_int(handle, "pins", "md_qe", &pins->md_qe);
	ini_get_key_int(handle, "pins", "MC_LIMIT", &pins->mc_limit);
	ini_get_key_int(handle, "pins", "MD_LIMIT", &pins->md_limit);
	ini_get_key_int(handle, "pins", "MC_LCD", &pins->mc_lcd);
	ini_get_key_int(handle, "pins", "MD_LCD", &pins->md_lcd);

	ini_get_key_int(handle, "pins", "INVERT_X_DIR", &pins->invert_x_dir);
	ini_get_key_int(handle, "pins", "X_STEP_PIN", &pins->x_step_pin);
	ini_get_key_int(handle, "pins", "X_DIR_PIN", &pins->x_dir_pin);
	ini_get_key_int(handle, "pins", "INVERT_Y_DIR", &pins->invert_y_dir);
	ini_get_key_int(handle, "pins", "Y_STEP_PIN", &pins->y_step_pin);
	ini_get_key_int(handle, "pins", "Y_DIR_PIN", &pins->y_dir_pin);	
	ini_get_key_int(handle, "pins", "INVERT_Z_DIR", &pins->invert_z_dir);
	ini_get_key_int(handle, "pins", "Z_STEP_PIN", &pins->z_step_pin);
	ini_get_key_int(handle, "pins", "Z_DIR_PIN", &pins->z_dir_pin);
	ini_get_key_int(handle, "pins", "INVERT_E_DIR", &pins->invert_e_dir);	
	ini_get_key_int(handle, "pins", "E_STEP_PIN", &pins->e_step_pin);
	ini_get_key_int(handle, "pins", "E_DIR_PIN", &pins->e_dir_pin);	
	
	ini_get_key_int(handle, "pins", "X_ENABLE_PORT", &pins->x_enable_port);
	ini_get_key_int(handle, "pins", "X_ENABLE_PIN", &pins->x_enable_pin);
	ini_get_key_int(handle, "pins", "INVERT_X_ENABLE", &pins->invert_x_enable);
	ini_get_key_int(handle, "pins", "Y_ENABLE_PORT", &pins->y_enable_port);
	ini_get_key_int(handle, "pins", "Y_ENABLE_PIN", &pins->y_enable_pin);
	ini_get_key_int(handle, "pins", "INVERT_Y_ENABLE", &pins->invert_y_enable);
	ini_get_key_int(handle, "pins", "Z_ENABLE_PORT", &pins->z_enable_port);
	ini_get_key_int(handle, "pins", "Z_ENABLE_PIN", &pins->z_enable_pin);
	ini_get_key_int(handle, "pins", "INVERT_Z_ENABLE", &pins->invert_z_enable);
	ini_get_key_int(handle, "pins", "E_ENABLE_PORT", &pins->e_enable_port);
	ini_get_key_int(handle, "pins", "E_ENABLE_PIN", &pins->e_enable_pin);
	ini_get_key_int(handle, "pins", "INVERT_E_ENABLE", &pins->invert_e_enable);
	
	ini_get_key_int(handle, "temperature", "EXTRUDERS", &tp->extruders);
	ini_get_key_ulong(handle, "temperature", "PWM_PERIOD", &tp->pwm_period);
	
	ini_get_key_double(handle, "temperature", "HEATER_VELOCITY", &tp->heater_velocity);
	ini_get_key_double(handle, "temperature", "K1", &tp->K1);
	tp->K2 = 1 - tp->K1;
	ini_get_key_int(handle, "temperature", "AUTOTUNE_PID_ENABLE", &tp->autotune_pid_enable);
	ini_get_key_double(handle, "temperature", "DEFAULT_KP", &tp->default_Kp);
	ini_get_key_double(handle, "temperature", "DEFAULT_KI", &tp->default_Ki);
	ini_get_key_double(handle, "temperature", "DEFAULT_KD", &tp->default_Kd);
	ini_get_key_double(handle, "temperature", "DEFAULT_BEDKP", &tp->default_bedKp);
	ini_get_key_double(handle, "temperature", "DEFAULT_BEDKI", &tp->default_bedKi);
	ini_get_key_double(handle, "temperature", "DEFAULT_BEDKD", &tp->default_bedKd);

	ini_get_key_int(handle, "temperature", "BANG_MAX", &tp->bang_max);
	ini_get_key_int(handle, "temperature", "PID_MAX", &tp->pid_max);
	ini_get_key_int(handle, "temperature", "MAX_BED_POWER", &tp->max_bed_power);
	ini_get_key_int(handle, "temperature", "FAN_MAX", &tp->fan_max);	
	ini_get_key_int(handle, "temperature", "PID_INTEGRAL_DRIVE_MAX", &tp->pid_integral_drive_max);
	
	ini_get_key_double(handle, "temperature", "HEATER0_MINTEMP", &tp->heater_mintemp[0]);
	ini_get_key_double(handle, "temperature", "HEATER0_MAXTEMP", &tp->heater_maxtemp[0]);
	ini_get_key_double(handle, "temperature", "BED_MINTEMP", &tp->bed_mintemp);
	ini_get_key_double(handle, "temperature", "BED_MAXTEMP", &tp->bed_maxtemp);
	ini_get_key_int(handle, "temperature", "OVERSAMPLER", &tp->oversampler);
	ini_get_key_int(handle, "temperature", "PID_FUNCTIONAL_RANGE", &tp->pid_functional_range);
	
	// 86Duino Print3D v1.0
	ini_get_key_int(handle, "pins", "MC_PWM_HEATER0", &pins->mc_pwm[0]);
	ini_get_key_int(handle, "pins", "MD_PWM_HEATER0", &pins->md_pwm[0]);
	ini_get_key_int(handle, "pins", "MC_PWM_HEATER1", &pins->mc_pwm[1]);
	ini_get_key_int(handle, "pins", "MD_PWM_HEATER1", &pins->md_pwm[1]);
	ini_get_key_int(handle, "pins", "MC_PWM_BED", &pins->mc_pwm[2]);
	ini_get_key_int(handle, "pins", "MD_PWM_BED", &pins->md_pwm[2]);
	ini_get_key_int(handle, "pins", "MC_PWM_FAN0", &pins->mc_pwm[3]);
	ini_get_key_int(handle, "pins", "MD_PWM_FAN0", &pins->md_pwm[3]);
	ini_get_key_int(handle, "pins", "MC_PWM_FAN1", &pins->mc_pwm[4]);
	ini_get_key_int(handle, "pins", "MD_PWM_FAN1", &pins->md_pwm[4]);

	ini_get_key_int(handle, "pins", "AD_HEATER0", &pins->extruder_ad[0]);
	ini_get_key_int(handle, "pins", "AD_HEATER1", &pins->extruder_ad[1]);
	ini_get_key_int(handle, "pins", "AD_BED", &pins->hotedbed_ad);
	ini_get_key_int(handle, "pins", "AD_POWER", &pins->vin_ad);
	/*
	// 86Duino Print3D v2.0
	pins->mc_pwm[0] = 3;
	pins->md_pwm[0] = 0;
	pins->mc_pwm[1] = 3;
	pins->md_pwm[1] = 1;
	pins->mc_pwm[2] = 2;
	pins->md_pwm[2] = 2;
	pins->mc_pwm[3] = 2;
	pins->md_pwm[3] = 0;
	pins->mc_pwm[4] = 2;
	pins->md_pwm[4] = 1;

	pins->extruder_ad[0] = 0;
	pins->extruder_ad[1] = 1;
	pins->hotedbed_ad = 2;
	pins->vin_ad = 3;*/
	
	ini_get_key_int(handle, "Auto Bed Leveling", "ENABLE_AUTO_BED_LEVELING", &level->enable_auto_bed_leveling);
	ini_get_key_int(handle, "Auto Bed Leveling", "AUTO_BED_LEVELING_GRID", &level->auto_bed_leveling_grid);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_1_X", &level->abl_probe_pt_1_x);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_1_Y", &level->abl_probe_pt_1_y);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_2_X", &level->abl_probe_pt_2_x);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_2_Y", &level->abl_probe_pt_2_y );
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_3_X", &level->abl_probe_pt_3_x);
	ini_get_key_double(handle, "Auto Bed Leveling", "ABL_PROBE_PT_3_Y", &level->abl_probe_pt_3_y);
	ini_get_key_double(handle, "Auto Bed Leveling", "XY_TRAVEL_SPEED", &level->xy_travel_speed);
	ini_get_key_double(handle, "Auto Bed Leveling", "X_PROBE_OFFSET_FROM_EXTRUDER", &level->x_probe_offset_from_extruder);
	ini_get_key_double(handle, "Auto Bed Leveling", "Y_PROBE_OFFSET_FROM_EXTRUDER", &level->y_probe_offset_from_extruder);
	ini_get_key_double(handle, "Auto Bed Leveling", "Z_PROBE_OFFSET_FROM_EXTRUDER", &level->z_probe_offset_from_extruder);
	ini_get_key_int(handle, "Auto Bed Leveling", "AUTO_BED_LEVELING_GRID_POINTS", &level->auto_bed_leveling_grid_points);
	ini_get_key_double(handle, "Auto Bed Leveling", "LEFT_PROBE_BED_POSITION", &level->left_probe_bed_position);
	ini_get_key_double(handle, "Auto Bed Leveling", "RIGHT_PROBE_BED_POSITION", &level->right_probe_bed_position);
	ini_get_key_double(handle, "Auto Bed Leveling", "BACK_PROBE_BED_POSITION", &level->back_probe_bed_position);
	ini_get_key_double(handle, "Auto Bed Leveling", "FRONT_PROBE_BED_POSITION", &level->front_probe_bed_position);
	ini_get_key_double(handle, "Auto Bed Leveling", "Z_RAISE_BEFORE_PROBING", &level->z_raise_before_probing);
	ini_get_key_double(handle, "Auto Bed Leveling", "Z_RAISE_BETWEEN_PROBINGS", &level->z_raise_between_probings);
	
	if(ini_close(handle) == 1){
		print_errmsg("ini save fail\n");
	}
	return 0;
}
Beispiel #27
0
void SidDatabase::close ()
{
    if (database)
        ini_close (database);
}