Skip to content

Commit

Permalink
Initial code.
Browse files Browse the repository at this point in the history
  • Loading branch information
waynegramlich committed Sep 1, 2013
1 parent cc2522e commit 05f4df3
Show file tree
Hide file tree
Showing 19 changed files with 635 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*~
*.o
*.d
Tags
Tags.ezc
6 changes: 6 additions & 0 deletions Double.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) 2013 by Wayne C. Gramlich. All rights reserved.

#include "Double.h"

// Any *Double* support code goes here.

10 changes: 10 additions & 0 deletions Double.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2013 by Wayne C. Gramlich. All rights reserved.

#if !defined(DOUBLE_H_INCLUDED)
#define DOUBLE_H_INCLUDED 1

/// @brief *Double* is a double precision (64-bits) floating point number.
typedef double Double;

#endif // !defined(DOUBLE_H_INCLUDED)

46 changes: 46 additions & 0 deletions File.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2013 by Wayne C. Gramlich all rights reserved.

#include <assert.h>

#include "File.h"
#include "String.h"

// *File* routines:

/// @brief Closes *file*.
/// @param file to close.
///
/// *File__close*() will close *file*.

void File__close(File file) {
assert (fclose(file) == 0);
}

/// @brief will write *format* out to *file* with all patterns that
/// start with "%" replaced by formatted versions of its arguments.
/// @param file to output to.
/// @parma format is the formatting string.
///
/// *File__format*() will write *format* out to *file* with all patterns that
/// start with "%" replaced by formatted versions of its arguments.

void File__format(File file, String format, ...) {
// Set up *variadic_arguments to start after *format*:
va_list variadic_arguments;
va_start(variadic_arguments, format);

// Perform the format:
Unsigned formatted_size = vfprintf(file, format, variadic_arguments);
}

/// @brief will open *file_name* using *flags* to specify read/write options.
/// @param file_name is the file name to open.
/// @param flags specify the read/write options.
///
/// *File__open*() will open *file_name* using *flags* to read/write options.
/// An open *File* object is returned or (*File)0 if the open failed.

File File__open(String file_name, String flags) {
return fopen(file_name, flags);
}

19 changes: 19 additions & 0 deletions File.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2013 by Wayne C. Gramlich. All rights reserved.

#if !defined(FILE_H_INCLUDED)
#define FILE_H_INCLUDED 1

#include <stdio.h>
#include <stdarg.h>

#include "String.h"

/// @brief *FILE* is a file I/O object.
typedef FILE *File;

// External declarations:
extern void File__close(File file);
extern void File__format(File file, String format, ...);
extern File File__open(String file_name, String flags);

#endif // !defined(FILE_H_INCLUDED)
Empty file added Integer.c
Empty file.
10 changes: 10 additions & 0 deletions Integer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2013 by Wayne C. Gramlich. All rights reserved.

#if !defined(INTEGER_H_INCLUDED)
#define INTEGER_H_INCLUDED 1

/// @brief *Integer* is a 32-bit signed integer.
typedef int Integer;

#endif // !defined(INTEGER_H_INCLUDED)

5 changes: 5 additions & 0 deletions Logical.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) by Wayne C. Gramlich. All rights reserved.

#include "Logical.h"

// Any *Logical* support code goes here.
9 changes: 9 additions & 0 deletions Logical.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// Copyright (c) 2013 by Wayne C. Gramlich. All rights reserved.

#if !defined(LOGICAL_H_INCLUDED)
#define LOGICAL_H_INCLUDED 1

/// @brief *Logical* is a true/false value.
typedef int Logical;

#endif // !defined(LOGICAL_H_INCLUDED)
79 changes: 79 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright (c) 2013 by Wayne C. Gramlich. All rights reserved.


