X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FDirMonitor.c;fp=sources%2FDirMonitor.c;h=c8fad95d3f079c29aee3aa52f9b57b3e9cb770d1;hp=0000000000000000000000000000000000000000;hb=e18f3ea57b725bc148f0d3443e384bf5270b2b9f;hpb=8fecd34eeb7db69bfa3cf2ca4b60ace29cad0356 diff --git a/sources/DirMonitor.c b/sources/DirMonitor.c new file mode 100644 index 0000000..c8fad95 --- /dev/null +++ b/sources/DirMonitor.c @@ -0,0 +1,107 @@ +/* DirMonitor.c + * + * Copyright (C) 2002 Simone Piccardi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/***************************************************************************** + * + * File DirMonitor: + * + * An example for shared memory use: monitor a directory status, + * saving data in a shared memory segment + * + * Author: S. Piccardi Jan. 2003 + * + * $Id: DirMonitor.c,v 1.1 2003/01/03 23:16:05 piccardi Exp $ + * + *****************************************************************************/ +#include +#include +#include /* directory */ +#include /* C standard library */ +#include + +#include "Gapil.h" + +/* Help printing routine */ +void usage(void); +/* computation function for DirScan */ +int ComputeValues(struct dirent * direntry); + +/* global variable for shared memory segment */ +int shmid; /* Shared memory identifier */ + +int main(int argc, char *argv[]) +{ + int i; + int mutex; + /* + * Input section: decode command line parameters + * Use getopt function + */ + opterr = 0; /* don't want writing to stderr */ + while ( (i = getopt(argc, argv, "hs:l:wrbf")) != -1) { + switch (i) { + /* + * Handling options + */ + case 'h': /* help option */ + printf("Wrong -h option use\n"); + usage(); + return -1; + break; + case '?': /* unrecognized options */ + printf("Unrecognized options -%c\n",optopt); + usage(); + default: /* should not reached */ + usage(); + } + } + /* *********************************************************** + * + * Options processing completed + * + * Main code beginning + * + * ***********************************************************/ + if ((argc - optind) != 1) { /* There must be remaing parameters */ + printf("Wrong number of arguments %d\n", argc - optind); + usage(); + } + + DirScan(argv[1], ComputeValues); + exit(0); +} +/* + * Routine to print file name and size inside DirScan + */ +int do_ls(struct dirent * direntry) +{ + struct stat data; + stat(direntry->d_name, &data); /* get stat data */ + printf("File: %s \t size: %d\n", direntry->d_name, data.st_size); + return 0; +} +/* + * routine to print usage info and exit + */ +void usage(void) { + printf("Program myls: list file in a directory \n"); + printf("Usage:\n"); + printf(" myls [-h] dirname \n"); + printf(" -h print this help\n"); + exit(1); +}