~ubuntu-branches/ubuntu/gutsy/findutils/gutsy-proposed

« back to all changes in this revision

Viewing changes to locate/frcode.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2005-07-04 11:37:37 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050704113737-ll89ui8be35r0pir
Tags: 4.2.22-2
* Remove locatedb on purge. (Closes: #315343)
* revert regex-syntax back to emacs-re. (Closes: #315136) Future versions
  will allow to select this by commandline parameter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
   You should have received a copy of the GNU General Public License
15
15
   along with this program; if not, write to the Free Software
16
 
   Foundation, Inc., 9 Temple Place - Suite 330, Boston, MA 02111-1307,
 
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17
17
   USA.
18
18
*/
19
19
 
61
61
   (6 = 14 - 8, and -9 = 5 - 14)
62
62
 
63
63
   Written by James A. Woods <jwoods@adobe.com>.
64
 
   Modified by David MacKenzie <djm@gnu.ai.mit.edu>.  */
 
64
   Modified by David MacKenzie <djm@gnu.org>.  */
65
65
 
66
 
#include <gnulib/config.h>
67
 
#undef VERSION
68
 
#undef PACKAGE_VERSION
69
 
#undef PACKAGE_TARNAME
70
 
#undef PACKAGE_STRING
71
 
#undef PACKAGE_NAME
72
 
#undef PACKAGE
73
66
#include <config.h>
74
67
#include <stdio.h>
75
68
#include <sys/types.h>
84
77
#include <stdlib.h>
85
78
#endif
86
79
 
 
80
#if ENABLE_NLS
 
81
# include <libintl.h>
 
82
# define _(Text) gettext (Text)
 
83
#else
 
84
# define _(Text) Text
 
85
#define textdomain(Domain)
 
86
#define bindtextdomain(Package, Directory)
 
87
#endif
 
88
#ifdef gettext_noop
 
89
# define N_(String) gettext_noop (String)
 
90
#else
 
91
/* We used to use (String) instead of just String, but apparentl;y ISO C
 
92
 * doesn't allow this (at least, that's what HP said when someone reported
 
93
 * this as a compiler bug).  This is HP case number 1205608192.  See
 
94
 * also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11250 (which references 
 
95
 * ANSI 3.5.7p14-15).  The Intel icc compiler also rejects constructs
 
96
 * like: static const char buf[] = ("string");
 
97
 */
 
98
# define N_(String) String
 
99
#endif
 
100
 
 
101
 
87
102
#include "locatedb.h"
88
103
#include <getline.h>
 
104
#include <getopt.h>
 
105
#include "closeout.h"
89
106
 
90
107
char *xmalloc PARAMS((size_t));
91
108
 
113
130
  return s1 - start;
114
131
}
115
132
 
 
133
static struct option const longopts[] =
 
134
{
 
135
  {"help", no_argument, NULL, 'h'},
 
136
  {"version", no_argument, NULL, 'v'},
 
137
  {"null", no_argument, NULL, '0'},
 
138
  {NULL, no_argument, NULL, 0}
 
139
};
 
140
 
 
141
extern char *version_string;
 
142
 
 
143
/* The name this program was run with. */
 
144
char *program_name;
 
145
 
 
146
 
 
147
static void
 
148
usage (FILE *stream)
 
149
{
 
150
  fprintf (stream,
 
151
           _("Usage: %s [-0 | --null] [--version] [--help]\n"),
 
152
           program_name);
 
153
  fputs (_("\nReport bugs to <bug-findutils@gnu.org>.\n"), stream);
 
154
}
 
155
 
 
156
 
116
157
int
117
158
main (int argc, char **argv)
118
159
{
121
162
  size_t pathsize, oldpathsize; /* Amounts allocated for them.  */
122
163
  int count, oldcount, diffcount; /* Their prefix lengths & the difference. */
123
164
  int line_len;                 /* Length of input line.  */
124
 
 
 
165
  int delimiter = '\n';
 
166
  int optc;
 
167
  
125
168
  program_name = argv[0];
 
169
  atexit (close_stdout);
126
170
 
127
171
  pathsize = oldpathsize = 1026; /* Increased as necessary by getline.  */
128
172
  path = xmalloc (pathsize);
133
177
  strcpy (oldpath, " ");
134
178
  oldcount = 0;
135
179
 
 
180
 
 
181
  while ((optc = getopt_long (argc, argv, "hv0", longopts, (int *) 0)) != -1)
 
182
    switch (optc)
 
183
      {
 
184
      case '0':
 
185
        delimiter = 0;
 
186
        break;
 
187
 
 
188
      case 'h':
 
189
        usage (stdout);
 
190
        return 0;
 
191
 
 
192
      case 'v':
 
193
        printf (_("GNU locate version %s\n"), version_string);
 
194
        return 0;
 
195
 
 
196
      default:
 
197
        usage (stderr);
 
198
        return 1;
 
199
      }
 
200
 
 
201
  /* We expect to have no arguments. */
 
202
  if (optind != argc)
 
203
    {
 
204
      usage (stderr);
 
205
      return 1;
 
206
    }
 
207
 
 
208
 
 
209
 
136
210
  fwrite (LOCATEDB_MAGIC, sizeof (LOCATEDB_MAGIC), 1, stdout);
137
211
 
138
 
  /* FIXME temporary: change the \n to \0 when we figure out how to sort
139
 
     null-terminated strings.  */
140
 
  while ((line_len = getline (&path, &pathsize, stdin)) > 0)
 
212
  while ((line_len = getdelim (&path, &pathsize, delimiter, stdin)) > 0)
141
213
    {
142
214
      path[line_len - 1] = '\0'; /* FIXME temporary: nuke the newline.  */
143
215
 
171
243
  free (path);
172
244
  free (oldpath);
173
245
 
174
 
  exit (0);
 
246
  return 0;
175
247
}