FreeCalypso > hg > ueda-linux
annotate netdiff/renpart/rename.c @ 138:77acb816727b
netdiff: donl-rename-parts put together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 07 Sep 2020 04:02:14 +0000 |
parents | |
children |
rev | line source |
---|---|
138
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <ctype.h> |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <string.h> |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <strings.h> |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdio.h> |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdlib.h> |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "struct.h" |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 extern struct part_rename *part_rename_list; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 static char *infname; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 static FILE *inf; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 static char linebuf[80]; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static int lineno; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static void |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 rename_entry(old, new) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char *old, *new; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 struct part_rename *rp, **rpp; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char *dp; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 for (rpp = &part_rename_list; rp = *rpp; rpp = &rp->next) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (!strcmp(rp->old, old)) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 fprintf(stderr, "%s line %d: old name %s given twice\n", |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 infname, lineno, old); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 exit(1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 rp = malloc(sizeof(struct part_rename) + strlen(old) + strlen(new) + 2); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 dp = (char *)(rp + 1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 rp->old = dp; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 strcpy(dp, old); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 dp += strlen(old) + 1; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 rp->new = dp; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 strcpy(dp, new); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 rp->next = 0; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 *rpp = rp; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 static void |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 process_line() |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 char *cp, *old, *new; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 for (cp = linebuf; isspace(*cp); cp++) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 ; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (*cp == '\0' || *cp == '#') |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 for (old = cp; *cp && !isspace(*cp); cp++) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 ; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (*cp) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 *cp++ = '\0'; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 while (isspace(*cp)) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 cp++; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (*cp == '\0' || *cp == '#') { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 fprintf(stderr, "%s line %d: too few fields\n", |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 infname, lineno); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 exit(1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 for (new = cp; *cp && !isspace(*cp); cp++) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 ; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (*cp) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 *cp++ = '\0'; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 while (isspace(*cp)) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 cp++; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (*cp != '\0' && *cp != '#') { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 fprintf(stderr, "%s line %d: too many fields\n", |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 infname, lineno); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 exit(1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 rename_entry(old, new); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 process_rename_file(input_filename) |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 char *input_filename; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 infname = input_filename; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 inf = fopen(infname, "r"); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (!inf) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 perror(infname); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 exit(1); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 while (fgets(linebuf, sizeof linebuf, inf)) { |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 lineno++; |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 process_line(); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 fclose(inf); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 return(0); |
77acb816727b
netdiff: donl-rename-parts put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |