File: cell.cc

package info (click to toggle)
abacus 0.9.13-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 6,308 kB
  • ctags: 5,121
  • sloc: ansic: 27,541; cpp: 11,425; tcl: 7,564; makefile: 386; yacc: 327; lex: 265; sh: 221
file content (999 lines) | stat: -rw-r--r-- 24,540 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
//
// $Id: cell.cc,v 1.44 1998/10/20 11:49:23 cthulhu Exp $
//


#include "cell.hh"
#define DEBUG_FORMULA 1

char Cell::buffer[256];

Cell::Cell() {
    iter = -1;
    tag = 0;
    dirty = 0;
    type = CODE_BLANK;
    value = 0;
    formula = NULL;
    label = NULL;
    has_rectangle = FALSE;
    modified = TRUE;
    item = NULL;
    border_item = NO_ITEM;
    error_code = NO_ERROR;
    wid = 0;
};


Cell::Cell(short c, short r) {
    col = c;
    row = r;
    iter = -1;
    tag = 0;
    dirty = 0;
    type = CODE_BLANK;
    value = 0;
    formula = NULL;
    label = NULL;
    has_rectangle = FALSE;
    modified = TRUE;
    item = NULL;
    border_item = NO_ITEM;
    error_code = NO_ERROR;
    wid = 0;
}

Cell::~Cell() {
    
    delete formula;
    delete label;
}

int Cell::filllevel() {
    return (format.bg.filllevel);
}

void Cell::set(char *sti,Parser &p) {
    int i;
    int code;

    if (sti[0] != 0) {
        p.cell = this;
        formula = new Formula();/* AML : to be changed */
        
        code = p.parse(sti,col,row);
    } else {
        code = CODE_BLANK;
    }
        
    type = code;
    switch(code) {
      case CODE_BLANK:
        break;
      case CODE_FORMULA:
        break;
      case CODE_NUMBER:
        value = p.number;
        delete formula;/* AML : to be changed */
        formula = NULL;
        break;
      case CODE_INTEGER:
        ivalue = p.integ;
        delete formula;/* AML : to be changed */
        formula = NULL;
        break;
      case CODE_LABEL:
        label = strsave(sti);
        type = CODE_LABEL;
        delete formula; /* AML : to be changed */
        formula = NULL;
        break;
      case PARSE_ERROR:
        label = new char[strlen(sti)+2];
        if (sti[0] == '\'')
          sprintf(label,"%s",sti);
        else 
          sprintf(label,"'%s",sti);
        type = CODE_LABEL;
        delete formula; /* AML : to be changed */
        formula = NULL;
        break;
    }
    modified = TRUE;
}

void Cell::operator=(const Cell &right) 
{
  type = right.type;
  label = strsave(right.label);
  format = right.format;
  if (right.formula != NULL)
    formula = new Formula(*right.formula);
  value = right.value;
  ivalue = right.ivalue;
  dirty = FALSE;      
  iter = -1;
  /* Row and column are not copied */
}

void Cell::loadvalue(const Cell &right)
{
  type = right.type;
  label = strsave(right.label);
  format = right.format;
  if (right.formula != NULL)
    formula = new Formula(*right.formula);
  value = right.value;
  ivalue = right.ivalue;
  dirty = FALSE;      
  iter = -1;
  /* Row and column are not copied */
}

char *Cell::display() {

    switch(error_code) {
      case NO_ERROR:
        break;
      case ERROR_DIV_BY_0:
        strcpy(buffer,ERROR_DIV_BY_0_STRING);
        return(buffer);
      case ERROR_BAD_VALUE:
        strcpy(buffer,ERROR_BAD_VALUE_STRING);
        return(buffer);
      case ERROR_BAD_REF:
        strcpy(buffer,ERROR_BAD_REF_STRING);
        return(buffer);
      default:
        internal_error();
    }
        

    switch(type) {
      case CODE_INTEGER:
        print_formatted(FORM_INT);
        return(buffer);
      case CODE_FORMULA:
        switch(formula->typ) {
          default:
          case FORM_FP:
          case FORM_INT:
            print_formatted(formula->typ);
            return(buffer);
            break;
          case FORM_STRING:
            sprintf(buffer,"%s",formula->st_value);
            return(buffer);
            break;
        }
        break;
        
      case CODE_NUMBER:
        print_formatted(FORM_FP);
        return(buffer);
      case CODE_BLANK:
        return("");
      case CODE_LABEL:
        return(label+1);
    }

}


Stack_elem *Cell::val() {
    static Stack_elem v;
    
    switch(type) {
      case CODE_BLANK:
      case CODE_LABEL:
      case CODE_FORMULA:
      case CODE_NUMBER:
        v.type = FORM_FP;
        v.contents.fp_val = value;
        break;
      case CODE_INTEGER:
        v.type = FORM_INT;
        v.contents.int_val = ivalue;
        break;
    }
    return(&v);
}

void Cell::setformat(int form) {
  switch(form) {
  case DEFAULT_DATE_FORMAT:
    format.form = form;
    break;
  default:
    internal_error();
  }
}

void Cell::append(void *pt,int type) {
    double *pt_fp,*pt_fp1;
    Ref *pt_ref,*pt_ref1;
    short *pt_int,*pt_int1;
    char *pt_st,*pt_st1;
    Range *pt_rg,*pt_rg1;
    static unsigned short rel_mask =  (1 << 15);
    short r,c;
    int *pa,a; short b;
    Cell *bcell;
    int size;

    char *aux;

    aux = formula->tmp_formula + formula->size;
    
    *aux = (char) type;
    aux++;
    formula->size++;
    

    switch(type) {
      case FORM_FP:
        pt_fp = (double*) aux;
        pt_fp1 = (double*) pt;
        
        /*
         *pt_fp = *pt_fp1; 
         */

        memcpy(pt_fp,pt_fp1,sizeof(double));
        formula->size += FORM_FP_SIZE;
        break;

      case FORM_REF:
        pt_ref = (Ref*) aux;
        pt_ref1 = (Ref*) pt;

        /* Now, change the references in case this is relative */

        if (pt_ref1->col & rel_mask) 
            change_col_to_relative(pt_ref1,col);
        
        if (pt_ref1->row & rel_mask) 
            change_row_to_relative(pt_ref1,row);
        
        /*
         *pt_ref = *pt_ref1;
         */
        
        memcpy(pt_ref,pt_ref1,sizeof(Ref));
               
        formula->size += FORM_REF_SIZE;

        /* Now, insert reference */
        
        break;
        
        
      case FORM_INT:
        pt_int = (short*) aux;
        pa = (int*) pt;
        b = (short) (*pa);
        /*
         *pt_int = *pt_int1;
         */
        memcpy(pt_int,&b,sizeof(short));

        formula->size += FORM_INT_SIZE;
        break;

      case FORM_RANGE:
        pt_rg = (Range*) aux;
        pt_rg1 = (Range*) pt;

        /* Now, change the references in case this is relative */

        if (pt_rg1->start.col & rel_mask) 
            change_col_to_relative(&(pt_rg1->start),col);
        if (pt_rg1->start.row & rel_mask) 
            change_row_to_relative(&(pt_rg1->start),row);

        if (pt_rg1->end.col & rel_mask) 
            change_col_to_relative(&(pt_rg1->end),col);
        if (pt_rg1->end.row & rel_mask) 
            change_row_to_relative(&(pt_rg1->end),row);

        /**pt_rg = *pt_rg1;*/
        memcpy(pt_rg,pt_rg1,sizeof(Range));
        formula->size += FORM_RANGE_SIZE;
        break;

      case FORM_RETURN:
        /* Now save formula in the right place */
        int i;
        formula->formula = new char[formula->size];
        memcpy(formula->formula,formula->tmp_formula,formula->size);
        delete [] formula->tmp_formula;
        formula->tmp_formula = NULL;
        break;
        
      case FORM_PAR:
        break;

      case FORM_STRING:
        pt_st = (char*) pt;
        size = strlen(pt_st)-2;
        memcpy(aux,pt_st+1,size+1);
        aux[size] = 0;
        formula->size += size+1;
        break;
        
      case FORM_UNMINUS:
        internal_error();

      case FORM_PLUS:
      case FORM_SUB:
      case FORM_MULT:
      case FORM_DIV:
      case FORM_POWER:
      case FORM_GREATER:
      case FORM_SMALLER:
      case FORM_EQUAL:
      case FORM_GREATEREQ:
      case FORM_SMALLEREQ:
      case FORM_NEQUAL:
      case FORM_AND:
      case FORM_OR:
      case FORM_NOT:
      case FORM_UNARY_MINUS:
      case FORM_ABS:
      case FORM_INTF:
      case FORM_SQRT:
      case FORM_LOG:
      case FORM_LN:
      case FORM_PI:
      case FORM_SIN:
      case FORM_COS:
      case FORM_TAN:
      case FORM_ATAN2:
      case FORM_ATAN:
      case FORM_ASIN:
      case FORM_ACOS:
      case FORM_EXP:
      case FORM_MOD:
      case FORM_MONTH:
      case FORM_DAY:
      case FORM_HOUR:
      case FORM_MINUTE:
      case FORM_SECOND:
        break;

      case FORM_UPPER:
      case FORM_LOWER:
      case FORM_PROPER:
        break;

      case FORM_SUM:
      case FORM_SUMIF:
      case FORM_AVG:
      case FORM_COUNT:
      case FORM_MAX:
      case FORM_MIN:
      case FORM_IF:
        pt_st = (char *)pt;
        *aux = *pt_st;
        formula->size++;
        break;

      case FORM_ROUND:
      case FORM_VLOOKUP:
      case FORM_HLOOKUP:
        break;

      default:
        internal_error();
    }

}

