summaryrefslogtreecommitdiffstats
path: root/advertising
Commit message (Expand)AuthorAgeFilesLines
* update advertisings for Mageia 3Anne Nicolas2013-04-0623-8/+18
* fix Mageia 1 imageAnne Nicolas2012-05-041-0/+0
* fix border in first imageAnne Nicolas2012-04-261-0/+0
* version 2Anne Nicolas2012-04-252-1/+5
* make advertising screens more genericAnne Nicolas2012-04-254-0/+0
* update advertising for final releaseAnne Nicolas2011-05-2615-4/+12
* switch to rc imagesAnne Nicolas2011-05-163-0/+0
* update wcreen with proper imagesAnne Nicolas2011-04-232-0/+0
* switch to betaAnne Nicolas2011-04-222-0/+0
* update installer and advertising design for beta1Anne Nicolas2011-04-013-0/+0
* update advertisingAnne Nicolas2011-03-124-0/+7
* remove old advertisingAnne Nicolas2011-03-122-1/+0
* new info screens (alexn83/marcom)Romain d'Alverny2011-03-124-1/+3
* update version in MakefileAnne Nicolas2011-02-091-1/+1
* Synthesized commit during git-svn import combining previous Mandriva history ...Mageia SVN-Git Migration2011-02-0618-52/+7
* SILENT update MakefileAnne Nicolas2010-05-021-1/+1
* update NEWSAnne Nicolas2010-05-021-0/+3
* update advertising images for 2010 SpringAnne Nicolas2010-05-025-0/+0
* fix pl file nameAnne Nicolas2009-10-284-0/+0
* update avertising for 2010Anne Nicolas2009-10-2812-5/+8
* fix flash imageAnne Nicolas2009-03-121-0/+0
* update versionAnne Nicolas2009-03-071-1/+1
* 2009.1 imagesAnne Nicolas2009-03-076-0/+3
* - 2009.0 versionFrederic Crozat2008-09-112-1/+4
* - Refreshed advertising screens for 2009.0Frederic Crozat2008-09-1112-3/+3
* - Test with new advertising sizeFrederic Crozat2008-09-034-1/+1
* - 2008.1 titlesPascal Rigaux2008-03-217-6/+14
* new images for 2008.1Pascal Rigaux2008-02-2624-13/+11
* 0.6Pascal Rigaux2007-09-182-1/+3
* - really add titles for 2008.0 adverstingPascal Rigaux2007-09-182-0/+3
* 0.5Pascal Rigaux2007-09-182-1/+3
* add missing entryPascal Rigaux2007-09-181-0/+4
* - fix 02IM_MIGRATION.png screenshotPascal Rigaux2007-09-182-0/+2
* add titles for 2008.0 adverstingPascal Rigaux2007-09-177-1/+7
* 0.3Pascal Rigaux2007-09-142-1/+3
* - 2008.0 advertising imagesPascal Rigaux2007-09-1425-49/+9
* re-sync after the big svn lossPascal Rigaux2007-05-1417-0/+45
* re-sync after the big svn lossPascal Rigaux2007-04-256-0/+74
405'>405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
/* Copyright (c) 1996, 1999, 2001 John E. Davis
 * This file is part of the S-Lang library.
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Perl Artistic License.
 */

/*--------------------------------*-C-*---------------------------------*
 * File:	slprepr.c
 *
 * preprocessing routines
 */
/*{{{ notes: */
/*
 * various preprocessing tokens supported
 *
 * #ifdef  TOKEN1 TOKEN2 ...
 *	- True if any of TOKEN1 TOKEN2 ... are defined
 *
 * #ifndef TOKEN1 TOKEN2 ...
 *	- True if none of TOKEN1 TOKEN2 ... are defined
 *
 * #iftrue
 * #ifnfalse
 *	- always True
 *
 * #iffalse
 * #ifntrue
 *	- always False
 *
 * #if$ENV
 *	- True if the enviroment variable ENV is set
 *
 * #ifn$ENV
 *	- True if the enviroment variable ENV is not set
 *
 * #if$ENV TOKEN1 TOKEN2 ...
 *	- True if the contents of enviroment variable ENV match
 *	  any of TOKEN1 TOKEN2 ...
 *
 * #ifn$ENV TOKEN1 TOKEN2 ...
 *	- True if the contents of enviroment variable ENV do not match
 *	  any of TOKEN1 TOKEN2 ...
 *
 *	NB: For $ENV, the tokens may contain wildcard characters:
 *		'?' - match any single character
 *		'*' - match any number of characters
 *
 * #elif...
 * #else
 * #endif
 *
 *
 * mj olesen
 *----------------------------------------------------------------------*/
