home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / fish / 911-930 / ff925 / donsgenies / frenchgenies.lha / Rexx / TexteMulticolor.pprx < prev    next >
Text File  |  1993-08-03  |  5KB  |  142 lines

  1. /*
  2. @BTexteMulticouleur @P @I Ecrit et © par Don Cox en décembre 1992
  3. @IN'est pas du Domaine Publique. Tous Droits Réservés.
  4. Traduit et modifié par Fabien Larini le 31/07/93.
  5.     
  6. Ce Génie applique une couleur aléatoire au texte sélectionné. 
  7. Avertissements : il est lent, il augmente la taille du texte (ajout de 
  8. codes de formatages) d'un facteur de 8 ou 9, il ralenti PPage. Donc, 
  9. utilisez le à la fin de votre mise en page. Il demande et sauve dans
  10. son fichier de configuration le répertoire où il stocke ses fichiers 
  11. temporaires.
  12. */
  13.  
  14.  
  15. /*MulticolourText*/
  16. /* This Genie applies random colours to a selected block of text. Warnings:
  17. it is slow, it increases the length of the selected text by a factor of 8 or
  18. 9 (because of all the style codes needed), and it slows ProPage down to a 
  19. crawl. So only do it at the end when you have got everything else right.
  20.  
  21. Written by Don Cox  ©  Dec 92  Not Public Domain. All rights reserved. */
  22.  
  23. signal on error
  24. signal on syntax
  25. address command                                  
  26.     
  27. tempdir = ""
  28. pos = 0
  29. fichiercfg = "rexx:TexteMulticolor.cfg"
  30. /* Demande si nouvelle config */
  31. if exists(fichiercfg) then
  32.     idem = ppm_Inform(2,"Utilisation de la configuration sauvée ?","Non","Oui")
  33.  
  34. /* Si fichier inexistant ou si utilisateur veut changer la config */
  35. if (~exists(fichiercfg) | idem=0) then do
  36.     /* Quel viewer */
  37.     tempdir = ppm_GetFileName("Choix du Répertoire Temporaire","","")
  38.     if tempdir = "" then exit_msg("Opération Annulée")
  39.     
  40.     /* Extrait le chemin */
  41.     pos = max(lastpos(":",tempdir),lastpos("/",tempdir))
  42.     tempdir = delstr(tempdir,pos+1)
  43.  
  44.     /* Sauver dans fichier ? */
  45.     if ppm_Inform(2,"Sauvegarder dans le fichier de configuration ?","Non","Oui") = 1 then do
  46.         if open(cfg,fichiercfg,"W") then do
  47.             call writeln(cfg,tempdir)
  48.             call close(cfg)
  49.         end
  50.         else
  51.             exit_msg("Impossible de sauvegarder le fichier de configuration")
  52.         end
  53.     end
  54. /* Chargement du fichier de config */
  55. else if idem = 1 then do
  56.         if open(cfg,fichiercfg,"R") then do
  57.             tempdir = readln(cfg)
  58.             call close(cfg)
  59.             end
  60.         else
  61.             exit_msg("Impossible de lire le fichier de configuration")
  62.         end    
  63.                                     
  64. tempfile = tempdir||"textefile.temp"
  65.  
  66. if word(ppm_GetState(), 1) ~= 3 then exit_msg("Vous devez être en mode Edition pour utiliser ce Génie")
  67.  
  68. text = ppm_GetBlockText(0)
  69. if text = '' then exit_msg("Pas de Texte Sélectionné")
  70.  
  71.  
  72. collist = ppm_GetColorList()
  73. collist = substr(collist, pos('0a'x, collist) + 1) /* It begins with a number */
  74. chosen = ppm_SelectFromList("Selection des Couleurs",36,24,1,collist)
  75. if chosen = "" then exit_msg("Pas de Couleurs Choisies")
  76.  
  77. n=1
  78. do forever  /* put colours into a compound variable  */
  79.     parse var chosen acolour "0a"x chosen
  80.     if acolour = "" then break
  81.     colours.n = acolour
  82.     n=n+1
  83.     end
  84. colournumber = n-1
  85.  
  86. call ppm_ShowStatus("Traitement du Text ...")
  87.  
  88. /* Split into sections to avoid trouble with ARexx's limit of 64k on length of strings  */
  89. sections = (length(text)%2000)+1
  90. do i=1 to sections
  91.     texts.i.endofsection = 2000
  92.     if i = sections then texts.i.endofsection = length(text)//2000
  93.     texts.i.thisSection = substr(text, (2000*(i-1))+1, texts.i.endofsection)
  94.     end
  95.  
  96. do i = 1 to sections
  97.     position = 1
  98.     newtext = ""
  99.     do until position = texts.i.endofsection+1
  100.         randcol = random(1,colournumber,time("s"))
  101.         thiscolour = colours.randcol
  102.         randbase = "\c<"||thiscolour||">"
  103.         nextchar = substr(texts.i.thisSection, position, 1)
  104.         newtext = newtext||randbase||nextchar
  105.         position = position+1
  106.         end
  107.     if i = 1 then call ppm_SaveText(tempfile,newtext)
  108.     if i>1 then call ppm_SaveMoreText(tempfile,newtext)
  109. end
  110.  
  111. call ppm_ShowStatus("Effacement de l'Ancien Texte ...")
  112. success = ppm_Cut()
  113. if success ~= 1 then exit_msg("Effacement Impossible")
  114. call ppm_ShowStatus("Insertion du Nouveau Texte ...")
  115. success = ppm_InsertFile(tempfile)
  116. if success~=1 then exit_msg("Insertion du Nouveau Texte Impossible")
  117.  
  118. if lastpos(" ",tempfile) ~= 0 then tempfile = '22'x||tempfile||'22'x
  119. "delete > nil: "tempfile
  120. call exit_msg()
  121. end
  122.  
  123.  
  124.  
  125. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  126.  
  127. error:
  128. syntax:
  129.     do
  130.     exit_msg("Arrêt du Génie dû à l'erreur: "errortext(rc))
  131.     end
  132.  
  133. exit_msg:
  134.     do
  135.     parse arg message
  136.     if message ~= "" then
  137.     call ppm_Inform(1,message,)
  138.     call ppm_ClearStatus()
  139.     exit
  140.     end
  141.  
  142.