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

1.1       paf         1: /*
1.15    ! paf         2:   $Id: parser.C,v 1.14 2001/02/21 16:12:16 paf Exp $
1.1       paf         3: */
                      4: 
                      5: #include <stdio.h>
                      6: #include <stdlib.h>
                      7: 
                      8: #include "pa_hash.h"
                      9: #include "pa_array.h"
                     10: #include "pa_table.h"
                     11: #include "pa_common.h"
1.4       paf        12: #include "pa_pool.h"
1.10      paf        13: #include "pa_vclass.h"
1.1       paf        14: 
1.14      paf        15: #include "core.h"
                     16: 
1.1       paf        17: char *itoa(int n, char *buf){
                     18:     snprintf(buf,MAX_STRING,"%d",n);
                     19:     return buf;
                     20: }
                     21: 
                     22: int main(int argc, char *argv[]) {
1.14      paf        23:        core();
1.15    ! paf        24:        return 0;
1.14      paf        25: 
1.2       paf        26:        Exception fatal_exception;
                     27:        if(EXCEPTION_TRY(fatal_exception)) {
1.4       paf        28:                Pool pool(fatal_exception);
1.2       paf        29:                
                     30:                char *file="file1";
1.5       paf        31:                String& string=*new(pool) String(pool);
1.7       paf        32:                string.APPEND("Hello, ", 0,file, 1);
                     33:                string.APPEND("w", 0,file, 2);
                     34:                string.APPEND("o", 0,file, 3);
                     35:                string.APPEND("r", 0,file, 4);
                     36:                string.APPEND("l", 0,file, 5);
                     37:                string.APPEND("d", 0,file, 6);
                     38:                string.APPEND("!\n ", 0,file, 7);
1.2       paf        39:                printf(string.cstr());
                     40:                
                     41:                char *key1_file="key1_file";
1.10      paf        42:                Hash& hash=*new(pool) Hash(pool);
1.2       paf        43:                String key1=string;
1.7       paf        44:                key1.APPEND("1", 0,key1_file, 1);
1.5       paf        45:                String& value1=*new(pool) String(pool);
1.7       paf        46:                value1.APPEND("i'm value1\n", 0,file, 1);
1.5       paf        47:                String& value2=*new(pool) String(pool);
1.7       paf        48:                value2.APPEND("i'm value2\n", 0,file, 1);
1.2       paf        49:                hash.put(key1, &value1);
                     50:                char *key2_file="key2_file";
                     51:                String key2=string;
1.7       paf        52:                key2.APPEND("2", 0,key2_file, 1);
1.2       paf        53:                hash.put(key2, &value2);
                     54:                String *found_value=(String*)hash.get(key2);
                     55:                printf(found_value?found_value->cstr():"not found\n");
                     56:                
1.7       paf        57:                String& a=*new(pool) String(pool);      a.APPEND("fi", 0,file, 1); a.APPEND("rst", 0,file, 2);
                     58:                String& b=*new(pool) String(pool);      b.APPEND("fir", 0,file, 1); b.APPEND("st", 0,file, 2);
1.2       paf        59:                printf(a==b?"eq\n":"ne\n");
                     60:                
                     61:                
1.5       paf        62:                Array& array=*new(pool) Array(pool, 2);
1.2       paf        63:                array+="first";
                     64:                array+="second";
                     65:                array+="third";
                     66:                printf("%s-%s-%s\n", 
1.1       paf        67:                        array.get_cstr(0), 
                     68:                        array.get_cstr(1),
                     69:                        array.get_cstr(2));
1.2       paf        70:                
1.5       paf        71:                Array& a1=*new(pool) Array(pool);
1.2       paf        72:                a1+="first";
1.5       paf        73:                Array& a2=*new(pool) Array(pool);
1.2       paf        74:                a2+="second";
1.5       paf        75:                Array& asum=*new(pool) Array(pool);
1.2       paf        76:                asum.append_array(a1);
                     77:                asum.append_array(a2);
                     78:                printf("%s-%s\n", 
1.1       paf        79:                        asum.get_cstr(0), 
                     80:                        asum.get_cstr(1));
                     81: 
1.4       paf        82:                Pool request_pool(fatal_exception);
1.2       paf        83:                Request request(request_pool);
                     84: 
                     85:                Exception operator_exception;
                     86:                Local_request_exception subst(request, operator_exception);
                     87:                if(EXCEPTION_TRY(request.exception())) {
1.3       paf        88:                        /*
1.2       paf        89:                        Array acolumns(request.pool());
1.1       paf        90:                        acolumns+="id";
                     91:                        acolumns+="name";
                     92:                        acolumns+="age";
1.3       paf        93:                        Table table(request, "_file.cfg", 1, &acolumns);
                     94:                        */
                     95:                        Table table(request, "_file.cfg", 1, 0);
1.1       paf        96:                        for(int n=1; n<=5; n++) {
1.5       paf        97:                                Array& row=*new(request.pool()) Array(request.pool(), 3/*table.columns()->size()*/);
1.2       paf        98:                                char *buf=static_cast<char *>(request.pool().malloc(MAX_STRING));
1.1       paf        99:                                row+=itoa(n, buf);
                    100:                                row+="paf";
                    101:                                row+="99";
                    102:                                
1.3       paf       103:                                table+=&row;
1.1       paf       104:                        }
1.3       paf       105:                        /*
                    106:                        for(int i=0; i<table.columns()->size(); i++) 
                    107:                                printf("%s\t", table.columns()->get_cstr(i));
1.1       paf       108:                        printf("\n");
1.3       paf       109:                        */
                    110:                        for(table.set_current(0); table.get_current()<table.size(); table.inc_current()) {
1.2       paf       111:                                String line(request.pool());
1.3       paf       112:                                for(int i=0; i<5/*table.columns()->size()*/; i++) {
                    113:                                        /**/
                    114:                                        String name(request.pool());
                    115:                                        char *buf=static_cast<char *>(request.pool().malloc(MAX_STRING));
1.7       paf       116:                                        name.APPEND(itoa(i, buf), 0,"names file", 0);
1.1       paf       117:                                        //name.APPEND("id", "names file", 0);
1.3       paf       118:                                        table.read_item(line, name);
                    119:                                        /*
                    120:                                        const char *cstr_name=table.columns()->get_cstr(i);
1.2       paf       121:                                        String name(request.pool());
1.1       paf       122:                                        name.APPEND(cstr_name, 0, 0);
1.3       paf       123:                                        table.read_item(line, name);
                    124:                                        /**/
1.7       paf       125:                                        line.APPEND("\t", 0,0, 0);
1.1       paf       126:                                }
                    127:                                printf("%s\n", line.cstr());
                    128:                        }
1.6       paf       129: 
1.7       paf       130: /*
1.6       paf       131:                        String it(request.pool());
                    132:                        it.APPEND("ab.cd[zzz]", 0,0);
                    133:                        String_iterator si(it);
1.7       paf       134:                        / *si++;
1.6       paf       135:                        si++;
                    136:                        si++;
                    137:                        si++;
                    138:                        si++;
                    139:                        si++;
1.7       paf       140:                        * /
                    141:                        / *bool found=si.skip_to('.');
1.6       paf       142:                        si++;
1.7       paf       143:                        * /
1.6       paf       144:                        si++;
                    145:                        Char_types types;
                    146:                        types.set(' ', 1);
                    147:                        types.set('[', 2);
                    148:                        types.set(']', 3);
                    149:                        int type=si.skip_to(types);
                    150:                        si++;
1.7       paf       151: */
1.1       paf       152:                } else {
1.2       paf       153:                        Exception& e=request.exception();
1.3       paf       154:                        printf("operator_error occured: %s\n", e.comment());
1.2       paf       155:                        const String *type=e.type();
                    156:                        if(type) {
                    157:                                printf("  type: %s", type->cstr());
                    158:                                const String *code=e.code();
                    159:                                if(code)
                    160:                                        printf(", code: %s", code->cstr());
                    161:                                printf("\n");
                    162:                        }
                    163:                        const String *problem_source=e.problem_source();
1.1       paf       164:                        if(problem_source) {
                    165:                                const Origin& origin=problem_source->origin();
1.12      paf       166:                                printf("  '%s'\n", 
                    167:                                        problem_source->cstr());
                    168:                                if(origin.file)
                    169:                                        printf(" [%s:%d]",
                    170:                                                origin.file, origin.line);
                    171:                                printf("\n");
1.1       paf       172:                        }
                    173:                }
                    174:        } else {
1.2       paf       175:                printf("fatal exception occured: %s\n", fatal_exception.comment());
1.1       paf       176:        }
                    177: 
                    178:        return 0;
                    179: }

E-mail: