diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actionparser.c | 10 | ||||
-rw-r--r-- | src/actionparser.h | 2 | ||||
-rw-r--r-- | src/actions.c | 4 | ||||
-rw-r--r-- | src/ck.c | 2 | ||||
-rw-r--r-- | src/ckerrlog.c | 31 | ||||
-rw-r--r-- | src/ckerrlog.h | 12 | ||||
-rw-r--r-- | src/cklist.c | 20 | ||||
-rw-r--r-- | src/cklist.h | 16 | ||||
-rw-r--r-- | src/ckutil.c | 2 | ||||
-rw-r--r-- | src/confparser.c | 2 | ||||
-rw-r--r-- | src/confparser.h | 1 | ||||
-rw-r--r-- | src/dblayer.c | 12 |
12 files changed, 52 insertions, 62 deletions
diff --git a/src/actionparser.c b/src/actionparser.c index 009ee2a..9954fbc 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -34,10 +34,10 @@ static int optNum; /* holds the list of the opts * as given by the user */ -static char **opts; +static const char **opts; /* points to the current token */ -static char *token; +static const char *token; /* the position to be read */ static int pos = 0; @@ -205,7 +205,7 @@ void determine_action(UserOpt *opt) { UserOpt make_empty_user_opt() { UserOpt opt; - opt.action = -1; + opt.action = CK_WRONG_ACTION; opt.err = PERR_NOERR; opt.confDir = NULL; opt.args = list_make_new(); @@ -252,7 +252,7 @@ int get_config(UserOpt *opt) { pos = pos - 1; token = opts[pos]; } - char * defaultConf = ".ck"; + char defaultConf[STR_S] = ".ck"; char * home = getenv("HOME"); opt->confDir = malloc(strlen(defaultConf) + 1 /* '/' */ + strlen(home) + 1); str_join_dirname_with_basename(opt->confDir, home, defaultConf); @@ -378,7 +378,7 @@ void print_parser_help() { report_help(); } -int parse_action(int argc, char* argv[], UserOpt *opt) { +int parse_action(int argc, const char **argv, UserOpt *opt) { /* make empty user opt */ *opt = make_empty_user_opt(); opts = argv; diff --git a/src/actionparser.h b/src/actionparser.h index 6fa6136..3735ea8 100644 --- a/src/actionparser.h +++ b/src/actionparser.h @@ -67,7 +67,7 @@ struct UserOptions { /* Parse cli args, fill UserOpt struct * and return the result enum */ -extern int parse_action(int argc, char* argv[], UserOpt *opt); +extern int parse_action(int argc, const char **argv, UserOpt *opt); extern CkAction parser_get_action(const char *name, char *actionName); extern void get_possible_action_strings(char *dest, CkAction ckAction); extern void free_user_opt(UserOpt *opt); diff --git a/src/actions.c b/src/actions.c index b887399..48a4066 100644 --- a/src/actions.c +++ b/src/actions.c @@ -230,10 +230,8 @@ int run_LIST(UserOpt *opt, Conf *conf) { return 1; } -FILE *popen(const char *command, const char *mode); -int pclose(FILE *stream); - int run_SEARCH(UserOpt *opt, Conf *conf) { + UNUSED(conf); if (system("which grep > /dev/null") != 0) { return 2; } @@ -36,7 +36,7 @@ ERRLOG(main); -int main(int argc, char *argv[]) { +int main(int argc, const char **argv) { initialize_errlog(argc, argv); UserOpt opt; Conf conf = {.vc_dir = NULL, .scrt_dir = NULL}; diff --git a/src/ckerrlog.c b/src/ckerrlog.c index a023521..cfafb39 100644 --- a/src/ckerrlog.c +++ b/src/ckerrlog.c @@ -31,7 +31,7 @@ char *get_time() { return buf; } -void log_command(int argc, char* argv[]) { +void log_command(int argc,const char* argv[]) { char tmp[STR_L] = ""; for(int i = 0; i < argc; i++) { strcat(tmp, argv[i]); @@ -41,7 +41,8 @@ void log_command(int argc, char* argv[]) { } #define X(stream) \ - void add_ ## stream ## _with_delim(char *delim, char *txt, \ + void add_ ## stream ## _with_delim(const char *delim, \ + const char *txt, \ va_list args) { \ char tmp[STR_L]; \ vsprintf(tmp, txt, args); \ @@ -56,22 +57,22 @@ void log_command(int argc, char* argv[]) { CK_STREAMS #undef X -#define X(stream) \ - void ck## stream(char *txt, ...) { \ - va_list args; \ - va_start(args, txt); \ - add_## stream ##_with_delim("\n", txt, args); \ - va_end(args); \ +#define X(stream) \ + void ck## stream(const char *txt, ...) { \ + va_list args; \ + va_start(args, txt); \ + add_## stream ##_with_delim("\n", txt, args); \ + va_end(args); \ } CK_STREAMS #undef X -#define X(stream) \ - void ck## stream ##_with_delim(char *d, char *txt, ...) { \ - va_list args; \ - va_start(args, txt); \ - add_## stream ##_with_delim(d, txt, args); \ - va_end(args); \ +#define X(stream) \ + void ck## stream ##_with_delim(const char *d, const char *txt, ...) { \ + va_list args; \ + va_start(args, txt); \ + add_## stream ##_with_delim(d, txt, args); \ + va_end(args); \ } CK_STREAMS #undef X @@ -123,7 +124,7 @@ extern void errlog_set_verbose(int level) { } -void initialize_errlog(int argc, char* argv[]) { +void initialize_errlog(int argc, const char** argv) { #define X(stream) stream = NULL; CK_STREAMS #undef X diff --git a/src/ckerrlog.h b/src/ckerrlog.h index aa5840b..9d71458 100644 --- a/src/ckerrlog.h +++ b/src/ckerrlog.h @@ -48,17 +48,13 @@ X(logv) \ X(help) -extern void initialize_errlog(int argc, char* argv[]); +extern void initialize_errlog(int argc, const char** argv); extern void report_errlog(); extern void errlog_set_verbose(int level); -extern void ckerr(char *err, ...); -extern void cklog(char *log, ...); -extern void ckhelp(char *log, ...); - -#define X(stream) \ - extern void ck## stream(char *log, ...); \ - void ck## stream ##_with_delim(char *d, char *txt, ...); \ +#define X(stream) \ + extern void ck## stream(const char *log, ...); \ + void ck## stream ##_with_delim(const char *d,const char *txt, ...); \ void report_## stream(); CK_STREAMS #undef X diff --git a/src/cklist.c b/src/cklist.c index 2fdfa07..f255556 100644 --- a/src/cklist.c +++ b/src/cklist.c @@ -50,19 +50,13 @@ int list_next(cklist *ckl) { } char* list_get(cklist *ckl) { - if (ckl->pos == -1) { - return NULL; - } if (ckl->pos >= ckl->size) { return NULL; } return ckl->arr[ckl->pos]; } -char* list_get_at(cklist *ckl, int pos) { - if (ckl->pos == -1) { - return NULL; - } +char* list_get_at(cklist *ckl, unsigned int pos) { if (ckl->pos >= ckl->size || pos >= ckl->size) { return NULL; @@ -94,7 +88,7 @@ cklist* list_move(cklist *ckl) { return _ckl; } -cklist* list_copy_from(cklist *ckl, int index) { +cklist* list_copy_from(cklist *ckl,unsigned int index) { list_rewind(ckl); cklist *_ckl = list_make_new(); if (ckl->pos >= index) { @@ -109,7 +103,7 @@ cklist* list_copy_from(cklist *ckl, int index) { return _ckl; } -cklist* list_copy_until(cklist *ckl, int index) { +cklist* list_copy_until(cklist *ckl,unsigned int index) { list_rewind(ckl); cklist *_ckl = list_make_and_add(list_get(ckl)); while(list_next(ckl)) { @@ -121,7 +115,7 @@ cklist* list_copy_until(cklist *ckl, int index) { return _ckl; } -cklist* list_copy_part(cklist *ckl, int from, int until) { +cklist* list_copy_part(cklist *ckl,unsigned int from,unsigned int until) { list_rewind(ckl); cklist *_ckl = list_make_new(); if (ckl->pos >= from && ckl->pos < until) { @@ -185,7 +179,7 @@ void list_print_concat(cklist *ckl) { } } -int list_exists(cklist *ckl, char *str) { +int list_exists(cklist *ckl, const char *str) { if (ckl->size > 0) { list_rewind(ckl); do { @@ -197,12 +191,12 @@ int list_exists(cklist *ckl, char *str) { return 0; } -int list_size(cklist *ckl) { +unsigned int list_size(cklist *ckl) { return ckl->size; } void list_free(cklist *ckl) { - int i; + unsigned int i; for (i=0; i<ckl->size; i++) { free(ckl->arr[i]); } diff --git a/src/cklist.h b/src/cklist.h index 3cf0f7c..dcc6763 100644 --- a/src/cklist.h +++ b/src/cklist.h @@ -16,8 +16,8 @@ #define CKLIST_H typedef struct cklist_st cklist; struct cklist_st { - int size; - int pos; + unsigned int size; + unsigned int pos; char **arr; }; @@ -28,9 +28,9 @@ extern void list_rewind(cklist *ckl); extern int list_next(cklist *ckl); extern char* list_get(cklist *ckl); -extern char* list_get_at(cklist *ckl, int pos); +extern char* list_get_at(cklist *ckl,unsigned int pos); -extern int list_size(cklist *ckl); +extern unsigned int list_size(cklist *ckl); /* rewinds */ extern cklist* list_duplicate(cklist *ckl); @@ -38,17 +38,17 @@ extern cklist* list_duplicate(cklist *ckl); extern cklist* list_move(cklist *ckl); /* rewinds * copy from index (>=) to the end */ -extern cklist* list_copy_from(cklist *ckl, int index); +extern cklist* list_copy_from(cklist *ckl,unsigned int index); /* rewinds * copy from the start until (<) index*/ -extern cklist* list_copy_until(cklist *ckl, int index); +extern cklist* list_copy_until(cklist *ckl,unsigned int index); /* rewinds * copy from (>=) until (<) */ -extern cklist* list_copy_part(cklist *ckl, int from, int until); +extern cklist* list_copy_part(cklist *ckl,unsigned int from,unsigned int until); /* return 1 if str exists in the list, 0 otherwise */ -extern int list_exists(cklist *ckl, char *str); +extern int list_exists(cklist *ckl, const char *str); /* rewinds */ extern void list_print_lisp(cklist *ckl); diff --git a/src/ckutil.c b/src/ckutil.c index b852f72..84eb43d 100644 --- a/src/ckutil.c +++ b/src/ckutil.c @@ -97,7 +97,7 @@ int util_move_file(const char *path, const char* dest) { struct stat st, newSt; fstat(srcFile, &st); - sendfile(destFile, srcFile, NULL, st.st_size); + sendfile(destFile, srcFile, NULL, (size_t)st.st_size); close(srcFile); fchmod(destFile, st.st_mode); diff --git a/src/confparser.c b/src/confparser.c index 6dea001..3a7c357 100644 --- a/src/confparser.c +++ b/src/confparser.c @@ -42,7 +42,7 @@ ConfVar match_variables(char *line, char matched[]) { } CONFIG_VARIABLES_TABLE #undef X - return -1; + return CV_WRONG_VAL; } void make_config_name(char * ret, const char *confPath) { diff --git a/src/confparser.h b/src/confparser.h index 94541c6..f4c52c3 100644 --- a/src/confparser.h +++ b/src/confparser.h @@ -24,6 +24,7 @@ enum ConfingVariables { CV_NO_VAL_OR_COMMENT, + CV_WRONG_VAL, #define X(var, str, name) CV_##var, CONFIG_VARIABLES_TABLE #undef X diff --git a/src/dblayer.c b/src/dblayer.c index 8703c1e..acdf339 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -41,7 +41,7 @@ int check_initialized_DB(sqlite3 *db) { dbh_form_query_select_all_tables(sql); sqlite3_stmt *stmt; - sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL); + sqlite3_prepare_v2(db, sql, (int)strlen(sql), &stmt, NULL); int program_table_ok, config_table_ok, rel_table_ok = 0; while (sqlite3_step(stmt) != SQLITE_DONE) { @@ -135,7 +135,7 @@ int get_next_valid_id_from_table(DB *db, const char* tableName) { if (rc != SQLITE_OK) { return -1; } - sqlite3_bind_text(stmt, 1, tableName, strlen(tableName), 0); + sqlite3_bind_text(stmt, 1, tableName, (int)strlen(tableName), 0); int id = 0; while (sqlite3_step(stmt) == SQLITE_ROW) { @@ -168,7 +168,7 @@ int insert_to_program_table(DB *db, const char *name) { return -1; } sqlite3_bind_int(stmt, 1, id); - sqlite3_bind_text(stmt, 2, name, strlen(name), 0); + sqlite3_bind_text(stmt, 2, name, (int)strlen(name), 0); if (sqlite3_step(stmt) != SQLITE_DONE) { PRINT_ERR("while excecuting insert to program sql."); db->error = SQL_ERR_SQLITE; @@ -196,7 +196,7 @@ int insert_to_config_table(DB *db, const char *path, const int secret, const int return -1; } sqlite3_bind_int(stmt, 1, id); - sqlite3_bind_text(stmt, 2, path, strlen(path), 0); + sqlite3_bind_text(stmt, 2, path, (int)strlen(path), 0); sqlite3_bind_int(stmt, 3, secret); sqlite3_bind_int(stmt, 4, prime); if (sqlite3_step(stmt) != SQLITE_DONE) { @@ -245,7 +245,7 @@ int get_program_id(DB *db, const char* name) { PRINT_ERR("Error while preparing get_program_id sql."); return -2; } - sqlite3_bind_text(stmt, 1, name, strlen(name), 0); + sqlite3_bind_text(stmt, 1, name, (int)strlen(name), 0); int id = -1; while (sqlite3_step(stmt) == SQLITE_ROW) { id = sqlite3_column_int(stmt, 0); @@ -274,7 +274,7 @@ int get_config_id(DB *db, const char* path) { PRINT_ERR("while preparing get_config_id sql."); return -2; } - sqlite3_bind_text(stmt, 1, path, strlen(path), 0); + sqlite3_bind_text(stmt, 1, path, (int)strlen(path), 0); int id = -1; while (sqlite3_step(stmt) == SQLITE_ROW) { id = sqlite3_column_int(stmt, 0); |