File: userint.c

package info (click to toggle)
dosemu-freedos 1%3A0.0.b9r5a%2Betch.1-0etch1
  • links: PTS
  • area: contrib
  • in suites: etch
  • size: 19,744 kB
  • ctags: 23,279
  • sloc: ansic: 143,864; asm: 20,397; makefile: 3,868; perl: 1,106; yacc: 690; sh: 553; pascal: 297; xml: 150; cpp: 67
file content (538 lines) | stat: -rw-r--r-- 20,901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/*
// Program:  Format
// Version:  0.91m
// (0.90b/c/d - better error messages - Eric Auer - May 2003)
// (0.91b..g - Eric Auer 2003 / 0.91k ... Eric Auer 2004)
// Written By:  Brian E. Reifsnyder
// Copyright:  2002-2004 under the terms of the GNU GPL, Version 2
// Module Name:  userint.c
// Module Description:  User interfacing functions.
*/

/* #include <stdlib.h> */ /* no // comments for Turbo C! -ea */


#define USERINT

#include <dos.h>
#include <ctype.h>	/* toupper */
#include <string.h>	/* strlen  */
#include <io.h>		/* write (to stderr) */

#include "format.h"
#include "userint.h"




void ASCII_CD_Number(unsigned long number)
{
  int comma_counter;
  int index;
  int right_index;
  int shift_counter;
  int shift_register;
  int shift_temp_register;
  int start_shift;
  unsigned char dsep, ksep; /* decimal- and kilo-separator */

  struct country mycountry; /* NLS stuff added 0.91k */
  /* we assume that this is DOS 2.11+: offset 7 1000s-sep 9 decsep    */
  /* also in this buffer: date format, 12<->24 clock, currency stuff, */
  /* date sep (. or / or -), time sep (:) and lots of other things    */

  ksep = ','; /* or . */
  dsep = '.'; /* or , */
  if ( country(0 /* current */, &mycountry) )
    {
      ksep = mycountry.co_thsep[0];
      dsep = mycountry.co_desep[0];
    }

  memset((void *)&ascii_cd_number[0], 0, sizeof(ascii_cd_number));

  ultoa(number, ascii_cd_number, 10);

  /* Add Commas */
  index = 13;
  right_index = 13;
  start_shift = FALSE;

  do
    {
    if (ascii_cd_number[index]>0) start_shift = TRUE;

    if (start_shift==TRUE)
      {
      ascii_cd_number[right_index] = ascii_cd_number[index];
      ascii_cd_number[index] = 0;
      right_index--;
      }

    index--;
    } while (index>=0);

  comma_counter = 0;
  index = 13;
  do
    {
    comma_counter++;

    if (ascii_cd_number[index]==0)
      {
      comma_counter = 5;
      ascii_cd_number[index] = ' ';
      }

    if (comma_counter==4)
      {
      shift_counter = index-1;
      shift_register = ascii_cd_number[index];
      ascii_cd_number[index] =  ksep; /* 1000s separator */
      do
	{
	shift_temp_register = ascii_cd_number[shift_counter];
	ascii_cd_number[shift_counter] = shift_register;
	shift_register = shift_temp_register;

	shift_counter--;
	} while (shift_counter>=0);

      comma_counter = 0;
      }

    index--;
    } while (index>=0);

  ascii_cd_number[14] = 0;

  /* cheat: add decimal separator after end of ascii_cd_number string */
  ascii_cd_number[15] =  dsep;

}


void Ask_User_To_Insert_Disk()
{
  printf(" Insert new diskette for drive %c:\n",param.drive_letter[0]);
  write(2, " Press ENTER when the right disk is in drive...",
    strlen(" Press ENTER when the right disk is in drive..."));
  /* write to STDERR for the case of STDOUT being redirected */

  /* Wait for a key */

  regs.h.ah = 0x08;
  intdos(&regs, &regs);

  printf("\n\n");
}


void Confirm_Hard_Drive_Formatting(int format) /* 0 unformat, 1 format */
{
  if (!format)
    {
      printf("UNFORMAT will revert your root directory and FAT to a\n");
      printf("previously recorded state. This can seriously mess up things!\n");
    }
  printf("\n WARNING: ALL DATA ON %s DISK\n",
    (param.drive_type==HARD) ? "NON-REMOVABLE" : "FLOPPY");
  printf(" DRIVE %c: %s LOST! PLEASE CONFIRM!\n",
    param.drive_letter[0],
    format ? "WILL BE" : "MIGHT GET" );
  /* printf(" Proceed with (Un)Format (YES/NO)? "); */
  if (!format)
    {
      write(2, " Proceed with Unformat (YES/NO)? ",
        strlen(" Proceed with Unformat (YES/NO)? "));
    }
  else
    {
      write(2, " Proceed with Format (YES/NO)? ",
        strlen(" Proceed with Format (YES/NO)? "));
    }
  /* write to STDERR for the case of STDOUT being redirected */

  /* Get keypress */
  regs.h.ah = 0x07;
  intdos(&regs, &regs);
  printf("%c",regs.h.al);

  if ( toupper(regs.h.al) != 'Y' )
    {
    printf("\n");
    exit(10);
    }

  /* Get keypress */
  regs.h.ah = 0x07;
  intdos(&regs, &regs);
  printf("%c",regs.h.al);

  if ( toupper(regs.h.al) != 'E' )
    {
    printf("\nYou have to type the whole word YES to confirm.");
    exit(10);
    }

  /* Get keypress */
  regs.h.ah = 0x07;
  intdos(&regs, &regs);
  printf("%c",regs.h.al);

  if ( toupper(regs.h.al) != 'S' )
    {
    printf("\nYou have to type the whole word YES to confirm.");
    exit(10);
    }

  printf("\n");
}


