Skip to content

Commit c972722

Browse files
update
1 parent 0e5de19 commit c972722

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
cmake_minimum_required(VERSION 3.9)
2-
project(JunLang VERSION 1.14.11 LANGUAGES CXX)
3-
set(CMAKE_CXX_STANDARD 11)
4-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5-
set(CMAKE_CXX_EXTENSIONS OFF)
2+
project(JunLang)
63
add_executable(JunLang src/main.cpp)

src/init.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Entry function of the program
3+
* By lemonorangeapple
4+
**/
15
#include <iostream>
26
#include <cstdlib>
37
#include <vector>
@@ -10,7 +14,7 @@
1014
using namespace std;
1115
#pragma GCC std("c++11")
1216
// Version of the program
13-
const string _VERSION_ = "v1.14.11";
17+
const string _VERSION_ = "v1.14.12";
1418
// Buffer size
1519
const int _BUFFER_SIZE_ = 1024;
1620
// All identifiers.

src/main.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Entry function of the program
3+
* By lemonorangeapple
4+
**/
15
#include "init.hpp"
26
#include "read.hpp"
37
#include "update.hpp"
@@ -7,12 +11,11 @@ int main(int argc, char* argv[]) {
711
// Output usage.
812
cout << "JunLang " << _VERSION_ << endl;
913
cout << "Usage: " << argv[0] << " [filename]" << endl;
14+
// Check update.
1015
update();
1116
exit(0);
1217
}
1318
// Read file.
1419
read(argv);
15-
// Check update.
16-
update();
1720
return 0;
1821
}

src/update.hpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1+
/**
2+
* Update function
3+
* By lemonorangeapple
4+
**/
15
#include <cstdlib>
26
#include <cstdio>
37
#include <string>
48

9+
// execute external command and store result in result
510
string execute(const char *command) {
6-
char buffer[1024];
7-
char result[1024] = {0};
8-
FILE *ptr;
9-
strcpy(result, command);
10-
if((ptr = popen(result, "r"))) {
11-
while (fgets(buffer, 1024, ptr)) {
12-
strcat(result, buffer);
13-
if (strlen(result) > 1024) {
14-
break;
15-
}
16-
}
17-
pclose(ptr);
18-
ptr = NULL;
19-
}
20-
return result;
11+
char buffer[1024];
12+
char result[1024] = {0};
13+
FILE *ptr;
14+
strcpy(result, command);
15+
if((ptr = popen(result, "r"))) {
16+
while (fgets(buffer, 1024, ptr)) {
17+
strcat(result, buffer);
18+
if (strlen(result) > 1024) {
19+
break;
20+
}
21+
}
22+
pclose(ptr);
23+
ptr = NULL;
24+
}
25+
return result;
2126
}
2227

28+
// update function
2329
void update() {
24-
string result = execute("curl -s https://junlang.imjcj.eu.org/VERSION").substr(41);
25-
if (result != _VERSION_) {
26-
cout << "Warning: Upgrade JunLang: \"https://junlang.imjcj.eu.org\"" << endl;
27-
}
30+
// get version number from https://junlang.imjcj.eu.org/VERSION
31+
string result = execute("curl -s https://junlang.imjcj.eu.org/VERSION").substr(44);
32+
// compare version number with _VERSION_
33+
if (result != _VERSION_ + '\n') {
34+
cout << "Warning: Please update: \"https://junlang.imjcj.eu.org\"" << endl;
35+
}
36+
return;
2837
}

0 commit comments

Comments
 (0)