- int cflag = 0; /* print in order of creation time */
- int nflag = 0; /* just print the number of jobs in
- queue */
- int usage(); /* print usage info and exit */
- int creation(); /* sort jobs by date of creation */
- int alphasort(); /* sort jobs by date of execution */
- int filewanted(); /* should a file be included in queue?*/
- int printqueue(); /* print the queue */
- int countfiles(); /* count the number of files in queue
- for a given person */
- char **namelist; /* array of specific name(s) requested*/
-
-
- --argc, ++argv;
-
- /*
- * Interpret command line flags if they exist.
- */
- while (argc > 0 && **argv == '-') {
- (*argv)++;
- while (**argv) switch (*(*argv)++) {
-
- case 'c' : cflag++;
- break;
-
- case 'n' : nflag++;
- break;
-
- default : usage();
-
- }
- --argc, ++argv;
- }
-
- /*
- * If a certain name (or names) is requested, set a pointer to the
- * beginning of the list.
- */
- if (**argv) {
- ++namewanted;
- namelist = argv;
- }
-
- /*
- * Move to the spooling area and scan the directory, placing the
- * files in the queue structure. The queue comes back sorted by
- * execution time or creation time.
- */
- if (chdir(ATDIR) == -1) {
- perror(ATDIR);
- exit(1);
- }
- if ((numentries = scandir(".",&queue,filewanted, (cflag) ? creation :
- alphasort)) < 0) {
- perror(ATDIR);
- exit(1);
- }
-
- /*
- * Either print a message stating:
- *
- * 1) that the spooling area is empty.
- * 2) the number of jobs in the spooling area.
- * 3) the number of jobs in the spooling area belonging to
- * a certain person.
- * 4) that the person requested doesn't have any files in the
- * spooling area.
- *
- * or send the queue off to "printqueue" for printing.
- *
- * This whole process might seem a bit elaborate, but it's worthwhile
- * to print some informative messages for the user.
- *
- */
- if ((numentries == 0) && (!nflag)) {
- printf("no files in queue.\n");
- exit(0);
- }
- if (nflag) {
- printf("%d\n",(namewanted) ? countfiles(namelist) : numentries);
- exit(0);
- }
- if ((namewanted) && (countfiles(namelist) == 0)) {
- printf("no files for %s.\n", (argc == 1) ?
- *argv : "specified users");
- exit(0);
- }
- printqueue(namelist);
- exit(0);
+ int cflag = 0; /* print in order of creation time */
+ int nflag = 0; /* just print the number of jobs in
+ queue */
+ int usage(); /* print usage info and exit */
+ int creation(); /* sort jobs by date of creation */
+ int alphasort(); /* sort jobs by date of execution */
+ int filewanted(); /* should a file be included in queue?*/
+ int printqueue(); /* print the queue */
+ int countfiles(); /* count the number of files in queue
+ for a given person */
+ char **namelist = &nullentry; /* array of specific name(s) requested*/
+
+
+ --argc, ++argv;
+
+ /*
+ * Interpret command line flags if they exist.
+ */
+ while (argc > 0 && **argv == '-') {
+ (*argv)++;
+ while (**argv) switch (*(*argv)++) {
+
+ case 'c' : cflag++;
+ break;
+
+ case 'n' : nflag++;
+ break;
+
+ default : usage();
+
+ }
+ --argc, ++argv;
+ }
+
+ /*
+ * If a certain name (or names) is requested, set a pointer to the
+ * beginning of the list.
+ */
+ if (argc > 0) {
+ ++namewanted;
+ namelist = argv;
+ }
+
+ /*
+ * Move to the spooling area and scan the directory, placing the
+ * files in the queue structure. The queue comes back sorted by
+ * execution time or creation time.
+ */
+ if (chdir(_PATH_ATDIR) == -1) {
+ perror(_PATH_ATDIR);
+ exit(1);
+ }
+ if ((numentries = scandir(".",&queue,filewanted, (cflag) ? creation :
+ alphasort)) < 0) {
+ perror(_PATH_ATDIR);
+ exit(1);
+ }
+
+ /*
+ * Either print a message stating:
+ *
+ * 1) that the spooling area is empty.
+ * 2) the number of jobs in the spooling area.
+ * 3) the number of jobs in the spooling area belonging to
+ * a certain person.
+ * 4) that the person requested doesn't have any files in the
+ * spooling area.
+ *
+ * or send the queue off to "printqueue" for printing.
+ *
+ * This whole process might seem a bit elaborate, but it's worthwhile
+ * to print some informative messages for the user.
+ *
+ */
+ if ((numentries == 0) && (!nflag)) {
+ printf("no files in queue.\n");
+ exit(0);
+ }
+ if (nflag) {
+ printf("%d\n",(namewanted) ? countfiles(namelist) : numentries);
+ exit(0);
+ }
+ if ((namewanted) && (countfiles(namelist) == 0)) {
+ printf("no files for %s.\n", (argc == 1) ?
+ *argv : "specified users");
+ exit(0);
+ }
+ printqueue(namelist);
+ exit(0);