Mac에 APM활성화 하기: http://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-osx-10-11-el-capitan/

Mac에 APM활성화 하기: https://www.youtube.com/watch?v=o2Qt1H4duYw

Android Studio를 통해서 Login & Register만들기: https://www.inflearn.com/course/안드로이드-스튜디오-안드로이드-앱-만들기/



Login & Register


인강처럼 cafe24에서 서버를 구매하고 실행해되지만 나는 Mac의 locahost를 설치하여 실행 했다.

하지만 위에 나와있는 방법으로 APM을 설치하면 무조건 오류가 난다.


주의할 점은 Mysql의 번전을 5.7로 받는 것이다. 최신 버전 8은 연동이 안되어서 android studio에서 접근이 안되었다. 버전을 5.7(영상에서 사용하는)로 재설치 하였더니 되었다.

즉, 최신 버전의 Mysql을 받지 마라.


android stuido에서 Request Activity 부분에서 url에 들어가는 부분에 http://localhost/...... 가 아닌 자신의 ip주소를(127.0.0.1말고 ifconfig를 통한 ip 주소) 사입하여라.

확실하지는 않지만, emulator로 인터넷에 접속하여 실행하기 때문에 해당 url의 localhost 혹은 127.0.0.1은 내 컴퓨터가 아닌 emulator의 localhost로 가기 때문에 해당 db로 접속을 하지 못했던 것 같다. 



나중에 여유가되면, 이미지 파일을 통해서 자세한 설명을 하겠다. 위에 link를 통해서 설치하고 coding하고 알려준 주의점을 생각하면 Mac으로도 충분히 Localhost를 기반으로 하는 android 형 LoginRegister를 만들 수 있다.

 



새로운 토큰을 파싱한다






해당 메뉴를 store.c에 파싱한다. Makefile에서 실행시킨다

{

"Yori":

[

{

  "name":"Haemultang",

          "size":"Jong",

          "price":50000

        },

{

          "name":"Haemultang",

          "size":"Dae",

          "price":60000

        },

{

          "name":"Haemuljimg",

          "size":"Jong",

          "price":50000

        },

{

          "name":"Haemuljim",

          "size":"Dae",

          "price":60000

        }

],

"Sicksa":

[

 {

          "name":"BJnoodle",

          "size":"1 piece",

          "price":7000

        },

{

          "name":"FIredSquid",

          "size":"1 piece",

          "price":8000

        },

{

          "name":"Rice with Suisi",

          "size":"1 piece",

          "price":10000

        }

]

}


store.c 및 여러 fucntion



#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "jsmn.h"



/*

 * A small example of jsmn parsing when JSON structure is known and number of

 * tokens is predictable.

 */


//void printkey(const char * a, jsmntok_t *b,int c );

static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {

if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&

strncmp(json + tok->start, s, tok->end - tok->start) == 0) {

return 0;

}

return -1;

}


char * jsmn_StringReader(const char * fileName){


char  a[20];

char * b;

FILE *f1;

f1=fopen(fileName,"r");


b=(char *)malloc(sizeof(char));

 //a=(char*)malloc(sizeof(char));


while(1){

  fgets(a,sizeof(a),f1);

        if(feof(f1))break;

  b=(char*)realloc(b,strlen(b)+strlen(a));

  //printf("\n%d\n",strlen(a));

  strncat(b,a,strlen(a));

}


fclose(f1);

 return b ;

}



void printall(const char *json,jsmntok_t *t,int tok_count ){

int i=0;

char t_type[20];

for( i=1;i<tok_count;i++){

printf("[%d] %.*s (size: %d, %d~%d,",i,t[i].end-t[i].start, json + t[i].start,t[i].size,t[i].start,t[i].end);

switch(t[i].type){

case 0: strcpy(t_type,"JSMN_UNDEFIEND");break;

case 1: strcpy(t_type,"JSMN_OBJECT");break;

case 2: strcpy(t_type,"JSMN_ARRAY");break;

case 3: strcpy(t_type,"JSMN_STRING");break;

case 4: strcpy(t_type,"JSMN_PRIMITIVE");break;

default:  break;



}

printf("%s) \n",t_type);

}



}






typedef enum{

 C_SET=0,

 C_MEAL=1

} mycategory_t;



typedef struct{

mycategory_t cat;

char name[20];

char size[10];

int price;

} mymenu_t;





void printmenu(mymenu_t*m[], int count){


int i=0;


for(i=0;i<count;i++){

switch(m[i]->cat){

case 0: printf("Yori-->\n");break;

case 1: printf("Sicksa-->\n");break;

}


printf("이름: %s\n",m[i]->name);

printf("크기: %s\n",m[i]->size);

printf("가격: %d\n",m[i]->price);

printf("\n");


}




}


int makemymenu(const char *json, jsmntok_t *t, int r, mymenu_t* m[]){

int size=0;

        int i=0,j=0,menucount=0;

int type=0;

char through[20];


        for(i=1;i<r;i++){

        if(t[i+1].type==2){

if( !strncmp("Yori", json + t[i].start,t[i].end-t[i].start)){type=0;}

else if ( !strncmp("Sicksa", json + t[i].start,t[i].end-t[i].start)){type=1;}

else type =0;

        size=t[i+1].size;

       

i+=4;


                for(j=menucount;j<menucount+size;i+=3,j++){

m[j]->cat=type;

                strncpy(m[j]->name, json + t[i].start,t[i].end-t[i].start);i+=2;

                strncpy(m[j]->size,json + t[i].start,t[i].end-t[i].start);i+=2;

strncpy(through,json+t[i].start,t[i].end-t[i].start);

                m[j]->price=atoi(through);

                }i-=3;

        menucount+=size;

}


        }




        return menucount;


        }





int order(mymenu_t *m[],int count){


int answer;

int receits=0;

int i=0;


while(1){

//aks

printf("Would you like to order? (1.yes  2.no)\n");

scanf("%d",&answer);

if(answer==2)break;


while(1){

for(i=0;i<count;i++){

printf("[%d]\tname: %s\n\t%s\n\t%d won\n\n",i+1,m[i]->name,m[i]->size,m[i]->price);

}

printf("Chose food you want to eat\n");

scanf("%d",&answer);

if(answer<1||answer>count)

printf("Type right index please.......\n");

else break;

}


receits+=m[answer-1]->price;

}


printf("You have orderd %d won \n",receits);

return receits;



}




void jsmn_init(jsmn_parser *parser);

int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,jsmntok_t *tokens, unsigned int num_tokens);


int main() {

int keyarray[128],keyamount;

int i;

int r;

int menucount;

jsmn_parser p;

jsmntok_t t[128]; /* We expect no more than 128 tokens */

mymenu_t *  mymenu[20];


for(i=0;i<20;i++)

mymenu[i]=(mymenu_t*)malloc(sizeof(mymenu_t));


char  fileName[20];

jsmn_init(&p);

printf("Insert a file Name:");

scanf("%s",fileName);

char * JSON_STRING=jsmn_StringReader(fileName);

r = jsmn_parse(&p, JSON_STRING, strlen(JSON_STRING), t, sizeof(t)/sizeof(t[0]));


<<<<<<< HEAD

    keyamount=findkeys(JSON_STRING,t,r,keyarray);

    printall(JSON_STRING,t,r);

    printkeys(JSON_STRING,t,r);

    printf("Keyamount is %d\n",keyamount);

    int b=0;for( b=0;b<keyamount;b++)printf("--> %d\n",keyarray[b]);

    

    

    

    printvalues(JSON_STRING,t,r,keyarray);

    return EXIT_SUCCESS;

=======


keyamount=findkeys(JSON_STRING,t,r,keyarray);

printall(JSON_STRING,t,r);

printkeys(JSON_STRING,t,r);

printf("Keyamount is %d\n",keyamount);

int b=0;for( b=0;b<keyamount;b++)printf("--> %d\n",keyarray[b]);

int k;

menucount=makemymenu(JSON_STRING,t,r,mymenu);

printf("\n\n\n menucount: %d\n",menucount);

printmenu(mymenu,menucount);

order(mymenu,menucount);

return EXIT_SUCCESS;

>>>>>>> 94ae9aa240ab50babaf259b9275e72cc0fd9856d

}







------------------------------------------------------------------------------------------------------------------------------------------

Output)




order()





order함수는 user로 부터 input을 받아서 user가 시킨 음식값을 반환하는 함수이다

각, 메뉴의 token number에 접근하여 구조체로 부터  직접 값을 얻어온다



