Skip to content

Commit

Permalink
Merge pull request #33 from Leomotors/HotFixes-3.2
Browse files Browse the repository at this point in the history
a p p r o v e
  • Loading branch information
leomotors authored Mar 3, 2021
2 parents e973b9d + a787cf2 commit 1ba4b3d
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 92 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: Never
IndentCaseLabels: false
ColumnLimit: 0
10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"code-runner.executorMap":{
"c": "cd $dir && gcc $fileName -Wall -Wextra -lm -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
"code-runner.executorMap": {
"c": "cd $dir && gcc $fileName -Wall -Wextra -Wsign-conversion -Werror -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wwrite-strings -Wcast-qual -Wunreachable-code -lm -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
"code-runner.ignoreSelection": true,
"files.associations": {
"safeinput.h": "c",
"safeinput_th.h": "c",
"safeinput_jp.h": "c"
}
}
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## Program's Features

### Vector Calculation

* Add Vectors

* Multiply Vector with scalar and vector
Expand All @@ -14,18 +16,40 @@

* Find area of parrallelogram under two vectors

### Extra Feature that help visualizing

* Import Vector Data from and Export to Files

* Set Number Precision (Number of digits after decimal point)

* Support 3 Languages: English, Thai, Japanese
### Very Good Memory Management

There is almost no memory leak in this program from testing so far.

* Tested using valgrind, however, some very small leaks are possible in rare case.

* Only applies on English Version

### Multilingual

* Support 3 Languages: English, Thai and Japanese

__Note__: In Thai and Japanese Version, Import/Export Vector and setting Number Precision is unstable. Please avoid using them.

## How to Run Program

Compile the source code and done!

To use import/export function, VectorSave Folder must be in the same directory.

## Sample Vector Data to start with

I've already put some sample vector data you can play with!

These are generated using ```numpy```.

Note: Use Import Vector Function to import them, but please avoid using them in TH,JP Version as it is unstable.

## Compatibility

Support both Windows and UNIX OS.
Expand All @@ -40,7 +64,7 @@ Note : ```-lm``` (Math Library) must be manually attached when compiling in UNIX

Version used to present to Teacher (Semester 1) : v1.3.0

Current Release : v3.2
Current Release : v3.3

## Credits

Expand Down Expand Up @@ -76,16 +100,22 @@ Note : ```-lm``` (Math Library) must be manually attached when compiling in UNIX

Subject : 「การเขียนโปรแกรม 2 (ง30222)」 Triam Udom Suksa School (2020/2)

* 総制作 : @Leomotors
* 制作監督 : @Leomotors

* Helper・Reviewer : @Teproanyx

* Honorable Mention : Stack Overflow

* Honor Helper : Stack Overflow
### Special Thanks

* Reviewer・Tester : @Teproanyx
This Project uses Safe Input Module by @Teproanyx

## Program Version History

### Version 3 (Latest Version)

**2021-03-03** Present Ready Update (3.3): Fixed many bugs. Program should be stable now

**2021-03-01** Release 3.2: Seperate File (SafeInput.h) and Fatal Bug Fixes

**2021-02-24** February Improvement Update (3.1): Upgrade to Double, Fix Mem Leak
Expand Down
13 changes: 9 additions & 4 deletions SafeInput.h → SafeInput/SafeInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* * Customed for this Vector Calculator: @Leomotors
*/

#ifndef TEPROANYX_SAFE_INPUT
#define TEPROANYX_SAFE_INPUT

#include <ctype.h>
#include <errno.h>
#include <float.h>
Expand Down Expand Up @@ -92,7 +95,7 @@ char *getString(const char *prompt)
{
size_t size = INITIAL_BUFFER;
printf("%s", prompt);
char *buffer = (char *)malloc((size + 1) * sizeof(*buffer));
char *buffer = malloc((size + 1) * sizeof(*buffer));
memoryError(buffer);
if (fgets(buffer, size + 1, stdin) == NULL)
{
Expand All @@ -102,7 +105,7 @@ char *getString(const char *prompt)
}
while (buffer[strlen(buffer) - 1] != '\n')
{
char *subBuffer = (char *)malloc((size + 1) * sizeof(*subBuffer));
char *subBuffer = malloc((size + 1) * sizeof(*subBuffer));
memoryError(subBuffer);

if (fgets(subBuffer, size + 1, stdin) == NULL)
Expand All @@ -114,14 +117,14 @@ char *getString(const char *prompt)
}

size *= 2;
buffer = (char *)realloc(buffer, size + 1);
buffer = realloc(buffer, size + 1);
memoryError(buffer);

strncat(buffer, subBuffer, size / 2);
free(subBuffer);
}
buffer[strlen(buffer) - 1] = '\0';
buffer = (char *)realloc(buffer, strlen(buffer) + 1);
buffer = realloc(buffer, strlen(buffer) + 1);
memoryError(buffer);
return buffer;
}
Expand All @@ -134,3 +137,5 @@ void memoryError(const void *pointer)
exit(EXIT_FAILURE);
}
}

