home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / dir_nm20.zip / Dir_NM_2.0 / NM-Table.c < prev    next >
C/C++ Source or Header  |  1992-07-16  |  18KB  |  616 lines

  1. /*                         ===  NM-Table.c  ===
  2.  *
  3.  * void On_Row()
  4.  * void On_Atom()
  5.  * void On_Column()
  6.  * void Un_Line()
  7.  * void Draw_Map(X,Y)
  8.  * void Draw_Table_Frame(Column_Num,Row_Num)
  9.  * void List()
  10.  * void Update_Table(Mouse_x,Mouse_y)
  11.  * void Do_Insert(Mouse_x,Mouse_y)
  12.  * void Do_Copy(Mouse_x,Mouse_y)
  13.  * void Do_Re_Name(Mouse_x,Mouse_y,Button)
  14.  * void Do_Move(Mouse_x,Mouse_y)
  15.  * void Do_Delete(Mouse_x,Mouse_y)
  16.  * void Do_Value()
  17.  * void Do_Check_Tempo(Mouse_x,Mouse_y)
  18.  * void Do_Switch(Mouse_x,Mouse_y)
  19.  * void Do_Load(Mouse_x,Mouse_y)
  20.  * void Edit_Table(Mouse_x,Mouse_y)
  21.  * void Re_New_Pos(Mouse_x,Mouse_y)
  22.  * void Add_Word(Mouse_x,Mouse_y,Capital)
  23.  * void Edit_Word(Button,Mouse_x,Mouse_y)
  24.  *
  25.  */
  26.  
  27.  
  28. #include "NM.h" 
  29.  
  30. void On_Row()
  31. {
  32.   Row_On=1;Atom_On=0;Column_On=0;Row_Id=-10;Column_Id=-10;
  33. }
  34.  
  35. void On_Atom()
  36. {
  37.   Atom_On=1;Row_On=0;Column_On=0;Row_Id=-10;Column_Id=-10;
  38. }
  39.  
  40. void On_Column()
  41.   Column_On=1;Row_On=0;Atom_On=0;Row_Id=-10;Column_Id=-10;
  42. }
  43.  
  44. void Un_Line()
  45. {
  46.   if (Column_On==1) Show_Column_Line=1-Show_Column_Line;
  47.   else if (Row_On==1)Show_Row_Line=1-Show_Row_Line;
  48. }
  49.  
  50. void Draw_Map(X,Y)
  51.   int X,Y;
  52. {
  53.   int i,j;
  54.  
  55.   Rub(X-2,Y-1,233,93,"MediumBlue");XSetLineAttributes(display,gc,2,0,0,0);
  56.   SetColor("DeepSkyBlue");DrawRectangle(X,Y,229,91);SetColor("ivory");
  57.   XSetLineAttributes(display,gc,1,0,0,0);S_bf=(char *)malloc(10);*S_bf='\0';
  58.   for (i=1;i<12;i++) Line(X+19*i,Y+1,X+19*i,Y+90);
  59.   for (i=1;i<5;i++) Line(X+1,Y+18*i,X+228,Y+18*i);SetColor("khaki");
  60.   for (i=0;i<5;i++) 
  61.     for (j=0;j<12;j++)
  62.       { sprintf(S_bf,"%c",Map_Letter(j,i));OutTextXY(X+6+19*j,Y+14+18*i,S_bf); }
  63. }
  64.  
  65. void Draw_Table_Frame(Column_Num,Row_Num)
  66.   int Column_Num,Row_Num;
  67. {
  68.   int i,Pos_X,Y;
  69.  
  70.   Rub(0,94,1139,768,"MediumBlue");Use_Font("7x14");
  71.   XSetLineAttributes(display,gc,2,0,0,0);
  72.   Rub(Head_Len+4,97,Table_Width-Head_Len-2,23,"MidNightBlue");
  73.   if (Row_Num>36)
  74.     {
  75.       Rub(Head_Len+4,122+36*20,Table_Width-Head_Len-2,23,"MidNightBlue");
  76.       Rub(4,122,Head_Len,36*20,"MidNightBlue");
  77.     }
  78.   else
  79.     {
  80.       Rub(Head_Len+4,122+Row_Num*20,Table_Width-Head_Len-2,23,"MidNightBlue");
  81.       Rub(4,122,Head_Len,Row_Num*20,"MidNightBlue");
  82.     }
  83.   SetColor("cyan");
  84.   if (Row_Num>36) DrawRectangle(3,96,Table_Width,49+36*20);
  85.   else DrawRectangle(3,96,Table_Width,49+Row_Num*20);
  86.   SetColor("yellow");XSetLineAttributes(display,gc,1,0,0,0);Pos_X=Head_Len+3;
  87.   for (i=Column_Pointer;i<Column_Pointer+Column_Num-1;i++)
  88.     { 
  89.       if (Show_Column_Line==1)
  90.     {
  91.       if (Row_Num>36) Line(Pos_X,97,Pos_X,144+36*20);
  92.       else Line(Pos_X,97,Pos_X,144+Row_Num*20);
  93.     }
  94.       Pos_X+=Column_Range[i].Delta*7;
  95.     }
  96.   SetColor("yellow");
  97.   for (i=0;i<Row_Num+1;i++)
  98.     {
  99.       Y=120+i*20;if (Show_Row_Line==1 && i<=36) Line(4,Y,Table_Width+3,Y);
  100.       Row_Range[i].Position=Y;Row_Range[i].Delta=20;
  101.     }
  102. }
  103.  
  104. void List()
  105. {
  106.   int i,j,Pos_X,Max_Length;
  107.  
  108.   Column_Range[0].Position=0;Max_Length=strlen(Table_Name);Map_Dx=0;Map_Dy=0;
  109.   for (j=Row_Pointer;j<Table_Row_Num;j++) 
  110.     Max_Length=Max(Max_Length,strlen(Atom_array[j][0]));
  111.   Column_Range[0].Delta=Max_Length+3;Head_Len=7*Column_Range[0].Delta;
  112.   Table_Width=Head_Len;
  113.   if (Table_Row_Num-Row_Pointer>36) Table_Height=2*23+36*20-3;
  114.   else Table_Height=2*23+(Table_Row_Num-Row_Pointer)*20-3;
  115.   for (i=Column_Pointer;i<Table_Column_Num;i++)
  116.     {
  117.       Max_Length=strlen(Out_name[i-1])+1;
  118.       for (j=Row_Pointer;j<Table_Row_Num;j++)
  119.     Max_Length=Max(Max_Length,strlen(Atom_array[j][i]));
  120.       Column_Range[i].Position=Table_Width;Column_Range[i].Delta=Max_Length+2;
  121.       Table_Width+=7*Column_Range[i].Delta;
  122.     }
  123.   Draw_Table_Frame(Table_Column_Num-Column_Pointer+1,Table_Row_Num-Row_Pointer);
  124.   SetColor("white");Pos_X=12;SetColor("white");OutTextXY(Pos_X,114,Table_Name);
  125.   OutTextXY(Pos_X,138+(Table_Row_Num-Row_Pointer)*20,Table_Name);
  126.   SetColor("PaleGreen");
  127.   if (Table_Row_Num-Row_Pointer>36)              /*  Display Row Names  */
  128.     for (i=Row_Pointer;i<Row_Pointer+36;i++) 
  129.       OutTextXY(Pos_X,136+(i-Row_Pointer)*20,Atom_array[i][0]);
  130.   else for (i=Row_Pointer;i<Table_Row_Num;i++) 
  131.          OutTextXY(Pos_X,136+(i-Row_Pointer)*20,Atom_array[i][0]);
  132.   Pos_X=Head_Len+12;
  133.   for (i=Column_Pointer;i<Table_Column_Num;i++)
  134.     {
  135.       SetColor("gold");OutTextXY(Pos_X,114,Out_name[i-1]);
  136.       if (Table_Row_Num-Row_Pointer>36)
  137.     OutTextXY(Pos_X,138+36*20,Out_name[i-1]);
  138.       else OutTextXY(Pos_X,138+(Table_Row_Num-Row_Pointer)*20,Out_name[i-1]);
  139.       SetColor("ivory");
  140.  
  141.       if (Table_Row_Num-Row_Pointer>36)
  142.     for (j=Row_Pointer;j<Row_Pointer+36;j++)
  143.       OutTextXY(Pos_X,136+(j-Row_Pointer)*20,Atom_array[j][i]);
  144.       else for (j=Row_Pointer;j<Table_Row_Num;j++) 
  145.          OutTextXY(Pos_X,136+(j-Row_Pointer)*20,Atom_array[j][i]);
  146.       Pos_X+=Column_Range[i].Delta*7;
  147.     }
  148. }
  149.  
  150. void Update_Table(Mouse_x,Mouse_y)
  151.   int Mouse_x,Mouse_y;
  152. {
  153.   SetColor("MediumBlue");FillRectangle(0,95,1139,767);List();
  154.   if (In_Table(Mouse_x,Mouse_y)==1) Hi_light_Table(Mouse_x,Mouse_y);
  155. }
  156.  
  157. void Do_Insert(Mouse_x,Mouse_y)
  158.   int Mouse_x,Mouse_y;
  159. {
  160.   int i,j;
  161.  
  162.   if (Column_Id!=0 && Row_Id!=0 && Atom_On==0)
  163.     {
  164.       if (Row_On==1)
  165.     {
  166.       for (i=0;i<Table_Column_Num;i++)
  167.         {
  168.           Atom_array[Table_Row_Num][i]=(char *)malloc(50);
  169.           *Atom_array[Table_Row_Num][i]='\0';
  170.         }
  171.       for (i=Table_Row_Num;i>Row_Id;i--)
  172.         for (j=0;j<Table_Column_Num;j++)
  173.           strcpy(Atom_array[i][j],Atom_array[i-1][j]);
  174.       for (j=0;j<Table_Column_Num;j++) 
  175.         sprintf(Atom_array[Row_Id][j],"%s","?\n");
  176.       Table_Row_Num++;
  177.     }
  178.       else if (Column_On==1)
  179.          { 
  180.            In_name[Table_Column_Num-1]=(char *)malloc(50);
  181.            *In_name[Table_Column_Num-1]='\0';
  182.            Out_name[Table_Column_Num-1]=(char *)malloc(50);
  183.            *Out_name[Table_Column_Num-1]='\0';
  184.            for (i=0;i<Table_Row_Num;i++)
  185.          {
  186.            Atom_array[i][Table_Column_Num]=(char *)malloc(50);
  187.            *Atom_array[i][Table_Column_Num]='\0';
  188.          }
  189.            for (j=Table_Column_Num;j>Column_Id;j--)
  190.          {
  191.            strcpy(In_name[j-1],In_name[j-2]);
  192.            strcpy(Out_name[j-1],Out_name[j-2]);
  193.            for (i=0;i<Table_Row_Num;i++)
  194.              strcpy(Atom_array[i][j],Atom_array[i][j-1]);
  195.          }
  196.            sprintf(In_name[Column_Id-1],"%s","?\n");
  197.            sprintf(Out_name[Column_Id-1],"%s","?\n");
  198.            for (i=0;i<Table_Row_Num;i++)
  199.          sprintf(Atom_array[i][Column_Id],"%s","?\n");
  200.            Table_Column_Num++;
  201.          }
  202.       Column_Id=-10;Row_Id=-10;Update_Table(Mouse_x,Mouse_y);
  203.     }
  204. }
  205.  
  206. void Do_Copy(Mouse_x,Mouse_y)
  207.   int Mouse_x,Mouse_y;
  208. {
  209.   int i;
  210.  
  211.   if (Copy==0)
  212.     { 
  213.       Copy=-1;
  214.       if (Atom_On==1) { Row_Aim=Row_Id;Column_Aim=Column_Id; }
  215.       else if (Row_On==1) Row_Aim=Row_Id;
  216.            else if (Column_On==1) Column_Aim=Column_Id;
  217.     }
  218.   else
  219.     {
  220.       Copy=0;
  221.       if (Atom_On==1 && ((Row_Id>=0 && Row_Aim>=0) || (Row_Id<0 && Row_Aim<0)))
  222.     {
  223.       if (Row_Id<0)
  224.         {
  225.           if  (Column_Id>0)
  226.         {
  227.           if (Row_Id==-2) 
  228.             strcpy(In_name[Column_Id-1],In_name[Column_Aim-1]);
  229.           else if (Row_Id==-3)
  230.             strcpy(Out_name[Column_Id-1],Out_name[Column_Aim-1]);
  231.         }
  232.           else { Copy=0;Column_Id=-10;Row_Id=-10; }
  233.         }
  234.       else
  235.         strcpy(Atom_array[Row_Id][Column_Id],
  236.            Atom_array[Row_Aim][Column_Aim]);
  237.     }
  238.       else if (Column_On==1) 
  239.          {
  240.            for (i=0;i<Table_Row_Num;i++)
  241.          strcpy(Atom_array[i][Column_Id],Atom_array[i][Column_Aim]);
  242.            strcpy(In_name[Column_Id-1],In_name[Column_Aim-1]);
  243.            strcpy(Out_name[Column_Id-1],Out_name[Column_Aim-1]);
  244.          }
  245.            else if (Row_On==1) 
  246.               for (i=0;i<Table_Column_Num;i++)
  247.             strcpy(Atom_array[Row_Id][i],Atom_array[Row_Aim][i]);
  248.       Column_Id=-10;Row_Id=-10;Update_Table(Mouse_x,Mouse_y);
  249.     }
  250. }
  251.  
  252. void Do_Re_Name(Mouse_x,Mouse_y,Button)
  253.   int Mouse_x,Mouse_y,Button;
  254. {
  255.   char ch;
  256.   int Num;
  257.  
  258.   if (Atom_On==1)
  259.     {
  260.       if (Replace==0 && In_Table(Mouse_x,Mouse_y)==1)
  261.     {
  262.       Replace=-1;Row_Aim=Row_Id;Column_Aim=Column_Id;
  263.       if (Row_Aim<0)
  264.         {
  265.           if (Column_Aim==0)
  266.         {
  267.           *Table_Name='\0';
  268.           sprintf(Table_Name+strlen(Table_Name),"%c",'?');
  269.         }
  270.           else
  271.         {
  272.           if (*Old_name[Column_Aim-1]=='\0') 
  273.             strcpy(Old_name[Column_Aim-1],In_name[Column_Aim-1]);
  274.           *In_name[Column_Aim-1]='\0';
  275.           sprintf(In_name[Column_Aim-1]+
  276.               strlen(In_name[Column_Aim-1]),"%c",'?');
  277.           S_bf=(char *)malloc(10);*S_bf='\0';
  278.           sprintf(S_bf,"%-4i",content[Column_Aim-1]);
  279.           *Out_name[Column_Aim-1]='\0';
  280.           strcpy(Out_name[Column_Aim-1],In_name[Column_Aim-1]);
  281.           sprintf(Out_name[Column_Aim-1]+
  282.               strlen(Out_name[Column_Aim-1])," = %s",S_bf);
  283.         }
  284.         }
  285.       else sprintf(Atom_array[Row_Aim][Column_Aim]+6,"%c",'?');
  286.       Update_Table(Mouse_x,Mouse_y);
  287.     }
  288.       else if (Replace==-1 && In_Map(Mouse_x,Mouse_y)==1)
  289.          {
  290.            if (Button==Button1)
  291.          ch=Map_Letter((Mouse_x-Map_SX-1)/19,(Mouse_y-4)/18);
  292.            else ch=Map_Letter((Mouse_x-Map_SX-1)/19,(Mouse_y-4)/18)-32;
  293.            if (Row_Aim<0)
  294.          {
  295.            if (Column_Aim==0)
  296.              {
  297.                sprintf(Table_Name+strlen(Table_Name)-1,"%c",ch);
  298.                sprintf(Table_Name+strlen(Table_Name),"%c",'\n');
  299.              }
  300.            else
  301.              {
  302.                sprintf(In_name[Column_Aim-1]
  303.                    +strlen(In_name[Column_Aim-1])-1,"%c",ch);
  304.                sprintf(In_name[Column_Aim-1]
  305.                    +strlen(In_name[Column_Aim-1]),"%c",'\n');
  306.                S_bf=(char *)malloc(10);*S_bf='\0';
  307.                sprintf(S_bf,"%-4i",content[Column_Aim-1]);
  308.                *Out_name[Column_Aim-1]='\0';
  309.                strcpy(Out_name[Column_Aim-1],In_name[Column_Aim-1]);
  310.                sprintf(Out_name[Column_Aim-1]+
  311.                    strlen(Out_name[Column_Aim-1])-1," = %s\n",S_bf);
  312.              }
  313.          }
  314.            else 
  315.          {
  316.            sprintf(Atom_array[Row_Aim][Column_Aim]+
  317.                strlen(Atom_array[Row_Aim][Column_Aim])-1,"%c",ch);
  318.            Str_Append(Atom_array[Row_Aim][Column_Aim],'\n',1);
  319.  
  320.            Num=Column_Aim*1000+Row_Aim-1000;
  321.            if (Column_Aim<Max_kind)
  322.              {
  323.                names[Num]=(char *)malloc(50);*names[Num]='\0';
  324.                sprintf(names[Num]+strlen(names[Num]),
  325.                    Atom_array[Row_Aim][Column_Aim]);
  326.              }
  327.            else 
  328.              {
  329.                *cont[Row_Aim].Set_name='\0';
  330.                sprintf(cont[Row_Aim].Set_name+
  331.                    strlen(cont[Row_Aim].Set_name),
  332.                    Atom_array[Row_Aim][Column_Aim]);
  333.              }
  334.          }
  335.            Update_Table(Mouse_x,Mouse_y);
  336.          }
  337.     }
  338. }
  339.  
  340. void Do_Move(Mouse_x,Mouse_y)
  341.   int Mouse_x,Mouse_y;
  342. {
  343.   int From_kind,From_num,To_kind,To_num;
  344.  
  345.   if (Move==0) { Move=-1;Row_Aim=Row_Id;Column_Aim=Column_Id; }
  346.   else
  347.     {
  348.       Move=0;
  349.       if (((Column_Aim==1 && Column_Id==1)||(1<Column_Aim && 1<Column_Id ))
  350.       && 0<=Row_Id && 0<=Row_Aim && Row_Aim<content[Column_Aim-1])
  351.     {
  352.       From_kind=Column_Aim-1;To_kind=Column_Id-1;
  353.       From_num=Row_Aim;To_num=Row_Id;
  354.       Move_Melody(From_kind,From_num,To_kind,To_num);
  355.       Get_List();Column_Id=-10;Row_Id=-10;Update_Table(Mouse_x,Mouse_y);
  356.     }
  357.       Action=0;
  358.     }
  359. }
  360.  
  361. void Do_Delete(Mouse_x,Mouse_y)
  362.   int Mouse_x,Mouse_y;
  363. {
  364.   int i,k,n,from,to,Num,Lim;
  365.  
  366.   if (Atom_On) 
  367.     {
  368.       if (Delete==0) { Delete=-1;Row_Aim=Row_Id;Column_Aim=Column_Id; }
  369.       else
  370.     {
  371.       Delete=0;
  372.       if (Column_Aim==Column_Id && 0<Column_Id && 0<=Row_Id && 
  373.           0<=Row_Aim && Row_Aim<content[Column_Aim-1])
  374.         {
  375.           n=Column_Id-1;
  376.           if (Row_Aim<Row_Id)
  377.         { from=Row_Aim;to=Row_Id;if (to>content[n]-1) to=content[n]-1; }
  378.           else { from=Row_Id;to=Row_Aim; }
  379.           Del=from;k=to-from+1;
  380.           if (Column_Aim<Max_kind)
  381.         {
  382.           Get_Filename(n);if (now != n) { now=n;Load(); } 
  383.           Move_Word(now,from,-1,to);Save(k,tail);Del=-1;
  384.         }
  385.           else 
  386.         {
  387.           Lim=content[Max_kind-1]-Del-k;
  388.           for (i=0;i<Lim;i++)
  389.             {
  390.               S_bf=(char *)malloc(10);*S_bf='\0';
  391.               *cont[Del+i].Set_name='\0';sprintf(S_bf,"%5ld",Del+i+1);
  392.               strcpy(cont[Del+i].Set_name,S_bf);ch='.';
  393.               sprintf(cont[Del+i].Set_name+strlen(cont[Del+i].Set_name),
  394.                   "%c",ch);
  395.               sprintf(cont[Del+i].Set_name+6,"%s",
  396.                   Sub_Str(cont[Del+i+k].Set_name,6,44));
  397.               for (Num=0;Num<6;Num++)
  398.             {
  399.               cont[Del+i].tempo[Num]=cont[Del+i+k].tempo[Num];
  400.               cont[Del+i].instru[Num]=cont[Del+i+k].instru[Num];
  401.             }
  402.             }
  403.           content[Max_kind-1]-=k;Lim=content[Max_kind-1];
  404.           for (i=Lim;i<Lim+k;i++)
  405.             {
  406.               S_bf=(char *)malloc(10);*S_bf='\0';
  407.               *cont[i].Set_name='\0';sprintf(S_bf,"%5ld",i+1);
  408.               strcpy(cont[i].Set_name,S_bf);ch='.';
  409.               sprintf(cont[i].Set_name+strlen(cont[i].Set_name),"%c"
  410.                   ,ch);
  411.               sprintf(cont[i].Set_name+strlen(cont[i].Set_name),"%s\n",
  412.                   "???");
  413.               for (j=0;j<6;j++) 
  414.             { cont[i].tempo[j]=0;cont[i].instru[j]=0; }
  415.             }
  416.         }
  417.           Get_List();Column_Id=-10;Row_Id=-10;Update_Table(Mouse_x,Mouse_y);
  418.         }
  419.       Action=0;
  420.     }
  421.     }
  422. }
  423.  
  424. void Do_Value()
  425. {
  426.   int Melody_Id;
  427.  
  428.   Melody_Id=-1;
  429.   if (Column_Id>0)
  430.     {
  431.       next=Column_Id-1;
  432.       if (0<=Row_Id && Row_Id<content[Column_Id-1]) Melody_Id=Row_Id;
  433.     }
  434.   if (next==0) return;
  435.   if (Melody_Id!=-1) 
  436.     { if (next!=now) { now=next;Load(); } Adjust_Value(Melody_Id); }
  437. }
  438.  
  439. void Do_Check_Tempo(Mouse_x,Mouse_y)
  440.   int Mouse_x,Mouse_y;
  441. {
  442.   if (1<Column_Id && Column_Id<Max_kind-1) next=Column_Id-1;else return;
  443.   if (-1<Row_Id && Row_Id<content[next]) M_Id=Row_Id;else return;
  444.   
  445.   if (now != next) { now=next;Load(); }
  446.   Check_Tempo();Column_Id=-10;Row_Id=-10;Update_Table(Mouse_x,Mouse_y);
  447. }
  448.  
  449. void Do_Switch(Mouse_x,Mouse_y)
  450.   int Mouse_x,Mouse_y;
  451. {
  452.   if (Switch==0) 
  453.     { 
  454.       if (1<Column_Id && Column_Id<Max_kind) 
  455.     { Switch=-1;Column_Aim=Column_Id; } else Action=0;return;
  456.     }
  457.   else
  458.     {
  459.       Switch=0;
  460.       if (1<Column_Id && Column_Id<Max_kind) 
  461.     {
  462.       Switch_Melody(Column_Aim-1,Column_Id-1);
  463.       Buffer[0]=(char *)malloc(50);*Buffer[0]='\0';
  464.       strcpy(Buffer[0],In_name[Column_Aim-1]);
  465.       strcpy(In_name[Column_Aim-1],In_name[Column_Id-1]);
  466.       strcpy(In_name[Column_Id-1],Buffer[0]);
  467.       Buffer[0]=(char *)malloc(50);*Buffer[0]='\0';
  468.       strcpy(Buffer[0],Out_name[Column_Aim-1]);
  469.       strcpy(Out_name[Column_Aim-1],Out_name[Column_Id-1]);
  470.       strcpy(Out_name[Column_Id-1],Buffer[0]);
  471.       Save_Name();Save_Words();Column_Id=-10;Row_Id=-10;
  472.       Update_Table(Mouse_x,Mouse_y);
  473.       if ((now==Column_Aim-1 || now==Column_Id-1) && content[now]>0) Load();
  474.     }
  475.       Action=0;
  476.     }
  477. }
  478.  
  479. void Do_Load(Mouse_x,Mouse_y)
  480.   int Mouse_x,Mouse_y;
  481. {
  482.   char f_head[100],fn[100],Suffix[10];
  483.   struct stat statbuf;
  484.   int rv_stat,Len;
  485.   struct dirent *dirbuf;
  486.   DIR *dir;
  487.  
  488.   next=Column_Id-1;if (now!=next) { now=next;if (content[now]>0) Load(); }
  489.   strcpy(f_head,"Dir_Text");rv_stat = stat(f_head, &statbuf);
  490.   if (!S_ISDIR(statbuf.st_mode))
  491.     { printf("%s is not a directory\n",f_head);return; }
  492.  
  493.   if ((dir=opendir(f_head)) == NULL)
  494.     { printf("failed to open %s\n",f_head);return; }
  495.  
  496.   while ((dirbuf = readdir(dir)) != NULL)
  497.     {
  498.       Len=strlen(dirbuf->d_name);strcpy(fn,f_head);
  499.       strcpy(Suffix,Sub_Str(dirbuf->d_name,Len-5,5));
  500.       if (strcmp(".text",Suffix)==0)
  501.     {
  502.       sprintf(fn+strlen(fn),"/%s",dirbuf->d_name);Load_From_Back_Up(fn,0,0);
  503.     }
  504.      }
  505.   closedir(dir);Save(1,content[now]);
  506.   Column_Id=-10;Row_Id=-10;Update_Table(Mouse_x,Mouse_y);
  507. }
  508.  
  509. void Edit_Table(Mouse_x,Mouse_y)
  510.   int Mouse_x,Mouse_y;
  511. {
  512.   if (In_Table(Mouse_x,Mouse_y)==1)
  513.     {
  514.       switch (Action) 
  515.     {
  516.       case Re_Name_On:Do_Re_Name(Mouse_x,Mouse_y,Button1);break;
  517.       case Move_On:Do_Move(Mouse_x,Mouse_y);break;
  518.       case Delete_On:Do_Delete(Mouse_x,Mouse_y);break;
  519.           case Value_On:Do_Value();break;
  520.           case Check_Tmp_On:Do_Check_Tempo(Mouse_x,Mouse_y);break;
  521.           case Switch_On:Do_Switch(Mouse_x,Mouse_y);break;
  522.       case Load_Text_On:Do_Load(Mouse_x,Mouse_y);break;
  523.     }
  524.       if (Action!=Re_Name_On) Renew_Notice();
  525.     }
  526. }
  527.  
  528. void Re_New_Pos(Mouse_x,Mouse_y)
  529.   int Mouse_x,Mouse_y;
  530. {
  531.   int Len;
  532.  
  533.   High_Light_Char(Word_X,Word_Y);Len=strlen(Words[New_Word])+Text_Base;
  534.   Word_X=(Mouse_x-47)/7;Word_Y=(Mouse_y-148)/Dist;
  535.   if (page*300+Word_Y*150+Word_X>Len)
  536.     { Word_X=Len % 150;Word_Y=(Len/150) % 2; }
  537.   else if (page*300+Word_Y*150+Word_X<Text_Base) { Word_X=Text_Base;Word_Y=0; }
  538.        else if (Word_X<0) { Word_X=0;Word_Y=(Len/150) % 2; }
  539.             else if (Word_X>150) { Word_X=150;Word_Y=(Len/150) % 2; }
  540.   High_Light_Char(Word_X,Word_Y);Word_Pos=page*300+Word_Y*150+Word_X;
  541. }
  542.  
  543. void Add_Word(Mouse_x,Mouse_y,Capital)
  544.   int Mouse_x,Mouse_y,Capital;
  545. {
  546.   char ch,Str[2],*Word_Tail;
  547.   int A_Pos;
  548.  
  549.   if (Word_Pos<(page+1)*300)
  550.     {
  551.       if (Capital!=-2) High_Light_Char(Word_X,Word_Y);
  552.       switch (Capital)
  553.     {
  554.       case 2:ch=Map_Letter(Text_Column_Id,Text_Row_Id)-32;break;
  555.       case 1:ch=Map_Letter(Text_Column_Id,Text_Row_Id);break;
  556.       case 0:ch=' ';Re_New_Pos(Mouse_x,Mouse_y);break;
  557.       case -1:ch=' ';break;
  558.       case -2:ch=' ';Re_New_Pos(Mouse_x,Mouse_y);break;
  559.     }
  560.       if (Word_Pos==strlen(Words[New_Word])+Text_Base)
  561.     {
  562.       Rub(Word_X*7+47,Word_Y*Dist+148,7,13,"NavyBlue");SetColor("cyan");
  563.       sprintf(Str,"%c",ch);OutTextXY(Word_X*7+47,Word_Y*Dist+159,Str);
  564.       sprintf(Words[New_Word]+strlen(Words[New_Word]),"%c",ch);
  565.       if (Word_Pos<3000 && Word_Pos!=(page+1)*300-1) Word_Pos++;
  566.     }
  567.       else
  568.          {
  569.            A_Pos=Word_Pos-Text_Base;
  570.            Word_Tail=(char *)malloc(3000);*Word_Tail='\0';
  571.            if (Capital>-1)
  572.          {
  573.            sprintf(Word_Tail+strlen(Word_Tail),"%s",
  574.                Sub_Str(Words[New_Word],A_Pos,
  575.                    strlen(Words[New_Word])-A_Pos));
  576.            sprintf(Words[New_Word]+A_Pos,"%c",ch);
  577.            sprintf(Words[New_Word]+A_Pos+1,"%s",Word_Tail);
  578.            if (Word_Pos<3000 && Word_Pos!=(page+1)*300-1) Word_Pos++;
  579.          }
  580.            else
  581.          {
  582.            sprintf(Word_Tail+strlen(Word_Tail),"%s",
  583.                Sub_Str(Words[New_Word],A_Pos+1,
  584.                    strlen(Words[New_Word])-A_Pos));
  585.            sprintf(Words[New_Word]+A_Pos,"%s",Word_Tail);
  586.            if (Word_Pos>strlen(Words[New_Word])+Text_Base) Word_Pos--;
  587.          }
  588.            Show_Word(New_Word,page);
  589.          }
  590.       Word_X=Word_Pos%150;Word_Y=(Word_Pos/150)%2;
  591.       High_Light_Char(Word_X,Word_Y);
  592.     }
  593. }
  594.  
  595. void Edit_Word(Button,Mouse_x,Mouse_y)
  596.   int Button,Mouse_x,Mouse_y;
  597. {
  598.   Use_Font("7x14");if (Word_Num>=0) Word_Num=-Word_Num;
  599.  
  600.   switch (Button)
  601.     {
  602.       case Button1:if (In_Text(Mouse_x,Mouse_y)==1) Add_Word(Mouse_x,Mouse_y,1);
  603.                    else if ((Mouse_y-148)%Dist<10) Re_New_Pos(Mouse_x,Mouse_y);
  604.     break;
  605.       case Button2:if (In_Text(Mouse_x,Mouse_y)==1) Add_Word(Mouse_x,Mouse_y,2);
  606.                    else if ((Mouse_y-148)%Dist<10) Add_Word(Mouse_x,Mouse_y,0);
  607.     break;
  608.       case Button3:if (In_Text(Mouse_x,Mouse_y)==1) 
  609.                  Add_Word(Mouse_x,Mouse_y,-1);
  610.                    else if ((Mouse_y-148)%Dist<10) Add_Word(Mouse_x,Mouse_y,-2);
  611.     break;
  612.     }
  613. }
  614.  
  615.