//**************************************************************** // icParse.js (ic_302.txt) // // Copyright (c) 2006 Clifford L. Collins // All rights are Reserved // // Collins Software // 7710 Janak Drive, Houston Texas // //---------------------------------------------------------------- // No distribution/publication/use of this code is permitted //**************************************************************** //================================================================ // isTrue //================================================================ function isTrue(value) { var test; test = value.toLowerCase(); if (test == 'true') return true; if (test == 't') return true; if (test == 'yes') return true; if (test == 'y') return true; return false; } //================================================================ // ic$parser (constructor) //================================================================ function ic$parser(fd) { this.fd = fd; this.topTable = null; this.curTable = null; this.line = 0; this.image = ''; this.c = new ic$copy(); this.copy = new Array(0); this.copy[0] = -1; this.sectionName = ''; this.csvRecord = ''; this.csv = new ic$csv(); // working this.cg2_ = PARSER$cg2_; this.style_ = PARSER$style_; this.define_ = PARSER$define_; this.section_ = PARSER$section_; this.read = PARSER$read; // read and split this.readLine = PARSER$readLine; // physical read a complete statement this.splitSub = PARSER$splitSub; // split A:B:C this.parseField = PARSER$parseField; this.findTable = PARSER$findTable; this.nextSection = PARSER$nextSection; this.readGraphic = PARSER$readGraphic; this.nextValue = PARSER$nextValue; this.makeCsv = PARSER$makeCsv; this.defineCsv = PARSER$defineCsv; this.loadGraphic = PARSER$loadGraphic; while (this.read()) { switch (this.type) { case '*cg2': this.cg2_(); break; case '*style': this.style_(); break; case '*define': this.define_(); break; case '*section': this.section_(); return; break; case '*end-of-file': return; break; } // switch } // while } //================================================================= // PARSER$findTable //================================================================= function PARSER$findTable(name) { var tbl; tbl = this.topTable; while (tbl) { if (tbl.name == name) return tbl tbl = tbl.next; } return null; } //================================================================= // PARSER$nextValue; //================================================================= function PARSER$nextValue() { if (this.pos >= this.tokens.length) return ''; this.pos = this.pos + 1; return this.tokens[this.pos-1]; } //================================================================= // PARSER$defineCsv; //================================================================= function PARSER$defineCsv(otable) { var nc; var ofld; var itable; this.copy = new Array(0); nc = 0; this.copy[0] = -1; if (!otable) return; ofld = otable.topField; itable = this.findTable(this.sectionName); if (! itable) return; while (ofld) { nc = nc + 1; this.copy[nc-1] = itable.indexOf(ofld.name); ofld = ofld.next; } } //================================================================= // PARSER$nextSection; //================================================================= function PARSER$nextSection() { this.sectionName = ''; while (true) { switch (this.type) { case '*section': this.sectionName = trim(this.tokens[1].toLowerCase()); return true; case '*define': this.define_(); break; } if (! this.read()) return false; } } //================================================================= // PARSER$readGraphic; //================================================================= function PARSER$readGraphic() { while (this.read()) { this.gra = null; switch (this.type) { case '*section': this.sectionName = this.tokens[1].toLowerCase(); return null; case '*define': this.define_(); break; default: if (this.loadGraphic(this.type)) return this.gra; } // switch } // while return null; } //================================================================= // PARSER$makeCsv //================================================================= function PARSER$makeCsv(tbl) { this.csv.clear(); for (i = 0; i < this.copy.length; ++i) { text = ''; j = this.copy[i]; if ((j >= 0) && (j < this.tokens.length-1)) text = this.tokens[j+1]; this.csv.add(text); } this.csvRecord = this.csv.data; } //================================================================= // PARSER$loadGraphic //================================================================= function PARSER$loadGraphic(tag) { tbl = this.topTable; var i; this.gra = null; while (tbl) { if (tbl.tag == tag) { if (tbl.makeGraphic) { tbl.makeGraphic(this); if (this.gra) return true; return false; } if (tbl.name == this.sectionName) { this.makeCsv(tbl); return false; } } tbl = tbl.next; } return false; } //================================================================= // PARSER$cg2_ //================================================================= function PARSER$cg2_() { } //================================================================= // PARSER$style_ //================================================================= function PARSER$style_() { } //================================================================= // ic$copy (constructor) //================================================================= function ic$copy() { this.clear = COPY$clear; this.DCLine = COPY$DCLine; this.DCSymbol = COPY$DCSymbol; this.DCText = COPY$DCText; this.DCShape = COPY$DCShape; this.DCImage = COPY$DCImage; this.GRAcommon = COPY$GRAcommon; } //================================================================= // COPY$GRAcommon //================================================================= function COPY$GRAcommon(gra) { gra.id = this.id; gra.link = this.link; gra.tag = this.tag; } //================================================================= // COPY$DCLine //================================================================= function COPY$DCLine(dc) { dc.lineColor = this.color; dc.lineFillcolor = this.fillcolor; dc.lineFill = this.fill; dc.lineWidth = this.linewidth; dc.lineDashStyle = this.dashstyle; dc.lineStyle = this.style; dc.lineJoin = this.join; dc.lineTransparent = this.transparent; dc.lineFillTransparent = this.filltransparent; dc.lineGradient = this.gradient; dc.lineShadow = this.shadow; dc.z = this.z; } //================================================================= // COPY$DCSymbol //================================================================= function COPY$DCSymbol(dc) { dc.symbolColor = this.color; dc.symbolFillcolor = this.fillcolor; dc.symbolFill = this.fill; dc.symbolName = this.name; dc.symbolSize = this.size; dc.symbolFillTransparent = this.filltransparent; dc.z = this.z; } //================================================================= // COPY$DCText //================================================================= function COPY$DCText(dc) { dc.textColor = this.color; dc.textBgcolor = this.bgcolor; dc.textFill = this.fill; dc.textFont = this.font; dc.textSize = this.size; dc.textBold = this.bold; dc.textItalic = this.italic; dc.textUnderline = this.underline; dc.textText = this.text; dc.textLineWidth = this.linewidth; dc.textFixedSize = this.fixedsize; dc.z = this.z; } //================================================================= // COPY$DCShape //================================================================= function COPY$DCShape(dc) { dc.shapeStyle = this.style; dc.textColor = this.color; dc.textBgcolor = this.bgcolor; dc.textFill = this.fill; dc.textFont = this.font; dc.textSize = this.size; dc.textBold = this.bold; dc.textItalic = this.italic; dc.textUnderline = this.underline; dc.textText = this.text; dc.textLineWidth = this.linewidth; dc.textFixedSize = this.fixedsize; dc.z = this.z; } //================================================================= // COPY$DCImage //================================================================= function COPY$DCImage(dc) { dc.imageName = this.imagename; dc.imageFixedSize = this.fixedsize; dc.z = this.z; } //================================================================= // COPY$clear //================================================================= function COPY$clear() { this.color = 'red'; this.x = 0; this.y = 0; this.z = 0; this.np = 0 this.px = new Array(0); this.py = new Array(0); this.xmin = 0; this.ymin = 0; this.xmax = 0; this.ymax = 0; this.height = 0; this.width = 0; this.gid = 0; // Not Used this.id = ''; this.link = ''; this.tag = ''; this.style = 62; this.fillcolor = 'white'; this.dashstyle = 'solid'; this.style = 'solid'; this.join = ''; this.transparent = 30; this.filltransparent = true; this.gradient = false; this.shadow = false; this.xmin = 0; this.ymin = 0; this.xmax = 0; this.ymax = 0; this.radius = 0; this.start = 0; this.sweep = 0; this.angle = 0; this.fill = true; this.bgcolor = 'white'; this.linewidth = '1'; this.fixedsize = false; this.font = 'arial'; this.size = '10'; this.text = ''; this.bold = false; this.italic = false; this.underline = false; this.name = ''; this.imagename = ''; } //================================================================= // FIELD$put_xy //================================================================= function FIELD$put_xy(p) { var text; var sub; text = p.nextValue(); sub = p.splitSub(text); p.c.x = parseFloat(sub[0]); p.c.y = parseFloat(sub[1]); } //================================================================= // FIELD$put_range //================================================================= function FIELD$put_range(p) { var text; var sub; var n; text = p.nextValue(); sub = p.splitSub(text); n = sub.length; if (n > 0) p.c.xmin = parseFloat(sub[0]); if (n > 1) p.c.ymin = parseFloat(sub[1]); if (n > 2) p.c.xmax = parseFloat(sub[2]); if (n > 3) p.c.ymax = parseFloat(sub[3]); } //================================================================= // FIELD$put_fixed //================================================================= function FIELD$put_fixed(p) { var text; var sub; var n; text = p.nextValue(); sub = p.splitSub(text); n = sub.length; p.c.fixed = false; p.c.height = 0; p.c.width = 0; if (n > 0) p.c.fixed = isTrue(sub[0]); if (n > 1) p.c.height = parseInt(sub[1]); if (n > 2) p.c.width = parseInt(sub[2]); } //================================================================= // FIELD$put_xy_list //================================================================= function FIELD$put_xy_list(p) { var text; p.c.np = p.nextValue(); for (i = 0; i < p.c.np; ++i) { text = p.nextValue(); sub = p.splitSub(text); if (sub.length < 2) sub[1] = 0; p.c.px[i] = parseFloat(sub[0]); p.c.py[i] = parseFloat(sub[1]); } } //================================================================= // FIELD$put_fillcolor //================================================================= function FIELD$put_gid(p) { p.c.gid = parseInt(p.nextValue()); } function FIELD$put_id(p) { p.c.id = p.nextValue(); } function FIELD$put_link(p) { p.c.link = p.nextValue(); } function FIELD$put_tag(p) { p.c.tag = p.nextValue(); } function FIELD$put_color(p) { p.c.color = p.nextValue(); } function FIELD$put_x(p) { p.c.x = parseFloat(p.nextValue()); } function FIELD$put_y(p) { p.c.y = parseFloat(p.nextValue()); } function FIELD$put_z(p) { p.c.z = parseInt(p.nextValue()); } function FIELD$put_fillcolor(p) { p.c.fillcolor = p.nextValue(); } function FIELD$put_width(p) { p.c.width = parseInt(p.nextValue()); } function FIELD$put_height(p) { p.c.height = parseInt(p.nextValue()); } function FIELD$put_dashstyle(p) { p.c.dashstyle = p.nextValue(); } function FIELD$put_style(p) { p.c.style = p.nextValue(); } function FIELD$put_join(p) { p.c.join = p.nextValue(); } function FIELD$put_transparent(p) { p.c.transparent = p.nextValue(); } function FIELD$put_filltransparent(p) { p.c.filltransparent = p.nextValue(); } function FIELD$put_gradient(p) { p.c.gradient = isTrue(p.nextValue()); } function FIELD$put_shadow(p) { p.c.shadow = isTrue(p.nextValue()); } function FIELD$put_xmin(p) { p.c.xmin = parseFloat(p.nextValue()); } function FIELD$put_ymin(p) { p.c.ymin = parseFloat(p.nextValue()); } function FIELD$put_xmax(p) { p.c.xmax = parseFloat(p.nextValue()); } function FIELD$put_ymax(p) { p.c.ymax = parseFloat(p.nextValue()); } function FIELD$put_radius(p) { p.c.radius = parseFloat(p.nextValue()); } function FIELD$put_start(p) { p.c.start = radian$(parseFloat(p.nextValue())); } function FIELD$put_sweep(p) { p.c.sweep = radian$(parseFloat(p.nextValue())); } function FIELD$put_angle(p) { p.c.angle = radian$(parseFloat(p.nextValue())); } function FIELD$put_fill(p) { p.c.fill = isTrue(p.nextValue()); } function FIELD$put_bgcolor(p) { p.c.bgcolor = p.nextValue(); } function FIELD$put_linewidth(p) { p.c.linewidth = parseInt(p.nextValue()); } function FIELD$put_style(p) { p.c.style = parseInt(p.nextValue()); } function FIELD$put_font(p) { p.c.font = p.nextValue(); } function FIELD$put_size(p) { p.c.size = parseInt(p.nextValue()); } function FIELD$put_text(p) { p.c.text = p.nextValue(); } function FIELD$put_bold(p) { p.c.bold = isTrue(p.nextValue()); } function FIELD$put_italic(p) { p.c.italic = isTrue(p.nextValue()); } function FIELD$put_underline(p) { p.c.underline = isTrue(p.nextValue()); } function FIELD$put_name(p) { p.c.name = p.nextValue(); } function FIELD$put_imagename(p) { p.c.imagename = p.nextValue(); } function FIELD$fake_put(p) { p.c.dummy = p.nextValue(); } //================================================================= // TABLE$line //================================================================= function TABLE$line(p) { this.loadValues(p); p.gra = new ic$Pline(p.c.np,p.c.px,p.c.py); p.c.GRAcommon(p.gra); p.c.DCLine(p.gra.dc); } //================================================================= // TABLE$polygon //================================================================= function TABLE$polygon(p) { this.loadValues(p); p.gra = new ic$Polygon(p.c.np,p.c.px,p.c.py); p.c.GRAcommon(p.gra); p.c.DCLine(p.gra.dc); } //================================================================= // TABLE$arc //================================================================= function TABLE$arc(p) { this.loadValues(p); p.gra = new ic$Arc(p.c.x, p.c.y, p.c.radius, p.c.start, p.c.sweep); p.c.GRAcommon(p.gra); p.c.DCLine(p.gra.dc); } //================================================================= // TABLE$circle //================================================================= function TABLE$circle(p) { this.loadValues(p); p.gra = new ic$Circle(p.c.x, p.c.y, p.c.radius); p.c.GRAcommon(p.gra); p.c.DCLine(p.gra.dc); } //================================================================= // TABLE$symbol //================================================================= function TABLE$symbol(p) { this.loadValues(p); p.gra = new ic$Symbol(p.c.x, p.c.y, p.c.angle); p.c.GRAcommon(p.gra); p.c.DCSymbol(p.gra.dc); fit$symbol(p.gra); } //================================================================= // TABLE$text //================================================================= function TABLE$text(p) { this.loadValues(p); p.gra = new ic$Text(p.c.x, p.c.y, p.c.angle); p.c.GRAcommon(p.gra); p.c.DCText(p.gra.dc); fit$text(p.gra); } //================================================================= // TABLE$textbox //================================================================= function TABLE$textbox(p) { var xmin,ymin,xmax,ymax,height,width; this.loadValues(p); xmin = parseFloat(p.c.xmin); ymin = parseFloat(p.c.ymin); xmax = parseFloat(p.c.xmax); ymax = parseFloat(p.c.ymax); height = parseInt(p.c.height); width = parseInt(p.c.width); p.gra = new ic$Textbox(xmin,ymin,xmax,ymax,height,width); p.c.GRAcommon(p.gra); p.c.DCText(p.gra.dc); } //================================================================= // TABLE$shape //================================================================= function TABLE$shape(p) { var xmin,ymin,xmax,ymax,height,width; this.loadValues(p); xmin = parseFloat(p.c.xmin); ymin = parseFloat(p.c.ymin); xmax = parseFloat(p.c.xmax); ymax = parseFloat(p.c.ymax); height = parseInt(p.c.height); width = parseInt(p.c.width); style = parseInt(p.c.style); p.gra = new ic$Shape(xmin,ymin,xmax,ymax,height,width); p.c.GRAcommon(p.gra); p.c.DCShape(p.gra.dc); } //================================================================= // TABLE$image //================================================================= function TABLE$image(p) { var xmin,ymin,xmax,ymax,height,width; this.loadValues(p); xmin = parseFloat(p.c.xmin); ymin = parseFloat(p.c.ymin); xmax = parseFloat(p.c.xmax); ymax = parseFloat(p.c.ymax); height = parseInt(p.c.height); width = parseInt(p.c.width); style = parseInt(p.c.style); p.gra = new ic$Image(xmin,ymin,xmax,ymax,height,width); p.c.GRAcommon(p.gra); p.c.DCImage(p.gra.dc); } //================================================================= // TABLE$rectangle //================================================================= function TABLE$rectangle(p) { var xmin,ymin,xmax,ymax; this.loadValues(p); xmin = parseFloat(p.c.xmin); ymin = parseFloat(p.c.ymin); xmax = parseFloat(p.c.xmax); ymax = parseFloat(p.c.ymax); p.gra = new ic$Rectangle(xmin,ymin,xmax,ymax); p.c.GRAcommon(p.gra); p.c.DCLine(p.gra.dc); } //================================================================= // TABLE$loadValues //================================================================= function TABLE$loadValues(p) { var fld; var i; p.c.clear(); p.pos = 1; fld = this.topField; while (fld) { fld.put(p); fld = fld.next; } } //================================================================= // PARSER$define_ //================================================================= function PARSER$define_() { var type,tag; var tbl; if (!this.sub[1]) return; type = trim(this.sub[1]).toLowerCase(); tag = trim(this.tokens[1]).toLowerCase(); tbl = new ic$table(this); tbl.name = tag; tbl.tag = tag; tbl.type = type; tbl.loadValues = TABLE$loadValues; tbl.makeGraphic = null; if (type == 'line') tbl.makeGraphic = TABLE$line; if (type == 'polygon') tbl.makeGraphic = TABLE$polygon; if (type == 'arc') tbl.makeGraphic = TABLE$arc; if (type == 'circle') tbl.makeGraphic = TABLE$circle; if (type == 'rectangle') tbl.makeGraphic = TABLE$rectangle; if (type == 'symbol') tbl.makeGraphic = TABLE$symbol; if (type == 'text') tbl.makeGraphic = TABLE$text; if (type == 'textbox') tbl.makeGraphic = TABLE$textbox; if (type == 'shape') tbl.makeGraphic = TABLE$shape; if (type == 'image') tbl.makeGraphic = TABLE$image; if (this.botTable == null) { this.botTable = tbl; this.topTable = tbl; } else { this.botTable.next = tbl; this.botTable = tbl; } for (i = 2; i < this.tokens.length; ++i) { fld = tbl.addField(''); this.parseField(fld,this.tokens[i]); fld.put = FIELD$fake_put; if (tbl.makeGraphic) { switch (fld.name) { case 'gid': fld.put = FIELD$put_gid; break; case 'id': fld.put = FIELD$put_id; break; case 'link': fld.put = FIELD$put_link; break; case 'tag': fld.put = FIELD$put_tag; break; case 'long': fld.put = FIELD$put_x; break; case 'lat': fld.put = FIELD$put_y; break; case 'color': fld.put = FIELD$put_color; break; case 'x': fld.put = FIELD$put_x; break; case 'y': fld.put = FIELD$put_y; break; case 'z': fld.put = FIELD$put_z; break; case 'xy': fld.put = FIELD$put_xy; break; case 'xy_list': fld.put = FIELD$put_xy_list; break; case 'fillcolor': fld.put = FIELD$put_fillcolor; break; case 'width': fld.put = FIELD$put_width; break; case 'height': fld.put = FIELD$put_height; break; case 'dashstyle': fld.put = FIELD$put_dashstyle; break; case 'style': fld.put = FIELD$put_style; break; case 'join': fld.put = FIELD$put_join; break; case 'transparent': fld.put = FIELD$put_transparent; break; case 'filltransparent': fld.put = FIELD$put_filltransparent; break; case 'gradient': fld.put = FIELD$put_gradient; break; case 'shadow': fld.put = FIELD$put_shadow; break; case 'xmin': fld.put = FIELD$put_xmin; break; case 'ymin': fld.put = FIELD$put_ymin; break; case 'xmax': fld.put = FIELD$put_xmax; break; case 'ymax': fld.put = FIELD$put_ymax; break; case 'range': fld.put = FIELD$put_range; break; case 'fixed': fld.put = FIELD$put_fixed; break; case 'radius': fld.put = FIELD$put_radius; break; case 'start': fld.put = FIELD$put_start; break; case 'sweep': fld.put = FIELD$put_sweep; break; case 'angle': fld.put = FIELD$put_angle; break; case 'fill': fld.put = FIELD$put_fill; break; case 'bgcolor': fld.put = FIELD$put_bgcolor; break; case 'linewidth': fld.put = FIELD$put_linewidth; break; case 'style': fld.put = FIELD$put_style; break; case 'fixedsize': fld.put = FIELD$put_fixedsize; break; case 'font': fld.put = FIELD$put_font; break; case 'size': fld.put = FIELD$put_size; break; case 'text': fld.put = FIELD$put_text; break; case 'bold': fld.put = FIELD$put_bold; break; case 'italic': fld.put = FIELD$put_italic; break; case 'underline': fld.put = FIELD$put_underline; break; case 'name': fld.put = FIELD$put_name; break; case 'imagename': fld.put = FIELD$put_imagename; break; } } } } //================================================================= // PARSER$parseField //================================================================= function PARSER$parseField(fld,text) { var list; var list2; list = this.splitSub(text); name = trim(list[0]).toLowerCase(); list2 = name.split("("); fld.name = list2[0]; } //================================================================= // PARSER$section_ //================================================================= function PARSER$section_() { } //================================================================= // PARSER$read //================================================================= function PARSER$read() { this.image = ''; this.type = ''; this.sub = ''; if (! this.readLine()) return false; this.tokens = this.csv.split(this.image); this.sub = this.splitSub(this.tokens[0]); this.type = trim(this.sub[0].toLowerCase()); return true; } //================================================================= // PARSER$splitSub //================================================================= function PARSER$splitSub(text) { var nl,list; var i,a; list = new Array(0); nl = 0; list[0] = ''; while (true) { i = text.indexOf(':'); if (i < 0) { nl = nl + 1; list[nl-1] = trim(text); return list; } a = text.substr(0,i); nl = nl + 1 list[nl-1] = trim(a); text = text.substr(i+1); } } //================================================================= // PARSER$readLine //================================================================= function PARSER$readLine() { this.image = ''; try { while (true) { this.text = this.fd.read(); this.text = trimComment(this.text); if (this.text == '') continue; if (this.text.substr(this.text.length-1) == ';') { this.text = this.text.substr(0,this.text.length-1); this.image = this.image + this.text; return true; } this.image = this.image + this.text; } } catch (e) { if (this.image != '') return true; } }