From c724dc146e8391018e768542213fa1ec85ecb43b Mon Sep 17 00:00:00 2001
From: Y-Less <alex@y-less.com>
Date: Fri, 11 Mar 2022 10:42:52 +0000
Subject: [PATCH 1/2] Add ".pwn" to the official list of extensions.

It is used by almost all scripts, so why shouldn't it be officially supported?
---
 source/compiler/sc2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c
index 0895dfac..62b440e1 100644
--- a/source/compiler/sc2.c
+++ b/source/compiler/sc2.c
@@ -134,7 +134,7 @@ SC_FUNC void clearstk(void)
 
 SC_FUNC int plungequalifiedfile(char *name)
 {
-static char extensions[][6] = { "", ".inc", ".p", ".pawn" };
+  static char extensions[][6] = { "", ".inc", ".p", ".pawn", ".pwn" };
   int found;
   struct stat st;
   FILE *fp;

From 39b8255173f0001fa65f20308f281ac774d0feeb Mon Sep 17 00:00:00 2001
From: Y_Less <git-athena@y-less.com>
Date: Sat, 19 Mar 2022 18:20:06 +0000
Subject: [PATCH 2/2] Fix a regression with new file extensions finding
 different files.

---
 source/compiler/sc.h  |  2 +-
 source/compiler/sc1.c |  4 ++--
 source/compiler/sc2.c | 15 ++++++++-------
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/source/compiler/sc.h b/source/compiler/sc.h
index d5576510..cfeebd2b 100644
--- a/source/compiler/sc.h
+++ b/source/compiler/sc.h
@@ -727,7 +727,7 @@ SC_FUNC cell do_static_check(int use_warning);
 SC_FUNC void pushstk(stkitem val);
 SC_FUNC stkitem popstk(void);
 SC_FUNC void clearstk(void);
-SC_FUNC int plungequalifiedfile(char *name);  /* explicit path included */
+SC_FUNC int plungequalifiedfile(char *name,char new_extensions);  /* explicit path included */
 SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths);   /* search through "include" paths */
 SC_FUNC int number(cell *val,const unsigned char *curptr);
 SC_FUNC void preprocess(void);
diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c
index cedcbcbb..ef385d59 100644
--- a/source/compiler/sc1.c
+++ b/source/compiler/sc1.c
@@ -664,7 +664,7 @@ int pc_compile(int argc, char *argv[])
       if (strcmp(incfname,sDEF_PREFIX)==0) {
         plungefile(incfname,FALSE,TRUE);    /* parse "default.inc" */
       } else {
-        if (!plungequalifiedfile(incfname)) /* parse "prefix" include file */
+        if (!plungequalifiedfile(incfname,1)) /* parse "prefix" include file */
           error(100,incfname);          /* cannot read from ... (fatal error) */
       } /* if */
     } /* if */
@@ -755,7 +755,7 @@ int pc_compile(int argc, char *argv[])
     if (strcmp(incfname,sDEF_PREFIX)==0)
       plungefile(incfname,FALSE,TRUE);  /* parse "default.inc" (again) */
     else
-      plungequalifiedfile(incfname);    /* parse implicit include file (again) */
+      plungequalifiedfile(incfname,1);    /* parse implicit include file (again) */
   } /* if */
   warnstack_init();
   preprocess();                         /* fetch first line */
diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c
index 62b440e1..6ba14039 100644
--- a/source/compiler/sc2.c
+++ b/source/compiler/sc2.c
@@ -132,16 +132,17 @@ SC_FUNC void clearstk(void)
   assert(stktop==0);
 }
 
-SC_FUNC int plungequalifiedfile(char *name)
+SC_FUNC int plungequalifiedfile(char *name,char new_extensions)
 {
-  static char extensions[][6] = { "", ".inc", ".p", ".pawn", ".pwn" };
+  unsigned int skipped_extensions=new_extensions?0:1;
+  static char extensions[][6] = { "", ".inc", ".p", ".pawn", ".pwn"};
   int found;
   struct stat st;
   FILE *fp;
   char *path;
   char *real_path;
   char *ext;
-  int ext_idx;
+  unsigned int ext_idx;
 
   fp=NULL;
   ext_idx=0;
@@ -178,7 +179,7 @@ SC_FUNC int plungequalifiedfile(char *name)
       found=FALSE;
     } /* if */
     ext_idx++;
-  } while (!found && ext_idx<arraysize(extensions));
+  } while (!found && ext_idx<arraysize(extensions)-skipped_extensions);
   if (!found) {
     *ext='\0';                  /* restore filename */
     free(path);
@@ -227,7 +228,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
   int result=FALSE;
 
   if (try_currentpath) {
-    result=plungequalifiedfile(name);
+    result=plungequalifiedfile(name,0);
     if (!result) {
       /* failed to open the file in the active directory, try to open the file
        * in the same directory as the current file --but first check whether
@@ -240,7 +241,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
           char path[_MAX_PATH];
           strlcpy(path,inpfname,len+1);
           strlcat(path,name,arraysize(path));
-          result=plungequalifiedfile(path);
+          result=plungequalifiedfile(path,1);
         } /* if */
       } /* if */
     } /* if */
@@ -253,7 +254,7 @@ SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
       char path[_MAX_PATH];
       strlcpy(path,ptr,arraysize(path));
       strlcat(path,name,arraysize(path));
-      result=plungequalifiedfile(path);
+      result=plungequalifiedfile(path,1);
     } /* for */
   } /* if */
   return result;