Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Anime and Manga management

Name: Anonymous 2009-09-26 10:28

I'm searching for an easy way to organize your Anime and Manga collection. Something like this

./anime "The Melanch*" +
The Melancholy of Suzumiya Haruhi Episode 110 -> Episode 111

If it doesn't exist yet, code it for me, you are prog after all.

Name: Anonymous 2009-09-28 10:27

>>61
Right, but if you notice inotify actually is able to return you relative paths too, so that number does not suffice if the path is too long. You should be using PATH_MAX + sizeof (struct inotify_event) to be completely on the safe side.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <time.h>

#include <unistd.h>

#include <sys/inotify.h>

/*
struct inotify_event {
int      wd;       // Watch descriptor
uint32_t mask;     // Mask of events
uint32_t cookie;   // Unique cookie associating related
                      events (for rename(2))
uint32_t len;      // Size of name field
char     name[];   // Optional null-terminated name
};
*/

#define WRITE_LOG "inotify.log"

int main(int argc, char **argv) {
  int *pfd, watch_fd[10], i, iev = inotify_init();
  struct inotify_event *s;
  size_t sn = sizeof *s + FILENAME_MAX; /* should be path max */
  ssize_t n;
  FILE *log;
  clock_t t;

  if(iev == -1) {
    perror("inotify_init");
    exit(EXIT_FAILURE);
  }
  s = malloc(sn);
  if(s == NULL) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  for(pfd = watch_fd, i = 1; i < argc; i++) {
    *pfd = inotify_add_watch(iev, argv[i], IN_ACCESS | IN_DELETE);
    if(*pfd == -1)
      perror("inotify_add_watch");
    else pfd++;
  }
  i = pfd - watch_fd;
#ifdef DEBUG
  // BUG: Duplicate filenames report additions
  printf("%d added to watch list\n", i);
#endif

  log = fopen(WRITE_LOG, "w");
  if(log == NULL) log = stdout;
  /*
 {
    perror(WRITE_LOG);
    free(s);
    exit(EXIT_FAILURE);
  }
  */
  while((n = read(iev, s, sn)) > 0) {
    t = clock();
    fprintf(log, "%s occured in %d at %s!\n", s->mask == IN_ACCESS ?
            "ACCESS" : "DELETION", s->wd, ctime(&t));
    fflush(log);
  }
  free(s);
  close(iev);
  return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List