static int InstallDll(BOOL install, const WCHAR *strDll, const WCHAR *command_line) { HRESULT hr; DLLINSTALL pfInstall; HMODULE DllHandle = NULL; pfInstall = LoadProc(strDll, "DllInstall", &DllHandle); if (!pfInstall) return GETPROCADDRESS_FAILED; hr = pfInstall(install, command_line); if(FAILED(hr)) { if (install) output_write(STRING_INSTALL_FAILED, strDll); else output_write(STRING_UNINSTALL_FAILED, strDll); return DLLSERVER_FAILED; } if (install) output_write(STRING_INSTALL_SUCCESSFUL, strDll); else output_write(STRING_UNINSTALL_SUCCESSFUL, strDll); if(DllHandle) FreeLibrary(DllHandle); return 0; }
int output_core(t_info *info) { t_outputfile *output; char *outputfile; t_word *word; int i; int j; t_cmd_list *cmdlist; output = output_init(); cmdlist = info->tete_cmd; output_num_32(output, COREWAR_EXEC_MAGIC); output_num_32(output, info->size_prog); output_str(output, info->name, PROG_NAME_LENGTH); output_str(output, info->comment, PROG_COMMENT_LENGTH); while (cmdlist) { for (j = 0; (word = cmdlist->cmd[j]); j++) for (i = 0; i < word->size; i++) output_char(output, invert_quartet(word->codage[i])); cmdlist = cmdlist->next; } outputfile = output_file(info->inputfile); output_write(output, outputfile); return 1; }
/** * Loads procedure. * * Parameters: * strDll - name of the dll. * procName - name of the procedure to load from the dll. * DllHandle - a variable that receives the handle of the loaded dll. */ static VOID *LoadProc(const WCHAR* strDll, const char* procName, HMODULE* DllHandle) { VOID* (*proc)(void); *DllHandle = LoadLibraryExW(strDll, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if(!*DllHandle) { output_write(STRING_DLL_LOAD_FAILED, strDll); ExitProcess(LOADLIBRARY_FAILED); } proc = (VOID *) GetProcAddress(*DllHandle, procName); if(!proc) { output_write(STRING_PROC_NOT_IMPLEMENTED, procName, strDll); FreeLibrary(*DllHandle); return NULL; } return proc; }
/** * Main processing routine of Sally. This function processes chunks of * strings. It might be suitable for OpenMP support in a later version. */ static void sally_process() { long read, i, j; int chunk; const char *hash_file; /* Check if a hash file is set */ config_lookup_string(&cfg, "features.hash_file", &hash_file); /* Get chunk size */ config_lookup_int(&cfg, "input.chunk_size", &chunk); /* Allocate space */ fvec_t **fvec = malloc(sizeof(fvec_t *) * chunk); string_t *strs = malloc(sizeof(string_t) * chunk); if (!fvec || !strs) fatal("Could not allocate memory for embedding"); info_msg(1, "Processing %d strings in chunks of %d.", entries, chunk); for (i = 0, read = 0; i < entries; i += read) { read = input_read(strs, chunk); if (read <= 0) fatal("Failed to read strings from input '%s'", input); /* Generic preprocessing of input */ input_preproc(strs, read); #ifdef ENABLE_OPENMP #pragma omp parallel for #endif for (j = 0; j < read; j++) { fvec[j] = fvec_extract(strs[j].str, strs[j].len); fvec_set_label(fvec[j], strs[j].label); fvec_set_source(fvec[j], strs[j].src); } if (!output_write(fvec, read)) fatal("Failed to write vectors to output '%s'", output); /* Free memory */ input_free(strs, read); output_free(fvec, read); /* Reset hash if enabled but no hash file is set */ if (fhash_enabled() && !strlen(hash_file) > 0) fhash_reset(); prog_bar(0, entries, i + read); } free(fvec); free(strs); }
static int output_vprintf(const WCHAR* fmt, va_list va_args) { WCHAR str[8192]; int len; len = vsnprintfW(str, sizeof(str)/sizeof(*str), fmt, va_args); if (len < 0) WINE_FIXME("String too long.\n"); else output_write(str, len); return 0; }
static int output_vnprintf(Output *o, size_t max, const char *format, va_list args) { char buf[max]; int r; assert_return(o, -EINVAL); assert_return(format, -EINVAL); assert_return(max <= 4096, -EINVAL); r = MIN(vsnprintf(buf, max, format, args), (int) max); return output_write(o, buf, r); }
static int UnregisterDll(const WCHAR* strDll) { HRESULT hr; DLLUNREGISTER pfUnregister; HMODULE DllHandle = NULL; pfUnregister = LoadProc(strDll, "DllUnregisterServer", &DllHandle); if (!pfUnregister) return GETPROCADDRESS_FAILED; hr = pfUnregister(); if(FAILED(hr)) { output_write(STRING_UNREGISTER_FAILED, strDll); return DLLSERVER_FAILED; } output_write(STRING_UNREGISTER_SUCCESSFUL, strDll); if(DllHandle) FreeLibrary(DllHandle); return 0; }
static int output_vprintf(Output *o, const char *format, va_list args) { char buf[4096]; int r; assert_return(o, -EINVAL); assert_return(format, -EINVAL); r = vsnprintf(buf, sizeof(buf), format, args); assert_return(r < (ssize_t)sizeof(buf), -ENOBUFS); return output_write(o, buf, r); }
static BOOL output_error_string(DWORD error) { LPWSTR pBuffer; if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, error, 0, (LPWSTR)&pBuffer, 0, NULL)) { output_write(pBuffer, lstrlenW(pBuffer)); LocalFree(pBuffer); return TRUE; } return FALSE; }
static int output_vnprintf(Output *o, size_t max, const char *format, va_list args) { char buf[4096]; int r; assert_return(o, -EINVAL); assert_return(format, -EINVAL); assert_return(max <= sizeof(buf), -EINVAL); r = vsnprintf(buf, max, format, args); if (r > (ssize_t)max) r = max; return output_write(o, buf, r); }
void zig_zag(int quant_coefficient_matrix[8][8]){ int i, j, h; int output_matrix[8][8]; //An array of what the proper reordering should be int zz_order[64] = {0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63}; for(h = 0; h < 64; h++){//Goes over every element of the zz array for(i = 0; i < 8; i++){ for(j = 0; j < 8; j++){ //If the position of element matches the one in the zz_order array if(i*8 + j == zz_order[h]){ // h/8 determines which row, h%8 determines which column output_matrix[h/8][h%8] = quant_coefficient_matrix[i][j]; } } } } // print_8x8_matrix(output_matrix); //Write this block to the file output_write(output_matrix, output_fileHandle); }
int main() { output_file = fopen("output.wav", "wb"); if (!output_file) die_perror("failed to open file"); int samplerate = SAMPLE_RATE; int channels = 2; int bitspersample = 16; int datarate = samplerate * channels * (bitspersample / 8); int blockalign = channels * (bitspersample / 8); // write wav header output_write("RIFF", 4); long riff_len_pos = ftell(output_file); // need to write 36+datalen to riff_len_pos write_le32(0); output_write("WAVE", 4); output_write("fmt ", 4); write_le32(16); write_le16(1); write_le16(channels); write_le32(samplerate); write_le32(datarate); write_le16(blockalign); write_le16(bitspersample); output_write("data", 4); long wav_data_pos = ftell(output_file); // need to write datalen to wav_data_pos write_le32(0); int i; for (i = 0; i < 22050; i++) output_sample(0, 0); // write 500ms of silence write_pulse(1, 4909, 1000000); // command start write_pulse(0, 4320, 1000000); i = 0; unsigned code = 0xe0e040bf; for (i = 0; i < 32; i++) { int bit = (code >> (31 - i)) & 0x1; if (bit) { write_pulse(1, 818, 1000000); // 1 bit write_pulse(0, 1425, 1000000); } else { write_pulse(1, 818, 1000000); // 0 bit write_pulse(0, 325, 1000000); } } write_pulse(1, 717, 1000000); // command stop write_pulse(0, 717, 1000000); for (i = 0; i < 22050; i++) output_sample(0, 0); // write 500ms of silence fseek(output_file, riff_len_pos, SEEK_SET); write_le32(36 + datalen); fseek(output_file, wav_data_pos, SEEK_SET); write_le32(datalen); fclose(output_file); return 0; }
void output_sample(short left, short right) { output_write(&left, 2); output_write(&right, 2); datalen += 4; }
static void write_le16(int i) { unsigned short u = (unsigned short)i; output_write((void*)&u, 2); }
static void write_le32(int i) { unsigned u = (unsigned)i; output_write((void*)&u, 4); }
int wmain(int argc, WCHAR* argv[]) { int i, res, ret = 0; BOOL CallRegister = TRUE; BOOL CallInstall = FALSE; BOOL Unregister = FALSE; BOOL DllFound = FALSE; WCHAR* wsCommandLine = NULL; WCHAR EmptyLine[1] = {0}; OleInitialize(NULL); /* We mirror the Microsoft version by processing all of the flags before * the files (e.g. regsvr32 file1 /s file2 is silent even for file1). * * Note the complication that this version may be passed Unix format filenames * which could be mistaken for flags. The Windows version conveniently * requires each flag to be separate (e.g. no /su), so we will simply * assume that anything longer than /. is a filename. */ for(i = 1; i < argc; i++) { if (argv[i][0] == '/' || argv[i][0] == '-') { if (!argv[i][1]) return INVALID_ARG; if (argv[i][2] && argv[i][2] != ':') continue; switch (tolowerW(argv[i][1])) { case 'u': Unregister = TRUE; break; case 's': Silent = TRUE; break; case 'i': CallInstall = TRUE; wsCommandLine = parse_command_line(argv[i] + 2); /* argv[i] + strlen("/i") */ if (!wsCommandLine) wsCommandLine = EmptyLine; break; case 'n': CallRegister = FALSE; break; case 'c': /* console output */; break; default: output_write(STRING_UNRECOGNIZED_SWITCH, argv[i]); output_write(STRING_USAGE); return INVALID_ARG; } argv[i] = NULL; } } if (!CallInstall && !CallRegister) /* flags: /n or /u /n */ return INVALID_ARG; for (i = 1; i < argc; i++) { if (argv[i]) { WCHAR *DllName = argv[i]; res = 0; DllFound = TRUE; if (CallInstall && Unregister) res = InstallDll(!Unregister, DllName, wsCommandLine); /* The Windows version stops processing the current file on the first error. */ if (res) { ret = res; continue; } if (!CallInstall || (CallInstall && CallRegister)) { if(Unregister) res = UnregisterDll(DllName); else res = RegisterDll(DllName); } if (res) { ret = res; continue; } if (CallInstall && !Unregister) res = InstallDll(!Unregister, DllName, wsCommandLine); if (res) { ret = res; continue; } } } if (!DllFound) { output_write(STRING_HEADER); output_write(STRING_USAGE); return INVALID_ARG; } OleUninitialize(); /* return the most recent error code, even if later DLLs succeed */ return ret; }