⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfgfile.c

📁 GSM猫管理程序
💻 C
字号:
/*SMS Server Tools 3Copyright (C) Keijo Kasvihttp://smstools3.kekekasvi.com/Based on SMS Server Tools 2 from Stefan Fringshttp://www.meinemullemaus.de/This program is free software unless you got it under another license directlyfrom the author. You can redistribute it and/or modify it under the terms ofthe GNU General Public License as published by the Free Software Foundation.Either version 2 of the License, or (at your option) any later version.*/#include "cfgfile.h"#include "extras.h"#include <sys/types.h>#include <limits.h>#include <string.h>void cutcomment(char*  text){  char* cp;  int laenge;  cp=strchr(text,'#');  if (cp!=0)    *cp=0;  laenge=strlen(text);  // 3.1beta7: this was dropping scandinavic characters, unsigned test added:  while (laenge > 0 && ((unsigned char)text[laenge -1] <= (unsigned char)' '))  {    text[laenge-1]=0;    laenge--;  }}int getsubparam_delim(char*  parameter,                       int n,                       char*  subparam,  int size_subparam,                      char delim){  int j;  char* cp;  char* cp2;  int size;  cp=(char*)parameter;  subparam[0]=0;  for (j=1; j<n; j++)  {    if (!strchr(cp,delim))      return 0;    cp=strchr(cp,delim)+1;  }  cp2=strchr(cp,delim);  if (cp2)    size=cp2-cp;  else    size=strlen(cp);  strncpy(subparam,cp,size);  subparam[size]=0;  cutspaces(subparam);  return 1;}int getsubparam(char*  parameter,                 int n,                 char*  subparam,  int size_subparam){  return getsubparam_delim(parameter, n, subparam, size_subparam, ',');}int splitline( char*  source,               char*  name,  int size_name,	      char*  value,  int size_value){  char* equalchar;  int n;  equalchar=strchr(source,'=');  value[0]=0;  name[0]=0;  if (equalchar)  {    strncpy(value,equalchar+1,size_value);    value[size_value -1]=0;    cutspaces(value);    n=equalchar-source;    if (n>0)    {      if (n>size_name-1)        n=size_name-1;      strncpy(name,source,n);      name[n]=0;      cutspaces(name);      return 1;    }  }  return 0;}int gotosection(FILE* file,  char*  name){  char line[PATH_MAX+32];  //int Length;  char* posi;  fseek(file,0,SEEK_SET);  while (fgets(line,sizeof(line),file))  {    cutcomment(line);    // 3.1beta7: clean whitespaces:    while (is_blank(*line))      strcpy(line, line +1);    //Length=strlen(line);    //if (Length>2)    if (*line)    {      posi=strchr(line,']');      if ((line[0]=='[') && posi)      {// 3.1beta7: added brackets, should be a block, otherwise name is still tested.        *posi=0;        if (strcmp(line+1,name)==0)	  return 1;      }    }  }  return 0;}int my_getline(FILE* file,            char*  name,  int size_name,	    char*  value,  int size_value){  char line[PATH_MAX+32];  //int Length;  while (fgets(line,sizeof(line),file))  {    cutcomment(line);    //Length=strlen(line);    // 3.1beta7: clean whitespaces:    while (is_blank(*line))      strcpy(line, line +1);    // 3.1beta7: lines with one or two illegal characters were not reported:    //if (Length>2)    if (*line)    {      if (line[0]=='[')        return 0;      else        if (splitline(line,name,size_name,value,size_value)==0)	{	  strncpy(value,line,size_value);	  value[size_value -1]=0;	  return -1;	}	else	  return 1;    }  }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -