annotate libcommon/filesearch.c @ 129:94d87d05f6c5

libcommon: initial support for file search
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 20 Feb 2021 21:00:24 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
129
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the function that searches for files
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * in a dedicated directory for SIM programming scripts.
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 static char script_install_dir[] = "/opt/freecalypso/sim-scripts";
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 FILE *
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 open_script_input_file(req_filename)
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char *req_filename;
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char pathbuf[256];
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 FILE *f;
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (!index(req_filename, '/') && strlen(req_filename) < 128) {
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 sprintf(pathbuf, "%s/%s", script_install_dir, req_filename);
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 f = fopen(pathbuf, "r");
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (f)
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return f;
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 f = fopen(req_filename, "r");
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return f;
94d87d05f6c5 libcommon: initial support for file search
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }