pkg://jex-1.3.7-1.src.rpm:114631/jex-1.3.7.tar.gz
info downloads
jex-1.3.7/ 40755 0 0 0 6674510012 10273 5 ustar root root jex-1.3.7/about.c 100644 0 0 10655 6672727026 11712 0 ustar root root #include <Xm/MessageB.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include "jex.h"
#include "xpm.h"
#include "jexlogo.xpm"
#include "jexrlogo.xpm"
Pixmap logo=0,logo2;
extern Widget top;
void AboutOK(Widget w,Editor *e,void *cbs)
{
SetCurrentWidget(e->text);
}
void ShowAboutDialog(Editor *e)
{
Widget w,f,l,l2;
Pixel fg,bg;
XmString xstr;
char version[30];
SP("ShowAboutDialog");
WatchCursor(e,1);
if (!e->abd)
{
e->abd=XmCreateMessageDialog(e->shell,"About",NULL,0);
XtUnmanageChild(XmMessageBoxGetChild(e->abd,XmDIALOG_CANCEL_BUTTON));
XtUnmanageChild(XmMessageBoxGetChild(e->abd,XmDIALOG_HELP_BUTTON));
XtAddCallback(e->abd,XmNokCallback,(XtCallbackProc)AboutOK,(void*)e);
if (!logo)
{
XtVaGetValues(e->abd,XmNforeground,&fg,XmNbackground,&bg,NULL);
/* logo=XCreatePixmapFromBitmapData(XtDisplay(top),
RootWindowOfScreen(XtScreen(top)),
jexlogo_bits,jexlogo_width,jexlogo_height,
fg,bg,
DefaultDepthOfScreen(XtScreen(top)));
logo2=XCreatePixmapFromBitmapData(XtDisplay(top),
RootWindowOfScreen(XtScreen(top)),
jexrlogo_bits,jexrlogo_width,jexrlogo_height,
fg,bg,
DefaultDepthOfScreen(XtScreen(top)));*/
logo=CreatePixmapFromXPM(top,jexlogo_xpm);
logo2=CreatePixmapFromXPM(top,jexrlogo_xpm);
}
f=XtVaCreateManagedWidget("aboutform",xmFormWidgetClass,e->abd,
XmNfractionBase,8,
NULL);
l=XtVaCreateManagedWidget("aboutlogo",xmLabelWidgetClass,f,
XmNlabelType,XmPIXMAP,
XmNlabelPixmap,logo,
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_NONE,
XmNtopAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_FORM,
NULL);
l2=XtVaCreateManagedWidget("aboutlogo2",xmLabelWidgetClass,f,
XmNlabelType,XmPIXMAP,
XmNlabelPixmap,logo2,
XmNleftAttachment,XmATTACH_NONE,
XmNrightAttachment,XmATTACH_FORM,
XmNtopAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_FORM,
NULL);
xstr=XmStringCreateLocalized("JEX");
w=XtVaCreateManagedWidget("about1",xmLabelWidgetClass,f,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,l,
XmNrightAttachment,XmATTACH_WIDGET,
XmNrightWidget,l2,
XmNtopAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_POSITION,
XmNbottomPosition,2,
XmNleftOffset,20,
XmNrightOffset,20,
XmNlabelString,xstr,
NULL);
XmStringFree(xstr);
xstr=XmStringCreateLocalized("Jorgen Editor for X");
w=XtVaCreateManagedWidget("about2",xmLabelWidgetClass,f,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,l,
XmNrightAttachment,XmATTACH_WIDGET,
XmNrightWidget,l2,
XmNtopAttachment,XmATTACH_POSITION,
XmNtopPosition,2,
XmNbottomAttachment,XmATTACH_POSITION,
XmNbottomPosition,3,
XmNleftOffset,20,
XmNrightOffset,20,
XmNlabelString,xstr,
NULL);
XmStringFree(xstr);
xstr=XmStringCreateLocalized("A programmer's editor");
w=XtVaCreateManagedWidget("about3",xmLabelWidgetClass,f,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,l,
XmNrightAttachment,XmATTACH_WIDGET,
XmNrightWidget,l2,
XmNtopAttachment,XmATTACH_POSITION,
XmNtopPosition,3,
XmNbottomAttachment,XmATTACH_POSITION,
XmNbottomPosition,4,
XmNleftOffset,20,
XmNrightOffset,20,
XmNlabelString,xstr,
NULL);
XmStringFree(xstr);
sprintf(version,"Version %d.%d.%d",MAJOR_VERSION,MINOR_VERSION,SUB_MINOR_VERSION);
xstr=XmStringCreateLocalized(version);
w=XtVaCreateManagedWidget("about4",xmLabelWidgetClass,f,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,l,
XmNrightAttachment,XmATTACH_WIDGET,
XmNrightWidget,l2,
XmNtopAttachment,XmATTACH_POSITION,
XmNtopPosition,5,
XmNbottomAttachment,XmATTACH_POSITION,
XmNbottomPosition,6,
XmNleftOffset,20,
XmNrightOffset,20,
XmNlabelString,xstr,
NULL);
XmStringFree(xstr);
xstr=XmStringCreateLocalized("(c) 1996-1998 by Jorgen Bosman");
w=XtVaCreateManagedWidget("about5",xmLabelWidgetClass,f,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,l,
XmNrightAttachment,XmATTACH_WIDGET,
XmNrightWidget,l2,
XmNtopAttachment,XmATTACH_POSITION,
XmNtopPosition,7,
XmNbottomAttachment,XmATTACH_FORM,
XmNleftOffset,20,
XmNrightOffset,20,
XmNlabelString,xstr,
NULL);
XmStringFree(xstr);
}
XtManageChild(e->abd);
WatchCursor(e,0);
EP;
}
jex-1.3.7/asksave.c 100644 0 0 2510 6672726717 12212 0 ustar root root #include <stdio.h>
#include <Xm/MessageB.h>
#include "jex.h"
extern Widget top;
void Function(void (*f)(),Editor *e)
{
SP("Function");
if (f)
f(e);
EP;
}
void NoSave(Widget w,Editor *e,void *cbs)
{
SP("NoSave");
if (e->f!=NULL)
Function((void(*)(void))e->f,e);
EP;
}
void CancelAskToSave(Widget w,Editor *e,void *cbs)
{
SP("CancelAskToSave");
XtUnmanageChild(e->ats);
SetCurrentWidget(e->text);
EP;
}
void AskToSaveOK(Widget w,Editor *e,void *cbs)
{
SP("AskToSaveOK");
Save(NULL,e,e->f);
SetCurrentWidget(e->text);
EP;
}
void AskToSave(Editor *e,void *f)
{
SP("AskToSave");
if (e->ats==NULL)
{
e->ats=XmCreateQuestionDialog(e->shell,"AskToSave",NULL,0);
e->f=f;
XtAddCallback(e->ats,XmNokCallback,(XtCallbackProc)AskToSaveOK,e);
XtAddCallback(e->ats,XmNcancelCallback,(XtCallbackProc)NoSave,e);
XtAddCallback(e->ats,XmNhelpCallback,(XtCallbackProc)CancelAskToSave,e);
}
else
{
XtRemoveAllCallbacks(e->ats,XmNokCallback);
XtRemoveAllCallbacks(e->ats,XmNcancelCallback);
XtRemoveAllCallbacks(e->ats,XmNhelpCallback);
e->f=f;
XtAddCallback(e->ats,XmNokCallback,(XtCallbackProc)AskToSaveOK,e);
XtAddCallback(e->ats,XmNcancelCallback,(XtCallbackProc)NoSave,e);
XtAddCallback(e->ats,XmNhelpCallback,(XtCallbackProc)CancelAskToSave,e);
}
XtManageChild(e->ats);
EP;
}
jex-1.3.7/bookmark.c 100644 0 0 7665 6672726717 12402 0 ustar root root #include "jex.h"
#include <Xm/List.h>
#include <Xm/MessageB.h>
#include <Xm/PushBG.h>
Widget bd=NULL,bdl;
extern Widget top;
extern Pixmap pixmap;
void OpenBookmark(Widget w,Editor *e,void *cbs)
{
XmString xstr;
char *str;
SP("OpenBookmark");
XtVaGetValues(w,XmNlabelString,&xstr,NULL);
XmStringGetLtoR(xstr,XmSTRING_DEFAULT_CHARSET,&str);
XmStringFree(xstr);
if (e->new_window)
{
CreateNewEditor();
if (loadfile(editor[editors-1],str,0,1))
LoadError(editor[editors-1]);
}
else
{
db_strcpy(e->choice,str);
if (e->saved)
LoadOldFile(e);
else
AskToSave(e,(void*)LoadOldFile);
}
EP;
}
void UpdateEditorBookmarks(Editor *e)
{
int count,x;
XmStringTable items;
SP("UpdateEditorBookmarks");
XtVaGetValues(bdl,XmNitemCount,&count,XmNitems,&items,NULL);
for (x=0;x<count && x<MAXBOOKMARKBUTTONS;x++)
{
e->bookm[x]=XtVaCreateManagedWidget("bookmarkbutton",
xmPushButtonGadgetClass,e->bookmarkmenu,XmNlabelString,items[x],NULL);
XtAddCallback(e->bookm[x],XmNactivateCallback,(XtCallbackProc)OpenBookmark,(void*)e);
}
EP;
}
void DeleteEditorBookmarks(Editor *e)
{
int count,x;
SP("DeleteEditorBookmarks");
XtVaGetValues(bdl,XmNitemCount,&count,NULL);
for (x=0;x<count && x<MAXBOOKMARKBUTTONS;x++)
XtDestroyWidget(e->bookm[x]);
EP;
}
void CloseBookmark(Widget w,void *e,void *cbs)
{
SP("CloseBookmark");
XtPopdown(bd);
EP;
}
void GotoBookmark(Widget w,void *date,XmListCallbackStruct *cbs)
{
XmStringTable selected_items;
int num_selected;
char *str;
int x;
SP("GotoBookmark");
XtVaGetValues(bdl,XmNselectedItemCount,&num_selected,XmNselectedItems,&selected_items,NULL);
if (num_selected==0)
{
EP;
return;
}
XmStringGetLtoR(selected_items[0],XmSTRING_DEFAULT_CHARSET,&str);
for (x=0;x<editors;x++)
{
if (db_strcmp(editor[x]->filename,str)==0)
{
XMapRaised(XtDisplay(editor[x]->shell),XtWindow(editor[x]->shell));
XtFree(str);
EP;
return;
}
}
CreateNewEditor();
if (loadfile(editor[editors-1],str,0,1))
LoadError(editor[editors-1]);
XtFree(str);
EP;
}
void DeleteBookmark(Widget w,void *data,void *cbs)
{
int *pos,count,x;
SP("DeleteBookmark");
XmListGetSelectedPos(bdl,&pos,&count);
if (count)
{
for (x=0;x<editors;x++)
DeleteEditorBookmarks(editor[x]);
XmListDeletePos(bdl,pos[0]);
XtFree((char*)pos);
for (x=0;x<editors;x++)
UpdateEditorBookmarks(editor[x]);
}
EP;
}
void CreateBookmarkDialog(void)
{
Widget w;
Arg arg[2];
SP("CreateBookmarkDialog");
if (bd==NULL)
{
bd=XtVaAppCreateShell("BookmarkDialog","BookmarkDialog",topLevelShellWidgetClass,XtDisplay(top),
XmNallowShellResize,True,
XmNiconPixmap,pixmap,
NULL);
w=XmCreateMessageBox(bd,"BookmarkDialog",NULL,0);
XtSetArg(arg[0],XmNlistSizePolicy,XmCONSTANT);
bdl=XmCreateScrolledList(w,"BookmarkList",arg,1);
XtVaSetValues(XtParent(bdl),
XmNscrollBarDisplayPolicy,XmSTATIC,
NULL);
XtVaSetValues(bdl,
XmNscrollBarDisplayPolicy,XmSTATIC,
XmNlistSizePolicy,XmCONSTANT,
NULL);
XtAddCallback(bdl,XmNdefaultActionCallback,(XtCallbackProc)GotoBookmark,NULL);
XtAddCallback(w,XmNokCallback,(XtCallbackProc)CloseBookmark,NULL);
XtAddCallback(w,XmNcancelCallback,(XtCallbackProc)GotoBookmark,NULL);
XtAddCallback(w,XmNhelpCallback,(XtCallbackProc)DeleteBookmark,NULL);
XtManageChild(bdl);
XtManageChild(w);
}
EP;
}
void AddBookmark(char *str)
{
XmString xstr;
int x;
SP("AddBookmark");
if (bdl && str[0])
{
for (x=0;x<editors;x++)
DeleteEditorBookmarks(editor[x]);
xstr=XmStringCreateLocalized(str);
if (!XmListItemExists(bdl,xstr))
XmListAddItemUnselected(bdl,xstr,0);
XmStringFree(xstr);
for (x=0;x<editors;x++)
UpdateEditorBookmarks(editor[x]);
}
EP;
}
void ShowBookmarkDialog(void)
{
SP("ShowBookmarkDialog");
XtPopup(bd,XtGrabNone);
XMapRaised(XtDisplay(bd),XtWindow(bd));
EP;
}
jex-1.3.7/combo.c 100644 0 0 14217 6672726722 11677 0 ustar root root #include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/TextF.h>
#include <Xm/DrawnB.h>
#include <Xm/RowColumn.h>
#include <Xm/PushBG.h>
#include "jbdbg.h"
#include "jex.h"
#include "list.h"
List combo_list=NULL;
extern Pixmap lov;
extern OwnRes ownres;
void ComboBoxSelect(Widget w,Widget text,void *cbs)
{
ComboBox c;
int x;
SP("ComboBoxSelect");
if (!FindElement(combo_list,&c,sizeof(Widget),&text))
{
EP;
return;
}
for (x=0;x<c.itemcount;x++)
{
if (c.items[x].button==w)
{
XtVaSetValues(text,XmNvalue,c.items[x].item,NULL);
if (c.function)
c.function(w,c.client_data,cbs);
break;
}
}
EP;
}
void UpdateComboBox(Widget w,char *str)
{
int x,end,exists=0;
XmString xstr;
ComboBox c;
SP("UpdateComboBox");
if (!FindElement(combo_list,&c,sizeof(Widget),&w))
{
EP;
return;
}
end=c.itemcount;
if (str && str[0])
{
for (x=0;x<c.itemcount;x++)
{
if (db_strcmp(c.items[x].item,str)==0)
{
end=x+1;
exists=1;
break;
}
}
if (c.itemcount<c.maxitems && !exists)
{
if (c.form)
{
c.items[c.itemcount].button=XtVaCreateManagedWidget("combobutton",
xmPushButtonGadgetClass,c.popup,NULL);
XtAddCallback(c.items[c.itemcount].button,XmNactivateCallback,(XtCallbackProc)ComboBoxSelect,c.text);
}
c.items[c.itemcount].item=NULL;
c.itemcount++;
end=c.itemcount;
}
for (x=end-2;x>=0;x--)
{
c.items[x+1].item=(char*)db_realloc(c.items[x+1].item,db_strlen(c.items[x].item)+1);
db_strcpy(c.items[x+1].item,c.items[x].item);
}
c.items[0].item=(char*)db_realloc(c.items[0].item,db_strlen(str)+1);
db_strcpy(c.items[0].item,str);
}
for (x=0;c.form && x<end;x++)
{
xstr=XmStringCreateLocalized(c.items[x].item);
XtVaSetValues(c.items[x].button,XmNlabelString,xstr,NULL);
XmStringFree(xstr);
}
ReplaceCurrentElement(combo_list,&c);
EP;
}
void ShowComboMenu(Widget b,Widget text,XmPushButtonCallbackStruct *cbs)
{
Position y,y2,h,x,x2,w;
Widget tmp;
ComboBox c;
XButtonPressedEvent xbe;
SP("ShowComboMenu");
if (!FindElement(combo_list,&c,sizeof(Widget),&text))
{
EP;
return;
}
xbe=*(XButtonPressedEvent*)&cbs->event;
tmp=XtParent(c.text);
y2=0;
x2=0;
while (!XtIsShell(tmp))
{
XtVaGetValues(tmp,XmNx,&x,XmNy,&y,NULL);
x2+=x;
y2+=y;
tmp=XtParent(tmp);
}
XtVaGetValues(c.text,XmNx,&x,XmNy,&y,XmNwidth,&w,XmNheight,&h,NULL);
xbe.y_root=y2+y+h;
xbe.x_root=x2+x;
XtVaGetValues(c.button,XmNwidth,&x,NULL);
w+=x;
if (c.itemcount)
XtVaSetValues(c.items[0].button,XmNwidth,w,NULL);
XmMenuPosition(c.popup,&xbe);
XtManageChild(c.popup);
EP;
}
Widget CreateComboBox(Widget parent,String name,ArgList arglist,Cardinal argcount,int maxitems)
{
ComboBox c;
char str[100];
SP("CreateComboBox");
if (!combo_list)
combo_list=CreateList(sizeof(ComboBox));
c.maxitems=maxitems;
c.itemcount=0;
c.items=(ComboButton*)db_malloc(sizeof(ComboButton)*maxitems);
c.function=NULL;
if (parent)
{
db_sprintf(str,"%s_form",name);
c.form=XmCreateForm(parent,str,arglist,argcount);
XtManageChild(c.form);
db_sprintf(str,"%s_button",name);
c.button=XtVaCreateManagedWidget(str,xmDrawnButtonWidgetClass,c.form,
XmNrightAttachment,XmATTACH_FORM,
XmNtopAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_FORM,
XmNlabelType,XmPIXMAP,
XmNlabelPixmap,lov,
XmNhighlightThickness,0,
XmNtopOffset,2,
XmNbottomOffset,2,
NULL);
c.text=XtVaCreateManagedWidget(name,xmTextFieldWidgetClass,c.form,
XmNleftAttachment,XmATTACH_FORM,
XmNtopAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_WIDGET,
XmNrightWidget,c.button,
NULL);
db_sprintf(str,"%s_popup",name);
c.popup=XmVaCreateSimplePopupMenu(c.form,str,NULL,
NULL);
XtAddCallback(c.button,XmNarmCallback,(XtCallbackProc)ShowComboMenu,c.text);
}
else
{
c.text=(Widget)db_strdup(name);
c.form=NULL;
c.button=NULL;
c.popup=NULL;
}
AddElement(combo_list,&c);
EP;
return c.text;
}
void DestroyAllComboBoxes(void)
{
ComboBox c;
int x;
if (combo_list)
{
if (GetFirstElement(combo_list,&c))
{
do
{
for (x=0;x<c.itemcount;x++)
db_free(c.items[x].item);
db_free(c.items);
if (!c.form)
db_free(c.text);
} while (GetNextElement(combo_list,&c));
}
DisposeList(combo_list);
}
}
int GetComboBox(Widget w,ComboBox *c)
{
SP("GetComboBox");
if (!FindElement(combo_list,c,sizeof(Widget),&w))
{
EP;
return 0;
}
EP;
return 1;
}
void InitializeComboBox(Widget w,Widget ref)
{
ComboBox c;
int x;
char *home,file[255],ini[255],*param,str[255],label[255];
FILE *f;
SP("InitializeComboBox");
if (editors)
{
if (!GetComboBox(ref,&c))
{
EP;
return;
}
for (x=0;x<c.itemcount;x++)
UpdateComboBox(w,c.items[x].item);
}
else
{
if (!GetComboBox(w,&c))
{
EP;
return;
}
if ((int)ownres.histhome)
{
home=getenv("HOME");
if (home)
db_sprintf(file,"%s/.jexhistory",home);
else
db_strcpy(file,".jexhistory");
}
else
db_strcpy(file,".jexhistory");
if ((f=fopen(file,"r"))==NULL)
{
EP;
return;
}
sprintf(label,"%s:",(c.form!=NULL)?XtName(w):(char*)w);
while (fgets(str,255,f))
{
str[db_strlen(str)-1]='\0';
sscanf(str,"%s",ini);
param=&str[db_strlen(ini)+1];
if (!strcmp(ini,label))
UpdateComboBox(w,param);
}
fclose(f);
}
EP;
}
void CopyComboBoxToFile(Widget w,FILE *f)
{
ComboBox c;
int x;
SP("CopyComboBoxToFile");
if (GetComboBox(w,&c))
{
for (x=0;x<c.itemcount;x++)
fprintf(f,"%s: %s\n",(c.form!=NULL)?XtName(w):(char*)w,c.items[x].item);
}
EP;
}
void ComboBoxAddCallback(Widget w,XtCallbackProc f,void *d)
{
ComboBox c;
if (!GetComboBox(w,&c))
return;
c.function=f;
c.client_data=d;
ReplaceCurrentElement(combo_list,&c);
}
jex-1.3.7/edit.c 100644 0 0 20032 6672726717 11521 0 ustar root root #include <Xm/MessageB.h>
#include <Xm/Text.h>
#include <ctype.h>
#include "jex.h"
extern Widget top;
void ClearSelection(Widget w,Editor *e,void *cbs)
{
XmTextPosition f,l,x;
char *str;
SP("ClearSelection");
if (e->read_only)
{
EP;
return;
}
WatchCursor(e,1);
XmTextGetSelectionPosition(e->text,&f,&l);
if (f==l)
{
WatchCursor(e,0);
EP;
return;
}
str=XmTextGetSelection(e->text);
for (x=0;x<l-f;x++)
{
if (str[x]!='\n')
str[x]=' ';
}
XmTextReplace(e->text,f,l,str);
XtFree(str);
SetCurrentWidget(e->text);
WatchCursor(e,0);
EP;
}
void CapsSelection(Widget w,Editor *e,void *cbs)
{
XmTextPosition f,l,x;
char *str;
SP("CapsSelection");
if (e->read_only)
{
EP;
return;
}
WatchCursor(e,1);
XmTextGetSelectionPosition(e->text,&f,&l);
if (f==l)
{
WatchCursor(e,0);
EP;
return;
}
str=XmTextGetSelection(e->text);
for (x=0;x<l-f;x++)
{
if (str[x]!='\n')
str[x]=toupper(str[x]);
}
XmTextReplace(e->text,f,l,str);
XmTextSetSelection(e->text,f,l,0);
XtFree(str);
SetCurrentWidget(e->text);
WatchCursor(e,0);
EP;
}
void LowsSelection(Widget w,Editor *e,void *cbs)
{
XmTextPosition f,l,x;
char *str;
SP("LowsSelection");
if (e->read_only)
{
EP;
return;
}
WatchCursor(e,1);
XmTextGetSelectionPosition(e->text,&f,&l);
if (f==l)
{
WatchCursor(e,0);
EP;
return;
}
str=XmTextGetSelection(e->text);
for (x=0;x<l-f;x++)
{
if (str[x]!='\n')
str[x]=tolower(str[x]);
}
XmTextReplace(e->text,f,l,str);
XmTextSetSelection(e->text,f,l,0);
XtFree(str);
SetCurrentWidget(e->text);
WatchCursor(e,0);
EP;
}
int FindTextString(Editor *e,char *str,int start_over,int set_pos)
{
static XmTextPosition pos=1,prev_pos=0,len=0;
XmTextPosition f,l;
SP("FindTextString");
XmTextGetSelectionPosition(e->text,&f,&l);
if (f!=l && f && pos!=0)
XmTextSetInsertionPosition(e->text,f+1);
if (XmTextFindString(e->text,XmTextGetInsertionPosition(e->text),str,XmTEXT_FORWARD,&pos))
{
prev_pos=pos;
len=db_strlen(str);
if (set_pos)
XmTextShowPosition(e->text,pos);
XmTextSetSelection(e->text,pos,pos+len,0);
if (set_pos)
XmTextSetInsertionPosition(e->text,pos+len);
EP;
return 1;
}
else if (pos!=0 && start_over)
{
if (XmTextFindString(e->text,0,str,XmTEXT_FORWARD,&pos))
{
pos=0;
if (set_pos)
XmTextSetInsertionPosition(e->text,0);
EP;
return FindTextString(e,str,1,set_pos);
}
else
{
EP;
return 0;
}
}
EP;
return 0;
}
int FindReverseTextString(Editor *e,char *str,int start_over)
{
static XmTextPosition pos=1,prev_pos=0,len=0;
XmTextPosition f,l;
SP("FindReverseTextString");
XmTextGetSelectionPosition(e->text,&f,&l);
if (f!=l && f && pos!=XmTextGetLastPosition(e->text))
XmTextSetInsertionPosition(e->text,f-1);
if (XmTextFindString(e->text,XmTextGetInsertionPosition(e->text),str,XmTEXT_BACKWARD,&pos))
{
prev_pos=pos;
len=db_strlen(str);
XmTextShowPosition(e->text,pos);
XmTextSetSelection(e->text,pos,pos+len,0);
if (pos)
XmTextSetInsertionPosition(e->text,pos+len);
else
XmTextSetInsertionPosition(e->text,XmTextGetLastPosition(e->text));
EP;
return 1;
}
else if (pos!=XmTextGetLastPosition(e->text) && start_over)
{
if (XmTextFindString(e->text,XmTextGetLastPosition(e->text),str,XmTEXT_BACKWARD,&pos))
{
pos=XmTextGetLastPosition(e->text);
XmTextSetInsertionPosition(e->text,pos);
EP;
return FindReverseTextString(e,str,1);
}
else
{
EP;
return 0;
}
}
EP;
return 0;
}
void ReplaceText(Editor *e,char *str)
{
XmTextPosition f,l;
SP("ReplaceText");
if (e->read_only)
{
EP;
return;
}
XmTextGetSelectionPosition(e->text,&f,&l);
XmTextReplace(e->text,f,l,str);
EP;
}
void CutText(Widget w,Editor *e,void *cbs)
{
SP("CutText");
XmTextCut(e->text,0);
EP;
}
void CopyText(Widget w,Editor *e,void *cbs)
{
SP("CopyText");
XmTextCopy(e->text,0);
EP;
}
void PasteText(Widget w,Editor *e,void *cbs)
{
SP("PasteText");
if (e->read_only)
{
EP;
return;
}
XmTextPaste(e->text);
EP;
}
void DeleteLine(Widget w,XAnyEvent *event,String *args,int *num_args)
{
char *str;
XmTextPosition left,right;
int len,selection=1;
SP("DeleteLine");
XtVaGetValues(w,XmNvalue,&str,NULL);
len=db_strlen(str);
if (!XmTextGetSelectionPosition(w,&left,&right) || left==right)
{
left=right=XmTextGetInsertionPosition(w);
selection=0;
}
while (left>0 && str[left-1]!='\0' && str[left-1]!='\n')
left--;
if ((right && str[right-1]!='\n') || right!=left)
right--;
while (right>=0 && right<len && str[right]!='\0' && str[right]!='\n')
right++;
if (right<len-1)
right++;
else if (left)
left--;
if (left>=right)
{
XtFree(str);
EP;
return;
}
XtFree(str);
XmTextSetSelection(w,left,right,0);
XmTextRemove(w);
EP;
}
void NotFound(Editor *e,char *findstr)
{
char str[200];
XmString xstr;
SP("NotFound");
if (db_strlen(findstr)>150)
strcpy(str,"Search string not found!");
else
sprintf(str,"String '%s' not found!",findstr);
xstr=XmStringCreateLocalized(str);
if (e->fd==NULL)
{
e->fd=XmCreateWarningDialog(e->shell,"NotFound",NULL,0);
XtUnmanageChild(XmMessageBoxGetChild(e->fd,XmDIALOG_CANCEL_BUTTON));
XtUnmanageChild(XmMessageBoxGetChild(e->fd,XmDIALOG_HELP_BUTTON));
}
XtVaSetValues(e->fd,XmNmessageString,xstr,NULL);
XmStringFree(xstr);
XtManageChild(e->fd);
EP;
}
void FindDown(Widget w,Editor *e,void *cbs)
{
char *str,*str2;
SP("FindDown");
WatchCursor(e,1);
XtVaGetValues(e->findf,XmNvalue,&str,NULL);
if (str[0])
{
UpdateComboBox(e->findf,str);
if (FindTextString(e,str,0,1)==0)
NotFound(e,str);
}
else
{
str2=XmTextGetSelection(e->text);
if (str2)
{
if (FindTextString(e,str2,0,1)==0)
NotFound(e,str2);
XtFree(str2);
}
}
XtFree(str);
WatchCursor(e,0);
EP;
}
void FindUp(Widget w,Editor *e,void *cbs)
{
char *str,*str2;
int x;
SP("FindUp");
WatchCursor(e,1);
XtVaGetValues(e->findf,XmNvalue,&str,NULL);
if (str[0])
{
for (x=0;x<editors;x++)
UpdateComboBox(editor[0]->findf,str);
/* UpdateFindList(str);*/
if (FindReverseTextString(e,str,0)==0)
NotFound(e,str);
}
else
{
str2=XmTextGetSelection(e->text);
if (str2)
{
if (FindReverseTextString(e,str2,0)==0)
NotFound(e,str2);
XtFree(str2);
}
}
XtFree(str);
WatchCursor(e,0);
EP;
}
void Replace(Widget w,Editor *e,void *cbs)
{
char *findstr,*replstr;
XmTextPosition f,l;
int x;
SP("Replace");
if (e->read_only)
{
EP;
return;
}
WatchCursor(e,1);
XtVaGetValues(e->findf,XmNvalue,&findstr,NULL);
XtVaGetValues(e->replf,XmNvalue,&replstr,NULL);
XmTextGetSelectionPosition(e->text,&f,&l);
if (w)
{
/* UpdateReplList(replstr);
UpdateFindList(findstr);*/
for (x=0;x<editors;x++)
{
UpdateComboBox(editor[0]->findf,findstr);
UpdateComboBox(editor[0]->replf,replstr);
}
}
if (f!=l)
ReplaceText(e,replstr);
if (findstr[0])
FindTextString(e,findstr,0,((int)cbs==-1)?0:1);
XtFree(findstr);
XtFree(replstr);
WatchCursor(e,0);
EP;
}
void ReplaceAll(Widget w,Editor *e,void *cbs)
{
char *findstr,*replstr;
XmTextPosition f,l;
int x;
SP("ReplaceAll");
if (e->read_only)
{
EP;
return;
}
WatchCursor(e,1);
XtVaGetValues(e->findf,XmNvalue,&findstr,NULL);
XtVaGetValues(e->replf,XmNvalue,&replstr,NULL);
XmTextGetSelectionPosition(e->text,&f,&l);
for (x=0;x<editors;x++)
{
UpdateComboBox(editor[0]->findf,findstr);
UpdateComboBox(editor[0]->replf,replstr);
}
/* UpdateReplList(replstr);
UpdateFindList(findstr);*/
if (db_strcmp(findstr,replstr)!=0)
{
if (f==l)
{
FindTextString(e,findstr,0,0);
XmTextGetSelectionPosition(e->text,&f,&l);
}
while (f!=l)
{
Replace(NULL,e,(void*)-1);
XmTextGetSelectionPosition(e->text,&f,&l);
}
}
XtFree(findstr);
XtFree(replstr);
WatchCursor(e,0);
EP;
}
jex-1.3.7/editors.c 100644 0 0 4445 6672726717 12237 0 ustar root root #include "jex.h"
#include <Xm/List.h>
#include <Xm/MessageB.h>
Widget edd=NULL,edl;
extern Widget top;
extern Pixmap pixmap;
void CloseEditors(Widget w,void *e,void *cbs)
{
SP("CloseEditors");
/* XtUnmanageChild(edd);*/
XtPopdown(edd);
EP;
}
void GotoEditor(Widget w,void *data,XmListCallbackStruct *cbs)
{
int pos_count;
int *positions;
SP("GotoEditor");
if (XmListGetSelectedPos(edl,&positions,&pos_count))
{
if (positions[0]<=editors)
XMapRaised(XtDisplay(editor[positions[0]-1]->shell),XtWindow(editor[positions[0]-1]->shell));
XtFree((char*)positions);
}
EP;
}
void CreateEditorDialog(void)
{
Widget w;
Arg arg[2];
SP("CreateEditorDialog");
if (edd==NULL)
{
edd=XtVaAppCreateShell("EditorsDialog","EditorsDialog",topLevelShellWidgetClass,XtDisplay(top),
XmNallowShellResize,True,
XmNiconPixmap,pixmap,
NULL);
w=XmCreateMessageBox(edd,"EditorsDialog",NULL,0);
XtSetArg(arg[0],XmNlistSizePolicy,XmCONSTANT);
edl=XmCreateScrolledList(w,"EditorList",arg,1);
XtVaSetValues(XtParent(edl),
XmNscrollBarDisplayPolicy,XmSTATIC,
NULL);
XtVaSetValues(edl,
XmNscrollBarDisplayPolicy,XmSTATIC,
XmNlistSizePolicy,XmCONSTANT,
NULL);
XtAddCallback(edl,XmNdefaultActionCallback,(XtCallbackProc)GotoEditor,NULL);
/* XtUnmanageChild(XmMessageBoxGetChild(w,XmDIALOG_HELP_BUTTON));*/
XtAddCallback(w,XmNokCallback,(XtCallbackProc)CloseEditors,NULL);
XtAddCallback(w,XmNcancelCallback,(XtCallbackProc)GotoEditor,NULL);
XtAddCallback(w,XmNhelpCallback,(XtCallbackProc)Help,"Editors");
XtManageChild(edl);
XtManageChild(w);
}
EP;
}
void UpdateEditorDialog(void)
{
int x;
XmString xstr;
SP("UpdateEditorDialog");
if (edl)
{
XtUnmanageChild(edl);
XmListDeleteAllItems(edl);
for (x=0;x<editors;x++)
{
if (editor[x]->filename[0])
xstr=XmStringCreateLocalized(editor[x]->filename);
else
xstr=XmStringCreateLocalized("<Untitled>");
XmListAddItemUnselected(edl,xstr,0);
XmStringFree(xstr);
}
XtManageChild(edl);
}
EP;
}
void ShowEditorDialog(void)
{
SP("ShowEditorDialog");
if (!edd)
{
CreateEditorDialog();
UpdateEditorDialog();
}
/* XtManageChild(edd);*/
XtPopup(edd,XtGrabNone);
XMapRaised(XtDisplay(edd),XtWindow(edd));
EP;
}
jex-1.3.7/execute.c 100644 0 0 45007 6672726717 12247 0 ustar root root #include <Xm/Xm.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/DialogS.h>
#include <Xm/List.h>
#include <Xm/MessageB.h>
#include <Xm/Form.h>
#include <Xm/LabelG.h>
#include <Xm/PushBG.h>
#include <Xm/Separator.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include "jex.h"
extern Widget top;
extern XtAppContext app;
extern Pixmap pixmap;
#define WORKTIMEOUT 150
#define WORKCOUNTS 20
/*char *workstr[]={"|","/","-","\\"};*/
char *workstr[]={
"/.........",
"./........",
"../.......",
".../......",
"..../.....",
"...../....",
"....../...",
"......./..",
"......../.",
"........./",
".........\\",
"........\\.",
".......\\..",
"......\\...",
".....\\....",
"....\\.....",
"...\\......",
"..\\.......",
".\\........",
"\\........."
};
void InputCallback1(Editor *e,int f,XtInputId l);
void InputCallback2(Editor *e,int f,XtInputId l);
void SetLabel(Editor *e,...)
{
va_list app;
char str[255],*tmp;
XmString xstr;
SP("SetLabel");
va_start(app,e);
tmp=va_arg(app,char *);
vsprintf(str,tmp,app);
va_end(app);
xstr=XmStringCreateLtoR(str,XmSTRING_DEFAULT_CHARSET);
XtVaSetValues(e->iodtext,XmNlabelString,xstr,NULL);
XmStringFree(xstr);
EP;
}
void wprintf(Widget window,...)
{
va_list app;
char str[512],*tmp;
XmString xstr;
SP("wprintf");
va_start(app,window);
/* if (!XtIsManaged(XtParent(XtParent(XtParent(window)))))
XtManageChild(XtParent(XtParent(XtParent(window))));*/
/* XtPopup(XtParent(XtParent(XtParent(window))),XtGrabNone);*/
tmp=va_arg(app,char *);
vsprintf(str,tmp,app);
va_end(app);
xstr=XmStringCreateLtoR(str,XmSTRING_DEFAULT_CHARSET);
XmListAddItemUnselected(window,xstr,0);
XmListSetBottomPos(window,0);
XmStringFree(xstr);
EP;
}
void SplitUp(char *str,char *list[])
{
SP("SplitUP");
while (*str!=0)
{
while ((*str==' ') || (*str=='\t') || (*str=='\n'))
*(str++)=0;
*(list++)=str;
while ((*str!=0) && (*str!=' ') && (*str!='\t') && (*str!='\n'))
str++;
}
*list=0;
EP;
}
void RemoveInputs(Editor *e,void *tid)
{
SP("RemoveInputs");
XtRemoveInput(e->t.id);
XtRemoveInput(e->t.id2);
db_close(e->t.fd[0]);
db_close(e->t.fd[1]);
db_close(e->t.fd2[0]);
db_close(e->t.fd2[1]);
db_close(e->t.fd3[0]);
db_close(e->t.fd3[1]);
EP;
}
void FreeClose(int sig,XtIntervalId tid)
{
int status,pid=0,x,y;
SP("FreeClose");
for (y=0;y<editors;y++)
{
if (editor[y]->t.pid)
{
if ((pid=waitpid(editor[y]->t.pid,&status,WNOHANG))==-1)
{
EP;
return;
}
else
{
if (pid)
{
for (x=0;x<editors;x++)
{
if (editor[x]->t.pid==pid)
{
XtAppAddTimeOut(app,0,(XtTimerCallbackProc)RemoveInputs,editor[x]);
if (sig)
{
InputCallback1(editor[x],0,0);
InputCallback2(editor[x],0,0);
}
if (editor[x]->x)
{
editor[x]->buf[editor[x]->x]=0;
wprintf(editor[x]->io_win,"%s",editor[x]->buf);
}
if (WIFEXITED(status)!=0)
{
if (WEXITSTATUS(status)==0)
SetLabel(editor[x],"%s has finished normally.",editor[x]->t.name);
else
SetLabel(editor[x],"%s has finished with error code %d.",
editor[x]->t.name,WEXITSTATUS(status));
}
else if (WIFSIGNALED(status))
SetLabel(editor[x],"%s has finished abnormally!! (signal %d)",
editor[x]->t.name,WTERMSIG(status));
else
SetLabel(editor[x],"%s has finished abnormally for an unknown reason!!",
editor[x]->t.name);
XtVaSetValues(editor[x]->compile,XmNsensitive,True,NULL);
XtVaSetValues(editor[x]->make,XmNsensitive,True,NULL);
XtVaSetValues(editor[x]->run,XmNsensitive,True,NULL);
XtVaSetValues(editor[x]->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(editor[x]->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(editor[x]->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(editor[x]->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(editor[x]->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
if (editor[x]->tid)
{
XtRemoveTimeOut(editor[x]->tid);
editor[x]->tid=0;
}
editor[x]->t.pid=0;
}
}
}
}
}
}
EP;
}
void ChildSignal(int sig)
{
SP("ChildSignal");
XtAppAddTimeOut(app,0,(XtTimerCallbackProc)FreeClose,(void*)sig);
EP;
}
void InputTimeout1(Editor *e,XtIntervalId tid)
{
SP("InputTimeout1");
if (e->x)
{
if (e->same_line)
XmListDeletePos(e->io_win,0);
e->buf[e->x]=0;
wprintf(e->io_win,e->buf);
e->same_line=1;
}
e->tid7=0;
EP;
}
void InputCallback1(Editor *e,int f,XtInputId l)
{
unsigned int bread;
SP("InputCallback1");
if (e->tid7)
XtRemoveTimeOut(e->tid7);
e->tid7=XtAppAddTimeOut(app,250,(XtTimerCallbackProc)InputTimeout1,e);
while ((bread=read(e->t.fd[0],&e->buf[e->x],1))==1)
{
if (e->x+1==BUFSIZE-1 || e->buf[e->x]=='\n')
{
if (e->buf[e->x]=='\n')
e->buf[e->x]='\0'; /* Make sure string is 0-terminated. */
else
e->buf[e->x+1]='\0'; /* Make sure string is 0-terminated. */
wprintf(e->io_win,"%s",e->buf);
e->same_line=0;
e->x=0;
}
else
{
e->x++;
}
}
if (bread==-1 && l==0)
FreeClose(0,0);
EP;
}
void InputCallback2(Editor *e,int f,XtInputId l)
{
unsigned int bread;
SP("InputCallback2");
if (e->tid7)
XtRemoveTimeOut(e->tid7);
e->tid7=XtAppAddTimeOut(app,250,(XtTimerCallbackProc)InputTimeout1,e);
while ((bread=read(e->t.fd2[0],&e->buf[e->x],1))==1)
{
if (e->x+1==BUFSIZE-1 || e->buf[e->x]=='\n')
{
if (e->buf[e->x]=='\n')
e->buf[e->x]='\0'; /* Make sure string is 0-terminated. */
else
e->buf[e->x+1]='\0'; /* Make sure string is 0-terminated. */
wprintf(e->io_win,"%s",e->buf);
e->x=0;
}
else
e->x++;
}
if (bread==-1 && l==0)
FreeClose(0,0);
EP;
}
void CloseCompile(Widget w,Editor *e,void *cbs)
{
SP("CloseCompile");
/* XtUnmanageChild(e->iod);*/
XtPopdown(e->iod);
SetCurrentWidget(e->text);
EP;
}
void CheckChild(int pid,XtIntervalId tid)
{
int status,result;
SP("CheckChild");
result=waitpid(pid,&status,WNOHANG);
if (result>=0)
{
kill(pid,SIGKILL);
}
EP;
}
void StopCompile(Widget w,Editor *e,void *cbs)
{
SP("StopCompile");
if (e->t.pid)
{
kill(e->t.pid,SIGQUIT);
SetLabel(e,"Sent quit signal to program...");
XtAppAddTimeOut(app,5000,(XtTimerCallbackProc)CheckChild,(void*)e->t.pid);
if (e->tid)
{
XtRemoveTimeOut(e->tid);
e->tid=0;
}
}
EP;
}
void SendInput(Widget w,Editor *e,void *cbs)
{
char *tmpstr;
SP("SendInput");
if (e->t.pid)
{
XtVaGetValues(e->owi,XmNvalue,&tmpstr,NULL);
write(e->t.fd3[1],tmpstr,strlen(tmpstr));
write(e->t.fd3[1],"\n",strlen("\n"));
if (strlen(e->buf)+strlen(tmpstr)<BUFSIZE)
{
if (e->same_line)
XmListDeletePos(e->io_win,0);
strcat(e->buf,tmpstr);
wprintf(e->io_win,"%s",e->buf);
e->x=0;
e->same_line=0;
}
XtFree(tmpstr);
XmTextFieldSetString(e->owi,""); // Clear the textfield.
}
EP;
}
void CreateOutputWindow(Editor *e)
{
Widget w,w2,w3;
Arg arg[9];
Dimension height;
SP("CreateOutputWindow");
if (!e->iod)
{
/* e->iod=XtVaCreateManagedWidget("IODialog",topLevelShellWidgetClass,top,
XmNallowShellResize,False,
XmNiconPixmap,pixmap,
NULL);*/
e->iod=XtVaAppCreateShell("IODialog","IODialog",topLevelShellWidgetClass,XtDisplay(top),
XmNallowShellResize,False,
XmNiconPixmap,pixmap,
NULL);
w2=XtVaCreateManagedWidget("IODialogForm",xmFormWidgetClass,e->iod,
NULL);
e->iodtext=XtVaCreateManagedWidget("IODialogText",xmLabelGadgetClass,w2,
XmNtopAttachment,XmATTACH_FORM,
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_NONE,
XmNalignment,XmALIGNMENT_CENTER,
NULL);
w3=XtVaCreateManagedWidget("IOButtons",xmFormWidgetClass,w2,
XmNtopAttachment,XmATTACH_NONE,
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_FORM,
XmNfractionBase,9,
XmNbottomOffset,10,
NULL);
w=XtVaCreateManagedWidget("IO_OK",xmPushButtonGadgetClass,w3,
XmNtopAttachment,XmATTACH_FORM,
XmNleftAttachment,XmATTACH_POSITION,
XmNleftPosition,1,
XmNrightAttachment,XmATTACH_POSITION,
XmNrightPosition,2,
XmNbottomAttachment,XmATTACH_FORM,
NULL);
XtAddCallback(w,XmNactivateCallback,(XtCallbackProc)CloseCompile,e);
w=XtVaCreateManagedWidget("IO_Stop",xmPushButtonGadgetClass,w3,
XmNtopAttachment,XmATTACH_FORM,
XmNleftAttachment,XmATTACH_POSITION,
XmNleftPosition,3,
XmNrightAttachment,XmATTACH_POSITION,
XmNrightPosition,4,
XmNbottomAttachment,XmATTACH_FORM,
NULL);
XtAddCallback(w,XmNactivateCallback,(XtCallbackProc)StopCompile,e);
w=XtVaCreateManagedWidget("IO_Goto",xmPushButtonGadgetClass,w3,
XmNtopAttachment,XmATTACH_FORM,
XmNleftAttachment,XmATTACH_POSITION,
XmNleftPosition,5,
XmNrightAttachment,XmATTACH_POSITION,
XmNrightPosition,6,
XmNbottomAttachment,XmATTACH_FORM,
NULL);
XtAddCallback(w,XmNactivateCallback,(XtCallbackProc)GotoError,e);
w=XtVaCreateManagedWidget("IO_Help",xmPushButtonGadgetClass,w3,
XmNtopAttachment,XmATTACH_FORM,
XmNleftAttachment,XmATTACH_POSITION,
XmNleftPosition,7,
XmNrightAttachment,XmATTACH_POSITION,
XmNrightPosition,8,
XmNbottomAttachment,XmATTACH_FORM,
NULL);
XtAddCallback(w,XmNactivateCallback,(XtCallbackProc)Help,"OutputWindow");
w=XtVaCreateManagedWidget("IOSep",xmSeparatorWidgetClass,w2,
XmNtopAttachment,XmATTACH_NONE,
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_WIDGET,
XmNbottomWidget,w3,
XmNorientation,XmHORIZONTAL,
XmNbottomOffset,10,
NULL);
w3=XtVaCreateManagedWidget("IOInputLabel",xmLabelGadgetClass,w2,
XmNtopAttachment,XmATTACH_NONE,
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_NONE,
XmNbottomAttachment,XmATTACH_WIDGET,
XmNbottomWidget,w,
NULL);
e->owi=XtVaCreateManagedWidget("IOInputField",xmTextFieldWidgetClass,w2,
XmNtopAttachment,XmATTACH_NONE,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,w3,
XmNrightAttachment,XmATTACH_FORM,
XmNbottomAttachment,XmATTACH_WIDGET,
XmNbottomWidget,w,
NULL);
XtAddCallback(e->owi,XmNactivateCallback,(XtCallbackProc)SendInput,e);
XtVaGetValues(e->owi,XmNheight,&height,NULL);
XtVaSetValues(w3,XmNheight,height,NULL);
XtSetArg(arg[0],XmNtopAttachment,XmATTACH_WIDGET);
XtSetArg(arg[1],XmNtopWidget,e->iodtext);
XtSetArg(arg[2],XmNleftAttachment,XmATTACH_FORM);
XtSetArg(arg[3],XmNrightAttachment,XmATTACH_FORM);
XtSetArg(arg[4],XmNbottomAttachment,XmATTACH_WIDGET);
XtSetArg(arg[5],XmNbottomWidget,e->owi);
XtSetArg(arg[6],XmNlistSizePolicy,XmCONSTANT);
XtSetArg(arg[7],XmNbottomOffset,10);
XtSetArg(arg[8],XmNtopOffset,10);
e->io_win=XmCreateScrolledList(w2,"IOList",arg,9);
XtVaSetValues(e->io_win,
XmNscrollBarDisplayPolicy,XmSTATIC,
XmNlistSizePolicy,XmCONSTANT,
NULL);
XtAddCallback(e->io_win,XmNdefaultActionCallback,(XtCallbackProc)GotoError,(void*)e);
XtManageChild(e->io_win);
}
EP;
}
void SetWorkingLabel(Editor *e,void *t)
{
SP("SetWorkingLabel");
e->workcount=(e->workcount+1)%WORKCOUNTS;
SetLabel(e,workstr[e->workcount]);
e->tid=XtAppAddTimeOut(app,WORKTIMEOUT,(XtTimerCallbackProc)SetWorkingLabel,e);
EP;
}
void ExecProg(Editor *e,char *_prog)
{
static char *command[20];
char *prog;
int pid;
SP("ExecProg");
WatchCursor(e,1);
XtVaSetValues(e->compile,XmNsensitive,False,NULL);
XtVaSetValues(e->make,XmNsensitive,False,NULL);
XtVaSetValues(e->run,XmNsensitive,False,NULL);
XtVaSetValues(e->grep,XmNsensitive,False,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,False,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,False,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,False,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,False,NULL);
#endif
CreateOutputWindow(e);
/* XtManageChild(e->iod);*/
XtPopup(e->iod,XtGrabNone);
XMapRaised(XtDisplay(e->iod),XtWindow(e->iod));
XmListDeleteAllItems(e->io_win);
e->x=0;
WatchCursor(e,0);
if (db_pipe(e->t.fd)!=0)
{
SetLabel(e,"Too many open files!");
XtVaSetValues(e->compile,XmNsensitive,True,NULL);
XtVaSetValues(e->make,XmNsensitive,True,NULL);
XtVaSetValues(e->run,XmNsensitive,True,NULL);
XtVaSetValues(e->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
EP;
return;
}
if (db_pipe(e->t.fd2)!=0)
{
SetLabel(e,"Too many open files!");
db_close(e->t.fd[0]);
db_close(e->t.fd[1]);
XtVaSetValues(e->compile,XmNsensitive,True,NULL);
XtVaSetValues(e->make,XmNsensitive,True,NULL);
XtVaSetValues(e->run,XmNsensitive,True,NULL);
XtVaSetValues(e->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
EP;
return;
}
if (db_pipe(e->t.fd3)!=0)
{
SetLabel(e,"Too many open files!");
db_close(e->t.fd[0]);
db_close(e->t.fd[1]);
db_close(e->t.fd2[0]);
db_close(e->t.fd2[1]);
XtVaSetValues(e->compile,XmNsensitive,True,NULL);
XtVaSetValues(e->make,XmNsensitive,True,NULL);
XtVaSetValues(e->run,XmNsensitive,True,NULL);
XtVaSetValues(e->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
EP;
return;
}
prog=(char*)db_malloc(db_strlen(_prog)*2);
db_strcpy(prog,_prog);
SetLabel(e,"%s",prog);
e->tid=XtAppAddTimeOut(app,500,(XtTimerCallbackProc)SetWorkingLabel,(void*)e);
e->same_line=0;
fcntl(e->t.fd[0],F_SETFL,O_NONBLOCK);
fcntl(e->t.fd2[0],F_SETFL,O_NONBLOCK);
e->t.id=XtAppAddInput(app,e->t.fd[0],(XtPointer)XtInputReadMask,(XtInputCallbackProc)InputCallback1,(XtPointer)e);
e->t.id2=XtAppAddInput(app,e->t.fd2[0],(XtPointer)XtInputReadMask,(XtInputCallbackProc)InputCallback2,(XtPointer)e);
SplitUp(prog,command);
db_strncpy(e->t.name,command[0],99);
signal(SIGCHLD,ChildSignal);
if ((pid=fork())>=0)
{
if (pid>0)
{
e->t.pid=pid;
db_free(prog);
e->grepped=0;
}
if (pid==0)
{
db_dup2(e->t.fd3[0],0);
db_dup2(e->t.fd[1],1);
db_dup2(e->t.fd2[1],2);
if (execvp(command[0],command)==-1)
exit(-1);
exit(0);
}
}
else
{
SetLabel(e,"fork() failed!");
XtVaSetValues(e->compile,XmNsensitive,True,NULL);
XtVaSetValues(e->make,XmNsensitive,True,NULL);
XtVaSetValues(e->run,XmNsensitive,True,NULL);
XtVaSetValues(e->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
EP;
return;
}
EP;
}
void CompileOK(Editor *e)
{
char str[255];
SP("CompileOK");
sprintf(str,e->compile_command,e->filename);
ExecProg(e,str);
EP;
}
void Compile(Widget w,Editor *e,void *cbs)
{
int x;
SP("Compile");
for (x=0;x<editors;x++)
{
if (!editor[x]->saved && editor[x]->filename[0])
Save(NULL,editor[x],NULL);
}
if (e->saved && e->filename[0])
CompileOK(e);
else
Save(NULL,e,(void*)CompileOK);
EP;
}
void MakeOK(Editor *e)
{
SP("MakeOK");
ExecProg(e,e->make_command);
EP;
}
void Make(Widget w,Editor *e,void *cbs)
{
int x;
SP("Make");
for (x=0;x<editors;x++)
{
if (!editor[x]->saved && editor[x]->filename[0])
Save(NULL,editor[x],NULL);
}
if (e->saved && e->filename[0])
MakeOK(e);
else
Save(NULL,e,(void*)MakeOK);
EP;
}
void LatestVersion(void)
{
char *cmd[3];
char browser[256];
if (!FindHelpFile("netscape",browser))
{
if (!FindHelpFile("Mosaic",browser))
{
if (!FindHelpFile("arena",browser))
{
HelpError("You can find the latest version at http://www.club.innet.be/~year1939/applications.html");
return;
}
}
}
if (!fork())
{
cmd[0]=strdup(browser);
cmd[1]=strdup("http://www.club.innet.be/~year1939/applications.html");
cmd[2]=NULL;
if (execvp(cmd[0],cmd)==-1)
exit(-1);
exit(0);
}
}
void RunOK(Editor *e)
{
char runstr[1000];
SP("Run");
sprintf(runstr,e->run_command,e->filename);
ExecProg(e,runstr);
EP;
}
void Run(Widget w,Editor *e,void *cbs)
{
SP("Run");
if (!e->run_command[0])
ShowError(e,"You must specify in the settings which program to run!");
else
{
if (e->saved && e->filename[0])
RunOK(e);
else
Save(NULL,e,(void*)RunOK);
}
EP;
}
jex-1.3.7/filemenu.c 100644 0 0 15372 6672726717 12413 0 ustar root root #include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include "jex.h"
extern char fl_files[FILELIST][255];
void Quit(Widget w,Editor *e,void *cbs)
{
SP("Quit");
if (e->saved)
Exit(e);
else
AskToSave(e,(void*)Exit);
EP;
}
void DoNew(Widget *w,Editor *e,void *cbs)
{
SP("DoNew");
if (e->saved)
New(e);
else
AskToSave(e,(void*)New);
EP;
}
void DoOpen(Widget *w,Editor *e,void *cbs)
{
SP("DoOpen");
if (e->saved)
Load(e);
else
AskToSave(e,(void*)Load);
EP;
}
void DoNewWindow(Widget *w,void *e,void *cbs)
{
SP("DoNewWindow");
CreateNewEditor();
EP;
}
void DoClone(Widget *w,Editor *e,void *cbs)
{
SP("DoClone");
CreateNewEditor();
if (e->filename[0])
{
if (loadfile(editor[editors-1],e->filename,0,1))
LoadError(editor[editors-1]);
}
EP;
}
void file_cb(Widget w,int item,void *cbs)
{
int x;
SP("file_cb");
for (x=0;x<editors;x++)
{
if (editor[x]->mb==XtParent(XtParent(XtParent(w))))
{
switch (item)
{
case 0: /* New window */
CreateNewEditor();
break;
case 1: /* New window */
CreateNewEditor();
if (editor[x]->filename[0])
{
if (loadfile(editor[editors-1],editor[x]->filename,0,1))
LoadError(editor[editors-1]);
}
break;
case 2: /* New */
if (editor[x]->saved)
New(editor[x]);
else
AskToSave(editor[x],(void*)New);
break;
case 3: /* Load */
if (editor[x]->saved)
Load(editor[x]);
else
AskToSave(editor[x],(void*)Load);
break;
case 4:
Save(NULL,editor[x],NULL);
break;
case 5:
editor[x]->func2=NULL;
SaveAs(editor[x]);
break;
case 6:
Reload(editor[x]);
break;
case 7:
Revert(editor[x]);
break;
case 8:
Insert(editor[x]);
break;
case 9:
Print(editor[x]);
break;
case 10:
Quit(NULL,editor[x],NULL);
break;
}
}
}
EP;
}
void edit_cb(Widget w,int item,void *cbs)
{
int x;
SP("edit_cb");
for (x=0;x<editors;x++)
{
if (editor[x]->mb==XtParent(XtParent(XtParent(w))))
{
switch (item)
{
case 0:
UndoAction(NULL,editor[x],NULL);
break;
case 1:
RedoAction(NULL,editor[x],NULL);
break;
case 2:
RepeatAction(NULL,editor[x],NULL);
break;
case 3:
CopyText(NULL,editor[x],NULL);
break;
case 4:
CutText(NULL,editor[x],NULL);
break;
case 5:
PasteText(NULL,editor[x],NULL);
break;
case 6:
ClearSelection(NULL,editor[x],NULL);
break;
case 7:
CapsSelection(NULL,editor[x],NULL);
break;
case 8:
LowsSelection(NULL,editor[x],NULL);
break;
case 9:
ShiftLeft(NULL,editor[x],NULL);
break;
case 10:
ShiftRight(NULL,editor[x],NULL);
break;
case 11:
FindMatchingChar(NULL,editor[x],NULL);
break;
case 12:
SetMarker(NULL,editor[x],NULL);
break;
case 13:
GotoMarker(NULL,editor[x],NULL);
break;
}
}
}
EP;
}
void PopupMenu(Widget w,XButtonPressedEvent *event,String *args,int *num_args)
{
int x;
SP("PopupMenu");
while (!XtIsShell(w))
w=XtParent(w);
for (x=0;x<editors;x++)
{
if (editor[x]->shell==w)
{
XmMenuPosition(editor[x]->pm,event);
XtManageChild(editor[x]->pm);
}
}
EP;
}
void popup_cb(Widget w,int item,XmAnyCallbackStruct *cbs)
{
int x;
SP("popup_cb");
for (x=0;x<editors;x++)
{
if (editor[x]->pm==XtParent(w))
{
switch ((int)item)
{
case 0:
CopyText(NULL,editor[x],NULL);
break;
case 1:
CutText(NULL,editor[x],NULL);
break;
case 2:
PasteText(NULL,editor[x],NULL);
break;
case 3:
ClearSelection(NULL,editor[x],NULL);
break;
case 4:
UndoAction(NULL,editor[x],NULL);
break;
case 5:
RedoAction(NULL,editor[x],NULL);
break;
case 6:
GotoLine(NULL,editor[x],NULL);
break;
}
}
}
EP;
}
void option_cb(Widget w,int item,void *cbs)
{
int x;
Boolean set;
SP("option_cb");
for (x=0;x<editors;x++)
{
if (editor[x]->mb==XtParent(XtParent(XtParent(w))))
{
switch (item)
{
case 0: Settings(editor[x]);break;
case 1: XtVaGetValues(w,XmNset,&set,NULL);
XtVaSetValues(editor[x]->text,XmNeditable,set?False:True,NULL);
editor[x]->read_only=set?1:0;
break;
case 3: Compile(NULL,editor[x],NULL);break;
case 4: Make(NULL,editor[x],NULL);break;
case 5: Grep(NULL,editor[x],NULL);break;
}
}
}
EP;
}
void bookmark_cb(Widget w,int item,void *cbs)
{
int x;
SP("bookmark_cb");
for (x=0;x<editors;x++)
{
if (editor[x]->mb==XtParent(XtParent(XtParent(w))))
{
switch (item)
{
case 0: AddBookmark(editor[x]->filename);break;
case 1: ShowBookmarkDialog();break;
}
}
}
EP;
}
void tools_cb(Widget w,int item,void *cbs)
{
int x;
SP("tools_cb");
for (x=0;x<editors;x++)
{
if (editor[x]->mb==XtParent(XtParent(XtParent(w))))
{
switch (item)
{
case 0: Compile(NULL,editor[x],NULL);break;
case 1: Make(NULL,editor[x],NULL);break;
case 2: Run(NULL,editor[x],NULL);break;
case 3: Grep(NULL,editor[x],NULL);break;
}
}
}
EP;
}
void view_cb(Widget w,int item,void *cbs)
{
int x;
SP("view_cb");
for (x=0;x<editors;x++)
{
if (editor[x]->mb==XtParent(XtParent(XtParent(w))))
{
switch (item)
{
case 0: ShowEditorDialog();break;
case 1: CreateOutputWindow(editor[x]);
/*XtManageChild(editor[x]->iod);*/
XtPopup(editor[x]->iod,XtGrabNone);
XMapRaised(XtDisplay(editor[x]->iod),XtWindow(editor[x]->iod));
break;
case 2: ShowStats(editor[x]);break;
}
}
}
EP;
}
void help_cb(Widget w,int item,void *cbs)
{
int x;
SP("help_cb");
for (x=0;x<editors;x++)
{
if (editor[x]->mb==XtParent(XtParent(XtParent(w))))
{
switch (item)
{
case 0: Help(NULL,"Contents",NULL);break;
case 1: LatestVersion();break;
case 2: ShowAboutDialog(editor[x]);break;
}
}
}
EP;
}
jex-1.3.7/files.c 100644 0 0 13174 6672726717 11707 0 ustar root root #include <Xm/Xm.h>
#include <Xm/FileSB.h>
#include <Xm/Text.h>
#include <Xm/TextStrSoP.h>
#include <Xm/MessageB.h>
#include "jex.h"
extern Widget top;
void CheckSaveAsOK(Widget w,Editor *e,Widget fw);
void SetTitle(Editor *e,char *str)
{
char title[255],directory[255],file[255];
SP("SetTitle");
if (str && *str)
{
sprintf(title,"jex: %s",str);
SplitPath(str,directory,file);
XtVaSetValues(e->shell,XmNiconName,file,NULL);
}
else
{
db_strcpy(title,"jex");
XtVaSetValues(e->shell,XmNiconName,"jex",NULL);
}
XtVaSetValues(e->shell,XmNtitle,title,NULL);
UpdateEditorDialog();
EP;
}
void SaveOK(Editor *e)
{
int stat;
char *str;
SP("SaveOK");
if (e->read_only)
{
EP;
return;
}
XtVaGetValues(e->text,XmNvalue,&str,NULL);
stat=savefile(e,e->filename,str);
XtFree(str);
if (!stat)
SaveError(e);
else
{
e->saved=1;
e->changes=0;
/* XtUnmanageChild(e->save);*/
SetSave(e,False);
if (e->func2!=NULL)
Function((void(*)(void))e->func2,e);
}
EP;
}
void SaveAsOK(Widget w,Editor *e,Widget fw)
{
char *file;
int x;
SP("SaveAsOK");
if (e->read_only)
{
EP;
return;
}
XtVaGetValues(fw,XmNvalue,&file,NULL);
db_strcpy(e->filename,file);
GetFullFileName(e->filename);
SetTitle(e,e->filename);
SaveOK(e);
if (strcmp(e->filename,file))
{
if (e->oldsource)
{
printf("1\n");
DetachEditor(e,file);
}
else
{
printf("2\n");
for (x=0;x<editors;x++)
{
if (editor[x]!=e && db_strcmp(editor[x]->filename,file)==0)
{
printf("3\n");
XmTextSetSource(e->tmpsource,XmTextGetSource(e->text),0,0);
XmTextSetSource(e->text,XmTextGetSource(editor[x]->text),0,0);
e->oldsource=1;
editor[x]->oldsource=1;
break;
}
}
}
}
XtFree(file);
EP;
}
void NoOverwrite(Widget w,Editor *e,void *cbs)
{
SP("NoOverwrite");
CreateFileSelectionDialog(e,"Save As",(void*)CheckSaveAsOK,e->func2);
EP;
}
void CancelAskToOverwrite(Widget w,Editor *e,void *cbs)
{
SP("CancelAskToOverwrite");
XtUnmanageChild(e->ato);
SetCurrentWidget(e->text);
EP;
}
void AskToOverwriteOK(Widget w,Editor *e,void *cbs)
{
SP("AskToOverwriteOK");
SaveAsOK(w,e,e->f);
SetCurrentWidget(e->text);
EP;
}
void CheckSaveAsOK(Widget w,Editor *e,Widget fw)
{
char *file;
struct stat st;
SP("CheckSaveAsOK");
if (e->read_only)
{
EP;
return;
}
XtVaGetValues(fw,XmNvalue,&file,NULL);
if (db_stat(file,&st)==-1)
SaveAsOK(w,e,fw);
else
{
if (e->ato==NULL)
{
e->ato=XmCreateQuestionDialog(e->shell,"AskToOverwrite",NULL,0);
e->f=fw;
XtAddCallback(e->ato,XmNokCallback,(XtCallbackProc)AskToOverwriteOK,e);
XtAddCallback(e->ato,XmNcancelCallback,(XtCallbackProc)NoOverwrite,e);
XtAddCallback(e->ato,XmNhelpCallback,(XtCallbackProc)CancelAskToOverwrite,e);
}
else
{
XtRemoveAllCallbacks(e->ato,XmNokCallback);
XtRemoveAllCallbacks(e->ato,XmNcancelCallback);
XtRemoveAllCallbacks(e->ato,XmNhelpCallback);
e->f=fw;
XtAddCallback(e->ato,XmNokCallback,(XtCallbackProc)AskToOverwriteOK,e);
XtAddCallback(e->ato,XmNcancelCallback,(XtCallbackProc)NoOverwrite,e);
XtAddCallback(e->ato,XmNhelpCallback,(XtCallbackProc)CancelAskToOverwrite,e);
}
XtManageChild(e->ato);
}
}
void SaveAs(Editor *e)
{
SP("SaveAs");
if (e->read_only)
{
EP;
return;
}
CreateFileSelectionDialog(e,"Save As",(void*)CheckSaveAsOK,e->func2);
EP;
}
void Save(Widget w,Editor *e,void *cbs)
{
SP("Save");
if (e->read_only)
{
EP;
return;
}
if (w)
e->func2=NULL;
else
e->func2=cbs;
if (e->filename[0])
SaveOK(e);
else
SaveAs(e);
EP;
}
void ValueChanged(Widget w,Editor *e,void *cbs)
{
SP("ValueChanged");
/* XtManageChild(e->save);*/
SetSave(e,True);
e->saved=0;
EP;
}
void New(Editor *e)
{
SP("New");
UnlinkFile(e);
DetachEditor(e,NULL);
XtVaSetValues(e->text,XmNvalue,"",NULL);
e->saved=1;
SetTitle(e,"");
e->filename[0]=0;
/* XtUnmanageChild(e->save);*/
SetSave(e,False);
NoUndo(e);
EP;
}
void LoadOK(Widget w,Editor *e,Widget fw)
{
char *file;
SP("LoadOK");
XtVaGetValues(fw,XmNvalue,&file,NULL);
if (loadfile(e,file,0,1))
LoadError(e);
else
{
/* db_strcpy(e->filename,file);*/
XtFree(file);
/* SetTitle(e,e->filename);*/
}
EP;
}
void Load(Editor *e)
{
SP("Load");
CreateFileSelectionDialog(e,"Load",(void*)LoadOK,NULL);
EP;
}
void Revert(Editor *e)
{
char tmpstr[255];
int result;
FILE *f;
SP("Revert");
if (e->read_only)
{
EP;
return;
}
if (e->filename[0])
{
if (e->saved)
{
sprintf(tmpstr,"%s~",e->filename);
if ((f=fopen(tmpstr,"r"))!=NULL)
{
fclose(f);
CopyFile(tmpstr,e->filename);
result=loadfile(e,tmpstr,0,0);
CopyFile(e->filename,tmpstr);
}
else
{
EP;
return;
}
}
else
result=loadfile(e,e->filename,0,0);
if (result!=0)
LoadError(e);
else
SetTitle(e,e->filename);
}
EP;
}
void PrintOK(Editor *e)
{
SP("PrintOK");
printfile(e,e->filename);
EP;
}
void Print(Editor *e)
{
SP("Print");
if (!e->saved)
{
e->f=(void*)PrintOK;
Save(NULL,(void*)e,NULL);
}
else
PrintOK(e);
EP;
}
void InsertOK(Widget w,Editor *e,Widget fw)
{
char *file;
SP("InsertOK");
if (e->read_only)
{
EP;
return;
}
XtVaGetValues(fw,XmNvalue,&file,NULL);
if (loadfile(e,file,1,0))
LoadError(e);
XtFree(file);
EP;
}
void Insert(Editor *e)
{
SP("Insert");
if (e->read_only)
{
EP;
return;
}
CreateFileSelectionDialog(e,"Insert",(void*)InsertOK,NULL);
EP;
}
jex-1.3.7/filesb.c 100644 0 0 27565 6672726717 12062 0 ustar root root #include <stdio.h>
#include <string.h>
#include <Xm/MessageB.h>
#include <Xm/LabelG.h>
#include <Xm/Form.h>
#include <Xm/List.h>
#include <Xm/TextF.h>
#include <Xm/RowColumn.h>
#include <Xm/SeparatoG.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include "match.h"
#include "jex.h"
extern Widget top,combo1,combo2,combo3;
void AddItem(Widget list,char *newtext)
{
char *text;
XmString str,*strlist;
int u_bound,l_bound=0,i;
SP("AddItem");
XtVaGetValues(list,XmNitemCount,&u_bound,
XmNitems,&strlist,
NULL);
u_bound--;
while (u_bound>=l_bound)
{
i=l_bound+(u_bound-l_bound)/2;
if (!XmStringGetLtoR(strlist[i],XmSTRING_DEFAULT_CHARSET,&text))
break;
if (db_strcmp(text,newtext)>0)
u_bound=i-1;
else
l_bound=i+1;
XtFree(text);
}
str=XmStringCreateLocalized(newtext);
XmListAddItemUnselected(list,str,l_bound+1);
XmStringFree(str);
EP;
}
void SplitPath(char *orig_path,char *directory,char *filter)
{
char *tmp;
char path[255];
SP("SplitPath");
db_strcpy(path,orig_path);
tmp=db_strrchr(path,'/');
if (tmp)
{
*tmp=0;
db_strcpy(directory,path);
if (!directory[0])
db_strcpy(directory,"/");
db_strcpy(filter,tmp+1);
if (!filter[0])
db_strcpy(filter,"*");
}
else
{
db_strcpy(directory,".");
db_strcpy(filter,path);
if (!filter[0])
db_strcpy(filter,"*");
}
EP;
}
void GetDirectory(Editor *e,char *directory,char *filter)
{
DIR *dp;
struct dirent *dir;
struct stat sbuf;
char file[255];
SP("GetDirectory");
XmListDeleteAllItems(e->filefield);
XmListDeleteAllItems(e->dir_field);
if ((dp=db_opendir(directory))==NULL)
{
/* fprintf(stderr,"Can't open directory %s\n",path);*/
EP;
return;
}
XtUnmanageChild(e->filefield);
XtUnmanageChild(e->dir_field);
while ((dir=db_readdir(dp))!=NULL)
{
if (dir->d_ino==0)
continue;
if (directory[db_strlen(directory)-1]!='/')
sprintf(file,"%s/%s",directory,dir->d_name);
else
sprintf(file,"%s%s",directory,dir->d_name);
if (db_stat(file,&sbuf)<0)
{
if (db_lstat(file,&sbuf)<0)
{
continue;
}
}
if ((sbuf.st_mode&S_IFMT)==S_IFDIR)
{
AddItem(e->dir_field,file);
continue;
}
if (match(filter,dir->d_name))
{
AddItem(e->filefield,dir->d_name);
}
}
db_closedir(dp);
XtManageChild(e->filefield);
XtManageChild(e->dir_field);
EP;
}
void SelectDir(Widget w,Editor *e,XmListCallbackStruct *cbs)
{
char *newdir,*curdir,directory[255],*filter,newpath[255],prevdir[255],tmp[255];
char olddir[255],newdirectory[255];
XmString size;
SP("SelectDir");
WatchCursor(e,1);
XmStringGetLtoR(cbs->item,XmSTRING_DEFAULT_CHARSET,&newdir);
XtVaGetValues(e->dirfilter_field,XmNvalue,&curdir,NULL);
XtVaGetValues(e->filter_field,XmNvalue,&filter,NULL);
SplitPath(newdir,olddir,newdirectory);
if (db_strcmp(newdirectory,".")==0)
{
if (olddir[db_strlen(prevdir)-1]!='/')
sprintf(newpath,"%s/%s",olddir,filter);
else
sprintf(newpath,"%s%s",olddir,filter);
}
else if (db_strcmp(newdirectory,"..")==0)
{
SplitPath(curdir,prevdir,tmp);
if (prevdir[db_strlen(prevdir)-1]!='/')
sprintf(newpath,"%s/%s",prevdir,filter);
else
sprintf(newpath,"%s%s",prevdir,filter);
}
else
{
if (newdir[db_strlen(newdir)-1]!='/')
sprintf(newpath,"%s/%s",newdir,filter);
else
sprintf(newpath,"%s%s",newdir,filter);
}
SplitPath(newpath,directory,filter);
XtVaSetValues(e->dirfilter_field,XmNvalue,directory,NULL);
XtVaSetValues(e->sel_field,XmNvalue,directory,NULL);
size=XmStringCreateLocalized("0 bytes");
XtVaSetValues(e->fssize,XmNlabelString,size,NULL);
GetDirectory(e,directory,filter);
XmStringFree(size);
XtFree(curdir);
XtFree(filter);
XtFree(newdir);
WatchCursor(e,0);
EP;
}
void BrowseSelect(Widget w,Editor *e,XmListCallbackStruct *cbs)
{
char *newfile,*curdir,filter[255];
struct stat st;
XmString size;
SP("BrowseSelect");
XmStringGetLtoR(cbs->item,XmSTRING_DEFAULT_CHARSET,&newfile);
XtVaGetValues(e->dirfilter_field,XmNvalue,&curdir,NULL);
if (curdir[db_strlen(curdir)-1]!='/')
sprintf(filter,"%s/%s",curdir,newfile);
else
sprintf(filter,"%s%s",curdir,newfile);
XtVaSetValues(e->sel_field,XmNvalue,filter,NULL);
db_stat(filter,&st);
if (st.st_size>1024*1024)
sprintf(filter,"%.1f Mb",(double)st.st_size/(1024.0*1024.0));
else if (st.st_size>1024)
sprintf(filter,"%.1f Kb",(double)st.st_size/1024.0);
else
sprintf(filter,"%lu bytes",(unsigned long)st.st_size);
size=XmStringCreateLocalized(filter);
XtVaSetValues(e->fssize,XmNlabelString,size,NULL);
XmStringFree(size);
XtFree(newfile);
XtFree(curdir);
EP;
}
void CallFunction(void (*f)(),Editor *e)
{
SP("CallFunction");
f(e->fs,e,e->sel_field);
EP;
}
void FSOKCallback(Widget w,Editor *e,void *cbs)
{
char *str;
int x;
SP("FSOKCallback");
XtVaGetValues(e->sel_field,XmNvalue,&str,NULL);
UpdateComboBox(combo3,str);
for (x=0;x<editors;x++)
{
if (editor[x]->fs)
UpdateComboBox(editor[x]->sel_field,str);
}
XtFree(str);
XtUnmanageChild(e->fs);
if (e->func!=NULL)
CallFunction((void(*)(void))e->func,e);
EP;
}
void FSCancelCallback(Widget w,Editor *e,void *cbs)
{
SP("FSCancelCallback");
XtUnmanageChild(e->fs);
EP;
}
void FSFilterCallback(Widget w,Editor *e,void *cbs)
{
char *filter,*dir;
XmString size;
int x;
SP("FSFilterCallback");
XtVaGetValues(e->filter_field,XmNvalue,&filter,NULL);
XtVaGetValues(e->dirfilter_field,XmNvalue,&dir,NULL);
UpdateComboBox(combo1,filter);
UpdateComboBox(combo2,dir);
for (x=0;x<editors;x++)
{
UpdateComboBox(editor[x]->filter_field,filter);
UpdateComboBox(editor[x]->dirfilter_field,dir);
}
GetDirectory(e,dir,filter);
size=XmStringCreateLocalized("0 bytes");
XtVaSetValues(e->fssize,XmNlabelString,size,NULL);
XmStringFree(size);
XtFree(dir);
XtFree(filter);
EP;
}
void CreateFileSelectionDialog(Editor *e,char *title,void *f,void *f2)
{
XmString xstr;
Arg arg[10];
char path[255];
Widget w,rc,l;
int n;
SP("CreateFileSelectionDialog");
e->func=f;
e->func2=f2;
WatchCursor(e,1);
if (e->fs==NULL)
{
XtSetArg(arg[0],XmNautoUnmanage,False);
XtSetArg(arg[1],XmNdefaultButtonType,NULL);
e->fs=XmCreateMessageDialog(e->shell,"FileSelection",arg,2);
XtAddCallback(e->fs,XmNokCallback,(XtCallbackProc)FSOKCallback,(void*)e);
XtAddCallback(e->fs,XmNcancelCallback,(XtCallbackProc)FSCancelCallback,(void*)e);
XtAddCallback(e->fs,XmNhelpCallback,(XtCallbackProc)FSFilterCallback,(void*)e);
xstr=XmStringCreateLocalized("Filter");
XtVaSetValues(e->fs,
XmNhelpLabelString,xstr,
XmNdialogStyle,XmDIALOG_FULL_APPLICATION_MODAL,
NULL);
XmStringFree(xstr);
e->form=XtVaCreateManagedWidget("FSForm",xmFormWidgetClass,e->fs,NULL);
l=XtVaCreateManagedWidget("FSTitle",xmLabelGadgetClass,e->form,
XmNtopAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_FORM,
XmNleftAttachment,XmATTACH_FORM,
NULL);
l=XtVaCreateManagedWidget("FSTitle",xmSeparatorGadgetClass,e->form,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,l,
XmNrightAttachment,XmATTACH_FORM,
XmNleftAttachment,XmATTACH_FORM,
NULL);
rc=XtVaCreateManagedWidget("FSRC",xmRowColumnWidgetClass,e->form,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,l,
XmNrightAttachment,XmATTACH_FORM,
XmNorientation,XmVERTICAL,
XmNmarginWidth,0,
XmNmarginHeight,0,
NULL);
w=XtVaCreateManagedWidget("FSFilter",xmLabelGadgetClass,rc,
XmNalignment,XmALIGNMENT_BEGINNING,
NULL);
e->filter_field=CreateComboBox(rc,"FSFilterField",NULL,0,10);
InitializeComboBox(e->filter_field,combo1);
ComboBoxAddCallback(e->filter_field,(XtCallbackProc)FSFilterCallback,(void*)e);
XtAddCallback(e->filter_field,XmNactivateCallback,(XtCallbackProc)FSFilterCallback,(void*)e);
rc=XtVaCreateManagedWidget("FSRC",xmRowColumnWidgetClass,e->form,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,l,
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_WIDGET,
XmNrightWidget,rc,
XmNorientation,XmVERTICAL,
XmNmarginWidth,0,
XmNmarginHeight,0,
NULL);
w=XtVaCreateManagedWidget("FSFilterDirLabel",xmLabelGadgetClass,rc,
XmNalignment,XmALIGNMENT_BEGINNING,
NULL);
e->dirfilter_field=CreateComboBox(rc,"FSFilterDirField",NULL,0,10);
InitializeComboBox(e->dirfilter_field,combo2);
ComboBoxAddCallback(e->dirfilter_field,(XtCallbackProc)FSFilterCallback,(void*)e);
XtAddCallback(e->dirfilter_field,XmNactivateCallback,(XtCallbackProc)FSFilterCallback,(void*)e);
e->dirlabel=XtVaCreateManagedWidget("FSDirLabel",xmLabelGadgetClass,e->form,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,XtParent(XtParent(e->filter_field)),
XmNleftAttachment,XmATTACH_FORM,
NULL);
XtSetArg(arg[0],XmNlistSizePolicy,XmRESIZE_IF_POSSIBLE);
e->dir_field=XmCreateScrolledList(e->form,"FSDirList",arg,1);
XtVaSetValues(XtParent(e->dir_field),
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,e->dirlabel,
XmNleftAttachment,XmATTACH_FORM,
XmNscrollBarDisplayPolicy,XmSTATIC,
NULL);
XtVaSetValues(e->dir_field,
XmNscrollBarDisplayPolicy,XmSTATIC,
XmNlistSizePolicy,XmRESIZE_IF_POSSIBLE,
NULL);
XtAddCallback(e->dir_field,XmNdefaultActionCallback,(XtCallbackProc)SelectDir,(void*)e);
XtManageChild(e->dir_field);
e->filelabel=XtVaCreateManagedWidget("FSFileLabel",xmLabelGadgetClass,e->form,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,XtParent(XtParent(e->filter_field)),
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,XtParent(e->dir_field),
XmNrightAttachment,XmATTACH_FORM,
NULL);
e->filefield=XmCreateScrolledList(e->form,"FSFileList",arg,1);
XtVaSetValues(XtParent(e->filefield),
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,e->filelabel,
XmNleftAttachment,XmATTACH_WIDGET,
XmNleftWidget,XtParent(e->dir_field),
XmNrightAttachment,XmATTACH_FORM,
XmNscrollBarDisplayPolicy,XmSTATIC,
XmNlistSizePolicy,XmRESIZE_IF_POSSIBLE,
NULL);
XtVaSetValues(e->filefield,
XmNscrollBarDisplayPolicy,XmSTATIC,
XmNlistSizePolicy,XmRESIZE_IF_POSSIBLE,
NULL);
XtAddCallback(e->filefield,XmNbrowseSelectionCallback,(XtCallbackProc)BrowseSelect,(void*)e);
XtAddCallback(e->filefield,XmNdefaultActionCallback,(XtCallbackProc)FSOKCallback,(void*)e);
XtManageChild(e->filefield);
e->fssize=XtVaCreateManagedWidget("FSSize",xmLabelGadgetClass,e->form,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,XtParent(e->dir_field),
XmNleftAttachment,XmATTACH_NONE,
XmNrightAttachment,XmATTACH_FORM,
NULL);
e->selection=XtVaCreateManagedWidget("FSSelection",xmLabelGadgetClass,e->form,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,XtParent(e->dir_field),
XmNleftAttachment,XmATTACH_FORM,
NULL);
n=0;
XtSetArg(arg[n],XmNtopAttachment,XmATTACH_WIDGET);n++;
XtSetArg(arg[n],XmNtopWidget,e->selection);n++;
XtSetArg(arg[n],XmNleftAttachment,XmATTACH_FORM);n++;
XtSetArg(arg[n],XmNrightAttachment,XmATTACH_FORM);n++;
e->sel_field=CreateComboBox(e->form,"FSSelectionField",arg,n,10);
InitializeComboBox(e->sel_field,combo3);
XtAddCallback(e->sel_field,XmNactivateCallback,(XtCallbackProc)FSOKCallback,(void*)e);
db_getcwd(path,255);
XtVaSetValues(e->filter_field,XmNvalue,"*",NULL);
XtVaSetValues(e->dirfilter_field,XmNvalue,path,NULL);
XtVaSetValues(e->sel_field,XmNvalue,path,NULL);
GetDirectory(e,path,"*");
}
else
FSFilterCallback(NULL,e,NULL); /* Refresh */
XtVaSetValues(XtParent(e->fs),XmNtitle,title,NULL);
xstr=XmStringCreateLocalized(title);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->fs,"*FSTitle"),XmNlabelString,xstr,NULL);
#endif
XmStringFree(xstr);
XtManageChild(e->fs);
WatchCursor(e,0);
EP;
}
jex-1.3.7/genres.c 100644 0 0 2114 6672726717 12040 0 ustar root root #include <stdio.h>
#include "jbdbg.h"
int main(int argc,char *argv[])
{
FILE *f1,*f2;
int ml=0;
char str[100];
if (argc!=3)
{
printf("Usage: genres header-file resource-file\n");
return 1;
}
if ((f1=db_fopen(argv[1],"r"))==NULL)
{
printf("Can't open file %s\n",argv[1]);
return 1;
}
if ((f2=db_fopen(argv[2],"w+"))==NULL)
{
printf("Can't create file %s\n",argv[2]);
return 1;
}
while (db_fgets(str,100,f1))
{
str[db_strlen(str)-1]=0;
if (db_strlen(str)>3 && str[0]=='"' && str[db_strlen(str)-1]==',' && str[db_strlen(str)-2]=='"')
{
str[db_strlen(str)-2]='\0';
fprintf(f2,"%s\n",&str[1]);
}
else if (db_strlen(str)>3 && str[db_strlen(str)-1]=='\\')
{
if (str[0]=='"')
fprintf(f2,"%s\n",&str[1]);
else
fprintf(f2,"%s\n",str);
ml=1;
}
else if (ml && db_strlen(str)>3 && str[db_strlen(str)-1]==',' && str[db_strlen(str)-2]=='"')
{
str[db_strlen(str)-2]='\0';
fprintf(f2,"%s\n",str);
ml=0;
}
}
db_fclose(f1);
db_fclose(f2);
return 0;
}
jex-1.3.7/gotoerr.c 100644 0 0 3534 6672726717 12245 0 ustar root root #include "jex.h"
#include <ctype.h>
#include <Xm/List.h>
int FindFileLine(char *str,Editor *e,char *file,int *l)
{
int x;
if (e->grepped)
return sscanf(str,"%[^:]:%d:",file,l);
for (x=0;x<e->ce_count;x++)
{
if (sscanf(str,e->compiler_error[x],file,l)==2)
return 2;
}
return 0;
}
void GotoError(Widget w,Editor *e,void *cbs)
{
char *str;
char file[255]/*,dir[255],name[255],name2[255]*/;
int line,x;
XmStringTable selected_items;
int num_selected,res;
SP("GotoError");
XtVaGetValues(e->io_win,XmNselectedItemCount,&num_selected,XmNselectedItems,&selected_items,NULL);
if (num_selected==0)
{
EP;
return;
}
WatchCursor(e,1);
XmStringGetLtoR(selected_items[0],XmSTRING_DEFAULT_CHARSET,&str);
res=FindFileLine(str,e,file,&line);
if (res==2)
{
/* SplitPath(file,dir,name2);*/
GetFullFileName(file);
for (x=0;x<editors;x++)
{
/* SplitPath(editor[x]->filename,dir,name);
if (db_strcmp(name,name2)==0)*/
if (db_strcmp(editor[x]->filename,file)==0)
{
XMapRaised(XtDisplay(editor[x]->shell),XtWindow(editor[x]->shell));
if (res==2)
{
sprintf(file,"%d",line);
XtVaSetValues(editor[x]->gotofield,XmNvalue,file,NULL);
GotoLine(NULL,editor[x],NULL);
}
XtFree(str);
WatchCursor(e,0);
EP;
return;
}
}
CreateNewEditor();
/* db_strcpy(editor[editors-1]->filename,file);
SetTitle(editor[editors-1],editor[editors-1]->filename);*/
if (loadfile(editor[editors-1],file,0,1))
LoadError(editor[editors-1]);
if (res==2)
{
sprintf(file,"%d",line);
XtVaSetValues(editor[editors-1]->gotofield,XmNvalue,file,NULL);
GotoLine(NULL,editor[editors-1],NULL);
}
XtFree(str);
WatchCursor(e,0);
EP;
return;
}
WatchCursor(e,0);
EP;
}
jex-1.3.7/grep.c 100644 0 0 10026 6672726717 11533 0 ustar root root #include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <ctype.h>
#include "match.h"
#include "jex.h"
#include "list.h"
int subdirs=0,case_sensitive=0,do_replace=0;
List f_list=NULL;
void strupr(char *str)
{
SP("strupr");
while (str && *str)
{
*str=toupper(*str);
str++;
}
EP;
}
void ReplaceString(char *str,char *srch,char *repl)
{
int x;
char tmpstr[255],tmppat[255];
SP("ReplaceString");
db_strcpy(tmpstr,str);
db_strcpy(tmppat,srch);
if (!case_sensitive)
{
strupr(tmpstr);
strupr(tmppat);
}
for (x=0;x<db_strlen(tmpstr);x++)
{
if ((x>db_strlen(tmpstr)-db_strlen(srch)) || ((db_strlen(tmpstr)+db_strlen(repl)-db_strlen(tmppat))>=255))
{
EP;
return;
}
if (db_memcmp(&tmpstr[x],tmppat,db_strlen(tmppat))==0)
{
if (x==0 || (x>0 && !isalpha(tmpstr[x-1]) && tmpstr[x-1]!='_'))
{
db_memmove(&str[x],&str[x+db_strlen(srch)],db_strlen(str)-x-db_strlen(srch)+1);
db_memmove(&str[x+db_strlen(repl)],&str[x],db_strlen(str)-x+1);
db_memcpy(&str[x],repl,db_strlen(repl));
db_memmove(&tmpstr[x],&tmpstr[x+db_strlen(tmppat)],db_strlen(tmpstr)-x-db_strlen(tmppat)+1);
db_memmove(&tmpstr[x+db_strlen(repl)],&tmpstr[x],db_strlen(tmpstr)-x+1);
db_memcpy(&tmpstr[x],repl,db_strlen(repl));
x+=db_strlen(repl);
}
}
}
EP;
}
void DoGrep(char *patrn,char *replace)
{
FILE *f,*f3=NULL;
int line=0,x,nl=1;
char str[255],str2[255],nw[255];
char path[255],direc[255],pattern[255],file[255],pat[255];
DIR *dp;
struct dirent *dir;
struct stat sbuf;
SP("DoGrep");
sprintf(pat,"*%s*",patrn);
if (!case_sensitive)
strupr(pat);
while (GetFirstElement(f_list,path))
{
DeleteFirstElement(f_list);
SplitPath(path,direc,pattern);
if ((dp=db_opendir(direc))==NULL)
{
fprintf(stderr,"Can't open directory %s\n",path);
continue;
}
while ((dir=db_readdir(dp))!=NULL)
{
if (dir->d_ino==0)
continue;
if (db_strcmp(direc,".")==0 || db_strcmp(direc,"./")==0)
sprintf(file,dir->d_name);
else
{
if (direc[db_strlen(direc)-1]!='/')
sprintf(file,"%s/%s",direc,dir->d_name);
else
sprintf(file,"%s%s",direc,dir->d_name);
}
if (db_stat(file,&sbuf)<0)
{
if (db_lstat(file,&sbuf)<0)
{
continue;
}
}
if ((sbuf.st_mode&S_IFMT)==S_IFDIR)
{
if (subdirs && db_strcmp(dir->d_name,".")!=0 && db_strcmp(dir->d_name,"..")!=0)
{
sprintf(path,"%s/%s",file,pattern);
AddFirstElement(f_list,path);
}
continue;
}
if (match(pattern,dir->d_name))
{
if ((f=db_fopen(file,"r"))==NULL)
{
printf("Can't open file %s\n",file);
continue;
}
if (do_replace)
{
sprintf(nw,"%s.tmp",file);
if ((f3=db_fopen(nw,"w+"))==NULL)
{
printf("Cannot open file %s\n",nw);
db_fclose(f);
return;
}
}
line=0;
while (db_fgets(str,254,f)!=NULL)
{
if (str[db_strlen(str)-1]=='\n')
{
line++;
str[db_strlen(str)-1]='\0';
nl=1;
}
else
nl=0;
db_strcpy(str2,str);
if (do_replace)
{
ReplaceString(str2,patrn,replace);
if (nl)
db_fprintf(f3,"%s\n",str2);
else
db_fprintf(f3,"%s",str2);
}
if (!case_sensitive)
strupr(str);
if (match(pat,str))
{
for (x=0;x<db_strlen(str2);x++)
{
if (str2[x]=='\t')
str2[x]=' ';
}
printf("%s:%d: %s\n",file,line,str2);
}
}
db_fclose(f);
if (do_replace)
db_fclose(f3);
db_rename(nw,file);
}
}
db_closedir(dp);
}
EP;
}
jex-1.3.7/grepd.c 100644 0 0 24633 6672726717 11710 0 ustar root root #include <Xm/MessageB.h>
#include <Xm/Form.h>
#include <Xm/LabelG.h>
#include <Xm/TextF.h>
#include <Xm/ToggleB.h>
#include <Xm/DrawnB.h>
#include <Xm/PushBG.h>
#include <Xm/List.h>
#include <signal.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
#include "list.h"
#include "jex.h"
extern List f_list;
extern int subdirs,grep_size,grep_file_size,case_sensitive,do_replace;
extern XtAppContext app;
extern Pixmap lov;
extern Widget combo4,combo5,combo6;
void GrepOK(Widget wdg,Editor *e,void *cbs)
{
char *what;
char *where;
char *repl="";
char str[255];
Boolean subdir,casesens,replace;
char *args[20];
int x,pid;
SP("GrepOK");
XtVaGetValues(e->gpat,XmNvalue,&what,NULL);
if (what[0]=='\0')
{
XtFree(what);
EP;
return;
}
UpdateComboBox(combo4,what);
for (x=0;x<editors;x++)
UpdateComboBox(editor[x]->gpat,what);
/* UpdateGrepList(what);*/
XtVaSetValues(e->compile,XmNsensitive,False,NULL);
XtVaSetValues(e->make,XmNsensitive,False,NULL);
XtVaSetValues(e->run,XmNsensitive,False,NULL);
XtVaSetValues(e->grep,XmNsensitive,False,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,False,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,False,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,False,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,False,NULL);
#endif
XtVaGetValues(e->gfiles,XmNvalue,&where,NULL);
if (where[0]=='\0')
{
XtFree(where);
where=(char*)XtMalloc(2);
db_strcpy(where,"*");
}
XtVaGetValues(XtNameToWidget(e->gd,"*GrepReplace"),XmNset,&replace,NULL);
if (replace)
{
do_replace=replace?1:0;
#ifndef LESSTIFF
XtVaGetValues(XtNameToWidget(e->gd,"*GrepReplaceField"),XmNvalue,&repl,NULL);
#endif
UpdateComboBox(combo6,repl);
for (x=0;x<editors;x++)
{
#ifndef LESSTIFF
if (XtNameToWidget(editor[x]->gd,"*GrepReplaceField"))
UpdateComboBox(XtNameToWidget(editor[x]->gd,"*GrepReplaceField"),repl);
#endif
}
}
UpdateComboBox(combo5,where);
for (x=0;x<editors;x++)
UpdateComboBox(editor[x]->gfiles,where);
/* UpdateGrepFileList(where);*/
XtVaGetValues(e->gsubd,XmNset,&subdir,NULL);
XtVaGetValues(e->casesens,XmNset,&casesens,NULL);
SplitUp(where,args);
e->t.pid=0;
CreateOutputWindow(e);
XtPopup(e->iod,XtGrabNone);
XMapRaised(XtDisplay(e->iod),XtWindow(e->iod));
XmListDeleteAllItems(e->io_win);
e->x=0;
SetLabel(e,"Grep");
if (db_pipe(e->t.fd)!=0)
{
SetLabel(e,"Too many open files!");
XtVaSetValues(e->compile,XmNsensitive,True,NULL);
XtVaSetValues(e->make,XmNsensitive,True,NULL);
XtVaSetValues(e->run,XmNsensitive,True,NULL);
XtVaSetValues(e->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
if (replace)
XtFree(repl);
EP;
return;
}
if (db_pipe(e->t.fd2)!=0)
{
SetLabel(e,"Too many open files!");
db_close(e->t.fd[0]);
db_close(e->t.fd[1]);
XtVaSetValues(e->compile,XmNsensitive,True,NULL);
XtVaSetValues(e->make,XmNsensitive,True,NULL);
XtVaSetValues(e->run,XmNsensitive,True,NULL);
XtVaSetValues(e->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
if (replace)
XtFree(repl);
EP;
return;
}
if (db_pipe(e->t.fd3)!=0)
{
SetLabel(e,"Too many open files!");
db_close(e->t.fd[0]);
db_close(e->t.fd[1]);
db_close(e->t.fd2[0]);
db_close(e->t.fd2[1]);
XtVaSetValues(e->compile,XmNsensitive,True,NULL);
XtVaSetValues(e->make,XmNsensitive,True,NULL);
XtVaSetValues(e->run,XmNsensitive,True,NULL);
XtVaSetValues(e->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
EP;
return;
}
e->tid=XtAppAddTimeOut(app,500,(XtTimerCallbackProc)SetWorkingLabel,(void*)e);
fcntl(e->t.fd[0],F_SETFL,O_NONBLOCK);
fcntl(e->t.fd2[0],F_SETFL,O_NONBLOCK);
e->t.id=XtAppAddInput(app,e->t.fd[0],(XtPointer)XtInputReadMask,(XtInputCallbackProc)InputCallback1,(XtPointer)e);
e->t.id2=XtAppAddInput(app,e->t.fd2[0],(XtPointer)XtInputReadMask,(XtInputCallbackProc)InputCallback2,(XtPointer)e);
db_strcpy(e->t.name,"Grep");
signal(SIGCHLD,ChildSignal);
if ((pid=fork())>=0)
{
if (pid>0)
{
e->t.pid=pid;
XtFree(what);
XtFree(where);
e->grepped=1;
}
if (pid==0)
{
db_postmortemdump=0;
signal(SIGQUIT,SIG_DFL);
signal(SIGILL,SIG_DFL);
signal(SIGTRAP,SIG_DFL);
signal(SIGIOT,SIG_DFL);
signal(SIGFPE,SIG_DFL);
signal(SIGKILL,SIG_DFL);
signal(SIGBUS,SIG_DFL);
signal(SIGSEGV,SIG_DFL);
signal(SIGTERM,SIG_DFL);
signal(SIGHUP,SIG_DFL);
signal(SIGSTOP,SIG_DFL);
signal(SIGINT,SIG_DFL);
signal(SIGIO,SIG_DFL);
signal(SIGPIPE,SIG_DFL);
signal(SIGUSR1,SIG_DFL);
signal(SIGUSR2,SIG_DFL);
signal(SIGPROF,SIG_DFL);
signal(SIGABRT,SIG_DFL);
db_setbuf(stdout,NULL);
db_dup2(e->t.fd[1],1);
db_dup2(e->t.fd2[1],2);
db_dup2(e->t.fd3[0],0);
subdirs=subdir;
case_sensitive=casesens;
f_list=CreateList(255);
x=0;
while (args[x])
{
db_strcpy(str,args[x]);
AddElement(f_list,str);
x++;
}
DoGrep(what,repl);
DisposeList(f_list);
exit(0);
}
}
else
{
SetLabel(e,"fork() failed!");
XtVaSetValues(e->compile,XmNsensitive,True,NULL);
XtVaSetValues(e->make,XmNsensitive,True,NULL);
XtVaSetValues(e->run,XmNsensitive,True,NULL);
XtVaSetValues(e->grep,XmNsensitive,True,NULL);
#ifndef LESSTIFF
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_0"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_1"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_2"),XmNsensitive,True,NULL);
XtVaSetValues(XtNameToWidget(e->mb,"*toolsmenu.button_3"),XmNsensitive,True,NULL);
#endif
EP;
return;
}
EP;}
void GrepCancel(Widget w,Editor *e,void *cbs)
{
SetCurrentWidget(e->text);
}
void ReplaceActive(Widget w,Widget f,XmToggleButtonCallbackStruct *cbs)
{
SP("ReplaceActive");
XtVaSetValues(f,XmNsensitive,(Boolean)cbs->set,NULL);
EP;
}
void Grep(Widget wdg,Editor *e,void *cbs)
{
Widget f,w1,w2,w3,w;
int n;
Arg arg[10];
SP("Grep");
WatchCursor(e,1);
if (e->gd==NULL)
{
e->gd=XmCreateMessageDialog(e->shell,"GrepDialog",NULL,0);
XtAddCallback(e->gd,XmNokCallback,(XtCallbackProc)GrepOK,(void*)e);
XtAddCallback(e->gd,XmNcancelCallback,(XtCallbackProc)GrepCancel,(void*)e);
XtAddCallback(e->gd,XmNhelpCallback,(XtCallbackProc)Help,"Grep");
f=XtVaCreateManagedWidget("GrepForm",xmFormWidgetClass,e->gd,
XmNfractionBase,3,NULL);
w1=XtVaCreateManagedWidget("GrepPatLabel",xmLabelGadgetClass,f,
XmNtopAttachment,XmATTACH_FORM,
XmNleftAttachment,XmATTACH_FORM,
XmNtopOffset,5,
XmNalignment,XmALIGNMENT_BEGINNING,
NULL);
n=0;
XtSetArg(arg[n],XmNtopAttachment,XmATTACH_FORM);n++;
XtSetArg(arg[n],XmNleftAttachment,XmATTACH_WIDGET);n++;
XtSetArg(arg[n],XmNleftWidget,w1);n++;
XtSetArg(arg[n],XmNrightAttachment,XmATTACH_FORM);n++;
e->gpat=CreateComboBox(f,"GrepPattern",arg,n,10);
InitializeComboBox(e->gpat,combo4);
w3=XtVaCreateManagedWidget("GrepFileLabel",xmLabelGadgetClass,f,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,XtParent(e->gpat),
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_OPPOSITE_WIDGET,
XmNrightWidget,w1,
XmNtopOffset,5,
XmNalignment,XmALIGNMENT_BEGINNING,
NULL);
n=0;
XtSetArg(arg[n],XmNtopAttachment,XmATTACH_WIDGET);n++;
XtSetArg(arg[n],XmNtopWidget,XtParent(e->gpat));n++;
XtSetArg(arg[n],XmNleftAttachment,XmATTACH_WIDGET);n++;
XtSetArg(arg[n],XmNleftWidget,w3);n++;
XtSetArg(arg[n],XmNrightAttachment,XmATTACH_FORM);n++;
e->gfiles=CreateComboBox(f,"GrepFiles",arg,n,10);
InitializeComboBox(e->gfiles,combo5);
w2=XtVaCreateManagedWidget("GrepReplace",xmToggleButtonWidgetClass,f,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,XtParent(e->gfiles),
XmNleftAttachment,XmATTACH_FORM,
NULL);
w3=XtVaCreateManagedWidget("GrepReplaceLabel",xmLabelGadgetClass,f,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,w2,
XmNleftAttachment,XmATTACH_FORM,
XmNrightAttachment,XmATTACH_OPPOSITE_WIDGET,
XmNrightWidget,w1,
XmNtopOffset,5,
XmNalignment,XmALIGNMENT_BEGINNING,
NULL);
n=0;
XtSetArg(arg[n],XmNtopAttachment,XmATTACH_WIDGET);n++;
XtSetArg(arg[n],XmNtopWidget,w2);n++;
XtSetArg(arg[n],XmNleftAttachment,XmATTACH_WIDGET);n++;
XtSetArg(arg[n],XmNleftWidget,w3);n++;
XtSetArg(arg[n],XmNrightAttachment,XmATTACH_FORM);n++;
w=CreateComboBox(f,"GrepReplaceField",arg,n,10);
InitializeComboBox(w,combo6);
XtAddCallback(w2,XmNvalueChangedCallback,(XtCallbackProc)ReplaceActive,(void*)w);
e->gsubd=XtVaCreateManagedWidget("GrepSubDirs",xmToggleButtonWidgetClass,f,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,XtParent(w),
XmNleftAttachment,XmATTACH_FORM,
NULL);
e->casesens=XtVaCreateManagedWidget("GrepCase",xmToggleButtonWidgetClass,f,
XmNtopAttachment,XmATTACH_WIDGET,
XmNtopWidget,e->gsubd,
XmNleftAttachment,XmATTACH_FORM,
NULL);
}
XtManageChild(e->gd);
WatchCursor(e,0);
EP;
}
jex-1.3.7/help.c 100644 0 0 24102 6672726717 11526 0 ustar root root #include <Xm/Xm.h>
#include <Xm/MessageB.h>
#include <Xm/Text.h>
#include <Xm/List.h>
#include <Xm/DialogS.h>
#include <Xm/Protocols.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "list.h"
#include "jex.h"
#include "help.h"
#include "helpstack.h"
extern Widget top;
List help_topics=NULL;
extern Pixmap pixmap;
Widget help_dialog=NULL,textw,tlist=NULL,tshell=NULL,ad=NULL;
HStack *hst=NULL;
char current_topic[40],helpfile[255];
List l=NULL;
extern XtAppContext app;
void SetZeroPos(Widget w,void *id)
{
SP("SetZeroPos");
XmTextSetInsertionPosition(w,0);
XmTextShowPosition(w,0);
EP;
}
/* Checks if the user has clicked on a link, if so, the current link is pushed
on the stack and the next topic is displayed.*/
void CheckLink(Widget w,List data,XmTextVerifyCallbackStruct *cbs)
{
int pos=cbs->newInsert;
HelpText ht;
HStackElem el;
SP("CheckLink");
if (GetFirstElement(data,&ht))
{
do
{
if (pos>=ht.start && pos<=ht.end)
{
XtRemoveCallback(w,XmNmotionVerifyCallback,(XtCallbackProc)CheckLink,data);
db_strncpy(el.data,current_topic,40);
Push(hst,el);
XtSetSensitive(XmMessageBoxGetChild(help_dialog,XmDIALOG_CANCEL_BUTTON),True);
DisplayTopic(w,ht.link,helpfile,data);
XtAppAddTimeOut(app,0,(XtTimerCallbackProc)SetZeroPos,w);
EP;
return;
}
} while (GetNextElement(data,&ht));
}
EP;
}
/* Display a new topic in the help window. The text is loaded from the file. */
void DisplayTopic(Widget w,char *topic,char *file,List l)
{
FILE *f;
HelpTopic htop;
HelpText ht,ht2;
char *str;
XmTextPosition position=0;
int found=0,first;
SP("DisplayTopic");
/* XmTextSetString(w,""); */
if ((f=db_fopen(file,"r"))==NULL)
{
/* XmTextSetString(w,"Cannot open help file!");*/
HelpError("Cannot open help file!");
XtAddCallback(w,XmNmotionVerifyCallback,(XtCallbackProc)CheckLink,l);
EP;
return;
}
if (GetFirstElement(help_topics,&htop))
{
do
{
if (db_strcmp(topic,htop.topic)==0)
{
found=1;
break;
}
} while (GetNextElement(help_topics,&htop));
if (!found)
{
/* XmTextSetString(w,"Topic not found!");*/
HelpError("Topic not found!");
XtAddCallback(w,XmNmotionVerifyCallback,(XtCallbackProc)CheckLink,l);
db_fclose(f);
EP;
return;
}
}
db_strncpy(current_topic,topic,40);
ClearList(l);
XmTextSetString(w,"");
if (GetFirstElement(htop.list,&ht))
{
first=ht.start;
do
{
db_fseek(f,ht.start,0);
str=(char *)db_malloc(ht.end-ht.start+1);
db_fread(str,ht.end-ht.start,1,f);
str[ht.end-ht.start]=0;
XmTextReplace(w,position,position+ht.end-ht.start,str);
ht2.start=position;
position+=ht.end-ht.start;
ht2.end=position;
db_strcpy(ht2.link,ht.link);
db_free(str);
if (ht.type==LINK_TEXT)
{
XmTextSetHighlight(w,ht2.start,ht2.end,XmHIGHLIGHT_SECONDARY_SELECTED);
AddElement(l,&ht2);
}
/* XmTextSetInsertionPosition(w,0);
XmTextShowPosition(w,0);*/
} while (GetNextElement(htop.list,&ht));
}
XmTextSetInsertionPosition(w,0);
XmTextShowPosition(w,0);
XtAddCallback(w,XmNmotionVerifyCallback,(XtCallbackProc)CheckLink,l);
db_fclose(f);
EP;
}
void help_ok(Widget w,List data,void *cbs)
{
SP("help_ok");
/* DisposeList(data);
l=NULL;
XtPopdown(XtParent(help_dialog));
help_dialog=NULL; */
XtUnmanageChild(help_dialog);
EP;
}
void help_cancel(Widget w,List data,void *cbs)
{
HStackElem el;
SP("help_cancel");
Pop(hst,&el);
XtRemoveCallback(textw,XmNmotionVerifyCallback,(XtCallbackProc)CheckLink,data);
if (StackSize(hst)==0)
XtSetSensitive(XmMessageBoxGetChild(help_dialog,XmDIALOG_CANCEL_BUTTON),False);
DisplayTopic(textw,el.data,helpfile,data);
EP;
}
void Help(Widget widget,char *c,void *d)
{
Arg arg[7];
XmTextScanType s_array[5];
/* Atom wm_delete;*/
SP("Help");
if (help_dialog==NULL)
{
hst=CreateHStack();
if ((help_topics=CompileHelp())==NULL)
{
HelpError("Can't find help file!");
EP;
return;
}
l=CreateList(sizeof(HelpText));
XtSetArg(arg[1],XmNdeleteResponse,XmDO_NOTHING);
XtSetArg(arg[0],XmNautoUnmanage,False);
help_dialog=XmCreateMessageDialog(top,"Help",arg,1);
XtAddCallback(help_dialog,XmNokCallback,help_ok,l);
XtAddCallback(help_dialog,XmNcancelCallback,help_cancel,l);
XtAddCallback(help_dialog,XmNhelpCallback,Index,NULL);
XtSetSensitive(XmMessageBoxGetChild(help_dialog,XmDIALOG_CANCEL_BUTTON),False);
if (help_topics==0)
XtSetSensitive(XmMessageBoxGetChild(help_dialog,XmDIALOG_HELP_BUTTON),False);
s_array[0]=XmSELECT_POSITION;
s_array[1]=XmSELECT_POSITION;
s_array[2]=XmSELECT_POSITION;
s_array[3]=XmSELECT_POSITION;
s_array[4]=XmSELECT_POSITION;
XtSetArg(arg[0],XmNeditable,False);
XtSetArg(arg[1],XmNeditMode,XmMULTI_LINE_EDIT);
XtSetArg(arg[2],XmNselectionArray,s_array);
XtSetArg(arg[3],XmNselectionArrayCount,5);
XtSetArg(arg[4],XmNcursorPositionVisible,False);
XtSetArg(arg[5],XmNwordWrap,True);
XtSetArg(arg[6],XmNscrollHorizontal,False);
textw=XmCreateScrolledText(help_dialog,"help_text",arg,7);
/* wm_delete=XmInternAtom(XtDisplay(help_dialog),"WM_DELETE_WINDOW",False);
XmAddWMProtocolCallback(XtParent(help_dialog),wm_delete,help_ok,NULL);*/
XtManageChild(textw);
XtManageChild(help_dialog);
}
else
{
HStackElem el;
db_strncpy(el.data,current_topic,40);
Push(hst,el);
XtSetSensitive(XmMessageBoxGetChild(help_dialog,XmDIALOG_CANCEL_BUTTON),True);
if (help_topics==0)
XtSetSensitive(XmMessageBoxGetChild(help_dialog,XmDIALOG_HELP_BUTTON),False);
XtRemoveCallback(textw,XmNmotionVerifyCallback,(XtCallbackProc)CheckLink,l);
XtManageChild(help_dialog);
}
DisplayTopic(textw,c,helpfile,l);
EP;
}
/* Callback for the index, when the user selects a topic. */
void list_select(Widget w,void *data,XmListCallbackStruct *cbs)
{
HelpTopic htop;
SP("list_select");
GetNthElement(help_topics,cbs->item_position-1,&htop);
Help(NULL,htop.topic,NULL);
XtPopdown(tshell);
EP;
}
void index_close(Widget w,void *d,void *cbs)
{
SP("index_close");
XtPopdown(tshell);
EP;
}
int SortProc(const void *n1,const void *n2)
{
int x;
SP("SortProc");
x=db_strcmp(((HelpTopic*)n1)->topic_text,((HelpTopic*)n2)->topic_text);
if (x<0)
{
EP;
return -1;
}
else if (x>0)
{
EP;
return 1;
}
EP;
return 0;
}
void Index(Widget w,void *data,void *cbs)
{
XmStringTable tops;
int x=0,n;
HelpTopic htop;
Atom wm_delete;
SP("Index");
if (tshell==NULL)
{
n=NumberElements(help_topics);
if (n==0)
{
EP;
return;
}
tops=(XmStringTable)XtMalloc(n*sizeof(XmString));
SortList(help_topics,SortProc);
if (GetFirstElement(help_topics,&htop))
{
do
{
tops[x++]=XmStringCreateLocalized(htop.topic_text);
} while (GetNextElement(help_topics,&htop));
}
tshell=XtVaCreatePopupShell("Topics",xmDialogShellWidgetClass,top,
XmNdeleteResponse,XmDO_NOTHING,
XmNallowShellResize,True,
NULL);
tlist=XmCreateScrolledList(tshell,"help_topics",NULL,0);
XtVaSetValues(tlist,XmNitems,tops,
XmNitemCount,n,
XmNdeleteResponse,XmDO_NOTHING,
XmNselectionPolicy,XmBROWSE_SELECT,
NULL);
XtAddCallback(tlist,XmNdefaultActionCallback,(XtCallbackProc)list_select,NULL);
wm_delete=XmInternAtom(XtDisplay(tshell),"WM_DELETE_WINDOW",False);
XmAddWMProtocolCallback(tshell,wm_delete,index_close,NULL);
XtManageChild(tlist);
XtManageChild(tshell);
}
else
XtPopup(tshell,XtGrabNone);
EP;
}
int FindHelpFile(char *helpfile,char *file)
{
char *env,*pos,*orig;
FILE *f;
SP("FindHelp");
if (!getenv("PATH"))
{
EP;
return 0;
}
orig=env=db_strdup(getenv("PATH"));
pos=db_strchr(env,':');
while (pos)
{
*pos=0;
sprintf(file,"%s/%s",env,helpfile);
if ((f=fopen(file,"r"))!=NULL)
{
fclose(f);
db_free(orig);
EP;
return 1;
}
env=pos+1;
pos=db_strchr(env,':');
}
sprintf(file,"%s/%s",env,helpfile);
if ((f=fopen(file,"r"))!=NULL)
{
fclose(f);
db_free(orig);
EP;
return 1;
}
db_free(orig);
EP;
return 0;
}
List CompileHelp(void)
{
FILE *f;
char ch,str[100];
int start,end,eof=0;
HelpText ht;
HelpTopic htop;
List l;
SP("CompileHelp");
if (!FindHelpFile("jex.hlp",helpfile))
{
EP;
return NULL;
}
if ((f=db_fopen(helpfile,"r"))==NULL)
{
EP;
return NULL;
}
l=CreateList(sizeof(HelpTopic));
while (!db_feof(f))
{
start=db_ftell(f);
fscanf(f,"%s",str);
if (db_strcmp(str,".topic")==0)
{
htop.list=CreateList(sizeof(HelpText));
fscanf(f,"%s",htop.topic);
ht.start=start=db_ftell(f)+1;
while ('\n'!=db_fgetc(f));
while ((ch=db_fgetc(f))==' ' || ch=='\t' || ch=='\n');
db_ungetc(ch,f);
db_fgets(htop.topic_text,100,f);
htop.topic_text[strlen(htop.topic_text)-1]=0;
AddElement(l,&htop);
for (;;)
{
ch=db_fgetc(f);
if (db_feof(f))
{
end=db_ftell(f);
eof=1;
break;
}
if (ch=='.')
{
end=db_ftell(f)-1;
fscanf(f,"%s",str);
db_fseek(f,end,0);
if (db_strcmp(str,"topic")==0)
break;
else
db_fseek(f,end+1,0);
}
else if (ch=='{')
{
end=db_ftell(f)-1;
ht.end=end;
ht.type=NORMAL_TEXT;
AddElement(htop.list,&ht);
ht.start=end+1;
ht.type=LINK_TEXT;
do
{
ch=db_fgetc(f);
} while (ch!=':' && ch!='}');
ht.end=db_ftell(f)-1;
if (ch=='}')
db_fseek(f,end+1,0);
end=0;
do
{
ch=db_fgetc(f);
if (ch!=' ' && ch!='}')
ht.link[end++]=ch;
} while (ch!='}');
ht.link[end]=0;
AddElement(htop.list,&ht);
ht.start=start=db_ftell(f);
}
else if (ch=='\\')
{
ht.end=db_ftell(f)-1;
ht.type=NORMAL_TEXT;
AddElement(htop.list,&ht);
db_fgetc(f);
ht.start=db_ftell(f)-1;
}
}
ht.type=NORMAL_TEXT;
ht.end=end;
AddElement(htop.list,&ht);
if (eof)
break;
}
else
{
db_fclose(f);
EP;
return NULL;
}
}
db_fclose(f);
EP;
return l;
}
jex-1.3.7/helpstack.c 100644 0 0 3304 6672726717 12535 0 ustar root root #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "helpstack.h"
#include "jex.h"
HStack *CreateHStack(void)
{
HStack *hst;
SP("CreateHStack");
if ((hst=(HStack*)db_malloc(sizeof(HStack)))==NULL)
{
EP;
return NULL;
}
hst->nelems=0;
hst->last=NULL;
EP;
return hst;
}
void DestroyHStack(HStack *hst)
{
HStackElement *ptr;
SP("DestroyHStack");
if (!hst)
{
EP;
return;
}
ptr=hst->last;
while (hst->last && ptr->prev)
{
hst->last=ptr->prev;
db_free(ptr);
ptr=hst->last;
}
if (hst->last)
db_free(hst->last);
db_free(hst);
EP;
}
void StackClear(HStack *hst)
{
HStackElement *ptr;
SP("StackClear");
if (!hst)
{
EP;
return;
}
ptr=hst->last;
while (hst->last && ptr->prev)
{
hst->last=ptr->prev;
db_free(ptr);
ptr=hst->last;
}
if (hst->last)
db_free(hst->last);
hst->last=NULL;
hst->nelems=0;
EP;
}
int Push(HStack *hst,HStackElem data)
{
HStackElement *ptr;
SP("Push");
if (!hst)
{
EP;
return 0;
}
if ((ptr=(HStackElement *)db_malloc(sizeof(HStackElement)))==NULL)
{
EP;
return -1;
}
db_memcpy(&ptr->s,&data,sizeof(HStackElem));
ptr->prev=hst->last;
hst->last=ptr;
hst->nelems++;
EP;
return hst->nelems-1;
}
int Pop(HStack *hst,HStackElem *data)
{
HStackElement *ptr;
SP("Pop");
if (!hst || !data)
{
EP;
return 0;
}
if (hst->nelems==0)
{
EP;
return 0;
}
db_memcpy(data,&hst->last->s,sizeof(HStackElem));
ptr=hst->last;
hst->last=hst->last->prev;
db_free(ptr);
hst->nelems--;
EP;
return hst->nelems;
}
int StackSize(HStack *hst)
{
SP("StackSize");
if (!hst)
{
EP;
return 0;
}
EP;
return hst->nelems;
}
jex-1.3.7/history.c 100644 0 0 3665 6672726717 12272 0 ustar root root #include <Xm/PushB.h>
#include <Xm/Xm.h>
#include <Xm/RowColumn.h>
#include <Xm/PushBG.h>
#include "jex.h"
int fl_size=0;
char fl_files[FILELIST][255];
void LoadOldFile(Editor *e)
{
SP("LoadOldFile");
if (loadfile(e,e->choice,0,1))
LoadError(e);
EP;
}
void OpenOldFile(Widget w,Editor *e,void *cbs)
{
int x;
SP("OpenOldFile");
for (x=0;x<fl_size;x++)
{
if (e->filelist[x]==w)
{
if (e->new_window)
{
CreateNewEditor();
if (loadfile(editor[editors-1],fl_files[x],0,1))
LoadError(editor[editors-1]);
}
else
{
db_strcpy(e->choice,fl_files[x]);
if (e->saved)
LoadOldFile(e);
else
AskToSave(e,(void*)LoadOldFile);
}
break;
}
}
EP;
}
void UpdateFileList(char *file)
{
int x,end,exists=0,e;
XmString xstr;
SP("UpdateFileList");
end=fl_size;
if (file && file[0])
{
for (x=0;x<fl_size;x++)
{
if (db_strcmp(fl_files[x],file)==0)
{
end=x+1;
exists=1;
break;
}
}
if (fl_size<FILELIST && !exists)
{
for (x=0;x<editors;x++)
{
editor[x]->filelist[fl_size]=XtVaCreateManagedWidget("filebutton",
xmPushButtonGadgetClass,editor[x]->filemenu,NULL);
XtAddCallback(editor[x]->filelist[fl_size],XmNactivateCallback,(XtCallbackProc)OpenOldFile,(void*)editor[x]);
}
fl_size++;
end=fl_size;
}
for (x=end-2;x>=0;x--)
db_strcpy(fl_files[x+1],fl_files[x]);
db_strcpy(fl_files[0],file);
}
for (x=0;x<end;x++)
{
xstr=XmStringCreateLocalized(fl_files[x]);
for (e=0;e<editors;e++)
{
XtVaSetValues(editor[e]->filelist[x],XmNlabelString,xstr,NULL);
}
XmStringFree(xstr);
}
EP;
}
void Reload(Editor *e)
{
SP("Reload");
if (e->filename[0])
{
db_strcpy(e->choice,e->filename);
if (e->saved)
LoadOldFile(e);
else
AskToSave(e,(void*)LoadOldFile);
}
EP;
}
jex-1.3.7/jex.c 100644 0 0 100317 6672727056 11404 0 ustar root root #include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/PushBG.h>
#include <Xm/PushB.h>
#include <Xm/DrawnB.h>
#include <Xm/ArrowBG.h>
#include <Xm/LabelG.h>
#include <Xm/ArrowB.h>
#include <Xm/Protocols.h>
#include <X11/Shell.h>
#include <sys/types.h>
#include <sys/time.h>
#include "fallbacks.h"
#include "jex.h"
#include "xpm.h"
#include "jex.xpm"
#include "lov.xbm"
#include "new.xpm"
#include "open.xpm"
#include "save.xpm"
#include "save2.xpm"
#include "clear.xpm"
#include "clone.xpm"
#include "compile.xpm"
#include "copy.xpm"
#include "cut.xpm"
#include "grep.xpm"
#include "left.xpm"
#include "make.xpm"
#include "newwind.xpm"
#include "paste.xpm"
#include "redo.xpm"
#include "right.xpm"
#include "undo.xpm"
#include "undo2.xpm"
#include "redo2.xpm"
#include "compile2.xpm"
#include "make2.xpm"
#include "grep2.xpm"
#include "up.xpm"
#include "down.xpm"
#include "setmarker.xpm"
#include "gotomarker.xpm"
#include "gotomarker2.xpm"
#include "caps.xpm"
#include "lows.xpm"
#include "down2.xpm"
#include "run.xpm"
#include "run2.xpm"
#include "gotoline.xpm"
#ifndef MAX
#define MAX(x,y) (((x)>(y))?(x):(y))
#endif
Widget top,combo1,combo2,combo3,combo4,combo5,combo6;
XtAppContext app;
int editors=0;
Editor *editor[MAXEDITORS];
Pixmap pixmap,lov,_new,_open,_save,_save2,_clear,_clone,_compile,_copy,_cut;
Pixmap _grep,_left,_make,_newwind,_paste,_redo,_right,_undo,_undo2,_redo2;
Pixmap _compile2,_make2,_grep2,_up,_down,_lows,_caps,_setmarker,_gotomarker;
Pixmap _gotomarker2,_down2,_run,_run2,_gotoline;
extern int fl_size,find_size,repl_size;
OwnRes ownres;
XtResource resources[]={
{"history_in_home_dir","History_In_Home_Dir",XtRBoolean,sizeof(Boolean),XtOffsetOf(OwnRes,histhome),XtRString,"False"},
{"settings_in_home_dir","Settings_In_Home_Dir",XtRBoolean,sizeof(Boolean),XtOffsetOf(OwnRes,setthome),XtRString,"False"}
};
void WriteTime(Editor *e,XtIntervalId id)
{
char timebuffer[100];
time_t t;
XmString xstr;
struct tm *lt;
SP("WriteTime");
time(&t);
strftime(timebuffer, 100, "%d/%m/%Y %H:%M",
localtime(&t));
xstr=XmStringCreateLocalized(timebuffer);