Steve,
Here is a gcc example of how to create a library using a make file.
James
c Files placed in their own directory:
cls.c
#include <windows.h>
void cls(void)
{
system("cls");
}
Locate.c
#include <windows.h>
void locate(int cx, int cy)
{
COORD coordScreen;
HANDLE hConsole;
coordScreen.X = cx;
coordScreen.Y = cy;
/* Get this console handle */
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
/* Put the cursor at its coordinates */
SetConsoleCursorPosition(hConsole, coordScreen);
}
color.c
#include <windows.h>
void color (int fg,int bg)
{
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute (hConsole,fg+bg*16);
}
StrToFloat
#include <stdlib.h>
void StrToFloat(char *NumStr, double *result)
{
*result = atof(NumStr);
}
FloateToStr2
#include <string.h>
#include <windows.h>
void FloatToStr2(double orgvalue, char *buffer)
{ char asciiValue[30];
int len;
gcvt(orgvalue, 80, buffer); /* convert double to ascii */
len = strlen(buffer);
len--;
if(buffer[len] == '.')
{ /* if this is an integer, get rid */
buffer[len] = '\0'; /* of trailing decimal point. */
}
if(orgvalue >= 0)
{
strcpy(asciiValue, " "); /* add leading blank space */
strcat(asciiValue, buffer);
strcpy(buffer, asciiValue);
}
}
Value2Str.c
#include <stdio.h>
#include <string.h>
char * value2strng(double value, char vartype)
{ static char buffer[81];
int len, idx=0, dot=0;
char ch, chx = vartype;
// char ch, chx='#';
// double value = 10;
/* --- convert to ascii, here --- */
sprintf(buffer, "% f", value);
len = strlen(buffer);
ch = buffer[idx];
/* --- trim trailing zeros --- */
if(chx == '#') /* Double: '#' */
{
idx = (len-1);
ch = buffer[idx];
while(ch == '0')
{
idx--;
ch = buffer[idx];
}
buffer[(idx+1)] = '\0';
}
/* --- round up to .nn --- */
else if(chx == '!') /* Single: '!' */
{
dot = (len-5);
idx = (len-1);
while(idx > dot)
{
if((buffer[idx] >= '5') && (buffer[(idx-1)] == '9'))
{
buffer[idx] = '\0';
}
else if(buffer[idx] >= '5')
{
buffer[(idx-1)]++;
buffer[idx] = '\0';
}
else
{
buffer[idx] = '\0';
}
idx--;
}
}
/* --- trim to dot --- */
else /* Integers: '%' */
{
idx = (len-7);
buffer[idx] = '\0';
}
return buffer;
}
The make file to compile and add all to a library.
AR = ar rcs
CC = gcc
OBJECTS = cls.o locate.o color.o StrToFloat.o FloatToStr2.o Value2Str.o
all : library clean_object_files
@echo Successful Build
#----------------------------------------
# compile all the *.c files in the directory
#----------------------------------------
%.o : %.c
$(CC) -Wall -c $<
#----------------------------------------
# create the library from the list of object files
#----------------------------------------
library : $(OBJECTS)
$(AR) libbxbasm.a $(OBJECTS)
#----------------------------------------
#remove all the object files
#----------------------------------------
clean_object_files :
@echo Cleaning Up
@del *.o
#----------------------------------------
#remove the object files and the library
#----------------------------------------
clean : clean_object_files
@echo Removing All Object and Library Files
@del *.a