void Critical_Error_Handler(int source, unsigned int error_code)
{
  unsigned int error_code_high = (error_code & 0xff00) >> 8;
  unsigned int error_code_low  = error_code & 0x00ff;

  if(source==BIOS) {
    error_code_high = error_code_low;
    error_code_low  = 0x00;
    printf("\n Critical error encountered while using INT 13 disk driver");
  } else {
    printf("\n Critical error encountered while using DOS disk driver");
  }

  /* Display Status Message. */

  if (source==BIOS) {
    printf("\n INT 13 status (hex): %2.2x", error_code_high);

    printf("\n   Bits: ");
    /* changed to allow bit fields -ea */
    if (error_code_high == 0x00) printf("none ");
    if (error_code_high & 0x01) printf("bad command ");
    if (error_code_high & 0x02) printf("bad address mark ");
    if (error_code_high & 0x04) printf("requested sector not found ");
    if (error_code_high & 0x08) printf("DMA troubles ");
    if (error_code_high & 0x10) printf("data error (bad CRC) ");
    if (error_code_high & 0x20) printf("controller failed ");
    if (error_code_high & 0x40) printf("seek operation failed ");
    if (error_code_high & 0x80) printf("timeout / no response ");

    printf("\n   Description: "); /* *** marks popular errors */
    switch (error_code_high) {
      case 0x01: printf("invalid function or parameter"); break;
      case 0x02: printf("address mark not found"); break; /* *** */
      case 0x03: printf("DISK WRITE-PROTECTED"); break; /* *** */
      case 0x04: printf("read error / sector not found"); break; /* *** */
      case 0x05: printf("harddisk reset failed"); break;
      case 0x06: printf("FLOPPY CHANGED"); break; /* *** */
      case 0x07: printf("drive parameter error"); break;
      case 0x08: printf("DMA overrun"); break;
      case 0x09: printf("DMA across 64k boundary attempted"); break; /* *** */
      case 0x0a: printf("bad sector on harddisk"); break;
      case 0x0b: printf("bad track on harddisk"); break;
      case 0x0c: printf("invalid media / track out of range"); break; /* *** */
      case 0x0d: printf("illegal sectors / track (PS/2)"); break;
      case 0x0e: printf("harddisk control data address mark detected"); break;
      case 0x0f: printf("harddisk DMA arbitration level overflow"); break;
      case 0x10: printf("READ ERROR (CRC/ECC wrong)"); break; /* *** */
      case 0x11: printf("read error corrected by CRC/ECC"); break;
      case 0x20: printf("controller failure"); break;
      case 0x31: printf("no media in drive"); break; /* (int 13 extensions) */
      case 0x32: printf("invalid CMOS drive type"); break; /* (Compaq) */
      case 0x40: printf("Seek failed"); break; /* *** */
      case 0x80: printf("timeout (drive not ready)"); break; /* *** */
      case 0x0aa: printf("timeout (harddisk not ready)"); break;
      case 0x0b0: printf("volume not locked in drive"); break; /* int 13 ext */
      case 0x0b1: printf("volume locked in drive"); break; /* int 13 ext */
      case 0x0b2: printf("volume not removable"); break; /* int 13 ext */
      case 0x0b3: printf("volume in use"); break; /* int 13 ext */
      case 0x0b4: printf("volume lock count overflow"); break; /* int 13 ext */
      case 0x0b5: printf("eject failed"); break; /* int 13 ext */
      case 0x0b6: printf("volume is read protected"); break; /* int 13 ext */
      case 0x0bb: printf("general harddisk error"); break;
      case 0x0cc: printf("harddisk WRITE ERROR"); break;
      case 0x0e0: printf("harddisk status register error"); break;
      case 0x0ff: printf("harddisk sense operation failed"); break;
      default: printf("(unknown error code)"); break;
    } /* switch */
  } /* BIOS */
  else
  { /* DOS */

    printf("\n DOS driver error (hex): %2.2x", error_code_low);

    printf("\n   Description: ");
    switch (error_code_low) {
      case 0x00: printf("write-protection violation attempted / none"); break;
      case 0x01: printf("unknown unit for driver"); break;
      case 0x02: printf("drive not ready"); break;
      case 0x03: printf("unknown command given to driver"); break;
      case 0x04: printf("data error (bad CRC)"); break;
      case 0x05: printf("bad device driver request structure length"); break;
      case 0x06: printf("seek error"); break;
      case 0x07: printf("unknown media type"); break;
      case 0x08: printf("sector not found"); break;
      case 0x09: printf("printer out of paper"); break;
      case 0x0a: printf("write fault"); break;
      case 0x0b: printf("read fault"); break;
      case 0x0c: printf("general failure"); break;
      case 0x0d: printf("sharing violation"); break;
      case 0x0e: printf("lock violation"); break;
      case 0x0f: printf("invalid disk change"); break;
      case 0x10: printf("FCB unavailable"); break;
      case 0x11: printf("sharing buffer overflow"); break;
      case 0x12: printf("code page mismatch"); break;
      case 0x13: printf("out of input"); break;
      case 0x14: printf("insufficient disk space"); break;
      default: printf("(unknown error code)"); break;
    } /* switch */
  } /* DOS */

  /* *** We should probably allow an IGNORE or RETRY in *some* cases! *** */

  printf("\n Program terminated.\n");

  exit(1);
}


/* 0.91k - avoid overflow if FAT32 */
void Display_Drive_Statistics()
{

#define DDS_unitstring ((param.fat_type == FAT32) ? "kbytes" : "bytes")
#define DDS_factor(x) ((param.fat_type == FAT32) ? ((x)>>1) : ((x) * \
  drive_statistics.bytes_per_sector))
