Previous 199869 Revisions Next

r33895 Monday 15th December, 2014 at 14:19:55 UTC by Miodrag Milanović
Converted file2str to python (nw)
[/trunk]makefile
[src/build]build.mak file2str.c file2str.py*
[src/mess]mess.mak
[src/osd/sdl]input.c
[src/osd/sdl/man]castool.1 chdman.1 floptool.1 imgtool.1 jedutil.1 ldresample.1 ldverify.1 mame.6 mess.6 romcmp.1 testkeys.1

trunk/makefile
r242406r242407
959959   @$(CPPCHECK) $(CPPCHECKFLAGS) $<
960960endif
961961
962$(OBJ)/%.lh: $(SRC)/%.lay $(FILE2STR_TARGET)
962$(OBJ)/%.lh: $(SRC)/%.lay $(SRC)/build/file2str.py
963963   @echo Converting $<...
964   @$(FILE2STR) $< $@ layout_$(basename $(notdir $<))
964   @$(PYTHON) $(SRC)/build/file2str.py $< $@ layout_$(basename $(notdir $<))
965965
966$(OBJ)/%.fh: $(SRC)/%.png $(PNG2BDC_TARGET) $(FILE2STR_TARGET)
966$(OBJ)/%.fh: $(SRC)/%.png $(PNG2BDC_TARGET) $(SRC)/build/file2str.py
967967   @echo Converting $<...
968968   @$(PNG2BDC) $< $(OBJ)/temp.bdc
969   @$(FILE2STR) $(OBJ)/temp.bdc $@ font_$(basename $(notdir $<)) UINT8
969   @$(PYTHON) $(SRC)/build/file2str.py $(OBJ)/temp.bdc $@ font_$(basename $(notdir $<)) UINT8
970970
971971$(DRIVLISTOBJ): $(DRIVLISTSRC)
972972   @echo Compiling $<...
trunk/src/build/build.mak
r242406r242407
1818# set of build targets
1919#-------------------------------------------------
2020
21FILE2STR_TARGET = $(BUILDOUT)/file2str$(BUILD_EXE)
2221MAKEDEP_TARGET = $(BUILDOUT)/makedep$(BUILD_EXE)
2322MAKEMAK_TARGET = $(BUILDOUT)/makemak$(BUILD_EXE)
2423MAKELIST_TARGET = $(BUILDOUT)/makelist$(BUILD_EXE)
2524PNG2BDC_TARGET = $(BUILDOUT)/png2bdc$(BUILD_EXE)
2625VERINFO_TARGET = $(BUILDOUT)/verinfo$(BUILD_EXE)
2726
28FILE2STR = $(FILE2STR_TARGET)
2927MAKEDEP = $(MAKEDEP_TARGET)
3028MAKEMAK = $(MAKEMAK_TARGET)
3129MAKELIST = $(MAKELIST_TARGET)
r242406r242407
3432
3533ifneq ($(TERM),cygwin)
3634ifeq ($(TARGETOS),win32)
37FILE2STR = $(subst /,\,$(FILE2STR_TARGET))
3835MAKEDEP = $(subst /,\,$(MAKEDEP_TARGET))
3936MAKEMAK = $(subst /,\,$(MAKEMAK_TARGET))
4037MAKELIST = $(subst /,\,$(MAKELIST_TARGET))
r242406r242407
4542
4643ifneq ($(CROSS_BUILD),1)
4744BUILD += \
48   $(FILE2STR_TARGET) \
4945   $(MAKEDEP_TARGET) \
5046   $(MAKEMAK_TARGET) \
5147   $(MAKELIST_TARGET) \
r242406r242407
5551
5652
5753#-------------------------------------------------
58# file2str
59#-------------------------------------------------
60
61FILE2STROBJS = \
62   $(BUILDOBJ)/file2str.o \
63
64$(FILE2STR_TARGET): $(FILE2STROBJS) $(LIBOCORE)
65   @echo Linking $@...
66   $(LD) $(LDFLAGS) $^ $(LIBS) -o $@
67
68
69
70#-------------------------------------------------
7154# makedep
7255#-------------------------------------------------
7356
r242406r242407
155138#-------------------------------------------------
156139# It's a CROSS_BUILD. Ensure the targets exist.
157140#-------------------------------------------------
158$(FILE2STR_TARGET):
159   @echo $@ should be built natively. Nothing to do.
160
161141$(MAKEDEP_TARGET):
162142   @echo $@ should be built natively. Nothing to do.
163143
trunk/src/build/file2str.c
r242406r242407
1/***************************************************************************
2
3    file2str.c
4
5    Simple file to string converter.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11
12#include <stdio.h>
13#include <stdlib.h>
14
15
16/*-------------------------------------------------
17    main - primary entry point
18-------------------------------------------------*/
19
20int main(int argc, char *argv[])
21{
22   const char *srcfile, *dstfile, *varname, *type;
23   FILE *src, *dst;
24   unsigned char *buffer;
25   int bytes, offs;
26   int terminate = 1;
27
28   /* needs at least three arguments */
29   if (argc < 4)
30   {
31      fprintf(stderr,
32         "Usage:\n"
33         "  laytostr <source.lay> <output.h> <varname> [<type>]\n"
34         "\n"
35         "The default <type> is char, with an assumed NULL terminator\n"
36      );
37      return 0;
38   }
39
40   /* extract arguments */
41   srcfile = argv[1];
42   dstfile = argv[2];
43   varname = argv[3];
44   type = (argc >= 5) ? argv[4] : "char";
45   if (argc >= 5)
46      terminate = 0;
47
48   /* open source file */
49   src = fopen(srcfile, "rb");
50   if (src == NULL)
51   {
52      fprintf(stderr, "Unable to open source file '%s'\n", srcfile);
53      return 1;
54   }
55
56   /* determine file size */
57   fseek(src, 0, SEEK_END);
58   bytes = ftell(src);
59   fseek(src, 0, SEEK_SET);
60
61   /* allocate memory */
62   buffer = (unsigned char *)malloc(bytes + 1);
63   if (buffer == NULL)
64   {
65      fclose(src);
66      fprintf(stderr, "Out of memory allocating %d byte buffer\n", bytes);
67      return 1;
68   }
69
70   /* read the source file */
71   fread(buffer, 1, bytes, src);
72   buffer[bytes] = 0;
73   fclose(src);
74
75   /* open dest file */
76   dst = fopen(dstfile, "w");
77   if (dst == NULL)
78   {
79      free(buffer);
80      fprintf(stderr, "Unable to open output file '%s'\n", dstfile);
81      return 1;
82   }
83
84   /* write the initial header */
85   fprintf(dst, "extern const %s %s[];\n", type, varname);
86   fprintf(dst, "const %s %s[] =\n{\n\t", type, varname);
87
88   /* write out the data */
89   for (offs = 0; offs < bytes + terminate; offs++)
90   {
91      fprintf(dst, "0x%02x%s", buffer[offs], (offs != bytes + terminate - 1) ? "," : "");
92      if (offs % 16 == 15)
93         fprintf(dst, "\n\t");
94   }
95   fprintf(dst, "\n};\n");
96
97   /* close the files */
98   free(buffer);
99   fclose(dst);
100   return 0;
101}
trunk/src/build/file2str.py
r0r242407
1#!/usr/bin/python
2
3import string
4import sys
5import os
6
7if (len(sys.argv) < 4) :
8    print('Usage:')
9    print('  file2str <source.lay> <output.h> <varname> [<type>]')
10    print('')
11    print('The default <type> is char, with an assumed NULL terminator')
12    sys.exit(0)
13
14terminate = 1
15srcfile = sys.argv[1]
16dstfile = sys.argv[2]
17varname = sys.argv[3]
18
19if (len(sys.argv) >= 5) :
20    type = sys.argv[4]
21    terminate = 0
22else:
23    type = 'char'
24
25try:
26    myfile = open(srcfile, 'rb')
27except IOError:
28    print("Unable to open source file '%s'" % srcfile)
29    sys.exit(-1)
30
31bytes = os.path.getsize(srcfile)
32try:
33    dst = open(dstfile,'w')
34    dst.write('extern const %s %s[];\n' % ( type, varname ));
35    dst.write('const %s %s[] =\n{\n\t' % ( type, varname));
36    offs = 0
37    with open(srcfile, "rb") as src:
38        while True:
39            chunk = src.read(16)
40            if chunk:
41                for b in chunk:
42                    dst.write('0x%02x' % ord(b))
43                    offs = offs + 1
44                    if offs != bytes:
45                  dst.write(',')
46            else:
47                break
48            if offs != bytes:
49                dst.write('\n\t')
50    if terminate == 1:
51       dst.write(',0x00')
52    dst.write('\n};\n')
53    dst.close()
54except IOError:
55    print("Unable to open output file '%s'" % dstfile)
56    sys.exit(-1)
No newline at end of file
trunk/src/mess/mess.mak
r242406r242407
18681868   $(MESS_DRIVERS)/fb01.o      \
18691869
18701870$(MESS_DRIVERS)/ymmu100.o: $(MESS_DRIVERS)/ymmu100.inc
1871$(MESS_DRIVERS)/ymmu100.inc: $(MESSSRC)/drivers/ymmu100.ppm $(FILE2STR_TARGET)
1871$(MESS_DRIVERS)/ymmu100.inc: $(MESSSRC)/drivers/ymmu100.ppm $(SRC)/build/file2str.py
18721872   @echo Converting $<...
1873   @$(FILE2STR) $(MESSSRC)/drivers/ymmu100.ppm $@ ymmu100_bkg UINT8
1873   @$(PYTHON) $(SRC)/build/file2str.py $(MESSSRC)/drivers/ymmu100.ppm $@ ymmu100_bkg UINT8
18741874
18751875$(MESSOBJ)/zenith.a:            \
18761876   $(MESS_DRIVERS)/z100.o      \
trunk/src/osd/sdl/input.c
r242406r242407
757757
758758      osd_printf_verbose("Joystick: %s\n", devinfo->name.cstr());
759759      osd_printf_verbose("Joystick:   ...  %d axes, %d buttons %d hats %d balls\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy), SDL_JoystickNumBalls(joy));
760      osd_printf_verbose("Joystick:   ...  Physical id %d mapped to logical id %d\n", physical_stick, stick + 1);
760      osd_printf_verbose("Joystick:   ...  Physical id %d mapped to logical id %d\n", physical_stick, stick);
761761
762762      // loop over all axes
763763      for (axis = 0; axis < SDL_JoystickNumAxes(joy); axis++)
trunk/src/osd/sdl/man/castool.1
r242406r242407
66.\" Cesare Falco <c.falco@ubuntu.com>, February 2011
77.\"
88.\"
9.TH CASTOOL 1 2014-12-15 0.157 "MESS Generic cassette manipulation tool"
9.TH CASTOOL 1 2014-11-19 0.156 "MESS Generic cassette manipulation tool"
1010.\"
1111.\"
1212.\" NAME chapter
trunk/src/osd/sdl/man/chdman.1
r242406r242407
66.\" Ashley T. Howes <debiandev@ashleyhowes.com>, February 2005
77.\" updated by Cesare Falco <c.falco@ubuntu.com>, February 2007
88.\"
9.TH CHDMAN 1 2014-12-15 0.157 "MAME Compressed Hunks of Data (CHD) manager"
9.TH CHDMAN 1 2014-11-19 0.156 "MAME Compressed Hunks of Data (CHD) manager"
1010.\"
1111.\" NAME chapter
1212.SH NAME
trunk/src/osd/sdl/man/floptool.1
r242406r242407
66.\" Cesare Falco <c.falco@ubuntu.com>, April 2014
77.\"
88.\"
9.TH FLOPTOOL 1 2014-12-15 0.157 "MESS Generic floppy manipulation tool"
9.TH FLOPTOOL 1 2014-11-19 0.156 "MESS Generic floppy manipulation tool"
1010.\"
1111.\"
1212.\" NAME chapter
trunk/src/osd/sdl/man/imgtool.1
r242406r242407
66.\" Cesare Falco <c.falco@ubuntu.com>, February 2011
77.\"
88.\"
9.TH IMGTOOL 1 2014-12-15 0.157 "MESS media image manipulation tool"
9.TH IMGTOOL 1 2014-11-19 0.156 "MESS media image manipulation tool"
1010.\"
1111.\"
1212.\" NAME chapter
trunk/src/osd/sdl/man/jedutil.1
r242406r242407
88.\" References
99.\" http://aarongiles.com/?p=159
1010.\"
11.TH JEDUTIL 1 2014-12-15 0.157 "MAME JEDEC file utilities"
11.TH JEDUTIL 1 2014-11-19 0.156 "MAME JEDEC file utilities"
1212.\"
1313.\" NAME chapter
1414.SH NAME
trunk/src/osd/sdl/man/ldresample.1
r242406r242407
33.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
44.\" other parameters are allowed: see man(7), man(1)
55.\"
6.TH LDRESAMPLE 1 2014-12-15 0.157 "MAME laserdisc audio manipulation tool"
6.TH LDRESAMPLE 1 2014-11-19 0.156 "MAME laserdisc audio manipulation tool"
77.\"
88.\" Please adjust this date whenever revising the manpage.
99.\"
trunk/src/osd/sdl/man/ldverify.1
r242406r242407
55.\" Man page created from source and usage information by
66.\" Cesare Falco <c.falco@ubuntu.com>, August 2008
77.\"
8.TH LDVERIFY 1 2014-12-15 0.157 "MAME laserdisc data checker"
8.TH LDVERIFY 1 2014-11-19 0.156 "MAME laserdisc data checker"
99.\"
1010.\" NAME chapter
1111.SH NAME
trunk/src/osd/sdl/man/mame.6
r242406r242407
1313.\" and updated by Andrew Burton <burtona@gol.com>, July 2003
1414.\"
1515.\"
16.TH MAME 6 2014-12-15 0.157 "MAME \- The Multiple Arcade Machine Emulator"
16.TH MAME 6 2014-11-19 0.156 "MAME \- The Multiple Arcade Machine Emulator"
1717.\"
1818.\"
1919.\" NAME chapter
trunk/src/osd/sdl/man/mess.6
r242406r242407
1616.\" http://www.mess.org/
1717.\"
1818.\"
19.TH MESS 6 2014-12-15 0.157 "The Multiple Emulator Super System (MESS)"
19.TH MESS 6 2014-11-19 0.156 "The Multiple Emulator Super System (MESS)"
2020.\"
2121.\"
2222.\" NAME chapter
trunk/src/osd/sdl/man/romcmp.1
r242406r242407
99.\" References
1010.\" http://www.mame.net/mamefaq.html
1111.\"
12.TH ROMCMP 1 2014-12-15 0.157 "MAME romset checking tool"
12.TH ROMCMP 1 2014-11-19 0.156 "MAME romset checking tool"
1313.\"
1414.\" NAME chapter
1515.SH NAME
trunk/src/osd/sdl/man/testkeys.1
r242406r242407
55.\" Man page created from source and usage information
66.\" Cesare Falco <c.falco@ubuntu.com>, February 2007
77.\"
8.TH TESTKEYS 1 2014-12-15 0.157 "MAME SDL keycode scanner"
8.TH TESTKEYS 1 2014-11-19 0.156 "MAME SDL keycode scanner"
99.\"
1010.\" NAME chapter
1111.SH NAME


Previous 199869 Revisions Next


© 1997-2024 The MAME Team