double Cell::getValueAsDouble()
{
  switch(type)
    {
    case CODE_INTEGER:
      return((double) ivalue);
    case CODE_NUMBER:
      return(value);
    case CODE_FORMULA:
      return(formula->value);
    default:
      internal_error();
      break;
    }
}
void Cell::addDependence(void *dep, int type) {
    int i;
    Cell *pt;

    for (i=0; i<deps.cnt; i++) {
        if (deps[i].cell == dep)
            return;
    }
    deps[i].cell = dep;
    deps[i].type = type;
    deps.cnt++;
     

}

void Cell::removeDependence(void *dep, int type) {
  int i;
  Cell *pt;
  
  for (i=0; i<deps.cnt; i++) {
    if (deps[i].cell == dep)
      if (deps.cnt > 0) {
	deps[i] = deps[deps.cnt-1];
	deps.cnt--;
      }
  }
}

void Cell::changeCellReference(unsigned char *aux ,Oper_info *info,short col2, short row2){
  
  short *pt;

  pt = (short*) aux;

  switch (info->type) {
  case COL_OPERATION:
    /* Orig above, other below, ref is relative */
    if ((col >= info->ref_line && col2 < info->ref_line && ((*pt) & Refmask)))
      (*pt) -= info->n;

    /* Orig below, other above */
    else if ((col < info->ref_line && col2 >= info->ref_line) )
      (*pt) += info->n;
    
    /* other above, ref is absolute */
    else if (col2 >= info->ref_line && !((*pt)&Refmask))
      (*pt) += info->n;
    break;
  case ROW_OPERATION:
    /* Orig above, other below, ref is relative */
    pt++;
    if ((row >= info->ref_line && row2 < info->ref_line && ((*pt) & Refmask)))
      (*pt) -= info->n;

    /* Orig below, other above */
    else if ((row < info->ref_line && row2 >= info->ref_line) )
      (*pt) += info->n;
    
    /* other above, ref is absolute */
    else if (row2 >= info->ref_line && !((*pt)&Refmask))
      (*pt) += info->n;
    break;
  default:
    internal_error();  
  }
  
    
}


