diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2007-12-17 23:06:42 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-12-20 00:17:52 -0500 |
commit | a4da2e3ec84cda635ac441efbe781a38d2ee41ee (patch) | |
tree | 47fa696faaf092920ee0c0226ddc7557fa743d4d /arch/powerpc/boot/dtc-src/srcpos.c | |
parent | 70e47528aa0eb5ef63fef6ee0d30065d9e09f3e5 (diff) |
[POWERPC] Merge dtc upstream source
This incorporates a copy of dtc into the kernel source, in
arch/powerpc/boot/dtc-src. This commit only imports the upstream
sources verbatim, a later commit will actually link it into the kernel
Makefiles and use the embedded code during the kernel build.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/boot/dtc-src/srcpos.c')
-rw-r--r-- | arch/powerpc/boot/dtc-src/srcpos.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/arch/powerpc/boot/dtc-src/srcpos.c b/arch/powerpc/boot/dtc-src/srcpos.c new file mode 100644 index 00000000000..352b0fe06fd --- /dev/null +++ b/arch/powerpc/boot/dtc-src/srcpos.c | |||
@@ -0,0 +1,105 @@ | |||
1 | /* | ||
2 | * Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License as | ||
6 | * published by the Free Software Foundation; either version 2 of the | ||
7 | * License, or (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
17 | * USA | ||
18 | */ | ||
19 | |||
20 | #include "dtc.h" | ||
21 | #include "srcpos.h" | ||
22 | |||
23 | |||
24 | /* | ||
25 | * Record the complete unique set of opened file names. | ||
26 | * Primarily used to cache source position file names. | ||
27 | */ | ||
28 | #define MAX_N_FILE_NAMES (100) | ||
29 | |||
30 | const char *file_names[MAX_N_FILE_NAMES]; | ||
31 | static int n_file_names = 0; | ||
32 | |||
33 | /* | ||
34 | * Like yylineno, this is the current open file pos. | ||
35 | */ | ||
36 | |||
37 | int srcpos_filenum = -1; | ||
38 | |||
39 | |||
40 | |||
41 | FILE *dtc_open_file(const char *fname) | ||
42 | { | ||
43 | FILE *f; | ||
44 | |||
45 | if (lookup_file_name(fname, 1) < 0) | ||
46 | die("Too many files opened\n"); | ||
47 | |||
48 | if (streq(fname, "-")) | ||
49 | f = stdin; | ||
50 | else | ||
51 | f = fopen(fname, "r"); | ||
52 | |||
53 | if (! f) | ||
54 | die("Couldn't open \"%s\": %s\n", fname, strerror(errno)); | ||
55 | |||
56 | return f; | ||
57 | } | ||
58 | |||
59 | |||
60 | |||
61 | /* | ||
62 | * Locate and optionally add filename fname in the file_names[] array. | ||
63 | * | ||
64 | * If the filename is currently not in the array and the boolean | ||
65 | * add_it is non-zero, an attempt to add the filename will be made. | ||
66 | * | ||
67 | * Returns; | ||
68 | * Index [0..MAX_N_FILE_NAMES) where the filename is kept | ||
69 | * -1 if the name can not be recorded | ||
70 | */ | ||
71 | |||
72 | int lookup_file_name(const char *fname, int add_it) | ||
73 | { | ||
74 | int i; | ||
75 | |||
76 | for (i = 0; i < n_file_names; i++) { | ||
77 | if (strcmp(file_names[i], fname) == 0) | ||
78 | return i; | ||
79 | } | ||
80 | |||
81 | if (add_it) { | ||
82 | if (n_file_names < MAX_N_FILE_NAMES) { | ||
83 | file_names[n_file_names] = strdup(fname); | ||
84 | return n_file_names++; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | return -1; | ||
89 | } | ||
90 | |||
91 | |||
92 | const char *srcpos_filename_for_num(int filenum) | ||
93 | { | ||
94 | if (0 <= filenum && filenum < n_file_names) { | ||
95 | return file_names[filenum]; | ||
96 | } | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | |||
102 | const char *srcpos_get_filename(void) | ||
103 | { | ||
104 | return srcpos_filename_for_num(srcpos_filenum); | ||
105 | } | ||