Back to index

texmacs  1.0.7.15
skeleton.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : skeleton.cpp
00004 * DESCRIPTION: Line breaking facility for paragraphs
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "skeleton.hpp"
00013 
00014 bool var_path_inf_eq (path p1, path p2);
00015 
00016 insertion_rep::insertion_rep (tree type2, skeleton sk2):
00017   type (type2), begin (sk2[0]->ins[0]->begin),
00018   end (sk2[0]->ins[0]->end), sk (sk2)
00019 {
00020   int i, n= N(sk);
00021   for (i=0; i<n; i++) {
00022     int j, k= N(sk[i]->ins);
00023     for (j=0; j<k; j++) {
00024       if (var_path_inf_eq (sk[i]->ins[j]->begin, begin))
00025        begin= sk[i]->ins[j]->begin;
00026       if (var_path_inf_eq (end, sk[i]->ins[j]->end))
00027        end= sk[i]->ins[j]->end;
00028     }
00029   }
00030 }
00031 
00032 bool
00033 operator == (insertion ins1, insertion ins2) {
00034   return
00035     (ins1->type  == ins2->type ) &&
00036     (ins1->begin == ins2->begin) &&
00037     (ins1->end   == ins2->end  ) &&
00038     (ins1->sk    == ins2->sk   );
00039 }
00040 
00041 bool
00042 operator != (insertion ins1, insertion ins2) {
00043   return
00044     (ins1->type  != ins2->type ) ||
00045     (ins1->begin != ins2->begin) ||
00046     (ins1->end   != ins2->end  ) ||
00047     (ins1->sk    != ins2->sk   );
00048 }
00049 
00050 bool
00051 operator < (insertion ins1, insertion ins2) {
00052   if (ins1->type != ins2->type) {
00053     if (is_tuple (ins1->type, "footnote")) return false;
00054     if (is_tuple (ins2->type, "footnote")) return true;
00055     if (ins1->type == tuple ("float", "b")) return false;
00056     if (ins2->type == tuple ("float", "b")) return true;
00057     if (ins1->type == tuple ("float", "t")) return true;
00058     if (ins2->type == tuple ("float", "t")) return false;
00059   }
00060   return !var_path_inf_eq (ins2->begin, ins1->begin);
00061 }
00062 
00063 tm_ostream&
00064 operator << (tm_ostream& out, insertion ins) {
00065   if (ins->type != "") out << ins->type << " ";
00066   out << "insertion [ " << ins->begin << " -- " << ins->end;
00067   if (N(ins->sk)>0) out << "; " << ins->sk;
00068   return out << " ]";
00069 }
00070 
00071 bool
00072 operator == (pagelet pg1, pagelet pg2) {
00073   if (is_nil (pg1) || is_nil (pg2)) return is_nil (pg1) == is_nil (pg2);
00074   return (pg1->ins == pg2->ins);
00075 }
00076 
00077 bool
00078 operator != (pagelet pg1, pagelet pg2) {
00079   if (is_nil (pg1) || is_nil (pg2)) return is_nil (pg1) != is_nil (pg2);
00080   return (pg1->ins != pg2->ins);
00081 }
00082 
00083 tm_ostream&
00084 operator << (tm_ostream& out, pagelet pg) {
00085   return out << "pagelet " << pg->ins;
00086 }
00087 
00088 void
00089 sort (pagelet& pg) {
00090   int i, n= N (pg->ins);
00091   while (true) {
00092     bool flag =true;
00093     for (i=0; i<n-1; i++)
00094       if (pg->ins[i+1] < pg->ins[i]) {
00095        insertion tmp= pg->ins[i];
00096        pg->ins[i]= pg->ins[i+1];
00097        pg->ins[i+1]= tmp;
00098        flag= false;
00099       }
00100     if (flag) break;
00101   }
00102 }