X Desktop Manager
Edward J. Groenendaal
eddyg at syma.sussex.ac.uk
Thu Apr 18 06:49:06 AEST 1991
---- Cut Here and unpack ----
#!/bin/sh
# this is part 3 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file code/map.c continued
#
CurArch=3
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
exit 1; fi
( read Scheck
if test "$Scheck" != $CurArch
then echo "Please unpack part $Scheck next!"
exit 1;
else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file code/map.c"
sed 's/^X//' << 'SHAR_EOF' >> code/map.c
X#include <X11/Shell.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/AsciiText.h>
X#include "Xedw/XedwForm.h"
X#include "Xedw/XedwList.h"
X
Xextern void realize_dialog(Widget);
X
X/* Widgets */
X
Xprivate Widget mappopup; /* For mapping prog over files */
Xprivate Widget mapform;
Xprivate Widget maplabel;
Xprivate Widget mappromptlabel;
Xprivate Widget maptext;
Xprivate Widget mapCancel;
Xprivate Widget mapOK;
X
Xpublic void init_map(Widget top)
X{
X Arg arglist[5];
X Cardinal i;
X XtTranslations mapTranslations;
X
X static char defaultTranslations[] =
X "Ctrl<Key>A: beginning-of-line() \n\
X Ctrl<Key>E: end-of-line() \n\
X <Key>Escape: beginning-of-line() kill-to-end-of-line() \n\
X <Key>Right: forward-character() \n\
X <Key>Left: backward-character() \n\
X <Key>Delete: delete-previous-character() \n\
X <Key>BackSpace: delete-previous-character() \n\
X <Key>: insert-char() \n\
X <FocusIn>: focus-in() \n\
X <FocusOut>: focus-out() \n\
X <BtnDown>: select-start()";
X
X
X mappopup = XtCreatePopupShell("mappopup",
X transientShellWidgetClass,
X top,
X NULL, 0);
X
X mapform = XtCreateManagedWidget("mapform",
X xedwFormWidgetClass,
X mappopup,
X NULL, 0);
X
X i = 0;
X XtSetArg(arglist[i], XtNborderWidth, 0); i++;
X XtSetArg(arglist[i], XtNfullWidth, True); i++;
X XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
X maplabel = XtCreateManagedWidget("maplabel",
X labelWidgetClass,
X mapform,
X arglist, i);
X
X i = 1;
X XtSetArg(arglist[i], XtNfromVert, maplabel); i++;
X mappromptlabel = XtCreateManagedWidget("mappromptlabel",
X labelWidgetClass,
X mapform,
X arglist, i);
X
X i = 2;
X XtSetArg(arglist[i], XtNfromHoriz, mappromptlabel); i++;
X XtSetArg(arglist[i], XtNfullWidth, True); i++;
X XtSetArg(arglist[i], XtNeditType, XawtextEdit); i++;
X maptext = XtCreateManagedWidget("maptext",
X asciiTextWidgetClass,
X mapform,
X arglist, i);
X
X i = 0;
X XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
X XtSetArg(arglist[i], XtNfromVert, maptext); i++;
X XtSetArg(arglist[i], XtNlabel, "Cancel"); i++;
X mapCancel = XtCreateManagedWidget("mapCancel",
X commandWidgetClass,
X mapform,
X arglist, i);
X
X i = 2;
X XtSetArg(arglist[i], XtNfromHoriz, mapCancel); i++;
X XtSetArg(arglist[i], XtNwidthLinked, mapCancel); i++;
X XtSetArg(arglist[i], XtNlabel, "OK"); i++;
X mapOK = XtCreateManagedWidget("mapOK",
X commandWidgetClass,
X mapform,
X arglist, i);
X
X
X XtUninstallTranslations(maptext);
X mapTranslations = XtParseTranslationTable(defaultTranslations);
X XtOverrideTranslations(maptext, mapTranslations);
X
X}
X
Xpublic void map_dialog(Boolean map)
X{
X /* if map is true then put map dialog up, otherwise use the
X * select dialog.
X */
X private void mapQueryResult(Widget, Boolean, caddr_t);
X private void selectQueryResult(Widget, Boolean, caddr_t);
X Arg arglist[1];
X
X XtSetArg(arglist[0], XtNstring, "");
X XtSetValues(maptext, arglist, 1);
X
X if (map == True) {
X XtSetArg(arglist[0], XtNlabel, " Map Program over Selected Files ");
X XtSetValues(maplabel, arglist, 1);
X
X XtSetArg(arglist[0], XtNlabel, "Program:");
X XtSetValues(mappromptlabel, arglist, 1);
X
X XtAddCallback(mapCancel, XtNcallback, mapQueryResult, False);
X XtAddCallback(mapOK, XtNcallback, mapQueryResult, True);
X } else {
X XtSetArg(arglist[0], XtNlabel, "Select Files by Regular Expression");
X XtSetValues(maplabel, arglist, 1);
X
X XtSetArg(arglist[0], XtNlabel, "RegExp: ");
X XtSetValues(mappromptlabel, arglist, 1);
X
X XtAddCallback(mapCancel, XtNcallback, selectQueryResult, False);
X XtAddCallback(mapOK, XtNcallback, selectQueryResult, True);
X }
X
X realize_dialog(mappopup);
X}
X
Xprivate void destroy_map_dialog(void)
X{
X Arg arglist[1];
X
X XtPopdown(mappopup);
X
X XtRemoveAllCallbacks(mapCancel, XtNcallback);
X XtRemoveAllCallbacks(mapOK, XtNcallback);
X}
X
Xprivate void mapQueryResult(Widget w, Boolean ok, caddr_t call_data)
X{
X extern String build_arguments(String, SelOptions);
X extern int execute(String, String, String, Boolean);
X extern void setCursor(Cursor);
X extern Cursor busy;
X String mapprogram, program, filename;
X Arg arglist[1];
X
X destroy_map_dialog();
X
X if (ok == True) {
X setCursor(busy);
X /* get program name from text widget */
X XtSetArg(arglist[0], XtNstring, &mapprogram);
X XtGetValues(maptext, arglist, 1);
X
X program = XtNewString(mapprogram);
X
X /* extract filename from program */
X filename = XtNewString(program);
X filename = strtok(filename, " ");
X
X /* Get list of files */
X program = build_arguments(program, M_SEL);
X
X execute(NULL, filename, program, False);
X setCursor(NULL);
X }
X}
X
Xprivate void selectQueryResult(Widget w, Boolean ok, caddr_t call_data)
X{
X extern void highlight_by_re(String);
X extern void setCursor(Cursor);
X extern Cursor busy;
X String re;
X Arg arglist[1];
X
X destroy_map_dialog();
X
X if (ok == True) {
X /* Get regular expression */
X setCursor(busy);
X XtSetArg(arglist[0], XtNstring, &re);
X XtGetValues(maptext, arglist, 1);
X
X highlight_by_re(re);
X
X setCursor(NULL);
X }
X}
SHAR_EOF
echo "File code/map.c is complete"
chmod 0644 code/map.c || echo "restore of code/map.c fails"
echo "x - extracting code/menus.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > code/menus.c &&
X/*****************************************************************************
X ** File : menus.c **
X ** Purpose : Create, and handle the pull down menus **
X ** Author : Edward Groenendaal **
X ** Date : 18th Feb 1991 **
X ** Documentation : Xdtm Design Folder **
X ** Related Files : **
X *****************************************************************************/
X
X#include "xdtm.h"
X#include "menus.h"
X#include <sys/stat.h>
X#include <X11/Xaw/MenuButton.h>
X#include <X11/Xaw/SimpleMenu.h>
X#include <X11/Xaw/SmeBSB.h>
X#include <X11/Xaw/SmeLine.h>
X
X#include "Xedw/XedwList.c"
X#include "Xedw/XedwForm.h"
X#include "bitmaps/Tick"
X#include "bitmaps/EmptyTick"
X
Xstatic MenuContents fileMenuStrings[] = {
X { "about", "About Xdtm...", About, noflag },
X { "help", "Help", Help, noflag },
X { LINE, NULL, 0, noflag },
X { "new", "New File", New, noflag },
X { "duplicate", "Duplicate File", Duplicate, noflag },
X { LINE, NULL, 0, noflag },
X { "getinfo", "Get Info", Getinfo, noflag },
X { "copy", "Copy files", Copy, noflag },
X { "move", "Move files", Move, noflag },
X { "trash", "Delete files", Trash, noflag },
X { LINE, NULL, 0, noflag },
X { "quit", "Quit Program", Quit, noflag },
X};
X
Xstatic MenuContents optionMenuStrings[] = {
X { "map", "Map Program over Files", Map, noflag },
X { "select", "Select Files by Template", Select, noflag },
X};
X
Xstatic MenuContents viewMenuStrings[] = {
X { "icons", "Show Icons", Icons, flagged },
X { "short", "No Icons", Short, flagged },
X { LINE, NULL, 0, flagged },
X { "long", "Long Listing", Long, flagged },
X { "options", "Options", Options, flagged },
X};
X
XCardinal fileMenuSize = sizeof(fileMenuStrings) /
X sizeof(fileMenuStrings[0]);
XCardinal optionMenuSize = sizeof(optionMenuStrings) /
X sizeof(optionMenuStrings[0]);
XCardinal viewMenuSize = sizeof(viewMenuStrings) /
X sizeof(viewMenuStrings[0]);
X
Xpublic Arg chain_position[] = { XtNtop, XtChainTop,
X XtNbottom, XtChainBottom,
X XtNleft, XtChainLeft,
X XtNright, XtChainRight,
X NULL, NULL
X };
X
XCardinal chain_size = sizeof(chain_position)/sizeof(chain_position[0]);
X
Xpublic Pixmap tick, emptytick;
Xpublic Widget menuBar;
X
Xpublic Icon_mode current_mode;
X
X
Xpublic void createMenuWidgets(Widget w)
X{
X private void menuSelect(Widget, Cardinal, caddr_t);
X public void createMenu(Widget, MenuContents[], Cardinal,
X void (*)(Widget, Cardinal, caddr_t) );
X
X Widget fileMenuButton, optionMenuButton, viewMenuButton, selectionMenuButton;
X Widget fileMenu, optionMenu, viewMenu;
X Arg arglist[5], *newlist;
X Cardinal i;
X
X i = 0;
X XtSetArg(arglist[i], XtNrubberWidth, False); i++;
X XtSetArg(arglist[i], XtNrubberHeight, False); i++;
X XtSetArg(arglist[i], XtNborderWidth, 0); i++;
X newlist = XtMergeArgLists(arglist, i, chain_position, chain_size);
X menuBar = XtCreateManagedWidget("menuBar",
X xedwFormWidgetClass,
X w,
X newlist, i + chain_size);
X XtFree(newlist);
X
X i = 0;
X XtSetArg(arglist[i], XtNhighlightThickness, 0); i++;
X XtSetArg(arglist[i], XtNborderWidth, 0); i++;
X XtSetArg(arglist[i], XtNmenuName, "fileMenu"); i++;
X XtSetArg(arglist[i], XtNlabel, "File"); i++;
X XtSetArg(arglist[i], XtNvertDistance, 0); i++;
X fileMenuButton = XtCreateManagedWidget("fileMenuButton",
X menuButtonWidgetClass,
X menuBar,
X arglist, i);
X
X i = 2;
X XtSetArg(arglist[i], XtNmenuName, "optionMenu"); i++;
X XtSetArg(arglist[i], XtNlabel, "Options"); i++;
X XtSetArg(arglist[i], XtNfromHoriz, fileMenuButton); i++;
X XtSetArg(arglist[i], XtNvertDistance, 0); i++;
X optionMenuButton = XtCreateManagedWidget("optionMenuButton",
X menuButtonWidgetClass,
X menuBar,
X arglist, i);
X
X i = 2;
X XtSetArg(arglist[i], XtNmenuName, "viewMenu"); i++;
X XtSetArg(arglist[i], XtNlabel, "View"); i++;
X XtSetArg(arglist[i], XtNfromHoriz, optionMenuButton); i++;
X XtSetArg(arglist[i], XtNvertDistance, 0); i++;
X viewMenuButton = XtCreateManagedWidget("viewMenuButton",
X menuButtonWidgetClass,
X menuBar,
X arglist, i);
X
X fileMenu = XtCreatePopupShell("fileMenu",
X simpleMenuWidgetClass,
X fileMenuButton,
X NULL, 0);
X
X optionMenu = XtCreatePopupShell("optionMenu",
X simpleMenuWidgetClass,
X optionMenuButton,
X NULL, 0);
X
X viewMenu = XtCreatePopupShell("viewMenu",
X simpleMenuWidgetClass,
X viewMenuButton,
X NULL, 0);
X
X tick = XCreateBitmapFromData(XtDisplay(w),
X RootWindowOfScreen(XtScreen(w)),
X tick_bits, tick_width,
X tick_height);
X
X emptytick = XCreateBitmapFromData(XtDisplay(w),
X RootWindowOfScreen(XtScreen(w)),
X EmptyTick_bits,
X EmptyTick_width,
X EmptyTick_height);
X
X createMenu(fileMenu, fileMenuStrings, fileMenuSize, menuSelect);
X
X createMenu(optionMenu, optionMenuStrings, optionMenuSize, menuSelect);
X
X createMenu(viewMenu, viewMenuStrings, viewMenuSize, menuSelect);
X
X current_mode.options = (PERMS | NLINKS | OWNER | GROUP | SIZE);
X
X}
X
X
X
Xpublic void createMenu(Widget menu, MenuContents menuStrings[],
X Cardinal menuSize, void (*function)())
X{
X Widget menuEntry;
X Cardinal i, n;
X Arg arglist[3];
X
X for(n=0; n < menuSize; n++) {
X MenuContents entry = menuStrings[n];
X String widgetname = entry.paneName;
X if (!strcmp(LINE, widgetname))
X menuEntry = XtCreateManagedWidget(widgetname, smeLineObjectClass,
X menu, NULL, 0);
X else {
X i = 0;
X XtSetArg(arglist[i], XtNlabel, entry.paneLabel); i++;
X if (entry.set == flagged) {
X XtSetArg(arglist[i], XtNleftMargin, (tick_width*1.5)); i++;
X if (entry.paneNumber == current_mode.mode) {
X XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
X } else {
X XtSetArg(arglist[i], XtNleftBitmap, None); i++;
X }
X }
X
X menuEntry = XtCreateManagedWidget(widgetname, smeBSBObjectClass,
X menu, arglist, i);
X if (entry.paneNumber == current_mode.mode && entry.set == flagged)
X current_mode.w = menuEntry;
X
X XtAddCallback(menuEntry, XtNcallback, function,
X (caddr_t) entry.paneNumber);
X }
X }
X}
X
X
Xprivate void menuSelect(Widget w, Cardinal paneNumber, caddr_t rubbish)
X{
X extern void map_dialog(Boolean);
X extern void quit_dialog(void);
X extern void query_dialog(String, Boolean);
X extern void displayfile(String);
X extern void newfile_dialog(Boolean, String, Boolean);
X extern void button_selected(Widget, Cardinal, caddr_t);
X extern void listoption_dialog(void);
X extern Boolean directoryManagerNewDirectory(String);
X extern String getfilename(String);
X extern void setCursor(Cursor);
X extern Cursor busy;
X extern String cwd;
X extern Widget directoryManager;
X XedwListReturnStruct *highlighted;
X String filename, fullname, level;
X struct stat filestatus;
X Arg arglist[6];
X Cardinal i;
X
X switch (paneNumber) {
X case About:
X level = XtMalloc (sizeof(char) * 25);
X sprintf(level, " Xdtm v%d.%d ", RELEASE, PATCHLEVEL);
X query_dialog(level, False);
X break;
X case Help:
X if (access(SYSTEM_HELP, R_OK) == 0)
X displayfile(SYSTEM_HELP);
X else
X query_dialog("Help not found!", False);
X break;
X
X case New:
X newfile_dialog(False, NULL, False);
X break;
X
X case Duplicate:
X /* Find out whether highlighted file is a regular file or a directory */
X highlighted = XedwListShowCurrent(directoryManager);
X if (highlighted->xedwList_index != XDTM_LIST_NONE) {
X if (highlighted->next != NULL)
X query_dialog("Only one file!", False);
X else {
X filename = getfilename(highlighted->string);
X fullname=(String) XtMalloc((strlen(filename)+strlen(cwd)+1) * sizeof(char));
X strcpy(fullname, cwd);
X if (strcmp(cwd, "/") != 0)
X strcat(fullname, "/");
X strcat(fullname, filename);
X if (stat(fullname, &filestatus) == -1) {
X fprintf(stderr,"xdtm: ARRRGGHHH stat error\n");
X } else {
X if ((filestatus.st_mode & S_IFMT) == S_IFDIR)
X /* Is a directory */
X newfile_dialog(True, filename, True);
X else if ((filestatus.st_mode & S_IFMT) == S_IFREG)
X newfile_dialog(True, filename, False);
X else
X query_dialog("Wrong file type!", False);
X }
X XtFree(fullname);
X }
X } else
X fprintf(stderr, "Error: Duplicate selected when should have been"
X " disabled\n");
X break;
X
X case Getinfo:
X query_dialog("Not implemented!", False);
X break;
X
X case Copy:
X case Move:
X case Trash:
X /* Call button press with it */
X button_selected(w, paneNumber, 0);
X break;
X
X case Quit:
X quit_dialog();
X break;
X
X case Map:
X map_dialog(True);
X break;
X
X case Select:
X map_dialog(False);
X break;
X
X case Icons:
X if (current_mode.mode != Icons) {
X i = 0;
X XtSetArg(arglist[i], XtNleftBitmap, None); i++;
X XtSetValues(current_mode.w, arglist, i);
X i = 0;
X XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
X XtSetValues(w, arglist, i);
X current_mode.w = w;
X current_mode.mode = Icons;
X XtSetArg(arglist[i], XtNshowIcons, True); i++;
X XtSetArg(arglist[i], XtNrowSpacing, 10); i++;
X XtSetArg(arglist[i], XtNforceColumns, False); i++;
X XtSetArg(arglist[i], XtNdefaultColumns, 2); i++;
X XtSetValues(directoryManager, arglist, i);
X directoryManagerNewDirectory(cwd);
X }
X break;
X
X case Short:
X if (current_mode.mode != Short) {
X i = 0;
X XtSetArg(arglist[i], XtNleftBitmap, None); i++;
X XtSetValues(current_mode.w, arglist, i);
X i = 0;
X XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
X XtSetValues(w, arglist, i);
X current_mode.w = w;
X current_mode.mode = Short;
X i = 0;
X XtSetArg(arglist[i], XtNshowIcons, False); i++;
X XtSetArg(arglist[i], XtNrowSpacing, 5); i++;
X XtSetArg(arglist[i], XtNforceColumns, False); i++;
X XtSetArg(arglist[i], XtNdefaultColumns, 2); i++;
X XtSetValues(directoryManager, arglist, i);
X directoryManagerNewDirectory(cwd); /* To be consistent */
X }
X break;
X
X case Long:
X if (current_mode.mode != Long) {
X i = 0;
X XtSetArg(arglist[i], XtNleftBitmap, None); i++;
X XtSetValues(current_mode.w, arglist, i);
X i = 0;
X XtSetArg(arglist[i], XtNleftBitmap, tick); i++;
X XtSetValues(w, arglist, i);
X current_mode.w = w;
X current_mode.mode = Long;
X i = 0;
X XtSetArg(arglist[i], XtNshowIcons, False); i++;
X XtSetArg(arglist[i], XtNrowSpacing, 5); i++;
X XtSetArg(arglist[i], XtNforceColumns, True); i++;
X XtSetArg(arglist[i], XtNdefaultColumns, 1); i++;
X XtSetValues(directoryManager, arglist, i);
X directoryManagerNewDirectory(cwd); /* To be consistent */
X }
X break;
X
X case Options:
X listoption_dialog();
X break;
X
X default:
X fprintf(stderr, "Menu option number %d not supported\n", paneNumber);
X break;
X }
X
X
X}
X
SHAR_EOF
chmod 0644 code/menus.c || echo "restore of code/menus.c fails"
echo "x - extracting code/menus.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > code/menus.h &&
X/***********************************************************************************
X ** File : menus.h **
X ** Purpose : **
X ** Author : Edward Groenendaal **
X ** Date : 18th Feb 1990 **
X ** Documentation : Xedw Design Folder **
X ** Related Files : menus.c **
X ***********************************************************************************/
X
X#ifndef _EG_menus_h
X#define _EG_menus_h
X
X#include <X11/Intrinsic.h>
X
X#define LINE "line"
X
X#define PERMS (1 << 1)
X#define NLINKS (1 << 2)
X#define OWNER (1 << 3)
X#define GROUP (1 << 4)
X#define SIZE (1 << 5)
X#define MODTM (1 << 6)
X#define ACCTM (1 << 7)
X
Xtypedef enum {flagged, noflag} Flags;
X
Xtypedef enum {
X About,
X Help,
X New,
X Duplicate,
X Getinfo,
X Copy,
X Move,
X Trash,
X Quit,
X Map,
X Select,
X Icons,
X Short,
X Long,
X Options
X} MenuValue;
X
Xtypedef struct {
X String paneName;
X String paneLabel;
X MenuValue paneNumber;
X Flags set;
X} MenuContents;
X
Xtypedef struct {
X Widget w;
X MenuValue mode;
X /* long listing options */
X Cardinal length;
X char options;
X} Icon_mode;
X
Xextern Widget menuBar;
Xextern Icon_mode current_mode;
Xextern Pixmap tick;
Xextern Pixmap emptytick;
X
X#endif /* _EG_menus_h */
SHAR_EOF
chmod 0644 code/menus.h || echo "restore of code/menus.h fails"
echo "x - extracting code/newfile.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > code/newfile.c &&
X/*****************************************************************************
X ** File : newfile.c **
X ** Purpose : Initialise and Realise newfile dialog **
X ** Author : Edward Groenendaal **
X ** Date : April 1991 **
X ** Documentation : Xdtm Design Folder **
X ** Related Files : **
X *****************************************************************************/
X
X#include "xdtm.h"
X
X#include <X11/Shell.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/AsciiText.h>
X#include "Xedw/XedwForm.h"
X
Xextern void realize_dialog(Widget);
X
X/* Widgets */
X
Xprivate Widget newfilepopup;
Xprivate Widget newfileform;
Xprivate Widget newfilelabel;
Xprivate Widget newfiletext;
Xprivate Widget newfilefile;
Xprivate Widget newfiledir;
Xprivate Widget newfilecancel;
X
Xtypedef struct {
X String filename;
X Boolean isdir;
X} Filetype;
X
Xpublic void init_newfile(Widget top)
X{
X /* Create Widgets for newfile dialog */
X private void destroy_newfile_dialog(Widget, caddr_t, caddr_t);
X
X Arg arglist[5];
X Cardinal i;
X XtTranslations newfileTranslations;
X
X static char defaultTranslations[] =
X "Ctrl<Key>A: beginning-of-line() \n\
X Ctrl<Key>E: end-of-line() \n\
X <Key>Escape: beginning-of-line() kill-to-end-of-line() \n\
X <Key>Right: forward-character() \n\
X <Key>Left: backward-character() \n\
X <Key>Delete: delete-previous-character() \n\
X <Key>BackSpace: delete-previous-character() \n\
X <Key>: insert-char() \n\
X <FocusIn>: focus-in() \n\
X <FocusOut>: focus-out() \n\
X <BtnDown>: select-start()";
X
X
X newfilepopup = XtCreatePopupShell("newfilepopup",
X transientShellWidgetClass,
X top,
X NULL, 0);
X
X newfileform = XtCreateManagedWidget("newfileform",
X xedwFormWidgetClass,
X newfilepopup,
X NULL, 0);
X
X /* label widget to prompt for new filename */
X
X i = 0;
X XtSetArg(arglist[i], XtNfullWidth, True); i++;
X XtSetArg(arglist[i], XtNborderWidth, 0); i++;
X XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++;
X newfilelabel = XtCreateManagedWidget("newfilelabel",
X labelWidgetClass,
X newfileform,
X arglist, i);
X
X /* new filename text input widget */
X
X i = 1;
X XtSetArg(arglist[i], XtNfromVert, newfilelabel); i++;
X XtSetArg(arglist[i], XtNeditType, XawtextEdit); i++;
X newfiletext = XtCreateManagedWidget("newfiletext",
X asciiTextWidgetClass,
X newfileform,
X arglist, i);
X
X i = 0;
X XtSetArg(arglist[i], XtNfromVert, newfiletext); i++;
X XtSetArg(arglist[i], XtNlabel, "Directory"); i++;
X newfiledir = XtCreateManagedWidget("newfiledir",
X commandWidgetClass,
X newfileform,
X arglist, i);
X i = 1;
X XtSetArg(arglist[i], XtNfromHoriz, newfiledir); i++;
X XtSetArg(arglist[i], XtNwidthLinked, newfiledir); i++;
X XtSetArg(arglist[i], XtNlabel, "File"); i++;
X newfilefile = XtCreateManagedWidget("newfilefile",
X commandWidgetClass,
X newfileform,
X arglist, i);
X
X i = 1;
X XtSetArg(arglist[i], XtNfromHoriz, newfilefile); i++;
X XtSetArg(arglist[i], XtNwidthLinked, newfilefile); i++;
X XtSetArg(arglist[i], XtNlabel, "Cancel"); i++;
X newfilecancel = XtCreateManagedWidget("newfilecancel",
X commandWidgetClass,
X newfileform,
X arglist, i);
X
X /* Add callbacks for buttons */
X XtAddCallback(newfilecancel, XtNcallback, destroy_newfile_dialog, 0);
X
X /* Do the translations on the text widget */
X XtUninstallTranslations(newfiletext);
X newfileTranslations = XtParseTranslationTable(defaultTranslations);
X XtOverrideTranslations(newfiletext, newfileTranslations);
X}
X
Xpublic void newfile_dialog(Boolean rename, String newname, Boolean isdir)
X{
X /* Popup the newfile dialog on screen with the correct data */
X private void newfileQueryReturn(Widget, Boolean, caddr_t);
X private void duplicateQueryReturn(Widget, Filetype*, caddr_t);
X Arg arglist[1];
X String filename;
X Filetype *filetype;
X
X static String defaultfilename = "untitled";
X
X filetype = (Filetype*) XtMalloc (sizeof(Filetype));
X
X if (newname == NULL)
X filename = defaultfilename;
X else
X filename = newname;
X
X if (rename == False) {
X /* Create a new file */
X
X XtSetArg(arglist[0], XtNlabel, "Create a new file");
X XtSetValues(newfilelabel, arglist, 1);
X
X XtSetArg(arglist[0], XtNstring, filename);
X XtSetValues(newfiletext, arglist, 1);
X
X /* Add callbacks for buttons */
X XtAddCallback(newfiledir, XtNcallback, newfileQueryReturn, True);
X XtAddCallback(newfilefile, XtNcallback, newfileQueryReturn, False);
X } else {
X /* rename an existing file */
X filetype->filename = filename;
X filetype->isdir = isdir;
X
X XtSetArg(arglist[0], XtNlabel, "Duplicate file");
X XtSetValues(newfilelabel, arglist, 1);
X
X XtSetArg(arglist[0], XtNstring, filename);
X XtSetValues(newfiletext, arglist, 1);
X
X if (isdir == True)
X XtSetSensitive(newfilefile, False);
X else
X XtSetSensitive(newfiledir, False);
X XtAddCallback(newfiledir, XtNcallback, duplicateQueryReturn, filetype);
X XtAddCallback(newfilefile, XtNcallback, duplicateQueryReturn, filetype);
X }
X
X realize_dialog(newfilepopup);
X
X}
X
Xprivate void destroy_newfile_dialog(Widget w, caddr_t dummy1, caddr_t dummy2)
X{
X
X XtPopdown(newfilepopup);
X
X XtSetSensitive(newfilefile, True);
X XtSetSensitive(newfiledir, True);
X XtRemoveAllCallbacks(newfilefile, XtNcallback);
X XtRemoveAllCallbacks(newfiledir, XtNcallback);
X}
X
Xprivate void newfileQueryReturn(Widget w, Boolean isdir, caddr_t dummy)
X{
X extern void query_dialog(String, Boolean);
X extern String cwd;
X String filename, fullname;
X Arg arglist[1];
X int fd;
X
X destroy_newfile_dialog(w, 0, 0);
X
X XtSetArg(arglist[0], XtNstring, &filename);
X XtGetValues(newfiletext, arglist, 1);
X
X fullname = (String) XtMalloc (sizeof(char) * (strlen(cwd) +
X strlen(filename) + 2));
X sprintf(fullname, "%s/%s", cwd, filename);
X
X if (isdir == True) {
X /* Create a directory with the name 'filename' */
X if ((fd = mkdir(fullname, 0777)) == -1)
X query_dialog("Can't create dir", False);
X else
X directoryManagerNewDirectory(cwd);
X } else {
X /* Create a file with the name 'filename' */
X if ((fd = creat(fullname, 0666)) == -1) {
X /* Can't create fullname, maybe should look in errno to see why? */
X query_dialog("Can't create file", False);
X } else {
X close(fd);
X directoryManagerNewDirectory(cwd);
X }
X }
X
X XtFree(fullname);
X}
X
X
Xprivate void duplicateQueryReturn(Widget w, Filetype *filetype, caddr_t dummy)
X{
X extern void query_dialog(String, Boolean);
X extern String cwd;
X String filename, command;
X Arg arglist[1];
X int fd;
X
X destroy_newfile_dialog(w, 0, 0);
X
X XtSetArg(arglist[0], XtNstring, &filename);
X XtGetValues(newfiletext, arglist, 1);
X
X command = XtMalloc (sizeof(char) * (strlen(filetype->filename) +
X strlen(filename) + 20));
X
X if (filetype->isdir == True) {
X /* make new directory, copy contents of old one into it */
X if ((fd = mkdir(filename, 0777)) == -1)
X query_dialog("Can't create dir", False);
X sprintf(command, "sh -c 'cp -r \"%s\"/ \"%s\"'", filetype->filename,
X filename);
X
X if (execute(NULL, "sh", command, True) != 0)
X query_dialog("Can't copy files!", False);
X else
X directoryManagerNewDirectory(cwd);
X } else {
X sprintf(command, "cp '%s' '%s'", filetype->filename, filename);
X
X if (execute(NULL, "cp", command, True) != 0)
X query_dialog("Can't create file!", False);
X else
X directoryManagerNewDirectory(cwd);
X }
X
X XtFree(command);
X}
SHAR_EOF
chmod 0644 code/newfile.c || echo "restore of code/newfile.c fails"
echo "x - extracting code/parse.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > code/parse.c &&
X/*****************************************************************************
X ** File : parse.c **
X ** Purpose : Parse setup file, select icon to be used. **
X ** Author : Edward Groenendaal **
X ** Date : 19th Feb 1990 **
X ** Documentation : Xdtm Design Folder **
X ** Related Files : **
X *****************************************************************************/
X
X#include "xdtm.h"
X
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <sys/param.h>
X#include <sys/file.h>
X#include <pwd.h>
X#include <grp.h>
X#include "parse.h"
X#include "menus.h"
X
X#include "Xedw/XedwList.h"
X
X#include "bitmaps/Grey.Mask"
X#include "bitmaps/folder.icon"
X#include "bitmaps/file.icon"
X
Xtypedef struct _BTree {
X Pixmap icon;
X Pixmap grey;
X struct _BTree *left;
X struct _BTree *right;
X} BTree;
X
Xextern FILE *yyin;
Xextern int step(char*, char*);
Xextern int circf;
Xextern typePrefs *prefs ;
X
Xpublic uid_t user;
Xpublic uid_t group;
Xprivate BTree *grey_tree;
X
Xprivate Pixmap applyprefs(typePrefs*, String, String, struct stat*);
Xprivate Pixmap do_iconprefs(iconPrefs*, String, String, struct stat*);
X
Xpublic GC xdtmgc;
Xpublic Pixmap foldericon, fileicon, grey_mask; /* default icons */
X
Xpublic Boolean getIconType(String filename, String path, XedwList *element)
X{
X /* Return True if file should be displayed, otherwise False.
X * If long listing is on, element should be DUMMY, and this
X * routine should fill the entries into the icon_list.
X */
X
X private Pixmap grey_icon(Pixmap);
X
X extern Icon_mode current_mode;
X struct stat *filestatus;
X typePrefs *myprefs = prefs;
X String fullname;
X Pixmap icon;
X
X element->string = XtNewString(filename);
X
X if (current_mode.mode != Short) {
X filestatus = (struct stat*) XtMalloc (sizeof(struct stat));
X fullname=(String) XtMalloc((strlen(filename)+strlen(path)+1) * sizeof(char));
X strcpy(fullname, path);
X strcat(fullname, "/");
X strcat(fullname, filename);
X if (lstat(fullname, filestatus) == -1) {
X /* maybe a link to a nonexistent file? */
X return(False);
X } else {
X if (current_mode.mode == Icons) {
X element->icon = fileicon;
X if ((filestatus->st_mode & S_IFMT) == S_IFDIR) /* stat(5) for details */
X element->icon = foldericon;
X
X /* try all rules in prefs */
X if ((icon = applyprefs(myprefs, fullname, filename, filestatus)) != NULL) {
X
X /* If the file is a directory but is not readable AND executable by the user
X * then grey it. If the file is not readable then grey it.
X */
X
X /* if not readable then grey it */
X if (icon != DUMMY)
X if (!(((filestatus->st_mode & S_IRUSR) != 0 &&
X user == filestatus->st_uid) ||
X ((filestatus->st_mode & S_IRGRP) != 0 &&
X group == filestatus->st_gid) ||
X ((filestatus->st_mode & S_IROTH) != 0))) {
X icon = grey_icon(icon);
X } else {
X if ((filestatus->st_mode & S_IFMT) == S_IFDIR)
X if (!(((filestatus->st_mode & S_IXUSR) != 0 &&
X user == filestatus->st_uid) ||
X ((filestatus->st_mode & S_IXGRP) != 0 &&
X group == filestatus->st_gid) ||
X ((filestatus->st_mode & S_IXOTH) != 0))) {
X icon = grey_icon(icon);
X }
X }
X element->icon = icon;
X }
X } else {
X /* Long Listing */
X Cardinal length;
X char cm = current_mode.options;
X String output_line = "";
X
X element->icon = NULL;
X length = 0;
X if (cm & PERMS) {
X char type;
X char xusr, xgrp, xoth;
X unsigned short mode = (filestatus->st_mode);
X
X output_line = (String) XtMalloc (sizeof(char) * 12);
X
X /* I could use the S_IS* macros here but I prefer to see what's
X * going on.
X */
X if ((mode & S_IFMT) == S_IFDIR) type = 'd'; /* Directory */
X else if ((mode & S_IFMT) == S_IFBLK) type = 'b'; /* Block device */
X else if ((mode & S_IFMT) == S_IFCHR) type = 'c'; /* Character device */
X else if ((mode & S_IFMT) == S_IFREG) type = ' '; /* Plain file */
X else if ((mode & S_IFMT) == S_IFIFO) type = 'f'; /* Fifo */
X else if ((mode & S_IFMT) == S_IFLNK) type = 'l'; /* Symbolic link */
X else if ((mode & S_IFMT) == S_IFSOCK) type = 's'; /* Socket */
X else type = '?';
X
X if (mode & S_ISUID) /* Set User Id */
X xusr = 's';
X else if (mode & S_IXUSR)
X xusr = 'x';
X else
X xusr = '-';
X
X if (mode & S_ISGID) /* Set Group Id */
X xgrp = 's';
X else if (mode & S_IXGRP)
X xgrp = 'x';
X else
X xgrp = '-';
X
X if (mode & S_ISVTX) /* Save Text */
X xoth = 't';
X else if (mode & S_IXOTH)
X xoth = 'x';
X else
X xoth = '-';
X
X sprintf(output_line,
X "%c%c%c%c%c%c%c%c%c%c ",
X type,
X (mode & S_IRUSR) ? 'r' : '-',
X (mode & S_IWUSR) ? 'w' : '-',
X xusr,
X (mode & S_IRGRP) ? 'r' : '-',
X (mode & S_IWGRP) ? 'w' : '-',
X xgrp,
X (mode & S_IROTH) ? 'r' : '-',
X (mode & S_IWOTH) ? 'w' : '-',
X xoth);
X }
X
X if (cm & NLINKS) {
X output_line = XtRealloc (output_line,
X sizeof(char) *
X (strlen(output_line) + 3 + 2));
X
X sprintf(output_line, "%s%3d ", output_line,
X filestatus->st_nlink);
X }
X if (cm & OWNER) {
X struct passwd *pw;
X
X output_line = XtRealloc (output_line,
X sizeof(char) *
X (strlen(output_line) + 8 + 2));
X
X if ((pw = getpwuid(filestatus->st_uid)) == NULL)
X sprintf(output_line, "%s%-8d ", output_line, filestatus->st_uid);
X else
X sprintf(output_line, "%s%-8s ", output_line, pw->pw_name);
X
X }
X if (cm & GROUP) {
X struct group *gr;
X
X output_line = XtRealloc (output_line,
X sizeof(char) *
X (strlen(output_line) + 8 + 2));
X
X if ((gr = getgrgid(filestatus->st_gid)) == NULL)
X sprintf(output_line, "%s%-8d ", output_line, filestatus->st_gid);
X else
X sprintf(output_line, "%s%-8s ", output_line, gr->gr_name);
X
X }
X if (cm & SIZE) {
X unsigned short mode = (filestatus->st_mode);
X
X output_line = XtRealloc (output_line,
X sizeof(char) *
X (strlen(output_line) + 9 + 2));
X if ((mode & S_IFMT) == S_IFBLK || (mode & S_IFMT) == S_IFCHR)
X sprintf(output_line, "%s%5d,%3d ", output_line,
X (filestatus->st_rdev >> 8) & 0377,
X (filestatus->st_rdev) & 0377);
X else
X sprintf(output_line, "%s%9d ", output_line, filestatus->st_size);
X }
X if (cm & MODTM) {
X String time;
X output_line = XtRealloc (output_line,
X sizeof(char) *
X (strlen(output_line) + 35 + 2));
X
X time = ctime(&(filestatus->st_mtime));
X *(time + (strlen(time) - 1)) = '\0';
X sprintf(output_line, "%s%s ", output_line, time);
X }
X if (cm & ACCTM) {
X String time;
X output_line = XtRealloc (output_line,
X sizeof(char) *
X (strlen(output_line) + 35 + 2));
X
X time = ctime(&(filestatus->st_atime));
X *(time + (strlen(time) - 1)) = '\0';
X sprintf(output_line, "%s%s ", output_line, time);
X }
X current_mode.length = strlen(output_line); /* length of data */
X output_line = XtRealloc (output_line,
X sizeof(char) *
X (strlen(output_line) + strlen(filename) + 2));
X sprintf(output_line, "%s%s", output_line, filename);
X element->string = output_line;
X }
X }
X XtFree(filestatus);
X XtFree(fullname);
X }
X
X if (element->icon == DUMMY)
X return(False);
X else
X return(True);
X}
X
Xprivate Pixmap applyprefs(typePrefs *tp, String fullname, String filename,
X struct stat *filestatus)
X{
X /* Recursively traverse the prefs structure until a match is found.
X * Jump out as soon as a match is found, try special files first */
X
X Pixmap icon = NULL;
X
X /* Try directories */
X if (icon == NULL &&
X tp->dir != NULL &&
X (filestatus->st_mode & S_IFMT) == S_IFDIR) {
X icon = applyprefs(tp->dir, fullname, filename, filestatus);
X }
X
X /* Try plain files */
X if (icon == NULL &&
X tp->file != NULL &&
X (filestatus->st_mode & S_IFMT) == S_IFREG) {
X icon = applyprefs(tp->file, fullname, filename, filestatus);
X }
X
X /* Try executable files */
X if (icon == NULL &&
X tp->exe != NULL &&
X (filestatus->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0) {
X icon = applyprefs(tp->exe, fullname, filename, filestatus);
X }
X /* Try Readable files */
X if (icon == NULL &&
X tp->read != NULL &&
X (filestatus->st_mode & (S_IRUSR | S_IRGRP | S_IROTH)) != 0) {
X icon = applyprefs(tp->read, fullname, filename, filestatus);
X }
X
X /* Try Writable files */
X if (icon == NULL &&
X tp->write != NULL &&
X (filestatus->st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) != 0) {
X icon = applyprefs(tp->write, fullname, filename, filestatus);
X }
X
X /* defaults */
X if (icon == NULL && tp->iconprefs != NULL) {
X icon = do_iconprefs(tp->iconprefs, fullname, filename, filestatus);
X }
X
X return(icon);
X}
X
Xprivate Pixmap grey_icon(Pixmap icon)
X{
X private BTree *grey_search(Pixmap, Pixmap*, BTree*);
X Pixmap result;
X
X grey_tree = grey_search(icon, &result, grey_tree);
X
X return(result);
X}
X
Xprivate BTree *grey_search(Pixmap icon, Pixmap *new, BTree *tree)
X{
X Pixmap newpixmap;
X Widget w;
X BTree *result;
X extern Widget topLevel;
X
X if (tree == NULL) {
X /* Create Pixmap */
X result = (BTree*) XtMalloc (sizeof(BTree));
X result->icon = icon;
X result->left = NULL;
X result->right = NULL;
X newpixmap = XCreatePixmap(XtDisplay(topLevel),
X RootWindowOfScreen(XtScreen(topLevel)),
X 32, 32, DefaultDepthOfScreen(XtScreen(topLevel)));
X XSetFunction(XtDisplay(topLevel), xdtmgc, GXcopy);
X XCopyPlane(XtDisplay(topLevel),
X icon, newpixmap, xdtmgc, 0, 0, 32, 32, 0, 0, 1);
X XSetFunction(XtDisplay(topLevel), xdtmgc, GXand);
X XCopyPlane(XtDisplay(topLevel),
X grey_mask, newpixmap, xdtmgc, 0, 0, 32, 32, 0, 0, 1);
X result->grey = newpixmap;
X *new = newpixmap;
X } else
X if (tree->icon == icon) {
X *new = tree->grey;
X result = tree;
X } else
X if (tree->icon < icon)
X result = grey_search(icon, new, tree->left);
X else
X result = grey_search(icon, new, tree->right);
X
X return(result);
X}
X
Xprivate Pixmap do_iconprefs(iconPrefs *ip, String fullname, String filename,
X struct stat *filestatus)
X{
X /* traverse linked list trying to match regular expressions against
X * the current filename
X */
X Pixmap icon = NULL;
X String string;
X
X if (ip != NULL)
X if (ip->expbuf == NULL) {
X /* default value */
X icon = ip->icon;
X } else {
X /* try to match regular expression,
X * Add stuff here to check for whether to use fullname or filename.
X */
X if (ip->checkpath == True)
X string = fullname;
X else
X string = filename;
X circf = ip->circf;
X if (step(string, ip->expbuf) != 0) {
X if (ip->extra != NULL) {
X icon = applyprefs((typePrefs*)ip->extra, fullname, filename, filestatus);
X }
X if (icon == NULL)
X icon = ip->icon;
X } else {
X icon = do_iconprefs(ip->next, fullname, filename, filestatus);
X }
X }
X return(icon);
X}
X
Xpublic Boolean parsePreferences(Widget w)
X{
X private void initBitmaps(Widget);
X extern int yyparse(void);
X extern void selectionChange(Widget, Cardinal, caddr_t);
X extern typePrefs *newTypePref(void);
X extern AppSelection **appselections;
X extern Cardinal selectionindex;
X extern String home;
X extern Widget selectionMenu;
X MenuContents *selectionmenu;
X String setupfile;
X Cardinal i;
X int n;
X
X initBitmaps(w);
X
X /* check to see it there is an .xdtmrc in the users home directory.
X * If not use the system one.. or the command line argument one.
X */
X
X setupfile = (String) XtMalloc ((strlen(home) + 8) * sizeof(char));
X
X user = geteuid();
X group = getegid();
X
X strcpy(setupfile, home);
X strcat(setupfile, "/.xdtmrc");
X if (((yyin = fopen(setupfile, "r")) == NULL) &&
X ((yyin = fopen(SYSTEM_XDTMRC, "r")) == NULL)) {
X fprintf(stderr, "Warning: No user or system xdtmrc found\n");
X prefs = newTypePref();
X } else {
X /* parse the file */
X (void) yyparse();
X }
X XtFree(setupfile);
X
X /* Create selection menu */
X selectionmenu = (MenuContents*) XtMalloc (sizeof(MenuContents) * selectionindex);
X for(i = 0; i < selectionindex; i++) {
X selectionmenu[i].paneName = appselections[i]->name;
X selectionmenu[i].paneLabel = appselections[i]->name;
X selectionmenu[i].paneNumber = i;
X selectionmenu[i].set = noflag;
X }
X
X createMenu(selectionMenu, selectionmenu, i, selectionChange);
X
X}
X
Xprivate void initBitmaps(Widget w)
X{
X XGCValues values;
X
X foldericon = XCreateBitmapFromData( XtDisplay(w),
X RootWindowOfScreen(XtScreen(w)),
X folder_bits,
X IconBitmapWidth, IconBitmapHeight);
X fileicon = XCreateBitmapFromData( XtDisplay(w),
X RootWindowOfScreen(XtScreen(w)),
X file_bits,
X IconBitmapWidth, IconBitmapHeight);
X grey_mask = XCreateBitmapFromData( XtDisplay(w),
X RootWindowOfScreen(XtScreen(w)),
X Grey_bits,
X IconBitmapWidth, IconBitmapHeight);
X
X if ((BlackPixelOfScreen(XtScreen(w))) == 1) {
X values.background = WhitePixelOfScreen(XtScreen(w));
X values.foreground = BlackPixelOfScreen(XtScreen(w));
X } else {
X values.background = BlackPixelOfScreen(XtScreen(w));
X values.foreground = WhitePixelOfScreen(XtScreen(w));
X }
X
X xdtmgc = XtGetGC(w, (unsigned) GCBackground | GCForeground, &values);
X
X grey_tree = NULL;
X}
X
X
Xpublic void highlight_by_re(String re)
X{
X /* This procedure is called by selectQueryResult in map.c, it should be in
X * map.c but can't because <regexp.h> can only be accessable from within
X * one file.
X */
X extern void selection_made(Widget, caddr_t, caddr_t);
X extern XedwList **icon_list;
X extern Cardinal icon_list_size;
X extern Widget directoryManager;
X String buffer;
X Cardinal i;
X
X buffer = (char*) XtMalloc (sizeof(char) * ESIZE);
X compile(re, buffer, &(buffer[ESIZE]), '\0');
X
X /* traverse icon_list calling XedwListHighlight on every filename
X * matched.
X */
X for (i = 0; i < icon_list_size; i++) {
X if (step(icon_list[i]->string, buffer) != 0)
X XedwListHighlight(directoryManager, i);
X }
X
X selection_made(directoryManager, 0, 0);
X
X XtFree(buffer);
X
X}
X
X
X
X
X
X
X
X
X
X
X
X
X
SHAR_EOF
chmod 0644 code/parse.c || echo "restore of code/parse.c fails"
echo "x - extracting code/parse.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > code/parse.h &&
X/*****************************************************************************
X ** File : parse.h **
X ** Purpose : **
X ** Author : Edward Groenendaal **
X ** Date : 18th Feb 1990 **
X ** Documentation : Xdtm Design Folder **
X ** Related Files : parse.c, lexical.h, parser.y **
X *****************************************************************************/
X
X#ifndef _parse_h
X#define _parse_h
X
X/* Directory Manager Structures */
X
Xtypedef struct _iconPrefs {
X char *expbuf;
X int circf;
X Boolean checkpath;
X XtPointer extra;
X Pixmap icon;
X struct _iconPrefs *next;
X} iconPrefs;
X
Xtypedef struct _typePrefs {
X iconPrefs *iconprefs;
X struct _typePrefs *dir;
X struct _typePrefs *file;
X struct _typePrefs *exe;
X struct _typePrefs *read;
X struct _typePrefs *write;
X} typePrefs;
X
X/* Application Manager Structure */
X
X#define APPPSIZE 10 /* Initial size of an AppProgram Array */
X#define APPPINC 5 /* Increment by which to increase AppProgram Array on overflow */
X
Xtypedef enum {M_SEL, O_SEL, N_SEL} SelOptions;
X
Xtypedef struct {
X String string;
X Pixmap icon;
X String program;
X SelOptions options;
X} AppProgram;
X
Xtypedef struct {
X String name;
X Cardinal number;
X AppProgram **list;
X} AppSelection;
X
X/* Regular Expression macros */
X
X#define ESIZE 1024 /* maximum size of an expression */
X
X#define INIT register String sp = instring;
X#define GETC() (*sp++)
X#define PEEKC() (*sp)
X#define UNGETC(c) (--sp)
X#define RETURN(c) return;
X#define ERROR(c) {fprintf(stderr,"regexp error %d\n", c); exit(1);};
X
X#endif /* _parse_h */
SHAR_EOF
chmod 0644 code/parse.h || echo "restore of code/parse.h fails"
echo "x - extracting code/parser.y (Text)"
sed 's/^X//' << 'SHAR_EOF' > code/parser.y &&
X%{ /*-*- Mode: C -*-*/
X/**************************************************************************
X * Filename : parser.y
X * Author : Edward Groenendaal
X * Date : 31/1/91
X * Purpose :
X *
X **************************************************************************/
X
X#define YYDEBUG 1
X#include "xdtm.h"
X#include "parse.h"
X#include <regexp.h>
X
Xtypedef struct _iconTree {
X String fullname; /* index on this */
X Pixmap icon;
X struct _iconTree *left;
X struct _iconTree *right;
X} iconTree;
X
Xtypedef struct _varStack {
X String *defpath;
X Cardinal dirinpath;
X Boolean checkpath;
X iconPrefs *iconpref;
X typePrefs *current;
X struct _varStack *next;
X} varStack;
X
Xpublic typePrefs *newTypePref(void);
Xprivate void start_block(typePrefs*,iconPrefs*);
Xprivate void end_block(void);
Xprivate String *stringtopath(String, Cardinal*);
Xprivate Pixmap lookupicon(String);
Xprivate iconPrefs *getlast(iconPrefs*);
Xprivate iconPrefs *inserticonpref(iconPrefs*, iconPrefs*);
Xprivate String strip_quotes(String);
Xprivate iconTree *get_pixmap(iconTree*,iconTree*);
Xprivate void set_path(String);
Xprivate void set_icon(String, Boolean);
Xprivate void set_deficon(String);
Xprivate void set_ignore(void);
Xprivate void newselection(String);
Xprivate void setapp(int, String);
X
X/* imported variables/procedures */
Xextern int parseerror; /* quantity of parse errors so far */
Xextern int yylineno; /* line number being parsed */
Xextern void yyerror(char *, ...); /* normal error printing routine */
X
X#ifndef DEBUG_YACC
Xextern Widget topLevel;
X#endif
X
Xpublic AppSelection **appselections;
Xpublic typePrefs *prefs; /* preferneces */
Xprivate varStack *varframe; /* stack frames */
Xprivate iconTree *icontable; /* table of pixmaps */
Xprivate char *ptr; /* general use pointer */
Xprivate AppSelection *current_selection;
Xprivate Cardinal listindex; /* index into current appprogram list */
Xprivate Cardinal currentlistmax; /* current list appprogram size */
Xpublic Cardinal selectionindex; /* index into appselections */
X
X%} /* Start of YACC declarations */
X
X%start xdtmrc
X
X%union /* valid types */
X{
X int number; /* number */
X char *string; /* string */
X}
X
X/* declare terminals with their types */
X
X%token <string> STRING_T
X%token <number> IF_T SET_T ICON_T NAME_T PATH_T DEFICON_T TYPE_T CHECKPATH_T
X%token <number> TRUE_T FALSE_T IGNORE_T
X%token <number> DIR_T FILE_T READ_T WRITE_T EXE_T PROG_T OPTIONS_T
X%token <number> MSEL_T OSEL_T NSEL_T DEFINE_T
X%token <number> ASSIGN_T EQUAL_T SEMIC_T COMMA_T
X%token <number> O_PAR_T C_PAR_T O_BRACE_T C_BRACE_T
X%token <value> EOFTOKEN ERRORTOKEN
X
X%type <string> identifier
X%type <number> block type var option
X
X%% /* Beginning of rule section */
X
Xxdtmrc : { init_structs(); }
X statements
X { free_structs(); }
X ;
Xstatements : /* Empty */
X | statements statement
X ;
Xstatement : ifstatement
X | setstatement SEMIC_T
X | define
X ;
Xifstatement : IF_T O_PAR_T expression C_PAR_T block
X ;
Xsetstatement : SET_T var ASSIGN_T identifier { switch ($2) {
X case PATH_T:
X set_path($4);
X break;
X case ICON_T:
X set_icon($4, False);
X break;
X case DEFICON_T:
X set_deficon($4);
X break;
X }
X }
X | SET_T CHECKPATH_T ASSIGN_T TRUE_T
X { varframe->checkpath = True; }
X | SET_T CHECKPATH_T ASSIGN_T FALSE_T
X { varframe->checkpath = False; }
X | SET_T IGNORE_T
X { set_icon("", True);}
X ;
Xdefine : DEFINE_T identifier {newselection($2);} ASSIGN_T defineblock
X ;
Xblock : O_BRACE_T
X statements {end_block();}
X C_BRACE_T
X ;
Xdefineblock : O_BRACE_T descriptions C_BRACE_T
X {current_selection->number = listindex;}
X ;
Xdescriptions : /* Empty */
X | descriptions description
X ;
Xdescription : O_BRACE_T
X
X { /* Allocate a new AppProgram */
SHAR_EOF
echo "End of part 3"
echo "File code/parser.y is continued in part 4"
echo "4" > s2_seq_.tmp
exit 0
More information about the Alt.sources
mailing list