restructure as a proper C90 project; add makefiles
This commit is contained in:
parent
9fdd8eea06
commit
0ffe156bcd
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
.claude/
|
||||
.grok/
|
||||
.idea/
|
||||
cmake-build-debug/
|
||||
build/
|
||||
|
||||
32
BUILD.BAT
Normal file
32
BUILD.BAT
Normal file
@ -0,0 +1,32 @@
|
||||
@ECHO OFF
|
||||
REM Build script for cnotes - Turbo C++ 3.0 on DOS/Win32
|
||||
REM Run this if you don't have MAKE available
|
||||
REM
|
||||
REM Assumes TCC.EXE is in your PATH
|
||||
|
||||
ECHO Building cnotes with Turbo C++ 3.0...
|
||||
ECHO.
|
||||
|
||||
REM Create build directory if it doesn't exist
|
||||
IF NOT EXIST build MKDIR build
|
||||
|
||||
ECHO Compiling addnote.exe...
|
||||
TCC -A -w -ml -I.\include -ebuild\addnote.exe src\addnote.c
|
||||
IF ERRORLEVEL 1 GOTO ERROR
|
||||
|
||||
ECHO Compiling dumpnotes.exe...
|
||||
TCC -A -w -ml -I.\include -ebuild\dumpnotes.exe src\dumpnotes.c
|
||||
IF ERRORLEVEL 1 GOTO ERROR
|
||||
|
||||
ECHO.
|
||||
ECHO Build successful!
|
||||
ECHO.
|
||||
DIR build\*.EXE
|
||||
GOTO END
|
||||
|
||||
:ERROR
|
||||
ECHO.
|
||||
ECHO Build failed!
|
||||
GOTO END
|
||||
|
||||
:END
|
||||
40
MAKEFILE.TC
Normal file
40
MAKEFILE.TC
Normal file
@ -0,0 +1,40 @@
|
||||
# Makefile for cnotes - Turbo C++ 3.0 on DOS/Win32
|
||||
# Strict C89/ANSI compliant build
|
||||
#
|
||||
# Usage from DOS/Windows command line:
|
||||
# make -f makefile.tc
|
||||
#
|
||||
# Or rename to MAKEFILE and run:
|
||||
# make
|
||||
#
|
||||
# Turbo C++ 3.0 should be in PATH, or adjust CC path below.
|
||||
|
||||
CC = tcc
|
||||
CFLAGS = -A -w -ml -I.\include
|
||||
# -A = ANSI keywords only
|
||||
# -w = Enable all warnings
|
||||
# -ml = Large memory model (for DOS)
|
||||
# -I = Include path
|
||||
|
||||
SRCDIR = src
|
||||
INCDIR = include
|
||||
BUILDDIR = build
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) -c -o$*.obj $<
|
||||
|
||||
all: $(BUILDDIR) $(BUILDDIR)\addnote.exe $(BUILDDIR)\dumpnotes.exe
|
||||
|
||||
$(BUILDDIR):
|
||||
if not exist $(BUILDDIR) mkdir $(BUILDDIR)
|
||||
|
||||
$(BUILDDIR)\addnote.exe: $(SRCDIR)\addnote.c $(INCDIR)\platform.h
|
||||
$(CC) $(CFLAGS) -e$(BUILDDIR)\addnote.exe $(SRCDIR)\addnote.c
|
||||
|
||||
$(BUILDDIR)\dumpnotes.exe: $(SRCDIR)\dumpnotes.c $(INCDIR)\platform.h
|
||||
$(CC) $(CFLAGS) -e$(BUILDDIR)\dumpnotes.exe $(SRCDIR)\dumpnotes.c
|
||||
|
||||
clean:
|
||||
if exist $(BUILDDIR)\*.exe del $(BUILDDIR)\*.exe
|
||||
if exist $(BUILDDIR)\*.obj del $(BUILDDIR)\*.obj
|
||||
if exist $(BUILDDIR) rmdir $(BUILDDIR)
|
||||
39
Makefile
Normal file
39
Makefile
Normal file
@ -0,0 +1,39 @@
|
||||
# Makefile for cnotes - GCC on Linux/Unix/macOS
|
||||
# Strict C89/ANSI compliant build
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -ansi -pedantic -Wall -Wextra -O2
|
||||
INCLUDES = -I include
|
||||
|
||||
SRCDIR = src
|
||||
INCDIR = include
|
||||
BUILDDIR = build
|
||||
|
||||
SOURCES = $(SRCDIR)/addnote.c $(SRCDIR)/dumpnotes.c
|
||||
HEADERS = $(INCDIR)/platform.h
|
||||
|
||||
TARGETS = $(BUILDDIR)/addnote $(BUILDDIR)/dumpnotes
|
||||
|
||||
.PHONY: all clean install uninstall
|
||||
|
||||
all: $(BUILDDIR) $(TARGETS)
|
||||
|
||||
$(BUILDDIR):
|
||||
mkdir -p $(BUILDDIR)
|
||||
|
||||
$(BUILDDIR)/addnote: $(SRCDIR)/addnote.c $(HEADERS)
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $(SRCDIR)/addnote.c
|
||||
|
||||
$(BUILDDIR)/dumpnotes: $(SRCDIR)/dumpnotes.c $(HEADERS)
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -o $@ $(SRCDIR)/dumpnotes.c
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)
|
||||
|
||||
# Install to /usr/local/bin (optional, run with sudo)
|
||||
install: $(TARGETS)
|
||||
install -m 755 $(BUILDDIR)/addnote /usr/local/bin/
|
||||
install -m 755 $(BUILDDIR)/dumpnotes /usr/local/bin/
|
||||
|
||||
uninstall:
|
||||
rm -f /usr/local/bin/addnote /usr/local/bin/dumpnotes
|
||||
@ -3,7 +3,6 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
@ -38,9 +37,9 @@ int get_cnotes_path(char *buffer, size_t bufsize) {
|
||||
const char *home;
|
||||
size_t len;
|
||||
|
||||
home = getenv("HOME");
|
||||
home = getenv(HOME_ENV);
|
||||
if (home == NULL) {
|
||||
fprintf(stderr, "Error: HOME environment variable not set\n");
|
||||
fprintf(stderr, "Error: %s environment variable not set\n", HOME_ENV);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -51,7 +50,7 @@ int get_cnotes_path(char *buffer, size_t bufsize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sprintf(buffer, "%s/%s", home, CNOTES_DIR);
|
||||
sprintf(buffer, "%s" PATH_SEP_STR "%s", home, CNOTES_DIR);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -109,7 +108,7 @@ int write_entry(const char *category, const char *message) {
|
||||
}
|
||||
|
||||
/* Build full file path */
|
||||
sprintf(file_path, "%s/%s", dir_path, CNOTES_FILE);
|
||||
sprintf(file_path, "%s" PATH_SEP_STR "%s", dir_path, CNOTES_FILE);
|
||||
|
||||
/* Open file in append mode */
|
||||
file = fopen(file_path, "a");
|
||||
@ -5,6 +5,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "platform.h"
|
||||
|
||||
#define MAX_LENGTH 500 /* Allow fgets to read up to this many characters */
|
||||
#define DATE_LENGTH 10 /* YYYY-MM-DD */
|
||||
@ -101,7 +102,7 @@ void print_entry(const Entry *entry) {
|
||||
|
||||
/* Parse a fixed-length field followed by a delimiter */
|
||||
static const char *parse_fixed_field(const char *ptr, char *dest, int length, char delimiter) {
|
||||
if (strlen(ptr) < length) return NULL;
|
||||
if ((int)strlen(ptr) < length) return NULL;
|
||||
strncpy(dest, ptr, length);
|
||||
dest[length] = '\0';
|
||||
ptr += length;
|
||||
@ -152,9 +153,9 @@ int get_cnotes_path(char *buffer, size_t bufsize) {
|
||||
const char *home;
|
||||
size_t len;
|
||||
|
||||
home = getenv("HOME");
|
||||
home = getenv(HOME_ENV);
|
||||
if (home == NULL) {
|
||||
fprintf(stderr, "Error: HOME environment variable not set\n");
|
||||
fprintf(stderr, "Error: %s environment variable not set\n", HOME_ENV);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -165,20 +166,27 @@ int get_cnotes_path(char *buffer, size_t bufsize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sprintf(buffer, "%s/%s/%s", home, CNOTES_DIR, CNOTES_FILE);
|
||||
sprintf(buffer, "%s" PATH_SEP_STR "%s" PATH_SEP_STR "%s", home, CNOTES_DIR, CNOTES_FILE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* start with a simple cat of the file */
|
||||
int main(int argc, char *argv[]) {
|
||||
int i;
|
||||
FILE *notesfile;
|
||||
char file_path[600];
|
||||
Entry entries[MAX_ENTRIES];
|
||||
Entry *entries;
|
||||
int entry_count = 0;
|
||||
char line[MAX_LENGTH +1];
|
||||
char *filename = CNOTES_FILE;
|
||||
char *filename = NULL;
|
||||
SortMode sort_mode = SORT_NONE;
|
||||
int i;
|
||||
|
||||
/* Insures that we won't run out of memory in DOS */
|
||||
entries = (Entry *)malloc(MAX_ENTRIES * sizeof(Entry));
|
||||
if (entries == NULL) {
|
||||
fprintf(stderr, "Error: Cannot allocate memory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Parse command line arguments */
|
||||
for (i = 1; i < argc; i++) {
|
||||
@ -209,6 +217,9 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: filename argument is parsed but not yet used */
|
||||
(void)filename;
|
||||
|
||||
/* Get cnotes file path */
|
||||
if (!get_cnotes_path(file_path, sizeof(file_path))) {
|
||||
return 1;
|
||||
@ -247,5 +258,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
print_footer();
|
||||
|
||||
free(entries);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user