Skip to content

Commit

Permalink
Merge pull request #123 from AleksArt000/main
Browse files Browse the repository at this point in the history
fixed stuff
  • Loading branch information
ilovethensa authored Dec 27, 2024
2 parents 258c13b + a3292cc commit 0b189ef
Show file tree
Hide file tree
Showing 33 changed files with 1,867 additions and 2,511 deletions.
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 @@ -45,49 +45,47 @@ int open(char* path,struct package* pkg)
}

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 @@ -104,7 +102,7 @@ int open(char* path,struct package* pkg)
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 @@ int open(char* path,struct package* pkg)

}
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 @@ int open(char* path,struct package* pkg)

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 @@ unsigned int parseraw(char* s, char** dest)
// 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 @@ -180,29 +179,37 @@ unsigned int parseinfo(char *s, struct package* dest) {
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;
}

Expand All @@ -221,7 +228,8 @@ unsigned int getsections(char* path,section*** sections) {
(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 @@ unsigned int getsections(char* path,section*** sections) {
}
strcat((*sections)[sectionscount-1]->buff,line);
}
free(line);
return sectionscount;
}

Expand All @@ -259,15 +268,13 @@ int create(const char* path,struct package* pkg)
// 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 @@ int create(const char* path,struct package* pkg)
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

0 comments on commit 0b189ef

Please sign in to comment.