mirror of https://gerrit.osmocom.org/asn1c
custom basename(3) and dirname(3)
git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@114 59561ff5-6e30-0410-9f3c-9617f08c8826
This commit is contained in:
parent
2c403fe938
commit
1f1d8cb956
|
@ -8,7 +8,6 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h> /* for stat(2) */
|
||||
#include <unistd.h>
|
||||
#include <libgen.h> /* for basename(3) */
|
||||
#include <sysexits.h> /* for EX_USAGE */
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
@ -18,6 +17,8 @@
|
|||
#include <asn1print.h> /* Print the ASN.1 tree */
|
||||
#include <asn1compiler.h> /* Compile the ASN.1 tree */
|
||||
|
||||
#include <asn1c_compat.h> /* Portable basename(3) and dirname(3) */
|
||||
|
||||
static void usage(char *av0); /* Print the Usage screen and exit(EX_USAGE) */
|
||||
|
||||
int
|
||||
|
@ -118,7 +119,7 @@ main(int ac, char **av) {
|
|||
av += optind;
|
||||
} else {
|
||||
fprintf(stderr, "%s: No input files specified\n",
|
||||
basename(av[0]));
|
||||
a1c_basename(av[0]));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -201,7 +202,7 @@ main(int ac, char **av) {
|
|||
char *p;
|
||||
int len;
|
||||
|
||||
p = dirname(av[-optind]);
|
||||
p = a1c_dirname(av[-optind]);
|
||||
|
||||
len = strlen(p) + sizeof("/../skeletons");
|
||||
skeletons_dir = alloca(len);
|
||||
|
@ -261,7 +262,7 @@ usage(char *av0) {
|
|||
"\t-Wdebug-fixer\tDebug ASN.1 semantics processor\n"
|
||||
"\t-Wdebug-compiler\tDebug ASN.1 compiler\n"
|
||||
,
|
||||
basename(av0), DATADIR
|
||||
a1c_basename(av0), DATADIR
|
||||
);
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
|
|
|
@ -21588,7 +21588,7 @@ _ACEOF
|
|||
fi
|
||||
|
||||
|
||||
for ac_header in errno.h
|
||||
for ac_header in sys/param.h
|
||||
do
|
||||
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||
if eval "test \"\${$as_ac_Header+set}\" = set"; then
|
||||
|
|
|
@ -67,7 +67,7 @@ esac
|
|||
|
||||
dnl Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(errno.h)
|
||||
AC_CHECK_HEADERS(sys/param.h)
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_BIGENDIAN
|
||||
|
|
|
@ -13,6 +13,7 @@ libasn1compiler_la_SOURCES = \
|
|||
asn1c_lang.c asn1c_lang.h \
|
||||
asn1c_save.c asn1c_save.h \
|
||||
asn1c_C.c asn1c_C.h \
|
||||
asn1c_compat.c asn1c_compat.h \
|
||||
asn1c_internal.h
|
||||
|
||||
libasn1compiler_la_LIBADD = \
|
||||
|
|
|
@ -54,7 +54,8 @@ libasn1compiler_la_DEPENDENCIES = \
|
|||
${top_builddir}/libasn1parser/libasn1parser.la \
|
||||
${top_builddir}/libasn1fix/libasn1fix.la
|
||||
am_libasn1compiler_la_OBJECTS = asn1compiler.lo asn1c_misc.lo \
|
||||
asn1c_out.lo asn1c_lang.lo asn1c_save.lo asn1c_C.lo
|
||||
asn1c_out.lo asn1c_lang.lo asn1c_save.lo asn1c_C.lo \
|
||||
asn1c_compat.lo
|
||||
libasn1compiler_la_OBJECTS = $(am_libasn1compiler_la_OBJECTS)
|
||||
check_compiler_SOURCES = check_compiler.c
|
||||
check_compiler_OBJECTS = check_compiler.$(OBJEXT)
|
||||
|
@ -68,6 +69,7 @@ DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
|
|||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/asn1c_C.Plo \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/asn1c_compat.Plo \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/asn1c_lang.Plo \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/asn1c_misc.Plo \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/asn1c_out.Plo \
|
||||
|
@ -210,6 +212,7 @@ libasn1compiler_la_SOURCES = \
|
|||
asn1c_lang.c asn1c_lang.h \
|
||||
asn1c_save.c asn1c_save.h \
|
||||
asn1c_C.c asn1c_C.h \
|
||||
asn1c_compat.c asn1c_compat.h \
|
||||
asn1c_internal.h
|
||||
|
||||
libasn1compiler_la_LIBADD = \
|
||||
|
@ -281,6 +284,7 @@ distclean-compile:
|
|||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asn1c_C.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asn1c_compat.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asn1c_lang.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asn1c_misc.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asn1c_out.Plo@am__quote@
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
#include <asn1c_compat.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h> /* For MAXPATHLEN */
|
||||
#endif
|
||||
|
||||
#ifndef MAXPATHLEN
|
||||
#define MAXPATHLEN 1024
|
||||
#endif
|
||||
|
||||
char *
|
||||
a1c_basename(const char *path) {
|
||||
static char strbuf[MAXPATHLEN];
|
||||
const char *pend;
|
||||
const char *name;
|
||||
|
||||
pend = path + strlen(path);
|
||||
if(pend == path) {
|
||||
strcpy(strbuf, ".");
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
/* Skip tailing slashes */
|
||||
for(pend--; pend > path && *pend == '/'; pend--);
|
||||
|
||||
if(pend == path && *path == '/') {
|
||||
strcpy(strbuf, "/");
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
for(name = pend; name > path && name[-1] != '/'; name--);
|
||||
|
||||
if((pend - name) >= sizeof(strbuf) - 1) {
|
||||
errno = ENAMETOOLONG;
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(strbuf, name, pend - name + 1);
|
||||
strbuf[pend - name + 1] = '\0';
|
||||
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
a1c_dirname(const char *path) {
|
||||
static char strbuf[MAXPATHLEN];
|
||||
const char *pend;
|
||||
const char *last = 0;
|
||||
int in_slash = 0;
|
||||
|
||||
/* One-pass determination of the last char of the pathname */
|
||||
for(pend = path; ; pend++) {
|
||||
printf("-%c", *pend);
|
||||
switch(*pend) {
|
||||
case '\0': break;
|
||||
case '/':
|
||||
if(!in_slash) {
|
||||
last = pend;
|
||||
in_slash = 1;
|
||||
}
|
||||
continue;
|
||||
default:
|
||||
if(in_slash) in_slash = 0;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if(last <= path) {
|
||||
strcpy(strbuf, *path == '/' ? "/" : ".");
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
if(!last) {
|
||||
strcpy(strbuf, "/");
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
if((last - path) >= sizeof(strbuf)) {
|
||||
errno = ENAMETOOLONG;
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(strbuf, path, last - path);
|
||||
strbuf[last - path] = '\0';
|
||||
|
||||
return strbuf;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef ASN1C_COMPAT_H
|
||||
#define ASN1C_COMPAT_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
char *a1c_basename(const char *path);
|
||||
char *a1c_dirname(const char *path);
|
||||
|
||||
#endif /* ASN1C_COMPAT_H */
|
|
@ -1,13 +1,16 @@
|
|||
#ifndef _ASN1_COMPILER_INTERNAL_H_
|
||||
#define _ASN1_COMPILER_INTERNAL_H_
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h> /* for fstat(2) */
|
||||
#include <unistd.h> /* for unlink(2) */
|
||||
#include <fcntl.h> /* for open(2) */
|
||||
#include <glob.h> /* for glob(3) */
|
||||
#include <libgen.h> /* for basename(3) */
|
||||
#include <string.h>
|
||||
#include <ctype.h> /* for isalnum(3) */
|
||||
#include <stdarg.h>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "asn1c_internal.h"
|
||||
#include "asn1c_compat.h"
|
||||
|
||||
static int asn1c_dump_streams(arg_t *arg);
|
||||
static int asn1c_print_streams(arg_t *arg);
|
||||
|
@ -73,7 +74,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir) {
|
|||
return -1;
|
||||
} else {
|
||||
fprintf(mkf, "\t\\\n\t%s",
|
||||
basename(pg.gl_pathv[i]));
|
||||
a1c_basename(pg.gl_pathv[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,11 +214,12 @@ asn1c_save_streams(arg_t *arg) {
|
|||
|
||||
static int
|
||||
asn1c_copy_over(arg_t *arg, char *path) {
|
||||
char *fname = basename(path);
|
||||
char *fname;
|
||||
|
||||
(void)arg; /* Unused argument */
|
||||
|
||||
if(symlink(path, fname)) {
|
||||
fname = a1c_basename(path);
|
||||
if(!fname || symlink(path, fname)) {
|
||||
if(errno == EEXIST) {
|
||||
struct stat sb1, sb2;
|
||||
if(stat(path, &sb1) == 0
|
||||
|
|
|
@ -546,8 +546,8 @@ distclean-generic:
|
|||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
-rm -f asn1p_y.c
|
||||
-rm -f asn1p_y.h
|
||||
-rm -f asn1p_y.c
|
||||
-rm -f asn1p_l.c
|
||||
clean: clean-am
|
||||
|
||||
|
|
Loading…
Reference in New Issue