| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: strfile.c,v 1.37 2013/09/19 00:18:52 uwe Exp $ */ | | 1 | /* $NetBSD: strfile.c,v 1.38 2013/09/19 00:34:00 uwe Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1989, 1993 | | 4 | * Copyright (c) 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Ken Arnold. | | 8 | * Ken Arnold. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -37,58 +37,48 @@ | | | @@ -37,58 +37,48 @@ |
37 | #endif | | 37 | #endif |
38 | | | 38 | |
39 | #ifdef __NetBSD__ | | 39 | #ifdef __NetBSD__ |
40 | #include <sys/cdefs.h> | | 40 | #include <sys/cdefs.h> |
41 | #ifndef lint | | 41 | #ifndef lint |
42 | __COPYRIGHT("@(#) Copyright (c) 1989, 1993\ | | 42 | __COPYRIGHT("@(#) Copyright (c) 1989, 1993\ |
43 | The Regents of the University of California. All rights reserved."); | | 43 | The Regents of the University of California. All rights reserved."); |
44 | #endif /* not lint */ | | 44 | #endif /* not lint */ |
45 | | | 45 | |
46 | #ifndef lint | | 46 | #ifndef lint |
47 | #if 0 | | 47 | #if 0 |
48 | static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; | | 48 | static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93"; |
49 | #else | | 49 | #else |
50 | __RCSID("$NetBSD: strfile.c,v 1.37 2013/09/19 00:18:52 uwe Exp $"); | | 50 | __RCSID("$NetBSD: strfile.c,v 1.38 2013/09/19 00:34:00 uwe Exp $"); |
51 | #endif | | 51 | #endif |
52 | #endif /* not lint */ | | 52 | #endif /* not lint */ |
53 | #endif /* __NetBSD__ */ | | 53 | #endif /* __NetBSD__ */ |
54 | | | 54 | |
55 | /* n.b.: this file is used at build-time - i.e. during build.sh. */ | | | |
56 | | | | |
57 | #include <sys/types.h> | | 55 | #include <sys/types.h> |
58 | #include <sys/param.h> | | 56 | #include <sys/param.h> |
59 | #include <ctype.h> | | 57 | #include <ctype.h> |
60 | #include <stdio.h> | | 58 | #include <stdio.h> |
61 | #include <stdlib.h> | | 59 | #include <stdlib.h> |
62 | #include <string.h> | | 60 | #include <string.h> |
63 | #include <time.h> | | 61 | #include <time.h> |
64 | #include <unistd.h> | | 62 | #include <unistd.h> |
65 | #include <inttypes.h> | | 63 | #include <inttypes.h> |
66 | #include <err.h> | | 64 | #include <err.h> |
67 | | | 65 | |
68 | #include "strfile.h" | | 66 | #include "strfile.h" |
69 | | | 67 | |
70 | #ifndef MAXPATHLEN | | 68 | #ifndef MAXPATHLEN |
71 | #define MAXPATHLEN 1024 | | 69 | #define MAXPATHLEN 1024 |
72 | #endif /* MAXPATHLEN */ | | 70 | #endif /* MAXPATHLEN */ |
73 | | | 71 | |
74 | #if defined(__NetBSD__) || defined(__dead) | | | |
75 | #define NORETURN __dead | | | |
76 | #elif defined __GNUC__ | | | |
77 | #define NORETURN __attribute__((__noreturn__)) | | | |
78 | #else | | | |
79 | #define NORETURN | | | |
80 | #endif | | | |
81 | | | | |
82 | /* | | 72 | /* |
83 | * This program takes a file composed of strings separated by | | 73 | * This program takes a file composed of strings separated by |
84 | * lines starting with two consecutive delimiting character (default | | 74 | * lines starting with two consecutive delimiting character (default |
85 | * character is '%') and creates another file which consists of a table | | 75 | * character is '%') and creates another file which consists of a table |
86 | * describing the file (structure from "strfile.h"), a table of seek | | 76 | * describing the file (structure from "strfile.h"), a table of seek |
87 | * pointers to the start of the strings, and the strings, each terminated | | 77 | * pointers to the start of the strings, and the strings, each terminated |
88 | * by a null byte. Usage: | | 78 | * by a null byte. Usage: |
89 | * | | 79 | * |
90 | * % strfile [-iorsx] [ -cC ] sourcefile [ datafile ] | | 80 | * % strfile [-iorsx] [ -cC ] sourcefile [ datafile ] |
91 | * | | 81 | * |
92 | * c - Change delimiting character from '%' to 'C' | | 82 | * c - Change delimiting character from '%' to 'C' |
93 | * s - Silent. Give no summary of data processed at the end of | | 83 | * s - Silent. Give no summary of data processed at the end of |
94 | * the run. | | 84 | * the run. |
| @@ -131,27 +121,27 @@ static int Xflag = 0; /* set rotated bi | | | @@ -131,27 +121,27 @@ static int Xflag = 0; /* set rotated bi |
131 | static long Num_pts = 0; /* number of pointers/strings */ | | 121 | static long Num_pts = 0; /* number of pointers/strings */ |
132 | | | 122 | |
133 | static off_t *Seekpts; | | 123 | static off_t *Seekpts; |
134 | | | 124 | |
135 | static FILE *Sort_1, *Sort_2; /* pointers for sorting */ | | 125 | static FILE *Sort_1, *Sort_2; /* pointers for sorting */ |
136 | | | 126 | |
137 | static STRFILE Tbl; /* statistics table */ | | 127 | static STRFILE Tbl; /* statistics table */ |
138 | | | 128 | |
139 | static STR *Firstch; /* first chars of each string */ | | 129 | static STR *Firstch; /* first chars of each string */ |
140 | | | 130 | |
141 | | | 131 | |
142 | static uint32_t h2nl(uint32_t h); | | 132 | static uint32_t h2nl(uint32_t h); |
143 | static void getargs(int argc, char **argv); | | 133 | static void getargs(int argc, char **argv); |
144 | static void usage(void) NORETURN; | | 134 | static void usage(void) __dead; |
145 | static void add_offset(FILE *fp, off_t off); | | 135 | static void add_offset(FILE *fp, off_t off); |
146 | static void do_order(void); | | 136 | static void do_order(void); |
147 | static int cmp_str(const void *vp1, const void *vp2); | | 137 | static int cmp_str(const void *vp1, const void *vp2); |
148 | static void randomize(void); | | 138 | static void randomize(void); |
149 | static void fwrite_be_offt(off_t off, FILE *f); | | 139 | static void fwrite_be_offt(off_t off, FILE *f); |
150 | | | 140 | |
151 | | | 141 | |
152 | /* | | 142 | /* |
153 | * main: | | 143 | * main: |
154 | * Drive the sucker. There are two main modes -- either we store | | 144 | * Drive the sucker. There are two main modes -- either we store |
155 | * the seek pointers, if the table is to be sorted or randomized, | | 145 | * the seek pointers, if the table is to be sorted or randomized, |
156 | * or we write the pointer directly to the file, if we are to stay | | 146 | * or we write the pointer directly to the file, if we are to stay |
157 | * in file order. If the former, we allocate and re-allocate in | | 147 | * in file order. If the former, we allocate and re-allocate in |