En busca de un estándar entre lenguajes y arquitecturas, ¿de dónde es este código?

En busca de un estándar entre lenguajes y arquitecturas, ¿de dónde es este código?
Sin comentarios Facebook Twitter Flipboard E-mail
johnbo

Johnbo

La semana pasada os presentamos esta serie denominada ¿De dónde es este código? y fueron varios los que, sin necesidad de copiar y pegar el código en un buscador, fueron capaces de reconocer que el código que os presentábamos pertenecía al núcleo de Linux, creado por Linus Torvalds y comentado por vez primera en la lista de correo de comp.os.minix.

En esta ocasión, os traemos otro clásico del Software Libre, sin el cual sería muy difícil comprender la actual extensión de los proyectos de código abierto.

Las pistas

Esta semana se cumplirán 27 años de la primera versión estable de este proyecto.

Originalmente fue escrito únicamente en C, aunque con los años se ha comenzado a usar algo de C++ y minoritariamente algún otro lenguaje como Ada.

A pesar de estar escrito en C, mantiene una estrecha relación con otros lenguajes, como Java, Objective-C o Fortran... y ensamblador.

La arquitectura del proyecto está formada por un programa controlador, diversos front-ends y un back-end.

Aparecieron múltiples forks de este código, a los que luego resultó muy difícil volver a ser integrados en el proyecto oficial, debido al exhaustivo control que se realizaba sobre lo que se podía añadir. Esto le valió ser utilizado como ejemplo de modelo de desarrollo "catedral" frente a los proyectos con modelo "bazar".

Uno de los grandes retos de este proyecto era el ser compatible con multitud de arquitecturas, siendo más de 50 las que soporta en la actualidad.

El código

Las siguientes líneas son un fragmento de la primera beta conocida de este proyecto, concretamente del controlador antes mencionado:

278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/* Add one argument to the vector at the end.
   This is done when a space is seen or at the end of the line.  */
 
void
store_arg (arg, tempnamep)
     char *arg;
     int tempnamep;
{
  if (argbuf_index + 1 == argbuf_length)
    {
      argbuf = (char **) realloc (argbuf, (argbuf_length *= 2) * sizeof (char *));
    }
 
  argbuf[argbuf_index++] = arg;
  argbuf[argbuf_index] = 0;
 
  if (tempnamep)
    record_temp_file (arg);
}
 
/* Execute the command specified by the arguments on the current line of spec.
   Returns 0 if successful, -1 if failed.  */
 
int
execute ()
{
  int pid;
  union wait status;
  int size;
  char *temp;
  int win = 0;
 
  size = strlen (standard_exec_prefix);
  if (user_exec_prefix != 0 && strlen (user_exec_prefix) > size)
    size = strlen (user_exec_prefix);
  if (strlen (standard_exec_prefix_1) > size)
    size = strlen (standard_exec_prefix_1);
  size += strlen (argbuf[0]) + 1;
  temp = (char *) alloca (size);
 
  /* Determine the filename to execute.  */
 
  if (user_exec_prefix)
    {
      strcpy (temp, user_exec_prefix);
      strcat (temp, argbuf[0]);
      win = (access (temp, X_OK) == 0);
    }
 
  if (!win)
    {
      strcpy (temp, standard_exec_prefix);
      strcat (temp, argbuf[0]);
      win = (access (temp, X_OK) == 0);
    }
 
  if (!win)
    {
      strcpy (temp, standard_exec_prefix_1);
      strcat (temp, argbuf[0]);
      win = (access (temp, X_OK) == 0);
    }
 
  if (vflag)
    {
      int i;
      for (i = 0; argbuf[i]; i++)
    {
      if (i == 0 && win)
        fprintf (stderr, " %s", temp);
      else
        fprintf (stderr, " %s", argbuf[i]);
    }
      fprintf (stderr, "\n");
#ifdef DEBUG
      fprintf (stderr, "\nGo ahead? (y or n) ");
      fflush (stderr);
      i = getchar ();
      if (i != '\n')
    while (getchar () != '\n') ;
      if (i != 'y' && i != 'Y')
    return 0;
#endif              /* DEBUG */
    }
 
  pid = vfork ();
  if (pid < 0)
    pfatal_with_name ("vfork");
  if (pid == 0)
    {
      if (win)
    execv (temp, argbuf);
      else
    execvp (argbuf[0], argbuf);
      perror_with_name (argbuf[0]);
      _exit (65);
    }
  wait (&status);
  if (WIFSIGNALED (status))
    fatal ("Program %s got fatal signal %d.", argbuf[0], status.w_termsig);
  if ((WIFEXITED (status) && status.w_retcode >= MIN_FATAL_STATUS)
      || WIFSIGNALED (status))
    return -1;
  return 0;
}
 
