Skip to content

Commit

Permalink
Merge pull request #25 from AleksArt000/main
Browse files Browse the repository at this point in the history
added mock implementations for listing installed files
  • Loading branch information
ilovethensa authored Oct 31, 2023
2 parents f32b025 + a0c09da commit 79364c2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/libspm.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ struct package

};

//test
int list_installed();
int count_installed();
int get_installed(int index);

//end test

// package info


Expand Down
75 changes: 75 additions & 0 deletions src/list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "sqlite3.h" // SQLite database library

// Include necessary headers
#include "libspm.h"
#include "cutils.h"

//should probably add there to the header when we are done

//will print the content of INSTALLED_DB
int list_installed()
{
msg(INFO, "listing installed packages from %s", getenv(INSTALLED_DB));

Check warning on line 16 in src/list.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/list.c:16:64 [clang-diagnostic-incompatible-pointer-types]

incompatible pointer types passing 'sqlite3 *' (aka 'struct sqlite3 *') to parameter of type 'const char *'
if(0 == 1)
{
sqlite3_stmt *stmt;

Check warning on line 19 in src/list.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/list.c:19:31 [cppcoreguidelines-init-variables]

variable 'stmt' is not initialized
int rc;

Check warning on line 20 in src/list.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/list.c:20:21 [cppcoreguidelines-init-variables]

variable 'rc' is not initialized

// Prepare the SQL query
const char *sql = "idfk";
rc = sqlite3_prepare_v2(getenv(INSTALLED_DB), sql, -1, &stmt, NULL);

Check warning on line 24 in src/list.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/list.c:24:41 [clang-diagnostic-incompatible-pointer-types]

incompatible pointer types passing 'char *' to parameter of type 'sqlite3 *' (aka 'struct sqlite3 *')

Check warning on line 24 in src/list.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/list.c:24:48 [clang-diagnostic-incompatible-pointer-types]

incompatible pointer types passing 'sqlite3 *' (aka 'struct sqlite3 *') to parameter of type 'const char *'
if (rc != SQLITE_OK) {
msg(ERROR, "SQL error: %s -- %d", sqlite3_errmsg(INSTALLED_DB), rc);
return 1;
}

// Bind the value for the parameter in the SQL query
sqlite3_bind_text(stmt, 1, "idk", -1, SQLITE_STATIC);

// Execute the PRINT statement or smth.
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) {
msg(ERROR, "Error executing PRINT statement or smth: %s\n", sqlite3_errmsg(INSTALLED_DB));
return -1;
}

// Finalize the statement.
rc = sqlite3_finalize(stmt);
if (rc != SQLITE_OK) {
msg(ERROR, "Error finalizing PRINT statement or smth: %s\n", sqlite3_errmsg(INSTALLED_DB));
return -1;
}

return 0;
}

}

Check warning on line 50 in src/list.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/list.c:50:5 [clang-diagnostic-return-type]

non-void function does not return a value

//will return the ammount of packages installed INSTALLED_DB
int count_installed()
{
int count = 1;

// do sql magic here

msg(INFO, "there are %d installed packages", count);

return count;
}

//will print the content of INSTALLED_DB at a specific index
int get_installed(int index)
{
int count = 0;
char* out = "test";
//out = sql magic

msg(INFO, "%s is installed at %d", out, index);

return count;

}

0 comments on commit 79364c2

Please sign in to comment.