Commit 101d18fe authored by Sébastien Wilmet's avatar Sébastien Wilmet
Browse files

Have same coding style for for loops in Vala and C

To make the life easier for contributors (and to myself too). Reduce the
number of differences between the coding style in Vala and C.
parent 87b28516
......@@ -29,10 +29,10 @@ For Vala:
- Curly braces are always on a separate line.
- For one-line blocks (if, for, while, etc), no curly braces.
- Some spaces almost everywhere:
- function (blah); // not function(blah);
- int num = 5; // not int num=5;
- if (! foo) // not if (!foo)
- for (int i = 0 ; i < max ; i++) // not for(int i=0;i<max;i++)
- function (blah); // not function(blah);
- int num = 5; // not int num=5;
- if (! foo) // not if (!foo)
- for (int i = 0; i < max; i++) // not for(int i=0;i<max;i++)
- etc...
- Do not use 'var' for declaring variables, unless the type is very long.
The type of a variable is useful to understand the code, it is a form of
......@@ -44,7 +44,6 @@ For C:
- No maximum line length (but short lines are better).
- Spacing differences with Vala:
- if (!foo)
- for (int i = 0; i < max; i++)
- Note that the GNU coding style was previously used, all the *.c files
have been converted to the GtkSourceView coding style with the uncrustify
config file (see the scripts/ directory in the GtkSourceView git
......
......@@ -76,7 +76,7 @@ private class GenerateSymbols : Object
break;
case "documentclass":
for (int i = 0 ; i < attr_names.length ; i++)
for (int i = 0; i < attr_names.length; i++)
{
switch (attr_names[i])
{
......@@ -91,7 +91,7 @@ private class GenerateSymbols : Object
break;
case "preamble":
for (int i = 0 ; i < attr_names.length ; i++)
for (int i = 0; i < attr_names.length; i++)
{
switch (attr_names[i])
{
......@@ -106,7 +106,7 @@ private class GenerateSymbols : Object
break;
case "convert":
for (int i = 0 ; i < attr_names.length ; i++)
for (int i = 0; i < attr_names.length; i++)
{
switch (attr_names[i])
{
......@@ -126,7 +126,7 @@ private class GenerateSymbols : Object
symbol.name = null;
symbol.math = false;
symbol.package = null;
for (int i = 0 ; i < attr_names.length ; i++)
for (int i = 0; i < attr_names.length; i++)
{
switch (attr_names[i])
{
......@@ -153,7 +153,7 @@ private class GenerateSymbols : Object
break;
case "document":
for (int i = 0 ; i < attr_names.length ; i++)
for (int i = 0; i < attr_names.length; i++)
{
switch (attr_names[i])
{
......
......@@ -206,7 +206,7 @@ public class BuildToolDialog : GLib.Object
typeof (string) // the name of the post processor
);
for (int type = 0 ; type < Latexila.PostProcessorType.NB_TYPES ; type++)
for (int type = 0; type < Latexila.PostProcessorType.NB_TYPES; type++)
{
unowned string name = Latexila.PostProcessor.get_name_from_type (
(Latexila.PostProcessorType) type);
......
......@@ -846,7 +846,7 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
throws MarkupError
{
_current_command = CompletionCommand ();
for (int attr_num = 0 ; attr_num < attr_names.length ; attr_num++)
for (int attr_num = 0; attr_num < attr_names.length; attr_num++)
{
switch (attr_names[attr_num])
{
......@@ -875,7 +875,7 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
_current_arg = CompletionArgument ();
_current_arg.optional = false;
for (int attr_num = 0 ; attr_num < attr_names.length ; attr_num++)
for (int attr_num = 0; attr_num < attr_names.length; attr_num++)
{
switch (attr_names[attr_num])
{
......@@ -899,7 +899,7 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
{
_current_choice = CompletionChoice ();
for (int attr_num = 0 ; attr_num < attr_names.length ; attr_num++)
for (int attr_num = 0; attr_num < attr_names.length; attr_num++)
{
switch (attr_names[attr_num])
{
......
......@@ -355,7 +355,7 @@ public class Document : Tepl.Buffer
begin_user_action ();
for (int line_num = start_line ; line_num <= end_line ; line_num++)
for (int line_num = start_line; line_num <= end_line; line_num++)
{
if (cur_iter.ends_line ())
// Don't insert a trailing space.
......@@ -380,7 +380,7 @@ public class Document : Tepl.Buffer
begin_user_action ();
for (int i = start_line ; i <= end_line ; i++)
for (int i = start_line; i <= end_line; i++)
{
get_iter_at_line (out start, i);
......
......@@ -603,7 +603,7 @@ public class DocumentStructure : GLib.Object
private void clear_all_structure_marks ()
{
for (int i = 0 ; i < _nb_marks ; i++)
for (int i = 0; i < _nb_marks; i++)
{
string mark_name = MARK_NAME_PREFIX + i.to_string ();
TextMark? mark = _doc.get_mark (mark_name);
......@@ -1106,7 +1106,7 @@ public class DocumentStructure : GLib.Object
/* Do the same for all the children */
int nb_children = _model.iter_n_children (tree_iter);
for (int child_num = 0 ; child_num < nb_children ; child_num++)
for (int child_num = 0; child_num < nb_children; child_num++)
{
TreeIter child_iter;
bool child_iter_set = _model.iter_nth_child (out child_iter, tree_iter,
......
......@@ -584,7 +584,7 @@ public class MainWindow : ApplicationWindow
{
Gee.List<Document> all_documents = new Gee.LinkedList<Document> ();
int nb_documents = _documents_panel.get_n_pages ();
for (int i = 0 ; i < nb_documents ; i++)
for (int i = 0; i < nb_documents; i++)
{
DocumentTab tab = _documents_panel.get_nth_page (i) as DocumentTab;
all_documents.add (tab.document);
......@@ -614,7 +614,7 @@ public class MainWindow : ApplicationWindow
int nb_documents = _documents_panel.get_n_pages ();
for (int i = 0 ; i < nb_documents ; i++)
for (int i = 0; i < nb_documents; i++)
{
DocumentTab tab = _documents_panel.get_nth_page (i) as DocumentTab;
all_views.add (tab.document_view);
......
......@@ -129,7 +129,7 @@ public class MainWindowDocuments
unowned SList<RadioAction> group = null;
for (int doc_num = 0 ; doc_num < nb_docs ; doc_num++)
for (int doc_num = 0; doc_num < nb_docs; doc_num++)
{
DocumentTab tab = _documents_panel.get_nth_page (doc_num) as DocumentTab;
string action_name = get_list_action_name (doc_num);
......
......@@ -169,7 +169,7 @@ public class MostUsedSymbols : GLib.Object
string id = null;
int num = 0;
for (int i = 0 ; i < attr_names.length ; i++)
for (int i = 0; i < attr_names.length; i++)
{
switch (attr_names[i])
{
......
......@@ -186,7 +186,7 @@ public class Projects
if (doc.location == null)
continue;
for (int i = 0 ; i < projects.size ; i++)
for (int i = 0; i < projects.size; i++)
{
if (doc.location.has_prefix (projects[i].directory))
{
......@@ -207,7 +207,7 @@ public class Projects
case "project":
Project project = Project ();
for (int i = 0 ; i < attr_names.length ; i++)
for (int i = 0; i < attr_names.length; i++)
{
switch (attr_names[i])
{
......
......@@ -72,7 +72,7 @@ public class GotoLine : Grid
string text = entry.get_text ();
// check if all characters are digits
for (int i = 0 ; i < text.length ; i++)
for (int i = 0; i < text.length; i++)
{
unichar c = text[i];
if (! c.isdigit ())
......
......@@ -328,7 +328,7 @@ public class StructureModel : TreeModel, GLib.Object
unowned int[] indices = path.get_indices ();
unowned Node<StructData?> node = _tree;
for (int cur_depth = 0 ; cur_depth < depth ; cur_depth++)
for (int cur_depth = 0; cur_depth < depth; cur_depth++)
{
int indice = indices[cur_depth];
if (indice < 0 || node.n_children () <= indice)
......@@ -781,7 +781,7 @@ public class StructureModel : TreeModel, GLib.Object
var list = get_list (node.data.type);
return_val_if_fail (list != null, -1);
for (int num = 0 ; num < list.size ; num++)
for (int num = 0; num < list.size; num++)
{
if (list[num] == node)
return num;
......
......@@ -292,7 +292,7 @@ private class NormalSymbols : Gtk.ListStore
symbol.package_required = null;
string icon_file = null;
for (int i = 0 ; i < attr_names.length ; i++)
for (int i = 0; i < attr_names.length; i++)
{
switch (attr_names[i])
{
......
......@@ -210,11 +210,11 @@ namespace Utils
// go to the common dir
uint nb_remaining_origin_dirs = origin_dirs.length () - nb_common_dirs;
for (uint i = 0 ; i < nb_remaining_origin_dirs ; i++)
for (uint i = 0; i < nb_remaining_origin_dirs; i++)
relative_path += "../";
// go to the target dir
for (uint i = nb_common_dirs ; i < target_dirs.length () ; i++)
for (uint i = nb_common_dirs; i < target_dirs.length (); i++)
{
File cur_target_dir = target_dirs.nth_data (i);
relative_path += cur_target_dir.get_basename () + "/";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment