This is squeeze.c in view mode; [Download] [Up]
/* * squeeze.c - A utility to check a set of .tiff files for compression "none". * Then use tiffutil to compress them with LZW compression. * * Version 1.0, Michael.Glenn@Dartmouth.edu, March 3, 1993. */ #include <stdio.h> #include <sys/types.h> #include <sys/dir.h> #include <sys/stat.h> #define SCRATCH_FILE "./squeeze_scratch" #define SQUEEZE_COMMAND "tiffutil -lzw \"%s\" -out %s 2>>/dev/null" extern needs_fixing(char *); file_exists(char *fname) { struct stat s; return stat(fname, &s) == 0; } is_tiff_file(char *fname) { int l; return (l=strlen(fname)) > 4 && !strcmp(&(fname[l-5]), ".tiff"); } do_file(char *fname) { char buff[256]; struct stat s; DIR *dp; struct direct *p; if (lstat(fname,&s) == -1) { fprintf(stderr, "Could not find %s\n", fname); return; } if ((s.st_mode & S_IFMT) == S_IFLNK) { if (is_tiff_file(fname)) printf("Ignoring symbolic link at %s\n", fname); else if (stat(fname,&s) == -1) fprintf(stderr, "Could not follow link at %s\n", fname); else if ((s.st_mode & S_IFMT) == S_IFDIR) printf("Ignoring symbolic link at %s\n", fname); return; } if ((s.st_mode & S_IFMT) == S_IFDIR) { if (!(dp=opendir(fname))) { fprintf (stderr, "Failed to open directory %s\n", fname); return; } while (p=readdir(dp)) if (strcmp(p->d_name,".") && strcmp(p->d_name,"..")) { sprintf(buff,"%s/%s", fname, p->d_name); do_file(buff); } closedir(dp); return; } if (is_tiff_file(fname)) { if (!needs_fixing(fname)) printf("Skipping %s\n", fname); else { printf("Squeezing %s\n", fname); sprintf(buff, SQUEEZE_COMMAND, fname, SCRATCH_FILE); system(buff); if (file_exists(SCRATCH_FILE)) rename(SCRATCH_FILE, fname); else fprintf(stderr, "File %s failed.\n", fname); } } } main(int argc, char **argv) { if (argc == 1) { fprintf(stderr, "usage: %s file1 [file2 file3 ...]\n", argv[0]); fprintf(stderr, " %s all\n", argv[0]); exit(1); } if (argc == 2 && !strcmp(argv[1], "all")) do_file("."); else for (; argc > 1; argc--, argv++) do_file(argv[1]); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.