示例#1
0
void Templateiser::processIF ( std::string &code, std::string::const_iterator &inItr, const std::string &str )
{
  std::string key;

  // read the rest of the key
  std::string::const_iterator itr = readKey(key,inItr,str);

  std::vector<std::string> commandParts = tokenize(key,std::string(" "),0,0);
  if (commandParts.size() < 2) {
    inItr = itr;
    return;
  }

  // check the params
  makelower(commandParts[0]);
  makelower(commandParts[1]);

  if ( commandParts[0] != "if" ) {
    inItr = itr;
    return;
  }

  std::string param;
  if (commandParts.size() > 2)
    param = commandParts[2];

  // now get the code for the next section
  std::string trueSection,elseSection;

  std::vector<std::string> checkKeys;
  checkKeys.push_back(format("?else %s",commandParts[1].c_str()));
  checkKeys.push_back(format("?end %s",commandParts[1].c_str()));

  std::string keyFound;
  itr = findNextTag(checkKeys,keyFound,trueSection,itr,str);

  if (keyFound == checkKeys[0]) { // we hit an else, so we need to check for it
    // it was the else, so go and find the end too
    if (itr == str.end()) {
      inItr = itr;
      return;
    }

    checkKeys.erase(checkKeys.begin());// kill the else, find the end
    itr = findNextTag(checkKeys,keyFound,elseSection,itr,str);
  }

  // test the if, stuff that dosn't exist is false
  if (callIF(commandParts[1],param)) {
    std::string newCode;
    processTemplate(newCode,trueSection);
    code += newCode;
  } else {
    std::string newCode;
    processTemplate(newCode,elseSection);
    code += newCode;
  }
  inItr = itr;
}
示例#2
0
void observerChat::Event ( bz_EventData *eventData )
{
  switch (eventData->eventType)
  {
  case bz_eRawChatMessageEvent:
    {
      bz_ChatEventData_V1 *data = (bz_ChatEventData_V1*)eventData;
      int from = data->from;
      bool isObserver = bz_getPlayerTeam(from) == eObservers;
      bool canSpawn = bz_hasPerm(from,bz_perm_spawn);
      const char* duringTheGame = "";

      if (!isObserver && canSpawn) return;
      if (data->to != BZ_ALLUSERS && (isObserver || data->team == eNoTeam)) return;
      if (bz_hasPerm(from,permName) || bz_getAdmin(from)) return;

      std::string variableValue = makelower(bz_getBZDBString(variableName).c_str());
      if (variableValue == "off" || variableValue == "disable" || variableValue == "disabled" || variableValue == "no") return;
      else if (!(variableValue == "on" || variableValue == "always" || variableValue == "alwayson" || variableValue == "enable" || variableValue == "enabled" || variableValue == "yes")) {
        if (!bz_isCountDownActive()) return;
        duringTheGame = " during the game";
      }

      bz_sendTextMessagef(BZ_SERVER,from,"You are not allowed to send global messages%s.",duringTheGame);
      bz_sendTextMessagef(BZ_SERVER,from,"Please use observer chat only.");
      data->message = "";
    }
    break;
  default:
    break;
  }
}
示例#3
0
文件: cavatar.c 项目: kivibot/CAvatar
/**
 * Index route, serves a static file and handles a redirect.
 */
void route_index(evhtp_request_t *req, void *arg) {
    evhtp_uri_t *uri = req->uri;
    evhtp_query_t *query = uri->query;
    const char *parq = evhtp_kv_find(query, "q");
    const char *pars = evhtp_kv_find(query, "s");
    const char *parm = evhtp_kv_find(query, "m");
    if (parq) {
        char *m = malloc(sizeof (char)*64);
        char *tmp = makelower(parq, strlen(parq));
        char *md = md5((const char *) tmp, strlen(parq));
        free(tmp);
        if (parm) {
            sprintf(m, "/meta/%s", md);
        } else if (pars) {
            sprintf(m, "/%s/%d", md, atoi(pars));
        } else {
            sprintf(m, "/%s", md);
        }
        free(md);
        evhtp_headers_add_header(req->headers_out,
                evhtp_header_new("Location", m, 0, 1));
        free(m);
        evhtp_send_reply(req, 301);
    } else {
        serve_static(req, "static/index.html", "text/html");
    }
}
示例#4
0
int
STRNCMP(char *s1, char *s2, int len)
{
	if (l_onecase) {
	    do
		if (*s2 - makelower(*s1))
			return (*s2 - makelower(*s1));
		else {
			s2++;
			s1++;
		}
	    while (--len);
	} else {
	    do
		if (*s2 - *s1)
			return (*s2 - *s1);
		else {
			s2++;
			s1++;
		}
	    while (--len);
	}
	return(0);
}
示例#5
0
std::string::const_iterator Templateiser::readKey ( std::string &key, std::string::const_iterator inItr, const std::string &str )
{
  std::string::const_iterator itr = inItr;

  while ( itr != str.end() ) {
    if (*itr != ']') {
      key += *itr;
      itr++;
    } else {
      // go past the code
      itr++;
      makelower(key);
      return itr;
    }
  }
  return itr;
}
示例#6
0
int main(int argc, char *argv[]) {
	/*
	 * Initialize i
	 */
   char string[] = {"Eric Sammons"};  
   int i;
/* 
 * Do we have the appropriate argument.
 */
   if(argc == 2) {
      if(strcmp(argv[1],"-U") == 0) {
         makecaps(string);
      } else if(strcmp(argv[1],"-L") == 0) {
         makelower(string);
      } else if(strcmp(argv[1],"-M") == 0) {
         /*
          * nothing to do here
          */
      } else {
         printf("Illegal argument: %s\n", argv[1]);
         return EXIT_FAILURE;
      }
   } else if(argc == 1) {
      makecaps(string);
   } else {
      printf("Too many arguments: ");
      for(i = 2; i < argc; i++) {
         printf("%s ", argv[i]);
      }
      putchar('\n');
      return EXIT_FAILURE;
   }
/* 
 * Print out our converted string
 */
   printf("%s\n", string);
	return EXIT_SUCCESS;
}
示例#7
0
void Templateiser::processLoop ( std::string &code, std::string::const_iterator &inItr, const std::string &str )
{
  std::string key,loopSection,emptySection,param;

  // read the rest of the key
  std::string::const_iterator itr = readKey(key,inItr,str);

  std::vector<std::string> commandParts = tokenize(key,std::string(" "),0,0);
  if (commandParts.size() < 2)
  {
    inItr = itr;
    return;
  }

  // check the params
  makelower(commandParts[0]);
  makelower(commandParts[1]);

  if (commandParts.size() > 2)
    param = commandParts[2];

  if ( commandParts[0] != "start" )
  {
    inItr = itr;
    return;
  }

  std::vector<std::string> checkKeys;
  checkKeys.push_back(format("*end %s",commandParts[1].c_str()));

  std::string keyFound;
  itr = findNextTag(checkKeys,keyFound,loopSection,itr,str);

  if (itr == str.end())
  {
    inItr = itr;
    return;
  }

  // do the empty section
  // loops have to have both
  checkKeys.clear();
  checkKeys.push_back(format("*empty %s",commandParts[1].c_str()));
  itr = findNextTag(checkKeys,keyFound,emptySection,itr,str);

  if (callLoop(commandParts[1],param))
  {
    std::string newCode;
    processTemplate(newCode,loopSection);
    code += newCode;

    while(callLoop(commandParts[1],param))
    {
      newCode = "";
      processTemplate(newCode,loopSection);
      code += newCode;
    }
  }
  else
  {
    std::string newCode;
    processTemplate(newCode,emptySection);
    code += newCode;
  }
  inItr = itr;
}
示例#8
0
文件: gram.c 项目: joequant/iraf
int 
crackident (char *s)
{
	struct keywords {
		char *k_name;		/* the keyword string itself.	*/
		short k_token;		/* yacc %token for the keyword	*/
		short k_yylval;		/* the value associated with token.*/
	};

	static struct keywords kw[] = {

	    /* Control flow keywords.
	     */
	    { "while",  Y_WHILE,  0 },	{ "if",        Y_IF,        0 },
	    { "else",   Y_ELSE,   0 },	{ "switch",    Y_SWITCH,    0 },
	    { "case",   Y_CASE,   0 },	{ "default",   Y_DEFAULT,   0 },
	    { "break",  Y_BREAK,  0 },	{ "next",      Y_NEXT,      0 }, 
	    { "return", Y_RETURN, 0 },	{ "goto",      Y_GOTO,      0 },
	    { "for",    Y_FOR,    0 },	{ "procedure", Y_PROCEDURE, 0 },
	    { "begin",  Y_BEGIN,  0 },	{ "end",       Y_END,       0 },
	    { "iferr",  Y_IFERR,  0 },	{ "ifnoerr",   Y_IFNOERR,   0 },
	    { "then",   Y_THEN,   0 },

	    /* Parameter and variable types.
	     */
	    { "int",    Y_INT,    0 },	{ "char",      Y_STRING,    0 },
	    { "real",   Y_REAL,   0 },	{ "string",    Y_STRING,    0 },
	    { "file",   Y_FILE,   0 },	{ "gcur",      Y_GCUR,      0 },
	    { "imcur",  Y_IMCUR,  0 },	{ "ukey",      Y_UKEY,      0 },
	    { "pset",   Y_PSET,   0 },	{ "bool",      Y_BOOL,      0 },
	    { "struct", Y_STRUCT, 0 },

	    /* debugging commands.
	     */
	    { "d_d",    D_D,      0 },
	    { "d_peek", D_PEEK,   0 },

	    { "", 0, 0 } 		/* sentinel; leave it here... */
	};

	static struct keywords kf[] = {
	    /* Keywords of intrinsic functions that get built into
	     * the grammar.  Most intrinsics handled by intrinsic().
	     */
	    { "scan",   Y_SCAN,   0 },
	    { "scanf",  Y_SCANF,  0 },
	    { "fscan",  Y_FSCAN,  0 },
	    { "fscanf", Y_FSCANF, 0 },

	    /* sentinel; leave it here... */
	    { "", 0, 0 } 
	};

	register struct keywords *kp;
	XINT	oldtopd;
	static	char sch, kch;		/* static storage is faster here   */
	char	*scopy;			/* non-makelower'd copy		   */
	char    sb[REALWIDTH];


	oldtopd = topd;			/* save topd			   */
	scopy = comdstr(s);		/* make a copy in the dictionary   */
	makelower (scopy);		/* make it lower case for compares */
	topd = oldtopd;			/*restore topd but scopy still there!*/

	/* Put the first character of the identifier we are searching for
	 * in local storage to permit fast rejection of keywords without all
	 * the overhead involved in a call to strcmp.  This is an easy way
	 * to speed things up several times w/o coding fancy data structures.
	 */
	sch = *scopy;
	kch = *s;	/* save original string */

	/* Check for and handle special-case keywords first.
	 */
	if (sch == *truestr && !strcmp (scopy, truestr)) {
	    yylval = addconst (truestr, OT_BOOL);
	    return (Y_CONSTANT);
	} else if (sch == *falsestr && !strcmp (scopy, falsestr)) {
	    yylval = addconst (falsestr, OT_BOOL);
	    return (Y_CONSTANT);
	} else if (sch == *indeflc && !strcmp (scopy, indeflc)) {
	    yylval = addconst (scopy, OT_INT);
	    return (Y_CONSTANT);
	} else if (sch == *eoflc && !strcmp (scopy, eoflc)) {
	    yylval = addconst (CL_EOFSTR, OT_INT);
	    return (Y_CONSTANT);
	} else if (sch == *errorstr && !strcmp (scopy, errorstr)) {
	    yylval = addconst (errorstr, OT_STRING);
	    return (Y_IDENT);

	/* Check for defined numerical constants.  For backwards compatability
	 * we match 'epsilon', however this particular value is deprecated by
	 * the fp_equal() builtin and we assume CL constants will be upper
	 * case strings.
	 */
	} else if ((sch == *epsilonstr && !strcmp (scopy, epsilonstr)) ||
		   (kch == *epsilonuc && !strcmp (s, epsilonuc))) {
	    sprintf (sb, "%e", EPSILON);
	    yylval = addconst (sb, OT_REAL);
	    return (Y_CONSTANT);

	} else if (const_str (pistr)) { 	retconst (PI);
	} else if (const_str (twopistr)) { 	retconst (TWOPI);
	} else if (const_str (fourpistr)) { 	retconst (FOURPI);
	} else if (const_str (halfpistr)) { 	retconst (HALFPI);
	} else if (const_str (sqrtpistr)) { 	retconst (SQRTOFPI);
	} else if (const_str (sqrttwostr)) { 	retconst (SQRTOF2);
	} else if (const_str (baseestr)) { 	retconst (BASE_E);
	} else if (const_str (ln2str)) { 	retconst (LN_2);
	} else if (const_str (ln10str)) { 	retconst (LN_10);
	} else if (const_str (lnpistr)) { 	retconst (LN_PI);
	} else if (const_str (logestr)) { 	retconst (LOG_E);
	} else if (const_str (gammastr)) { 	retconst (GAMMA);
	} else if (const_str (radianstr)) { 	retconst (RADIAN);

	} else if (const_str (austr)) { 	retconst (AU);
	} else if (const_str (gaccelstr)) { 	retconst (GRAV_ACCEL);
	} else if (const_str (gconststr)) { 	retconst (GRAV_CONST);
	} else if (const_str (lystr)) { 	retconst (LIGHT_YEAR);
	} else if (const_str (parsecstr)) { 	retconst (PARSEC);
	} else if (const_str (lightstr)) { 	retconst (SPEED_OF_LIGHT);
	} else if (const_str (solmassstr)) { 	retconst (SOLAR_MASS);


	} else if (!inarglist && parenlevel == 0) {
	    /* Search the keyword list; kewords are not recognized in argument
	     * lists and expressions, else unquoted strings like "for" and
	     * "file" will cause syntax errors.
	     */
	    for (kp=kw;  (kch = *kp->k_name);  kp++)
		if (kch == sch)
		    if (strcmp (scopy, kp->k_name) == 0) {
			yylval = kp->k_yylval;
			return (kp->k_token);
		    }

	} else {
	    /* Search the list of intrinsic functions.
	     */
	    for (kp=kf;  (kch = *kp->k_name);  kp++)
		if (kch == sch)
		    if (strcmp (scopy, kp->k_name) == 0) {
			yylval = kp->k_yylval;
			return (kp->k_token);
		    }
	}

	/* S not a keyword, so it's just an identifier.
	 */
	yylval = addconst (s, OT_STRING);	/* use original */
	return (Y_IDENT);
}
示例#9
0
文件: filename.c 项目: vaxvms/dibol2c
// Convert a VMS filespec into a Unix filespec
// volume names are turned into directories in the root directory
// (unless they are SYSDISK which is our pseudo name)
void make_unix_filespec(char *unixname, char *vmsname)
{
    char volume[PATH_MAX];
    char dir[PATH_MAX];
    char file[PATH_MAX];
    int  ptr;
    int  i;
    char *semi;
    char *basedir;

    strcpy(file, vmsname);

    // Remove the trailing version number
    semi = strchr(file, ';');
    if (semi) *semi = '\0';

    // If the filename has a trailing dot them remove that too
    if (file[strlen(file)-1] == '.')
        file[strlen(file)-1] = '\0';
    
    unixname[0] = '\0';

    /* We add the environement variable DIBOLBASEDIR
     * it at the beginning of the unix filespec */
    if ((basedir=getenv("DIBOLBASEDIR"))!=NULL)
        strcat(unixname,basedir);

    // Split it into its component parts
    parse_vms_filespec(volume, dir, file);

    // Remove the trailing colon from the volume name
    if (volume[strlen(volume)-1] == ':')
	volume[strlen(volume)-1] = '\0';
    
    // If the filename has the dummy SYSDISK volume then start from the
    // filesystem root
    if (strcasecmp(volume, sysdisk_name) == 0)
    {
	strcat(unixname, "/");
    }
    else
    {
	if (volume[0] != '\0')
	{
	    strcat(unixname, "/");
	    strcat(unixname, volume);
	}
    }
    ptr = strlen(unixname);
    
    // Copy the directory
    for (i=0; i< (int)strlen(dir); i++)
    {
	// If the directory name starts [. then it is relative to the
	// user's home directory and we lose the starting slash
	// If there is also a volume name present then it all falls
	// to bits but then it's pretty dodgy on VMS too.
	if (dir[i] == '[' &&
	    dir[i+1] == '.')
	{
	    i++;
	    ptr = 0;
	    continue;
	}

	if (dir[i] == '[' ||
	    dir[i] == ']' ||
	    dir[i] == '.')
	{
	    unixname[ptr++] = '/';
	}
	else
	{
	    // Skip root directory specs
	    if (dir[i] == '0' && strncmp(&dir[i], "000000", 6))
	    {
		i += 5;
		continue;
	    }
	    if (dir[i] == '0' && strncmp(&dir[i], "0,0", 3))
	    {
		i += 2;
		continue;
	    }
	    unixname[ptr++] = dir[i];
	}
    }
    unixname[ptr++] = '\0'; // so that strcat will work properly

    // A special case (ugh!), if VMS sent us '*.*' (maybe as part of *.*;*)
    // then change it to just '*' so we get all the files.
    if (strcmp(file, "*.*") == 0) strcpy(file, "*");

    strcat(unixname, "/");
    strcat(unixname, file);

    // Finally convert it all to lower case. This is not the greatest way to
    // cope with it but because VMS will upper-case everything anyway we
    // can't really distinguish case. I know samba does fancy stuff with
    // matching various combinations of case but I really can't be bothered.
    makelower(unixname);

    // If the name ends in .dir and there is a directory of that name without
    // the .dir then remove it (the .dir, not the directory!)
    if (strstr(unixname, ".dir") == unixname+strlen(unixname)-4)
    {
	char dirname[strlen(unixname)+1];
	struct stat st;
	char *ext;

	strcpy(dirname, unixname);
	ext = strstr(dirname, ".dir");
	if (ext) *ext = '\0';
	if (stat(dirname, &st) == 0 &&
	    S_ISDIR(st.st_mode))
	{
	    char *ext = strstr(unixname, ".dir");
	    if (ext) *ext = '\0';
	}
    }
}