Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
guyewhite committed Nov 22, 2022
0 parents commit 61bc67d
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## v1 (20 November 2022)
- Initial release.
9 changes: 9 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2022 G. Elvin White

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]
[![LinkedIn][linkedin-shield]][linkedin-url]

## About The Project

[![Product Name Screen Shot][product-screenshot]]

CSVto3Dstrings is a useful tool to convert any CSV file into a 3-d array of strings in C. I created it after amassing a fairly large spreadsheet of musical scale and note values and wanted to convert those for use in a C program. This tool could be useful for anyone needing to keep track of various attributes within such a 3d array.

### Built With

* [![Python][Python.org]][Python-url]
* [![Clang][Clang]][Clang-url]

### Installation

1. Download this repo to your local drive.
2. Open a terminal.
3. Navigate in your terminal to the folder containing this repo.

## Usage

1. Move your CSV files to the same folder as `csvto3dstrings.py`.
2. In the terminal, execute with the following usage: `python csvto3dstrings.py INPUTFILE OUTPUTFILE STRUCTURENAME`. For example, you might execute `python csvto3dstrings.py scales.csv scales.h myScales`. Notice that `scales.csv` in the inputfile, `scales.h` is the output file, and the name of the 3-d array is `myScales`.
3. For testing purposes, the above referenced input file is included in the repo for testing.

<!-- CONTRIBUTING -->
## Contributing

Your contributions to this project are very much appreciated. If you would like to help make this project better, fork to repo and create a pull request. Alternatively, you can open an issue with the tag "request." Please star this project!

1. Fork the Project and make a branch with your feature (`git checkout -b feature/myFeature`).
3. Commit your Changes (`git commit -m 'Added myFeature'`).
4. Push to the Branch (`git push origin feature/myFeature`).
5. Open a Pull Request.

## License

Distributed under the MIT License. See `LICENSE.txt` for more information.

## Contact

Pending.

<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
[contributors-shield]: https://img.shields.io/github/contributors/github_username/repo_name.svg?style=for-the-badge
[contributors-url]: https://github.com/github_username/repo_name/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/github_username/repo_name.svg?style=for-the-badge
[forks-url]: https://github.com/github_username/repo_name/network/members
[stars-shield]: https://img.shields.io/github/stars/github_username/repo_name.svg?style=for-the-badge
[stars-url]: https://github.com/github_username/repo_name/stargazers
[issues-shield]: https://img.shields.io/github/issues/github_username/repo_name.svg?style=for-the-badge
[issues-url]: https://github.com/github_username/repo_name/issues
[license-shield]: https://img.shields.io/github/license/github_username/repo_name.svg?style=for-the-badge
[license-url]: https://github.com/github_username/repo_name/blob/master/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/linkedin_username
[product-screenshot]: images/screenshot.png
[Next.js]: https://img.shields.io/badge/next.js-000000?style=for-the-badge&logo=nextdotjs&logoColor=white
[Next-url]: https://nextjs.org/
[React.js]: https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB
[React-url]: https://reactjs.org/
[Vue.js]: https://img.shields.io/badge/Vue.js-35495E?style=for-the-badge&logo=vuedotjs&logoColor=4FC08D
[Vue-url]: https://vuejs.org/
[Angular.io]: https://img.shields.io/badge/Angular-DD0031?style=for-the-badge&logo=angular&logoColor=white
[Angular-url]: https://angular.io/
[Svelte.dev]: https://img.shields.io/badge/Svelte-4A4A55?style=for-the-badge&logo=svelte&logoColor=FF3E00
[Svelte-url]: https://svelte.dev/
[Laravel.com]: https://img.shields.io/badge/Laravel-FF2D20?style=for-the-badge&logo=laravel&logoColor=white
[Laravel-url]: https://laravel.com
[Bootstrap.com]: https://img.shields.io/badge/Bootstrap-563D7C?style=for-the-badge&logo=bootstrap&logoColor=white
[Bootstrap-url]: https://getbootstrap.com
[JQuery.com]: https://img.shields.io/badge/jQuery-0769AD?style=for-the-badge&logo=jquery&logoColor=white
[JQuery-url]: https://jquery.com
[Python.org]: https://img.shields.io/badge/python-version?style=for-the-badge&logo=python&logoColor=FFFFFF
[Python-url]: https://python.org
[Clang]: https://img.shields.io/badge/Clang-version?style=for-the-badge&logo=C&logoColor=FFFFFF
[Clang-url]: https://clang.llvm.org/
100 changes: 100 additions & 0 deletions csvto3dstrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# csvto3dstrings.py
# CSV to 3D-Array of Strings in C, v1
#
# G. Elvin White
# 20 November 2022
#
# Usage: python csvto3dstrings.py INPUTFILE OUTPUTFILE STRUCTURENAME
# Example: python csvto3dstrings.py scales.csv scales.h myScales
#

