diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f72c0c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,264 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.o +*.so +*morse-encode-and-decode + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Bb]uild/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +.vs/ +.vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f58ae2d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.10) + +project(morse-encode-and-decode) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_FLAGS, "-Wall") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +if(CMAKE_CONFIGURATION_TYPES) + set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "My multi config types" FORCE) +elseif(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RELEASE) +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) +file(GLOB SRCS "src/*.c" "src/*.h") +add_executable(${PROJECT_NAME} ${SRCS}) + +if(UNIX) + set(CMAKE_INSTALL_PREFIX /usr/local) + install(TARGETS ${PROJECT_NAME} DESTINATION bin) +elseif(WIN32) + set(CMAKE_INSTALL_PREFIX "C:/Program Files (x86)/") + install(TARGETS ${PROJECT_NAME} DESTINATION bin) +endif() diff --git a/Makefile b/Makefile index f04cf96..20b57b3 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,18 @@ +cc = gcc +prom = morse-encode-and-decode +deps = $(shell find ./src -name "*.h") +src = $(shell find ./src -name "*.c") +obj = $(src:%.c=%.o) +$(prom): $(obj) + $(cc) -o $(prom) $(obj) -CC = cc - -CFLAGS = -Wall -g - -INCLUDES = - -LFLAGS = - -LIBS = -lm - -#define the C source files -SRCS = main.c morse.c - -#define the C object files -OBJS = $(SRCS:.c=.o) - -#define the executable fiel -MAIN = morsetest - -.PHONY: depend clean - -all: $(MAIN) - @echo the program of \" $(MAIN) \" has been compiled - -$(MAIN): $(OBJS) - $(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS) - -# -.c.o: - $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ +%.o: %.c $(deps) + $(cc) -Wall -g -fPIC -shared -o $@ -c $< clean: - $(RM) *.o *~ $(MAIN) + rm -rf $(obj) $(prom) -depend: $(SRCS) - makedepend $(INCLUDES) $^ +install: + cp $(prom) /usr/local/bin -# DO NOT DELETE THIS LINE -- make depend needs it diff --git a/README.md b/README.md index 3eed175..5cd892a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ -# morse_encode +# morse-encode-and-decode + +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4781e30bba254e4da7ec8373234718d9)](https://app.codacy.com/gh/Joker2770/morse-encode-and-decode?utm_source=github.com&utm_medium=referral&utm_content=Joker2770/morse-encode-and-decode&utm_campaign=Badge_Grade_Settings) + morse encode and decode + +## Build +Required: +* make +* gcc + +Step: +~~~ +git clone https://github.com/Joker2770/morse-encode-and-decode.git +cd morse-encode-and-decode +make +./morse-encode-and-decode +sudo make install +morse-encode-and-decode +~~~ + +## Usage + +**morse-encode-and-decode -l**
+**morse-encode-and-decode {-e|-d} {\}**
+ +~~~ + + --list (-l) List morse code table. + + --encode (-e) Encode string. e.g.: morse-encode-and-decode -e "Hello world!" + + --decode (-d) Decode Morse code. e.g.: morse-encode-and-decode -d ".- -... -.-. " + +~~~ \ No newline at end of file diff --git a/main.c b/main.c deleted file mode 100644 index be0b98c..0000000 --- a/main.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include -#include - -#include "morse.h" - -#define BUF_LEN 300 - - -int main() { - - 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); - - //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 NORMAL STRING - MorseString2String(mor, str, BUF_LEN); - printf("\nget decode string:\n%s\n", str); - - return 0; -} - diff --git a/morse.h b/morse.h deleted file mode 100644 index 997b4f7..0000000 --- a/morse.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef MORSE_H_ -#define MORSE_H_ - - -typedef int bool; -#define false 0 -#define true 1 - -/* - * FAKE_SPACE IS MARING FOR A SPACE - */ -#define FAKE_SPACE '/' - -/* - * THE CHARACTER THAT BETWEEN TWO MORSE STRING - */ -#define SEPARATOR ' ' - - -typedef struct Morse Morse_t; -struct Morse{ - char c[9]; -}; - - - -Morse_t *new_morse(); - -bool str2morse(char m , Morse_t *morse); -bool morse2str(Morse_t *morse, char *ch); - -bool mark2morse(char n, Morse_t *morse); -bool morse2mark(Morse_t *morse, char *n); - -bool num2morse(char n, Morse_t *morse); -bool morse2num(Morse_t *morse, char *n); - -void MorseString2String(char *morse ,char *string, int buf_len); - -void String2MorseString(char *string ,char *morse, int buf_len); - -void str2lowcase(char *str, char *out, int buf_len); - -#endif /* MORSE_H_ */ diff --git a/snap/gui/icon.png b/snap/gui/icon.png new file mode 100644 index 0000000..d520015 Binary files /dev/null and b/snap/gui/icon.png differ diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..bdb22db --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,31 @@ +name: morse-encode-and-decode # you probably want to 'snapcraft register ' +version: '0.7' # just for humans, typically '1.2+git' or '1.3.2' +summary: Encoding or decoding with morse # 79 char long summary +description: | + A simple command-line tool, created by Joker2770< https://github.com/Joker2770/morse-encode-and-decode >. + +# icon: gui/icon.png + +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: morse-encode-and-decode + +parts: + morse-encode-and-decode: + # See 'snapcraft plugins' + plugin: make + source: https://github.com/Joker2770/morse-encode-and-decode.git + source-type: git + source-branch: master + source-depth: 1 + # source: ../ + artifacts: [morse-encode-and-decode] + + # env: + # plugin: dump + # organize: + # ./morse-encode-and-decode: /bin/morse-encode-and-decode + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..d7ba893 --- /dev/null +++ b/src/main.c @@ -0,0 +1,142 @@ +/* + + morse-encode-and-decode + Copyright (C) 2019-2020 Joker2770 + Copyright (C) {years} robert1207 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + +*/ + +#include +#include +#include + +#include "morse.h" + +#define BUF_LEN 512 + + +int main(int argc, char **argv) { + + if(argc < 2 || 0 == strcmp(*(argv+1), "-h") || 0 == strcmp(*(argv+1), "-H") || 0 == strcmp(*(argv+1), "--help")) + { + printf( + "\n--list (-l) List morse code table." + "\n--version (-v) Show current version." + "\n--encode (-e) String to encode. e.g.: morse-encode-and-decode -e \"Hello world!\"" + "\n--decode (-d) String to decode. e.g.: morse-encode-and-decode -d \".- -... -.-. \"" + "\n\n"); + exit(0); + } + + char mor[BUF_LEN] = ""; + char str[BUF_LEN] = ""; + char out[BUF_LEN] = ""; + + if(0 == strcmp(*(argv+1), "-l") || 0 == strcmp(*(argv+1), "-L") || 0 == strcmp(*(argv+1), "--list")) + { + + char *mystr = "abcdefghijklmnopqrstuvwxyz0123456789.:,;?='/!-_\"()$&@"; + memset(out, 0, BUF_LEN); + memset(mor, 0, BUF_LEN); + memset(str, 0, BUF_LEN); + + //TO LOWCASE + str2lowcase(mystr, out, BUF_LEN); + + char szTmpOne[4] = ""; + unsigned int i = 0; + for(i = 0; i < strlen(mystr); i++) + { + memset(mor, 0, BUF_LEN); + memset(szTmpOne, 0, sizeof(szTmpOne)); + sprintf(szTmpOne, "%c", out[i]); + printf("\t%c\t", out[i]); + + //TO MORSE STRING + String2MorseString(szTmpOne , mor, BUF_LEN); + printf("%s\n" , mor); + } + } + else if(0 == strcmp(*(argv+1), "--encode") || 0 == strcmp(*(argv+1), "-e") || 0 == strcmp(*(argv+1), "-E")) + { + 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); + + } + else if(0 == strcmp(*(argv+1), "--decode") || 0 == strcmp(*(argv+1), "-d") || 0 == strcmp(*(argv+1), "-D")) + { + 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); + + } + + if (0 == strcmp(*(argv+1), "--version") || 0 == strcmp(*(argv+1), "-v") || 0 == strcmp(*(argv+1), "-V")) + { + printf("v0.7\n"); + } + + return 0; +} + diff --git a/morse.c b/src/morse.c similarity index 74% rename from morse.c rename to src/morse.c index d94da1d..57945de 100644 --- a/morse.c +++ b/src/morse.c @@ -1,3 +1,56 @@ +/* + + morse-encode-and-decode + Copyright (C) 2019 Joker2770 + Copyright (C) {years} robert1207 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + +*/ + #include "morse.h" #include @@ -204,10 +257,10 @@ void MorseString2String(char *morse ,char *string, int buf_len) { else if (morse[a] == SEPARATOR && morse[a-1] != FAKE_SPACE) {//get one charactor if (true == morse2str(temp, &ch) && b < 5) { string[c++] = ch; - } else if (true == morse2num(temp, &ch)) { - string[c++] = ch; } else if (true == morse2mark(temp, &ch)) { string[c++] = ch; + } else if (true == morse2num(temp, &ch)) { + string[c++] = ch; } else { printf("has morse that not be decoded !\n"); } diff --git a/src/morse.h b/src/morse.h new file mode 100644 index 0000000..5aacd01 --- /dev/null +++ b/src/morse.h @@ -0,0 +1,97 @@ +/* + + morse-encode-and-decode + Copyright (C) 2019 Joker2770 + Copyright (C) {years} robert1207 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + {signature of Ty Coon}, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. + +*/ + +#ifndef MORSE_H_ +#define MORSE_H_ + + +typedef int bool; +#define false 0 +#define true 1 + +/* + * FAKE_SPACE IS MARING FOR A SPACE + */ +#define FAKE_SPACE '/' + +/* + * THE CHARACTER THAT BETWEEN TWO MORSE STRING + */ +#define SEPARATOR ' ' + + +typedef struct Morse Morse_t; +struct Morse{ + char c[9]; +}; + + + +Morse_t *new_morse(); + +bool str2morse(char m , Morse_t *morse); +bool morse2str(Morse_t *morse, char *ch); + +bool mark2morse(char n, Morse_t *morse); +bool morse2mark(Morse_t *morse, char *n); + +bool num2morse(char n, Morse_t *morse); +bool morse2num(Morse_t *morse, char *n); + +void MorseString2String(char *morse ,char *string, int buf_len); + +void String2MorseString(char *string ,char *morse, int buf_len); + +void str2lowcase(char *str, char *out, int buf_len); + +#endif /* MORSE_H_ */