progress
This commit is contained in:
parent
3878a5fb80
commit
01080e8e2c
32
src/main.c
32
src/main.c
@ -54,10 +54,6 @@ struct access_log_entry_t {
|
|||||||
char *http_user_agent;
|
char *http_user_agent;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct access_log_table_t {
|
|
||||||
struct *access_log_entry_t;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void debugmsg(const char *format, ...) {
|
void debugmsg(const char *format, ...) {
|
||||||
if(DEBUG == true) {
|
if(DEBUG == true) {
|
||||||
@ -68,7 +64,7 @@ void debugmsg(const char *format, ...) {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
int checkparams(int *argc, char *argv[]) {
|
int checkparams(int *argc, char *argv[]) {
|
||||||
if(*argc != EXPECTED_PARAMS) {
|
if(*argc != EXPECTED_PARAMS) {
|
||||||
@ -97,6 +93,7 @@ unsigned int count_lines(FILE *filepointer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
debugmsg( "Detected %d Lines in filestream\n", lines);
|
debugmsg( "Detected %d Lines in filestream\n", lines);
|
||||||
|
rewind(filepointer);
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +101,7 @@ unsigned int calculate_filesize(FILE *filepointer){
|
|||||||
rewind(filepointer);
|
rewind(filepointer);
|
||||||
fseek(filepointer, 0L, SEEK_END);
|
fseek(filepointer, 0L, SEEK_END);
|
||||||
int filesize = ftell(filepointer);
|
int filesize = ftell(filepointer);
|
||||||
|
rewind(filepointer);
|
||||||
return filesize;
|
return filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,26 +120,22 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("Datei konnte nicht geöffnet werden.\n");
|
printf("Datei konnte nicht geöffnet werden.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}else{
|
}else{
|
||||||
|
char line_buffer[BUF];
|
||||||
unsigned int filesize = calculate_filesize(fp);
|
unsigned int filesize = calculate_filesize(fp);
|
||||||
unsigned int linecount = count_lines(fp);
|
unsigned int linecount = count_lines(fp);
|
||||||
debugmsg("Datei %s geöffnet. Speicheradresse %p, Speichergröße %d Byte\n", filepath, &fp, filesize);
|
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);
|
struct access_log_entry_t *log_entries = malloc(filesize);
|
||||||
debugmsg("Speicher erfolgreich für access_logentry alloziert: %d Byte\n", sizeof(access_logentry));
|
debugmsg("Speicher erfolgreich für log_entries alloziert: %d Byte\n", sizeof(*log_entries));
|
||||||
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));
|
for (int counter = 0; counter < 10 && fgets(line_buffer, BUF, fp); counter++) {
|
||||||
if(access_log_table==NULL){
|
|
||||||
return -1;
|
|
||||||
};
|
|
||||||
rewind(fp);
|
|
||||||
for (int counter = 0; counter < 10 && fgets(access_log_table, BUF, fp); counter++) {
|
|
||||||
char outputline[BUF];
|
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);
|
fputs(outputline, stdout);
|
||||||
}
|
}
|
||||||
free(access_log_table);
|
//free(line_buffer);
|
||||||
free(access_logentry);
|
free(log_entries);
|
||||||
access_log_table = NULL;
|
//line_buffer = NULL;
|
||||||
access_logentry = NULL;
|
log_entries = NULL;
|
||||||
}
|
}
|
||||||
debugmsg("END OF PROGRAM");
|
debugmsg("END OF PROGRAM");
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user