-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
993 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
imamLL | ||
|
||
version 1.0 5 July 2015 | ||
|
||
- initial release | ||
- basic doubly linked list support | ||
|
||
version 1.1 10 July 2015 | ||
|
||
- extended support for positioning of new elements | ||
- fixing of memory leaking due to payload not being freed in the code | ||
|
||
version 1.2 24 July 2015 | ||
|
||
- refining of function and struct variables types | ||
|
||
version 1.3 27 July 2015 | ||
|
||
- further refine data types |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Copyright (c) 2015 Md Imam Hossain | ||
|
||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
|
||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
|
||
1. The origin of this software must not be misrepresented; you must not | ||
claim that you wrote the original software. If you use this software | ||
in a product, an acknowledgement in the product documentation would be | ||
appreciated but is not required. | ||
2. Altered source versions must be plainly marked as such, and must not be | ||
misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source distribution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Files changed in version 1.1 | ||
|
||
- README | ||
- ChangeLog | ||
- examples/number_list.c | ||
- examples/product_list.c | ||
- examples/student_book.c | ||
- src/imamll.c | ||
- src/imamll.h | ||
- Modified | ||
|
||
Files changed in version 1.2 | ||
|
||
- ChangeLog | ||
- src/imamll.c | ||
- src/imamll.h | ||
- Modified | ||
|
||
Files changed in version 1.3 | ||
|
||
- ChangeLog | ||
- src/imamll.c | ||
- src/imamll.h | ||
- Modified |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
Imam Linear List | ||
|
||
(imamLL) | ||
|
||
Version 1.1 | ||
|
||
-------------------------------------------------------------------------------------- | ||
|
||
This is the Imam Linear List, a simple linked list implementation library | ||
for storing data structures and data lists into the heap memory. | ||
|
||
Please read Intro for a detail description and example. | ||
|
||
There are example programs in the examples directory and also have a look at the imamll.h header file for a better understanding of the library. | ||
|
||
imamLL is written in C, but should work with C++ natively. | ||
|
||
To install imamLL, execute build.sh script in the terminal. | ||
|
||
After installing the library to compile your code using gcc just add -limamll in the compile command, e.g: gcc -Wall -o main main.c -limamll | ||
|
||
This library is distributed under zlib license. Please read License for more information | ||
|
||
Enjoy! | ||
|
||
Md Imam Hossain (emamhd@gmail.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
echo "imamLL library installation" | ||
|
||
./compile.sh | ||
|
||
if [ "$?" -ne 0 ] | ||
then | ||
exit 1 | ||
fi | ||
|
||
sudo ./install.sh | ||
|
||
if [ "$?" -ne 0 ] | ||
then | ||
exit 1 | ||
fi | ||
|
||
./examples.sh | ||
|
||
echo "Done" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
echo "Compiling imamLL library..." | ||
sleep 1 | ||
|
||
cd src | ||
|
||
gcc -c -Wall -Werror -fpic imamll.c | ||
|
||
if [ "$?" -ne 0 ] | ||
then | ||
echo "Error compiling imamll.c" | ||
exit 1 | ||
fi | ||
|
||
gcc -shared -o libimamll.so imamll.o | ||
|
||
if [ "$?" -ne 0 ] | ||
then | ||
echo "Error creating libimamll.so" | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
echo "Compiling examples..." | ||
sleep 1 | ||
|
||
cd examples | ||
|
||
gcc -Wall -o number_list number_list.c -limamll | ||
|
||
if [ "$?" -ne 0 ] | ||
then | ||
echo "Error compiling number_list.c" | ||
fi | ||
|
||
gcc -Wall -o product_list product_list.c -limamll | ||
|
||
if [ "$?" -ne 0 ] | ||
then | ||
echo "Error compiling product_list.c" | ||
fi | ||
|
||
gcc -Wall -o student_book student_book.c -limamll | ||
|
||
if [ "$?" -ne 0 ] | ||
then | ||
echo "Error compiling student_book.c" | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright (c) 2015 Md Imam Hossain | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; you must not | ||
claim that you wrote the original software. If you use this software | ||
in a product, an acknowledgment in the product documentation would be | ||
appreciated but is not required. | ||
2. Altered source versions must be plainly marked as such, and must not be | ||
misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source distribution. | ||
Md. Imam Hossain | ||
emamhd@gmail.com | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <imamll.h> | ||
|
||
struct imamLL *number_list = NULL; | ||
struct imamLL_element *element = NULL; | ||
int number; | ||
|
||
int main (int argc, char** argv) | ||
{ | ||
number_list = imamLL_list_create (); | ||
|
||
if (number_list == NULL) { | ||
printf ("Can not create list\n"); | ||
exit (EXIT_FAILURE); | ||
} | ||
|
||
for (number = 0; number < 10; number++) { | ||
element = imamLL_element_add (number_list, sizeof (number), AT_END); | ||
if (element == NULL) printf ("Error allocating memory for a number\n"); | ||
else memcpy (element->data, &number, sizeof(number)); | ||
} | ||
|
||
printf ("There are %ld numbers in the list\n", number_list->number_of_elements); | ||
printf ("Total memory allocated %ld bytes\n\n", number_list->size); | ||
|
||
imamLL_list_rewind (number_list); | ||
|
||
while (1) { | ||
element = imamLL_element_get_next (number_list); | ||
if (element == NULL) break; | ||
else printf ("%d\n", *((int *)element->data)); | ||
} | ||
|
||
if (imamLL_list_destroy (number_list) == -1) printf ("Can not free memory\n"); | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
Copyright (c) 2015 Md Imam Hossain | ||
This software is provided 'as-is', without any express or implied | ||
warranty. In no event will the authors be held liable for any damages | ||
arising from the use of this software. | ||
Permission is granted to anyone to use this software for any purpose, | ||
including commercial applications, and to alter it and redistribute it | ||
freely, subject to the following restrictions: | ||
1. The origin of this software must not be misrepresented; you must not | ||
claim that you wrote the original software. If you use this software | ||
in a product, an acknowledgment in the product documentation would be | ||
appreciated but is not required. | ||
2. Altered source versions must be plainly marked as such, and must not be | ||
misrepresented as being the original software. | ||
3. This notice may not be removed or altered from any source distribution. | ||
Md. Imam Hossain | ||
emamhd@gmail.com | ||
*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include <imamll.h> | ||
|
||
struct imamLL *product_list = NULL; | ||
struct imamLL_element *element = NULL; | ||
struct imamLL_element *temp = NULL; | ||
|
||
char product[128]; | ||
|
||
int main (int argc, char** argv) | ||
{ | ||
|
||
product_list = imamLL_list_create (); | ||
|
||
if (product_list == NULL) { | ||
printf ("Can not create list\n"); | ||
exit (EXIT_FAILURE); | ||
} | ||
|
||
strcpy (product, "Bearing"); | ||
element = imamLL_element_add (product_list, strlen (product) + 1, AT_END); | ||
if (element == NULL) printf ("Error allocating memory for Bearing element\n"); | ||
strcpy ((char *)element->data, product); | ||
|
||
strcpy (product, "Switch"); | ||
element = imamLL_element_add (product_list, strlen (product) + 1, AT_END); | ||
if (element == NULL) printf ("Error allocating memory for Switch element\n"); | ||
strcpy ((char *)element->data, product); | ||
|
||
strcpy (product, "Nozzle"); | ||
element = imamLL_element_add (product_list, strlen (product) + 1, AT_END); | ||
if (element == NULL) printf ("Error allocating memory for Nozzle element\n"); | ||
strcpy ((char *)element->data, product); | ||
|
||
imamLL_list_rewind (product_list); | ||
while (1) { | ||
element = imamLL_element_get_next (product_list); | ||
if (element == NULL) break; | ||
else printf ("%s\n", (char *)element->data); | ||
} | ||
|
||
printf ("There are %ld elements in the list\n", product_list->number_of_elements); | ||
printf ("Total memory allocated %ld bytes\n", product_list->size); | ||
|
||
strcpy (product, "Nozzle"); | ||
element = imamLL_element_get (product_list, product, strlen (product) + 1); | ||
|
||
if (element == NULL) printf ("Error getting the Nozzle element"); | ||
else { | ||
if (imamLL_element_remove (product_list, element) != 1) printf ("Error removing the Nozzle element\n"); | ||
} | ||
|
||
imamLL_list_rewind (product_list); | ||
while (1) { | ||
element = imamLL_element_get_next (product_list); | ||
if (element == NULL) break; | ||
else printf ("%s\n", (char *)element->data); | ||
} | ||
|
||
printf ("There are %ld elements in the list\n", product_list->number_of_elements); | ||
printf ("Total memory allocated %ld bytes\n", product_list->size); | ||
|
||
if (imamLL_list_destroy (product_list) == -1) printf ("Can not free memory\n"); | ||
|
||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.