File name: welboard2/util/upnotice (3,811 bytes) Text file viewer v1.2
    1 : #!/bin/wel
    2 : 
    3 : /*  file: upnotice
    4 : 
    5 :     notice.wel V1.1.2 변환 프로그램(author: 서광현)
    6 :     Copyright (c) 2001/04/05 by Wesoft
    7 :     All Rights Reserved.
    8 : */
    9 : 
   10 : print("<<< Convert notice.wel V1.1.2 to WelBoard V2.0.4 >>>\n\n");
   11 : if(argc!=3)
   12 :  {
   13 :      print("Usage: upnotice  dbname  notice_data_directory\n");
   14 :      return;
   15 :  }
   16 : 
   17 : db= argv[1];
   18 : notice_datadir= argv[2];
   19 : break_on= -1;
   20 : if(include("include/board.inc")!=OK) return;
   21 : message_form= "";
   22 : 
   23 : function cancel_message(string msg)
   24 :  {
   25 :     if(msg!="") print("\n ERROR: ", msg, "\n\n");
   26 :     print(" upnotice is cancelled.\n\n");
   27 :     return;
   28 :  }
   29 : 
   30 : function get_noticename(string notice_data_dir)
   31 :  {
   32 :     while( (pos= strfind(notice_data_dir, "/")) > 0)
   33 :      {
   34 :         notice_data_dir= mid(notice_data_dir, pos+1);
   35 :      }
   36 :     return( notice_data_dir );
   37 :  }
   38 : 
   39 : rt= mysql_connection("");
   40 : if(rt==MYSQL_ERR)
   41 :  {
   42 :     if(mysql==MYSQL_ERR) msg= "MySQL connection error!";
   43 :       else msg= "MySQL select db error! (DB=" ~ mydb ~ ")";
   44 :     cancel_message(msg);
   45 :     return disconnect();
   46 :  }
   47 : 
   48 : recnt= get_recount(mytable,"");
   49 : if(recnt<0)
   50 :  {
   51 :     cancel_message("MySQL database=" ~ mydb ~ " , table="
   52 :                    ~ mytable ~ " : Table error!");
   53 :     return disconnect();
   54 :  }
   55 : if(right(notice_datadir,1)=="/")
   56 :  {
   57 :     notice_datadir= left(notice_datadir, len(notice_datadir)-1);
   58 :  }
   59 : notice_dbname= get_noticename(notice_datadir);
   60 : notice_datadir ~= "/";
   61 : notice_conf= notice_datadir ~ notice_dbname ~ ".conf";
   62 : notice_lastnum= notice_datadir ~ notice_dbname ~ ".num";
   63 : if(!fexist(notice_conf))
   64 :  {
   65 :     cancel_message("notice.wel V1.1.2: Configuration file not found error!\n"
   66 :                    ~ "                     File: " ~ notice_conf);
   67 :     return disconnect();
   68 :  }
   69 : if(!fexist(notice_lastnum))
   70 :  {
   71 :     cancel_message("notice.wel V1.1.2: LastNumber file not found error!\n"
   72 :                    ~ "                     File: " ~ notice_lastnum);
   73 :     return disconnect();
   74 :  }
   75 : 
   76 : include(notice_conf, -1);
   77 : fp= fopen(notice_lastnum, "r");
   78 : if(fp==FILE_OPEN_ERR)
   79 :  {
   80 :     cancel_message("notice.wel V1.1.2: LastNumber file open error!\n"
   81 :                    ~ "                     File: " ~ notice_lastnum);
   82 :     return disconnect();
   83 :  }
   84 : lastnum= finput(fp);
   85 : fclose(fp);
   86 : 
   87 : print(" 1. Target notice: ", notice_datadir, "\n");
   88 : print(" 2. Notice name: ", title, "\n");
   89 : print(" 3. Maximum number: ", lastnum, "\n\n");
   90 : sel= choice(" Do you want to continue?(Y/n) ", "Yy\nNn");
   91 : if(sel==3) print("Y");
   92 : print("\n\n");
   93 : if(sel>3) { cancel_message(""); return disconnect(); }
   94 : 
   95 : function int convert(string datafile, string memofile)
   96 :  {
   97 :    if(!fexist(datafile)) return(-1);
   98 :    include(datafile, -1);
   99 :    content= strform("{&fdump(memofile)}");
  100 : 
  101 :    subject= strchange(left(lrtrim(DT_SUBJECT),60,1), fch, rch);
  102 :    content= strchange(content, fch, rch);
  103 :    linecnt= strcount(content, "\n");
  104 :    if(right(content,1)!="\n") ++linecnt;
  105 :    wdtime= left(DT_DATE,10) ~ " " ~ left(time(1),5);
  106 :    grpno= selno= get_maximum(mytable, "selno", "") + 1;
  107 : 
  108 :    qstr= "insert into " ~ mytable
  109 :        ~ " (selno,grpno,answer,subject,content,readcnt,downcnt,linecnt,"
  110 :        ~ "wdtime,wip,whost,wname) values ("
  111 :        ~ strform("{$selno},{$grpno},'','{$subject}','{$content}',0,0,",
  112 :                  "{$linecnt},'{$wdtime}','127.0.0.1','localhost','관리자')");
  113 : 
  114 :   if(mysql_query(mysql, qstr)==MYSQL_ERR) return(0);
  115 :   return(1);
  116 :  }
  117 : 
  118 : num= 1;
  119 : totcnt= errcnt= 0;
  120 : while(num<=lastnum)
  121 :  {
  122 :     data_file= notice_datadir ~ num ~ ".dat";
  123 :     memo_file= notice_datadir ~ num ~ ".txt";
  124 :     rt= convert(data_file, memo_file);
  125 :     if(rt!=-1)
  126 :      {
  127 :         totcnt++;
  128 :         if(rt==0)
  129 :          {
  130 :             errcnt++;
  131 :             print(" *** converting error: ", data_file, "\n");
  132 :          }
  133 :      }
  134 :     num++;
  135 :  }
  136 : print("\n >> Total record: ", totcnt);
  137 : if(errcnt>0) printf(" , Error: ", errcnt);
  138 : print(" , Converted record: ", totcnt-errcnt, "\n");
  139 : return disconnect();
File name: welboard2/util/upnotice (3,811 bytes) Wesoft Corp. ⓒ 2001 All rights reserved.