From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56573d75358b9d2d,start X-Google-Attributes: gid103376,public From: berlich@pc66.mppmu.mpg.de (Ruediger Berlich) Subject: Could need some advice :-) (long) Date: 1996/07/07 Message-ID: <4rp7p9$3g0b@sat.ipp-garching.mpg.de>#1/1 X-Deja-AN: 164187753 organization: Rechenzentrum der Max-Planck-Gesellschaft in Garching newsgroups: comp.lang.ada Date: 1996-07-07T00:00:00+00:00 List-Id: Hi all, I'm currently changing from C/C++. I worked through the tutorials about migrating from C/C++ to Ada on http://lglwww.epfl.ch/Ada/ and through the Lovelace-Tutorial (at least most of it) and now think about starting with a non-trivial example (since I made the experience, that this is the best way to learn a language). So now I could need some advice to get me started, since a lot of things are still unclear to me or weren't covered in these tutorials. I would like to write a procedure (or probably more than one :-), which reads and parses configuration-files or data-files. Therefore I first need a procedure, which reads a file of arbitrary lenght and fills each line into a string. Since I don't know about the lenght of each line and the number of lines in the file, I need unbounded strings and unbounded arrays to hold the strings (i.e. no size-limit has to be specified in advance). I read, that this exists for strings, but didn't find a hint, that it is possible for arrays of arbitrary type (e.g. arrays of strings). Since a string is just an array of characters, I suspect that it's possible, though. Under C++ I would just create a class with an overloaded []-Operator and would copy internally the array holding the data into a larger array, if the index exceeds the border of the array. How do I do that in Ada95 ? (I.e. do I have to do the same as in C++ or is there a predefined package ?) The next step is then, to take each string, and parse it for the required information. I would like to cover two cases : 1. The file contains data in the form 1.23 4.56 7.89 ... 3.65 3.44 4.23 ... 2. it looks like Variable1 = 1.234 Variable2 = 5.678 NKnots = 7 StringVar = "SaveResults.dat u: rwx" ... So, when I finally have the strings holding a line, I need some functions to parse the string. Thereby I would like to tell the procedure at runtime, what is considered to be a WhiteSpace-character (e.g. ' ' or 'x', if you like that) and what is a comment (e.g. #, $ or !) . The procedure shouldn't care, whether I say Variable1 = 1.234 or Variable1 1.234 (Could be done by defining '=' as a WhiteSpace). In case 1 it want to divide the string into substrings holding the numbers (as characters) and then convert these strings into numbers, thereby taking care of typos and raising exceptions, if that happens (e.g. 1.X34 or 1.2341.456). These numbers are than filled into an array which is of size NLinesWithNumber x NNumbersPerLine . The array should be the result of the function. In case 2 the function takes an array of strings as argument, holding the names of allowed variables (e.g. 'Variable1' or 'StringVar') together with some character specifying the type of the Variable (e.g. 'StringVar Str'). It should then convert the values (strings) belonging to the variable into the respective type and fill it into an array. The array for each type could be sorted in alphabetical order, so you know, in which position you have to fill that value. I know how to do all that in C++ (e.g. some magic programming with 'void *'), but I have no idea how to do this type-conversion in Ada. Any hint on what of the above is impossible in Ada and any general comment are welcome. What I'm looking for, are a couple of keywords of Ada-features, that you think might be relevant for the above. Also I would be glad about hints, which of these features are already implemented in some predefined and standardised Ada-package. Bye and have a nice day, Ruediger Berlich [berlich@pc66.mppmu.mpg.de]