Esempio n. 1
0
static void __fault(int errcode, const char * msg, const char *file, int line) {
    if (errcode) 
        pf_log("err(%d): %s, error occured in file %s, line %d\n\n\t have a look at fterrdef.h\n",errcode, msg, file, line);
    else
        pf_log("err: %s, occured in file %s, line %d\n", msg, file, line);
    exit(1);
}
Esempio n. 2
0
static JNIEnv *
_getenv() {
    JNIEnv *env = pthread_getspecific(KEY);
    if (env) return env;

    jint ret = (*VM)->GetEnv(VM, (void**)&env, JNI_VERSION_1_4);
    switch (ret) {
    case JNI_OK:
        pthread_setspecific(KEY, env);
        return env;
    case JNI_EDETACHED:
        if ((*VM)->AttachCurrentThread(VM,&env, NULL) < 0) {
            pf_log("JavaVM attach thread fail");
            return NULL;
        }
        pthread_setspecific(KEY, env);
        return env;
    case JNI_EVERSION:
        pf_log("JNI version 1.4 not supported");
        return NULL;
    default:
        pf_log("JavaVM GetEnv fail");
        return NULL;
    }
}
Esempio n. 3
0
void
font_init(const char* fontname) {
    if (FT_Init_FreeType(&library)) {
        pf_log("font init failed");
    }
    strncpy(TTFONT,fontname,MAXFILENAME);
    TTFONT[strlen(fontname)+1] = '0';
    pf_log("TTFONT=%s",TTFONT);
}
Esempio n. 4
0
int
asset_extract(const char *assetdir, const char *topath, const char *ext) {
    char fromdir[PATH_MAX];
    if (assetdir[0] == '\0') {
        strcpy(fromdir, "files");
    } else {
        snprintf(fromdir, sizeof(fromdir), "files/%s", assetdir);
    }
    AAssetDir *dir = AAssetManager_openDir(__A, fromdir);
    if (dir == NULL) {
        pf_log("[!no asset dir] %s", fromdir);
        return 1;
    }
    char buf[2048];
    char todir[PATH_MAX];
    if (assetdir[0] == '\0') {
        strcpy(todir, topath);
    } else {
        snprintf(todir, sizeof(todir), "%s/%s", topath, assetdir);
    }
    mkdir(todir, 0770);

    size_t extlen = strlen(ext);

    char fromfile[PATH_MAX];
    char tofile[PATH_MAX];
    const char *fname;
    while (fname = AAssetDir_getNextFileName(dir)) {
        if (endswith(fname, ext, extlen)) {
            snprintf(fromfile, sizeof(fromfile), "%s/%s", fromdir, fname);
            snprintf(tofile, sizeof(tofile), "%s/%s", todir, fname);
            pf_log("%s -> %s", fromfile, tofile);
            AAsset *asset = AAssetManager_open(__A, fromfile, 2);
            if (asset) {
                FILE *fp = fopen(tofile, "w+");
                if (fp == NULL) {
                    pf_log("asset extract fail: %s", tofile);
                }
                int rd;
                while ((rd = AAsset_read(asset, buf, sizeof(buf))) > 0) {
                    fwrite(buf, rd, 1, fp);
                }
                fclose(fp);
                AAsset_close(asset);
            } else {
                pf_log("[!no asset] %s", fromfile);
            }
        }
    }
    AAssetDir_close(dir);
    return 0;
}
Esempio n. 5
0
/**
 * Logs the entire parse frame stack
 */
void pf_log_all(log_sev_t logsev)
{
   int idx;

   LOG_FMT(logsev, "##=- Parse Frame : %d entries\n", cpd.frame_count);

   for (idx = 0; idx < cpd.frame_count; idx++)
   {
      LOG_FMT(logsev, "##  <%d> ", idx);

      pf_log(logsev, &cpd.frames[idx]);
   }
   LOG_FMT(logsev, "##=-\n");
}
Esempio n. 6
0
void 
font_size(const char *str, int unicode, struct font_context *ctx) {
    FT_Face face = ctx->font;
    FT_UInt glyph_index = FT_Get_Char_Index(face, unicode);
	if (!glyph_index) {
		pf_log("cannot find glyph %d\n", unicode);
		//exit(1);
	}
    FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_BITMAP);
    
    int err = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
	if (err)
        _fault(err, "render failed");

    FT_GlyphSlot slot = face->glyph;

    ctx->w = slot->advance.x >> 6;
}
Esempio n. 7
0
void
font_init() {
    if (FT_Init_FreeType(&library)) {
        pf_log("font init failed");
    } 
}
Esempio n. 8
0
/**
 * Returns the pp_indent to use for this line
 */