/* a cheat: ASCII_CD_Number puts the decimal point at index 15... */
#define DDS_dp ((param.fat_type == FAT32) ? ascii_cd_number[15] : ' ')
#define DDS_half(x) ((param.fat_type == FAT32) ? (((x) & 1) ? "5" : "0") : "")

  if ((drive_statistics.bytes_per_sector != 512) && (param.fat_type == FAT32))
    printf("Sector size is not 512 bytes - kbyte values will be wrong.\n");

  /* changed in 0.91h */
  /* avail = data area size (w/o root dir), total = "diskimage" size */
  drive_statistics.allocation_units_available_on_disk
    = drive_statistics.sect_available_on_disk
    / drive_statistics.sect_in_each_allocation_unit;

  drive_statistics.sect_available_on_disk -=
    ( drive_statistics.allocation_units_with_bad_sectors
      * drive_statistics.sect_in_each_allocation_unit );

  ASCII_CD_Number(DDS_factor(drive_statistics.sect_total_disk_space));
  printf("\n%13s%c%s %s total disk space (disk size)\n",
    ascii_cd_number, DDS_dp, DDS_half(drive_statistics.sect_total_disk_space),
    DDS_unitstring);

  if (drive_statistics.bad_sectors > 0) /* changed 0.91c */
    {
    ASCII_CD_Number(DDS_factor(drive_statistics.bad_sectors));
    printf("%13s%c%s %s in bad sectors\n",
      ascii_cd_number, DDS_dp, DDS_half(drive_statistics.bad_sectors),
      DDS_unitstring);
    ASCII_CD_Number(DDS_factor(drive_statistics.sect_total_disk_space -
      drive_statistics.sect_available_on_disk));
    printf("%13s%c%s %s in clusters with bad sectors\n",
      ascii_cd_number, DDS_dp, DDS_half(drive_statistics.sect_total_disk_space -
        drive_statistics.sect_available_on_disk), DDS_unitstring);
    }

  ASCII_CD_Number(DDS_factor(drive_statistics.sect_available_on_disk));
  printf("%13s%c%s %s available on disk (free clusters)\n",
    ascii_cd_number, DDS_dp, DDS_half(drive_statistics.sect_available_on_disk),
    DDS_unitstring);

  printf("\n");

  ASCII_CD_Number(DDS_factor(drive_statistics.sect_in_each_allocation_unit));
  printf("%13s%c%s %s in each allocation unit.\n",
    ascii_cd_number, DDS_dp, DDS_half(drive_statistics.sect_in_each_allocation_unit),
    DDS_unitstring);

  ASCII_CD_Number(drive_statistics.allocation_units_available_on_disk);
  printf("%13s%s allocation units on disk.\n", ascii_cd_number,
    (param.fat_type == FAT32) ? "  " : "");

  if (drive_statistics.allocation_units_with_bad_sectors > 0) /* 0.91c */
    {
    ASCII_CD_Number(drive_statistics.allocation_units_with_bad_sectors);
    printf("%13s%s of the allocation units marked as bad\n", ascii_cd_number,
      (param.fat_type == FAT32) ? "  " : "");
    }

  printf("\n Volume Serial Number is %04X-%04X\n",
   drive_statistics.serial_number_high, drive_statistics.serial_number_low);
}


void Display_Invalid_Combination()
{
  printf("\n Invalid combination of options... please read documentation.\n");
  printf(" Operation Terminated.\n");
  exit(4);
}


void Key_For_Next_Page(void);

void Key_For_Next_Page()
{
  if (!isatty(1))
    return; /* redirected? then do not wait. */
    /* interesting: redirection to MORESYS (>MORE$) still is a TTY   */
    /* redirection to a file is not a TTY, so waiting is avoided :-) */

  printf("-- press enter to see the next page or ESC to abort  --");

  /* Get keypress */
  regs.h.ah = 0x07;
  intdos(&regs, &regs);
  if (regs.h.al == 27)
    {
      printf("\nAborted at user request.\n");
      exit(1);
    }

  printf("\n\n");

} /* Key_For_Next_Page() */


