|
From: Seth D. <set...@us...> - 2006-01-25 00:39:12
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10988 Modified Files: oplangtext.c Log Message: Lots of little changes in oplangtextvisit to correct problems with round-trip issues. Converting an outline script to text and then re-inserting that text into a new script outline would result in corruption of comments and structure. I apologize to all future generations of kernel hackers for the condition of oplangtextvisit()! It was ugly -- really ugly -- when I found it. Now it's even uglier and more spaghetti-like, as if a circus freak mated with a bowl of pasta and produced one ugly function. Ok, ok, that's enough of a checkin note. Index: oplangtext.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/oplangtext.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** oplangtext.c 11 Jan 2005 22:48:09 -0000 1.4 --- oplangtext.c 25 Jan 2006 00:39:02 -0000 1.5 *************** *** 41,46 **** static short langtextlastlevel; /*globals used for visit routines*/ - //static Handle hlangtext; - static boolean flfirstlangtextline; --- 41,44 ---- *************** *** 62,66 **** if (len > 0 && (*bs) [len - 1] == '\\') { - //setstringlength (bs, len - 1); popfromhandle (bs, 1, nil); --- 60,63 ---- *************** *** 96,99 **** --- 93,117 ---- } /*poptrailingwhitespacehandle*/ + static boolean remainingsubheadsarecomments (hdlheadrecord hnode) { + + /* + are all of the remaining subheads (at the current level) comments? + */ + + hdlheadrecord nomad = hnode; + + if (!(**nomad).flcomment) + return false; + + while (opnavigate (down, &nomad)) { + + if (!(**nomad).flcomment) + return false; + + } + + return true; + } /*remainingsubheadsarecomments*/ + static boolean oplangtextvisit (hdlheadrecord hnode, ptrvoid refcon) { *************** *** 130,138 **** 6.0a13 dmb: rewrote to use handles, handlestreams */ ! register hdlheadrecord h = hnode; handlestream *langtext = (handlestream *) refcon; ! register short level; bigstring bs; Handle bshead; --- 148,161 ---- 6.0a13 dmb: rewrote to use handles, handlestreams + + 2006-01-23 smd: lots of changes when flmakepretty is true, + to fix problems with round trip between script outline and text. + This function is in desperate need of a rewrite, but it seem to work now + for every test case I could come up with. */ ! hdlheadrecord h = hnode; handlestream *langtext = (handlestream *) refcon; ! short level; bigstring bs; Handle bshead; *************** *** 140,143 **** --- 163,167 ---- boolean fltobecontinued = false; boolean flcomment; + boolean flparentwascomment = false; hdlheadrecord nomad; bigstring bsfirst; *************** *** 152,164 **** if (flcomment) { /*just generate a blank line for a comment line*/ ! bshead = nil; //setemptystring (bshead); if (flmakeitpretty) { - //opgetheadstring (h, bshead); if (!copyhandle ((**h).headstring, &bshead)) goto exit; - //insertchar (chcomment, bshead); ch = chcomment; --- 176,186 ---- if (flcomment) { /*just generate a blank line for a comment line*/ ! bshead = nil; if (flmakeitpretty) { if (!copyhandle ((**h).headstring, &bshead)) goto exit; ch = chcomment; *************** *** 166,176 **** goto exit; - //setemptystring (bscomment); } nomad = h; ! if (opnavigate (left, &nomad) && opnestedincomment (nomad)) goto L2; if (level > langtextlastlevel) { --- 188,205 ---- goto exit; } nomad = h; ! if (opnavigate (left, &nomad) && opnestedincomment (nomad)) { ! ! if (!copyhandle (bshead, &bscomment)) ! goto exit; ! ! flparentwascomment = true; ! goto L2; + + } if (level > langtextlastlevel) { *************** *** 192,196 **** else { - //getheadstring (h, bshead); if (!copyhandle ((**h).headstring, &bshead)) goto exit; --- 221,224 ---- *************** *** 205,209 **** len2 = langcommentdelete (chcomment, *bshead, len1); ! if (len2 >= 0) { //comment detected if (flmakeitpretty) { /*for exporting, we want to *add* comment character*/ --- 233,237 ---- len2 = langcommentdelete (chcomment, *bshead, len1); ! if (len2 >= 0) { /* line is partly a comment */ if (flmakeitpretty) { /*for exporting, we want to *add* comment character*/ *************** *** 243,248 **** setemptystring (bsfirst); ! if (!equalidentifiers (bsfirst, STR_else)) /*never want a semicolon before else*/ ! pushchar (';', bs); } } --- 271,279 ---- setemptystring (bsfirst); ! if (!equalidentifiers (bsfirst, STR_else)) { /*never want a semicolon before else*/ ! ! if (!flmakeitpretty || !flcomment || !remainingsubheadsarecomments (h)) /* no semicolon before the closing braces */ ! pushchar (';', bs); ! } } } *************** *** 258,262 **** L2: ! if (flmakeitpretty) { if (!writehandlestreamhandle (langtext, *plastcomment)) --- 289,293 ---- L2: ! if (flmakeitpretty && !flcomment) { if (!writehandlestreamhandle (langtext, *plastcomment)) *************** *** 265,270 **** disposehandle (*plastcomment); - //copystring (bscomment, plastcomment); *plastcomment = bscomment; } --- 296,301 ---- disposehandle (*plastcomment); *plastcomment = bscomment; + } *************** *** 283,294 **** } ! if (!writehandlestreamstring (langtext, bs)) ! goto exit; } flfirstlangtextline = false; ! if (!writehandlestreamhandle (langtext, bshead)) ! goto exit; if (fltobecontinued) --- 314,358 ---- } ! if (flmakeitpretty && flparentwascomment) { ! ! if (!pushtexthandle (bs, *plastcomment)) ! goto exit; ! ! } ! else if (flmakeitpretty && flcomment) { ! ! if (!inserttextinhandle (bscomment, 0L, bs)) ! goto exit; ! ! } ! else { ! ! if (!writehandlestreamstring (langtext, bs)) ! goto exit; ! ! } } flfirstlangtextline = false; ! if (flmakeitpretty && flcomment) { ! ! if (! *plastcomment) ! ! *plastcomment = bscomment; ! ! else { ! ! if (!pushhandle (bscomment, *plastcomment)) ! goto exit; ! ! } ! } ! ! else { ! ! if (!writehandlestreamhandle (langtext, bshead)) ! goto exit; ! } if (fltobecontinued) *************** *** 350,356 **** setemptystring (bs); - // if (!newgrowinghandle (0, htext)) - // return (false); - *htext = nil; --- 414,417 ---- *************** *** 384,388 **** fllastwascomment = true; - //setemptystring (bslastcomment); bslastcomment = nil; --- 445,448 ---- |