about summary refs log tree commit diff stats
path: root/numericx.c
diff options
context:
space:
mode:
Diffstat (limited to 'numericx.c')
-rw-r--r--numericx.c179
1 files changed, 139 insertions, 40 deletions
diff --git a/numericx.c b/numericx.c
index 344e19d..3ac74c4 100644
--- a/numericx.c
+++ b/numericx.c
@@ -1,3 +1,6 @@
+/** @file numericx.c
+ * Source code of the number translator command-line interface.
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -9,40 +12,71 @@
 
 /* ||COMPILATION FLAGS|| */
 
-/*
- * Show debug message of step by step
- * incrementation of the number
+/**
+ * @name Compilation Flags
+ *
+ * These are the valid compilation flags for the definition of numerical systems.
+ * Use them to make the program show more output, or
+ * to set the proprieties of the FROM and the TO numerical system.
+ *
+ * @{
+ */
+
+/**
+ * @param bool
+ *
+ * Show debug message of the step by step incrementation of the number.
  */
 #ifndef DEBUG
 #define DEBUG false
 #endif
 
-/*
- * Configuration of the corresponding numeral system
- * to have the units place of the end (on the right)
+/**
+ * @param bool
+ *
+ * Configuration of the resulting numeral system
+ * to have the units place on the end of the writing direction (on the right).
  */
 #ifndef TO_UNITS_ON_THE_END
 #define TO_UNITS_ON_THE_END false
 #endif
 
+/**
+ * @param bool
+ *
+ * Configuration of the numeral system of the number input
+ * to have the units place on the end of the writing direction (on the right).
+ */
 #ifndef FROM_UNITS_ON_THE_END
 #define FROM_UNITS_ON_THE_END false
 #endif
 
-/*
- * Configuration of the corresponding numeral system
+/**
+ * @param bool
+ *
+ * Configuration of the resulting numeral system
  * to start counting on the second number, being the
- * first number void
+ * first number void.
  */
 #ifndef TO_FIRST_NUMBER_VOID
 #define TO_FIRST_NUMBER_VOID false
 #endif
 
+/**
+ * @param bool
+ *
+ * Configuration of the numeral system of the number input
+ * to start counting on the second number, being the
+ * first number void.
+ */
 #ifndef FROM_FIRST_NUMBER_VOID
 #define FROM_FIRST_NUMBER_VOID false
 #endif
 
-/* Configuration of the corresponding numeral system
+/**
+ * @param bool
+ *
+ * Configuration of the resulting numeral system
  * to have the first number as an infinite number,
  * for example, if the first number is 'A', then
  * A == AA == AAA == AAAA ...
@@ -51,56 +85,81 @@
 #define TO_INFINITE_BASE false
 #endif
 
+/**
+ * @param bool
+ *
+ * Configuration of the numeral system of the number input
+ * to have the first number as an infinite number,
+ * for example, if the first number is 'A', then
+ * A == AA == AAA == AAAA ...
+ */
 #ifndef FROM_INFINITE_BASE
 #define FROM_INFINITE_BASE false
 #endif
 
+/** @} */
 
 /* ||DATA STRUCTURE|| */
 
+/**
+ * @brief Numeral structure
+ *
+ * This struct is in use to apply our operations on the number.
+ * The number are converted to this struct, the operations are applied,
+ * and on the end, the resulting number is converted from this struct.
+ */
 typedef struct NumeralPtr
 {
-	char const* symbol;
-	struct NumeralPtr *next;
-	struct NumeralPtr *previous;
+	char const* symbol; /**< a pointer to the glyph/numeral/symbol of this digit. */
+	struct NumeralPtr *next; /**< a pointer to the next digit */
+	struct NumeralPtr *previous; /**< a pointer to the previous digit */
 } numeral_ptr;
 
 
 /* ||FUNCTIONS|| */
 
-/*
- * Creates new digit for numeral_ptr.
+/**
+ * @brief Create new digit for numeral_ptr.
+ *
  * It needs the last_numeral ('last_numeral') into which will
  * add the new numeral, and also need to know the symbol of the
  * new numeral ('to_first').
  *
- * Return pointer to new numeral_ptr.
- * Returns NULL in case of no memory.
+ * @param last_numeral - last numeral_ptr* into which new numeral_ptr will be added.
+ * @param to_first - symbol of the new digit.
+ *
+ * @return pointer to new numeral_ptr in case of success.
+ * @return NULL in case of no memory.
  */
 numeral_ptr*
 new_digit(numeral_ptr* last_numeral, char const* to_first)
 {
-	numeral_ptr* starting_point = malloc(sizeof(numeral_ptr));
-	if(starting_point == NULL)
+	numeral_ptr* new_numeral = malloc(sizeof(numeral_ptr));
+	if(new_numeral == NULL)
 	{
 		fprintf(stderr, "error: %s: %s!", PROG_NAME, strerror(ENOMEM));
 		return NULL;
 	}
 
-	starting_point->symbol = to_first;
-	starting_point->previous = last_numeral;
-	starting_point->next = NULL;
+	new_numeral->symbol = to_first;
+	new_numeral->previous = last_numeral;
+	new_numeral->next = NULL;
 
-	return starting_point;
+	return new_numeral;
 }
 
