/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "counter.p" */ #include /* counter: program counter Dr. Thomas D. Schneider National Institutes of Health National Cancer Institute Center for Cancer Research Nanobiology Program Molecular Information Theory Group Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu (use only if first address fails) http://www.ccrnp.ncifcrf.gov/~toms/ */ /* end of program */ /* begin module version */ #define version 1.00 /* of counter.p 2009 Apr 13 2009 Apr 13, 1.00: origin */ #define updateversion 1.00 /* defines lowest acceptable current parameter file */ /* end module version */ /* begin module describe.counter */ /* name counter: program counter synopsis counter(input: in, output: out) files input: parameters to control the program. The file must contain the following parameters, on one line: number: an integer number to display width: the number of positions to use for the display output: messages to the user description Output the given number and then backspace. This allows a running counter to be displayed by a script. examples Example script: ******************************************************************************** #!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) echo version = 1.00 of mk 2009 Apr 13 @ n = 0 echo -n "here we go! >" while ($n < 1000) echo "$n 5" | counter @ n = $n + 1 end echo "$n< done!" ******************************************************************************** documentation see also {module digitcounter in} scan.p author Thomas Dana Schneider bugs technical notes */ /* end module describe.counter */ Static _TEXT afile; /* file used by this program */ Static _TEXT counterp; /* file used by this program */ Static _TEXT bfile; /* file used by this program */ Static jmp_buf _JL1; /* begin module halt */ Static Void halt() { /* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. */ printf(" program halt.\n"); longjmp(_JL1, 1); } #define ordControlH 8 /* end module halt version = 'delmod 6.16 84 mar 12 tds/gds'; */ /* begin module digitcounter */ Static Void digitcounter(afile, counter, previous) _TEXT *afile; long *counter, *previous; { /* Make a digit counter on a single line. The digits are written and overwritten the next time by using control H. To initialize, set the 'previous' variable to zero. To terminate, put a "writeln(afile,'whateveryouwant');". If you put "write(afile,'babble-counter: ');" before the call, the numbers will show up on the same line and your message can indicate what the counter is about. */ /* the ordinal of control H so that we do not have to put an actual control H into the source code. The chr() of this will give the control H character */ long digits; /* number of digits in in previous number */ long digitcount; /* index to digits */ if (*previous > 0) { /* backspace the PREVIOUS number of digits */ /* Compute the number of digits. For sequencenumber = 1000, we add an extra 0.5 to avoid rounding that would give 3 instead of 4 as the number of digits. Other cases work fine with this. */ digits = (long)(log(*previous + 0.5) / log(10.0) + 1); /* writeln(output, digits:1, ' ', counter:1); for digitcount := 1 to previous do write(output, 'H'); */ for (digitcount = 1; digitcount <= digits; digitcount++) putchar((Char)ordControlH); /* writeln(output, digits:1, ' ', counter:1, ' ',previous:1); */ } printf("%ld", *counter); *previous = *counter; } #undef ordControlH #define ordControlH 8 /* end module digitcounter version = 5.32; (@ of prgmod.p 2007 Mar 25 */ /* begin module counter.themain */ Static Void themain(afile, counterp, bfile) _TEXT *afile, *counterp, *bfile; { /* the main procedure of the program */ /* the ordinal of control H so that we do not have to put an actual control H into the source code. The chr() of this will give the control H character */ double parameterversion; /* parameter version number */ long widthindex; /* index for the width */ long number; /* the number to display */ long width; /* the number of characters used for the number */ /* previous: integer; (* the number of characters used for the number *) */ scanf("%ld%ld", &number, &width); printf("%*ld", (int)width, number); for (widthindex = 1; widthindex <= width; widthindex++) putchar((Char)ordControlH); /* previous := 0; digitcounter(output,number, previous) */ } #undef ordControlH /* end module counter.themain */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; bfile.f = NULL; *bfile.name = '\0'; counterp.f = NULL; *counterp.name = '\0'; afile.f = NULL; *afile.name = '\0'; themain(&afile, &counterp, &bfile); _L1: if (afile.f != NULL) fclose(afile.f); if (counterp.f != NULL) fclose(counterp.f); if (bfile.f != NULL) fclose(bfile.f); exit(EXIT_SUCCESS); } /* End. */