C_WARNING_OPTIONS := \
-Wreturn-type \
-Wno-missing-braces \
-Wextra \
-Wno-missing-field-initializers \
-Wformat=2 \
-Wswitch-default \
-Wcast-align \
-Wpointer-arith \
-Wbad-function-cast \
-Wstrict-overflow=5 \
-Wstrict-prototypes \
-Winline \
-Wundef \
-Wcast-qual \
-Wshadow \
-Wunreachable-code \
-Wlogical-op \
-Wfloat-equal \
-Wstrict-aliasing=2 \
-Wold-style-definition \
-Werror \

C_OPTIONS := \
-std=c11 \
-g \
-MMD \
${C_WARNING_OPTIONS} \

CC := gcc ${C_OPTIONS}

COMMON_O_FILES := \
Double.o \
File.o \
Integer.o \
Logical.o \
Memory.o \
String.o \
SVG.o \
Unsigned.o \

TAGS_O_FILES := \
Tags.o \

ALL_O_FILES := \
${COMMON_O_FILES} \
${TAGS_O_FILES} \

ALL_C_BACKUPS := ${ALL_O_FILES:%.o=%.c~}
ALL_D_FILES := ${ALL_O_FILES:%.o=%.d}
ALL_H_BACKUPS := ${ALL_O_FILES:%.o=%.h~}

PROGRAMS := \
Tags \

all: ${PROGRAMS}

Tags: ${COMMON_O_FILES} ${TAGS_O_FILES}
$(CC) -o $@ ${TAGS_O_FILES} ${COMMON_O_FILES}

clean:
rm -f ${ALL_C_BACKUPS}
rm -f ${ALL_D_FILES}
rm -f ${ALL_H_BACKUPS}
rm -f ${ALL_O_FILES}
rm -f ${PROGRAMS}
rm Makefile~ Tags.ezc~

%.o: %c
$(CC) -c -o $@ $<


# Used with gcc -MMD option to force automagic dependency checking:
-include ${ALL_D_FILES}


28 changes: 28 additions & 0 deletions Memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2013 by Wayne C. Gramlich. All rights reserved.

#include <assert.h>
#include <stdlib.h>
#include "Unsigned.h"
#include "Memory.h"

/// @brief Allocates *bytes* of memory and returns a pointer to it.
/// @param bytes is the number of bytes to allocate.
/// @returns a pointer to the allocated memory chunk.
///
/// *Memory__allocate*() will allocated and return a pointer to a chunk
/// of *bytes* memory.

Memory Memory__allocate(Unsigned bytes) {
Memory memory = (Memory)malloc(bytes);
assert (memory != (Memory)0);
return memory;
}

/// @brief Releases the storage associated with *memory*.
/// @param memory to release.
///
/// *Memory__free*() will release the storage associated with *memory*.

void Memory__free(Memory memory) {
free(memory);
}
35 changes: 35 additions & 0 deletions Memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2013 by Wayne C. Gramlich. All rights reserved.

#if !defined(MEMORY_H_INCLUDED)
#define MEMORY_H_INCLUDED 1

/// @brief Allocate a *Type* object from the heap.
///
/// The type must be a pointer type where the underlying type defintion
/// is available to the compiler.
///
/// This allocates an object of type *Type* by doing "Memory_new(Type)".
/// This macro when expanded works as follows:
///
/// Type zilch = (Type)0;
/// UInteger type_size = sizeof(*zilch);
/// Type type = (Type)Memory_allocate(type_size);
///
/// "sizeof(*((Type)0))" does not generate any code. The compiler
/// evaluates it to get the number of bytes associated with "Type":

#define Memory__new(Type) ((Type)Memory__allocate(sizeof(*((Type)0))))

/// @brief *Memory* is a pointer to memory.
typedef void *Memory;

#include "Unsigned.h"

// Extern declarations:

extern Memory Memory__allocate(Unsigned bytes);
extern void Memory__free(Memory memory);


#endif // !defined(MEMORY_H_INCLUDED)

Loading

0 comments on commit 05f4df3

Please sign in to comment.