2010-10-27 12:38:25 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-21 14:30:25 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
2013-03-19 01:26:21 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2001-04-19 07:20:23 +00:00
|
|
|
|
2014-04-10 15:31:22 +02:00
|
|
|
#include <_getopt.h>
|
|
|
|
|
2001-04-19 07:20:23 +00:00
|
|
|
#define EPR fprintf(stderr,
|
|
|
|
#define ERR(str, chr) if(opterr) { EPR "%s%c\n", str, chr); }
|
|
|
|
|
2017-01-09 20:19:22 +01:00
|
|
|
static int opterr = 1;
|
2001-04-19 07:20:23 +00:00
|
|
|
int optind = 1;
|
|
|
|
int optopt;
|
|
|
|
char *optarg;
|
|
|
|
|
|
|
|
int
|
2007-11-12 14:29:54 +00:00
|
|
|
stgetopt(int argc, char *const argv[], const char *opts)
|
2001-04-19 07:20:23 +00:00
|
|
|
{
|
|
|
|
static int sp = 1;
|
2014-06-24 07:44:01 +02:00
|
|
|
int c;
|
|
|
|
char *cp;
|
2001-04-19 07:20:23 +00:00
|
|
|
|
|
|
|
if (sp == 1)
|
2004-04-21 12:24:33 +00:00
|
|
|
{
|
2001-04-19 07:20:23 +00:00
|
|
|
if (optind >= argc ||
|
|
|
|
argv[optind][0] != '-' || argv[optind][1] == '\0')
|
|
|
|
return -1;
|
2009-09-16 14:49:32 +00:00
|
|
|
else if (strcmp(argv[optind], "--") == 0)
|
2001-04-19 07:20:23 +00:00
|
|
|
{
|
|
|
|
optind++;
|
|
|
|
return -1;
|
|
|
|
}
|
2009-09-16 14:49:32 +00:00
|
|
|
else if (strcmp(argv[optind], "-isysroot") == 0)
|
|
|
|
{
|
|
|
|
// skip Mac OS X SDK selection flags
|
|
|
|
optind++; optind++;
|
|
|
|
}
|
2004-04-21 12:24:33 +00:00
|
|
|
}
|
2001-04-19 07:20:23 +00:00
|
|
|
optopt = c = argv[optind][sp];
|
2015-11-10 16:19:59 +01:00
|
|
|
if (c == ':' || (cp = strchr(opts, c)) == NULL)
|
2001-04-19 07:20:23 +00:00
|
|
|
{
|
|
|
|
ERR(": illegal option -- ", c);
|
|
|
|
if (argv[optind][++sp] == '\0')
|
|
|
|
{
|
|
|
|
optind++;
|
|
|
|
sp = 1;
|
|
|
|
}
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
if (*++cp == ':')
|
|
|
|
{
|
|
|
|
if (argv[optind][sp + 1] != '\0')
|
|
|
|
optarg = &argv[optind++][sp + 1];
|
|
|
|
else
|
|
|
|
if (++optind >= argc)
|
|
|
|
{
|
|
|
|
ERR(": option requires an argument -- ", c);
|
|
|
|
sp = 1;
|
|
|
|
return '?';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
optarg = argv[optind++];
|
|
|
|
sp = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (argv[optind][++sp] == '\0')
|
|
|
|
{
|
|
|
|
sp = 1;
|
|
|
|
optind++;
|
|
|
|
}
|
2015-11-10 16:19:59 +01:00
|
|
|
optarg = NULL;
|
2001-04-19 07:20:23 +00:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
2010-10-27 12:38:25 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|