X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fflip.c;h=7b33d3dbbbb67ed207e87359a614af0e026f69b3;hb=4611b8e15a8286d4039ce64b59e5a891af549238;hp=d0949980472699e505018ef45ac5d1fb89a489d8;hpb=05e356b2a3087e819ef3b5388e29c822f41502e1;p=pspp diff --git a/src/flip.c b/src/flip.c index d094998047..7b33d3dbbb 100644 --- a/src/flip.c +++ b/src/flip.c @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include "config.h" #include "error.h" @@ -38,6 +38,12 @@ #include "var.h" #include "vfm.h" +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#include "gettext.h" +#define _(msgid) gettext (msgid) /* List of variable names. */ struct varname @@ -181,25 +187,27 @@ destroy_flip_pgm (struct flip_pgm *flip) static int make_new_var (char name[]) { + char *cp; + + /* Trim trailing spaces. */ + cp = strchr (name, '\0'); + while (cp > name && isspace ((unsigned char) cp[-1])) + *--cp = '\0'; + /* Fix invalid characters. */ - { - char *cp; - - for (cp = name; *cp && !isspace (*cp); cp++) + for (cp = name; *cp && cp < name + SHORT_NAME_LEN; cp++) + if (cp == name) { - *cp = toupper ((unsigned char) *cp); - if (!isalpha (*cp) && *cp != '@' && *cp != '#' - && (cp == name || (*cp != '.' && *cp != '$' && *cp != '_' - && !isdigit (*cp)))) - { - if (cp == name) - *cp = 'V'; /* _ not valid in first position. */ - else - *cp = '_'; - } + if (!CHAR_IS_ID1 (*cp) || *cp == '$') + *cp = 'V'; } - *cp = 0; - } + else + { + if (!CHAR_IS_IDN (*cp)) + *cp = '_'; + } + *cp = '\0'; + str_uppercase (name); if (dict_create_var (default_dict, name, 0)) return 1; @@ -285,7 +293,8 @@ flip_sink_create (struct flip_pgm *flip) /* Write variable names as first case. */ for (i = 0; i < flip->var_cnt; i++) - st_bare_pad_copy (info->output_buf[i].s, flip->var[i]->name, MAX_SHORT_STRING); + buf_copy_str_rpad (info->output_buf[i].s, MAX_SHORT_STRING, + flip->var[i]->name); if (fwrite (info->output_buf, sizeof *info->output_buf, flip->var_cnt, flip->file) != (size_t) flip->var_cnt) msg (FE, _("Error writing FLIP file: %s."), strerror (errno)); @@ -323,8 +332,7 @@ flip_sink_write (struct case_sink *sink, const struct ccase *c) { char name[INT_DIGITS + 2]; sprintf (name, "V%d", (int) f); - strncpy (v->name, name, SHORT_NAME_LEN); - name[SHORT_NAME_LEN] = 0; + str_copy_trunc (v->name, sizeof v->name, name); } } else