Skip to content

Create test.cpp #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions a/a.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main(int argc,char* args[]){
printf("AAAAAAAAAA\n");
return 0
}
6 changes: 6 additions & 0 deletions a/a.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __A_H__
#define __A_H__

const int A = 12;

#endif
86 changes: 86 additions & 0 deletions inifile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "inifile.h"
char strBuf[MAX_ARRAY_LEN] = { '0' };// buffer of read ini
int GetPrivateProfileStringLinux(const char* pAppName, const char* pKeyName, const char* lpDefault,
char* pReturnedString, unsigned long nSize, const char* pFileName) {

if (pReturnedString && strlen(pReturnedString))
memset(pReturnedString, 0, nSize);

FILE* fp;
int hasSectionFlag = 0;
char sSection[256], * sTempValue;

// open ini file
fopen_s(&fp, pFileName, "r");
if (!fp) {
return -1;
}

// section string [XXX]
sprintf_s(sSection, "[%s]", pAppName);

while (NULL != fgets(strBuf, MAX_ARRAY_LEN, fp))
{
if (0 == strncmp("//", strBuf, 2)) continue;// comment[//]
if ('#' == strBuf[0]) continue;// comment[#]
if (hasSectionFlag && '[' == strBuf[0]) break;

sTempValue = strchr(strBuf, '=');
if ((NULL != sTempValue) && (hasSectionFlag)) {
// key and value
if (0 == strncmp(pKeyName, strBuf, sTempValue - strBuf)) {
int line_feed_code = 0;//count
if ('\n' == strBuf[strlen(strBuf) - 1]) {
line_feed_code = 1;
// windows CR+LF
if (isLinuxOS) {
if ('\r' == strBuf[strlen(strBuf) - 2]) {
line_feed_code = 2;
}
}
// end code
strBuf[strlen(strBuf) - line_feed_code] = '\0';
}
fclose(fp);
// an empty string value
if(strlen(sTempValue) == 1)
memcpy(pReturnedString, lpDefault, strlen(lpDefault));
else
memcpy(pReturnedString, sTempValue + 1, strlen(sTempValue) - 1);
return (int)strlen(pReturnedString);
}
}
else {
// read section
if (strlen(strBuf) - 1 > 0) {
if (0 == strncmp(sSection, strBuf, strlen(strBuf) - 1)) {
hasSectionFlag = 1;
}
else {
// windows CR+LF
if (isLinuxOS) {
if (0 == strncmp(sSection, strBuf, strlen(strBuf) - 2))
hasSectionFlag = 1;
}
}
}
}
}
fclose(fp);

memcpy(pReturnedString, lpDefault, strlen(lpDefault));
return (int)strlen(pReturnedString);
}

int GetPrivateProfileIntLinux(const char* pAppName, const char* pKeyName, int nDefault, const char* pFileName)
{
char buf[1024] = { 0 };

if (GetPrivateProfileStringLinux(pAppName, pKeyName, "", buf, 1024, pFileName) <= 0)
return nDefault;

if (strlen(buf) == 0)
return nDefault;

return atoi(buf);
}
44 changes: 44 additions & 0 deletions inifile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN16) || defined(_WIN32) || defined(WIN64)
const bool isLinuxOS = false;
#elif defined(__linux__)
const bool isLinuxOS = true;// linux OS
#define sprintf_s(_Buffer, _Format, ...) sprintf(_Buffer, _Format,__VA_ARGS__)
#define fopen_s(_Stream, _FileName, _Mode) *_Stream = fopen(_FileName,_Mode)
#endif

#define MAX_ARRAY_LEN (1024 * 512) //buffer size


/*
* function is similar to GetPrivateProfileString(win32)
*
* param
* lpAppName section name
* lpKeyName key name
* lpDefault default value
* pReturnedString buffer string
* nSize size of buffer
* lpFileName ini file
* return
* The return value is the number of characters copied to the buffer
* comment
* can read [\r\n](line feed code) and [\n]
*/
int GetPrivateProfileStringLinux(const char* pAppName, const char* pKeyName, const char* lpDefault, char* pReturnedString, unsigned long nSize, const char* pFileName);
/*
* function is similar to GetPrivateProfileInt(win32)
*
* param
* lpAppName section name
* lpKeyName key name
* nDefault default value
* lpFileName ini file
* return
* number(int) read from ini-file
*
*/
int GetPrivateProfileIntLinux(const char* pAppName, const char* pKeyName, int nDefault, const char* pFileName);
7 changes: 7 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main(int argc,char* args[])
{
printf("Hello word\n");
return 0;
}
7 changes: 7 additions & 0 deletions upd/udp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main(int argc,char* args[])
{
printf("upd\n");
return 0;
}
6 changes: 6 additions & 0 deletions upd/udp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __UDP_H__
#define __UDP_H__

const int isUDP = 1;

#endif