#! /usr/bin/gawk -f # Last edited on 2024-01-01 09:53:53 by stolfi # To be included with "-f" in other {gawk} scripts. function read_alunos(fname,nam,niv, ntbl,nlin,lin,nfld,fld,ra,name) { # Reads the tables {nam[ra]} and {niv[ra]} from file {fname} which must have fields # "| {RA} {LOGIN} {NV} {CUR} {D} {M} {NOME} {EMAIL}" # Ignores lines that are blank or start with '#', '+, '-'. ntbl=0; nlin=0; while((getline lin < fname) > 0) { nlin++; if (! match(lin, /^[ \011]*([-+#]|$)/)) { nfld = split(lin, fld, " "); if ((nfld >= 10) && (fld[10] ~ /^[#]/)) { nfld = 9; } if (nfld != 9) { table_error(fname, nlin, ("bad table entry = \"" lin "\"")); } ra = fld[2]; nivel = fld[4]; name = fld[8] if (ra in nam) { table_error(fname, nlin, ("repeated key = \"" lin "\"")); } nam[ra] = name; niv[ra] = nivel; ntbl++; } } if ((ERRNO != "0") && (ERRNO != "")) { table_error(fname, nlin, ERRNO); } close (fname); if (nlin == 0) { arg_error(("file \"" fname "\" empty or missing")); } # printf "loaded %6d map pairs\n", ntbl > "/dev/stderr" }