/* Help Routine (removed legacy stuff in 0.91c, but it is still parsed) */
/* There should be an help file which explains everything in detail,    */
/* including the (hardly ever used but still supported) legacy options! */
/* 0.91n - if detailed is non-zero, display multi-page help screen. */
void Display_Help_Screen(int detailed)
{
  printf("FreeDOS %6s Version %s\n",NAME,VERSION);
  printf("Written by Brian E. Reifsnyder (and several contributors).\n");
  printf("Copyright 1999 - 2004 under the terms of the GNU GPL, Version 2.\n\n");

  if (detailed)
    printf("Syntax (see documentation for more details background information):\n\n");
  else
    printf("Syntax (see documentation or use /Z:longhelp for more options):\n\n");

#if LEGACY_HELP /* with legacy stuff */
  printf("FORMAT drive: [/V[:label]] [/Q] [/U] [/F:size] [/B | /S] [/D]\n");
  printf("FORMAT drive: [/V[:label]] [/Q] [/U] [/T:tracks /N:sectors] [/B | /S] [/D]\n");
  printf("FORMAT drive: [/V[:label]] [/Q] [/U] [/4] [/B | /S] [/D]\n");
  printf("FORMAT drive: [/Q] [/U] [/1] [/4] [/8] [/B | /S] [/D]\n\n");
#else /* new - without legacy stuff */
  printf("FORMAT drive: [/V[:label]] [/Q] [/U] [/F:size] [/S] [/D]\n");
  printf("FORMAT drive: [/V[:label]] [/Q] [/U] [/T:tracks /N:sectors] [/S] [/D]\n");
  /* the /4 option is a legacy shorthand for size selection: 360k in 1.2M drive */
  /* (drive type detection and "double stepping" setting are automatic on ATs.) */
  printf("FORMAT drive: [/V[:label]] [/Q] [/U] [/4] [/S] [/D]\n\n");
#endif

  printf(" /V:label   Specifies a volume label for the disk, stores date and time of it.\n");
  printf(" /S         Calls SYS to make the disk bootable and to add system files.\n");

#if LEGACY_HELP /* legacy, DOS 1.x (/B cannot be combined with /S) */
  printf(" /B         Kept for compatibility, formerly reserved space for the boot files.\n");
#endif  
  printf(" /D         Be very verbose and show debugging output. For bug reports.\n");

  printf(" /Q         Quick formats the disk. If not combined with /U, can be UNFORMATed\n");
  printf("            and preserves bad cluster marks (/Q /U does not).\n");
  /* preserving the bad cluster list is new in 0.91k */
  printf(" /U         Unconditionally formats the disk. Lowlevel format if floppy disk.\n");

  printf(" /F:size    Specifies the size of the floppy disk to format. Normal sizes are:\n");
  printf("            360, 720, 1200, 1440, or 2880 (unit: kiloBytes). /F:0 shows a list.\n");
  printf(" /4         Formats a 360k floppy disk in a 1.2 MB floppy drive.\n");
  printf(" /T:tracks  Specifies the number of tracks on a floppy disk.\n");
  printf(" /N:sectors Specifies the number of sectors on a floppy disk.\n");

#if LEGACY_HELP /* legacy, DOS 1.x */
  printf(" /1         Formats a single side of a floppy disk (160k / 180k).\n");
  printf(" /8         Formats a 5.25\" disk with 8 sectors per track (160k / 320k).\n");
#endif  

  if (!detailed) return; /* stop here for normal, short, help screen */

  printf("\n"); /* we got enough space for that */
  Key_For_Next_Page();

  printf("This FORMAT is made for the http://www.freedos.org/ project.\n");
  printf("  See http://www.gnu.org/ for information about GNU GPL license.\n");
  printf("Made in 1999-2003 by Brian E. Reifsnyder <reifsnyderb@mindspring.com>\n");
  printf("  Maintainer of 0.90 / 0.91 series: Eric Auer <eric@coli.uni-sb.de>\n");
  printf("Contributors: Jan Verhoeven, John Price, James Clark, Tom Ehlert,\n");
  printf("  Bart Oldeman, Jim Hall and others. Not to forget all the testers!\n\n");

  printf("Switches and additional features explained:\n");
  printf("/D (debug) and /Y (skip confirmation request) are always allowed.\n");
  printf("/B (reserve space for sys) is dummy and cannot be combined with /S (sys)\n");
  printf("/V:label is not for 160k/320k disks. The label stores the format date/time.\n\n");

  printf("Size specifications only work for floppy disks. You can use\n");
  printf("either /F:size (in kilobytes, size 0 displays a list of allowed sizes)\n");
  printf("or     /T:tracks /N:sectors_per_track\n");
  printf("or any combination of /1 (one-sided, 160k/180k),\n");
  printf("                      /8 (8 sectors per track, 160k/320k, DOS 1.x)\n");
  printf("                  and /4 (format 160-360k disk in 1200k drive)\n\n");
  printf("To suppress the harddisk format confirmation prompt, use    /Z:seriously\n");
  printf("To save only unformat (mirror) data without formatting, use /Z:mirror\n");
  printf("To UNFORMAT a disk for which fresh mirror data exists, use  /Z:unformat\n");

  printf("\n"); /* we got enough space for that */
  Key_For_Next_Page();

  printf("Modes for FLOPPY are: Tries to use quick safe format. Use lowlevel format\n");
  printf("  only when needed. Quick safe format saves mirror data for unformat.\n");
  printf("Modes for HARDDISK are: Tries to use quick safe format. Use quick full\n");
  printf("  format only when needed. Quick full format only resets the filesystem\n");
  printf("If you want to force lowlevel format (floppy) or want to have the whole\n");
  printf("  disk surface scanned and all contents wiped (harddisk), use /U.\n");
  printf("  FORMAT /Q /U is quick full format (no lowlevel format / scan / wipe!)\n");
  printf("  FORMAT /Q is quick save format (save mirror data if possible)\n");
  printf("    the mirror data will always overwrite the end of the data area!\n");
  printf("  FORMAT autoselects a mode (see above) if you select neither /Q nor /U\n\n");

  printf("Supported FAT types are: FAT12, FAT16, FAT32, all with mirror / unformat.\n");
  printf("Supported floppy sizes are: 160k 180k 320k 360k and 1200k for 5.25inch\n");
  printf("  and 720k and 1440k (2880k never tested so far) for 3.5inch drives.\n");
#if 0 /* should be obvious */
// printf("DD drives are limited to 360k/720k respectively. 2880k is ED drives only.\n");
#endif
  printf("Supported overformats are: 400k 800k 1680k (and 3660k) with more sectors\n");
  printf("  and 1494k (instead of 1200k) and 1743k (and 3486k) with more tracks, too.\n");
  printf("  More tracks will not work on all drives, use at your own risk.\n");
  printf("  Warning: older DOS versions can only use overformats with a driver.\n");
  printf("  720k in 1440k is known to be problematic. 360k in 1200k 'depends'...\n\n");
  
  printf("For FAT32 formatting, you can use the /A switch to force 4k alignment.\n");
  printf("WARNING: Running FORMAT for FAT32 under Win98 seems to create broken format!\n");

} /* Display_Help_Screen */


void Display_Percentage_Formatted(unsigned long percentage)
{
  if (debug_prog==TRUE)
    {
    printf("%3d%% ", percentage);
    }
  else
    {
    if (isatty(1 /* stdout */))
      printf("%3d percent completed.\r", percentage); /* on screen */
    else
      printf("%3d percent completed.\n", percentage); /* for redirect */
    /* \r re-positions cursor back to the beginning of the line */
    }
}


void IllegalArg(char *option, char *argptr)
{
    printf("Parameter value not allowed - %s%s\n", option, argptr);
    exit(1);
}