Annotation of parser3/src/targets/parser/parser.C, revision 1.1

1.1     ! paf         1: /*
        !             2:   $Id: parser.C,v 1.16 2001/01/29 22:34:58 paf Exp $
        !             3: */
        !             4: 
        !             5: #include <stdio.h>
        !             6: #include <stdlib.h>
        !             7: 
        !             8: #include "pa_pool.h"
        !             9: #include "pa_hash.h"
        !            10: #include "pa_array.h"
        !            11: #include "pa_table.h"
        !            12: #include "pa_common.h"
        !            13: 
        !            14: char *itoa(int n, char *buf){
        !            15:     snprintf(buf,MAX_STRING,"%d",n);
        !            16:     return buf;
        !            17: }
        !            18: 
        !            19: int main(int argc, char *argv[]) {
        !            20:        parser_Pool pool;
        !            21: 
        !            22:        char *file="file1";
        !            23:        String& string=pool.make_string();
        !            24:        string.APPEND("Hello, ", file, 1);
        !            25:        string.APPEND("w", file, 2);
        !            26:        string.APPEND("o", file, 3);
        !            27:        string.APPEND("r", file, 4);
        !            28:        string.APPEND("l", file, 5);
        !            29:        string.APPEND("d", file, 6);
        !            30:        string.APPEND("!\n ", file, 7);
        !            31:        printf(string.cstr());
        !            32: 
        !            33:        char *key1_file="key1_file";
        !            34:        Hash& hash=pool.make_hash();
        !            35:        String key1=string;
        !            36:        key1.APPEND("1", key1_file, 1);
        !            37:        String& value1=pool.make_string();
        !            38:        value1.APPEND("i'm value1\n", file, 1);
        !            39:        String& value2=pool.make_string();
        !            40:        value2.APPEND("i'm value2\n", file, 1);
        !            41:        hash.put(key1, &value1);
        !            42:        char *key2_file="key2_file";
        !            43:        String key2=string;
        !            44:        key2.APPEND("2", key2_file, 1);
        !            45:        hash.put(key2, &value2);
        !            46:        String *found_value=(String*)hash.get(key2);
        !            47:        printf(found_value?found_value->cstr():"not found\n");
        !            48: 
        !            49:        String& a=pool.make_string();   a.APPEND("fi", file, 1); a.APPEND("rst", file, 2);
        !            50:        String& b=pool.make_string();   b.APPEND("fir", file, 1); b.APPEND("st", file, 2);
        !            51:        printf(a==b?"eq\n":"ne\n");
        !            52: 
        !            53: 
        !            54:        Array& array=pool.make_array(2);
        !            55:        array+="first";
        !            56:        array+="second";
        !            57:        array+="third";
        !            58:        printf("%s-%s-%s\n", 
        !            59:                        array.get_cstr(0)        !            60:                        array.get_cstr(1),
        !            61:                        array.get_cstr(2));
        !            62: 
        !            63:        Array& a1=pool.make_array();
        !            64:        a1+="first";
        !            65:        Array& a2=pool.make_array();
        !            66:        a2+="second";
        !            67:        Array& asum=pool.make_array();
        !            68:        asum.append_array(a1);
        !            69:        asum.append_array(a2);
        !            70:        printf("%s-%s\n", 
        !            71:                        asum.get_cstr(0)        !            72:                        asum.get_cstr(1));
        !            73: 
        !            74:        parser_Pool request_pool;
        !            75:        Request request(&request_pool);
        !            76:        Exception global_exception;
        !            77:        request.pool.set_global_exception(&global_exception);
        !            78:        if(EXCEPTION_TRY(request.pool.global_exception())) {
        !            79:                Exception local_exception;
        !            80:                request.pool.set_local_exception(&local_exception);
        !            81:                if(EXCEPTION_TRY(request.pool.local_exception())) {
        !            82:                        Array acolumns(request.pool);
        !            83:                        acolumns+="id";
        !            84:                        acolumns+="name";
        !            85:                        acolumns+="age";
        !            86:                        Table named_table(request, "_file.cfg", 1, &acolumns);
        !            87:                        for(int n=1; n<=5; n++) {
        !            88:                                Array& row=request.pool.make_array(named_table.columns()->size());
        !            89:                                char *buf=static_cast<char *>(request.pool.malloc(MAX_STRING));
        !            90:                                row+=itoa(n, buf);
        !            91:                                row+="paf";
        !            92:                                row+="99";
        !            93:                                
        !            94:                                named_table+=&row;
        !            95:                        }
        !            96:                        
        !            97:                        for(int i=0; i<named_table.columns()->size(); i++) 
        !            98:                                printf("%s\t", named_table.columns()->get_cstr(i));
        !            99:                        printf("\n");
        !           100:                        for(named_table.set_current(0); named_table.get_current()<named_table.size(); named_table.inc_current()) {
        !           101:                                String line(request.pool);
        !           102:                                for(int i=0; i<named_table.columns()->size(); i++) {
        !           103:                                        //String name(request.pool);
        !           104:                                        //char *buf=static_cast<char *>(request.pool.malloc(MAX_STRING));
        !           105:                                        //name.APPEND(itoa(i, buf), "names file", 0);
        !           106:                                        //name.APPEND("id", "names file", 0);
        !           107:                                        //named_table.read_item(line, name);
        !           108:                                        const char *cstr_name=named_table.columns()->get_cstr(i);
        !           109:                                        String name(request.pool);
        !           110:                                        name.APPEND(cstr_name, 0, 0);
        !           111:                                        named_table.read_item(line, name);
        !           112:                                        line.APPEND("\t", 0, 0);
        !           113:                                }
        !           114:                                printf("%s\n", line.cstr());
        !           115:                        }
        !           116:                } else {
        !           117:                        printf("operator_error occured: \n");
        !           118:                        const String *problem_source=request.operator_error.problem_source();
        !           119:                        if(problem_source) {
        !           120:                                const Origin& origin=problem_source->origin();
        !           121:                                printf("  origin: '%s', file '%s', line %d\n", 
        !           122:                                        problem_source->cstr(),
        !           123:                                        origin.file, origin.line);
        !           124:                        }
        !           125:                        printf("  comment: %s\n", request.operator_error.comment());
        !           126:                }
        !           127:        } else {
        !           128:                printf("request_error occured: \n");
        !           129:                const String *problem_source=request.request_error.problem_source();
        !           130:                if(problem_source) {
        !           131:                        const Origin& origin=problem_source->origin();
        !           132:                        printf("  origin: '%s', file '%s', line %d\n", 
        !           133:                                problem_source->cstr(),
        !           134:                                origin.file, origin.line);
        !           135:                }
        !           136:                printf("  comment: %s\n", request.request_error.comment());
        !           137:        }
        !           138: 
        !           139:        return 0;
        !           140: }

E-mail: