Example #1
0
/*----------------------------------------------------------------------------*/
static void
gltextAddFont(Var vfont)
{
    VarValidator varvalid;
    GlFont font;
    PtrArrayIterator it;
    
    varvalid = VarValidator_new();
    
    /*default values*/
    VarValidator_declareStringVar(varvalid, "font_name", "");
    VarValidator_declareStringVar(varvalid, "font_picture", "");
    VarValidator_declareIntVar(varvalid, "char_width", 1);
    VarValidator_declareIntVar(varvalid, "char_height", 1);
    VarValidator_declareIntVar(varvalid, "hor_spacing", 4);
    
    /*validate*/
    VarValidator_validate(varvalid, vfont);
    VarValidator_del(varvalid);

    /*we create the font*/
    font = (GlFont)MALLOC(sizeof(pv_GlFont));
    font->name = String_newByCopy(Var_getValueString(Var_getArrayElemByCName(vfont, "font_name")));

    shellPrintf(LEVEL_ERRORSTACK, "For font '%s'", String_get(font->name));
    
    font->surf = GlSurface_newFromFile(Var_getValueString(Var_getArrayElemByCName(vfont, "font_picture")));
    font->w = Var_getValueInt(Var_getArrayElemByCName(vfont, "char_width"));
    font->h = Var_getValueInt(Var_getArrayElemByCName(vfont, "char_height"));
    font->wspacing = Var_getValueInt(Var_getArrayElemByCName(vfont, "hor_spacing"));
    font->wcrop = MALLOC(sizeof(Gl2DSize) * 256);
    
    font->lastcolor = GlColor_NULL;
    
    /*some checks*/
    if ((GlSurface_getWidth(font->surf) != font->w * 16)
        || GlSurface_getHeight(font->surf) != font->h * 16)
    {
        shellPrintf(LEVEL_ERROR, "Sizes don't match. Font not added.");
        GlFont_del(font);
    }
    else
    {
        /*we crop for non-monospace drawing*/
        performAutoCrop(font);
        
        /*if the font already exists, we delete the old one*/
        it = PtrArray_findSorted(_fonts, font);
        if (it != NULL)
        {
            shellPrintf(LEVEL_ERROR, "Font already exists, will be replaced by the new one.");
            PtrArray_removeIt(_fonts, it);
        }
    
        /*and add the new one to the font set*/
        PtrArray_insertSorted(_fonts, font);
        
        /*correct the renderers that need this font*/
        for (it = PtrArray_START(_textrenders); it != PtrArray_STOP(_textrenders); it++)
        {
            if ((((GlTextRender)(*it))->fontname != NULL)
             && (String_cmp(&((GlTextRender)(*it))->fontname, &font->name) == 0))
            {
                ((GlTextRender)(*it))->font = font;
            }
        }
    }
    
    shellPopErrorStack();
}
Example #2
0
/*----------------------------------------------------------------------------*/
static int
I18n_elem_cmp(I18n_elem* e1, I18n_elem* e2)
{
    return String_cmp(&((*e1)->orig), &((*e2)->orig));
}
Example #3
0
/*----------------------------------------------------------------------------*/
static int
GlFont_cmp(GlFont* font1, GlFont* font2)
{
    return String_cmp(&((*font1)->name), &((*font2)->name));
}
Example #4
0
static Bool isDaemonRunning (Char * pidName)
{
    DIR           * dir;
    pid_t           pid;
    Int             dirNum;
    FILE          * fp;
    struct dirent * next;
    Bool            isRunning                   = FALSE;
    Char            filename [READ_BUF_SIZE];
    Char            buffer [READ_BUF_SIZE];
    Char          * bptr                        = buffer;
    Char          * name;

    pid = getpid ();
    dir = opendir ("/proc");
    if (!dir) {
        Osal_printf ("Warning: Cannot open /proc filesystem\n");
        return isRunning;
    }

    name = strrchr (pidName, '/');
    if (name) {
        pidName = (name + 1);
    }

    while ((next = readdir (dir)) != NULL) {
        /* If it isn't a number, we don't want it */
        if (!isdigit (*next->d_name)) {
            continue;
        }

        dirNum = strtol (next->d_name, NULL, 10);
        if (dirNum == pid) {
            continue;
        }

        snprintf (filename, READ_BUF_SIZE, "/proc/%s/cmdline", next->d_name);
        if (!(fp = fopen (filename, "r"))) {
            continue;
        }
        if (fgets (buffer, READ_BUF_SIZE, fp) == NULL) {
            fclose (fp);
            continue;
        }
        fclose (fp);

        name = strrchr (buffer, '/');
        if (name && (name + 1)) {
            bptr = (name + 1);
        }
        else {
            bptr = buffer;
        }

        /* Buffer should contain the enitre command line */
        if (String_cmp (bptr, pidName) == 0) {
            isRunning = TRUE;
            break;
        }
    }
    closedir (dir);

    return isRunning;
}