void Cell::print_formatted(int val_type) {
  
  int c = format.form;
  double fv;
  char format_string[10];
  time_t  tt;
  struct tm *tm;


  if (val_type == FORM_FP){
    fv = value;
  }
  else {
    fv = ivalue;
  }

  if (fv == 0) fv = 0;
  

  int tp = (c & 0x70) >> 4;
  int dp = (c & 0x0f);

  switch(tp) {
  case 0:
    sprintf(format_string,"%%.%df",dp);
    sprintf(buffer,format_string,fv);
    break;
  case 1:
    sprintf(format_string,"%%.%dE",dp);
    sprintf(buffer,format_string,fv);
    break;
  case 2:    
    sprintf(format_string,"$ %%.%df",dp);
    sprintf(buffer,format_string,fv);
    break;
  case 3:
    sprintf(format_string,"%%.%df %%%%",dp);
    sprintf(buffer,format_string,fv*100);
    break;
  case 4:    
    sprintf(format_string,"%%.%df",dp);
    sprintf(buffer,format_string,fv);
    break;
  case 5:
    sprintf(buffer,"###");
    break;
  case 6:  
    sprintf(buffer,"###");
    break;
  case 7:
    switch(dp) {
    case 0:
      if (fv >= 0) 
        sprintf(buffer,"+");
      else
        sprintf(buffer,"-");
      break;
    case 1:
      sprintf(buffer,"%g",fv);
      break;
    case 2:
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      sprintf(buffer,"%d-%s-%02d",
              tm->tm_mday,month_names[tm->tm_mon],tm->tm_year%100);
      break;
    case 3:
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      sprintf(buffer,"%d-%s",tm->tm_mday,month_names[tm->tm_mon]);
      break;
    case 4:
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      sprintf(buffer,"%s-%02d",month_names[tm->tm_mon],tm->tm_year%100);
      break;
    case 5:
      sprintf(buffer,"Not implemented");
      break;
    case 6:
      sprintf(buffer,"");
      break;
    case 7:
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      sprintf(buffer,"%d-%s-%02d %02d:%02d:%02d",
              tm->tm_mday,month_names[tm->tm_mon],tm->tm_year%100,
              tm->tm_hour,tm->tm_min,tm->tm_sec);
      break;
    case 8:
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      sprintf(buffer,"%d-%s-%02d %02d:%02d",
              tm->tm_mday,month_names[tm->tm_mon],tm->tm_year%100,
              tm->tm_hour,tm->tm_min);
      break;
    case 9:
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      sprintf(buffer,"%d/%d/%d",tm->tm_mon+1,tm->tm_mday,tm->tm_year%100);
      break;
    case 10:
      fv = fv-DAYS_BETWEEN_1970_1900;
      tt = (long)(SECONDS_IN_A_DAY*fv);
      tm = localtime(&tt);
      sprintf(buffer,"%d/%d/%d",tm->tm_mday,tm->tm_mon+1,tm->tm_year%100);
      break;
    case 11:
      sprintf(buffer,"###");
      break;
    case 12:
      sprintf(buffer,"###");
      break;
    case 13:
      sprintf(buffer,"###");
      break;
    case 14:
      sprintf(buffer,"###");
      break;
    case 15:
      sprintf(buffer,"###");
      break;
    }

  }
}

