示例#1
0
    static void validateTopicName(const QString& topic)
    {
        if (topic.isEmpty())
        {
            throw std::invalid_argument("empty topic");
        }

        // Can't start or end with a '/' but anywhere else is okay
        // Can't have "//" as that implies empty token
        if (topic.startsWith("/") || topic.endsWith("/") ||
                topic.contains("//"))
        {
            throw std::invalid_argument(QString("invalid topic: %1").arg(topic).toStdString());
        }

        QString::const_iterator topicEnd = topic.end();
        QChar A('A'), Z('Z'), a('a'), z('z'), zero('0'), nine('9');
        QChar dash('-'), slash('/'), underscore('_');
        for (QString::const_iterator i = topic.begin(); i < topicEnd; ++i)
        {
            QChar c(*i);
            if ((A <= c) && (c <= Z)) continue;
            if ((a <= c) && (c <= z)) continue;
            if ((zero <= c) && (c <= nine)) continue;
            if ((c == underscore) || (c == dash) || (c == slash)) continue;
            throw std::invalid_argument(QString("invalid topic: %1").arg(topic).toStdString());
        }
    }
示例#2
0
文件: fontname.c 项目: yfyang86/yytex
FILE *tryopen(char *filename, char *ext, char *openmode){
	FILE *input;

	extension(filename, ext);
	input = fopen(filename, openmode);
	if (input == NULL) {
		underscore(filename);
		input = fopen(filename, openmode);
	}
	return input;
}
示例#3
0
std::string formatSuperAndSubscripts(const std::string& str, DocumentFormat fmt) {
  if (fmt == DocumentFormat::LaTeX) {
    std::string wStr(str);
    wStr = boost::regex_replace(wStr, superscript(), "$1\\\\ensuremath{$2}");
    wStr = boost::regex_replace(wStr, subscript(), "$1\\\\ensuremath{$2}");
    return wStr;
  }
  if (fmt == DocumentFormat::XHTML) {
    std::string wStr(str);
    wStr = boost::regex_replace(wStr, superscript(), "$1<sup>$3$4</sup>");
    wStr = boost::regex_replace(wStr, subscript(), "$1<sub>$3$4</sub>");
    wStr = boost::regex_replace(wStr, underscore(), "_");
    return wStr;
  }
  return str;
}
示例#4
0
void AssignNode::compile(ostream& out, CPilaDeSimbolos& stack, CFunctionTable& functable)
{
	//Compilamos la expresion para que quede en en tope de la pila
	exp->compile(out, stack, functable);

	ExpType t = stack.getTipo(id->toString());

	if (stack.GetAsmID(id->toString()) != -1)
	{
		//Guardar tope de la pila en id
		string underscore("_");
		if (t == ET_STRING)
		{
			underscore = string(" ");
		}
		out << "\t" << util::compileInst(t) << "store" << underscore << stack.GetAsmID(id->toString()) << "\n";
	}
	else
	{
		out << "\tputstatic " << className << "/" << id->toString() << " " << util::compile(t) << "\n";	
	}
}
示例#5
0
void DeclNode::compile(ostream& out, CPilaDeSimbolos& stack, CFunctionTable& functable)
{
	//Nueva definicion
	stack.NuevaDefinicion(t, id->toString());

	if (stack.getCurrFuncID() != "__GLOBAL__")
	{
		//La variable es local
		if (exp != NULL)
		{
			//Compilar expresion
			exp->compile(out, stack, functable);
			//Guardar tope de la pila en id
			string underscore("_");
			if (t == TSTRING)
			{
				underscore = string(" ");
			}
			out << "\t" << util::compileInst(util::Tipo2ExpType(t)) << "store" << underscore << stack.GetAsmID(id->toString()) << "\n";
		}
	}
}
示例#6
0
int cmd_userid(string str) {
   mixed *all;
   object who;
   string name;
   int loop;
 
   seteuid(getuid(this_object()));
 
   if(!adminp(geteuid(this_player()))) return 0;
 
   if(!str || str == "") {
  
      all = users();

      write(underscore("Present Active User's Source Accounts") + "\n\n");
 
      for(loop=0; loop<sizeof(all); loop++) {
	name = (string)all[loop]->link_data("cap_name");
	if(!name) continue;

	if(strlen(name) > 6) 
	  write(" " + name + "\t" + get_userid(all[loop]) + "\n");
	else write(" " + name + "\t\t" + get_userid(all[loop]) + "\n");
      }

   return 1; }
 
   who = find_player(str);
 
   if(!who) {
     notify_fail("Userid: No such user is presently online.\n");
   return 0; }
 
   write((string)who->link_data("cap_name") + "'s userid is " +
	 lower_case(get_userid(who)) + ".\n");
 
return 1; }
示例#7
0
int process_users(int when, int verbose, int flag, int test) {
  string *main;
  int loop;

   //	Check time length and caller's permissions.
 
   if(!when || !intp(when) || (geteuid(previous_object()) != ROOT_UID &&
      !adminp(geteuid(previous_object()))))
	return 0;
 
   seteuid(getuid(this_object()));
 
   //	Check to see if the daemon is presently in use ... If so
   //	tell the caller to try again later (shouldn't really have
   //	repeated calls anyways).
 
   if(busy)  return 0;
 
   busy = 1;
 
   //	If there isn't a this_player(), then any write()s will get 
   //	dumped to the syslog ... would be messy ... so block it. :)

   if(!this_player())  verbose = 0;
 
   //	Check to make sure the flags are acceptable.
 
   if(flag < 0)  flag = 0;
   if(flag > 2)  flag = 2;
 
   //	Create temporary link connection object for restoring data.
 
   link = new(CONNECTION);
   total = 0;
 
   //	Get subdirectory listing from user save directory.

   main = get_dir( PDATA_DIR + "/" );
// For a test ;
 
   if(!main || !sizeof(main))  return 0;
 
   if(verbose)
	write(underscore("Initiating user character " +
	      (test ? "test " : "") + "purge") + "\n" +
	      "Last login prior to " + ctime(time()) + ".\n\n");
 
   //	Loop through directory contents using a catch() to catch 
   //	the "Too large evaluation" errors, then backup and do the
   //	failed directory again until you finish it.
 
   for(loop=0; loop<sizeof(main); loop++) 
      call_out( "sweep_dir", loop * SWEEP_CALL_TIME, 
	PDATA_DIR + "/" + main[loop] + "/", when, verbose, flag, test );

/*
   if(err = catch(sweep_dir(PDATA_DIR + "/" + main[loop] + "/", when, verbose,
      flag, test))) {
    errors++;
    if( errors >= MAX_ERRORS ) {
        error( "Purge giving up.\n" );
        return 0;
    }

   if(verbose)  write("Error occurred: " + err + "\nRestarting subdir sweep.\n");
   loop--;
   }
    errors = 0;
    }
*/
 
     call_out( "alert", (loop+3)*SWEEP_CALL_TIME, verbose, test) ;
return 1; }
示例#8
0
/* The type for the machine dependency structure is generated from the
   Makefile */