import csv
import sys

def main():
# Verify file present
if len(sys.argv) != 4:
print("Usage: python csvto3dstrings.py INPUTFILE OUTPUTFILE STRUCTURENAME")
exit()

inputfile = sys.argv[1]
outputfile = sys.argv[2]
structureName = sys.argv[3]

# open csv
with open(inputfile, "r") as inFile:
csvreader = csv.reader(inFile)

# create the C header file
with open(outputfile, "w") as outFile:

# discover number of columns and skip first line
columns = len(next(csvreader))

#discover number of rows
rows = sum(1 for row in csvreader)

# find the largest item in the cells
inFile.seek(0)
next(csvreader)
itemSize = 0
for row in csvreader:
for item in row:
if len(item) > itemSize:
itemSize = len(item)
itemSize = itemSize + 1

# Write first row of outfile
line = "char " + structureName + "[" + str(rows) + "][" + str(columns) + "][" + str(itemSize) + "] = {\n"
outFile.write(line)

# return to top and iterate through each row
inFile.seek(0)
next(csvreader)
currentRow = 0
for row in csvreader:

# write opening of row
line = "\t{"
outFile.write(line)

# for each item in a row
itemCount = 0
for item in row:

#start quote
quote = "\""
outFile.write(quote)

#item
outFile.write(item)

#end quote
quote = "\""
outFile.write(quote)
if itemCount < columns-1:
line = ", "
outFile.write(line)
itemCount = itemCount + 1

# write closing of row
line = "}"
outFile.write(line)

# add comma if not last row
if currentRow != rows:
line = ","
outFile.write(line)

# new line
line = "\n"
outFile.write(line)

currentRow = currentRow + 1

# write the last line
line = "};"
outFile.write(line)

if __name__ == "__main__":
main()
Binary file added images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions scales.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Key,Mode,1,2,3,4,5,6,7
C,Major,C,D,E,F,G,A,B
D,Major,D,E,F#,G,A,B,C#
E,Major,E,F#,G#,A,B,C#,D#
F,Major,F,G,A,Bb,C,D,E
G,Major,G,A,B,C,D,E,F#
A,Major,A,B,C#,D,E,F#,G#
B,Major,B,C#,D,E,F,G#,A#
9 changes: 9 additions & 0 deletions scales.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
char scales[7][9][6] = {
{"C", "Major", "C", "D", "E", "F", "G", "A", "B"},
{"D", "Major", "D", "E", "F#", "G", "A", "B", "C#"},
{"E", "Major", "E", "F#", "G#", "A", "B", "C#", "D#"},
{"F", "Major", "F", "G", "A", "Bb", "C", "D", "E"},
{"G", "Major", "G", "A", "B", "C", "D", "E", "F#"},
{"A", "Major", "A", "B", "C#", "D", "E", "F#", "G#"},
{"B", "Major", "B", "C#", "D", "E", "F", "G#", "A#"},
};

0 comments on commit 61bc67d

Please sign in to comment.