void Cell::mergeformats(Format *fmt)
{
  if(fmt->form!=DEFAULT_FORMAT)
    {
      if(format.form==DEFAULT_FORMAT)
	{
	  format.form=fmt->form;
	  format.timestamp=fmt->timestamp;
	}
      else
	{
	  if(format.timestamp<fmt->timestamp)
	    {
	      format.form=fmt->form;
	      format.timestamp=fmt->timestamp;
	    }
	}
    }
  if(fmt->alignment!=DEFAULT_ALIGNMENT)
    {
      if(format.alignment==DEFAULT_ALIGNMENT)
	{
	  format.alignment=fmt->alignment;
	  format.timestamp=fmt->timestamp;
	}
      else
	{
	  if(format.timestamp<fmt->timestamp)
	    {
	      format.alignment=fmt->alignment;
	      format.timestamp=fmt->timestamp;
	    }
	}
    }
  if(!fmt->font.isdefault())
    {
      if(fmt->font.size!=DEFAULT_FONT_SIZE)
	{
	  if(format.font.size==DEFAULT_FONT_SIZE)
	    {
	      format.font.size=fmt->font.size;
	      format.timestamp=fmt->timestamp;
	    }
	  else
	    {
	      if(format.timestamp<fmt->timestamp)
		{
		  format.font.size=fmt->font.size;
		  format.timestamp=fmt->timestamp;
		}
	    }
	}
      if(fmt->font.italics!=DEFAULT_FONT_ITALICS)
	{
	  if(format.font.italics==DEFAULT_FONT_ITALICS)
	    {
	      format.font.italics=fmt->font.italics;
	      format.timestamp=fmt->timestamp;
	    }
	  else
	    {
	      if(format.timestamp<fmt->timestamp)
		{
		  format.font.italics=fmt->font.italics;
		  format.timestamp=fmt->timestamp;
		}
	    }
	}
      if(fmt->font.bold!=DEFAULT_FONT_BOLD)
	{
	  if(format.font.bold==DEFAULT_FONT_BOLD)
	    {
	      format.font.bold=fmt->font.bold;
	      format.timestamp=fmt->timestamp;
	    }
	  else
	    {
	      if(format.timestamp<fmt->timestamp)
		{
		  format.font.bold=fmt->font.bold;
		  format.timestamp=fmt->timestamp;
		}
	    }
	}
      if(fmt->font.family!=DEFAULT_FONT_FAMILY)
	{
	  if(format.font.family==DEFAULT_FONT_FAMILY)
	    {
	      format.font.family=fmt->font.family;
	      format.timestamp=fmt->timestamp;
	    }
	  else
	    {
	      if(format.timestamp<fmt->timestamp)
		{
		  format.font.family=fmt->font.family;
		  format.timestamp=fmt->timestamp;
		}
	    }
	}
    }
  if(!fmt->borders.isdefault())
    {
      if(fmt->borders.top!=DEFAULT_BORDER)
	{
	  if(format.borders.top==DEFAULT_BORDER)
	    {
	      format.borders.top=fmt->borders.top;
	      format.timestamp=fmt->timestamp;
	    }
	  else
	    {
	      if(format.timestamp<fmt->timestamp)
		{
		  format.borders.top=fmt->borders.top;
		  format.timestamp=fmt->timestamp;
		}
	    }
	}
      if(fmt->borders.bottom!=DEFAULT_BORDER)
	{
	  if(format.borders.bottom==DEFAULT_BORDER)
	    {
	      format.borders.bottom=fmt->borders.bottom;
	      format.timestamp=fmt->timestamp;
	    }
	  else
	    {
	      if(format.timestamp<fmt->timestamp)
		{
		  format.borders.bottom=fmt->borders.bottom;
		  format.timestamp=fmt->timestamp;
		}
	    }
	}
      if(fmt->borders.left!=DEFAULT_BORDER)
	{
	  if(format.borders.left==DEFAULT_BORDER)
	    {
	      format.borders.left=fmt->borders.left;
	      format.timestamp=fmt->timestamp;
	    }
	  else
	    {
	      if(format.timestamp<fmt->timestamp)
		{
		  format.borders.left=fmt->borders.left;
		  format.timestamp=fmt->timestamp;
		}
	    }
	}
      if(fmt->borders.right!=DEFAULT_BORDER)
	{
	  if(format.borders.right==DEFAULT_BORDER)
	    {
	      format.borders.right=fmt->borders.right;
	      format.timestamp=fmt->timestamp;
	    }
	  else
	    {
	      if(format.timestamp<fmt->timestamp)
		{
		  format.borders.right=fmt->borders.right;
		  format.timestamp=fmt->timestamp;
		}
	    }
	}
    }
  if(fmt->bg.filllevel!=DEFAULT_FILL)
    {
      if(format.bg.filllevel==DEFAULT_FILL)
	{
	  format.bg.filllevel=fmt->bg.filllevel;
	  format.timestamp=fmt->timestamp;
	}
      else
	{
	  if(format.timestamp<fmt->timestamp)
	    {
	      format.bg.filllevel=fmt->bg.filllevel;
	      format.timestamp=fmt->timestamp;
	    }
	}
    }
}

