[Résolu] Mise en commentaire dans XCode

Philippe49Philippe49 Membre
avril 2010 modifié dans Xcode et Developer Tools #1
Le script "Un/Comment selection" de XCode ne marche plus depuis quelques temps : il ne met plus que la première ligne en commentaire en laissant les autres lignes intactes, comme si la sélection était désormais limitée  à  une seule ligne.

Une idée sur un changement à  faire sur le script perl utilisé :

<br />#! /usr/bin/perl -w<br />#<br /># un_commentLines.pl - 	Comments or uncomments the selected lines<br />#			Uses &#39;# &#39; for Perl and shell scripts; &#39;// &#39; otherwise<br /><br />my $outputString = &quot;&quot;;<br />my $perlCmt = &quot;#&quot;;<br />my $cCmt = &quot;//&quot;;<br /><br /># Get the first few lines of the file<br />my $fileString = &lt;&lt;&#39;HEADTEXT&#39;;<br />%%%{PBXHeadText}%%%<br />HEADTEXT<br /><br /><br /># determine the type of file we have by looking for the #! line at the top<br /># careful--it might already be commented out!<br />my $commentString;<br />if ($fileString =~ m!^($perlCmt|$cCmt)?#&#092;!&#092;s*.*?/perl|^($perlCmt|$cCmt)?#&#092;!&#092;s*.*?/sh!) {<br />	$commentString = $perlCmt;<br />} else {<br />	$commentString = $cCmt;<br />}<br /><br />my @selection = &lt;STDIN&gt;;&nbsp; &nbsp; &nbsp;  # read the selection from standard input<br /><br /># no chars in selection, so create an empty selection<br />if (!@selection) {<br />&nbsp; &nbsp; push @selection, &quot;&quot;;<br />};&nbsp; <br /><br /># add or remove comment markers depending on the state of the first line of the selection<br /># if it is uncommented, comment all lines.&nbsp; If it is commented, remove comment markers, if present<br />my $firstLineOfSelection = $selection[0]; #get first line<br />my $addingCommentsString = 1;<br />if ($firstLineOfSelection =~ /^$commentString/) { #selection starts with comment<br />&nbsp; &nbsp; $addingCommentsString = 0;<br />}<br /><br />foreach my $line (@selection) {<br />&nbsp; &nbsp; if ($addingCommentsString == 1) {<br />&nbsp; &nbsp; &nbsp; &nbsp; $outputString .= $commentString.$line;<br />&nbsp; &nbsp; } else {<br />&nbsp; &nbsp; &nbsp; &nbsp; $line =~ s/^$commentString//;<br />&nbsp; &nbsp; &nbsp; &nbsp; $outputString .= $line;<br />&nbsp; &nbsp; }<br />}<br /><br />print &quot;%%%{PBXSelection}%%%&quot;;<br />print $outputString;<br />print &quot;%%%{PBXSelection}%%%&quot;;<br />


Réponses

  • sekaijinsekaijin Membre
    17:10 modifié #2
    tu n'as pas un pb sur la façon d'encoder les fin de ligne

    unix utilise LF (char(13))
    Windows utiliser CRLF(char(10)char(13))
    et à  l'origine MacOS utilise CR (char(10))

    pour qu'un shell script s'éxécute correctement i doit utiliser le mode unix soit LF
    si ton fichier utilise CR c'est comme s'il n'y avais aucun retour à  la ligne

    en général un cat dans le terminal t'affiche le fichier avec des ^M s'il est mal encodé

    A+JYT
  • Philippe49Philippe49 Membre
    17:10 modifié #3
    [move] [/move]

    Effectivement, c'est le problème : mon fichier récalcitrant contient des '\r' en fin de ligne au lieu des '\n'
    Pas compris comment ils sont arrivés là , mais bon ...

  • AliGatorAliGator Membre, Modérateur
    17:10 modifié #4
    Pomme-I sur le fichier .m, et dans les infos, onglet "General" tu peux choisir/changer l'encodage de texte, mais aussi les "Line Endings" ;)
Connectez-vous ou Inscrivez-vous pour répondre.