-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
71 lines (63 loc) · 2.07 KB
/
Copy pathparser.h
File metadata and controls
71 lines (63 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef PARSER_H
#define PARSER_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "complex.h"
#include "circuit.h"
/**
* @brief Parses an initialization file containing circuit information.
*
* The file must contain '#qubits' and '#init' state vector.
*
* @param path Path to the initialization file.
* @return Circuit structure initialized from the file.
*/
Circuit parse_init_file(char *path);
/**
* @brief Parses a complex number in the form "a+ib".
*
* @param token The string representing the complex number.
* @return A complex number parsed from the string.
*/
complex parse_complex(char *token);
/**
* @brief Parses a circuit file containing gate definitions and gate order.
*
* The file should contain `#define` sections for gate matrices, and a `#circuit` section
* indicating the order of application.
*
* @param circuit Pointer to a Circuit structure to be populated.
* @param path Path to the circuit definition file.
*/
void parse_circ_file(Circuit *circuit, char *path);
/**
* @brief Reads a full line from a file.
*
* Dynamically allocates a buffer and returns a null-terminated string.
* The returned string must be freed by the caller.
*
* @param fptr A pointer to an open file.
* @return A dynamically allocated string containing the line (excluding the newline character).
*/
char *read_line(FILE *fptr);
/**
* @brief Trims a string in-place between two given characters.
*
* Adjusts the pointer to point to the substring between `s_char` and `e_char`.
* Null-terminates the string at the closing character.
*
* @param str Pointer to the string pointer to be trimmed.
* @param s_char Starting delimiter (e.g. '[').
* @param e_char Ending delimiter (e.g. ']').
*/
void trim_string(char **str, char s_char, char e_char);
/**
* @brief Parses a matrix of complex numbers from a string.
*
* @param str The string representing the matrix.
* @param n The number of rows and columns (assumes n x n square matrix).
* @return A dynamically allocated 2D array of complex numbers.
*/
complex** parse_matrix(char *str, unsigned int n);
#endif