/*}}}*/
/*{{{ includes: */
#include "slinclud.h"

#include "slang.h"
#include "_slang.h"
/*}}}*/

int (*SLprep_exists_hook) (char *, char);
int (*_SLprep_eval_hook) (char *);

/*{{{ SLprep_open_prep (), SLprep_close_prep () */
int SLprep_open_prep (SLPreprocess_Type *pt)
{
   pt->this_level = 0;
   pt->exec_level = 0;
   pt->prev_exec_level = 0;
   pt->comment_char = '%';
   pt->preprocess_char = '#';
   pt->flags = 0;
   return 0;
}

void SLprep_close_prep (SLPreprocess_Type *pt)
{
   (void) pt;
}
/*}}}*/

/*{{{ SLwildcard () */
/*----------------------------------------------------------------------*
 * Does `string' match `pattern' ?
 *
 * '*' in pattern matches any sub-string (including the null string)
 * '?' matches any single char.
 *
 * Code taken from that donated by Paul Hudson <paulh@harlequin.co.uk>
 * to the fvwm project.
 * It is public domain, no strings attached. No guarantees either.
 *----------------------------------------------------------------------*/
static int SLwildcard (char *pattern, char *string)
{
   if (pattern == NULL || *pattern == '\0' || !strcmp (pattern, "*"))
     return 1;
   else if (string == NULL)
     return 0;

   while (*pattern && *string) switch (*pattern)
     {
      case '?':
	/* match any single character */
	pattern++;
	string++;
	break;

      case '*':
	/* see if rest of pattern matches any trailing */
	/* substring of the string. */
	if (*++pattern == '\0')
	  return 1;	/* trailing * must match rest */

	while (*string)
	  {
	     if (SLwildcard (pattern, string)) return 1;
	     string++;
	  }
	return 0;

	/* break; */

      default:
	if (*pattern == '\\')
	  {
	     if (*++pattern == '\0')
	       pattern--;	/* don't skip trailing backslash */
	  }
	if (*pattern++ != *string++) return 0;
	break;
     }

   return ((*string == '\0')
	   && ((*pattern == '\0') || !strcmp (pattern, "*")));
}
/*}}}*/

#if defined(__16_BIT_SYSTEM__)
# define MAX_DEFINES 10
#else
# define MAX_DEFINES 128
#endif

/* The extra one is for NULL termination */
char *_SLdefines [MAX_DEFINES + 1];

int SLdefine_for_ifdef (char *s)	/*{{{*/
{
   unsigned int i;

   for (i = 0; i < MAX_DEFINES; i++)
     {
	char *s1 = _SLdefines [i];

	if (s1 == s)
	  return 0;		       /* already defined (hashed string) */

	if (s1 != NULL)
	  continue;

	s = SLang_create_slstring (s);
	if (s == NULL)
	  return -1;

	_SLdefines[i] = s;
	return 0;
     }
   return -1;
}
/*}}}*/

/*{{{ static functions */
static int is_any_defined(char *buf, char comment)	/*{{{*/
{
   char *sys;
   unsigned int i;

   while (1)
     {
	register char ch;

	/* Skip whitespace */
	while (((ch = *buf) == ' ') || (ch == '\t'))
	  buf++;

	if ((ch == '\n') || (ch == 0) || (ch == comment))
	  return 0;

	i = 0;
	while (NULL != (sys = _SLdefines [i++]))
	  {
	     unsigned int n;

	     if (*sys != ch)
	       continue;

	     n = strlen (sys);
	     if (0 == strncmp (buf, sys, n))
	       {
		  char ch1 = *(buf + n);

		  if ((ch1 == '\n') || (ch1 == 0) ||
		      (ch1 == ' ') || (ch1 == '\t') || (ch1 == comment))
		    return 1;
	       }
	  }

	/* Skip past word */
	while (((ch = *buf) != ' ')
	       && (ch != '\n')
	       && (ch != 0)
	       && (ch != '\t')
	       && (ch != comment))
	  buf++;
     }
}
/*}}}*/

static unsigned char *tokenize (unsigned char *buf, char *token, unsigned int len)
{
   register char *token_end;

   token_end = token + (len - 1);      /* allow room for \0 */

   while ((token < token_end) && (*buf > ' '))
     *token++ = *buf++;

   if (*buf > ' ') return NULL;	/* token too long */

   *token = '\0';

   while ((*buf == ' ') || (*buf == '\t')) buf++;

   return buf;
}

