Bob Mottram 3 years ago
parent
commit
b39b6dc6d2
6 changed files with 292 additions and 56 deletions
  1. 132 5
      src/database.c
  2. 18 1
      src/edit.c
  3. 1 1
      src/edit.h
  4. 7 1
      src/help.c
  5. 132 46
      src/import.c
  6. 2 2
      src/import.h

+ 132 - 5
src/database.c

@@ -555,6 +555,38 @@ int database_save_transaction(
     return 1;
 }
 
+/**
+ * @brief
+ * @param account
+ * @param current_datetime
+ * @param adjustment_type
+ * @param transaction_identifier
+ * @param quantity
+ * @param description
+ * @param spend
+ * @param receive
+ * @param date
+ * @param timestr
+ * @param recur
+ * @param currency
+ * @param status
+ * @param invoice_number
+ * @param sales_number
+ * @param purchase_number
+ * @param works_number
+ * @param job_number
+ * @param serial_number
+ * @param part_number
+ * @param tracking_number
+ * @param progress
+ * @param latitude
+ * @param longitude
+ * @param altitude
+ * @param supplier
+ * @param customer
+ * @param VATrate
+ * @returns 1 on success
+ */
 int database_save_adjustment(
     char account[],
     char current_datetime[],
@@ -683,6 +715,15 @@ int database_save_adjustment(
     return 1;
 }
 
+/**
+ * @brief Return the balance for the given account
+ * @param account Name of the account
+ * @param currency Currency to use
+ * @param total_spent Returned total spent
+ * @param total_received Returned total received
+ * @param balance Returned balance
+ * @returns 1 on success
+ */
 int get_balance(
     char account[],
     char ** currency, char ** total_spent,
@@ -794,6 +835,10 @@ int get_balance(
     return 1;
 }
 
+/**
+ * @brief Clears transaction numbers
+ * @returns 1 on success
+ */
 int clear_transaction_numbers()
 {
     FILE * fp;
@@ -811,6 +856,11 @@ int clear_transaction_numbers()
     return 1;
 }
 
+/**
+ * @brief Saves a transaction number
+ * @param transaction_number Transaction number
+ * @returns 1 on success
+ */
 int save_transaction_number(char transaction_number[])
 {
     FILE * fp;
@@ -830,6 +880,12 @@ int save_transaction_number(char transaction_number[])
     return 1;
 }
 
+/**
+ * @brief Returns the transaction number for a record number
+ * @param record_number Record number
+ * @param transaction_number Returned transaction number
+ * @return 1 if the record exists
+ */
 int get_transaction_number_from_record_number(int record_number,
                                               char transaction_number[])
 {
@@ -849,7 +905,7 @@ int get_transaction_number_from_record_number(int record_number,
     fp = fopen(filename, "r");
     if (fp != 0L) {
         while (!feof(fp)) {
-            if (fgets(str,64,fp) != NULL) {
+            if (fgets(str, STRING_BLOCK-1, fp) != NULL) {
                 if (rec == record_number) {
                     sprintf(transaction_number, "%s", str);
                     /* remove carriage return */
@@ -865,6 +921,33 @@ int get_transaction_number_from_record_number(int record_number,
     return found;
 }
 
+/**
+ * @brief Edits a record
+ * @param account
+ * @param record_number
+ * @param prev_date
+ * @param prev_timestr
+ * @param prev_status
+ * @param prev_description
+ * @param prev_currency
+ * @param prev_VATrate
+ * @param float prev_progress
+ * @param prev_supplier
+ * @param prev_receive
+ * @param prev_spend
+ * @param date
+ * @param timestr
+ * @param status
+ * @param description
+ * @param currency
+ * @param VATrate
+ * @param progress
+ * @param supplier
+ * @param receive
+ * @param spend
+ * @param date_format
+ * @return 1 on success
+ */
 int database_edit_record(
     char account[],
     int record_number,
@@ -989,7 +1072,12 @@ int database_edit_record(
     return 1;
 }
 
-
+/**
+ * @brief Delete a given record number
+ * @param account The account to delete from
+ * @param record number The record number to delete
+ * @returns 1 on success
+ */
 int database_delete_record(char account[], int record_number)
 {
     int retval,tries,max_tries = 4;
@@ -1105,6 +1193,23 @@ int database_delete_record(char account[], int record_number)
     return 1;
 }
 
+/**
+ * @brief Gets a database record
+ * @param account
+ * @param record_number
+ * @param date
+ * @param timestr
+ * @param transaction_number
+ * @param status
+ * @param description
+ * @param currency
+ * @param VATrate
+ * @param progress
+ * @param supplier
+ * @param receive
+ * @param spend
+ * @returns 1 on success
+ */
 int database_get_record(
     char account[],
     int record_number,
@@ -1237,6 +1342,18 @@ int database_get_record(
 /**
  * @brief A shorter version of transaction save
  * @param account The account name to be saved
+ * @param date
+ * @param timestr
+ * @param date_format
+ * @param status
+ * @param description
+ * @param currency
+ * @param VATrate
+ * @param progress
+ * @param supplier
+ * @param receive
+ * @param spend
+ * @returns 1 on success
  */
 int database_save_short(char account[],
                         char date[], char timestr[],
@@ -1995,7 +2112,17 @@ int transaction_volume(char account[], char currency[], int year,
     return 1;
 }
 
-/* returns total spend and receive values for the given search string */
+/**
+ * @brief returns total spend and receive values for the given search string
+ * @param account
+ * @param search_string
+ * @param month_number
+ * @param year
+ * @param currency
+ * @param total_receive
+ * @param total_spend
+ * @returns 1 on success
+ */
 int get_totals(char account[], char search_string[],
                int month_number, int year,
                char * currency,
@@ -2060,7 +2187,7 @@ int get_totals(char account[], char search_string[],
     while (1) {
         retval = sqlite3_step(stmt);
 
-        if(retval == SQLITE_ROW) {
+        if (retval == SQLITE_ROW) {
 
             for(col = 0; col < cols; col++) {
                 char *val = (char*)sqlite3_column_text(stmt, col);
@@ -2073,7 +2200,7 @@ int get_totals(char account[], char search_string[],
                 }
             }
         }
-        else if(retval == SQLITE_DONE) {
+        else if (retval == SQLITE_DONE) {
             break;
         }
     }

+ 18 - 1
src/edit.c

@@ -1,6 +1,6 @@
 /*
   Fin - a simple personal accounts manager
-  Copyright (C) 2012-2015  Bob Mottram <bob@robotics.uk.to>
+  Copyright (C) 2012-2015,2017  Bob Mottram <bob@freedombone.net>
 
   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
@@ -18,6 +18,23 @@
 
 #include "undo.h"
 
+/**
+ * @brief Edit a record
+ * @param account
+ * @param record_number
+ * @param date
+ * @param timestr
+ * @param date_format
+ * @param status
+ * @param description
+ * @param currency
+ * @param VATrate
+ * @param progress
+ * @param supplier
+ * @param receive
+ * @param spend
+ * @returns 1 on success
+ */
 int command_edit(char * account,
                  int record_number,
                  char * date, char * timestr,

+ 1 - 1
src/edit.h

@@ -1,6 +1,6 @@
 /*
   Fin - a simple personal accounts manager
-  Copyright (C) 2012-2015  Bob Mottram <bob@robotics.uk.to>
+  Copyright (C) 2012-2015,2017  Bob Mottram <bob@freedombone.net>
 
   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

+ 7 - 1
src/help.c

@@ -1,6 +1,6 @@
 /*
   Fin - a simple personal accounts manager
-  Copyright (C) 2012-2015  Bob Mottram <bob@robotics.uk.to>
+  Copyright (C) 2012-2015,2017  Bob Mottram <bob@freedombone.net>
 
   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
@@ -18,6 +18,9 @@
 
 #include "help.h"
 
+/**
+ * @brief Shows help in English
+ */
 void show_help_english()
 {
     printf("%s","\nFin: The command line personal finances manager\n");
@@ -54,6 +57,9 @@ void show_help_english()
     printf("%s","For more details see the README file.\n\n");
 }
 
+/**
+ * @brief Shows help
+ */
 void show_help()
 {
     char * language = settings_get_language();

+ 132 - 46
src/import.c

@@ -1,6 +1,6 @@
 /*
   Fin - a simple personal accounts manager
-  Copyright (C) 2012-2015  Bob Mottram <bob@robotics.uk.to>
+  Copyright (C) 2012-2015,2017  Bob Mottram <bob@freedombone.net>
 
   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
@@ -31,11 +31,25 @@ enum {
     FIELDS
 };
 
-static void parse_value(char * str, int * fields, int field_number,
-                        char * date, char * timestr,
-                        char * receive, char * spend,
-                        char * status, char * description,
-                        char * currency, char * field_type)
+/**
+ * @brief
+ * @param str
+ * @param fields
+ * @param field_number
+ * @param date
+ * @param timestr
+ * @param receive
+ * @param spend
+ * @param status
+ * @param description
+ * @param currency
+ * @param field_type
+ */
+static void parse_value(char str[], int fields[], int field_number,
+                        char date[], char timestr[],
+                        char receive[], char spend[],
+                        char status[], char description[],
+                        char currency[], char field_type[])
 {
     int i,j;
 
@@ -100,7 +114,7 @@ static void parse_value(char * str, int * fields, int field_number,
     }
 }
 
-static void categorize_string(char * str, int * fields, int field_number)
+static void categorize_string(char str[], int fields[], int field_number)
 {
     remove_eol(str);
     trim(str);
@@ -146,7 +160,7 @@ static void categorize_string(char * str, int * fields, int field_number)
         fields[FIELD_TIME] = field_number;
 }
 
-static void parse_header(char * header, char separator, int * fields)
+static void parse_header(char header[], char separator, int fields[])
 {
     int i,start=0,field_number=0;
     int reading_text=0;
@@ -173,7 +187,7 @@ static void parse_header(char * header, char separator, int * fields)
     categorize_string(str, fields, field_number);
 }
 
-static int valid_field_type(char * field_type)
+static int valid_field_type(char field_type[])
 {
     if (field_type[0] == 0)
         return 1;
@@ -185,10 +199,10 @@ static int valid_field_type(char * field_type)
     return 1;
 }
 
-static int parse_row(char * account, char * line, char separator, int * fields,
-                     char * date, char * timestr,
-                     char * receive, char * spend, char * status,
-                     char * description, char * currency, char * field_type)
+static int parse_row(char account[], char line[], char separator, int fields[],
+                     char date[], char timestr[],
+                     char receive[], char spend[], char status[],
+                     char description[], char currency[], char field_type[])
 {
     int i,start=0,field_number=0;
     int reading_text=0;
@@ -268,8 +282,12 @@ static int parse_row(char * account, char * line, char separator, int * fields,
     return transaction_added;
 }
 
-/* extract data from an xml field */
-static void extract_xml_field(char * line, char * result)
+/**
+ * @brief extract data from an xml field
+ * @param line
+ * @param result
+ */
+static void extract_xml_field(char line[], char result[])
 {
     int i,ctr=0;
 
@@ -291,8 +309,12 @@ static void extract_xml_field(char * line, char * result)
     trim(result);
 }
 
-/* parses a value of the type num/denom into a decimal string */
-static void parse_gnucash_value(char * value, char * result)
+/**
+ * @brief parses a value of the type num/denom into a decimal string
+ * @param value String containing value
+ * @param result Parsed value
+ */
+static void parse_gnucash_value(char value[], char result[])
 {
     int i,state=0,ctr=0,zeroes=0;
     char numerator[128];
@@ -331,8 +353,12 @@ static void parse_gnucash_value(char * value, char * result)
     result[ctr]=0;
 }
 
-/* lists the gnucash accounts which have some transactions */
-static int show_gnucash_accounts(char * filename)
+/**
+ * @brief lists the gnucash accounts which have some transactions
+ * @param filename GNU Cash file
+ * @returns Number of accounts
+ */
+static int show_gnucash_accounts(char filename[])
 {
     FILE * fp;
     char line[STRING_BLOCK];
@@ -403,10 +429,16 @@ static int show_gnucash_accounts(char * filename)
     return no_of_accounts;
 }
 
-/* returns the guid assocuated with the given account name */
-static void get_gnucash_account_guid(char * filename,
-                                     char * gnucash_account_name,
-                                     char * guid,
+/**
+ * @brief returns the guid associated with the given account name
+ * @param filename File to be checked
+ * @param gnucash_account_name GNU Cash account name
+ * @param guid Returned guid
+ * @param assets_account Returns 1 if this is an assets account
+ */
+static void get_gnucash_account_guid(char filename[],
+                                     char gnucash_account_name[],
+                                     char guid[],
                                      int * assets_account)
 {
     FILE * fp;
@@ -468,20 +500,37 @@ static void get_gnucash_account_guid(char * filename,
     }
 }
 
-/* parses a single line of a gnucash xml file */
-static int parse_gnucash_transaction(char * account,
-                                     char * line,
-                                     int * reading_record,
-                                     char * date,
-                                     char * timestr,
-                                     char * receive,
-                                     char * spend,
-                                     char * quantity,
-                                     char * description,
-                                     char * currency,
-                                     int * field_type,
-                                     int * value_found,
-                                     char * gnucash_account_guid,
+/**
+ * @brief parses a single line of a gnucash xml file
+ * @param account
+ * @param line
+ * @param reading_record
+ * @param date
+ * @param timestr
+ * @param receive
+ * @param spend
+ * @param quantity
+ * @param description
+ * @param currency
+ * @param field_type
+ * @param value_found
+ * @param gnucash_account_guid
+ * @param assets_account
+ * @returns Non on success
+ */
+static int parse_gnucash_transaction(char account[],
+                                     char line[],
+                                     int reading_record[],
+                                     char date[],
+                                     char timestr[],
+                                     char receive[],
+                                     char spend[],
+                                     char quantity[],
+                                     char description[],
+                                     char currency[],
+                                     int field_type[],
+                                     int value_found[],
+                                     char gnucash_account_guid[],
                                      int assets_account)
 {
     char result[STRING_BLOCK],datestr[STRING_BLOCK];
@@ -653,7 +702,11 @@ static int parse_gnucash_transaction(char * account,
     return 0;
 }
 
-static void get_gnucash_account_name(char * name)
+/**
+ * @brief Gets the gnucash account name
+ * @param name The returned account name
+ */
+static void get_gnucash_account_name(char name[])
 {
     int i;
 
@@ -672,8 +725,14 @@ static void get_gnucash_account_name(char * name)
     trim(name);
 }
 
-static int command_import_gnucash(char * account,
-                                  char * import_filename)
+/**
+ * @brief Import transactions from gnucash
+ * @param account Name of the account
+ * @param import_filename gnucash file
+ * @returns Number of transactions imported
+ */
+static int command_import_gnucash(char account[],
+                                  char import_filename[])
 {
     FILE * fp;
     char line[STRING_BLOCK];
@@ -764,8 +823,15 @@ static int command_import_gnucash(char * account,
     return transactions_added;
 }
 
-static int command_import_csv(char * account,
-                              char * import_filename,
+/**
+ * @brief Import transactions from a csv file
+ * @param account Name of the account
+ * @param import_filename csv file
+ * @param separator Field separation character
+ * @returns Number of transactions imported
+ */
+static int command_import_csv(char account[],
+                              char import_filename[],
                               char separator)
 {
     FILE * fp;
@@ -804,7 +870,13 @@ static int command_import_csv(char * account,
     return transactions_added;
 }
 
-static int no_of_separators(char separator, char * str)
+/**
+ * @brief Returns the number of field separators within the given string
+ * @param separator Field separation character
+ * @param str String to be analysed
+ * @returns Number of field separators
+ */
+static int no_of_separators(char separator, char str[])
 {
     int i,ctr=0;
 
@@ -815,8 +887,15 @@ static int no_of_separators(char separator, char * str)
     return ctr;
 }
 
-static int command_import_emacs(char * account,
-                                char * import_filename,
+/**
+ * @brief Import transactions from an emacs org file containing a table
+ * @param account Name of the account
+ * @param import_filename The org file containing a table
+ * @param separator Field separation character
+ * @returns Number of transactions imported
+ */
+static int command_import_emacs(char account[],
+                                char import_filename[],
                                 char separator)
 {
     FILE * fp;
@@ -864,7 +943,14 @@ static int command_import_emacs(char * account,
     return transactions_added;
 }
 
-int command_import(char * account, char * import_filename, char separator)
+/**
+ * @brief Import csv data into an account
+ * @param account Name of the account
+ * @param import_filename The csv file to be imported
+ * @param separator The character used for field separation
+ * @returns Number of transactions imported
+ */
+int command_import(char account[], char import_filename[], char separator)
 {
     if ((strstr(import_filename,".csv") != 0) ||
         (strstr(import_filename,".CSV") != 0))

+ 2 - 2
src/import.h

@@ -1,6 +1,6 @@
 /*
     Fin - a simple personal accounts manager
-    Copyright (C) 2012-2015  Bob Mottram <bob@robotics.uk.to>
+    Copyright (C) 2012-2015,2017  Bob Mottram <bob@freedombone.net>
 
     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
@@ -22,6 +22,6 @@
 #include "parse.h"
 #include "database.h"
 
-int command_import(char * account, char * import_filename, char separator);
+int command_import(char account[], char import_filename[], char separator);
 
 #endif