home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Utilities / FileSpy-1.1-MIHS / Controller.m < prev    next >
Encoding:
Text File  |  1996-09-22  |  64.4 KB  |  2,069 lines

  1. /*
  2.  *   This sourcecode is part of FileSpy, a logfile observing utility.
  3.  *   Copyright (C) 1996  Felix Rauch
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation; either version 2 of the License, or
  8.  *   (at your option) any later version.
  9.  *   
  10.  *   Notice that this program may not be possessed, used, copied,
  11.  *   distributed or modified by people having to do with nuclear
  12.  *   weapons. See the file CONDITIONS for details.
  13.  *
  14.  *   This program is distributed in the hope that it will be useful,
  15.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *   GNU General Public License for more details.
  18.  *
  19.  *   You should have received a copy of the GNU General Public License
  20.  *   along with this program; if not, write to the Free Software
  21.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  *
  23.  *   To contact the original author, try:
  24.  *   e-mail: Felix.Rauch@nice.ch
  25.  *   Traditional mail:    Felix Rauch
  26.  *            Sempacherstrasse 33
  27.  *            8032 Zurich
  28.  *            Switzerland
  29.  */
  30.  
  31. #import "Controller.h"
  32.  
  33. #define SHORTESTTIME 1        /* minimal time between two tests on a file */
  34. #define LONGESTTIME 60        /* maximal time    -       "      -        */
  35.  
  36. #define WIN_DELTA_X 25.0    /* coord-difference of new windows */
  37. #define WIN_DELTA_Y 25.0    /* remember: Y comes down! */
  38. #define WIN_START_X 100.0
  39. #define WIN_START_Y 500.0
  40. #define WIN_MAX_X 500.0
  41. #define WIN_MAX_Y 100.0
  42.  
  43. #define MAXFILELEN MAXNAMLEN
  44.  
  45. #ifdef DEBUG
  46.     #define DEFOWNER "FileSpyDebug"
  47. #else
  48.     #define DEFOWNER "FileSpy"
  49. #endif
  50.  
  51. int wildmat(char *text, char *p);    // still uses wildmat, should use GNU-regexp in the near future
  52.  
  53. @implementation Controller
  54.  
  55. - appWillInit:sender
  56. {
  57.     whileInit = YES;
  58.     return self;
  59. }
  60.  
  61. - appDidInit:sender
  62. {
  63.     NXRect    matrixRect, scrollRect;
  64.     NXSize    interCellSpacing = {0.0, 0.0}, cellSize;
  65.     const char *fileType[] = {NXFilenamePboardType};
  66.  
  67.     winx = WIN_START_X;
  68.     winy = WIN_START_Y;
  69.     fileCount = 0;        // no files yet
  70.     secs = 2.0;        // this one should probably be in the defaults database
  71.                 // now set some defaults
  72.     saveFileList = YES;
  73.     prefPopup = YES;
  74.     prefBeepOnChange = YES;
  75.     prefSuperlog = NO;
  76.     prefUseFilter = NO;
  77.     prefFileMode = RADIO_ENTIRE;
  78.     prefColor = NX_COLORBLACK;    // defined in <appkit/color.h>
  79.     prefTimeStamp = NO;        // no timestamps is default
  80.     prefSuperCopyFilename = ONCE;
  81.     prefSpytype = SPY_CONTENTS;    // only spy for contents
  82.     superPopup = YES;
  83.     superBeepOnChange = YES;
  84.     superUseFilter = NO;
  85.     useFilter = NO;
  86.     filterMode = FILTER_DONTBEEP;
  87.     filterIsUpToDate = YES;
  88.     displayCurWindow = YES;        // only used when loading preferences
  89.     becomeKey = NO;
  90.     saveState = NO;
  91.     maxLineState = NO;
  92.     maxLines = 100;
  93.     inspectorFrame = (char *)0;
  94.     myWindowIsVisible = NO;
  95.     nrOpenWindows = 0;
  96. //    lastSuperlogString = (char *)0;
  97.     tmpList = [[List allocFromZone:[self zone]] init];    // temporary List used by all objects
  98.     [SpyTextFieldCell setSharedTmpList:tmpList];
  99.     existenceSeen = YES;
  100.     mySound = nil;            // why do I need this???
  101.     swapfilename = NULL;
  102.     swapfilesize = -1;
  103.     swapfileTooBig = swapfileError = NO;
  104.  
  105.     [[NXApp appListener] setServicesDelegate:self];
  106.     [self registerServices:self];
  107.     if(system("/bin/stty pass8 pass8out nl > /dev/console") == 127)        // proposed by mwa
  108.         printf("filespy: couldn't open shell for 'stty pass8 pass8out nl > /dev/console\n");
  109.     [[[myScrollView setHorizScrollerRequired: NO]        // setup mainwindow
  110.         setVertScrollerRequired: YES]
  111.         setBorderType: NX_BEZEL];
  112.     [myScrollView getFrame:&scrollRect];
  113.     [ScrollView getContentSize:&(matrixRect.size)
  114.         forFrameSize:&(scrollRect.size)
  115.         horizScroller: NO
  116.         vertScroller: YES
  117.         borderType:NX_BEZEL];
  118.     myMatrix = [[MyMatrix alloc] initFrame: &matrixRect
  119.         mode: NX_LISTMODE
  120.         cellClass: [SpyTextFieldCell class]
  121.         numRows: 0
  122.         numCols: 1];
  123.     [myMatrix setIntercell:&interCellSpacing];
  124.     [myMatrix getCellSize:&cellSize];
  125.     cellSize.width = NX_WIDTH(&matrixRect);
  126.     [myMatrix setCellSize:&cellSize];
  127.     [myMatrix sizeToCells];
  128.     [myMatrix setAutosizeCells:YES];
  129.     [myMatrix setAutoscroll:YES];
  130.     [myScrollView setDocView:myMatrix];
  131.     [[myMatrix superview] setAutoresizeSubviews:YES];
  132.     [myMatrix setAutosizing:NX_WIDTHSIZABLE];
  133.     [myMatrix setTarget:self];
  134.     [myMatrix setAction:@selector(singleClick:)];
  135.     [myMatrix setDoubleAction:@selector(doubleClick:)];
  136.     [myScrollView setController:self];
  137.     [myScrollView registerForDraggedTypes:fileType count:1];
  138.  
  139.     [[[myExistenceScrollView setHorizScrollerRequired: NO]        // setup existencelog
  140.         setVertScrollerRequired: YES]
  141.         setBorderType: NX_BEZEL];
  142.     [myExistenceScrollView getFrame:&scrollRect];
  143.     [ScrollView getContentSize:&(matrixRect.size)
  144.         forFrameSize:&(scrollRect.size)
  145.         horizScroller: NO
  146.         vertScroller: YES
  147.         borderType:NX_BEZEL];
  148.     myExistenceMatrix = [[SimpleMatrix alloc] initFrame: &matrixRect
  149.         mode: NX_TRACKMODE
  150.         cellClass: [ExistenceTextFieldCell class]
  151.         numRows: 0
  152.         numCols: 1];
  153.     [myExistenceMatrix setIntercell:&interCellSpacing];
  154.     [myExistenceMatrix getCellSize:&cellSize];
  155.     cellSize.width = NX_WIDTH(&matrixRect);
  156.     [myExistenceMatrix setCellSize:&cellSize];
  157.     [myExistenceMatrix sizeToCells];
  158.     [myExistenceMatrix setAutosizeCells:YES];
  159.     [myExistenceMatrix setAutoscroll:YES];
  160.     [myExistenceScrollView setDocView:myExistenceMatrix];
  161.     [[myExistenceMatrix superview] setAutoresizeSubviews:YES];
  162.     [myExistenceMatrix setAutosizing:NX_WIDTHSIZABLE];
  163.     [myExistenceMatrix setTarget:self];
  164.     [myExistenceScrollView setController:self];
  165.     [myExistenceScrollView registerForDraggedTypes:fileType count:1];
  166.  
  167.     finder = [[Finder alloc] init];
  168.     [finder setDelegate:self];
  169.     [self setupFilter];
  170.     [self setupSuperlog];
  171.     [self loadPreferences:self];
  172.     if(firstFileStore) {        // load files dragged on icon before start
  173.     unsigned int max = [firstFileStore count], i;
  174.     newFileOffset = YES;
  175.     displayCurWindow = NO;
  176.     for(i = 1; i != max; i++)
  177.         [self addFileWithName:[firstFileStore elementAt:i]];
  178.     [firstFileStore free];
  179.     }
  180.     if(fileCount == 0) {    // set the main window correctly
  181.     [radioMatrix selectCellAt:0:prefFileMode];
  182.     [popupSwitch setState:(prefPopup ? 1 : 0)];
  183.     [soundButton setState:(prefBeepOnChange ? 1 : 0)];
  184.     [filterSwitch setState:(prefUseFilter ? 1 : 0)];
  185.     [superlogSwitch setState:(prefSuperlog ? 1 : 0)];
  186.     }
  187.  
  188.     [self startSpyIfNeeded];
  189. #ifdef DEBUG
  190.     [myWindow setTitle:"Debug"];
  191. #endif
  192.     whileInit = NO;
  193.     
  194.     return self;
  195. }
  196.  
  197. - appWillTerminate:sender
  198. {
  199.     if(saveState)
  200.     [self savePreferences:self];
  201.     [self stopSpy];
  202.     return self;
  203. }
  204.  
  205. - app:sender powerOffIn:(int)ms andSave:(int)aFlag
  206. {
  207.     return [self appWillTerminate:sender];
  208. }
  209.  
  210. - free            // hmm.. I'd say there're some more things to free, aren't there?
  211. {
  212.     [myWindow free];
  213.     return [super free];
  214. }
  215.  
  216. - (BOOL)appAcceptsAnotherFile:sender
  217. {
  218.     return YES;
  219. }
  220.  
  221. - (int)app:sender openFile:(const char *)filename type:(const char *)aType;
  222. {
  223.     BOOL tmpdcw = displayCurWindow;        // tmpDisplayCurWindow
  224.     displayCurWindow = NO;
  225.     if(whileInit) {
  226.     if(!firstFileStore)
  227.         firstFileStore = [[Storage alloc] initCount:1 elementSize:MAXFILELEN description:"[MAXFILELENc]"];
  228.     [firstFileStore addElement:(char *)filename];
  229.     } else {
  230.     newFileOffset = YES;    // place window at a new position (its position is not in the defaults database)
  231.     displayCurWindow = NO;
  232.     [self addFileWithName:filename];
  233.     displayCurWindow = YES;
  234.     }
  235.     displayCurWindow = tmpdcw;
  236.     return YES;
  237. }
  238.  
  239. - addFileWithName:(const char *)name
  240. {
  241.     [myTextField setStringValue:name];
  242.     [self addFile:self];
  243.     return self;
  244. }
  245.  
  246. - addFile:sender
  247. {
  248.     const char *str;
  249.     int rowCount, colCount, button, i = 0;
  250.     SpyTextFieldCell *newCell;
  251.     BOOL fileExists = NO;    // is the file already in the list?
  252.  
  253.     str = [myTextField stringValue];
  254.     if(*str == '\000') {
  255.     [self chooseFile:self];
  256.     return self;
  257.     }
  258.     [myTextField selectText:self];
  259.     [myMatrix getNumRows:&rowCount numCols:&colCount];
  260.     while((i < rowCount) && !fileExists) {        // only one window per file
  261.     if(strcmp([[myMatrix cellAt:i :0] stringValue], str) == 0)
  262.         fileExists = TRUE;
  263.     else
  264.         i++;
  265.     }
  266.  
  267.     if(!fileExists) {
  268.     BOOL newFile = YES;
  269.     struct stat st;
  270.     int actRowNr, actColNr, statRet;
  271.  
  272.     [myMatrix getRow:&actRowNr andCol:&actColNr ofCell:[myMatrix selectedCell]];
  273.     [myMatrix selectCellAt:-1:-1];
  274.     [myMatrix addRow];
  275.     newCell = [myMatrix cellAt:rowCount :0];
  276.     [newCell setTag:rowCount];
  277.     [newCell setStringValue: str];
  278.                         // now set all the default-values
  279.     [newCell setFileMode:prefFileMode];
  280.     [newCell setAutoPopUp:prefPopup];
  281.     [newCell setBeepOnChange:prefBeepOnChange];
  282.     [newCell setMyDelegate:self];
  283.     [newCell setLogToSuperlog:prefSuperlog];
  284.     [newCell setUseFilter:prefUseFilter];
  285.     [newCell setDontCopy:prefDontCopySuperlog];
  286.     [newCell setSuperCopyFilename:prefSuperCopyFilename];
  287.     [newCell setColor:prefColor];
  288.     [newCell setTimeStamp:prefTimeStamp];
  289.     [newCell setMaxLines:(maxLineState ? maxLines : 0)];
  290.     [newCell setSpytype:prefSpytype];
  291.     [newCell setShowTime:showTime];
  292.     if(prefFont)
  293.         [newCell setSpyFont:prefFont];
  294.     if(((statRet = stat(str, &st)) < 0) && !whileInit) {
  295.         if(errno == ENOENT) {
  296.         displayCurWindow = NO;
  297.         button = NXRunAlertPanel("Alert",
  298.             "File %s doesn't exist.\nAre you sure you want to spy it?",  "Ok", "Cancel", NULL, str);
  299.         if(button != NX_ALERTDEFAULT) {
  300.             [myMatrix selectCellAt:rowCount :0];
  301.             [self deleteFile:self];
  302.             newFile = NO;
  303.         }
  304.         } else if(errno == EACCES) {
  305.         displayCurWindow = NO;
  306.         button = NXRunAlertPanel("Alert",
  307.             "No permission for file %s.\nAre you sure you want to spy it?", "Ok", "Cancel", NULL, str);
  308.         if(button != NX_ALERTDEFAULT) {
  309.             [myMatrix selectCellAt:rowCount :0];
  310.             [self deleteFile:self];
  311.             newFile = NO;
  312.         }
  313.         }
  314.     }
  315.     if(newFile) {
  316.         if(newFileOffset) {
  317.         winx = winx + WIN_DELTA_X;
  318.         winy = winy - WIN_DELTA_Y;
  319.         if((winx > WIN_MAX_X) || (winy < WIN_MAX_Y)) {
  320.             winx = WIN_START_X;
  321.             winy = WIN_START_Y;
  322.         }
  323.         [newCell moveWindowTo:winx:winy];
  324.         } else {
  325.         [[newCell window] setFrameFromString:frameStr];
  326.         }
  327.         [newCell updateFile];
  328.     }
  329.     [myMatrix sizeToCells];
  330.     [myMatrix selectCellAt:(newFile ? rowCount : actRowNr) :0];
  331.     [myMatrix scrollCellToVisible:rowCount :0];
  332.     fileCount++;
  333.     [self startSpyIfNeeded];
  334.     } else {        // file is already beeing spyed, so beep and select it
  335.     [self nxbeep];
  336.     [myMatrix selectCellAt:i :0];
  337.     [myMatrix scrollCellToVisible:i :0];
  338.     }
  339.     [self singleClick:self];
  340.     return self;
  341. }
  342.  
  343. - deleteFile:sender
  344. {
  345.     id selectedCellsList;
  346.     int i, rowCount, colCount;
  347.  
  348.     [myTextField setStringValue:""];
  349.     selectedCellsList = [tmpList empty];
  350.     [myMatrix getSelectedCells:selectedCellsList];
  351.     [myMatrix getNumRows:&rowCount numCols:&colCount];
  352.     for(i=0; i<rowCount; i++) {
  353.     if([selectedCellsList indexOf:[myMatrix cellAt:i :0]] != NX_NOT_IN_LIST) {
  354.         [[myMatrix cellAt:i :0] delete];
  355.         [myMatrix removeRowAt:i-- andFree:YES];
  356.         fileCount--;
  357.     }
  358.     }
  359.     [[myMatrix sizeToCells] display];
  360.     [myExistenceMatrix sizeToCells];
  361.     [myExistenceScrollView display];
  362.  
  363.     if((fileCount == 0) || ([myMatrix selectedCell] == nil)) {
  364.     [self setInspectorToView:[inspectorNoView contentView]];
  365.     }
  366.     [self stopSpyIfNeeded];
  367.     return self;
  368. }
  369.  
  370. - chooseFile:sender
  371. {
  372.     id openPanel;
  373.     const char *const fileType[1] = {NULL};
  374.     const char *const *files;
  375.     char tmpfile[MAXFILENAMELENGHT];
  376.     int i = 0;
  377.  
  378.     openPanel = [OpenPanel new];
  379.     [openPanel setDelegate:self];
  380.     [openPanel chooseDirectories:NO];
  381.     [openPanel allowMultipleFiles:YES];
  382.     if([openPanel runModalForDirectory:[myTextField stringValue] file:NULL types:fileType] == NX_OKTAG) {
  383.     if((files = [openPanel filenames]) != (const char *const *)0) {
  384.         while(files[i]) {
  385.         sprintf(tmpfile, "%s/%s", [openPanel directory], files[i++]);
  386.         [self addFileWithName:tmpfile];
  387.         }
  388.     }
  389.     }
  390.     [self singleClick:self];
  391.     return self;
  392. }
  393.  
  394. - singleClick:sender
  395. {
  396.     PopUpList *popupList = [[superFilenameButton cell] target], *spytypePopuplist = [[spytypeButton cell] target];
  397.     Matrix *popupMatrix = [popupList itemList], *spytypeMatrix = [spytypePopuplist itemList];
  398.     id selectedCell = [myMatrix selectedCell];
  399.  
  400.     if(selectedCell != nil) {                        // this does not work correctly because of a bug in NS!
  401.                                         // tempi passati
  402.     [myTextField setStringValue:[selectedCell stringValue]];
  403.     [myTextField selectText:self];
  404.     if(inspectorPanel) {        // if the inspectorPanel is open, then set all the values
  405.         [radioMatrix selectCellAt:0 :[selectedCell fileMode]];
  406.         [soundButton setState:[selectedCell beepOnChange]];
  407.         [popupSwitch setState:[selectedCell autoPopUp]];
  408.         [superlogSwitch setState:[selectedCell logToSuperlog]];
  409.         [filterSwitch setState:[selectedCell useFilter]];
  410.         [dontCopySwitch setState:[selectedCell dontCopy]];
  411.         [timeSwitch setState:[selectedCell timeStamp]];
  412.         [popupMatrix selectCellWithTag:[selectedCell superCopyFilename]];
  413.         [superFilenameButton setTitle:
  414.             [[popupMatrix findCellWithTag:[selectedCell superCopyFilename]] title]];
  415.         [superColorWell setColor:[selectedCell color]];
  416.         [fontTextField setFont:[selectedCell spyFont]];
  417.         [myFontManager setSelFont:[selectedCell spyFont] isMultiple:NO];
  418.         [spytypeMatrix selectCellWithTag:(int)[selectedCell spytype]];
  419.         [spytypeButton setTitle:
  420.             [[spytypeMatrix findCellWithTag:(int)[selectedCell spytype]] title]];
  421.         if([[myMatrix getSelectedCells:[tmpList empty]] count] > 1) {        // if multiple selection...
  422.         [inspectorFile setStringValue:"Files: "];
  423.         [inspectorName setTextGray:NX_DKGRAY];
  424.         } else {
  425.         [inspectorFile setStringValue:"File: "];
  426.         [inspectorName setTextGray:NX_BLACK];
  427.         }
  428.         [inspectorName setStringValue:[selectedCell stringValue]];
  429.         [self setInspectorToView:[inspectorNormalView contentView]];
  430.     }
  431.     } else {        // if no cell is selected
  432. #ifdef DEBUG
  433. //    puts("selectedCell == nil");    // for testing if the bug still exists // it doesn't...
  434. #endif
  435.     [myTextField setStringValue:""];
  436.     [myTextField selectText:self];
  437.     [self setInspectorToView:[inspectorNoView contentView]];
  438.     }
  439.     return self;
  440. }
  441.  
  442. - doubleClick:sender
  443. {
  444.     [[myMatrix selectedCell] displayWindow];
  445.     return self;
  446. }
  447.  
  448. - radioClick:sender        // if user selects the radio-button for entire file/only new text
  449. {
  450.     List *selectedCellsList = [tmpList empty];
  451.     unsigned int i;
  452.     int mode = [[radioMatrix selectedCell] tag];
  453.  
  454.     [myMatrix getSelectedCells:selectedCellsList];
  455.     for(i = 0; i < [selectedCellsList count]; i++)
  456.     [[selectedCellsList objectAt:i] setFileMode:mode];
  457.     return self;
  458. }
  459.  
  460. - autoPopUpClick:sender
  461. {
  462.     List *selectedCellsList = [tmpList empty];
  463.     unsigned int i;
  464.     BOOL state = [popupSwitch state];
  465.  
  466.     [myMatrix getSelectedCells:selectedCellsList];
  467.     for(i = 0; i < [selectedCellsList count]; i++)
  468.     [[selectedCellsList objectAt:i] setAutoPopUp:state];
  469.     return self;
  470. }
  471.  
  472. - beepOnChangeClick:sender
  473. {
  474.     List *selectedCellsList = [tmpList empty];
  475.     unsigned int i;
  476.     BOOL state = [soundButton state];
  477.  
  478.     [myMatrix getSelectedCells:selectedCellsList];
  479.     for(i = 0; i < [selectedCellsList count]; i++)
  480.     [[selectedCellsList objectAt:i] setBeepOnChange:state];
  481.     return self;
  482. }
  483.  
  484. - superlogClick:sender
  485. {
  486.     List *selectedCellsList = [tmpList empty];
  487.     unsigned int i, max;
  488.     BOOL state = [sender state];
  489.  
  490.     [myMatrix getSelectedCells:selectedCellsList];
  491.     max = [selectedCellsList count];
  492.     for(i = 0; i < max; i++)
  493.     [[selectedCellsList objectAt:i] setLogToSuperlog:state];
  494.     return self;
  495. }
  496.  
  497. - useFilterClick:sender
  498. {
  499.     List *selectedCellsList = [tmpList empty];
  500.     unsigned int i, max;
  501.     BOOL state = [sender state];
  502.  
  503.     [myMatrix getSelectedCells:selectedCellsList];
  504.     max = [selectedCellsList count];
  505.     for(i = 0; i < max; i++)
  506.     [[selectedCellsList objectAt:i] setUseFilter:state];
  507.     return self;
  508. }
  509.  
  510. - copySuperlogClick:sender
  511. {
  512.     List *selectedCellsList = [tmpList empty];
  513.     unsigned int i, max;
  514.     BOOL state = [sender state];
  515.  
  516.     selectedCellsList = [tmpList empty];
  517.     [myMatrix getSelectedCells:selectedCellsList];
  518.     max = [selectedCellsList count];
  519.     for(i = 0; i < max; i++)
  520.         [[selectedCellsList objectAt:i] setDontCopy:state];
  521.     return self;
  522.  
  523. }
  524.  
  525. - filterModeClick:sender
  526. {
  527.     switch([[sender selectedCell] tag]) {
  528.         case 0: filterMode = FILTER_DONTCOPY; break;
  529.         case 1: filterMode = FILTER_DONTBEEP; break;
  530. #ifdef DEBUG
  531.         default: printf("filespy: unknown filtermode %d\n", [sender state]);
  532. #endif
  533.     }
  534.     return self;
  535. }
  536.  
  537. // if user changes something in the preferences-window
  538. - prefRadioClick:sender
  539. {
  540.     prefFileMode = [[prefRadioMatrix selectedCell] tag];
  541.     return self;
  542. }
  543.  
  544. - prefSuperlogClick:sender
  545. {
  546.     prefSuperlog = [sender state];
  547.     return self;
  548. }
  549.  
  550. - prefAutoPopUpClick:sender
  551. {
  552.     prefPopup = [sender state];
  553.     return self;
  554. }
  555.  
  556. - prefBeepOnChangeClick:sender
  557. {
  558.     prefBeepOnChange = [sender state];
  559.     return self;
  560. }
  561.  
  562. - prefUseFilterClick:sender
  563. {
  564.     prefUseFilter = [sender state];
  565.     return self;
  566. }
  567.  
  568. - prefCopySuperlogClick:sender
  569. {
  570.     prefDontCopySuperlog = [sender state];
  571.     return self;
  572. }
  573.  
  574. - superAutoPopUpClick:sender
  575. {
  576.     superPopup = [sender state];
  577.     return self;
  578. }
  579.  
  580. - superBeepOnChangeClick:sender
  581. {
  582.     superBeepOnChange = [sender state];
  583.     return self;
  584. }
  585.  
  586. - superUseFilterClick:sender
  587. {
  588.     superUseFilter = [sender state];
  589.     return self;
  590. }
  591.  
  592. - superDupLinesClick:sender
  593. {
  594. //    BOOL oldState = noDuplicatedLines;
  595.  
  596.     noDuplicatedLines = [sender state];
  597. #if 0
  598.     if((noDuplicatedLines == YES) && (oldState == NO))
  599.     lastSuperlogString = (char *)malloc(MAXSTRLEN * sizeof(char));
  600.     else if((noDuplicatedLines == NO) && (oldState == YES))
  601.     free(lastSuperlogString);
  602. #endif
  603.     return self;
  604. }
  605.  
  606. - saveFileListClick:sender
  607. {
  608.     saveFileList = [sender state];
  609.     return self;
  610. }
  611.  
  612. - keyClick:sender
  613. {
  614.     becomeKey = [sender state];
  615.     return self;
  616. }
  617.  
  618. - stateClick:sender
  619. {
  620.     saveState = [sender state];
  621.     return self;
  622. }
  623.  
  624. - setShowTimeClick:sender
  625. {
  626.     unsigned int i, max;
  627.     List *selectedCellsList = [myMatrix cellList];
  628.  
  629.     showTime = [sender state];
  630.     max = [selectedCellsList count];
  631.     for(i = 0; i < max; i++)
  632.     [[selectedCellsList objectAt:i] setShowTime:showTime];
  633.     if(existencelogWindow)
  634.     [existencelogWindow display];
  635.     return self;
  636. }
  637.  
  638. - (BOOL)showTime
  639. {
  640.     return showTime;
  641. }
  642.  
  643. - startSpy
  644. {
  645.     if(!running) {
  646.     alarmTimedEntry = DPSAddTimedEntry(secs, &alarmHandler, self, NX_BASETHRESHOLD);
  647.     running = YES;
  648.     }
  649.     return self;
  650. }
  651.  
  652. - startSpyIfNeeded
  653. {
  654.     if(fileCount > 0 || (swapfilename != NULL && swapfilesize >= 0))
  655.     [self startSpy];
  656.     return self;
  657. }
  658.  
  659. - stopSpy
  660. {
  661.     if(running) {
  662.     DPSRemoveTimedEntry(alarmTimedEntry);
  663.     NXPing();
  664.     running = NO;
  665.     }
  666.     return self;
  667. }
  668.  
  669. - stopSpyIfNeeded
  670. {
  671.     if(fileCount == 0 && (swapfilename == NULL || swapfilesize < 0))
  672.     [self stopSpy];
  673.     return self;
  674. }
  675.  
  676. - checkFiles    // update all the files
  677. {
  678.     unsigned int i, max;
  679.     int row, col;
  680.     SpyTextFieldCell *actualCell;
  681.     BOOL exMatrixUpdate = NO;
  682.  
  683.     [tmpList empty];
  684.     for(i=0; i<fileCount; i++) {
  685.     actualCell = [myMatrix cellAt:i :0];
  686.     [actualCell updateFile];
  687.     if([actualCell changedState])
  688.         [actualCell updateText];
  689.     if([actualCell askUpdateTime] && showTime)
  690.         exMatrixUpdate = YES;
  691.     }
  692.     max = [tmpList count];
  693.     if(max > 0) {
  694.     if(existenceSeen) {
  695.         existenceSeen = NO;
  696.         [myExistenceMatrix clearSelectedCell];
  697.     }
  698.     for(i=0; i<max; i++) {        // select all cell that changed existence in existencelog
  699.         [myExistenceMatrix getRow:&row andCol:&col ofCell:[tmpList objectAt:i]];
  700.         [myExistenceMatrix setSelectionFrom:row to:row anchor:row lit:YES];
  701.     }
  702.     [myExistenceMatrix getRow:&row andCol:&col ofCell:[tmpList objectAt:0]];    // get first selected cell
  703.     [myExistenceMatrix scrollCellToVisible:row :col];                // and scroll it to visible
  704.     } 
  705.     if((max > 0) || (exMatrixUpdate)) {
  706.     [existencelogWindow display];
  707.     }
  708.     if((swapfilename != NULL) && (swapfilesize >= 0)) {
  709.     [self updateSwapfile];
  710.     }
  711.     return self;
  712. }
  713.  
  714. - changeUpdatePeriod:sender
  715. {
  716.     int newPeriod = [sender intValue];
  717.  
  718.     if(newPeriod > LONGESTTIME)
  719.     newPeriod = LONGESTTIME;
  720.     if(newPeriod < SHORTESTTIME)
  721.     newPeriod = SHORTESTTIME;
  722.     [secsTextField setIntValue:newPeriod];
  723.     [secsScroller setIntValue:newPeriod];
  724.     secs = newPeriod;
  725.     [self stopSpy];
  726.     [self startSpyIfNeeded];
  727.     return self;
  728. }
  729.  
  730. - showPreferences:sender    // shows preferences panel
  731. {
  732.     PopUpList *popupList;
  733.     Matrix *popupMatrix;
  734.  
  735.     if(!preferencesPanel) {
  736.     if(![NXApp loadNibSection:"Preferences.nib" owner:self withNames:NO fromZone:[self zone]]) {
  737.         NXLogError("Can't open Preferences.nib!");
  738.     }
  739.     [self setPrefToView:[prefGenView contentView]];
  740.     }
  741.     popupList = [[prefSuperFilenameButton cell] target];
  742.     popupMatrix = [popupList itemList];
  743.     [secsScroller setDoubleValue:secs];
  744.     [secsTextField setDoubleValue:secs];
  745.     [prefPopupSwitch setState:prefPopup];
  746.     [prefSoundButton setState:prefBeepOnChange];
  747.     [prefFilterSwitch setState:prefUseFilter];
  748.     [prefSuperlogSwitch setState:prefSuperlog];
  749.     [superPopupSwitch setState:superPopup];
  750.     [superSoundSwitch setState:superBeepOnChange];
  751.     [superFilterSwitch setState:superUseFilter];
  752.     [superDupSwitch setState:noDuplicatedLines];
  753.     [prefRadioMatrix selectCellAt:0:prefFileMode];
  754.     [keySwitch setState:becomeKey];
  755.     [stateSwitch setState:saveState];
  756.     [fileListButton setState:saveFileList];
  757.     [prefDontCopySwitch setState:prefDontCopySuperlog];
  758.     [showTimeSwitch setState:showTime];
  759.     [prefSuperFilenameButton setTitle:
  760.         [[popupMatrix findCellWithTag:prefSuperCopyFilename] title]];
  761.     [prefColorWell setColor:prefColor];
  762.  
  763.     popupList = [[prefSpytypeButton cell] target];
  764.     popupMatrix = [popupList itemList];
  765.     [prefSpytypeButton setTitle:
  766.         [[popupMatrix findCellWithTag:prefSpytype] title]];
  767.     [prefFontTextField setFont:prefFont];
  768.     [myFontManager setSelFont:prefFont isMultiple:NO];
  769.     [prefTimeSwitch setState:prefTimeStamp];
  770.     [[maxLinesScroller setIntValue:maxLines] setEnabled:maxLineState];
  771.     [[maxLinesTextField setIntValue:maxLines] setEnabled:maxLineState];
  772.     [maxLinesMatrix selectCellWithTag:maxLineState];
  773.     if(mySound != nil)
  774.     [soundTextField setStringValue:[mySound name]];
  775.     if(swapfilename != NULL) {
  776.     [prefSwapfileTextField setStringValue:swapfilename];
  777.     [prefSwapfileSizeTextField setIntValue:swapfilesize/(1024*1024)];
  778.     } else {
  779.     [prefSwapfileTextField setStringValue:""];
  780.     [prefSwapfileSizeTextField setStringValue:""];
  781.     }
  782.     [preferencesPanel makeKeyAndOrderFront:sender];
  783.     return self;
  784. }
  785.  
  786. - setPref:sender
  787. {
  788.     id newView = nil;
  789.     int tag = [[sender selectedCell] tag];
  790.     
  791.     switch(tag) {
  792.     case 0:    newView = [prefGenView contentView];
  793.         break;
  794.     case 1: newView = [prefNewView contentView];
  795.         break;
  796.     case 2: newView = [prefSuperView contentView];
  797.         break;
  798.     case 3: newView = [prefSwapfileView contentView];
  799.         break;
  800. #ifdef DEBUG
  801.     default: printf("filespy: unknown tag in setPref:sender\n");    // this shouldn't happen
  802.         break;
  803. #endif
  804.     }
  805.     [self setPrefToView:newView];
  806.     [popButton setTitle:[[sender selectedCell] title]];
  807.  
  808.     return self;
  809. }
  810.  
  811. - setPrefToView:theView
  812. {
  813.     NXRect boxRect, viewRect;
  814.     
  815.     [multiView getFrame:&boxRect];
  816.     [theView getFrame:&viewRect];
  817.     [multiView setContentView:theView];
  818.     NX_X(&viewRect) = (NX_WIDTH(&boxRect) - NX_WIDTH(&viewRect)) / 2.0;
  819.     NX_Y(&viewRect) = (NX_HEIGHT(&boxRect) - NX_HEIGHT(&viewRect)) / 2.0;
  820.     [theView setFrame:&viewRect];
  821.     [multiView display];
  822.     return self;
  823. }
  824.  
  825. - savePreferences:sender    // saves preferences to defaults-database
  826. {
  827.     unsigned int i, oldCount = 0;
  828.     char *str;
  829.     id cellList, actualCell;
  830.     NXDefaultsVector vec = {                        // contains global defaults
  831.     {"filterMode", ""},                        // 0
  832.     {"superUseFilter", (superUseFilter ? "YES" : "NO")},        // 1
  833.     {"prefUseFilter", (prefUseFilter ? "YES" : "NO")},        // 2
  834.     {"secs",""},                            // 3
  835.     {"prefPopup", (prefPopup ? "YES" : "NO")},            // 4
  836.     {"prefBeepOnChange", (prefBeepOnChange ? "YES" : "NO")},    // 5
  837.     {"prefSuperlog", (prefSuperlog ? "YES" : "NO")},        // 6
  838.     {"superPopup", (superPopup ? "YES" : "NO")},            // 7
  839.     {"superBeepOnChange", (superBeepOnChange ? "YES" : "NO")},    // 8
  840.     {"prefFileMode", ""},                        // 9
  841.     {"saveFileList", (saveFileList ? "YES" : "NO")},        // 10
  842.     {"fileCount",""},                        // 11
  843.     {"myWindowFrame", ""},                        // 12
  844.     {"myWindowVisible", [myWindow isVisible] ? "YES" : "NO"},    // 13
  845.     {"superWindowFrame", ""},                    // 14
  846.     {"superWindowVisible", [superWindow isVisible] ? "YES" : "NO"},    // 15
  847.     {"becomeKey", becomeKey ? "YES" : "NO"},            // 16
  848.     {"saveState", saveState ? "YES" : "NO"},            // 17
  849.     {"prefDontCopySuperlog", prefDontCopySuperlog ? "YES" : "NO"},    // 18
  850.     {"prefSuperCopyFilename", ""},                    // 19
  851.     {"prefColor", ""},                        // 20
  852.     {"prefTimeStamp", prefTimeStamp ? "YES" : "NO"},        // 21
  853.     {"prefFont", ""},                        // 22
  854.     {"maxLines", ""},                        // 23
  855.     {"inspectorFrame", ""},                        // 24
  856.     {"superNoDupLines", noDuplicatedLines ? "YES" : "NO"},        // 25
  857.     {"prefSpytype", ""},                        // 26
  858.     {"exWindowFrame", ""},                        // 27
  859.     {"exWindowVisible",[existencelogWindow isVisible]? "YES":"NO"},    // 28
  860.     {"soundfile", ""},                        // 29
  861.     {"showTime", "NO"},                        // 30
  862.     {"swapFileName", ""},                        // 31
  863.     {"swapFileSize", "-1"},                        // 32
  864.     {NULL, NULL}                            // <- enter this number in VECLEN
  865.     };
  866. #define VECLEN 33
  867.  
  868.     NXDefaultsVector fileVec = {                    // contains defaults for each file
  869.     {"", ""},    // 0
  870.     {"", ""},
  871.     {"", ""},
  872.     {"", ""},
  873.     {"", ""},
  874.     {"", ""},
  875.     {"", ""},
  876.     {"", ""},
  877.     {"", ""},
  878.     {"", ""},
  879.     {"", ""},
  880.     {"", ""},
  881.     {"", ""},
  882.     {"", ""},    // 13
  883.     {NULL, NULL},    // <- enter this number in FILEVECLEN!
  884.     };
  885. #define FILEVECLEN 14
  886.  
  887.     oldCount = atoi(NXGetDefaultValue(DEFOWNER, "fileCount"));        // need to remember how many files were in the database
  888.                                         // so that I can remove thouse which now longer belong there
  889.     vec[0].value = (char *)alloca(16);
  890.     sprintf(vec[0].value, "%d", filterMode);
  891.     vec[3].value = (char *)alloca(16);
  892.     sprintf(vec[3].value, "%f", secs);
  893.     vec[9].value = (char *)alloca(16);
  894.     sprintf(vec[9].value, "%d", prefFileMode);
  895.     vec[19].value = (char *)alloca(16);
  896.     sprintf(vec[19].value, "%d", prefSuperCopyFilename);
  897.     vec[20].value = (char *)alloca(32);
  898.     sprintf(vec[20].value, "%f,%f,%f", NXRedComponent(prefColor), NXGreenComponent(prefColor), NXBlueComponent(prefColor));
  899.     vec[22].value = (char *)alloca(32);        // hope this is enough for a fontname, is there some constant somewhere?
  900.     sprintf(vec[22].value, "%s %f", [prefFont name], [prefFont pointSize]);
  901.     vec[23].value = (char *)alloca(16);
  902.     sprintf(vec[23].value, "%d", maxLineState ? maxLines : -maxLines);
  903.     vec[26].value = (char *)alloca(16);
  904.     sprintf(vec[26].value, "%hu", prefSpytype);
  905.     vec[29].value = (char *)alloca(MAXNAMLEN);
  906.     sprintf(vec[29].value, [self soundName]);
  907.     vec[30].value = (char *)alloca(4);
  908.     sprintf(vec[30].value, showTime ? "YES" : "NO");
  909.     if(swapfilename != NULL) {
  910.     vec[31].value = (char *)alloca(strlen(swapfilename) + 1);
  911.     strcpy(vec[31].value, swapfilename);
  912.     vec[32].value = (char *)alloca(sizeof(char)*11);
  913.     sprintf(vec[32].value, "%ld", swapfilesize);
  914.     }
  915.  
  916.     vec[11].value = (char *)alloca(16);
  917.     if(saveFileList)
  918.     sprintf(vec[11].value, "%d", fileCount);
  919.     else
  920.     sprintf(vec[11].value, "%d", oldFileCount);
  921.     vec[12].value = (char *)alloca(NX_MAXFRAMESTRINGLENGTH);
  922.     [myWindow saveFrameToString:vec[12].value];
  923.     vec[14].value = (char *)alloca(NX_MAXFRAMESTRINGLENGTH);
  924.     [superWindow saveFrameToString:vec[14].value];
  925.     vec[24].value = (char *)alloca(NX_MAXFRAMESTRINGLENGTH);
  926.     if(inspectorPanel) {            // remember the inspector panel's position
  927.     [inspectorPanel saveFrameToString:vec[24].value];
  928.     } else if(inspectorFrame != (char *)0) {
  929.     strcpy(vec[24].value, inspectorFrame);
  930.     }
  931.     vec[27].value = (char *)alloca(NX_MAXFRAMESTRINGLENGTH);
  932.     [existencelogWindow saveFrameToString:vec[27].value];
  933.  
  934.     if(NXWriteDefaults(DEFOWNER, vec) != VECLEN)
  935.     NXLogError("error while writing to defaults database");
  936.  
  937.     [self saveFilter:self];
  938.  
  939.     if(saveFileList) {        // save defaults for each file
  940.     NXColor col;
  941.     for(i = 0; i < FILEVECLEN; i++) {
  942.         fileVec[i].name = (char *)alloca(32);
  943.         fileVec[i].value = (char *)alloca(NX_MAXFRAMESTRINGLENGTH);
  944.     }
  945.     cellList = [myMatrix cellList];
  946.     for(i = 0; i < fileCount; i++) {
  947.         actualCell = [cellList objectAt:i];
  948.         sprintf(fileVec[0].name, "fileName%d", i);
  949.         strcpy(fileVec[0].value, [actualCell stringValue]);
  950.         sprintf(fileVec[1].name, "fileFrame%d", i);
  951.         [[actualCell window] saveFrameToString:fileVec[1].value];
  952.         sprintf(fileVec[2].name, "fileMode%d", i);
  953.         sprintf(fileVec[2].value, "%d", [actualCell fileMode]);
  954.         sprintf(fileVec[3].name, "filePop%d", i);
  955.         strcpy(fileVec[3].value, [actualCell autoPopUp] ? "YES" : "NO");
  956.         sprintf(fileVec[4].name, "fileBeep%d", i);
  957.         strcpy(fileVec[4].value, [actualCell beepOnChange] ? "YES" : "NO");
  958.         sprintf(fileVec[5].name, "fileLog%d", i);
  959.         strcpy(fileVec[5].value, [actualCell logToSuperlog] ? "YES" : "NO");
  960.         sprintf(fileVec[6].name, "fileFilter%d", i);
  961.         strcpy(fileVec[6].value, [actualCell useFilter] ? "YES" : "NO");
  962.         sprintf(fileVec[7].name, "fileVisible%d", i);
  963.         strcpy(fileVec[7].value, [[actualCell window] isVisible] ? "YES" : "NO");
  964.         sprintf(fileVec[8].name, "fileDontCopy%d", i);
  965.         strcpy(fileVec[8].value, [actualCell dontCopy] ? "YES" : "NO");
  966.         sprintf(fileVec[9].name, "fileSuperCopyName%d", i);
  967.         sprintf(fileVec[9].value, "%d", [actualCell superCopyFilename]);
  968.         col = [actualCell color];
  969.         sprintf(fileVec[10].name, "fileColor%d", i);
  970.         sprintf(fileVec[10].value, "%f,%f,%f", NXRedComponent(col), NXGreenComponent(col), NXBlueComponent(col));
  971.         sprintf(fileVec[11].name, "fileTimeStamp%d", i);
  972.         sprintf(fileVec[11].value, [actualCell timeStamp] ? "YES" : "NO");
  973.         sprintf(fileVec[12].name, "fileFont%d", i);
  974.         sprintf(fileVec[12].value, "%s %f", [[actualCell spyFont] name], [[actualCell spyFont] pointSize]);
  975.         sprintf(fileVec[13].name, "fileSpytype%d", i);
  976.         sprintf(fileVec[13].value, "%hu", [actualCell spytype]);
  977.  
  978.         if(NXWriteDefaults(DEFOWNER, fileVec) != FILEVECLEN)
  979.         NXLogError("error while writing filevector to defaults database");
  980.     }
  981.     if(oldCount > fileCount) {    // remove old entries which sould no longer be there
  982.         str = (char *)alloca(32);
  983.         for(i = fileCount; i < oldCount; i++) {
  984.         sprintf(str, "fileName%d", i);
  985.         NXRemoveDefault(DEFOWNER, str);
  986.         sprintf(str, "fileFrame%d", i);
  987.         NXRemoveDefault(DEFOWNER, str);
  988.         sprintf(str, "fileMode%d", i);
  989.         NXRemoveDefault(DEFOWNER, str);
  990.         sprintf(str, "filePop%d", i);
  991.         NXRemoveDefault(DEFOWNER, str);
  992.         sprintf(str, "fileBeep%d", i);
  993.         NXRemoveDefault(DEFOWNER, str);
  994.         sprintf(str, "fileLog%d", i);
  995.         NXRemoveDefault(DEFOWNER, str);
  996.         sprintf(str, "fileFilter%d", i);
  997.         NXRemoveDefault(DEFOWNER, str);
  998.         sprintf(str, "fileVisible%d", i);
  999.         NXRemoveDefault(DEFOWNER, str);
  1000.         sprintf(str, "fileDontCopy%d", i);
  1001.         NXRemoveDefault(DEFOWNER, str);
  1002.         sprintf(str, "fileSuperCopyName%d", i);
  1003.         NXRemoveDefault(DEFOWNER, str);
  1004.         sprintf(str, "fileColor%d", i);
  1005.         NXRemoveDefault(DEFOWNER, str);
  1006.         sprintf(str, "fileTimeStamp%d", i);
  1007.         NXRemoveDefault(DEFOWNER, str);
  1008.         sprintf(str, "fileFont%d", i);
  1009.         NXRemoveDefault(DEFOWNER, str);
  1010.         sprintf(str, "fileSpytype%d", i);
  1011.         NXRemoveDefault(DEFOWNER, str);
  1012.         }
  1013.     }
  1014.     }
  1015.     return self;
  1016. }
  1017.  
  1018. - saveFilter:sender        // save filter-patterns to defaults database
  1019. {
  1020.     char *tmp = (char *)alloca(16);
  1021.     const char *tmpStr;
  1022.     unsigned int i, maxFilter, oldCount = 0;
  1023.  
  1024.     maxFilter = [filterStore count];
  1025.     tmpStr = NXGetDefaultValue(DEFOWNER, "filterStoreCount");
  1026.     if(tmpStr != (const char *)0)
  1027.     oldCount = atoi(tmpStr);
  1028.     sprintf(tmp, "%d", maxFilter);
  1029.     if(!NXWriteDefault(DEFOWNER, "filterStoreCount", tmp))
  1030.     NXLogError("error while writing filterStoreCount to defaults database");
  1031.     for(i = 0; i < maxFilter; i++) {                // save all filter strings
  1032.     sprintf(tmp, "filterLine%d", i);
  1033.     if(!NXWriteDefault(DEFOWNER, tmp, (char *)[filterStore elementAt:i]))
  1034.         NXLogError("error while writing filterLine to defaults database");
  1035.     }
  1036.     for(i = maxFilter; i < oldCount; i++) {        // remove remaining old entries
  1037.     sprintf(tmp, "filterLine%d", i);
  1038.     NXRemoveDefault(DEFOWNER, tmp);
  1039.     }
  1040.     if([filterWindow isDocEdited])
  1041.     [filterWindow setDocEdited:NO];
  1042.     return self;
  1043. }
  1044.  
  1045. - loadPreferences:sender        // load preferences from defaults database
  1046. {
  1047.     NXDefaultsVector vec = {                        // contains global defaults
  1048.     {"filterMode", "1"},                        // 0
  1049.     {"superUseFilter", "NO"},                    // 1
  1050.     {"prefUseFilter", "NO"},                    // 2
  1051.     {"secs", "2.000000"},                        // 3
  1052.     {"prefPopup", "YES"},                        // 4
  1053.     {"prefBeepOnChange", "YES"},                    // 5
  1054.     {"prefSuperlog", "NO"},                        // 6
  1055.     {"superPopup", "YES"},                        // 7
  1056.     {"superBeepOnChange", "YES"},                    // 8
  1057.     {"prefFileMode", "0"},                        // 9
  1058.     {"saveFileList", "YES"},                    // 10
  1059.     {"fileCount", "0"},                        // 11
  1060.     {"myWindowFrame", ""},                        // 12
  1061.     {"myWindowVisible", "YES"},                    // 13
  1062.     {"superWindowFrame", ""},                    // 14
  1063.     {"superWindowVisible", "NO"},                    // 15
  1064.     {"becomeKey", "NO"},                        // 16
  1065.     {"saveState", "NO"},                        // 17
  1066.     {"prefDontCopySuperlog", "YES"},                // 18
  1067.     {"filterStoreCount", "0"},                    // 19
  1068.     {"prefSuperCopyFilename", "0"},                    // 20
  1069.     {"prefColor", "0,0,0"},                        // 21
  1070.     {"prefTimeStamp", "NO"},                    // 22
  1071.     {"prefFont", "Ohlfs 10.000000"},                // 23
  1072.     {"maxLines", "-100"},                        // 24
  1073.     {"inspectorFrame", ""},                        // 25
  1074.     {"superNoDupLines", "NO"},                    // 26
  1075.     {"prefSpytype", "1"},                        // 27
  1076.     {"exWindowFrame", ""},                        // 28
  1077.     {"exWindowVisible", "NO"},                    // 29
  1078.     {"soundfile", ""},                        // 30
  1079.     {"showTime", "NO"},                        // 31
  1080.     {"swapFileName", ""},                        // 32
  1081.     {"swapFileSize", "-1"},                        // 33
  1082.     {NULL, NULL}
  1083.     };
  1084.     NXDefaultsVector fileVec = {                    // contains defaults for individual files
  1085.     {"", ""},    // 0
  1086.     {"", ""},
  1087.     {"", ""},
  1088.     {"", ""},
  1089.     {"", ""},
  1090.     {"", ""},
  1091.     {"", ""},
  1092.     {"", ""},
  1093.     {"", ""},
  1094.     {"", ""},
  1095.     {"", ""},
  1096.     {"", ""},
  1097.     {"", ""},
  1098.     {"", ""},    // 13
  1099.     {NULL, NULL},    // <- enter this number in NRFILEVEC
  1100.     };
  1101. #define NRFILEVEC 14
  1102.  
  1103.     unsigned int max, i;
  1104.     BOOL tmpPopup, tmpBeepOnChange, tmpLogToSuperlog, tmpUseFilter;
  1105.     unsigned short int tmpSpytype;
  1106.     int tmpFileMode;
  1107.     float red, green, blue;
  1108.     char str[MAXFILELEN], fontStr[48];
  1109.     const char *tmpStr;
  1110.  
  1111.     NXRegisterDefaults(DEFOWNER, vec);
  1112.     [self setSound:NXGetDefaultValue(DEFOWNER, "soundfile")];        // set 'beep'
  1113.     filterMode = atoi(NXGetDefaultValue(DEFOWNER, "filterMode"));
  1114.     superUseFilter = (strncmp(NXGetDefaultValue(DEFOWNER, "superUseFilter"), "NO", 2) == 0) ? NO : YES;
  1115.     tmpUseFilter = (strncmp(NXGetDefaultValue(DEFOWNER, "prefUseFilter"), "NO", 2) == 0) ? NO : YES;
  1116.     secs = atof(NXGetDefaultValue(DEFOWNER, "secs"));
  1117.     tmpPopup = (strncmp(NXGetDefaultValue(DEFOWNER, "prefPopup"), "NO", 2) == 0) ? NO : YES;
  1118.     tmpBeepOnChange = (strncmp(NXGetDefaultValue(DEFOWNER, "prefBeepOnChange"), "NO", 2) == 0) ? NO : YES;
  1119.     tmpLogToSuperlog = (strncmp(NXGetDefaultValue(DEFOWNER, "prefSuperlog"), "NO", 2) == 0) ? NO : YES;
  1120.     superPopup = (strncmp(NXGetDefaultValue(DEFOWNER, "superPopup"), "NO", 2) == 0) ? NO : YES;
  1121.     superBeepOnChange = (strncmp(NXGetDefaultValue(DEFOWNER, "superBeepOnChange"), "NO", 2) == 0) ? NO : YES;
  1122.     noDuplicatedLines = (strncmp(NXGetDefaultValue(DEFOWNER, "superNoDupLines"), "NO", 2) == 0) ? NO : YES;
  1123. #if 0
  1124.     if(noDuplicatedLines)
  1125.     lastSuperlogString = (char *)malloc(MAXSTRLEN * sizeof(char));
  1126.     else
  1127.     lastSuperlogString = (char *)0;
  1128. #endif
  1129.     tmpFileMode = atoi(NXGetDefaultValue(DEFOWNER, "prefFileMode"));
  1130.     tmpSpytype = (unsigned short int)atoi(NXGetDefaultValue(DEFOWNER, "prefSpytype"));
  1131.     saveFileList = (strncmp(NXGetDefaultValue(DEFOWNER, "saveFileList"), "NO", 2) == 0) ? NO : YES;
  1132.     maxLines = atoi(NXGetDefaultValue(DEFOWNER, "maxLines"));
  1133.     if(maxLines < 0) {
  1134.     maxLineState = NO;
  1135.     maxLines = -maxLines;
  1136.     } else
  1137.     maxLineState = YES;
  1138.     showTime = (strncmp(NXGetDefaultValue(DEFOWNER, "showTime"), "NO", 2) == 0) ? NO : YES;
  1139.     tmpStr = NXGetDefaultValue(DEFOWNER, "swapFileName");
  1140.     if(tmpStr != NULL && *tmpStr != '\000') {
  1141.     swapfilename = (char *)malloc(strlen(tmpStr)+1);
  1142.     strcpy(swapfilename, tmpStr);
  1143.     swapfilesize = atoi(NXGetDefaultValue(DEFOWNER, "swapFileSize"));
  1144.     }
  1145.  
  1146.     [superWindow setFrameFromString:NXGetDefaultValue(DEFOWNER, "superWindowFrame")];
  1147.     max = atoi(NXGetDefaultValue(DEFOWNER, "filterStoreCount"));
  1148.     for(i = 0; i < max; i++) {
  1149.     const char *ts;
  1150.     sprintf(str, "filterLine%d", i);
  1151.     ts = NXGetDefaultValue(DEFOWNER, str);
  1152.     if(ts != (const char *)0)
  1153.         [filterStore addElement:(char *)ts];
  1154.     }
  1155.     filterIsUpToDate = NO;
  1156.  
  1157.     for(i = 0; i < NRFILEVEC; i++) {
  1158.     fileVec[i].name = (char *)alloca(32);
  1159.     fileVec[i].value = (char *)alloca(NX_MAXFRAMESTRINGLENGTH);
  1160.     }
  1161.  
  1162.     max = oldFileCount= atoi(NXGetDefaultValue(DEFOWNER, "fileCount"));
  1163.     displayCurWindow = NO;
  1164.     newFileOffset = NO;
  1165.  
  1166.     for(i = 0; i < max; i++) {
  1167.     sprintf(fileVec[0].name, "fileName%d", i);
  1168.     sprintf(fileVec[1].name, "fileFrame%d", i);
  1169.     sprintf(fileVec[2].name, "fileMode%d", i);
  1170.     sprintf(fileVec[3].name, "filePop%d", i);
  1171.     sprintf(fileVec[4].name, "fileBeep%d", i);
  1172.     sprintf(fileVec[5].name, "fileLog%d", i);
  1173.     sprintf(fileVec[6].name, "fileDontCopy%d", i);
  1174.     sprintf(fileVec[7].name, "fileFilter%d", i);
  1175.     sprintf(fileVec[8].name, "fileVisible%d", i);
  1176.     sprintf(fileVec[9].name, "fileSuperCopyName%d", i);
  1177.     sprintf(fileVec[10].name, "fileColor%d", i);
  1178.     sprintf(fileVec[11].name, "fileTimeStamp%d", i);
  1179.     sprintf(fileVec[12].name, "fileFont%d", i);
  1180.     sprintf(fileVec[13].name, "fileSpytype%d", i);
  1181.  
  1182.     strcpy(fileVec[0].value, "/");
  1183.     strcpy(fileVec[1].value, "");
  1184.     strcpy(fileVec[2].value, "0");
  1185.     strcpy(fileVec[3].value, "YES");
  1186.     strcpy(fileVec[4].value, "YES");
  1187.     strcpy(fileVec[5].value, "NO");
  1188.     strcpy(fileVec[6].value, "YES");
  1189.     strcpy(fileVec[7].value, "NO");
  1190.     strcpy(fileVec[8].value, "YES");
  1191.     strcpy(fileVec[9].value, "0");
  1192.     strcpy(fileVec[10].value, "0,0,0");
  1193.     strcpy(fileVec[11].value, "NO");
  1194.     strcpy(fileVec[12].value, "Ohlfs 10.000000");
  1195.     strcpy(fileVec[13].value, "1");
  1196.     
  1197.     NXRegisterDefaults(DEFOWNER, fileVec);
  1198.     
  1199.     [myTextField setStringValue:NXGetDefaultValue(DEFOWNER, fileVec[0].name)];
  1200.     strcpy(frameStr, NXGetDefaultValue(DEFOWNER, fileVec[1].name));
  1201.     prefFileMode = atoi(NXGetDefaultValue(DEFOWNER, fileVec[2].name));
  1202.     prefPopup = (strncmp(NXGetDefaultValue(DEFOWNER, fileVec[3].name), "NO", 2) == 0) ? NO : YES;
  1203.     prefBeepOnChange = (strncmp(NXGetDefaultValue(DEFOWNER, fileVec[4].name), "NO", 2) == 0) ? NO : YES;
  1204.     prefSuperlog = (strncmp(NXGetDefaultValue(DEFOWNER, fileVec[5].name), "NO", 2) == 0) ? NO : YES;
  1205.     prefDontCopySuperlog = (strncmp(NXGetDefaultValue(DEFOWNER, fileVec[6].name), "NO", 2) == 0) ? NO : YES;
  1206.     prefUseFilter = (strncmp(NXGetDefaultValue(DEFOWNER, fileVec[7].name), "NO", 2) == 0) ? NO : YES;
  1207.     prefSuperCopyFilename = atoi(NXGetDefaultValue(DEFOWNER, fileVec[9].name));
  1208.     strcpy(str, NXGetDefaultValue(DEFOWNER, fileVec[10].name));
  1209.     sscanf(str, "%f,%f,%f", &red, &green, &blue);
  1210.     prefColor = NXConvertRGBToColor(red, green, blue);
  1211.     prefTimeStamp = (strncmp(NXGetDefaultValue(DEFOWNER, fileVec[11].name), "NO", 2) == 0) ? NO : YES;
  1212.     strcpy(str, NXGetDefaultValue(DEFOWNER, fileVec[12].name));
  1213.     sscanf(str, "%s %f", fontStr, &red);
  1214.     prefFont = [Font newFont:fontStr size:red];
  1215.     prefSpytype = atoi(NXGetDefaultValue(DEFOWNER, fileVec[13].name));
  1216.  
  1217.     [self addFile:self];
  1218.     if(strncmp(NXGetDefaultValue(DEFOWNER, fileVec[8].name), "YES", 3) == 0) {
  1219.         [[myMatrix selectedCell] displayWindow];
  1220.         [self addWindow:self];
  1221.     }
  1222.  
  1223.     }
  1224.     displayCurWindow = YES;
  1225.     newFileOffset = YES;
  1226.     
  1227.     [myWindow setFrameFromString:NXGetDefaultValue(DEFOWNER, "myWindowFrame")];
  1228.     if(strncmp(NXGetDefaultValue(DEFOWNER, "myWindowVisible"), "YES", 3) == 0) {
  1229.     myWindowIsVisible = YES;
  1230.     [myWindow makeKeyAndOrderFront:self];
  1231.     } else
  1232.     myWindowIsVisible = NO;
  1233.  
  1234.     [existencelogWindow setFrameFromString:NXGetDefaultValue(DEFOWNER, "exWindowFrame")];
  1235.     if(strncmp(NXGetDefaultValue(DEFOWNER, "exWindowVisible"), "YES", 3) == 0) {
  1236.     [existencelogWindow makeKeyAndOrderFront:self];
  1237.     }
  1238.  
  1239.     prefPopup = tmpPopup;
  1240.     prefBeepOnChange = tmpBeepOnChange;
  1241.     prefSuperlog = tmpLogToSuperlog;
  1242.     prefUseFilter = tmpUseFilter;
  1243.     prefFileMode = tmpFileMode;
  1244.     prefDontCopySuperlog = (strncmp(NXGetDefaultValue(DEFOWNER, "prefDontCopySuperlog"), "NO", 2) == 0) ? NO : YES;
  1245.     prefSuperCopyFilename = atoi(NXGetDefaultValue(DEFOWNER, "prefSuperCopyFilename"));
  1246.     strcpy(str, NXGetDefaultValue(DEFOWNER, "prefColor"));
  1247.     sscanf(str, "%f,%f,%f", &red, &green, &blue);
  1248.     prefColor = NXConvertRGBToColor(red, green, blue);
  1249.     prefTimeStamp = (strncmp(NXGetDefaultValue(DEFOWNER, "prefTimeStamp"), "NO", 2) == 0) ? NO : YES;
  1250.     strcpy(str, NXGetDefaultValue(DEFOWNER, "prefFont"));
  1251.     sscanf(str, "%s %f", fontStr, &red);
  1252.     prefFont = [Font newFont:fontStr size:red];
  1253.     prefSpytype = tmpSpytype;
  1254.  
  1255.     if(strncmp(NXGetDefaultValue(DEFOWNER, "superWindowVisible"), "YES", 3) == 0)
  1256.     [superWindow makeKeyAndOrderFront:self];
  1257.     becomeKey = strncmp(NXGetDefaultValue(DEFOWNER, "becomeKey"), "NO", 2) == 0 ? NO : YES;
  1258.     saveState = strncmp(NXGetDefaultValue(DEFOWNER, "saveState"), "NO", 2) == 0 ? NO : YES;
  1259.     if(NXGetDefaultValue(DEFOWNER, "inspectorFrame") != (const char *)0) {
  1260.     inspectorFrame = (char *)malloc(NX_MAXFRAMESTRINGLENGTH*sizeof(char));
  1261.     strcpy(inspectorFrame, NXGetDefaultValue(DEFOWNER, "inspectorFrame"));
  1262.     }
  1263.     [self singleClick:self];    // update the filelist with all buttons
  1264.  
  1265.     return self;
  1266. }
  1267.  
  1268. - changeBeepState:sender;
  1269. {
  1270.     BOOL beepOnChange;
  1271.     unsigned int i, max;
  1272.     List *selectedCellsList = [tmpList empty];
  1273.  
  1274.     if([sender state] == 0)
  1275.     beepOnChange = NO;
  1276.     else
  1277.     beepOnChange = YES;
  1278.     [myMatrix getSelectedCells:selectedCellsList];
  1279.     max = [selectedCellsList count];
  1280.     for(i = 0; i < max; i++)
  1281.     [[selectedCellsList objectAt:i] setBeepOnChange:beepOnChange];
  1282.     return self;
  1283. }
  1284.  
  1285. - showSuperlog:sender
  1286. {
  1287.     [superWindow orderFront:self];
  1288.     return self;
  1289. }
  1290.  
  1291. - updateSuperlog:sender :(char *)newText :(BOOL)changed :(BOOL)beepThis :(BOOL)popThis
  1292. {
  1293.     long int tmpPos, superLen;
  1294.     char myText[strlen(newText) + MAXFILELEN], senderName[MAXFILELEN];
  1295.  
  1296.     if(*newText == '\000')    // if there's no new text then forget it
  1297.     return self;
  1298.  
  1299.     if(maxLineState)
  1300.     [self shortSuperText];
  1301.     if(noDuplicatedLines && (sender != lastSuperlogUser)) {    // if user doesn't want the same line from multiple log-files
  1302.                                     // logged more than once, then don't append the line to superlog
  1303.     unsigned int len, len2, oldLineNumber = 0 , newLineNumber = 0, i ,j, k;
  1304.     NXSelPt start, end;
  1305.     char *oldText, *pos;
  1306.     char **oldLines, **newLines;
  1307.     
  1308.     [superText getSel:&start :&end];
  1309.     len = end.cp - start.cp;
  1310.     if(len != 0) {
  1311.         oldText = (char *)alloca(sizeof(char) * (len + 1));
  1312.         [superText getSubstring:oldText start:start.cp length:len];
  1313.         oldText[len] = '\000';
  1314.         for(pos = oldText; *pos != '\000'; ) {    // remove all \r from oldText
  1315.         if(*pos == '\n') {            // count number of lines
  1316.             oldLineNumber++;
  1317.             pos++;
  1318.         } else if(*pos == '\r')            // (they are inserted in some logfiles and in some not)
  1319.             strcpy(pos, pos+1);
  1320.         else
  1321.             pos++;
  1322.         }
  1323.         for(pos = newText; *pos != '\000'; ) {    // same for newtext
  1324.         if(*pos == '\n') {
  1325.             newLineNumber++;
  1326.             pos++;
  1327.         } else if(*pos == '\r')
  1328.             strcpy(pos, pos+1);
  1329.         else
  1330.             pos++;
  1331.         }
  1332.             // get the starting positions of the lines
  1333.         oldLines = (char **)malloc(oldLineNumber * sizeof(char *));
  1334.         newLines = (char **)malloc(newLineNumber * sizeof(char *));
  1335.         oldLineNumber = newLineNumber = 1;
  1336.         oldLines[0] = oldText;
  1337.         newLines[0] = newText;
  1338.         for(pos = oldText; *pos != '\000'; pos++) {
  1339.         if((pos[0] == '\n') && (pos[1] != '\000'))
  1340.             oldLines[oldLineNumber++] = pos+1;
  1341.         }
  1342.         for(pos = newText; *pos != '\000'; pos++) {
  1343.         if((pos[0] == '\n') && (pos[1] != '\000'))
  1344.             newLines[newLineNumber++] = pos+1;
  1345.         }
  1346.             // compare all the new lines with the old ones
  1347.         for(i = 0; i < newLineNumber; i++) {    // for each line in the new text
  1348.         for(len = 0; (newLines[i][len] != '\n') && (newLines[i][len] != '\000'); len++) ;
  1349.         for(j = 0; j < oldLineNumber; j++) {
  1350.             for(len2 = 0; (oldLines[j][len2] != '\n') && (oldLines[j][len2] != '\000'); len2++) ;
  1351.             if((len == len2) && (strncmp(newLines[i], oldLines[j], len) == 0)) {
  1352.                     // in case of a match, remove the new line
  1353.             for(k = i + 1; k < newLineNumber; k++)
  1354.                 strcpy(newLines[k-1], newLines[k]);
  1355.             len = newLines[i+1] - newLines[i];
  1356.             for(k = i+1; k < newLineNumber; k++)
  1357.                 newLines[k] -= len;
  1358.             newLineNumber--;
  1359.             i--;                // will be increased in the for loop, so adjust here
  1360.             if(i < newLineNumber)
  1361.                 break;
  1362.             }
  1363.         }
  1364.         }
  1365.         if(newLineNumber == 0)    // if there are no new lines left, we don't have to add any text
  1366.         return self;
  1367.     }
  1368.     }
  1369.     if(changed || (filterMode == FILTER_DONTBEEP)) {
  1370.     if(changed) {        // if something passed the filter
  1371.         if(superBeepOnChange && beepThis)    // and we prefer beeps in general and in this very special case
  1372.         [self nxbeep];            // then beep
  1373.         if(superPopup && popThis) {        // if we prefer popups uf the superlogwindow and especially in this case...
  1374.         [superWindow orderFrontRegardless];
  1375.         if(becomeKey) {
  1376.             [NXApp unhide:self];
  1377.             [superWindow makeKeyWindow];
  1378.         }
  1379.         }
  1380.     }
  1381.     if(![superWindow isKeyWindow] && ![superWindow isDocEdited])
  1382.         [superWindow setDocEdited:YES];
  1383.     myText[0] = '\000';
  1384.  
  1385.     strcpy(senderName, [sender stringValue]);        // sender's filename
  1386.     superLen = [superText textLength];
  1387.     [superText setAutodisplay:NO];
  1388.     [superText setSel:superLen :superLen];
  1389.  
  1390.     switch([sender superCopyFilename]) {
  1391.         case ONCE:
  1392.         if(sender != lastSuperlogUser) {
  1393.             strcpy(myText, senderName);
  1394.             strcat(myText, ":\n");
  1395.         } else
  1396.             *myText = '\000';
  1397.         tmpPos = superLen + strlen(myText);
  1398.         strcat(myText, newText);
  1399.         [superText replaceSel :myText];
  1400.         [[superText setSel :superLen :tmpPos] underline:self];
  1401.         [superText setSel :superLen :superLen + strlen(myText) + 1];
  1402.         break;
  1403.         case EACHLINE:{
  1404.         char tmpText[strlen(newText) + MAXFILELEN], *p, *cp, tmp;
  1405.  
  1406.         tmpPos = superLen;        // remember current length of superText to select new text afterwards
  1407.         strcpy(myText, senderName);
  1408.         strcat(myText, ":\t");        // tab better than space (Tremblin), maybe use rulers?
  1409.         cp = newText;
  1410.         while(*cp != '\000') {        // start each line with myText
  1411.             strcpy(tmpText, myText);
  1412.             p = cp;
  1413.             while((*p != '\000') && (*p != '\n'))    // search end of line/string
  1414.             p++;
  1415.             tmp = *p;
  1416.             *p = '\000';
  1417.             strcat(tmpText, cp);
  1418.             strcat(tmpText, "\n");            // copy text up to there and append newline
  1419.             if(tmp == '\n')                // go to next line if we haven't found end of string yet
  1420.             cp = p + 1;
  1421.             else
  1422.             cp = p;
  1423.             superLen = [superText textLength];
  1424.             [superText setSel:superLen :superLen];
  1425.             [superText replaceSel :tmpText];        // append this line to superText
  1426.         }
  1427.         [superText setSel :tmpPos :[superText textLength]];
  1428.         break;}
  1429.         case NONE:
  1430.         [superText replaceSel :newText];
  1431.         [superText setSel :superLen :[superText textLength]];
  1432.         break;
  1433. #ifdef DEBUG
  1434.         default:            // that doesn't happen anyway...
  1435.         printf("unmatched case-value\n");
  1436. #endif
  1437.     }
  1438.     [superText setSelColor:[sender color]];
  1439.     if([sender spyFont])
  1440.         [superText setSelFont:[sender spyFont]];
  1441.     if([superText needsDisplay])
  1442.         [superText display];
  1443.     [superText setAutodisplay:YES];
  1444.     [[[superText sizeToFit] scrollSelToVisible] display];
  1445.     if(!lastSuperlogUser && inspectorPanel && [inspectorPanel isVisible] && [superWindow isKeyWindow] && !myWindowIsVisible)
  1446.         [self setInspectorToView:[inspectorNormalView contentView]];
  1447.     lastSuperlogUser = sender;
  1448.         
  1449.     }
  1450.     return self;
  1451. }
  1452.  
  1453. - setupSuperlog
  1454. {
  1455.     superFont = [Font newFont:"Ohlfs"
  1456.             size:10
  1457.             style:0
  1458.             matrix:NX_FLIPPEDMATRIX];
  1459.     [Text setDefaultFont:superFont];
  1460.     superDoc = [Document new:self];
  1461.     superWindow = [[superDoc scrollView] window];
  1462.     superScrollView = [superDoc scrollView];
  1463.     superText = [[superDoc scrollView] docView];
  1464.     [superWindow setFreeWhenClosed:NO];
  1465.     [superWindow setTitle:"Multilog"];
  1466.     [superWindow setDelegate:self];
  1467.     [superText setMonoFont:NO];
  1468.  
  1469.     return self;
  1470. }
  1471.  
  1472. - setupFilter
  1473. {
  1474.     filterStore = [[Storage alloc] initCount:0        // contains filter-lines
  1475.                     elementSize:128
  1476.                     description:"[128c]"];
  1477.     return self;
  1478. }
  1479.  
  1480. - showFilter:sender
  1481. {
  1482.     if(!filterWindow) {
  1483.     if(![NXApp loadNibSection:"Filter.nib" owner:self withNames:NO fromZone:[self zone]]) {
  1484.         NXLogError("Can't open Filter.nib!");
  1485.         return self;
  1486.     }
  1487.     [filterText setDelegate:self];
  1488.     }
  1489.     [filterModeMatrix selectCellAt:filterMode:0];
  1490.     if(!filterIsUpToDate) {
  1491.     unsigned int i, max;
  1492.  
  1493.     [filterText setSel:0 :[filterText textLength]];
  1494.     [filterText replaceSel:""];
  1495.     max = [filterStore count];
  1496.     for(i = 0; i < max; i++) {        // read lines from filterStore and insert them in the text in the filter-panel
  1497.         char str[128];
  1498.         int filterTextLen;
  1499.  
  1500.         filterTextLen = [filterText textLength];
  1501.         [filterText setSel:filterTextLen :filterTextLen];
  1502.         strcpy(str, (char *)[filterStore elementAt:i]);
  1503.         strcat(str, "\n");
  1504.         [filterText replaceSel:str];
  1505.     }
  1506.     filterIsUpToDate = YES;
  1507.     }
  1508.     [filterWindow makeKeyAndOrderFront:self];
  1509.     return self;
  1510. }
  1511.  
  1512. - textDidGetKeys:sender isEmpty:(BOOL)flag
  1513. {
  1514.     if(sender == filterText) {
  1515.     if(![filterWindow isDocEdited])
  1516.         [filterWindow setDocEdited:YES];
  1517.     }
  1518.     return self;
  1519. }
  1520.  
  1521. - applyFilter:sender        // copy all the filter-lines from the text-object to the filterStore
  1522. {
  1523.     int max,i, s, l;
  1524.     char str[128];
  1525.  
  1526.     [filterStore empty];
  1527.     max = [filterText lineFromPosition:[filterText textLength]];
  1528.     for(i = 1; i < max; i++) {
  1529.     s = [filterText positionFromLine:i];
  1530.     l = [filterText positionFromLine:i+1] - s;
  1531.     if(l > 127) {
  1532.         [[[filterText setSel:s :127] scrollSelToVisible] display];
  1533.         NXRunAlertPanel("Warning", "Filterline to long, string is truncated to 127 characters.", "Ok", NULL, NULL);
  1534.         l = 127;
  1535.     }
  1536.     [filterText getSubstring:str
  1537.             start: s
  1538.             length: l];
  1539.     str[l-1] = '\000';    // without '\n' please
  1540.     if((str[0] == '|') && (strchr(str+1, '|') == NULL)) {    // illegal syntax for file-sensitive filterstrings
  1541.         [[[filterText setSel:s :l] scrollSelToVisible] display];
  1542.         NXRunAlertPanel("Alert", "Filename for file-sensitive filterstring must be between two '|'.", "Ok", NULL, NULL);
  1543.     } else {
  1544.         [filterStore addElement:str];
  1545.     }
  1546.     }
  1547.     return self;
  1548. }
  1549.  
  1550.  
  1551. - (BOOL)filterString:(char *)str andRemove:(BOOL)rm who:sender    // returns YES if something passes the filter
  1552. {
  1553.     unsigned int i, max;
  1554.     char *from, *to, *ptr, ch;
  1555.     BOOL matched = NO, pass = NO;    // pass: TRUE if something passed the filter
  1556.     char *senderName = (char *)[sender stringValue];
  1557.  
  1558.     from = to = str;
  1559.     max = [filterStore count];
  1560.     while(*from != '\000') {
  1561.     ptr = from;
  1562.     while((*ptr != '\n') && (*ptr != '\000'))
  1563.         ptr++;
  1564.     ch = *ptr;    // in case that this line has no NL at the end
  1565.     *ptr = '\000';
  1566.     for(i = 0; i < max; i++) {        // go through all filter-lines
  1567.         char *filtStr = (char *)[filterStore elementAt:i], *tmpStr = filtStr;
  1568.         
  1569.         if(((filtStr = strchr(filtStr, '|')) != (char *)0) &&
  1570.             (filtStr[1] != '|')) {    // file-sensitive filterstring
  1571.         *filtStr = '\000';
  1572.         if(!wildmat(senderName, tmpStr)) {
  1573.             *filtStr = '|';
  1574.             break;    // if we're doing file-sensitive filtering and this is the wrong file, then skip filterline
  1575.         }
  1576.         *filtStr++ = '|';    // restore filterstring and advance to real filterstring (the one after the filename)
  1577.         } else
  1578.         filtStr = tmpStr;
  1579.         if(wildmat(from, filtStr)) {
  1580.         matched = TRUE;
  1581.         break;
  1582.         }
  1583.     }
  1584.     if(!matched && rm) {    // if we didn't match anything but are removing matches line, we have to copy the whole line
  1585.         while(*from != '\000')
  1586.         *to++ = *from++;
  1587.         *to++ = ch;
  1588.         from++;
  1589.         while(*from == '\r')
  1590.         from++;
  1591.     } else {    
  1592.         from = (char *)(ptr + 1);
  1593.         *ptr = ch;
  1594.         while(*from == '\r') {        // remove '\r's from begin of line
  1595.         ptr = from;
  1596.         while(ptr[1] != '\000') {
  1597.             *ptr++ = ptr[1];
  1598.         }
  1599.         *ptr = ptr[1];
  1600.         }
  1601.     }
  1602.     if(!matched)
  1603.         pass = YES;
  1604.     }
  1605.     if(rm)
  1606.     *to = '\000';
  1607.     return pass;
  1608. }
  1609.  
  1610. - (int)filterMode
  1611. {
  1612.     return filterMode;
  1613. }
  1614.  
  1615. - (BOOL)superUsesFilter
  1616. {
  1617.     return superUseFilter;
  1618. }
  1619.  
  1620. - (BOOL)becomeKey
  1621. {
  1622.     return becomeKey;
  1623. }
  1624.  
  1625. - unhideApp:sender
  1626. {
  1627.     [NXApp unhide:self];
  1628.     return self;
  1629. }
  1630.  
  1631. - clearBuffer:sender
  1632. {
  1633.     id keyWindow = [NXApp keyWindow];
  1634.     
  1635.     if((keyWindow != nil) && (keyWindow != myWindow) && (keyWindow != superWindow)) {
  1636.     [[keyWindow delegate] clearBuffer:self];
  1637.     } else if(keyWindow == myWindow) {
  1638.     List *selectedCellsList = [tmpList empty];
  1639.     unsigned int i;
  1640.  
  1641.     [myMatrix getSelectedCells:selectedCellsList];
  1642.     for(i = 0; i < [selectedCellsList count]; i++)
  1643.         [[selectedCellsList objectAt:i] clearBuffer:self];
  1644.     } else if(keyWindow == superWindow) {
  1645.     [superText setSel :0 :[superText textLength]];
  1646.     [superText replaceSel:""];
  1647.     [[superText sizeToFit] scrollSelToVisible];
  1648.     if(lastSuperlogUser && inspectorPanel && [inspectorPanel isVisible] && !myWindowIsVisible && [superWindow isKeyWindow]) {
  1649.         // if there is already something in the superlog AND the inspectorPanel is already loaded AND it is visible
  1650.         // AND the mainwindow is not visible AND the (now empty) superlogwindow is the keywindow
  1651.         // THEN the inspectorpanel doesn't know which file it should inspect...
  1652.         [self setInspectorToView:[inspectorNoView contentView]];
  1653.     }
  1654.     lastSuperlogUser = nil;
  1655.     }
  1656.  
  1657.     return self;
  1658. }
  1659.  
  1660. - windowDidBecomeKey:sender
  1661. {
  1662.     if(sender == myWindow) {
  1663.     myWindowIsVisible = YES;
  1664.     if([myMatrix selectedCell] != nil) {
  1665.         [self setInspectorToView:[inspectorNormalView contentView]];
  1666.         [self singleClick:self];
  1667.     }
  1668.     return self;
  1669.     } else if(sender == superWindow) {
  1670.     if([superWindow isDocEdited])
  1671.         [superWindow setDocEdited:NO];
  1672.     if(!myWindowIsVisible && inspectorPanel && [inspectorPanel isVisible]) {
  1673.         if(lastSuperlogUser) {
  1674.             // if the superwindow just became the keywindow and the mainwindow is not visible but the
  1675.         // inspectorpanel is, then set the inspector to the last file that logged something in the superlog
  1676.         [self setInspectorToView:[inspectorNormalView contentView]];
  1677.         [myMatrix selectCell:lastSuperlogUser];
  1678.         [self singleClick:self];
  1679.         } else {
  1680.         // if nothing is in the superlog, then set the inspector to the empty view
  1681.             [self setInspectorToView:[inspectorNoView contentView]];
  1682.         }
  1683.     }
  1684.     } else if(sender == inspectorPanel) {
  1685.     if(myWindowIsVisible) {
  1686.         if([myMatrix cellCount] > 0) {
  1687.         [myFontManager setSelFont:[[myMatrix selectedCell] spyFont] isMultiple:NO];
  1688.         [self setInspectorToView:[inspectorNormalView contentView]];
  1689.         } else {
  1690.         [self setInspectorToView:[inspectorNoView contentView]];
  1691.         }
  1692.     } else if((nrOpenWindows > 0) || ([superWindow isVisible] && lastSuperlogUser)) {
  1693.         [self setInspectorToView:[inspectorNormalView contentView]];
  1694.     } else {
  1695.         [self setInspectorToView:[inspectorNoView contentView]];
  1696.     }
  1697.     } else if(sender == preferencesPanel) {
  1698.     [myFontManager setSelFont:prefFont isMultiple:NO];
  1699.     } else if(sender == existencelogWindow) {
  1700.     existenceSeen = YES;            // existenceWindow has been seen by the user
  1701.     } else if(!myWindowIsVisible && inspectorPanel && [inspectorPanel isVisible]
  1702.         && ([[sender delegate] class] == [SpyTextFieldCell class])) {
  1703.     // if the mainwindow is not visible but the inspectorpanel is and the window which just became the
  1704.     // keywindow is a normal window, then update the inspector the the right file
  1705.     [myMatrix selectCell:[sender delegate]];
  1706.     [self singleClick:self];
  1707.     [self setInspectorToView:[inspectorNormalView contentView]];
  1708.     }
  1709.     return self;
  1710. }
  1711.  
  1712. - windowWillClose:sender
  1713. {
  1714.     Window *keyWindow;
  1715.     if(sender == myWindow) {
  1716.     myWindowIsVisible = NO;
  1717.     keyWindow = [NXApp keyWindow];
  1718.     if((keyWindow != myWindow) && (keyWindow != nil)
  1719.             && (([[keyWindow delegate] class] == [SpyTextFieldCell class]) || (keyWindow == superWindow))) {
  1720.         [self windowDidBecomeKey:keyWindow];
  1721.     } else if(nrOpenWindows == 0) {
  1722.         [self setInspectorToView:[inspectorNoView contentView]];
  1723.     }
  1724.     } else if(sender == existencelogWindow) {
  1725.     existenceSeen = YES;        // we assume that the user has noticed eventual changes in the existencelogWindow
  1726.     } else if([[sender delegate] class] == [SpyTextFieldCell class]) {
  1727.     if(nrOpenWindows > 0) {
  1728.         if((--nrOpenWindows == 0) && !myWindowIsVisible && ![superWindow isVisible]) {
  1729.         // if this was tha last open window (except the panels) then clear the inspectorpanel
  1730.         [self setInspectorToView:[inspectorNoView contentView]];
  1731.         }
  1732.     }
  1733.     } else if((sender == superWindow) && (nrOpenWindows == 0)) {
  1734.     [self setInspectorToView:[inspectorNoView contentView]];
  1735.     }
  1736.     return self;
  1737. }
  1738.  
  1739. - showInspectorPanel:sender
  1740. {
  1741.     if(!inspectorPanel) {
  1742.     if(![NXApp loadNibSection:"Inspector.nib" owner:self withNames:NO fromZone:[self zone]]) {
  1743.         NXLogError("Can't open Inspector.nib!");
  1744.     }
  1745.     if(inspectorFrame != (char *)0) {    // if we read a window-position for the inspectorpanel from the defaults database,
  1746.                         // then set the window accordingly
  1747.         [inspectorPanel setFrameFromString:inspectorFrame];
  1748.         free(inspectorFrame);
  1749.     }
  1750.     if((myWindowIsVisible && ([myMatrix cellCount] > 0) && ([myMatrix selectedCell] != nil))
  1751.             || (nrOpenWindows > 0) || ([superWindow isVisible] && lastSuperlogUser)) {
  1752.         [self setInspectorToView:[inspectorNormalView contentView]];
  1753.     } else {
  1754.         [self setInspectorToView:[inspectorNoView contentView]];
  1755.     }
  1756.     }
  1757.     [self singleClick:self];
  1758.     [inspectorPanel makeKeyAndOrderFront:self];
  1759.     return self;
  1760. }
  1761.  
  1762. - setInspectorToView:theView
  1763. {
  1764.     NXRect boxRect, viewRect;
  1765.     
  1766.     if([inspectorMultiView contentView] != theView) {
  1767.     [inspectorMultiView getFrame:&boxRect];
  1768.     [theView getFrame:&viewRect];
  1769.     [inspectorMultiView setContentView:theView];
  1770.     NX_X(&viewRect) = (NX_WIDTH(&boxRect) - NX_WIDTH(&viewRect)) / 2.0;
  1771.     NX_Y(&viewRect) = (NX_HEIGHT(&boxRect) - NX_HEIGHT(&viewRect)) / 2.0;
  1772.     [theView setFrame:&viewRect];
  1773.     [inspectorMultiView display];
  1774.     }
  1775.     return self;
  1776. }
  1777.  
  1778. - showFindPanel:sender
  1779. {
  1780.     [finder showFindPanel:self];
  1781.     return self;
  1782. }
  1783.  
  1784. - findNext:sender
  1785. {
  1786.     [finder findNext:self];
  1787.     return self;
  1788. }
  1789.  
  1790. - findPrevious:sender
  1791. {
  1792.     [finder findPrevious:self];
  1793.     return self;
  1794. }
  1795.  
  1796. - enterSelection:sender
  1797. {
  1798.     [finder enterSelection:self];
  1799.     return self;
  1800. }
  1801.  
  1802. - jumpToSelection:sender
  1803. {
  1804.     const id mainWindow = [NXApp mainWindow];
  1805.  
  1806.     if(mainWindow == superWindow)
  1807.     [superText makeSelectionVisible];
  1808.     else if(mainWindow == filterWindow)
  1809.     [filterText makeSelectionVisible];
  1810.     else if([[mainWindow delegate] class] == [SpyTextFieldCell class])
  1811.     [[[mainWindow delegate] text] makeSelectionVisible];
  1812.     return self;
  1813. }
  1814.  
  1815. - findTexts:(BOOL)all
  1816. {
  1817.     List *textList;
  1818.     const id mainWindow = [NXApp mainWindow];
  1819.  
  1820.     textList = [[List alloc] init];
  1821.     if(all) {            // return ALL text objects you have
  1822.     unsigned int i;
  1823.     List *cellList;
  1824.  
  1825.     cellList = [myMatrix cellList];
  1826.     if(mainWindow == superWindow)            // if the superlogWindow is main, search there first
  1827.         [textList addObject:superText];
  1828.     else if(mainWindow == filterWindow)
  1829.         [textList addObject:filterText];
  1830.     else if(mainWindow == helpWindow)
  1831.         [textList addObject:helpText];
  1832.     else if((mainWindow != nil) && ([[mainWindow delegate] class] == [SpyTextFieldCell class]))
  1833.         [textList addObject:[[mainWindow delegate] text]];    // then search in the mainWindows text
  1834.     for(i = 0; i < [cellList count]; i++)            // add all other texts
  1835.         [textList addObjectIfAbsent:[[cellList objectAt:i] text]];
  1836.     [textList addObjectIfAbsent:superText];            // if the superWindow is not opened, add it at the end
  1837.     [textList addObjectIfAbsent:filterText];
  1838.     return textList;
  1839.     } else if(mainWindow == myWindow) {        // return only the text objects currently selected in the matrix
  1840.     [myMatrix getSelectedCells:textList];
  1841.     return textList;
  1842.     } else if(mainWindow == superWindow) {
  1843.     [textList addObject:superText];
  1844.     return textList;
  1845.     } else if(mainWindow == filterWindow) {
  1846.     [textList addObject:filterText];
  1847.     return textList;
  1848.     } else if(mainWindow == helpWindow) {
  1849.     [textList addObject:helpText];
  1850.     return textList;
  1851.     } else if((mainWindow != nil) && ([[mainWindow delegate] class] == [SpyTextFieldCell class])) {
  1852.     [textList addObject:[[mainWindow delegate] text]];
  1853.     return textList;
  1854.     } else {
  1855.     [textList free];
  1856.     return nil;
  1857.     }
  1858. }
  1859.  
  1860. - superFilenameClick:sender
  1861. {
  1862.     List *selectedCellsList = [tmpList empty];
  1863.     unsigned int i, max, state = [[sender selectedCell] tag]; 
  1864.     PopUpList *popupList = [[superFilenameButton cell] target];
  1865.     Matrix *popupMatrix = [popupList itemList];
  1866.  
  1867.     [myMatrix getSelectedCells:selectedCellsList];
  1868.     max = [selectedCellsList count];
  1869.     for(i = 0; i < max; i++)
  1870.     [[selectedCellsList objectAt:i] setSuperCopyFilename:state];
  1871.     
  1872.     [popupMatrix selectCellWithTag:state];
  1873.     [superFilenameButton setTitle:[[popupMatrix findCellWithTag:state] title]];
  1874.  
  1875.     return self;
  1876. }
  1877.  
  1878. - prefSuperFilenameClick:sender
  1879. {
  1880.     PopUpList *popupList = [[prefSuperFilenameButton cell] target];
  1881.     Matrix *popupMatrix = [popupList itemList];
  1882.     unsigned int state = [[sender selectedCell] tag];
  1883.  
  1884.     prefSuperCopyFilename = state;
  1885.     [popupMatrix selectCellWithTag:state];
  1886.     [prefSuperFilenameButton setTitle:[[popupMatrix findCellWithTag:state] title]];
  1887.     return self;
  1888. }
  1889.  
  1890. - timeClick:sender
  1891. {
  1892.     List *selectedCellsList;
  1893.     unsigned int i, max;
  1894.     BOOL state = [sender state];
  1895.  
  1896.     selectedCellsList = [tmpList empty];
  1897.     [myMatrix getSelectedCells:selectedCellsList];
  1898.     max = [selectedCellsList count];
  1899.     for(i = 0; i < max; i++)
  1900.     [[selectedCellsList objectAt:i] setTimeStamp:state];
  1901.     return self;
  1902. }
  1903.  
  1904. - prefTimeClick:sender
  1905. {
  1906.     prefTimeStamp = [sender state];
  1907.     return self;
  1908. }
  1909.  
  1910. - spytypeClick:sender
  1911. {
  1912.     unsigned int i, max;
  1913.     int tag = [[sender selectedCell] tag];
  1914.     
  1915.     [tmpList empty];
  1916.     [myMatrix getSelectedCells:tmpList];
  1917.     max = [tmpList count];
  1918.     for(i = 0; i < max; i++)
  1919.     [[tmpList objectAt:i] setSpytype:(unsigned short int)tag];
  1920.     [myMatrix display];
  1921.     return self;
  1922. }
  1923.  
  1924. - prefSpytypeClick:sender
  1925. {
  1926.     prefSpytype = (unsigned short int)[[sender selectedCell] tag];
  1927.     return self;
  1928. }
  1929.  
  1930. - showExistenceLog:sender
  1931. {
  1932.     return self;
  1933. }
  1934.  
  1935. - colorChanged:sender
  1936. {
  1937.     List *selectedCellsList = [tmpList empty];
  1938.     unsigned int i, max;
  1939.     NXColor color = [superColorWell color];
  1940.  
  1941.     [myMatrix getSelectedCells:selectedCellsList];
  1942.     max = [selectedCellsList count];
  1943.     for(i = 0; i < max; i++) {
  1944.     [[selectedCellsList objectAt:i] setColor:color];
  1945.     }
  1946.     [myMatrix display];
  1947.     return self;
  1948. }
  1949.  
  1950. - prefColorChanged:sender
  1951. {
  1952.     prefColor = [sender color];
  1953.     return self;
  1954. }
  1955.  
  1956. - (NXColor)prefColor
  1957. {
  1958.     return prefColor;
  1959. }
  1960.  
  1961. - changeFont:sender
  1962. {
  1963.     List *selectedCellsList = [tmpList empty];
  1964.     unsigned int i, max;
  1965.     id actCell;
  1966.  
  1967.     if([NXApp keyWindow] != preferencesPanel) {
  1968.     [fontTextField setFont:[sender convertFont:[fontTextField font]]];
  1969.     [myMatrix getSelectedCells:selectedCellsList];
  1970.     max = [selectedCellsList count];
  1971.     for(i = 0; i < max; i++) {
  1972.         actCell = [selectedCellsList objectAt:i];
  1973.         [actCell setSpyFont:[sender convertFont:[actCell spyFont]]];
  1974.     }
  1975.     } else {
  1976.     [prefFontTextField setFont:[sender convertFont:[prefFontTextField font]]];
  1977.     prefFont = [prefFontTextField font];
  1978.     }
  1979.     return self;
  1980. }
  1981.  
  1982. - showFontPanel:sender
  1983. {
  1984.     return [myFontManager orderFrontFontPanel:sender];
  1985. }
  1986.  
  1987. - setMaxLines:sender
  1988. {
  1989.     int oldMaxLines = maxLines;
  1990.     if((sender == maxLinesScroller) || (sender == maxLinesTextField)) {
  1991.     maxLines = [sender intValue];
  1992.     if(maxLines < 10)
  1993.         maxLines = 10;
  1994.     if(maxLines > INT_MAX)
  1995.         maxLines = INT_MAX;
  1996.     if(sender == maxLinesScroller)            // set the other one to the correct value
  1997.         [maxLinesTextField setIntValue:maxLines];
  1998.     else
  1999.         [maxLinesScroller setIntValue:maxLines];
  2000.     } else {                        // so it must be the matrix of ButtonCells
  2001.     maxLineState = [[sender selectedCell] tag];
  2002.     [maxLinesScroller setEnabled:maxLineState];
  2003.     [maxLinesTextField setEnabled:maxLineState];
  2004.     }
  2005.     if(oldMaxLines != maxLines) {
  2006.     List *selectedCellsList = [tmpList empty];
  2007.     unsigned int i, max;
  2008.     int state = (maxLineState ? maxLines : 0);
  2009.  
  2010.     [myMatrix getSelectedCells:selectedCellsList];
  2011.     max = [selectedCellsList count];
  2012.     for(i = 0; i < max; i++)
  2013.         [(SpyTextFieldCell *)[selectedCellsList objectAt:i] setMaxLines:state];
  2014.     }
  2015.     return self;
  2016. }
  2017.  
  2018. - (int)maxLines;
  2019. {
  2020.     return maxLines;
  2021. }
  2022.  
  2023. - shortSuperText
  2024. {
  2025.     int textLen = [superText textLength];
  2026.     int textLines = [superText lineFromPosition:textLen];
  2027. #ifdef DEBUG
  2028.     assert(maxLines != 0);
  2029. #endif
  2030.     if(textLines > maxLines)
  2031.     [[superText setSel:0 :[superText positionFromLine:textLines - maxLines]] replaceSel:""];
  2032.     return self;
  2033. }
  2034.  
  2035. - addWindow:sender;
  2036. {
  2037.     if(nrOpenWindows++ == 0) {
  2038.     if(!myWindowIsVisible && inspectorPanel && [inspectorPanel isVisible]) {
  2039.         [self setInspectorToView:[inspectorNormalView contentView]];
  2040.         [myMatrix selectCell:sender];
  2041.         [self singleClick:self];
  2042.     }
  2043.     }
  2044.     return self;
  2045. }
  2046.  
  2047. - existenceMatrix
  2048. {
  2049.     return myExistenceMatrix;
  2050. }
  2051.  
  2052. - showExistencelogRegardless
  2053. {
  2054.     [existencelogWindow orderFrontRegardless];
  2055.     return self;
  2056. }
  2057.  
  2058. - window
  2059. {
  2060.     return [NXApp mainWindow];
  2061. }
  2062.  
  2063. @end
  2064.  
  2065. void alarmHandler(DPSTimedEntry te, double timeNow, void *data)
  2066. {
  2067.     [(id)data checkFiles];
  2068. }
  2069.