Esempio n. 1
0
sDInt sDIDir::Cmd(sInt cmd,sChar *name,sDiskItem *di)
{
  sInt result;
  sChar buffer[sDI_PATHSIZE];

  switch(cmd)
  {
  case sDIC_FINDALL:
  case sDIC_FIND:
    if(!Complete)
      LoadDir();
    return sTRUE;
  case sDIC_CREATEDIR:
    sCopyString(buffer,Path,sDI_PATHSIZE);
    sAppendString(buffer,"/",sDI_PATHSIZE);
    sAppendString(buffer,name,sDI_PATHSIZE);
    result = sSystem->MakeDir(buffer);
    LoadDir();
    return result;
  case sDIC_CREATEFILE:
    sCopyString(buffer,Path,sDI_PATHSIZE);
    sAppendString(buffer,"/",sDI_PATHSIZE);
    sAppendString(buffer,name,sDI_PATHSIZE);
    result = sSystem->SaveFile(buffer,(sU8*)" ",0);
    LoadDir();
    return result;
  case sDIC_RELOAD:
    Complete = 0;
    LoadDir();
    return sTRUE;
  default:
    return sFALSE;
  }
}
Esempio n. 2
0
void sTextApp::UpdateStatus()
{
  sSPrintF(StatusLine,32,"Line %d",Edit->GetCursorY()+1);
  sSPrintF(StatusColumn,32,"Col %d",Edit->GetCursorX()+1);
  if(Edit->PathName[0]==0)
    sCopyString(StatusName,"(noname)",sizeof(StatusName));
  else
    sCopyString(StatusName,Edit->PathName,sizeof(StatusName));
  StatusChanged[0] = 0;
  if(Edit->Changed)
    sCopyString(StatusChanged,"Changed",32);

}
Esempio n. 3
0
static sBool sCompileDX9(sCompileResult &result, sInt stype, sInt dtype, sInt flags, const sChar8 *src, sInt len, const sChar8 *name)
{
#if sCOMP_DX9_ENABLE
  ID3DXBuffer *bytecode;

  sRelease(result.D3D9.CTable);
  sRelease(result.D3D9.Errors);

  sU32 d3dflags = 0;
  if(flags&sSCF_DEBUG)
    d3dflags |= D3DXSHADER_DEBUG;
  //if (sGetShellSwitch(L"n"))
  //  flags |= D3DXSHADER_SKIPOPTIMIZATION; // only use in case of emergency

  const sChar8 *profile8 = GetProfile(dtype);
  sChar profile[16];
  sCopyString(profile,profile8,16);

  // use old compiler for generating shader model 1_* code
#ifdef D3DXSHADER_USE_LEGACY_D3DX9_31_DLL
  if(sMatchWildcard(L"ps_1_*",profile))
    d3dflags |= D3DXSHADER_USE_LEGACY_D3DX9_31_DLL;
#endif

  if(D3DXCompileShader(src,len,0,0,name,profile8,d3dflags,&bytecode,&result.D3D9.Errors,&result.D3D9.CTable)!=D3D_OK)
    result.Valid = sFALSE;
  else
    result.Valid = sTRUE;

  // print errors and warnings
  if(result.D3D9.Errors)
  {
    ID3DXBuffer *buffer = result.D3D9.Errors;
    //sInt size = buffer->GetBufferSize();
    sCopyString(result.Errors,(sChar8*)buffer->GetBufferPointer(),result.Errors.Size());
  }

  if(!result.Valid)
  {
    sRelease(bytecode);
    return sFALSE;
  }

  // get source code
  sAddShaderBlob(result.ShaderBlobs,dtype,bytecode->GetBufferSize(),(const sU8*)bytecode->GetBufferPointer());
  return result.Valid;
#else
  return sFALSE;
#endif // sCOMP_DX9_ENABLE
}
Esempio n. 4
0
void sMakeAbsolutePath(const sStringDesc &buffer,const char *file)
{
  if(sIsAbsolutePath(file))
  {
    sCopyString(buffer,file);
  }
  else
  {
    sString<sMaxPath> b;
    sGetCurrentDir(b);
    b.Add("/");
    b.Add(file);
    sCopyString(buffer,b);
  }
}
Esempio n. 5
0
void LaunchGrid()
{
  sGridFrame *win;
  static sInt Data[64];
  static sChar buffer[64];
  
  sCopyString(buffer,"hello, world!",sizeof(buffer));

  win = new sGridFrame();
  win->SetGrid(12,5,0,sPainter->GetHeight(sGui->PropFont)+8);
  win->Position.Init(0,0,300,200);
  win->AddCon(0,0,4,1)->Button("button",0); 
  win->AddCon(0,1,4,1)->EditBool(0,&Data[0],"bool");
  win->AddCon(0,2,4,1)->EditCycle(0,&Data[1],"cycle","null|eins|zwei|drei|vier");
  win->AddCon(4,0,4,1)->EditRGB(0,&Data[8],"rgb");
  win->AddCon(4,1,4,1)->EditRGBA(0,&Data[12],"rgba");
  win->AddCon(4,2,4,1,2)->EditFixed(0,&Data[16],0);
  win->AddCon(0,3,2,1)->Label("vector"); 
  win->AddCon(2,3,6,1,4)->EditInt(0,&Data[20],"");
  win->AddCon(8,0,4,1)->EditInt(0,&Data[2],"int");
  win->AddCon(8,1,4,1)->EditFloat(0,(sF32 *)&Data[3],"float");
  win->AddCon(8,2,4,1)->EditHex(0,(sU32 *)&Data[4],"hex");
  win->AddCon(8,3,4,1)->EditFixed(0,&Data[5],"fixed");
  win->AddCon(0,4,2,1)->Label("edit"); 
  win->AddCon(2,4,10,1)->EditString(0,buffer,0,64);
  win->AddBorder(new sSizeBorder);
  win->AddBorder(new sScrollBorder);
  sGui->AddApp(win);
}
Esempio n. 6
0
// helpers
static sChar *BStrToString( BSTR str, sChar *defString = "", bool stripWhitespace = false )
{
  if(!str)
  {
    sInt len = sGetStringLen(defString);
    sChar *buffer = new sChar[len+1];
    sCopyString(buffer,defString,len+1);

    return buffer;
  }
  else
  {
    sInt len = SysStringLen(str);
    sChar *buffer = new sChar[len+1];

	sInt j = 0;
    for( sInt i=0;i<len;i++ )
	{
		if( stripWhitespace && isspace(str[i]) )
			continue;
		buffer[j] = (str[i] >= 32 && str[i] < 128) ? str[i] : '?';
		++j;
	}

    buffer[j] = 0;

    return buffer;
  }
}
Esempio n. 7
0
sBool sResolveName(const sChar *hostname, sIPAddress &address)
{
  sChar8 name[512];
  sCopyString(name,hostname,511);

  sClear(address);

  struct hostent *result=gethostbyname(name);

  if (result && result->h_addrtype==AF_INET && result->h_length==4)
  {
    sInt n=0;
    while (result->h_addr_list[n]) n++;
    if (n>1)
    {
      // if there are several IP addresses for a host name, pick one
      // randomly. In most cases this is due to load balancing anyway.
      sRandom rnd;
      rnd.Seed(sGetRandomSeed());
      n=rnd.Int(n);
    }
    else n--;

    for (sInt i=0; i<4; i++)
      address.Addr[i]=result->h_addr_list[n][i];
    return sTRUE;
  }
  return sFALSE;
}
Esempio n. 8
0
sInt DebugInfo::GetNameSpaceByName(sChar *name)
{
  sChar *pp = name - 2;
  sChar *p;
  sInt cname;

  while((p = sFindString(pp+2,"::")))
    pp = p;

  while((p = sFindString(pp+1,".")))
    pp = p;

  if(pp != name - 2)
  {
    sChar buffer[2048];
    sCopyString(buffer,name,2048);

    if(pp - name < 2048)
      buffer[pp - name] = 0;

    cname = MakeString(buffer);
  }
  else
    cname = MakeString("<global>");

  return GetNameSpace(cname);
}
Esempio n. 9
0
sBool sDIFile::SetAttr(sInt attr,void *data,sInt s)
{
  sChar path[sDI_PATHSIZE];
  sChar path2[sDI_PATHSIZE];
  sInt result;

  result = sTRUE;
  switch(attr)
  {
  case sDIA_NAME:
    MakePath(path);
    MakePath(path2,(sChar *)data);
    result = sSystem->RenameFile(path,path2);
    if(result)
      sCopyString(Name,(sChar *)data,sizeof(Name));
    break;
  case sDIA_DATA:
    MakePath(path);
    result = sSystem->SaveFile(path,(sU8 *)data,s);
    if(result)
      Size = s;
    else
      ;//Size = 0;   // need better error handling here!
    break;
  default:
    result = sFALSE;
    break;
  }
  return result;
}
Esempio n. 10
0
sBool sDIDir::GetAttr(sInt attr,void *data,sInt &size)
{
  sInt result;
  sChar *t,*r;

  result = sTRUE;
  switch(attr)
  {
  case sDIA_NAME:
    r = t =  Path;
    while(*r!=0)
    {
      if(*r=='/')
        t = r+1;
      r++;
    }
    sCopyString((sChar *)data,t,size);
    break;
  case sDIA_ISDIR:
    *(sInt*)data = 1;
    break;
  case sDIA_INCOMPLETE:
    *(sInt*)data = Complete ? 0 : 1;
    break;
  default:
    result = sFALSE;
    break;
  }

  return result;
}
Esempio n. 11
0
sBool sDIFile::Init(sChar *name,sDiskItem *parent,void *data)
{
  Size = ((sU32 *)(data))[0];
  WriteProtect = ((sU32 *)(data))[1];
  sCopyString(Name,name,sizeof(Name));
  Parent = parent;
  return sTRUE;
}
Esempio n. 12
0
void sDIFile::MakePath(sChar *dest,sChar *name)
{
  if(name==0)
    name = Name;
  sCopyString(dest,((sDIDir *)Parent)->Path,sDI_PATHSIZE);
  sAppendString(dest,"/",sDI_PATHSIZE);
  sAppendString(dest,name,sDI_PATHSIZE);
}
Esempio n. 13
0
void sFileWindow::GetPath(sChar *buffer,sInt size)
{
  sCopyString(buffer,Path,size);
  if(Name[0])
  {
    sAppendString(buffer,"/",size);
    sAppendString(buffer,Name,size);
  }
}
Esempio n. 14
0
void sFont2D::Init(const sChar *name,sInt size,sInt flags,sInt width)
{
  Exit();

  TEXTMETRIC tm;

  prv = new sFont2DPrivate;
  prv->Font=0;
  prv->BackPen = 0;

  if (name && name[0])
  {
    LOGFONTW log;
    sClear(log);
    log.lfHeight = size;
    log.lfWidth = width;
    log.lfCharSet = DEFAULT_CHARSET;
    if(flags & sF2C_BOLD)
      log.lfWeight = FW_BOLD;
    if(flags & sF2C_ITALICS)
      log.lfItalic = 1;
    if(flags & sF2C_UNDERLINE)
      log.lfUnderline = 1;
    if(flags & sF2C_STRIKEOUT)
      log.lfStrikeOut = 1;
    if(flags & sF2C_SYMBOLS)
      log.lfCharSet = SYMBOL_CHARSET;
    if(flags & sF2C_NOCLEARTYPE)
      log.lfQuality = ANTIALIASED_QUALITY;
    sCopyString(log.lfFaceName,name,LF_FACESIZE);
    prv->Font = CreateFontIndirectW(&log);
  }

  if (!prv->Font) // no font found -> get default Windows font
  {
    NONCLIENTMETRICS ncm;
    sClear(ncm);
    ncm.cbSize=sizeof(ncm);
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(ncm),&ncm,0);
    prv->Font = CreateFontIndirectW(&ncm.lfMessageFont);
  }

  prv->BackColor = GDICOL(0xffffff);
  prv->TextColor = GDICOL(0x000000);

  // Get font metrics. must create a DC for this!
  HDC dc = GetDC(sHWND);
  HGDIOBJ oldfont = SelectObject(dc,prv->Font);
  GetTextMetricsW(dc,&tm);
  GetCharABCWidths(dc,0,NUMABC-1,prv->Widths);
  SelectObject(dc,oldfont);
  ReleaseDC(sHWND,dc);

  prv->Baseline = tm.tmAscent;
  prv->Height = tm.tmHeight;
  prv->CharHeight = tm.tmHeight - tm.tmInternalLeading;
}
Esempio n. 15
0
bool sGetSystemPath(sSystemPath sp,const sStringDesc &desc)
{
    switch(sp)
    {
    case sSP_User:
        sCopyString(desc,"~");
        return true;
    }
    return false;
}
Esempio n. 16
0
sBool sShaderCompile(sCompileResult &result, sInt stype, sInt dtype, const sChar *source, sInt len, sInt flags /*=0*/, const sChar *name/*=0*/)
{
  for(sInt i=0;i<CompilerCount;i++)
  {
    if((ShaderCompiler[i].SrcType&(sSTF_PLATFORM|sSTF_PROFILE)) == (stype&(sSTF_PLATFORM|sSTF_PROFILE)) && (ShaderCompiler[i].DstType&(sSTF_PLATFORM|sSTF_PROFILE)) == (dtype&(sSTF_PLATFORM|sSTF_PROFILE)))
    {
      sChar8 *buffer = new sChar8[len];
      sCopyString(buffer,source,len);
      if(!name) name = L"main";
      sChar8 name8[64];
      sCopyString(name8,name,64);
      sBool check = (*ShaderCompiler[i].Func)(result,stype,dtype,flags,buffer,len,name8);
      sDeleteArray(buffer);
      return check;
    }
  }
  sPrintF(L"no shader compiler found for 0x%08x -> 0x%08x\n",stype,dtype);
  return sFALSE;
}
Esempio n. 17
0
sBool sGetHostName(const sStringDesc &str, const sIPAddress &address)
{
  struct hostent *result = gethostbyaddr((const char*)address.Addr,4,AF_INET);
  if(result)
  {
    sCopyString(str.Buffer,result->h_name,str.Size);
    return sTRUE;
  }
  return sFALSE;
}
Esempio n. 18
0
sBool sDISystemInfo::GetAttr(sInt attr,void *d,sInt &s)
{
  switch(attr)
  {
  case sDIA_NAME:
    sCopyString((sChar *)d,Name,s);
    return sTRUE;
  default:
    return sFALSE;
  }
}
Esempio n. 19
0
sBool sGetLocalHostName(const sStringDesc &str)
{
  sChar8 name[512];
  str.Buffer[0]=0;
  if (!gethostname(name,512))
  {
    sCopyString(str,name);
    return sTRUE;
  }
  return sFALSE;
}
Esempio n. 20
0
void sDIDir::LoadDir()
{
  sDIDir *nd;
  sDIFile *nf;
  sDirEntry *dir,*ds;
  sChar name[sDI_PATHSIZE];
  sU32 prv[2];

  List->Clear();

  ds = dir = sSystem->LoadDir(Path);
  while(dir && dir->Name[0])
  {
    if(dir->IsDir)
    {
      sCopyString(name,Path,sDI_PATHSIZE);
      sAppendString(name,"/",sDI_PATHSIZE);
      sAppendString(name,dir->Name,sDI_PATHSIZE);
      nd = new sDIDir;
      if(nd->Init(name,this,0))
        List->Add(nd);
    }
    else
    {
      prv[0] = dir->Size;
      prv[1] = 0;
      sCopyString(name,dir->Name,sDI_NAMESIZE);

      nf = new sDIFile;
      if(nf->Init(name,this,prv))
        List->Add(nf);
    }

    dir++;
  }
  delete[] ds;
  Complete = 1;
}
Esempio n. 21
0
void sTextControl::Realloc(sInt size)
{
  sChar *s;
  if(size>TextAlloc)
  {
    size = sMax(size*3/2,TextAlloc*2);
    s = new sChar[size];
    sCopyString(s,Text,size);
    delete[] Text;
    Text = s;
    TextAlloc = size;
    Post(ReallocCmd);
  }
}
Esempio n. 22
0
static sBool GetCgError(const sStringDesc &errors)
{
#if sCOMP_CG_ENABLE
  CGerror error;
  const sChar8 *string = cgGetLastErrorString(&error);

  if(error==CG_NO_ERROR) return sFALSE;

  sErrorString temp0;
  sErrorString temp1;
  sCopyString(temp0,string,0x4000);

  if(error==CG_COMPILER_ERROR)
  {
    const sChar8 *msg = cgGetLastListing(CGC);
    if(msg)
      sCopyString(temp1,msg,0x4000);
  }
  sSPrintF(errors,L"%s\n%s",temp0,temp1);
  return sTRUE;
#else
  return sTRUE;
#endif
}
Esempio n. 23
0
sBool sMiniFTPClient::Connect(const sChar *host,sIPPort port)
{
  Disconnect();

  sCopyString(TargetHost,host);
  TargetPort = port;
  if(!sResolveNameAndPort(host,TargetAddress,TargetPort))
  {
    sLogF(L"MiniFTP",L"Could not resolve host '%s'.\n",host);
    return sFALSE;
  }

  State = CS_NOTCONNECTED;
  return TryReconnect(1);
}
Esempio n. 24
0
sBool sDIApp::GetAttr(sInt attr,void *data,sInt &size)
{
  sInt result;

  result = sTRUE;
  switch(attr)
  {
  case sDIA_NAME:
    sCopyString((sChar *)data,Name,size);
    break;
  default:
    result = sFALSE;
    break;
  }

  return result;
}
Esempio n. 25
0
sBool sDIFile::GetAttr(sInt attr,void *data,sInt &s)
{
  sChar path[sDI_PATHSIZE];
  sInt result;
  sU8 *d2;
  sInt rs;

  result = sTRUE;
  switch(attr)
  {
  case sDIA_NAME:
    sCopyString((sChar *)data,Name,s);
    break;
  case sDIA_DATA:
    MakePath(path);
    if(data)
    {
      d2 = sSystem->LoadFile(path,rs);
      if(d2 && rs<=s)
      {
        sCopyMem(data,d2,rs);
        result = sTRUE;
      }
      else
      {
        result = sFALSE;
      }
      if(d2)
        delete[] d2;
    }
    else
      s = Size;
    break;
  case sDIA_ISDIR:
    *(sInt *)data = 0;
    break;
  case sDIA_WRITEPROT:
    *(sInt *)data = WriteProtect;
    break;

  default:
    result = sFALSE;
  }
  return result;
}
Esempio n. 26
0
sBool sCompileExtern(sCompileCallback cb, sCompileResult &result, sInt stype, sInt dtype, sInt flags, const sChar8 *source, sInt len, const sChar8 *name)
{
  if(cb)
  {
    sExternCompileBuffer buffer(128*1024,4*1024);
    result.Valid = (*cb)(&buffer,stype,dtype,flags,source,len,name);
    if(result.Valid)
      sAddShaderBlob(result.ShaderBlobs,dtype,buffer.ResultSize,buffer.Buffer);
    else
    {
      sChar error[4096];
      sCopyString(error,buffer.Message,4096);
      sLogF(L"asc",L"extern compiler error:\n%s\n",error);
      result.Errors = error;
    }
    return result.Valid;
  }
  return sFALSE;
}
Esempio n. 27
0
sBool sDIRoot::GetAttr(sInt attr,void *d,sInt &s)
{
  sInt result;

  result = sTRUE;
  switch(attr)
  {
  case sDIA_NAME:
    sCopyString((sChar *)d,"root",s);
    break;
  case sDIA_ISDIR:
    *(sInt*)d = 1;
    break;
  default:
    result = sFALSE;
    break;
  }

  return result;
}
Esempio n. 28
0
sTextControl::sTextControl()
{
  TextAlloc = 0x1000;
  Text = new sChar[TextAlloc];
  Text[0] = 0;

  Cursor = 0;
  Overwrite = 0;
  SelMode = 0;
  SelPos = 0;
  CursorWish = 0;

  DoneCmd = 0;
  CursorCmd = 0;
  ReallocCmd = 0;
  Changed = 0;
  Static = 0;
  RecalcSize = 0;

  File = 0;
  PathName[0] = 0;
  sCopyString(PathName,"Disks/c:/NxN",sDI_PATHSIZE);
}
Esempio n. 29
0
// helpers
static sChar *BStrToString(BSTR str,sChar *defString="")
{
    if(!str)
    {
        sInt len = sGetStringLen(defString);
        sChar *buffer = new sChar[len+1];
        sCopyString(buffer,defString,len+1);

        return buffer;
    }
    else
    {
        sInt len = SysStringLen(str);
        sChar *buffer = new sChar[len+1];

        for(sInt i=0; i<len; i++)
            buffer[i] = (str[i] >= 32 && str[i] < 128) ? str[i] : '?';

        buffer[len] = 0;

        return buffer;
    }
}
Esempio n. 30
0
static sBool sCompileCg(sCompileResult &result, sInt stype, sInt dtype, sInt flags, const sChar8 *src, sInt len, const sChar8 *name)
{
#if sCOMP_CG_ENABLE
  if(result.Cg.Program)
    cgDestroyProgram(result.Cg.Program);

  sChar8 *src8 = new sChar8[len];
  sCopyString(src8,src,len);

  CGprofile prof = cgGetProfile(GetProfile(dtype));
  CGprogram program = cgCreateProgram(CGC,CG_SOURCE,src8,prof,name,0);

  if(GetCgError(result.Errors)) goto error;

  cgCompileProgram(program);
  if(GetCgError(result.Errors)) goto error;
  const sChar8 *out8 = cgGetProgramString(program,CG_COMPILED_PROGRAM);
  if(GetCgError(result.Errors)) goto error;
  sInt size = 0;
  while(out8[size]) size++;

  sAddShaderBlob(result.ShaderBlobs,dtype,size,(const sU8*)out8);

  result.Valid = sTRUE;
  sDeleteArray(src8);
  return sTRUE;

error:

  result.Valid = sFALSE;
  sDeleteArray(src8);
  return sFALSE;
#else
  sLogF(L"asc",L"sCOMP_CG_ENABLE == 0 no cg compiler available\n");
  return sFALSE;
#endif // sCOMP_CG_ENABLE
}