#endif
33 changes: 20 additions & 13 deletions SafeInput-wchar.h → SafeInput/SafeInput_JP.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/**
* * Safe Input Module wchar_t as prompt version
* * Safe Input Module Japanese Version
* ! Translation might not be 100% correct. Author is just at N5.
* ! 翻訳が全部正しくない可能性があります。 作者はただN5です。
* * Original Work: @Teproanyx
* * Customed for this Vector Calculator: @Leomotors
*/

#ifndef TEPROANYX_SAFE_INPUT
#define TEPROANYX_SAFE_INPUT

#include <ctype.h>
#include <errno.h>
#include <float.h>
Expand All @@ -30,7 +35,7 @@ long getLong(const wchar_t *prompt)
if (buffer[0] == '\0')
{
free(buffer);
printf("Input error, please try again!\n");
wprintf(L"入力エラー もう一度やり直してください。\n");
return getLong(prompt);
}

Expand All @@ -42,7 +47,7 @@ long getLong(const wchar_t *prompt)
{
free(buffer);
fprintf(stderr, "Value conversion error\n");
printf("Input error, please try again!\n");
wprintf(L"入力エラー もう一度やり直してください。\n");
return getLong(prompt);
}

Expand All @@ -56,7 +61,7 @@ int getInt(const wchar_t *prompt)
long n = getLong(prompt);
if (n > INT_MAX || n < INT_MIN)
{
printf("Input error, please try again!\n");
wprintf(L"入力エラー もう一度やり直してください。\n");
return getInt(prompt);
}
return (int)n;
Expand All @@ -68,7 +73,7 @@ double getDouble(const wchar_t *prompt)
if (buffer[0] == '\0')
{
free(buffer);
printf("Input error, please try again!\n");
wprintf(L"入力エラー もう一度やり直してください。\n");
return getLong(prompt);
}

Expand All @@ -80,7 +85,7 @@ double getDouble(const wchar_t *prompt)
{
free(buffer);
fprintf(stderr, "Value conversion error\n");
printf("Input error, please try again!\n");
wprintf(L"入力エラー もう一度やり直してください。\n");
return getDouble(prompt);
}

Expand All @@ -93,36 +98,36 @@ char *getString(const wchar_t *prompt)
{
size_t size = INITIAL_BUFFER;
wprintf(L"%s", prompt);
char *buffer = (char *)malloc((size + 1) * sizeof(*buffer));
char *buffer = malloc((size + 1) * sizeof(*buffer));
memoryError(buffer);
if (fgets(buffer, size + 1, stdin) == NULL)
{
free(buffer);
printf("Error, try again!\n");
wprintf(L"エラー、もう一度やり直してください。\n");
return getString(prompt);
}
while (buffer[strlen(buffer) - 1] != '\n')
{
char *subBuffer = (char *)malloc((size + 1) * sizeof(*subBuffer));
char *subBuffer = malloc((size + 1) * sizeof(*subBuffer));
memoryError(subBuffer);

if (fgets(subBuffer, size + 1, stdin) == NULL)
{
free(buffer);
free(subBuffer);
printf("Read Error(WTF HOW), try again MTFKER!\n");
wprintf(L"Read Error(WTF HOW), try again MTFKER!\n");
return getString(prompt);
}

size *= 2;
buffer = (char *)realloc(buffer, size + 1);
buffer = realloc(buffer, size + 1);
memoryError(buffer);

strncat(buffer, subBuffer, size / 2);
free(subBuffer);
}
buffer[strlen(buffer) - 1] = '\0';
buffer = (char *)realloc(buffer, strlen(buffer) + 1);
buffer = realloc(buffer, strlen(buffer) + 1);
memoryError(buffer);
return buffer;
}
Expand All @@ -131,7 +136,9 @@ void memoryError(const void *pointer)
{
if (pointer == NULL)
{
printf("Not enough RAM. Terminating program...\n");
wprintf(L"RAMは十分ではありません プログラムを終了しています...\n");
exit(EXIT_FAILURE);
}
}

#endif
Loading

0 comments on commit 1ba4b3d

Please sign in to comment.