Going forward.

With new technology, there is always some challenges going from an old platform to a new one. Years ago, worked in an independent computer store. This was long before ethernet and the networking that makes things so easy to transfer files between systems. One of my customers who was a college professor wanted to transfer data files from his old eight bit Atari computer to the new Atari. Of course, I volunteered to copy the files to the new system.


To copy the files, you had to use what is known as a null modem connection. To make things even more complicated, the way the files were saved were different in that every system had it's own ascii table. For instance, the letter "a" normally would be stored as the number 65. Not all characters were stored as the same numbers between systems. Transferred the files as text between the systems to let the terminal programs do worst of the translation between the systems.


For some files though, all but one character was converted. When I tried to display the files, everything was in one long cast of characters. The paragraphs  should have been broken up with a special character known as a carriage return, When examining the files character by character, found the carriage return was represented by the number 155.  Most systems are now standardized using the number thirteen as the carriage return. Obviously, a conversion had to be made.

So we needed to read in the old file one character at a time and write to the new file one character at a time. As we were reading and writing characters, we would replace the old carriage return character for the new one.
This led to some code that looked like this:

OPEN "battery.doc" FOR INPUT AS #1
OPEN "battery.txt" FOR OUTPUT AS #2

WHILE NOT EOF(1)
    a$ = INPUT$(1, #1)
    IF ASC(a$) = 155 THEN
        PRINT
        PRINT #2, CHR$(13);
    ELSE
        PRINT #2, ASC(a$);
        PRINT a$;
    END IF
WEND
CLOSE #1
CLOSE #2

Just for my own interests, the characters were echoed to the screen to made sure everything was ok. Lot of work, but the files were transferred and converted.

 


Ironically today, we still have that sort of problem between unix systems and dos based systems.

To go from unix to dos systems the code might be:

OPEN "battery.doc" FOR INPUT AS #1
OPEN "battery.txt" FOR OUTPUT AS #2

WHILE NOT EOF(1)
    a$ = INPUT$(1, #1)
    IF ASC(a$) = 13 THEN
        PRINT
        PRINT #2, CHR$(13);chr$(10);
    ELSE
        PRINT #2, a$;
        PRINT a$;
    END IF
WEND
CLOSE #1
CLOSE #2


To go from Dos to unix, the code might be:

OPEN "battery.doc" FOR INPUT AS #1
OPEN "battery.txt" FOR OUTPUT AS #2

OPEN "battery.doc" FOR INPUT AS #1
OPEN "battery.txt" FOR OUTPUT AS #2

WHILE NOT EOF(1)
    a$ = INPUT$(1, #1)
    IF ASC(a$) = 10 THEN
       rem do not print the character to the new file.
       print ;
    ELSE
        PRINT #2, ASC(a$);
        PRINT a$;
    END IF
WEND
CLOSE #1
CLOSE #2

This code may seem unimportant, but  you never know when something simple can get the job done.

Comments

Popular posts from this blog

Guiless?

MSOffice vs Libreoffice

Raspberry pi zero.