OSDN Git Service

Merge branch 'branch_0.13.0'
[modchxj/mod_chxj.git] / src / chxj_qr_code.c
index 34e54a6..29a2d33 100644 (file)
@@ -1,6 +1,6 @@
 /*
+ * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
- * Copyright (C) 2005 Atsushi Konno All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 */
 #define EXIT_MAGICK_ERROR() \
           do { \
-             char *description; ExceptionType severity; \
+             char *description; \
+             ExceptionType severity; \
              description=MagickGetException(magick_wand,&severity); \
              ap_log_rerror(APLOG_MARK,APLOG_DEBUG, 0, r,"%s %s %d %s\n",__FILE__,(__func__),__LINE__,description); \
              description=(char *) MagickRelinquishMemory(description); \
              DestroyMagickWand(magick_wand); \
-          }while(1)
+          }while(0)
 
 /*----------------------------------------------------------------------------*/
 /* ¥â¡¼¥É»Ø¼¨»Ò¥Æ¡¼¥Ö¥ë                                                       */
@@ -552,47 +553,46 @@ static qr_capacity_t v_capacity_table[] = {
 };
 
 
-static char*  s_get_mode_spec       (qr_code_t* qrcode);
-static char*  s_get_char_bit_count  (qr_code_t* qrcode, int len);
-static char*  s_data_to_bin_num     (qr_code_t* qrcode, int data_code_count);
-static char*  s_data_to_bin_alpha   (qr_code_t* qrcode, int data_code_count);
-static int    s_char_to_num_alpha   (qr_code_t* qrcode, char src);
-static char*  s_data_to_bin_8bit    (qr_code_t* qrcode, int data_code_count);
-static char*  s_data_to_bin_kanji   (qr_code_t* qrcode, int data_code_count);
-static char*  s_tidy_8bit_code      (qr_code_t* qrcode, const char* indata, int data_code_count);
-static char*  s_str_to_bin          (qr_code_t* qrcode, char* indata, int data_code_count);
-static void   s_init_modules        (qr_code_t* qrcode, qr_mask_pattern_t pat, char* module[]);
-static void   s_setup_probe_position(qr_code_t* qrcode, char* dst[], int pos_x, int pos_y);
-static void   s_setup_timing_pattern(qr_code_t* qrcode, char* dst[]);
-static void   s_setup_position_adjust(qr_code_t* qrcode, char* dst[]);
-static void   s_setup_type_info     (qr_code_t* qrcode, char* dst[], qr_mask_pattern_t pat);
-static void   s_setup_version_info  (qr_code_t* qrcode, char* dst[]);
-static void   s_map_data            (qr_code_t* qrcode, char* dst[], unsigned char* indata,
+static char   *s_get_mode_spec       (qr_code_t *qrcode);
+static char   *s_get_char_bit_count  (qr_code_t *qrcode, int len);
+static char   *s_data_to_bin_num     (qr_code_t *qrcode, int data_code_count);
+static char   *s_data_to_bin_alpha   (qr_code_t *qrcode, int data_code_count);
+static int    s_char_to_num_alpha    (qr_code_t *qrcode, char src);
+static char   *s_data_to_bin_8bit    (qr_code_t *qrcode, int data_code_count);
+static char   *s_data_to_bin_kanji   (qr_code_t *qrcode, int data_code_count);
+static char   *s_tidy_8bit_code      (qr_code_t *qrcode, const char *indata, int data_code_count);
+static char   *s_str_to_bin          (qr_code_t *qrcode, char *indata, int data_code_count);
+static void   s_init_modules         (qr_code_t *qrcode, qr_mask_pattern_t pat, char *module[]);
+static void   s_setup_probe_position (qr_code_t *qrcode, char *dst[], int pos_x, int pos_y);
+static void   s_setup_timing_pattern (qr_code_t *qrcode, char *dst[]);
+static void   s_setup_position_adjust(qr_code_t *qrcode, char *dst[]);
+static void   s_setup_type_info      (qr_code_t *qrcode, char *dst[], qr_mask_pattern_t pat);
+static void   s_setup_version_info   (qr_code_t *qrcode, char *dst[]);
+static void   s_map_data             (qr_code_t *qrcode, char *dst[], unsigned char *indata,
                 int data_count, qr_mask_pattern_t pat);
 static int    s_get_mask            (qr_mask_pattern_t pat, int yy, int xx);
 static int    s_get_bit_count       (int data);
-static int    s_calc_lost_point     (qr_code_t* qrcode, char* dst[]);
+static int    s_calc_lost_point     (qr_code_t *qrcode, char *dst[]);
 static int    s_count_same_module   (qr_ver_t ver, char* dst[]);
 static int    s_count_same_block    (qr_ver_t ver, char* dst[]);
 static int    s_count_11311_pattern (qr_ver_t ver, char* dst[]);
 static int    s_count_dark_ratio    (qr_ver_t ver, char* dst[]);
 
-static void   chxj_qr_code          (qr_code_t* qrcode, char* module[]);
+static void   chxj_qr_code          (qr_code_t *qrcode, char *module[]);
 
 int
-chxj_qr_code_handler(request_recr)
+chxj_qr_code_handler(request_rec *r)
 {
   int                sts;
   size_t             len;
   qr_code_t          qrcode;
   Doc                doc;
-  char*              img;
-  Node*              root;
-  mod_chxj_config*   conf;
+  char               *img;
+  Node               *root;
+  mod_chxj_config    *conf;
 
-#ifdef QR_CODE_DEBUG
   DBG(r,"start chxj_qr_code_handler()");
-#endif
+
   if (strcasecmp(r->handler, "chxj-qrcode")) {
     DBG(r, "end chxj_qr_code_handler()");
     return DECLINED;
@@ -601,7 +601,7 @@ chxj_qr_code_handler(request_rec* r)
   /*--------------------------------------------------------------------------*/
   /* ¤â¤·¡¢¥¤¥á¡¼¥¸ÊÑ´¹¥Ï¥ó¥É¥éÃæ¤Ç¤¢¤ì¤Ð¡¢¤³¤³¤Ç¤Ï½èÍý¤·¤Ê¤¤                 */
   /*--------------------------------------------------------------------------*/
-  conf = ap_get_module_config(r->per_dir_config, &chxj_module);
+  conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
   if (!conf || conf->image == CHXJ_IMG_ON)
     return DECLINED;
 
@@ -627,22 +627,22 @@ chxj_qr_code_handler(request_rec* r)
   if (sts != OK)
     return sts;
 
-  ap_set_content_type(r, "image/jpg");
+  chxj_set_content_type(r, "image/jpg");
 
-  ap_rwrite((void*)img, len, r);
+  ap_rwrite((void *)img, len, r);
 
   return OK;
 }
 
 
-char
-chxj_qr_code_blob_handler(request_rec* r, const char* indata, size_t* len)
+char *
+chxj_qr_code_blob_handler(request_rec *r, const char *indata, size_t *len)
 {
   int                sts;
   qr_code_t          qrcode;
   Doc                doc;
-  char*              img;
-  Node*              root;
+  char               *img;
+  Node               *root;
 
   DBG(r, "start chxj_qr_code_blob_handler()");
 
@@ -669,7 +669,7 @@ chxj_qr_code_blob_handler(request_rec* r, const char* indata, size_t* len)
     return NULL;
   }
 
-  ap_set_content_type(r, "image/jpg");
+  chxj_set_content_type(r, "image/jpg");
 
   DBG(r, "end chxj_qr_code_blob_handler()");
 
@@ -679,25 +679,25 @@ chxj_qr_code_blob_handler(request_rec* r, const char* indata, size_t* len)
 
 int
 chxj_qrcode_create_image_data(
-  qr_code_tqrcode,
-  char**     img,
-  size_t*    img_len)
+  qr_code_t   *qrcode,
+  char        **img,
+  apr_size_t  *img_len)
 {
   int                xx, yy;
   int                module_count;
   MagickBooleanType  status;
-  request_rec*       r = qrcode->r;
-  MagickWand*        magick_wand;
-  MagickWand*        black_wand;
-  unsigned char*     tmp;
-  char**             module;
+  request_rec        *r = qrcode->r;
+  MagickWand         *magick_wand;
+  MagickWand         *black_wand;
+  unsigned char      *tmp;
+  char               **module;
 
 #ifdef QR_CODE_DEBUG
   DBG(r,"start s_create_image_file()");
 #endif
 
   module_count  = v_module_count_table[qrcode->version];
-  module = (char**)apr_palloc(r->pool, sizeof(char*)*(module_count+1));
+  module = (char **)apr_palloc(r->pool, sizeof(char*)*(module_count+1));
   for (yy=0; yy<module_count; yy++) {
     module[yy] = (char*)apr_palloc(r->pool, module_count+1);
     memset(module[yy], -1, module_count+1);
@@ -705,7 +705,6 @@ chxj_qrcode_create_image_data(
 
   chxj_qr_code(qrcode,  module);
 
-
   magick_wand = NewMagickWand();
   black_wand = NewMagickWand();
 
@@ -796,15 +795,15 @@ on_error:
 
 
 static void
-chxj_qr_code(qr_code_t* qrcode, char* module[])
+chxj_qr_code(qr_code_t *qrcode, char *module[])
 {
-  request_rec*      r     = qrcode->doc->r;
-  unsigned char*    eccstr;
+  request_rec       *r     = qrcode->doc->r;
+  unsigned char     *eccstr;
   int               ii;
   int               data_code_count;
-  char*             real_data  = NULL;
-  char*             decstr;
-  char*             binstr;
+  char              *real_data  = NULL;
+  char              *decstr;
+  char              *binstr;
   int               data_total_count;
   int               min_lost_point;
   int               min_mask_pattern;
@@ -828,7 +827,7 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
     binstr = apr_pstrcat(r->pool, binstr, 
                   s_get_char_bit_count(qrcode, strlen(qrcode->indata)), NULL);
 #ifdef QR_CODE_DEBUG
-    DBG1(r, "s_get_char_bit_count()[%s]", binstr);
+    DBG(r, "s_get_char_bit_count()[%s]", binstr);
 #endif
 
     /*------------------------------------------------------------------------*/
@@ -836,7 +835,7 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
     /*------------------------------------------------------------------------*/
     data_code_count = v_data_code_count[qrcode->version][qrcode->level];
 #ifdef QR_CODE_DEBUG
-    DBG1(r,"data_code_count=[%d]", data_code_count);
+    DBG(r,"data_code_count=[%d]", data_code_count);
 #endif
 
     /*------------------------------------------------------------------------*/
@@ -873,16 +872,16 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
   /*--------------------------------------------------------------------------*/
   binstr = apr_pstrcat(r->pool, binstr, real_data, NULL);
 #ifdef QR_CODE_DEBUG
-  DBG1(r,"Before TERM BIT[%s]", binstr);
+  DBG(r,"Before TERM BIT[%s]", binstr);
 #endif
-  if (data_code_count * 8 > strlen(binstr)) {
+  if ((size_t)(data_code_count * 8) > strlen(binstr)) {
     int binstr_len = strlen(binstr);
     for (ii=0; ii< (data_code_count * 8) - binstr_len && ii < 4; ii++) {
       binstr = apr_pstrcat(r->pool, binstr, "0", NULL);
     }
   }
 #ifdef QR_CODE_DEBUG
-  DBG3(r, "After TERM BIT[%s] len[%d]bit [%f]byte", binstr, strlen(binstr), (float)(((float)strlen(binstr))/8.0));
+  DBG(r, "After TERM BIT[%s] len[%d]bit [%f]byte", binstr, strlen(binstr), (float)(((float)strlen(binstr))/8.0));
   DBG(r,"add term data");
 #endif
 
@@ -891,7 +890,7 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
   /*--------------------------------------------------------------------------*/
   binstr = s_tidy_8bit_code(qrcode, binstr, data_code_count);
 #ifdef QR_CODE_DEBUG
-  DBG1(r,"After Tidy 8 BIT[%s]", binstr);
+  DBG(r,"After Tidy 8 BIT[%s]", binstr);
   DBG(r,"s_tidy_8bit_code()");
 #endif
 
@@ -912,7 +911,7 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
     for (ii=0; ii<data_code_count; ii++) {
       rows = apr_pstrcat(r->pool, rows, apr_psprintf(r->pool, "[%02x]\n", (unsigned char)decstr[ii]), NULL);
     }
-    DBG1(r,"decstr[%s]", rows);
+    DBG(r,"decstr[%s]", rows);
   }while(0);
 #endif
 
@@ -924,7 +923,7 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
   eccstr = apr_palloc(r->pool, module_count* module_count);
   data_total_count = chxj_calc_ecc(qrcode, (unsigned char*)decstr, eccstr);
 #ifdef QR_CODE_DEBUG
-  DBG1(r,"chxj_calc_ecc() total_count[%d]", data_total_count);
+  DBG(r,"chxj_calc_ecc() total_count[%d]", data_total_count);
 #endif
 
   /*--------------------------------------------------------------------------*/
@@ -955,7 +954,7 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
   /* ºÇŬ¥Þ¥¹¥¯¤ÇºÆÅÙºî¤ê¤Ê¤ª¤·                                               */
   /*--------------------------------------------------------------------------*/
 #ifdef QR_CODE_DEBUG
-  DBG1(r, "selected mask[%d]", min_mask_pattern);
+  DBG(r, "selected mask[%d]", min_mask_pattern);
 #endif
 
   s_init_modules(qrcode, min_mask_pattern, module);
@@ -973,7 +972,7 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
   do {
     int xx, yy;
     int module_count = v_module_count_table[qrcode->version];
-    DBG1(r,"loop to [%d]", module_count);
+    DBG(r,"loop to [%d]", module_count);
     for (yy=0; yy<module_count; yy++) {
       char *rows ;
 
@@ -982,7 +981,7 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
       for (xx=0; xx<module_count; xx++)
         rows = apr_pstrcat(r->pool, rows, "[", apr_psprintf(r->pool, "%c", module[yy][xx]), "]", NULL);
 
-      DBG2(r,"%d:%s", yy,rows);
+      DBG(r,"%d:%s", yy,rows);
     }
   } while(0);
   /* DEBUG END */
@@ -994,19 +993,22 @@ chxj_qr_code(qr_code_t* qrcode, char* module[])
 }
 
 void
-chxj_qrcode_node_to_qrcode(qr_code_t* qrcode, Node* node)
+chxj_qrcode_node_to_qrcode(qr_code_t *qrcode, Node *node)
 {
-  request_rec* r = qrcode->r;
-  Doc* doc = qrcode->doc;
-  Node* child;
+  request_rec  *r;
+  Doc          *doc;
+  Node         *child;
+
+  r   = qrcode->r;
+  doc = qrcode->doc;
 
   for (child = qs_get_child_node(doc,node);
        child ;
-       child = qs_get_next_node(doc,child))
-  {
-    char* name = qs_get_node_name(doc,child);
-    if (strcasecmp("qrcode",name) == 0)
-    {
+       child = qs_get_next_node(doc,child)) {
+    char *name = qs_get_node_name(doc,child);
+
+    if (strcasecmp("qrcode",name) == 0) {
+
       qrcode->found       = QR_FOUND;
       qrcode->mode_change = QR_NOT_CHANGE;
       qrcode->version     = QR_VER_5;
@@ -1017,38 +1019,35 @@ chxj_qrcode_node_to_qrcode(qr_code_t* qrcode, Node* node)
       chxj_qrcode_node_to_qrcode(qrcode, child);
     }
     else
-    if (strcasecmp("version", name) == 0)
-    {
-      int ver;
-      Node* cchild = qs_get_child_node(doc, child);
-      char* value;
-      if (cchild == NULL)
-      {
+    if (strcasecmp("version", name) == 0) {
+      int   ver;
+      Node  *cchild;
+      char  *value;
+
+      cchild = qs_get_child_node(doc, child);
+
+      if (cchild == NULL) {
         qrcode->version = QR_VER_1;
         continue;
       }
 
       name = qs_get_node_name(doc, cchild);
       value = qs_get_node_value(doc, cchild);
-      if (strcasecmp("TEXT", name) != 0)
-      {
+      if (strcasecmp("TEXT", name) != 0) {
         qrcode->version = QR_VER_1;
         continue;
       }
-      if (value == NULL || strlen(value) == 0)
-      {
+      if (value == NULL || strlen(value) == 0) {
         qrcode->version = QR_VER_1;
         continue;
       }
 
-      if (chxj_chk_numeric(value))
-      {
+      if (chxj_chk_numeric(value)) {
         qrcode->version = QR_VER_1;
         continue;
       }
       ver = chxj_atoi(value);
-      if (ver <= 0 || ver > 40)
-      {
+      if (ver <= 0 || ver > 40) {
         qrcode->version = QR_VER_1;
         continue;
       }
@@ -1056,46 +1055,38 @@ chxj_qrcode_node_to_qrcode(qr_code_t* qrcode, Node* node)
       qrcode->version = ver - 1;
     }
     else
-    if (strcasecmp("level", name) == 0)
-    {
-      Node* cchild = qs_get_child_node(doc, child);
-      char* value;
-      if (cchild == NULL)
-      {
+    if (strcasecmp("level", name) == 0) {
+      Node *cchild = qs_get_child_node(doc, child);
+      char *value;
+      if (cchild == NULL) {
         qrcode->level = QR_LEVEL_L;
         continue;
       }
-      name = qs_get_node_name(doc, cchild);
+      name  = qs_get_node_name(doc, cchild);
       value = qs_get_node_value(doc, cchild);
-      if (strcasecmp("TEXT", name) != 0)
-      {
+      if (strcasecmp("TEXT", name) != 0) {
         qrcode->level = QR_LEVEL_L;
         continue;
       }
 
-      if (value == NULL || strlen(value) == 0)
-      {
+      if (value == NULL || strlen(value) == 0) {
         qrcode->level = QR_LEVEL_L;
         continue;
       }
 
-      if (strcasecmp("L", value) == 0)
-      {
+      if (strcasecmp("L", value) == 0) {
         qrcode->level = QR_LEVEL_L;
       }
       else
-      if (strcasecmp("M", value) == 0)
-      {
+      if (strcasecmp("M", value) == 0) {
         qrcode->level = QR_LEVEL_M;
       }
       else
-      if (strcasecmp("Q", value) == 0)
-      {
+      if (strcasecmp("Q", value) == 0) {
         qrcode->level = QR_LEVEL_Q;
       }
       else
-      if (strcasecmp("H", value) == 0)
-      {
+      if (strcasecmp("H", value) == 0) {
         qrcode->level = QR_LEVEL_H;
       }
       else
@@ -1106,8 +1097,8 @@ chxj_qrcode_node_to_qrcode(qr_code_t* qrcode, Node* node)
     else
     if (strcasecmp("mode", name) == 0)
     {
-      Nodecchild = qs_get_child_node(doc, child);
-      charvalue;
+      Node *cchild = qs_get_child_node(doc, child);
+      char *value;
       if (cchild == NULL)
       {
         qrcode->mode = QR_NUM_MODE;
@@ -1166,8 +1157,8 @@ chxj_qrcode_node_to_qrcode(qr_code_t* qrcode, Node* node)
     if (strcasecmp("data", name) == 0)
     {
       /* TODO: ²þ¹Ô¤â²Äǽ¤Ê¤è¤¦¤Ë½¤Àµ¤¹¤ë */
-      Nodecchild = qs_get_child_node(doc, child);
-      charvalue;
+      Node *cchild = qs_get_child_node(doc, child);
+      char *value;
 
       qrcode->indata = apr_palloc(r->pool, 1);
       qrcode->indata[0] = 0;
@@ -1194,8 +1185,8 @@ chxj_qrcode_node_to_qrcode(qr_code_t* qrcode, Node* node)
     if (strcasecmp("size", name) == 0)
     {
       int size;
-      charvalue;
-      Nodecchild = qs_get_child_node(doc, child);
+      char *value;
+      Node *cchild = qs_get_child_node(doc, child);
 
       if (cchild == NULL)
       {
@@ -1235,10 +1226,10 @@ chxj_qrcode_node_to_qrcode(qr_code_t* qrcode, Node* node)
     }
   }
 #ifdef QR_CODE_DEBUG
-  DBG1(r,"qrcode->version[%d]", qrcode->version);
-  DBG1(r,"qrcode->level[%d]", qrcode->level);
-  DBG1(r,"qrcode->mode[%d]", qrcode->mode);
-  DBG1(r,"qrcode->indata[%s]", qrcode->indata);
+  DBG(r,"qrcode->version[%d]", qrcode->version);
+  DBG(r,"qrcode->level[%d]", qrcode->level);
+  DBG(r,"qrcode->mode[%d]", qrcode->mode);
+  DBG(r,"qrcode->indata[%s]", qrcode->indata);
 #endif
 }
 
@@ -1246,15 +1237,15 @@ chxj_qrcode_node_to_qrcode(qr_code_t* qrcode, Node* node)
 /**
  * ¥â¡¼¥É»Ø¼¨»Ò¤ò¼èÆÀ¤·¤Þ¤¹.
  */
-static char*
+static char *
 s_get_mode_spec(qr_code_t *qrcode)
 {
-  charresult = (char*)apr_palloc(qrcode->r->pool, 4+1);
+  char *result = (char*)apr_palloc(qrcode->r->pool, 4+1);
 
   memset(result, 0, 5);
   memcpy(result, v_mode_table[qrcode->mode], 4);
 #ifdef QR_CODE_DEBUG
-  DBG1(r,"Mode Spec[%s]", result);
+  DBG(r,"Mode Spec[%s]", result);
 #endif
 
   return result;
@@ -1264,16 +1255,16 @@ s_get_mode_spec(qr_code_t *qrcode)
 /**
  * Ê¸»ú¿ô»Ø¼¨»Ò¤ò¼èÆÀ¤·¤Þ¤¹.
  */
-static char*
-s_get_char_bit_count(qr_code_tqrcode, int len)
+static char *
+s_get_char_bit_count(qr_code_t *qrcode, int len)
 {
   int bit_count = v_char_count_table[qrcode->version][qrcode->mode];
   int ii,jj;
-  chartmp;
-  charresult;
+  char *tmp;
+  char *result;
   int data_capacity   = v_capacity_table[qrcode->version*4+qrcode->level].size[qrcode->mode];
 
-  DBG1(qrcode->r, "len [%d]", len);
+  DBG(qrcode->r, "len [%d]", len);
   if (qrcode->mode == QR_KANJI_MODE && data_capacity * 2 < len) {
     len = data_capacity * 2;
   }
@@ -1286,9 +1277,9 @@ s_get_char_bit_count(qr_code_t* qrcode, int len)
     len /= 2;
   }
 
-  DBG1(qrcode->r, "len [%d]", len);
+  DBG(qrcode->r, "len [%d]", len);
 
-  tmp = (char*)apr_palloc(qrcode->r->pool, bit_count + 1);
+  tmp = (char *)apr_palloc(qrcode->r->pool, bit_count + 1);
   for (ii=0; ii<bit_count; ii++) {
     tmp[ii] = (len & 0x01) ? '1' : '0';
     len = len >> 1;
@@ -1296,7 +1287,7 @@ s_get_char_bit_count(qr_code_t* qrcode, int len)
 
   tmp[bit_count] = '\0';
 
-  result = (char*)apr_palloc(qrcode->r->pool, bit_count+1);
+  result = (char *)apr_palloc(qrcode->r->pool, bit_count+1);
   for (jj=0,ii=bit_count-1; ii>=0 && jj < bit_count; ii--, jj++) {
     result[ii] = tmp[jj];
   }
@@ -1304,7 +1295,7 @@ s_get_char_bit_count(qr_code_t* qrcode, int len)
   result[bit_count] = '\0';
 
 #ifdef QR_CODE_DEBUG
-  DBG1(qrcode->r, "Character Count bit [%s]", result);
+  DBG(qrcode->r, "Character Count bit [%s]", result);
 #endif
 
   return result;
@@ -1314,8 +1305,8 @@ s_get_char_bit_count(qr_code_t* qrcode, int len)
  * ¿ô»ú¥â¡¼¥É
  * ÆþÎϥǡ¼¥¿¤«¤é¡¢£²¿Êʸ»úÎó¤ò¼èÆÀ¤·¤Þ¤¹.
  */
-static char*
-s_data_to_bin_num(qr_code_t* qrcode, int data_code_count)
+static char *
+s_data_to_bin_num(qr_code_t *qrcode, int UNUSED(data_code_count))
 {
   int len = strlen(qrcode->indata);
   int setn;
@@ -1323,7 +1314,7 @@ s_data_to_bin_num(qr_code_t* qrcode, int data_code_count)
   int ii;
   int jj;
   int kk;
-  charresult;
+  char  *result;
   char  tmp[4];
   char  tmp_bit[11];
   int data_capacity   = v_capacity_table[qrcode->version*4+qrcode->level].size[qrcode->mode];
@@ -1384,8 +1375,8 @@ s_data_to_bin_num(qr_code_t* qrcode, int data_code_count)
  * ±Ñ¿ô»ú¥â¡¼¥É
  * ÆþÎϥǡ¼¥¿¤«¤é¡¢£²¿Êʸ»úÎó¤ò¼èÆÀ¤·¤Þ¤¹.
  */
-static char*
-s_data_to_bin_alpha(qr_code_t* qrcode, int data_code_count)
+static char *
+s_data_to_bin_alpha(qr_code_t *qrcode, int UNUSED(data_code_count))
 {
   int len = strlen(qrcode->indata);
   int setn;
@@ -1393,7 +1384,7 @@ s_data_to_bin_alpha(qr_code_t* qrcode, int data_code_count)
   int ii;
   int jj;
   int kk;
-  charresult;
+  char  *result;
   char  tmp[2+1];
   char  tmp_bit[11+1];
   int data_capacity   = v_capacity_table[qrcode->version*4+qrcode->level].size[qrcode->mode];
@@ -1405,7 +1396,7 @@ s_data_to_bin_alpha(qr_code_t* qrcode, int data_code_count)
   setn = len / 2;
   modn = len % 2;
 
-  result = (char*)apr_palloc(qrcode->r->pool, setn*11 + ((modn == 1) ? 6 : 0) + 1); 
+  result = (char *)apr_palloc(qrcode->r->pool, setn*11 + ((modn == 1) ? 6 : 0) + 1); 
 
   kk = 0;
   for (ii=0; ii<len; ii++) {
@@ -1461,7 +1452,7 @@ s_data_to_bin_alpha(qr_code_t* qrcode, int data_code_count)
  * ±Ñ¿ô»ú¤«¤é¡¢¿ôÃͤËÊÑ´¹¤·¤Þ¤¹.
  */
 static int
-s_char_to_num_alpha(qr_code_tqrcode, char src)
+s_char_to_num_alpha(qr_code_t *qrcode, char src)
 {
   switch(src) {
   case '0': return 0;
@@ -1529,14 +1520,14 @@ s_char_to_num_alpha(qr_code_t* qrcode, char src)
  * 8bit¥Ð¥¤¥È¥â¡¼¥É
  * ÆþÎϥǡ¼¥¿¤«¤é£²¿Êʸ»úÎó¤ò¼èÆÀ¤·¤Þ¤¹.
  */
-static char*
-s_data_to_bin_8bit(qr_code_t* qrcode, int data_code_count)
+static char *
+s_data_to_bin_8bit(qr_code_t *qrcode, int UNUSED(data_code_count))
 {
   int len = strlen(qrcode->indata);
   int ii;
   int jj;
   int kk;
-  charresult;
+  char  *result;
   char  tmp_bit[8+1];
   int data_capacity   = v_capacity_table[qrcode->version*4+qrcode->level].size[qrcode->mode];
 
@@ -1565,7 +1556,7 @@ s_data_to_bin_8bit(qr_code_t* qrcode, int data_code_count)
   result[kk] = 0;
 
 #ifdef QR_CODE_DEBUG
-  DBG2(qrcode->r, "input data --> 2bin result[%s] len:[%d]", result, strlen(result));
+  DBG(qrcode->r, "input data --> 2bin result[%s] len:[%d]", result, strlen(result));
 #endif
 
   return result;
@@ -1575,14 +1566,14 @@ s_data_to_bin_8bit(qr_code_t* qrcode, int data_code_count)
  * Kanji mode.
  * A binary character string is acquired from input data.
  */
-static char*
-s_data_to_bin_kanji(qr_code_t* qrcode, int data_code_count)
+static char *
+s_data_to_bin_kanji(qr_code_t *qrcode, int UNUSED(data_code_count))
 {
   int len = strlen(qrcode->indata);
   int ii;
   int jj;
   int kk;
-  charresult;
+  char  *result;
   char  tmp_bit[13+1];
 
   int data_capacity   = v_capacity_table[qrcode->version*4+qrcode->level].size[qrcode->mode];
@@ -1643,7 +1634,7 @@ s_data_to_bin_kanji(qr_code_t* qrcode, int data_code_count)
   result[kk] = 0;
 
 #ifdef QR_CODE_DEBUG
-  DBG2(qrcode->r, "input data --> 2bin result[%s] len:[%d]", result, strlen(result));
+  DBG(qrcode->r, "input data --> 2bin result[%s] len:[%d]", result, strlen(result));
 #endif
 
   return result;
@@ -1652,18 +1643,18 @@ s_data_to_bin_kanji(qr_code_t* qrcode, int data_code_count)
 /**
  * 8bitŤˤ¢¤ï¤»¤Þ¤¹
  */
-static char*
-s_tidy_8bit_code(qr_code_t* qrcode, const char* indata, int data_code_count)
+static char *
+s_tidy_8bit_code(qr_code_t *qrcode, const char *indata, int data_code_count)
 {
   int len = strlen(indata);
   int ii;
   int n;
   int rest;
-  chartmp = NULL;
-  charresult;
+  char *tmp = NULL;
+  char *result;
 
 #ifdef QR_CODE_DEBUG
-  DBG2(qrcode->r, "len[%d] data_code_count * 8 [%d]", len, data_code_count * 8);
+  DBG(qrcode->r, "len[%d] data_code_count * 8 [%d]", len, data_code_count * 8);
 #endif
 
   assert (len <= data_code_count * 8);
@@ -1697,7 +1688,7 @@ s_tidy_8bit_code(qr_code_t* qrcode, const char* indata, int data_code_count)
   }
 
 #ifdef QR_CODE_DEBUG
-  DBG2(qrcode->r, "tidy len[%d] data_code_count[%d]", strlen(result)/8, data_code_count);
+  DBG(qrcode->r, "tidy len[%d] data_code_count[%d]", strlen(result)/8, data_code_count);
 #endif
 
   return result;
@@ -1706,16 +1697,16 @@ s_tidy_8bit_code(qr_code_t* qrcode, const char* indata, int data_code_count)
 /**
  * £²¿Êʸ»úÎó¤ò¥Ð¥¤¥Ê¥ê¤ËÊÑ´¹¤·¤Þ¤¹.
  */
-static char
-s_str_to_bin(qr_code_t* qrcode, char* indata, int data_code_count)
+static char *
+s_str_to_bin(qr_code_t *qrcode, char *indata, int data_code_count)
 {
-  char* result ;
+  char *result;
   int pos;
   int len ;
   int ii;
 
   len = strlen(indata);
-  result = (char*)apr_palloc(qrcode->r->pool, data_code_count);
+  result = (char *)apr_palloc(qrcode->r->pool, data_code_count);
   memset(result, 0, data_code_count);
 
   pos = 0;
@@ -1733,7 +1724,7 @@ s_str_to_bin(qr_code_t* qrcode, char* indata, int data_code_count)
  * ¤½¤Î¤Û¤«¤Î¾ì½ê¤Ë¤Ï¡¢-1¤òÀßÄꤷ¤Þ¤¹.
  */
 static void
-s_init_modules(qr_code_t* qrcode, qr_mask_pattern_t pat, char* dst[])
+s_init_modules(qr_code_t *qrcode, qr_mask_pattern_t pat, char *dst[])
 {
   int module_count = v_module_count_table[qrcode->version];
   int yy;
@@ -1765,7 +1756,7 @@ s_init_modules(qr_code_t* qrcode, qr_mask_pattern_t pat, char* dst[])
  * °ÌÃÖ¸¡½Ð¥Ñ¥¿¡¼¥ó¤È¤Ä¤¤¤Ç¤ËʬΥ¥Ñ¥¿¡¼¥ó¤Î½ÐÎÏ
  */
 static void
-s_setup_probe_position(qr_code_t* qrcode, char* dst[], int pos_x, int pos_y)
+s_setup_probe_position(qr_code_t *qrcode, char *dst[], int pos_x, int pos_y)
 {
   int module_count = v_module_count_table[qrcode->version];
   int xx;
@@ -1834,13 +1825,13 @@ s_setup_probe_position(qr_code_t* qrcode, char* dst[], int pos_x, int pos_y)
  * ¥¿¥¤¥ß¥ó¥°¥Ñ¥¿¡¼¥ó
  */
 static void
-s_setup_timing_pattern(qr_code_t* qrcode, char* dst[])
+s_setup_timing_pattern(qr_code_t *qrcode, char *dst[])
 {
   int module_count = v_module_count_table[qrcode->version];
   int xx, yy;
 #ifdef QR_CODE_DEBUG
   DBG(qrcode->r, "start s_setup_timing_pattern()");
-  DBG1(qrcode->r, "module_count[%d]", module_count);
+  DBG(qrcode->r, "module_count[%d]", module_count);
 #endif
 
   yy=6;
@@ -1874,10 +1865,10 @@ s_setup_timing_pattern(qr_code_t* qrcode, char* dst[])
  * °ÌÃÖ¹ç¤ï¤»¥Ñ¥¿¡¼¥ó
  */
 static void
-s_setup_position_adjust(qr_code_t* qrcode, char* dst[])
+s_setup_position_adjust(qr_code_t *qrcode, char *dst[])
 {
   int module_count = v_module_count_table[qrcode->version];
-  intpos_list = v_position_adjust_table[qrcode->version].position;
+  int *pos_list = v_position_adjust_table[qrcode->version].position;
   int xx, yy;
   int mxx, myy;
   int dxx, dyy;
@@ -1924,7 +1915,7 @@ s_setup_position_adjust(qr_code_t* qrcode, char* dst[])
 }
 
 static void
-s_setup_type_info(qr_code_t* qrcode, char* dst[], qr_mask_pattern_t pat)
+s_setup_type_info(qr_code_t *qrcode, char *dst[], qr_mask_pattern_t pat)
 {
   int module_count = v_module_count_table[qrcode->version];
   int typedata;
@@ -1936,7 +1927,7 @@ s_setup_type_info(qr_code_t* qrcode, char* dst[], qr_mask_pattern_t pat)
 
 #ifdef QR_CODE_DEBUG
   DBG(qrcode->r, "start s_setup_type_info()");
-  DBG1(qrcode->r, "module_count[%d]", module_count);
+  DBG(qrcode->r, "module_count[%d]", module_count);
 #endif
 
   /* ·Á¼°¾ðÊó¥Ç¡¼¥¿¤ÎÀ¸À® */
@@ -2024,12 +2015,12 @@ s_get_bit_count(int data)
 
 
 static void
-s_setup_version_info(qr_code_t* qrcode, char* dst[])
+s_setup_version_info(qr_code_t *qrcode, char *dst[])
 {
-  charbits = v_version_info_table[qrcode->version].bits;
+  char *bits = v_version_info_table[qrcode->version].bits;
   int module_count = v_module_count_table[qrcode->version];
-  int xx;
-  int yy;
+  size_t xx;
+  size_t yy;
 
   if (bits == NULL) {
     /* ¥Ð¡¼¥¸¥ç¥ó£·°Ê¹ß¤Î¤ßÂоݠ*/
@@ -2048,9 +2039,9 @@ s_setup_version_info(qr_code_t* qrcode, char* dst[])
 }
 
 static void 
-s_map_data(qr_code_tqrcode,
-           chardst[], 
-           unsigned charindata, int data_count,qr_mask_pattern_t pat)
+s_map_data(qr_code_t     *qrcode,
+           char          *dst[], 
+           unsigned char *indata, int data_count,qr_mask_pattern_t pat)
 {
   int module_count = v_module_count_table[qrcode->version];
   int inc_yy_flag = -1;
@@ -2063,8 +2054,8 @@ s_map_data(qr_code_t* qrcode,
 
 #ifdef QR_CODE_DEBUG
   DBG(qrcode->r, "start s_map_data()");
-  DBG1(qrcode->r, "module_count[%d]", module_count);
-  DBG1(qrcode->r, "data_count[%d]", data_count);
+  DBG(qrcode->r, "module_count[%d]", module_count);
+  DBG(qrcode->r, "data_count[%d]", data_count);
 #endif
   in_pos = 0;
   now_bit = 7;
@@ -2145,7 +2136,7 @@ s_get_mask(qr_mask_pattern_t pat, int yy, int xx)
 
 
 static int
-s_calc_lost_point(qr_code_t* qrcode, char* dst[])
+s_calc_lost_point(qr_code_t *qrcode, char *dst[])
 {
   int point = 0;
 
@@ -2169,28 +2160,32 @@ s_calc_lost_point(qr_code_t* qrcode, char* dst[])
  * ¼ºÅÀ=3+i
  */
 static int
-s_count_same_module(qr_ver_t ver, chardst[])
+s_count_same_module(qr_ver_t ver, char *dst[])
 {
-  int module_count = v_module_count_table[ver];
-  int point = 0;
+  int module_count;
+  int point;
   int xx, yy;
-  int same_count = 0;
-  int prev_value = -1;
+  int same_count;
+  int prev_value;
+
+  module_count = v_module_count_table[ver];
+  point        = 0;
+  same_count   = 0;
+  prev_value   = -1;
 
   /* ²£Êý¸þ¤Ç¥Á¥§¥Ã¥¯ */
   for (yy=0; yy<module_count; yy++) {
     prev_value = -1;
     same_count = 0;
     for (xx=0; xx<module_count; xx++) {
-      if (prev_value == (unsigned char)dst[yy][xx]) {
+      if (prev_value == (unsigned char)dst[yy][xx])
         same_count++;
-      }
-      else {
+      else
         same_count = 0;
-      }
-      if (same_count >= 5) {
+
+      if (same_count >= 5) 
         point++;
-      }
+
       prev_value = (unsigned char)dst[yy][xx];
     }
   }
@@ -2225,13 +2220,15 @@ s_count_same_module(qr_ver_t ver, char* dst[])
  * Æ±¿§¤Î¥â¥¸¥å¡¼¥ë¥Ö¥í¥Ã¥¯ ¥Ö¥í¥Ã¥¯¥µ¥¤¥º 2¡ß2 
  */
 static int
-s_count_same_block(qr_ver_t ver, chardst[])
+s_count_same_block(qr_ver_t ver, char *dst[])
 {
-  int module_count = v_module_count_table[ver];
+  int module_count;
   int point;
   int count;
   int xx,yy;
 
+  module_count = v_module_count_table[ver];
+
   point = 0;
   for (yy = 0; yy < module_count-1; yy++) {
     for (xx = 0; xx < module_count-1; xx++) {
@@ -2249,12 +2246,14 @@ s_count_same_block(qr_ver_t ver, char* dst[])
 }
 
 static int
-s_count_11311_pattern(qr_ver_t ver, chardst[])
+s_count_11311_pattern(qr_ver_t ver, char *dst[])
 {
-  int module_count = v_module_count_table[ver];
+  int module_count;
   int point;
   int xx,yy;
 
+  module_count = v_module_count_table[ver];
+
   point = 0;
   /* ²£Êý¸þ¤Î¥Á¥§¥Ã¥¯ */
   for (yy = 0; yy < module_count; yy++) {
@@ -2288,17 +2287,23 @@ s_count_11311_pattern(qr_ver_t ver, char* dst[])
 
   return point;
 }
+
+
 /* 
  * Á´ÂΤËÀê¤á¤ë°Å¥â¥¸¥å¡¼¥ë¤Î³ä¹ç 50¡Þ(5+k)%¡Á50¡Þ(5+(k+1))% 
  */
 static int
-s_count_dark_ratio(qr_ver_t ver, chardst[])
+s_count_dark_ratio(qr_ver_t ver, char *dst[])
 {
-  int module_count = v_module_count_table[ver];
-  int dark_count = 0;
+  int module_count;
+  int dark_count;
   int xx, yy;
   int ratio;
-  int all_count = module_count * module_count;
+  int all_count;
+
+  module_count = v_module_count_table[ver];
+  dark_count   = 0;
+  all_count    = module_count * module_count;
 
   /* Ã±¤Ë"°Å"¤ò¥«¥¦¥ó¥È¤¹¤ë */
   for (yy=0; yy<module_count; yy++) {