KDK_PRINTER_GET_FILENAME(3)

📦 version 3.0.1.4, in arch rolling, ubuntu resolute, ubuntu stonking

💖 KDK_PRINTER_GET_FILENAME 💖

okay bestie, welcome to the Library Functions Manual corner of the internet, where we're gonna talk about kdk_printer_get_filename(3). pull up a chair, grab a boba, this one's a little cutie that just wants to hand you a filename 🎀


✨ NAME ✨

kdk_printer_get_filename — 获取当前打印任务状态(发送打印任务之后下需要等待一会再获取状态,状态不是实时更新)

bestie that Chinese line is just saying: it grabs the current print job status, and heads up — after you send a print job you gotta wait a lil minute before asking for the status, because the status is not updated in real time. lowkey the most important gossip on this whole page 🙈


🌸 SYNOPSIS 🌸

#include <libkyprinter.h>

extern char* kdk_printer_get_filename(const char *url);

Link with -lkyprinter.

yes queen, that -lkyprinter is not optional, link it or cry about it 💅


🦋 DETAILED DESCRIPTION 🦋

the whole main character job of this interface? it's to obtain the file name that lives inside the url. that's it. that's the vibe. ✨

The argument url is printer name, url.

not me being literally told "printer name, url" and just accepting that as lore 🫶 that's the spec, bestie, we don't question the spec.

💜 RETURN VALUE 💜

  • On success, returns the parsed file name of type char*. slay, a whole filename, handed to you.
  • On error, return NULL. ngl when it's NULL it's giving "nothing for you today bestie", so check it before you use it 😭

🎀 EXAMPLES 🎀

here's the full little demo, and yes we're keeping every single line exactly as it is because that's the law 💖

#include "libkyprinter.h"
#include <stdio.h>

int main()
{
    int index = 0;
    //获取打印机列表
    char **printers = kdk_printer_get_available_list();
    while (printers[index])
    {
        printf("%zd: %s0, index + 1, printers[index]);

        //取消当前打印机所有打印任务
        kdk_printer_cancel_all_jobs(printers[index]);

        //获取url对应的文件名
        char *url = "http://www.cztouch.com/upfiles/soft/testpdf.pdf";
        int res = -1;
        char *filename = kdk_printer_get_filename(url); //从完整路径名中解析出文件名称,例如:/home/test/abc.txt,解析完成后为abc.txt
        printf("filename = %s0, filename);

        //设置打印参数
        kdk_printer_set_options(2, "A4", "lrtb", "two-sided-long-edge");

        //下载
        res = kdk_printer_print_download_remote_file(url, filename);
        printf("[%s] res = %d0, __FUNCTION__, res);
        printf("[%s] filepath = %s0, __FUNCTION__, filename);

        //打印
        int job_id = kdk_printer_print_local_file(printers[index], filename);
        if (job_id == 0)
        {
            //打印失败
            printf("[%s] create print job fail0, __FUNCTION__);
        }
        else
        {
            //打印成功,等待一会获取任务状态
            sleep(10);
            int status = kdk_printer_get_job_status(printers[index], job_id);
        }

        index++;
        free(filename);
    }
    kdk_printer_freeall(printers);
    return 0;
}

the comment right there in the middle is the moment fr fr: it parses the filename out of a full path, like /home/test/abc.txt becomes abc.txt. iconic behavior, no notes. 👑


🌈 CONFORMING TO 🌈

These functions are as per the withdrawn POSIX.1e draft specification.

The following functions are Linux extensions: kdk_printer_get_list(), kdk_printer_get_available_list(), kdk_printer_set_options(), kdk_printer_print_download_remote_file(), kdk_printer_print_local_file(), kdk_printer_cancel_all_jobs(), kdk_printer_get_status(), kdk_printer_get_job_status() and kdk_printer_freeall().

withdrawn POSIX.1e draft? yeah she's retired but we still love her 💀 the rest of the crew are Linux extensions, iykyk.

⭐ SEE ALSO ⭐

go read the whole friend group, they're all linked and they all ate 💅


okay that's the whole page bestie, every flag, every return, every last detail, all present and accounted for 🫶

💖 this lil page came from the Linux Programmer's Manual, dated Fri Aug 25 2023, and it's filed under KDK_PRINTER_GET_FILENAME(3) — and that's the periodt. 🎀✨

📦 where this page comes from