]> git.sur5r.net Git - cc65/blobdiff - samples/enumdevdir.c
Minor math optimizations
[cc65] / samples / enumdevdir.c
index 5969c2339423d3fe65018810048bc955d49b988c..ce2dc99ec1e44360770a76db65eecad6ce0aa47b 100644 (file)
@@ -1,19 +1,19 @@
 /*
- * Enumerate devices, directories and files.
- *
- * 2012-10-15, Oliver Schmidt (ol.sc@web.de)
- *
- */
+** Enumerate devices, directories and files.
+**
+** 2012-10-15, Oliver Schmidt (ol.sc@web.de)
+**
+*/
 
 
 
 #include <stdio.h>
-#include <conio.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <device.h>
 #include <dirent.h>
+#include <cc65.h>
 
 
 void printdir (char *newdir)
@@ -30,21 +30,21 @@ void printdir (char *newdir)
     if (chdir (newdir)) {
 
         /* If chdir() fails we just print the
-         * directory name - as done for files.
-         */
+        ** directory name - as done for files.
+        */
         printf ("  Dir  %s\n", newdir);
         return;
     }
 
     /* We call getcwd() in order to print the
-     * absolute pathname for a subdirectory.
-     */
+    ** absolute pathname for a subdirectory.
+    */
     getcwd (curdir, sizeof (curdir));
     printf (" Dir %s:\n", curdir);
 
     /* Calling opendir() always with "." avoids
-     * fiddling around with pathname separators.
-     */
+    ** fiddling around with pathname separators.
+    */
     dir = opendir (".");
     while (ent = readdir (dir)) {
 
@@ -54,9 +54,9 @@ void printdir (char *newdir)
         }
 
         /* We defer handling of subdirectories until we're done with the
-         * current one as several targets don't support other disk i/o
-         * while reading a directory (see cc65 readdir() doc for more).
-         */
+        ** current one as several targets don't support other disk i/o
+        ** while reading a directory (see cc65 readdir() doc for more).
+        */
         if (_DE_ISDIR (ent->d_type)) {
             subdirs = realloc (subdirs, FILENAME_MAX * (dirnum + 1));
             strcpy (subdirs + FILENAME_MAX * dirnum++, ent->d_name);
@@ -79,15 +79,15 @@ void main (void)
     char devicedir[FILENAME_MAX];
 
     /* Calling getfirstdevice()/getnextdevice() does _not_ turn on the motor
-     * of a drive-type device and does _not_ check for a disk in the drive.
-     */
+    ** of a drive-type device and does _not_ check for a disk in the drive.
+    */
     device = getfirstdevice ();
     while (device != INVALID_DEVICE) {
         printf ("Device %d:\n", device);
 
         /* Calling getdevicedir() _does_ check for a (formatted) disk in a
-         * floppy-disk-type device and returns NULL if that check fails.
-         */
+        ** floppy-disk-type device and returns NULL if that check fails.
+        */
         if (getdevicedir (device, devicedir, sizeof (devicedir))) {
             printdir (devicedir);
         } else {
@@ -97,5 +97,7 @@ void main (void)
         device = getnextdevice (device);
     }
 
-    cgetc ();
+    if (doesclrscrafterexit ()) {
+        getchar ();
+    }
 }