int order(mymenu_t *m[],int count){


int answer;

int receits=0;

int i=0;


while(1){

//aks

printf("Would you like to order? (1.yes  2.no)\n");

scanf("%d",&answer);

if(answer==2)break;


while(1){

for(i=0;i<count;i++){

printf("[%d]\tname: %s\n\t%s\n\t%d won\n\n",i+1,m[i]->name,m[i]->size,m[i]->price);

}

printf("Chose food you want to eat\n");

scanf("%d",&answer);

if(answer<1||answer>count)

printf("Type right index please.......\n");

else break;

}


receits+=m[answer-1]->price;

}


printf("You have orderd %d won \n",receits);

return receits;



}

---------------------------------------------------------------------------------------------------------------------------------------------------------------

Output)


위의 예제는 user가 메뉴판을 보고 해당 index값을 넣고 해당 index에 대한 메뉴의 가격이 종합되어서 출력되는 예제이다.


printmenu()






[jsmn]파싱된 토큰으로 새로운 구조체에 저장하기에서 받은 메뉴값을 출력하는 함수이다

이미 mymenu_t라는 구조체 안에 각 메뉴들이 저장되어 있다. 그래서 각 token에 대하여 올바르게 print하면 된다




void printmenu(mymenu_t*m[], int count){


int i=0;


for(i=0;i<count;i++){

switch(m[i]->cat){

case 0: printf("Yori-->\n");break;

case 1: printf("Sicksa-->\n");break;

}


printf("이름: %s\n",m[i]->name);

printf("크기: %s\n",m[i]->size);

printf("가격: %d\n",m[i]->price);

printf("\n");


}




}




type은 enum이기 때문에 int값이다. 그래서 switch를 통해서 더 정확한 정보를 출력한다



Output)









makemymenu()


typedef enum{

 C_SET=0,

 C_MEAL=1

} mycategory_t;



typedef struct{

mycategory_t cat;

char name[20];

char size[10];

int price;

} mymenu_t;



로 구성된 구조체에 다음 메뉴를 저장하기를 원한다


{

"Yori":

[

{

  "name":"Haemultang",

          "size":"Jong",

          "price":50000

        },

{

          "name":"Haemultang",

          "size":"Dae",

          "price":60000

        },

{

          "name":"Haemuljimg",

          "size":"Jong",

          "price":50000

        },

{

          "name":"Haemuljim",

          "size":"Dae",

          "price":60000

        }

],

"Sicksa":

[

 {

          "name":"BJnoodle",

          "size":"1 piece",

          "price":7000

        },

{

          "name":"FIredSquid",

          "size":"1 piece",

          "price":8000

        },

{

          "name":"Rice with Suisi",

          "size":"1 piece",

          "price":10000

        }

]

}




---------------------------------------------------------------------------------------------------

int makemymenu(const char *json, jsmntok_t *t, int r, mymenu_t* m[]){
int size=0;
        int i=0,j=0,menucount=0;
int type=0;
char through[20];

        for(i=1;i<r;i++){
        if(t[i+1].type==2){
if( !strncmp("Yori", json + t[i].start,t[i].end-t[i].start)){type=0;}
else if ( !strncmp("Sicksa", json + t[i].start,t[i].end-t[i].start)){type=1;}
else type =0;
        size=t[i+1].size;
       
i+=4;

                for(j=menucount;j<menucount+size;i+=3,j++){
m[j]->cat=type;
                strncpy(m[j]->name, json + t[i].start,t[i].end-t[i].start);i+=2;
                strncpy(m[j]->size,json + t[i].start,t[i].end-t[i].start);i+=2;
strncpy(through,json+t[i].start,t[i].end-t[i].start);
                m[j]->price=atoi(through);
                }i-=3;
        menucount+=size;
}

        }



        return menucount;

        }

다음 코드는 object의 type을 "Yori"와 "Sicksa"로 구분하여 이름, 크기 그리고 가격으로 구조체에 저장하는 함수이다.
즉, 음식점의 요리류와 식사류의 음식을 메뉴로 parsing하는 함수이다



<printvalue()>




#include <stdio.h>

#include <string.h>

#include "jsmn.h"




void printvalues(const char *json, jsmntok_t *t, int tokcount,int *keys){

int i,j=0;

for(i=0;i<=tokcount;i++){

if(i==keys[j]){

printf("[%d] value:  %.*s\n",j+1,t[i+1].end-t[i+1].start,json+t[i+1].start);

j++;

}

}

}


설명: 다음 함수는 key에 저장된 key token의 번호 데이터를 통해서 token의 위치와 같은 경우 (즉, key token인 경우) 출력하게 하는 함수이다.



    printvalues(JSON_STRING,t,r,keyarray);

    return EXIT_SUCCESS;

}

