OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [sw/] [tools/] [amber-mem-ascii.c] - Blame information for rev 46

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 csantifort
/*----------------------------------------------------------------
2
//                                                              //
3
//  amber-mem-ascii                                             //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Take a stream of hex format text and convert to ascii       //
10
//  format. E.g. converts 4B to K                               //
11
//                                                              //
12
//  Author(s):                                                  //
13
//      - Conor Santifort, csantifort.amber@gmail.com           //
14
//                                                              //
15
//////////////////////////////////////////////////////////////////
16
//                                                              //
17
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
18
//                                                              //
19
// This source file may be used and distributed without         //
20
// restriction provided that this copyright statement is not    //
21
// removed from the file and that any derivative work contains  //
22
// the original copyright notice and the associated disclaimer. //
23
//                                                              //
24
// This source file is free software; you can redistribute it   //
25
// and/or modify it under the terms of the GNU Lesser General   //
26
// Public License as published by the Free Software Foundation; //
27
// either version 2.1 of the License, or (at your option) any   //
28
// later version.                                               //
29
//                                                              //
30
// This source is distributed in the hope that it will be       //
31
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
32
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
33
// PURPOSE.  See the GNU Lesser General Public License for more //
34
// details.                                                     //
35
//                                                              //
36
// You should have received a copy of the GNU Lesser General    //
37
// Public License along with this source; if not, download it   //
38
// from http://www.opencores.org/lgpl.shtml                     //
39
//                                                              //
40
----------------------------------------------------------------*/
41
 
42
 
43
#include <stdio.h>
44
#include <stdlib.h> 
45
 
46
 
47
int conv_hstring ( char *string, unsigned int * addr)
48
{
49
    int pos = 0;
50
    *addr = 0;
51
 
52
    while (((string[pos] >= '0' && string[pos] <= '9') ||
53
           (string[pos] >= 'a' && string[pos] <= 'f')) && pos < 9) {
54
        if (string[pos] >= '0' && string[pos] <= '9')
55
            *addr =  (*addr << 4) + ( string[pos++] - '0' );
56
        else
57
            *addr =  (*addr << 4) + ( string[pos++] - 'a' ) + 10;
58
        }
59
 
60
    return pos;
61
}
62
 
63
 
64
int main (int argc, char **argv)
65
{
66
    FILE *input_file;
67
    int i;
68
    int bytes_read;
69
    size_t nbytes = 100;
70
    char *line_buffer;
71
 
72
    char s_number[12];
73
    unsigned int number;
74
 
75
    input_file = stdin;
76
 
77
    if (input_file==NULL)
78
        {
79
        printf("Input file open failed\n");
80
        return 1;
81
        }
82
 
83
 
84
    /* Read the input file into a structure */
85
    /* reads a line */
86
    line_buffer  = (char *) malloc (nbytes + 1);
87
 
88
    /* Assign names to jumps */
89
    while ( (bytes_read = getline (&line_buffer, &nbytes, input_file)) > 0)
90
        {
91
        sscanf(line_buffer, "%s", s_number);
92
 
93
        if ( !conv_hstring(s_number, &number) )
94
            {
95
            fprintf(stderr,"ERROR: conv_hstring error in jumps file, number, with i = %d\n", i);
96
            return 1;
97
            }
98
 
99
        printf("%c", number);
100
        }
101
 
102
    fclose(input_file);
103
 
104
}
105
 
106
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.