-/*
+/**
+ * @brief Initializer of numeral_ptr
+ *
  * Creates a number of the form numeral_ptr that
  * begins with 'case' number of cases, and all cases
  * are set to 'to_first' char.
  *
- * Returns pointer to numeral_ptr.
- * Returns NULL in case of no memory (because depends
+ * @param to_first - the symbol of the cases for the new number.
+ * @param cases - number of cases of the new number.
+ *
+ * @return pointer to numeral_ptr in case of success.
+ * @return NULL in case of no memory ( because depends
  * on new_digit() ).
  */
 numeral_ptr*
@@ -118,12 +177,19 @@ numeral_infinity(char const* to_first, size_t cases)
 	return starting_case;
 }
 
-/* Increments numeral_ptr 'numeral' one unit up.
+/**
+ * @brief Increment numeral_ptr 'numeral' one unit up.
+ *
  * It needs 'num_first' as the first numeral of the numerical
  * system. Also needs 'num_last' as the last numeral of the
  * numerical system.
- * If incrementing, the function adds a new digit/numeral, it
- * will use the 'brand_new_digit' as its numeral/digit.
+ * When incrementing, if the function adds a new digit/numeral, it
+ * will use the 'brand_new_digit' as its new numeral/digit.
+ *
+ * @param numeral - numeral to increment.
+ * @param num_first - number's numeral system first numeral.
+ * @param num_last - number's numeral system last numeral.
+ * @param brand_new_digit - brand new created numeral, if needed by incrementation.
  */
 void
 increment(numeral_ptr* numeral, char* num_first, char* num_last, char* brand_new_digit)
@@ -146,12 +212,18 @@ increment(numeral_ptr* numeral, char* num_first, char* num_last, char* brand_new
 		++(numeral->symbol);
 }
 
-/*
- * Decrements a string 'number' by one unit.
+/**
+ * @brief Decrement a string 'number' by one unit.
+ *
  * It needs to know the first numeral ('first_numeral') and also the
  * last numeral ('last_numeral'). It also needs the numeral system in
  * form of a string ('numeral_system') to know which is the numeral
  * before the actual numeral that needs decrementation.
+ *
+ * @param number - the string number to be decremented.
+ * @param first_numeral - number's numeral system first numeral.
+ * @param last_numeral - number's numeral system last numeral.
+ * @param numeral_system - string of the corresponding number's numeral system numeral.
  */
 void
 decrement_number_string(char* number, char* first_numeral, char* last_numeral, char* numeral_system)
@@ -175,10 +247,16 @@ decrement_number_string(char* number, char* first_numeral, char* last_numeral, c
 	}
 }
 
-/*
+/**
+ * @brief Check if numeral_ptr and string are of the same value
+ *
  * Compares if a numeral_ptr ('numeral') matches the string ('number_arg').
  *
- * Return true if matches, false if numeral_ptr doesn't match the string.
+ * @param numeral - numeral_ptr to check.
+ * @param number_arg - string to check.
+ *
+ * @return true if matches.
+ * @return false if doesn't match.
  */
 bool
 is_the_same(numeral_ptr* numeral, char* number_arg)
@@ -198,8 +276,12 @@ is_the_same(numeral_ptr* numeral, char* number_arg)
 	return (*number_arg == '\0') ? true : false;
 }
 
-/*
+/**
+ * @brief Print numeral
+ *
  * Prints to standard output numeral_ptr ('numeral').
+ *
+ * @param numeral - numeral_ptr to print.
  */
 void
 print_numeral(numeral_ptr* numeral)
@@ -225,8 +307,10 @@ print_numeral(numeral_ptr* numeral)
 	}
 }
 
-/*
- * Reverse a string.
+/**
+ * @brief Reverse a string.
+ *
+ * @param string - string to be reversed.
  */
 void
 reverse_string(char* string)
@@ -242,13 +326,19 @@ reverse_string(char* string)
 	}
 }
 
-/*
+/**
+ * @brief Does string belongs to numeral system?
+ *
  * Check if string 'number' belongs to the numerical
  * system ('numeral_system'), which is also a string.
  * Belonging mean all the symbols of 'number' are included
  * in 'numeral_system'.
  *
- * Return true if it belongs, false otherwise.
+ * @param numeral_system - numeral system string to check against.
+ * @param number - number to see if belongs.
+ *
+ * @return true if it belongs.
+ * @return false if it doesn't belong.
  */
 bool
 is_valid_number(char* numeral_system, char *number)
@@ -267,8 +357,12 @@ is_valid_number(char* numeral_system, char *number)
 	return true;
 }
 
-/*
- * Free up numeral_ptr ('numeral').
+/**
+ * @brief Free numeral memory.
+ *
+ * Free up numeral_ptr ('numeral') linked chain.
+ *
+ * @param numeral - numeral_ptr to free.
  */
 void
 free_numeral(numeral_ptr* numeral)
@@ -286,6 +380,11 @@ free_numeral(numeral_ptr* numeral)
 
 /* ||MAIN FUNCTION|| */
 
+/**
+ * @brief Translate number.
+ *
+ * Main function that does the translation of the number.
+ */
 int
 main(int argc, char* argv[])
 {