home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / ArchiveUtils / Uncompress / Source / UncompressApp.m < prev   
Encoding:
Text File  |  1990-07-02  |  2.7 KB  |  128 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "UncompressApp.h"
  5. #import <stdio.h>
  6. #import <string.h>
  7. #import <appkit/Form.h>
  8. #import <appkit/Panel.h>
  9. #import <appkit/Text.h>
  10. #import <appkit/OpenPanel.h>
  11.  
  12. @implementation UncompressApp
  13.  
  14. - appDidInit:sender
  15. {
  16.     openPanel = [OpenPanel new]; 
  17.     [openPanel allowMultipleFiles:YES]; 
  18.     mode = NO;
  19.     [nameWindow selectTextAt:0];
  20.     [[nameWindow window] makeKeyWindow];
  21.     return self;
  22. }
  23.  
  24. - setMode:sender
  25. {
  26.     mode = [sender intValue];
  27.     [nameWindow  selectTextAt:0];
  28.     return self;
  29. }
  30.  
  31. - setNameWindow:anObject
  32. {
  33.     nameWindow = anObject;
  34.     return self;
  35. }
  36.  
  37. - go:sender
  38. {
  39.     const char *fname;
  40.     id textObj;
  41.     int end, errnum;
  42.     char command[BUFSIZ], tmpbuf[3];
  43.     int system();
  44.  
  45.     fname = [nameWindow stringValueAt:0];
  46.     [nameWindow  selectTextAt:0];
  47.     textObj = [nameWindow currentEditor];
  48.     end = [textObj textLength];
  49.  
  50.     // Select Uncompress or Compress Command and fix string in nameWindow
  51.     [textObj getSubstring:tmpbuf start:end-2 length:2];
  52.     if (mode == NO) {
  53.     strcpy(command,"/usr/ucb/uncompress ");
  54.     if (strncmp(tmpbuf,".Z",2)) {
  55.         NXRunAlertPanel("Uncompress","File is not in compressed format", NULL, NULL, NULL);
  56.         return nil;
  57.     }
  58.     [textObj setSel:end-2 :end];
  59.     [textObj delete:nil];
  60.     }
  61.     else {
  62.     strcpy(command,"/usr/ucb/compress ");
  63.     if ( strncmp(tmpbuf,".Z",2) ) {
  64.         [textObj setSel:end :end];
  65.         [textObj replaceSel:".Z"];
  66.     } else {
  67.         NXRunAlertPanel("Compress","File is already compressed", NULL, NULL, NULL);
  68.         return nil;
  69.     }
  70.     }
  71.  
  72.     // Execute command
  73.     strcat(command,fname);
  74.     if (errnum = system(command)) {
  75.     char *errorString = strerror(errnum);
  76.     NXRunAlertPanel("Uncompress","Didn't work! - %s", NULL, NULL, NULL,errorString);
  77.     return nil;
  78.     }
  79.  
  80.     return self;
  81. }
  82.  
  83. - (BOOL)appAcceptsAnotherFile:sender
  84. {
  85.     return YES;
  86. }
  87.  
  88. - (int)appOpenFile:(const char *)fileName type:(const char *)aType
  89. {
  90.     [nameWindow setStringValue:fileName at:0];
  91.     [nameWindow selectTextAt:0];
  92.     return YES;
  93.     //[self go:nil];
  94. }
  95.  
  96. - setFile:sender
  97. {
  98.     const char *directory;
  99.     const char *const *files;
  100.     char path[BUFSIZ];
  101.     static const char *const dataType[2] = {"Z", NULL};
  102.  
  103.     if ([openPanel runModalForTypes:(mode==NO)?dataType:NULL]) {
  104.     files = [openPanel filenames];
  105.     directory = [openPanel directory];
  106.     }
  107.     else return nil;
  108.  
  109.     if (directory && *directory && files && *files) {
  110.     const char *const *ptr;
  111.     for(ptr = files; *ptr; ptr++) {
  112.         strcat(path, directory);
  113.         strcat(path, "/");
  114.         strcat(path, *ptr);
  115.         strcat(path," ");
  116.     }
  117.     path[strlen(path)-1] = 0;
  118.     [nameWindow setStringValue:path at:0];
  119.     [nameWindow selectTextAt:0];
  120.     } else {
  121.     NXRunAlertPanel("Uncompress","Null file name",NULL,NULL,NULL);
  122.     return nil;
  123.     }
  124.     return self;
  125. }
  126.  
  127. @end
  128.