SA-MP Forums Archive
Strange #include behaviour? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Strange #include behaviour? (/showthread.php?tid=368485)



Strange #include behaviour? - Dan.. - 13.08.2012

Hello!

I've been trying to organize my gamemode in multiple files to make it look "cleaner", but I've ran into some issues lately and I can't find any explaination for them. Sometimes, when I use #include I can't include multiple files from the same folder. (* I'm not sure, but it this might be true, look down to see which files are included and which aren't.)

This is my main gamemode:

main.pwn
pawn Код:
#include <a_samp>

// ... a few 'system' includes

// ... some variables

#include "packages/mysql/header.pwn"    // yes, included
#include "packages/mysql/package.pwn"   // yes, included

// ... some more includes ...
packages/mysql/package.pwn
pawn Код:
#include "packages/mysql/cache/cache_get_field_content_float.pwn"   // yes, included
#include "packages/mysql/cache/cache_get_field_content_int.pwn"     // no, not included
#include "packages/mysql/cache/cache_get_row_float.pwn"             // no
#include "packages/mysql/cache/cache_get_row_int.pwn"               // no
#include "packages/mysql/event/OnQueryError.pwn"                    // yes
#include "packages/mysql/event/OnQueryFinish.pwn"                   // no
#include "packages/mysql/mysql_fetch_field_row_float.pwn"           // yes
#include "packages/mysql/mysql_fetch_field_row_int.pwn"             // no
All files exist and packages/mysql/*.pwn files are filled with some random functions, I've tried modifying them, but the output is the same.

EDIT: A guy on the IRC recommended me to use #include file_name instead of #include "file_name", but no differences.


Re: Strange #include behaviour? - Dan.. - 13.08.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
If you have two files with the same name - REGARDLESS OF FOLDER - only the first one will be included. Not sure if that's the issue here though. How are you determining if they're included or not?
Each file has a unique name and about determining if they are included or not.. well.. I make sure I don't use #include twice with the same file.


Re: Strange #include behaviour? - FalconX - 13.08.2012

For include what you have to do is, script and then save it (DONT COMPILE INCLUDES) in .inc extension and then use

pawn Код:
#include <your_include>
And whenever you want to edit the inc file you can open it from pawno and edit it then save it (don't compile again). And then compile your gm it will show errors there if ther is one.

I think that's a good way of including your small scripts with Gamemode. (I personally do this)

Edit: I m not sure what's wrong with your script everything work fine here and yes I read your thread xd


Re: Strange #include behaviour? - Vince - 13.08.2012

Errors, probably. Though I have noticed that the name of an include can not be longer than 14 characters (or was it 16?), including extension otherwise it won't work (properly).


Re: Strange #include behaviour? - Dan.. - 13.08.2012

Quote:
Originally Posted by FalconX
Посмотреть сообщение
For include what you have to do is, script and then save it (DONT COMPILE INCLUDES) in .inc extension and then use

pawn Код:
#include <your_include>
And whenever you want to edit the inc file you can open it from pawno and edit it then save it (don't compile again). And then compile your gm it will show errors there if ther is one.
You didn't read my thread, did you?

Quote:
Originally Posted by Vince
Посмотреть сообщение
Errors, probably. Though I have noticed that the name of an include can not be longer than 14 characters (or was it 16?), including extension otherwise it won't work (properly).
pawn Код:
#include "packages/mysql/cache/cache_get_field_content_float.pwn"   // yes, included
#include "packages/mysql/cache/cache_get_field_content_int.pwn"     // no, not included
Check this, the first one which has a longer name is included, but the second one isn't.


Re: Strange #include behaviour? - Vince - 13.08.2012

Well, go ahead and just try to give it shorter names, just to test. I've ran into a similar problem once and it was fixed when I shortened the name of the include.


Re: Strange #include behaviour? - Dan.. - 13.08.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
Well, go ahead and just try to give it shorter names, just to test. I've ran into a similar problem once and it was fixed when I shortened the name of the include.
WHAT THE FUCK?! That worked! I renamed the first file in a.pwn and the second one in b.pwn and now, both are getting included.

This issue is weird.


Re: Strange #include behaviour? - Dan.. - 13.08.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
Actually, if there is a max length then the truncated names may look the same and thus trigger the issue I mentioned.
Do you know if there is a way to change the max length of an include file name?


Re: Strange #include behaviour? - Dan.. - 13.08.2012

I thought it was closed-source. Is that right?


Re: Strange #include behaviour? - Dan.. - 13.08.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
No, PAWN is open-source and is publically available, hence it is used in SA:MP. The compiler has been modified with use with SA:MP and although the open source modifications were lost I believe they have been recovered.
Код:
/*  doinclude
 *
 *  Gets the name of an include file, pushes the old file on the stack and
 *  sets some options. This routine doesn't use lex(), since lex() doesn't
 *  recognize file names (and directories).
 *
 *  Global references: inpf     (altered)
 *                     inpfname (altered)
 *                     lptr     (altered)
 */
static void doinclude(int silent)
{
  char name[_MAX_PATH];
  char symname[sNAMEMAX];
  char *ptr;
  char c;
  int i, result;

  while (*lptr<=' ' && *lptr!='\0')         /* skip leading whitespace */
    lptr++;
  if (*lptr=='<' || *lptr=='\"') {
    c=(char)((*lptr=='\"') ? '\"' : '>');   /* termination character */
    lptr++;
    while (*lptr<=' ' && *lptr!='\0')       /* skip whitespace after quote */
      lptr++;
  } else {
    c='\0';
  } /* if */

  i=0;
  while (*lptr!=c && *lptr!='\0' && i<sizearray(name)-1)  /* find the end of the string */
    name[i++]=*lptr++;
  while (i>0 && name[i-1]<=' ')
    i--;                        /* strip trailing whitespace */
  assert(i>=0 && i<sizearray(name));
  name[i]='\0';                 /* zero-terminate the string */

  if (*lptr!=c) {               /* verify correct string termination */
    error(37);                  /* invalid string */
    return;
  } /* if */
  if (c!='\0')
    check_empty(lptr+1);        /* verify that the rest of the line is whitespace */

  /* create a symbol from the name of the include file; this allows the system
   * to test for multiple inclusions
   */
  strcpy(symname,"_inc_");
  if ((ptr=strrchr(name,DIRSEP_CHAR))!=NULL)
    strlcat(symname,ptr+1,sizearray(symname));
  else
    strlcat(symname,name,sizearray(symname));
  /* replace invalid characters by '_' (anything not a digit, character or
   * underscore)
   */
  for (i=0; symname[i]!='\0'; i++)
    if (!alphanum(symname[i]))
      symname[i]='_';
  #if defined __WIN32__ || defined _WIN32 || defined _Windows || defined __MSDOS__
    /* on systems with case-insentive filenames, force the symbol for the file
     * to lower case
     */
    strlwr(symname);
  #endif
  if (find_symbol(&glbtab,symname,fcurrent,-1)==NULL) {
    /* constant is not present, so this file has not been included yet */

    /* Include files between "..." or without quotes are read from the same
     * relative path as the current file, from the active directory, or from
     * a list of "include directories". Include files between <...> are only
     * read from the list of include directories.
     */
    result=plungefile(name,(c!='>'),TRUE);
    if (result)
      add_constant(symname,1,sGLOBAL,0);
    else if (!silent)
      error(100,name);            /* cannot read from ... (fatal error) */
  } /* if */
}
Where _MAX_PATH > 250, which is enough IMO. I'll investigate further.