/* Find all the switches given to us
   and make a vector describing them.
   The elements of the vector a strings, one per switch given.
   The string includes a minus sign, the switch name,
   and possibly an argument after that, with a space between them
   if that the user gave the switch its argument as two args.  */
 
char **switches;
 
int n_switches;
 
/* Also a vector of input files specified.  */
 
char **infiles;
 
int n_infiles;
 
/* And a vector of corresponding output files is made up later.  */
 
char **outfiles;
 
char *
make_switch (p1, s1, p2, s2)
     char *p1;
     int s1;
     char *p2;
     int s2;
{
  register char *new;
  if (p2 && s2 == 0)
    s2 = strlen (p2);
  new = (char *) xmalloc (s1 + s2 + 2);
  bcopy (p1, new, s1);
  if (p2)
    {
      new[s1++] = ' ';
      bcopy (p2, new + s1, s2);
    }
  new[s1 + s2] = 0;
  return new;
}
 
/* Create the vector `switches' and its contents.
   Store its length in `n_switches'.  */
 
void
process_command (argc, argv)
     int argc;
     char **argv;
{
  register int i;
  n_switches = 0;
  n_infiles = 0;
 
  /* Scan argv twice.  Here, the first time, just count how many switches
     there will be in their vector, and how many input files in theirs.
     Here we also parse the switches that itself uses (e.g. -v).  */
 
  for (i = 1; i < argc; i++)
    {
      if (argv[i][0] == '-' && argv[i][1] != 'l')
    {
      register char *p = &argv[i][1];
      register int c = *p;
 
      switch (c)
        {
        case 'B':
          user_exec_prefix = p + 1;
          break;
 
        case 'v':   /* Print commands as we execute them */
          vflag++;
 
        default:
          n_switches++;
 
          if (SWITCH_TAKES_ARG (c) && p[1] == 0)
        i++;
        }
    }
      else
    n_infiles++;
    }
 
  /* Then create the space for the vectors and scan again.  */
 
  switches = (char **) xmalloc ((n_switches + 1) * sizeof (char *));
  infiles = (char **) xmalloc ((n_infiles + 1) * sizeof (char *));
  n_switches = 0;
  n_infiles = 0;
 
  /* This, time, copy the text of each switch and store a pointer
     to the copy in the vector of switches.
     Store all the infiles in their vector.  */
 
  for (i = 1; i < argc; i++)
    {
      if (argv[i][0] == '-' && argv[i][1] != 'l')
    {
      register char *p = &argv[i][1];
      register int c = *p;
 
      if (c == 'B')
        continue;
      if (SWITCH_TAKES_ARG (c) && p[1] == 0)
        switches[n_switches++] = make_switch (p, 1, argv[++i], 0);
      else
        switches[n_switches++] = make_switch (p, strlen (p),
                          (char *)0, 0);
    }
      else
    infiles[n_infiles++] = argv[i];
    }
 
  switches[n_switches] = 0;
  infiles[n_infiles] = 0;
}

El reto

Al igual que la semana pasada, no sólo os pedimos el nombre del proyecto, sino también algunas cuestiones relacionadas:

  • ¿Quién es el autor de este código?

  • ¿Qué librerías o conjunto de aplicaciones requiere este programa para su funcionamiento?

  • ¿Qué fork del proyecto vivió un merge de nuevo hacia la rama oficial?

  • ¿Qué ficheros de 0 bytes había incluidos en esta primera beta y cuál era su finalidad?

Como siempre, esperamos vuestras respuestas y sugerencias en los comentarios.

Comentarios cerrados
Inicio
×

Utilizamos cookies de terceros para generar estadísticas de audiencia y mostrar publicidad personalizada analizando tu navegación. Si sigues navegando estarás aceptando su uso. Más información