Quellcode durchsuchen

Better error message for non-existing files ("not found" instead of the vague "is not a regular file").

git-svn-id: file:///var/svn/tigccpp/trunk@508 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler vor 18 Jahren
Ursprung
Commit
52056e26d3
3 geänderte Dateien mit 21 neuen und 8 gelöschten Zeilen
  1. 18 6
      ktigcc/mainform.ui.h
  2. 2 1
      ktigcc/tpr.cxx
  3. 1 1
      ktigcc/tpr.h

+ 18 - 6
ktigcc/mainform.ui.h

@@ -816,9 +816,15 @@ void MainForm::addRecent(const QString &fileName)
 QListViewItem * MainForm::openFile(QListViewItem * category, QListViewItem * parent, const QString &fileCaption, const QString &fileName)
 {
   QString fileText;
-  if (getPathType(fileName)!=PATH_FILE) {
-    KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
-    return NULL;
+  switch (getPathType(fileName)) {
+    case PATH_FILE: // OK
+      break;
+    case PATH_NOTFOUND:
+      KMessageBox::error(this,QString("File \'%1\' not found").arg(fileName));
+      return NULL;
+    default:
+      KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
+      return NULL;
   }
   if (IS_EDITABLE_CATEGORY(category)) {
     fileText=loadFileText(fileName);
@@ -968,9 +974,15 @@ void MainForm::openProject(const QString &fileName)
   TPRDataStruct TPRData;
   KURL dir;
   dir.setPath(fileName);
-  if (getPathType(fileName)!=PATH_FILE) {
-    KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
-    return;
+  switch (getPathType(fileName)) {
+    case PATH_FILE: // OK
+      break;
+    case PATH_NOTFOUND:
+      KMessageBox::error(this,QString("File \'%1\' not found").arg(fileName));
+      return;
+    default:
+      KMessageBox::error(this,QString("\'%1\' is not a regular file").arg(fileName));
+      return;
   }
   int ret=loadTPR(fileName, &TPRData);
   if (ret == -1) {

+ 2 - 1
ktigcc/tpr.cxx

@@ -23,6 +23,7 @@
 
 #include <cstdio>
 #include <cstdlib>
+#include <cerrno>
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/dir.h>
@@ -819,7 +820,7 @@ int getPathType(const QString &thePath)
   struct stat statvar;
   int result=stat(thePath,&statvar);
   if (result)
-    return PATH_ERROR;
+    return errno==ENOENT?PATH_NOTFOUND:PATH_ERROR;
   if (statvar.st_mode&S_IFDIR)
     return PATH_FOLDER;
   if (statvar.st_mode&S_IFREG)

+ 1 - 1
ktigcc/tpr.h

@@ -148,7 +148,7 @@ typedef struct
   TPRFileList quill_files;
 } TPRDataStruct;
 
-enum {PATH_ERROR,PATH_FILE,PATH_FOLDER}; //return types for getPathType
+enum {PATH_ERROR,PATH_NOTFOUND,PATH_FILE,PATH_FOLDER}; //return types for getPathType
 
 const char *smartAscii(const QString &s);