00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define _XMENU_FILE_SOURCE_
00025
00026 #include <stdio.h>
00027 #include <errno.h>
00028 #include <stdlib.h>
00029 #include <unistd.h>
00030
00031 #include "setup.h"
00032
00033 #include "constant.h"
00034 #include "commline.h"
00035 #include "router.h"
00036 #include "symbol.h"
00037 #include "scanner.h"
00038
00039 #include "xsetup.h"
00040 #include "xclips.h"
00041 #include "xclipstext.h"
00042 #include "xmenu.h"
00043 #include "xmain.h"
00044 #include "xmenu_file.h"
00045 #include "xmenu_wind.h"
00046
00047 #include <string.h>
00048 #include <sys/types.h>
00049 #include <sys/stat.h>
00050 #include <sys/dir.h>
00051 #include <sys/param.h>
00052
00053 #ifndef MAX
00054 #define MAX(x, y) ((x) > (y) ? (x) : (y))
00055 #endif
00056
00057
00058
00059 static char * GetBufferFromTextEdit(Widget);
00060 static void printMatch(Widget,XtPointer,XtPointer);
00061 static void printMatchForTextEdit(Widget,XtPointer,XtPointer);
00062 static void ClipsSave(void);
00063 static char **GetDirectory(void);
00064 static void FileToDialog(Widget,XtPointer,XtPointer);
00065 static void GetFileForCLIPS(char *);
00066
00067
00068 Widget file_dribble;
00069 Widget TheFile, file_list;
00070 int file_item = -1;
00071 char path[255];
00072 char **filenames = NULL;
00073 char *completionString = NULL;
00074 int number_entries;
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 void EditCallback(
00086 Widget w,
00087 XtPointer client_data,
00088 XtPointer call_data)
00089 {
00090 file_item = EDIT;
00091 (void)FileSelect();
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 void CompletionDialogCallback(
00103 Widget w,
00104 XtPointer client_data,
00105 XtPointer call_data)
00106 {
00107 void *theEnv = GetCurrentEnvironment();
00108 unsigned int NumberOfMatches;
00109 int length;
00110 struct symbolMatch *matches;
00111 char *commandString;
00112
00113
00114
00115
00116
00117
00118 if(completionString != NULL)
00119 {
00120 free(completionString);
00121 completionString = NULL;
00122 }
00123
00124
00125
00126
00127
00128
00129 commandString = GetCommandString(GetCurrentEnvironment());
00130 if(commandString != NULL)
00131 {
00132 length = strlen(commandString);
00133 commandString = GetCommandCompletionString(GetCurrentEnvironment(),commandString,length);
00134 }
00135 if(commandString == NULL)
00136 {
00137 XBell(XtDisplay(toplevel),100);
00138 return;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148 completionString = (char*)malloc(strlen(commandString) + 1);
00149 strcpy(completionString,commandString);
00150
00151
00152
00153
00154
00155
00156
00157 matches = FindSymbolMatches(GetCurrentEnvironment(),completionString,&NumberOfMatches,NULL);
00158 if(NumberOfMatches == 0)
00159 {
00160 XBell(XtDisplay(toplevel),100);
00161 return;
00162 }
00163 else if (NumberOfMatches == 1)
00164 {
00165 length = strlen(completionString);
00166 AppendCommandString(GetCurrentEnvironment(),&(matches->match->contents[length]));
00167 EnvPrintRouter(theEnv,"stdin",&(matches->match->contents[length]));
00168 }
00169 else
00170 {
00171 DisplayMatchedList(dialog_text,matches);
00172 }
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 void CompletionEditCallback(
00185 Widget w,
00186 XtPointer client_data,
00187 XtPointer call_data)
00188 {
00189 unsigned int NumberOfMatches;
00190 int length;
00191 struct symbolMatch *matches;
00192 XawTextBlock text;
00193 char *matchString = NULL;
00194 Widget source = XawTextGetSource((Widget)client_data);
00195 XawTextPosition CurrentPosition,EndPosition;
00196
00197
00198
00199
00200
00201
00202 if(completionString != NULL)
00203 {
00204 free(completionString);
00205 completionString = NULL;
00206 }
00207
00208
00209
00210
00211
00212
00213
00214 XawTextGetSelectionPos((Widget)client_data,&CurrentPosition,&EndPosition);
00215 if(CurrentPosition == EndPosition)
00216 {
00217 matchString = GetBufferFromTextEdit((Widget)client_data);
00218 length = strlen(matchString);
00219 }
00220 else
00221 {
00222 XawTextSourceRead(source,CurrentPosition,&text,EndPosition - CurrentPosition);
00223 XawTextUnsetSelection((Widget)client_data);
00224 XawTextSetInsertionPoint((Widget)client_data,EndPosition);
00225 matchString = text.ptr;
00226 length = text.length;
00227 }
00228
00229
00230
00231
00232
00233 matchString = GetCommandCompletionString(GetCurrentEnvironment(),matchString,length);
00234 if(matchString == NULL)
00235 {
00236 XBell(XtDisplay(toplevel),100);
00237 return;
00238 }
00239 completionString = (char*)malloc(strlen(matchString) + 1);
00240 strcpy(completionString,matchString);
00241 matches = FindSymbolMatches(GetCurrentEnvironment(),completionString,&NumberOfMatches,NULL);
00242 if(NumberOfMatches == 0)
00243 {
00244 XBell(XtDisplay(toplevel),100);
00245 return;
00246 }
00247 else if (NumberOfMatches == 1)
00248 {
00249 length = strlen(completionString);
00250 text.firstPos = 0;
00251 text.length = strlen(&(matches->match->contents[length]));
00252 text.ptr = &(matches->match->contents[length]);
00253 XawTextReplace((Widget)client_data,
00254 XawTextGetInsertionPoint((Widget)client_data),
00255 XawTextGetInsertionPoint((Widget)client_data),&text);
00256 XawTextSetInsertionPoint((Widget)client_data,
00257 XawTextGetInsertionPoint((Widget)client_data) + text.length);
00258
00259 }
00260 else
00261 {
00262 DisplayMatchedList((Widget)client_data,matches);
00263 }
00264 }
00265
00266
00267
00268
00269
00270 static char * GetBufferFromTextEdit(
00271 Widget w)
00272 {
00273 XawTextBlock text_return;
00274 char *buffer;
00275
00276 Widget source = XawTextGetSource(w);
00277 XawTextPosition NewPos,EndPos = XawTextGetInsertionPoint(w);
00278
00279
00280
00281
00282
00283
00284
00285
00286 if(EndPos == 0)
00287 return("");
00288 NewPos = EndPos - 1;
00289 XawTextSourceRead(source,NewPos,&text_return,1);
00290 while((text_return.ptr[0] != ' ') && (NewPos != 0))
00291 {
00292 NewPos--;
00293 XawTextSourceRead(source,NewPos,&text_return,1);
00294 }
00295 if(NewPos != 0)
00296 NewPos++;
00297 XawTextSourceRead(source,NewPos,&text_return,EndPos - NewPos);
00298 buffer = (char *)malloc(text_return.length + 1);
00299 strncpy(buffer,text_return.ptr,text_return.length);
00300 buffer[text_return.length] = 0;
00301 return(buffer);
00302 }
00303
00304
00305
00306
00307
00308
00309 int DisplayMatchedList(
00310 Widget w,
00311 struct symbolMatch *matches)
00312 {
00313 Widget matchShell,matchForm,matchViewport,
00314 matchDialog,matchList;
00315 int n;
00316
00317 if(GetMatchList(matches) == 0)
00318 return(0);
00319 matchShell = XtCreatePopupShell("Matches",
00320 topLevelShellWidgetClass,
00321 toplevel,
00322 NULL, 0);
00323 matchForm = XtCreateManagedWidget( "manager_form", formWidgetClass,
00324 matchShell, NULL,0);
00325
00326 XtSetArg(TheArgs[0],XtNallowHoriz, True);
00327
00328 XtSetArg(TheArgs[1],XtNallowVert, True);
00329
00330 matchViewport = XtCreateManagedWidget("manager_viewport",viewportWidgetClass,
00331 matchForm,NULL,0);
00332
00333 n = 0;
00334 XtSetArg(TheArgs[n],XtNlist,item_list);n++;
00335 matchList = XtCreateManagedWidget("manager_list",
00336 listWidgetClass,
00337 matchViewport,
00338 TheArgs,n);
00339 n = 0;
00340 XtSetArg(TheArgs[n], XtNresizable, True);n++;
00341 XtSetArg(TheArgs[n],XtNlabel,"");n++;
00342 XtSetArg(TheArgs[n], XtNvalue, "");n++;
00343 XtSetArg(TheArgs[n], XtNfromVert, matchViewport);n++;
00344 XtSetArg(TheArgs[n], XtNicon, clips_logo);n++;
00345 XtSetArg(TheArgs[n], XtNleft, XtChainLeft);n++;
00346 XtSetArg(TheArgs[n], XtNright, XtChainRight);n++;
00347 XtSetArg(TheArgs[n], XtNtop, XtChainBottom);n++;
00348 XtSetArg(TheArgs[n], XtNbottom, XtChainBottom);n++;
00349
00350
00351
00352
00353
00354
00355
00356
00357 if(w == dialog_text)
00358 {
00359 matchDialog = XtCreateManagedWidget("match_dialog",
00360 dialogWidgetClass,
00361 matchForm,
00362 TheArgs, n);
00363 XawDialogAddButton(matchDialog, "SELECT",printMatch, (XtPointer)completionString);
00364 }
00365 else
00366 {
00367 matchDialog = XtCreateManagedWidget("match_editor",
00368 dialogWidgetClass,
00369 matchForm,
00370 TheArgs, n);
00371 XawDialogAddButton(matchDialog, "SELECT",printMatchForTextEdit,(XtPointer)w);
00372 }
00373 XawDialogAddButton(matchDialog, "CANCEL", CancelPopupSelect,
00374 (XtPointer) matchForm);
00375 XtAddCallback(matchList, XtNcallback, FileToDialog, (XtPointer) matchDialog);
00376 XtPopup(matchShell,XtGrabNonexclusive);
00377
00378 return 0;
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 void MatchDialogReturnD(
00391 Widget w,
00392 XEvent *event,
00393 String *params,
00394 Cardinal *num_params)
00395 {
00396 printMatch(w,(XtPointer)completionString,NULL);
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 void MatchDialogReturnE(
00412 Widget w,
00413 XEvent *event,
00414 String *params,
00415 Cardinal *num_params)
00416 {
00417
00418 }
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 static void printMatch(
00429 Widget w,
00430 XtPointer client_data,
00431 XtPointer call_data)
00432 {
00433 void *theEnv = GetCurrentEnvironment();
00434 String aString = XawDialogGetValueString(XtParent(w));
00435 int length = strlen((char*)client_data);
00436
00437 AppendCommandString(theEnv,&(aString[length]));
00438 EnvPrintRouter(theEnv,"stdin",&(aString[length]));
00439 XtDestroyWidget(XtParent(XtParent(XtParent(w))));
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450 static void printMatchForTextEdit(
00451 Widget w,
00452 XtPointer client_data,
00453 XtPointer call_data)
00454 {
00455 XawTextBlock text;
00456 String aString = XawDialogGetValueString(XtParent(w));
00457 Widget text_widget = (Widget)client_data;
00458 int length;
00459
00460 length = strlen(completionString);
00461 text.firstPos = 0;
00462 text.length = strlen(&(aString[length]));
00463 text.ptr = &(aString[length]);
00464 XawTextReplace(text_widget,
00465 XawTextGetInsertionPoint(text_widget),
00466 XawTextGetInsertionPoint(text_widget),&text);
00467 XawTextSetInsertionPoint(text_widget,
00468 XawTextGetInsertionPoint(text_widget) + text.length);
00469 XtDestroyWidget(XtParent(XtParent(XtParent(w))));
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479 int GetMatchList(
00480 struct symbolMatch *matches)
00481 {
00482 int maxItems = 20,itemCount;
00483 if(matches == NULL)
00484 return(0);
00485 if(item_list != NULL)
00486 {
00487 free(item_list);
00488 item_list = NULL;
00489 }
00490 item_list = (String *)calloc(maxItems,sizeof(String));
00491 for(itemCount = 0;matches != NULL;matches = matches->next)
00492 {
00493 item_list[itemCount] = balloc(strlen(matches->match->contents) + 1,char);
00494 strcpy(item_list[itemCount], matches->match->contents);
00495 itemCount++;
00496 if(itemCount == (maxItems -1))
00497 {
00498 maxItems = 2*maxItems;
00499 item_list = (String *)realloc(item_list,maxItems * sizeof(String));
00500 }
00501 }
00502 item_list[itemCount] = NULL;
00503 sortList(item_list,itemCount);
00504 return(itemCount);
00505 }
00506
00507
00508
00509
00510
00511 void sortList(
00512 String *list,
00513 int num)
00514 {
00515 int i,j,theIndex;
00516 char *tempString;
00517
00518 if(num == 1)
00519 return;
00520 for(i = 0;i < num;i++)
00521 {
00522 tempString = list[i];
00523 theIndex = i;
00524 for(j = i + 1;j < num; j++)
00525 {
00526 if(strcmp(tempString,list[j]) > 0)
00527 {
00528 tempString = list[j];
00529 theIndex = j;
00530 }
00531 }
00532 if(i != theIndex)
00533 {
00534 list[theIndex] = list[i];
00535 list[i] = tempString;
00536 }
00537 }
00538 }
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 void LoadBatchCallback(
00549 Widget w,
00550 XtPointer client_data,
00551 XtPointer call_data)
00552 {
00553 file_item = LOADBATCH;
00554 (void)FileSelect();
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565 void LoadBinaryCallback(
00566 Widget w,
00567 XtPointer client_data,
00568 XtPointer call_data)
00569 {
00570 file_item = LOADBINARY;
00571 (void)FileSelect();
00572 }
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 void LoadFactsCallback(
00583 Widget w,
00584 XtPointer client_data,
00585 XtPointer call_data)
00586 {
00587 file_item = LOADFACTS;
00588 (void)FileSelect();
00589 }
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599 void LoadRulesCallback(
00600 Widget w,
00601 XtPointer client_data,
00602 XtPointer call_data)
00603 {
00604 file_item = LOADRULES;
00605 (void)FileSelect();
00606
00607 }
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 void DribbleCallback(
00618 Widget w,
00619 XtPointer client_data,
00620 XtPointer call_data)
00621 {
00622 void *theEnv = GetCurrentEnvironment();
00623 MoveEndOfFile(dialog_text, &TheEvent);
00624 file_item = DRIBBLEON;
00625 if (Dribble_status)
00626 {
00627 XtSetArg(TheArgs[0], XtNleftBitmap, None);
00628 XtSetValues(file_dribble, TheArgs, 1);
00629 SetCommandString(theEnv,"(dribble-off)\n");
00630 if(!CommandLineData(theEnv)->EvaluatingTopLevelCommand)
00631 EnvPrintRouter(theEnv,"wclips","(dribble-off)\n");
00632 quit_get_event = True;
00633 Dribble_status = !Dribble_status;
00634 }
00635 else
00636 FileSelect();
00637 }
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647 void SaveBinaryCallback(
00648 Widget w,
00649 XtPointer client_data,
00650 XtPointer call_data)
00651 {
00652 file_item = SAVEBINARY;
00653 ClipsSave();
00654 }
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664 void SaveFactsCallback(
00665 Widget w,
00666 XtPointer client_data,
00667 XtPointer call_data)
00668 {
00669
00670 file_item = SAVEFACTS;
00671 ClipsSave();
00672 }
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682 void SaveRulesCallback(
00683 Widget w,
00684 XtPointer client_data,
00685 XtPointer call_data)
00686 {
00687
00688 file_item = SAVERULES;
00689 ClipsSave();
00690 }
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 void QuitCallback(
00701 Widget w,
00702 XtPointer client_data,
00703 XtPointer call_data)
00704 {
00705 Widget confirmshell, confirm;
00706
00707 confirmshell = XtCreatePopupShell("Confirmation",
00708 topLevelShellWidgetClass,
00709 toplevel,
00710 NULL, 0);
00711
00712 XtSetArg(TheArgs[0], XtNlabel, "Quit XCLIPS.\nAre you sure?");
00713 XtSetArg(TheArgs[1], XtNicon, clips_logo);
00714 confirm = XtCreateManagedWidget("confirm",
00715 dialogWidgetClass,
00716 confirmshell,
00717 TheArgs, 2);
00718
00719 XawDialogAddButton(confirm, "Quit", Quit, (XtPointer) confirm);
00720 XawDialogAddButton(confirm, "Restart", Restart, (XtPointer) confirm);
00721 XawDialogAddButton(confirm, "Cancel", CancelPopupSelect, (XtPointer) confirm);
00722
00723 XtPopup(confirmshell, XtGrabNonexclusive);
00724 }
00725
00726
00727
00728
00729
00730
00731
00732
00733 static void ClipsSave()
00734 {
00735 Widget popup, file_dialog;
00736
00737 popup = XtCreatePopupShell("File",
00738 topLevelShellWidgetClass,
00739 toplevel,
00740 NULL, 0);
00741
00742 XtSetArg(TheArgs[0], XtNlabel, "Enter file name:");
00743 XtSetArg(TheArgs[1], XtNvalue, "");
00744 XtSetArg(TheArgs[2], XtNicon, clips_logo);
00745 file_dialog = XtCreateManagedWidget("file_dialog",
00746 dialogWidgetClass,
00747 popup,
00748 TheArgs, 3);
00749 XawDialogAddButton(file_dialog, "Save", IntSave, (XtPointer)NULL);
00750 XawDialogAddButton(file_dialog, "Cancel", CancelPopupSelect,
00751 (XtPointer)file_dialog);
00752
00753 XtPopup(popup, XtGrabNonexclusive);
00754 }
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764 void IntSave(
00765 Widget w,
00766 XtPointer client_data,
00767 XtPointer call_data)
00768 {
00769 void *theEnv = GetCurrentEnvironment();
00770 char *filename = XawDialogGetValueString(XtParent(w));
00771
00772 switch(file_item)
00773 {
00774 case SAVEBINARY:
00775 EnvPrintRouter(theEnv,"wclips", "(bsave ");
00776 SetCommandString(theEnv,"(bsave");
00777 AppendCommandString(theEnv,"\"");
00778 EnvPrintRouter(theEnv,"wclips", "\"");
00779 AppendCommandString(theEnv,filename);
00780 EnvPrintRouter(theEnv,"wclips", filename);
00781 AppendCommandString(theEnv,"\"");
00782 EnvPrintRouter(theEnv,"wclips", "\"");
00783 AppendCommandString(theEnv,")\n");
00784 EnvPrintRouter(theEnv,"wclips", ")\n");
00785 quit_get_event = True;
00786 break;
00787
00788 case SAVEFACTS:
00789 EnvPrintRouter(theEnv,"wclips", "(save-facts ");
00790 SetCommandString(theEnv,"(save-facts");
00791 AppendCommandString(theEnv,"\"");
00792 EnvPrintRouter(theEnv,"wclips", "\"");
00793 AppendCommandString(theEnv,filename);
00794 EnvPrintRouter(theEnv,"wclips", filename);
00795 AppendCommandString(theEnv,"\"");
00796 EnvPrintRouter(theEnv,"wclips", "\"");
00797 AppendCommandString(theEnv,")\n");
00798 EnvPrintRouter(theEnv,"wclips", ")\n");
00799 quit_get_event = True;
00800 break;
00801
00802 case SAVERULES:
00803 EnvPrintRouter(theEnv,"wclips", "(save ");
00804 SetCommandString(theEnv,"(save");
00805 AppendCommandString(theEnv,"\"");
00806 EnvPrintRouter(theEnv,"wclips", "\"");
00807 AppendCommandString(theEnv,filename);
00808 EnvPrintRouter(theEnv,"wclips", filename);
00809 AppendCommandString(theEnv,"\"");
00810 EnvPrintRouter(theEnv,"wclips", "\"");
00811 AppendCommandString(theEnv,")\n");
00812 EnvPrintRouter(theEnv,"wclips", ")\n");
00813 quit_get_event = True;
00814 break;
00815 }
00816
00817 XtDestroyWidget(XtParent(XtParent(w)));
00818 }
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830 void FileSelect()
00831 {
00832 Widget file_form, file_dialog, view;
00833
00834
00835 TheFile = XtCreatePopupShell("File",
00836 topLevelShellWidgetClass,
00837 toplevel,
00838 NULL, 0);
00839
00840 file_form = XtCreateManagedWidget("file_form",
00841 formWidgetClass,
00842 TheFile,
00843 NULL, 0);
00844
00845 XtSetArg(TheArgs[0], XtNforceBars, True);
00846 XtSetArg(TheArgs[1], XtNbottom, XtChainBottom);
00847 XtSetArg(TheArgs[2], XtNheight,150);
00848 XtSetArg(TheArgs[3], XtNallowHoriz,True);
00849 XtSetArg(TheArgs[4],XtNallowVert,True);
00850 view = XtCreateManagedWidget("view",
00851 viewportWidgetClass,
00852 file_form,
00853 TheArgs, 5);
00854
00855
00856
00857
00858
00859
00860 XtSetArg(TheArgs[0], XtNresizable, True);
00861 XtSetArg(TheArgs[1], XtNlabel, "Enter File Name");
00862 XtSetArg(TheArgs[2], XtNvalue, "");
00863 XtSetArg(TheArgs[3], XtNfromVert, view);
00864 XtSetArg(TheArgs[4], XtNicon, clips_logo);
00865 XtSetArg(TheArgs[5], XtNleft, XtChainLeft);
00866 XtSetArg(TheArgs[6], XtNright, XtChainRight);
00867 XtSetArg(TheArgs[7], XtNtop, XtChainBottom);
00868 XtSetArg(TheArgs[8], XtNbottom, XtChainBottom);
00869 file_dialog = XtCreateManagedWidget("file_dialog",
00870 dialogWidgetClass,
00871 file_form,
00872 TheArgs, 9);
00873 XawDialogAddButton(file_dialog, "SELECT", MenuFunc, (XtPointer) file_dialog);
00874 XawDialogAddButton(file_dialog, "CANCEL", CancelPopupSelect,
00875 (XtPointer) file_form);
00876
00877 XtSetArg(TheArgs[0], XtNfromHoriz, file_dialog);
00878 XtSetArg(TheArgs[1], XtNfromVert, view);
00879
00880
00881
00882
00883
00884 if(getwd(path) == NULL)
00885 printf("Error getting current working directory '%s'\n", path);
00886
00887 if(path[strlen(path) - 1] != '/')
00888 strcat(path, "/");
00889
00890
00891
00892
00893
00894 XtSetArg(TheArgs[0], XtNdefaultColumns, 4);
00895 XtSetArg(TheArgs[1], XtNlist, GetDirectory());
00896 XtSetArg(TheArgs[2], XtNforceColumns, False);
00897 XtSetArg(TheArgs[3], XtNverticalList, True);
00898 XtSetArg(TheArgs[4], XtNinternalWidth, 10);
00899 file_list = XtCreateManagedWidget("file_dialog",
00900 listWidgetClass,
00901 view,
00902 TheArgs, 5);
00903 XtAddCallback(file_list, XtNcallback, FileToDialog, (XtPointer) file_dialog);
00904
00905 XtPopup(TheFile, XtGrabNonexclusive);
00906
00907 }
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920 static char **GetDirectory()
00921 {
00922 int fcount;
00923 char *fullpath;
00924 DIR *dirp;
00925 struct direct *entry;
00926 int namelength = 0;
00927
00928 if ((dirp = opendir(path)) == NULL)
00929 {
00930 number_entries = 1;
00931 filenames = (char **) calloc(1,sizeof(char **));
00932 filenames[0] = (char *) malloc(sizeof(char) * 14);
00933 strcpy(filenames[0], "..");
00934 return(filenames);
00935 }
00936
00937
00938
00939
00940
00941 fcount = 0;
00942
00943 while ((entry = readdir(dirp)) != NULL)
00944 {
00945 namelength = MAX(namelength,strlen(entry->d_name));
00946 fcount++;
00947 }
00948
00949
00950
00951
00952
00953 namelength = MAX((namelength + 2), 14);
00954 if (strcmp(path,"/") == 0)
00955 { fcount--; }
00956 number_entries = fcount - 1;
00957
00958 rewinddir(dirp);
00959
00960 filenames = (char **)calloc(fcount, sizeof(char *));
00961 filenames[0] = (char *)malloc(sizeof(char *) * fcount * namelength);
00962 fullpath = (char *) malloc(sizeof(char) * (strlen(path) + namelength));
00963 fcount = 0;
00964
00965
00966
00967
00968
00969 while ((entry = readdir(dirp)) != NULL)
00970 {
00971 if (strcmp(entry->d_name, "."))
00972 {
00973 if ((strcmp(path,"/") != 0)|| (strcmp (entry->d_name,"..") != 0))
00974 {
00975 filenames[fcount] = *filenames + (fcount * namelength);
00976 strcpy(filenames[fcount], entry->d_name);
00977
00978 sprintf(fullpath, "%s%s", path, entry->d_name);
00979
00980 if (IsDirectory(fullpath))
00981 { strcat(filenames[fcount], "/"); }
00982 fcount++;
00983 }
00984 }
00985 }
00986
00987 closedir(dirp);
00988
00989 qsort(*filenames, fcount, (sizeof(char) * namelength),
00990 (int (*)(const void *, const void *)) strcmp);
00991
00992 return(filenames);
00993 }
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005 int IsDirectory(
01006 char *temppath)
01007 {
01008 struct stat sbuf;
01009
01010 if(!stat(temppath, &sbuf) && ((sbuf.st_mode & S_IFMT) == S_IFDIR))
01011 return(1);
01012
01013 else
01014 return(0);
01015 }
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028 static void FileToDialog(
01029 Widget w,
01030 XtPointer client_data,
01031 XtPointer call_data)
01032 {
01033 XawListReturnStruct *item = (XawListReturnStruct *)call_data;
01034 char *ptr;
01035
01036 if (!strcmp(item->string, "../"))
01037 {
01038 path[strlen(path) - 1] = '\0';
01039 ptr = strrchr(path, '/');
01040 ptr++;
01041 *(ptr) = '\0';
01042
01043
01044
01045
01046
01047 if (filenames != NULL)
01048 {
01049 free(filenames[0]);
01050 free(filenames);
01051 }
01052
01053 XawListChange(w, GetDirectory(), 0, 0, True);
01054 }
01055 else if (strrchr(item->string, '/'))
01056 {
01057 strcat(path, item->string);
01058 XawListChange(w, GetDirectory(), 0, 0, True);
01059 }
01060
01061 else
01062 {
01063 XtSetArg(TheArgs[0], XtNvalue, item->string);
01064 XtSetValues((Widget)client_data, TheArgs, 1);
01065 }
01066 }
01067
01068
01069
01070
01071
01072
01073
01074 void LoadBatch(
01075 char *str)
01076 {
01077 void *theEnv = GetCurrentEnvironment();
01078 EnvPrintRouter(theEnv,"wclips", "(batch ");
01079 SetCommandString(theEnv,"(batch");
01080 GetFileForCLIPS(str);
01081 EnvPrintRouter(theEnv,"wclips", ")\n");
01082 AppendCommandString(theEnv,")\n");
01083 quit_get_event = True;
01084 }
01085
01086
01087
01088
01089
01090
01091
01092 void LoadBinary(
01093 char *str)
01094 {
01095 void *theEnv = GetCurrentEnvironment();
01096 EnvPrintRouter(theEnv,"wclips", "(bload ");
01097 SetCommandString(theEnv,"(bload");
01098 GetFileForCLIPS(str);
01099 EnvPrintRouter(theEnv,"wclips", ")\n");
01100 AppendCommandString(theEnv,")\n");
01101 quit_get_event = True;
01102 }
01103
01104
01105
01106
01107
01108
01109
01110 void LoadTheFacts(
01111 char *str)
01112 {
01113 void *theEnv = GetCurrentEnvironment();
01114 EnvPrintRouter(theEnv,"wclips", "(load-facts ");
01115 SetCommandString(theEnv,"(load-facts");
01116 GetFileForCLIPS(str);
01117 EnvPrintRouter(theEnv,"wclips", ")\n");
01118 AppendCommandString(theEnv,")\n");
01119 quit_get_event = True;
01120 }
01121
01122
01123
01124
01125
01126
01127
01128 void LoadRules(
01129 char *str)
01130 {
01131 void *theEnv = GetCurrentEnvironment();
01132 EnvPrintRouter(theEnv,"wclips", "(load ");
01133 SetCommandString(theEnv,"(load");
01134 GetFileForCLIPS(str);
01135 EnvPrintRouter(theEnv,"wclips", ")\n");
01136 AppendCommandString(theEnv,")\n");
01137 quit_get_event = True;
01138 }
01139
01140
01141
01142
01143
01144
01145
01146 void IntDribbleOn(
01147 String str)
01148 {
01149 void *theEnv = GetCurrentEnvironment();
01150 if(!CommandLineData(theEnv)->EvaluatingTopLevelCommand)
01151 EnvPrintRouter(theEnv,"wclips", "(dribble-on ");
01152 SetCommandString(theEnv,"(dribble-on");
01153 GetFileForCLIPS(str);
01154 if(!CommandLineData(theEnv)->EvaluatingTopLevelCommand)
01155 EnvPrintRouter(theEnv,"wclips", ")\n");
01156 AppendCommandString(theEnv,")\n");
01157 quit_get_event = True;
01158 if (((access(str, 02) == 0) || (access(str, 00))) && (strcmp(str, "\0") != 0))
01159 {
01160 Dribble_status = True;
01161 XtSetArg(TheArgs[0], XtNleftBitmap, checker);
01162 XtSetValues(file_dribble, TheArgs, 1);
01163 }
01164 }
01165
01166
01167
01168
01169
01170
01171
01172 static void GetFileForCLIPS(
01173 char *file)
01174 {
01175 void *theEnv = GetCurrentEnvironment();
01176 AppendCommandString(theEnv,"\"");
01177 AppendCommandString(theEnv,file);
01178 AppendCommandString(theEnv,"\"");
01179 if(!CommandLineData(theEnv)->EvaluatingTopLevelCommand)
01180 {
01181 EnvPrintRouter(theEnv,"wclips", "\"");
01182 EnvPrintRouter(theEnv,"wclips", file);
01183 EnvPrintRouter(theEnv,"wclips", "\"");
01184 }
01185 }
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195 void Restart(
01196 Widget w,
01197 XtPointer client_data,
01198 XtPointer call_data)
01199 {
01200 void *theEnv = GetCurrentEnvironment();
01201 system("xclips&");
01202 XclipsExit(theEnv,0);
01203 }
01204
01205
01206
01207
01208
01209
01210
01211 void Quit(
01212 Widget w,
01213 XtPointer client_data,
01214 XtPointer call_data)
01215 {
01216 void *theEnv = GetCurrentEnvironment();
01217 XclipsExit(theEnv,0);
01218 }
01219