common functions that all dpkg binaries call.
+Fri May 24 00:11:01 CDT 2002 Adam Heath <doogie@debian.org>
+
+ * include/dpkg.h.in, include/myopt.h, lib/Makefile.in, lib/myopt.c,
+ main/main.c main/query.c dpkg-deb/main.c split/main.c dselect/main.cc,
+ lib/startup.c: New functions, standard_startup, standard_shutdown, that
+ contain the most common functions that all dpkg binaries call.
+
Thu May 23 23:23:03 CDT 2002 Adam Heath <doogie@debian.org>
* lib/lock.c: Use setcloexec wrapper instead of calling fcntl directly.
int main(int argc, const char *const *argv) {
jmp_buf ejbuf;
- setlocale(LC_ALL, "");
setlocale(LC_NUMERIC, "POSIX");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
- error_unwind(ehflag_bombout); exit(2);
- }
- push_error_handler(&ejbuf,print_error_fatal,0);
-
- myopt(&argv,cmdinfos);
+ standard_startup(&ejbuf, argc, &argv, NULL, 0, cmdinfos);
if (!cipaction) badusage(_("need an action option"));
unsetenv("GZIP");
action(argv);
- set_error_display(0,0);
- error_unwind(ehflag_normaltidy);
+ standard_shutdown();
exit(0);
}
int main(int, const char *const *argv) {
jmp_buf ejbuf;
- char *home, *homerc;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
}
push_error_handler(&ejbuf,print_error_fatal,0);
- myfileopt(CONFIGDIR "/" DSELECT ".cfg", cmdinfos);
- if ((home= getenv("HOME")) != NULL) {
- homerc= (char*)malloc((strlen(home)+strlen("/." DSELECT ".cfg")+1)*sizeof(char));
- sprintf(homerc, "%s/.%s.cfg", home, DSELECT);
- myfileopt(homerc, cmdinfos);
- free(homerc);
- }
+ loadcfgfile(DSELECT, cmdinfos);
myopt(&argv,cmdinfos);
if (*argv) {
}
cursesoff();
- set_error_display(0,0);
- error_unwind(ehflag_normaltidy);
+ standard_shutdown();
return(0);
}
#include <stdio.h>
#include <sys/types.h>
+#include <myopt.h>
+
#define ARCHIVEVERSION "2.0"
#define SPLITVERSION "2.1"
#define OLDARCHIVEVERSION "0.939000"
extern const char thisname[]; /* defined separately in each program */
extern const char printforhelp[];
+/*** from startup.c ***/
+
+void standard_startup(jmp_buf *ejbuf, int argc, const char *const **argv, const char *prog, int loadcfg, const struct cmdinfo cmdinfos[]);
+void standard_shutdown(void);
+
/*** from ehandle.c ***/
void push_error_handler(jmp_buf *jbufp,
void myfileopt(const char* fn, const struct cmdinfo* cmdinfos);
void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos);
-
+void loadcfgfile(const char *prog, const struct cmdinfo *cmdinfos);
#endif /* MYOPT_H */
SOURCES = compat.c database.c dbmodify.c dump.c ehandle.c fields.c \
lock.c mlib.c myopt.c nfmalloc.c parse.c parsehelp.c \
showcright.c showpkg.c tarfn.c varbuf.c vercmp.c md5.c \
- utils.c
+ utils.c startup.c
OBJECTS = $(patsubst %.c, %.o, $(SOURCES))
GENFILES = $(OBJECTS) libdpkg.a
#include <string.h>
#include <errno.h>
#include <ctype.h>
+#include <stdlib.h>
#include <config.h>
#include <myopt.h>
if (fclose(file)) ohshite(_("error closing configuration file `%.255s'"), fn);
}
+void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) {
+ char *home, *file;
+ int l1, l2;
+ l1 = strlen(CONFIGDIR "/.cfg") + strlen(prog);
+ file = malloc(l1 + 1);
+ sprintf(file, CONFIGDIR "/%s.cfg", prog);
+ myfileopt(file, cmdinfos);
+ if ((home = getenv("HOME")) != NULL) {
+ l2 = strlen(home) + strlen("/.cfg") + strlen(prog);
+ if (l2 > l1) {
+ free(file);
+ file = malloc(l2 + 1);
+ l1 = l2;
+ }
+ myfileopt(file, cmdinfos);
+ }
+ free(file);
+}
+
void myopt(const char *const **argvp, const struct cmdinfo *cmdinfos) {
const struct cmdinfo *cip;
const char *p, *value;
--- /dev/null
+/*
+ * dpkg - main program for package management
+ * main.c - main program
+ *
+ * Copyright (C) 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2,
+ * or (at your option) any later version.
+ *
+ * This is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with dpkg; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <limits.h>
+#include <ctype.h>
+
+#include <config.h>
+#include <dpkg.h>
+#include <dpkg-db.h>
+#include <version.h>
+#include <myopt.h>
+
+void standard_startup(jmp_buf *ejbuf, int argc, const char *const **argv, const char *prog, int loadcfg, const struct cmdinfo cmdinfos[]) {
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */
+ error_unwind(ehflag_bombout); exit(2);
+ }
+ push_error_handler(ejbuf,print_error_fatal,0);
+
+ umask(022); /* Make sure all our status databases are readable. */
+
+ if (loadcfg)
+ loadcfgfile(prog, cmdinfos);
+
+ myopt(argv,cmdinfos);
+}
+
+void standard_shutdown(void) {
+ set_error_display(0,0);
+ error_unwind(ehflag_normaltidy);
+}
int main(int argc, const char *const *argv) {
jmp_buf ejbuf;
static void (*actionfunction)(const char *const *argv);
- char *home, *homerc;
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
- error_unwind(ehflag_bombout); exit(2);
- }
- push_error_handler(&ejbuf,print_error_fatal,0);
-
- umask(022); /* Make sure all our status databases are readable. */
-
- myfileopt(CONFIGDIR "/" DPKG ".cfg", cmdinfos);
- if ((home= getenv("HOME")) != NULL) {
- homerc= (char*)malloc((strlen(home)+strlen("/." DPKG ".cfg")+1)*sizeof(char));
- sprintf(homerc, "%s/.%s.cfg", home, DPKG);
- myfileopt(homerc, cmdinfos);
- free(homerc);
- }
- myopt(&argv,cmdinfos);
+ standard_startup(&ejbuf, argc, &argv, DPKG, 1, cmdinfos);
if (!cipaction) badusage(_("need an action option"));
setvbuf(stdout,0,_IONBF,0);
actionfunction(argv);
- set_error_display(0,0);
- error_unwind(ehflag_normaltidy);
+ standard_shutdown();
return reportbroken_retexitstatus();
}
jmp_buf ejbuf;
static void (*actionfunction)(const char *const *argv);
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
- error_unwind(ehflag_bombout); exit(2);
- }
- push_error_handler(&ejbuf,print_error_fatal,0);
-
- umask(022); /* Make sure all our status databases are readable. */
-
- myopt(&argv,cmdinfos);
+ standard_startup(&ejbuf, argc, &argv, NULL, 0, cmdinfos);
if (!cipaction) badusage(_("need an action option"));
setvbuf(stdout,0,_IONBF,0);
actionfunction(argv);
- set_error_display(0,0);
- error_unwind(ehflag_normaltidy);
+ standard_shutdown();
return reportbroken_retexitstatus();
}
int l;
char *p;
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
- error_unwind(ehflag_bombout); exit(2);
- }
- push_error_handler(&ejbuf,print_error_fatal,NULL);
-
- myopt(&argv,cmdinfos);
+ standard_startup(&ejbuf, argc, &argv, NULL, 0, cmdinfos);
if (!cipaction) badusage(_("need an action option"));
l= strlen(depotdir);
if (ferror(stderr)) werr("stderr");
- set_error_display(NULL,NULL);
- error_unwind(ehflag_normaltidy);
+ standard_shutdown();
exit(0);
}