int pf_check(struct parse_frame *frm, chunk_t *pc)
{
   int        in_ifdef = frm->in_ifdef;
   int        b4_cnt   = cpd.frame_count;
   int        pp_level = cpd.pp_level;
   const char *txt     = NULL;
   chunk_t    *next;

   if (pc->type != CT_PREPROC)
   {
      return(pp_level);
   }
   next = chunk_get_next(pc);

   if (pc->parent_type != next->type)
   {
      LOG_FMT(LNOTE, "%s: Preproc parent not set correctly on line %d: got %s expected %s\n",
              __func__, pc->orig_line, get_token_name(pc->parent_type),
              get_token_name(next->type));
      pc->parent_type = next->type;
   }

   LOG_FMT(LPFCHK, "%s: %5d] %s\n",
           __func__, pc->orig_line, get_token_name(pc->parent_type));
   pf_log_frms(LPFCHK, "TOP", frm);

   if ((pc->flags & PCF_IN_PREPROC) != 0)
   {
      LOG_FMT(LPF, " <In> ");
      pf_log(LPF, frm);

      if (pc->parent_type == CT_PP_IF)
      {
         /* An #if pushes a copy of the current frame on the stack */
         cpd.pp_level++;
         pf_push(frm);
         frm->in_ifdef = CT_PP_IF;
         txt           = "if-push";
      }
      else if (pc->parent_type == CT_PP_ELSE)
      {
         pp_level--;

         /**
          * For #else of #elif, we want to keep the #if part and throw out the
          * else parts.
          * We check to see what the top type is to see if we just push or
          * pop and then push.
          * We need to use the copy right before the if.
          */
         if (frm->in_ifdef == CT_PP_IF)
         {
            /* we have [...] [base]-[if], so push an [else] */
            pf_push(frm);
            frm->in_ifdef = CT_PP_ELSE;
         }
         /* we have [...] [base] [if]-[else], copy [base] over [else] */
         pf_copy_2nd_tos(frm);
         frm->in_ifdef = CT_PP_ELSE;
         txt           = "else-push";
      }
      else if (pc->parent_type == CT_PP_ENDIF)
      {
         /**
          * we may have [...] [base] [if]-[else] or [...] [base]-[if].
          * Throw out the [else].
          */
         cpd.pp_level--;
         pp_level--;

         if (frm->in_ifdef == CT_PP_ELSE)
         {
            /**
             * We have: [...] [base] [if]-[else]
             * We want: [...]-[if]
             */
            pf_copy_tos(frm);     /* [...] [base] [if]-[if] */
            frm->in_ifdef = cpd.frames[cpd.frame_count - 2].in_ifdef;
            pf_trash_tos();       /* [...] [base]-[if] */
            pf_trash_tos();       /* [...]-[if] */

            txt = "endif-trash/pop";
         }
         else if (frm->in_ifdef == CT_PP_IF)
         {
            /**
             * We have: [...] [base] [if]
             * We want: [...] [base]
             */
            pf_pop(frm);
            txt = "endif-pop";
         }
         else
         {
            txt = "???";
         }
      }
   }

   if (txt != NULL)
   {
      LOG_FMT(LPF, "%s: %d> %s: %s in_ifdef=%d/%d counts=%d/%d\n", __func__,
              pc->orig_line, get_token_name(pc->parent_type), txt,
              in_ifdef, frm->in_ifdef, b4_cnt, cpd.frame_count);
      pf_log_all(LPF);
      LOG_FMT(LPF, " <Out>");
      pf_log(LPF, frm);
   }

   pf_log_frms(LPFCHK, "END", frm);

   return(pp_level);
}