parsejson.c에 마지막 부분에 추가한 printvalues()함수이다




<Output>







<findkeys()>



#include <stdio.h>

#include <string.h>

#include "jsmn.h"






int findkeys(const char *json, jsmntok_t *t, int tokcount, int * keys){ int i,j=0;

for(i=1;i<tokcount;i++){

if(t[i].size>=1&&t[i].type==3){

keys[j++]=i;

}

}

return j;


}


설며이: 코드는 간단하다. parsing된 token들의 데이터를 토대로 조건문과 반복문을 돌려 size가 1이 이상인경우 그리고 JSMN_STRING인 경우의 token만 keys (parse.c에서는 int array의 argument를 받는다)에 저장하게 된다.




keyamount=findkeys(JSON_STRING,t,r,keyarray);

printall(JSON_STRING,t,r);

printkeys(JSON_STRING,t,r);

printf("Keyamount is %d\n",keyamount);

int b=0;for( b=0;b<keyamount;b++)printf("--> %d\n",keyarray[b]);

return EXIT_SUCCESS;

}


parsejson.c  파일 하단에 findkeys함수와 그 값을 출력하는 값을 출력 하였다. 

<Output>

그럼 다음과 같은 결과 값이 나온다. keyarray에 저장된 array 수는 총 10개이며 각 index에는 parsing된 token의 token번호가 순서대로 저장되어있다.


<printall()>


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "jsmn.h"




void printkeys(const char *json, jsmntok_t *t, int tokcount){

int i=0;

int j=0;

printf("***********All Keys***********");

for(i=1;i<tokcount;i++){

if(t[i].size<1||t[i].type!=3)continue;

else{ j++; 

printf("\n[%d] %.*s (%d)",j,t[i].end-t[i].start,json+t[i].start,i);


}

}

puts("");

}

설명: 해당 함수는 token의 type을 통해서 token이 string인 경우 출력하는 함수이다

하지만, type이 string임에도 key가 아닌 경우가 있다. key가 아닌 내용인 경우 size가 0이기 때문에 그부분도 거른다.

([jsmn]parsing된 token 정보 출력하는 printall함수 page의 output을 보면 알수 있다) 


즉, token이 OBJECT이거나 ARRAY인 경우는 continue를 통해서 출력 제외 대상이 된다



<Output>

괄호안에는 토큰의 순서를 표시한다

예를 들어 keywords는 전체 token의 3번째 token이다





<parsejsmn.c>


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "jsmn.h"



/*

 * A small example of jsmn parsing when JSON structure is known and number of

 * tokens is predictable.

 */



static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {

if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&

strncmp(json + tok->start, s, tok->end - tok->start) == 0) {

return 0;

}

return -1;

}


char * jsmn_StringReader(const char * fileName){


char  a[20];

char * b;

FILE *f1;

f1=fopen(fileName,"r");


b=(char *)malloc(sizeof(char));

 //a=(char*)malloc(sizeof(char));


while(1){

  fgets(a,sizeof(a),f1);

        if(feof(f1))break;

  b=(char*)realloc(b,strlen(b)+strlen(a));

  //printf("\n%d\n",strlen(a));

  strncat(b,a,strlen(a));

}


fclose(f1);

 return b ;

}



void printall(const char *json,jsmntok_t *t,int tok_count ){

int i=0;

char t_type[20];

for( i=1;i<tok_count;i++){

printf("[%d] %.*s (size: %d, %d~%d,",i,t[i].end-t[i].start, json + t[i].start,t[i].size,t[i].start,t[i].end);

switch(t[i].type){

case 0: strcpy(t_type,"JSMN_UNDEFIEND");break;

case 1: strcpy(t_type,"JSMN_OBJECT");break;

case 2: strcpy(t_type,"JSMN_ARRAY");break;

case 3: strcpy(t_type,"JSMN_STRING");break;

case 4: strcpy(t_type,"JSMN_PRIMITIVE");break;

default:  break;



}

printf("%s) \n",t_type);

}



}









void jsmn_init(jsmn_parser *parser);

int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,jsmntok_t *tokens, unsigned int num_tokens);


