mkfs, mkproto: minor improvements
[minix.git] / commands / isoread / isoread.c
bloba6c806d4e5b0ad6fc6a928c18671d389f14e128f
1 /*
2 * isoread.c
4 * isoread reads a file system in ISO9660 or HIGH SIERRA format from
5 * a given device.
7 * Apr 5 1995 Michel R. Prevenier
8 * Nov 16 1996 Kees J. Bot -- bug fix: isoread filename matching
9 * Dec 7 1997 Albert S. Woodhull -- bug fix: return values
10 * " " : isodir filename handling
11 * -- added : isoread -a option
12 * Mar 21 2000 Michael A. Temari -- bug fix: look_up only searched first
13 * : block of directory
14 * : stack overflow in recurse_dir
15 * : and various other bugs
16 * Apr 14 2002 Michael A. Temari -- bug fix: fixed recursing directories
17 * : and printing dates 2000 and
18 * : later
19 * May 14 2002 Kees J. Bot -- bug fix: fixed error messages
20 * Mar 14 2003 Kees J. Bot -- added : iso{dir,read} -B option
21 * Jul 24 2003 Michael A. Temari -- bug fix: bytes to blocks roundup fix
24 #include <ctype.h>
25 #include <errno.h>
26 #include <limits.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <fcntl.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <time.h>
34 #include <sys/times.h>
35 #include <unistd.h>
37 /*
38 * definitions used by the ISO9660 and HIGH SIERRA file system
41 #define ISO9660_ID "CD001"
42 #define HIGH_SIERRA_ID "CDROM"
43 #define BLOCK_SIZE 2048
44 #define BLOCK_SHIFT 11
47 /* Fields in a ISO9660 volume descriptor */
48 struct iso9660_descriptor
50 char type[1];
51 char id[5];
52 char version[1];
53 char reserved1[1];
54 char system_id[32];
55 char volume_id[32];
56 char reserved2[8];
57 char volume_size[8];
58 char reserved3[32];
59 char volume_set_size[4];
60 char volume_seq_nr[4];
61 char block_size[4];
62 char path_table_size[8];
63 char type_l_path_table[4];
64 char opt_type_l_path_table[4];
65 char type_m_path_table[4];
66 char opt_type_m_path_table[4];
67 char root_dir_entry[34];
68 char vol_set_id[128];
69 char publ_id[128];
70 char prep_id[128];
71 char appl_id[128];
72 char copyright_file_id[37];
73 char abstract_file_id[37];
74 char bibl_file_id[37];
75 char creation_date[17];
76 char mod_date[17];
77 char exp_date[17];
78 char eff_date[17];
79 char file_struc_version[1];
80 char reserved4[1];
81 char appl_data[512];
82 char reserved5[653];
86 /* Fields in a High Sierra volume descriptor */
87 struct high_sierra_descriptor
89 char reserved1[8];
90 char type[1];
91 char id[5];
92 char version[1];
93 char reserved2[1];
94 char system_id[32];
95 char volume_id[32];
96 char reserved3[8];
97 char volume_size[8];
98 char reserved4[32];
99 char vol_set_size[4];
100 char volume_seq_nr[4];
101 char block_size[4];
102 char path_table_size[8];
103 char type_l_path_table[4];
104 char reserved5[28];
105 char root_dir_entry[34];
109 /* Fields in a directory entry */
110 struct dir_entry
112 char length[1];
113 char ext_attr_length[1];
114 char first_block[8];
115 char size[8];
116 char date[7];
117 char flags[1];
118 char file_unit_size[1];
119 char interleave[1];
120 char volume_seq_nr[4];
121 char name_length[1];
122 char name[1];
126 #define STDOUT stdout
127 #define STDERR stderr
128 #define NULL_DIR (struct dir_entry *) 0
129 #define MAX_NAME_LENGTH 255
130 #define MAX_PATH_LENGTH 1024
132 #define NR_OF_CHARS 13
133 #define NR_OF_BLANKS 2
134 #define NR_OF_COLS (80 / (NR_OF_CHARS + NR_OF_BLANKS))
136 /* This macro always returns a lower case character */
137 #define LOWER_CASE(CHR) (CHR >= 'A' && CHR <= 'Z' ? CHR | 0x20 : CHR)
139 /* Macro's for determining . , .. and normal directory entries */
140 #define IS_DOT(PTR) (PTR->name_length[0] == 1 && PTR->name[0] == 0 ? 1 : 0)
141 #define IS_DOT_DOT(PTR) (PTR->name_length[0] == 1 && PTR->name[0] == 1 ? 1 : 0)
142 #define IS_DIR(PTR) (PTR->flags[-High_Sierra] & 2 ? 1 : 0)
145 int main(int argc, char **argv);
146 int iso_cmp(char *name, struct dir_entry *dir_ptr, int dir_flag);
147 void list_dir(struct dir_entry *dir_ptr);
148 void list_file(struct dir_entry *dir_ptr);
149 struct dir_entry *look_up(char *name);
150 void recurse_dir(char *path, struct dir_entry *dir_ptr);
151 void read_device(long offset, int nr_of_bytes, char *buffer);
152 int valid_fs(void);
153 void usage(void);
154 void print_date(char *date);
155 void print_dir_date(char *date);
156 void iso_info(struct iso9660_descriptor *vol_desc);
157 void hs_info(struct high_sierra_descriptor *vol_desc);
158 int iso_711(char *c);
159 int iso_712(char *c);
160 int iso_721(char *c);
161 int iso_722(char *c);
162 int iso_723(char *c);
163 long iso_731(char *c);
164 long iso_732(char *c);
165 long iso_733(char *c);
168 char Buffer[BLOCK_SIZE]; /* buffer to hold read data */
169 int Device; /* global file descriptor */
170 struct iso9660_descriptor *Iso_Vol_Desc; /* iso9660 volume descriptor */
171 struct high_sierra_descriptor *Hs_Vol_Desc; /* high sierra volume descriptor */
172 int High_Sierra = 0; /* 1 = high sierra format */
173 int Iso9660 = 0; /* 1 = iso9660 format */
175 /* This comes in handy when printing the date */
176 char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
178 /* Flags displaying what to do */
179 int Read_File = 0; /* 1 = Read file */
180 int Read_Dir = 0; /* 1 = Read directory entry */
181 int Read_Info = 0; /* 1 = Read volume descriptor */
182 int Recurse = 0; /* 1 = Recursively descend directories */
183 int Verbose = 0; /* 1 = Print all info on directories */
184 int ByteOffset = 0; /* 1 = Print byte offset and length of files */
185 int Aflag = 0; /* 1 = Suppress output of \r */
187 int iso_cmp(name, dir_ptr, dir_flag)
188 char *name;
189 struct dir_entry *dir_ptr;
190 int dir_flag;
192 /* Compare name with directory entries, looking for match with a dirname.
193 * An iso9660 filename is terminated by ";n", where n will probably
194 * be 1. A directory name is not terminated by anything special, it may be
195 * followed by a \0 if padding is needed to put the following directory
196 * entry on an even address.
198 int i;
199 int len;
201 /* First match the filename */
202 len = strlen(name);
203 if (len > iso_711(dir_ptr->name_length)) return 1;
204 for (i = 0; i < len; i++)
206 if (dir_ptr->name[i] == ';') return 1; /* found end of a filename */
207 if (name[i] != LOWER_CASE(dir_ptr->name[i])) return 1; /* match failed */
209 if (dir_ptr->name[i] != ';' && i != len) return 1; /* incomplete match */
211 /* The filename is ok, now look at the file type */
212 if (dir_flag && !IS_DIR(dir_ptr)) return 1; /* File type not correct */
214 return 0;
218 void usage()
220 if (Read_Dir)
221 fprintf (STDERR, "Usage: isodir [-lrB] inputfile [dir]\n");
222 else if (Read_Info)
223 fprintf (STDERR, "Usage: isoinfo inputfile\n");
224 else
225 fprintf (STDERR, "Usage: isoread [-a] inputfile file\n");
226 exit(1);
230 int main(argc, argv)
231 int argc;
232 char **argv;
234 struct dir_entry *entry;
235 char path[MAX_PATH_LENGTH];
236 char *input_file;
237 char *basename;
238 char *file_name;
239 int i,j;
241 /* Read arguments */
242 basename = argv[0];
243 while (*argv[0] != '\0')
244 if (*argv[0]++ == '/') basename = argv[0];
246 if (strcmp(basename,"isodir") == 0) Read_Dir = 1;
247 else if (strcmp(basename,"isoinfo") == 0) Read_Info = 1;
248 else Read_File = 1;
250 if ((argc > 5 && Read_Dir) || (argc != 2 && Read_Info) ||
251 (argc > 4 && Read_File)) usage();
253 i = 1;
255 while (i < argc && argv[i][0] == '-')
257 char *opt = argv[i++] + 1;
259 if (opt[0] == '-' && opt[1] == '\0') break;
261 while (*opt != '\0')
263 if (Read_Info) usage();
264 if (Read_Dir)
265 switch (*opt++)
267 case 'r': Recurse = 1; break;
268 case 'l': Verbose = 1; break;
269 case 'B': ByteOffset = 1; break;
270 default: usage();
272 if (Read_File)
273 switch (*opt++)
275 case 'a': Aflag = 1; break;
276 case 'B': ByteOffset = 1; break;
277 default: usage();
282 if (i >= argc) usage();
283 input_file = argv[i++];
285 if (Read_File)
287 if (i >= argc) usage();
288 file_name = argv[i++];
291 if (Read_Dir)
293 file_name = "/";
294 if (i < argc)
296 file_name = argv[i++];
300 if (i < argc) usage();
302 if (Read_File || Read_Dir)
304 for (i=0; file_name[i] != '\0'; i++)
305 path[i] = LOWER_CASE(file_name[i]);
306 path[i] = '\0';
309 /* Open file system (file or device) */
310 if ((Device = open(input_file, O_RDONLY)) < 0)
312 fprintf (STDERR, "cannot open %s: %s\n", input_file, strerror(errno));
313 exit(-1);
317 if (!valid_fs())
319 fprintf (STDERR, "File system not in ISO9660 or HIGH SIERRA format \n");
320 exit(-1);
324 if (Read_Info)
326 if (Iso9660)
327 iso_info(Iso_Vol_Desc);
328 else
329 hs_info(Hs_Vol_Desc);
330 exit(0);
333 /* Lookup file */
334 if ((entry = look_up(path)) != NULL_DIR)
336 if (Read_Dir)
337 if (Recurse) recurse_dir(path,entry);
338 else list_dir(entry);
339 else
340 list_file(entry);
342 else
344 if (Read_Dir)
345 fprintf (STDERR, "Directory");
346 else
347 fprintf (STDERR, "File");
348 fprintf (STDERR, " %s not found\n", path);
349 exit(-1);
351 return 0;
355 struct dir_entry *look_up(path)
356 char *path;
358 /* Lookup a file name */
360 struct dir_entry *dir_ptr;
361 long block;
362 int nr_of_blocks;
363 int offset;
364 char name[MAX_NAME_LENGTH + 1];
365 int name_index = 0;
366 int last_in_path = 0;
367 int found;
368 int i,j;
370 /* Get the right dir entry structure */
371 if (Iso9660)
372 dir_ptr = (struct dir_entry *) Iso_Vol_Desc->root_dir_entry;
373 else
374 dir_ptr = (struct dir_entry *) Hs_Vol_Desc->root_dir_entry;
376 /* If we look for the root we already have the right entry */
377 if (path[0] == '/')
378 if (strlen(path) == 1) return dir_ptr;
379 else name_index = 1; /* first name in path */
381 /* Keep searching for the path elements until all are found */
382 while (!last_in_path)
384 /* Get next name in path */
385 for (i = name_index; i < strlen(path); i++)
387 if (path[i] == '/') break;
388 name[i - name_index] = path[i];
390 last_in_path =
391 (i == strlen(path) || (i == strlen(path) - 1 && path[i] == '/'));
392 name[i-name_index] = '\0';
393 name_index = i + 1;
395 /* Get block of next directory */
396 block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
397 nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
399 /* Search for file in dir entry */
400 found = 0;
401 for (j=0; j < nr_of_blocks && !found; j++)
403 /* Read a directory block */
404 read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
405 block++;
407 dir_ptr = (struct dir_entry *) Buffer;
409 offset = 0;
410 /* Compare with all entries in this block */
411 while (iso_711(dir_ptr->length) > 0 && offset < BLOCK_SIZE)
413 if (iso_cmp(name, dir_ptr,
414 (Read_Dir || (!Read_Dir && !last_in_path))) == 0)
416 found = 1;
417 break;
419 /* Next entry */
420 offset += iso_711(dir_ptr->length);
421 dir_ptr = (struct dir_entry *) (Buffer + offset);
424 if (!found) return NULL_DIR; /* path element not found */
426 return dir_ptr;
430 void recurse_dir(path, dir_ptr)
431 char *path;
432 struct dir_entry *dir_ptr;
434 /* Recursively descend all directories starting with dir_ptr */
436 char tmp_path[MAX_PATH_LENGTH];
437 int i,j, path_length;
438 long block, saveblock, dblock;
439 int nr_of_blocks;
440 int offset = 0;
443 /* Save block number and nr of blocks of current dir entry because
444 * list_dir changes dir_ptr
446 block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
447 nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
449 /* Add a trailing / to path if necessary */
450 path_length = strlen(path);
451 if (path[path_length-1] != '/')
453 path[path_length++] = '/';
454 path[path_length] = '\0';
457 /* Print current path of directory, and list contents of directory */
458 fprintf(STDOUT,"directory %s:\n\n", path);
459 list_dir(dir_ptr);
460 fprintf(STDOUT,"\n\n");
462 for (j=0; j < nr_of_blocks; j++)
464 read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
465 saveblock = block++;
467 /* Save buffer, because the next recursive call destroys
468 * the global Buffer
470 dir_ptr = (struct dir_entry *) Buffer;
472 /* Search this dir entry for directories */
473 offset = 0;
474 while (iso_711(dir_ptr->length) != 0 && offset < BLOCK_SIZE)
476 /* Is current file a directory and not the . or .. entries */
477 if (IS_DIR(dir_ptr) && !IS_DOT(dir_ptr) && !IS_DOT_DOT(dir_ptr))
479 /* setup path for next recursive call */
480 for (i=0; i<path_length; i++) tmp_path[i] = path[i];
481 for (i=0;i<iso_711(dir_ptr->name_length) && dir_ptr->name[i] != ';';i++)
482 tmp_path[i+path_length] = LOWER_CASE(dir_ptr->name[i]);
483 tmp_path[i+path_length] = '/';
484 tmp_path[i+1+path_length] = '\0';
486 /* Read block of directory we found */
487 dblock = iso_733(dir_ptr->first_block);
488 read_device(dblock*BLOCK_SIZE, BLOCK_SIZE, Buffer);
490 /* And start all over again with this entry */
491 recurse_dir(tmp_path, (struct dir_entry *) Buffer);
493 /* get the block we were looking at */
494 read_device(saveblock*BLOCK_SIZE, BLOCK_SIZE, Buffer);
497 /* Go to the next file in this directory */
498 offset += iso_711(dir_ptr->length);
499 dir_ptr = (struct dir_entry *) (Buffer + offset);
505 void list_dir(dir_ptr)
506 struct dir_entry *dir_ptr;
508 /* List all entries in a directory */
509 int tty;
510 long block;
511 int nr_of_blocks;
512 int i,j;
513 int offset = 0;
514 char name[NR_OF_CHARS+NR_OF_BLANKS+1];
515 int name_len;
516 int column = 0;
517 int skip = 0;
519 tty = isatty(STDOUT_FILENO);
520 /* Get first block of directory */
521 block = iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length);
522 nr_of_blocks = (iso_733(dir_ptr->size) + (BLOCK_SIZE-1)) >> BLOCK_SHIFT;
524 /* Read all directory blocks and display their contents */
525 for (j=0; j < nr_of_blocks; j++)
527 read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
528 block++;
530 dir_ptr = (struct dir_entry *) (Buffer);
531 offset = 0;
532 while (iso_711(dir_ptr->length) != 0 && offset < BLOCK_SIZE)
534 name_len = 0;
535 if (IS_DOT(dir_ptr))
537 name[name_len++] = '.';
538 if (!Verbose) skip = 1;
540 else
542 if (IS_DOT_DOT(dir_ptr))
544 name[name_len++] = '.';
545 name[name_len++] = '.';
546 if (!Verbose) skip = 1;
548 else
550 for (i=0; i<iso_711(dir_ptr->name_length) &&
551 i<NR_OF_CHARS; i++)
553 if (dir_ptr->name[i] == ';') break;
554 name[name_len++] = LOWER_CASE(dir_ptr->name[i]);
556 if (IS_DIR(dir_ptr) && tty) name[name_len++] = '/';
559 if (!skip)
561 if (ByteOffset)
563 fprintf (STDOUT, "%10ld ",
564 (iso_733(dir_ptr->first_block) + iso_711(dir_ptr->ext_attr_length))
565 * BLOCK_SIZE);
567 if (Verbose || ByteOffset)
569 fprintf (STDOUT, "%10ld ", iso_733(dir_ptr->size));
571 if (Verbose)
573 print_dir_date(dir_ptr->date);
574 fprintf (STDOUT, " ");
576 if(!tty)
577 name[name_len] = '\0';
578 else {
579 for(i=name_len; i<(NR_OF_CHARS+NR_OF_BLANKS); i++) name[i] = ' ';
580 name[NR_OF_CHARS+NR_OF_BLANKS] = '\0';
582 fprintf(STDOUT, "%s", name);
583 if (!(Verbose || ByteOffset))
585 column++;
586 if (column >= NR_OF_COLS || !tty)
588 column = 0;
589 fprintf(STDOUT,"\n");
592 else fprintf(STDOUT,"\n");
594 skip = 0;
595 offset += iso_711(dir_ptr->length);
596 dir_ptr = (struct dir_entry *) (Buffer+offset);
599 if (!Verbose && column) fprintf(STDOUT,"\n");
603 void print_dir_date(date)
604 char *date;
606 /* Print date in a directory entry */
608 int m;
610 m = iso_711(&date[1]) - 1;
611 if(m < 0 || m > 11)
612 fprintf(STDOUT, " ");
613 else
614 fprintf(STDOUT,"%.3s",&months[m*3]);
616 fprintf (STDOUT, " %02d %04d %02d:%02d:%02d",
617 date[2],
618 1900+date[0],
619 date[3],
620 date[4],
621 date[5]);
625 void list_file(dir_ptr)
626 struct dir_entry *dir_ptr;
628 /* List contents of a file */
630 int i;
631 long block;
632 long size;
633 char c;
635 block = iso_733(dir_ptr->first_block);
636 size = iso_733(dir_ptr->size);
638 if (ByteOffset) {
639 fprintf(STDOUT, "%ld %ld\n", block*BLOCK_SIZE, size);
640 return;
643 while (size > 0)
644 if (Aflag == 1) {
645 read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
646 for (i=0; ((i < size) && (i < BLOCK_SIZE)); i++)
647 if (Buffer[i] != '\r') fprintf(STDOUT, "%c", Buffer[i]);
648 size-= BLOCK_SIZE;
649 block++;
650 } else {
651 read_device(block*BLOCK_SIZE, BLOCK_SIZE, Buffer);
652 for (i=0; ((i < size) && (i < BLOCK_SIZE)); i++)
653 fprintf(STDOUT, "%c", Buffer[i]);
654 size-= BLOCK_SIZE;
655 block++;
660 void print_date(date)
661 char *date;
663 /* Print the date in a volume descriptor */
665 fprintf (STDOUT, "%c%c-%c%c-%c%c%c%c %c%c:%c%c:%c%c",
666 date[4],
667 date[5],
668 date[6],
669 date[7],
670 date[0],
671 date[1],
672 date[2],
673 date[3],
674 date[8],
675 date[9],
676 date[10],
677 date[11],
678 date[12],
679 date[13]);
682 void iso_info(vol_desc)
683 struct iso9660_descriptor *vol_desc;
685 int i;
687 fprintf (STDOUT, "Format: ISO9660 \n");
688 fprintf (STDOUT, "System id: ");
689 for (i=0; i< sizeof(vol_desc->system_id); i++)
690 fprintf(STDOUT, "%c", vol_desc->system_id[i]);
691 fprintf (STDOUT, "\n");
692 fprintf (STDOUT, "Volume id: ");
693 for (i=0; i< sizeof(vol_desc->volume_id); i++)
694 fprintf(STDOUT, "%c", vol_desc->volume_id[i]);
695 fprintf (STDOUT, "\n");
696 fprintf (STDOUT, "Volume size: %ld Kb\n", iso_733(vol_desc->volume_size)*2);
697 fprintf (STDOUT, "Block size: %d bytes \n", iso_723(vol_desc->block_size));
698 fprintf (STDOUT, "Creation date: ");
699 print_date(vol_desc->creation_date);
700 fprintf(STDOUT, "\n");
701 fprintf (STDOUT, "Modification date: ");
702 print_date(vol_desc->mod_date);
703 fprintf (STDOUT, "\n");
704 fprintf (STDOUT, "Expiration date: ");
705 print_date(vol_desc->exp_date);
706 fprintf (STDOUT, "\n");
707 fprintf (STDOUT, "Effective date: ");
708 print_date(vol_desc->eff_date);
709 fprintf (STDOUT, "\n");
713 void hs_info(vol_desc)
714 struct high_sierra_descriptor *vol_desc;
716 int i;
718 fprintf (STDOUT, "Format: HIGH SIERRA \n");
719 fprintf (STDOUT, "System id: ");
720 for (i=0; i< sizeof(vol_desc->system_id); i++)
721 fprintf(STDOUT, "%c", vol_desc->system_id[i]);
722 fprintf (STDOUT, "\n");
723 fprintf (STDOUT, "Volume id: ");
724 for (i=0; i< sizeof(vol_desc->volume_id); i++)
725 fprintf(STDOUT, "%c", vol_desc->volume_id[i]);
726 fprintf (STDOUT, "\n");
727 fprintf (STDOUT, "Volume size: %ld Kb\n", (iso_733(vol_desc->volume_size)*2));
728 fprintf (STDOUT, "Block size: %d bytes \n", iso_723(vol_desc->block_size));
732 int valid_fs()
735 int i;
737 /* search for a volume descriptor */
738 for (i=16; i<100; i++)
741 read_device((long)(i)*BLOCK_SIZE, BLOCK_SIZE, Buffer);
743 Iso_Vol_Desc = (struct iso9660_descriptor *) Buffer;
744 Hs_Vol_Desc = (struct high_sierra_descriptor *) Buffer;
746 if (strncmp(Iso_Vol_Desc->id, ISO9660_ID, sizeof Iso_Vol_Desc->id) == 0)
748 /* iso_info(Iso_Vol_Desc); */
749 Iso9660 = 1;
750 break;
753 if (strncmp(Hs_Vol_Desc->id, HIGH_SIERRA_ID, sizeof Hs_Vol_Desc->id) == 0)
755 /* hs_info(Hs_Vol_Desc); */
756 High_Sierra = 1;
757 break;
761 if (i >= 100) return 0;
762 return 1;
766 void read_device(offset, nr_of_bytes, buffer)
767 long offset;
768 int nr_of_bytes;
769 char *buffer;
771 int bytes_read;
773 if (lseek(Device, offset, SEEK_SET) == -1)
775 fflush (stdout);
776 fprintf (STDERR, "seek error: %s\n", strerror(errno));
777 exit(1);
780 bytes_read = read(Device, buffer, nr_of_bytes);
781 if (bytes_read != nr_of_bytes)
783 fprintf (STDERR, "read error: %s\n",
784 bytes_read >= 0 ? "Short read" : strerror(errno));
785 exit (1);
790 /* The ISO9660 functions */
792 int iso_711 (c)
793 char *c;
795 return (*c & 0xff);
799 int iso_712 (c)
800 char *c;
802 int n;
804 n = *c;
805 if (n & 0x80) n |= 0xffffff00;
806 return n;
809 int iso_721 (c)
810 char *c;
812 return ((c[0] & 0xff) | ((c[1] & 0xff) << 8));
815 int iso_722 (c)
816 char *c;
818 return (((c[0] & 0xff) << 8) | (c[1] & 0xff));
821 int iso_723 (c)
822 char *c;
824 if (c[0] != c[3] || c[1] != c[2])
826 fprintf (STDERR, "Invalid ISO 7.2.3 number\n");
827 exit (1);
829 return (iso_721 (c));
832 long iso_731 (c)
833 char *c;
835 return ((long)(c[0] & 0xff)
836 | ((long)(c[1] & 0xff) << 8)
837 | ((long)(c[2] & 0xff) << 16)
838 | ((long)(c[3] & 0xff) << 24));
842 long iso_732 (c)
843 char *c;
845 return (((long)(c[0] & 0xff) << 24)
846 | (((long)c[1] & 0xff) << 16)
847 | (((long)c[2] & 0xff) << 8)
848 | ((long)c[3] & 0xff));
851 long iso_733 (c)
852 char *c;
854 int i;
856 for (i = 0; i < 4; i++)
858 if (c[i] != c[7-i])
860 fprintf (STDERR, "Invalid ISO 7.3.3 number\n");
861 exit (1);
864 return (iso_731(c));