[Résolu] Mise en commentaire dans XCode
Philippe49
Membre
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é :
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 '# ' for Perl and shell scripts; '// ' otherwise<br /><br />my $outputString = "";<br />my $perlCmt = "#";<br />my $cCmt = "//";<br /><br /># Get the first few lines of the file<br />my $fileString = <<'HEADTEXT';<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)?#\!\s*.*?/perl|^($perlCmt|$cCmt)?#\!\s*.*?/sh!) {<br /> $commentString = $perlCmt;<br />} else {<br /> $commentString = $cCmt;<br />}<br /><br />my @selection = <STDIN>; # read the selection from standard input<br /><br /># no chars in selection, so create an empty selection<br />if (!@selection) {<br /> push @selection, "";<br />}; <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. 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 /> $addingCommentsString = 0;<br />}<br /><br />foreach my $line (@selection) {<br /> if ($addingCommentsString == 1) {<br /> $outputString .= $commentString.$line;<br /> } else {<br /> $line =~ s/^$commentString//;<br /> $outputString .= $line;<br /> }<br />}<br /><br />print "%%%{PBXSelection}%%%";<br />print $outputString;<br />print "%%%{PBXSelection}%%%";<br />
Connectez-vous ou Inscrivez-vous pour répondre.
Réponses
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
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 ...