int main() {

int i;

int r;

jsmn_parser p;

jsmntok_t t[128]; /* We expect no more than 128 tokens */


char  fileName[20];

jsmn_init(&p);

printf("Insert a file Name:");

scanf("%s",fileName);

char * JSON_STRING=jsmn_StringReader(fileName);

// printf("%s\n",JSON_STRING);

r = jsmn_parse(&p, JSON_STRING, strlen(JSON_STRING), t, sizeof(t)/sizeof(t[0]));

if (r < 0) {

printf("Failed to parse JSON: %d\n", r);

return 1;

}


/* Assume the top-level element is an object */

if (r < 1 || t[0].type != JSMN_OBJECT) {

printf("Object expected\n");

return 1;

}

#ifdef DEBUG_MODE


printf("r의 값은 %d입니다",r);

#endif

/* Loop over all keys of the root object */

for (i = 1; i < r; i++) {

if (jsoneq(JSON_STRING, &t[i], "name") == 0) {

/* We may use strndup() to fetch string value */

//printf("%.*s",t[i].end-t[i].start,

                          //             JSON_STRING + t[i].start);

printf("- Name: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


        printf("User의 token은 %d번째입니다",i);

        #endif

} else if (jsoneq(JSON_STRING, &t[i], "keywords") == 0) {

/* We may additionally check if the value is either "true" or "false" */

printf("- Keywords: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


                 printf("Admin의 token은 %d번째입니다",i);

                 #endif


} else if (jsoneq(JSON_STRING, &t[i], "description") == 0) {

/* We may want to do strtol() here to get numeric value */

printf("- Description: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

} 


else if (jsoneq(JSON_STRING, &t[i], "type") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- type: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE

                 #endif

                } 



else if (jsoneq(JSON_STRING, &t[i], "url") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- url: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                } 



else if (jsoneq(JSON_STRING, &t[i], "frameworks") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Frameworks: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }

else if (jsoneq(JSON_STRING, &t[i], "platforms") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Platfroms: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }


else if (jsoneq(JSON_STRING, &t[i], "exclude") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Excludes: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }



else if (jsoneq(JSON_STRING, &t[i], "examples") == 0) {

                        int j;

                        printf("- Exampleis:\n");

                        if (t[i+1].type != JSMN_ARRAY) {

                                continue; /* We expect groups to be an array of strings */

                        }

                        for (j = 0; j < t[i+1].size; j++) {

                                jsmntok_t *g = &t[i+j+2];

                                printf("  * %.*s\n", g->end - g->start, JSON_STRING + g->start);

                        }

                        i += t[i+1].size + 1;

                } 



else if (jsoneq(JSON_STRING, &t[i], "repository") == 0) {

int j;

printf("- Repository:\n");

if (t[i+1].type != JSMN_ARRAY) {

continue; /* We expect groups to be an array of strings */

}

for (j = 0; j < t[i+1].size; j++) {

jsmntok_t *g = &t[i+j+2];

printf("  * %.*s\n", g->end - g->start, JSON_STRING + g->start);

}

i += t[i+1].size + 1;

#ifdef DEBUG_MODE


                 printf("Object인 groups의  token은 %d번째입니다",i);

                 #endif

} else {

printf("Unexpected key: %.*s\n", t[i].end-t[i].start,

JSON_STRING + t[i].start);

}

}


printall(JSON_STRING,t,r);

return EXIT_SUCCESS;

}




설명: parsejsmn은 기본적으로 입력된 txt file을 읽어주어서 parsing하는 코드이다. 여기에 printall이라는 함수를 추가했다. 마지막 return 되기전에 printall이라는 함수가 존재한다. parameter는 json_string(입받은 txt을 string form), parsing된 r, token들의 정보를 가진 t로 받는다. 그러면, printall에서는 각각의 token에 대하여 정보를 출력한다


<printall()>

void printall(const char *json,jsmntok_t *t,int tok_count ){

     int i=0;

     char t_type[20];

     for( i=1;i<tok_count;i++){

         printf("[%d] %.*s (size: %d, %d~%d,",i,t[i].end-t[i].start, json + t[i].start,t[i].size,t[i].start,t[i].end);

                 switch(t[i].type){

                     case 0: strcpy(t_type,"JSMN_UNDEFIEND");break;

                     case 1: strcpy(t_type,"JSMN_OBJECT");break;

                     case 2: strcpy(t_type,"JSMN_ARRAY");break;

                     case 3: strcpy(t_type,"JSMN_STRING");break;

                     case 4: strcpy(t_type,"JSMN_PRIMITIVE");break;

                     default:  break;

        

                }

            printf("%s) \n",t_type);

          }



}


출력되는 값들은.....

1. 해당 token의 size

2. token의 문자열 위치(시작과 끝)

3. token의 type





<Output>


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "jsmn.h"



/*

 * A small example of jsmn parsing when JSON structure is known and number of

 * tokens is predictable.

 */



static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {

if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&

strncmp(json + tok->start, s, tok->end - tok->start) == 0) {

return 0;

}

return -1;

}


char * jsmn_StringReader(){


char * a;

char * b;

FILE *f1;

f1=fopen("library.json","r");


b=(char *)malloc(sizeof(char));

 a=(char*)malloc(sizeof(char));


while(1){

  fgets(a,sizeof(a),f1);

        if(feof(f1))break;

  b=(char*)realloc(b,strlen(b)+strlen(a));

  //printf("\n%d\n",strlen(a));

  strncat(b,a,strlen(a));

}


fclose(f1);

 return b ;

}




void jsmn_init(jsmn_parser *parser);

int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,jsmntok_t *tokens, unsigned int num_tokens);


int main() {

int i;

int r;

jsmn_parser p;

jsmntok_t t[128]; /* We expect no more than 128 tokens */


jsmn_init(&p);

char * JSON_STRING=jsmn_StringReader();

printf("%s\n",JSON_STRING);

r = jsmn_parse(&p, JSON_STRING, strlen(JSON_STRING), t, sizeof(t)/sizeof(t[0]));

if (r < 0) {

printf("Failed to parse JSON: %d\n", r);

return 1;

}


/* Assume the top-level element is an object */

if (r < 1 || t[0].type != JSMN_OBJECT) {

printf("Object expected\n");

return 1;

}

#ifdef DEBUG_MODE


printf("r의 값은 %d입니다",r);

#endif

/* Loop over all keys of the root object */

for (i = 1; i < r; i++) {

if (jsoneq(JSON_STRING, &t[i], "name") == 0) {

/* We may use strndup() to fetch string value */

printf("- Name: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


        printf("User의 token은 %d번째입니다",i);

        #endif

} else if (jsoneq(JSON_STRING, &t[i], "keywords") == 0) {

/* We may additionally check if the value is either "true" or "false" */

printf("- Keywords: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


                 printf("Admin의 token은 %d번째입니다",i);

                 #endif


} else if (jsoneq(JSON_STRING, &t[i], "description") == 0) {

/* We may want to do strtol() here to get numeric value */

printf("- Description: %.*s\n", t[i+1].end-t[i+1].start,

JSON_STRING + t[i+1].start);

i++;

#ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

} 


else if (jsoneq(JSON_STRING, &t[i], "type") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- type: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE

                 #endif

                } 



else if (jsoneq(JSON_STRING, &t[i], "url") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- url: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                } 



else if (jsoneq(JSON_STRING, &t[i], "frameworks") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Frameworks: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }

else if (jsoneq(JSON_STRING, &t[i], "platforms") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Platfroms: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }


else if (jsoneq(JSON_STRING, &t[i], "exclude") == 0) {

                        /* We may want to do strtol() here to get numeric value */

                        printf("- Excludes: %.*s\n", t[i+1].end-t[i+1].start,

                                        JSON_STRING + t[i+1].start);

                        i++;

                #ifdef DEBUG_MODE


                 printf("Uid의 token은 %d번째입니다",i);

                 #endif

                }



else if (jsoneq(JSON_STRING, &t[i], "examples") == 0) {

                        int j;

                        printf("- Exampleis:\n");

                        if (t[i+1].type != JSMN_ARRAY) {

                                continue; /* We expect groups to be an array of strings */

                        }

                        for (j = 0; j < t[i+1].size; j++) {

                                jsmntok_t *g = &t[i+j+2];

                                printf("  * %.*s\n", g->end - g->start, JSON_STRING + g->start);

                        }

                        i += t[i+1].size + 1;

                } 



else if (jsoneq(JSON_STRING, &t[i], "repository") == 0) {

int j;

printf("- Repository:\n");

if (t[i+1].type != JSMN_ARRAY) {

continue; /* We expect groups to be an array of strings */

}

for (j = 0; j < t[i+1].size; j++) {

jsmntok_t *g = &t[i+j+2];

printf("  * %.*s\n", g->end - g->start, JSON_STRING + g->start);

}

i += t[i+1].size + 1;

#ifdef DEBUG_MODE


                 printf("Object인 groups의  token은 %d번째입니다",i);

                 #endif

} else {

printf("Unexpected key: %.*s\n", t[i].end-t[i].start,

JSON_STRING + t[i].start);

}

}

return EXIT_SUCCESS;

}


+ Recent posts