Merge remote-tracking branch 'origin/release-v4.5.2'
[WRF.git] / var / da / makedepf90-2.8.8 / modfile_name.c
blobbff8c5b3b1fd18acd6ede56bfa33072d3e4ad396
1 /*
2 * Copyright (C) 2000-2005 Erik Edelmann <Erik.Edelmann@iki.fi>
4 * This program is free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License version 2 as published by the Free Software
7 * Foundation.
9 * This program is distributed in the hope that it will be
10 * useful, but WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free
17 * Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307 USA
21 #include <ctype.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include "global.h"
25 #include "errormesg.h"
26 #include "xmalloc.h"
29 char *modfile_name (const char *modulename, const char *filename)
30 /*
31 * Create a "modfile" name out of 'modulename' and 'filename' using format given
32 * by 'options.modfile_fmt'.
35 char *modfile;
36 const char *fmt = options.modfile_fmt;
37 int mi = 0, j, i;
39 modfile = (char *)xmalloc (sizeof(char)*MODFILE_NAME_LEN);
41 for (i = 0; fmt[i]; i++) {
42 if (fmt[i] == '%') {
43 i++;
44 switch (fmt[i]) {
45 case 'f':
46 for (j = 0; filename[j]; j++)
47 modfile[mi++] = filename[j];
49 /* Skip the file name extension */
50 for (mi--; modfile[mi] != '.'; mi--);
51 break;
52 case 'm':
53 for (j = 0; modulename[j]; j++)
54 modfile[mi++] = tolower (modulename[j]);
55 break;
56 case 'M':
57 for (j = 0; modulename[j]; j++)
58 modfile[mi++] = toupper (modulename[j]);
59 break;
60 case '%':
61 modfile[mi++] = '%';
62 break;
63 default:
64 warning ("Unknown modifier '%%%c' in modfile format '%s'",
65 fmt[i], fmt);
66 break;
68 } else {
69 modfile[mi++] = fmt[i];
72 modfile[mi] = '\0';
74 return modfile;