Showing posts with label TCC. Show all posts
Showing posts with label TCC. Show all posts

Friday, April 1, 2022

TCC, SQLITE, UTF-8 super working (command line tool creation) * pure C is awesome

#include<stdio.h>
#include<stdlib.h>
   #include <sqlite3.h>

 // Compile instructions:
// tcc ctext.c sqlite3.def

// If you use ulaz.txt file saved as utf-8 text file,
// than first line of text must be empty
// just put all select, insert, update and other sqlite commands in ulaz.txt
//line by line
//callback can be modified to write data formated to HTML TABLE, than open it

  static int callback(void *NotUsed, int argc, char **argv, char **azColName){
    int i;
    for(i=0; i<argc; i++){
      printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
    }
    printf("\n");
    return 0;
  }

//int main(int argc, char* argv[])
int main()
{

char const* const fileName = "ulaz.txt";

FILE* file = fopen(fileName, "r");

if(!file){
printf("\n Unable to open : %s ", fileName);
return -1;
}

    char line[500];
    const char algv1[8] = "dora.db";

    //algv1 = "dora.db";

    char str[50];
    FILE *fp;
    fp = fopen("izlaz2.txt", "w");

    if(fp == NULL)
    {
        printf("Error opening file\n");
        exit(1);
    }

    sqlite3 *db;
    char *zErrMsg = 0;
    int rc;

/*  
    if( argc!=3 ){
      fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
      return(1);
    }
*/

    rc = sqlite3_open("dora.db", &db);
    if( rc ){
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      sqlite3_close(db);
      return(1);
    }

/*
    rc = sqlite3_exec(db, "select * from dora where a4 like '%Сремски%'", callback, 0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      fprintf(stderr, "SQL error: %s\n", zErrMsg);
      sqlite3_free(zErrMsg);
    }

*/

//    sqlite3_close(db);

int i=0;
 
while (fgets(line, sizeof(line), file)) {
        printf("%s", line);
//        fputs(str, fp);
        fputs(line, fp);

if (i>0) {
    rc = sqlite3_exec(db, line, callback, 0, &zErrMsg);
    if( rc!=SQLITE_OK ){
      fprintf(stderr, "SQL error: %s\n", zErrMsg);
      sqlite3_free(zErrMsg);
    }
}
    i = i + 1;

    }

    fclose(fp);
    fclose(file);
        sqlite3_close(db);

    return 0;

} 

OR YOU CAN TRY THIS IN GOLANG TOO:


But in GOLANG, you must to install GCC first and:

https://github.com/mattn/go-sqlite3

too many hussle for the same result.

On Windows GCC best installation is MinGW way.

Hundreds and hundreds megabytes for simple peace of code.

On the other hand in TCC you need to install only 1,2 MB and we are in business.

TCC need only dll and def files from main SQLITE web site.

Saturday, May 8, 2021

Unicode @ Bellard TCC as console app finally



TCC @ Windows 10 tips:

#include <fcntl.h>
#include <io.h>
#include <stdio.h>

int main(void) {
    wchar_t str[80];
    int i;
    setmode(_fileno(stdout), _O_U16TEXT);
    setmode(_fileno(stdin), _O_U16TEXT);
    wprintf(L"\x043a\x043e\x0448\x043a\x0430 \nđšđšđ77ђшђшђшђшђ");
    wscanf(L"%ls", str);
    wscanf(L"%d", &i);
    wprintf(L"I am a %ls ,and I have %d year.\n", str, i);
    return 0;
}

//I am very happy about TCC unicode, are you too ?
//Using of: tcc-0.9.27-win64-bin.zip installation


//Lean Mean Coding Machine



I have already managed to set up to use TCC to read from a SQLITE table and write to a text file, but this is much more effective, isn't it ?
You can now use SQLITE in addition to entering and printing text.


And you can try this too:

const wchar_t * wstring = L"some wide string";
wprintf( L"%s\n", wstring );

wchar_t wideChar = 0x1234;
wprintf( L"hex: %04X  char: %c\n", wideChar, wideChar );

Secure your Network with OpenDNS:




Linux tips:


Homebrew Cask extends Homebrew and brings its elegance, simplicity, and speed to the installation and management of GUI macOS applications such as Atom and Google Chrome.

We do this by providing a friendly CLI workflow for the administration of macOS applications distributed as binaries.

$ brew install alfred
==> Downloading https://cachefly.alfredapp.com/Alfred_4.2.1_1187.dmg
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'alfred'.
==> Installing Cask alfred
==> Moving App 'Alfred 4.app' to '/Applications/Alfred 4.app'.
🍺  alfred was successfully installed!
And there we have it. An application installed with one quick command: no clicking, no dragging, no dropping.


$

ls -latr

  1. l - long list  
  2. a - include hidden files 
  3. r - reverse order 
  4. t - sort by time 

  5. $
  6. lspci -k

  7. ++