int main() { const std::vector<std::string> src = get_list_of_files(); YAL_SESSION_CREATE(session1, "disable"); YAL_SESSION_TO_TERM(session1, true, "terminal"); const std::vector<std::string> dst = get_list_of_files(); const bool ok = (src == dst); YAL_ASSERT_TERM(std::cerr, ok); }
/*> ## Processing the input files So now we can start to process the files. Let's jump to the `main` function and see the good parts. First we get files to process and open the output file. If there are no input files, we terminate and wont overwrite an existing `README.md` file (just be save). <*/ int main(int argc, char **argv) { str_lst *files = get_list_of_files(); return_unless(files, EXIT_FAILURE, "can't read list of files"); return_unless(str_lst_count(files), EXIT_SUCCESS, "nothing to process"); FILE *out = fopen("README.md", "w"); if (!out) { str_lst_free(files); return_unless(false, EXIT_FAILURE, "can't open README.md"); } /*> Now we open each file and call the process function. The function needs to know, if the file contains MarkDown directly, or is a source code file, that only contains MarkDown in special comment blocks. We do the suffix magic to check, if it ends in `.md`. Otherwise we will assume it a source code file. <*/ for (char **cur = str_lst_begin(files); cur != str_lst_end(files); ++cur) { FILE *in = fopen(*cur, "r"); if (!in) { fclose(out); return_unless(false, EXIT_FAILURE, "can't read \"%s\"", *cur); } printf("processing \"%s\" ... ", *cur); size_t length = strlen(*cur); bool code_file = length < 3 || strcmp(*cur + length - 3, ".md"); puts(process_file(in, out, code_file) ? "ok" : "FAILED"); fclose(in); } fclose(out); str_lst_free(files); }
size_t parse_data_rcvd(void *rcv_data, void **outBuffer) { int size; struct data *data; struct data new_data; data = rcv_data; rcv_data = rcv_data + sizeof(struct data); switch (data->data_type){ case LIST:{ *outBuffer = malloc(sizeof(char) * 5000); get_list_of_files(OUR_PATH, *outBuffer + sizeof(struct data)); new_data.data_type = LIST; new_data.size = strlen(*outBuffer + sizeof(struct data)); memcpy(*outBuffer, &new_data, sizeof(struct data)); size = sizeof(struct data) + new_data.size; break; }; case GET:{ size = map_file_in_mem(data->str, outBuffer); new_data.data_type = GET; if(size == -1){ *outBuffer = alloc(sizeof(struct data)); new_data.response = ERROR; strcpy(new_data.str, "Request GET. No such file on the server: "); strcpy(new_data.str + 41, rcv_data); memcpy(*outBuffer, &new_data, sizeof(struct data)); size = sizeof(struct data); break; } new_data.response = OK; new_data.size = size; strcpy(new_data.str, data->str); memcpy(*outBuffer, &new_data, sizeof(struct data)); size = size + sizeof(struct data); break; }; case PUT:{ char path[128]; sprintf(path, "/home/dorel/Scrivania/"); /* TODO: just for the test USE THE PATH OTHERWISE */ sprintf(path + 22, data->str); create_file(rcv_data, data->size, path); /*put on file */ *outBuffer = malloc(sizeof(struct data)); /* for the response */ new_data.data_type = PUT; sprintf(new_data.str, "%s", data->str); new_data.size = 0; new_data.response = OK; memcpy(*outBuffer, &new_data, sizeof(struct data)); size = sizeof(struct data); /* Just ADDED */ break; }; default:{ size = 0; }; } return size; }