Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed stuff #123

Merged
merged 23 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev
- name: Install libsqlite3-dev
run: |
sudo apt-get update
sudo apt-get install -y libsqlite3-dev
- name: Install libgit2
run: |
curl -L https://codeload.github.com/libgit2/libgit2/tar.gz/refs/tags/v1.8.1 --output libgit2-1.8.1.tar.gz
Expand Down
1 change: 0 additions & 1 deletion compile_flags.txt

This file was deleted.

76 changes: 41 additions & 35 deletions formats/ecmp/ecmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
}section;


unsigned int getsections(char* path,section*** sectionq);

Check warning on line 27 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:27:14 [readability-inconsistent-declaration-parameter-name]

function 'getsections' has a definition with different parameter names

unsigned int parseinfo(char* s, struct package* dest);
unsigned int parseraw(char* s, char** dest);
unsigned int parsenl(char* s,char*** dest);

hashtable* hm;

Check warning on line 33 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:33:12 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'hm' is non-const and globally accessible, consider making it const

Check warning on line 33 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:33:12 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'hm' provides global access to a non-const object; consider making the pointed-to data 'const'
hashtable* infohm;

Check warning on line 34 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:34:12 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'infohm' is non-const and globally accessible, consider making it const

Check warning on line 34 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:34:12 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'infohm' provides global access to a non-const object; consider making the pointed-to data 'const'

#ifdef STATIC
int open_ecmp(char* path,struct package* pkg)
Expand All @@ -45,49 +45,47 @@
}

void* parsers[][3] = {
{parseinfo,pkg,NULL},
{parseinfo,&pkg,NULL},

{parseraw,&pkg->info.make,NULL},
{parseraw,&pkg->info.install,NULL},
{parseraw,&pkg->info.download,NULL},
{parseraw,&pkg->info.prepare,NULL},
{parseraw,&pkg->info.special,NULL},

{parsenl,&pkg->files,&pkg->filesCount},
{parsenl,&pkg->dependencies,&pkg->dependenciesCount},
{parsenl,&pkg->optional,&pkg->optionalCount},
{parsenl,&pkg->inputs,&pkg->inputsCount},

{parsenl,&pkg->locations,&pkg->locationsCount},
{parseraw,&pkg->info.description,NULL},
{parsenl,&pkg->exports,&pkg->exportsCount}
{parseraw,&pkg->description,NULL},
{parsenl,&pkg->config,&pkg->configCount}
};

void* pairs[][2] = {
{"info",parsers[0]},

{"make",parsers[1]},
{"install",parsers[2]},
{"download",parsers[3]},
{"prepare",parsers[4]},
{"special",parsers[5]},

{"files",parsers[6]},
{"dependencies",parsers[7]},
{"optional",parsers[8]},
{"inputs",parsers[9]},
{"locations",parsers[10]},
{"description",parsers[11]},
{"exports",parsers[12]},
{"install",parsers[1]},
{"prepare",parsers[2]},
{"special",parsers[3]},

{"files",parsers[4]},
{"dependencies",parsers[5]},
{"optional",parsers[6]},

{"locations",parsers[7]},
{"description",parsers[8]},
{"config",parsers[9]},
{NULL,NULL}
};

void* infodict[][2] = {
// This is very stupid, but basically I assume that the name was obtained from the database
// This is to go around a memory leak caused by overwriting name when opening a package
// This is very stupid
{"name",&pkg->name},
{"version",&pkg->version},
{"type",&pkg->type},
{"url",&pkg->url},
{"license",&pkg->license},
{"sha256",&pkg->sha256},
{"environment",&pkg->environment},
{NULL,NULL}
};
Expand All @@ -96,15 +94,15 @@



unsigned int (*parser)(char* s,void* dest);

Check warning on line 97 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:97:17 [cppcoreguidelines-init-variables]

variable 'parser' is not initialized

section** sections;

Check warning on line 99 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:99:12 [cppcoreguidelines-init-variables]

variable 'sections' is not initialized
uint count = getsections(path,&sections);

for (unsigned int i = 0; i < count; i++) {
void** options = hm_get(hm,sections[i]->name);
if (options == NULL) {
msg(WARNING,"Unknown section : %s",sections[i]->name);
msg(FATAL,"Unknown section : %s",sections[i]->name);
free(sections[i]->buff);
continue;
}
Expand All @@ -118,14 +116,15 @@

}
else {
msg(WARNING,"Unknown parser for section : %s",sections[i]->name);
msg(FATAL,"Unknown parser for section : %s",sections[i]->name);
}
}
dbg(2,"done parsing | returning");

// free sections
for (unsigned int i = 0; i < count; i++) {
free(sections[i]->name);
free(sections[i]->buff);
free(sections[i]);
}
free(sections);
Expand All @@ -141,10 +140,10 @@

unsigned int parsenl(char* s,char*** dest)
{
char* str;
//char* str;
// the parseraw below is useless but i'll keep since in case
parseraw(s,&str);
return splita(str,'\n',dest);
//parseraw(s,&str);
return splita(s,'\n',dest);
}
unsigned int parseraw(char* s, char** dest)
{
Expand All @@ -153,7 +152,7 @@
// So we are just going to copy the pointer to it
// In the last version , we were copying the string to a new buffer
// Because the `s` string was a buffer that was going to be freed by `getline()`
*dest = s;
*dest = strdup(s);
return strlen(s);
}

