From 836daeb69b79588d0d4e238a22b6208de24cadf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Wed, 9 Oct 2024 19:50:53 +0200 Subject: [PATCH] Switch to using C++. --- Makefile | 10 +++++----- README.md | 4 ++-- src/{arg_parse.c => arg_parse.cpp} | 3 +-- src/{arg_parse.h => arg_parse.hpp} | 0 src/{cmd.c => cmd.cpp} | 4 ++-- src/{cmd.h => cmd.hpp} | 0 src/{db.c => db.cpp} | 2 +- src/{db.h => db.hpp} | 0 src/{main.c => main.cpp} | 4 ++-- src/util.h | 20 -------------------- 10 files changed, 13 insertions(+), 34 deletions(-) rename src/{arg_parse.c => arg_parse.cpp} (96%) rename src/{arg_parse.h => arg_parse.hpp} (100%) rename src/{cmd.c => cmd.cpp} (98%) rename src/{cmd.h => cmd.hpp} (100%) rename src/{db.c => db.cpp} (99%) rename src/{db.h => db.hpp} (100%) rename src/{main.c => main.cpp} (96%) delete mode 100644 src/util.h diff --git a/Makefile b/Makefile index cc44d77..cfbc155 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,8 @@ DEBUG=0 INCFLAGS= LDFLAGS=-lsqlite3 DEFS= -CFLAGS=$(INCFLAGS) -std=gnu99 -Wall -Wextra -Wfatal-errors -Werror -HDRS=src/arg_parse.h src/util.h src/db.h src/cmd.h +CFLAGS=$(INCFLAGS) -std=c++11 -Wall -Wextra -Wfatal-errors -Werror +HDRS=src/arg_parse.hpp src/db.hpp src/cmd.hpp OBJS=src/main.o src/arg_parse.o src/db.o src/cmd.o VERSION=1.0 @@ -33,11 +33,11 @@ else CFLAGS+=-O2 -DNDEBUG endif -%.o:%.c $(HDRS) - $(CC) -c -o $@ $< $(CFLAGS) -DVERSION=\"$(VERSION)\" +%.o:%.cpp $(HDRS) + $(CXX) -c -o $@ $< $(CFLAGS) -DVERSION=\"$(VERSION)\" menu-helper: $(OBJS) - $(CC) -o $@ $^ $(LDFLAGS) + $(CXX) -o $@ $^ $(LDFLAGS) .PHONY: clean distclean install diff --git a/README.md b/README.md index 802020e..9d8c982 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Ensure the `XDG_DATA_HOME` variable is set (e.g. to `$HOME/.local/share`). To build the program you will require the following dependencies: -- A C compiler compatible with GNU99 C (preferably GCC). -- SQLite3 C library +- A C++ compiler compatible with GNU99 C (preferably GCC). +- SQLite3 C/C++ library - Make Once installed, compile the project with the `make` command. diff --git a/src/arg_parse.c b/src/arg_parse.cpp similarity index 96% rename from src/arg_parse.c rename to src/arg_parse.cpp index 038c7b7..b428043 100644 --- a/src/arg_parse.c +++ b/src/arg_parse.cpp @@ -15,9 +15,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "arg_parse.h" +#include "arg_parse.hpp" -#include "util.h" #include enum cmd_id parse_args(const char *cmd) { diff --git a/src/arg_parse.h b/src/arg_parse.hpp similarity index 100% rename from src/arg_parse.h rename to src/arg_parse.hpp diff --git a/src/cmd.c b/src/cmd.cpp similarity index 98% rename from src/cmd.c rename to src/cmd.cpp index 910dce1..d3c7ec5 100644 --- a/src/cmd.c +++ b/src/cmd.cpp @@ -15,8 +15,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "cmd.h" -#include "db.h" +#include "cmd.hpp" +#include "db.hpp" #include #include diff --git a/src/cmd.h b/src/cmd.hpp similarity index 100% rename from src/cmd.h rename to src/cmd.hpp diff --git a/src/db.c b/src/db.cpp similarity index 99% rename from src/db.c rename to src/db.cpp index 1db2381..5de802e 100644 --- a/src/db.c +++ b/src/db.cpp @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "db.h" +#include "db.hpp" #include #include diff --git a/src/db.h b/src/db.hpp similarity index 100% rename from src/db.h rename to src/db.hpp diff --git a/src/main.c b/src/main.cpp similarity index 96% rename from src/main.c rename to src/main.cpp index 1c51870..cc4a96b 100644 --- a/src/main.c +++ b/src/main.cpp @@ -18,8 +18,8 @@ #include #include -#include "arg_parse.h" -#include "cmd.h" +#include "arg_parse.hpp" +#include "cmd.hpp" int main(int argc, char *argv[]) { enum cmd_id id; diff --git a/src/util.h b/src/util.h deleted file mode 100644 index 5f306ff..0000000 --- a/src/util.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2024 Nicolás Ortega Froysa - * Nicolás Ortega Froysa - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#pragma once - -#define ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0]))