home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 January / VPR0101A.BIN / OLS / TAR32053 / tar32053.exe / SRC / CHKFNAME.C < prev    next >
C/C++ Source or Header  |  1999-05-23  |  16KB  |  780 lines

  1. #ifndef __DEFCONF_H
  2. #include "defconf.h"
  3. #endif
  4. /*
  5.    This file was hacked for kmtar for WIN32
  6.                                     at 1996-05-06.
  7.                                     by tantan SGL00213@niftyserve.or.jp 
  8. */
  9. /*
  10.  *    chkfname - check & rename file name to MS-DOS style
  11.  *
  12.  *    Written by AssistantIO
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <ctype.h>
  17. #include <sys/types.h>
  18. #include <sys/stat.h>
  19. #include <stdlib.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <string.h>
  23. #include "defs.h"
  24. #include "chkfname.h"
  25. #include "misc.h"
  26.  
  27. #define USE_QSORT 1
  28. #include <direct.h>
  29. #if USE_QSORT
  30.     #include    <search.h>
  31. #endif
  32. #undef    tolower
  33.  
  34.  
  35. struct _rename_t {
  36.     char *org_name;
  37.     char *new_name;
  38.     int dir_p;
  39.     struct _rename_t *next;
  40. };
  41.  
  42. typedef struct _rename_t rename_t;
  43.  
  44.  
  45. #define NAMLEN 300
  46. #define NAMLEN_NT 256
  47. #define MAX_NAM 8
  48. #define MAX_EXT 3
  49.  
  50. #define    NO    0
  51. #define YES 1
  52.  
  53.  
  54.  
  55. #define    is_pathchar(c)    ((c) == '\\' || (c) == '/')
  56.  
  57. static int register_rename_table(char *org_name, int dir_p, char *new_name);
  58. static char *search_orgname(char *org_name, int dir_p);
  59. static char *search_newname(char *new_name);
  60. static char *make_new_fname(char *newname, char *name, int make_new, int dir_p);
  61. static int last_char(char *p);
  62. static char *normalize_fname(char *destin, char *source, int dir_p);
  63. static char *trim_jstr(char *p, char *q, int len);
  64. static int is_dir(char *filename);
  65. static int is_character_device(char *name);
  66.  
  67. void erase_rename_table(void);
  68. static int out_of_memory=0;
  69.  
  70. void em_erase_rename_table(void)
  71. {
  72.     out_of_memory = 1;
  73.     fputs("\aError Out of memory !! file name check will not work\n",stderr);
  74.     fputs("\t -------  Hit RET Key for continue. -------",stderr);
  75.     getchar();
  76. /*    fputs("\t OK !. Now erase the wast array.\n",stderr);*/
  77.     erase_rename_table();
  78. }
  79.  
  80. global void check_fname(char *dest, char *sour, int make_new, int dir_p)
  81. {
  82.     char *p;
  83.  
  84.     if ((p = search_orgname(sour, dir_p)) != NULL) {
  85.         strcpy((char *)dest, p);
  86.         return;
  87.     }
  88.     
  89.     if (make_new_fname(dest, sour, make_new, dir_p) == NULL) {
  90.         strcpy(dest, sour);
  91.     }
  92.     if (out_of_memory)
  93.         return;
  94.  
  95.     if (register_rename_table(sour, dir_p, dest) == NO){
  96.         em_erase_rename_table();
  97.     }
  98. }
  99.  
  100. static rename_t *rename_table = NULL;
  101.  
  102.  
  103. static int
  104. register_rename_table(char *org_name, int dir_p, char *new_name) {
  105.     rename_t *nt;
  106.  
  107.     if ((nt = (rename_t  *)malloc((unsigned int)sizeof(rename_t))) == NULL) {
  108.         return NO;
  109.     }
  110.     if ((nt->org_name = strdup((char *)org_name)) == NULL) {
  111.         return NO;
  112.     }
  113.     if ((nt->new_name = strdup((char *)new_name)) == NULL) {
  114.         return NO;
  115.     }
  116.     nt->dir_p = dir_p;
  117.     nt->next = rename_table;
  118.     rename_table = nt;
  119.     
  120.     return YES;
  121. }
  122.  
  123. void erase_rename_table(void) /* tantan */
  124. {
  125.     rename_t *nt, *bt;
  126.  
  127.     for (nt = rename_table; nt != NULL;) {
  128.         free(nt->org_name);
  129.         free(nt->new_name);
  130.         bt = nt->next;
  131.         free(nt);
  132.         nt = bt;
  133.     }
  134.     rename_table = NULL;
  135. }
  136.  
  137. int chk_rename_table()
  138. {    return rename_table==NULL ? 0:1; }
  139.  
  140. static char *
  141. search_orgname(char *org_name, int dir_p) {
  142.     rename_t *nt;
  143.  
  144.     for (nt = rename_table; nt != NULL; nt = nt->next) {
  145.         if (strcmp(org_name, nt->org_name) == 0
  146.             && dir_p == nt->dir_p) {
  147.             return nt->new_name;
  148.         }
  149.     }
  150.     return NULL;
  151. }
  152.  
  153. static char *
  154. search_newname(char *new_name) {
  155.     rename_t *nt;
  156.  
  157.     for (nt = rename_table; nt != NULL; nt = nt->next) {
  158.         if (strcmp(new_name, nt->new_name) == 0) {
  159.             return nt->new_name;
  160.         }
  161.     }
  162.     return NULL;
  163. }
  164.  
  165. static char *
  166. make_new_fname(char *newname, char *name, int make_new, int dir_p) {
  167.     int is_dir();
  168.     char *d, *s, *p, *q, *period;
  169.     char tmpname[NAMLEN], basename[NAMLEN];
  170.     int extent_no;
  171.     struct stat statbuf;
  172.  
  173.     normalize_fname(tmpname, name, dir_p);
  174.  
  175.     d = newname;
  176.     s = tmpname;
  177.     if (isascii(*s) && isalpha(*s) && *(s + 1) ==':') {
  178.         *d++ = *s++;
  179.         *d++ = *s++;
  180.     }
  181.     while (*s != '\0') {
  182.         if (is_pathchar(*s)) {
  183.             *d++ = *s++;
  184.         }
  185.         if (*s == '.' && *(s + 1) == '.' && is_pathchar(*(s + 2))) {  /* ..\  */
  186.             *d++ = *s++;
  187.             *d++ = *s++;
  188.         } else if (*s == '.' && is_pathchar(*(s + 1))) {  /*  .\ */
  189.             *d++ = *s++;
  190.         } else {
  191.             p = d;
  192.             period = NULL;
  193.             while (*s != '\0' && !is_pathchar(*s)) {
  194.                 if (iskanji(*s) && iskanji2(*(s + 1))) {
  195.                     *d++ = *s++;
  196.                     *d++ = *s++;
  197.                 } else if (*s == '.') {
  198.                     period = d;
  199.                     *d++ = *s++;
  200.                 } else {
  201.                     *d++ = *s++;
  202.                 }
  203.             }
  204.             *d = '\0';
  205.             if (dir_p || *s != '\0') {
  206.                 if (strchr("/\\:", last_char(newname)) == NULL
  207.                     && !is_dir(newname)
  208.                     && make_new
  209.                     && mkdir(newname) < 0) {
  210.                         basename[0] = '_';
  211.                         strcpy(basename + 1, p);
  212.                         normalize_fname(p, basename, 1);
  213.                         d = p + strlen(p);
  214.                     if (!is_dir(newname) && mkdir(newname) < 0) {
  215.                             return NULL;
  216.                     }
  217.                 }
  218.             }
  219.         }
  220.     }
  221.     if (dir_p) {
  222.         return newname;
  223.     }
  224. /*    printf("-- %s\n",newname); */
  225.     if (stat(newname, &statbuf) != 0) {
  226.         return newname;
  227.     }
  228.     if (!is_character_device(newname)
  229.         && make_new == 0 && search_newname(newname) == NULL) {
  230.         return newname;
  231.     }
  232.     basename[0] = '_';
  233.     strcpy(basename + 1, p);
  234.     extent_no = -1;
  235.     q = d;
  236.     while (++extent_no < 1000) {
  237.         sprintf(q, ".%03d", extent_no);
  238.         if (stat(newname, &statbuf) != 0) {
  239.             return newname;
  240.         }
  241.         if (is_character_device(newname)) {
  242.             break;
  243.         }
  244.         if (make_new == 0 && search_newname(newname) == NULL) {
  245.             return newname;
  246.         }
  247.     }
  248.     normalize_fname(p, basename, 0);
  249.     if (stat(newname, &statbuf) != 0) {
  250.         return newname;
  251.     }
  252.     if (!is_character_device(newname) && make_new == 0) {
  253.         return newname;
  254.     }
  255.     d = p + strlen(p);
  256.     q = d;
  257.     while (*p != '\0') {
  258.         if (iskanji(*p) && iskanji2(*(p + 1))) {
  259.             p++;
  260.         } else if (*p == '.') {
  261.             q = p;
  262.         }
  263.         p++;
  264.     }
  265.     extent_no = -1;
  266.     while (++extent_no < 1000) {
  267.         sprintf(q, ".%03d", extent_no);
  268.         if (stat(newname, &statbuf) != 0) {
  269.             return newname;
  270.         }
  271.         if (is_character_device(newname)) {
  272.             break;
  273.         }
  274.         if (make_new == 0 && search_newname(newname) == NULL) {
  275.             return newname;
  276.         }
  277.     }
  278.     return NULL;
  279. }
  280.  
  281. static int
  282. last_char(char *p) {
  283.     int c;
  284.  
  285.     for (c = *p; *p; p++) {
  286.         c = *p;
  287.         if (iskanji(*p) && iskanji2(p[1])) {
  288.             p++;
  289.         }
  290.     }
  291.     return c;
  292. }
  293.  
  294. #ifdef    WIN32
  295. int is_forbid_char(int c)
  296. {
  297.   return (int)strchr("?\"/\\<>*|:",c);
  298. }
  299. #endif
  300.  
  301. static char *
  302. normalize_fname(char *destin, char *source, int dir_p) {
  303.     char *d, *s, *p, *q, *period;
  304.  
  305.     d = destin;
  306.     s = source;
  307.     if (isascii(*s) && isalpha(*s) && *(s + 1) ==':') {
  308.         *d++ = tolower(*s++);
  309.         *d++ = *s++;
  310.     }
  311.     while (*s != '\0') {
  312.         if (is_pathchar(*s)) {
  313.             *d++ = *s++;
  314.         }
  315.         while (is_pathchar(*s)) {
  316.             s++;
  317.         }
  318.         p = d;
  319.         if (*s == '.' && *(s + 1) == '.' &&
  320.             (is_pathchar(*(s + 2)) || (dir_p && *(s + 2) == '\0'))) {
  321.             *d++ = *s++;
  322.             *d++ = *s++;
  323.         } else if (*s == '.' &&
  324.             (is_pathchar(*(s + 1)) || (dir_p && *(s + 1) == '\0'))) {
  325.             *d++ = *s++;
  326.         } else {
  327. #ifndef    WIN32 
  328.             if (*s == '.') {   /* WIN32 では .forward も許される */
  329.                 *d++ = '_';
  330.                 s++;
  331.             }
  332. #endif
  333.             period = NULL;
  334.             while (*s != '\0' && !is_pathchar(*s)) {
  335.                 if (iskanji(*s) && iskanji2(*(s + 1))) {
  336.                     *d++ = *s++;
  337.                     *d++ = *s++;
  338.                 } else if ((isascii(*s) && isalnum(*s))
  339.                            || iskana(*s)
  340.                            || is_forbid_char(*s) == 0){
  341.                     *d++ = *s++;
  342.                 } else {
  343.                     *d++ = '_';
  344.                     s++;
  345.                 }
  346.             }
  347.             if (period != NULL) {
  348.                 if ((q = trim_jstr(p, period, MAX_NAM)) != NULL) {
  349.                     memmove(q, period, d - period);
  350.                     d += q - period;
  351.                     period = q;
  352.                 }
  353.                 if ((q = trim_jstr(period + 1, d, MAX_EXT)) != NULL) {
  354.                     d = q;
  355.                 }
  356.             } else {
  357.                 if ((q = trim_jstr(p, d, NAMLEN_NT)) != NULL) {
  358.                     d = q;
  359.                 }
  360.             }
  361.         }
  362.     }
  363.     *d = '\0';
  364.     return destin;
  365. }
  366.  
  367. static char *
  368. trim_jstr(char *p, char *q, int len) {
  369.     char *r, *s;
  370.  
  371.     if (q - p <= len) {
  372.         return NULL;
  373.     }
  374.     r = p;
  375.     while ((s = r + (iskanji(*r) ? 2 : 1)) - p <= len) {
  376.         r = s;
  377.     }
  378.     return r;
  379. }
  380.  
  381. static int
  382. is_dir(char *filename) {
  383.     struct stat stat_buf;
  384.     int result;
  385.  
  386.     result = stat(filename, &stat_buf);
  387.     if (result < 0
  388.         && (access(filename, 0) == 0
  389.             || (isascii(*filename)
  390.                 && isalpha(*filename)
  391.                 && strcmp(filename + 1, ":") == 0))) {
  392.         result = 0;
  393.         stat_buf.st_mode = S_IFDIR;
  394.                         /* July 30 1990 */
  395.      }
  396.     return result == 0 && (stat_buf.st_mode & S_IFMT) == S_IFDIR;
  397.                         /* July 30 1990 */
  398. }
  399.  
  400. static int
  401. is_character_device(char *name) {
  402.     int ret;
  403.     FILE *fp;
  404.  
  405.     if ((fp = fopen(name, "r")) == NULL) {
  406.         return 0;
  407.     }
  408.     ret = isatty(fileno(fp));
  409.     fclose(fp);
  410.     return ret ? 1: 0;
  411. }
  412. #include    <time.h>
  413. #include    "main.h"
  414. static rename_t **fn_list;
  415. static rename_t *t_rename_table = NULL;
  416. static int n_rename=0;
  417.  
  418. #define    OVERLAP_flag    11
  419. #define    CHANGED_flag    12
  420.  
  421.  
  422. #if    LSI_C
  423. static char far *lsi_far_strdup(char far *str)
  424. {
  425.     char far *dest;
  426.     dest = (char far *)_far_malloc((unsigned long)(_far_strlen(str)+1));
  427.     if (dest != NULL)
  428.         _far_strcpy(dest,str);
  429.     return dest;
  430. }
  431. char *f_to_n(char far *str)
  432. {
  433.     static char buf[NAMLEN];
  434.     
  435.     _far_strcpy((char far *)buf,str);
  436.     
  437.     return buf;
  438. }
  439.  
  440. #endif
  441. static int store_name(char *sour,char *dest) /* for t commnad */
  442. {
  443.     rename_t *nt;
  444.  
  445.     if ((nt = (rename_t *) malloc((unsigned int)sizeof(rename_t))) == NULL) {
  446.         return NO;
  447.     }
  448.     if ((nt->org_name = strdup(sour)) == NULL) {
  449.         return NO;
  450.     }
  451.     if ((nt->new_name = strdup(dest)) == NULL) {
  452.         return NO;
  453.     }
  454.     nt->dir_p = 0;
  455.     nt->next = t_rename_table;
  456.     n_rename++;
  457.     t_rename_table = nt;
  458.     return YES;
  459. }
  460.  
  461. static void print_header(void)
  462. {
  463.     time_t ltime;
  464.  
  465.     printf(
  466.     "#  This report is made by kmtar for WIN-NT \n"
  467.     "#\t by tantan at "__DATE__ "\n#\n");
  468.     
  469.     time(<ime);
  470.     printf("#  FILE :%s\n#  DATE :%s",Archives[0],ctime(<ime));
  471.     printf("#  TOTAL:%d files detect\n#\n",n_rename);
  472.  
  473. }
  474.  
  475. static void print_names(int flag)
  476. {
  477.     int i;
  478.  
  479.     for (i=0;i<n_rename;i++){
  480.         if (fn_list[i]->dir_p == flag){
  481. #if    !LSI_C
  482.             printf("%s\t%s\n",fn_list[i]->org_name,fn_list[i]->new_name);
  483. #else
  484.             printf("%s\t",f_to_n(fn_list[i]->org_name));
  485.             printf("%s\n",f_to_n(fn_list[i]->new_name));
  486. #endif
  487.         }
  488.     }
  489. }
  490.  
  491. static int check_overlap(void)    /* used by t command */
  492. {
  493.     int i,flag=0,count=0;
  494.  
  495.     for (i=1;i<n_rename;i++){
  496. #ifdef    WIN32
  497.         if (stricmp(fn_list[i-1]->new_name,fn_list[i]->new_name) == 0){
  498. #else
  499.         if (strcmp(fn_list[i-1]->new_name,fn_list[i]->new_name) == 0){
  500. #endif
  501.             if (!flag){
  502.                 fn_list[i-1]->dir_p = OVERLAP_flag;
  503.                 flag = 1;
  504.                 count++;
  505.             }
  506.             fn_list[i]->dir_p = OVERLAP_flag;
  507.             count++;
  508.         }else
  509.             flag=0;
  510.     }
  511.     return count;
  512. }
  513.  
  514. int check_rename_or_not(void)    /* used by t command */
  515. {
  516.     int i,count=0;
  517.  
  518.     for (i=0;i<n_rename;i++){
  519.         if (fn_list[i]->dir_p == OVERLAP_flag) /* skip overlap name */
  520.             continue;
  521.         if (strcmp(fn_list[i]->new_name,fn_list[i]->org_name) != 0){
  522.             count++;
  523.             fn_list[i]->dir_p = CHANGED_flag;
  524.         }
  525.     }
  526.     return count;
  527. }
  528.  
  529. /*----------------------------------------------------*/
  530. static int count_sl(char *str)
  531. {
  532.     int i;
  533.     for(i=0;*str;++str)
  534.         if (*str == '/')
  535.             i++;
  536.     return i;
  537. }
  538.  
  539. static int fname_cmp(char *n1,char *n2)
  540. {
  541.     int n;
  542.     if ((n = count_sl(n1) - count_sl(n2)) != 0)
  543.         return n;
  544.     return strcmp(n1,n2);
  545. }
  546.  
  547. #ifdef    USE_QSORT
  548. static int
  549. #ifdef MSC
  550. __cdecl
  551. #endif
  552. compare(const void *x,const void *y)
  553. {
  554.     int n;
  555.     n = fname_cmp((*(rename_t **)x)->new_name,
  556.                     (*(rename_t **)y)->new_name);
  557.     if (n != 0)
  558.         return n;
  559.     return  fname_cmp((*(rename_t **)x)->org_name,
  560.                         (*(rename_t **)y)->org_name);
  561. }
  562. #endif
  563.  
  564. #ifdef    MSC
  565. #pragma loop_opt(off)
  566. #endif
  567. void sort_rename_table(void)
  568. {
  569. #ifdef    USE_QSORT
  570.     qsort((void *)fn_list,(size_t)n_rename,(size_t)sizeof(rename_t *),compare);
  571. #else
  572.  /*
  573.  * This sorting algorithm 
  574.  *    "NIKKEY BYTE ",
  575.  *    
  576.  */
  577.     #define    SHRINKFACTOR    1.3
  578.     /*use combsort11 */
  579.     int switches, i, j, top, gap, size = n_rename, di;
  580.     rename_t *tmp;
  581.  
  582.  
  583.     gap = size;
  584.     do{
  585.         gap = (int)((float)gap /SHRINKFACTOR);
  586.         switch(gap){
  587.             case 0:
  588.                 gap = 1;
  589.                 break;
  590.             case 9:
  591.             case 10:
  592.                 gap = 11;
  593.             default:
  594.                 break;
  595.         }
  596.         switches = 0;
  597.         top = size - gap;
  598.         for(i=0;i<top;++i){
  599.             j=i+gap;
  600.             if ((di = fname_cmp(fn_list[i]->new_name,
  601.                         fn_list[j]->new_name)) > 0 || 
  602.                 (di == 0 && fname_cmp(fn_list[i]->org_name,
  603.                         fn_list[j]->org_name) > 0)){
  604.                 tmp = fn_list[i];
  605.                 fn_list[i] = fn_list[j];
  606.                 fn_list[j] = tmp;
  607.                 ++switches;
  608.             }
  609.         }
  610.     }while(switches     || (gap > 1));
  611. #endif
  612. }
  613. #ifdef    MSC
  614. #pragma loop_opt(on)
  615. #endif
  616.  
  617. int inspect_fname_list(void)    /* used by t command */
  618. {
  619.     rename_t *nt;
  620.     int i,n_over,n_change;
  621.  
  622.  
  623.     if((fn_list = (rename_t **)malloc((unsigned int)sizeof(rename_t *)*n_rename)) == NULL)
  624.         fatal("chkfname","Out of memory");
  625.     
  626.     for (i=0,nt = t_rename_table; nt != NULL; nt = nt->next,i++) {
  627.         fn_list[i] = nt;
  628.     }
  629.  
  630.  
  631.     sort_rename_table();
  632.     n_over = check_overlap();        /* mark overlap name */
  633.     n_change = check_rename_or_not();  /* mark changed name */
  634.  
  635.     print_header();
  636.  
  637.     printf("#--------- check OVERLAP\t[total %d]\n",n_over);
  638.     printf("#\t[in Archive]\t\t\t[in WIN32]\n");
  639.     print_names(OVERLAP_flag);
  640.  
  641.     printf("#\n#--------- check RENAME\t[total %d]\n",n_change);
  642.     printf("#\t[in Archive]\t\t\t[in WIN32]\n");
  643.     print_names(CHANGED_flag);
  644.     return YES;
  645. }
  646.  
  647. /*read_res_file関数の内部変数*/
  648. static int read_res_file_first=1;
  649.  
  650. void read_res_file(char ***argv)    /* used by x or t  command */
  651. {
  652.     return;
  653.  
  654.     /* comment out by tsuneo 1997.8.25 */
  655.     /* response file(間接引数)はここでは扱わないようにした。*/
  656.     /* 理由:mallocのところでメモリが次々消費されていくため。 */
  657. #if 0
  658.     FILE *rf;
  659.     char **p,line[220],*s1;
  660.     char **new_argv,**pp;
  661.     int  argc=0;
  662.     // static int first=1;
  663.     
  664.     if (!read_res_file_first)
  665.         return;
  666.     if ((new_argv = (char **)malloc(sizeof(char *)*MAXARG)) == NULL)
  667.         fatal("chkfname","Out of memory");
  668.  
  669.     read_res_file_first = 0;
  670.     for(pp = new_argv,p = *argv;*p != NULL;p++){
  671.         if(**p == '@'){    /* response file */
  672.             if ((rf = fopen(*p+1,"rb")) == NULL){
  673.                 printf("Response file [%s] can't open\n",p[0]+1);
  674.                 exit(1);
  675.             }
  676.             while(fgets(line, sizeof(line), rf) != NULL){
  677.                 if (line[0] == '#')
  678.                     continue;
  679.                 if ((s1 = strtok(line," \t\n\r")) != NULL){
  680.                     *pp = strdup(s1);
  681.                     argc++;
  682.                     pp++;
  683.                     if (argc >= MAXARG){
  684.                          fatal("chkfname","ARG size too big");
  685.                     }
  686.                 }
  687.             }
  688.             fclose(rf);
  689.         }else{
  690.             *pp = strdup(*p);
  691.             argc++;
  692.             pp++;
  693.             if (argc >= MAXARG){
  694.                  fatal("chkfname","ARG size too big");
  695.             }
  696.         }
  697.     }
  698.     *pp = NULL;
  699.     *argv = new_argv;
  700. #endif
  701. }
  702.  
  703. char *get_orgname(char *new_name)
  704. {
  705.     rename_t  *nt;
  706.     for (nt = rename_table; nt != NULL; nt = nt->next) {
  707.         if (strcmp(new_name, nt->new_name) == 0) 
  708.             return nt->org_name;
  709.     }
  710.     return NULL;
  711. }
  712.  
  713. void recode_names(char *sour) /* for t command */
  714. {
  715.     char dest[NAMLEN], *p;
  716.  
  717.     if ((p = search_orgname(sour, 0)) != NULL) {
  718.         if(store_name((char *)sour, p) == NO)
  719.             fatal("chkfname","Out of memory");
  720.         return;
  721.     }
  722.     if (make_new_fname(dest, sour, 0, 0) == NULL) {
  723.         strcpy(dest, sour);
  724.     }
  725.     if (store_name((char *)sour,(char *)dest) == NO){
  726.         fatal("chkfname","Out of memory");
  727.     }
  728. }
  729.  
  730. /* Read rule file into rename table */
  731. /* and erase "#file" argument from  */
  732. /* argv                                */
  733. void read_rule_file(char **argv)    /* used by all command */
  734. {
  735.     FILE *rf;
  736.     char **p,line[NAMLEN*2+30],*s1,*s2;
  737.     
  738.     for(p = argv;*p != NULL;p++){
  739.         if(**p == '#'){    /* rule-file */
  740.             if ((rf = fopen(*p+1,"rb")) == NULL){
  741.                 printf("Rule file [%s] can't open\n",p[0]+1);
  742.                 exit(1);
  743.             }
  744.             while(fgets(line, sizeof(line), rf) != NULL){
  745.                 if ((s1 = strtok(line," \t\n\r")) == NULL)
  746.                     continue;
  747.                 if (*s1=='#')    /* comment line */
  748.                     continue;
  749.                 if ((s2 = strtok(NULL," \t\n\r")) == NULL)
  750.                     continue;
  751.                 if (register_rename_table(s1, 0, s2)== NO)
  752.                         fatal("chkfname","Out of memory");
  753.             }
  754.             fclose(rf);
  755.             while(*p){
  756.                 *p = *(p + 1);
  757.                 p++;
  758.             }
  759.             return;
  760.         }
  761.     }
  762. }
  763. #ifdef DLL
  764. void chkfname_static_init(void)
  765. {
  766.     out_of_memory=0;
  767.  
  768.     /* rename_table = NULL;*/
  769.     if(rename_table!=NULL){
  770.         erase_rename_table();
  771.     }
  772.  
  773.     fn_list=NULL;
  774.     t_rename_table = NULL;
  775.     n_rename=0;
  776.  
  777.     read_res_file_first=1;
  778. }
  779. #endif
  780.