Expand All @@ -172,44 +171,52 @@
}

// split with nl
char** nlist;

Check warning on line 174 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:174:12 [cppcoreguidelines-init-variables]

variable 'nlist' is not initialized
int count = parsenl(s, &nlist);

dbg(3, "count : %d", count);
for (int i = 0; i < count; i++) {
char* key = strtok(nlist[i], "=");
char* value = strtok(NULL, "=");

Check warning on line 180 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:180:15 [cppcoreguidelines-init-variables]

variable 'value' is not initialized
if (key == NULL || value == NULL) {
msg(WARNING, "Invalid key-value pair: '%s'", nlist[i]);
msg(FATAL, "Invalid key-value pair: '%s'", nlist[i]);
continue;
}

// add to corresponding value in dict
char** destbuff = hm_get(infohm, key);

if(strcmp(key, "name") == 0)
{
// This is very stupid
free(nlist[i]);
continue;
}
if (destbuff == NULL) {
msg(WARNING, "Unknown key : '%s'", key);
msg(FATAL, "Unknown key : '%s'", key);
continue;
}

*destbuff = strdup(value);
if (*destbuff == NULL) {
msg(ERROR, "Error allocating memory for %s value", key);
free(nlist);
free(s);
//free(s);
return 0;
}
dbg(3, "Setting destbuff to %p - %s", *destbuff, *destbuff);
free(nlist[i]);
}

free(nlist);
free(s);
//free(s);
return 0;
}


unsigned int getsections(char* path,section*** sections) {
FILE* fp = fopen(path,"r");
char* line = NULL;

Check warning on line 219 in formats/ecmp/ecmp.c

View workflow job for this annotation

GitHub Actions / c-linter

formats/ecmp/ecmp.c:219:8 [cppcoreguidelines-init-variables]

variable 'line' is not initialized
size_t len = 0;
ssize_t read;
*sections = calloc(16,sizeof(section));
Expand All @@ -221,7 +228,8 @@
(void)current;
unsigned int alloc = 0;

while ((read = getline(&line,&len,fp)) != EOF) {
while ((read = getline(&line,&len,fp)) != EOF)
{
if (line[0] == '#' || line[0] == '\n' || strlen(line) < 2) {
continue;
}
Expand All @@ -246,6 +254,7 @@
}
strcat((*sections)[sectionscount-1]->buff,line);
}
free(line);
return sectionscount;
}

Expand All @@ -259,15 +268,13 @@
// i love hashmaps but here we'll use maparray
// we have the list[0] = section and list[1] = function to do stuff
void* list[][3] = {
{"download",pkg->info.download,NULL},
{"prepare",pkg->info.prepare,NULL},
{"make",pkg->info.make,NULL},
{"install",pkg->info.install,NULL},
{"special",pkg->info.special,NULL},

{"dependencies",pkg->dependencies,&pkg->dependenciesCount},
{"optional",pkg->optional,&pkg->optionalCount},
{"description",pkg->info.description,NULL},
{"description",pkg->description,NULL},

{"locations",pkg->locations,&pkg->locationsCount},
};
Expand All @@ -287,7 +294,6 @@
if (pkg->type != NULL) fprintf(ecmp,"type = %s\n",pkg->type);
if (pkg->license != NULL) fprintf(ecmp,"license = %s\n",pkg->license);
if (pkg->url != NULL) fprintf(ecmp,"url = %s\n",pkg->url);
if (pkg->sha256 != NULL) fprintf(ecmp,"sha256 = %s\n",pkg->sha256);
fprintf(ecmp,"\n"); // for improved readability

for (unsigned int i = 0;i < sizeof(list) / sizeof(list[0]);i++ )
Expand Down
19 changes: 6 additions & 13 deletions include/globals.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
#include "stdbool.h"

Check failure on line 1 in include/globals.h

View workflow job for this annotation

GitHub Actions / c-linter

include/globals.h:1:10 [clang-diagnostic-error]

'stdbool.h' file not found

#define QUEUE_MAX 64
// This is very stupid, but I don't want to work on this right now.
#define QUEUE_MAX 65536

#define MAX_PATH 2048
/*
START OF THE (sort of) CONSTANTS DECALRATIONS
(They are not mean to be modified a lot)
*/


// enable testing mode
extern bool TESTING;
// overwrite file when installing
extern bool OVERWRITE;
// enable verbose mode
extern bool QUIET;
// Flag for skipping checksum validation
extern bool INSECURE;
// Flag indicating that a user passed either Y or N to be used as default
extern bool OVERWRITE_CHOISE;
// Choise for passing N or Y to a prompt by default
extern char* USER_CHOISE[2];

extern char* PACKAGE_QUEUE[QUEUE_MAX];
extern int QUEUE_COUNT;
// Flag indicating that no inputs are required
extern bool AUTO;
// Package queue
extern struct packages* PACKAGE_QUEUE;

Loading
Loading