static int is_env_defined (char *buf, char comment)	/*{{{*/
{
   char * env, token [32];

   if ((*buf <= ' ') || (*buf == comment)) return 0;	/* no token */

   if (NULL == (buf = (char *) tokenize ((unsigned char *) buf,
					 token, sizeof (token))))
     return 0;

   if (NULL == (env = getenv (token)))
     return 0;		/* ENV not defined */

   if ((*buf == '\0') || (*buf == '\n') || (*buf == comment))
     return 1;			/* no tokens, but getenv() worked */

   do
     {
	buf = (char *) tokenize ((unsigned char *) buf, token, sizeof (token));
	if (buf == NULL) return 0;

	if (SLwildcard (token, env))
	  return 1;
     }
   while (*buf && (*buf != '\n') && (*buf != comment));

   return 0;
}
/*}}}*/
/*}}}*/

int SLprep_line_ok (char *buf, SLPreprocess_Type *pt)	/*{{{*/
{
   int level, prev_exec_level, exec_level;

   if ((buf == NULL) || (pt == NULL)) return 1;

   if (*buf != pt->preprocess_char)
     {
	if (pt->this_level != pt->exec_level)
	  return 0;

	if (*buf == '\n') return pt->flags & SLPREP_BLANK_LINES_OK;
	if (*buf == pt->comment_char) return pt->flags & SLPREP_COMMENT_LINES_OK;

	return 1;
     }

   level = pt->this_level;
   exec_level = pt->exec_level;
   prev_exec_level = pt->prev_exec_level;

   buf++;

   /* Allow '#!' to pass.  This could be a shell script with something
    like '#! /local/bin/slang'  */
   if ((*buf == '!') && (pt->preprocess_char == '#'))
     return 0;

   /* Allow whitespace as in '#   ifdef'  */
   while ((*buf == ' ') || (*buf == '\t')) buf++;
   if (*buf < 'a') return (level == exec_level);

   if (!strncmp(buf, "endif", 5))
     {
	if (level == exec_level)
	  {
	     exec_level--;
	     prev_exec_level = exec_level;
	  }
	level--;
	if (level < prev_exec_level) prev_exec_level = level;
	goto done;
     }

   if ((buf[0] == 'e') && (buf[1] == 'l'))   /* else, elifdef, ... */
     {
	if ((level == exec_level + 1)
	    && (prev_exec_level != level))
	  {
	     /* We are in position to execute */
	     buf += 2;
	     if ((buf[0] == 's') && (buf[1] == 'e'))
	       {
		  /* "else" */
		  exec_level = level;
		  goto done;
	       }

	     /* drop through to ifdef testing.  First set variable
	      * to values appropriate for ifdef testing.
	      */
	     level--;		       /* now == to exec level */
	  }
	else
	  {
	     if (level == exec_level)
	       {
		  exec_level--;
	       }
	     goto done;
	  }
     }

   if ((buf[0] == 'i') && (buf[1] == 'f'))
     {
	int truth;

	if (level != exec_level)
	  {
	     /* Not interested */
	     level++;
	     goto done;
	  }

	level++;

	buf += 2;
	if (buf[0] == 'n')
	  {
	     truth = 0;
	     buf++;
	  }
	else truth = 1;

	if (!strncmp (buf, "def", 3))
	  truth = (truth == is_any_defined(buf + 3, pt->comment_char));

	else if (!strncmp (buf, "false", 5))
	  truth = !truth;

	else if (*buf == '$')
	  truth = (truth == is_env_defined (buf + 1, pt->comment_char));

	else if (!strncmp (buf, "exists", 6)
		 && (SLprep_exists_hook != NULL))
	  truth = (truth == (*SLprep_exists_hook)(buf + 6, pt->comment_char));

	else if (!strncmp (buf, "eval", 4)
		 && (_SLprep_eval_hook != NULL))
	  truth = (truth == (*_SLprep_eval_hook) (buf + 4));
			   
	else if (0 != strncmp (buf, "true", 4))
	  return 1;		       /* let it bomb */

	if (truth)
	  {
	     exec_level = level;
	     prev_exec_level = exec_level;
	  }
     }
   else return 1;  /* let it bomb. */

   done:

   if (exec_level < 0) return 1;

   pt->this_level = level;
   pt->exec_level = exec_level;
   pt->prev_exec_level = prev_exec_level;
   return 0;
}
/*}}}*/

/*{{{ main() - for testing only */
#if 0
int main ()
{
   char buf[1024];
   SLPreprocess_Type pt;

   SLprep_open_prep (&pt);

   SLdefine_for_ifdef ("UNIX");

   while (NULL != fgets (buf, sizeof (buf) - 1, stdin))
     {
	if (SLprep_line_ok (buf, &pt))
	  {
	     fputs (buf, stdout);
	  }
     }

   SLprep_close_prep (&pt);
   return 0;
}
#endif
/*}}}*/