Hello Dan,

Dan wrote on Tue, Aug 05, 2025 at 09:15:38AM +0200:
> Ingo Schwarze <schwa...@usta.de> wrote:

>> That said, if you want to do terminal manipulation of this kind,
>> then you almost certainly do not want to write your program in
>> the ksh(1) language.  Instead, you want to write your program
>> in C and use curses(3) for cursor positioning and selective
>> updates of terminal window content.  Or in another high-level
>> language that provides terminal manipulation facilities.
>> 
>> Any *sh(1) scripting language is a very poor fit for writing
>> a program that wants to perform terminal manipulation.

> I'm writing my textual pdf reader and I just miss to fix/erase my
> visual feedback offered to the user while processing the ocred stuff,
> nothing about terminal manipulation, don't be afraid.
> 
> Anyway if you are interested in my pdftexter I'm going to post it in
> the usual places, starting from https://github/par7133 

Apparently, you mean:
  https://github.com/par7133/pdftexter/blob/main/pdftexter

A few random remarks:
 * No manual page, so it's hard to say what the point is.
 * "textual pdf reader" sounds somewhat misleading.
   To me, it looks more like a ghostscript + tesseract wrapper script.
 * If you want to use the same licensing policy as OpenBSD,
   follow the instructions in /usr/share/misc/license.template .
   In particular, copy the complete license *into each file*,
   then edit the Copyright line as required.
   Having this line in no good - neither sufficient nor intelligible:
   # Copyright 5 Mode and other contributors; Licensed MIT
   Does that mean you are not even the author of parts of this code?
 * No matter the programming language, doing option parsing by hand
   is a terrible idea.  Use getopt(3) or the equivalent.
 * If you merely want to check for the presence of a file,
   use test(1) -e (or rather, the ksh(1) builtin).
   No need messing around with ls(1).
   Then again, you want to test whether software is installed,
   which should be tested at install time of your program,
   not at the run time of your program.
 * "mkdir ./tmp" needs error checking: what if it exists, but
   is not a directory?  Just barrelling on regardless is clearly
   a bad idea.  Besides, i doubt the wisdom of creating a tmp
   directory in the current working directory.
   Use /tmp/, that's what it's for.
   Look at what this command does, see mktemp(1):
     mktemp -d -p /tmp/ pdftexter.XXXXXXXXXX
 * There are more unchecked commands down the line.
 * gs -dBATCH -dNOPAUSE -dFirstPage=$param2 ...
   OUCH.  Vulnerable to whitespace and shell metacharacter attacks.
 * I'm not quite sure what the 'printf "\b\b\b"' is supposed
   to erase, maybe some kind of ad-hoc progress meter implemented
   by simple printing dots at various points in the program?
   The normal way of dealing with a finished progress meter
   in a shell script is *not* erasing it, but doing something like
     echo " FOO done"
   where FOO is replaced with a one-word description of what it is
   that was completed.  And yes, when you want a progress meter
   that gets erased when completed, then i would indeed count
   that as a (simple) terminal control task.
 * I'm not quite sure how exactly this program is supposed to
   work - but it seems as if you are converting PDF to a bitmap
   and then using OCR to extract text?  That would be a bad
   idea because most PDF files contain actual text, so no OCR
   is needed.  Are you aware of programs like pdftotext(1),
   to be installed with:
     pkg_add poppler-utils
   You should only use use OCR if the PDF file contains images
   rather than text, i.e. when pdftotext(1) is helpless.
   Look at https://www.iso.org/standard/75839.html
   for more details.  Yes, that document is 986 pages long.
   PDF is probably the most complicated text markup language ever.
 * I'm not planning to do a full audit.

My first impression boils down to this:
 * Your code is teeming with beginner's mistakes and extremely sloppy.
 * You lack basic experience writing sh(1) code.
 * ksh(1) is indeed a bad choice of a programming language here,
   especially for a beginner, whatever the exact purpose
   of the script may be.

Not trying to discourage you, just trying to help developing
a realistic self-evaluation of your current skill level.
Try practising, and have fun!

Yours,
  Ingo

Reply via email to