//
// $Log: cell.cc,v $
// Revision 1.44  1998/10/20 11:49:23  cthulhu
// Cell destructor was receiving parameters- cut & paste strike again!
//
// Revision 1.43  1998/08/06 21:08:41  aml
// Released alpha version of Abacus.
//
// Revision 1.42  1997/02/10  15:11:05  aml
// Print settings now are saved to file.
// Fixed buggy error message when loading sheets.
//
// Revision 1.41  1997/01/07 01:07:46  aml
// Error propagation for formulas fixed.
// Edit operations in place.
//
// Revision 1.40  1997/01/02  16:15:34  aml
// Fixed unsufficient range of colunm width.
// First cut of vlookup and hlookup functions.
// Fixed bug in display routines.
//
// Revision 1.39  1996/12/31 17:38:41  aml
// On-demand calculation improved. Loops are detected.
// Automatic recalculation can now be disabled.
// Printing was improved.
//
// Revision 1.38  1996/12/11 21:40:03  aml
// Sumif implemented.
// Diverse time functions implemented.
// Fixed needtoscroll2 to avoid out of control scroll.
//
// Revision 1.37  1996/11/22  16:29:19  aml
// First cut at transforming canvas into a true cell widget.
// Text, lines and rectangles are now relative to row and colunm numbers.
// It still has a bug with wrong estimation of column widths.
//
// Revision 1.36  1996/10/07 12:35:37  aml
// First cut at error handling.
// Date formats are in.
// Fixed problem with blank cell drawing.
//
// Revision 1.35  1996/09/19  12:17:04  aml
// Created row and column insert.
// Fixed small problem with display of vergrown cells.
//
// Revision 1.34  1996/09/17 15:16:24  aml
// Fixed problems with copying of cells with non-default formats.
// Created printing formats, alignment formats.
// Format toolbar now reflects format of active cell.
//
// Revision 1.33  1996/09/16 18:42:40  aml
// Some performance problems addressed by reducing tag use.
// Several performance problems remain when heavy use is made
// of borders and shading in large spreadsheets.
//
// Revision 1.32  1996/09/14  23:56:03  aml
// Created cell shading.
//
// Revision 1.31  1996/09/04  14:29:59  aml
// Fixed double redrawing of sheets that was taking place.
// Fixed a item reference problem when the sheet is redrawn.
// Fixed misplacement of row labels.
// Created first version of format toolbar.
//
// Revision 1.30  1996/09/02 10:51:38  aml
// Cell fonts created, loaded and saved.
// Row height created.
//
// Revision 1.29  1996/08/28  17:17:54  aml
// Load and save now accept string_value for formula cells.
// This fixes previous thought problem of formula values not
// being stored.
// Functions upper,lower and proper created.
// Function if can now return labels.
// Fixed problem with function count.
// Reasonably stable version, very used to manipulate notas.wk1.
//
// Revision 1.28  1996/08/27 17:18:55  aml
// First version of regressive tests created.
// Changes were made to allow for string functions.
// String function upper created. Raises the problem
// that formulas do NOT have a space for string values,
// and therefore have to be evaluated upon loading.
//
// Revision 1.27  1996/08/26 17:22:28  aml
// Function round fixed.
// Many other functions added, from power to mod.
//
// Revision 1.26  1996/07/18 10:19:31  aml
// Created formats for cells.
// Load cell now makes copy of old file.
//
// Revision 1.25  1996/04/27 11:37:09  aml
// Started changes for format.
//
// Revision 1.24  1996/04/23 09:43:04  aml
// Data structures for ordered scans of rows and columns are in place.
// Cell overlap is working.
// Forward cell dependences inserted. Automatic recalculation created.
// Uniformizaed label entry procedure.
//
// Revision 1.23  1996/04/21 13:28:13  aml
// Sped up scroll functions, caching keys presses.
// First cut at handling overflowing cells.
// Overflow into ajoining filled cells not solved.
//
// Revision 1.22  1996/03/11  15:47:49  aml
// Made redraw more efficient by removing at once all cells before redrawing.
// Fixed problem with unsufficient difinition of logical expressions.
// Added >=, <=, <>, @and and @or functions.
//
// Revision 1.21  1996/03/08 19:00:34  aml
// Fixed problem in string_single_arg macro
// Created if function, boolean evaluations and so on.
//
// Revision 1.20  1996/03/07 20:33:08  aml
// Created print range ability.
// Set in gray non-working menus.
// Created RangeKill command.
// Created round function and macros for single argument functions.
//
// Revision 1.19  1996/02/19  15:47:38  aml
// Fixed abnormality with mouse click.
// Variable width columns implemented, but not yet saved.
// Labels are now a lex element, fixing some aberrant behavior that existed.
//
// Revision 1.18  1996/02/16 23:09:38  aml
// Improved user interf state machine.
// Centralized range definitions.
// Range defined outiside current view work properly.
//
// Revision 1.17  1996/02/16  18:04:10  aml
// Fixed a memory bug in formula copy with purify.
// Fixed a few minor bugs. Functional, stable version.
//
// Revision 1.16  1996/02/13 12:03:49  aml
// Fixed bug with range definition via mouse.
// Fixed bug in range iterators.
//
// Revision 1.15  1996/01/30  16:05:41  aml
// User interface for cell and range copy created.
// Improved user interface state machine when entering and viewing cells.
// Fixed unaligned accesses during formula parsing and io operations.
//
// Revision 1.14  1996/01/27  23:10:31  aml
// CellCopy created.
// CellGet fixed.
// Tcl range operators created.
// User interface improved. Cell references and ranges
// can now be defined with the mouse.
//
// Revision 1.13  1996/01/11  22:48:52  aml
// Range iterators created.
// Functions sum, max and min now work properly.
// Negative numbers now allowed by flex (oops :-)
//
// Revision 1.12  1996/01/10  18:53:44  aml
// Fixed limited integer range of cells.
// Fixed incorrect code in spreadsheet type.
// Users interface improved. Cursors and mouse clicks
// now work in the most basic modes.
//
// Revision 1.11  1996/01/09  18:34:54  aml
// Load, save, open, close and exit now work properly (hopefuly).
// Sheet utility functions also work : SheetExists, SheetEmpty, SheetModified
//
// Revision 1.10  1996/01/07  09:07:43  aml
// Sheet::save and Sheet::load created.
// Program can now write and read wk1 files.
// Slight changes made to relative references. Bit 14 is now always 0.
//
// Revision 1.9  1996/01/05  23:06:00  aml
// Cell references evaluated.
// Spreadsheet is recalculated at every change, by an arbitrary order.
// Reformulated program structure. Evaluation and reverse parsing
// are member functions of Sheet.
//
// Revision 1.8  1996/01/04  20:27:18  aml
// Range references parsed and reverse parsed.
//
// Revision 1.7  1996/01/03  23:07:15  aml
// Absolute and relative references to cells introduced.
// They are parsed and reverse parsed, not yet evaluated.
//
// Revision 1.6  1996/01/02  16:22:11  aml
// Formula compilation, evaluation and decompilation now work.
// Cells can be of type label, numerical formula or numbers.
//
// Revision 1.5  1995/12/30  16:41:47  aml
// First cut of formula compilation.
//
// Revision 1.4  1995/12/28  19:20:39  aml
// Created skeleton to merge calculation engine
//
// Revision 1.3  1995/12/27  23:12:59  aml
// First draft of Sheet::display
//
// Revision 1.2  1995/12/13  14:32:43  aml
// Created Cell, set and val member functions
//
// Revision 1.1  1995/12/06  14:50:19  aml
// Initial revision
//
//