First version of automatic ID and COUNT columns, to discuss (for now,

columns created when NUC_SEQ views are closed if the columns don't
already exist)
This commit is contained in:
Celine Mercier
2017-07-17 17:31:09 +02:00
parent 1e57bfacb4
commit c88df2e12c
4 changed files with 200 additions and 5 deletions

View File

@ -18,6 +18,7 @@
#include <dirent.h>
#include <unistd.h>
#include <time.h>
#include <math.h>
#include "utils.h"
#include "obidebug.h"
@ -35,6 +36,43 @@
**********************************************************************/
int digit_count(index_t i)
{
int n_digits;
if (i == 0)
n_digits = 1;
else
n_digits = floor(log10(llabs(i))) + 1;
return n_digits;
}
char* build_word_with_idx(const char* prefix, index_t idx)
{
char* word;
int n_digits;
n_digits = digit_count(idx);
word = (char*) malloc((strlen(prefix) + 1+ n_digits + 1)*sizeof(char));
if (word == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for a character string");
return NULL;
}
if (sprintf(word, "%s_%lld", prefix, idx) < 0)
{
obi_set_errno(OBI_UTILS_ERROR);
obidebug(1, "\nProblem building a word from a prefix and an index");
return NULL;
}
return word;
}
int count_dir(char* dir_path)
{
struct dirent* dp;