Davide Santachiara writes:

> A couple of days ago my friend (80 years old) Adelchi Moscardini came to 
> my
> place asking for help concerning a simple sorting procedure. He has a file
> containing the name of around 5000 people which he has to sort in 
> ascendent
> order. However he discovered that:
>
> "de angelis"
>
> came after
>
> "degola"
>
> Which is not correct. So I made some tests and I discovered that the 
> problem
> seems due to a Minerva bug. In fact if you try
>
> PRINT "de angelis">"degola"
>
> You get 0 on SMSQ/E (correct) and 1 on Minerva (1.97).
>
> My question is whether there is a smart way to overcome this problem 
> without
> having to convert the program for SMSQ/E.

It may not necessarily be a bug, but it appears not to be what is wanted in 
this case. One workaround is to write your own comparison routine that does 
what you want. Below is an example, written in Basic. It is a simplistic 
translation of an assembler routine I wrote many yeas ago. Not tested very 
thoroughly, so better beware if it is to be used in production.

It doesnt reproduce well in email, but it should be possible to cut and 
paste it into a PC editor, such as Notepad and save it to disk. Just 
remember to remove the carriage returns at the end of the lines. If you have 
QPC2, youll know what to do. Whatever you do, dont re-type it!!

The relevant InitXX only needs to be called once to prime the GLOBal 
variable str$, thus:

    InitCI: REMark Initialise Case Independent comparison

Then for each comparison in the loop use:

    IF GT(string1$, string2$) THEN
        do whatever has to be done if string1 > string2
    ELSE
        do whatever has to be done if string1 <= string2
    END IF

5000 names could take a while to sort using a Basic routine...

Per
-------------------------------------------------------------------------------------
1 InitCI
2 test#2, 'Case Independent'
3 :
4 InitCD
5 test#1, 'Case Dependent'
6 :
10 DEFine PROCedure test(ch, txt$)
11 RESTORE
12 CLS#ch: PRINT#ch; txt$
13 REPeat loop
14  READ x$, y$: IF x$ = '' AND y$ = '': EXIT loop
15  PRINT#ch; x$! '>'! y$; '?', GT(x$, y$)
16 END REPeat loop
17 END DEFine test
18 :
19 DATA "abc", "ABC"
20 DATA "abc", "abc"
21 DATA "ABC", "abc"
22 DATA "xBC", "abc"
23 DATA "S?,", "ª¦¢"
24 DATA  "¨>?", "Cun"
25 DATA "de angelis", "degola"
26 DATA "degola", "de angelis"
27 DATA '', ''
28 :
100 DEFine PROCedure InitCI
110 REMark Case Independent
120 str$ = FILL$(" ", 33)
130 :
140 str$ = str$ &  '!"' & "#$%&'()*+,-./0123456789:;<=>?@"
150 str$ = str$ & "abcdefghijklmnopqrstuvwxyz[\]^_`"
160 str$ = str$ & "abcdefghijklmnopqrstuvwxyz{|}~"
170 str$ = str$ & "?,f".??^?S<OZ''"".--~Ts>ozY"
180 str$ = str$ & "?,f".??^?S<¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"
190 str$ = str$ & FILL$(" ", 256 - LEN(str$))
200 END DEFine
210 :
220 DEFine PROCedure InitCD
230 REMark Case Dependent
240 str$ = FILL$(" ", 33)
250 :
260 str$ = str$ &  '!"' & "#$%&'()*+,-./0123456789:;<=>?@"
270 str$ = str$ & "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`"
280 str$ = str$ & "abcdefghijklmnopqrstuvwxyz{|}~"
290 str$ = str$ & "?,f".??^?S<OZ''"".--~Ts>ozY"
300 str$ = str$ & " ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"
310 str$ = str$ & FILL$(" ", 256 - LEN(str$))
320 END DEFine
330 :
340 DEFine PROCedure InitAI
350 REMark Accent Independent
360 REMark (Adjust according to country convention)
370 str$ = FILL$(" ", 33)
380 :
390 str$ = str$ &  '!"' & "#$%&'()*+,-./0123456789:;<=>?@"
400 str$ = str$ & "abcdefghijklmnopqrstuvwxyz[\]^_`"
410 str$ = str$ & "abcdefghijklmnopqrstuvwxyz{|}~"
420 str$ = str$ & "?a,e"o??cnSaaaaeeeiiiiooouuuozY"
430 str$ = str$ & "?a,e"o??cnSa¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"
440 str$ = str$ & FILL$(" ", 256 - LEN(str$))
450 END DEFine
460 :
500 DEFine FuNction GT(a$, b$)
510 LOCal i%, l%, d%
520 IF LEN(a$) < LEN(b$): l% = LEN(a$): ELSE : l% = LEN(b$)
530 d% = 0
540 FOR i% = 1 TO l%
550  IF str$(CODE(a$(i%)) + 1) <> str$(CODE(b$(i%)) + 1): d% = i%: EXIT i%
560 END FOR i%
570 IF d% > 0 THEN
580  IF str$(CODE(a$(i%)) + 1) > str$(CODE(b$(i%)) + 1): RETurn d%: ELSE : 
RETurn 0
590 ELSE
600  IF LEN(a$) > LEN(b$): RETurn l% + 1
610 END IF
620 RETurn 0
630 END DEFine
640 :
_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to