From 85c68bc0975db58460fc79ecb73c914db7230cc8 Mon Sep 17 00:00:00 2001 From: bjt-user Date: Tue, 15 Aug 2023 16:31:07 +0200 Subject: [PATCH] first commit --- Makefile | 7 + a.out | Bin 0 -> 21360 bytes calendar.ics | 314 +++++++++++++++++++++++++++++++++++++++ src/cut_string.c | 41 +++++ src/cut_string.h | 5 + src/date_time_handling.c | 12 ++ src/date_time_handling.h | 4 + src/list_handling.c | 54 +++++++ src/list_handling.h | 12 ++ src/main.c | 66 ++++++++ src/move_lines.c | 59 ++++++++ src/move_lines.h | 20 +++ src/read_until_nl.c | 16 ++ src/read_until_nl.h | 5 + src/read_until_string.c | 26 ++++ src/read_until_string.h | 7 + src/remove_whitespace.c | 45 ++++++ src/remove_whitespace.h | 8 + src/seek_string_a.c | 22 +++ src/seek_string_a.h | 6 + 20 files changed, 729 insertions(+) create mode 100644 Makefile create mode 100755 a.out create mode 100644 calendar.ics create mode 100644 src/cut_string.c create mode 100644 src/cut_string.h create mode 100644 src/date_time_handling.c create mode 100644 src/date_time_handling.h create mode 100644 src/list_handling.c create mode 100644 src/list_handling.h create mode 100644 src/main.c create mode 100644 src/move_lines.c create mode 100644 src/move_lines.h create mode 100644 src/read_until_nl.c create mode 100644 src/read_until_nl.h create mode 100644 src/read_until_string.c create mode 100644 src/read_until_string.h create mode 100644 src/remove_whitespace.c create mode 100644 src/remove_whitespace.h create mode 100644 src/seek_string_a.c create mode 100644 src/seek_string_a.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d3f4b83 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +debug: + gcc -Wall -g *.c + gdb a.out + +run: + gcc -Wall ./src/*.c + ./a.out diff --git a/a.out b/a.out new file mode 100755 index 0000000000000000000000000000000000000000..d555dbafb232de5286e9a5633d6ef2fe47370538 GIT binary patch literal 21360 zcmeHPe{@vUoxhV1j3^|!qEQq^Bo?d0@IyAJ=mdE1Py!JWe^Bi(Boi`gGKup;B3s(% z7?)`pH|r6~d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ieh9=_KJOP8@_7!+yZwJo>2v&fUCXeQ6%};rzv$BE{UXDs|A_u;E`6_B z@G{(EJ7yW;_G7be0iiv+8aDR*NqoPXTb}a_--m9AL!ZyF=o@%SENA6(p6MfCP~YM5 zc^_@x*QeTFb!*!mx8oM2N7wu1?<0EF2mn~oF{V zvQwY;WxYO2-fIE-FZ;~|dOw3~vH!fj-|e#`xEz+JvYctMD!I@yGg3=;|WU z(xA^WSg8g!&BN5r><`bMr-R16TN>)`3JbpNVsg1GOWP}#h-AHegC%jUOTm>D{{=H+ B3L^jj literal 0 HcmV?d00001 diff --git a/calendar.ics b/calendar.ics new file mode 100644 index 0000000..b54e00b --- /dev/null +++ b/calendar.ics @@ -0,0 +1,314 @@ +BEGIN:VCALENDAR +CALSCALE:GREGORIAN +PRODID:-//Ximian//NONSGML Evolution Calendar//EN +VERSION:2.0 +X-EVOLUTION-DATA-REVISION:2023-07-19T15:30:34.391871Z(3) +BEGIN:VTIMEZONE +TZID:/freeassociation.sourceforge.net/Europe/Berlin +X-LIC-LOCATION:Europe/Berlin +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+005328 +TZOFFSETTO:+0100 +DTSTART:18930401T000000 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19160430T230000 +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19161001T010000 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19170416T020000 +RRULE:FREQ=YEARLY;UNTIL=19180415T010000Z;BYDAY=3MO;BYMONTH=4 +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19170917T030000 +RRULE:FREQ=YEARLY;UNTIL=19180916T010000Z;BYDAY=3MO;BYMONTH=9 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19400401T020000 +RDATE:19430329T020000 +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19421102T030000 +END:STANDARD +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19431004T030000 +RRULE:FREQ=YEARLY;UNTIL=19441002T010000Z;BYDAY=1MO;BYMONTH=10 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19440403T020000 +RRULE:FREQ=YEARLY;UNTIL=19450402T010000Z;BYDAY=1MO;BYMONTH=4 +END:DAYLIGHT +BEGIN:DAYLIGHT +TZNAME:CEMT +TZOFFSETFROM:+0200 +TZOFFSETTO:+0300 +DTSTART:19450524T020000 +END:DAYLIGHT +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0300 +TZOFFSETTO:+0200 +DTSTART:19450924T030000 +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19451118T030000 +RDATE:19461007T030000 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19460414T020000 +END:DAYLIGHT +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19470406T030000 +END:DAYLIGHT +BEGIN:DAYLIGHT +TZNAME:CEMT +TZOFFSETFROM:+0200 +TZOFFSETTO:+0300 +DTSTART:19470511T030000 +END:DAYLIGHT +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0300 +TZOFFSETTO:+0200 +DTSTART:19470629T030000 +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19471005T030000 +RRULE:FREQ=YEARLY;UNTIL=19491002T010000Z;BYDAY=1SU;BYMONTH=10 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19480418T020000 +RDATE:19490410T020000 +RDATE:19800406T020000 +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19800928T030000 +RRULE:FREQ=YEARLY;UNTIL=19950924T010000Z;BYDAY=-1SU;BYMONTH=9 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19810329T020000 +RRULE:FREQ=YEARLY;UNTIL=20370329T010000Z;BYDAY=-1SU;BYMONTH=3 +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19961027T030000 +RRULE:FREQ=YEARLY;UNTIL=20361026T010000Z;BYDAY=-1SU;BYMONTH=10 +END:STANDARD +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:20371025T030000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:20380328T020000 +RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3 +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +UID:fdcb901ffea509c9993c7ccd1ede47148f499022 +DTSTAMP:20230510T153553Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230612T090000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230612T092500 +SEQUENCE:2 +SUMMARY:12:00 Werkstatt +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230510T153646Z +LAST-MODIFIED:20230510T153646Z +END:VEVENT +BEGIN:VEVENT +UID:cde7c41ee121397509f0d88b7c6d188f0508b4ed +DTSTAMP:20230510T153553Z +DTSTART;VALUE=DATE:20230612 +DTEND;VALUE=DATE:20230613 +SEQUENCE:2 +SUMMARY:HOME OFFICE +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230510T153655Z +LAST-MODIFIED:20230510T153655Z +END:VEVENT +BEGIN:VEVENT +UID:c8297cf0792b5910f7b270b1477daf9d6dfcd4b2 +DTSTAMP:20230518T085020Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230518T130000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230518T140000 +SEQUENCE:2 +SUMMARY:go for a walk +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230518T091107Z +LAST-MODIFIED:20230518T091107Z +END:VEVENT +BEGIN:VEVENT +UID:fddba04ef1150f1d725fd62fa4da720362432196 +DTSTAMP:20230518T085020Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230519T090000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230519T170000 +SEQUENCE:2 +SUMMARY:working +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230518T091320Z +LAST-MODIFIED:20230518T091320Z +END:VEVENT +BEGIN:VEVENT +UID:580febe9d714174e36fc604120dd2bf73a745bae +DTSTAMP:20230518T085020Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230519T180000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230519T190000 +SEQUENCE:2 +SUMMARY:fly to New York +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230518T091406Z +LAST-MODIFIED:20230518T091406Z +END:VEVENT +BEGIN:VEVENT +UID:7ed683872694a9553fec9b161b4b873059f21380 +DTSTAMP:20230518T085020Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230519T170000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230519T173000 +SEQUENCE:2 +SUMMARY:buy screws and dowels +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230518T091446Z +LAST-MODIFIED:20230518T091446Z +END:VEVENT +BEGIN:VEVENT +UID:6c7d898399f4f598af4590993e190b2b0ffe6710 +DTSTAMP:20230518T085020Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230518T170000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230518T171500 +SEQUENCE:2 +SUMMARY:take a shower +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230518T091708Z +LAST-MODIFIED:20230518T091708Z +END:VEVENT +BEGIN:VEVENT +UID:6c5e539ca1c266d2df74d02567a3678e8fd31dd1 +DTSTAMP:20230601T155814Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230617T073000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230617T093000 +SEQUENCE:3 +SUMMARY:take exam +TRANSP:OPAQUE +DESCRIPTION:um 8:00 startet das exam\num 7:30 kann man schon mit einem + "check-in" starten\n\nAUSWEIS!\nWEBCAM!\nHEADSET! +CLASS:PUBLIC +CREATED:20230601T165026Z +LAST-MODIFIED:20230601T165058Z +END:VEVENT +BEGIN:VEVENT +UID:251b5064c6f62b6c99304045e6f3c1a7a4e6f840 +DTSTAMP:20230604T154734Z +DTSTART;VALUE=DATE:20230608 +DTEND;VALUE=DATE:20230609 +SEQUENCE:2 +SUMMARY:FEIERTAG +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230604T154847Z +LAST-MODIFIED:20230604T154847Z +END:VEVENT +BEGIN:VEVENT +UID:a7cf77db2adcfe7b82d6cc071adc7cb858586cd2 +DTSTAMP:20230717T153059Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230729T090000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230729T103000 +SEQUENCE:2 +SUMMARY:9:00 exam +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230717T153132Z +LAST-MODIFIED:20230717T153132Z +END:VEVENT +BEGIN:VEVENT +UID:ce6cc0e3ca1bb6a22783ace61034b12c57325b4e +DTSTAMP:20230719T152822Z +DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230831T180000 +DTEND;TZID=/freeassociation.sourceforge.net/Europe/Berlin: + 20230831T220000 +SEQUENCE:3 +SUMMARY:dentist +TRANSP:OPAQUE +CLASS:PUBLIC +CREATED:20230719T153023Z +LAST-MODIFIED:20230719T153034Z +END:VEVENT +END:VCALENDAR diff --git a/src/cut_string.c b/src/cut_string.c new file mode 100644 index 0000000..7d546cc --- /dev/null +++ b/src/cut_string.c @@ -0,0 +1,41 @@ +// cut a string into two parts by the first occurence of delimiter +// and choose the first part (side 0) or the second part (side 1) +// the chosen part will overwrite the original string + +// cut a string into two parts by delimiter +// and choose the first part (side 0) or the second part (side 1) +// the chosen part will overwrite the original string + +#include + +void cut_string(char my_string[], char delimiter, int side) { + char part1[256] = ""; + char part2[256] = ""; + + int split = 0; + + int j = 0; + for (int i = 0; i < strlen(my_string); i++) { + if (my_string[i] == delimiter) { + if (split == 0) { + split = 1; + continue; + } + } + + if (split == 0) { + part1[i] = my_string[i]; + } else { + part2[j] = my_string[i]; + j++; + } + } + + memset(my_string, '\0', strlen(my_string)); + if (side == 0) { + strcpy(my_string, part1); + } else { + strcpy(my_string, part2); + } +} + diff --git a/src/cut_string.h b/src/cut_string.h new file mode 100644 index 0000000..9b8803d --- /dev/null +++ b/src/cut_string.h @@ -0,0 +1,5 @@ +#pragma once + +// cut string into two parts and choose one part +// side is 0 or 1 +void cut_string(char my_string[], char delimiter, int side); diff --git a/src/date_time_handling.c b/src/date_time_handling.c new file mode 100644 index 0000000..e2bb470 --- /dev/null +++ b/src/date_time_handling.c @@ -0,0 +1,12 @@ +#include "date_time_handling.h" +#include +#include + +void get_date(char buffer[]) { + // add 1 because strlen does not include the null character + size_t buffer_size = strlen(buffer) + 1; + time_t my_unix_ts = time(NULL); + struct tm* my_tm_local = localtime(&my_unix_ts); + strftime(buffer, buffer_size, "%Y%m%dT%H%M%S", my_tm_local); +} + diff --git a/src/date_time_handling.h b/src/date_time_handling.h new file mode 100644 index 0000000..3d2b3ec --- /dev/null +++ b/src/date_time_handling.h @@ -0,0 +1,4 @@ +#include +#include + +void get_date(char buffer[]); diff --git a/src/list_handling.c b/src/list_handling.c new file mode 100644 index 0000000..13d216e --- /dev/null +++ b/src/list_handling.c @@ -0,0 +1,54 @@ +#include "list_handling.h" +#include +#include +#include + +void print_list(struct event *head) { + while (head != NULL) { + printf("%s\n", head->date); + printf("%s\n", head->summary); + head = head->next; + } +} + +void sorted_insert(struct event** head, char date[], char summary[]) { + struct event *new_node = malloc(sizeof(struct event)); + strcpy((*new_node).date, date); + strcpy((*new_node).summary, summary); + + if (*head == NULL || strcmp((*head)->date, new_node->date) >= 0) { + new_node->next = *head; + *head = new_node; + } + else { + // Locate the node before the point of insertion + struct event* current = *head; + while (current->next!=NULL && strcmp(current->next->date, new_node->date) < 0) { + current = current->next; + } + new_node->next = current->next; + current->next = new_node; + } +} + +void free_list(struct event *head) +{ + struct event* tmp; + + while (head != NULL) + { + tmp = head; + head = head->next; + free(tmp); + } +} + +void print_upcoming(struct event *head, char current_date[]) { + while (head != NULL) { + if (strcmp(head->date, current_date) >= 0) { + printf("%s\n", head->date); + printf("%s\n", head->summary); + } + head = head->next; + } +} diff --git a/src/list_handling.h b/src/list_handling.h new file mode 100644 index 0000000..79af4e6 --- /dev/null +++ b/src/list_handling.h @@ -0,0 +1,12 @@ +#pragma once + +struct event { + char summary[256]; + char date[256]; + struct event *next; +}; + +void print_list(struct event *head); +void sorted_insert(struct event **head, char date[], char summary[]); +void free_list(struct event *head); +void print_upcoming(struct event *head, char current_date[]); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..fb008d3 --- /dev/null +++ b/src/main.c @@ -0,0 +1,66 @@ +#include "date_time_handling.h" +#include "list_handling.h" +#include "cut_string.h" +#include "move_lines.h" +#include "read_until_nl.h" +#include "read_until_string.h" +#include "seek_string_a.h" +#include "remove_whitespace.h" +#include +#include +#include +#include + +int main() { + const char ICS_PATH[] = "calendar.ics"; + + char my_line[4096] = ""; + + int myfd = open(ICS_PATH, O_RDONLY); + if (myfd == -1) { + perror ("Error opening file"); + return 1; + } + + // initialize linked list + struct event *head = NULL; + + static char current_date[] = "xxxxxxxxTxxxxxx"; + get_date(current_date); + printf ("Current date and time: %s\n\n", current_date); + + char date[256] = ""; + char summary[256] = ""; + + while(read_until_nl(myfd, my_line)) { + if (strncmp(my_line, "BEGIN:VEVENT", 12) == 0) { + memset(my_line, '\0', sizeof(my_line)); + // go to DTSTART, but dont write to a variable + seek_string_a(myfd, "DTSTART"); + read_until_string(myfd, my_line, "DTEND"); + remove_whitespace(my_line); + cut_string(my_line, ':', 1); + strcpy(date, my_line); + + memset(my_line, '\0', sizeof(my_line)); + + seek_string_a(myfd, "SUMMARY:"); + read_until_string(myfd, my_line, "TRANSP:"); + remove_nl_and_cr(my_line); + strcpy(summary, my_line); + memset(my_line, '\0', sizeof(my_line)); + + sorted_insert(&head, date, summary); + memset(date, '\0', sizeof(date)); + memset(summary, '\0', sizeof(summary)); + } + memset(my_line, '\0', sizeof(my_line)); + } + + //print_list(head); + print_upcoming(head, current_date); + + free_list(head); + + return 0; +} diff --git a/src/move_lines.c b/src/move_lines.c new file mode 100644 index 0000000..5d2eb40 --- /dev/null +++ b/src/move_lines.c @@ -0,0 +1,59 @@ +// functions that can move the file position conveniently +// remember that the last line of a file is usually empty and goes from '\n' to EOF + +#include "move_lines.h" +#include + +// function to move back/up +void go_back_x_lines(int fd, int lines) { + for (int i = 0; i < lines; i++) { + seek_previous_line(fd); + } +} + +void seek_previous_line(int fd) { + seek_line_start(fd); + lseek(fd, -1, SEEK_CUR); + seek_line_start(fd); +} + +// set file position to the beginning of the line +void seek_line_start(int fd) { + char cur_char = '\0'; + + while (cur_char != '\n') { + int ret_lseek = lseek(fd, -1, SEEK_CUR); + if (ret_lseek == -1) + break; + + read(fd, &cur_char, 1); + if (cur_char != '\n') + lseek(fd, -1, SEEK_CUR); + } +} + +// function to move forward/down +void go_forward_x_lines(int fd, int lines) { + for (int i = 0; i < lines; i++) { + seek_next_line(fd); + } +} + +void seek_next_line(int fd) { + seek_line_end(fd); + lseek(fd, 1, SEEK_CUR); +} + +// set file position to the end of the line +void seek_line_end(int fd) { + char cur_char = '\0'; + + while (cur_char != '\n') { + // return code 0 of read indicates EOF + if (read(fd, &cur_char, 1) == 0) + break; + } + + lseek(fd, -1, SEEK_CUR); +} + diff --git a/src/move_lines.h b/src/move_lines.h new file mode 100644 index 0000000..fe9200a --- /dev/null +++ b/src/move_lines.h @@ -0,0 +1,20 @@ +// functions that can move the file position conveniently +// remember that the last line of a file is usually empty and goes from '\n' to EOF + +#pragma once + +// function to move back/up +void go_back_x_lines(int fd, int lines); + +void seek_previous_line(int fd); + +// set file position to the beginning of the line +void seek_line_start(int fd); + +// function to move forward/down +void go_forward_x_lines(int fd, int lines); + +void seek_next_line(int fd); + +// set file position to the end of the line +void seek_line_end(int fd); diff --git a/src/read_until_nl.c b/src/read_until_nl.c new file mode 100644 index 0000000..1d1f487 --- /dev/null +++ b/src/read_until_nl.c @@ -0,0 +1,16 @@ +#include + +// this function will read until the next newline character +// and save the characters in a string you provide in arg2 +int read_until_nl(int fd, char line[]) { + int i = 0; + int ret_read = 0; + while ((ret_read = read(fd, &line[i], 1))) { + if (line[i] == '\n') { + break; + } + i++; + } + return ret_read; +} + diff --git a/src/read_until_nl.h b/src/read_until_nl.h new file mode 100644 index 0000000..4259ebc --- /dev/null +++ b/src/read_until_nl.h @@ -0,0 +1,5 @@ +#pragma once + +// this function will read until the next newline character +// and save the characters in a string you provide in arg2 +int read_until_nl(int fd, char line[]); diff --git a/src/read_until_string.c b/src/read_until_string.c new file mode 100644 index 0000000..ae4a416 --- /dev/null +++ b/src/read_until_string.c @@ -0,0 +1,26 @@ +// the same as read_until_string, but this function not only truncates but fills remaining chars with null characters +// this function is cleaner and nicer to work with, but not as fast as "read_until_string" +// ct means "clean truncate" +// return 1 on success, -1 when buffer is NULL + +#include +#include + +void read_until_string(int fd, char buffer[], char search_string[]) { + int i = 0; + int j = 0; + + while(read(fd, &buffer[i], 1)) { + if (buffer[i] == search_string[j]) { + j++; + } else { + j = 0; + } + if (j == (strlen(search_string))) { + break; + } + i++; + } + size_t truncate_position = strlen(buffer) - strlen(search_string); + memset(&buffer[truncate_position], '\0', truncate_position); +} diff --git a/src/read_until_string.h b/src/read_until_string.h new file mode 100644 index 0000000..2066c22 --- /dev/null +++ b/src/read_until_string.h @@ -0,0 +1,7 @@ +// the same as read_until_string, but this function not only truncates but fills remaining chars with null characters +// this function is cleaner and nicer to work with, but not as fast as "read_until_string" +// ct means "clean truncate" + +#pragma once + +void read_until_string(int fd, char buffer[], char search_string[]); diff --git a/src/remove_whitespace.c b/src/remove_whitespace.c new file mode 100644 index 0000000..646e2aa --- /dev/null +++ b/src/remove_whitespace.c @@ -0,0 +1,45 @@ +// this function removes all new lines and carriage returns from a string +// you might want to write a new function that replaces '\r' and '\n' +// with a delimiter of user's choice + +#include + +void remove_nl_and_cr(char raw_string[]) { + char processed_string[strlen(raw_string)]; + + // counter for num of elements of processed_string + int j = 0; + for (int i = 0; i +#include +#include + +void seek_string_a(int fd, char search_string[]) { + int j = 0; + char char_reader = '\0'; + + while(read(fd, &char_reader, 1)) { + if (char_reader == search_string[j]) { + j++; + } else { + j = 0; + } + if (j == (strlen(search_string))) { + break; + } + } +} diff --git a/src/seek_string_a.h b/src/seek_string_a.h new file mode 100644 index 0000000..ac3658e --- /dev/null +++ b/src/seek_string_a.h @@ -0,0 +1,6 @@ +// this function will seek for a string in an open file +// it will place the file position AFTER that string + +#pragma once + +void seek_string_a(int fd, char search_string[]);