From 5285b9e22faaac806131bd91ffe9cc8cb85a4327 Mon Sep 17 00:00:00 2001 From: joker2770 <1214220480@qq.com> Date: Mon, 12 Aug 2019 10:56:41 +0800 Subject: [PATCH] add snap build --- SnapBuild/snap/snapcraft.yaml | 17 ++++++++ src/test.c | 75 ++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 SnapBuild/snap/snapcraft.yaml diff --git a/SnapBuild/snap/snapcraft.yaml b/SnapBuild/snap/snapcraft.yaml new file mode 100644 index 0000000..4a1fe11 --- /dev/null +++ b/SnapBuild/snap/snapcraft.yaml @@ -0,0 +1,17 @@ +name: morse-encode-and-decode # you probably want to 'snapcraft register ' +version: '0.2' # just for humans, typically '1.2+git' or '1.3.2' +summary: Coding or decoding with morse # 79 char long summary +description: | + A simple command-line tool, create by Joker2770. + +grade: stable # must be 'stable' to release into candidate/stable channels +confinement: strict # use 'strict' once you have the right plugs and slots + +apps: + morse-encode-and-decode: + command: bin/morse-encode-and-decode + +parts: + morse-encode-and-decode: + # See 'snapcraft plugins' + plugin: dump diff --git a/src/test.c b/src/test.c index ebc6306..6a7f7dd 100644 --- a/src/test.c +++ b/src/test.c @@ -60,30 +60,77 @@ Public License instead of this License. #define BUF_LEN 300 -int main() { +int main(int argc, char **argv) { + + if(argc < 2) + { + printf( + "\n--list (-l) List command." + "\n--encode (-e) Encode string. e.g, MorseCodeTest -e \"Hello world!\"" + "\n--decode (-d) Decode Morse code. e.g, MorseCodeTest -d \".- -... -.-. \"" + "\n\n"); + exit(0); + } - char *mystr = "abcdefghijklmnopqrstuvwxyz0123456789.:,;?='/!-_\"()$&@"; char mor[BUF_LEN]; char str[BUF_LEN]; char out[BUF_LEN]; - memset(out, 0, BUF_LEN); - memset(mor, 0, BUF_LEN); - memset(str, 0, BUF_LEN); - printf("base string:\n%s\n", mystr); + if(strcmp(*(argv+1), "-l") == 0 || strcmp(*(argv+1), "--list") == 0) + { - //TO LOWCASE - str2lowcase(mystr, out, BUF_LEN); + char *mystr = "abcdefghijklmnopqrstuvwxyz0123456789.:,;?='/!-_\"()$&@"; + memset(out, 0, BUF_LEN); + memset(mor, 0, BUF_LEN); + memset(str, 0, BUF_LEN); + + printf("base string:\n%s\n", mystr); + + //TO LOWCASE + str2lowcase(mystr, out, BUF_LEN); - //TO MORSE STRING - String2MorseString(out , mor, BUF_LEN); - printf("\nget morse code string:\n%s\n" , mor); + //TO MORSE STRING + String2MorseString(out , mor, BUF_LEN); + printf("\nget morse code string:\n%s\n" , mor); - //TO NORMAL STRING - MorseString2String(mor, str, BUF_LEN); - printf("\nget decode string:\n%s\n", str); + //TO NORMAL STRING + MorseString2String(mor, str, BUF_LEN); + printf("\nget decode string:\n%s\n", str); + } + if(strcmp(*(argv+1), "--encode") == 0 || strcmp(*(argv+1), "-e") == 0) + { + memset(out, 0, BUF_LEN); + memset(mor, 0, BUF_LEN); + memset(str, 0, BUF_LEN); + + printf("base string:\n%s\n", *(argv+2)); + + //TO LOWCASE + str2lowcase(*(argv+2), out, BUF_LEN); + + //TO MORSE STRING + String2MorseString(out , mor, BUF_LEN); + printf("\nget morse code string:\n%s\n" , mor); + + } + + if(strcmp(*(argv+1), "--decode") == 0 || strcmp(*(argv+1), "-d") == 0) + { + memset(out, 0, BUF_LEN); + memset(mor, 0, BUF_LEN); + memset(str, 0, BUF_LEN); + + printf("base string:\n%s\n", *(argv+2)); + + //TO NORMAL STRING + MorseString2String(*(argv+2), str, BUF_LEN); + printf("\nget decode string:\n%s\n", str); + + } + + return 0; }