This commit is contained in:
Mario Stöckl 2025-07-06 00:22:27 +02:00
parent 3878a5fb80
commit 01080e8e2c
2 changed files with 13 additions and 19 deletions

BIN
bin/main

Binary file not shown.

View File

@ -54,10 +54,6 @@ struct access_log_entry_t {
char *http_user_agent;
};
struct access_log_table_t {
struct *access_log_entry_t;
}
void debugmsg(const char *format, ...) {
if(DEBUG == true) {
@ -68,7 +64,7 @@ void debugmsg(const char *format, ...) {
printf("\n");
va_end(args);
}
}
};
int checkparams(int *argc, char *argv[]) {
if(*argc != EXPECTED_PARAMS) {
@ -97,6 +93,7 @@ unsigned int count_lines(FILE *filepointer) {
}
}
debugmsg( "Detected %d Lines in filestream\n", lines);
rewind(filepointer);
return lines;
}
@ -104,6 +101,7 @@ unsigned int calculate_filesize(FILE *filepointer){
rewind(filepointer);
fseek(filepointer, 0L, SEEK_END);
int filesize = ftell(filepointer);
rewind(filepointer);
return filesize;
}
@ -122,26 +120,22 @@ int main(int argc, char *argv[]) {
printf("Datei konnte nicht geöffnet werden.\n");
return -1;
}else{
char line_buffer[BUF];
unsigned int filesize = calculate_filesize(fp);
unsigned int linecount = count_lines(fp);
debugmsg("Datei %s geöffnet. Speicheradresse %p, Speichergröße %d Byte\n", filepath, &fp, filesize);
struct access_log_entry_t *access_logentry = malloc(sizeof(struct access_log_entry_t)*BUF);
debugmsg("Speicher erfolgreich für access_logentry alloziert: %d Byte\n", sizeof(access_logentry));
struct access_log_table_t *access_log_table = malloc(sizeof(access_logentry_t)*linecount);
debugmsg("Speicher erfolgreich für _log_tablaccess_log_table alloziert: %d Byte\n", sizeof(access_log_table));
if(access_log_table==NULL){
return -1;
};
rewind(fp);
for (int counter = 0; counter < 10 && fgets(access_log_table, BUF, fp); counter++) {
struct access_log_entry_t *log_entries = malloc(filesize);
debugmsg("Speicher erfolgreich für log_entries alloziert: %d Byte\n", sizeof(*log_entries));
for (int counter = 0; counter < 10 && fgets(line_buffer, BUF, fp); counter++) {
char outputline[BUF];
sprintf(outputline, "LINE %d: %s", counter+1, access_log_table);
sprintf(outputline, "LINE %d: %s", counter+1, line_buffer);
fputs(outputline, stdout);
}
free(access_log_table);
free(access_logentry);
access_log_table = NULL;
access_logentry = NULL;
//free(line_buffer);
free(log_entries);
//line_buffer = NULL;
log_entries = NULL;
}
debugmsg("END OF PROGRAM");
return 0;