1 /* ------------------------------------------------------------------------ */
3 /* header.c -- header manipulate functions */
5 /* Modified Nobutaka Watazaki */
7 /* Original Y.Tagawa */
8 /* modified 1991.12.16 M.Oki */
9 /* Ver. 1.10 Symbolic Link added 1993.10.01 N.Watazaki */
10 /* Ver. 1.13b Symbolic Link Bug Fix 1994.08.22 N.Watazaki */
11 /* Ver. 1.14 Source All chagned 1995.01.14 N.Watazaki */
12 /* Ver. 1.14e bug fixed 1999.05.27 T.Okamoto */
13 /* ------------------------------------------------------------------------ */
16 /* ------------------------------------------------------------------------ */
18 /* ------------------------------------------------------------------------ */
26 for (sum = 0; len; len--)
32 /* ------------------------------------------------------------------------ */
40 return (b1 << 8) + b0;
43 /* ------------------------------------------------------------------------ */
52 /* ------------------------------------------------------------------------ */
62 return (b3 << 24) + (b2 << 16) + (b1 << 8) + b0;
65 /* ------------------------------------------------------------------------ */
76 /* ------------------------------------------------------------------------ */
78 msdos_to_unix_filename(name, len)
84 #define X0201_KANA_P(c)\
85 (0xa0 < (unsigned char)(c) && (unsigned char)(c) < 0xe0)
89 for (i = 0; i < len; i++) {
90 /* modified by Koji Arai */
91 if (X0201_KANA_P(name[i])) {
93 for (j = len; j >= i; j--) {
94 name[j+1] = name[j]; /* no check over */
100 if (MULTIBYTE_FIRST_P(name[i]) &&
101 MULTIBYTE_SECOND_P(name[i + 1])) {
103 c1 = name[i]; c2 = name[i+1];
105 name[i] = c1; name[i+1] = c2;
108 else if (name[i] == '\\')
110 else if (isupper(name[i]))
111 name[i] = tolower(name[i]);
114 for (i = 0; i < len; i++) {
115 if (MULTIBYTE_FIRST_P(name[i]) &&
116 MULTIBYTE_SECOND_P(name[i + 1]))
118 else if (name[i] == '\\')
120 else if (isupper(name[i]))
121 name[i] = tolower(name[i]);
123 #endif /* SUPPORT_X0201 */
125 for (i = 0; i < len; i++) {
128 else if (isupper(name[i]))
129 name[i] = tolower(name[i]);
134 /* ------------------------------------------------------------------------ */
136 generic_to_unix_filename(name, len)
141 boolean lower_case_used = FALSE;
143 #ifdef MULTIBYTE_CHAR
145 for (i = 0; i < len; i++) {
146 /* modified by Koji Arai */
147 if (X0201_KANA_P(name[i])) {
149 for (j = len; j >= i; j--) {
150 name[j+1] = name[j]; /* no check over */
157 if (MULTIBYTE_FIRST_P(name[i]) &&
158 MULTIBYTE_SECOND_P(name[i + 1]))
160 else if (islower(name[i])) {
161 lower_case_used = TRUE;
166 for (i = 0; i < len; i++) {
167 if (MULTIBYTE_FIRST_P(name[i]) &&
168 MULTIBYTE_SECOND_P(name[i + 1]))
170 else if (islower(name[i])) {
171 lower_case_used = TRUE;
175 #endif /* SUPPORT_X0201 */
176 for (i = 0; i < len; i++) {
177 if (MULTIBYTE_FIRST_P(name[i]) &&
178 MULTIBYTE_SECOND_P(name[i + 1]))
180 else if (name[i] == '\\')
182 else if (!lower_case_used && isupper(name[i]))
183 name[i] = tolower(name[i]);
186 for (i = 0; i < len; i++)
187 if (islower(name[i])) {
188 lower_case_used = TRUE;
191 for (i = 0; i < len; i++) {
194 else if (!lower_case_used && isupper(name[i]))
195 name[i] = tolower(name[i]);
200 /* ------------------------------------------------------------------------ */
202 macos_to_unix_filename(name, len)
208 /* modified by Koji Arai */
210 for (i = 0; i < len; i ++) {
211 /* modified by Koji Arai */
212 if (X0201_KANA_P(name[i])) {
214 for (j = len; j >= i; j--) {
215 name[j+1] = name[j]; /* no check over */
222 if (MULTIBYTE_FIRST_P (name[i]) &&
223 MULTIBYTE_SECOND_P (name[i+1])) {
225 c1 = name[i]; c2 = name[i+1];
227 name[i] = c1; name[i+1] = c2;
230 else if (name[i] == ':')
232 else if (name[i] == '/')
235 else if (isupper (name[i]))
236 name[i] = tolower (name[i]);
240 for (i = 0; i < len; i++) {
243 else if (name[i] == '/')
246 #endif /* SUPPORT_X0201 */
249 /* ------------------------------------------------------------------------ */
251 unix_to_generic_filename(name, len)
257 for (i = 0; i < len; i++) {
260 else if (islower(name[i]))
261 name[i] = toupper(name[i]);
265 /* ------------------------------------------------------------------------ */
267 /* Generic stamp format: */
269 /* 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 */
270 /* |<-------- year ------->|<- month ->|<-- day -->| */
272 /* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 */
273 /* |<--- hour --->|<---- minute --->|<- second*2 ->| */
275 /* ------------------------------------------------------------------------ */
278 * NOTE : If you don't have `gettimeofday(2)', or your gettimeofday(2)
279 * returns bogus timezone information, try FTIME, MKTIME, TIMELOCAL or TZSET.
283 #if defined(HAVE_MKTIME)
284 #ifdef HAVE_TIMELOCAL
285 #undef HAVE_TIMELOCAL
287 #endif /* defined(HAVE_MKTIME) */
289 #if defined(HAVE_MKTIME) || defined(HAVE_TIMELOCAL)
293 #endif /* defined(HAVE_MKTIME) || defined(HAVE_TIMELOCAL) */
295 #if defined(HAVE_MKTIME) || defined(HAVE_TIMELOCAL) || defined(HAVE_TZSET)
301 #if defined(HAVE_MKTIME) || defined(HAVE_TIMELOCAL) || defined(HAVE_TZSET) || defined(HAVE_FTIME)
302 #ifdef HAVE_GETTIMEOFDAY
303 #undef HAVE_GETTIMEOFDAY
306 #ifndef HAVE_GETTIMEOFDAY
307 #define HAVE_GETTIMEOFDAY /* use gettimeofday() */
312 #include <sys/timeb.h>
316 * You may define as : #define TIMEZONE_HOOK \ extern long
317 * timezone ; \ extern void tzset();
321 /* Which do you like better, `TIMEZONE_HOOK' or `TIMEZONE_HOOK;' ? */
324 #if defined(HAVE_TZSET) && defined(_MINIX)
325 extern long timezone; /* not defined in time.h */
328 /* ------------------------------------------------------------------------ */
329 #if defined(HAVE_FTIME) || defined(HAVE_GETTIMEOFDAY) || defined(HAVE_TZSET)
339 /* ------------------------------------------------------------------------ */
340 #if !defined(HAVE_TZSET) && defined(HAVE_FTIME)
345 return buf.timezone * 60L;
349 /* ------------------------------------------------------------------------ */
350 #if !defined(HAVE_TZSET) && !defined(HAVE_FTIME) /* maybe defined(HAVE_GETTIMEOFDAY) */
352 #ifdef HAVE_TM_GMTOFF
356 return -localtime(&tt)->tm_gmtoff;
357 #else /* HAVE_TM_GMTOFF */
360 gettimeofday(&tp, &tzp);/* specific to 4.3BSD */
362 * return (tzp.tz_minuteswest * 60L + (tzp.tz_dsttime != 0 ? 60L *
365 return (tzp.tz_minuteswest * 60L);
366 #endif /* HAVE_TM_GMTOFF */
369 #endif /* defined(HAVE_FTIME) || defined(HAVE_GETTIMEOFDAY) ||
370 * defined(HAVE_TZSET) */
372 /* ------------------------------------------------------------------------ */
375 msdos_to_unix_stamp_tm(a)
380 t.tm_sec = (a & 0x1f) * 2;
381 t.tm_min = (a >> 5) & 0x3f;
382 t.tm_hour = (a >> 11) & 0x1f;
383 t.tm_mday = (a >> 16) & 0x1f;
384 t.tm_mon = ((a >> 16 + 5) & 0x0f) - 1;
385 t.tm_year = ((a >> 16 + 9) & 0x7f) + 80;
390 /* ------------------------------------------------------------------------ */
392 generic_to_unix_stamp(t)
394 #if defined(HAVE_MKTIME) || defined(HAVE_TIMELOCAL)
399 * special case: if MSDOS format date and time were zero, then we
400 * set time to be zero here too.
405 dostm.tm_sec = (t & 0x1f) * 2;
406 dostm.tm_min = t >> 5 & 0x3f;
407 dostm.tm_hour = t >> 11 & 0x1f;
408 dostm.tm_mday = t >> 16 & 0x1f;
409 dostm.tm_mon = (t >> 16 + 5 & 0x0f) - 1; /* 0..11 */
410 dostm.tm_year = (t >> 16 + 9 & 0x7f) + 80;
412 dostm.tm_isdst = 0; /* correct? */
414 dostm.tm_isdst = -1; /* correct? */
416 return (time_t) mktime(&dostm);
417 #else /* maybe defined(HAVE_TIMELOCAL) */
418 return (time_t) timelocal(&dostm);
422 #else /* defined(HAVE_MKTIME) || defined(HAVE_TIMELOCAL) */
424 int year, month, day, hour, min, sec;
426 static unsigned int dsboy[12] = {0, 31, 59, 90, 120, 151,
427 181, 212, 243, 273, 304, 334};
431 * special case: if MSDOS format date and time were zero, then we
432 * set time to be zero here too.
437 year = ((int) (t >> 16 + 9) & 0x7f) + 1980;
438 month = (int) (t >> 16 + 5) & 0x0f; /* 1..12 means Jan..Dec */
439 day = (int) (t >> 16) & 0x1f; /* 1..31 means 1st,...31st */
441 hour = ((int) t >> 11) & 0x1f;
442 min = ((int) t >> 5) & 0x3f;
443 sec = ((int) t & 0x1f) * 2;
445 /* Calculate days since 1970.01.01 */
446 days = (365 * (year - 1970) + /* days due to whole years */
447 (year - 1970 + 1) / 4 + /* days due to leap years */
448 dsboy[month - 1] + /* days since beginning of this year */
449 day - 1); /* days since beginning of month */
451 if ((year % 4 == 0) &&
452 (year % 100 != 0 || year % 400 == 0) && /* 1999.5.24 t.oka */
453 (month >= 3)) /* if this is a leap year and month */
454 days++; /* is March or later, add a day */
456 /* Knowing the days, we can find seconds */
457 longtime = (((days * 24) + hour) * 60 + min) * 60 + sec;
458 longtime += gettz(); /* adjust for timezone */
460 /* LONGTIME is now the time in seconds, since 1970/01/01 00:00:00. */
461 return (time_t) longtime;
463 #endif /* defined(HAVE_MKTIME) || defined(HAVE_TIMELOCAL) */
465 /* ------------------------------------------------------------------------ */
467 unix_to_generic_stamp(t)
470 struct tm *tm = localtime(&t);
472 return ((((long) (tm->tm_year - 80)) << 25) +
473 (((long) (tm->tm_mon + 1)) << 21) +
474 (((long) tm->tm_mday) << 16) +
475 (long) ((tm->tm_hour << 11) +
480 /* ------------------------------------------------------------------------ */
481 /* build header functions */
482 /* ------------------------------------------------------------------------ */
486 register LzHeader *hdr;
490 char data[LZHEADER_STRAGE];
491 char dirname[FILENAME_LENGTH];
499 bzero(hdr, sizeof(LzHeader));
501 if (((header_size = getc(fp)) == EOF) || (header_size == 0)) {
502 return FALSE; /* finish */
505 if (fread(data + I_HEADER_CHECKSUM,
506 sizeof(char), header_size - 1, fp) < header_size - 1) {
507 fatal_error("Invalid header (LHarc file ?)");
508 return FALSE; /* finish */
510 setup_get(data + I_HEADER_LEVEL);
511 hdr->header_level = get_byte();
512 if (hdr->header_level != 2 &&
513 fread(data + header_size, sizeof(char), 2, fp) < 2) {
514 fatal_error("Invalid header (LHarc file ?)");
515 return FALSE; /* finish */
518 if (hdr->header_level >= 3) {
519 fatal_error("Unknown level header");
523 setup_get(data + I_HEADER_CHECKSUM);
524 checksum = get_byte();
526 hdr->header_size = header_size;
527 bcopy(data + I_METHOD, hdr->method, METHOD_TYPE_STRAGE);
528 setup_get(data + I_PACKED_SIZE);
529 hdr->packed_size = get_longword();
530 hdr->original_size = get_longword();
531 hdr->last_modified_stamp = get_longword();
532 hdr->attribute = get_byte();
534 if ((hdr->header_level = get_byte()) != 2) {
535 if (calc_sum(data + I_METHOD, header_size) != checksum)
536 warning("Checksum error (LHarc file?)", "");
537 name_length = get_byte();
538 for (i = 0; i < name_length; i++)
539 hdr->name[i] = (char) get_byte();
540 hdr->name[name_length] = '\0';
543 hdr->unix_last_modified_stamp = hdr->last_modified_stamp;
547 /* defaults for other type */
548 hdr->unix_mode = UNIX_FILE_REGULAR | UNIX_RW_RW_RW;
553 if (hdr->header_level == 0) {
554 extend_size = header_size - name_length -22;
555 if (extend_size < 0) {
556 if (extend_size == -2) {
557 hdr->extend_type = EXTEND_GENERIC;
558 hdr->has_crc = FALSE;
560 fatal_error("Unkonwn header (lha file?)");
565 hdr->crc = get_word();
568 if (extend_size >= 1) {
569 hdr->extend_type = get_byte();
572 if (hdr->extend_type == EXTEND_UNIX) {
573 if (extend_size >= 11) {
574 hdr->minor_version = get_byte();
575 hdr->unix_last_modified_stamp = (time_t) get_longword();
576 hdr->unix_mode = get_word();
577 hdr->unix_uid = get_word();
578 hdr->unix_gid = get_word();
581 hdr->extend_type = EXTEND_GENERIC;
584 while (extend_size-- > 0)
586 if (hdr->extend_type == EXTEND_UNIX)
588 } else if (hdr->header_level == 1) {
590 extend_size = header_size - name_length-25;
591 hdr->crc = get_word();
592 hdr->extend_type = get_byte();
593 while (extend_size-- > 0)
595 } else { /* level 2 */
597 hdr->crc = get_word();
598 hdr->extend_type = get_byte();
601 if (hdr->header_level > 0) {
603 if (hdr->header_level != 2)
604 setup_get(data + hdr->header_size);
606 while ((header_size = get_word()) != 0) {
607 if (hdr->header_level != 2 &&
608 ((data + LZHEADER_STRAGE - get_ptr < header_size) ||
609 fread(get_ptr, sizeof(char), header_size, fp) < header_size)) {
610 fatal_error("Invalid header (LHa file ?)");
613 switch (get_byte()) {
618 setup_get(get_ptr + header_size - 3);
624 for (i = 0; i < header_size - 3; i++)
625 hdr->name[i] = (char) get_byte();
626 hdr->name[header_size - 3] = '\0';
627 name_length = header_size - 3; /* modified by Koji Arai */
633 for (i = 0; i < header_size - 3; i++)
634 dirname[i] = (char) get_byte();
635 dirname[header_size - 3] = '\0';
636 convdelim(dirname, DELIM);
637 dir_length = header_size - 3;
643 if (hdr->extend_type == EXTEND_MSDOS ||
644 hdr->extend_type == EXTEND_HUMAN ||
645 hdr->extend_type == EXTEND_GENERIC)
646 hdr->attribute = get_word();
652 if (hdr->extend_type == EXTEND_UNIX)
653 hdr->unix_mode = get_word();
659 if (hdr->extend_type == EXTEND_UNIX) {
660 hdr->unix_gid = get_word();
661 hdr->unix_uid = get_word();
668 setup_get(get_ptr + header_size - 3);
674 setup_get(get_ptr + header_size - 3);
678 * UNIX last modified time
680 if (hdr->extend_type == EXTEND_UNIX)
681 hdr->unix_last_modified_stamp = (time_t) get_longword();
687 setup_get(get_ptr + header_size - 3);
691 if (hdr->header_level != 2 && get_ptr - ptr != 2) {
692 hdr->packed_size -= get_ptr - ptr - 2;
693 hdr->header_size += get_ptr - ptr - 2;
697 strcat(dirname, hdr->name);
698 strcpy(hdr->name, dirname);
699 name_length += dir_length;
702 switch (hdr->extend_type) {
704 msdos_to_unix_filename(hdr->name, name_length);
706 if (hdr->header_level == 2)
707 hdr->unix_last_modified_stamp = hdr->last_modified_stamp;
709 hdr->unix_last_modified_stamp =
710 generic_to_unix_stamp(hdr->last_modified_stamp);
721 macos_to_unix_filename(hdr->name, name_length);
722 hdr->unix_last_modified_stamp =
723 generic_to_unix_stamp(hdr->last_modified_stamp);
727 generic_to_unix_filename(hdr->name, name_length);
728 if (hdr->header_level == 2)
729 hdr->unix_last_modified_stamp = hdr->last_modified_stamp;
731 hdr->unix_last_modified_stamp =
732 generic_to_unix_stamp(hdr->last_modified_stamp);
736 printf("header level=%d\n", hdr->header_level); fflush(stdout);
742 /* ------------------------------------------------------------------------ */
744 init_header(name, v_stat, hdr)
751 if (compress_method == LZHUFF5_METHOD_NUM) /* Changed N.Watazaki */
752 bcopy(LZHUFF5_METHOD, hdr->method, METHOD_TYPE_STRAGE);
753 else if (compress_method)
754 bcopy(LZHUFF1_METHOD, hdr->method, METHOD_TYPE_STRAGE);
756 bcopy(LZHUFF0_METHOD, hdr->method, METHOD_TYPE_STRAGE);
758 hdr->packed_size = 0;
759 hdr->original_size = v_stat->st_size;
760 hdr->last_modified_stamp = unix_to_generic_stamp(v_stat->st_mtime);
761 hdr->attribute = GENERIC_ATTRIBUTE;
762 hdr->header_level = header_level;
763 strcpy(hdr->name, name);
766 hdr->extend_type = EXTEND_UNIX;
767 hdr->unix_last_modified_stamp = v_stat->st_mtime;
768 /* since 00:00:00 JAN.1.1970 */
769 #ifdef NOT_COMPATIBLE_MODE
770 /* Please need your modification in this space. */
772 hdr->unix_mode = v_stat->st_mode;
775 hdr->unix_uid = v_stat->st_uid;
776 hdr->unix_gid = v_stat->st_gid;
778 if (is_directory(v_stat)) {
779 bcopy(LZHDIRS_METHOD, hdr->method, METHOD_TYPE_STRAGE);
780 hdr->attribute = GENERIC_DIRECTORY_ATTRIBUTE;
781 hdr->original_size = 0;
782 if (len > 0 && hdr->name[len - 1] != '/')
783 strcpy(&hdr->name[len++], "/");
787 if (is_symlink(v_stat)) {
790 bcopy(LZHDIRS_METHOD, hdr->method, METHOD_TYPE_STRAGE);
791 hdr->attribute = GENERIC_DIRECTORY_ATTRIBUTE;
792 hdr->original_size = 0;
793 len = readlink(name, lkname, 256);
794 lkname[len] = (char)'\0';
795 sprintf(hdr->name, "%s|%s", hdr->name, lkname);
799 unix_to_generic_filename(hdr->name, len);
802 /* ------------------------------------------------------------------------ */
803 /* Write unix extended header or generic header. */
805 write_header(nafp, hdr)
811 char data[LZHEADER_STRAGE];
815 bzero(data, LZHEADER_STRAGE);
816 bcopy(hdr->method, data + I_METHOD, METHOD_TYPE_STRAGE);
817 setup_put(data + I_PACKED_SIZE);
818 put_longword(hdr->packed_size);
819 put_longword(hdr->original_size);
821 if (hdr->header_level == HEADER_LEVEL2)
822 put_longword((long) hdr->unix_last_modified_stamp);
824 put_longword(hdr->last_modified_stamp);
826 switch (hdr->header_level) {
828 put_byte(hdr->attribute);
836 put_byte(hdr->header_level);
838 convdelim(hdr->name, DELIM2);
839 if (hdr->header_level != HEADER_LEVEL2) {
840 if (p = (char *) strrchr(hdr->name, DELIM2))
841 name_length = strlen(++p);
843 name_length = strlen(hdr->name);
844 put_byte(name_length);
845 bcopy(p ? p : hdr->name, data + I_NAME, name_length);
846 setup_put(data + I_NAME + name_length);
850 if (header_level == HEADER_LEVEL0) {
851 if (generic_format) {
852 header_size = I_GENERIC_HEADER_BOTTOM - 2 + name_length;
853 data[I_HEADER_SIZE] = header_size;
854 data[I_HEADER_CHECKSUM] = calc_sum(data + I_METHOD, header_size);
856 /* write old-style extend header */
857 put_byte(EXTEND_UNIX);
858 put_byte(CURRENT_UNIX_MINOR_VERSION);
859 put_longword((long) hdr->unix_last_modified_stamp);
860 put_word(hdr->unix_mode);
861 put_word(hdr->unix_uid);
862 put_word(hdr->unix_gid);
863 header_size = I_UNIX_EXTEND_BOTTOM - 2 + name_length;
864 data[I_HEADER_SIZE] = header_size;
865 data[I_HEADER_CHECKSUM] = calc_sum(data + I_METHOD, header_size);
868 /* write extend header. */
874 put_byte(EXTEND_UNIX);
877 if (hdr->header_level == HEADER_LEVEL2) {
878 /* write common header */
881 headercrc_ptr = put_ptr;
885 if (generic_format) {
886 header_size = put_ptr - data; /* +2 for last 0x0000 */
889 if (hdr->header_level == HEADER_LEVEL1)
890 header_size = put_ptr - data - 2;
891 put_byte(0x50); /* permission */
892 put_word(hdr->unix_mode);
894 put_byte(0x51); /* gid and uid */
895 put_word(hdr->unix_gid);
896 put_word(hdr->unix_uid);
898 if (p = (char *) strrchr(hdr->name, DELIM2)) {
901 name_length = p - hdr->name + 1;
902 put_word(name_length + 3);
903 put_byte(2); /* dirname */
904 for (i = 0; i < name_length; i++)
905 put_byte(hdr->name[i]);
907 } /* if generic .. */
909 if (header_level != HEADER_LEVEL2) {
910 if (!generic_format) {
912 put_byte(0x54); /* time stamp */
913 put_longword(hdr->unix_last_modified_stamp);
915 hdr->packed_size += put_ptr - ptr;
917 setup_put(data + I_PACKED_SIZE);
918 put_longword(hdr->packed_size);
920 data[I_HEADER_SIZE] = header_size;
921 data[I_HEADER_CHECKSUM] = calc_sum(data + I_METHOD, header_size);
922 } else { /* header level 2 */
924 if (p = (char *) strrchr(hdr->name, DELIM2))
925 name_length = strlen(++p);
928 name_length = strlen(hdr->name);
930 put_word(name_length + 3);
931 put_byte(1); /* filename */
932 for (i = 0; i < name_length; i++)
934 } /* if he.. != HEAD_LV2 */
935 header_size = put_ptr - data;
938 if (header_level == HEADER_LEVEL2) {
940 setup_put(data + I_HEADER_SIZE);
941 put_word(header_size + 2);
943 hcrc = calc_header_crc(data, (unsigned int) header_size + 2);
944 setup_put(headercrc_ptr);
948 if (fwrite(data, sizeof(char), header_size + 2, nafp) == 0)
949 fatal_error("Cannot write to temporary file");
951 convdelim(hdr->name, DELIM);
956 * SJIS <-> EUC ÊÑ´¹´Ø¿ô
957 * ¡ÖÆüËܸì¾ðÊó½èÍý¡× ¥½¥Õ¥È¥Ð¥ó¥¯(³ô)
958 * ¤è¤êÈ´¿è(by Koji Arai)
961 euc2sjis(int *p1, int *p2)
963 unsigned char c1 = *p1 & 0x7f;
964 unsigned char c2 = *p2 & 0x7f;
965 int rowoff = c1 < 0x5f ? 0x70 : 0xb0;
966 int celoff = c1 % 2 ? (c2 > 0x5f ? 0x20 : 0x1f) : 0x7e;
967 *p1 = ((c1 + 1) >> 1) + rowoff;
968 *p2 += celoff - 0x80;
972 sjis2euc(int *p1, int *p2)
974 unsigned char c1 = *p1;
975 unsigned char c2 = *p2;
976 int adjust = c2 < 0x9f;
977 int rowoff = c1 < 0xa0 ? 0x70 : 0xb0;
978 int celoff = adjust ? (c2 > 0x7f ? 0x20 : 0x1f) : 0x7e;
979 *p1 = ((c1 - rowoff) << 1) - adjust;
985 #endif /* SUPPORT_X0201 */
987 /* Local Variables: */