~ubuntu-branches/ubuntu/lucid/silo/lucid

« back to all changes in this revision

Viewing changes to common/bin2h.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2007-10-25 09:28:08 UTC
  • mfrom: (15.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071025092808-1yhj12t7s4zqsfu5
Tags: 1.4.13a+git20070930-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build with -fno-stack-protector.
  - Change silo.postinst to automatically update the boot block without
    invoking siloconfig and keep asking questions on upgrades.
  - Convert silo.conf to use /dev/disk/by-uuid.
  - Ubuntu maintainer foobar.
  - Fix debian/rules call to dh_installdocs.
  - Drop the requirement of gcc-4.1 and start using default gcc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* a simple utility to dump binary into a header file
 
2
   
 
3
   Copyright (C) 1996 Jakub Jelinek
 
4
   
 
5
   This program is free software; you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; either version 2 of the License, or
 
8
   (at your option) any later version.
 
9
   
 
10
   This program is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
   GNU General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU General Public License
 
16
   along with this program; if not, write to the Free Software
 
17
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 
18
   USA.  */
 
19
 
 
20
#include <stdio.h>
 
21
#include <stdlib.h>
 
22
#include <string.h>
 
23
 
 
24
int main (int argc, char **argv)
 
25
{
 
26
    FILE *f;
 
27
    char buffer[512], *array_name, *file_name, *lendef_name = NULL;
 
28
    int i, j, offset = 1;
 
29
    
 
30
    if (argc != 3 && !(argc == 5 && !strcmp(argv[1],"-l"))) {
 
31
        fprintf(stderr, "Usage: %s [-l len_def] <array name> <file>\n", argv[0]);
 
32
        exit (1);
 
33
    }
 
34
 
 
35
    if (!strcmp(argv[1],"-l")) {
 
36
        lendef_name = argv[offset + 1];
 
37
        offset += 2;
 
38
    }
 
39
 
 
40
    array_name = argv[offset++];
 
41
    file_name = argv[offset];
 
42
 
 
43
    if ((f = fopen(file_name, "r")) == NULL) {
 
44
        perror("fopen");
 
45
        exit (1);
 
46
    }
 
47
 
 
48
    if (lendef_name != NULL) {
 
49
        int len;
 
50
        if (fseek (f, 0, SEEK_END)) {
 
51
            perror("fseek");
 
52
            exit (1);
 
53
        }
 
54
 
 
55
        len = ftell (f);
 
56
 
 
57
        if (fseek (f, 0, SEEK_SET)) {
 
58
            perror("fseek");
 
59
            exit (1);
 
60
        }
 
61
 
 
62
        printf ("#define %s %d\n\n",lendef_name, len);
 
63
    }
 
64
 
 
65
    printf ("char %s[] = {\n", array_name);
 
66
    while ((offset = fread (buffer, 1, sizeof(buffer), f))) {
 
67
        for (i = 0; i < 32 && offset; i++) {
 
68
            for (j = 0; j < 16 && offset; j++) {
 
69
                printf ("0x%02X, ", (unsigned char)buffer[16 * i + j]);
 
70
                offset--;
 
71
            }
 
72
            printf ("\n");
 
73
        }
 
74
    }
 
75
    fclose(f);
 
76
    printf ("};\n");
 
77
    exit (0);
 
78
}