Move to gitHub the edn project (remove history keep it on my nas)
This commit is contained in:
168
tools/exampleCustumWidget/Makefile
Normal file
168
tools/exampleCustumWidget/Makefile
Normal file
@@ -0,0 +1,168 @@
|
||||
##################################################################################################################
|
||||
# #
|
||||
# Fichier : Makefile #
|
||||
# #
|
||||
# Type : Makefile d'un programme complet #
|
||||
# #
|
||||
# Auteur : Heero Yui #
|
||||
# #
|
||||
# Evolutions : Date Auteur Raison #
|
||||
# 2010-01-29 Heero Yui Mise en place d'un makefile ultra simple #
|
||||
# #
|
||||
# Concu Pour le projet edn #
|
||||
# #
|
||||
##################################################################################################################
|
||||
export F_GRAS=[1m
|
||||
export F_INVERSER=[7m
|
||||
export F_SOUSLIGNER=[4m
|
||||
export F_NORMALE=[m
|
||||
export F_NOIR=[31m
|
||||
export F_ROUGE=[31m
|
||||
export F_VERT=[32m
|
||||
export F_MARRON=[33m
|
||||
export F_BLUE=[34m
|
||||
export F_VIOLET=[35m
|
||||
export F_CYAN=[36m
|
||||
export F_GRIS=[37m
|
||||
export CADRE_HAUT_BAS=' $(F_INVERSER) $(F_NORMALE)'
|
||||
export CADRE_COTERS='
|
||||
$(F_INVERSER) $(F_NORMALE) $(F_INVERSER) $(F_NORMALE)'
|
||||
|
||||
|
||||
###############################################################################
|
||||
### Compilateur base system ###
|
||||
###############################################################################
|
||||
CXX=$(BIN_PREFIX)g++
|
||||
CC=$(BIN_PREFIX)gcc
|
||||
AR=$(BIN_PREFIX)ar
|
||||
|
||||
###############################################################################
|
||||
### Compilation Define ###
|
||||
###############################################################################
|
||||
DEFINE= -DEDN_DEBUG_LEVEL=3
|
||||
|
||||
|
||||
|
||||
|
||||
###############################################################################
|
||||
### Basic Cfags ###
|
||||
###############################################################################
|
||||
|
||||
# basic GTK librairy
|
||||
CXXFLAGS= `pkg-config --cflags --libs gtk+-2.0`
|
||||
#CXXFLAGS= `wx-config --libs --cppflags`
|
||||
# Linux thread system
|
||||
CXXFLAGS+= -lpthread
|
||||
# Enable debug (cgdb edn)
|
||||
CXXFLAGS+= -g -O0
|
||||
#CXXFLAGS+= -O2
|
||||
# display all flags
|
||||
CXXFLAGS+= -Wall
|
||||
# ...
|
||||
CXXFLAGS+= -D_REENTRANT
|
||||
# internal defines
|
||||
CXXFLAGS+= $(DEFINE)
|
||||
|
||||
CFLAGS= $(CXXFLAGS) -std=c99
|
||||
|
||||
# basic GTK librairy
|
||||
LDFLAGS= `pkg-config --cflags --libs gtk+-2.0`
|
||||
#LDFLAGS= `wx-config --libs --cppflags`
|
||||
# Linux thread system
|
||||
LDFLAGS+= -lpthread
|
||||
# Dynamic connection of the CALLBACK of the GUI
|
||||
LDFLAGS+= -Wl,--export-dynamic
|
||||
|
||||
###############################################################################
|
||||
### Project Name ###
|
||||
###############################################################################
|
||||
OUTPUT_NAME=example
|
||||
|
||||
###############################################################################
|
||||
### Basic Project description Files ###
|
||||
###############################################################################
|
||||
FILE_DIRECTORY=Sources
|
||||
OBJECT_DIRECTORY=Object
|
||||
|
||||
###############################################################################
|
||||
### Generique dependency ###
|
||||
###############################################################################
|
||||
MAKE_DEPENDENCE=Makefile
|
||||
|
||||
###############################################################################
|
||||
### Liste of folder where .h can be ###
|
||||
###############################################################################
|
||||
LISTE_MODULES = .
|
||||
|
||||
|
||||
INCLUDE_DIRECTORY = $(addprefix -I$(FILE_DIRECTORY)/, $(LISTE_MODULES))
|
||||
|
||||
###############################################################################
|
||||
### Files Listes ###
|
||||
###############################################################################
|
||||
|
||||
CFILES= \
|
||||
main.c \
|
||||
cpu.c \
|
||||
###############################################################################
|
||||
### Build Object Files List ###
|
||||
###############################################################################
|
||||
OBJ = $(addprefix $(OBJECT_DIRECTORY)/, $(CFILES:.c=.o))
|
||||
|
||||
|
||||
|
||||
###############################################################################
|
||||
### Main Part of Makefile ###
|
||||
###############################################################################
|
||||
all: build
|
||||
|
||||
-include $(OBJ:.o=.d)
|
||||
|
||||
build: .encadrer $(OUTPUT_NAME) $(MAKE_DEPENDENCE)
|
||||
|
||||
.encadrer:
|
||||
@echo $(CADRE_HAUT_BAS)
|
||||
@echo $(CADRE_COTERS)
|
||||
@echo ' DEBUT DE COMPILATION DU PROGRAMME :'$(CADRE_COTERS)
|
||||
@echo ' Repertoire Sources : $(FILE_DIRECTORY)/'$(CADRE_COTERS)
|
||||
@echo ' Repertoire object : $(OBJECT_DIRECTORY)/'$(CADRE_COTERS)
|
||||
@echo ' Binaire de sortie : $(F_VIOLET)$(OUTPUT_NAME) / $(OUTPUT_NAME)-stripped$(F_NORMALE)'$(CADRE_COTERS)
|
||||
@echo $(CADRE_COTERS)
|
||||
@echo $(CADRE_HAUT_BAS)
|
||||
@mkdir -p $(OBJECT_DIRECTORY)/
|
||||
|
||||
|
||||
|
||||
|
||||
# build C
|
||||
$(OBJECT_DIRECTORY)/%.o: $(FILE_DIRECTORY)/%.c $(MAKE_DEPENDENCE)
|
||||
@echo $(F_VERT)" (.o) $<"$(F_NORMALE)
|
||||
@#echo $(CXX) $< -c -o $@ $(INCLUDE_DIRECTORY) $(CXXFLAGS) -MMD
|
||||
@$(CXX) $< -c -o $@ $(INCLUDE_DIRECTORY) $(CXXFLAGS) -MMD
|
||||
|
||||
# build C++
|
||||
$(OBJECT_DIRECTORY)/%.o: $(FILE_DIRECTORY)/%.cpp $(MAKE_DEPENDENCE)
|
||||
@echo $(F_VERT)" (.o) $<"$(F_NORMALE)
|
||||
@#echo $(CXX) $< -c -o $@ $(INCLUDE_DIRECTORY) $(CXXFLAGS) -MMD
|
||||
@$(CXX) $< -c -o $@ $(INCLUDE_DIRECTORY) $(CXXFLAGS) -MMD
|
||||
|
||||
# build binary
|
||||
$(OUTPUT_NAME): $(OBJ)
|
||||
@echo $(F_ROUGE)" (bin) $@ & $@-stripped"$(F_NORMALE)
|
||||
@$(CXX) $(OBJ) $(LDFLAGS) -o $@
|
||||
@cp $@ $@-stripped
|
||||
@strip -s $@-stripped
|
||||
|
||||
|
||||
clean:
|
||||
@echo $(CADRE_HAUT_BAS)
|
||||
@echo ' CLEANING : $(F_VIOLET)$(OUTPUT_NAME)$(F_NORMALE)'$(CADRE_COTERS)
|
||||
@echo $(CADRE_HAUT_BAS)
|
||||
@echo Remove Folder : $(OBJECT_DIRECTORY)
|
||||
@rm -rf $(OBJECT_DIRECTORY)
|
||||
@echo Remove File : $(OUTPUT_NAME)
|
||||
@rm -f $(OUTPUT_NAME)
|
||||
@echo Remove File : $(OUTPUT_NAME)-stripped
|
||||
@rm -f $(OUTPUT_NAME)-stripped
|
||||
|
||||
|
205
tools/exampleCustumWidget/Sources/cpu.c
Normal file
205
tools/exampleCustumWidget/Sources/cpu.c
Normal file
@@ -0,0 +1,205 @@
|
||||
/* cpu.c */
|
||||
|
||||
#include "cpu.h"
|
||||
|
||||
|
||||
static void gtk_cpu_class_init(GtkCpuClass *klass);
|
||||
static void gtk_cpu_init(GtkCpu *cpu);
|
||||
static void gtk_cpu_size_request(GtkWidget *widget, GtkRequisition *requisition);
|
||||
static void gtk_cpu_size_allocate(GtkWidget *widget, GtkAllocation *allocation);
|
||||
static void gtk_cpu_realize(GtkWidget *widget);
|
||||
static gboolean gtk_cpu_expose(GtkWidget *widget, GdkEventExpose *event);
|
||||
static void gtk_cpu_paint(GtkWidget *widget);
|
||||
static void gtk_cpu_destroy(GtkObject *object);
|
||||
|
||||
|
||||
GtkType gtk_cpu_get_type(void)
|
||||
{
|
||||
static GtkType gtk_cpu_type = 0;
|
||||
|
||||
if (!gtk_cpu_type) {
|
||||
static const GtkTypeInfo gtk_cpu_info = {
|
||||
"GtkCpu",
|
||||
sizeof(GtkCpu),
|
||||
sizeof(GtkCpuClass),
|
||||
(GtkClassInitFunc) gtk_cpu_class_init,
|
||||
(GtkObjectInitFunc) gtk_cpu_init,
|
||||
NULL,
|
||||
NULL,
|
||||
(GtkClassInitFunc) NULL
|
||||
};
|
||||
gtk_cpu_type = gtk_type_unique(GTK_TYPE_WIDGET, >k_cpu_info);
|
||||
}
|
||||
|
||||
|
||||
return gtk_cpu_type;
|
||||
}
|
||||
|
||||
void gtk_cpu_set_state(GtkCpu *cpu, gint num)
|
||||
{
|
||||
cpu->sel = num;
|
||||
gtk_cpu_paint(GTK_WIDGET(cpu));
|
||||
}
|
||||
|
||||
|
||||
GtkWidget * gtk_cpu_new()
|
||||
{
|
||||
return GTK_WIDGET(gtk_type_new(gtk_cpu_get_type()));
|
||||
}
|
||||
|
||||
|
||||
static void gtk_cpu_class_init(GtkCpuClass *klass)
|
||||
{
|
||||
GtkWidgetClass *widget_class;
|
||||
GtkObjectClass *object_class;
|
||||
|
||||
|
||||
widget_class = (GtkWidgetClass *) klass;
|
||||
object_class = (GtkObjectClass *) klass;
|
||||
|
||||
widget_class->realize = gtk_cpu_realize;
|
||||
widget_class->size_request = gtk_cpu_size_request;
|
||||
widget_class->size_allocate = gtk_cpu_size_allocate;
|
||||
widget_class->expose_event = gtk_cpu_expose;
|
||||
|
||||
object_class->destroy = gtk_cpu_destroy;
|
||||
}
|
||||
|
||||
|
||||
static void gtk_cpu_init(GtkCpu *cpu)
|
||||
{
|
||||
cpu->sel = 0;
|
||||
}
|
||||
|
||||
|
||||
static void gtk_cpu_size_request(GtkWidget *widget,
|
||||
GtkRequisition *requisition)
|
||||
{
|
||||
g_return_if_fail(widget != NULL);
|
||||
g_return_if_fail(GTK_IS_CPU(widget));
|
||||
g_return_if_fail(requisition != NULL);
|
||||
|
||||
requisition->width = 80;
|
||||
requisition->height = 100;
|
||||
}
|
||||
|
||||
|
||||
static void gtk_cpu_size_allocate(GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
g_return_if_fail(widget != NULL);
|
||||
g_return_if_fail(GTK_IS_CPU(widget));
|
||||
g_return_if_fail(allocation != NULL);
|
||||
|
||||
widget->allocation = *allocation;
|
||||
|
||||
if (GTK_WIDGET_REALIZED(widget)) {
|
||||
gdk_window_move_resize(
|
||||
widget->window,
|
||||
allocation->x, allocation->y,
|
||||
allocation->width, allocation->height
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void gtk_cpu_realize(GtkWidget *widget)
|
||||
{
|
||||
GdkWindowAttr attributes;
|
||||
guint attributes_mask;
|
||||
|
||||
g_return_if_fail(widget != NULL);
|
||||
g_return_if_fail(GTK_IS_CPU(widget));
|
||||
|
||||
GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
|
||||
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
attributes.x = widget->allocation.x;
|
||||
attributes.y = widget->allocation.y;
|
||||
attributes.width = 80;
|
||||
attributes.height = 100;
|
||||
|
||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||
attributes.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK;
|
||||
|
||||
attributes_mask = GDK_WA_X | GDK_WA_Y;
|
||||
|
||||
widget->window = gdk_window_new(
|
||||
gtk_widget_get_parent_window (widget),
|
||||
& attributes, attributes_mask
|
||||
);
|
||||
|
||||
gdk_window_set_user_data(widget->window, widget);
|
||||
|
||||
widget->style = gtk_style_attach(widget->style, widget->window);
|
||||
gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
static gboolean gtk_cpu_expose(GtkWidget *widget, GdkEventExpose *event)
|
||||
{
|
||||
g_return_val_if_fail(widget != NULL, FALSE);
|
||||
g_return_val_if_fail(GTK_IS_CPU(widget), FALSE);
|
||||
g_return_val_if_fail(event != NULL, FALSE);
|
||||
|
||||
gtk_cpu_paint(widget);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static void gtk_cpu_paint(GtkWidget *widget)
|
||||
{
|
||||
cairo_t *cr;
|
||||
|
||||
cr = gdk_cairo_create(widget->window);
|
||||
|
||||
cairo_translate(cr, 0, 7);
|
||||
|
||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||
cairo_paint(cr);
|
||||
|
||||
gint pos = GTK_CPU(widget)->sel;
|
||||
gint rect = pos / 5;
|
||||
|
||||
cairo_set_source_rgb(cr, 0.2, 0.4, 0);
|
||||
|
||||
gint i;
|
||||
for ( i = 1; i <= 20; i++) {
|
||||
if (i > 20 - rect) {
|
||||
cairo_set_source_rgb(cr, 0.6, 1.0, 0);
|
||||
} else {
|
||||
cairo_set_source_rgb(cr, 0.2, 0.4, 0);
|
||||
}
|
||||
cairo_rectangle(cr, 8, i*4, 30, 3);
|
||||
cairo_fill(cr);
|
||||
if (i > 20 - rect) {
|
||||
cairo_set_source_rgb(cr, 0.9, 1.0, 0);
|
||||
} else {
|
||||
cairo_set_source_rgb(cr, 0.4, 0.4, 0);
|
||||
}
|
||||
cairo_rectangle(cr, 42, i*4, 30, 3);
|
||||
cairo_fill(cr);
|
||||
}
|
||||
|
||||
cairo_destroy(cr);
|
||||
}
|
||||
|
||||
|
||||
static void gtk_cpu_destroy(GtkObject *object)
|
||||
{
|
||||
GtkCpu *cpu;
|
||||
GtkCpuClass *klass;
|
||||
|
||||
g_return_if_fail(object != NULL);
|
||||
g_return_if_fail(GTK_IS_CPU(object));
|
||||
|
||||
cpu = GTK_CPU(object);
|
||||
/*
|
||||
klass = gtk_type_class( gtk_widget_get_type() );
|
||||
|
||||
if (GTK_OBJECT_CLASS(klass)->destroy) {
|
||||
(* GTK_OBJECT_CLASS(klass)->destroy) (object);
|
||||
}
|
||||
*/
|
||||
}
|
39
tools/exampleCustumWidget/Sources/cpu.h
Normal file
39
tools/exampleCustumWidget/Sources/cpu.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* cpu.h */
|
||||
|
||||
#ifndef __CPU_H
|
||||
#define __CPU_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <cairo.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
#define GTK_CPU(obj) GTK_CHECK_CAST(obj, gtk_cpu_get_type (), GtkCpu)
|
||||
#define GTK_CPU_CLASS(klass) GTK_CHECK_CLASS_CAST(klass, gtk_cpu_get_type(), GtkCpuClass)
|
||||
#define GTK_IS_CPU(obj) GTK_CHECK_TYPE(obj, gtk_cpu_get_type())
|
||||
|
||||
|
||||
typedef struct _GtkCpu GtkCpu;
|
||||
typedef struct _GtkCpuClass GtkCpuClass;
|
||||
|
||||
|
||||
struct _GtkCpu {
|
||||
GtkWidget widget;
|
||||
|
||||
gint sel;
|
||||
};
|
||||
|
||||
struct _GtkCpuClass {
|
||||
GtkWidgetClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
GtkType gtk_cpu_get_type(void);
|
||||
void gtk_cpu_set_sel(GtkCpu *cpu, gint sel);
|
||||
GtkWidget * gtk_cpu_new();
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CPU_H */
|
61
tools/exampleCustumWidget/Sources/main.c
Normal file
61
tools/exampleCustumWidget/Sources/main.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* main.c */
|
||||
|
||||
#include "cpu.h"
|
||||
|
||||
|
||||
static void set_value(GtkWidget * widget, gpointer data)
|
||||
{
|
||||
GdkRegion *region;
|
||||
|
||||
GtkRange *range = (GtkRange *) widget;
|
||||
GtkWidget *cpu = (GtkWidget *) data;
|
||||
GTK_CPU(cpu)->sel = gtk_range_get_value(range);
|
||||
|
||||
region = gdk_drawable_get_clip_region(cpu->window);
|
||||
gdk_window_invalidate_region(cpu->window, region, TRUE);
|
||||
gdk_window_process_updates(cpu->window, TRUE);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
GtkWidget *window;
|
||||
GtkWidget *cpu;
|
||||
GtkWidget *fixed;
|
||||
GtkWidget *scale;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
|
||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_title(GTK_WINDOW(window), "CPU widget");
|
||||
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
|
||||
gtk_window_set_default_size(GTK_WINDOW(window), 200, 180);
|
||||
|
||||
|
||||
g_signal_connect(G_OBJECT(window), "destroy",
|
||||
G_CALLBACK(gtk_main_quit), NULL);
|
||||
|
||||
fixed = gtk_fixed_new();
|
||||
gtk_container_add(GTK_CONTAINER(window), fixed);
|
||||
|
||||
cpu = gtk_cpu_new();
|
||||
gtk_fixed_put(GTK_FIXED(fixed), cpu, 30, 40);
|
||||
|
||||
|
||||
scale = gtk_vscale_new_with_range(0.0, 100.0, 1.0);
|
||||
gtk_range_set_inverted(GTK_RANGE(scale), TRUE);
|
||||
gtk_scale_set_value_pos(GTK_SCALE(scale), GTK_POS_TOP);
|
||||
gtk_widget_set_size_request(scale, 50, 120);
|
||||
gtk_fixed_put(GTK_FIXED(fixed), scale, 130, 20);
|
||||
|
||||
g_signal_connect(G_OBJECT(scale), "value_changed",
|
||||
G_CALLBACK(set_value), (gpointer) cpu);
|
||||
|
||||
gtk_widget_show(cpu);
|
||||
gtk_widget_show(fixed);
|
||||
gtk_widget_show_all(window);
|
||||
gtk_main();
|
||||
|
||||
return 0;
|
||||
}
|
202
tools/pngToCpp/pngToCpp.c
Normal file
202
tools/pngToCpp/pngToCpp.c
Normal file
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file pngToCpp.cpp
|
||||
* @brief convert a binary file into a C source vector
|
||||
* @author Sandro Sigala
|
||||
* @date 26/01/2011
|
||||
* @par Project
|
||||
* ---
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
* @compilation g++ pngToCpp -o pngToCpp
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
bool zeroTerminated = false;
|
||||
|
||||
int myfgetc(FILE *f)
|
||||
{
|
||||
int c = fgetc(f);
|
||||
if (c == EOF && zeroTerminated)
|
||||
{
|
||||
zeroTerminated = 0;
|
||||
return 0;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void generateHeader(FILE *file)
|
||||
{
|
||||
fprintf(file, "/**\n");
|
||||
fprintf(file, " ******************************************************************************* \n");
|
||||
fprintf(file, " * \n");
|
||||
fprintf(file, " * @par Project\n");
|
||||
fprintf(file, " * Edn\n");
|
||||
fprintf(file, " * \n");
|
||||
fprintf(file, " * Automatic generated file for Edn Software\n");
|
||||
fprintf(file, " * Please do not save this file on File configuration server\n");
|
||||
fprintf(file, " * \n");
|
||||
fprintf(file, " * @par Copyright\n");
|
||||
fprintf(file, " * \n");
|
||||
fprintf(file, " * Copyright 2010 Edouard DUPIN, all right reserved\n");
|
||||
fprintf(file, " * \n");
|
||||
fprintf(file, " * his software is distributed in the hope that it will be useful, but WITHOUT\n");
|
||||
fprintf(file, " * ANY WARRANTY.\n");
|
||||
fprintf(file, " * \n");
|
||||
fprintf(file, " * Licence summary : \n");
|
||||
fprintf(file, " * You can modify and redistribute the sources code and binaries.\n");
|
||||
fprintf(file, " * You can send me the bug-fix\n");
|
||||
fprintf(file, " * You can not earn money with this Software (if the source extract from Edn\n");
|
||||
fprintf(file, " * represent less than 50/100 of original Sources)\n");
|
||||
fprintf(file, " * Term of the licence in in the file licence.txt.\n");
|
||||
fprintf(file, " * \n");
|
||||
fprintf(file, " ******************************************************************************* \n");
|
||||
fprintf(file, " */\n\n");
|
||||
}
|
||||
|
||||
FILE *ofile=NULL;
|
||||
FILE *ofileH=NULL;
|
||||
|
||||
void process(const char *ifname)
|
||||
{
|
||||
FILE *ifile=NULL;
|
||||
ifile = fopen(ifname, "rb");
|
||||
if (ifile == NULL)
|
||||
{
|
||||
fprintf(stderr, "cannot open %s for reading\n", ifname);
|
||||
exit(1);
|
||||
}
|
||||
char buf[PATH_MAX], *p;
|
||||
const char *cp;
|
||||
if ((cp = strrchr(ifname, '/')) != NULL)
|
||||
{
|
||||
++cp;
|
||||
} else {
|
||||
if ((cp = strrchr(ifname, '\\')) != NULL)
|
||||
++cp;
|
||||
else
|
||||
cp = ifname;
|
||||
}
|
||||
strcpy(buf, cp);
|
||||
for (p = buf; *p != '\0'; ++p)
|
||||
{
|
||||
if (!isalnum(*p))
|
||||
*p = '_';
|
||||
}
|
||||
fprintf(ofile, "unsigned char %s[] = {\n\t\t", buf);
|
||||
int n = 0;
|
||||
unsigned char c = 0;
|
||||
while(fread(&c, 1, 1, ifile) == 1)
|
||||
{
|
||||
if(n%100 == 0) {
|
||||
fprintf(ofile, "\n\t\t");
|
||||
}
|
||||
fprintf(ofile, "0x%02x,", c);
|
||||
n++;
|
||||
}
|
||||
fprintf(ofile, "\n};\n");
|
||||
fprintf(ofile, "unsigned long int %s_size = sizeof(%s);\n\n\n", buf, buf);
|
||||
|
||||
fprintf(ofileH, "extern unsigned char %s[];\n", buf);
|
||||
fprintf(ofileH, "extern unsigned long int %s_size;\n", buf);
|
||||
|
||||
fclose(ifile);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: pngToCpp <output_file>.xxx <input_file>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//zeroTerminated = true;
|
||||
if (argc < 3) {
|
||||
usage();
|
||||
}
|
||||
// dynamic output name :
|
||||
char tmpOutput[PATH_MAX*2] = "";
|
||||
strcpy(tmpOutput, argv[1]);
|
||||
int32_t sizeName = strlen(tmpOutput);
|
||||
if (6>=sizeName) {
|
||||
usage();
|
||||
}
|
||||
if (tmpOutput[sizeName-1] == '.') {
|
||||
tmpOutput[sizeName-1] = '\0';
|
||||
} else if (tmpOutput[sizeName-2] == '.') {
|
||||
tmpOutput[sizeName-2] = '\0';
|
||||
} else if (tmpOutput[sizeName-3] == '.') {
|
||||
tmpOutput[sizeName-3] = '\0';
|
||||
} else if (tmpOutput[sizeName-4] == '.') {
|
||||
tmpOutput[sizeName-4] = '\0';
|
||||
} else if (tmpOutput[sizeName-5] == '.') {
|
||||
tmpOutput[sizeName-5] = '\0';
|
||||
} else if (tmpOutput[sizeName-6] == '.') {
|
||||
tmpOutput[sizeName-6] = '\0';
|
||||
}
|
||||
//fprintf(stderr, "writing to %s\n", tmpOutput);
|
||||
|
||||
char tmpOutputCPP[PATH_MAX*2] = "";
|
||||
char tmpOutputH[PATH_MAX*2] = "";
|
||||
// Generate the output filename
|
||||
sprintf(tmpOutputCPP,"%s.cpp", tmpOutput);
|
||||
sprintf(tmpOutputH,"%s.h", tmpOutput);
|
||||
// open destination name :
|
||||
ofile = fopen(tmpOutputCPP, "wb");
|
||||
if (ofile == NULL)
|
||||
{
|
||||
fprintf(stderr, "cannot open %s for writing\n", tmpOutputCPP);
|
||||
exit(1);
|
||||
}
|
||||
generateHeader(ofile);
|
||||
ofileH = fopen(tmpOutputH, "wb");
|
||||
if (ofileH == NULL)
|
||||
{
|
||||
fprintf(stderr, "cannot open %s for writing\n", tmpOutputH);
|
||||
exit(1);
|
||||
}
|
||||
generateHeader(ofileH);
|
||||
fprintf(ofileH, "#ifndef __INPUT_PNG_FILE_GENERATED_H__\n");
|
||||
fprintf(ofileH, "#define __INPUT_PNG_FILE_GENERATED_H__\n");
|
||||
//fprintf(ofileH, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
|
||||
//fprintf(ofile, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n");
|
||||
|
||||
// Generate the output
|
||||
int32_t i;
|
||||
for(i=2; i<argc; i++) {
|
||||
process(argv[i]);
|
||||
}
|
||||
|
||||
//fprintf(ofile, "#ifdef __cplusplus\n}\n#endif\n");
|
||||
//fprintf(ofileH, "#ifdef __cplusplus\n}\n#endif\n");
|
||||
|
||||
fprintf(ofileH, "#endif\n\n");
|
||||
// Close destination files
|
||||
fclose(ofile);
|
||||
fclose(ofileH);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user