Esempio n. 1
0
//-----------------------------------------------------------------------------
float mglFont::Width(const wchar_t *str,int font) const
{
	if(GetNumGlyph()==0 || !str || *str==0)	return 0;
	float ww=0,w=0;
	size_t size = mgl_wcslen(str)+1;
	if(parse)
	{
		unsigned *wcs = new unsigned[size], *buf=wcs;
		memcpy(wcs,str,size*sizeof(wchar_t));
		Convert(str, wcs);
		for(size_t i=0;wcs[i];i++)	if(wcs[i]=='\n')	// parse '\n' symbol
		{
			wcs[i]=0;	w = Puts(buf,0,0,1.,0x10|font,'k','k');	// find width
			buf=wcs+i+1;	if(w>ww)	ww=w;
		}
		w = Puts(buf,0,0,1.,0x10|font,'k','k');
		if(w<ww)	w=ww;
		delete []wcs;
	}
	else
	{
		int s = (font/MGL_FONT_BOLD)&3;
		for(size_t i=0;i<size;i++)
		{
			long j = str[i]!=' ' ? Internal(str[i]) : Internal('!');
			if(j==-1)	continue;
			w+= GetWidth(s,j)/fact[s];
		}
	}
	return w;
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
float mglFont::Puts(const wchar_t *str,int font,int align, float c1,float c2) const
{
	if(GetNumGlyph()==0 || !str || *str==0)	return 0;
	float ww=0,w=0,h = (align&4) ? 500./fact[0] : 0;
	size_t size = mgl_wcslen(str)+1,num=0;
	if(parse)
	{
		unsigned *wcs = new unsigned[size], *buf=wcs;
		memcpy(wcs,str,size*sizeof(wchar_t));
		Convert(str, wcs);
		for(size_t i=0;wcs[i];i++)
		{
			if(wcs[i]=='\n')	// parse '\n' symbol
			{
				wcs[i]=0;	w = Puts(buf,0,0,1.f,0x10|font,c1,c2);	// find width
				Puts(buf,-w*(align&3)/2.f,-h - 500.*num/fact[0],1.f,font,c1,c2);	// draw it really
				buf=wcs+i+1;	num++;	if(w>ww)	ww=w;
			}
			if(wcs[i]=='\\' && wcs[i+1]=='n' && (wcs[i+2]>' ' || wcschr(L"{}[]()!@#$%^&*/-?.,_=+\\\"", wcs[i+2])))	// parse '\n' symbol
			{
				wcs[i]=0;	w = Puts(buf,0,0,1.f,0x10|font,c1,c2);	// find width
				Puts(buf,-w*(align&3)/2.f,-h - 500.*num/fact[0],1.f,font,c1,c2);	// draw it really
				buf=wcs+i+2;	num++;	if(w>ww)	ww=w;
			}
		}
		// draw string itself
		w = Puts(buf,0,0,1.f,0x10|font,c1,c2);	// find width
		Puts(buf,-w*(align&3)/2.f,-h - 500.*num/fact[0],1.f,font,c1,c2);	// draw it really
		if(w>ww)	ww=w;
		delete []wcs;
	}
	else
	{
		int s = (font/MGL_FONT_BOLD)&3;
		h *= fact[0]/fact[s];
		for(size_t i=0;i<size;i++)		// find width
		{
			long j = str[i]!=' ' ? Internal(str[i]) : Internal('!');
			if(j==-1)	continue;
			w+= GetWidth(s,j)/fact[s];
		}
		ww = w;		w *= -(align&3)/2.f;
		if(gr)	for(size_t i=0;i<size;i++)		// draw it
		{
			long j=0;	//Internal('!');
			if(str[i]!=' ')
			{
				j = Internal(str[i]);
				if(j==-1)	continue;
				gr->Glyph(w, -h, 1, (s+(font&MGL_FONT_WIRE))?4:0, j, c1+i*(c2-c1)/(size-1));
			}
			w+= GetWidth(s,j)/fact[s];
		}
	}
	return ww;
}
Esempio n. 3
0
void CE_SetNumArg (CodeEntry* E, long Num)
/* Set a new numeric argument for the given code entry that must already
** have a numeric argument.
*/
{
    char Buf[16];

    /* Check that the entry has a numerical argument */
    CHECK (E->Flags & CEF_NUMARG);

    /* Make the new argument string */
    if (E->Size == 2) {
        Num &= 0xFF;
        xsprintf (Buf, sizeof (Buf), "$%02X", (unsigned) Num);
    } else if (E->Size == 3) {
        Num &= 0xFFFF;
        xsprintf (Buf, sizeof (Buf), "$%04X", (unsigned) Num);
    } else {
        Internal ("Invalid instruction size in CE_SetNumArg");
    }

    /* Replace the argument by the new one */
    CE_SetArg (E, Buf);

    /* Use the new numerical value */
    E->Num = Num;
}
Esempio n. 4
0
void Logger::Error(const char *in, ...)
{
	string str;
	FORMAT(str);

	Internal(str, "ERROR", FG_RED);
}
Esempio n. 5
0
Logger::Logger(std::string path)
{
	string dir = path.substr(0, path.find_last_of("/"));

	m_File = new File(dir);
	m_File->mkdir();

	// Logger is borked if this happens
	if (!m_File->open(path, FileAccessMode_Write))
	{
		printf("%s\n", m_File->get_last_error().c_str());
		assert(0);
		return;
	}

	UseColors(true);
	ShowTraces(true);
#if DEBUG
	ShowDebug(true);
#else
	ShowDebug(false);
#endif

//	time_t raw = time(NULL);
//	char sTime[25];
//	strftime(sTime, 25, "%m/%d/%Y @ %H:%M:%S", localtime(&raw));

	Internal(string("# ") + Nepgear::FullName + " log started", "", FG_INVALID, false, false);
}
Esempio n. 6
0
  void Start()
  {
    Internal("Http::Start","()");

    if (enabled && !ctx)
    {
      // Try listening on the configured port number (8080 by default)
      // and advance foward until one is available

      for (int i = 0; i<100; ++i)
      {
        string j = print_string(port+i);
        const char *options[3] = { "listening_ports", j.c_str(), NULL};
        ctx = mg_start(&callback, NULL, options);
        if (ctx)
          break;
      }

      const char *option = NULL;
      if (ctx)
        option = mg_get_option(ctx,"listening_ports");

      if (option)
      {
        Info("Listening for HTTP connections on port ",option);
      }
      else
      {
        Info("Not listening for HTTP connections.");
      }
    }
  }
Esempio n. 7
0
  void Cleanup()
  {
    Internal("Logging::Cleanup","()");

    initialized = false;

    if (logOutput)
      fileClose(&logOutput);

#if !REGAL_NO_JSON
    if (jsonOutput)
    {
      fprintf(jsonOutput,"%s","{} ] }\n");
      fileClose(&jsonOutput);
    }
#endif

#if REGAL_LOG_ONCE
    delete uniqueMutex;
    uniqueMutex = NULL;
#endif

    delete buffer;
    delete bufferMutex;
    buffer = NULL;
    bufferMutex = NULL;
  }
Esempio n. 8
0
void MacExpandStart (Macro* M)
/* Start expanding a macro */
{
    MacExp* E;

    /* Check the argument */
    PRECONDITION (M && (M->Style != MAC_STYLE_DEFINE || DisableDefines == 0));

    /* We cannot expand an incomplete macro */
    if (M->Incomplete) {
        Error ("Cannot expand an incomplete macro");
        return;
    }

    /* Don't allow too many nested macro expansions - otherwise it is possible
     * to force an endless loop and assembler crash.
     */
    if (MacExpansions >= MAX_MACEXPANSIONS) {
        Error ("Too many nested macro expansions");
        return;
    }

    /* Create a structure holding expansion data */
    E = NewMacExp (M);

    /* Call the apropriate subroutine */
    switch (M->Style) {
        case MAC_STYLE_CLASSIC: StartExpClassic (E);    break;
        case MAC_STYLE_DEFINE:  StartExpDefine (E);     break;
        default:                Internal ("Invalid macro style: %d", M->Style);
    }
}
Esempio n. 9
0
void Logger::Trace(const char *in, ...)
{
	string str;
	FORMAT(str);

	Internal(str, "", FG_INVALID, m_show_traces);
}
Esempio n. 10
0
void Logger::Debug(const char *in, ...)
{
	string str;
	FORMAT(str);

	Internal(str, "Debug", FG_CYAN, m_show_debug);
}
Esempio n. 11
0
bc_t GetBranchCond (opc_t OPC)
/* Get the condition for the conditional branch in OPC */
{
    switch (OPC) {
        case OP65_BCC:  return BC_CC;
        case OP65_BCS:  return BC_CS;
        case OP65_BEQ:  return BC_EQ;
        case OP65_BMI:  return BC_MI;
        case OP65_BNE:  return BC_NE;
        case OP65_BPL:  return BC_PL;
        case OP65_BVC:  return BC_VC;
        case OP65_BVS:  return BC_VS;
        case OP65_JCC:  return BC_CC;
        case OP65_JCS:  return BC_CS;
        case OP65_JEQ:  return BC_EQ;
        case OP65_JMI:  return BC_MI;
        case OP65_JNE:  return BC_NE;
        case OP65_JPL:  return BC_PL;
        case OP65_JVC:  return BC_VC;
        case OP65_JVS:  return BC_VS;
        default:
            Internal ("GetBranchCond: Invalid opcode: %d", OPC);
            return 0;
    }
}
Esempio n. 12
0
void Logger::Warn(const char *in, ...)
{
	string str;
	FORMAT(str);

	Internal(str, "WARNING", FG_YELLOW);
}
Esempio n. 13
0
 IndexReader::IndexReader(){
 //Constructor.
 //Func - Creates an instance of IndexReader
 //Pre  - true
 //Post - An instance has been created with writeLock = NULL
   _internal = _CLNEW Internal(NULL, this);
 }
Esempio n. 14
0
opc_t MakeLongBranch (opc_t OPC)
/* Return the long version of the given branch. If the branch is already
** a long branch, return the opcode unchanged.
*/
{
    switch (OPC) {
        case OP65_BCC:
        case OP65_JCC:  return OP65_JCC;
        case OP65_BCS:
        case OP65_JCS:  return OP65_JCS;
        case OP65_BEQ:
        case OP65_JEQ:  return OP65_JEQ;
        case OP65_BMI:
        case OP65_JMI:  return OP65_JMI;
        case OP65_BNE:
        case OP65_JNE:  return OP65_JNE;
        case OP65_BPL:
        case OP65_JPL:  return OP65_JPL;
        case OP65_BVC:
        case OP65_JVC:  return OP65_JVC;
        case OP65_BVS:
        case OP65_JVS:  return OP65_JVS;
        case OP65_BRA:
        case OP65_JMP:  return OP65_JMP;
        default:
            Internal ("MakeLongBranch: Invalid opcode: %d", OPC);
            return 0;
    }
}
Esempio n. 15
0
opc_t MakeShortBranch (opc_t OPC)
/* Return the short version of the given branch. If the branch is already
** a short branch, return the opcode unchanged.
*/
{
    switch (OPC) {
        case OP65_BCC:
        case OP65_JCC:  return OP65_BCC;
        case OP65_BCS:
        case OP65_JCS:  return OP65_BCS;
        case OP65_BEQ:
        case OP65_JEQ:  return OP65_BEQ;
        case OP65_BMI:
        case OP65_JMI:  return OP65_BMI;
        case OP65_BNE:
        case OP65_JNE:  return OP65_BNE;
        case OP65_BPL:
        case OP65_JPL:  return OP65_BPL;
        case OP65_BVC:
        case OP65_JVC:  return OP65_BVC;
        case OP65_BVS:
        case OP65_JVS:  return OP65_BVS;
        case OP65_BRA:
        case OP65_JMP:  return (CPUIsets[CPU] & CPU_ISET_65SC02)? OP65_BRA : OP65_JMP;
        default:
            Internal ("MakeShortBranch: Invalid opcode: %d", OPC);
            return 0;
    }
}
Esempio n. 16
0
opc_t GetInverseBranch (opc_t OPC)
/* Return a branch that reverse the condition of the branch given in OPC */
{
    switch (OPC) {
        case OP65_BCC:  return OP65_BCS;
        case OP65_BCS:  return OP65_BCC;
        case OP65_BEQ:  return OP65_BNE;
        case OP65_BMI:  return OP65_BPL;
        case OP65_BNE:  return OP65_BEQ;
        case OP65_BPL:  return OP65_BMI;
        case OP65_BVC:  return OP65_BVS;
        case OP65_BVS:  return OP65_BVC;
        case OP65_JCC:  return OP65_JCS;
        case OP65_JCS:  return OP65_JCC;
        case OP65_JEQ:  return OP65_JNE;
        case OP65_JMI:  return OP65_JPL;
        case OP65_JNE:  return OP65_JEQ;
        case OP65_JPL:  return OP65_JMI;
        case OP65_JVC:  return OP65_JVS;
        case OP65_JVS:  return OP65_JVC;
        default:
            Internal ("GetInverseBranch: Invalid opcode: %d", OPC);
            return 0;
    }
}
Esempio n. 17
0
unsigned GetInsnSize (opc_t OPC, am_t AM)
/* Return the size of the given instruction */
{
    /* Get the opcode desc and check the size given there */
    const OPCDesc* D = &OPCTable[OPC];
    if (D->Size != 0) {
        return D->Size;
    }

    /* Check the addressing mode. */
    switch (AM) {
        case AM65_IMP:     return 1;
        case AM65_ACC:     return 1;
        case AM65_IMM:     return 2;
        case AM65_ZP:      return 2;
        case AM65_ZPX:     return 2;
        case AM65_ABS:     return 3;
        case AM65_ABSX:    return 3;
        case AM65_ABSY:    return 3;
        case AM65_ZPX_IND: return 2;
        case AM65_ZP_INDY: return 2;
        case AM65_ZP_IND:  return 2;
        default:
            Internal ("Invalid addressing mode");
            return 0;
    }
}
Esempio n. 18
0
unsigned SizeOf (const Type* T)
/* Compute size of object represented by type array. */
{
    switch (UnqualifiedType (T->C)) {

        case T_VOID:
            return 0;   /* Assume voids have size zero */

        case T_SCHAR:
        case T_UCHAR:
            return SIZEOF_CHAR;

        case T_SHORT:
        case T_USHORT:
            return SIZEOF_SHORT;

        case T_INT:
        case T_UINT:
            return SIZEOF_INT;

        case T_PTR:
        case T_FUNC:    /* Maybe pointer to function */
            return SIZEOF_PTR;

        case T_LONG:
        case T_ULONG:
            return SIZEOF_LONG;

        case T_LONGLONG:
        case T_ULONGLONG:
            return SIZEOF_LONGLONG;

        case T_ENUM:
            return SIZEOF_INT;

        case T_FLOAT:
            return SIZEOF_FLOAT;

        case T_DOUBLE:
            return SIZEOF_DOUBLE;

        case T_STRUCT:
        case T_UNION:
            return ((SymEntry*) T->A.P)->V.S.Size;

        case T_ARRAY:
            if (T->A.L == UNSPECIFIED) {
                /* Array with unspecified size */
                return 0;
            } else {
                return T->A.L * SizeOf (T + 1);
            }

        default:
            Internal ("Unknown type in SizeOf: %04lX", T->C);
            return 0;

    }
}
Esempio n. 19
0
const char* GetModelName (O65Model M)
/* Map the model to its name. */
{
    if (M < 0 || M >= O65_MODEL_COUNT) {
        Internal ("O65 Model %d not found", M);
    }
    return NameTable[M];
}
Esempio n. 20
0
static void WarnPragma (StrBuf* B)
/* Enable/disable warnings */
{
    long   Val;
    int    Push;

    /* A warning name must follow */
    IntStack* S = GetWarning (B);
    if (S == 0) {
        return;
    }

    /* Comma follows */
    if (!GetComma (B)) {
        return;
    }

    /* Check for the "push" or "pop" keywords */
    switch (ParsePushPop (B)) {

        case PP_NONE:
            Push = 0;
            break;

        case PP_PUSH:
            Push = 1;
            break;

        case PP_POP:
            /* Pop the old value and bail out */
            PopInt (S);
            return;

        case PP_ERROR:
            /* Bail out */
            return;

        default:
            Internal ("Invalid result from ParsePushPop");
    }

    /* Boolean argument follows */
    if (HasStr (B, "true") || HasStr (B, "on")) {
        Val = 1;
    } else if (HasStr (B, "false") || HasStr (B, "off")) {
        Val = 0;
    } else if (!SB_GetNumber (B, &Val)) {
        Error ("Invalid pragma argument");
        return;
    }

    /* Set/push the new value */
    if (Push) {
        PushInt (S, Val);
    } else {
        IS_Set (S, Val);
    }
}
Esempio n. 21
0
File: segments.c Progetto: cc65/cc65
void SegDump (void)
/* Dump the segments and it's contents */
{
    unsigned I, J;
    unsigned long Count;
    unsigned char* Data;

    for (I = 0; I < CollCount (&SegmentList); ++I) {
        Segment* Seg = CollAtUnchecked (&SegmentList, I);
        printf ("Segment: %s (%lu)\n", GetString (Seg->Name), Seg->Size);
        for (J = 0; J < CollCount (&Seg->Sections); ++J) {
            Section* S = CollAtUnchecked (&Seg->Sections, J);
            unsigned J;
            Fragment* F = S->FragRoot;
            printf ("  Section:\n");
            while (F) {
                switch (F->Type) {

                    case FRAG_LITERAL:
                        printf ("    Literal (%u bytes):", F->Size);
                        Count = F->Size;
                        Data  = F->LitBuf;
                        J = 100;
                        while (Count--) {
                            if (J > 75) {
                                printf ("\n   ");
                                J = 3;
                            }
                            printf (" %02X", *Data++);
                            J += 3;
                        }
                        printf ("\n");
                        break;

                    case FRAG_EXPR:
                        printf ("    Expression (%u bytes):\n", F->Size);
                        printf ("    ");
                        DumpExpr (F->Expr, 0);
                        break;

                    case FRAG_SEXPR:
                        printf ("    Signed expression (%u bytes):\n", F->Size);
                        printf ("      ");
                        DumpExpr (F->Expr, 0);
                        break;

                    case FRAG_FILL:
                        printf ("    Empty space (%u bytes)\n", F->Size);
                        break;

                    default:
                        Internal ("Invalid fragment type: %02X", F->Type);
                }
                F = F->Next;
            }
        }
    }
}
Esempio n. 22
0
void CheckAssertions (void)
/* Check all assertions */
{
    unsigned I;

    /* Walk over all assertions */
    for (I = 0; I < CollCount (&Assertions); ++I) {

        const LineInfo* LI;
        const char* Module;
        unsigned Line;

        /* Get the assertion */
        Assertion* A = CollAtUnchecked (&Assertions, I);

        /* Ignore assertions that shouldn't be handled at link time */
        if (!AssertAtLinkTime (A->Action)) {
            continue;
        }

        /* Retrieve the relevant line info for this assertion */
        LI = CollConstAt (&A->LineInfos, 0);

        /* Get file name and line number from the source */
        Module = GetSourceName (LI);
        Line   = GetSourceLine (LI);

        /* If the expression is not constant, we're not able to handle it */
        if (!IsConstExpr (A->Expr)) {
            Warning ("Cannot evaluate assertion in module `%s', line %u",
                     Module, Line);
        } else if (GetExprVal (A->Expr) == 0) {

            /* Assertion failed */
            const char* Message = GetString (A->Msg);

            switch (A->Action) {

                case ASSERT_ACT_WARN:
                case ASSERT_ACT_LDWARN:
                    Warning ("%s(%u): %s", Module, Line, Message);
                    break;

                case ASSERT_ACT_ERROR:
                case ASSERT_ACT_LDERROR:
                    Error ("%s(%u): %s", Module, Line, Message);
                    break;

                default:
                    Internal ("Invalid assertion action (%u) in module `%s', "
                              "line %u (file corrupt?)",
                              A->Action, Module, Line);
                    break;
            }
        }
    }
}
Esempio n. 23
0
long GetExportVal (const Export* E)
/* Get the value of this export */
{
    if (E->Expr == 0) {
     	/* OOPS */
       	Internal ("`%s' is an undefined external", GetString (E->Name));
    }
    return GetExprVal (E->Expr);
}
Esempio n. 24
0
void
Parser::onPop()
{
  Internal("Regal::Json::Parser::onPop","()");

  if (depth)
    --depth;
  else
    current = parent[current];
}
Esempio n. 25
0
static int GetCmpRegVal (const CodeEntry* E)
/* Return the register value for an immediate compare */
{
    switch (E->OPC) {
	case OP65_CMP: return E->RI->In.RegA;
	case OP65_CPX: return E->RI->In.RegX;
	case OP65_CPY: return E->RI->In.RegY;
	default:       Internal ("Invalid opcode in GetCmpRegVal");
	               return 0;  /* Not reached */
    }
}
Esempio n. 26
0
void
Parser::onValue()
{
  Internal("Regal::Json::Parser::onValue","NULL");

  switch (current)
  {
    default:
      Warning("Ignoring JSON value NULL");
      break;
  }
}
Esempio n. 27
0
static unsigned long ReadO65Size (FILE* F, const O65Header* H)
/* Read a size variable (16 or 32 bit, depending on the mode word in the
 * header) from the o65 file.
 */
{
    unsigned long Size = 0;     /* Initialize to avoid warnings */
    switch (H->mode & O65_SIZE_MASK) {
        case O65_SIZE_32BIT:    Size = Read32 (F);      break;
        case O65_SIZE_16BIT:    Size = Read16 (F);      break;
        default:                Internal ("Invalid size field value in o65 header");
    }
    return Size;
}
Esempio n. 28
0
static char GetAddrSizeCode (unsigned char AddrSize)
/* Get a one char code for the address size */
{
    switch (AddrSize) {
        case ADDR_SIZE_ZP:      return 'Z';
        case ADDR_SIZE_ABS:     return 'A';
        case ADDR_SIZE_FAR:     return 'F';
        case ADDR_SIZE_LONG:    return 'L';
        default:
            Internal ("Invalid address size: %u", AddrSize);
	    /* NOTREACHED */
	    return '-';
    }
}
Esempio n. 29
0
const char* ED_GetLabelName (const ExprDesc* Expr, long Offs)
/* Return the assembler label name of the given expression. Beware: This
 * function may use a static buffer, so the name may get "lost" on the second
 * call to the function.
 */
{
    static StrBuf Buf = STATIC_STRBUF_INITIALIZER;

    /* Expr may have it's own offset, adjust Offs accordingly */
    Offs += Expr->IVal;

    /* Generate a label depending on the location */
    switch (ED_GetLoc (Expr)) {

        case E_LOC_ABS:
            /* Absolute: numeric address or const */
            SB_Printf (&Buf, "$%04X", (int)(Offs & 0xFFFF));
            break;

        case E_LOC_GLOBAL:
        case E_LOC_STATIC:
            /* Global or static variable */
            if (Offs) {
                SB_Printf (&Buf, "%s%+ld", SymGetAsmName (Expr->Sym), Offs);
            } else {
                SB_Printf (&Buf, "%s", SymGetAsmName (Expr->Sym));
            }
            break;

        case E_LOC_REGISTER:
            /* Register variable */
            SB_Printf (&Buf, "regbank+%u", (unsigned)((Offs + Expr->Name) & 0xFFFFU));
            break;

        case E_LOC_LITERAL:
            /* Literal in the literal pool */
            if (Offs) {
                SB_Printf (&Buf, "%s%+ld", LocalLabelName (Expr->Name), Offs);
            } else {
                SB_Printf (&Buf, "%s", LocalLabelName (Expr->Name));
            }
            break;

        default:
            Internal ("Invalid location in ED_GetLabelName: 0x%04X", ED_GetLoc (Expr));
    }

    /* Return a pointer to the static buffer */
    return SB_GetConstBuf (&Buf);
}
Esempio n. 30
0
void MacExpandStart (void)
/* Start expanding the macro in SVal */
{
    /* Search for the macro */
    Macro* M = HT_FindEntry (&MacroTab, &SVal);
    CHECK (M != 0);

    /* Call the apropriate subroutine */
    switch (M->Style) {
    	case MAC_STYLE_CLASSIC:	StartExpClassic (M);	break;
	case MAC_STYLE_DEFINE:	StartExpDefine (M);	break;
	default:   	      	Internal ("Invalid macro style: %d", M->Style);
    }
}