home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Utilities / FileSpy-1.1-MIHS / cSwapfile.m < prev    next >
Encoding:
Text File  |  1996-04-12  |  3.3 KB  |  117 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. @implementation Controller(Swapfile)
  34.  
  35. - swapfilenameClick:sender
  36. {
  37.     const char *str = [prefSwapfileTextField stringValue];
  38.     
  39.     if(*str == '\000') {
  40.     if(swapfilename != NULL) {
  41.         free(swapfilename);
  42.         swapfilename = NULL;
  43.         [prefSwapfileSizeTextField setStringValue:""];
  44.         [self stopSpyIfNeeded];
  45.     }
  46.     return self;
  47.     }
  48.     if((swapfilename != NULL) && (strlen(swapfilename) < strlen(str))) {
  49.     free(swapfilename);
  50.     swapfilename = NULL;
  51.     }
  52.     if(swapfilename == NULL)  {
  53.     swapfilename = (char *)malloc(strlen(str)+1);
  54.     }
  55.     strcpy(swapfilename, str);
  56.     [self startSpyIfNeeded];
  57.     return self;
  58. }
  59.  
  60. - swapfileSetNameClick:sender
  61. {
  62.     id openPanel;
  63.     const char *const *files;
  64.     char tmpfile[MAXFILENAMELENGHT];
  65.     const char *file = swapfilename;
  66.  
  67.     if(swapfilename == NULL)
  68.     file = "/private/vm";
  69.     openPanel = [OpenPanel new];
  70.     [openPanel chooseDirectories:NO];
  71.     [openPanel allowMultipleFiles:NO];
  72.     if([openPanel runModalForDirectory:file file:NULL] == NX_OKTAG) {
  73.     if((files = [openPanel filenames]) != (const char *const *)0) {
  74.         sprintf(tmpfile, "%s/%s", [openPanel directory], files[0]);
  75.         [prefSwapfileTextField setStringValue:tmpfile];
  76.         [self swapfilenameClick:self];
  77.     }
  78.     }
  79.     return self;
  80. }
  81.  
  82. - swapfilesizeClick:sender
  83. {
  84.     swapfilesize = [sender intValue] * 1024*1024;
  85.     [self startSpyIfNeeded];
  86.     return self;
  87. }
  88.  
  89. - updateSwapfile
  90. {
  91.     struct stat st;
  92.     
  93.     if(stat(swapfilename, &st) < 0 && !swapfileError) {
  94.     switch(errno) {
  95.         case ENOENT:
  96.         case ENOTDIR:
  97.         printf("filespy: swapfile %s does not exist.\n", swapfilename);
  98.         break;
  99.         case EACCES:
  100.         printf("filespy: can't access swapfile %s.\n", swapfilename);
  101.         break;
  102.         default:
  103.         perror("filespy: stat");
  104.     }
  105.     swapfileError = YES;
  106.     } else if(!swapfileTooBig && st.st_size > swapfilesize) {
  107.     printf("filespy: swapfile %s reached size of %.2f MB.\n", swapfilename, (float)st.st_size/(1024*1024));
  108.     swapfileTooBig = YES;
  109.     } else if(swapfileTooBig && st.st_size <= swapfilesize) {
  110.     printf("filespy: swapfile %s shrunk to %.2f MB.\n", swapfilename, (float)st.st_size/(1024*1024));
  111.     swapfileTooBig = NO;
  112.     }
  113.     return self;
  114. }
  115.  
  116. @end
  117.