| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| After reading the "Re Respect" item, I noted that the author said "ps. from time to time i write a 'cobol' program in 'straight-line' just to remember how it used to be. but only to remember." I am not sure if my understanding of 'straight-line' is the same as anyone else, but to me it is embodied by the following code. At 72, I too qualify as an old-timer. I don't program as much as I used to, but enjoy it from time to time - maybe it will keep my 'brain' active to forestall Alzheimer's! I learned COBOL in the sixties and established my chosen style and methods thereafter and never changed it. As some might recall, I favor the use of a subset of COBOL consisting of only the most elementary items. Things like MOVE CORRESPONDING and Reference Modification are never used. This ensures high compatibility with multiple compilers. I live off my POS software which was originally written in MF COBOL for the Tandy 2000. That same software, still using the same compiler, is still supporting me 20 years later. I never changed the compiler since I didn't want to spend the money and go through the mess of conversion. It worked on Windows 3.1 and every version of Windows since, including Vista without modification or recompilation. (I use the wonderful SP2 - the same version I bought ages ago.) I do not like 'structured' programming and I won't annoy you by telling you what I think of it. Nor do I approve of the idiotic concept of having only one period in a program. So, I do 'straight-line' coding in the old fashioned way, all upper case and straight-forward - periods and commas all over the place. . . I have hundreds of HTML files and I needed a program to read an HTML file and to pluck out of it the names of all images used in IMG SRC statements. The program asks for a file name and writes a BAT file which I can then use to copy the files to a particular directory. This facilitates FTPing and things like that. So I wrote one. Now, I challenge all of you to write a program which does the same thing using the style and language(s) of your choice. You will then post the code and let the CLC offer their opinions. Thank you Tony Dilworth $set ans85 noosvs mf IDENTIFICATION DIVISION. PROGRAM-ID. HTML. AUTHOR. A. R. DILWORTH. DATE-WRITTEN. 08/30/08. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. TANDY-2000. OBJECT-COMPUTER. TANDY-2000. INPUT-OUTPUT SECTION. FILE- CONTROL. SELECT HTMLFILE ASSIGN TO DISK, ORGANIZATION IS LINE SEQUENTIAL, FILE STATUS IS W- FSTAT. SELECT IMGSRC ASSIGN TO DISK, ORGANIZATION IS LINE SEQUENTIAL, FILE STATUS IS W- FSTAT. DATA DIVISION. FILE SECTION. FD HTMLFILE LABEL RECORDS ARE STANDARD, VALUE OF FILE-ID IS W-HTML. 01 HREC. 02 HCHAR PIC X OCCURS 256 TIMES. FD IMGSRC LABEL RECORDS ARE STANDARD, VALUE OF FILE-ID IS 'IMGSRC.BAT'. 01 IMGREC. 02 IMGDAT PIC X OCCURS 256 TIMES. WORKING-STORAGE SECTION. 01 W-HTML PIC X(256) VALUE SPACE. 01 W-IMGSRC. 02 W-IMGCHAR PIC X(01) OCCURS 50 TIMES. * W9901 IS A GENERAL-PURPOSE COPY CONTAINING SUBSCRIPTS, ETC, ETC. COPY W9901.CBL. PROCEDURE DIVISION. A. DISPLAY 'INPUT FILE NAME:'. ACCEPT W-HTML. OPEN INPUT HTMLFILE. IF W-FSTAT NOT = '00' DISPLAY ' INVALID FILE NAME', GO TO A. OPEN OUTPUT IMGSRC. B. READ HTMLFILE AT END GO TO X. C. MOVE SPACE TO W-IMGSRC. MOVE HREC TO W-WORK. PERFORM S9912 THRU S9912X. MOVE W-WORK TO HREC. PERFORM CA VARYING X1 FROM 1 BY 1 UNTIL X1 > 256. CA. IF HCHAR (X1) = "I" ADD 1 TO X1, IF HCHAR (X1) = "M" ADD 1 TO X1 IF HCHAR (X1) = "G" ADD 2 TO X1 IF HCHAR (X1) = 'S' ADD 1 TO X1, IF HCHAR (X1) = 'R' ADD 1 TO X1, IF HCHAR (X1) = 'C' PERFORM CB VARYING X1 FROM X1 BY 1 UNTIL X1 > 256. CAA. GO TO B. CB. IF HCHAR (X1) = '"' OR "'" MOVE 1 TO X2, GO TO CC. CC. ADD 1 TO X1. IF HCHAR (X1) = '"' OR "'" DISPLAY W-IMGSRC, STRING 'COPY ' W-IMGSRC DELIMITED BY SIZE INTO IMGREC, WRITE IMGREC, GO TO B, ELSE MOVE HCHAR (X1) TO W-IMGCHAR (X2), ADD 1 TO X2, GO TO CC. X. CLOSE IMGSRC. CLOSE HTMLFILE. STOP RUN. * S9912 IS AN UPCASE ROUTINE. COPY S9912.CBL. |
|
#2
| |||
| |||
| On Sep 1, 1:08*am, foodman <foodman...@aol.com> wrote: I have no idea why you thought that posting this would be useful at all, either to you or to us. It is unlikely to convince us that there is any merit at all in your coding style and you have stated that you haven't changed anything you do for decades and this can be taken that any comments that are made will not change your opinions at all. As I have stated many times: What is easy is entirely what you are used to. You can glance at this code, or similar code, and know immediately what it does. When you look at other code it is confusing to you. Thus you think that yours is somehow 'better'. Well, certainly it is to you. To us it is likely that, while we can understand the code, we see its faults and probably see how it would be improved, mainly by discarding and starting again. I quickly picked up a couple of faults in the code which I would have not expected from a trainee programmer when I ran Cobol courses in the early 70s. For example: You PERFORM CA until X1 is > 256 then drop through CA. As X1 now has a value of 257 it would fail a bound check. This is very poor programming. You also abuse the language. You exit the performed paragraph CB with a GO TO CC. This could result in the perform stack being exceeded resulting in program failure. It is unlikely that you have reached that with this program, but it is indiicative of your lack of any defensive coding style. The program also fails to do what you promise for it, at least it would fail to do this on many of the HTML files that I have. While you do upper case the line you require that the HTML tag text be exactly 'IMG SRC'. Other attributes may exist in an IMG tag, notably ALT. These can be in any order and any amount of whitespace, including line feeds, may exist. So the program may work (mostly) for your files with limited variation, but not for all, or even for all of mine. You also uppercase the whole line which will result in the image file name in the COPY statement being upper cased. This will work in CP/M derivitive systems but not where there is case sensitivity. As you say that there are hundreds of HTML files then this program would fail to match any real usability criteria. It appears to require that the name be manually keyed in after starting the program. It is unlikely that anyone would want to do this for hundreds of files. Any rational program would take the input file from the command line, or probably a series of file names. But then you are stuck in Tandy-Land so you may never have thought of this. I am sure that this program will receive many other negative comments (such as no error checking on the output file, but you have specified a file status so the run-time won't error). Overall I would have failed a junior coder back in the 70s for producing such a poorly written program, other may be less kind. Top posted: no response after this. > After reading the "Re Respect" item, I noted that the author said > "ps. *from > time to time i write a 'cobol' program in 'straight-line' just to > remember how it used to be. *but only to remember." > > I am not sure if my understanding of 'straight-line' is the same > as anyone else, but to me it is embodied by the following code. > > At 72, I too qualify as an old-timer. I don't program as > much as I used to, but enjoy it from time to time - maybe it > will keep my 'brain' active to forestall Alzheimer's! > > I learned COBOL in the sixties and established my chosen style and > methods thereafter and never changed it. > > As some might recall, I favor the use of a subset of COBOL > consisting of only the most elementary items. *Things like > MOVE CORRESPONDING and Reference Modification are never used. > This ensures high compatibility with multiple compilers. > > I live off my POS software which was originally written in > MF COBOL for the Tandy 2000. > > That same software, still using the same compiler, is still > supporting me 20 years later. > > I never changed the compiler since I didn't want to spend the > money and go through the mess of conversion. > > It worked on Windows 3.1 and every version of Windows since, > including Vista without modification or recompilation. > > (I use the wonderful SP2 - the same version I bought ages ago.) > > I do not like 'structured' programming and I won't annoy you > by telling you what I think of it. Nor do I approve of the > idiotic concept of having only one period in a program. > > So, I do 'straight-line' coding in the old fashioned way, > all upper case and straight-forward - periods and commas > all over the place. . . > > I have hundreds of HTML files and I needed a program to > read an HTML file and to pluck out of it the names of > all images used in IMG SRC statements. The program > asks for a file name and writes a BAT file which I can > then use to copy the files to a particular directory. > This facilitates FTPing and things like that. > > So I wrote one. > > Now, I challenge all of you to write a program which > does the same thing using the style and language(s) of your > choice. You will then post the code and let the CLC offer their > opinions. > > Thank you > > Tony Dilworth > > * * * $set ans85 noosvs mf > > * * * *IDENTIFICATION > DIVISION. > * * * *PROGRAM-ID. * * * * * * HTML. > > * * * *AUTHOR. * * * * * * * * A. R. > DILWORTH. > * * * *DATE-WRITTEN. * * * * * 08/30/08. > * * * *ENVIRONMENT > DIVISION. > * * * *CONFIGURATION > SECTION. > * * * *SOURCE-COMPUTER. * * * *TANDY-2000. > * * * *OBJECT-COMPUTER. * * * *TANDY-2000. > > * * * *INPUT-OUTPUT > SECTION. > * * * *FILE- > CONTROL. > * * * * * *SELECT HTMLFILE * * ASSIGN TO DISK, > * * * * * * * * * * * * * * * *ORGANIZATION IS LINE SEQUENTIAL, > * * * * * * * * * * * * * * * *FILE STATUS IS W- > FSTAT. > > * * * * * *SELECT IMGSRC * * * ASSIGN TO DISK, > * * * * * * * * * * * * * * * *ORGANIZATION IS LINE SEQUENTIAL, > * * * * * * * * * * * * * * * *FILE STATUS IS W- > FSTAT. > * * * *DATA > DIVISION. > * * * *FILE > SECTION. > > * * * *FD *HTMLFILE *LABEL RECORDS ARE STANDARD, > * * * * * * * * * VALUE OF FILE-ID IS W-HTML. > * * * *01 *HREC. > * * * * * *02 HCHAR PIC X OCCURS 256 TIMES. > > * * * *FD *IMGSRC LABEL RECORDS ARE STANDARD, > * * * * * * * * * VALUE OF FILE-ID IS 'IMGSRC.BAT'. > * * * *01 *IMGREC. > * * * * * *02 IMGDAT PIC X OCCURS 256 TIMES. > > * * * *WORKING-STORAGE SECTION. > > * * * *01 *W-HTML * * * PIC X(256) VALUE SPACE. > * * * *01 *W-IMGSRC. > * * * * * *02 *W-IMGCHAR PIC X(01) OCCURS 50 TIMES. > > * * * * W9901 IS A GENERAL-PURPOSE COPY CONTAINING SUBSCRIPTS, ETC, > ETC. > > * * * *COPY W9901.CBL. > > * * * *PROCEDURE DIVISION. > * * * *A. > * * * * * *DISPLAY 'INPUT FILE NAME:'. > * * * * * *ACCEPT W-HTML. > * * * * * *OPEN INPUT HTMLFILE. > * * * * * *IF W-FSTAT NOT = '00' > * * * * * * * *DISPLAY ' INVALID FILE NAME', > * * * * * * * *GO TO A. > * * * * * *OPEN OUTPUT IMGSRC. > * * * *B. > * * * * * *READ HTMLFILE *AT END GO TO X. > * * * *C. > * * * * * *MOVE SPACE TO W-IMGSRC. > * * * * * *MOVE HREC TO W-WORK. > * * * * * *PERFORM S9912 THRU S9912X. > * * * * * *MOVE W-WORK TO HREC. > * * * * * *PERFORM CA VARYING X1 FROM 1 BY 1 UNTIL X1 > 256. > > * * * *CA. > * * * * * * * *IF HCHAR (X1) = "I" > * * * * * * * *ADD 1 TO X1, > > * * * * * * * *IF HCHAR (X1) = "M" > * * * * * * * *ADD 1 TO X1 > > * * * * * * * *IF HCHAR (X1) = "G" > * * * * * * * *ADD 2 TO X1 > > * * * * * * * *IF HCHAR (X1) = 'S' > * * * * * * * *ADD 1 TO X1, > > * * * * * * * *IF HCHAR (X1) = 'R' > * * * * * * * *ADD 1 TO X1, > > * * * * * * * *IF HCHAR (X1) = 'C' > * * * * * * * * * PERFORM CB > * * * * * * * * * VARYING X1 FROM X1 BY 1 UNTIL X1 > 256. > * * * *CAA. > * * * * * *GO TO B. > * * * *CB. > * * * * * *IF HCHAR (X1) = '"' OR "'" > * * * * * * * *MOVE 1 TO X2, > * * * * * * * *GO TO CC. > * * * *CC. > * * * * * *ADD 1 TO X1. > * * * * * *IF HCHAR (X1) = '"' OR "'" > * * * * * * * *DISPLAY W-IMGSRC, > * * * * * * * *STRING 'COPY ' W-IMGSRC DELIMITED BY SIZE INTO IMGREC, > * * * * * * * *WRITE IMGREC, > * * * * * * * *GO TO B, > * * * * * * ELSE > * * * * * * * *MOVE HCHAR (X1) TO W-IMGCHAR (X2), > * * * * * * * *ADD 1 TO X2, > * * * * * * * *GO TO CC. > > * * * *X. > * * * * * *CLOSE IMGSRC. > * * * * * *CLOSE HTMLFILE. > * * * * * *STOP RUN. > > * * * * S9912 IS AN UPCASE ROUTINE. > > * * * *COPY S9912.CBL. |
|
#3
| |||
| |||
| On Sep 1, 1:08*am, foodman <foodman...@aol.com> wrote: > I do not like 'structured' programming and I won't annoy you > by telling you what I think of it. Nor do I approve of the > idiotic concept of having only one period in a program. Actually there is no such concept as "only one period in a program", apart from all the data division items requiring them, each non-empty paragraph must have at least two, one on the label, and one to terminate it. You do use this style yourself, such as paragraphs CA and CB. Your paragraph CC does have one additional full stop. The questions then are: does it add anything to the code ? (no, not at all) and: does it detract or add additional work if the code were to be changed ? My answer here is yes, If I were to change the code I might want to start with a conditional, such as (in a theoretical general case): "IF X1 < 100". Then I would indent the remaining code, BUT, I would also have to examine all the code seeking out full stops. You may think of this explanation as 'idiotic'. I think that scattering pointless full stops, and especially the useless commas, through the code as idiotic. But, as you say, you haven't managed to learn anything new for decades, so I don't expect that you will learn anything from anyone's comments now. > So, I do 'straight-line' coding in the old fashioned way, > all upper case and straight-forward - periods and commas > all over the place. . . > > I have hundreds of HTML files and I needed a program to > read an HTML file and to pluck out of it the names of > all images used in IMG SRC statements. The program > asks for a file name and writes a BAT file which I can > then use to copy the files to a particular directory. > This facilitates FTPing and things like that. > > So I wrote one. > > Now, I challenge all of you to write a program which > does the same thing using the style and language(s) of your > choice. You will then post the code and let the CLC offer their > opinions. > > Thank you > > Tony Dilworth > > * * * $set ans85 noosvs mf > > * * * *IDENTIFICATION > DIVISION. > * * * *PROGRAM-ID. * * * * * * HTML. > > * * * *AUTHOR. * * * * * * * * A. R. > DILWORTH. > * * * *DATE-WRITTEN. * * * * * 08/30/08. > * * * *ENVIRONMENT > DIVISION. > * * * *CONFIGURATION > SECTION. > * * * *SOURCE-COMPUTER. * * * *TANDY-2000. > * * * *OBJECT-COMPUTER. * * * *TANDY-2000. > > * * * *INPUT-OUTPUT > SECTION. > * * * *FILE- > CONTROL. > * * * * * *SELECT HTMLFILE * * ASSIGN TO DISK, > * * * * * * * * * * * * * * * *ORGANIZATION IS LINE SEQUENTIAL, > * * * * * * * * * * * * * * * *FILE STATUS IS W- > FSTAT. > > * * * * * *SELECT IMGSRC * * * ASSIGN TO DISK, > * * * * * * * * * * * * * * * *ORGANIZATION IS LINE SEQUENTIAL, > * * * * * * * * * * * * * * * *FILE STATUS IS W- > FSTAT. > * * * *DATA > DIVISION. > * * * *FILE > SECTION. > > * * * *FD *HTMLFILE *LABEL RECORDS ARE STANDARD, > * * * * * * * * * VALUE OF FILE-ID IS W-HTML. > * * * *01 *HREC. > * * * * * *02 HCHAR PIC X OCCURS 256 TIMES. > > * * * *FD *IMGSRC LABEL RECORDS ARE STANDARD, > * * * * * * * * * VALUE OF FILE-ID IS 'IMGSRC.BAT'. > * * * *01 *IMGREC. > * * * * * *02 IMGDAT PIC X OCCURS 256 TIMES. > > * * * *WORKING-STORAGE SECTION. > > * * * *01 *W-HTML * * * PIC X(256) VALUE SPACE. > * * * *01 *W-IMGSRC. > * * * * * *02 *W-IMGCHAR PIC X(01) OCCURS 50 TIMES. > > * * * * W9901 IS A GENERAL-PURPOSE COPY CONTAINING SUBSCRIPTS, ETC, > ETC. > > * * * *COPY W9901.CBL. > > * * * *PROCEDURE DIVISION. > * * * *A. > * * * * * *DISPLAY 'INPUT FILE NAME:'. > * * * * * *ACCEPT W-HTML. > * * * * * *OPEN INPUT HTMLFILE. > * * * * * *IF W-FSTAT NOT = '00' > * * * * * * * *DISPLAY ' INVALID FILE NAME', > * * * * * * * *GO TO A. > * * * * * *OPEN OUTPUT IMGSRC. > * * * *B. > * * * * * *READ HTMLFILE *AT END GO TO X. > * * * *C. > * * * * * *MOVE SPACE TO W-IMGSRC. > * * * * * *MOVE HREC TO W-WORK. > * * * * * *PERFORM S9912 THRU S9912X. > * * * * * *MOVE W-WORK TO HREC. > * * * * * *PERFORM CA VARYING X1 FROM 1 BY 1 UNTIL X1 > 256. > > * * * *CA. > * * * * * * * *IF HCHAR (X1) = "I" > * * * * * * * *ADD 1 TO X1, > > * * * * * * * *IF HCHAR (X1) = "M" > * * * * * * * *ADD 1 TO X1 > > * * * * * * * *IF HCHAR (X1) = "G" > * * * * * * * *ADD 2 TO X1 > > * * * * * * * *IF HCHAR (X1) = 'S' > * * * * * * * *ADD 1 TO X1, > > * * * * * * * *IF HCHAR (X1) = 'R' > * * * * * * * *ADD 1 TO X1, > > * * * * * * * *IF HCHAR (X1) = 'C' > * * * * * * * * * PERFORM CB > * * * * * * * * * VARYING X1 FROM X1 BY 1 UNTIL X1 > 256. > * * * *CAA. > * * * * * *GO TO B. > * * * *CB. > * * * * * *IF HCHAR (X1) = '"' OR "'" > * * * * * * * *MOVE 1 TO X2, > * * * * * * * *GO TO CC. > * * * *CC. > * * * * * *ADD 1 TO X1. > * * * * * *IF HCHAR (X1) = '"' OR "'" > * * * * * * * *DISPLAY W-IMGSRC, > * * * * * * * *STRING 'COPY ' W-IMGSRC DELIMITED BY SIZE INTO IMGREC, > * * * * * * * *WRITE IMGREC, > * * * * * * * *GO TO B, > * * * * * * ELSE > * * * * * * * *MOVE HCHAR (X1) TO W-IMGCHAR (X2), > * * * * * * * *ADD 1 TO X2, > * * * * * * * *GO TO CC. > > * * * *X. > * * * * * *CLOSE IMGSRC. > * * * * * *CLOSE HTMLFILE. > * * * * * *STOP RUN. > > * * * * S9912 IS AN UPCASE ROUTINE. > > * * * *COPY S9912.CBL. |
|
#4
| |||
| |||
| On Sun, 31 Aug 2008 06:08:10 -0700 (PDT), foodman <foodman123@aol.com> wrote: >After reading the "Re Respect" item, I noted that the author said >"ps. from >time to time i write a 'cobol' program in 'straight-line' just to >remember how it used to be. but only to remember." > >I am not sure if my understanding of 'straight-line' is the same >as anyone else, but to me it is embodied by the following code. > >At 72, I too qualify as an old-timer. I don't program as >much as I used to, but enjoy it from time to time - maybe it >will keep my 'brain' active to forestall Alzheimer's! > >I learned COBOL in the sixties and established my chosen style and >methods thereafter and never changed it. > >As some might recall, I favor the use of a subset of COBOL >consisting of only the most elementary items. Things like >MOVE CORRESPONDING and Reference Modification are never used. >This ensures high compatibility with multiple compilers. Hold that thought. (Which compiler does not support the '85 Standard?) >I live off my POS software which was originally written in >MF COBOL for the Tandy 2000. > >That same software, still using the same compiler, is still >supporting me 20 years later. > >I never changed the compiler since I didn't want to spend the >money and go through the mess of conversion. First you say your code is portable, then contradict yourself when you complain about the difficulty of porting it. Make up your mind. >It worked on Windows 3.1 and every version of Windows since, >including Vista without modification or recompilation. > >(I use the wonderful SP2 - the same version I bought ages ago.) > >I do not like 'structured' programming and I won't annoy you >by telling you what I think of it. Nor do I approve of the >idiotic concept of having only one period in a program. Structured programming was invented around 1970. We're waiting to see whether it catches on. >So, I do 'straight-line' coding in the old fashioned way, >all upper case and straight-forward - periods and commas >all over the place. . . > >I have hundreds of HTML files and I needed a program to >read an HTML file and to pluck out of it the names of >all images used in IMG SRC statements. The program >asks for a file name and writes a BAT file which I can >then use to copy the files to a particular directory. >This facilitates FTPing and things like that. > >So I wrote one. > >Now, I challenge all of you to write a program which >does the same thing using the style and language(s) of your >choice. You will then post the code and let the CLC offer their >opinions. > >Thank you > >Tony Dilworth Sounds like a job for Windows PowerShell, the official scripting language for Windows. Or run Ch and do it with one line of Unix script using awk, or just grep with a regular expression. Since this is a Cobol forum, here's one way to write it in Cobol. > $set ans85 noosvs mf > > IDENTIFICATION >DIVISION. > PROGRAM-ID. HTML. > > AUTHOR. A. R. >DILWORTH. > DATE-WRITTEN. 08/30/08. > ENVIRONMENT >DIVISION. > CONFIGURATION >SECTION. > SOURCE-COMPUTER. TANDY-2000. > OBJECT-COMPUTER. TANDY-2000. > > > INPUT-OUTPUT >SECTION. > FILE- >CONTROL. > SELECT HTMLFILE ASSIGN TO DISK, > ORGANIZATION IS LINE SEQUENTIAL, > FILE STATUS IS W- >FSTAT. > > SELECT IMGSRC ASSIGN TO DISK, > ORGANIZATION IS LINE SEQUENTIAL, > FILE STATUS IS W- >FSTAT. > DATA >DIVISION. > FILE >SECTION. > > FD HTMLFILE LABEL RECORDS ARE STANDARD, > VALUE OF FILE-ID IS W-HTML. > 01 HREC. > 02 HCHAR PIC X OCCURS 256 TIMES. > > > FD IMGSRC LABEL RECORDS ARE STANDARD, > VALUE OF FILE-ID IS 'IMGSRC.BAT'. > 01 IMGREC. > 02 IMGDAT PIC X OCCURS 256 TIMES. > > WORKING-STORAGE SECTION. > > 01 W-HTML PIC X(256) VALUE SPACE. > 01 W-IMGSRC. > 02 W-IMGCHAR PIC X(01) OCCURS 50 TIMES. > > * W9901 IS A GENERAL-PURPOSE COPY CONTAINING SUBSCRIPTS, ETC, >ETC. > > COPY W9901.CBL. > > PROCEDURE DIVISION. > A. > DISPLAY 'INPUT FILE NAME:'. > ACCEPT W-HTML. > OPEN INPUT HTMLFILE. > IF W-FSTAT NOT = '00' > DISPLAY ' INVALID FILE NAME', > GO TO A. > OPEN OUTPUT IMGSRC. > B. > READ HTMLFILE AT END GO TO X. MOVE 1 TO X1 SEARCH IMGDAT VARYING X1 WHEN FUNCTION UPPERCASE(IMGREC(X1:7)) = 'IMG DAT' MOVE 'COPY ' TO W-IMGREC UNSTRING IMGREC(X1 DELIMITED BY '"' OR "'"INTO THROWAWAY IMGREC(6 ![]() IF IMGREC(6 NOT EQUAL TO SPACESWRITE IMGREC ELSE DISPLAY 'Malformed line ' IMGREC(X1 .GO TO B. X. CLOSE IMGSRC, HTMLFILE STOP RUN. *> Delete clunky code following > C. > MOVE SPACE TO W-IMGSRC. > MOVE HREC TO W-WORK. > PERFORM S9912 THRU S9912X. > MOVE W-WORK TO HREC. > PERFORM CA VARYING X1 FROM 1 BY 1 UNTIL X1 > 256. > > CA. > IF HCHAR (X1) = "I" > ADD 1 TO X1, > > IF HCHAR (X1) = "M" > ADD 1 TO X1 > > IF HCHAR (X1) = "G" > ADD 2 TO X1 > > IF HCHAR (X1) = 'S' > ADD 1 TO X1, > > IF HCHAR (X1) = 'R' > ADD 1 TO X1, > > IF HCHAR (X1) = 'C' > PERFORM CB > VARYING X1 FROM X1 BY 1 UNTIL X1 > 256. > CAA. > GO TO B. > CB. > IF HCHAR (X1) = '"' OR "'" > MOVE 1 TO X2, > GO TO CC. > CC. > ADD 1 TO X1. > IF HCHAR (X1) = '"' OR "'" > DISPLAY W-IMGSRC, > STRING 'COPY ' W-IMGSRC DELIMITED BY SIZE INTO IMGREC, > WRITE IMGREC, > GO TO B, > ELSE > MOVE HCHAR (X1) TO W-IMGCHAR (X2), > ADD 1 TO X2, > GO TO CC. > > > > * S9912 IS AN UPCASE ROUTINE. > > COPY S9912.CBL. > > > > > > > |
|
#5
| |||
| |||
| On Sep 1, 11:36*am, Robert <n...@e.mail> wrote: > On Sun, 31 Aug 2008 06:08:10 -0700 (PDT), foodman <foodman...@aol.com> wrote: > >After reading the "Re Respect" item, I noted that the author said > >"ps. *from > >time to time i write a 'cobol' program in 'straight-line' just to > >remember how it used to be. *but only to remember." > > >I am not sure if my understanding of 'straight-line' is the same > >as anyone else, but to me it is embodied by the following code. > > >At 72, I too qualify as an old-timer. I don't program as > >much as I used to, but enjoy it from time to time - maybe it > >will keep my 'brain' active to forestall Alzheimer's! > > >I learned COBOL in the sixties and established my chosen style and > >methods thereafter and never changed it. > > >As some might recall, I favor the use of a subset of COBOL > >consisting of only the most elementary items. *Things like > >MOVE CORRESPONDING and Reference Modification are never used. > >This ensures high compatibility with multiple compilers. > > Hold that thought. (Which compiler does not support the '85 Standard?) > Microfocus Level II Cobol is a '74 compiler. It is unlikely that he is using the earlier Microfocus CIS Cobol, but may be using Level II which was current when the Tandy 2000 was being sold. > >I live off my POS software which was originally written in > >MF COBOL for the Tandy 2000. > > >That same software, still using the same compiler, is still > >supporting me 20 years later. > > >I never changed the compiler since I didn't want to spend the > >money and go through the mess of conversion. > > First you say your code is portable, then contradict yourself when you complain about the > difficulty of porting it. Make up your mind. > > >It worked on Windows 3.1 and every version of Windows since, > >including Vista without modification or recompilation. > > >(I use the wonderful SP2 - the same version I bought ages ago.) > However, I am not sure that SP/2 was available for Level II. It may have been. > >I do not like 'structured' programming and I won't annoy you > >by telling you what I think of it. Nor do I approve of the > >idiotic concept of having only one period in a program. > > Structured programming was invented around 1970. We're waiting to see whether it catches > on. > > > > >So, I do 'straight-line' coding in the old fashioned way, > >all upper case and straight-forward - periods and commas > >all over the place. . . > > >I have hundreds of HTML files and I needed a program to > >read an HTML file and to pluck out of it the names of > >all images used in IMG SRC statements. The program > >asks for a file name and writes a BAT file which I can > >then use to copy the files to a particular directory. > >This facilitates FTPing and things like that. > > >So I wrote one. > > >Now, I challenge all of you to write a program which > >does the same thing using the style and language(s) of your > >choice. You will then post the code and let the CLC offer their > >opinions. > > >Thank you > > >Tony Dilworth > > Sounds like a job for Windows PowerShell, the official scripting languagefor Windows. Or > run Ch and do it with one line of Unix script using awk, or just grep with a regular > expression. *Since this is a Cobol forum, here's one way to write it inCobol. > Obviously not tested though, or even sight checked. Geez, these junior coders worry me with their inattention to details. > > * * *$set ans85 noosvs mf > > > * * * IDENTIFICATION > >DIVISION. > > * * * PROGRAM-ID. * * * * * * HTML. > > > * * * AUTHOR. * * * * * * * * A. R. > >DILWORTH. > > * * * DATE-WRITTEN. * * * * * 08/30/08. > > * * * ENVIRONMENT > >DIVISION. > > * * * CONFIGURATION > >SECTION. > > * * * SOURCE-COMPUTER. * * * *TANDY-2000. > > * * * OBJECT-COMPUTER. * * * *TANDY-2000. > > > * * * INPUT-OUTPUT > >SECTION. > > * * * FILE- > >CONTROL. > > * * * * * SELECT HTMLFILE * * ASSIGN TO DISK, > > * * * * * * * * * * * * * * * ORGANIZATION IS LINE SEQUENTIAL, > > * * * * * * * * * * * * * * * FILE STATUSIS W- > >FSTAT. > > > * * * * * SELECT IMGSRC * * * ASSIGN TO DISK, > > * * * * * * * * * * * * * * * ORGANIZATION IS LINE SEQUENTIAL, > > * * * * * * * * * * * * * * * FILE STATUSIS W- > >FSTAT. > > * * * DATA > >DIVISION. > > * * * FILE > >SECTION. > > > * * * FD *HTMLFILE *LABEL RECORDS ARE STANDARD, > > * * * * * * * * *VALUE OF FILE-ID IS W-HTML. > > * * * 01 *HREC. > > * * * * * 02 HCHAR PIC X OCCURS 256 TIMES. > > > * * * FD *IMGSRC LABEL RECORDS ARE STANDARD, > > * * * * * * * * *VALUE OF FILE-ID IS 'IMGSRC.BAT'. > > * * * 01 *IMGREC. > > * * * * * 02 IMGDAT PIC X OCCURS 256 TIMES. > > > * * * WORKING-STORAGE SECTION. > > > * * * 01 *W-HTML * * * PIC X(256) VALUE SPACE. > > * * * 01 *W-IMGSRC. > > * * * * * 02 *W-IMGCHAR PIC X(01) OCCURS 50 TIMES. > > > * * ** W9901 IS A GENERAL-PURPOSE COPY CONTAINING SUBSCRIPTS, ETC, > >ETC. > > > * * * COPY W9901.CBL. > > > * * * PROCEDURE DIVISION. > > * * * A. > > * * * * * DISPLAY 'INPUT FILE NAME:'. > > * * * * * ACCEPT W-HTML. > > * * * * * OPEN INPUT HTMLFILE. > > * * * * * IF W-FSTAT NOT = '00' > > * * * * * * * DISPLAY ' INVALID FILE NAME', > > * * * * * * * GO TO A. > > * * * * * OPEN OUTPUT IMGSRC. > > * * * B. > > * * * * * READ HTMLFILE *AT END GO TO X. > > MOVE 1 TO X1 > SEARCH IMGDAT VARYING X1 > * * WHEN FUNCTION UPPERCASE(IMGREC(X1:7)) = 'IMG DAT' > * * * * MOVE 'COPY ' TO W-IMGREC > * * * * *UNSTRING IMGREC(X1 DELIMITED BY '"' OR "'"> * * * * * * * * INTO THROWAWAY IMGREC(6 ![]() > * * * * *IF *IMGREC(6 NOT EQUAL TO SPACES> * * * * * * * *WRITE IMGREC > * * * * *ELSE > * * * * * * * *DISPLAY 'Malformed line ' IMGREC(X1 .> GO TO B. > X. > * CLOSE IMGSRC, HTMLFILE > * STOP RUN. > > *> Delete clunky code following > > > * * * C. > > * * * * * MOVE SPACE TO W-IMGSRC. > > * * * * * MOVE HREC TO W-WORK. > > * * * * * PERFORM S9912 THRU S9912X. > > * * * * * MOVE W-WORK TO HREC. > > * * * * * PERFORM CA VARYING X1 FROM 1 BY 1 UNTIL X1 > 256. > > > * * * CA. > > * * * * * * * IF HCHAR (X1) = "I" > > * * * * * * * ADD 1 TO X1, > > > * * * * * * * IF HCHAR (X1) = "M" > > * * * * * * * ADD 1 TO X1 > > > * * * * * * * IF HCHAR (X1) = "G" > > * * * * * * * ADD 2 TO X1 > > > * * * * * * * IF HCHAR (X1) = 'S' > > * * * * * * * ADD 1 TO X1, > > > * * * * * * * IF HCHAR (X1) = 'R' > > * * * * * * * ADD 1 TO X1, > > > * * * * * * * IF HCHAR (X1) = 'C' > > * * * * * * * * *PERFORM CB > > * * * * * * * * *VARYING X1 FROM X1 BY 1 UNTIL X1 > 256. > > * * * CAA. > > * * * * * GO TO B. > > * * * CB. > > * * * * * IF HCHAR (X1) = '"' OR "'" > > * * * * * * * MOVE 1 TO X2, > > * * * * * * * GO TO CC. > > * * * CC. > > * * * * * ADD 1 TO X1. > > * * * * * IF HCHAR (X1) = '"' OR "'" > > * * * * * * * DISPLAY W-IMGSRC, > > * * * * * * * STRING 'COPY ' W-IMGSRC DELIMITED BY SIZE INTO IMGREC, > > * * * * * * * WRITE IMGREC, > > * * * * * * * GO TO B, > > * * * * * *ELSE > > * * * * * * * MOVE HCHAR (X1) TO W-IMGCHAR (X2), > > * * * * * * * ADD 1 TO X2, > > * * * * * * * GO TO CC. > > > * * ** S9912 IS AN UPCASE ROUTINE. > > > * * * COPY S9912.CBL. > > |
|
#6
| |||
| |||
| In article <92fcce4e-2525-4bc8-a4ef-aeff6ac7a50a@n33g2000pri.googlegroups.com>, Richard <riplin@azonic.co.nz> wrote: [snip] >My answer here is yes, If I were to change the code I might >want to start with a conditional, such as (in a theoretical general >case): "IF X1 < 100". Then I would indent the remaining code, BUT, I >would also have to examine all the code seeking out full stops. What's this... if you desire to change the depth of condition the current design of the code would force you to go through the rest of it, line by line, making sure your change did not introduce any unanticipated errors? Horrors! *Everyone* knows that well-designed code allows for the depth of condition to be altered at a moment's notice, with no consideration whatsoever for what's going on around it... all ya gotta do is slap in the change and be done with it. > >You may think of this explanation as 'idiotic'. I think that >scattering pointless full stops, and especially the useless commas, >through the code as idiotic. Styles differ, Mr Plinston; I was taugh, e'er-so-long ago, that the intention of COBOL was to be English-like to the point where a period/full stop was to signal the end of a sentence, the completion of a thought, the full conveying of a particular set of instructions. Code - with some exceptions - is written for a variety of audiences. One of those audiences is composed of those-who-maintain. My experience is limited, I admit, but I have never heard those-who-maintain grouse or bellyache that 'the sentences are too clear and the code is too simple'. DD |
|
#7
| |||
| |||
| On Sep 1, 12:31*pm, docdw...@panix.com () wrote: > In article <92fcce4e-2525-4bc8-a4ef-aeff6ac7a...@n33g2000pri.googlegroups..com>, > > Richard *<rip...@azonic.co.nz> wrote: > > [snip] > > >My answer here is yes, If I were to change the code I might > >want to start with a conditional, such as (in a theoretical general > >case): "IF X1 < 100". Then I would indent the remaining code, BUT, I > >would also have to examine all the code seeking out full stops. > > What's this... if you desire to change the depth of condition the current > design of the code would force you to go through the rest of it, line by > line, making sure your change did not introduce any unanticipated errors? Well of course it is still checked, but in _my_ code I reduce the amount that needs to be _changed_. And, for example, if the IF were later removed and the code unindented, then presumably the 'dots everywhere' brigade would go back and add them to each line. """If you don't know what you are doing then do it neatly.""" > Horrors! **Everyone* knows that well-designed code allows for the depthof > condition to be altered at a moment's notice, with no consideration > whatsoever for what's going on around it... all ya gotta do is slap in the > change and be done with it. Ideally, defensive coding would have that be the case, yes. Of course no code is ideal, some less so than others. > >You may think of this explanation as 'idiotic'. I think that > >scattering pointless full stops, and especially the useless commas, > >through the code as idiotic. > > Styles differ, Mr Plinston; Which is why I usually specify what _I_ do, what _my_ code is like, and the benefits that _I_ find, rather than attempting to persuade others to do it in any particular way. > I was taugh, e'er-so-long ago, that the > intention of COBOL was to be English-like to the point where a period/full > stop was to signal the end of a sentence, the completion of a thought, the > full conveying of a particular set of instructions. Yes, but even you have specified the plural 'instructions'. I ensure that, as far as possible, each of my paragraphs is, to me, one 'set of instructions', one 'thought'. I do know that some claim to use a full stop "at the end of every line", but their code does not reflect this. For example, as already pointed out, paragraphs CA and CB only have just one full stop. > Code - with some exceptions - is written for a variety of audiences. *One > of those audiences is composed of those-who-maintain. *My experience is > limited, I admit, but I have never heard those-who-maintain grouse or > bellyache that 'the sentences are too clear and the code is too simple'. That _may_ be because they haven't seen my code. |
|
#8
| |||
| |||
| >You are correct in that I did not expect to change anyone's opinions >nor was it my intention and I know that very well from prior encounters >in CLC. I know in advance what the response is going to be like. >It was in response to one old-timer's >comments about coding perhaps to help him 'remember'. >And, to give people an opportunity to demonstrate their style >which only one person did. I know quite >well that CLC denizens do not like my style, but I do and that >is all that counts. IF I ever have to get another compiler >for whatever reason, I know that it will be an easy conversion >and that is vital to me. It is always interesting to see how >other people do things even if you don't like them. As I have stated many times: What is easy is entirely what you are used to. You can glance at this code, or similar code, and know immediately what it does. When you look at other code it is confusing to you. Thus you think that yours is somehow 'better'. Well, certainly it is to you. >I never said it was 'better', it is merely my style which I like. >I don't think that a 'glance' at Robert's incomplete code tells immediately >what it does if one didn't know already. Again, I restrict my code >to a basic subset of COBOL and there are definite advantages to that. >I also wonder what a 'malformed line' is and why the user is not >given an opportunity to respond in the example. For example: You PERFORM CA until X1 is > 256 then drop through CA. As X1 now has a value of 257 it would fail a bound check. This is very poor programming. >But X1 is never referenced greater than 256. So it is not a problem. >And, I do that all the time and always have with no problems. So, >if it is not a problem and the compiler doesn't mind, why not do it? >It works. You also abuse the language. You exit the performed paragraph CB with a GO TO CC. This could result in the perform stack being exceeded resulting in program failure. It is unlikely that you have reached that with this program, but it is indiicative of your lack of any defensive coding style. > I don't find anything wrong with that at all. And, it works >perfectly fine and I've been doing it for years and it always works. >So, if it works all the time why not do it? Of course, switching >compilers COULD present problems but it is not likely in this case. You also uppercase the whole line which will result in the image file name in the COPY statement being upper cased. This will work in CP/M derivitive systems but not where there is case sensitivity. >That's OK, it is a DOS BAT file, after all and case sensitivity is NOT >a problem. BTW, the generated COPY statement is incomplete. Incidentally, >my server is a Unix machine which, as you probably know, is case- >sensitive so I have to be very careful when FTPing. As you say that there are hundreds of HTML files then this program would fail to match any real usability criteria. It appears to require that the name be manually keyed in after starting the program. It is unlikely that anyone would want to do this for hundreds of files. Any rational program would take the input file from the command line, or probably a series of file names. But then you are stuck in Tandy-Land so you may never have thought of this. >No, I don't WANT to do hundreds at a time. I want to do ONE at a time. >It was written for MY HTML, not everybody's. It works perfectly for me. >So, it is perfectly 'usable' and meets my requirements exactly. >You could also make comments such that the name of the output file >could be specified by the user, etc. Again, it was written for >one file at a time because that is what I want and criticizing >it for not being something else is pointless. >If you would like to see an example of usability download my demo. Robert said "First you say your code is portable, then contradict yourself when you complain about the difficulty of porting it. Make up your mind. >There is no question that moving from one compiler to another >will uncover incompatibilities between the two. It is not that >it is so difficult, but it can be time-consuming and affect other >matters such as distribution and prior-version support. and, it costs money >(my money, not someone else's) . I never want >to have to go through that regardless of the 'difficulty' and I >know I won't have to. That's the point. It makes sense. >My mind IS made up. >It is correct that I do not check the file-status after every >I-O operation as I would if this program were to be used >by others and as is the case with my POS software . But it is >for my personal use so it is not a problem. File-Status is specified. >Robert provided his chosen way, how about some others? >I wonder if Sea Side Sam will have any comments? >BTW, I did upgrade my compiler after the original Tandy >version, but I don't remember the details. All I know >is that it still works for all versions of Windows >and that is my top priority. My distributed software >is just over 2mb and expands to about 5mb. All of >my competitor's software is typically in the 256mb >range which is indicative of the software used. >Mine has to be better and is. The small size and >rapid installation is a definite advantage when >prospects download demo versions of my software >which you can see for yourself at foodman123.com. >Richard, why don't you give us your version >of how you would code this? Come on, I'd like to >see it. >Richard said "Obviously not tested though, or even sight checked." >It was tested and it does what I want it to do and I actually use it for >the purpose intended with no problem. >I don't know of anyone in CLC who lives off their own software. >Maybe there are, I don't know of anyone and would like to >'compare notes' if there are. >Most everyone works for a big corporation where money is no >object and people can use whatever they feel like to some >degree. Put yourselves in my position where every decision >can affect my bottom line. I don't think that anyone can >argue that I would be better off using a later compiler >or current technology such as .NET or whatever. >My approach, discounting coding style, makes sense. Doesn't it? >Well, doesn't it? >Finally, I provide free support to over 800 users all >over the world. I get about one phone call a week. >Some weeks I don't get any. That has to say something >about the quality of the software and its high level >of dependability, usability, etc. which further supports >my position. >Well, doesn't it? Tony Dilworth |
|
#9
| |||
| |||
| In article <88af676a-5ab8-44cb-a9ac-b06fb0f76e12@w1g2000prk.googlegroups.com>, Richard <riplin@azonic.co.nz> wrote: >On Sep 1, 12:31*pm, docdw...@panix.com () wrote: >> In article ><92fcce4e-2525-4bc8-a4ef-aeff6ac7a...@n33g2000pri.googlegroups.com>, >> >> Richard *<rip...@azonic.co.nz> wrote: >> >> [snip] >> >> >My answer here is yes, If I were to change the code I might >> >want to start with a conditional, such as (in a theoretical general >> >case): "IF X1 < 100". Then I would indent the remaining code, BUT, I >> >would also have to examine all the code seeking out full stops. >> >> What's this... if you desire to change the depth of condition the current >> design of the code would force you to go through the rest of it, line by >> line, making sure your change did not introduce any unanticipated errors? > >Well of course it is still checked, but in _my_ code I reduce the >amount that needs to be _changed_. What needs to be _changed_ (emphasis original), Mr Plinston... the indentation? Proponents of free-form source code might question that as a matter of necessity. > >And, for example, if the IF were later removed and the code >unindented, then presumably the 'dots everywhere' brigade would go >back and add them to each line. Mr Plinston, you cannot control what other 'would do', you can only control - to what extent is another matter - what you do yourself. > >"""If you don't know what you are doing then do it neatly.""" Neatness is also a matter of style, Mr Plinston. Would you say a ninety-degree angle is more neat than a sixty-degree one? > >> Horrors! **Everyone* knows that well-designed code allows for the depth of >> condition to be altered at a moment's notice, with no consideration >> whatsoever for what's going on around it... all ya gotta do is slap in the >> change and be done with it. > >Ideally, defensive coding would have that be the case, yes. > >Of course no code is ideal, some less so than others. That, I would say, depends on who establishes and who evaluates the criteria for what you are calling ideal. I, personally, do not write code for ideals, I write code in order to make the person who signs my timesheets smile. >> >You may think of this explanation as 'idiotic'. I think that >> >scattering pointless full stops, and especially the useless commas, >> >through the code as idiotic. >> >> Styles differ, Mr Plinston; > >Which is why I usually specify what _I_ do, what _my_ code is like, >and the benefits that _I_ find, rather than attempting to persuade >others to do it in any particular way. You might want to re-examine your own views of yourself, Mr Plinston. You describe a matter of style as 'idiotic'; idiot, according to http://www.merriam-webster.com/dictionary/idiot , is a term which is 'usually offensive'. > >> I was taugh, e'er-so-long ago, that the >> intention of COBOL was to be English-like to the point where a period/full >> stop was to signal the end of a sentence, the completion of a thought, the >> full conveying of a particular set of instructions. > >Yes, but even you have specified the plural 'instructions'. Even I!. > >I ensure that, as far as possible, each of my paragraphs is, to me, >one 'set of instructions', one 'thought'. You see, Mr Plinston... it can be argued that this is a limitation of style. A paragraph, by definition, contains 'one or more sentences'; by requiring yourself to keep to a subset of the definition ('one sentence only') you practise and advocate a subset of possibilities. Your reasons for doing this are your own, of course... but to call something other than the particular subset you've chosen 'idiotic' does not, to me, appear to be a reasoned or dispassioned evaluation. [snip] >> Code - with some exceptions - is written for a variety of audiences. *One >> of those audiences is composed of those-who-maintain. *My experience is >> limited, I admit, but I have never heard those-who-maintain grouse or >> bellyache that 'the sentences are too clear and the code is too simple'. > >That _may_ be because they haven't seen my code. You write code that causes those-who-maintain to grouse or bellyache? How brave of you to admit it! DD |
|
#10
| |||
| |||
| Richard <riplin@azonic.co.nz> wrote in message news:5141cde0-ff72-41de-a456-ec8e1e3da5b3@v39g2000pro.googlegroups.com... On Sep 1, 1:08 am, foodman <foodman...@aol.com> wrote: <snip> For example: You PERFORM CA until X1 is > 256 then drop through CA. As X1 now has a value of 257 it would fail a bound check. This is very poor programming. You also abuse the language. You exit the performed paragraph CB with a GO TO CC. This could result in the perform stack being exceeded resulting in program failure. It is unlikely that you have reached that with this program, but it is indiicative of your lack of any defensive coding style. [pl] That isn't necessarily the case. Using a stack isn't the only way of doing this. As for the rest: his style makes me itch but as the code does what is required of it - it works, he understands it, and he finds it easy to maintain (and he's the only one that has to be considered) - nothing else needs to be considered . So he uses uper-case letters. So? I do too. Just that I'm used to doing it that way. {/pl] |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.