/*********************************************************************/ /* bibView: Administration of BibTeX-Databases */ /* (Verwaltung von BibTeX-Literaturdatenbanken) */ /* */ /* Module: bibview.c */ /* */ /* - Main Program */ /* - Signal Handling */ /* */ /* Author: Holger Martin, martinh@informatik.tu-muenchen.de */ /* Peter M. Urban, urban@informatik.tu-muenchen.de */ /* */ /* History: */ /* 11.22.91 PMU created */ /* 05.26.92 Version 1.0 released */ /* */ /* Copyright 1992 TU MUENCHEN */ /* See ./Copyright for complete rights and liability information. */ /* */ /*********************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bibview.h" #include "bitmaps/bv_ico64" #include "bitmaps/bv_lst64" #include "bitmaps/bv_mac64" #include "bitmaps/bv_crd64" #include "bitmaps/bv_hlp64" #include "bitmaps/bv_ann64" #include "bitmaps/chkmrk16" #include "bitmaps/error32" #include "bitmaps/warn32" #include "bitmaps/notice32" #include "bitmaps/quest32" #ifdef GERMAN #include "bitmaps/proggerm.xbm" #else #include "bitmaps/proginfo.xbm" #endif /* external global variables */ /* ------------------------- */ extern Widget desktop; extern char *latexHeader, *latexFooter; extern int latexHeaderLen, latexFooterLen; extern char *style_file; extern int cont_indent, fld_indent, newline_indent, max_linelen; extern char *actual_path; extern UserDefFld userDefFlds[]; extern PredefLists predefLst; extern listEntry *list_layout; /* exported global variables */ /* ------------------------- */ XtAppContext app_context; Widget topLevel; Pixmap bvIconPixmap; String bvIconName; Pixmap lstIconPixmap; Pixmap macIconPixmap; Pixmap crdIconPixmap; Pixmap helpIconPixmap; Pixmap annoteIconPixmap; Pixmap chkmarkPixmap; Pixmap errorPixmap; Pixmap warnPixmap; Pixmap noticePixmap; Pixmap questPixmap; Pixmap progInfoPixmap; int sortedby; /* names for card types , the order must be the same as */ /* for the type CardType in bibview.h */ String cardNames[MAX_BIBTEX_TYPES+1] = { "article", "book", "booklet", "conference", "inbook", "incollection", "inproceedings", "manual", "mastersthesis", "misc", "phdthesis", "proceedings", "techreport", "unpublished", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "userdefined" }; /* names for fields , the order must be the same as for */ /* the type FieldName in bibview.h */ String fieldNames[MAX_FIELDS] = { "crossref", "key", "author", "editor", "title", "booktitle", "institution", "journal", "organization", "chapter", "pages", "year", "month", "publisher", "address", "school", "edition", "howpublished", "volume", "number", "series", "type", "note", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; char sort_field[MAX_FIELDS]; char is_search_field[MAX_FIELDS]; char standardfields [MAX_BIBTEX_TYPES+1][MAX_FIELDS]; char requiredfields [MAX_BIBTEX_TYPES+1][MAX_FIELDS]; int max_fields; int max_bibtex_types; /* local global variables */ /* ---------------------- */ /* fallback resources */ static char *fallback_resources[] = { #ifdef GERMAN #include "fb_ger.h" #else #include "fb_res.h" #endif NULL }; static char bibfile[MAXPATHLEN+1]; OptionsRec options; #define Offset(field) XtOffsetOf(OptionsRec, field) XtResource resources[] = { { "quiet", "Quiet", XtRBoolean, sizeof(Boolean), Offset(quiet), XtRString, "False" }, { "iconsOnDesk", "IconsOnDesk", XtRBoolean, sizeof(Boolean), Offset(iconsOnDesk), XtRString, (XtPointer)"False" }, { "makeBackup", "MakeBackup", XtRBoolean, sizeof(Boolean), Offset(makeBackup), XtRString, (XtPointer)"True" }, { "autoCheck", "AutoCheck", XtRBoolean, sizeof(Boolean), Offset(autoCheck), XtRString, (XtPointer)"True" }, { "reqFields", "ReqFields", XtRBoolean, sizeof(Boolean), Offset(reqFields), XtRString, (XtPointer)"False" }, { "ignoreCase", "IgnoreCase", XtRBoolean, sizeof(Boolean), Offset(ignoreCase), XtRString, (XtPointer)"True" }, { "printAsBib", "PrintAsBib", XtRBoolean, sizeof(Boolean), Offset(printAsBib), XtRString, (XtPointer)"True" }, { "displayErrWin", "DisplayErrWin", XtRBoolean, sizeof(Boolean), Offset(displayErrWin), XtRString, (XtPointer)"True" }, { "focus", "Focus", XtRBoolean, sizeof(Boolean), Offset(focus), XtRString, (XtPointer)"True" }, { "orig", "Orig", XtRBoolean, sizeof(Boolean), Offset(orig), XtRString, (XtPointer)"False" }, { "bibfile", "Bibfile", XtRString, sizeof(String), Offset(bibfile), XtRString, (XtPointer)NULL }, { "rcfile", "Rcfile", XtRString, sizeof(String), Offset(rcfile), XtRString, (XtPointer)NULL }, { "bibdir", "Bibdir", XtRString, sizeof(String), Offset(bibdir), XtRString, (XtPointer)NULL }, { "focusColor", "FocusColor", XtRPixel, sizeof(Pixel), Offset(focusColor), XtRString, XtDefaultBackground }, { "reqColor", "ReqColor", XtRPixel, sizeof(Pixel), Offset(reqColor), XtRString, XtDefaultBackground }, { "authedColor", "AuthedColor", XtRPixel, sizeof(Pixel), Offset(authedColor), XtRString, XtDefaultBackground }, }; #undef Offset static XrmOptionDescRec optionDesc[] = { { "-quiet", "*quiet", XrmoptionNoArg, (XtPointer)"on" }, { "+quiet", "*quiet", XrmoptionNoArg, (XtPointer)"off" }, { "-iconsOnDesk", "*iconsOnDesk", XrmoptionNoArg, (XtPointer)"on" }, { "+iconsOnDesk", "*iconsOnDesk", XrmoptionNoArg, (XtPointer)"off" }, { "-makeBackup", "*makeBackup", XrmoptionNoArg, (XtPointer)"on" }, { "+makeBackup", "*makeBackup", XrmoptionNoArg, (XtPointer)"off" }, { "-autoCheck", "*autoCheck", XrmoptionNoArg, (XtPointer)"on" }, { "+autoCheck", "*autoCheck", XrmoptionNoArg, (XtPointer)"off" }, { "-reqFields", "*reqFields", XrmoptionNoArg, (XtPointer)"on" }, { "+reqFields", "*reqFields", XrmoptionNoArg, (XtPointer)"off" }, { "-ignoreCase", "*ignoreCase", XrmoptionNoArg, (XtPointer)"on" }, { "+ignoreCase", "*ignoreCase", XrmoptionNoArg, (XtPointer)"off" }, { "-printAsBib", "*printAsBib", XrmoptionNoArg, (XtPointer)"on" }, { "+printAsBib", "*printAsBib", XrmoptionNoArg, (XtPointer)"off" }, { "-displayErrWin","*displayErrWin", XrmoptionNoArg, (XtPointer)"on" }, { "+displayErrWin","*displayErrWin", XrmoptionNoArg, (XtPointer)"off" }, { "-focus", "*focus", XrmoptionNoArg, (XtPointer)"on" }, { "+focus", "*focus", XrmoptionNoArg, (XtPointer)"off" }, { "-orig", "*orig", XrmoptionNoArg, (XtPointer)"on" }, { "+orig", "*orig", XrmoptionNoArg, (XtPointer)"off" }, { "-rcfile", "*rcfile", XrmoptionSepArg, (XtPointer)NULL }, { "-bibdir", "*bibdir", XrmoptionSepArg, (XtPointer)NULL }, { "-file", "*bibfile", XrmoptionSepArg, (XtPointer)NULL } }; /* local function prototypes */ static void printHelp (int argc, char **argv); static void processCommandlineOptions (void); static Boolean readBibfile (XtPointer clientData); static void makeIconPixmaps (void); static void installErrorHandlers (void); static XtErrorHandler Xt_warningHandler (String warn); static XtErrorHandler Xt_errorHandler (String error); static int X_errorHandler (Display *dsp, XErrorEvent *event); static int IO_errorHandler (Display *dsp); static void signalHandler (int signal, int code); static void initializeFields (void); /*********************************************************************/ /* MAIN: */ /*********************************************************************/ int main(int argc, char *argv[]) { static char iconname[MAX_ICONNAMELEN+1]; static char *p, path[MAX_FILEPATHLEN+1]; int i; topLevel = XtVaAppInitialize(&app_context, /* Appl context */ "BibView", /* Appl class */ optionDesc, /* cmdline options */ XtNumber(optionDesc), &argc, argv, /* command line args */ (String *)fallback_resources,/* fallback resources */ NULL); /* end varargs list */ /* process commandline options */ XtGetApplicationResources(topLevel, (XtPointer) &options, resources, XtNumber(resources), (Arg *)NULL, 0); if (argc > 1) printHelp(argc, argv); style_file = XtMalloc(MAXPATHLEN+1); strcpy(style_file, "alpha"); sortedby = SORT_UNSRT; cont_indent = CONTINDENT; fld_indent = FLDINDENT; newline_indent = NEWLINEINDENT; max_linelen = MAX_LINELEN; actual_path = XtMalloc(MAXPATHLEN+1); for (i=0; i and key in card window\n", " -orig none Edit fields in original style\n", " +quiet none Turn on/off beep on error\n", " +iconsOnDesk none Don't keep icons on bibview desktop\n", " +makeBackup none Don't save files to backup on save\n", " +autoCheck none Turn off consistency checking\n", " +reqFields none Allow empty required fields\n", " +ignoreCase none Use case in search\n", " +focus none Use mouse in card window\n", " +orig none Edit fields in bibview style\n", " -file BibTeX File Load BibTeX-File on startup\n", " -rcfile bibview rcFile Use specific configuration file\n", " -help none Show this list\n", "\n", NULL }; char **p; int i; /* print help message */ p = help; while (*p) { fprintf(stderr, *p); p++; } /* show illegal arguments */ if (strcmp(argv[1], "-help")) { fprintf(stderr, "bibview: command line option unknown:\n"); for (i=1; i < argc; i++) fprintf(stderr, " option: %s\n", argv[i]); } else { /* just show help and exit */ exit(0); } } /*********************************************************************/ /* processCommandlineOptions: */ /* Process options not controlling widgets */ /*********************************************************************/ static void processCommandlineOptions (void) { optionsStatus[OPT_BEEP_ON_ERROR] = !options.quiet; optionsStatus[OPT_BACKUP_ON_SAVE] = options.makeBackup; optionsStatus[OPT_ICON_ON_DESKTOP] = options.iconsOnDesk; optionsStatus[OPT_AUTO_CHECK_BIB] = options.autoCheck; optionsStatus[OPT_REQUIRED_FIELDS] = options.reqFields; optionsStatus[OPT_IGNORE_CASE] = options.ignoreCase; optionsStatus[OPT_PRINT_AS_BIB] = options.printAsBib; optionsStatus[OPT_DISPLAY_ERRWIN] = options.displayErrWin; optionsStatus[OPT_FOCUS] = options.focus; optionsStatus[OPT_ORIG] = options.orig; } /*********************************************************************/ /* readBibfile: */ /* Read a bibfile with name given on command line */ /*********************************************************************/ static Boolean readBibfile (XtPointer clientData) { String filename = (String)clientData; BibPtr bp; Errcode status; /* check whether desktop positioned already */ if (XtWindow(desktop) == (Window) NULL) return (False); /* desktop is there, open file and window */ if ((status = glbNewBibListEl(&bp)) != OK) { guwError(status); return (True); } strcpy(bp->filename, filename); if ((filename[0]!='/') && (filename[0]!='~')){ #ifdef SYSV (void) getcwd(bp->filepath, MAX_FILEPATHLEN); #else (void) getwd(bp->filepath); #endif strcat(bp->filepath, "/"); strcat(bp->filepath, filename); CollapsePath(bp->filepath, filename); strcpy(bp->filepath, filename); } else CollapsePath(filename, bp->filepath); bp->mw=NULL; bp->ew=NULL; bp->lw=NULL; bp->sortedby=sortedby; glbReadFileOpenBib(bp); return(True); } /*********************************************************************/ /* initializeFields: */ /* initialize standardfields and requiredfields */ /*********************************************************************/ static void initializeFields (void) { int i, j; max_fields = 24; max_bibtex_types = 14; list_layout = (listEntry *) XtCalloc(1, sizeof(listEntry)); list_layout->number = 0; list_layout->field[list_layout->number] = nauthor; list_layout->width[(list_layout->number)++] = 30; list_layout->field[list_layout->number] = ntitle; list_layout->width[(list_layout->number)++] = 50; list_layout->field[list_layout->number] = nyear; list_layout->width[(list_layout->number)++] = 5; list_layout->field[list_layout->number] = -2; /* BibTeX type */ list_layout->width[(list_layout->number)++] = 10; list_layout->field[list_layout->number] = -1; /* mainkey */ list_layout->width[(list_layout->number)++] = 10; for (i=0; i< MAX_BIBTEX_TYPES+1; i++){ for (j=0; j< MAX_FIELDS; j++){ standardfields[i][j] = '0'; requiredfields[i][j] = '0'; } } for (i=0; i< max_bibtex_types; i++){ for (j=0; jerror_code, msg, 80); fprintf(stderr, "Error code %s\n", msg); return(0); } /*********************************************************************/ /* IO_errorHandler: */ /* Service I/O errors from X */ /*********************************************************************/ static int IO_errorHandler (Display *dsp) { fprintf(stderr, "Fatal Error on X Display %s\n", (char *)XDisplayName(NULL)); exit(1); } /*********************************************************************/ /* signalHandler: */ /* Service signals */ /*********************************************************************/ static void signalHandler (int s, int code) { signal(s, (sig_t)signalHandler); }