Exemple #1
0
    static int next(lua_State * L)
    {
        directory_iterator * self = reinterpret_cast<directory_iterator *>(luaL_checkudata(L, 1, MT));
        if(!self->m_dir) return 0;
        struct dirent * entry = readdir(self->m_dir);
        if(!entry) return 0;
        
        char file[1024];
        copystring(file, self->m_dir_path, sizeof(file));
        concatstring(file, "/", sizeof(file));
        concatstring(file, entry->d_name, sizeof(file));
	    
        struct stat info;
        if (stat(file, &info)) return 0;
        
        unsigned char file_type = DT_UNKNOWN;
        if (S_ISREG(info.st_mode))       file_type = DT_REG;
        else if (S_ISDIR(info.st_mode))  file_type = DT_DIR;
        else if (S_ISFIFO(info.st_mode)) file_type = DT_FIFO;
        else if (S_ISLNK(info.st_mode))  file_type = DT_LNK;
        else if (S_ISBLK(info.st_mode))  file_type = DT_BLK;
        else if (S_ISCHR(info.st_mode))  file_type = DT_CHR;
        else if (S_ISSOCK(info.st_mode)) file_type = DT_SOCK;
	
        lua_pushinteger(L, file_type);
        lua_pushstring(L, entry->d_name);
        
        return 2;
    }
Exemple #2
0
void
runtime·concatstring(int32 n, String s1)
{
#line 3484 "C:\Go\src\pkg\runtime\string.goc"

	(&s1)[n] = concatstring(n, &s1);
}
Exemple #3
0
static char* build_json_item(char *key, char *value) {
    char *pack_key = packstring(key, "\"");
    char *pack_value = packstring(value, "\"");
    char *ret = concatstring(pack_key, ":", pack_value);
    if (pack_key) free(pack_key);
    if (pack_value) free(pack_value);
    return ret;
}
Exemple #4
0
char *makerelpath(const char *dir, const char *file, const char *prefix, const char *cmd)
{
    static string tmp;
    if(prefix) copystring(tmp, prefix);
    else tmp[0] = '\0';
    if(file[0]=='<')
    {
        const char *end = strrchr(file, '>');
        if(end)
        {
            size_t len = strlen(tmp);
            copystring(&tmp[len], file, min(sizeof(tmp)-len, size_t(end+2-file)));
            file = end+1;
        }
    }
    if(cmd) concatstring(tmp, cmd);
    defformatstring(pname)("%s/%s", dir, file);
    concatstring(tmp, pname);
    return tmp;
}
Exemple #5
0
void
runtime·concatstrings(Slice s, String res)
{
	res.str = 0;
	res.len = 0;
	FLUSH(&res);
#line 205 "/home/14/ren/source/golang/go/src/pkg/runtime/string.goc"

	res = concatstring(s.len, (String*)s.array);
	FLUSH(&res);
}
Exemple #6
0
void
runtime·concatstring2(String s1, String s2, String res)
{
	res.str = 0;
	res.len = 0;
	FLUSH(&res);
#line 179 "/home/14/ren/source/golang/go/src/pkg/runtime/string.goc"

	USED(&s2);
	res = concatstring(2, &s1);
	FLUSH(&res);
}
Exemple #7
0
void
runtime·concatstring4(String s1, String s2, String s3, String s4, String res)
{
	res.str = 0;
	res.len = 0;
	FLUSH(&res);
#line 190 "/home/14/ren/source/golang/go/src/pkg/runtime/string.goc"

	USED(&s2);
	USED(&s3);
	USED(&s4);
	res = concatstring(4, &s1);
	FLUSH(&res);
}
void 
runtime·concatstring ( intgo n , String s1 , ... ) 
{ 
( &s1 ) [n] = concatstring ( n , &s1 ) ; 
} 
Exemple #9
0
void audiomanager::initsound()
{
    if(!audio)
    {
        conoutf("audio is disabled");
        return;
    }

    nosound = true;
    device = NULL;
    context = NULL;

    // list available devices
    if(alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
    {
        const ALCchar *devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
        if(devices)
        {
            string d;
            copystring(d, "Audio devices: ");

            // null separated device string
            for(const ALchar *c = devices; *c; c += strlen(c)+1)
            {
                if(c!=devices) concatstring(d, ", ");
                concatstring(d, c);
            }
            conoutf("%s", d);
        }
    }

    // open device
    const char *devicename = getalias("openaldevice");
    device = alcOpenDevice(devicename && devicename[0] ? devicename : NULL);

    if(device)
    {
        context = alcCreateContext(device, NULL);
        if(context)
        {
            alcMakeContextCurrent(context);

            alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);

            // backend infos
            conoutf("Sound: %s / %s (%s)", alcGetString(device, ALC_DEVICE_SPECIFIER), alGetString(AL_RENDERER), alGetString(AL_VENDOR));
            conoutf("Driver: %s", alGetString(AL_VERSION));

            // allocate OpenAL resources
            sourcescheduler::instance().init(16);

            // let the stream get the first source from the scheduler
            gamemusic = new oggstream();
            if(!gamemusic->valid) DELETEP(gamemusic);
            setmusicvol(musicvol);

            nosound = false;
        }
    }

    if(nosound)
    {
        ALERR;
        if(context) alcDestroyContext(context);
        if(device) alcCloseDevice(device);
        conoutf("sound initialization failed!");
    }
}