00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <string.h>
00012 #include <grass/gis.h>
00013 #include <grass/glocale.h>
00014
00015 int G_put_cell_title (char *name, char *title)
00016 {
00017 char *mapset;
00018 FILE *in, *out;
00019 char *tempfile;
00020 int line ;
00021 char buf[1024];
00022
00023 mapset = G_mapset() ;
00024 in = out = 0 ;
00025 in = G_fopen_old ("cats", name, mapset);
00026 if (!in)
00027 {
00028 sprintf (buf, _("category information for [%s] in [%s] missing or invalid"), name, mapset);
00029 G_warning (buf);
00030 return -1;
00031 }
00032
00033 tempfile = G_tempfile();
00034 out = fopen (tempfile, "w");
00035 if (!out)
00036 {
00037 fclose (in);
00038 sprintf (buf, _("G_put_title - can't create a temp file"));
00039 G_warning (buf);
00040 return -1;
00041 }
00042
00043 for (line = 0; G_getl (buf, sizeof buf, in); line++)
00044 {
00045 if (line == 1)
00046 {
00047 strcpy (buf, title);
00048 G_strip (buf);
00049 }
00050 fprintf (out, "%s\n", buf);
00051 }
00052 fclose (in);
00053 fclose (out);
00054
00055
00056 if (line < 3)
00057 {
00058 sprintf (buf, _("category information for [%s] in [%s] invalid"), name, mapset);
00059 G_warning (buf);
00060 return -1;
00061 }
00062
00063 in = fopen (tempfile, "r");
00064 if (!in)
00065 {
00066 sprintf (buf, _("G_put_title - can't reopen temp file"));
00067 G_warning (buf);
00068 return -1;
00069 }
00070
00071 out = G_fopen_new ("cats", name);
00072 if (!out)
00073 {
00074 fclose (in);
00075 sprintf (buf, _("can't write category information for [%s] in [%s]"), name, mapset);
00076 G_warning (buf);
00077 return -1;
00078 }
00079
00080 while (fgets(buf, sizeof buf, in))
00081 fprintf (out, "%s", buf);
00082
00083 fclose (in);
00084 fclose (out);
00085 remove ( tempfile );
00086
00087 return 1;
00088 }