new branch for option to insert an event
This commit is contained in:
parent
c713522736
commit
3cab08dbf3
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
a.out
|
||||
.gitconfig
|
||||
*.o
|
||||
|
31
src/Makefile
31
src/Makefile
@ -1,3 +1,22 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall
|
||||
|
||||
# List of all source files (assuming they're all in the same directory)
|
||||
SRC_FILES = $(wildcard *.c)
|
||||
|
||||
# Generate a list of object files by replacing the .c extension with .o
|
||||
OBJ_FILES = $(SRC_FILES:.c=.o)
|
||||
|
||||
ics_analyzer: $(OBJ_FILES)
|
||||
gcc -Wall $(OBJ_FILES) -o ics_analyzer
|
||||
|
||||
main.o: main.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
# use implicit rule to compile C source files to object files
|
||||
%.o: %.c %.h
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
.PHONY:all
|
||||
all:
|
||||
gcc -Wall *.c
|
||||
@ -10,15 +29,15 @@ debug:
|
||||
.PHONY:run
|
||||
run:
|
||||
gcc -Wall *.c
|
||||
./a.out
|
||||
./ics_analyzer
|
||||
|
||||
.PHONY:install
|
||||
install: a.out
|
||||
cp a.out /usr/local/bin/ics_analyzer
|
||||
cp ics_analyzer /usr/local/bin/ics_analyzer
|
||||
|
||||
.PHONY:clean
|
||||
clean:
|
||||
-rm a.out
|
||||
-rm ics_analyzer *.o
|
||||
|
||||
.PHONY:uninstall
|
||||
uninstall:
|
||||
@ -26,8 +45,8 @@ uninstall:
|
||||
|
||||
.PHONY:test
|
||||
test:
|
||||
./a.out
|
||||
./ics_analyzer
|
||||
@echo
|
||||
./a.out -h
|
||||
./ics_analyzer -h
|
||||
@echo
|
||||
./a.out -f ../tests/calendar.ics
|
||||
./ics_analyzer -f ../tests/calendar.ics
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "insert_event.h"
|
||||
#include "cli_arg_parsing.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -15,7 +16,6 @@ void get_cli_args(int argc, char **argv, char **file_name) {
|
||||
|
||||
memset(file_name, '\0', strlen(*file_name));
|
||||
|
||||
if (argc < 2) {
|
||||
char *home = getenv("HOME");
|
||||
*file_name = home;
|
||||
|
||||
@ -25,17 +25,18 @@ void get_cli_args(int argc, char **argv, char **file_name) {
|
||||
printf ("Environment variable HOME is not set.\n");
|
||||
exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
while ((opt = getopt(argc, argv, "f:h")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "f:hi")) != -1) {
|
||||
switch(opt) {
|
||||
case 'f':
|
||||
*file_name = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
break;
|
||||
case 'i':
|
||||
insert_event(*file_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
33
src/insert_event.c
Normal file
33
src/insert_event.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include "insert_event.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void insert_event(char *file_name) {
|
||||
int myfd = open(file_name, O_APPEND | O_WRONLY);
|
||||
|
||||
char summary_buf[256] = "SUMMARY:";
|
||||
|
||||
char *input_buffer = &summary_buf[8];
|
||||
|
||||
printf("Insert a new event\n");
|
||||
printf("SUMMARY: ");
|
||||
fgets (input_buffer, (sizeof(summary_buf)-strlen(summary_buf)), stdin);
|
||||
|
||||
if (strchr(input_buffer, '\n') == NULL)
|
||||
printf ("The input has been truncated to:\n%s\n", input_buffer);
|
||||
|
||||
// modify the string to have \r\n line ending
|
||||
summary_buf[strlen(summary_buf)+1] = '\0';
|
||||
summary_buf[strlen(summary_buf)-1] = '\r';
|
||||
summary_buf[strlen(summary_buf)] = '\n';
|
||||
|
||||
write(myfd, "BEGIN:VEVENT\r\n", strlen("BEGIN:VEVENT\r\n"));
|
||||
write(myfd, summary_buf, strlen(summary_buf));
|
||||
|
||||
close(myfd);
|
||||
|
||||
exit(0);
|
||||
}
|
3
src/insert_event.h
Normal file
3
src/insert_event.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void insert_event(char *file_name);
|
Loading…
Reference in New Issue
Block a user