home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / educatio / xcoral16.zip / CHARS_CM.C < prev    next >
C/C++ Source or Header  |  1993-01-15  |  20KB  |  861 lines

  1. /*
  2. ** Copyright 1989, 1992 by Lionel Fournigault
  3. **
  4. ** Permission to use, copy, and distribute for non-commercial purposes,
  5. ** is hereby granted without fee, providing that the above copyright
  6. ** notice appear in all copies and that both the copyright notice and this
  7. ** permission notice appear in supporting documentation.
  8. ** The software may be modified for your own purposes, but modified versions
  9. ** may not be distributed.
  10. ** This software is provided "as is" without any expressed or implied warranty.
  11. **
  12. **
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <X11/Xlib.h>
  17. #include <X11/cursorfont.h>
  18. #include <X11/Xutil.h>
  19. #include <X11/keysym.h>
  20. #include <ctype.h>
  21. #include <string.h>
  22. #include <sys/time.h>
  23. #include <signal.h>
  24. #include <malloc.h>
  25.  
  26. #include "text.h"
  27. #include "flist.h"
  28.  
  29. extern Display *dpy;
  30. static int toggle_del = 0;
  31. static int MatchChar (), MatchChar ();
  32. static void AligneChar (), InsertLines (), Indent (), donothing (),
  33.     SmallTime (), DisplayModel () ;
  34.  
  35.  
  36. /*
  37. **    Function name : f_impc
  38. **
  39. **    Description : Imprime un caractere ( position courrante ). 
  40. **    Input : Le caractere.
  41. **    Ouput :
  42. */
  43. void f_impc ( text, c )
  44.     Text *text;
  45.     char c;
  46. {
  47.     register int newpos;
  48.     register char cc;
  49.     register int old_x, old_y;
  50.        
  51.     TextCursorOff ( text );
  52.     InsertNchar ( text -> buf, &c, 1 );
  53.  
  54.     if ( (text -> modif == False) && (strcmp(text -> filename,"NoName")==NULL) ) { 
  55.         text -> modif = True; 
  56.         SetScrollLine ( text -> swin , 1 );
  57.         ShowScrollFrame ( dpy, text -> swin );
  58.     }
  59.  
  60.     SetCurrentLine ( text );
  61.     switch ( c ) {
  62.         case ')': cc = '(';break;
  63.         case '}': cc = '{';break;
  64.         case ']': cc = '[';break;
  65.         default: cc = '\0';break;
  66.     }
  67.     if ( cc != '\0' ) {
  68.         if ( (newpos = MatchChar ( text , cc, c, text -> n1 )) >= 0 ) {
  69.             TextCursorOn ( text );
  70.             TextCursorOff ( text );
  71.             old_x = text -> x_pos; old_y = text -> y_pos;
  72.             GotoPos ( text, LeftBuf (text -> buf),  newpos, -1 );
  73.             TextCursorOn ( text );
  74.             XSync ( dpy, False );
  75.             SmallTime ( (long) 200000  );
  76.             TextCursorOff ( text );
  77.             (void) MoveToXYinTextWindow ( text, old_x, old_y );
  78.                     AligneChar ( text, c );             
  79.         }
  80.     }    
  81.     TextCursorOn ( text );
  82.     SetTextModif ( text );
  83. }
  84.  
  85.  
  86. /*
  87. **    Function name : AligneChar
  88. **
  89. **    Description : aligne le caractere '}' en mode C et C++
  90. **    Input : Le text courant, le caractere a aligner.
  91. **    Ouput :
  92. */
  93. static void AligneChar ( text, c )
  94.     Text *text;
  95.     register char c;
  96. {
  97.     int len;
  98.     register char *s = (char *) GetCurrentLine ( text -> buf, &len );
  99.     register int len_s;
  100.  
  101.     if ( (text -> mode == TEXT) || (text -> mode) == LATEX || c != '}' )
  102.         return;
  103.  
  104.     len_s =  --len;    /* On ne tient pas compte du dernier caractere */
  105.     while ( len ) {     /* On verifie que la ligne est vide */
  106.         if ( (*s != '\t') && (*s != ' ') ) return;
  107.         s ++; 
  108.         len --;
  109.     }
  110.     len = strlen ( text -> indent );     /* nb de caractere a enlever */
  111.     if ( len > len_s ) return;     /* Pour ne pas sortir de la ligne courante */
  112.  
  113.     BackwardChar ( text );        /* On saute le '}' */
  114.     DeleteNchar ( text -> buf, len );    /* On enleve ce qu'il faut */
  115.  
  116.     (void) ForwardChar ( text );
  117.  
  118.     ClipOn ( text, NULL );
  119.     ClearLine ( text, text -> n1 + 1 );    /* On affiche la ligne */
  120.     SetCurrentLine ( text );
  121.     ClipOff ( text );
  122. }
  123.  
  124.  
  125. /*
  126. **    Function name : MatchChar
  127. **
  128. **    Description : En mode C, C++, recherche le '{',
  129. **        '(', ou '[' qui match.
  130. **    Input : Le text courant,
  131. **        le caratere courant '}', ')', ou ']',
  132. **        le caractere a matcher '{', '(' ou '[', 
  133. **        le nombre de ligne visible au dessus de
  134. **        la ligne courante.
  135. **    Ouput : La position relative du caractere a matcher.
  136. */
  137. static int MatchChar ( text, c,ic, n )
  138.     Text *text;
  139.     register char c, ic;
  140.     register int n;
  141. {
  142.     register char *start = (char * ) LeftBuf ( text -> buf );
  143.     register char *end = (char * ) TopBuf ( text -> buf );
  144.     register int line = 1;
  145.     register int i = 2;
  146.     register int count = 0;
  147.     register int audela = False;
  148.     char tmp [32];
  149.     
  150.     start --; /* On saute le premier pour ne pas incrementer count */
  151.     ClearMessageWindow ( text -> mwin );
  152.     while ( start >= end ) {
  153.         if ( *start == c ) {
  154.             if ( count != 0 )
  155.                 count--;
  156.             else {
  157.                 if ( audela == True ) {
  158.                     (void) sprintf ( tmp, "Match '%c' at line %d",  c,
  159.                         text -> no_current_line - line );
  160.                     DisplayMessage ( text -> mwin, tmp );
  161.                     return -1;
  162.                 }
  163.                 else
  164.                     return i;
  165.             }
  166.         }
  167.         if ( n == 0 ) {
  168.             /* On est sur la premiere ligne de la page courante */
  169.             if ( line > 1 ) audela = True;
  170.         }
  171.         else 
  172.             if ( line > n ) audela = True;
  173.  
  174.         if ( *start == '\n' ) line++;
  175.         if ( *start == ic ) count++;
  176.         start --;
  177.         i ++;
  178.     }
  179.     DisplayMessage ( text -> mwin, "No match" );
  180.     return -1;
  181. }
  182.  
  183.  
  184. /*
  185. **    Function name : f_tab
  186. **
  187. **    Description : Tabulation.
  188. **    Input : Le text courant. 
  189. **    Ouput :
  190. */
  191. void f_tab ( text )
  192.     Text *text;
  193. {
  194.     register int ligne = text -> n1 + 1;
  195.  
  196.     TextCursorOff ( text );
  197.     InsertNchar ( text -> buf, "\t", 1 );
  198.  
  199.     if ( (text -> modif == False) && (strcmp(text -> filename,"NoName")==NULL) ) { 
  200.               text -> modif = True;
  201.         SetScrollLine ( text -> swin , 1 );
  202.         ShowScrollFrame ( dpy, text -> swin );
  203.     }
  204.  
  205.     ClipOn ( text, NULL );
  206.     ClearLine ( text, ligne );
  207.     SetCurrentLine ( text );
  208.     ClipOff ( text );
  209.     TextCursorOn ( text );
  210.        SetTextModif ( text );
  211. }
  212.  
  213.  
  214. /*
  215. **    Function name : f_return
  216. **
  217. **    Description : Retour chariot.
  218. **    Input : Le text courant.
  219. **    Ouput :
  220. */
  221. void f_return ( text )
  222.     Text *text;
  223. {
  224.     TextCursorOff ( text );
  225.  
  226.     if ( (text -> modif == False) && (strcmp(text -> filename,"NoName")==NULL) ) { 
  227.         text -> modif = True;
  228.         SetScrollLine ( text -> swin , 1 );
  229.         ShowScrollFrame ( dpy, text -> swin );
  230.     }
  231.  
  232.     if ( text -> n2 == NULL ) 
  233.         CurrentLineToMiddle ( text );
  234.  
  235.     InsertNchar ( text -> buf, "\n", 1 );
  236.     
  237.     text -> n1 ++;
  238.     text -> n2 --;
  239.     text ->  no_current_line ++;
  240.     text -> lines_in_buf ++;
  241.  
  242.     if ( (text -> mode == CPLUS ) || ( text -> mode == STD_C )) {
  243.         Indent ( text );
  244.     }
  245.  
  246.     SetLinesTable ( text );
  247.     ClipOn ( text, text -> n1 -1);
  248.     RefreshPage ( text );
  249.     ClipOff ( text );
  250.  
  251.     SetScrollLine ( text -> swin , text -> lines_in_buf );
  252.     ShowScrollFrame ( dpy, text -> swin );
  253.     (void) MoveScrollBar ( dpy, text -> swin, 
  254.         CURRENT, text -> no_current_line - text -> n1 - 1 );
  255.  
  256.     TextCursorOn ( text );
  257.     SetTextModif ( text );
  258. }
  259.  
  260.  
  261. /*
  262. **    Function name : Indent
  263. **
  264. **    Description : Very trivial auto indent.
  265. **    Input : Le text courant.
  266. **    Ouput :
  267. */
  268. static void Indent ( text )
  269.     Text *text;
  270. {
  271.     register char *start = (char * ) LeftBuf ( text -> buf );
  272.     register char *end = (char * ) TopBuf ( text -> buf );
  273.     register int indent = 0;
  274.  
  275.     start --; /* On saute le dernier return */
  276.     while ( start >= end ) {
  277.         if ( (*start == '\n') && (*(start+1) != ' ') && (*(start+1) != '\t') &&(*(start+1) != '\n') ) {
  278.             break;
  279.         }
  280.         if ( (*start == '(') || (*start == '{') || (*start == '[') ) indent++;
  281.         if ( (*start == ')') || (*start == '}') || (*start == ']') ) indent--;
  282.         start --;
  283.     }
  284.     if ( indent < 0 ) indent = 0;
  285.     while ( indent > 0 ) {
  286.         InsertNchar ( text -> buf, text -> indent, strlen ( text -> indent) );        
  287.         indent--;
  288.     }
  289. }
  290.  
  291.  
  292. /*
  293. **    Function name : f_delete
  294. **
  295. **    Description : Delete ou backspace.
  296. **    Input : Le text courant.
  297. **    Ouput :
  298. */
  299. void f_delete ( text)
  300.     Text *text;
  301. {
  302.     char c;
  303.  
  304.     if ( TextInBuf ( text ) == False ) 
  305.         return;
  306.     TextCursorOff ( text );
  307.     GetPrevChar ( text -> buf, &c );
  308.  
  309.     if ( c == '\n' ) {
  310.         if ( text -> n1 == 0 ) 
  311.             CurrentLineToMiddle ( text );
  312.         DeleteNchar ( text -> buf, 1 );
  313.         text -> n1 --;
  314.         text -> n2 ++;
  315.         text -> no_current_line--;
  316.         text -> lines_in_buf --;
  317.         SetLinesTable ( text );
  318.         ClipOn ( text, text -> n1 );
  319.         RefreshPage ( text );
  320.         ClipOff ( text );
  321.         SetScrollLine ( text -> swin , text -> lines_in_buf );
  322.         ShowScrollFrame ( dpy, text -> swin );
  323.         if ( text -> no_current_line == 1 ) {
  324.             (void) MoveScrollBar ( dpy, text -> swin, FIRST, 0 );
  325.         }
  326.         else
  327.             (void) MoveScrollBar ( dpy, text -> swin, 
  328.                 CURRENT, text -> no_current_line - text -> n1 - 1 );
  329.     }
  330.     else {
  331.         DeleteNchar ( text -> buf, 1 );
  332.         ClipOn ( text, NULL );
  333.         ClearLine ( text, text -> n1 + 1 );
  334.         SetCurrentLine ( text );
  335.         ClipOff ( text );
  336.        }
  337.     TextCursorOn ( text );
  338.     SetTextModif ( text );    
  339. }
  340.  
  341.  
  342. /*
  343. **    Function name : Controle_D
  344. **
  345. **    Description : Efface le caractere courant.
  346. **    Input : Le text courant.
  347. **    Ouput :
  348. */
  349. void Control_D ( text )
  350.     Text *text;
  351. {
  352.     if ( TextInBuf ( text ) == False ) 
  353.         return;
  354.     if ( ForwardChar ( text ) == True ) {
  355.         f_delete ( text );
  356.         SetTextModif ( text );
  357.     }
  358. }
  359.  
  360.  
  361. /*
  362. **    Function name : Control_K
  363. **
  364. **    Description : Delete une ou plusieurs lignes
  365. **    Input : Le text courant.
  366. **    Ouput : Le nb de lignes.
  367. */
  368. void Control_K ( text, n )
  369.     Text *text;
  370.     register int n;
  371. {
  372.        register char *p;
  373.        int len, dn;
  374.        if ( TextInBuf ( text ) == False ) 
  375.           return;
  376.  
  377.        p = (char *) DeleteLines ( text -> buf, n, &len, &dn );
  378.        
  379.        StoreInKillBuf ( p, len, dn );
  380. #ifdef DEBUG
  381.        fprintf ( stderr, "n = %d Delete lines = %d len = %d\n", n, dn, len );
  382. #endif DEBUG
  383.        SetLinesTable ( text );
  384.  
  385.        ClipOn ( text, text -> n1 );
  386.        RefreshPage ( text );
  387.        ClipOff ( text );
  388.  
  389.        if ( dn > 0 ) {
  390.           text -> lines_in_buf = GetNumberOfLineInBuf ( text -> buf );
  391.           SetScrollLine ( text -> swin , text -> lines_in_buf );
  392.           ShowScrollFrame ( dpy, text -> swin );
  393.           (void) MoveScrollBar ( dpy, text -> swin, 
  394.                  CURRENT, text -> no_current_line - text -> n1 - 1 );
  395.        }
  396.     SetTextModif ( text );
  397. }
  398.  
  399.  
  400. /*
  401. **    Function name : Control_Y
  402. **
  403. **    Description : Restore un portion de texte.
  404. **    Input : Le text courant, le no a restorer.
  405. **    Ouput :
  406. */
  407. void Control_Y ( text, i )
  408.     Text *text;
  409.     register int i;
  410. {
  411.     register char *p;
  412.     int len, dn;
  413.  
  414.     TextCursorOff ( text );
  415.     p = (char *) RestoreKillBuf ( i, &len, &dn );
  416.     if ( p == NULL ) {
  417.         TextCursorOn ( text );
  418.         return;
  419.     }
  420. #ifdef DEBUG
  421.        fprintf ( stderr, "i = %d len = %d Restore lines = %d\n", i, len, dn );
  422.        write ( 1, p, len );
  423. #endif DEBUG
  424.     ClipOn ( text, NULL );
  425.     SetTextModif ( text );
  426.     if ( dn == 1 ) {
  427.         if ( len == 1 ) {  /* ligne vide */
  428.             f_return ( text );
  429.         }
  430.         else {
  431.             InsertNchar ( text -> buf, p, len );      
  432.             ClearLine ( text, text -> n1 + 1 );
  433.             SetCurrentLine ( text );
  434.         }
  435.     }
  436.     else 
  437.         InsertLines ( text, p, len, dn );
  438.  
  439.     ClipOff ( text );
  440.     TextCursorOn ( text );
  441. }
  442.  
  443.  
  444. /*
  445. **    Function name : DisplayKillBuffer
  446. **
  447. **    Description : Affiche la fenetre des choses tuees.
  448. **        et restore eventuellement.
  449. **    Input : Le text courant.
  450. **    Ouput :
  451. */
  452. void DisplayKillBuffer ( text ) 
  453. Text *text;
  454. {
  455.     register char *str;
  456.   
  457.        if ( GetVisibility ( dpy, text ) == False )
  458.         return;
  459.  
  460.     str = (char *) GetStringFromSelect ( text -> window, KILLBUF );
  461.     if ( str != 0 ) {
  462.                  /* str += 9; */
  463.         /* On vire le "Select : " */
  464.          /* On ne prend que les 2 premier caracteres */
  465.         *(str+2) = 0;
  466.         /* On restore la nieme entree */
  467.         Control_Y ( text, atoi(str) - 1 );
  468.               if ( str != 0 )
  469.                   (void) free ( str ); 
  470.               }
  471.     else
  472.         DisplayMessage ( text -> mwin, "Abort" );
  473. }
  474.  
  475.  
  476. /*
  477. **    Function name : GetBytesFromCutBuffer
  478. **
  479. **    Description : Comme son nom l'indique.
  480. **    Input : Le text courant.
  481. **    Ouput :
  482. */
  483. void GetBytesFromCutBuffer ( text )
  484.     Text *text;
  485. {
  486.     register int lines;
  487.     register char *s;
  488.     int nbytes;
  489.  
  490.     s = XFetchBuffer ( dpy, &nbytes, 0 );
  491.  
  492.     if ( (s != 0) && (nbytes != 0 )) {
  493.         TextCursorOff ( text );
  494.         ClipOn ( text, NULL );
  495.         lines = GetNewLine ( s, nbytes);
  496.         SetTextModif ( text );
  497.         if ( lines == 0 ) {
  498.             InsertNchar ( text -> buf, s, nbytes);
  499.             ClearLine ( text, text -> n1 + 1 );
  500.             SetCurrentLine ( text );
  501.         }
  502.         else {
  503.             InsertLines ( text, s, nbytes, lines );
  504.             RefreshScrollBar ( dpy, text -> swin );
  505.         }
  506.         TextCursorOn ( text );
  507.         ClipOff ( text );
  508.     }
  509. }
  510.  
  511.  
  512. /*
  513. **    Function name : InsertLines
  514. **
  515. **    Description : Insere une ou plusieurs lignes.
  516. **    Input : Le text courant, la chaine, sa longueur et
  517. **        le nombre de lignes.
  518. **    Ouput :
  519. */
  520. static void InsertLines ( text, s, nbytes, lines )
  521.     Text *text;
  522.     register char *s;
  523.     register int nbytes;
  524.     register int lines;
  525. {
  526.     InsertNchar ( text -> buf, s, nbytes );      
  527.     text -> no_current_line += lines;
  528.     text -> lines_in_buf = GetNumberOfLineInBuf ( text -> buf );
  529.     SetScrollLine ( text -> swin , text -> lines_in_buf );
  530.     ShowScrollFrame ( dpy, text -> swin );
  531.      
  532.     if ( text -> n2 < lines ) {
  533.         CurrentLineToMiddle ( text );
  534.     }
  535.     else {
  536.         text -> n1 += lines;
  537.         text -> n2 -= lines;
  538.         SetLinesTable ( text );
  539.         RefreshPage ( text );
  540.         (void) MoveScrollBar ( dpy, text -> swin, 
  541.             CURRENT, text -> no_current_line - text -> n1 - 1 );
  542.     }
  543. }
  544.  
  545.  
  546. /*
  547. **    Function name : StoreBytesInCutBuffer
  548. **
  549. **    Description : Selection.
  550. **    Input : Le text, la position du cursor.
  551. **    Ouput :
  552. */
  553. void StoreBytesInCutBuffer ( text, x, y )
  554.     Text *text;
  555.     register int x, y;
  556. {
  557.     register old_x = text -> x_pos;
  558.     register old_y = text -> y_pos;
  559.     register char *old_left = (char *) LeftBuf ( text -> buf );
  560.     register char *old_right = (char *) RightBuf ( text -> buf );
  561.     register char *new_left, *new_right;
  562.  
  563.     (void) MoveToXYinTextWindow ( text, x, y );
  564.     TextCursorOn ( text );
  565.     XSync ( dpy, False );
  566.     
  567.     new_left = (char *) LeftBuf ( text -> buf );
  568.     new_right = (char *) RightBuf ( text -> buf );
  569.  
  570.     if ( new_left > old_left )  { /* Deplacement vers la droite du curseur */
  571.         XStoreBytes ( dpy, old_left +1, new_left - old_left );
  572.     }
  573.     else {
  574.         XStoreBytes ( dpy, new_right, old_right - new_right );
  575.     }
  576.     toggle_del = False;
  577.     SmallTime ( (long) 200000 );    /* 0.20 secondes */
  578.     TextCursorOff ( text );
  579.     (void) MoveToXYinTextWindow ( text, old_x, old_y );
  580. }
  581.  
  582.  
  583. /*
  584. **    Function name : DeleteBytesFromCutBuffer
  585. **
  586. **    Description : Efface une slection.
  587. **    Input : Le text courant.
  588. **    Ouput :
  589. */
  590. void DeleteBytesFromCutBuffer ( text )
  591.     Text *text;
  592. {
  593.     register int lines;
  594.     register char *s;
  595.     int nbytes;
  596.  
  597.     s = XFetchBuffer ( dpy, &nbytes, 0 );
  598.  
  599.     if ( (s != 0) && (nbytes != 0 ) && (toggle_del == False) ) {
  600.         if ( (text -> modif == False) && (strcmp(text -> filename,"NoName")==NULL) ) {
  601.             return;
  602.         }
  603.         TextCursorOff ( text );
  604.         ClipOn ( text, NULL );
  605.         lines = GetNewLine ( s, nbytes);
  606.         (void) MoveHole ( text -> buf, nbytes );
  607.         DeleteNchar ( text -> buf, nbytes);
  608.  
  609.         SetTextModif ( text );
  610.  
  611.         if ( lines == 0 ) {
  612.             ClearLine ( text, text -> n1 + 1 );
  613.             SetCurrentLine ( text );
  614.         }
  615.         else {
  616.             text -> lines_in_buf = GetNumberOfLineInBuf ( text -> buf );
  617.             SetScrollLine ( text -> swin , text -> lines_in_buf );
  618.             ShowScrollFrame ( dpy, text -> swin );
  619.             SetLinesTable ( text );
  620.             RefreshPage ( text );
  621.             (void) MoveScrollBar ( dpy, text -> swin, 
  622.                 CURRENT, text -> no_current_line - text -> n1 - 1 );
  623.             RefreshScrollBar ( dpy, text -> swin );
  624.         }
  625.         TextCursorOn ( text );
  626.         ClipOff ( text );
  627.         toggle_del = True;
  628.     }
  629. }
  630.  
  631. static void donothing () {}
  632.  
  633.  
  634. /*
  635. **    Function name : SmallTime
  636. **
  637. **    Description : Un reveil
  638. **    Input : Le temps.
  639. **    Ouput :
  640. */
  641. static void SmallTime ( t )
  642.     register long t; /* micros-secondes */
  643. {
  644.     struct itimerval value, ovalue;
  645.     value.it_interval.tv_sec = 0;
  646.  
  647.     value.it_interval.tv_usec = t;
  648.  
  649.     value.it_value.tv_sec = 0;
  650.     value.it_value.tv_usec = t;
  651.     
  652.     (void) signal ( SIGALRM, donothing );
  653.     (void) setitimer ( ITIMER_REAL, &value, &ovalue );
  654.     (void) pause ();
  655.     (void) signal ( SIGALRM, SIG_IGN );
  656. }
  657.  
  658.  
  659. /*
  660. **    Function name : MakeClass
  661. **
  662. **    Description : Fabrique un squelette de classe.
  663. **    Input : Le text courant.
  664. **    Ouput :
  665. */
  666. void MakeClass ( text )
  667.     Text *text;
  668. {
  669.     register char *class_name, *parent_name, *str, *buf;
  670.        register int len;
  671.     char c = '\007';
  672.  
  673.     if ( text -> visible != VisibilityUnobscured ) {
  674.         XRaiseWindow ( dpy, text -> w_parent ); 
  675.         return;
  676.     }
  677.  
  678.        str = ( char *)  GetStringFromDialogBox ( text -> window, "Class name : " );
  679.  
  680.     if ( (str == 0) || (strncmp(str, &c, 1) == 0) ) {
  681.         DisplayMessage ( text -> mwin, "Abort" );
  682.         return;
  683.     }
  684.  
  685.        class_name = ( char * ) malloc ( (unsigned int) strlen (str) + 1);
  686.        (void) strcpy ( class_name, str );
  687.        str = ( char *)  GetStringFromDialogBox ( text -> window, "Parent class name : " );
  688.  
  689.        if ( str != 0 ) {
  690.            if ( strncmp(str, &c, 1) == 0 ) {
  691.             DisplayMessage ( text -> mwin, "Abort" );
  692.             return;
  693.         }        
  694.              parent_name = ( char * ) malloc ( (unsigned int) strlen (str) + 1);
  695.            (void) strcpy ( parent_name, str );
  696.         len = 6 * strlen ( class_name ) + strlen ( parent_name);
  697.         }
  698.     else 
  699.         len = 6 * strlen ( class_name );
  700.  
  701.     len += 256; /* Pour les commantaires */
  702.  
  703.     buf = ( char *) malloc ( (unsigned int) len );
  704.     bzero ( buf,  len );
  705.  
  706.     (void) sprintf ( buf, "\n//\n//\tClass name : %s\n//\n//\tDescription : \n//\nclass %s",
  707.         class_name, class_name );
  708.        if ( str != 0 ) {
  709.         (void) strcat ( buf, " : public " );
  710.         (void) strcat ( buf, parent_name );
  711.     }
  712.     (void) sprintf ( buf + strlen (buf),
  713.         " {\npublic:\n\t%s ();\n\t%s ( const %s & );\n\t~%s ();\n\t\nprotected:\nprivate:\n};\n",
  714.          class_name, class_name, class_name, class_name );
  715.  
  716.     DisplayModel ( text, buf, 15, 4 );
  717.     if ( class_name != 0 )
  718.            (void) free ( class_name );
  719.     if ( str != 0 ) {
  720.               if ( parent_name != 0 )
  721.                (void) free ( parent_name );
  722.     }
  723.        if ( buf != 0 )
  724.         (void) free ( buf );
  725. }
  726.  
  727.  
  728. /*
  729. **    Function name : MakeMethod
  730. **
  731. **    Description : Fabrique un squelette de methode.
  732. **    Input : Le text courant.
  733. **    Ouput :
  734. */
  735. void MakeMethod ( text )
  736.     Text *text;
  737. {
  738.     register char *buf, *method_name, *class_name, *str;
  739.     register int len;
  740.     char c = '\007';
  741.  
  742.     if ( text -> visible != VisibilityUnobscured ) {
  743.         XRaiseWindow ( dpy, text -> w_parent ); 
  744.         return;
  745.     }
  746.  
  747.        str = ( char *)  GetStringFromDialogBox ( text -> window, "Method name : " );
  748.        if ( (str == 0) || (strncmp(str, &c, 1) == 0) ) {
  749.         DisplayMessage ( text -> mwin, "Abort" );
  750.         return;
  751.     }
  752.        method_name = ( char * ) malloc ( (unsigned int) strlen (str) + 1);
  753.        (void) strcpy ( method_name, str );
  754.   
  755.     str = ( char *)  GetStringFromDialogBox ( text -> window, "Class name : " );
  756.  
  757.        if ( (str == 0) || (strncmp(str, &c, 1) == 0 ) ) {
  758.               if ( method_name != 0 )
  759.             (void) free ( method_name );
  760.         DisplayMessage ( text -> mwin, "Abort" );
  761.         return;
  762.     }
  763.  
  764.        class_name = ( char * ) malloc ( (unsigned int) strlen (str) + 1);
  765.     (void) strcpy ( class_name, str );
  766.  
  767.     len = ( 2 * strlen ( method_name )) + strlen ( class_name ) + 128;
  768.     buf = ( char *) malloc ( (unsigned int) len );
  769.     bzero ( buf,  len );
  770.  
  771.     (void) sprintf ( buf, 
  772.         "\n//\n//\tMethod name : %s\n//\n//\tDescription : \n//\tInput : \n//\tOuput :\n//\n%s :: %s ()\n{\n\t\n}\n",
  773.         method_name, class_name, method_name );
  774.  
  775.     DisplayModel ( text, buf, 12, 2 );
  776.     if ( method_name != 0 )
  777.            (void) free ( method_name );
  778.        if ( class_name != 0 )
  779.         (void) free ( class_name );
  780.        if ( buf != 0 )
  781.         (void) free ( buf );
  782. }
  783.  
  784.  
  785. /*
  786. **    Function name : MakeFunction
  787. **
  788. **    Description : Fabrique un squelette de fonction.
  789. **    Input : Le text courant.
  790. **    Ouput :
  791. */
  792. void MakeFunction ( text )
  793.     Text *text;
  794. {
  795.     register char *buf, *f_name, *str;
  796.     register int len;
  797.     char c = '\007';
  798.  
  799.     if ( text -> visible != VisibilityUnobscured ) {
  800.         XRaiseWindow ( dpy, text -> w_parent ); 
  801.         return;
  802.     }
  803.  
  804.        str = ( char *)  GetStringFromDialogBox ( text -> window, "Function name : " );
  805.        if ( (str == 0) || (strncmp(str, &c, 1) == 0) ) {
  806.         DisplayMessage ( text -> mwin, "Abort" );
  807.         return;
  808.     }
  809.        f_name = ( char * ) malloc ( (unsigned int) strlen (str) + 1);
  810.        (void) strcpy ( f_name, str );
  811.  
  812.     len = strlen ( f_name ) + 128;
  813.     buf = ( char *) malloc ( (unsigned int) len );
  814.     bzero ( buf,  len );
  815.  
  816.     (void) sprintf ( buf, 
  817.         "\n/*\n**\tFunction name : %s\n**\n**\tDescription : \n**\tInput : \n**\tOuput :\n*/\n%s ()\n{\n\t\n}\n",
  818.         f_name, f_name );
  819.  
  820.     DisplayModel ( text, buf, 12, 2 );
  821.  
  822.        if ( f_name != 0 )
  823.            (void) free ( f_name );
  824.        if ( buf != 0 )
  825.         (void) free ( buf );
  826. }
  827.  
  828.  
  829. /*
  830. **    Function name : DisplayModel
  831. **
  832. **    Description : Affiche les differents modeles
  833. **    Input : Le text courant, le buffer a afficher,
  834. **        le nombres de lignes, pour le retour
  835. **        du curseur.
  836. **    Ouput :
  837. */
  838. static void DisplayModel ( text, buf, lines, x )
  839.     Text *text;
  840.     register char *buf;
  841.     register int lines, x;    /* nb lines to insert, back */
  842. {
  843.     TextCursorOff ( text);
  844.     ClipOn ( text, 0 );
  845.     InsertLines ( text, buf, strlen (buf), lines ); 
  846.     SetTextModif ( text );
  847.     ClipOff ( text );
  848.  
  849.        (void) MoveToLine ( text -> buf, -x ); 
  850.        MoveToEline ( text );
  851.     text -> n1 -= x;
  852.        text -> n2 += x;
  853.        text -> no_current_line -= x;
  854.        (void) MoveScrollBar ( dpy, text -> swin, 
  855.         CURRENT, text -> no_current_line - text -> n1 - 1 );
  856.  
  857.        TextCursorOn ( text);
  858.     SetAndDisplayPage ( text ); 
  859. }
  860.  
  861.