diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..90048cb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +*.a +lib/*/* diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0eb4296 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,11 @@ +[submodule "lib/ccsv"] + path = lib/ccsv + url = https://github.com/Ayush-Tripathy/ccsv + +[submodule "lib/microtar"] + path = lib/microtar + url = https://github.com/rxi/microtar + +[submodule "lib/ctl"] + path = lib/ctl + url = https://github.com/glouw/ctl diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..76d04dc --- /dev/null +++ b/LICENSE @@ -0,0 +1,280 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/Makefile b/Makefile index 0914571..00024f9 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,24 @@ +# +# Makefile +# +# Copyright 2024 keXa +# Copyright 2025 keXa , Egor00f +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + CC = kos32-gcc LD = kos32-ld AR = kos32-ar @@ -8,18 +29,22 @@ CONTRIB_DIR = $(abspath $(HOME_DIR)/kolibrios/contrib) SDK_DIR = $(CONTRIB_DIR)/sdk C_LAYER = $(CONTRIB_DIR)/C_Layer -CFLAGS = -fno-ident -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -I $(SDK_DIR)/sources/newlib/libc/include -LDFLAGS = -static -S -nostdlib -T app.lds --subsystem native -DNDEBUG -L $(TOOLCHAIN_DIR)/lib -L $(TOOLCHAIN_DIR)/mingw32/lib -L $(SDK_DIR)/lib +MICROTAR = lib/microtar/src +CCSV = lib/ccsv -INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include -I.. +CFLAGS = -fno-ident -fomit-frame-pointer -U__WIN32__ -U_Win32 -U_WIN32 -U__MINGW32__ -UWIN32 -DNDEBUG -c +LDFLAGS = -static -S -nostdlib -T app.lds --subsystem native -L $(TOOLCHAIN_DIR)/lib -L $(TOOLCHAIN_DIR)/mingw32/lib -L $(SDK_DIR)/lib + +INCLUDES = -I $(SDK_DIR)/sources/newlib/libc/include -I include -I $(SDK_DIR)/sources/newlib/libc/include -I $(MICROTAR) -I $(CCSV)/include LIBPATH = -L $(SDK_DIR)/lib -L $(TOOLCHAIN_DIR)/mingw32/lib -MICROTAR_SOURCES = lib/microtar/src/microtar.c -CCSV_SOURCE = lib/ccsv/src/ccsv.c +MICROTAR_SOURCES = $(MICROTAR)/microtar.c +CCSV_SOURCE = $(CCSV)/src/ccsv.c SOURCES := $(MICROTAR_SOURCES) $(CCSV_SOURCE) \ - src/kospm_tar.c src/kospm_list.c src/kospm_common.c \ - src/kospm_package.c src/kospm_db.c src/kospm.c + src/kospm_tar.c src/kospm_list.c src/kospm_csv.c \ + src/kospm_pkgmeta.c src/kospm_pkgfile.c src/kospm_pkglist.c \ + src/kospm_pkgbundle.c src/kospm_pkgdb.c src/kospm.c OBJECTS := $(SOURCES:.c=.o) @@ -32,4 +57,4 @@ libkospm.a: $(OBJECTS) Makefile $(CC) $(CFLAGS) $(INCLUDES) -o $@ $< clean: - rn -f $(OBJECTS) libkospm.a + rm -f $(OBJECTS) libkospm.a diff --git a/README.md b/README.md index 7ddffbc..738e9c9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ -# kospm +#kospm - package management library for KolibriOS(WIP) -Package management library for KolibriOS \ No newline at end of file +This is library used by [Nest/Eggs package manager](https://git.kolibrios.org/keXa/nest) to interact with software packages. + +This library is licensed under [GNU GPL version 2 or later](LICENSE). +ccsv, microtar and ctl are licensed under MIT License, included in folders of respective submodules. diff --git a/include/kospm.h b/include/kospm.h index d539e6d..654ca6e 100644 --- a/include/kospm.h +++ b/include/kospm.h @@ -1,7 +1,7 @@ /* * kospm.h * - * Copyright 2024 keXa + * Copyright 2024-2025 keXa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,11 +20,27 @@ * * */ -#include "kospm_db.h" -#include "kospm_package.h" +#include +#include "kospm_pkgdb.h" +#include "kospm_pkgbundle.h" -int kospm_install(kospm_db_t *db, char *pkg_file); +enum kospm_query_modes { + KOSPM_FILELIST = 0x1, + KOSPM_BYTAG = 0x2, +}; -int kospm_remove(kospm_db_t *db, char *pkg_name); +enum kospm_errors { + KOSPM_OK = 0, + KOSPM_ERROR = -1, + KOSPM_NODB = -2, + KOSPM_NOBUNDLE = -3, + KOSPM_NOSUCHPKG = -4, + KOSPM_FAULTYDB = -5, + KOSPM_FAULTYBUNDLE =-6 +}; -int kospm_query(kospm_db_t *db, char *pkg_name); +int kospm_install(kospm_pkg_db_t *db, char *pkg_file, char *pkg_name); + +int kospm_remove(kospm_pkg_db_t *db, char *pkg_name); + +int kospm_query(kospm_pkg_db_t *db, char *pkg_name, int8_t query_mode); diff --git a/include/kospm_common.h b/include/kospm_csv.h similarity index 66% rename from include/kospm_common.h rename to include/kospm_csv.h index f997b60..b26e42d 100644 --- a/include/kospm_common.h +++ b/include/kospm_csv.h @@ -1,7 +1,7 @@ /* - * kospm_common.h + * kospm_csv.h * - * Copyright 2024 keXa + * Copyright 2025 keXa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ #include "../lib/ccsv.h" #include "kospm_list.h" -ccsv_reader_options _kospm_csv_reader_options = { +ccsv_reader_options kospm_csv_reader_options = { .delim = ',', .quote_char = '"', .skip_initial_space = 1, @@ -36,19 +36,25 @@ ccsv_reader_options _kospm_csv_reader_options = { .skip_comments = 1 }; -ccsv_reader_options _kospm_csv_writer_options = { +ccsv_reader_options kospm_csv_writer_options = { .delim = ',', .quote_char = '"' }; - -typedef struct { +typedef struct kospm_csv_header_col { int col_number; char *col_name; -} kospm_csv_header_column; +} kospm_csv_header_col; -kospm_list_t* _kospm_csv_header_get(FILE* file); +typedef struct kospm_csv_header { + kospm_list_t *col_list; + int col_amount; +} kospm_csv_header; -int _kospm_csv_col_get(kospm_list_t* col_list, char* col_name); +kospm_csv_header* kospm_csv_header_get(FILE* file); + +int kospm_csv_col_get(kospm_csv_header *header, char* col_name); + +char* kospm_csv_string_get(ccsv_row *row, kospm_csv_header *header, char* col_name); #endif diff --git a/include/kospm_db.h b/include/kospm_db.h deleted file mode 100644 index b61ec46..0000000 --- a/include/kospm_db.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * kospm_db.h - * - * Copyright 2024 keXa - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ -#ifndef KOSPM_DB -#define KOSPM_DB - -#include -#include "kospm_list.h" -#include "kospm_package.h" - -#define DB_FOLDER "/kospm/db" -#define METADATA_TABLE "/packages.csv" -#define FILES_TABLE "/files.csv" - -char **_kospm_db_metadata_table_header; -char **_kospm_db_files_table_header; - -typedef struct kospm_db { - char *db_path; - FILE* metadata_table; - FILE* files_table; - kospm_list_t *packages; - kospm_list_t *files; -} kospm_db_t; - -kospm_db_t* kospm_db_init(char *root_dir); - -kospm_db_t* kospm_db_open(char *root_dir); - -int kospm_db_save(kospm_db_t *db); - -int kospm_db_close(kospm_db_t *db); - -int kospm_db_package_add(kospm_db_t *db, kospm_package_t *package); - -kospm_package_t* kospm_db_package_query(kospm_db_t *db, char *pkg_name); - -int kospm_db_package_remove(kospm_db_t *db, char *pkg_name); - -int kospm_db_file_add(kospm_db_t *db, char *pkg_name, kospm_package_file_t *file); - -kospm_package_t* kospm_db_file_query(kospm_db_t *db, char *file_name); - -int kospm_db_file_remove(kospm_db_t *db, char *filename); - -int kospm_db_packages_add(kospm_db_t *db, kospm_package_list_t *package_list); - -int kospm_db_files_add(kospm_db_t *db, kospm_list_t *file_list); - -int kospm_db_packagelist_save(kospm_db_t *db); - -int kospm_db_filelist_save(kospm_db_t *db); - -#endif diff --git a/include/kospm_list.h b/include/kospm_list.h index 5d858df..74e4ee5 100644 --- a/include/kospm_list.h +++ b/include/kospm_list.h @@ -1,7 +1,7 @@ /* * kospm_list.h - * - * Copyright 2024 keXa + * + * Copyright 2024-2025 keXa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,18 +25,33 @@ #include "stddef.h" -typedef struct { - void *data; - kospm_list_t *prev; - kospm_list_t *next; - } kospm_list_t; +//Do I need this since I am gonna move to CTL lists anyway? +//Maybe, if I won't like its container approach... -kospm_list_t* kospm_list_new(void *data); +typedef struct kospm_list_node { + void* data; + struct kospm_list_node *prev; + struct kospm_list_node *next; +} kospm_list_node_t; -void kospm_list_add(kospm_list_t **list, void *data); +typedef struct kospm_list { + kospm_list_node_t *current; + kospm_list_node_t *first; + kospm_list_node_t *last; +} kospm_list_t; -void kospm_list_del_by_value(kospm_list_t **list, void *data, int (*cmp)(void *, void *)); +kospm_list_t* kospm_list_new(); -void kospm_list_free(kospm_list_t *list); +void kospm_list_add(kospm_list_t *dlist, void *data); + +void kospm_list_prev(kospm_list_t *dlist); + +void kospm_list_next(kospm_list_t *dlist); + +kospm_list_node_t* kospm_list_get_by_value(kospm_list_t *dlist, void *data, int (*cmp)(void *, void *)); + +void kospm_list_del_by_value(kospm_list_t *dlist, void *data, int (*cmp)(void *, void *), void (*free_alt)(void *)); + +void kospm_list_free(kospm_list_t *dlist, void (*free_alt)(void *)); #endif diff --git a/include/kospm_macros.h b/include/kospm_macros.h new file mode 100644 index 0000000..2c0687a --- /dev/null +++ b/include/kospm_macros.h @@ -0,0 +1,31 @@ +/* + * kospm_macros.h + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +//some macros cuz I don't want to copy-paste type every time +#define MALLOCNEW(var_name, type) \ + type* var_name = (type*)malloc(sizeof(type)) + +#define CALLOCNEW(var_name, type) \ + type* var_name = (type*)calloc(sizeof(type)) + +#define MALLOCNEWARR(var_name, type, amount) \ + type* var_name = (type*)malloc(amount*sizeof(type)) diff --git a/include/kospm_pkgbundle.h b/include/kospm_pkgbundle.h new file mode 100644 index 0000000..d3dfaa9 --- /dev/null +++ b/include/kospm_pkgbundle.h @@ -0,0 +1,44 @@ +/* + * kospm_pkgbundle.h + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +#ifndef KOSPM_PKGBUNDLE +#define KOSPM_PKGBUNDLE + +#include "kospm_pkglist.h" + +#define BUNDLE_CACHE "/tmp0/1/kospm/" +#define META_CACHE "/tmp0/1/kospm/META" +#define FILES_CACHE "/tmp0/1/kospm/FILES" + +typedef struct kospm_pkg_bundle { + char* bundle_path; + kospm_pkg_list_t *package_list; +} kospm_pkg_bundle_t; + +kospm_pkg_bundle_t* kospm_pkg_bundle_open(char* bundle_path); + +int kospm_pkg_bundle_unpack(char *root_path, + kospm_pkg_bundle_t* pkg_bundle, char *pkg_name); + +int kospm_pkg_bundle_close(kospm_pkg_bundle_t* pkg_bundle); + +#endif diff --git a/include/kospm_pkgdb.h b/include/kospm_pkgdb.h new file mode 100644 index 0000000..d4a3b25 --- /dev/null +++ b/include/kospm_pkgdb.h @@ -0,0 +1,51 @@ +/* + * kospm_pkgdb.h + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +#ifndef KOSPM_PKGDB +#define KOSPM_PKGDB + +#include "kospm_pkglist.h" + +#define DB_FOLDER "/kospm/db" + +typedef struct kospm_pkg_db { + char *root_path; + kospm_pkg_list_t *package_list; +} kospm_pkg_db_t; + +kospm_pkg_db_t* kospm_db_init(); + +kospm_pkg_db_t* kospm_db_open(kospm_pkg_db_t *db, char *root_path); + +int kospm_db_save(kospm_pkg_db_t *db); + +int kospm_db_close(kospm_pkg_db_t *db); + +int kospm_db_pkg_add(kospm_pkg_db_t *db, kospm_pkg_meta_t *package); + +int kospm_db_pkg_remove(kospm_pkg_db_t *db, char *pkg_name); + +int kospm_db_pkg_file_add(kospm_pkg_db_t *db, kospm_pkg_file_t *file); + +int kospm_db_pkg_file_remove(kospm_pkg_db_t *db, char *file_name); + +#endif diff --git a/include/kospm_pkgfile.h b/include/kospm_pkgfile.h new file mode 100644 index 0000000..9edd34d --- /dev/null +++ b/include/kospm_pkgfile.h @@ -0,0 +1,44 @@ +/* + * kospm_pkgfile.h + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +#ifndef KOSPM_PKGFILE +#define KOSPM_PKGFILE + +#include "kospm_string.h" +#include "kospm_csv.h" + +typedef struct { + char pkg_name[NAME_MAX]; + char *file_name; +} kospm_pkg_file_t; + +kospm_pkg_meta_t* kospm_pkg_file_init(); + +kospm_pkg_meta_t* kospm_pkg_file_load(ccsv_row *row, + kospm_list_t *header); + +char** kospm_pkg_file_store(kospm_pkg_file_t *pkg_file, + kospm_list_t *header); + +int kospm_pkg_file_free(kospm_pkg_file_t *pkg_file); + +#endif diff --git a/include/kospm_package.h b/include/kospm_pkglist.h similarity index 53% rename from include/kospm_package.h rename to include/kospm_pkglist.h index 0269ecc..2741a2e 100644 --- a/include/kospm_package.h +++ b/include/kospm_pkglist.h @@ -1,56 +1,61 @@ /* - * kospm_package.h - * - * Copyright 2024 keXa - * + * kospm_pkglist.h + * + * Copyright 2025 keXa + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * 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., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. - * - * + * + * */ -#ifndef KOSPM_PKG -#define KOSPM_PKG +#ifndef KOSPM_PKGLIST +#define KOSPM_PKGLIST -#include #include "kospm_list.h" -#define PKGINFO "PKGINFO.CSV" -#define FILES "FILES.CSV" -#define CACHE "/tmp0/1/kospm/cache/" + +#define META_TABLE "META.CSV" +#define FILES_TABLE "FILES.CSV" typedef struct { - char pkg_name[64]; + char pkg_name[32]; char *file_name; -} kospm_package_file_t; +} kospm_pkg_file_t; typedef struct { - char pkg_name[64]; + char pkg_name[32]; char pkg_version[16]; char *pkg_description; -} kospm_package_t; + //kospm_list_t *pkg_depends; + //kospm_list_t *pkg_tags; +} kospm_pkg_meta_t; typedef struct { kospm_list_t *packages; kospm_list_t *files; -} kospm_package_list_t; +} kospm_pkg_list_t; -kospm_list_t* kospm_package_metadata_get(FILE* fp); +kospm_pkg_list_t* kospm_pkg_list_init(); -kospm_list_t* kospm_package_files_get(FILE* fp); +kospm_pkg_list_t* kospm_pkg_list_open(kospm_pkg_list_t *pkg_list, char* pkg_list_path); -kospm_package_list_t* kospm_package_list_open(char *pkg_file); +int kospm_pkg_list_save(kospm_pkg_list_t *pkg_list, char* pkglist_path); -int kospm_package_list_close(kospm_package_list_t *package_list); +int kospm_pkg_list_close(kospm_pkg_list_t* pkg_list); + +kospm_pkg_meta_t* kospm_pkg_list_meta_query(kospm_pkg_list_t *pkg_list, char *pkg_name); + +kospm_list_t* kospm_pkg_list_files_query(kospm_pkg_list_t *pkg_list, char *pkg_name); #endif diff --git a/include/kospm_pkgmeta.h b/include/kospm_pkgmeta.h new file mode 100644 index 0000000..258c1a5 --- /dev/null +++ b/include/kospm_pkgmeta.h @@ -0,0 +1,50 @@ +/* + * kospm_pkgmeta.h + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +#ifndef KOSPM_PKGMETA +#define KOSPM_PKGMETA + +#include "kospm_string.h" +#include "kospm_csv.h" + +typedef struct { + char pkg_name[NAME_MAX]; + char pkg_version[VERSION_MAX]; + char *pkg_description; + int pkg_size; + kospm_list_t *pkg_depends; + kospm_list_t *pkg_tags; +} kospm_pkg_meta_t; + +kospm_pkg_meta_t* kospm_pkg_meta_init(); + +kospm_pkg_meta_t* kospm_pkg_meta_load(ccsv_row *row, + kospm_list_t *header); + +char** kospm_pkg_meta_store(kospm_pkg_meta_t *pkg_meta, + kospm_list_t *header); + +int kospm_pkg_meta_cmp(kospm_pkg_meta_t *pkg_meta, char* pkg_name); + +int kospm_pkg_meta_free(kospm_pkg_meta_t *pkg_meta); + +#endif diff --git a/include/kospm_string.h b/include/kospm_string.h new file mode 100644 index 0000000..4f9ba37 --- /dev/null +++ b/include/kospm_string.h @@ -0,0 +1,44 @@ +/* + * kospm_string.h + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +#ifndef KOSPM_STRING +#define KOSPM_STRING + +#include +#include + +#define NAME_MAX 32 +#define VERSION_MAX 16 +#define DESC_MAX 256 +#define FILE_MAX 4096 + +static inline char* strcpynew(const char *src, size_t n) { + char *dst = malloc(n + 1); + if (dst) { + strncpy(dst, src, n); + dst[n] = '\0'; + } + return dst; +} + +#endif diff --git a/include/kospm_tar.h b/include/kospm_tar.h index 67fac3f..a46f7eb 100644 --- a/include/kospm_tar.h +++ b/include/kospm_tar.h @@ -1,7 +1,7 @@ /* * kospm_tar.h * - * Copyright 2024 keXa + * Copyright 2024-2025 keXa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,8 +24,13 @@ #define KOSPM_TAR #include "../lib/microtar/src/microtar.h" +#include "kospm_list.h" -int tar_unpack(const char *tar_name, +kospm_list_t* kospm_tar_filelist_get(const char *tar_name); + +int kospm_tar_file_exists(kospm_list_t* file_list, const char *file_name); + +int kospm_tar_unpack(const char *tar_name, const char *src_file, const char *dest_file); #endif diff --git a/kos_build.sh b/kos_build.sh index 80b7770..e69de29 100644 --- a/kos_build.sh +++ b/kos_build.sh @@ -1,3 +0,0 @@ -#SHS - -/kolibrios/develop/tcc/tcc -r -o libkospm.o lib/microtar/src/microtar.c lib/ccsv/src/ccsv.c src/kospm_tar.c src/kospm_list.c src/kospm_common.c src/kospm_package.c src/kospm_db.c src/kospm.c diff --git a/kospm.geany b/kospm.geany index 76a58f1..c4988d9 100644 --- a/kospm.geany +++ b/kospm.geany @@ -19,32 +19,59 @@ indent_mode=2 [project] name=kospm -base_path=/home/kexa/Документы/npoekt/kospm +base_path=./ description= +file_patterns= [long line marker] long_line_behaviour=1 long_line_column=72 [files] -current_page=0 -FILE_NAME_0=1194;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm.c;0;4 -FILE_NAME_1=4136;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_db.c;0;4 -FILE_NAME_2=961;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_list.c;0;4 -FILE_NAME_3=3586;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_package.c;0;4 -FILE_NAME_4=1069;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_tar.c;0;4 -FILE_NAME_5=861;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm.h;0;4 -FILE_NAME_6=1948;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_db.h;0;4 -FILE_NAME_7=1205;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_list.h;0;4 -FILE_NAME_8=1498;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_package.h;0;4 -FILE_NAME_9=990;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_tar.h;0;4 -FILE_NAME_10=198;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fkos_build.sh;0;4 -FILE_NAME_11=907;Make;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2FMakefile;0;4 -FILE_NAME_12=9813;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fccsv%2Finclude%2Fccsv.h;0;4 -FILE_NAME_13=0;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fmicrotar%2Fsrc%2Fmicrotar.h;0;4 -FILE_NAME_14=17;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_common.c;0;4 -FILE_NAME_15=1269;C++;0;EUTF-8;1;1;1;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_common.h;0;4 -FILE_NAME_16=2814;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fccsv%2Fsrc%2Fccsv.c;0;4 +current_page=31 +FILE_NAME_0=1469;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm.c;0;4 +FILE_NAME_1=17;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_csv.c;0;4 +FILE_NAME_2=45;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_list.c;0;4 +FILE_NAME_3=1787;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_pkgbundle.c;0;4 +FILE_NAME_4=2266;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_pkgdb.c;0;4 +FILE_NAME_5=19;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_pkgfile.c;0;4 +FILE_NAME_6=5457;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_pkglist.c;0;4 +FILE_NAME_7=0;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_pkgmeta.c;0;4 +FILE_NAME_8=44;C;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fsrc%2Fkospm_tar.c;0;4 +FILE_NAME_9=503;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm.h;0;4 +FILE_NAME_10=35;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_csv.h;0;4 +FILE_NAME_11=80;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_list.h;0;4 +FILE_NAME_12=37;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_macros.h;0;4 +FILE_NAME_13=40;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_pkgbundle.h;0;4 +FILE_NAME_14=810;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_pkgdb.h;0;4 +FILE_NAME_15=817;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_pkgfile.h;0;4 +FILE_NAME_16=812;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_pkglist.h;0;4 +FILE_NAME_17=589;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_pkgmeta.h;0;4 +FILE_NAME_18=18;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_string.h;0;4 +FILE_NAME_19=43;C++;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Finclude%2Fkospm_tar.h;0;4 +FILE_NAME_20=0;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Fkos_build.sh;0;4 +FILE_NAME_21=0;C++;1;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fmicrotar%2Fsrc%2Fmicrotar.h;0;4 +FILE_NAME_22=0;C;1;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fmicrotar%2Fsrc%2Fmicrotar.c;0;4 +FILE_NAME_23=2;C++;1;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fctl%2Fctl%2Flst.h;0;4 +FILE_NAME_24=0;C++;1;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fctl%2Fctl%2Fstk.h;0;4 +FILE_NAME_25=0;C++;1;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fctl%2Fctl%2Fstr.h;0;4 +FILE_NAME_26=0;C++;1;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fctl%2Fctl%2Fvec.h;0;4 +FILE_NAME_27=359;C++;1;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2Flib%2Fctl%2Fctl%2Fctl.h;0;4 +FILE_NAME_28=859;Make;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2FMakefile;0;4 +FILE_NAME_29=0;None;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2F.gitignore;0;4 +FILE_NAME_30=85;None;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2F.gitmodules;0;4 +FILE_NAME_31=351;Markdown;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2FREADME.md;0;4 +FILE_NAME_32=15179;None;0;EUTF-8;1;1;0;%2Fhome%2Fkexa%2FДокументы%2Fnpoekt%2Fkospm%2FLICENSE;0;4 [VTE] -last_dir=/home/kexa +last_dir=/home/kexa/Документы/npoekt/kospm + +[prjorg] +expanded_paths=/home/keXa/Documents/проект/kospm/include;/home/keXa/Documents/проект/kospm/src; +source_patterns=*.c;*.C;*.cpp;*.cxx;*.c++;*.cc;*.m; +header_patterns=*.h;*.H;*.hpp;*.hxx;*.h++;*.hh; +ignored_dirs_patterns=.*;CVS; +ignored_file_patterns=*.o;*.obj;*.a;*.lib;*.so;*.dll;*.lo;*.la;*.class;*.jar;*.pyc;*.mo;*.gmo; +generate_tag_prefs=0 +show_empty_dirs=true +external_dirs= diff --git a/kospm.tags b/kospm.tags new file mode 100644 index 0000000..b87f150 --- /dev/null +++ b/kospm.tags @@ -0,0 +1,548 @@ +!_TAG_EXTRA_DESCRIPTION anonymous /Include tags for non-named objects like lambda/ +!_TAG_EXTRA_DESCRIPTION fileScope /Include tags of file scope/ +!_TAG_EXTRA_DESCRIPTION pseudo /Include pseudo tags/ +!_TAG_EXTRA_DESCRIPTION subparser /Include tags generated by subparsers/ +!_TAG_FIELD_DESCRIPTION file /File-restricted scoping/ +!_TAG_FIELD_DESCRIPTION input /input file/ +!_TAG_FIELD_DESCRIPTION name /tag name/ +!_TAG_FIELD_DESCRIPTION pattern /pattern/ +!_TAG_FIELD_DESCRIPTION signature /Signature of routine (e.g. prototype or parameter list)/ +!_TAG_FIELD_DESCRIPTION typeref /Type and name of a variable or typedef/ +!_TAG_FIELD_DESCRIPTION!C++ name /aliased names/ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 2 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_KIND_DESCRIPTION!C d,macro /macro definitions/ +!_TAG_KIND_DESCRIPTION!C e,enumerator /enumerators (values inside an enumeration)/ +!_TAG_KIND_DESCRIPTION!C f,function /function definitions/ +!_TAG_KIND_DESCRIPTION!C g,enum /enumeration names/ +!_TAG_KIND_DESCRIPTION!C h,header /included header files/ +!_TAG_KIND_DESCRIPTION!C m,member /struct, and union members/ +!_TAG_KIND_DESCRIPTION!C p,prototype /function prototypes/ +!_TAG_KIND_DESCRIPTION!C s,struct /structure names/ +!_TAG_KIND_DESCRIPTION!C t,typedef /typedefs/ +!_TAG_KIND_DESCRIPTION!C u,union /union names/ +!_TAG_KIND_DESCRIPTION!C v,variable /variable definitions/ +!_TAG_KIND_DESCRIPTION!C++ c,class /classes/ +!_TAG_KIND_DESCRIPTION!C++ d,macro /macro definitions/ +!_TAG_KIND_DESCRIPTION!C++ e,enumerator /enumerators (values inside an enumeration)/ +!_TAG_KIND_DESCRIPTION!C++ f,function /function definitions/ +!_TAG_KIND_DESCRIPTION!C++ g,enum /enumeration names/ +!_TAG_KIND_DESCRIPTION!C++ h,header /included header files/ +!_TAG_KIND_DESCRIPTION!C++ m,member /class, struct, and union members/ +!_TAG_KIND_DESCRIPTION!C++ n,namespace /namespaces/ +!_TAG_KIND_DESCRIPTION!C++ p,prototype /function prototypes/ +!_TAG_KIND_DESCRIPTION!C++ s,struct /structure names/ +!_TAG_KIND_DESCRIPTION!C++ t,typedef /typedefs/ +!_TAG_KIND_DESCRIPTION!C++ u,union /union names/ +!_TAG_KIND_DESCRIPTION!C++ v,variable /variable definitions/ +!_TAG_KIND_DESCRIPTION!Make I,makefile /makefiles/ +!_TAG_KIND_DESCRIPTION!Make m,macro /macros/ +!_TAG_KIND_DESCRIPTION!Make t,target /targets/ +!_TAG_KIND_DESCRIPTION!Markdown c,chapter /chapters/ +!_TAG_KIND_DESCRIPTION!Markdown h,hashtag /hashtags/ +!_TAG_KIND_DESCRIPTION!Markdown n,footnote /footnotes/ +!_TAG_KIND_DESCRIPTION!Markdown s,section /sections/ +!_TAG_KIND_DESCRIPTION!Markdown S,subsection /level 2 sections/ +!_TAG_KIND_DESCRIPTION!Markdown T,l4subsection /level 4 sections/ +!_TAG_KIND_DESCRIPTION!Markdown t,subsubsection /level 3 sections/ +!_TAG_KIND_DESCRIPTION!Markdown u,l5subsection /level 5 sections/ +!_TAG_KIND_DESCRIPTION!Sh a,alias /aliases/ +!_TAG_KIND_DESCRIPTION!Sh f,function /functions/ +!_TAG_KIND_DESCRIPTION!Sh h,heredoc /label for here document/ +!_TAG_KIND_DESCRIPTION!Sh s,script /script files/ +!_TAG_OUTPUT_EXCMD number /number, pattern, mixed, or combineV2/ +!_TAG_OUTPUT_FILESEP slash /slash or backslash/ +!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/ +!_TAG_OUTPUT_VERSION 0.0 /current.age/ +!_TAG_PARSER_VERSION!C 1.1 /current.age/ +!_TAG_PARSER_VERSION!C++ 1.1 /current.age/ +!_TAG_PARSER_VERSION!Make 0.0 /current.age/ +!_TAG_PARSER_VERSION!Markdown 1.1 /current.age/ +!_TAG_PARSER_VERSION!Sh 0.0 /current.age/ +!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/ +!_TAG_PROC_CWD /home/keXa/Documents/проект/kospm/ // +!_TAG_PROGRAM_AUTHOR Universal Ctags Team // +!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/ +!_TAG_PROGRAM_URL https://ctags.io/ /official site/ +!_TAG_PROGRAM_VERSION 6.1.0 /v6.1.0/ +!_TAG_ROLE_DESCRIPTION!C!function foreigndecl /declared in foreign languages/ +!_TAG_ROLE_DESCRIPTION!C!header local /local header/ +!_TAG_ROLE_DESCRIPTION!C!header system /system header/ +!_TAG_ROLE_DESCRIPTION!C!macro undef /undefined/ +!_TAG_ROLE_DESCRIPTION!C!struct foreigndecl /declared in foreign languages/ +!_TAG_ROLE_DESCRIPTION!C++!header local /local header/ +!_TAG_ROLE_DESCRIPTION!C++!header system /system header/ +!_TAG_ROLE_DESCRIPTION!C++!macro undef /undefined/ +!_TAG_ROLE_DESCRIPTION!Make!makefile included /included/ +!_TAG_ROLE_DESCRIPTION!Make!makefile optional /optionally included/ +!_TAG_ROLE_DESCRIPTION!Sh!heredoc endmarker /end marker/ +!_TAG_ROLE_DESCRIPTION!Sh!script loaded /loaded/ +% ./lib/ccsv/examples/makefile 4;" target +% ./lib/ccsv/tests/Makefile 4;" target +%.o ./Makefile 36;" target +ADD_FIELD ./lib/ccsv/src/ccsv.c 105;" macro file: signature:(field) +AR ./Makefile 3;" macro +ARRAY_LEN ./lib/ccsv/include/ccsv.h 102;" macro signature:(array) +Basic Usage ./lib/microtar/README.md 5;" section chapter:microtar +BUNDLE_CACHE ./include/kospm_pkgbundle.h 28;" macro +bundle_path ./include/kospm_pkgbundle.h 33;" member struct:kospm_pkg_bundle typeref:typename:char * +CALLOCNEW ./include/kospm_macros.h 5;" macro signature:(var_name,type) +CC ./lib/ccsv/examples/makefile 1;" macro +CC ./lib/ccsv/tests/Makefile 1;" macro +CC ./Makefile 1;" macro +ccsv ./lib/ccsv/README.md 1;" chapter +CCSV_BUFFER_SIZE ./lib/ccsv/include/ccsv.h 58;" macro +ccsv_close ./lib/ccsv/include/ccsv.h 218;" prototype typeref:typename:void signature:(void * obj) +ccsv_close ./lib/ccsv/src/ccsv.c 376;" function typeref:typename:void signature:(void * obj) +CCSV_COMMENT_CHAR ./lib/ccsv/include/ccsv.h 68;" macro +CCSV_CR ./lib/ccsv/include/ccsv.h 64;" macro +CCSV_DELIMITER ./lib/ccsv/include/ccsv.h 62;" macro +CCSV_ERBUFNTALLOC ./lib/ccsv/include/ccsv.h 88;" macro +CCSV_ERINVALID ./lib/ccsv/include/ccsv.h 82;" macro +CCSV_ERINVOBJTYPE ./lib/ccsv/include/ccsv.h 86;" macro +CCSV_ERMODE ./lib/ccsv/include/ccsv.h 84;" macro +CCSV_ERNOMEM ./lib/ccsv/include/ccsv.h 81;" macro +CCSV_ERNULLFP ./lib/ccsv/include/ccsv.h 83;" macro +CCSV_ERNULLROW ./lib/ccsv/include/ccsv.h 87;" macro +CCSV_EROPEN ./lib/ccsv/include/ccsv.h 85;" macro +CCSV_ERROR ./lib/ccsv/include/ccsv.h 80;" macro +ccsv_free_row ./lib/ccsv/include/ccsv.h 288;" prototype typeref:typename:void signature:(ccsv_row * row) +ccsv_free_row ./lib/ccsv/src/ccsv.c 233;" function typeref:typename:void signature:(ccsv_row * row) +ccsv_get_status_message ./lib/ccsv/include/ccsv.h 229;" prototype typeref:typename:const char * signature:(short status) +ccsv_get_status_message ./lib/ccsv/src/ccsv.c 54;" function typeref:typename:const char * signature:(short status) +CCSV_HIGH_BUFFER_SIZE ./lib/ccsv/include/ccsv.h 54;" macro +ccsv_init_reader ./lib/ccsv/include/ccsv.h 255;" prototype typeref:typename:ccsv_reader * signature:(ccsv_reader_options * options,short * status) +ccsv_init_reader ./lib/ccsv/src/ccsv.c 147;" function typeref:typename:ccsv_reader * signature:(ccsv_reader_options * options,short * status) +ccsv_init_writer ./lib/ccsv/include/ccsv.h 303;" prototype typeref:typename:ccsv_writer * signature:(ccsv_writer_options * options,short * status) +ccsv_init_writer ./lib/ccsv/src/ccsv.c 953;" function typeref:typename:ccsv_writer * signature:(ccsv_writer_options * options,short * status) +ccsv_is_error ./lib/ccsv/include/ccsv.h 241;" prototype typeref:typename:int signature:(void * obj,short * status) +ccsv_is_error ./lib/ccsv/src/ccsv.c 78;" function typeref:typename:int signature:(void * obj,short * status) +CCSV_LARGE_FILE_SIZE ./lib/ccsv/include/ccsv.h 50;" macro +CCSV_LF ./lib/ccsv/include/ccsv.h 65;" macro +CCSV_LOW_BUFFER_SIZE ./lib/ccsv/include/ccsv.h 56;" macro +CCSV_MED_BUFFER_SIZE ./lib/ccsv/include/ccsv.h 55;" macro +CCSV_MED_FILE_SIZE ./lib/ccsv/include/ccsv.h 51;" macro +ccsv_next ./lib/ccsv/include/ccsv.h 280;" prototype typeref:typename:ccsv_row * signature:(ccsv_reader * reader) +ccsv_next ./lib/ccsv/src/ccsv.c 399;" function typeref:typename:ccsv_row * signature:(ccsv_reader * reader) +CCSV_NULL_CHAR ./lib/ccsv/include/ccsv.h 69;" macro +ccsv_open ./lib/ccsv/include/ccsv.h 210;" prototype typeref:typename:void * signature:(const char * filename,short object_type,const char * mode,void * options,short * status) +ccsv_open ./lib/ccsv/src/ccsv.c 258;" function typeref:typename:void * signature:(const char * filename,short object_type,const char * mode,void * options,short * status) +CCSV_QUOTE_CHAR ./lib/ccsv/include/ccsv.h 63;" macro +ccsv_reader ./lib/ccsv/include/ccsv.h 157;" struct +ccsv_reader ./lib/ccsv/include/ccsv.h 174;" typedef typeref:struct:ccsv_reader +CCSV_READER ./lib/ccsv/include/ccsv.h 99;" macro +ccsv_reader_options ./lib/ccsv/include/ccsv.h 146;" struct +ccsv_reader_options ./lib/ccsv/include/ccsv.h 155;" typedef typeref:struct:ccsv_reader_options +ccsv_row ./lib/ccsv/include/ccsv.h 176;" struct +ccsv_row ./lib/ccsv/include/ccsv.h 180;" typedef typeref:struct:ccsv_row +CCSV_SOURCE ./Makefile 22;" macro +CCSV_SPACE ./lib/ccsv/include/ccsv.h 66;" macro +CCSV_SUCCESS ./lib/ccsv/include/ccsv.h 79;" macro +CCSV_TAB ./lib/ccsv/include/ccsv.h 67;" macro +CCSV_VERSION ./lib/ccsv/include/ccsv.h 42;" macro +ccsv_write ./lib/ccsv/include/ccsv.h 308;" prototype typeref:typename:int signature:(ccsv_writer * writer,ccsv_row row) +ccsv_write ./lib/ccsv/src/ccsv.c 1005;" function typeref:typename:int signature:(ccsv_writer * writer,ccsv_row row) +CCSV_WRITER ./lib/ccsv/include/ccsv.h 100;" macro +ccsv_writer ./lib/ccsv/include/ccsv.h 189;" struct +ccsv_writer ./lib/ccsv/include/ccsv.h 198;" typedef typeref:struct:ccsv_writer +ccsv_writer_options ./lib/ccsv/include/ccsv.h 182;" struct +ccsv_writer_options ./lib/ccsv/include/ccsv.h 187;" typedef typeref:struct:ccsv_writer_options +CCSV_WRITE_FIELD ./lib/ccsv/include/ccsv.h 109;" macro signature:(fp,writer,string) +ccsv_write_from_array ./lib/ccsv/include/ccsv.h 321;" prototype typeref:typename:int signature:(ccsv_writer * writer,char ** fields,int fields_len) +ccsv_write_from_array ./lib/ccsv/src/ccsv.c 1016;" function typeref:typename:int signature:(ccsv_writer * writer,char ** fields,int fields_len) +CCSV_WRITE_ROW_END ./lib/ccsv/include/ccsv.h 121;" macro signature:(fp,writer,last_field) +CCSV_WRITE_ROW_START ./lib/ccsv/include/ccsv.h 106;" macro signature:(fp,writer) +CFLAGS ./lib/ccsv/examples/makefile 2;" macro +CFLAGS ./lib/ccsv/tests/Makefile 2;" macro +CFLAGS ./Makefile 11;" macro +checksum ./lib/microtar/src/microtar.c 37;" member struct:__anon2ac420210108 typeref:typename:char[8] file: +checksum ./lib/microtar/src/microtar.c 49;" function typeref:typename:unsigned file: signature:(const mtar_raw_header_t * rh) +clean ./lib/ccsv/examples/makefile 7;" target +clean ./lib/ccsv/tests/Makefile 7;" target +clean ./Makefile 39;" target +close ./lib/microtar/src/microtar.h 60;" member struct:mtar_t typeref:typename:int (*)(mtar_t * tar) +col_amount ./include/kospm_csv.h 51;" member struct:__anon1f1fcb200208 typeref:typename:int +col_list ./include/kospm_csv.h 50;" member struct:__anon1f1fcb200208 typeref:typename:kospm_list_t * +col_name ./include/kospm_csv.h 46;" member struct:__anon1f1fcb200108 typeref:typename:char * +col_number ./include/kospm_csv.h 45;" member struct:__anon1f1fcb200108 typeref:typename:int +comment_char ./lib/ccsv/include/ccsv.h 150;" member struct:ccsv_reader_options typeref:typename:char +CONTRIB_DIR ./Makefile 7;" macro +Create a reader object ./lib/ccsv/README.md 7;" subsection section:ccsv""Usage +Create a reader object with custom options ./lib/ccsv/README.md 13;" subsection section:ccsv""Usage +current ./include/kospm_list.h 35;" member struct:kospm_list typeref:typename:kospm_list_node_t * +C_LAYER ./Makefile 9;" macro +data ./include/kospm_list.h 29;" member struct:kospm_list_node typeref:typename:void * +DB_FOLDER ./include/kospm_pkgdb.h 28;" macro +default ./Makefile 31;" target +DEFAULT_COMMENT_CHAR ./lib/ccsv/include/ccsv.h 74;" macro +DEFAULT_DELIMITER ./lib/ccsv/include/ccsv.h 71;" macro +DEFAULT_ESCAPE_CHAR ./lib/ccsv/include/ccsv.h 73;" macro +DEFAULT_QUOTE_CHAR ./lib/ccsv/include/ccsv.h 72;" macro +delim ./lib/ccsv/include/ccsv.h 148;" member struct:ccsv_reader_options typeref:typename:char +delim ./lib/ccsv/include/ccsv.h 184;" member struct:ccsv_writer_options typeref:typename:char +DESC_MAX ./include/kospm_string.h 9;" macro +Error handling ./lib/microtar/README.md 59;" section chapter:microtar +escape_char ./lib/ccsv/include/ccsv.h 151;" member struct:ccsv_reader_options typeref:typename:char +escape_char ./lib/ccsv/include/ccsv.h 186;" member struct:ccsv_writer_options typeref:typename:char +Example ./lib/ccsv/README.md 64;" section chapter:ccsv +Feel free to contribute! ./lib/ccsv/README.md 117;" section chapter:ccsv +fields ./lib/ccsv/include/ccsv.h 178;" member struct:ccsv_row typeref:typename:char ** +fields_count ./lib/ccsv/include/ccsv.h 179;" member struct:ccsv_row typeref:typename:int +FIELD_END ./lib/ccsv/include/ccsv.h 132;" enumerator enum:State +FIELD_NOT_STARTED ./lib/ccsv/include/ccsv.h 131;" enumerator enum:State +FIELD_START ./lib/ccsv/include/ccsv.h 130;" enumerator enum:State +FIELD_STARTED ./lib/ccsv/include/ccsv.h 133;" enumerator enum:State +files ./include/kospm_pkglist.h 46;" member struct:__anon88dcd4b20308 typeref:typename:kospm_list_t * +FILES_CACHE ./include/kospm_pkgbundle.h 30;" macro +FILES_TABLE ./include/kospm_pkglist.h 29;" macro +file_close ./lib/microtar/src/microtar.c 171;" function typeref:typename:int file: signature:(mtar_t * tar) +FILE_MAX ./include/kospm_string.h 10;" macro +file_name ./include/kospm_pkgfile.h 9;" member struct:__anon7ad9ca760108 typeref:typename:char * +file_name ./include/kospm_pkglist.h 33;" member struct:__anon88dcd4b20108 typeref:typename:char * +file_read ./lib/microtar/src/microtar.c 161;" function typeref:typename:int file: signature:(mtar_t * tar,void * data,unsigned size) +file_seek ./lib/microtar/src/microtar.c 166;" function typeref:typename:int file: signature:(mtar_t * tar,unsigned offset) +file_write ./lib/microtar/src/microtar.c 156;" function typeref:typename:int file: signature:(mtar_t * tar,const void * data,unsigned size) +first ./include/kospm_list.h 36;" member struct:kospm_list typeref:typename:kospm_list_node_t * +Free the memory allocated to a row with ./lib/ccsv/README.md 50;" subsection section:ccsv""Usage +Free the memory allocated to the reader with ./lib/ccsv/README.md 56;" subsection section:ccsv""Usage +Get a field from a row with ./lib/ccsv/README.md 44;" subsection section:ccsv""Usage +Get the number of fields in a row with ./lib/ccsv/README.md 38;" subsection section:ccsv""Usage +group ./lib/microtar/src/microtar.c 34;" member struct:__anon2ac420210108 typeref:typename:char[8] file: +GROW_FIELD_BUFFER_IF_NEEDED ./lib/ccsv/src/ccsv.c 117;" macro file: signature:(field,field_size,field_pos) +GROW_ROW_BUFFER_IF_NEEDED ./lib/ccsv/src/ccsv.c 130;" macro file: signature:(row_string,row_len,row_pos) +header_to_raw ./lib/microtar/src/microtar.c 118;" function typeref:typename:int file: signature:(mtar_raw_header_t * rh,const mtar_header_t * h) +HOME_DIR ./Makefile 5;" macro +INCLUDES ./Makefile 18;" macro +INSIDE_QUOTED_FIELD ./lib/ccsv/include/ccsv.h 134;" enumerator enum:State +IS_TERMINATOR ./lib/ccsv/src/ccsv.c 692;" macro file: signature:(c) +KOSPM_CSV ./include/kospm_csv.h 24;" macro +kospm_csv_col_get ./include/kospm_csv.h 56;" prototype typeref:typename:int signature:(kospm_csv_header * header,char * col_name) +kospm_csv_col_get ./src/kospm_csv.c 38;" function typeref:typename:int signature:(kospm_csv_header * header,char * col_name) +kospm_csv_field_get ./src/kospm_csv.c 44;" function typeref:typename:char * signature:(ccsv_row * row,kospm_csv_header * header,char * col_name) +kospm_csv_header ./include/kospm_csv.h 52;" typedef typeref:struct:__anon1f1fcb200208 +kospm_csv_header_col ./include/kospm_csv.h 47;" typedef typeref:struct:__anon1f1fcb200108 +kospm_csv_header_get ./include/kospm_csv.h 54;" prototype typeref:typename:kospm_csv_header * signature:(FILE * file) +kospm_csv_header_get ./src/kospm_csv.c 5;" function typeref:typename:kospm_csv_header * signature:(FILE * file) +kospm_csv_reader_options ./include/kospm_csv.h 31;" variable typeref:typename:ccsv_reader_options +kospm_csv_string_get ./include/kospm_csv.h 58;" prototype typeref:typename:char * signature:(ccsv_row * row,kospm_csv_header * header,char * col_name) +kospm_csv_writer_options ./include/kospm_csv.h 39;" variable typeref:typename:ccsv_reader_options +kospm_db_close ./include/kospm_pkgdb.h 41;" prototype typeref:typename:int signature:(kospm_pkg_db_t * db) +kospm_db_close ./src/kospm_pkgdb.c 57;" function typeref:typename:int signature:(kospm_pkg_db_t * db) +kospm_db_init ./include/kospm_pkgdb.h 35;" prototype typeref:typename:kospm_pkg_db_t * signature:() +kospm_db_init ./src/kospm_pkgdb.c 26;" function typeref:typename:kospm_pkg_db_t * signature:() +kospm_db_open ./include/kospm_pkgdb.h 37;" prototype typeref:typename:kospm_pkg_db_t * signature:(kospm_pkg_db_t * db,char * root_path) +kospm_db_open ./src/kospm_pkgdb.c 34;" function typeref:typename:kospm_pkg_db_t * signature:(kospm_pkg_db_t * db,char * root_path) +kospm_db_pkg_add ./include/kospm_pkgdb.h 43;" prototype typeref:typename:int signature:(kospm_pkg_db_t * db,kospm_pkg_meta_t * package) +kospm_db_pkg_add ./src/kospm_pkgdb.c 68;" function typeref:typename:int signature:(kospm_pkg_db_t * db,kospm_pkg_meta_t * package) +kospm_db_pkg_file_add ./include/kospm_pkgdb.h 47;" prototype typeref:typename:int signature:(kospm_pkg_db_t * db,kospm_pkg_file_t * file) +kospm_db_pkg_file_add ./src/kospm_pkgdb.c 81;" function typeref:typename:int signature:(kospm_pkg_db_t * db,kospm_pkg_file_t * file) +kospm_db_pkg_file_remove ./include/kospm_pkgdb.h 49;" prototype typeref:typename:int signature:(kospm_pkg_db_t * db,char * file_name) +kospm_db_pkg_file_remove ./src/kospm_pkgdb.c 87;" function typeref:typename:int signature:(kospm_pkg_db_t * db,char * file_name) +kospm_db_pkg_remove ./include/kospm_pkgdb.h 45;" prototype typeref:typename:int signature:(kospm_pkg_db_t * db,char * pkg_name) +kospm_db_pkg_remove ./src/kospm_pkgdb.c 74;" function typeref:typename:int signature:(kospm_pkg_db_t * db,char * pkg_name) +kospm_db_save ./include/kospm_pkgdb.h 39;" prototype typeref:typename:int signature:(kospm_pkg_db_t * db) +kospm_db_save ./src/kospm_pkgdb.c 43;" function typeref:typename:int signature:(kospm_pkg_db_t * db) +KOSPM_EXACTNAME ./include/kospm.h 29;" enumerator enum:kospm_query_modes +KOSPM_FILELIST ./include/kospm.h 28;" enumerator enum:kospm_query_modes +kospm_install ./include/kospm.h 42;" prototype typeref:typename:int signature:(kospm_db_t * db,char * pkg_file,char * pkg_name) +kospm_install ./src/kospm.c 25;" function typeref:typename:int signature:(kospm_db_t * db,char * pkg_file,char * pkg_name) +KOSPM_LIST ./include/kospm_list.h 24;" macro +kospm_list ./include/kospm_list.h 34;" struct +kospm_list_add ./include/kospm_list.h 42;" prototype typeref:typename:void signature:(kospm_list_t * dlist,void * data) +kospm_list_add ./src/kospm_list.c 36;" function typeref:typename:void signature:(kospm_list_t * dlist,void * data) +kospm_list_del_by_value ./include/kospm_list.h 50;" prototype typeref:typename:void signature:(kospm_list_t * dlist,void * data,int (* cmp)(void *,void *),void (* free_alt)(void *)) +kospm_list_del_by_value ./src/kospm_list.c 75;" function typeref:typename:void signature:(kospm_list_t * dlist,void * data,int (* cmp)(void *,void *),void (* free_alt)(void *)) +kospm_list_free ./include/kospm_list.h 52;" prototype typeref:typename:void signature:(kospm_list_t * dlist,void (* free_alt)(void *)) +kospm_list_get_by_value ./include/kospm_list.h 48;" prototype typeref:typename:kospm_list_node_t * signature:(kospm_list_t * dlist,void * data,int (* cmp)(void *,void *)) +kospm_list_get_by_value ./src/kospm_list.c 59;" function typeref:typename:kospm_list_node_t * signature:(kospm_list_t * dlist,void * data,int (* cmp)(void *,void *)) +kospm_list_new ./include/kospm_list.h 40;" prototype typeref:typename:kospm_list_t * signature:() +kospm_list_new ./src/kospm_list.c 26;" function typeref:typename:kospm_list_t * signature:() +kospm_list_next ./include/kospm_list.h 46;" prototype typeref:typename:void signature:(kospm_list_t * dlist) +kospm_list_next ./src/kospm_list.c 54;" function typeref:typename:void * signature:(kospm_list_t * dlist) +kospm_list_node ./include/kospm_list.h 28;" struct +kospm_list_node_t ./include/kospm_list.h 32;" typedef typeref:struct:kospm_list_node +kospm_list_prev ./include/kospm_list.h 44;" prototype typeref:typename:void signature:(kospm_list_t * dlist) +kospm_list_prev ./src/kospm_list.c 49;" function typeref:typename:void * signature:(kospm_list_t * dlist) +kospm_list_t ./include/kospm_list.h 38;" typedef typeref:struct:kospm_list +KOSPM_PKGBUNDLE ./include/kospm_pkgbundle.h 24;" macro +KOSPM_PKGDB ./include/kospm_pkgdb.h 24;" macro +KOSPM_PKGFILE ./include/kospm_pkgfile.h 2;" macro +KOSPM_PKGLIST ./include/kospm_pkglist.h 24;" macro +KOSPM_PKGMETA ./include/kospm_pkgmeta.h 2;" macro +kospm_pkg_bundle ./include/kospm_pkgbundle.h 32;" struct +kospm_pkg_bundle_close ./include/kospm_pkgbundle.h 42;" prototype typeref:typename:int signature:() +kospm_pkg_bundle_close ./src/kospm_pkgbundle.c 68;" function typeref:typename:int signature:(kospm_pkg_bundle_t * pkg_bundle) +kospm_pkg_bundle_open ./include/kospm_pkgbundle.h 37;" prototype typeref:typename:kospm_pkg_bundle_t * signature:(char * bundle_path) +kospm_pkg_bundle_open ./src/kospm_pkgbundle.c 26;" function typeref:typename:kospm_pkg_bundle_t * signature:(char * bundle_path) +kospm_pkg_bundle_t ./include/kospm_pkgbundle.h 35;" typedef typeref:struct:kospm_pkg_bundle +kospm_pkg_bundle_unpack ./include/kospm_pkgbundle.h 39;" prototype typeref:typename:int signature:(char * root_path,kospm_pkg_bundle_t * pkg_bundle,char * pkg_name) +kospm_pkg_bundle_unpack ./src/kospm_pkgbundle.c 46;" function typeref:typename:int signature:(kospm_pkg_bundle_t * pkg_bundle,char * root_path,char * pkg_name) +kospm_pkg_db ./include/kospm_pkgdb.h 30;" struct +kospm_pkg_db_t ./include/kospm_pkgdb.h 33;" typedef typeref:struct:kospm_pkg_db +kospm_pkg_file_check_pkgname ./src/kospm_pkgfile.c 31;" function typeref:typename:int signature:(kospm_pkg_meta_t * pkg_meta,char * pkg_name) +kospm_pkg_file_free ./include/kospm_pkgfile.h 20;" prototype typeref:typename:int signature:(kospm_pkg_file_t * pkg_file) +kospm_pkg_file_free ./src/kospm_pkgfile.c 36;" function typeref:typename:int signature:(kospm_pkg_file_t * pkg_file) +kospm_pkg_file_init ./include/kospm_pkgfile.h 12;" prototype typeref:typename:kospm_pkg_meta_t * signature:() +kospm_pkg_file_init ./src/kospm_pkgfile.c 4;" function typeref:typename:kospm_pkg_file_t * signature:() +kospm_pkg_file_load ./include/kospm_pkgfile.h 14;" prototype typeref:typename:kospm_pkg_meta_t * signature:(ccsv_row * row,kospm_list_t * header) +kospm_pkg_file_load ./src/kospm_pkgfile.c 10;" function typeref:typename:kospm_pkg_file_t * signature:(ccsv_row * row,kospm_csv_header * header) +kospm_pkg_file_store ./include/kospm_pkgfile.h 17;" prototype typeref:typename:char ** signature:(kospm_pkg_file_t * pkg_file,kospm_list_t * header) +kospm_pkg_file_store ./src/kospm_pkgfile.c 20;" function typeref:typename:char ** signature:(kospm_pkg_file_t * pkg_file,kospm_csv_header * header) +kospm_pkg_file_t ./include/kospm_pkgfile.h 10;" typedef typeref:struct:__anon7ad9ca760108 +kospm_pkg_file_t ./include/kospm_pkglist.h 34;" typedef typeref:struct:__anon88dcd4b20108 +kospm_pkg_list_close ./include/kospm_pkglist.h 55;" prototype typeref:typename:int signature:(kospm_pkg_list_t * pkg_list) +kospm_pkg_list_close ./src/kospm_pkglist.c 177;" function typeref:typename:int signature:(kospm_pkg_list_t * pkg_list) +kospm_pkg_list_files_query ./include/kospm_pkglist.h 59;" prototype typeref:typename:kospm_list_t * signature:(kospm_pkg_list_t * pkg_list,char * pkg_name) +kospm_pkg_list_files_query ./src/kospm_pkglist.c 195;" function typeref:typename:kospm_list_t * signature:(kospm_pkg_list_t * pkg_list,char * pkg_name) +kospm_pkg_list_init ./include/kospm_pkglist.h 49;" prototype typeref:typename:kospm_pkg_list_t * signature:() +kospm_pkg_list_init ./src/kospm_pkglist.c 113;" function typeref:typename:kospm_pkg_list_t * signature:() +kospm_pkg_list_meta_query ./include/kospm_pkglist.h 57;" prototype typeref:typename:kospm_pkg_meta_t * signature:(kospm_pkg_list_t * pkg_list,char * pkg_name) +kospm_pkg_list_meta_query ./src/kospm_pkglist.c 186;" function typeref:typename:kospm_pkg_meta_t * signature:(kospm_pkg_list_t * pkg_list,char * pkg_name) +kospm_pkg_list_open ./include/kospm_pkglist.h 51;" prototype typeref:typename:kospm_pkg_list_t * signature:(kospm_pkg_list_t * pkg_list,char * pkg_list_path) +kospm_pkg_list_open ./src/kospm_pkglist.c 122;" function typeref:typename:kospm_pkg_list_t * signature:(kospm_pkg_list_t * pkg_list,char * pkg_list_path) +kospm_pkg_list_save ./include/kospm_pkglist.h 53;" prototype typeref:typename:int signature:(kospm_pkg_list_t * pkg_list,char * pkglist_path) +kospm_pkg_list_save ./src/kospm_pkglist.c 143;" function typeref:typename:int signature:(kospm_pkg_list_t * pkg_list,char * pkglist_path) +kospm_pkg_list_t ./include/kospm_pkglist.h 47;" typedef typeref:struct:__anon88dcd4b20308 +kospm_pkg_meta_check_pkgname ./src/kospm_pkgmeta.c 42;" function typeref:typename:int signature:(kospm_pkg_meta_t * pkg_meta,char * pkg_name) +kospm_pkg_meta_cmp ./include/kospm_pkgmeta.h 24;" prototype typeref:typename:int signature:(kospm_pkg_meta_t * pkg_meta,char * pkg_name) +kospm_pkg_meta_free ./include/kospm_pkgmeta.h 26;" prototype typeref:typename:int signature:(kospm_pkg_meta_t * pkg_meta) +kospm_pkg_meta_free ./src/kospm_pkgmeta.c 47;" function typeref:typename:int signature:(kospm_pkg_meta_t * pkg_meta) +kospm_pkg_meta_init ./include/kospm_pkgmeta.h 16;" prototype typeref:typename:kospm_pkg_meta_t * signature:() +kospm_pkg_meta_init ./src/kospm_pkgmeta.c 5;" function typeref:typename:kospm_pkg_meta_t * signature:() +kospm_pkg_meta_load ./include/kospm_pkgmeta.h 18;" prototype typeref:typename:kospm_pkg_meta_t * signature:(ccsv_row * row,kospm_list_t * header) +kospm_pkg_meta_load ./src/kospm_pkgmeta.c 11;" function typeref:typename:kospm_pkg_meta_t * signature:(ccsv_row * row,kospm_csv_header * header) +kospm_pkg_meta_store ./include/kospm_pkgmeta.h 21;" prototype typeref:typename:char ** signature:(kospm_pkg_meta_t * pkg_meta,kospm_list_t * header) +kospm_pkg_meta_store ./src/kospm_pkgmeta.c 27;" function typeref:typename:char ** signature:(kospm_pkg_meta_t * pkg_meta,kospm_csv_header * header) +kospm_pkg_meta_t ./include/kospm_pkglist.h 42;" typedef typeref:struct:__anon88dcd4b20208 +kospm_pkg_meta_t ./include/kospm_pkgmeta.h 14;" typedef typeref:struct:__anon8ae9d6dd0108 +kospm_query ./include/kospm.h 46;" prototype typeref:typename:int signature:(kospm_db_t * db,char * pkg_name,int8_t query_mode) +kospm_query_modes ./include/kospm.h 27;" enum +kospm_remove ./include/kospm.h 44;" prototype typeref:typename:int signature:(kospm_db_t * db,char * pkg_name) +KOSPM_STRING ./include/kospm_string.h 2;" macro +KOSPM_TAR ./include/kospm_tar.h 24;" macro +kospm_tar_filelist_get ./include/kospm_tar.h 29;" prototype typeref:typename:kospm_list_t * signature:(const char * tar_name) +kospm_tar_filelist_get ./src/kospm_tar.c 26;" function typeref:typename:kospm_list_t * signature:(const char * tar_name) +kospm_tar_unpack ./include/kospm_tar.h 31;" prototype typeref:typename:int signature:(const char * tar_name,const char * src_file,const char * dest_file) +kospm_tar_unpack ./src/kospm_tar.c 54;" function typeref:typename:int signature:(const char * tar_name,const char * src_file,const char * dest_file) +last ./include/kospm_list.h 37;" member struct:kospm_list typeref:typename:kospm_list_node_t * +last_header ./lib/microtar/src/microtar.h 64;" member struct:mtar_t typeref:typename:unsigned +LD ./Makefile 2;" macro +LDFLAGS ./Makefile 16;" macro +libkospm.a ./Makefile 33;" target +LIBPATH ./Makefile 19;" macro +License ./lib/ccsv/README.md 114;" section chapter:ccsv +License ./lib/microtar/README.md 97;" section chapter:microtar +linkname ./lib/microtar/src/microtar.c 39;" member struct:__anon2ac420210108 typeref:typename:char[100] file: +linkname ./lib/microtar/src/microtar.h 50;" member struct:__anon2ac420260308 typeref:typename:char[100] +main ./lib/ccsv/examples/count_rf.c 7;" function typeref:typename:int signature:(int argc,char * argv[]) +main ./lib/ccsv/examples/cpy.c 7;" function typeref:typename:int signature:(int argc,char * argv[]) +main ./lib/ccsv/examples/cpy_new.c 6;" function typeref:typename:int signature:(int argc,char ** argv) +main ./lib/ccsv/examples/handling_memory_allocation_failure.c 6;" function typeref:typename:int signature:(void) +main ./lib/ccsv/examples/print_each_row.c 6;" function typeref:typename:int signature:(void) +main ./lib/ccsv/examples/print_each_row_ccsv_v0.5.c 6;" function typeref:typename:int signature:(void) +main ./lib/ccsv/examples/print_headers.c 6;" function typeref:typename:int signature:(void) +main ./lib/ccsv/examples/with_reader_options.c 6;" function typeref:typename:int signature:(void) +main ./lib/ccsv/examples/writer_macros.c 6;" function typeref:typename:int signature:(void) +main ./lib/ccsv/examples/writing_from_array.c 5;" function typeref:typename:int signature:(void) +main ./lib/ccsv/examples/writing_from_CSVRow_struct.c 6;" function typeref:typename:int signature:(void) +main ./lib/ccsv/tests/test_ccsv.c 6;" function typeref:typename:int signature:(void) +MALLOCNEW ./include/kospm_macros.h 2;" macro signature:(var_name,type) +MALLOCNEWARR ./include/kospm_macros.h 8;" macro signature:(var_name,type,amount) +MAX_FIELD_SIZE ./lib/ccsv/include/ccsv.h 59;" macro +MAY_BE_ESCAPED ./lib/ccsv/include/ccsv.h 135;" enumerator enum:State +META_CACHE ./include/kospm_pkgbundle.h 29;" macro +META_TABLE ./include/kospm_pkglist.h 28;" macro +microtar ./lib/microtar/README.md 1;" chapter +MICROTAR_H ./lib/microtar/src/microtar.h 9;" macro +MICROTAR_SOURCES ./Makefile 21;" macro +mode ./lib/microtar/src/microtar.c 32;" member struct:__anon2ac420210108 typeref:typename:char[8] file: +mode ./lib/microtar/src/microtar.h 44;" member struct:__anon2ac420260308 typeref:typename:unsigned +mtar_close ./lib/microtar/src/microtar.c 211;" function typeref:typename:int signature:(mtar_t * tar) +mtar_close ./lib/microtar/src/microtar.h 71;" prototype typeref:typename:int signature:(mtar_t * tar) +MTAR_EBADCHKSUM ./lib/microtar/src/microtar.h 28;" enumerator enum:__anon2ac420260103 +MTAR_EFAILURE ./lib/microtar/src/microtar.h 23;" enumerator enum:__anon2ac420260103 +MTAR_ENOTFOUND ./lib/microtar/src/microtar.h 30;" enumerator enum:__anon2ac420260103 +MTAR_ENULLRECORD ./lib/microtar/src/microtar.h 29;" enumerator enum:__anon2ac420260103 +MTAR_EOPENFAIL ./lib/microtar/src/microtar.h 24;" enumerator enum:__anon2ac420260103 +MTAR_EREADFAIL ./lib/microtar/src/microtar.h 25;" enumerator enum:__anon2ac420260103 +MTAR_ESEEKFAIL ./lib/microtar/src/microtar.h 27;" enumerator enum:__anon2ac420260103 +MTAR_ESUCCESS ./lib/microtar/src/microtar.h 22;" enumerator enum:__anon2ac420260103 +MTAR_EWRITEFAIL ./lib/microtar/src/microtar.h 26;" enumerator enum:__anon2ac420260103 +mtar_finalize ./lib/microtar/src/microtar.c 373;" function typeref:typename:int signature:(mtar_t * tar) +mtar_finalize ./lib/microtar/src/microtar.h 84;" prototype typeref:typename:int signature:(mtar_t * tar) +mtar_find ./lib/microtar/src/microtar.c 244;" function typeref:typename:int signature:(mtar_t * tar,const char * name,mtar_header_t * h) +mtar_find ./lib/microtar/src/microtar.h 76;" prototype typeref:typename:int signature:(mtar_t * tar,const char * name,mtar_header_t * h) +mtar_header_t ./lib/microtar/src/microtar.h 51;" typedef typeref:struct:__anon2ac420260308 +mtar_next ./lib/microtar/src/microtar.c 230;" function typeref:typename:int signature:(mtar_t * tar) +mtar_next ./lib/microtar/src/microtar.h 75;" prototype typeref:typename:int signature:(mtar_t * tar) +mtar_open ./lib/microtar/src/microtar.c 177;" function typeref:typename:int signature:(mtar_t * tar,const char * filename,const char * mode) +mtar_open ./lib/microtar/src/microtar.h 70;" prototype typeref:typename:int signature:(mtar_t * tar,const char * filename,const char * mode) +mtar_raw_header_t ./lib/microtar/src/microtar.c 41;" typedef typeref:struct:__anon2ac420210108 file: +mtar_read_data ./lib/microtar/src/microtar.c 290;" function typeref:typename:int signature:(mtar_t * tar,void * ptr,unsigned size) +mtar_read_data ./lib/microtar/src/microtar.h 78;" prototype typeref:typename:int signature:(mtar_t * tar,void * ptr,unsigned size) +mtar_read_header ./lib/microtar/src/microtar.c 270;" function typeref:typename:int signature:(mtar_t * tar,mtar_header_t * h) +mtar_read_header ./lib/microtar/src/microtar.h 77;" prototype typeref:typename:int signature:(mtar_t * tar,mtar_header_t * h) +mtar_rewind ./lib/microtar/src/microtar.c 223;" function typeref:typename:int signature:(mtar_t * tar) +mtar_rewind ./lib/microtar/src/microtar.h 74;" prototype typeref:typename:int signature:(mtar_t * tar) +mtar_seek ./lib/microtar/src/microtar.c 216;" function typeref:typename:int signature:(mtar_t * tar,unsigned pos) +mtar_seek ./lib/microtar/src/microtar.h 73;" prototype typeref:typename:int signature:(mtar_t * tar,unsigned pos) +mtar_strerror ./lib/microtar/src/microtar.c 140;" function typeref:typename:const char * signature:(int err) +mtar_strerror ./lib/microtar/src/microtar.h 68;" prototype typeref:typename:const char * signature:(int err) +mtar_t ./lib/microtar/src/microtar.h 54;" typedef typeref:struct:mtar_t +mtar_t ./lib/microtar/src/microtar.h 56;" struct +MTAR_TBLK ./lib/microtar/src/microtar.h 38;" enumerator enum:__anon2ac420260203 +MTAR_TCHR ./lib/microtar/src/microtar.h 37;" enumerator enum:__anon2ac420260203 +MTAR_TDIR ./lib/microtar/src/microtar.h 39;" enumerator enum:__anon2ac420260203 +MTAR_TFIFO ./lib/microtar/src/microtar.h 40;" enumerator enum:__anon2ac420260203 +MTAR_TLNK ./lib/microtar/src/microtar.h 35;" enumerator enum:__anon2ac420260203 +MTAR_TREG ./lib/microtar/src/microtar.h 34;" enumerator enum:__anon2ac420260203 +MTAR_TSYM ./lib/microtar/src/microtar.h 36;" enumerator enum:__anon2ac420260203 +MTAR_VERSION ./lib/microtar/src/microtar.h 19;" macro +mtar_write_data ./lib/microtar/src/microtar.c 357;" function typeref:typename:int signature:(mtar_t * tar,const void * data,unsigned size) +mtar_write_data ./lib/microtar/src/microtar.h 83;" prototype typeref:typename:int signature:(mtar_t * tar,const void * data,unsigned size) +mtar_write_dir_header ./lib/microtar/src/microtar.c 345;" function typeref:typename:int signature:(mtar_t * tar,const char * name) +mtar_write_dir_header ./lib/microtar/src/microtar.h 82;" prototype typeref:typename:int signature:(mtar_t * tar,const char * name) +mtar_write_file_header ./lib/microtar/src/microtar.c 332;" function typeref:typename:int signature:(mtar_t * tar,const char * name,unsigned size) +mtar_write_file_header ./lib/microtar/src/microtar.h 81;" prototype typeref:typename:int signature:(mtar_t * tar,const char * name,unsigned size) +mtar_write_header ./lib/microtar/src/microtar.c 323;" function typeref:typename:int signature:(mtar_t * tar,const mtar_header_t * h) +mtar_write_header ./lib/microtar/src/microtar.h 80;" prototype typeref:typename:int signature:(mtar_t * tar,const mtar_header_t * h) +mtime ./lib/microtar/src/microtar.c 36;" member struct:__anon2ac420210108 typeref:typename:char[12] file: +mtime ./lib/microtar/src/microtar.h 47;" member struct:__anon2ac420260308 typeref:typename:unsigned +name ./lib/microtar/src/microtar.c 31;" member struct:__anon2ac420210108 typeref:typename:char[100] file: +name ./lib/microtar/src/microtar.h 49;" member struct:__anon2ac420260308 typeref:typename:char[100] +NAME_MAX ./include/kospm_string.h 7;" macro +next ./include/kospm_list.h 31;" member struct:kospm_list_node typeref:struct:kospm_list_node * +OBJECTS ./Makefile 29;" macro +object_type ./lib/ccsv/include/ccsv.h 173;" member struct:ccsv_reader typeref:typename:short +object_type ./lib/ccsv/include/ccsv.h 197;" member struct:ccsv_writer typeref:typename:short +owner ./lib/microtar/src/microtar.c 33;" member struct:__anon2ac420210108 typeref:typename:char[8] file: +owner ./lib/microtar/src/microtar.h 45;" member struct:__anon2ac420260308 typeref:typename:unsigned +packages ./include/kospm_pkglist.h 45;" member struct:__anon88dcd4b20308 typeref:typename:kospm_list_t * +package_list ./include/kospm_pkgbundle.h 34;" member struct:kospm_pkg_bundle typeref:typename:kospm_pkg_list_t * +package_list ./include/kospm_pkgdb.h 32;" member struct:kospm_pkg_db typeref:typename:kospm_pkg_list_t * +pkg_depends ./include/kospm_pkgmeta.h 12;" member struct:__anon8ae9d6dd0108 typeref:typename:kospm_list_t * +pkg_description ./include/kospm_pkglist.h 39;" member struct:__anon88dcd4b20208 typeref:typename:char * +pkg_description ./include/kospm_pkgmeta.h 10;" member struct:__anon8ae9d6dd0108 typeref:typename:char * +pkg_name ./include/kospm_pkgfile.h 8;" member struct:__anon7ad9ca760108 typeref:typename:char[] +pkg_name ./include/kospm_pkglist.h 32;" member struct:__anon88dcd4b20108 typeref:typename:char[32] +pkg_name ./include/kospm_pkglist.h 37;" member struct:__anon88dcd4b20208 typeref:typename:char[32] +pkg_name ./include/kospm_pkgmeta.h 8;" member struct:__anon8ae9d6dd0108 typeref:typename:char[] +pkg_size ./include/kospm_pkgmeta.h 11;" member struct:__anon8ae9d6dd0108 typeref:typename:int +pkg_tags ./include/kospm_pkgmeta.h 13;" member struct:__anon8ae9d6dd0108 typeref:typename:kospm_list_t * +pkg_version ./include/kospm_pkglist.h 38;" member struct:__anon88dcd4b20208 typeref:typename:char[16] +pkg_version ./include/kospm_pkgmeta.h 9;" member struct:__anon8ae9d6dd0108 typeref:typename:char[] +pos ./lib/microtar/src/microtar.h 62;" member struct:mtar_t typeref:typename:unsigned +prev ./include/kospm_list.h 30;" member struct:kospm_list_node typeref:struct:kospm_list_node * +quote_char ./lib/ccsv/include/ccsv.h 149;" member struct:ccsv_reader_options typeref:typename:char +quote_char ./lib/ccsv/include/ccsv.h 185;" member struct:ccsv_writer_options typeref:typename:char +raw_to_header ./lib/microtar/src/microtar.c 90;" function typeref:typename:int file: signature:(mtar_header_t * h,const mtar_raw_header_t * rh) +read ./lib/microtar/src/microtar.h 57;" member struct:mtar_t typeref:typename:int (*)(mtar_t * tar,void * data,unsigned size) +Read a row with ./lib/ccsv/README.md 28;" subsection section:ccsv""Usage +Reading ./lib/microtar/README.md 10;" subsubsection section:microtar""Basic Usage +Reading ./lib/microtar/README.md 80;" subsubsection section:microtar""Wrapping a stream +read_row ./lib/ccsv/include/ccsv.h 268;" prototype typeref:typename:ccsv_row * signature:(FILE * fp,ccsv_reader * parser) +read_row ./lib/ccsv/src/ccsv.c 419;" function typeref:typename:ccsv_row * signature:(FILE * fp,ccsv_reader * reader) +remaining_data ./lib/microtar/src/microtar.h 63;" member struct:mtar_t typeref:typename:unsigned +RETURN_IF_WRITE_ERROR ./lib/ccsv/src/ccsv.c 143;" macro file: signature:(writer,desired_status) +root_path ./include/kospm_pkgdb.h 31;" member struct:kospm_pkg_db typeref:typename:char * +round_up ./lib/microtar/src/microtar.c 44;" function typeref:typename:unsigned file: signature:(unsigned n,unsigned incr) +rows_read ./lib/ccsv/include/ccsv.h 159;" member struct:ccsv_reader typeref:typename:int +SDK_DIR ./Makefile 8;" macro +seek ./lib/microtar/src/microtar.h 59;" member struct:mtar_t typeref:typename:int (*)(mtar_t * tar,unsigned pos) +size ./lib/microtar/src/microtar.c 35;" member struct:__anon2ac420210108 typeref:typename:char[12] file: +size ./lib/microtar/src/microtar.h 46;" member struct:__anon2ac420260308 typeref:typename:unsigned +skip_comments ./lib/ccsv/include/ccsv.h 154;" member struct:ccsv_reader_options typeref:typename:int +skip_empty_lines ./lib/ccsv/include/ccsv.h 153;" member struct:ccsv_reader_options typeref:typename:int +skip_initial_space ./lib/ccsv/include/ccsv.h 152;" member struct:ccsv_reader_options typeref:typename:int +SOURCES ./Makefile 24;" macro +State ./lib/ccsv/include/ccsv.h 128;" enum +State ./lib/ccsv/include/ccsv.h 136;" typedef typeref:enum:State +status ./lib/ccsv/include/ccsv.h 172;" member struct:ccsv_reader typeref:typename:short +status_messages ./lib/ccsv/src/ccsv.c 46;" variable typeref:typename:const char * [] +strcpynew ./include/kospm_string.h 12;" function typeref:typename:char * signature:(const char * src,size_t n) +stream ./lib/microtar/src/microtar.h 61;" member struct:mtar_t typeref:typename:void * +TOOLCHAIN_DIR ./Makefile 6;" macro +TOTAL_ERROR_MESSAGES ./lib/ccsv/include/ccsv.h 76;" macro +tread ./lib/microtar/src/microtar.c 63;" function typeref:typename:int file: signature:(mtar_t * tar,void * data,unsigned size) +twrite ./lib/microtar/src/microtar.c 70;" function typeref:typename:int file: signature:(mtar_t * tar,const void * data,unsigned size) +type ./lib/microtar/src/microtar.c 38;" member struct:__anon2ac420210108 typeref:typename:char file: +type ./lib/microtar/src/microtar.h 48;" member struct:__anon2ac420260308 typeref:typename:unsigned +Usage ./lib/ccsv/README.md 6;" section chapter:ccsv +VERSION_MAX ./include/kospm_string.h 8;" macro +Wrapping a stream ./lib/microtar/README.md 66;" section chapter:microtar +write ./lib/microtar/src/microtar.h 58;" member struct:mtar_t typeref:typename:int (*)(mtar_t * tar,const void * data,unsigned size) +WriterState ./lib/ccsv/include/ccsv.h 138;" enum +WriterState ./lib/ccsv/include/ccsv.h 144;" typedef typeref:enum:WriterState +WRITER_NOT_STARTED ./lib/ccsv/include/ccsv.h 140;" enumerator enum:WriterState +WRITER_ROW_END ./lib/ccsv/include/ccsv.h 143;" enumerator enum:WriterState +WRITER_ROW_START ./lib/ccsv/include/ccsv.h 141;" enumerator enum:WriterState +WRITER_WRITING_FIELD ./lib/ccsv/include/ccsv.h 142;" enumerator enum:WriterState +WRITE_ENDED ./lib/ccsv/include/ccsv.h 92;" macro +WRITE_ERALWRITING ./lib/ccsv/include/ccsv.h 96;" macro +WRITE_ERINVALID ./lib/ccsv/include/ccsv.h 95;" macro +WRITE_ERNOMEM ./lib/ccsv/include/ccsv.h 94;" macro +WRITE_ERNOTSTARTED ./lib/ccsv/include/ccsv.h 93;" macro +write_null_bytes ./lib/microtar/src/microtar.c 77;" function typeref:typename:int file: signature:(mtar_t * tar,int n) +write_row ./lib/ccsv/include/ccsv.h 331;" prototype typeref:typename:int signature:(FILE * fp,ccsv_writer * writer,ccsv_row row) +write_row ./lib/ccsv/src/ccsv.c 1027;" function typeref:typename:int signature:(FILE * fp,ccsv_writer * writer,ccsv_row row) +write_row_from_array ./lib/ccsv/include/ccsv.h 345;" prototype typeref:typename:int signature:(FILE * fp,ccsv_writer * writer,char ** fields,int row_len) +write_row_from_array ./lib/ccsv/src/ccsv.c 1034;" function typeref:typename:int signature:(FILE * fp,ccsv_writer * writer,char ** fields,int row_len) +WRITE_STARTED ./lib/ccsv/include/ccsv.h 91;" macro +write_status ./lib/ccsv/include/ccsv.h 196;" member struct:ccsv_writer typeref:typename:short +WRITE_SUCCESS ./lib/ccsv/include/ccsv.h 90;" macro +Writing ./lib/microtar/README.md 36;" subsubsection section:microtar""Basic Usage +Writing ./lib/microtar/README.md 89;" subsubsection section:microtar""Wrapping a stream +You can find more examples in the `examples` folder ./lib/ccsv/README.md 107;" subsubsection section:ccsv""Example +_free_multiple ./lib/ccsv/include/ccsv.h 397;" prototype typeref:typename:void signature:(int num,...) +_free_multiple ./lib/ccsv/src/ccsv.c 244;" function typeref:typename:void signature:(int num,...) +_get_object_type ./lib/ccsv/include/ccsv.h 358;" prototype typeref:typename:int signature:(void * obj) +_get_object_type ./lib/ccsv/src/ccsv.c 64;" function typeref:typename:int signature:(void * obj) +_is_buffer_empty ./lib/ccsv/include/ccsv.h 387;" prototype typeref:typename:int signature:(ccsv_reader * reader) +_is_buffer_empty ./lib/ccsv/src/ccsv.c 946;" function typeref:typename:int signature:(ccsv_reader * reader) +_kospm_csv_col_cmp ./src/kospm_csv.c 34;" function typeref:typename:int signature:(kospm_csv_header_col * column,char * name) +_kospm_files_table_read ./src/kospm_pkglist.c 51;" function typeref:typename:kospm_list_t * signature:(char * file_path) +_kospm_files_table_write ./src/kospm_pkglist.c 92;" function typeref:typename:int signature:(kospm_pkg_list_t * pkg_list,char * file_path) +_kospm_meta_table_read ./src/kospm_pkglist.c 31;" function typeref:typename:kospm_list_t * signature:(char * file_path) +_kospm_meta_table_write ./src/kospm_pkglist.c 71;" function typeref:typename:int signature:(kospm_pkg_list_t * pkg_list,char * file_path) +_kospm_pkg_file_free ./src/kospm_pkglist.c 171;" function typeref:typename:void signature:(kospm_pkg_file_t * pkg_file) +_kospm_pkg_meta_free ./src/kospm_pkglist.c 165;" function typeref:typename:void signature:(kospm_pkg_meta_t * pkg_meta) +_next ./lib/ccsv/include/ccsv.h 382;" prototype typeref:typename:ccsv_row * signature:(FILE * fp,ccsv_reader * reader) +_next ./lib/ccsv/src/ccsv.c 694;" function typeref:typename:ccsv_row * signature:(FILE * fp,ccsv_reader * reader) +_padding ./lib/microtar/src/microtar.c 40;" member struct:__anon2ac420210108 typeref:typename:char[255] file: +_read_row ./lib/ccsv/include/ccsv.h 370;" prototype typeref:typename:ccsv_row * signature:(FILE * fp,ccsv_reader * reader) +_read_row ./lib/ccsv/src/ccsv.c 429;" function typeref:typename:ccsv_row * signature:(FILE * fp,ccsv_reader * reader) +_same_pkgname ./src/kospm_pkgdb.c 64;" function typeref:typename:int signature:(void * struc,char * name) +_write_field ./lib/ccsv/include/ccsv.h 412;" prototype typeref:typename:int signature:(FILE * fp,ccsv_writer * writer,const char * string) +_write_field ./lib/ccsv/src/ccsv.c 1127;" function typeref:typename:int signature:(FILE * fp,ccsv_writer * writer,const char * string) +_write_row_end ./lib/ccsv/include/ccsv.h 438;" prototype typeref:typename:int signature:(FILE * fp,ccsv_writer * writer) +_write_row_end ./lib/ccsv/src/ccsv.c 1099;" function typeref:typename:int signature:(FILE * fp,ccsv_writer * writer) +_write_row_start ./lib/ccsv/include/ccsv.h 425;" prototype typeref:typename:int signature:(FILE * fp,ccsv_writer * writer) +_write_row_start ./lib/ccsv/src/ccsv.c 1052;" function typeref:typename:int signature:(FILE * fp,ccsv_writer * writer) +__anon1f1fcb200108 ./include/kospm_csv.h 44;" struct +__anon1f1fcb200208 ./include/kospm_csv.h 49;" struct +__anon2ac420210108 ./lib/microtar/src/microtar.c 30;" struct file: +__anon2ac420260103 ./lib/microtar/src/microtar.h 21;" enum +__anon2ac420260203 ./lib/microtar/src/microtar.h 33;" enum +__anon2ac420260308 ./lib/microtar/src/microtar.h 43;" struct +__anon7ad9ca760108 ./include/kospm_pkgfile.h 7;" struct +__anon88dcd4b20108 ./include/kospm_pkglist.h 31;" struct +__anon88dcd4b20208 ./include/kospm_pkglist.h 36;" struct +__anon88dcd4b20308 ./include/kospm_pkglist.h 44;" struct +__anon8ae9d6dd0108 ./include/kospm_pkgmeta.h 7;" struct +__buffer ./lib/ccsv/include/ccsv.h 167;" member struct:ccsv_reader typeref:typename:char * +__buffer_allocated ./lib/ccsv/include/ccsv.h 170;" member struct:ccsv_reader typeref:typename:bool +__buffer_pos ./lib/ccsv/include/ccsv.h 168;" member struct:ccsv_reader typeref:typename:size_t +__buffer_size ./lib/ccsv/include/ccsv.h 169;" member struct:ccsv_reader typeref:typename:size_t +__comment_char ./lib/ccsv/include/ccsv.h 162;" member struct:ccsv_reader typeref:typename:char +__delim ./lib/ccsv/include/ccsv.h 160;" member struct:ccsv_reader typeref:typename:char +__delim ./lib/ccsv/include/ccsv.h 191;" member struct:ccsv_writer typeref:typename:char +__escape_char ./lib/ccsv/include/ccsv.h 163;" member struct:ccsv_reader typeref:typename:char +__escape_char ./lib/ccsv/include/ccsv.h 193;" member struct:ccsv_writer typeref:typename:char +__fp ./lib/ccsv/include/ccsv.h 171;" member struct:ccsv_reader typeref:typename:FILE * +__fp ./lib/ccsv/include/ccsv.h 195;" member struct:ccsv_writer typeref:typename:FILE * +__quote_char ./lib/ccsv/include/ccsv.h 161;" member struct:ccsv_reader typeref:typename:char +__quote_char ./lib/ccsv/include/ccsv.h 192;" member struct:ccsv_writer typeref:typename:char +__skip_comments ./lib/ccsv/include/ccsv.h 166;" member struct:ccsv_reader typeref:typename:int +__skip_empty_lines ./lib/ccsv/include/ccsv.h 165;" member struct:ccsv_reader typeref:typename:int +__skip_initial_space ./lib/ccsv/include/ccsv.h 164;" member struct:ccsv_reader typeref:typename:int +__state ./lib/ccsv/include/ccsv.h 194;" member struct:ccsv_writer typeref:typename:WriterState diff --git a/lib/ccsv/.gitignore b/lib/ccsv/.gitignore deleted file mode 100644 index 7aa4469..0000000 --- a/lib/ccsv/.gitignore +++ /dev/null @@ -1,58 +0,0 @@ -/.vscode -/.vs - -tests/write_test.c -rough*.c - -# Prerequisites -*.d - -# Object files -*.o -*.ko -*.obj -*.elf - -# Linker output -*.ilk -*.map -*.exp - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb - -# Kernel Module Compile Results -*.mod* -*.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf diff --git a/lib/ccsv/LICENSE b/lib/ccsv/LICENSE deleted file mode 100644 index 8dd313f..0000000 --- a/lib/ccsv/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 Ayush Tripathy - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/lib/ccsv/README.md b/lib/ccsv/README.md deleted file mode 100644 index bfe9357..0000000 --- a/lib/ccsv/README.md +++ /dev/null @@ -1,117 +0,0 @@ -# ccsv -Fast, flexible, easy-to-use CSV reading, writing library for C - -For full documentation, see the [docs](https://github.com/Ayush-Tripathy/ccsv/tree/main/docs) - -## Usage -### Create a reader object - -```c -ccsv_reader *reader = ccsv_init_reader(NULL); // NULL for default options -``` - -### Create a reader object with custom options - -```c -ccsv_reader_options options = { - .delim = ',', - .quote_char = '"', - .skip_initial_space = 0, - .skip_empty_lines = 1, - .skip_comments = 1}; - -// Initialize the reader with the options -ccsv_reader *reader = ccsv_init_reader(&options); -``` - - -### Read a row with - -```c -CSVRow *row = read_row(fp, reader); // Will return NULL if all rows are read -``` - -`fp` is a FILE pointer to the CSV file you want to read - -`reader` is a ccsv_reader object - -### Get the number of fields in a row with - -```c -int row_len = row->fields_count; -``` - -### Get a field from a row with - -```c -char *field = row->fields[0]; // 0 for the first field -``` - -### Free the memory allocated to a row with - -```c -free_row(row); -``` - -### Free the memory allocated to the reader with - -```c -free(reader); -``` - - - -## Example - -```c -#include -#include - -#include "ccsv.h" - -int main(void) -{ - FILE *fp = fopen("../../ign.csv", "r"); // Specify the path to your file - - if (fp == NULL) - { - printf("Error opening file\n"); - exit(1); - } - - // Reader object - ccsv_reader *reader = ccsv_init_reader(NULL); // NULL for default options - - CSVRow *row; - - // Read each row and print each field - while ((row = read_row(fp, reader)) != NULL) - { - int row_len = row->fields_count; // Get number of fields in the row - for (int i = 0; i < row_len; i++) - { - printf("%d.Field: %s\n", i + 1, row->fields[i]); // Print each field - } - printf("\n"); - free_row(row); // Free the memory allocated to the row - } - printf("\n\nRows read: %d\n", reader->rows_read); // Print number of rows read - - free(reader); // Free the memory allocated to the reader - fclose(fp); - - return 0; -} -``` - -#### You can find more examples in the `examples` folder - -Compile with `make ./example_file_name` - - -For full documentation, see the [docs](https://github.com/Ayush-Tripathy/ccsv/tree/main/docs) - -## License -This project is licensed under the MIT License. See the [LICENSE](LICENSE) - -## Feel free to contribute! diff --git a/lib/ccsv/docs/ccsv.pdf b/lib/ccsv/docs/ccsv.pdf deleted file mode 100644 index 4c68ac6..0000000 Binary files a/lib/ccsv/docs/ccsv.pdf and /dev/null differ diff --git a/lib/ccsv/examples/count_rf.c b/lib/ccsv/examples/count_rf.c deleted file mode 100644 index a2f30c7..0000000 --- a/lib/ccsv/examples/count_rf.c +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include - -#include "ccsv.h" - -int main(int argc, char *argv[]) -{ - clock_t start = clock(); - - if (argc != 2) - { - fprintf(stderr, "Usage: %s \n", argv[0]); - return 1; - } - - char *filename = argv[1]; - - ccsv_reader_options options = {.skip_initial_space = 1, .skip_empty_lines = 0}; - - ccsv_reader *reader = ccsv_open(filename, CCSV_READER, "r", &options, NULL); - if (reader == NULL || ccsv_is_error(reader, NULL)) - { - fprintf(stderr, "Error initializing CSV reader\n"); - return 1; - } - - ccsv_row *row; - - size_t fields_count = 0; - while ((row = ccsv_next(reader)) != NULL) - { - fields_count += row->fields_count; - ccsv_free_row(row); - } - - printf("%s: %d rows, %ld fields\n", argv[1], reader->rows_read, fields_count); - - ccsv_close(reader); - - clock_t end = clock(); - double time_spent = (double)(end - start) / CLOCKS_PER_SEC; - printf("Time taken: %lf seconds\n", time_spent); - - return 0; -} diff --git a/lib/ccsv/examples/cpy.c b/lib/ccsv/examples/cpy.c deleted file mode 100644 index 856f1f6..0000000 --- a/lib/ccsv/examples/cpy.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include - -#include "ccsv.h" - -int main(int argc, char *argv[]) -{ - clock_t start = clock(); - - if (argc != 2) - { - fprintf(stderr, "Usage: %s \n", argv[0]); - return 1; - } - - char *filename = argv[1]; - - ccsv_reader *reader = ccsv_init_reader(NULL, NULL); - if (reader == NULL || reader == (void *)CCSV_ERNOMEM) - { - fprintf(stderr, "Error initializing CSV reader\n"); - return 1; - } - - FILE *file = fopen(filename, "r"); - if (file == NULL) - { - fprintf(stderr, "Error opening file\n"); - free(reader); - return 1; - } - - FILE *output = fopen("output.csv", "w+"); - if (output == NULL) - { - fprintf(stderr, "Error opening file\n"); - free(reader); - fclose(file); - return 1; - } - - ccsv_writer *writer = ccsv_init_writer(NULL, NULL); - - ccsv_row *row; - - size_t fields_count = 0; - while ((row = read_row(file, reader)) != NULL) - { - fields_count += row->fields_count; - write_row(output, writer, *row); - ccsv_free_row(row); - } - - printf("%s - %d rows, %ld fields\n", argv[1], reader->rows_read, fields_count); - printf("Output written to output.csv\n"); - - fclose(file); - fclose(output); - free(reader); - free(writer); - - clock_t end = clock(); - double time_spent = (double)(end - start) / CLOCKS_PER_SEC; - printf("Time taken: %lf seconds\n", time_spent); - - return 0; -} diff --git a/lib/ccsv/examples/cpy_new.c b/lib/ccsv/examples/cpy_new.c deleted file mode 100644 index a4b0b68..0000000 --- a/lib/ccsv/examples/cpy_new.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include - -#include "ccsv.h" - -int main(int argc, char **argv) -{ - clock_t start = clock(); - - if (argc != 3) - { - fprintf(stderr, "Usage: %s \n", argv[0]); - return 1; - } - - char *source = argv[1]; - char *destination = argv[2]; - - ccsv_reader *reader = ccsv_open(source, CCSV_READER, "r", NULL, NULL); - if (reader == NULL) - { - fprintf(stderr, "Error initializing CSV reader\n"); - return 1; - } - - ccsv_writer *writer = ccsv_open(destination, CCSV_WRITER, "w+", NULL, NULL); - if (writer == NULL) - { - fprintf(stderr, "Error initializing CSV writer\n"); - return 1; - } - - ccsv_row *row; - while ((row = ccsv_next(reader)) != NULL) - { - ccsv_write(writer, *row); - ccsv_free_row(row); - } - - printf("Rows read: %d\n", reader->rows_read); - - printf("CSV file written to %s\n", destination); - - ccsv_close(reader); - ccsv_close(writer); - - clock_t end = clock(); - double time_spent = (double)(end - start) / CLOCKS_PER_SEC; - printf("Time taken: %lf seconds\n", time_spent); - - return 0; -} \ No newline at end of file diff --git a/lib/ccsv/examples/handling_memory_allocation_failure.c b/lib/ccsv/examples/handling_memory_allocation_failure.c deleted file mode 100644 index fe5ea0b..0000000 --- a/lib/ccsv/examples/handling_memory_allocation_failure.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include - -#include "../include/ccsv.h" - -int main(void) -{ - FILE *csv_file = fopen("../../ign.csv", "r"); - if (csv_file == NULL) - { - perror("Error opening file"); - return 1; - } - - ccsv_reader_options options = { - .delim = ',', // Example delimiter, change according to your CSV file - .quote_char = '"', - .skip_initial_space = 0, - // Add other options if necessary - }; - - ccsv_reader *reader = ccsv_init_reader(&options, NULL); - if (reader == NULL || ccsv_is_error(reader, NULL)) - { - fprintf(stderr, "Error initializing CSV reader\n"); - fclose(csv_file); - return 1; - } - - ccsv_row *row; - short err_status; - while (1) - { - row = read_row(csv_file, reader); - if (row == NULL && ccsv_is_error(reader, &err_status)) - { - if (err_status == CCSV_ERNOMEM) - fprintf(stderr, "Memory allocation failure while reading row\n"); - break; - } - - int fields_count = row->fields_count; - for (int i = 0; i < fields_count; ++i) - { - printf("%s\t", row->fields[i]); - } - printf("\n"); - - ccsv_free_row(row); - } - printf("\n\nRows read: %d\n", reader->rows_read); - - fclose(csv_file); - free(reader); - - return 0; -} diff --git a/lib/ccsv/examples/makefile b/lib/ccsv/examples/makefile deleted file mode 100644 index ab2471e..0000000 --- a/lib/ccsv/examples/makefile +++ /dev/null @@ -1,8 +0,0 @@ -CC = gcc -CFLAGS = -Wall -Wextra -std=c99 -I../include - -%: %.c - $(CC) $(CFLAGS) -o $@.out $< ../src/ccsv.c - -clean: - rm -f *.out diff --git a/lib/ccsv/examples/print_each_row.c b/lib/ccsv/examples/print_each_row.c deleted file mode 100644 index e2d7b4e..0000000 --- a/lib/ccsv/examples/print_each_row.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -#include "../include/ccsv.h" - -int main(void) -{ - - // ** There is new way to read rows in ccsv v0.5.0 ** - // ** Check examples/print_each_row_ccsv_v0.5.c ** - - FILE *fp = fopen("../../ign.csv", "r"); // Specify the path to your file - - if (fp == NULL) - { - printf("Error opening file\n"); - exit(1); - } - - // Reader object - ccsv_reader *reader = ccsv_init_reader(NULL, NULL); // NULL for default options - /* - Default options: - delim = ',' - quote_char = '"' - skip_initial_space = 0 - skip_empty_lines = 0 - skip_comments = 0 - */ - - ccsv_row *row; - - // Read each row and print each field - while ((row = read_row(fp, reader)) != NULL) - { - int row_len = row->fields_count; // Get number of fields in the row - for (int i = 0; i < row_len; i++) - { - printf("%d.Field: %s\n", i + 1, row->fields[i]); // Print each field - } - printf("\n"); - ccsv_free_row(row); // Free the memory allocated to the row - } - printf("\n\nRows read: %d\n", reader->rows_read); // Print number of rows read - - free(reader); // Free the memory allocated to the reader - fclose(fp); - - return 0; -} \ No newline at end of file diff --git a/lib/ccsv/examples/print_each_row_ccsv_v0.5.c b/lib/ccsv/examples/print_each_row_ccsv_v0.5.c deleted file mode 100644 index 539d678..0000000 --- a/lib/ccsv/examples/print_each_row_ccsv_v0.5.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - -#include "../include/ccsv.h" - -int main(void) -{ - ccsv_reader_options options = { - .delim = ',', - .quote_char = '"', - .skip_comments = 1, - .skip_initial_space = 0, - .skip_empty_lines = 0, - }; - // Reader object - ccsv_reader *reader = ccsv_open("../../comments.csv", CCSV_READER, "r", &options, NULL); // NULL for default options - if (reader == NULL) - { - fprintf(stderr, "Error initializing CSV reader\n"); - return 1; - } - - ccsv_row *row; - - // Read each row and print each field - while ((row = ccsv_next(reader)) != NULL) - { - int row_len = row->fields_count; // Get number of fields in the row - for (int i = 0; i < row_len; i++) - { - printf("%d.Field: %s\n", i + 1, row->fields[i]); // Print each field - } - printf("\n"); - ccsv_free_row(row); // Free the memory allocated to the row - } - printf("\n\nRows read: %d\n", reader->rows_read); // Print number of rows read - - ccsv_close(reader); // Close the reader - - return 0; -} \ No newline at end of file diff --git a/lib/ccsv/examples/print_headers.c b/lib/ccsv/examples/print_headers.c deleted file mode 100644 index 927c41d..0000000 --- a/lib/ccsv/examples/print_headers.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include - -#include "../include/ccsv.h" - -int main(void) -{ - FILE *fp = fopen("../../ign.csv", "r"); // Specify the path to your file - - if (fp == NULL) - { - printf("Error opening file\n"); - exit(1); - } - - // ** There is new way to read rows in ccsv v0.5.0 ** - // ** Check examples/print_each_row_ccsv_v0.5.c ** - - // Reader object - ccsv_reader *reader = ccsv_init_reader(NULL, NULL); // NULL for default options - - ccsv_row *row = read_row(fp, reader); - - int row_len = row->fields_count; // Get number of fields in the row - for (int i = 0; i < row_len; i++) - { - printf("%d.Field: %s\n", i + 1, row->fields[i]); // Print each field - } - - ccsv_free_row(row); // Free the memory allocated to the row - free(reader); // Free the memory allocated to the reader - fclose(fp); - - return 0; -} \ No newline at end of file diff --git a/lib/ccsv/examples/with_reader_options.c b/lib/ccsv/examples/with_reader_options.c deleted file mode 100644 index 223c204..0000000 --- a/lib/ccsv/examples/with_reader_options.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include - -#include "../include/ccsv.h" - -int main(void) -{ - FILE *fp = fopen("../../ign.csv", "r"); // Specify the path to your file - - if (fp == NULL) - { - printf("Error opening file\n"); - exit(1); - } - - /* - ------- Way 1 ------- - ccsv_reader_options *options = (ccsv_reader_options *)malloc(sizeof(ccsv_reader_options)); - options->delim = ','; - options->quote_char = '"'; - options->skip_initial_space = 0; - */ - - /* OR */ - - ccsv_reader_options options = { - .delim = ',', - .quote_char = '"', - .skip_initial_space = 0, - .skip_empty_lines = 1, - .skip_comments = 1}; - - // Reader object - ccsv_reader *reader = ccsv_init_reader(&options, NULL); // NULL for default options - // free(options); /* If you used Way 1 */ - - ccsv_row *row; - - // Read each row and print each field - while ((row = read_row(fp, reader)) != NULL) - { - int row_len = row->fields_count; // Get number of fields in the row - for (int i = 0; i < row_len; i++) - { - printf("%s\t", row->fields[i]); // Print each field - } - printf("\n"); - ccsv_free_row(row); // Free the memory allocated to the row - } - printf("\n\nRows read: %d\n", reader->rows_read); // Print number of rows read - - free(reader); // Free the memory allocated to the reader - fclose(fp); - - return 0; -} \ No newline at end of file diff --git a/lib/ccsv/examples/writer_macros.c b/lib/ccsv/examples/writer_macros.c deleted file mode 100644 index 620844a..0000000 --- a/lib/ccsv/examples/writer_macros.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -#include "ccsv.h" - -int main(void) -{ - // Initialize ccsv_writer_options - ccsv_writer_options options = { - .delim = ',', - .quote_char = '"' - // Add other options if necessary - }; - - // Initialize the writer - ccsv_writer *writer = ccsv_init_writer(&options, NULL); - if (writer == NULL) - { - fprintf(stderr, "Error initializing CSV writer\n"); - return 1; - } - - FILE *file = fopen("output.csv", "w+"); - if (file == NULL) - { - fprintf(stderr, "Error opening file\n"); - free(writer); - return 1; - } - - CCSV_WRITE_ROW_START(file, writer); // Write row start - CCSV_WRITE_FIELD(file, writer, "hi"); // Write field - CCSV_WRITE_FIELD(file, writer, "hello, world!"); // Write field - CCSV_WRITE_FIELD(file, writer, "\"escapedword\""); // Write field - CCSV_WRITE_ROW_END(file, writer, NULL); // Write row end - - short err_status; - if (ccsv_is_error(writer, &err_status)) - { - fprintf(stderr, "Error writing CSV row from string: %s\n", ccsv_get_status_message(err_status)); - fclose(file); - free(writer); - return 1; - } - - fclose(file); - free(writer); - - return 0; -} diff --git a/lib/ccsv/examples/writing_from_CSVRow_struct.c b/lib/ccsv/examples/writing_from_CSVRow_struct.c deleted file mode 100644 index 725fa65..0000000 --- a/lib/ccsv/examples/writing_from_CSVRow_struct.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include - -#include "ccsv.h" - -int main(void) -{ - // Initialize ccsv_writer_options - ccsv_writer_options options = { - .delim = ',', - .quote_char = '"' - // Add other options if necessary - }; - - // Initialize the writer - ccsv_writer *writer = ccsv_init_writer(&options, NULL); - if (writer == NULL) - { - fprintf(stderr, "Error initializing CSV writer\n"); - return 1; - } - - ccsv_reader *reader = ccsv_init_reader(NULL, NULL); - - FILE *dest_file = fopen("output.csv", "a+"); - if (dest_file == NULL) - { - fprintf(stderr, "Error opening file\n"); - free(writer); - return 1; - } - FILE *source_file = fopen("../../ign.csv", "r"); - if (source_file == NULL) - { - fprintf(stderr, "Error opening file\n"); - free(writer); - return 1; - } - - ccsv_row *row = read_row(source_file, reader); - write_row(dest_file, writer, *row); // Pass the value of the row pointer - ccsv_free_row(row); // Free the row - - row = read_row(source_file, reader); // Read the next row - write_row(dest_file, writer, *row); // Write row to file - ccsv_free_row(row); // Free the row - - if (ccsv_is_error(writer, NULL)) - { - fprintf(stderr, "Error writing CSV row.\n"); - fclose(dest_file); - fclose(source_file); - free(reader); - free(writer); - return 1; - } - - fclose(dest_file); - fclose(source_file); - free(reader); - free(writer); - - return 0; -} diff --git a/lib/ccsv/examples/writing_from_array.c b/lib/ccsv/examples/writing_from_array.c deleted file mode 100644 index 55f99ad..0000000 --- a/lib/ccsv/examples/writing_from_array.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include "../include/ccsv.h" - -int main(void) -{ - // Initialize ccsv_writer_options - ccsv_writer_options options = { - .delim = ',', - .quote_char = '"' - // Add other options if necessary - }; - - // Initialize the writer - ccsv_writer *writer = ccsv_init_writer(&options, NULL); - if (writer == NULL) - { - fprintf(stderr, "Error initializing CSV writer\n"); - return 1; - } - - FILE *file = fopen("output.csv", "a+"); - if (file == NULL) - { - fprintf(stderr, "Error opening file\n"); - free(writer); - return 1; - } - - char *row_string[] = {"hi", "hello", "hello, world!", "\"escapedword\"", "hola", "bonjour"}; - - write_row_from_array(file, writer, row_string, ARRAY_LEN(row_string)); /* Write row to file */ - - short err_status; - if (ccsv_is_error(writer, &err_status)) - { - fprintf(stderr, "Error writing CSV row from string: %s\n", ccsv_get_status_message(err_status)); - fclose(file); - free(writer); - return 1; - } - - fclose(file); - free(writer); - - return 0; -} diff --git a/lib/ccsv/include/ccsv.h b/lib/ccsv/include/ccsv.h deleted file mode 100644 index 8a5f936..0000000 --- a/lib/ccsv/include/ccsv.h +++ /dev/null @@ -1,442 +0,0 @@ -// File: ccsv.h - -// Created: 2023 by Ayush Tripathy -// github.com/Ayush-Tripathy - -/* - * CCSV - A CSV parser and writer library for C. - * Version: 0.1 - * - * For full documentation, see the README.md file. - */ - -/* - MIT License - - Copyright (c) 2023 Ayush Tripathy - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#include -#include - -#define CCSV_VERSION 0.1f - -#ifdef __cplusplus -extern "C" -{ -#endif - -// File sizes -#define CCSV_LARGE_FILE_SIZE 524288000ULL /* 500 MiB */ -#define CCSV_MED_FILE_SIZE 20971520ULL /* 20 MiB */ - -// Buffer sizes -#define CCSV_HIGH_BUFFER_SIZE 65536 /* 64 KiB */ -#define CCSV_MED_BUFFER_SIZE 16384 /* 16 KiB */ -#define CCSV_LOW_BUFFER_SIZE 2048 /* 2 KiB */ - -#define CCSV_BUFFER_SIZE 8096 -#define MAX_FIELD_SIZE 256 - -// Default values -#define CCSV_DELIMITER 0x2c -#define CCSV_QUOTE_CHAR 0x22 -#define CCSV_CR 0x0d -#define CCSV_LF 0x0a -#define CCSV_SPACE 0x20 -#define CCSV_TAB 0x09 -#define CCSV_COMMENT_CHAR 0x23 -#define CCSV_NULL_CHAR 0x00 - -#define DEFAULT_DELIMITER CCSV_DELIMITER -#define DEFAULT_QUOTE_CHAR CCSV_QUOTE_CHAR -#define DEFAULT_ESCAPE_CHAR CCSV_QUOTE_CHAR -#define DEFAULT_COMMENT_CHAR CCSV_COMMENT_CHAR - -#define TOTAL_ERROR_MESSAGES 7 - -// Return codes -#define CCSV_SUCCESS 0 -#define CCSV_ERROR -1 -#define CCSV_ERNOMEM -2 -#define CCSV_ERINVALID -3 -#define CCSV_ERNULLFP -6 /* File pointer is NULL */ -#define CCSV_ERMODE -7 /* Invalid mode */ -#define CCSV_EROPEN -8 /* Error opening file */ -#define CCSV_ERINVOBJTYPE -9 /* Invalid object type */ -#define CCSV_ERNULLROW -10 /* Row is NULL */ -#define CCSV_ERBUFNTALLOC -11 /* Buffer not allocated */ - -#define WRITE_SUCCESS CCSV_SUCCESS -#define WRITE_STARTED 1 -#define WRITE_ENDED 2 -#define WRITE_ERNOTSTARTED -4 /* Writer not started */ -#define WRITE_ERNOMEM CCSV_ERNOMEM -#define WRITE_ERINVALID CCSV_ERINVALID -#define WRITE_ERALWRITING -5 /* Already writing field */ - -// Object types -#define CCSV_READER 21 -#define CCSV_WRITER 22 - -#define ARRAY_LEN(array) sizeof(array) / sizeof(array[0]) - -// Writer Macros -/* Start new row */ -#define CCSV_WRITE_ROW_START(fp, writer) _write_row_start(fp, writer) - -/* Write field */ -#define CCSV_WRITE_FIELD(fp, writer, string) \ - if (writer->__state == WRITER_ROW_START) \ - { \ - writer->__state = WRITER_WRITING_FIELD; \ - } \ - else \ - { \ - fputc(writer->__delim, fp); \ - } \ - _write_field(fp, writer, string); - -/* End row, with an additional field */ -#define CCSV_WRITE_ROW_END(fp, writer, last_field) \ - if (last_field) \ - { \ - _write_field(fp, writer, last_field); \ - } \ - _write_row_end(fp, writer); - - typedef enum State - { - FIELD_START, /* Start of field */ - FIELD_NOT_STARTED, /* Spaces before field start */ - FIELD_END, /* End of field */ - FIELD_STARTED, /* Inside field */ - INSIDE_QUOTED_FIELD, /* Inside quoted field */ - MAY_BE_ESCAPED /* Quote char detected inside quoted field */ - } State; - - typedef enum WriterState - { - WRITER_NOT_STARTED, /* Writer not started */ - WRITER_ROW_START, /* Writer setup done */ - WRITER_WRITING_FIELD, /* Field writing started */ - WRITER_ROW_END /* Row writing ended */ - } WriterState; - - typedef struct ccsv_reader_options - { - char delim; - char quote_char; - char comment_char; - char escape_char; - int skip_initial_space; - int skip_empty_lines; - int skip_comments; - } ccsv_reader_options; - - typedef struct ccsv_reader - { - int rows_read; - char __delim; - char __quote_char; - char __comment_char; - char __escape_char; - int __skip_initial_space; - int __skip_empty_lines; - int __skip_comments; - char *__buffer; - size_t __buffer_pos; - size_t __buffer_size; - bool __buffer_allocated; - FILE *__fp; - short status; - short object_type; - } ccsv_reader; - - typedef struct ccsv_row - { - char **fields; - int fields_count; - } ccsv_row; - - typedef struct ccsv_writer_options - { - char delim; - char quote_char; - char escape_char; - } ccsv_writer_options; - - typedef struct ccsv_writer - { - char __delim; - char __quote_char; - char __escape_char; - WriterState __state; - FILE *__fp; - short write_status; - short object_type; - } ccsv_writer; - - // Public functions ------------------------------------------------------------------------ - - /* -------- General -------- */ - - /* - * This function opens a file and attaches it with specified object. - * - * returns: - * void*: pointer to the object - */ - void *ccsv_open(const char *filename, short object_type, const char *mode, void *options, short *status); - - /* - * This function closes the ccsv object (reader or writer). - * - * params: - * obj: pointer to the object - */ - void ccsv_close(void *obj); - - /* - * This function returns the status message for the given status code. - * - * params: - * status: status code - * - * returns: - * char*: pointer to the status message - */ - const char *ccsv_get_status_message(short status); - - /* - * This function returns if error occurred in the object. - * - * params: - * obj: pointer to the object - * - * returns: - * int: 1, if error occurred - * int: 0, if no error occurred - */ - int ccsv_is_error(void *obj, short *status); - - /* -------- Reader -------- */ - - /* - * This function initializes the parser with the given parameters, and - * returns a pointer to the parser. - * - * params: - * options: pointer to the reader options struct - * - * returns: - * ccsv_reader*: pointer to the reader - */ - ccsv_reader *ccsv_init_reader(ccsv_reader_options *options, short *status); - - /* - * This function reads a row from the file pointer, and returns a pointer - * to CSVRow struct. - * - * params: - * fp: file pointer - * parser: pointer to the parser - * - * returns: - * CSVRow*: pointer to the CSVRow struct - */ - ccsv_row *read_row(FILE *fp, ccsv_reader *parser); - - /* - * This function reads a row from reader, and returns a pointer - * to CSVRow struct. - * - * params: - * reader: pointer to the reader - * - * returns: - * CSVRow*: pointer to the CSVRow struct - */ - ccsv_row *ccsv_next(ccsv_reader *reader); - - /* - * This function frees the memory allocated to the CSVRow struct. - * - * params: - * row: pointer to the CSVRow struct - */ - void ccsv_free_row(ccsv_row *row); - - /* -------- Writer -------- */ - - /* - * This function initializes the writer with the given parameters, and - * returns a pointer to the writer. - * - * params: - * options: pointer to the writer options struct - * - * returns: - * ccsv_writer*: pointer to the writer - * - */ - ccsv_writer *ccsv_init_writer(ccsv_writer_options *options, short *status); - - /* - * This function writes a row (from CSVRow struct) to the file pointer. - */ - int ccsv_write(ccsv_writer *writer, ccsv_row row); - - /* - * This function writes a row (from string array) to the file pointer. - * - * params: - * writer: pointer to the writer - * row_string: pointer to the row string - * - * returns: - * int: 0, if successful - * CSV_ERNOMEM, if memory allocation failed - */ - int ccsv_write_from_array(ccsv_writer *writer, char **fields, int fields_len); - - /* - * This function writes a row (from CSVRow struct) to the file pointer. - * - * params: - * fp: file pointer - * writer: pointer to the writer - * row: CSVRow struct - */ - int write_row(FILE *fp, ccsv_writer *writer, ccsv_row row); - - /* - *This function writes a row (from string array) to the file pointer. - * - * params: - * fp: file pointer - * writer: pointer to the writer - * row_string: pointer to the row string - * - * returns: - * int: 0, if successful - * CSV_ERNOMEM, if memory allocation failed - */ - int write_row_from_array(FILE *fp, ccsv_writer *writer, char **fields, int row_len); - - // Private functions ----------------------------------------------------------------------- - - /* - * This function returns the object type of the object. - * - * params: - * obj: pointer to the object - * - * returns: - * int: object type - */ - int _get_object_type(void *obj); - - /* - * This function reads a row from the file pointer, and returns a pointer to CSVRow struct. - * - * params: - * fp: file pointer - * reader: pointer to the reader - * - * returns: - * CSVRow*: pointer to the CSVRow struct - */ - ccsv_row *_read_row(FILE *fp, ccsv_reader *reader); - - /* - * This function reads a row from the file pointer, and returns a pointer to CSVRow struct. - * - * params: - * fp: file pointer - * reader: pointer to the reader - * - * returns: - * CSVRow*: pointer to the CSVRow struct - */ - ccsv_row *_next(FILE *fp, ccsv_reader *reader); - - /* - * This functions checks if the reader buffer is empty. - */ - int _is_buffer_empty(ccsv_reader *reader); - - /* - *This function frees multiple pointers. - * - * params: - * num: number of pointers to free - * ...: pointers to free - * - */ - void _free_multiple(int num, ...); - - /* - * This function writes a field to the file pointer. - * - * params: - * fp: file pointer - * writer: pointer to the writer - * string: pointer to the string - * string_len: length of the string - * string_pos: pointer to the position of the string - * - * returns: - * size_t: number of characters written - */ - int _write_field(FILE *fp, ccsv_writer *writer, const char *string); - - /* - *This function writes a row start to the file pointer. - * - * params: - * fp: file pointer - * writer: pointer to the writer - * - * returns: - * int: WRITE_STARTED, if successful - * int: WRITE_ERALWRITING, if already writing field - */ - int _write_row_start(FILE *fp, ccsv_writer *writer); - - /* - * This function writes a row end to the file pointer. - * - * params: - * fp: file pointer - * writer: pointer to the writer - * - * returns: - * int: WRITE_ENDED, if successful - * int: WRITE_ERNOTSTARTED, if writer not started - */ - int _write_row_end(FILE *fp, ccsv_writer *writer); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/lib/ccsv/src/ccsv.c b/lib/ccsv/src/ccsv.c deleted file mode 100644 index 505a01e..0000000 --- a/lib/ccsv/src/ccsv.c +++ /dev/null @@ -1,1179 +0,0 @@ -// File: ccsv.c - -// Created: 2023 by Ayush Tripathy -// github.com/Ayush-Tripathy - -/* - * This library provides functions to handle reading, writing csv files. - */ - -/* - MIT License - - Copyright (c) 2023 Ayush Tripathy - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -// ccsv header file -#include "ccsv.h" - - const char *status_messages[] = { - "Success", - "Error", - "Memory allocation failure.", - "Malformed CSV file.", - "Not started writing, CSV_WRITE_ROW_START() not called.", - "Already writing field, CSV_WRITE_ROW_START() already called."}; - - const char *ccsv_get_status_message(short status) - { - if (status > 0) - return status_messages[0]; - - if (status < -5) - return NULL; - return status_messages[-1 * status]; - } - - int _get_object_type(void *obj) - { - if (obj == NULL) - return CCSV_NULL_CHAR; - - if (((ccsv_reader *)obj)->object_type == CCSV_READER) - return CCSV_READER; - - if (((ccsv_writer *)obj)->object_type == CCSV_WRITER) - return CCSV_WRITER; - - return CCSV_NULL_CHAR; - } - - int ccsv_is_error(void *obj, short *status) - { - if (obj == NULL) - return 0; - - if (_get_object_type(obj) == CCSV_READER) - { - short __status = ((ccsv_reader *)obj)->status; - if (status != NULL) - *status = __status; - return __status < 0; - } - - if (_get_object_type(obj) == CCSV_WRITER) - { - short __status = ((ccsv_writer *)obj)->write_status; - if (status != NULL) - *status = __status; - return __status < 0; - } - - return 0; - } - -/* Reader */ - -// These macros should be used only in read_row() function -#define ADD_FIELD(field) \ - field[field_pos++] = CCSV_NULL_CHAR; \ - fields_count++; \ - fields = (char **)realloc(fields, sizeof(char *) * fields_count); \ - if (fields == NULL) \ - { \ - _free_multiple(3, field, row_string, row); \ - reader->status = CCSV_ERNOMEM; \ - return NULL; \ - } \ - fields[fields_count - 1] = field; - -#define GROW_FIELD_BUFFER_IF_NEEDED(field, field_size, field_pos) \ - if (field_pos > field_size - 1) \ - { \ - field_size += MAX_FIELD_SIZE; \ - field = (char *)realloc(field, field_size + 1); \ - if (field == NULL) \ - { \ - _free_multiple(3, fields, row_string, row); \ - reader->status = CCSV_ERNOMEM; \ - return NULL; \ - } \ - } - -#define GROW_ROW_BUFFER_IF_NEEDED(row_string, row_len, row_pos) \ - if (row_pos > row_len - 1) \ - { \ - row_string_size += reader->__buffer_size; \ - row_string = (char *)realloc(row_string, row_string_size + 1); \ - if (row_string == NULL) \ - { \ - _free_multiple(2, fields, row); \ - reader->status = CCSV_ERNOMEM; \ - return NULL; \ - } \ - } - -#define RETURN_IF_WRITE_ERROR(writer, desired_status) \ - if (writer->write_status != desired_status) \ - return writer->write_status; - - ccsv_reader *ccsv_init_reader(ccsv_reader_options *options, short *status) - { - char delim, quote_char, comment_char, escape_char; - int skip_initial_space, skip_empty_lines, skip_comments; - if (options == NULL) - { - delim = DEFAULT_DELIMITER; - quote_char = DEFAULT_QUOTE_CHAR; - comment_char = DEFAULT_COMMENT_CHAR; - escape_char = DEFAULT_ESCAPE_CHAR; - skip_initial_space = 0; - skip_empty_lines = 0; - skip_comments = 0; - } - else - { - // It is not mandatory to pass all options to options struct - // So check if the option is passed or not, if not then use the default value - if (options->delim == CCSV_NULL_CHAR) - delim = DEFAULT_DELIMITER; - - else - delim = options->delim; - - if (options->quote_char == CCSV_NULL_CHAR) - quote_char = DEFAULT_QUOTE_CHAR; - - else - quote_char = options->quote_char; - - if (options->comment_char == CCSV_NULL_CHAR) - comment_char = DEFAULT_COMMENT_CHAR; - - else - comment_char = options->comment_char; - - if (options->escape_char == CCSV_NULL_CHAR) - escape_char = DEFAULT_ESCAPE_CHAR; - - else - escape_char = options->escape_char; - - if (options->skip_initial_space == CCSV_NULL_CHAR) - skip_initial_space = 0; - - else - skip_initial_space = options->skip_initial_space; - - if (options->skip_empty_lines == CCSV_NULL_CHAR) - skip_empty_lines = 0; - - else - skip_empty_lines = options->skip_empty_lines; - - if (options->skip_comments == CCSV_NULL_CHAR) - skip_comments = 0; - - else - skip_comments = options->skip_comments; - } - - // Parser - ccsv_reader *parser = (ccsv_reader *)malloc(sizeof(ccsv_reader)); - if (parser == NULL) - { - if (status != NULL) - *status = CCSV_ERNOMEM; - return NULL; - } - parser->__delim = delim; - parser->__quote_char = quote_char; - parser->__comment_char = comment_char; - parser->__escape_char = escape_char; - parser->__skip_initial_space = skip_initial_space; - parser->__skip_empty_lines = skip_empty_lines; - parser->__skip_comments = skip_comments; - - parser->__fp = NULL; - - parser->rows_read = 0; - parser->status = CCSV_SUCCESS; - parser->object_type = CCSV_READER; - - return parser; - } - - void ccsv_free_row(ccsv_row *row) - { - const int fields_count = row->fields_count; - for (int i = 0; i < fields_count; i++) - { - free(row->fields[i]); - } - free(row->fields); - free(row); - } - - void _free_multiple(int num, ...) - { - va_list args; - va_start(args, num); - - for (int i = 0; i < num; ++i) - { - void *ptr = va_arg(args, void *); - free(ptr); - } - - va_end(args); - } - - void *ccsv_open(const char *filename, short object_type, const char *mode, void *options, short *status) - { - if (filename == NULL) - return NULL; - - if (object_type != CCSV_READER && object_type != CCSV_WRITER) - { - if (status != NULL) - *status = CCSV_ERINVOBJTYPE; - return NULL; - } - - if (strcmp(mode, "r") != 0 && - strcmp(mode, "rb") != 0 && - strcmp(mode, "r+") != 0 && - strcmp(mode, "rb+") != 0 && - strcmp(mode, "w+") != 0 && - strcmp(mode, "a+") != 0) - { - if (status != NULL) - *status = CCSV_ERMODE; - return NULL; - } - - if (object_type == CCSV_READER) - { - short init_status; - -#ifdef __cplusplus - ccsv_reader_options *reader_options = reinterpret_cast(options); - ccsv_reader *reader = ccsv_init_reader(reader_options, &init_status); -#else - options = (ccsv_reader_options *)options; - ccsv_reader *reader = ccsv_init_reader(options, &init_status); -#endif - - if (init_status == CCSV_ERNOMEM || reader == NULL) - { - if (status != NULL) - *status = CCSV_ERNOMEM; - return NULL; - } - FILE *fp = fopen(filename, mode); - if (fp == NULL) - { - if (status != NULL) - *status = CCSV_EROPEN; - return NULL; - } - - if (!reader->__buffer_allocated) - { - size_t buffer_size = CCSV_BUFFER_SIZE; - - size_t file_size; - - fseek(fp, 0, SEEK_END); - file_size = ftell(fp); - fseek(fp, 0, SEEK_SET); - - if (file_size >= CCSV_LARGE_FILE_SIZE) - buffer_size = CCSV_HIGH_BUFFER_SIZE; - else if (file_size >= CCSV_MED_FILE_SIZE) - buffer_size = CCSV_MED_BUFFER_SIZE; - else - buffer_size = CCSV_LOW_BUFFER_SIZE; - - reader->__buffer = (char *)malloc(buffer_size + 1); - if (reader->__buffer == NULL) - { - free(reader); - if (status != NULL) - *status = CCSV_ERNOMEM; - return NULL; - } - reader->__buffer[0] = CCSV_NULL_CHAR; - - reader->__buffer_size = buffer_size; - reader->__buffer_allocated = true; - } - reader->__fp = fp; - reader->object_type = object_type; - - return reader; - } - else if (object_type == CCSV_WRITER) - { - FILE *fp = fopen(filename, mode); - if (fp == NULL) - { - if (status != NULL) - *status = CCSV_EROPEN; - return NULL; - } - - short init_status; - -#ifdef __cplusplus - ccsv_writer_options *writer_options = reinterpret_cast(options); - ccsv_writer *writer = ccsv_init_writer(writer_options, &init_status); -#else - options = (ccsv_writer_options *)options; - ccsv_writer *writer = ccsv_init_writer(options, &init_status); -#endif - if (init_status == CCSV_ERNOMEM || writer == NULL) - { - if (status != NULL) - *status = CCSV_ERNOMEM; - return NULL; - } - writer->__fp = fp; - writer->object_type = object_type; - - return writer; - } - return NULL; - } - - void ccsv_close(void *obj) - { - if (obj == NULL) - return; - - if (_get_object_type(obj) == CCSV_READER) - { - ccsv_reader *reader = (ccsv_reader *)obj; - fclose(reader->__fp); - free(reader); - } - else if (_get_object_type(obj) == CCSV_WRITER) - { - ccsv_writer *writer = (ccsv_writer *)obj; - fclose(writer->__fp); - free(writer); - } - else - { - return; - } - } - - ccsv_row *ccsv_next(ccsv_reader *reader) - { - if (reader == NULL) - return NULL; - - if (reader->__buffer == NULL) - { - reader->status = CCSV_ERBUFNTALLOC; - return NULL; - } - - if (reader->__fp == NULL) - { - reader->status = CCSV_ERNULLFP; - return NULL; - } - - return _next(reader->__fp, reader); - } - - ccsv_row *read_row(FILE *fp, ccsv_reader *reader) - { - if (fp == NULL) - { - reader->status = CCSV_ERNULLFP; - return NULL; - } - return _read_row(fp, reader); - } - - ccsv_row *_read_row(FILE *fp, ccsv_reader *reader) - { - ccsv_row *row = (ccsv_row *)malloc(sizeof(ccsv_row)); - if (row == NULL) - { - reader->status = CCSV_ERNOMEM; - return NULL; - } - - const char DELIM = reader->__delim; - const char QUOTE_CHAR = reader->__quote_char; - const char COMMENT_CHAR = reader->__comment_char; - const int SKIP_INITIAL_SPACE = reader->__skip_initial_space; - const int SKIP_EMPTY_LINES = reader->__skip_empty_lines; - const int SKIP_COMMENTS = reader->__skip_comments; - - State state = FIELD_START; - - char *row_string = (char *)malloc(CCSV_BUFFER_SIZE + 1); - if (row_string == NULL) - { - _free_multiple(1, row); - reader->status = CCSV_ERNOMEM; - return NULL; - } - size_t row_string_size = CCSV_BUFFER_SIZE; - size_t row_pos = 0; - - char **fields = (char **)malloc(sizeof(char *)); - if (fields == NULL) - { - _free_multiple(2, row_string, row); - reader->status = CCSV_ERNOMEM; - return NULL; - } - size_t fields_count = 0; - - char *field = (char *)malloc(MAX_FIELD_SIZE + 1); - if (field == NULL) - { - _free_multiple(3, row_string, fields, row); - reader->status = CCSV_ERNOMEM; - return NULL; - } - size_t field_size = MAX_FIELD_SIZE; - size_t field_pos = 0; - - int inside_quotes = 0; - - size_t row_len; - - readfile: - if (fgets(row_string, CCSV_BUFFER_SIZE, fp) == NULL) - { - /* If fields is not empty then return the row */ - if (fields_count > 0 || field_pos > 0) - { - /* Add the last field */ - - /* - * If fields_count > 0: - * This happens when the function holding the values of last row - * but yet to return the last row - * - * if field_pos > 0: - * This only happens when there is a single element in the last row and also - * there is no line after the current line - * So we need to add the only field of the last row - */ - ADD_FIELD(field); - goto end; - } - - _free_multiple(4, row_string, field, fields, row); - return NULL; - } - - row_len = strlen(row_string); - row_pos = 0; - - while (1) - { - char c = row_string[row_pos]; - switch (state) - { - case FIELD_START: - if (c == QUOTE_CHAR) - { - /* Start of quoted field */ - state = INSIDE_QUOTED_FIELD; - } - else if (SKIP_INITIAL_SPACE && c == CCSV_SPACE) - { - /* Skip initial spaces */ - state = FIELD_NOT_STARTED; - } - else if (c == DELIM || c == CCSV_CR || c == CCSV_LF) - { - /* Return empty field or empty row */ - state = FIELD_END; - row_pos--; - } - else - { - state = FIELD_STARTED; - field[field_pos++] = c; - } - break; - - case INSIDE_QUOTED_FIELD: - inside_quotes = 1; - if (c == QUOTE_CHAR) - { - /* Might be the end of the field, or it might be a escaped quote */ - state = MAY_BE_ESCAPED; - } - else - { - state = FIELD_STARTED; - field[field_pos++] = c; - } - break; - - case FIELD_NOT_STARTED: - if (c == QUOTE_CHAR) - { - /* Start of quoted field */ - state = INSIDE_QUOTED_FIELD; - } - else if (c == DELIM) - { - /* Return empty field */ - row_pos--; - state = FIELD_END; - } - else if (c == CCSV_SPACE) - { - /* - * Skip initial spaces, will only get to this point if - * skip_initial_spaces = 1 - */ - state = FIELD_NOT_STARTED; - } - else - { - /* Start of non-quoted field */ - state = FIELD_STARTED; - field[field_pos++] = c; - } - break; - - case FIELD_STARTED: - GROW_FIELD_BUFFER_IF_NEEDED(field, field_size, field_pos); - GROW_ROW_BUFFER_IF_NEEDED(row_string, row_len, row_pos); - - if (c == QUOTE_CHAR && inside_quotes) - { - /* Might be the end of the field, or it might be a escaped quote */ - state = MAY_BE_ESCAPED; - } - else if (c == QUOTE_CHAR && !inside_quotes) - { - /* Add the quote char if not at the start of field */ - state = FIELD_STARTED; - field[field_pos++] = c; - } - else if ((c == DELIM && !inside_quotes) || - ((c == CCSV_LF || c == CCSV_CR) && !inside_quotes) || - (c == CCSV_NULL_CHAR)) - { - /* End of field */ - state = FIELD_END; - row_pos--; - } - else - { - /* Add the character to the field */ - state = FIELD_STARTED; - field[field_pos++] = c; - } - break; - - case MAY_BE_ESCAPED: - if (c == QUOTE_CHAR) - { - /* Escaped quote */ - state = FIELD_STARTED; - field[field_pos++] = c; - } - else - { - /* End of field */ - inside_quotes = 0; - state = FIELD_STARTED; - row_pos--; - } - - break; - - case FIELD_END: - state = FIELD_START; - if (SKIP_EMPTY_LINES && - fields_count == 0 && - field_pos == 0 && - (c == CCSV_CR || c == CCSV_LF || c == CCSV_NULL_CHAR) && - !inside_quotes) - { - /* Do not return empty lines, parse again */ - goto readfile; - } - else if (SKIP_COMMENTS && - fields_count == 0 && - field_pos > 0 && - field[0] == COMMENT_CHAR && - !inside_quotes) - { - /* Do not return comment lines, parse again */ - field_pos = 0; - goto readfile; - } - else - { - ADD_FIELD(field); - } - field = (char *)malloc(MAX_FIELD_SIZE + 1); - field_size = MAX_FIELD_SIZE; - if (field == NULL) - { - _free_multiple(3, fields, row_string, row); - reader->status = CCSV_ERNOMEM; - return NULL; - } - field_pos = 0; - - if (c == CCSV_CR || c == CCSV_LF || c == CCSV_NULL_CHAR) - { - free(field); - goto end; - } - break; - - default: - break; - } - - row_pos++; - - if (row_pos > row_len - 1) - { - goto readfile; - } - } - - end: - row->fields = fields; - row->fields_count = fields_count; - free(row_string); - - reader->rows_read++; - reader->status = CCSV_SUCCESS; - return row; - } - -#define IS_TERMINATOR(c) (c == CCSV_CR || c == CCSV_LF || c == CCSV_NULL_CHAR) - - ccsv_row *_next(FILE *fp, ccsv_reader *reader) - { - ccsv_row *row = (ccsv_row *)malloc(sizeof(ccsv_row)); - if (row == NULL) - { - reader->status = CCSV_ERNOMEM; - return NULL; - } - - const char DELIM = reader->__delim; - const char QUOTE_CHAR = reader->__quote_char; - const char COMMENT_CHAR = reader->__comment_char; - const char ESCAPE_CHAR = reader->__escape_char; - const int SKIP_INITIAL_SPACE = reader->__skip_initial_space; - const int SKIP_EMPTY_LINES = reader->__skip_empty_lines; - const int SKIP_COMMENTS = reader->__skip_comments; - - size_t buffer_size = reader->__buffer_size; - - State state = FIELD_START; - - char *row_string = reader->__buffer; - size_t row_pos = 0; - - char **fields = (char **)malloc(sizeof(char *)); - if (fields == NULL) - { - _free_multiple(2, row_string, row); - reader->status = CCSV_ERNOMEM; - return NULL; - } - - size_t fields_count = 0; - - char *field = (char *)malloc(MAX_FIELD_SIZE + 1); - if (field == NULL) - { - _free_multiple(3, row_string, fields, row); - reader->status = CCSV_ERNOMEM; - return NULL; - } - - size_t field_size = MAX_FIELD_SIZE; - size_t field_pos = 0; - - size_t bytes_read; - readfile: - - /* Checking buffer */ - if (_is_buffer_empty(reader)) - { - bytes_read = fread(reader->__buffer, sizeof(char), buffer_size, fp); - - if (bytes_read <= 0) - { - if (fields_count > 0 || field_pos > 0) - { - /* Add the last field */ - - /* - * If fields_count > 0: - * This happens when the function holding the values of last row - * but yet to return the last row - * - * if field_pos > 0: - * This only happens when there is a single element in the last row and also - * there is no line after the current line - * So we need to add the only field of the last row - */ - ADD_FIELD(field); - goto end; - } - - _free_multiple(4, row_string, field, fields, row); - return NULL; - } - - reader->__buffer[bytes_read] = CCSV_NULL_CHAR; - reader->__buffer_size = bytes_read; - reader->__buffer_pos = 0; - row_pos = 0; - row_string = reader->__buffer; - - if (IS_TERMINATOR(row_string[row_pos]) && state == FIELD_START) - row_pos++; - } - else - { - row_string = reader->__buffer; - bytes_read = reader->__buffer_size; - row_pos = reader->__buffer_pos; - } - - for (; row_pos < bytes_read;) - { - char c = row_string[row_pos++]; - - switch (state) - { - case FIELD_START: - if (c == QUOTE_CHAR) - state = INSIDE_QUOTED_FIELD; /* Start of quoted field */ - else if (SKIP_INITIAL_SPACE && c == CCSV_SPACE) - state = FIELD_NOT_STARTED; /* Skip initial spaces */ - else if (c == DELIM || IS_TERMINATOR(c)) - { - state = FIELD_END; /* Empty field or empty row */ - row_pos--; - } - else - { - state = FIELD_STARTED; - field[field_pos++] = c; - } - break; - - case INSIDE_QUOTED_FIELD: - GROW_FIELD_BUFFER_IF_NEEDED(field, field_size, field_pos); - if (c == QUOTE_CHAR) - state = MAY_BE_ESCAPED; /* Might be the end of the field, or it might be a escaped quote */ - else if (c == ESCAPE_CHAR) - { - field[field_pos++] = c; /* Escaped escape character */ - row_pos++; - } - else - field[field_pos++] = c; - - break; - - case MAY_BE_ESCAPED: - if (c == QUOTE_CHAR) - { - state = INSIDE_QUOTED_FIELD; /* Escaped quote */ - field[field_pos++] = c; - } - else if (c == DELIM || IS_TERMINATOR(c)) - { - state = FIELD_END; /* End of field */ - row_pos--; - } - else - { - state = FIELD_STARTED; - field[field_pos++] = c; - } - - break; - - case FIELD_NOT_STARTED: - if (c == QUOTE_CHAR) - state = INSIDE_QUOTED_FIELD; /* Start of quoted field */ - else if (c == DELIM) - { - state = FIELD_END; /* Return empty field */ - row_pos--; - } - else if (c == CCSV_SPACE) - state = FIELD_NOT_STARTED; /* Skip initial spaces, will only get to this point if skip_initial_spaces = 1 */ - else - { - state = FIELD_STARTED; - field[field_pos++] = c; /* Start of non-quoted field */ - } - break; - - case FIELD_STARTED: - GROW_FIELD_BUFFER_IF_NEEDED(field, field_size, field_pos); - - if (c == DELIM || IS_TERMINATOR(c)) - { - state = FIELD_END; /* End of field */ - row_pos--; - } - else - field[field_pos++] = c; /* Add the character to the field */ - break; - - case FIELD_END: - state = FIELD_START; - - if (SKIP_EMPTY_LINES && - fields_count == 0 && - field_pos == 0 && - IS_TERMINATOR(c)) - { - /* Do not return empty lines, parse again */ - reader->__buffer_pos = row_pos; - goto readfile; - } - else if (SKIP_COMMENTS && - fields_count == 0 && - field_pos > 0 && - field[0] == COMMENT_CHAR) - { - /* Do not return comment lines, parse again */ - field_pos = 0; - reader->__buffer_pos = row_pos + 1; - goto readfile; - } - else - { - ADD_FIELD(field); - } - - field = (char *)malloc(MAX_FIELD_SIZE + 1); - field_size = MAX_FIELD_SIZE; - if (field == NULL) - { - _free_multiple(3, fields, row_string, row); - reader->status = CCSV_ERNOMEM; - return NULL; - } - field_pos = 0; - - if (IS_TERMINATOR(c)) /* CR or LF */ - { - - if (IS_TERMINATOR(row_string[row_pos])) /* CRLF */ - row_pos++; - - free(field); - goto end; - } - break; - - default: - break; - } - } - - // This point is reached only when for loop is completed fully - if (row_pos > bytes_read - 1) - { - reader->__buffer[0] = CCSV_NULL_CHAR; /* Reset the buffer */ - goto readfile; - } - - end: - row->fields = fields; - row->fields_count = fields_count; - - if (row_pos > bytes_read - 1) - reader->__buffer[0] = CCSV_NULL_CHAR; /* Reset the buffer */ - else - reader->__buffer_pos = row_pos; - - reader->rows_read++; - reader->status = CCSV_SUCCESS; - return row; - } - - int _is_buffer_empty(ccsv_reader *reader) - { - return reader->__buffer[0] == CCSV_NULL_CHAR; - } - - /* Writer */ - - ccsv_writer *ccsv_init_writer(ccsv_writer_options *options, short *status) - { - char delim, quote_char, escape_char; - WriterState state = WRITER_NOT_STARTED; - if (options == NULL) - { - delim = DEFAULT_DELIMITER; - quote_char = DEFAULT_QUOTE_CHAR; - escape_char = DEFAULT_ESCAPE_CHAR; - } - else - { - // It is not mandatory to pass all options to options struct - // So check if the option is passed or not, if not then use the default value - if (options->delim == CCSV_NULL_CHAR) - delim = DEFAULT_DELIMITER; - - else - delim = options->delim; - - if (options->quote_char == CCSV_NULL_CHAR) - quote_char = DEFAULT_QUOTE_CHAR; - - else - quote_char = options->quote_char; - - if (options->escape_char == CCSV_NULL_CHAR) - escape_char = DEFAULT_ESCAPE_CHAR; - - else - escape_char = options->escape_char; - } - - // Writer - ccsv_writer *writer = (ccsv_writer *)malloc(sizeof(ccsv_writer)); - if (writer == NULL) - { - if (status != NULL) - *status = CCSV_ERNOMEM; - return NULL; - } - writer->__delim = delim; - writer->__quote_char = quote_char; - writer->__escape_char = escape_char; - writer->__state = state; - - writer->write_status = WRITER_NOT_STARTED; - writer->object_type = CCSV_WRITER; - - return writer; - } - - int ccsv_write(ccsv_writer *writer, ccsv_row row) - { - if (writer == NULL) - return WRITE_ERNOTSTARTED; - - if (writer->__fp == NULL) - return CCSV_ERNULLFP; - - return write_row(writer->__fp, writer, row); - } - - int ccsv_write_from_array(ccsv_writer *writer, char **fields, int fields_len) - { - if (writer == NULL) - return WRITE_ERNOTSTARTED; - - if (writer->__fp == NULL) - return CCSV_ERNULLFP; - - return write_row_from_array(writer->__fp, writer, fields, fields_len); - } - - int write_row(FILE *fp, ccsv_writer *writer, ccsv_row row) - { - const int fields_count = row.fields_count; - char **fields = row.fields; - return (write_row_from_array(fp, writer, fields, fields_count)); - } - - int write_row_from_array(FILE *fp, ccsv_writer *writer, char **fields, int row_len) - { - CCSV_WRITE_ROW_START(fp, writer); - RETURN_IF_WRITE_ERROR(writer, WRITE_STARTED); - - for (int i = 0; i < row_len; i++) - { - const char *field = fields[i]; - CCSV_WRITE_FIELD(fp, writer, field); - RETURN_IF_WRITE_ERROR(writer, WRITE_SUCCESS); - } - CCSV_WRITE_ROW_END(fp, writer, NULL); - RETURN_IF_WRITE_ERROR(writer, WRITE_ENDED); - - writer->write_status = WRITE_SUCCESS; - return WRITE_SUCCESS; - } - - int _write_row_start(FILE *fp, ccsv_writer *writer) - { - long file_size; - char last_char; - - switch (writer->__state) - { - case WRITER_NOT_STARTED: - writer->__state = WRITER_ROW_START; /* Start writing row */ - - /* Move the file pointer to the end to get the file size */ - fseek(fp, 0, SEEK_END); - file_size = ftell(fp); - - /* Move the pointer to the penultimate position */ - fseek(fp, -1, SEEK_END); - - last_char = fgetc(fp); - - if (last_char != CCSV_LF && last_char != CCSV_CR && file_size > 0) - { - fputc(CCSV_CR, fp); - fputc(CCSV_LF, fp); - } - - /* Rewind the file pointer */ - fseek(fp, -file_size, SEEK_END); - break; - - case WRITER_ROW_END: - writer->__state = WRITER_ROW_START; /* Start writing row */ - break; - - case WRITER_WRITING_FIELD: - case WRITER_ROW_START: - writer->__state = WRITER_ROW_END; - writer->write_status = WRITE_ERALWRITING; /* Already writing field */ - return WRITE_ERALWRITING; - - default: - break; - } - - writer->write_status = WRITE_STARTED; - return WRITE_STARTED; - } - - int _write_row_end(FILE *fp, ccsv_writer *writer) - { - switch (writer->__state) - { - case WRITER_NOT_STARTED: - writer->__state = WRITER_ROW_END; - writer->write_status = WRITE_ERNOTSTARTED; /* Not started writing, CSV_WRITE_ROW_START() not called */ - return WRITE_ERNOTSTARTED; - - case WRITER_ROW_START: - case WRITER_WRITING_FIELD: - writer->__state = WRITER_ROW_END; - fputc(CCSV_CR, fp); - fputc(CCSV_LF, fp); - break; - - case WRITER_ROW_END: - writer->__state = WRITER_NOT_STARTED; /* Reset the state */ - break; - - default: - break; - } - - writer->write_status = WRITE_ENDED; - return WRITE_ENDED; - } - - int _write_field(FILE *fp, ccsv_writer *writer, const char *string) - { - WriterState state = writer->__state; - if (state != WRITER_ROW_START && state != WRITER_WRITING_FIELD) - { - /* Not started writing, CSV_WRITE_ROW_START() not called */ - writer->write_status = WRITE_ERNOTSTARTED; - return WRITE_ERNOTSTARTED; - } - - const char DELIM = writer->__delim; - const char QUOTE_CHAR = writer->__quote_char; - const char ESCAPE_CHAR = writer->__escape_char; - - int inside_quotes = 0; - - size_t string_len = strlen(string); - - char ch; - for (size_t i = 0; i < string_len; i++) - { - ch = string[i]; - if (ch == DELIM || ch == QUOTE_CHAR || ch == CCSV_CR || ch == CCSV_LF) - { - inside_quotes = 1; - break; - } - } - - if (inside_quotes) - { - fputc(QUOTE_CHAR, fp); - for (size_t i = 0; i < string_len; i++) - { - ch = string[i]; - /* Escape the quote character */ - if (ch == QUOTE_CHAR) - fputc(ESCAPE_CHAR, fp); - - fputc(ch, fp); - } - fputc(QUOTE_CHAR, fp); - } - else - fputs(string, fp); - - writer->write_status = WRITE_SUCCESS; - return WRITE_SUCCESS; - } - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/lib/ccsv/tests/Makefile b/lib/ccsv/tests/Makefile deleted file mode 100644 index ab2471e..0000000 --- a/lib/ccsv/tests/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -CC = gcc -CFLAGS = -Wall -Wextra -std=c99 -I../include - -%: %.c - $(CC) $(CFLAGS) -o $@.out $< ../src/ccsv.c - -clean: - rm -f *.out diff --git a/lib/ccsv/tests/test_ccsv.c b/lib/ccsv/tests/test_ccsv.c deleted file mode 100644 index 220a4d5..0000000 --- a/lib/ccsv/tests/test_ccsv.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -#include "ccsv.h" - -int main(void) -{ - return 0; -} \ No newline at end of file diff --git a/lib/microtar/LICENSE b/lib/microtar/LICENSE deleted file mode 100644 index 7e3bf17..0000000 --- a/lib/microtar/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2017 rxi - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/lib/microtar/README.md b/lib/microtar/README.md deleted file mode 100644 index 42acf49..0000000 --- a/lib/microtar/README.md +++ /dev/null @@ -1,99 +0,0 @@ -# microtar -A lightweight tar library written in ANSI C - - -## Basic Usage -The library consists of `microtar.c` and `microtar.h`. These two files can be -dropped into an existing project and compiled along with it. - - -#### Reading -```c -mtar_t tar; -mtar_header_t h; -char *p; - -/* Open archive for reading */ -mtar_open(&tar, "test.tar", "r"); - -/* Print all file names and sizes */ -while ( (mtar_read_header(&tar, &h)) != MTAR_ENULLRECORD ) { - printf("%s (%d bytes)\n", h.name, h.size); - mtar_next(&tar); -} - -/* Load and print contents of file "test.txt" */ -mtar_find(&tar, "test.txt", &h); -p = calloc(1, h.size + 1); -mtar_read_data(&tar, p, h.size); -printf("%s", p); -free(p); - -/* Close archive */ -mtar_close(&tar); -``` - -#### Writing -```c -mtar_t tar; -const char *str1 = "Hello world"; -const char *str2 = "Goodbye world"; - -/* Open archive for writing */ -mtar_open(&tar, "test.tar", "w"); - -/* Write strings to files `test1.txt` and `test2.txt` */ -mtar_write_file_header(&tar, "test1.txt", strlen(str1)); -mtar_write_data(&tar, str1, strlen(str1)); -mtar_write_file_header(&tar, "test2.txt", strlen(str2)); -mtar_write_data(&tar, str2, strlen(str2)); - -/* Finalize -- this needs to be the last thing done before closing */ -mtar_finalize(&tar); - -/* Close archive */ -mtar_close(&tar); -``` - - -## Error handling -All functions which return an `int` will return `MTAR_ESUCCESS` if the operation -is successful. If an error occurs an error value less-than-zero will be -returned; this value can be passed to the function `mtar_strerror()` to get its -corresponding error string. - - -## Wrapping a stream -If you want to read or write from something other than a file, the `mtar_t` -struct can be manually initialized with your own callback functions and a -`stream` pointer. - -All callback functions are passed a pointer to the `mtar_t` struct as their -first argument. They should return `MTAR_ESUCCESS` if the operation succeeds -without an error, or an integer below zero if an error occurs. - -After the `stream` field has been set, all required callbacks have been set and -all unused fields have been zeroset the `mtar_t` struct can be safely used with -the microtar functions. `mtar_open` *should not* be called if the `mtar_t` -struct was initialized manually. - -#### Reading -The following callbacks should be set for reading an archive from a stream: - -Name | Arguments | Description ---------|------------------------------------------|--------------------------- -`read` | `mtar_t *tar, void *data, unsigned size` | Read data from the stream -`seek` | `mtar_t *tar, unsigned pos` | Set the position indicator -`close` | `mtar_t *tar` | Close the stream - -#### Writing -The following callbacks should be set for writing an archive to a stream: - -Name | Arguments | Description ---------|------------------------------------------------|--------------------- -`write` | `mtar_t *tar, const void *data, unsigned size` | Write data to the stream - - -## License -This library is free software; you can redistribute it and/or modify it under -the terms of the MIT license. See [LICENSE](LICENSE) for details. diff --git a/lib/microtar/src/microtar.c b/lib/microtar/src/microtar.c deleted file mode 100644 index 4b89776..0000000 --- a/lib/microtar/src/microtar.c +++ /dev/null @@ -1,376 +0,0 @@ -/* - * Copyright (c) 2017 rxi - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include -#include -#include -#include - -#include "microtar.h" - -typedef struct { - char name[100]; - char mode[8]; - char owner[8]; - char group[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char type; - char linkname[100]; - char _padding[255]; -} mtar_raw_header_t; - - -static unsigned round_up(unsigned n, unsigned incr) { - return n + (incr - n % incr) % incr; -} - - -static unsigned checksum(const mtar_raw_header_t* rh) { - unsigned i; - unsigned char *p = (unsigned char*) rh; - unsigned res = 256; - for (i = 0; i < offsetof(mtar_raw_header_t, checksum); i++) { - res += p[i]; - } - for (i = offsetof(mtar_raw_header_t, type); i < sizeof(*rh); i++) { - res += p[i]; - } - return res; -} - - -static int tread(mtar_t *tar, void *data, unsigned size) { - int err = tar->read(tar, data, size); - tar->pos += size; - return err; -} - - -static int twrite(mtar_t *tar, const void *data, unsigned size) { - int err = tar->write(tar, data, size); - tar->pos += size; - return err; -} - - -static int write_null_bytes(mtar_t *tar, int n) { - int i, err; - char nul = '\0'; - for (i = 0; i < n; i++) { - err = twrite(tar, &nul, 1); - if (err) { - return err; - } - } - return MTAR_ESUCCESS; -} - - -static int raw_to_header(mtar_header_t *h, const mtar_raw_header_t *rh) { - unsigned chksum1, chksum2; - - /* If the checksum starts with a null byte we assume the record is NULL */ - if (*rh->checksum == '\0') { - return MTAR_ENULLRECORD; - } - - /* Build and compare checksum */ - chksum1 = checksum(rh); - sscanf(rh->checksum, "%o", &chksum2); - if (chksum1 != chksum2) { - return MTAR_EBADCHKSUM; - } - - /* Load raw header into header */ - sscanf(rh->mode, "%o", &h->mode); - sscanf(rh->owner, "%o", &h->owner); - sscanf(rh->size, "%o", &h->size); - sscanf(rh->mtime, "%o", &h->mtime); - h->type = rh->type; - strcpy(h->name, rh->name); - strcpy(h->linkname, rh->linkname); - - return MTAR_ESUCCESS; -} - - -static int header_to_raw(mtar_raw_header_t *rh, const mtar_header_t *h) { - unsigned chksum; - - /* Load header into raw header */ - memset(rh, 0, sizeof(*rh)); - sprintf(rh->mode, "%o", h->mode); - sprintf(rh->owner, "%o", h->owner); - sprintf(rh->size, "%o", h->size); - sprintf(rh->mtime, "%o", h->mtime); - rh->type = h->type ? h->type : MTAR_TREG; - strcpy(rh->name, h->name); - strcpy(rh->linkname, h->linkname); - - /* Calculate and write checksum */ - chksum = checksum(rh); - sprintf(rh->checksum, "%06o", chksum); - rh->checksum[7] = ' '; - - return MTAR_ESUCCESS; -} - - -const char* mtar_strerror(int err) { - switch (err) { - case MTAR_ESUCCESS : return "success"; - case MTAR_EFAILURE : return "failure"; - case MTAR_EOPENFAIL : return "could not open"; - case MTAR_EREADFAIL : return "could not read"; - case MTAR_EWRITEFAIL : return "could not write"; - case MTAR_ESEEKFAIL : return "could not seek"; - case MTAR_EBADCHKSUM : return "bad checksum"; - case MTAR_ENULLRECORD : return "null record"; - case MTAR_ENOTFOUND : return "file not found"; - } - return "unknown error"; -} - - -static int file_write(mtar_t *tar, const void *data, unsigned size) { - unsigned res = fwrite(data, 1, size, tar->stream); - return (res == size) ? MTAR_ESUCCESS : MTAR_EWRITEFAIL; -} - -static int file_read(mtar_t *tar, void *data, unsigned size) { - unsigned res = fread(data, 1, size, tar->stream); - return (res == size) ? MTAR_ESUCCESS : MTAR_EREADFAIL; -} - -static int file_seek(mtar_t *tar, unsigned offset) { - int res = fseek(tar->stream, offset, SEEK_SET); - return (res == 0) ? MTAR_ESUCCESS : MTAR_ESEEKFAIL; -} - -static int file_close(mtar_t *tar) { - fclose(tar->stream); - return MTAR_ESUCCESS; -} - - -int mtar_open(mtar_t *tar, const char *filename, const char *mode) { - int err; - mtar_header_t h; - - /* Init tar struct and functions */ - memset(tar, 0, sizeof(*tar)); - tar->write = file_write; - tar->read = file_read; - tar->seek = file_seek; - tar->close = file_close; - - /* Assure mode is always binary */ - if ( strchr(mode, 'r') ) mode = "rb"; - if ( strchr(mode, 'w') ) mode = "wb"; - if ( strchr(mode, 'a') ) mode = "ab"; - /* Open file */ - tar->stream = fopen(filename, mode); - if (!tar->stream) { - return MTAR_EOPENFAIL; - } - /* Read first header to check it is valid if mode is `r` */ - if (*mode == 'r') { - err = mtar_read_header(tar, &h); - if (err != MTAR_ESUCCESS) { - mtar_close(tar); - return err; - } - } - - /* Return ok */ - return MTAR_ESUCCESS; -} - - -int mtar_close(mtar_t *tar) { - return tar->close(tar); -} - - -int mtar_seek(mtar_t *tar, unsigned pos) { - int err = tar->seek(tar, pos); - tar->pos = pos; - return err; -} - - -int mtar_rewind(mtar_t *tar) { - tar->remaining_data = 0; - tar->last_header = 0; - return mtar_seek(tar, 0); -} - - -int mtar_next(mtar_t *tar) { - int err, n; - mtar_header_t h; - /* Load header */ - err = mtar_read_header(tar, &h); - if (err) { - return err; - } - /* Seek to next record */ - n = round_up(h.size, 512) + sizeof(mtar_raw_header_t); - return mtar_seek(tar, tar->pos + n); -} - - -int mtar_find(mtar_t *tar, const char *name, mtar_header_t *h) { - int err; - mtar_header_t header; - /* Start at beginning */ - err = mtar_rewind(tar); - if (err) { - return err; - } - /* Iterate all files until we hit an error or find the file */ - while ( (err = mtar_read_header(tar, &header)) == MTAR_ESUCCESS ) { - if ( !strcmp(header.name, name) ) { - if (h) { - *h = header; - } - return MTAR_ESUCCESS; - } - mtar_next(tar); - } - /* Return error */ - if (err == MTAR_ENULLRECORD) { - err = MTAR_ENOTFOUND; - } - return err; -} - - -int mtar_read_header(mtar_t *tar, mtar_header_t *h) { - int err; - mtar_raw_header_t rh; - /* Save header position */ - tar->last_header = tar->pos; - /* Read raw header */ - err = tread(tar, &rh, sizeof(rh)); - if (err) { - return err; - } - /* Seek back to start of header */ - err = mtar_seek(tar, tar->last_header); - if (err) { - return err; - } - /* Load raw header into header struct and return */ - return raw_to_header(h, &rh); -} - - -int mtar_read_data(mtar_t *tar, void *ptr, unsigned size) { - int err; - /* If we have no remaining data then this is the first read, we get the size, - * set the remaining data and seek to the beginning of the data */ - if (tar->remaining_data == 0) { - mtar_header_t h; - /* Read header */ - err = mtar_read_header(tar, &h); - if (err) { - return err; - } - /* Seek past header and init remaining data */ - err = mtar_seek(tar, tar->pos + sizeof(mtar_raw_header_t)); - if (err) { - return err; - } - tar->remaining_data = h.size; - } - /* Read data */ - err = tread(tar, ptr, size); - if (err) { - return err; - } - tar->remaining_data -= size; - /* If there is no remaining data we've finished reading and seek back to the - * header */ - if (tar->remaining_data == 0) { - return mtar_seek(tar, tar->last_header); - } - return MTAR_ESUCCESS; -} - - -int mtar_write_header(mtar_t *tar, const mtar_header_t *h) { - mtar_raw_header_t rh; - /* Build raw header and write */ - header_to_raw(&rh, h); - tar->remaining_data = h->size; - return twrite(tar, &rh, sizeof(rh)); -} - - -int mtar_write_file_header(mtar_t *tar, const char *name, unsigned size) { - mtar_header_t h; - /* Build header */ - memset(&h, 0, sizeof(h)); - strcpy(h.name, name); - h.size = size; - h.type = MTAR_TREG; - h.mode = 0664; - /* Write header */ - return mtar_write_header(tar, &h); -} - - -int mtar_write_dir_header(mtar_t *tar, const char *name) { - mtar_header_t h; - /* Build header */ - memset(&h, 0, sizeof(h)); - strcpy(h.name, name); - h.type = MTAR_TDIR; - h.mode = 0775; - /* Write header */ - return mtar_write_header(tar, &h); -} - - -int mtar_write_data(mtar_t *tar, const void *data, unsigned size) { - int err; - /* Write data */ - err = twrite(tar, data, size); - if (err) { - return err; - } - tar->remaining_data -= size; - /* Write padding if we've written all the data for this file */ - if (tar->remaining_data == 0) { - return write_null_bytes(tar, round_up(tar->pos, 512) - tar->pos); - } - return MTAR_ESUCCESS; -} - - -int mtar_finalize(mtar_t *tar) { - /* Write two NULL records */ - return write_null_bytes(tar, sizeof(mtar_raw_header_t) * 2); -} diff --git a/lib/microtar/src/microtar.h b/lib/microtar/src/microtar.h deleted file mode 100644 index f4a62d1..0000000 --- a/lib/microtar/src/microtar.h +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright (c) 2017 rxi - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the MIT license. See `microtar.c` for details. - */ - -#ifndef MICROTAR_H -#define MICROTAR_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include -#include - -#define MTAR_VERSION "0.1.0" - -enum { - MTAR_ESUCCESS = 0, - MTAR_EFAILURE = -1, - MTAR_EOPENFAIL = -2, - MTAR_EREADFAIL = -3, - MTAR_EWRITEFAIL = -4, - MTAR_ESEEKFAIL = -5, - MTAR_EBADCHKSUM = -6, - MTAR_ENULLRECORD = -7, - MTAR_ENOTFOUND = -8 -}; - -enum { - MTAR_TREG = '0', - MTAR_TLNK = '1', - MTAR_TSYM = '2', - MTAR_TCHR = '3', - MTAR_TBLK = '4', - MTAR_TDIR = '5', - MTAR_TFIFO = '6' -}; - -typedef struct { - unsigned mode; - unsigned owner; - unsigned size; - unsigned mtime; - unsigned type; - char name[100]; - char linkname[100]; -} mtar_header_t; - - -typedef struct mtar_t mtar_t; - -struct mtar_t { - int (*read)(mtar_t *tar, void *data, unsigned size); - int (*write)(mtar_t *tar, const void *data, unsigned size); - int (*seek)(mtar_t *tar, unsigned pos); - int (*close)(mtar_t *tar); - void *stream; - unsigned pos; - unsigned remaining_data; - unsigned last_header; -}; - - -const char* mtar_strerror(int err); - -int mtar_open(mtar_t *tar, const char *filename, const char *mode); -int mtar_close(mtar_t *tar); - -int mtar_seek(mtar_t *tar, unsigned pos); -int mtar_rewind(mtar_t *tar); -int mtar_next(mtar_t *tar); -int mtar_find(mtar_t *tar, const char *name, mtar_header_t *h); -int mtar_read_header(mtar_t *tar, mtar_header_t *h); -int mtar_read_data(mtar_t *tar, void *ptr, unsigned size); - -int mtar_write_header(mtar_t *tar, const mtar_header_t *h); -int mtar_write_file_header(mtar_t *tar, const char *name, unsigned size); -int mtar_write_dir_header(mtar_t *tar, const char *name); -int mtar_write_data(mtar_t *tar, const void *data, unsigned size); -int mtar_finalize(mtar_t *tar); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/kospm.c b/src/kospm.c index dba9ffa..c666bc4 100644 --- a/src/kospm.c +++ b/src/kospm.c @@ -1,7 +1,7 @@ /* * kospm.c * - * Copyright 2024 keXa + * Copyright 2024-2025 keXa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,18 +20,33 @@ * * */ -#include "../include/kospm.h" +#include "kospm.h" -int kospm_install(char *root_dir, char *pkg_file){ - kospm_db_t *db = kospm_db_open(root_dir); - kospm_package_list_t *package_list = kospm_package_list_open(pkg_file); +int kospm_install(kospm_pkg_db_t *db, char *pkg_file, char *pkg_name){ + kospm_pkg_bundle_t* bundle = kospm_pkg_bundle_open(pkg_file); - kospm_db_packages_add(db, package_list->packages); - kospm_db_files_add(db, package_list->files); + if(pkg_name) { + //if pkg_name isn't null pointer: + //if package pkg_name doesn't exist, + //exit with error; + //install needed package and exit; + + if(!kospm_pkg_list_meta_query(bundle->package_list, pkg_name)) { + return KOSPM_NOSUCHPKG; + } + + kospm_db_pkg_add(db, + kospm_pkg_list_meta_query(bundle->package_list, pkg_name)); + + //do {} while(kospm_); + + kospm_pkg_bundle_unpack(db->root_path, bundle, pkg_name); + } else { + //install every package in the bundle and exit; + + } - kospm_package_list_close(package_list); kospm_db_save(db); - kospm_db_close(db); - return 0; + return KOSPM_OK; } diff --git a/src/kospm_common.c b/src/kospm_common.c deleted file mode 100644 index 60e64a1..0000000 --- a/src/kospm_common.c +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include "../include/kospm_common.h" - -kospm_list_t* _kospm_csv_header_get(FILE *file){ - ccsv_reader *reader = ccsv_init_reader(&_kospm_csv_reader_options); - kospm_list_t *header = (kospm_list_t*)malloc(sizeof(kospm_list_t)); - ccsv_row *row; - kospm_csv_header_column *head_elem; - - fseek(fp, 0, SEEK_SET); - if ((row = read_row(fp, reader)) != NULL){ - for (int i = 0; i < row->fields_count; i++){ - head_elem->col_number = i; - head_elem->col_name = row->fields[i]; - - kospm_list_add(header, head_elem); - } - } - - ccsv_free_row(row); - free(reader); - - return header; -} - -int _kospm_csv_col_get(kospm_list_t* col_list, char* col_name){ - kospm_list_t *current = col_list; - - while(strcmp(current->data->col_name, col_name) || current!=NULL){ - current=current->next; - } - - if(current==NULL){return -1;} - - return current->data->col_num; -} diff --git a/src/kospm_csv.c b/src/kospm_csv.c new file mode 100644 index 0000000..4e6e471 --- /dev/null +++ b/src/kospm_csv.c @@ -0,0 +1,68 @@ +/* + * kospm_csv.c + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +#include +#include "kospm_macros.h" +#include "kospm_csv.h" + +kospm_csv_header* kospm_csv_header_get(FILE *file) { + ccsv_reader *reader = ccsv_init_reader(&_kospm_csv_reader_options); + kospm_list_t *col_list = kospm_list_new(); + ccsv_row *row; + kospm_csv_header_col *header_elem; + + fseek(fp, 0, SEEK_SET); + if ((row = read_row(fp, reader)) == NULL) { return NULL; } + + for (int i = 0; i < row->fields_count; i++) { + header_elem = + (kospm_csv_header_col*)malloc(sizeof(kospm_csv_header_col)); + header_elem->col_number = i; + header_elem->col_name = row->fields[i]; + + kospm_list_add(col_list, head_elem); + } + + + MALLOCNEW(header, kospm_csv_header); + header->col_amount = row->fields_count; + header->col_list = col_list; + + ccsv_free_row(row); + free(reader); + + return header; +} + +int _kospm_csv_col_cmp(kospm_csv_header_col *column, char* name){ + return strcmp(current->data->col_name, col_name); +} + +int kospm_csv_col_get(kospm_csv_header *header, char* col_name) { + kospm_csv_header_col *current = kospm_list_get_by_value(header->col_list, col_name, _kospm_csv_col_cmp); + + return current->data->col_number; +} + +char* kospm_csv_field_get(ccsv_row *row, kospm_csv_header *header, char* col_name){ + return row->fields[kospm_csv_col_get(header->col_list, col_name)]; +} diff --git a/src/kospm_db.c b/src/kospm_db.c deleted file mode 100644 index e527b13..0000000 --- a/src/kospm_db.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * kospm_db.c - * - * Copyright 2024 keXa - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ -#include -#include -#include "../include/kospm_db.h" -#include "../include/kospm_common.h" - -int _kospm_db_metadata_list_write(FILE* metadata_table, kospm_list_t *metadata_list){ - kospm_list_t *metadata_col_list = _kospm_csv_header_get(db->metadata_table); - kospm_list_t *current = metadata_list; - - short *write_status; - ccsv_writer *writer = ccsv_init_writer(&_kospm_csv_writer_options, write_status); - - char **metadata = malloc(12*sizeof(char*)); - - while(*current!=NULL){ - metadata[_kospm_csv_col_get(metadata_col_list, "name")] = current->data->pkg_name; - metadata[_kospm_csv_col_get(metadata_col_list, "version")] = current->data->pkg_version; - metadata[_kospm_csv_col_get(metadata_col_list, "description")] = current->data->pkg_description; - - write_row_from_array(metadata_table, writer, metadata, 12); - } - - free(metadata); - - return 0; -} - -int _kospm_db_files_list_write(FILE* files_table, kospm_list_t *file_list){ - kospm_list_t *files_col_list = _kospm_csv_header_get(db->files_table); - kospm_list_t *current = file_list; - - short *write_status; - ccsv_writer *writer = ccsv_init_writer(&_kospm_csv_writer_options, write_status); - - char **file = malloc(4*sizeof(char*)); - - while(*current!=NULL){ - file[_kospm_csv_col_get(files_col_list, "pkgname")] = current->data->pkg_name; - file[_kospm_csv_col_get(files_col_list, "filename")] = current->data->file_name; - - write_row_from_array(metadata_table, writer, metadata, 4); - } - - free(metadata); - - return 0; -} - -kospm_db_t* kospm_db_init(char *root_dir){ - kospm_db_t *db = (kospm_db_t*)malloc(sizeof(kospm_db_t)); - db->path = strcat(root_dir, DB_FOLDER); - - db->metadata_table = fopen(strcat(db->path, METADATA_TABLE), "a+"); - db->files_table = fopen(strcat(db->path, FILES_TABLE), "a+"); - - fprintf(metadata_table, "name, version, description"); - fprintf(files_table, "pkgname, filename"); - - freopen(strcat(db->path, METADATA_TABLE), "r+", db->metadata_table); - freopen(strcat(db->path, FILES_TABLE), "r+", db->files_table); - return db; -} - -kospm_db_t* kospm_db_open(char *root_dir){ - kospm_db_t *db = (kospm_db_t*)malloc(sizeof(kospm_db_t)); - - db->path = strcat(root_dir, DB_FOLDER); - db->metadata_table = fopen(strcat(db->path, METADATA_TABLE), "r+"); - db->files_table = fopen(strcat(db->path, FILES_TABLE), "r+"); - db->packages = kospm_package_metadata_get(metadata_table); - db->files = kospm_package_files_get(files_table); - - return db; -} - -int kospm_db_save(kospm_db_t *db){ - _kospm_db_metadata_list_write(db->metadata_table, db->packages); - _kospm_db_files_list_write(db->files_table, db->files); - - return 0; -} - -int kospm_db_close(kospm_db_t *db){ - kospm_list_free(db->files); - kospm_list_free(db->packages); - - fclose(db->files_table); - fclose(db->metadata_table); - - free(db); - - return 0; -} - -int kospm_db_package_add(kospm_db_t *db, kospm_package_t *package){ - kospm_list_add(db->packages, package); - - return 0; -} - -int kospm_db_packages_add(kospm_db_t *db, kospm_list_t *package_list){ - kospm_list_t *current = package_list; - while(*current!=NULL){ - kospm_list_add(db->packages, current->data); - - *current = package_list->next; - } - - return 0; -} - -int kospm_db_file_add(kospm_db_t *db, char *pkg_name, kospm_package_file_t *file){ - kospm_list_add(db->files, file); - - return 0; -} - -int kospm_db_files_add(kospm_db_t *db, kospm_list_t *file_list){ - kospm_list_t *current = file_list; - while(*current!=NULL){ - kospm_list_add(db->files, current->data); - - *current = package_list->next; - } - - return 0; -} diff --git a/src/kospm_list.c b/src/kospm_list.c index 452ae3b..5663027 100644 --- a/src/kospm_list.c +++ b/src/kospm_list.c @@ -1,7 +1,7 @@ /* * kospm_list.c * - * Copyright 2024 keXa + * Copyright 2024-2025 keXa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,54 +20,94 @@ * * */ -#include "../include/kospm_list.h" +#include "kospm_macros.h" +#include "kospm_list.h" -kospm_list_t* kospm_list_new(void *data) { - kospm_list_t *node = (kospm_list_t*)malloc(sizeof(kospm_list_t)); - node->data = data; - node->next = NULL; - node->prev = NULL; - return node; +//This will stay here until I'm sure I won't need it. +//Although, I may consider changing it. Nothing's new under the sun. + +kospm_list_t* kospm_list_new() { + MALLOCNEW(dlist, kospm_list_t); + + dlist->first = NULL; + dlist->current = NULL; + dlist->last = NULL; + + return dlist; } -void kospm_list_add(kospm_list_t **list, void *data) { - kospm_list_t *new_node = kospm_list_new(data); - if (*list == NULL) { - *list = new_node; +void kospm_list_add(kospm_list_t *dlist, void *data) { + MALLOCNEW(dlist, kospm_list_node_t); + + if (*dlist->first == NULL) { + *dlist->first = new_node; } else { - kospm_list_t *current = *list; - while (current->next != NULL) { - current = current->next; - } + kospm_list_node_t *current = *dlist->last; current->next = new_node; new_node->prev = current; } + *dlist->last = new_node; } +void* kospm_list_prev(kospm_list_t *dlist){ + dlist->current=dlist->current->prev; + return dlist->current->data; +} -void kospm_list_del_by_value(kospm_list_t **list, void *data, int (*cmp)(void *, void *)) { - kospm_list_t *current = *list; - while (current != NULL) { +void* kospm_list_next(kospm_list_t *dlist){ + dlist->current=dlist->current->next; + return dlist->current->data; +} + +kospm_list_node_t* kospm_list_get_by_value(kospm_list_t *dlist, + void *data, int (*cmp)(void *, void *)) { + kospm_list_node_t *current = dlist->current; + + while (current != dlist->last) { + if (cmp(current->data, data) == 0) { + dlist->current = current; + return current; + } + current = current->next; + } + + dlist->current = dlist->first; + return NULL; +} + +void kospm_list_del_by_value(kospm_list_t *dlist, void *data, + int (*cmp)(void *, void *), void (*free_alt)(void *)) { + kospm_list_node_t *current = *dlist->first; + + while (current != dlist->first) { if (cmp(current->data, data) == 0) { - if (current->prev != NULL) { - current->prev->next = current->next; + if(current == dlist->first){ + *dlist->first = current->next; } else { - *list = current->next; + current->prev->next = current->next; } - if (current->next != NULL) { + + if(current == dlist->last){ + *dlist->last = current->prev; + } else { current->next->prev = current->prev; } - free(current); + + (free_alt) ? free_alt(current) : free(current); + } break; } current = current->next; } + dlist->current = current; } -void kospm_list_free(kospm_list_t *list) { - while (list != NULL) { - kospm_list_t *temp = list; - list = list->next; - free(temp); +void kospm_list_free(kospm_list_t *dlist, void (*free_alt)(void *)) { + kospm_list_node_t *current = dlist->first; + while (current != dlist->last) { + kospm_list_node_t *temp = current; + current = current->next; + (free_alt) ? free_alt(current) : free(current); } + free(dlist); } diff --git a/src/kospm_package.c b/src/kospm_package.c deleted file mode 100644 index 71abba6..0000000 --- a/src/kospm_package.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * kospm_package.c - * - * Copyright 2024 keXa - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * - */ - -#include -#include -#include "../lib/microtar/src/microtar.h" -#include "../include/kospm_tar.h" -#include "../lib/ccsv/include/ccsv.h" -#include "../include/kospm_package.h" -#include "../include/kospm_common.h" - - - -kospm_list_t* kospm_package_files_get(FILE* fp){ - kospm_list_t *file_list = (kospm_list_t*)malloc(sizeof(kospm_list_t)); - kospm_package_file_t *file; - char *files_path = strcat(CACHE, FILES); - char *files_fields[] = {"pkgname", "filename"}; - short *read_status; - ccsv_reader *reader = ccsv_init_reader(&_kospm_csv_reader_options, read_status); - kospm_list_t *files_col_list = _kospm_csv_header_get(fp); - - ccsv_row *row; - while ((row = read_row(fp, reader)) != NULL) { - file = (kospm_package_file_t*)malloc(sizeof(kospm_package_file_t)); - - file->pkg_name = row->fields[_kospm_csv_col_number_get(files_col_list, files_fields[0])]; - file->file_name = row->fields[_kospm_csv_col_number_get(files_col_list, files_fields[1])]; - - kospm_list_add(file_list, file); - } - - kospm_list_free(files_col_list); - ccsv_free_row(row); - free(reader); - - return file_list; -} - -kospm_list_t* kospm_package_metadata_get(FILE* fp){ - kospm_list_t *metadata_list = (kospm_list_t*)malloc(sizeof(kospm_list_t)); - kospm_package_t *package; - char *pkginfo_path = strcat(CACHE, PKGINFO); - char *metadata_fields[] = {"name", "version", "description"}; - short *read_status; - ccsv_reader *reader = ccsv_init_reader(&_kospm_csv_reader_options, read_status); - kospm_list_t *metadata_col_list = _kospm_csv_header_get(fp); - - ccsv_row *row; - while ((row = read_row(fp, reader)) != NULL) { - package = (kospm_package_t*)malloc(sizeof(kospm_package_t)); - - package->pkg_name = row.fields[_kospm_csv_col_get(metadata_col_list, metadata_fields[0])]; - package->pkg_version = row.fields[_kospm_csv_col_get(metadata_col_list, metadata_fields[1])]; - package->pkg_description = row.fields[_kospm_csv_col_get(metadata_col_list, metadata_fields[2])]; - - kospm_list_add(metadata_list, package); - } - - kospm_list_free(metadata_col_list); - ccsv_free_row(row); - free(reader); - - return metadata_list; -} - -kospm_package_list_t *kospm_package_list_open(char *pkg_file){ - kospm_package_list_t *package_list = (kospm_package_list_t*)malloc(sizeof(kospm_package_list_t)); - FILE* metadata_fp; - FILE* files_fp; - char *pkginfo_path = strcat(CACHE, PKGINFO); - char *files_path = strcat(CACHE, FILES); - - tar_unpack(pkg_file, PKGINFO, pkginfo_path); - tar_unpack(pkg_file, FILES, files_path); - metadata_fp = fopen(pkginfo_path, "r"); - files_fp = fopen(files_path, "r"); - - package_list->packages = kospm_package_metadata_get(metadata_fp); - - package_list->files = kospm_package_files_get(files_fp); - - free(reader); - fclose(metadata_fp); - fclose(files_fp); - - return package_list; -} - -int kospm_package_list_close(kospm_package_list_t *package_list){ - kospm_list_free(package_list->packages); - kospm_list_free(package_list->files); - free(package_list); - - return 0; -} diff --git a/src/kospm_pkgbundle.c b/src/kospm_pkgbundle.c new file mode 100644 index 0000000..37f0ac8 --- /dev/null +++ b/src/kospm_pkgbundle.c @@ -0,0 +1,94 @@ +/* + * kospm_pkgbundle.c + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +#include "kospm_macros.h" +#include "kospm_pkgbundle.h" + +kospm_pkg_bundle_t* kospm_pkg_bundle_open(char* bundle_path){ + MALLOCNEW(bundle, kospm_pkg_bundle_t); + + char* meta_file_path = META_CACHE; + char* files_file_path = FILES_CACHE; + + if (tar_unpack(bundle_path, META_TABLE, meta_file_path) || + tar_unpack(bundle_path, FILES_TABLE, files_file_path)){ + free(meta_file_path); + free(files_file_path); + + return NULL; + } + + bundle->bundle_path=bundle_path; + bundle->package_list=kospm_pkg_list_open(NULL, BUNDLE_CACHE); + + return pkg_bundle; +} + +int kospm_pkg_bundle_unpack(kospm_pkg_bundle_t* pkg_bundle, + char *root_path, char *pkg_name){ + kospm_list_t* pkg_files_list; + kospm_list_t* file_list; + + //It's true if there is a needed package which isn't in the bundle. + //Otherwise files of all packages in the bundle are unpacked. + if(pkg_name && !kospm_pkg_list_meta_query(pkg_bundle->package_list, + pkg_name)){ + return -1; + } + + pkg_files_list = kospm_pkg_list_files_query(pkg_bundle, pkg_name); + + file_list = kospm_tar_filelist_get(pkg_bundle->bundle_path); + + do { + if(!kospm_tar_file_exists(file_list, pkg_files_list->current) { + kospm_list_free(pkg_files_list, kospm_pkg_file_free); + kospm_list_free(file_list, NULL); + + return -1; + } + } while(kospm_list_next(pkg_files_list)); + + pkg_files_list->current=pkg_files_list->first; + char* file_path = (char*)malloc(FILE_MAX*sizeof(char)); + + do { + if (snprintf(file_path, FILE_MAX, "%s%s", root_path, DB_FOLDER) + >=FILE_MAX){ + free(file_path); + return -1; + } + + kospm_tar_unpack(pkg_bundle->bundle_path, + pkg_files_list->current, file_path); + } while(kospm_list_next(pkg_files_list)); + + return 0; +} + +int kospm_pkg_bundle_close(kospm_pkg_bundle_t* pkg_bundle){ + free(pkg_bundle->bundle_path); + kospm_pkg_list_close(pkg_bundle->package_list); + free(pkg_bundle); + + return 0; +} diff --git a/src/kospm_pkgdb.c b/src/kospm_pkgdb.c new file mode 100644 index 0000000..1559746 --- /dev/null +++ b/src/kospm_pkgdb.c @@ -0,0 +1,92 @@ +/* + * kospm_pkgdb.c + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +#include "kospm_macros.h" +#include "kospm_pkgdb.h" + +kospm_pkg_db_t* kospm_db_init(){ + MALLOCNEW(list, kospm_pkg_db_t); + + db->package_list = kospm_pkg_list_init(); + + return db; +} + +kospm_pkg_db_t* kospm_db_open(kospm_pkg_db_t *db, char *root_path){ + if (!db) db = kospm_db_init(); + + db->root_path=root_path; + db->package_list=kospm_pkg_list_open(NULL, root_path); + + return db; +} + +int kospm_db_save(kospm_pkg_db_t *db){ + char* db_path = (char*)malloc(FILE_MAX*sizeof(char)); + if (snprintf(db_path, FILE_MAX, "%s%s", db->root_path, + DB_FOLDER)>=FILE_MAX){ + free(db_path); + + return -1; + } + + kospm_pkg_list_save(db->package_list, db_path); + + return 0; +} + +int kospm_db_close(kospm_pkg_db_t *db){ + free(db->db_path); + kospm_pkg_list_close(db->package_list); + + free(db); +} + +int _same_pkgname(void *struc, char *name){ + return (strcmp(struc->pkg_name, name)) ? 0 : 1; +} + +int kospm_db_pkg_add(kospm_pkg_db_t *db, kospm_pkg_meta_t *package){ + kospm_list_add(db->package_list->packages, package); + + return 0; +} + +int kospm_db_pkg_remove(kospm_pkg_db_t *db, char *pkg_name){ + kospm_list_del_by_value(db->package_list->packages, pkg_name, + _same_pkgname, kospm_pkg_meta_free); + + return 0; +} + +int kospm_db_pkg_file_add(kospm_pkg_db_t *db, kospm_pkg_file_t *file){ + kospm_list_add(db->package_list->files, file); + + return 0; +} + +int kospm_db_pkg_file_remove(kospm_pkg_db_t *db, char *file_name){ + kospm_list_del_by_value(db->package_list->files, file_name, + _same_pkgname, kospm_pkg_file_free); + + return 0; +} diff --git a/src/kospm_pkgfile.c b/src/kospm_pkgfile.c new file mode 100644 index 0000000..cd31c0a --- /dev/null +++ b/src/kospm_pkgfile.c @@ -0,0 +1,63 @@ +/* + * kospm_pkgfile.h + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ +#include "kospm_macros.h" +#include "kospm_pkgfile.h" + +kospm_pkg_file_t* kospm_pkg_file_init(){ + MALLOCNEW(pkg_file, kospm_pkg_file_t); + + return pkg_file; +} + +kospm_pkg_file_t* kospm_pkg_file_load(ccsv_row *row, + kospm_csv_header *header){ + kospm_pkg_file_t *pkg_file = kospm_pkg_file_init(); + + strncpy(pkg_file->pkg_name, kospm_csv_field_get(row, header, "pkgname"), NAME_MAX); + pkg_file->file_name = strcpynew(kospm_csv_field_get(row, header, "filename"), FILE_MAX); + + return pkg_file; +} + +char** kospm_pkg_file_store(kospm_pkg_file_t *pkg_file, + kospm_csv_header *header){ + char* row[header->col_amount]; + row->fields[kospm_csv_field_get(row, header, "pkgname")] = + strcpynew(pkg_file->pkg_name, NAME_MAX-1); + row->fields[kospm_csv_field_get(row, header, "filename")] = + strcpynew(pkg_meta->pkg_description, FILE_MAX-1); + + return row; +} + +int kospm_pkg_file_check_pkgname(kospm_pkg_meta_t *pkg_meta, + char* pkg_name){ + return (pkg_name) ? !strcmp(pkg_file->pkg_name, pkg_name) : 1; +} + +int kospm_pkg_file_free(kospm_pkg_file_t *pkg_file){ + free(pkg_file->file_name); + free(pkg_file); + + return 0; +} diff --git a/src/kospm_pkglist.c b/src/kospm_pkglist.c new file mode 100644 index 0000000..f382bda --- /dev/null +++ b/src/kospm_pkglist.c @@ -0,0 +1,209 @@ +/* + * kospm_pkglist.c + * + * Copyright 2025 keXa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + +#include +#include +#include "kospm_macros.h" +#include "kospm_csv.h" +#include "kospm_pkglist.h" +#include "kospm_pkgmeta.h" + +kospm_list_t* _kospm_meta_table_read(char* file_path){ + kospm_list_t *dlist = kospm_list_new(); + FILE* meta_file = fopen(file_path, "r"); + kospm_list_t *header = kospm_csv_header_get(meta_file); + kospm_pkg_meta_t *pkg_meta; + + ccsv_reader *reader = ccsv_init_reader(kospm_csv_reader_options, NULL); + ccsv_row row; + while(row = read_row(meta_file, reader)){ + pkg_meta = kospm_pkg_meta_load(ccsv_row *row, kospm_list_t *header); + + kospm_list_add(dlist, pkg_meta); + ccsv_free_row(row); + } + + fclose(meta_file); + + return dlist; +} + +kospm_list_t* _kospm_files_table_read(char* file_path){ + kospm_list_t *dlist = kospm_list_new(); + FILE* files_file = fopen(file_path, "r"); + kospm_list_t *header = kospm_csv_header_get(files_file); + kospm_pkg_file_t *pkg_file; + + ccsv_reader *reader = ccsv_init_reader(kospm_csv_reader_options, NULL); + ccsv_row row; + while(row = read_row(files_file, reader)){ + pkg_file = kospm_pkg_file_load(ccsv_row *row, kospm_list_t *header); + + kospm_list_add(dlist, pkg_file); + ccsv_free_row(row); + } + + fclose(files_file); + + return dlist; +} + +int _kospm_meta_table_write(kospm_pkg_list_t *pkg_list, char* file_path){ + FILE* meta_file = fopen(file_path, "w"); + kospm_csv_header *header = kospm_csv_header_get(meta_file); + kospm_list_t *meta_list = pkg_list->packages; + + ccsv_writer *writer = ccsv_init_writer(kospm_csv_writer_options, NULL); + meta_list->current = meta_list->first; + char **meta_row; + while(meta_list->current){ + meta_row = kospm_pkg_meta_store(meta_list->current->data, + header); + + write_row_from_array(meta_file, writer, meta_row, + header->col_amount); + } + + fclose(meta_file); + + return 0; +} + +int _kospm_files_table_write(kospm_pkg_list_t *pkg_list, char* file_path){ + FILE* files_file = fopen(file_path, "w"); + kospm_csv_header *header = kospm_csv_header_get(files_file); + kospm_list_t *files_list = pkg_list->files; + + ccsv_writer *writer = ccsv_init_writer(kospm_csv_writer_options, NULL); + files_list->current = files_list->first; + char **file_row; + while(_list->current){ + file_row = kospm_pkg_file_store(files_list->current->data, + header); + + write_row_from_array(meta_file, writer, file_row, + header->col_amount); + } + + fclose(files_file); + + return 0; +} + +kospm_pkg_list_t* kospm_pkg_list_init(){ + kospm_pkg_list_t *pkg_list = (kospm_pkg_list_t*)malloc(sizeof(kospm_pkg_list_t)); + + pkg_list->packages = kospm_list_new(); + pkg_list->files = kospm_list_new(); + + return pkg_list; +} + +kospm_pkg_list_t* kospm_pkg_list_open(kospm_pkg_list_t *pkg_list, char* pkg_list_path){ + char* meta_file_path = (char*)malloc(FILE_MAX*sizeof(char)); + char* files_file_path = (char*)malloc(FILE_MAX*sizeof(char)); + if ((snprintf(meta_list_path, FILE_MAX, "%s%s", pkglist_path, + META_TABLE)>=FILE_MAX)|| + (snprintf(files_file_path, FILE_MAX, "%s%s", pkglist_path, + FILES_TABLE)>=FILE_MAX)){ + free(meta_file_path); + free(files_file_path); + + return -1; + } + + if (!pkg_list) pkg_list = kospm_pkg_list_init(); + + pkg_list->packages = _kospm_meta_table_read(meta_file_path); + pkg_list->files = _kospm_files_table_read(files_filefile_path); + + return pkg_list; +} + +int kospm_pkg_list_save(kospm_pkg_list_t *pkg_list, char* pkglist_path){ + MALLOCNEWARR(meta_file_path, char, FILE_MAX); + MALLOCNEWARR(files_file_path, char, FILE_MAX); + if ((snprintf(meta_list_path, FILE_MAX, "%s%s", pkglist_path, + META_TABLE)>=FILE_MAX) || + (snprintf(files_file_path, FILE_MAX, "%s%s", pkglist_path, + FILES_TABLE)>=FILE_MAX)){ + free(meta_file_path); + free(files_file_path); + + return -1; + } + + _kospm_meta_table_write(pkg_list, meta_file_path); + _kospm_files_table_write(pkg_list, files_file_path); + + free(meta_file_path); + free(files_file_path); + + return 0; +} + +void _kospm_pkg_meta_free(kospm_pkg_meta_t *pkg_meta){ + free(pkg_meta->pkg_description); + + free(pkg_meta); +} + +void _kospm_pkg_file_free(kospm_pkg_file_t *pkg_file){ + free(pkg_file->file_name); + + free(pkg_file); +} + +int kospm_pkg_list_close(kospm_pkg_list_t* pkg_list){ + kospm_list_free(pkg_list->packages, _kospm_pkg_meta_free); + kospm_list_free(pkg_list->files, _kospm_pkg_file_free); + + free(pkg_list); + + return 0; +} + +kospm_pkg_meta_t* kospm_pkg_list_meta_query(kospm_pkg_list_t *pkg_list, + char *pkg_name){ + kospm_pkg_meta_t* pkg_meta = + kospm_list_get_by_value(pkg_list->packages, pkg_name, + kospm_pkg_meta_cmp); + pkg_list->packages->current=pkg_list->packages->first; + + return pkg_meta; +} + +kospm_list_t* kospm_pkg_list_files_query(kospm_pkg_list_t *pkg_list, + char *pkg_name){ + kospm_list_t* file_list = kospm_list_init(); + + pkg_list->files->current = pkg_list->files->first; + + + while(kospm_list_get_by_value(pkg_list->files, pkg_name, + kospm_pkg_file_check_pkgname)!=NULL){ + kospm_list_add(file_list, pkg_list->files->current); + } + + return file_list; +} diff --git a/src/kospm_pkgmeta.c b/src/kospm_pkgmeta.c new file mode 100644 index 0000000..ab48772 --- /dev/null +++ b/src/kospm_pkgmeta.c @@ -0,0 +1,52 @@ +#include +#include "kospm_macros.h" +#include "kospm_pkgmeta.h" + +kospm_pkg_meta_t* kospm_pkg_meta_init(){ + kospm_pkg_meta_t *pkg_meta = (kospm_pkg_meta_t*)malloc(sizeof(kospm_pkg_meta_t)); + + return pkg_meta; +} + +kospm_pkg_meta_t* kospm_pkg_meta_load(ccsv_row *row, + kospm_csv_header *header){ + kospm_pkg_meta_t *pkg_meta = kospm_pkg_meta_init(); + + strncpy(pkg_meta->pkg_name, kospm_csv_field_get(row, header, "name"), NAME_MAX); + strncpy(pkg_meta->pkg_version, kospm_csv_field_get(row, header, "version"), VERSION_MAX); + pkg_meta->pkg_description = + strcpynew(kospm_csv_field_get(row, header, "description"), + DESCRIPTION_MAX-1); + char* size_lit = + strcpynew(kospm_csv_field_get(row, header, "description"), 10); + pkg_meta->pkg_size=atoi(size_lit); + + return pkg_meta; +} + +char** kospm_pkg_meta_store(kospm_pkg_meta_t *pkg_meta, + kospm_csv_header *header){ + char** row[header->col_amount]; + row[kospm_csv_field_get(row, header, "name")] = + strcpynew(pkg_meta->pkg_name, NAME_MAX-1); + row[kospm_csv_field_get(row, header, "version")] = + strcpynew(pkg_meta->pkg_version, VERSION_MAX-1); + row[kospm_csv_field_get(row, header, "description")] = + strcpynew(pkg_meta->pkg_description, DESC_MAX-1); + row[kospm_csv_field_get(row, header, "size")] = + strcpynew((pkg_meta->pkg_size), DESC_MAX-1); + + return row; +} + +int kospm_pkg_meta_check_pkgname(kospm_pkg_meta_t *pkg_meta, + char* pkg_name){ + return !strcmp(pkg_meta->pkg_name, pkg_name); +} + +int kospm_pkg_meta_free(kospm_pkg_meta_t *pkg_meta){ + free(pkg_meta->pkg_description); + free(pkg_meta); + + return 0; +} diff --git a/src/kospm_tar.c b/src/kospm_tar.c index 1f2f2e6..ec69145 100644 --- a/src/kospm_tar.c +++ b/src/kospm_tar.c @@ -1,7 +1,7 @@ /* * kospm_tar.c * - * Copyright 2024 keXa + * Copyright 2024-2025 keXa * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,16 +21,54 @@ * */ #include -#include "../include/kospm_tar.h" +#include +#include "kospm_tar.h" -int tar_unpack(const char *tar_name, const char *src_file, - const char *dest_file){ +kospm_list_t* kospm_tar_filelist_get(const char *tar_name){ + mtar_t tar; + mtar_header_t* header; + int error = MTAR_ESUCCESS; + + if(mtar_open(tar, tar_name, "r") != MTAR_ESUCCESS) {return NULL;} + + kospm_list_t* filelist = kospm_list_new(); + + header = malloc(sizeof(mtar_header_t)); + + //add code that creates a list of files + while ((error = mtar_read_header(&tar, &header)) && (error != MTAR_ENULLRECORD)) { + if (error == MTAR_EBADCHKSUM){ + kospm_list_free(filelist, NULL); + + return NULL; + } + kospm_list_add(filelist, header); + + mtar_next(&tar); + } + + mtar_close(tar); + filelist->current=filelist->first; + + return filelist; +} + +int _kospm_tar_file_name_cmp(mtar_header_t* header, char* file_name){ + return !strcmp(header->name, file_name); +} + +int kospm_tar_file_exists(kospm_list_t* file_list, const char *file_name){ + return (kospm_list_get_by_value(file_list, file_name, _kospm_tar_file_name_cmp)) ? 1 : 0; +} + +int kospm_tar_unpack(const char *tar_name, const char *src_file, + const char *dest_file) { mtar_t tar; mtar_header_t header; - if(mtar_open(tar, tar_name, "r") != MTAR_ESUCCESS){return 1;} + if(mtar_open(tar, tar_name, "r") != MTAR_ESUCCESS) {return 1;} - if (mtar_find(&tar, file_to_extract, &header) != MTAR_ESUCCESS) { + if (mtar_find(&tar, src_file, &header) != MTAR_ESUCCESS) { return 1; }