fixed a makefile thing and added the thingy that does things

This commit is contained in:
david committed 2026-10-06 04:21:57 -03:00
1 parent 1535072cc9
commit 4144b61070
3 files changed
+38 -5

No files matched your search

+9 -3
View File
@@ -2,13 +2,16 @@ CC = gcc
CFLAGS = -Wall -Wextra -O2 -pipe CFLAGS = -Wall -Wextra -O2 -pipe
TARGET = timetolocal TARGET = timetolocal
SRC = $(wildcard *.c) SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
PREFIX = /usr/local PREFIX = /usr/local
all: $(TARGET) all: $(TARGET)
$(TARGET): $(OBJ) $(TARGET): $(OBJ)
@mkdir -p $(@D) $(CC) $(CFLAGS) -o $(TARGET) $(OBJ)
$(CC) $(CFLAGS) -o $(TARGET) $(SRC)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
install: $(TARGET) install: $(TARGET)
install -D $(TARGET) $(DESTDIR)$(PREFIX)/bin/$(notdir $(TARGET)) install -D $(TARGET) $(DESTDIR)$(PREFIX)/bin/$(notdir $(TARGET))
@@ -17,4 +20,7 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(notdir $(TARGET)) rm -f $(DESTDIR)$(PREFIX)/bin/$(notdir $(TARGET))
clean: clean:
rm -rf $(TARGET) rm -f $(TARGET) $(OBJ)
.PHONY: all install uninstall clean
+29 -2
View File
@@ -3,6 +3,7 @@
#include <strings.h> #include <strings.h>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include "tztable.h" #include "tztable.h"
/*it's not case sensitive /*it's not case sensitive
@@ -37,6 +38,17 @@ davidtime strtimetoint(char *whattimeisit) {
return timehoursandminutes; return timehoursandminutes;
} }
char* gethhmm(char* buffer, size_t max_size) {
time_t raw_time;
struct tm* time_info;
time(&raw_time);
time_info = localtime(&raw_time);
strftime(buffer, max_size, "%H:%M", time_info);
return buffer;
}
int convert(char *timey, char *zone){ int convert(char *timey, char *zone){
time_t rawtime = time(NULL); time_t rawtime = time(NULL);
struct tm *ptm = gmtime(&rawtime); struct tm *ptm = gmtime(&rawtime);
@@ -67,13 +79,28 @@ int convert(char *timey, char *zone){
return 0; return 0;
} }
int main (int argc, char **argv){ int main (int argc, char **argv){
if((argc <= 2) || (argc > 3)){ if((argc <= 1) || (argc > 3)){
printf("%s: usage: %s [TIME (24hs)] [ZONE]\ne.g: %s 7:15 est\n", argv[0], argv[0], argv[0]); printf("%s: usage: %s [TIME (24hs)] [ZONE]\ne.g: %s 7:15 est\n\nalso get relative times like %s [ZONE]\ne.g: %s est\n", argv[0], argv[0], argv[0], argv[0], argv[0]);
exit(0); exit(0);
} }
char timestr[16];
gethhmm(timestr, sizeof(timestr));
if (argc == 2) {
if (isdigit((unsigned char)argv[1][0])) {
printf("timezones don't have numbers in them\n");
return 1;
}
if (convert(timestr, argv[1]) == -1) {
printf("%s: time zone not found, did you write it correctly?\n", argv[0]);
return 1;
}
return 0;
}
if(convert(argv [1], argv[2]) == -1){ if(convert(argv [1], argv[2]) == -1){
printf("%s: time zone not found, did you write it correctly?\n", argv[0]); printf("%s: time zone not found, did you write it correctly?\n", argv[0]);
return 1; return 1;
BIN
View File
Binary file not shown.