issue108:tutoriel1
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue108:tutoriel1 [2016/04/30 18:15] – créée auntiee | issue108:tutoriel1 [2016/05/12 11:57] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | In the early days of computers, a company called Digital Equipment Corporation (DEC) created its 32-bit VAX computer using openVMS as its operating system. Because a VAX/VMS computer is so reliable, there are today - after more than 25 years - still a large number of them in use. But, in the end, even these reliable computers will have to be replaced. As described in part 1, you could migrate from VAX/VMS to Linux, as the way Linux works is largely compatible with VAX/VMS. If you use Pascal as your programming language, you will find that Lazarus/ | + | **In the early days of computers, a company called Digital Equipment Corporation (DEC) created its 32-bit VAX computer using openVMS as its operating system. Because a VAX/VMS computer is so reliable, there are today - after more than 25 years - still a large number of them in use. But, in the end, even these reliable computers will have to be replaced. As described in part 1, you could migrate from VAX/VMS to Linux, as the way Linux works is largely compatible with VAX/VMS. If you use Pascal as your programming language, you will find that Lazarus/ |
- | Mailboxes | + | Au début des ordinateurs, |
+ | |||
+ | **Mailboxes | ||
For IPC (interprocess communication), | For IPC (interprocess communication), | ||
Ligne 7: | Ligne 9: | ||
• To create a mailbox in VMS, you call $CREMBX (handle, logical_name, | • To create a mailbox in VMS, you call $CREMBX (handle, logical_name, | ||
- | In Linux you have to get a key first. In the examples from the documentation, | + | In Linux you have to get a key first. In the examples from the documentation, |
- | Now you can create or link to a mailbox using this key as the identifier to get a handle. So you can use two methods: Either create a dummy file for every mailbox you want to use and always use 0 as the small number, or use, e.g., the folder at the base of the current version of your project (see part 3) to get separate mailboxes for every version and assign a constant (smaller than 256) to every mailbox to get the unique key. Whichever method you use, the created mailbox will be permanent. In Linux there are no temporary mailboxes. So be aware of that when starting a new session; you might get old messages left in the mailboxes from a previous run. | + | Boîtes mail |
- | • Now you are ready to send and receive messages. To send data in VMS, you would fill a buffer with data and make a call to $QIO(W) (see part 2) using the handle of the mailbox you want to put the message into, a pointer to the buffer, and the size of the buffer (plus an eventflag, see part 2). To receive data, you would make the same call to $QIO(W), only the function specifier would be “read” instead of “write”. On return, the buffer will be filled with the received message, and the size parameter will be filled with the size of the received message. | + | Pour l' |
- | To send data in Linux, you would fill a buffer just like in VMS, but there must be an extra integer at the beginning of the buffer. This integer value must be filled with a number not being zero! Then you would call sndmsg() with the handle, | + | • Pour créer une boîte aux lettres dans VMS, vous appelez $CREMBX |
- | Another difference is that, in VMS, you must specify the total size of the mailbox when you create it. In Linux the size is fixed. This might be a problem when using large, or a huge number of, messages. | + | Dans Linux, vous devez d' |
- | The implementation | + | **Now you can create or link to a mailbox using this key as the identifier to get a handle. So you can use two methods: Either create a dummy file for every mailbox you want to use and always use 0 as the small number, or use, e.g., the folder at the base of the current version of your project (see part 3) to get separate mailboxes for every version and assign a constant (smaller than 256) to every mailbox to get the unique key. Whichever method you use, the created mailbox will be permanent. In Linux there are no temporary mailboxes. So be aware of that when starting a new session; you might get old messages left in the mailboxes from a previous run. |
+ | |||
+ | • Now you are ready to send and receive messages. To send data in VMS, you would fill a buffer with data and make a call to $QIO(W) (see part 2) using the handle of the mailbox you want to put the message into, a pointer to the buffer, and the size of the buffer (plus an eventflag, see part 2). To receive data, you would make the same call to $QIO(W), only the function specifier would be “read” instead of “write”. On return, the buffer will be filled with the received message, and the size parameter will be filled with the size of the received message.** | ||
+ | |||
+ | Maintenant, vous pouvez créer un lien vers une boîte aux lettres en utilisant cette clé comme identifiant pour obtenir un handle (indicateur). Vous pouvez utiliser deux méthodes : soit créer un fichier factice pour chaque boîte aux lettres que vous voulez utiliser et toujours utiliser 0 comme plus petit nombre, ou utiliser, par exemple, le dossier à la base de la version courante de votre projet (voir partie 3), pour disposer d'une boîte aux lettres différente pour chaque version et assigner une constante (inférieure à 256) à chaque boîte pour avoir une clé unique. Quelle que soit la méthode utilisée, la boîte aux lettres créée sera permanente. Dans Linux, il n'y a pas de boîte aux lettres temporaire. Aussi, soyez bien conscient de cela quand vous démarrez une nouvelle session ; vous pourriez trouvez de vieux messages datant d'un fonctionnement précédent. | ||
+ | |||
+ | • Maintenant, vous êtes prêt à envoyer et recevoir des messages. Pour envoyer des données dans VMS, vous rempliriez un tampon (buffer) avec des données et feriez appel à $QIO(W) (voir partie 2) en utilisant le handle de la boîte aux lettres dans laquelle vous voulez placer le message, un pointeur vers le buffer, et la taille du buffer (plus un eventflag, voir partie 2). Pour recevoir des données, vous feriez le même appel à $QIO(W), mais l' | ||
+ | |||
+ | **To send data in Linux, you would fill a buffer just like in VMS, but there must be an extra integer at the beginning of the buffer. This integer value must be filled with a number not being zero! Then you would call sndmsg() with the handle, a pointer to the buffer, and the size of the buffer – not counting the extra integer! To receive a message, you would call rcvmsg() with the same parameters plus a message identifier. This message identifier is used to filter the messages sent to you, so you get only the messages with the matching number in the extra integer value. If the message identifier is zero, there will be no filtering. For example: suppose there are five messages sent to you: message A with that extra integer set to 1, B with 2, C with 1 again, D with 3, and E with 2 again. If you start rcvmsg (...., 2), you will get message B first and then message E. Then rcvmsg (..., 3) will retrieve message D, and, eventually, rcvmsg (...., 0) will get the rest: A and C. If rcvmsg (...., 4) is issued, no messages will be returned. The message size, again not counting the extra integer, is returned as the result of the function. | ||
+ | |||
+ | Another difference is that, in VMS, you must specify the total size of the mailbox when you create it. In Linux the size is fixed. This might be a problem when using large, or a huge number of, messages.** | ||
+ | |||
+ | Pour envoyer des données dans Linux, vous rempliriez un buffer comme dans VMS, mais il y a un entier supplémentaire au début du buffer. La valeur de cet entier sera un nombre différent de zéro ! Ensuite, vous appelleriez sndmsg() avec le handle, un pointeur vers le buffer, et la taille du buffer - sans compter l' | ||
+ | |||
+ | Autre différence : dans VMS, vous devez spécifier la taille totale de la boîte aux lettres quand vous la créez. Dans Linux, la taille est fixée. Ceci peut être un problème si vous utilisez des messages très grands ou très nombreux. | ||
+ | |||
+ | **The implementation | ||
In the beginning, I simply replaced every reference to mailboxes with the corresponding Linux calls. I used the specified logical as the name of a dummy file in a dedicated folder to get the unique key. For a small project, this would be acceptable, but this is not the intention of this migration tool. So I created the functions _CREMBX and _QIO(W) to behave the same as in VMS. (A “$” sign is not allowed in names when using Free Pascal, so my conversion program substitutes the “$” by an underscore. The same problem arose when using the terminal, I will discus this in part 5 about DCL). | In the beginning, I simply replaced every reference to mailboxes with the corresponding Linux calls. I used the specified logical as the name of a dummy file in a dedicated folder to get the unique key. For a small project, this would be acceptable, but this is not the intention of this migration tool. So I created the functions _CREMBX and _QIO(W) to behave the same as in VMS. (A “$” sign is not allowed in names when using Free Pascal, so my conversion program substitutes the “$” by an underscore. The same problem arose when using the terminal, I will discus this in part 5 about DCL). | ||
• _CREMBX uses a dedicated logical to point to a file containing info about assigned numbers. This file is also used for creating the unique key. _CREMBX assigns a free number in the range 0-255 if the mailbox does not already exist. The given logical in table LNM_PERMANENT_MAILBOXES is used or created just like VMS would. Then the mailbox is linked to or created using the key, and the handle is returned. | • _CREMBX uses a dedicated logical to point to a file containing info about assigned numbers. This file is also used for creating the unique key. _CREMBX assigns a free number in the range 0-255 if the mailbox does not already exist. The given logical in table LNM_PERMANENT_MAILBOXES is used or created just like VMS would. Then the mailbox is linked to or created using the key, and the handle is returned. | ||
• The _QIO(W) will send or receive depending on the function specifier. It uses a new thread and the specified eventflag to create the asynchronous behavior as in VMS (see part 2). | • The _QIO(W) will send or receive depending on the function specifier. It uses a new thread and the specified eventflag to create the asynchronous behavior as in VMS (see part 2). | ||
- | This way, the only thing you would have to do for the migration is define the above mentioned dedicated logical and add the extra integer in front of the declaration of the buffer. Removing the logical used for a mailbox would cause the creation of a new mailbox upon opening, while the still connected processes would use the old one, exactly like in VMS. | + | This way, the only thing you would have to do for the migration is define the above mentioned dedicated logical and add the extra integer in front of the declaration of the buffer. Removing the logical used for a mailbox would cause the creation of a new mailbox upon opening, while the still connected processes would use the old one, exactly like in VMS.** |
- | File version numbers | + | L' |
+ | |||
+ | Au début, j'ai simplement remplacé chaque référence à une boîte aux lettres par l' | ||
+ | • _CREMBX utilise un logical dédié pour pointer vers un fichier contenant l' | ||
+ | • _QIO(W) recevra ou enverra suivant les paramètres de la fonction. Elle utilise un nouveau fil et l' | ||
+ | |||
+ | De cette façon, la seule chose à faire pour la migration est de définir le logical dédié mentionné plus haut et d' | ||
+ | |||
+ | **File version numbers | ||
This part is about file systems: In the beginning, there was DOS (and CP/M) which used FAT as its file system. File names were 8 characters long with a file type of 3 characters. Later, NTFS (New Technology File System) offered long names and types,and more attributes for better security. They were both using assigned drive letters to identify the device (disk). In Linux, most of the time “Ext” is used as its default file system, currently Ext4. As mentioned in part 3, Linux does not use assigned drive letters, but mounting points. From a functional perspective, | This part is about file systems: In the beginning, there was DOS (and CP/M) which used FAT as its file system. File names were 8 characters long with a file type of 3 characters. Later, NTFS (New Technology File System) offered long names and types,and more attributes for better security. They were both using assigned drive letters to identify the device (disk). In Linux, most of the time “Ext” is used as its default file system, currently Ext4. As mentioned in part 3, Linux does not use assigned drive letters, but mounting points. From a functional perspective, | ||
- | When DEC created ODS-2 (On Disk Structure version 2), it took a different approach. They named all devices (not just disks) with two characters to specify the type, one character starting with A, then B and so on to identify the adapter, plus a serial number. The base folder (directory) on a disk is named [000000] and names and types of files are long like in NTFS and EXT. And they decided that there should be more versions of the same file in the same directory (folder). An example: | + | When DEC created ODS-2 (On Disk Structure version 2), it took a different approach. They named all devices (not just disks) with two characters to specify the type, one character starting with A, then B and so on to identify the adapter, plus a serial number. The base folder (directory) on a disk is named [000000] and names and types of files are long like in NTFS and EXT. And they decided that there should be more versions of the same file in the same directory (folder). An example:** |
- | Suppose I create a text file with an editor and save the file. Besides the name and type that I specify, it will also get a version number, starting with “1”. If I would use the editor to change this file and save it again, the existing file will not be overwritten like in Linux and Windows. The editor creates a new file, with the same name and type, but with a higher version number, “2” in this case. The same happens with log files, executables (programs), and so on. The advantage is that you can see the history of a file and even restore a previous version. For example, if a new version of a program does not work as it should, you can just kill the process and start the previous version, it is still there (unless you deleted it). But of course there is also a down-side: For a thousand | + | Numéros de versions |
- | If your project is depending on this behavior | + | Cette partie concerne les systèmes de fichiers ; au début, il y avait DOS (et CP/M) qui utilisaient FAT comme système de fichiers. Les noms de fichiers avaient 8 caractères avec un type de fichier de 3 caractères. Plus tard, NTFS (New Technology File System - Système de Fichiers de Nouvelle Technologie) permit des noms et des types longs, et plus d' |
- | Packed array of chars | + | Quand DEC a créé ODS-2 (On Disk Structure version 2 - structure sur disque version 2), il a pris une autre approche. Il nomma tous les périphériques (pas seulement les disques) avec deux caractères qui spécifiaient le type, un caractère commençant à A, puis B et ainsi de suite pour identifier l' |
+ | |||
+ | **Suppose I create a text file with an editor and save the file. Besides the name and type that I specify, it will also get a version number, starting with “1”. If I would use the editor to change this file and save it again, the existing file will not be overwritten like in Linux and Windows. The editor creates a new file, with the same name and type, but with a higher version number, “2” in this case. The same happens with log files, executables (programs), and so on. The advantage is that you can see the history of a file and even restore a previous version. For example, if a new version of a program does not work as it should, you can just kill the process and start the previous version, it is still there (unless you deleted it). But of course there is also a down-side: For a thousand versions of a file, you need a thousand times the disk-space and the version is limited to 32767. If you go beyond that, the creating program will crash! | ||
+ | |||
+ | If your project is depending on this behavior (the file version, not the crashing), you will have to change your programs. Either by adding a “version number” to the name or type, or by changing your project in such a way it will no longer depend on the file versions. Whichever solution is best depends on the project and there' | ||
+ | |||
+ | Supposez que je crée un fichier texte dans un éditeur et que je le sauvegarde. Outre le nom et le type que je spécifie, il y aura aussi un numéro de version, commençant à « 1 ». Si j' | ||
+ | |||
+ | Si votre projet est sensible à ce comportement (la version de fichier, pas le plantage), vous devrez changer vos programmes. Soit en ajoutant un « numéro de version » aux nom et type, ou en changeant votre projet de telle façon qu'il ne dépende plus des numéros de version. L'une de ces solutions est la meilleure pour votre projet, mais il n'y a pas de solution unique qui réponde à tous les cas. | ||
+ | |||
+ | **Packed array of chars | ||
In Free Pascal, two worlds collide. On the one hand are the C-type strings, and on the other the Pascal-type strings. C-type strings are either a pointer to a data-structure which can dynamically change in size, or a data-structure of fixed size, starting with a byte containing the length of the string. Both contain a zero terminated number of characters. Pascal-type strings are essentially just another fixed size array, without the terminating zero. In VAX-Pascal, there is a variant that uses a length word in front of the array (VARYING OF CHAR), but Free Pascal does not recognize the keyword VARYING. You will have to use fixed size C-type strings to replace a VARYING, but the behavior is not exactly the same. For this type of strings, the migration will need some work. | In Free Pascal, two worlds collide. On the one hand are the C-type strings, and on the other the Pascal-type strings. C-type strings are either a pointer to a data-structure which can dynamically change in size, or a data-structure of fixed size, starting with a byte containing the length of the string. Both contain a zero terminated number of characters. Pascal-type strings are essentially just another fixed size array, without the terminating zero. In VAX-Pascal, there is a variant that uses a length word in front of the array (VARYING OF CHAR), but Free Pascal does not recognize the keyword VARYING. You will have to use fixed size C-type strings to replace a VARYING, but the behavior is not exactly the same. For this type of strings, the migration will need some work. | ||
- | Big problems arise when you compare two strings with at least one of them being a packed array of chars. In VAX-Pascal, the remainder of a packed array of chars will be filled with spaces, in Free Pascal the remainder is unknown! As a result, comparing even fails if the strings you use are equal. Suppose you have a packed array of chars with size 10 ([1..10]) named STR. Now fill it with a text of size 4 like “STR := ' | + | Big problems arise when you compare two strings with at least one of them being a packed array of chars. In VAX-Pascal, the remainder of a packed array of chars will be filled with spaces, in Free Pascal the remainder is unknown! As a result, comparing even fails if the strings you use are equal. Suppose you have a packed array of chars with size 10 ([1..10]) named STR. Now fill it with a text of size 4 like “STR := ' |
- | This is clearly a bug, but I didn't have the time to fill out a bug-report. | + | Les matrices empaquetées de caractères |
+ | |||
+ | En Free Pascal, deux mondes se télescopent. D'un côté, il y a les chaînes de type C et, de l' | ||
+ | |||
+ | Les gros problèmes surviennent quand vous comparez deux chaînes et qu'au moins l'une d' | ||
+ | |||
+ | **This is clearly a bug, but I didn't have the time to fill out a bug-report. | ||
As a workaround, you could add a string of spaces with the same length as the size of the packed array of char, because Free Pascal will not complain about the string being too long. It just truncates it. So “STR := ' | As a workaround, you could add a string of spaces with the same length as the size of the packed array of char, because Free Pascal will not complain about the string being too long. It just truncates it. So “STR := ' | ||
Ligne 46: | Ligne 88: | ||
There will be also problems when assigning a C-type string from a packed array of chars. If the remainder of the packed array of chars are zero's (usually the case) the contents of the string will list as “test” in the above example in the debugger, but the length of the string will be 10, so a comparison to “test” will fail. In the debugger, it looks like they are the same, but still the “if” statement will execute the “else” part. It took me days to figure that out. It shows an inconsistency in the way Free Pascal handles strings, as the terminating zero is ignored. Worth a bug report! | There will be also problems when assigning a C-type string from a packed array of chars. If the remainder of the packed array of chars are zero's (usually the case) the contents of the string will list as “test” in the above example in the debugger, but the length of the string will be 10, so a comparison to “test” will fail. In the debugger, it looks like they are the same, but still the “if” statement will execute the “else” part. It took me days to figure that out. It shows an inconsistency in the way Free Pascal handles strings, as the terminating zero is ignored. Worth a bug report! | ||
- | Next month: In the next article, I will go more in-depth about DCL (Digital Command Language) – the interface used by Digital when interacting with the terminal, and AST's (Asynchronous System Trap), also named ‘call back routines’, | + | Next month: In the next article, I will go more in-depth about DCL (Digital Command Language) – the interface used by Digital when interacting with the terminal, and AST's (Asynchronous System Trap), also named ‘call back routines’, |
+ | |||
+ | C'est clairement un défaut, mais je n' | ||
+ | |||
+ | Comme contournement, | ||
+ | |||
+ | Des problèmes apparaîtront aussi lors de la déclaration d'une chaîne de type C à partir d'une chaîne empaquetée de caractères. Si le reste de la chaîne empaquetée de caractères est zéro (cas classique), le contenu de la chaîne sera affiché « test » dans le débogueur, pour reprendre l' | ||
+ | |||
+ | La mois prochain : dans le prochain article, j' |
issue108/tutoriel1.1462032924.txt.gz · Dernière modification : 2016/04/30 18:15 de auntiee