+#!/usr/bin/php4 -qC
+<?php
+
+error_reporting(E_ALL);
+
+$origen = isset( $argv[1] ) ? $argv[1] : '.';
+$destino = isset( $argv[2] ) ? $argv[2] : '.';
+$libdir = isset( $argv[3] ) ? $argv[3] : getcwd();
+
+require_once "$libdir/corregir_lib.php";
+
+$fi = fopen( "$origen/webgen", 'r' );
+$fo = fopen( "$destino/estado", 'w' );
+$fe = fopen( 'php://stderr', 'w' );
+
+$s = fgets( $fi ); // Saca la descripción.
+fputs( $fo, "nrodoc,dependencia,estado,funcion\n" );
+$c = 1;
+while ( ( $s = fgets( $fi ) ) !== false ) {
+ if ( preg_match( '/^(\d{10}),(SCA|SAS|CAS),(AD|CA|SG|SE|ME|MA|MY|PL),(\w\d{9}),$/', $s, $m ) ) {
+ #if ( preg_match( '/^(\d{10}),([^,]+),(\d{8}),([:\d]*),([:\d]*),$/', $s, $m ) ) {
+ list( $todo, $doc, $est, $func, $dep ) = $m;
+ $doc = sacar_ceros( $doc );
+ fputs( $fo, "$doc,$dep,$est,$func\n" );
+ } else {
+ fputs( $fe, "ERROR: No se pudo interpretar la fila $c: $s.\n" );
+ }
+ $c++;
+}
+
+?>