int main(int argc, char **argv)
{
  int env = argc == 2 && !strcmp(argv[1], "--env");
  int alignof_short, alignof_int, alignof_long, alignof_ptr, alignof_enum,
    alignof_float, alignof_double, alignof_longdouble, sizeof_fun,
    alignof_fun, alignof_str, alignof_aligned, alignof_longlong, 
    little_endian, char_is_unsigned, alignof_bool;

  // The alignment of a short
  {
    struct shortstruct {
      char c;
      short s;
    };
    alignof_short = (int)(&((struct shortstruct*)0)->s);
  }

  // The alignment of an int
  {
    struct intstruct {
      char c;
      int i;
    };
    alignof_int = (int)(&((struct intstruct*)0)->i);
  }
  
  // The alignment of a bool
  {
    struct boolstruct {
      char c;
      bool b;
    };
    alignof_bool = (int)(&((struct boolstruct*)0)->b);
  }
  
  // The alignment of a long
  {
    struct longstruct {
      char c;
      long l;
    };
    alignof_long = (int)(&((struct longstruct*)0)->l);
  }
    
  // The alignment of long long
  {
    struct longlong {
      char c;
      LONGLONG ll;
    };
    alignof_longlong = (int)(&((struct longlong*)0)->ll);
  }

  // The alignment of a ptr
  {
    struct ptrstruct {
      char c; 
      int * p;
    };
    alignof_ptr = (int)(&((struct ptrstruct*)0)->p);
  }

  // The alignment of an enum
  {
    struct enumstruct {
      char c; 
      enum e2 { THREE, FOUR, FIVE } e;
    };
    alignof_enum = (int)(&((struct enumstruct*)0)->e);
  }
    
  // The alignment of a float
  {
    struct floatstruct {
      char c;
      float f;
    };
    alignof_float = (int)(&((struct floatstruct*)0)->f);
  }
  
  // The alignment of double
  {
    struct s1 {
      char c;
      double d;
    };
    alignof_double = (int)(&((struct s1*)0)->d);
  }    

  // The alignment of long  double
  {
    struct s1 {
      char c;
      long double ld;
    };
    alignof_longdouble = (int)(&((struct s1*)0)->ld);
  }    
    
  alignof_str = __alignof("a string");
  alignof_fun = __alignof(main);

  sizeof_fun = 0;
#ifdef __GNUC__
  sizeof_fun = sizeof(main);
#endif

  // The alignment of anything with __attribute__((aligned))
  alignof_aligned = 0;
#ifdef __GNUC__
  {
    char __attribute__((aligned)) c;
    long double  __attribute__((aligned)) ld;
    if (__alignof(c) != __alignof(ld)) {
      fprintf(stderr, "__attribute__((aligned)) has a different effect on different types.  alignments may be computed incorrectly.\n");
    }
    alignof_aligned = __alignof(c);
  }
#endif


  // Whether char is unsigned
  char_is_unsigned = ((char)0xff) > 0;

  // endianness
  {
    int e = 0x11223344;
    little_endian = (0x44 == *(char*)&e) ? 1 :
      ((0x11 == *(char*)&e) ? 0 : (exit(1), 0));
  }

  if (env)
    {
      fprintf(stderr, "Generating CIL_MACHINE machine dependency information string (for CIL)\n");
      printf("short=%d,%d int=%d,%d long=%d,%d long_long=%d,%d pointer=%d,%d "
	     "enum=%d,%d float=%d,%d double=%d,%d long_double=%d,%d void=%d "
	     "bool=%d,%d fun=%d,%d alignof_string=%d max_alignment=%d size_t=%s "
	     "wchar_t=%s char_signed=%s const_string_literals=%s "
	     "big_endian=%s __thread_is_keyword=%s __builtin_va_list=%s "
	     "underscore_name=%s\n",
	     (int)sizeof(short), alignof_short, (int)sizeof(int), alignof_int,
	     (int)sizeof(long), alignof_long, (int)sizeof(long long), alignof_longlong, 
	     (int)sizeof(int *), alignof_ptr, (int)sizeof(enum e { ONE, TWO }), alignof_enum,
	     (int)sizeof(float), alignof_float, (int)sizeof(double), alignof_double, 
	     (int)sizeof(long double), alignof_longdouble, (int)sizeof(void), 
	     sizeof(bool), alignof_bool,
	     sizeof_fun, alignof_fun, alignof_str, alignof_aligned, 
	     underscore(TYPE_SIZE_T), underscore(TYPE_WCHAR_T), 
	     char_is_unsigned ? "false" : "true", CONST_STRING_LITERALS, 
	     little_endian ? "false" : "true",
	     THREAD_IS_KEYWORD, HAVE_BUILTIN_VA_LIST, UNDERSCORE_NAME);
    }
  else
    {
      fprintf(stderr, "Generating machine dependency information for CIL\n");

      printf("(* Generated by code in %s *)\n", __FILE__);
      printf("\t version_major    = %d;\n", VERSION_MAJOR);
      printf("\t version_minor    = %d;\n", VERSION_MINOR);
      printf("\t version          = \"%s\";\n", VERSION);

      // Size of certain types
      printf("\t sizeof_short          = %d;\n", (int)sizeof(short));
      printf("\t sizeof_int            = %d;\n", (int)sizeof(int));
      printf("\t sizeof_bool           = %d;\n", (int)sizeof(bool));
      printf("\t sizeof_long           = %d;\n", (int)sizeof(long));
      printf("\t sizeof_longlong       = %d;\n", (int)sizeof(LONGLONG));
      printf("\t sizeof_ptr            = %d;\n", (int)sizeof(int *));
      printf("\t sizeof_enum           = %d;\n", (int)sizeof(enum e { ONE, TWO }));
      printf("\t sizeof_float          = %d;\n", (int)sizeof(float));
      printf("\t sizeof_double         = %d;\n", (int)sizeof(double));
      printf("\t sizeof_longdouble     = %d;\n", (int)sizeof(long double));
      printf("\t sizeof_void           = %d;\n", (int)sizeof(void));
      printf("\t sizeof_fun            = %d;\n", (int)sizeof_fun);
      printf("\t size_t                = \"%s\";\n", TYPE_SIZE_T);
      printf("\t wchar_t               = \"%s\";\n", TYPE_WCHAR_T);
      printf("\t alignof_short         = %d;\n", alignof_short);
      printf("\t alignof_int           = %d;\n", alignof_int);
      printf("\t alignof_bool          = %d;\n", alignof_bool);
      printf("\t alignof_long          = %d;\n", alignof_long);
      printf("\t alignof_longlong      = %d;\n", alignof_longlong);
      printf("\t alignof_ptr           = %d;\n", alignof_ptr);
      printf("\t alignof_enum          = %d;\n", alignof_enum);
      printf("\t alignof_float         = %d;\n", alignof_float);
      printf("\t alignof_double        = %d;\n", alignof_double);
      printf("\t alignof_longdouble    = %d;\n", alignof_longdouble);
      printf("\t alignof_str           = %d;\n", alignof_str);
      printf("\t alignof_fun           = %d;\n", alignof_fun);
      printf("\t alignof_aligned       = %d;\n", alignof_aligned);
      printf("\t char_is_unsigned      = %s;\n", char_is_unsigned ? "true" : "false");
      printf("\t const_string_literals = %s;\n", CONST_STRING_LITERALS);
      printf("\t underscore_name       = %s;\n", UNDERSCORE_NAME);
      printf("\t __builtin_va_list     = %s;\n", HAVE_BUILTIN_VA_LIST);
      printf("\t __thread_is_keyword   = %s;\n", THREAD_IS_KEYWORD);
      printf("\t little_endian         = %s;\n", little_endian ? "true" : "false");
    }
  return 0;
}